// Every button on the button grid uses this as its click handler. private void btnProgramChange_Click(object sender, EventArgs e) { // Get the patchNo from within the button that was clicked MidiProgram midiProgram = (MidiProgram)(((Button)sender).Tag); // And switch to it. if (midiProgram != null && midiProgram.myPatchNumber >= 0) { // Override the default intput device in the mapping to be the on for this tab LogicalInputDevice deviceForThisMidiProgram = mapper.configuration.primaryInputDevice; if (tabControl1.SelectedTab.Tag != null && tabControl1.SelectedTab.Tag is LogicalInputDevice) { deviceForThisMidiProgram = (LogicalInputDevice)tabControl1.SelectedTab.Tag; } // Rebind it to make the device override take effect midiProgram.bind(mapper.configuration.logicalInputDeviceDict, mapper.configuration.soundGenerators, mapper.configuration.mappings, deviceForThisMidiProgram); // Fire the program change mapper.ProgramChange((midiProgram.myBankNumber * 128) + midiProgram.myPatchNumber); mapper.masterTranspose = 0; } // Select (only) this button unselectAllRandomAccessButtons(); ((Button)sender).BackColor = SystemColors.Highlight; }
public void changeMasterVol(int vol) { LogicalInputDevice logicalInputDevice = configuration.logicalInputDeviceDict[configuration.volSliderInputDeviceName]; if (logicalInputDevice != null) { ControlChange(logicalInputDevice.device, configuration.volSliderMidiChannel, configuration.volSliderControlNum, vol); // Ctl 75 is assigned in the } }
private void Form1_Random_Access_Load(object sender, EventArgs e) { // Populate the 8x8 button matrix with buttons to access the MidiPrograms defined. Each gets a button in th 8x8 grid based on its midi program number. // I'm not dealing in banks yet, but imagine having multiple banks of 8x8 selected by a bank select command. refreshRandomAccessButtonGrid(); // If there's at least one setlist define, make the first one the current one. if (mapper.configuration.setlists.Count > 0) { currentSetlist = mapper.configuration.setlists[0]; } // Initialize patch TreeViews and set to SG (Sound Generator) organization by "clicking" the "SG" button. btnPatchTreeViewBySG_Click(null, null); btnMappingEditPatchTreeViewBySG_Click(null, null); // Initialize the Input Device dropdown on the RandomAccess (and Misc) pages. foreach (String sourceDeviceLogicalName in mapper.configuration.logicalInputDeviceDict.Keys) { LogicalInputDevice logicalInputDevice = mapper.configuration.logicalInputDeviceDict[sourceDeviceLogicalName]; if (logicalInputDevice.device != null) { cbRandomAccessInputDevice.Items.Add(logicalInputDevice.logicalDeviceName); lbInputDevices.Items.Add(logicalInputDevice.logicalDeviceName + " -> " + logicalInputDevice.device.Name); } } // Assocaite each Random Access Tab Page with the Logical Input Device it's been configured to manage foreach (TabPage tabPage in tabControl1.TabPages) { if (tabPage.Text.StartsWith("Random Access")) { if (mapper.configuration.randomAccessTabInputDeviceNames.ContainsKey(tabPage.Text)) { String inputDeviceName = mapper.configuration.randomAccessTabInputDeviceNames[tabPage.Text]; if (mapper.configuration.logicalInputDeviceDict.ContainsKey(inputDeviceName)) { tabPage.Tag = mapper.configuration.logicalInputDeviceDict[mapper.configuration.randomAccessTabInputDeviceNames[tabPage.Text]]; } else { tabPage.Tag = mapper.configuration.primaryInputDevice; } } else { tabPage.Tag = mapper.configuration.primaryInputDevice; } } } // Select the current tab's Logical Input Device in its Input Device selector if (tabControl1.SelectedTab.Tag != null && tabControl1.SelectedTab.Tag is LogicalInputDevice) { cbRandomAccessInputDevice.Text = ((LogicalInputDevice)tabControl1.SelectedTab.Tag).logicalDeviceName; } }
public static void createTrialConfiguration(Dictionary <String, LogicalInputDevice> logicalInputDeviceDict) { logicalInputDeviceDict.Clear(); LogicalInputDevice logicalInputDevice = new LogicalInputDevice(); logicalInputDevice.logicalInputDeviceNumber = 1; logicalInputDevice.logicalDeviceName = "Input Device 1"; logicalInputDevice.physicalDevicePreferenceList.Add("Oxygen 61"); logicalInputDevice.physicalDevicePreferenceList.Add("In From MIDI Yoke: 1"); logicalInputDeviceDict.Add(logicalInputDevice.logicalDeviceName, logicalInputDevice); }
public void createTrialConfiguration() { dirty = true; try { Mapping.PerDeviceChannelMapping globalPerInputDeviceChannelMapping = new Mapping.PerDeviceChannelMapping(); globalPerInputDeviceChannelMapping.logicalInputDeviceName = "Input Device 1"; globalPerInputDeviceChannelMapping.inputDeviceChannel = 0; ControlMapping globalControlMapping = new ControlMapping(); globalControlMapping.soundGeneratorName = "Reaper"; globalControlMapping.soundGeneratorRelativeChannel = 0; globalControlMapping.sourceControlNumber = 75; // Top Left Rotary Knob on Oxygen globalControlMapping.mappedControlNumber = 9; // I've got Reaper Master Volume mapped to this. globalControlMapping.min = 30; // This provides a nice workable vol range globalControlMapping.max = 91; globalPerInputDeviceChannelMapping.controlMappings.Add(globalControlMapping); globalControlMappings.Add(globalPerInputDeviceChannelMapping); primaryInputDeviceName = "Input Device 1"; LogicalInputDevice.createTrialConfiguration(logicalInputDeviceDict); LogicalOutputDevice.createTrialConfiguration(logicalOutputDeviceDict); SoundGenerator.createTrialConfiguration(soundGenerators); Mapping.createTrialConfiguration(mappings); MidiProgram.createTrialConfiguration(midiPrograms); Setlist.createTrialConfiguration(songDict, setlists); } catch (Exception e) { MessageBox.Show("Exception creating trial configurations: " + e); } }
private void enableUiDeviceLabelsForFirstTwoInputDevices() { lblMappingInputDevice1.Text = mapper.configuration.primaryInputDeviceName; // Only make InputDevice2 mapping def fields visible if we find a second InputDevices configured (ie, with logicalInputDeviceNumber == 2) if (mapper.configuration.logicalInputDeviceDict.Count > 1) { LogicalInputDevice secondaryInputDevice = null; // Look for logicalInputDevice with number == 2 foreach (LogicalInputDevice inputDevice in mapper.configuration.logicalInputDeviceDict.Values) { if (inputDevice.logicalInputDeviceNumber == 2) { secondaryInputDevice = inputDevice; break; } } if (secondaryInputDevice != null) { // Found it. Enable UI elements for it lblMappingInputDevice2.Text = secondaryInputDevice.logicalDeviceName; lblMappingInputDevice2.Visible = true; cbMappingSplitDevice2.Visible = true; } else { // Not found. We probably should use whatever non-primary one we find, but for now we're hiding InputDevice2 mapping. lblMappingInputDevice2.Visible = false; cbMappingSplitDevice2.Visible = false; } } else { // Only one InputDevice. Hide all InputDevice2 mapping def fields lblMappingInputDevice2.Visible = false; cbMappingSplitDevice2.Visible = false; } }
//-------------------------------------------------------------------------------- // When you click on a program in the Programs treeview that program is activated. //-------------------------------------------------------------------------------- private void tvProgramPatches_Click(object sender, EventArgs e) { TreeNode node = tvProgramPatches.SelectedNode; if (node != null) { if (node.Tag is SoundGenerator) { // Route out to this SG, but send no program change... // Allows user to select an SG and then set sound directly from it. Useful during configuration. } else if (node.Tag is SoundGeneratorPatch) { // Create an MidiProgram that won't be assigned to any buttons. Use it to formulate a Mapping and make that the current Mapping. SoundGeneratorPatch soundGeneratorPatch = (SoundGeneratorPatch)node.Tag; MidiProgram midiProgram = new MidiProgram(); midiProgram.bSingle = true; midiProgram.SingleSoundGeneratorName = soundGeneratorPatch.soundGenerator.name; midiProgram.SinglePatchName = soundGeneratorPatch.name; // Determine the input device for this midiProgram: the tab's currently selected input device LogicalInputDevice deviceForThisMidiProgram = mapper.configuration.primaryInputDevice; if (tabControl1.SelectedTab.Tag != null && tabControl1.SelectedTab.Tag is LogicalInputDevice) { deviceForThisMidiProgram = (LogicalInputDevice)tabControl1.SelectedTab.Tag; } // Have the midiProgram flesh out its inner details midiProgram.bind(mapper.configuration.logicalInputDeviceDict, mapper.configuration.soundGenerators, mapper.configuration.mappings, deviceForThisMidiProgram); mapper.SetMapping(midiProgram.mapping); } else if (node.Tag is Mapping) { Mapping mapping = (Mapping)node.Tag; mapper.SetMapping(mapping); } } }
public void bind(Dictionary <String, LogicalInputDevice> logicalInputDeviceDict, Dictionary <String, SoundGenerator> soundGenerators, Dictionary <String, Mapping> mappings, LogicalInputDevice primaryInputDevice) { foreach (SongProgram songProgram in programs) { songProgram.bind(logicalInputDeviceDict, soundGenerators, mappings, primaryInputDevice); } }
public bool bind() { foreach (String key in logicalInputDeviceDict.Keys) { LogicalInputDevice device = logicalInputDeviceDict[key]; if (device.bind() == false) { return(false); } } // Resolve the Primary Input Device. (If non defined, pick the first on in the dict.) if (primaryInputDeviceName == null && logicalInputDeviceDict.Count > 0) { primaryInputDeviceName = logicalInputDeviceDict.Keys.First <String>(); dirty = true; } if (logicalInputDeviceDict.ContainsKey(primaryInputDeviceName)) { primaryInputDevice = logicalInputDeviceDict[primaryInputDeviceName]; } else { MessageBox.Show("Cannot find primary logical input device by configured name " + primaryInputDeviceName); return(false); } foreach (String key in logicalOutputDeviceDict.Keys) { LogicalOutputDevice device = logicalOutputDeviceDict[key]; if (device.bind() == false) { return(false); } } foreach (String key in soundGenerators.Keys) { SoundGenerator soundGenerator = soundGenerators[key]; if (soundGenerator.bind(logicalOutputDeviceDict) == false) { return(false); } } foreach (Mapping.PerDeviceChannelMapping perDeviceChannelMapping in globalControlMappings) { perDeviceChannelMapping.bind(logicalInputDeviceDict, soundGenerators); } foreach (String key in mappings.Keys) { Mapping mapping = mappings[key]; if (mapping.bind(logicalInputDeviceDict, soundGenerators) == false) { return(false); } } foreach (int bankAndProgram in midiPrograms.Keys) { MidiProgram midiProgram = midiPrograms[bankAndProgram]; midiProgram.bind(logicalInputDeviceDict, soundGenerators, mappings, primaryInputDevice); } // Drop up any non-bound midiPrograms (ie, that point to mappings or SoundGeneratorPatches that no longer exist) List <MidiProgram> midiProgramListClone = midiPrograms.Values.ToList <MidiProgram>(); foreach (MidiProgram midiProgram in midiProgramListClone) { if (midiProgram.mapping == null) { midiPrograms.Remove(midiProgram.key); } } foreach (String songTitle in songDict.Keys) { Song song = songDict[songTitle]; song.bind(logicalInputDeviceDict, soundGenerators, mappings, primaryInputDevice); } foreach (Setlist setlist in setlists) { setlist.bind(songDict, logicalInputDeviceDict, soundGenerators, mappings, primaryInputDevice); } if (primaryControllerButtonProgramNumbers.Count == 0) { int[] casioPx3Buttons = new int[8] { 0x0, 0x4, 0x5, 0x7, 0x12, 0x30, 0x19, 0x3D }; primaryControllerButtonProgramNumbers.Add("CASIO USB-MIDI", casioPx3Buttons); } if (primaryControllerButtonProgramNumbers.ContainsKey(primaryInputDevice.device.Name)) { currentPrimaryControllerButtonProgramNumbers = primaryControllerButtonProgramNumbers[primaryInputDevice.device.Name]; } else { currentPrimaryControllerButtonProgramNumbers = new int[8] { -1, -1, -1, -1, -1, -1, -1, -1 }; } return(true); }
virtual public bool bind(Dictionary <String, LogicalInputDevice> logicalInputDeviceDict, Dictionary <String, SoundGenerator> soundGenerators, Dictionary <String, Mapping> mappings, LogicalInputDevice primaryInputDevice) { // Find or create a Mapping for this MidiProgram that it will point to if (bSingle == false) // If it's not a single, then it's a mapping, so just find the one named. { if (mappings.ContainsKey(this.MappingName)) { mapping = mappings[this.MappingName]; return(true); } else { MessageBox.Show("MidiProgram Mapping " + this.MappingName + " not defined in this configuration."); return(false); } } else { // If it's a single, then we create a mapping on the fly for it. mapping = new Mapping(); String candidateName = "(S) " + this.SinglePatchName; if (mappings.ContainsKey(candidateName)) { // Patch Name alone isn't a unique mapping name. Fully qualify it with the SG name too. candidateName = "(S) " + this.SingleSoundGeneratorName + " - " + this.SinglePatchName; } mapping.name = candidateName; // Create a single mapping with some settings values on the fly Mapping.PerDeviceChannelMapping perDeviceChannelMapping = new Mapping.PerDeviceChannelMapping(); perDeviceChannelMapping.logicalInputDeviceName = primaryInputDevice.logicalDeviceName; perDeviceChannelMapping.inputDeviceChannel = 0; NoteMapping noteMapping = new NoteMapping(); noteMapping.soundGeneratorName = this.SingleSoundGeneratorName; noteMapping.soundGeneratorRelativeChannel = 0; noteMapping.lowestNote = 0; noteMapping.highestNote = 127; noteMapping.pitchOffset = 0; perDeviceChannelMapping.noteMappings.Add(noteMapping); MappingPatch mappingPatch = new MappingPatch(); mappingPatch.soundGeneratorName = this.SingleSoundGeneratorName; mappingPatch.soundGeneratorRelativeChannel = 0; mappingPatch.patchName = this.SinglePatchName; perDeviceChannelMapping.mappingPatches.Add(mappingPatch); PitchBendMapping pitchBendMapping = new PitchBendMapping(); pitchBendMapping.soundGeneratorName = this.SingleSoundGeneratorName; pitchBendMapping.soundGeneratorRelativeChannel = 0; pitchBendMapping.scale = 1.0; perDeviceChannelMapping.pitchBendMappings.Add(pitchBendMapping); ControlMapping controlMapping = new ControlMapping(); controlMapping.soundGeneratorName = this.SingleSoundGeneratorName; controlMapping.soundGeneratorRelativeChannel = 0; controlMapping.sourceControlNumber = 1; // Mod Wheel controlMapping.mappedControlNumber = 1; controlMapping.min = 0; controlMapping.max = 127; controlMapping.initialValue = -1; perDeviceChannelMapping.controlMappings.Add(controlMapping); controlMapping = new ControlMapping(); controlMapping.soundGeneratorName = this.SingleSoundGeneratorName; controlMapping.soundGeneratorRelativeChannel = 0; controlMapping.sourceControlNumber = -1; controlMapping.mappedControlNumber = 7; // Vol controlMapping.min = 0; controlMapping.max = 127; controlMapping.initialValue = 127; perDeviceChannelMapping.controlMappings.Add(controlMapping); controlMapping = new ControlMapping(); controlMapping.soundGeneratorName = this.SingleSoundGeneratorName; controlMapping.soundGeneratorRelativeChannel = 0; controlMapping.sourceControlNumber = 64; // Damper controlMapping.mappedControlNumber = 64; controlMapping.min = 0; controlMapping.max = 127; controlMapping.initialValue = -1; perDeviceChannelMapping.controlMappings.Add(controlMapping); // Kurzweil Artis Variation Button... controlMapping = new ControlMapping(); controlMapping.soundGeneratorName = this.SingleSoundGeneratorName; controlMapping.soundGeneratorRelativeChannel = 0; controlMapping.sourceControlNumber = 0x1D; controlMapping.mappedControlNumber = 0x1D; controlMapping.min = 0; controlMapping.max = 127; controlMapping.initialValue = -1; perDeviceChannelMapping.controlMappings.Add(controlMapping); mapping.perDeviceChannelMappings.Add(perDeviceChannelMapping.key, perDeviceChannelMapping); return(mapping.bind(logicalInputDeviceDict, soundGenerators)); } }
private void btnRandAccessCol_DragDrop(object sender, DragEventArgs e) { Console.WriteLine("btnRandAccessCol DragDrop: " + e); if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false)) { // Figure out the table layout panel column of heading button that this TreeNode got dropped onto int col = tlpRandomAccess.GetColumn((System.Windows.Forms.Control)sender); // Find the first unoccupied row in that column int row; for (row = 0; row < N_RANDOMACCESS_ROWS; ++row) { if (tlpRandomAccess.GetControlFromPosition(col, row + FIRST_RANDOMACCESS_BTN_ROW) == null) { break; } } if (row == N_RANDOMACCESS_ROWS) { MessageBox.Show("No room in this column"); return; } // Get the dropped node TreeNode droppedNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode"); // Get the SoundGeneratorPatch or Mapping that it points to Object o = droppedNode.Tag; // Create a new midiProgram to capture the action of the random access button we're about to create MidiProgram midiProgram; // Initialize the midiProgram appropriately, depending on whether there was a SoundGeneratorPatch or a Mapping in the droppped TreeNode if (o is SoundGeneratorPatch) { midiProgram = new MidiProgram((SoundGeneratorPatch)o); } else if (o is Mapping) { midiProgram = new MidiProgram((Mapping)o); } else { return; } // Determine the input device for this midiProgram: the tab's currently selected input device LogicalInputDevice deviceForThisMidiProgram = mapper.configuration.primaryInputDevice; if (tabControl1.SelectedTab.Tag != null && tabControl1.SelectedTab.Tag is LogicalInputDevice) { deviceForThisMidiProgram = (LogicalInputDevice)tabControl1.SelectedTab.Tag; } // Have the midiProgram flesh out its inner details midiProgram.bind(mapper.configuration.logicalInputDeviceDict, mapper.configuration.soundGenerators, mapper.configuration.mappings, deviceForThisMidiProgram); // Assign this Midi Program a patch number based on where it was dropped in the button matrix. midiProgram.myPatchNumber = (row * N_RANDOMACCESS_COLS) + col - FIRST_RANDOMACCESS_BTN_COL; // Assign it a bank number based on which Random Access page it's dropped on (which is captured in currentRandomAccessBank) midiProgram.myBankNumber = currentRandomAccessBank; // Add the newly created midiProgram to the master dictionary of such things. Mark config as dirty so this change gets saved on close. mapper.configuration.midiPrograms.Add(midiProgram.key, midiProgram); mapper.configuration.dirty = true; // Create a new button for this sound generator patch Button btn = new Button(); btn.Font = buttonFont; btn.Text = midiProgram.mapping.name; btn.BackColor = System.Drawing.Color.DimGray; btn.ForeColor = System.Drawing.Color.White; btn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; btn.FlatAppearance.BorderColor = System.Drawing.Color.LightGreen; btn.Visible = true; btn.Dock = DockStyle.Fill; btn.MouseDown += btnPrograms_MouseDown; btn.ContextMenuStrip = this.contextMenuStrip1; btn.Tag = midiProgram; midiProgram.activationButton = btn; btn.Click += new System.EventHandler(this.btnProgramChange_Click); // And add it to the table layout panel in the designated spot. tlpRandomAccess.Controls.Add(btn, col, row + FIRST_RANDOMACCESS_BTN_ROW); } }
public void bind(Dictionary <String, Song> songDict, Dictionary <String, LogicalInputDevice> logicalInputDeviceDict, Dictionary <String, SoundGenerator> soundGenerators, Dictionary <String, Mapping> mappings, LogicalInputDevice primaryInputDevice) { songs.Clear(); foreach (String songTitle in songTitles) { if (songDict.ContainsKey(songTitle)) { Song song = songDict[songTitle]; songs.Add(song); // song.bind(logicalInputDeviceDict, soundGenerators, mappings, primaryInputDevice); } } }