public static SongNote ConvertXmlNoteToSongNote(double noteTime, Note xmlNote) { var songNote = new SongNote(); songNote.NoteTime = noteTime; songNote.PitchId = (xmlNote.Pitch.Octave + 1) * 12 + XmlMusicHelper.GetMidiIdOffsetFromC(xmlNote); songNote.Velocity = 100; songNote.Duration = xmlNote.Duration; return songNote; }
public static int GetMidiIdOffsetFromC(Note note) { switch (note.Pitch.Step) { case 'C': return 0; case 'D': return 2; case 'E': return 4; case 'F': return 5; case 'G': return 7; case 'A': return 9; case 'B': return 11; default: throw new ArgumentException("Note Step not parsable/not acceptable value : " + note); } }
public static void ExtendSongNote(double noteTime, Song song, Note xmlNote, double duration) { int pitchId = GetPitchIdFromNote(xmlNote); //searching the list backwards will be faster.. //I'm sure there's nice linq for this, but hey.. foreach (double itemNoteTime in song.Keys.Reverse()) { foreach(var note in song[itemNoteTime].KeyPresses) { if (note.PitchId == pitchId) { note.Duration += duration; return; } } } }
public static void AddSongNoteToSong(double noteTime, Song song, Note xmlNote, double duration) { var songNote = new SongNote(); songNote.NoteTime = noteTime; songNote.PitchId = GetPitchIdFromNote(xmlNote); songNote.Velocity = 100; songNote.Duration = duration; SongNoteEventCollections noteEventCollections; if (!song.TryGetValue(noteTime, out noteEventCollections)) { noteEventCollections = new SongNoteEventCollections(); song.Add(noteTime, noteEventCollections); }; noteEventCollections.KeyPresses.Add(songNote); }
public void AddNote(Note note, Timing timing, double devisions, double noteTime, double yCoord, double defaultNoteSize) { Type glyphType = typeof(BlackNoteHeadGlyph); double finalYCoord = yCoord; double defaultNoteWidth = 20.0; if (note.IsRest) { switch (note.Type) { case "128th": glyphType = typeof(Rest128thGlyph); break; case "64th": glyphType = typeof(Rest64thGlyph); break; case "32nd": glyphType = typeof(Rest32ndGlyph); break; case "16th": glyphType = typeof(Rest16thGlyph); break; case "eigth": glyphType = typeof(RestEighthGlyph); break; case "quarter": glyphType = typeof(RestQuarterGlyph); break; case "half": glyphType = typeof(RestHalfGlyph); defaultNoteWidth = defaultNoteWidth * 2; break; case "whole": glyphType = typeof(RestWholeGlyph); defaultNoteWidth = defaultNoteWidth * 4; break; case "": glyphType = CalculateRestType(note.Duration, timing, devisions); break; } finalYCoord = GetRestYCoord(glyphType); } else { switch (note.Type) { case "half": glyphType = typeof(HalfNoteGlyph); break; case "whole": glyphType = typeof(WholeNoteGlyph); break; case "breve": break; case "long": break; case "": break; } } if (note.Stem != "") { Line line = new Line(); line.StrokeThickness = 1.2; line.Stroke = Brushes.Black; double stemHeight = defaultNoteSize * 3.0; switch(note.Stem) { case "down": line.Y1 = 0.1; line.Y2 = stemHeight; line.X1 = 0.1; line.X2 = 0.1; break; case "up": line.Y1 = - 0.1; line.Y2 = - stemHeight; line.X1 = defaultNoteSize - 0.1; line.X2 = defaultNoteSize - 0.1; break; } _renderHelper.AddItemToRender(noteTime, line, finalYCoord, 0, RenderItemType.NoteStem); } TextBlock tb = _renderHelper.Glyphs.GetGlyph(glyphType, defaultNoteSize * 3.3); _renderHelper.AddItemToRender(noteTime, tb, finalYCoord - tb.BaselineOffset, 20.0, RenderItemType.Note); }
private int GetNoteOffsetFromC(Note note) { switch (note.Pitch.Step) { case 'C': return 0; case 'D': return 1; case 'E': return 2; case 'F': return 3; case 'G': return 4; case 'A': return 5; case 'B': return 6; default: throw new ArgumentException("Note Step not parsable/not acceptable value : " + note); } }
private double CalculateYForRest(Note note) { return LowestLine_Y + LineSpacing * 2.0; }
private double CalculateYForNote(Note note) { if (note.IsRest) return CalculateYForRest(note); double middleC_Y; switch (ClefType) { case ClefTypes.StandardTrebble : middleC_Y = LowestLine_Y + LineSpacing; break; case ClefTypes.StandardBass : middleC_Y = HighestLine_Y - LineSpacing; break; default: middleC_Y = LowestLine_Y + LineSpacing; break; } int octaveOffsetFromMiddleC = note.Pitch.Octave - 4; //Octave 4 starts at middle C return middleC_Y - (octaveOffsetFromMiddleC * 7.0 + GetNoteOffsetFromC(note)) * ScoreLayoutDetails.OffsetPerNote_Y; }
public void AddNote(Note note, double devisions, double noteTime) { _noteRenderHelper.AddNote(note, Timing, devisions, noteTime, CalculateYForNote(note), LineSpacing); }
public static int GetPitchIdFromNote(Note note) { return (note.Pitch.Octave + 1) * 12 + XmlMusicHelper.GetMidiIdOffsetFromC(note) + note.Pitch.Alter; }
private Staff GetStaffFromNote(List<Staff> staffs, Note note) { int staffId = note.Staff; if (staffId > 0 && staffId <= staffs.Count) return staffs[staffId-1]; return null; }
public NoteAlterationType GetAlteration(Note note) { if (note.Pitch == null) return NoteAlterationType.Natural; var proposedNoteAlteration = Alterations.IntToAlteration(note.Pitch.Alter); var naturalKeyAlteration = Alterations.CreateFromFifths(_currentKey.Fifths).ForNote(note.Pitch.Step); var currentKeyAlteration = _alterations.ForNote(note.Pitch.Step); //Do nothing if natural if (currentKeyAlteration == proposedNoteAlteration) return NoteAlterationType.Natural; NoteAlterationType newAlterationType = NoteAlterationType.Natural; switch (note.Pitch.Alter - Alterations.AlterationToInt(currentKeyAlteration)) { case -2: newAlterationType = NoteAlterationType.DoubleFlat; break; case -1: newAlterationType = NoteAlterationType.Flat; break; case 0: newAlterationType = NoteAlterationType.Natural; break; case 1: newAlterationType = NoteAlterationType.Sharp; break; case 2: newAlterationType = NoteAlterationType.DoubleSharp; break; } if (note.Pitch.Alter == 0) newAlterationType = NoteAlterationType.Natural; _alterations.SetAlteration(note.Pitch.Step, newAlterationType); if (note.Pitch.Alter == 0) return NoteAlterationType.Neutral; return newAlterationType; }