private void mapControlToCommandGrid_CellEndEdit(object sender, DataGridViewCellEventArgs e) { var Cell = mapControlToCommandGrid.Rows[e.RowIndex].Cells[e.ColumnIndex]; var Row = Cell.OwningRow; var Col = Cell.OwningColumn; if (Col.IsDataBound && Col.Name == "CatCmdIdColumn") { if (mapControlToCommandGrid.CurrentCell.EditType == typeof(DataGridViewComboBoxEditingControl)) { DataGridViewComboBoxCell cb = (DataGridViewComboBoxCell)mapControlToCommandGrid[e.ColumnIndex, e.RowIndex]; cb.DataSource = catCmdsBindingSource; } } else if (Col.IsDataBound && Col.Name == "midiControlTypeColumn") { ControlType ctrlType = (ControlType)Row.Cells["midiControlTypeColumn"].Value; CatCmd CatCmdValue = (CatCmd)Row.Cells["CatCmdIdColumn"].Value; var attr = CatCmdDb.Get(CatCmdValue); if (attr.ControlType != ctrlType) { System.Data.DataRowView obj = (System.Data.DataRowView)mapControlToCommandGrid.CurrentRow.DataBoundItem; obj.BeginEdit(); obj.Row["CatCmdId"] = 0; obj.EndEdit(); } } }
private void LoadNonDataBoundControls(int ctrlId, int value) { DataRowView view = (DataRowView)controllerMappingBindingSource1.Current; CatCmd currentCatCmdId = (CatCmd)view["CatCmdId"]; if (CatCmdToUse != CatCmd.None) { currentCatCmdId = CatCmdToUse; mappingControlTypeCB2.SelectedValue = ControlTypeToUse; if (value == 0) { CatCmdToUse = CatCmd.None; ControlTypeToUse = ControlType.Unknown; } } if (value > int.MinValue) { int currentMinValue = (int)view["MinValue"]; int currentMaxValue = (int)view["MaxValue"]; if (value < currentMinValue) { view["MinValue"] = value; view.Row.AcceptChanges(); } if (value > currentMaxValue) { view["MaxValue"] = value; view.Row.AcceptChanges(); } } mappingValueLabel2.Text = value.ToString(); mappingMessageLabel2.Text = CatCmdDb.Get(currentCatCmdId).Desc; mappingControlNameTB2.Text = (string)view["MidiControlName"]; mappingMaxValueLabel2.Text = ((int)view["MaxValue"]).ToString(); mappingMinValueLabel2.Text = ((int)view["MinValue"]).ToString(); mappingControlIdLabel2.Text = ((int)view["MidiControlId"]).ToString(); buttonDownEventTB.Text = _db.ConvertFromDBVal <string>(view["MidiOutCmdDown"]); buttonUpEventTB.Text = _db.ConvertFromDBVal <string>(view["MidiOutCmdUp"]); newValueReceivedEventTB.Text = _db.ConvertFromDBVal <string>(view["MidiOutCmdSetValue"]); if (string.IsNullOrWhiteSpace(buttonDownEventTB.Text) && string.IsNullOrWhiteSpace(buttonUpEventTB.Text) && string.IsNullOrWhiteSpace(newValueReceivedEventTB.Text)) { advancedLinkLabel.Text = showAdvancedSettings; } else { advancedLinkLabel.Text = hideAdvancedSettings; } ControlType currentControlType = (ControlType)mappingControlTypeCB2.SelectedValue; buttonDownEventTB.Enabled = (currentControlType == ControlType.Button); buttonUpEventTB.Enabled = (currentControlType == ControlType.Button); string filter = "( InUse = False AND ControlType = " + mappingControlTypeCB2.SelectedValue.ToString() + " OR ControlType = 0 )"; filter += " OR ( CmdId = " + ((int)currentCatCmdId) + ")"; if (filter != catCmdsFilteredBindingSource.Filter) { catCmdsFilteredBindingSource.Filter = filter; } mappingAvailableCmdsLB.SelectedValue = currentCatCmdId; }
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); } }); }