Exemple #1
0
 private void CloseMidiDevice()
 {
     if (midiDevice != null)
     {
         midiDevice.CloseMidiIn();
         midiDevice.CloseMidiOut();
         midiDevice = null;
     }
 }
Exemple #2
0
 private void OpenMidiDevice()
 {
     if (midiDevice == null)
     {
         midiDevice = new MidiDevice();
         midiDevice.onMidiDebugMessage += onMidiDebugMsg;
         midiDevice.onMidiInput        += OnMidiInput;
     }
     midiDevice.OpenMidiIn(DeviceIndex, DeviceName);
     ignoreMidiMessagesUntil = DateTime.Now.AddSeconds(5);
 }
Exemple #3
0
        void OnMidiInput(MidiDevice Device, int DeviceIdx, int ControlId, int Data, int Status, int Event, int Channel)
        {
            // Following opening the midi controller most controllers will immediatly send current status of any knobs and sliders
            // We are not interested in these messages when in setup. The Only way to ignore them is to introduce a delay following the open command.
            if (DateTime.Now < ignoreMidiMessagesUntil)
            {
                return;
            }

            this.InvokeIfRequired(p =>
            {
                if (tabControl.SelectedTab == debugTab)
                {
                    _diagList.Add(new MidiDiagItem {
                        Device = DeviceIdx.ToString("X2"), ControlId = ControlId.ToString("X2"), Data = Data.ToString("X2"), Status = Status.ToString("X2"), Voice = ((MidiEvent)Event).ToString().Replace("_", " "), Channel = (Channel + 1).ToString("X2")
                    });
                    if (_diagList.Count > 100)
                    {
                        _diagList.RemoveAt(0);
                    }
                    midiDiagDataGrid.CurrentCell = midiDiagDataGrid.Rows[_diagList.Count - 1].Cells[0];
                }

                if (tabControl.SelectedTab == commandsTabPage)
                {
                    tabControl.SelectedTab = mappedControlsTab;
                    if (mappedCommandsGridView.SelectedRows.Count == 1)
                    {
                        var row          = mappedCommandsGridView.SelectedRows[0];
                        int cmdIdx       = mappedCommandsGridView.Columns["cmdIdDataGridViewTextBoxColumn"].Index;
                        CatCmdToUse      = (CatCmd)row.Cells[cmdIdx].Value;
                        int ctIdx        = mappedCommandsGridView.Columns["controlTypeDataGridViewTextBoxColumn"].Index;
                        ControlTypeToUse = (ControlType)row.Cells[ctIdx].Value;
                    }
                }

                if (tabControl.SelectedTab == mappedControlsTab)
                {
                    ControllerMapping mapping = DB.GetMapping(DeviceName, ControlId);
                    if (AddingControl && AddingControlId != ControlId)
                    {
                        MappingDone();
                    }
                    if (mapping == null)
                    {
                        mapping = new ControllerMapping {
                            MidiControlId = ControlId, MaxValue = int.MinValue, MinValue = int.MaxValue, MidiControlType = ControlTypeToUse, MidiControlName = ""
                        };
                        mapping.CatCmd      = CatCmdDb.Get(CatCmd.None);
                        DataRowView newView = (DataRowView)controllerMappingBindingSource1.AddNew();
                        DB.PopulateRow(newView.Row, mapping);
                        DB.AddRow(DeviceName, newView.Row);
                        newView.Row.AcceptChanges();
                        mapControlToCommandGrid.Refresh();
                        DB.SaveChanges(DeviceName);
                        AddingControl   = true;
                        AddingControlId = ControlId;
                    }

                    int Idx = controllerMappingBindingSource1.Find("MidiControlId", mapping.MidiControlId);
                    controllerMappingBindingSource1.Position = Idx;
                    ShowMapInCtrl2CmdDialog(ControlId, Data);
                    ValidateDialogInput();
                    SendMidiCommand(Channel, Data, Status, ControlId, mapping);
                }
            });
        }