int ExportOrFindNote(Note note) { var gpNote = new Gpif.Note(); gpNote.Id = gpif.Notes.Count; // add string and fret numbers gpNote.Properties.Add(new Property() { Name = "String", String = note.String }); gpNote.Properties.Add(new Property() { Name = "Fret", Fret = note.Fret }); // should we add muting? if (note.PalmMuted) gpNote.Properties.Add(new Property() { Name = "PalmMuted", Enable = new Property.EnableType() }); if (note.Muted) gpNote.Properties.Add(new Property() { Name = "Muted", Enable = new Property.EnableType() }); // handle ties with previous/next note if (link[note.String] || note.LinkNext) { gpNote.Tie = new Gpif.Note.TieType() { Destination = link[note.String], Origin = note.LinkNext && note.Slide != Note.SlideType.ToNext }; link[note.String] = note.LinkNext && note.Slide != Note.SlideType.ToNext; } // handle hammer-on / pull-off if (hopo[note.String]) { gpNote.Properties.Add(new Property() { Name = "HopoDestination", Enable = new Property.EnableType() }); hopo[note.String] = false; } if (note.Hopo) { gpNote.Properties.Add(new Property() { Name = "HopoOrigin", Enable = new Property.EnableType() }); hopo[note.String] = true; } if (note.Tapped) { gpNote.Properties.Add(new Property() { Name = "Tapped", Enable = new Property.EnableType() }); } // handle vibrato if (note.Vibrato) gpNote.Vibrato = "Slight"; // handle accent if (note.Accent) gpNote.Accent = 4; // handle harmonics if (note.Harmonic) { gpNote.Properties.Add(new Property() { Name = "HarmonicType", HType = "Natural" }); gpNote.Properties.Add(new Property() { Name = "HarmonicFret", HFret = note.Fret == 3 ? "3.2" : note.Fret.ToString() }); } else if (note.PinchHarmonic) { gpNote.Properties.Add(new Property() { Name = "HarmonicType", HType = "Pinch" }); gpNote.Properties.Add(new Property() { Name = "HarmonicFret", HFret = "12" }); } // handle slides int slideFlag = 0; switch (note.Slide) { case Note.SlideType.ToNext: slideFlag = 2; break; case Note.SlideType.UnpitchDown: slideFlag = 4; break; case Note.SlideType.UnpitchUp: slideFlag = 8; break; } if (slideFlag != 0) gpNote.Properties.Add(new Property() { Name = "Slide", Flags = slideFlag }); // handle bends if (note.BendValues.Count != 0) { float origin = note.BendValues.First().Step; float destination = note.BendValues.Last().Step; float middle = origin; float middleOffset1 = 0; float middleOffset2 = 0; float destinationOffset = note.BendValues.Last().RelativePosition; // GPX doesn't support arbitrarily complex bends, it can do at most a bend/release. // So we'll look for the point inside the bend that differs the most from the start // and use that as the intermediary bend value. for (int i = 1; i < note.BendValues.Count - 1; ++i) { var bend = note.BendValues[i]; if (bend.Step - origin > middle - origin) { middle = bend.Step; middleOffset1 = bend.RelativePosition; middleOffset2 = bend.RelativePosition; } else if (bend.Step == middle) middleOffset2 = bend.RelativePosition; if (bend.Step == destination) destinationOffset = bend.RelativePosition; else destinationOffset = note.BendValues.Last().RelativePosition; } // add the properties if (origin != 0 || middle != 0 || destination != 0) { // for some reason, some notes have nonsensical bend data attached, so ignore that gpNote.Properties.Add(new Property() { Name = "Bended", Enable = new Property.EnableType() }); gpNote.Properties.Add(new Property() { Name = "BendOriginValue", Float = Math.Round(origin * 50) }); // don't add the middle if it equals destination, GPX can't really handle that. if (middle != destination) { gpNote.Properties.Add(new Property() { Name = "BendMiddleValue", Float = Math.Round(middle * 50) }); gpNote.Properties.Add(new Property() { Name = "BendMiddleOffset1", Float = Math.Round(middleOffset1 * 100) }); gpNote.Properties.Add(new Property() { Name = "BendMiddleOffset2", Float = Math.Round(middleOffset2 * 100) }); } gpNote.Properties.Add(new Property() { Name = "BendDestinationValue", Float = Math.Round(destination * 50) }); gpNote.Properties.Add(new Property() { Name = "BendDestinationOffset", Float = Math.Round(destinationOffset * 100) }); } } // if available, place left hand fingering hint if (note.LeftFingering >= 0 && note.LeftFingering <= 4) { var fingerNames = new string[] { "P", "I", "M", "A", "C" }; gpNote.LeftFingering = fingerNames[note.LeftFingering]; } // see if this note already exists, otherwise add var searchNote = gpif.Notes.Find(x => x.Equals(gpNote)); if (searchNote != null) gpNote = searchNote; else gpif.Notes.Add(gpNote); return gpNote.Id; }
int ExportOrFindNote(Note note) { var gpNote = new Gpif.Note(); gpNote.Id = gpif.Notes.Count; // add string and fret numbers gpNote.Properties.Add(new Property() { Name = "String", String = note.String }); gpNote.Properties.Add(new Property() { Name = "Fret", Fret = note.Fret }); // should we add muting? if (note.PalmMuted) { gpNote.Properties.Add(new Property() { Name = "PalmMuted", Enable = new Property.EnableType() }); } if (note.Muted) { gpNote.Properties.Add(new Property() { Name = "Muted", Enable = new Property.EnableType() }); } // handle ties with previous/next note if (link[note.String] || note.LinkNext) { gpNote.Tie = new Gpif.Note.TieType() { Destination = link[note.String], Origin = note.LinkNext && note.Slide != Note.SlideType.ToNext }; link[note.String] = note.LinkNext && note.Slide != Note.SlideType.ToNext; } // handle hammer-on / pull-off if (hopo[note.String]) { gpNote.Properties.Add(new Property() { Name = "HopoDestination", Enable = new Property.EnableType() }); hopo[note.String] = false; } if (note.Hopo) { gpNote.Properties.Add(new Property() { Name = "HopoOrigin", Enable = new Property.EnableType() }); hopo[note.String] = true; } if (note.Tapped) { gpNote.Properties.Add(new Property() { Name = "Tapped", Enable = new Property.EnableType() }); } // handle vibrato if (note.Vibrato) { gpNote.Vibrato = "Slight"; } // handle accent if (note.Accent) { gpNote.Accent = 4; } // handle harmonics if (note.Harmonic) { gpNote.Properties.Add(new Property() { Name = "HarmonicType", HType = "Natural" }); gpNote.Properties.Add(new Property() { Name = "HarmonicFret", HFret = note.Fret == 3 ? "3.2" : note.Fret.ToString() }); } else if (note.PinchHarmonic) { gpNote.Properties.Add(new Property() { Name = "HarmonicType", HType = "Pinch" }); gpNote.Properties.Add(new Property() { Name = "HarmonicFret", HFret = "12" }); } // handle slides int slideFlag = 0; switch (note.Slide) { case Note.SlideType.ToNext: slideFlag = 2; break; case Note.SlideType.UnpitchDown: slideFlag = 4; break; case Note.SlideType.UnpitchUp: slideFlag = 8; break; } if (slideFlag != 0) { gpNote.Properties.Add(new Property() { Name = "Slide", Flags = slideFlag }); } // handle bends if (note.BendValues.Count != 0) { float origin = note.BendValues.First().Step; float destination = note.BendValues.Last().Step; float middle = origin; float middleOffset1 = 0; float middleOffset2 = 0; float destinationOffset = note.BendValues.Last().RelativePosition; // GPX doesn't support arbitrarily complex bends, it can do at most a bend/release. // So we'll look for the point inside the bend that differs the most from the start // and use that as the intermediary bend value. for (int i = 1; i < note.BendValues.Count - 1; ++i) { var bend = note.BendValues[i]; if (bend.Step - origin > middle - origin) { middle = bend.Step; middleOffset1 = bend.RelativePosition; middleOffset2 = bend.RelativePosition; } else if (bend.Step == middle) { middleOffset2 = bend.RelativePosition; } if (bend.Step == destination) { destinationOffset = bend.RelativePosition; } else { destinationOffset = note.BendValues.Last().RelativePosition; } } // add the properties if (origin != 0 || middle != 0 || destination != 0) { // for some reason, some notes have nonsensical bend data attached, so ignore that gpNote.Properties.Add(new Property() { Name = "Bended", Enable = new Property.EnableType() }); gpNote.Properties.Add(new Property() { Name = "BendOriginValue", Float = Math.Round(origin * 50) }); // don't add the middle if it equals destination, GPX can't really handle that. if (middle != destination) { gpNote.Properties.Add(new Property() { Name = "BendMiddleValue", Float = Math.Round(middle * 50) }); gpNote.Properties.Add(new Property() { Name = "BendMiddleOffset1", Float = Math.Round(middleOffset1 * 100) }); gpNote.Properties.Add(new Property() { Name = "BendMiddleOffset2", Float = Math.Round(middleOffset2 * 100) }); } gpNote.Properties.Add(new Property() { Name = "BendDestinationValue", Float = Math.Round(destination * 50) }); gpNote.Properties.Add(new Property() { Name = "BendDestinationOffset", Float = Math.Round(destinationOffset * 100) }); } } // if available, place left hand fingering hint if (note.LeftFingering >= 0 && note.LeftFingering <= 4) { var fingerNames = new string[] { "P", "I", "M", "A", "C" }; gpNote.LeftFingering = fingerNames[note.LeftFingering]; } // see if this note already exists, otherwise add var searchNote = gpif.Notes.Find(x => x.Equals(gpNote)); if (searchNote != null) { gpNote = searchNote; } else { gpif.Notes.Add(gpNote); } return(gpNote.Id); }