public static StringToBytes ( string OutputBytesString, byte channel, byte velocity ) : byte[] | ||
OutputBytesString | string | |
channel | byte | |
velocity | byte | |
return | byte[] |
private void MapNoteDetailsUI_FormClosing(object sender, FormClosingEventArgs e) { if (this.DialogResult == DialogResult.OK) { FormToEntity(); // Parse the strings with dummy substitution values to verify they're OK. Don't use 0 as it may mask weird input ('NN33', for example) try { MapNoteItem.StringToBytes(MIDIBytesOnTxt.Text, 15, 255); } catch // All, assume parsing errors { this.MIDIBytesOnTxt.BackColor = System.Drawing.Color.Yellow; e.Cancel = true; } try { MapNoteItem.StringToBytes(MIDIBytesOffTxt.Text, 15, 255); } catch // All, assume parsing errors { this.MIDIBytesOffTxt.BackColor = System.Drawing.Color.Yellow; e.Cancel = true; } } }
// Process the incoming VST events. This is the core of the app right here. !!!! public void Process(VstEventCollection inputEvents) { _plugin.callCount++; foreach (VstEvent evnt in inputEvents) { _plugin.eventCount++; // Skip non-MIDI Events if (evnt.EventType != VstEventTypes.MidiEvent) { continue; } _plugin.midiCount++; VstMidiEvent midiInputEvent = (VstMidiEvent)evnt; // Filter out everything except Note On/Note Off events byte midiCommand = (byte)(midiInputEvent.Data[0] & 0xF0); if ((midiCommand == 0x90) || (midiCommand == 0x80)) { byte triggerNoteNum = midiInputEvent.Data[1]; if (_plugin.NoteMap.Contains(triggerNoteNum)) { _plugin.hitCount++; byte channel = (byte)(midiInputEvent.Data[0] & 0x0F); byte velocity = midiInputEvent.Data[2]; MapNoteItem item = _plugin.NoteMap[triggerNoteNum]; byte[] midiData = null; if (midiCommand == 0x90) { midiData = MapNoteItem.StringToBytes(item.OutputBytesStringOn, channel, velocity); } else if (midiCommand == 0x80) { midiData = MapNoteItem.StringToBytes(item.OutputBytesStringOff, channel, velocity); } // else midiData remains null, which should never happen // If OutputBytes was empty, ignore this event. Could try sending the event with an empty array (not null) - not sure what would happen. if (midiData == null) { continue; } // Trick: Use VstMidiSysExEvent in place of VstMidiEvent, since this seems to allow arbitary bytes. VstMidiSysExEvent mappedEvent = new VstMidiSysExEvent(midiInputEvent.DeltaFrames, midiData); Events.Add(mappedEvent); } else if (_plugin.midiThru) { // add original event Events.Add(evnt); } // Otherwise ignore silently } } }