Beispiel #1
0
        // 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;
        }
Beispiel #2
0
        //--------------------------------------------------------------------------------
        // 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);
                }
            }
        }
Beispiel #3
0
        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);
        }