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; } } }
// "Delete" Button private void DeleteBtn_Click(object sender, EventArgs e) { // Exit if nothing selected if (MapListVw.SelectedItems.Count == 0) { return; } byte oldTriggerNoteNum = Byte.Parse(MapListVw.SelectedItems[0].Name); // .Name was filled in by FillList if (_plugin.NoteMap.Contains(oldTriggerNoteNum)) { MapNoteItem item = _plugin.NoteMap[oldTriggerNoteNum]; if (MessageBox.Show(this, String.Format("Are you sure you want to delete {0} ({1})?", item.KeyName, item.TriggerNoteNumber), "Delete a Note Map Item.", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { _plugin.NoteMap.Remove(oldTriggerNoteNum); FillList(); } } else { MessageBox.Show("(Delete) Logic Error: triggerNoteNum=" + oldTriggerNoteNum + " is in table but not found in list."); } }
// "Add" Button private void AddBtn_Click(object sender, EventArgs e) { MapNoteItem newMapNoteItem = new MapNoteItem() { KeyName = "New Note Map", TriggerNoteNumber = 60, // C4 OutputBytesStringOn = "", OutputBytesStringOff = "" }; bool complete = false; while (!complete) { MapNoteDetailsUI dlg = new MapNoteDetailsUI(newMapNoteItem); if (dlg.ShowDialog(this) == DialogResult.OK) { // Check if the NoteMap already exists, and prompt for replacement if (_plugin.NoteMap.Contains(dlg.TempMapNoteItem.TriggerNoteNumber)) { if (MessageBox.Show(this, String.Format("A mapping with Note# {0} already exists. Replace?", dlg.TempMapNoteItem.TriggerNoteNumber), "Add a Note Map Item.", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { // Remove the old entry Could use the ChangeItemKey Method here, but let's start simple. _plugin.NoteMap.Remove(dlg.TempMapNoteItem.TriggerNoteNumber); } else { newMapNoteItem = dlg.TempMapNoteItem; // This is a bit wonky, but persists the note item for the next iteration. continue; // Show the dialog again } } // if // Add new entry _plugin.NoteMap.Add(dlg.TempMapNoteItem); complete = true; // Successfully added } else { complete = true; // Successfully cancelled } } // while FillList(); }
public void ReadPrograms(Stream stream, VstProgramCollection programs) { BinaryReader reader = new BinaryReader(stream, _encoding); _plugin.NoteMap.Clear(); int count = reader.ReadInt32(); for (int n = 0; n < count; n++) { MapNoteItem item = new MapNoteItem(); item.KeyName = reader.ReadString(); item.TriggerNoteNumber = reader.ReadByte(); item.OutputBytesStringOn = reader.ReadString(); item.OutputBytesStringOff = reader.ReadString(); _plugin.NoteMap.Add(item); } _plugin.midiThru = reader.ReadBoolean(); _plugin.presetsLoaded = true; }
// Works! private void ReadOldPreset(BinaryReader reader) { _plugin.ResetMaps(); reader.BaseStream.Position = 0; reader.BaseStream.Seek(0, SeekOrigin.Begin); int count = reader.ReadInt32(); for (int n = 0; n < count; n++) { MapNoteItem item = new MapNoteItem(); item.KeyName = reader.ReadString(); int trigger = reader.ReadByte(); item.OutputBytesStringOn = reader.ReadString(); item.OutputBytesStringOff = reader.ReadString(); _plugin.NoteMaps[trigger] = item; } try // In case the preset was written with an older version that didn't have all these options yet. { _plugin.Options.MidiThru = reader.ReadBoolean(); _plugin.Options.MidiThruAll = reader.ReadBoolean(); _plugin.Options.AlwaysSysEx = reader.ReadBoolean(); } catch // all, i.e. (System.IO.EndOfStreamException e) { // Note: This catch block never seems to be reached, investigate (Low priority) ; } _plugin.olderpresetswarning = true; _plugin.presetsLoaded = true; }
/// <summary> /// Constructs a new instance. /// </summary> public MapNoteDetailsUI(MapNoteItem myMapNoteitem) { TempMapNoteItem = myMapNoteitem; InitializeComponent(); }
// 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 } } }
// "Edit" Button private void EditBtn_Click(object sender, EventArgs e) { // Exit if nothing selected if (MapListVw.SelectedItems.Count == 0) { return; } byte oldTriggerNoteNum = Byte.Parse(MapListVw.SelectedItems[0].Name); // .Name was filled in by FillList if (_plugin.NoteMap.Contains(oldTriggerNoteNum)) { MapNoteItem tempItem = new MapNoteItem { KeyName = _plugin.NoteMap[oldTriggerNoteNum].KeyName, TriggerNoteNumber = oldTriggerNoteNum, OutputBytesStringOn = _plugin.NoteMap[oldTriggerNoteNum].OutputBytesStringOn, OutputBytesStringOff = _plugin.NoteMap[oldTriggerNoteNum].OutputBytesStringOff }; MapNoteDetailsUI dlg = new MapNoteDetailsUI(tempItem); bool complete = false; while (!complete) { if (dlg.ShowDialog(this) == DialogResult.OK) { // Check if the NoteMap changed, but already exists in the list if ((dlg.TempMapNoteItem.TriggerNoteNumber != oldTriggerNoteNum) && (_plugin.NoteMap.Contains(dlg.TempMapNoteItem.TriggerNoteNumber))) { MessageBox.Show(this, String.Format("A mapping with Note# {0} already exists.", dlg.TempMapNoteItem.TriggerNoteNumber), "Edit a Note Map Item."); continue; // Show dialog again } // Remove the old entry Could use the ChangeItemKey Method here, but let's keep it simple. if (_plugin.NoteMap.Remove(oldTriggerNoteNum)) { // Add new entry _plugin.NoteMap.Add(dlg.TempMapNoteItem); complete = true; // Successfully replaced } else { MessageBox.Show("(Edit) Logic Error: Remove Failed! oldTriggerNoteNum=" + oldTriggerNoteNum); break; } } else { complete = true; // Successfully cancelled } } // while FillList(); } else { MessageBox.Show("(Edit) Logic Error: oldTriggerNoteNum=" + oldTriggerNoteNum + " is in table but was not found in list."); } }
public void ResetMaps() { NoteMaps = new MapNoteItem[Constants.MAXNOTES]; for (int note = 0; note < NoteMaps.Length; note++) { NoteMaps[note] = new MapNoteItem(); NoteMaps[note].KeyName = "Undefined Map " + note; } }
// "Edit" Button private void EditBtn_Click(object sender, EventArgs e) { // Exit if nothing selected if (MapListVw.SelectedItems.Count == 0) return; byte oldTriggerNoteNum = Byte.Parse(MapListVw.SelectedItems[0].Name); // .Name was filled in by FillList if (_plugin.NoteMap.Contains(oldTriggerNoteNum)) { MapNoteItem tempItem = new MapNoteItem { KeyName = _plugin.NoteMap[oldTriggerNoteNum].KeyName, TriggerNoteNumber = oldTriggerNoteNum, OutputBytesStringOn = _plugin.NoteMap[oldTriggerNoteNum].OutputBytesStringOn, OutputBytesStringOff = _plugin.NoteMap[oldTriggerNoteNum].OutputBytesStringOff }; MapNoteDetailsUI dlg = new MapNoteDetailsUI(tempItem); bool complete = false; while (!complete) { if (dlg.ShowDialog(this) == DialogResult.OK) { // Check if the NoteMap changed, but already exists in the list if ( (dlg.TempMapNoteItem.TriggerNoteNumber != oldTriggerNoteNum) && (_plugin.NoteMap.Contains(dlg.TempMapNoteItem.TriggerNoteNumber)) ) { MessageBox.Show(this, String.Format("A mapping with Note# {0} already exists.", dlg.TempMapNoteItem.TriggerNoteNumber), "Edit a Note Map Item."); continue; // Show dialog again } // Remove the old entry Could use the ChangeItemKey Method here, but let's keep it simple. if (_plugin.NoteMap.Remove(oldTriggerNoteNum)) { // Add new entry _plugin.NoteMap.Add(dlg.TempMapNoteItem); complete = true; // Successfully replaced } else { MessageBox.Show("(Edit) Logic Error: Remove Failed! oldTriggerNoteNum=" + oldTriggerNoteNum); break; } } else { complete = true; // Successfully cancelled } } // while FillList(); } else { MessageBox.Show("(Edit) Logic Error: oldTriggerNoteNum=" + oldTriggerNoteNum + " is in table but was not found in list."); } }