internal static SongLevel2014[] Parse(Sng2014HSL.Sng sngData)
        {
            var levels = new SongLevel2014[sngData.Arrangements.Count];

            for (var i = 0; i < sngData.Arrangements.Count; i++)
            {
                var level = new SongLevel2014();
                level.Difficulty = sngData.Arrangements.Arrangements[i].Difficulty;
                level.Notes      = SongNote2014.Parse(sngData.Arrangements.Arrangements[i].Notes);
                level.Chords     = SongChord2014.Parse(sngData, sngData.Arrangements.Arrangements[i].Notes);
                level.Anchors    = SongAnchor2014.Parse(sngData.Arrangements.Arrangements[i].Anchors);
                level.HandShapes = SongHandShape.Parse(sngData.Arrangements.Arrangements[i]);
                levels[i]        = level;
            }
            return(levels);
        }
        internal static SongChord2014[] Parse(Sng2014HSL.Sng sngData, Sng2014HSL.NotesSection notesSection)
        {
            var chords = new List <SongChord2014>();

            for (var i = 0; i < notesSection.Count; i++)
            {
                if (notesSection.Notes[i].ChordId == -1)
                {
                    continue; //Skip single notes (get only chord notes)
                }
                var chord = new SongChord2014();
                chord.ChordId = notesSection.Notes[i].ChordId;
                chord.Time    = notesSection.Notes[i].Time;
                // Debug.WriteLine("Song2014 chord.ChordId = " + chord.ChordId);

                // TECHNIQUES
                chord.parseChordMask(notesSection.Notes[i], notesSection.Notes[i].NoteMask);

                // CHORD NOTES (WITHOUT TECHNIQUES) + NOT HIGH DENSITY
                if (chord.HighDensity != 1)
                {
                    chord.ParseChordNotes(sngData.Chords.Chords[chord.ChordId]);
                }

                // CHORD NOTES (WITH TECHNIQUES)
                var cnId = notesSection.Notes[i].ChordNotesId;
                if (cnId != -1)
                {
                    if (sngData.ChordNotes.ChordNotes.Length > cnId)
                    {
                        chord.ParseChordNotes(sngData.Chords.Chords[chord.ChordId], sngData.ChordNotes.ChordNotes[cnId]);
                    }
                }

                chords.Add(chord);
            }

            return(chords.ToArray());
        }
 /// <summary>
 /// Showlights only.
 /// </summary>
 /// <param name="tuning"></param>
 /// <param name="crd"></param>
 /// <param name = "handShape"></param>
 /// <param name="bass"></param>
 /// <param name = "capo"></param>
 /// <returns></returns>
 public static Int32 getChordNote(Int16[] tuning, SongChord2014 crd, SongChordTemplate2014[] handShape, bool bass, int capo)
 {
     if (handShape[crd.ChordId] != null)
     {
         List<int> cNote = new List<int>();
         cNote.AddRange(new int[]{
             GetMidiNote(tuning, (Byte)0, (Byte)handShape[crd.ChordId].Fret0, bass, capo),
             GetMidiNote(tuning, (Byte)1, (Byte)handShape[crd.ChordId].Fret1, bass, capo),
             GetMidiNote(tuning, (Byte)2, (Byte)handShape[crd.ChordId].Fret2, bass, capo),
             GetMidiNote(tuning, (Byte)3, (Byte)handShape[crd.ChordId].Fret3, bass, capo),
             GetMidiNote(tuning, (Byte)4, (Byte)handShape[crd.ChordId].Fret4, bass, capo),
             GetMidiNote(tuning, (Byte)5, (Byte)handShape[crd.ChordId].Fret5, bass, capo)
         });
         //Cleanup for -1 notes
         var cOut = cNote.Where(c => c > 0).ToList();
         if (cOut.Count < 1)
             return 35;
         //Return bass note for doublestops
         if (cOut.Count < 3 && cOut[0] > cOut[1])
             return cOut[1];
         //Return most used note
         return cOut.Count > 3 ? cOut.FirstOrDefault(n => cOut.Any(t => t > n)) : cOut[0];
     } return 35;
 }
        internal static SongChord2014[] Parse(Sng2014HSL.Sng sngData, Sng2014HSL.NotesSection notesSection)
        {
            var chords = new List<SongChord2014>();

            for (var i = 0; i < notesSection.Count; i++) {
                if (notesSection.Notes[i].ChordId == -1)
                    continue; //Skip single notes (get only chord notes)

                var chord = new SongChord2014();
                chord.ChordId = notesSection.Notes[i].ChordId;
                chord.Time = notesSection.Notes[i].Time;

                // TECHNIQUES
                chord.parseChordMask(notesSection.Notes[i], notesSection.Notes[i].NoteMask);

                // CHORD NOTES (WITHOUT TECHNIQUES) + NOT HIGH DENSITY
                if (chord.HighDensity != 1) {
                    chord.ParseChordNotes(sngData.Chords.Chords[chord.ChordId]);
                }

                // CHORD NOTES (WITH TECHNIQUES)
                var cnId = notesSection.Notes[i].ChordNotesId;
                if (cnId != -1) {
                    if (sngData.ChordNotes.ChordNotes.Length > cnId)
                        chord.ParseChordNotes(sngData.Chords.Chords[chord.ChordId], sngData.ChordNotes.ChordNotes[cnId]);
                }

                chords.Add(chord);
            }

            return chords.ToArray();
        }
        private void parseChord(Song2014 xml, Sng2014File sng, SongChord2014 chord, Notes n, Int32 chordNotesId)
        {
            n.NoteMask |= CON.NOTE_MASK_CHORD;
            if (chordNotesId != -1)
            {
                // there should always be a STRUM too => handshape at chord time
                // probably even for chordNotes which are not exported to SNG
                n.NoteMask |= CON.NOTE_MASK_CHORDNOTES;
            }

            if (chord.LinkNext != 0)
                n.NoteMask |= CON.NOTE_MASK_PARENT;

            if (chord.Accent != 0)
                n.NoteMask |= CON.NOTE_MASK_ACCENT;
            if (chord.FretHandMute != 0)
                n.NoteMask |= CON.NOTE_MASK_FRETHANDMUTE;
            if (chord.HighDensity != 0)
                n.NoteMask |= CON.NOTE_MASK_HIGHDENSITY;
            if (chord.Ignore != 0)
                n.NoteMask |= CON.NOTE_MASK_IGNORE;
            if (chord.PalmMute != 0)
                n.NoteMask |= CON.NOTE_MASK_PALMMUTE;
            // TODO: does not seem to have a mask or any effect
            // if (chord.Hopo != 0)
            //     n.NoteMask |= ;

            // numbering will be set later
            //n.NoteFlags = CON.NOTE_FLAGS_NUMBERED;

            n.Time = chord.Time;
            n.StringIndex = unchecked((Byte)(-1));
            // always -1
            n.FretId = unchecked((Byte)(-1));
            // anchor fret will be set later
            n.AnchorFretId = unchecked((Byte)(-1));
            // will be overwritten
            n.AnchorWidth = unchecked((Byte)(-1));
            n.ChordId = chord.ChordId;
            n.ChordNotesId = chordNotesId;
            n.PhraseIterationId = getPhraseIterationId(xml, n.Time, false);
            n.PhraseId = xml.PhraseIterations[n.PhraseIterationId].PhraseId;
            // these will be overwritten
            n.FingerPrintId[0] = -1;
            n.FingerPrintId[1] = -1;
            // these will be overwritten
            n.NextIterNote = -1;
            n.PrevIterNote = -1;
            // seems to be unused for chords
            n.ParentPrevNote = -1;
            n.SlideTo = unchecked((Byte)(-1));
            n.SlideUnpitchTo = unchecked((Byte)(-1));
            n.LeftHand = unchecked((Byte)(-1));
            n.Tap = unchecked((Byte)(-1));
            n.PickDirection = unchecked((Byte)(-1));
            n.Slap = unchecked((Byte)(-1));
            n.Pluck = unchecked((Byte)(-1));
            if (chord.ChordNotes != null)
            {
                foreach (var cn in chord.ChordNotes)
                    if (cn.Sustain > n.Sustain)
                        n.Sustain = cn.Sustain;
            }

            if (n.Sustain > 0)
                n.NoteMask |= CON.NOTE_MASK_SUSTAIN;

            int cnt = 0;
            for (int str = 0; str < 6; str++)
                if (sng.Chords.Chords[chord.ChordId].Frets[str] != 255)
                    ++cnt;
            if (cnt == 2)
                n.NoteMask |= CON.NOTE_MASK_DOUBLESTOP;

            // there are only zeros for all chords in lessons
            //n.Vibrato = 0;
            //n.MaxBend = 0;
            n.BendData = new BendDataSection();
            n.BendData.Count = 0;
            n.BendData.BendData = new BendData32[n.BendData.Count];
        }
        public Int32 addChordNotes(Sng2014File sng, SongChord2014 chord)
        {
            var c = new ChordNotes();
            for (int i = 0; i < 6; i++)
            {
                SongNote2014 n = null;
                foreach (var cn in chord.ChordNotes)
                {
                    if (cn.String == i)
                    {
                        n = cn;
                        break;
                    }
                }
                // TODO: need to figure out which masks are not applied
                c.NoteMask[i] = parseNoteMask(n, false);
                c.BendData[i] = new BendData();
                c.BendData[i].BendData32 = parseBendData(n, false);
                if (n != null && n.BendValues != null)
                    c.BendData[i].UsedCount = n.BendValues.Length;
                if (n != null)
                {
                    c.SlideTo[i] = (Byte)n.SlideTo;
                    c.SlideUnpitchTo[i] = (Byte)n.SlideUnpitchTo;
                }
                else
                {
                    c.SlideTo[i] = unchecked((Byte)(-1));
                    c.SlideUnpitchTo[i] = unchecked((Byte)(-1));
                }
                if (n != null)
                    c.Vibrato[i] = n.Vibrato;
            }

            UInt32 crc = sng.HashStruct(c);
            if (cnsId.ContainsKey(crc))
                return cnsId[crc];

            // don't export chordnotes if there are no techniques
            bool noTechniques = c.NoteMask.All(m => m == 0);
            if (noTechniques)
                return -1;

            // add new ChordNotes instance
            Int32 id = cns.Count;
            cnsId[crc] = id;
            cns.Add(c);
            return cnsId[crc];
        }
        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();
        }
示例#8
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;
        }
 public SongNoteChordWrapper(SongChord2014 wrappedObject)
 {
     _wrappedObject = wrappedObject;
     Time = wrappedObject.Time;
 }
        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 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);
                    }
                }          
            }


        }