// Updates the UI with the NoteOnEvents public void ProcessIdle() { if (NoteOnNumbers.Count > 0) { byte noteNo; lock (_notesOn) { noteNo = NoteOnNumbers.Dequeue(); _notesOn.Add(noteNo); } displayNotes(); } if (NoteOffNumbers.Count > 0) { byte noteNo; lock (_notesOn) { noteNo = NoteOffNumbers.Dequeue(); _notesOn.RemoveAll(n => n.Equals(noteNo)); } displayNotes(); } }
public void Process(VstEventCollection events) { foreach (VstEvent evnt in events) { if (evnt.EventType != VstEventTypes.MidiEvent) { continue; } VstMidiEvent midiEvent = (VstMidiEvent)evnt; // note on if ((midiEvent.Data[0] & 0xF0) == 0x90) { // note off // You can treat note-on midi events with a velocity of 0 (zero) as a note-off midi event. if (midiEvent.Data[2] == 0) { lock (((ICollection)NoteOffNumbers).SyncRoot) { lock (((ICollection)_noteOnEvents).SyncRoot) { lock (((ICollection)_octavesAddedOrderedNoteOnEvents).SyncRoot) { NoteOffNumbers.Enqueue(midiEvent.Data[1]); _noteOnEvents.RemoveAll(n => n.Data[1] == midiEvent.Data[1]); AddOctaves(); OrderNoteOnEventsWithOctaves(); } } } } // note on else { lock (((ICollection)NoteOnNumbers).SyncRoot) { lock (((ICollection)_noteOnEvents).SyncRoot) { lock (((ICollection)_octavesAddedOrderedNoteOnEvents).SyncRoot) { NoteOnNumbers.Enqueue(midiEvent.Data[1]); _noteOnEvents.Add(midiEvent); AddOctaves(); OrderNoteOnEventsWithOctaves(); } } } } } // note off else if ((midiEvent.Data[0] & 0xF0) == 0x80) { lock (((ICollection)NoteOffNumbers).SyncRoot) { lock (((ICollection)_noteOnEvents).SyncRoot) { lock (((ICollection)_octavesAddedOrderedNoteOnEvents).SyncRoot) { NoteOffNumbers.Enqueue(midiEvent.Data[1]); /* FOR TESTING ADDOCTAVES() * string notes = ""; * foreach (VstMidiEvent e in _noteOnEvents) * notes += e.Data[1] + " "; * * MessageBox.Show("Process method: \nNoteOnEvents: " + notes); */ _noteOnEvents.RemoveAll(n => n.Data[1] == midiEvent.Data[1]); AddOctaves(); OrderNoteOnEventsWithOctaves(); } } } } } }