internal static SongAnchor2014[] Parse(Sng2014HSL.AnchorSection anchorSection)
 {
     var anchors = new SongAnchor2014[anchorSection.Count];
     for (var i = 0; i < anchorSection.Count; i++)
     {
         anchors[i] = new SongAnchor2014
         {
             Time = anchorSection.Anchors[i].StartBeatTime,
             Fret = anchorSection.Anchors[i].FretId,
             Width = anchorSection.Anchors[i].Width
         };
     }
     return anchors;
 }
 internal static SongAnchor2014[] Parse(Sng2014HSL.AnchorSection anchorSection)
 {
     var anchors = new SongAnchor2014[anchorSection.Count];
     for (var i = 0; i < anchorSection.Count; i++) {
         var anchor = new SongAnchor2014();
         anchor.Time = anchorSection.Anchors[i].StartBeatTime;
         anchor.Fret = anchorSection.Anchors[i].FretId;
         anchor.Width = anchorSection.Anchors[i].Width;
         anchors[i] = anchor;
     }
     return anchors;
 }
        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();
        }