private static void AddBeatWithChordToVoice(Voice voice, SongChord2014 sourceChord, Duration duration)
        {
            var beat = new Beat();

            beat.duration = duration;
            voice.addBeat(beat);
            beat.chordId = sourceChord.ChordId.ToString();
            var chord = beat.chord();

            var chordString       = chord == null ? "null" : "not null";
            var sourceChordString = sourceChord.ChordNotes != null?sourceChord.ChordNotes.Length.ToString() : "null";

            Debug.WriteLine(beat.chordId + " - chord: " + chordString + ", sourceChord.ChordNotes: " + sourceChordString);

            //if (chord != null && sourceChord.ChordNotes.Any())
            //{
            //    DbgAssert(false);
            //}

            //Will be non-null if predefined chord exist (and predefined chord should exist if ChordId is present in ChordTemplates)
            if (chord == null)
            {
                beat.chordId = null;
                //chord = new global::alphatab.model.Chord();
                //voice.bar.track.chords.set(beat.chordId, chord);

                //Set notes in beat from this chord
                if (sourceChord.ChordNotes != null)
                {
                    foreach (var sourceNote in sourceChord.ChordNotes)
                    {
                        var note1 = NoteFromNote(sourceNote);
                        beat.addNote(note1);
                    }
                }
            }
            else
            {
                //Set notes in beat from predefined chord
                for (int i = 0; i < chord.strings.length; i++)
                {
                    var tmpstrFret = chord.strings[i];
                    if (tmpstrFret > -1)
                    {
                        var note1 = new Note();
                        note1.fret    = tmpstrFret;
                        note1.@string = i + 1;
                        beat.addNote(note1);
                    }
                }
            }
        }
Example #2
0
        private static void AddBeatWithChordToVoice(Voice voice, SongChord2014 sourceChord, Duration duration, Single durationTime)
        {
            var beat = new Beat();

            beat.Duration = duration;
            voice.AddBeat(beat);
            beat.ChordId = sourceChord.ChordId.ToString();
            AlphaTab.Model.Chord chord = null;
            try
            {
                chord = beat.Chord;
            }
            catch (KeyNotFoundException)
            {
            }

            //Will be non-null if predefined chord exist (and predefined chord should exist if ChordId is present in ChordTemplates)
            if (chord == null)
            {
                beat.ChordId = null;
                //chord = new global::alphatab.model.Chord();
                //voice.bar.track.chords.set(beat.chordId, chord);

                //Set notes in beat from this chord
                if (sourceChord.ChordNotes != null)
                {
                    foreach (var sourceNote in sourceChord.ChordNotes)
                    {
                        var note1 = NoteFromNote(sourceNote, durationTime);
                        beat.AddNote(note1);
                    }
                }
            }
            else
            {
                //Set notes in beat from predefined chord
                for (int i = 0; i < chord.Strings.Count; i++)
                {
                    var tmpstrFret = chord.Strings[i];
                    if (tmpstrFret > -1)
                    {
                        var note1 = new Note();
                        note1.Fret   = tmpstrFret;
                        note1.String = i + 1;
                        beat.AddNote(note1);
                    }
                }
            }
        }
        private static void AddNotes(Song2014 rsSong, ZpeSong zigSong, string arrangement)
        {
            int spread     = 3;
            int width      = spread;
            var notes      = new Dictionary <string, List <SongNote2014> >();
            var chords     = new Dictionary <string, List <SongChord2014> >();
            var anchors    = new Dictionary <string, List <SongAnchor2014> >();
            var handShapes = new Dictionary <string, List <SongHandShape> >();
            var chordTemps = new Dictionary <string, Tuple <int, SongChordTemplate2014> >();

            var guitarTrack     = zigSong.Tracks.SingleOrDefault(tr => arrangement.Equals(tr.Name));
            var difficultyCount = guitarTrack.Chords.GroupBy(chord => chord.Difficulty).Count();

            foreach (var group in guitarTrack.Chords.GroupBy(chord => chord.Difficulty))
            {
                var gNotes      = notes[group.Key] = new List <SongNote2014>();
                var gChords     = chords[group.Key] = new List <SongChord2014>();
                var gAnchors    = anchors[group.Key] = new List <SongAnchor2014>();
                var gHandShapes = handShapes[group.Key] = new List <SongHandShape>();
                var zChords     = group.OrderBy(chord => chord.StartTime).ToList();
                var lastMeasure = 0;
                int highFret    = -1;
                //bool lastWasChord = false;
                SongAnchor2014 curAnchor = null;
                // dont see any tempo, time sig note or chord time adjustment here because
                // start end times have already been tempo timsig map adjusted
                for (int i = 0; i < zChords.Count; i++)
                {
                    var zChord = zChords[i];
                    if (zChord.Notes.Count > 1)  // cord
                    {
                        Tuple <int, SongChordTemplate2014> val = GetChordTemplate(zChord, chordTemps);

                        int minCFret = Math.Min(DeZero(val.Item2.Fret0), Math.Min(DeZero(val.Item2.Fret1), Math.Min(DeZero(val.Item2.Fret2), Math.Min(DeZero(val.Item2.Fret3), Math.Min(DeZero(val.Item2.Fret4), DeZero(val.Item2.Fret5))))));

                        if (minCFret != int.MaxValue)
                        {
                            if (curAnchor == null)
                            {
                                if (gAnchors.Count == 0 || gAnchors[gAnchors.Count - 1].Fret != minCFret)
                                {
                                    gAnchors.Add(new SongAnchor2014 {
                                        Fret = Math.Min(18, minCFret), Time = (float)Math.Round(zChord.StartTime, 3), Width = spread
                                    });
                                }
                            }
                            else
                            {
                                if (minCFret + spread <= highFret)
                                {
                                    curAnchor.Fret = minCFret;
                                }
                                gAnchors.Add(curAnchor);
                                if (curAnchor.Fret != minCFret)
                                {
                                    gAnchors.Add(new SongAnchor2014 {
                                        Fret = Math.Min(18, minCFret), Time = (float)Math.Round(zChord.StartTime, 3), Width = spread
                                    });
                                }
                                curAnchor = null;
                            }
                        }

                        SongHandShape handShape = new SongHandShape {
                            ChordId = val.Item1, StartTime = (float)Math.Round(zChord.StartTime, 3)
                        };

                        do
                        {
                            SongChord2014 chord = new SongChord2014();
                            chord.Time    = (float)Math.Round(zChord.StartTime, 3);
                            chord.ChordId = val.Item1;
                            chord.Strum   = "down"; // required by CST

                            List <SongNote2014> noteList = new List <SongNote2014>();
                            for (int zNoteIndex = 0; zNoteIndex < zChord.Notes.Count; zNoteIndex++)
                            {
                                var note = GetNote(zChord, null, zNoteIndex);
                                noteList.Add(note);
                            }
                            chord.ChordNotes = noteList.ToArray();

                            var measure = rsSong.Ebeats.FirstOrDefault(ebeat => ebeat.Time >= chord.Time);
                            if (measure == null || measure.Measure > lastMeasure)
                            {
                                lastMeasure       = measure == null ? lastMeasure : measure.Measure;
                                chord.HighDensity = 0;
                            }
                            else if (gChords.Count == 0 || gChords[gChords.Count - 1].ChordId != chord.ChordId)
                            {
                                chord.HighDensity = 0;
                            }
                            else
                            {
                                chord.HighDensity = 1;
                            }

                            gChords.Add(chord);

                            if (i + 1 < zChords.Count)
                            {
                                zChord = zChords[i + 1];
                            }
                        } while (i + 1 < zChords.Count && zChord.Notes.Count > 1 && val.Item1 == GetChordTemplate(zChord, chordTemps).Item1&& ++i != -1);


                        handShape.EndTime = zChord.StartTime;

                        if (handShape.EndTime > handShape.StartTime)
                        {
                            handShape.EndTime -= (handShape.EndTime - zChords[i].EndTime) / 2;
                        }
                        gHandShapes.Add(handShape);
                    }
                    else // single notes
                    {
                        var note = GetNote(zChord, i == zChords.Count - 1 ? null : zChords[i + 1]);
                        if (note.Fret > 0)
                        {
                            if (curAnchor == null)
                            {
                                curAnchor = new SongAnchor2014 {
                                    Fret = Math.Min(18, (int)note.Fret), Time = note.Time, Width = spread
                                };
                                highFret = note.Fret;
                            }
                            else if (note.Fret < curAnchor.Fret)
                            {
                                if (note.Fret + spread >= highFret)
                                {
                                    curAnchor.Fret = note.Fret;
                                }
                                else
                                {
                                    gAnchors.Add(curAnchor);
                                    curAnchor = new SongAnchor2014 {
                                        Fret = Math.Min(18, (int)note.Fret), Time = note.Time, Width = spread
                                    };
                                    highFret = note.Fret;
                                }
                            }
                            else if (note.Fret > highFret)
                            {
                                if (note.Fret - spread <= curAnchor.Fret)
                                {
                                    highFret = note.Fret;
                                }
                                else
                                {
                                    gAnchors.Add(curAnchor);
                                    curAnchor = new SongAnchor2014 {
                                        Fret = Math.Min(18, (int)note.Fret), Time = note.Time, Width = spread
                                    };
                                    highFret = note.Fret;
                                }
                            }
                        }
                        gNotes.Add(note);

                        //if (note.Fret > width)
                        //    width = note.Fret;
                    }
                }

                //if (width > 8)
                //{
                //    string msgText = zigSong.Name + "  " + guitarTrack.Name + ": has a note spread of " + width + " frets   " +
                //        "\r\nThis exceed the useful intended capicity of this program\r\n" +
                //        "and the Rocksmith note highway will be very wide for this song.\r\n\r\n " +
                //        "I understand it could look like crap, but I want to continue anyhow.";

                //    if (MessageBox.Show(new Form { TopMost = true },
                //        msgText, @"Midi File: Fret Spread Warning",
                //        MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                //    {
                //        Application.Exit();
                //        // Application.Restart();
                //        Environment.Exit(-1);
                //    }
                //}

                if (curAnchor != null)
                {
                    gAnchors.Add(curAnchor);
                }
            }

            if (difficultyCount == 1)
            {
                rsSong.Levels = new SongLevel2014[]
                {
                    new SongLevel2014 {
                        Difficulty = 0, Notes = notes["Easy"].ToArray(), Chords = chords["Easy"].ToArray(), Anchors = anchors["Easy"].ToArray(), HandShapes = handShapes["Easy"].ToArray()
                    }
                };
            }
            else
            {
                rsSong.Levels = new SongLevel2014[]
                {
                    new SongLevel2014 {
                        Difficulty = 0,
                        Notes      = notes["Easy"].ToArray(),
                        Chords     = chords["Easy"].ToArray(),
                        Anchors    = anchors["Easy"].ToArray(),
                        HandShapes = handShapes["Easy"].ToArray()
                    },
                    new SongLevel2014 {
                        Difficulty = 1,
                        Notes      = notes["Medium"].ToArray(),
                        Chords     = chords["Medium"].ToArray(),
                        Anchors    = anchors["Medium"].ToArray(),
                        HandShapes = handShapes["Medium"].ToArray()
                    },
                    new SongLevel2014 {
                        Difficulty = 2,
                        Notes      = notes["Hard"].ToArray(),
                        Chords     = chords["Hard"].ToArray(),
                        Anchors    = anchors["Hard"].ToArray(),
                        HandShapes = handShapes["Hard"].ToArray()
                    },
                    new SongLevel2014 {
                        Difficulty = 3,
                        Notes      = notes["Expert"].ToArray(),
                        Chords     = chords["Expert"].ToArray(),
                        Anchors    = anchors["Expert"].ToArray(),
                        HandShapes = handShapes["Expert"].ToArray()
                    }
                };
            }
            rsSong.ChordTemplates = chordTemps.Values.OrderBy(v => v.Item1).Select(v => v.Item2).ToArray();
        }
Example #4
0
        static Chord CreateChord(SongChord2014 rsChord, Dictionary <int, ChordTemplate> chordTemplates, int capo)
        {
            var chord = new Chord();

            chord.Start   = rsChord.Time;
            chord.ChordId = rsChord.ChordId;
            chord.Tremolo = false;
            if (rsChord.ChordNotes != null)
            {
                foreach (var note in rsChord.ChordNotes)
                {
                    chord.Notes.Add(note.String, CreateNote(note, capo));
                }
            }
            if (chordTemplates.ContainsKey(chord.ChordId))
            {
                // need to determine chords from the chord template
                var template = chordTemplates[chord.ChordId];
                for (int i = 0; i < 6; ++i)
                {
                    if (template.Frets[i] >= 0 && !chord.Notes.ContainsKey(i))
                    {
                        var note = new Note()
                        {
                            Fret           = template.Frets[i],
                            String         = i,
                            LeftFingering  = template.Fingers[i],
                            RightFingering = -1,
                        };
                        chord.Notes.Add(i, note);
                    }
                }
            }
            if (chord.Notes.Count == 0)
            {
                Console.WriteLine("  Warning: Empty chord. Cannot find chord with chordId {0}.", chord.ChordId);
            }

            // some properties set on the chord in Rocksmith need to be passed down to the individual notes
            // and vice versa
            foreach (var kvp in chord.Notes)
            {
                if (rsChord.PalmMute != 0)
                {
                    kvp.Value.PalmMuted = true;
                }
                if (rsChord.FretHandMute != 0)
                {
                    kvp.Value.Muted = true;
                }
                if (rsChord.Accent != 0)
                {
                    kvp.Value.Accent = true;
                }
                if (kvp.Value.Tremolo)
                {
                    chord.Tremolo = true;
                }
                if (kvp.Value.Slapped)
                {
                    chord.Slapped = true;
                }
                if (kvp.Value.Popped)
                {
                    chord.Popped = true;
                }
            }

            // we will show a strum hint for all chords played with an up-stroke,
            // and a down-stroke hint for all chords with more than 3 notes (to exclude power-chords)
            //if (rsChord.Strum.ToLower() == "up")
            //    chord.BrushDirection = Chord.BrushType.Up;
            //else if (chord.Notes.Count > 3 && rsChord.Strum.ToLower() == "down")
            //    chord.BrushDirection = Chord.BrushType.Down;
            // disabled, since apparently the strum hints aren't really useful. I might have
            // misunderstood the parameter.

            return(chord);
        }
Example #5
0
 public SongNoteChordWrapper(SongChord2014 wrappedObject)
 {
     _wrappedObject = wrappedObject;
     Time           = wrappedObject.Time;
 }