/// <summary> /// Handles and filters the incoming midi events. /// </summary> /// <param name="events">The midi events for the current cycle.</param> public void Process(VstEventCollection events) { foreach (VstEvent evnt in events) { if (evnt.EventType == VstEventTypes.MidiEvent) { VstMidiEvent midiEvent = (VstMidiEvent)evnt; //System.Diagnostics.Debug.WriteLine("Receiving Midi Event:" + midiEvent.MidiData[0], "VST.NET"); // pass note on and note off to the sample manager if ((midiEvent.Data[0] & 0xF0) == 0x80) { NoteOff?.Invoke(midiEvent.Data[1]); } if ((midiEvent.Data[0] & 0xF0) == 0x90) { // note on with velocity = 0 is a note off if (midiEvent.Data[2] == 0) { NoteOff?.Invoke(midiEvent.Data[1]); } else { NoteOn?.Invoke(midiEvent.Data[1]); } } } } }
private void Decode(byte[] message) { byte status = message[0]; switch (status & 0b1111_0000) { case Midi.Status.NoteOffBitmask: if (NoteOffMessage.TryDecode(message, out var noteOffMessage)) { NoteOff?.Invoke(this, in noteOffMessage); } break; case Midi.Status.NoteOnBitmask: if (NoteOnMessage.TryDecoce(message, out var noteOnMessage)) { NoteOn?.Invoke(this, in noteOnMessage); } break; case Midi.Status.PolyphonicKeyPressureBitmask: if (PolyphonicKeyPressureMessage.TryDecode(message, out var polyphonicKeyPressureMessage)) { PolyphonicKeyPressure?.Invoke(this, in polyphonicKeyPressureMessage); } break; case Midi.Status.ControlChangeBitmask: if (ControlChangeMessage.TryDecode(message, out var controlChangeMessage)) { _nrpnInterpreters[(int)controlChangeMessage.Channel].HandleControlChangeMessage(in controlChangeMessage); } break; case Midi.Status.ProgramChangeBitmask: if (ProgramChangeMessage.TryDecode(message, out var programChangeMessage)) { ProgramChange?.Invoke(this, in programChangeMessage); } break; case Midi.Status.ChannelPressureBitmask: if (ChannelPressureMessage.TryDecode(message, out var channelPressureMessage)) { ChannelPressure?.Invoke(this, in channelPressureMessage); } break; case Midi.Status.PitchBendChange: if (PitchBendMessage.TryDecode(message, out var pitchBendMessage)) { PitchBend?.Invoke(this, in pitchBendMessage); } break; default: Log.Error("Unknown message type {Bitmask}", $"{status & 0b1111_0000:X2}"); break; } }
private void lastKeyOff() { if (lastKeyOn >= 0) { NoteOffEvent noe = new NoteOffEvent((SevenBitNumber)lastKeyOn, (SevenBitNumber)127); NoteOff?.Invoke(this, noe); lastKeyOn = -1; } }
private void Update() { foreach (var key in virtualKeysDict.Keys) { if (Input.GetKeyDown(key)) { NoteOn?.Invoke(virtualKeysDict[key], 1f); } if (Input.GetKeyUp(key)) { NoteOff?.Invoke(virtualKeysDict[key]); } } }
/// <summary> /// Метод, вызывающий событие NoteOff с заданными параметрами. /// </summary> /// <param name="noteNo"></param> /// <param name="velocity"></param> private void OnNoteOff(byte noteNo, byte velocity) { NoteOff?.Invoke(this, new MidiNoteEventArgs(noteNo, velocity, pressedNotesCount)); }
private void Decode(byte[] message) { byte status = message[0]; switch (status & 0b1111_0000) { case Midi.Status.NoteOffBitmask: if (NoteOffMessage.TryDecode(message, out var noteOffMessage)) { NoteOff?.Invoke(this, in noteOffMessage); } break; case Midi.Status.NoteOnBitmask: if (NoteOnMessage.TryDecode(message, out var noteOnMessage)) { NoteOn?.Invoke(this, in noteOnMessage); } break; case Midi.Status.PolyphonicKeyPressureBitmask: if (PolyphonicKeyPressureMessage.TryDecode(message, out var polyphonicKeyPressureMessage)) { PolyphonicKeyPressure?.Invoke(this, in polyphonicKeyPressureMessage); } break; case Midi.Status.ControlChangeBitmask: if (ControlChangeMessage.TryDecode(message, out var controlChangeMessage)) { _nrpnInterpreters[(int)controlChangeMessage.Channel].HandleControlChangeMessage(in controlChangeMessage); } break; case Midi.Status.ProgramChangeBitmask: if (ProgramChangeMessage.TryDecode(message, out var programChangeMessage)) { ProgramChange?.Invoke(this, in programChangeMessage); } break; case Midi.Status.ChannelPressureBitmask: if (ChannelPressureMessage.TryDecode(message, out var channelPressureMessage)) { ChannelPressure?.Invoke(this, in channelPressureMessage); } break; case Midi.Status.PitchBendChange: if (PitchBendMessage.TryDecode(message, out var pitchBendMessage)) { PitchBend?.Invoke(this, in pitchBendMessage); } break; case Midi.Status.System: switch (status) { case Midi.Status.SysExStart: if (SysExMessage.TryDecode(message, out var sysExMessage)) { SysEx?.Invoke(this, in sysExMessage); } break; case Midi.Status.MidiTimeCodeQuarterFrame: if (MidiTimeCodeQuarterFrameMessage.TryDecode(message, out var timeCodeQuarterFrameMessage)) { MidiTimeCodeQuarterFrame?.Invoke(this, in timeCodeQuarterFrameMessage); } break; case Midi.Status.SongPositionPointer: if (SongPositionPointerMessage.TryDecode(message, out var songPositionPointerMessage)) { SongPositionPointer?.Invoke(this, in songPositionPointerMessage); } break; case Midi.Status.SongSelect: if (SongSelectMessage.TryDecode(message, out var songSelectMessage)) { SongSelect?.Invoke(this, in songSelectMessage); } break; case Midi.Status.TuneRequest: if (TuneRequestMessage.TryDecode(message, out var tuneRequestMessage)) { TuneRequest?.Invoke(this, in tuneRequestMessage); } break; default: Log.Error("Unknown system message type {Status}", $"{status:X2}"); break; } break; default: Log.Error("Unknown message type {Bitmask}", $"{status & 0b1111_0000:X2}"); break; } }
private void HandleNoteOff(int noteNumber) { currentNoteNumbers.Remove(noteNumber); NoteOff?.Invoke(noteNumber); }