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 SongHandShape[] Parse(Sng2014HSL.Arrangement arrangement) { var count = arrangement.Fingerprints1.Count + arrangement.Fingerprints2.Count; var fprints = new List <Sng2014HSL.Fingerprint>(); fprints.AddRange(arrangement.Fingerprints1.Fingerprints); fprints.AddRange(arrangement.Fingerprints2.Fingerprints); fprints = fprints.OrderBy(e => e.StartTime).ToList <Sng2014HSL.Fingerprint>(); var hshapes = new SongHandShape[count]; for (var i = 0; i < count; i++) { var hs = new SongHandShape(); hs.StartTime = fprints[i].StartTime; hs.EndTime = fprints[i].EndTime; hs.ChordId = fprints[i].ChordId; hshapes[i] = hs; } return(hshapes); }
private void AddNotes(RsSong rsSong, Song zigSong) { int spread = 3; var notes = new Dictionary<string, List<SongNote>>(); var chords = new Dictionary<string, List<SongChord>>(); var anchors = new Dictionary<string, List<SongAnchor>>(); var handShapes = new Dictionary<string, List<SongHandShape>>(); var chordTemps = new Dictionary<string, Tuple<int, SongChordTemplate>>(); var guitarTrack = GetTrack(zigSong); foreach (var group in guitarTrack.Chords.GroupBy(chord => chord.Difficulty)) { var gNotes = notes[group.Key] = new List<SongNote>(); var gChords = chords[group.Key] = new List<SongChord>(); var gAnchors = anchors[group.Key] = new List<SongAnchor>(); 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; SongAnchor curAnchor = null; for (int i = 0; i < zChords.Count; i++) { var zChord = zChords[i]; if (zChord.Notes.Count > 1) { Tuple<int, SongChordTemplate> 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 SongAnchor { Fret = Math.Min(19, minCFret), Time = zChord.StartTime }); } } else { if (minCFret + spread <= highFret) { curAnchor.Fret = minCFret; } gAnchors.Add(curAnchor); if (curAnchor.Fret != minCFret) { gAnchors.Add(new SongAnchor { Fret = Math.Min(19, minCFret), Time = zChord.StartTime }); } curAnchor = null; } } SongHandShape handShape = new SongHandShape { ChordId = val.Item1, StartTime = zChord.StartTime }; do { SongChord chord = new SongChord(); chord.Time = zChord.StartTime; chord.ChordId = val.Item1; 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 { var note = GetNote(zChord, i == zChords.Count - 1 ? null : zChords[i + 1]); if (note.Fret > 0) { if (curAnchor == null) { curAnchor = new SongAnchor { Fret = Math.Min(19, (int)note.Fret), Time = note.Time }; highFret = note.Fret; } else if (note.Fret < curAnchor.Fret) { if (note.Fret + spread >= highFret) { curAnchor.Fret = note.Fret; } else { gAnchors.Add(curAnchor); curAnchor = new SongAnchor { Fret = Math.Min(19, (int)note.Fret), Time = note.Time }; highFret = note.Fret; } } else if (note.Fret > highFret) { if (note.Fret - spread <= curAnchor.Fret) { highFret = note.Fret; } else { gAnchors.Add(curAnchor); curAnchor = new SongAnchor { Fret = Math.Min(19, (int)note.Fret), Time = note.Time }; highFret = note.Fret; } } } gNotes.Add(note); } } if (curAnchor != null) { gAnchors.Add(curAnchor); } } rsSong.Levels = new SongLevel[] { new SongLevel { Difficulty=0, Notes = notes["Easy"].ToArray() , Chords = chords["Easy"].ToArray() , Anchors = anchors["Easy"].ToArray() , HandShapes = handShapes["Easy"].ToArray() }, new SongLevel { Difficulty=1, Notes = notes["Medium"].ToArray() , Chords = chords["Medium"].ToArray() , Anchors = anchors["Medium"].ToArray() , HandShapes = handShapes["Medium"].ToArray() }, new SongLevel { Difficulty=2, Notes = notes["Hard"].ToArray(), Chords = chords["Hard"].ToArray(), Anchors = anchors["Hard"].ToArray() , HandShapes = handShapes["Hard"].ToArray() }, new SongLevel { 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(); }
// INCOMPLETE private static void WriteRocksmithSngLevelHandShapes(EndianBinaryWriter w, SongHandShape[] handShapes, Xml.SongLevel level, float songLength) { // sample section begins @ 328,356 in NumberThirteen_Combo.sng // sample section begins @ 4,300 in TCPowerChords_Lead.sng if (handShapes == null || handShapes.Length == 0) { w.Write(new byte[4]); // empty header return; } // output notes header count w.Write(handShapes.Length); // ouput handshapes for (int i = 0; i < handShapes.Length; i++) { SongHandShape handShape = handShapes[i]; // hand shape start time w.Write(handShape.StartTime); // hand shape end time w.Write(handShape.EndTime); // unknown w.Write(Convert.ToSingle(-1)); // unknown w.Write(Convert.ToSingle(-1)); // chord id w.Write(handShape.ChordId); // chord start time again ??? // Probably the first chord in the shape. w.Write(handShape.StartTime); var endTime = handShape.EndTime; //var endTime = i == handShapes.Length - 1 // ? songLength // : handShapes[i + 1].StartTime; // This should actually be the time of the last chord before the end time. float? lastChord = null; var chords = level.Chords == null ? null : level.Chords.Where(chord => chord.Time >= handShape.StartTime && chord.Time < endTime); var note = level.Notes == null ? null : level.Notes.FirstOrDefault(n => n.Time == endTime); if (note != null) { lastChord = endTime; } else if (chords != null && chords.Count() > 0) { lastChord = chords.Max(chord => chord.Time); } w.Write(lastChord ?? endTime); } }
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(); }
internal static SongHandShape[] Parse(Sng2014HSL.Arrangement arrangement) { var count = arrangement.Fingerprints1.Count + arrangement.Fingerprints2.Count; var fprints = new List<Sng2014HSL.Fingerprint>(); fprints.AddRange(arrangement.Fingerprints1.Fingerprints); fprints.AddRange(arrangement.Fingerprints2.Fingerprints); fprints = fprints.OrderBy(e => e.StartTime).ToList<Sng2014HSL.Fingerprint>(); var hshapes = new SongHandShape[count]; for (var i = 0; i < count; i++) { var hs = new SongHandShape(); hs.StartTime = fprints[i].StartTime; hs.EndTime = fprints[i].EndTime; hs.ChordId = fprints[i].ChordId; hshapes[i] = hs; } return hshapes; }