private static IEnumerable <PlaybackEvent> GetPlaybackEvents(Note note, TempoMap tempoMap) { TimeSpan noteStartTime = note.TimeAs <MetricTimeSpan>(tempoMap); TimeSpan noteEndTime = TimeConverter.ConvertTo <MetricTimeSpan>(note.Time + note.Length, tempoMap); var noteMetadata = new NotePlaybackEventMetadata(note, noteStartTime, noteEndTime); yield return(GetPlaybackEventWithNoteMetadata(note.TimedNoteOnEvent, tempoMap, noteMetadata)); yield return(GetPlaybackEventWithNoteMetadata(note.TimedNoteOffEvent, tempoMap, noteMetadata)); }
private static PlaybackEvent GetPlaybackEventWithNoteMetadata(TimedEvent timedEvent, TempoMap tempoMap, NotePlaybackEventMetadata noteMetadata) { var playbackEvent = new PlaybackEvent(timedEvent.Event, timedEvent.TimeAs <MetricTimeSpan>(tempoMap), timedEvent.Time); playbackEvent.Metadata.Note = noteMetadata; return(playbackEvent); }
private bool TryPlayNoteEvent(NotePlaybackEventMetadata noteMetadata, MidiEvent midiEvent, bool isNoteOnEvent, TimeSpan time, out Note note) { note = null; if (noteMetadata == null) { return(false); } var notePlaybackData = noteMetadata.NotePlaybackData; var noteCallback = NoteCallback; if (noteCallback != null && midiEvent is NoteOnEvent) { notePlaybackData = noteCallback(noteMetadata.RawNotePlaybackData, noteMetadata.RawNote.Time, noteMetadata.RawNote.Length, time); noteMetadata.SetCustomNotePlaybackData(notePlaybackData); } note = noteMetadata.RawNote; if (noteMetadata.IsCustomNotePlaybackDataSet) { if (notePlaybackData == null || !notePlaybackData.PlayNote) { midiEvent = null; } else { note = noteMetadata.GetEffectiveNote(); midiEvent = midiEvent is NoteOnEvent ? (MidiEvent)notePlaybackData.GetNoteOnEvent() : notePlaybackData.GetNoteOffEvent(); } } else if (midiEvent == null) { midiEvent = isNoteOnEvent ? (MidiEvent)notePlaybackData.GetNoteOnEvent() : notePlaybackData.GetNoteOffEvent(); } if (midiEvent != null) { SendEvent(midiEvent); if (midiEvent is NoteOnEvent) { _activeNotesMetadata.Add(noteMetadata); } else { _activeNotesMetadata.Remove(noteMetadata); } } else { note = null; } return(true); }
private bool TryPlayNoteEvent(NotePlaybackEventMetadata noteMetadata, bool isNoteOnEvent, TimeSpan time, out Note note) { return(TryPlayNoteEvent(noteMetadata, null, isNoteOnEvent, time, out note)); }