Esempio n. 1
0
        public static CatCommandAttribute Get(CatCmd Id)
        {
            var type       = typeof(CatCmd);
            var memInfo    = type.GetMember(Id.ToString());
            var attributes = memInfo[0].GetCustomAttributes(typeof(CatCommandAttribute), false);
            var CatCommand = ((CatCommandAttribute)attributes[0]);

            CatCommand.CatCommandId = Id;
            return(CatCommand);
        }
Esempio n. 2
0
        public void SetCatCmdInUse(CatCmd catCmd, bool inUse)
        {
            DataTable t  = ds.Tables["CatCmds"];
            DataRow   dr = t.Rows.Find(catCmd);

            if (dr != null)
            {
                dr["InUse"] = inUse;
                dr.AcceptChanges();
            }
        }
Esempio n. 3
0
 private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (tabControl.SelectedTab == commandsTabPage)
     {
         MappedCommands mappedCommands = new MappedCommands(_enumsDb.ds.Tables["CatCmds"], _db.ds.Tables[DeviceName]);
         mappedCommandsBindingSource.DataSource = mappedCommands;
     }
     else if (tabControl.SelectedTab == mappedControlsTab)
     {
         CatCmdToUse = CatCmd.None;
     }
     else if (tabControl.SelectedTab == debugTab)
     {
         CatCmdToUse = CatCmd.None;
     }
 }
Esempio n. 4
0
        private void mapControlToCommandGrid_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            var    Cell           = mapControlToCommandGrid.Rows[e.RowIndex].Cells[e.ColumnIndex];
            var    Row            = Cell.OwningRow;
            var    Col            = Cell.OwningColumn;
            string sCurrentValue  = Cell.Value.ToString();
            string sPreviousValue = (string)Cell.Tag;

            if (Col.Name == "CatCmdIdColumn")
            {
                CatCmd currentCmd  = (CatCmd)Convert.ToInt32(sCurrentValue);
                CatCmd previousCmd = (CatCmd)Convert.ToInt32(sPreviousValue);
                _enumsDb.SetCatCmdInUse(previousCmd, false);
                _enumsDb.SetCatCmdInUse(currentCmd, true);
            }
            DB.SaveChanges(DeviceName);
        }
Esempio n. 5
0
        public ControllerMapping GetReverseMapping(string MidiDeviceName, CatCmd cmd)  //-W2PA To allow flowing commands back to MIDI devices
        {
            ControllerMapping mapping = null;
            DataTable         t       = GetTable(MidiDeviceName);
            DataRow           dr      = t.Rows.Find(cmd);

            string sel = "CatCmdId = " + Convert.ToString((int)cmd);

            DataRow[] dr1 = t.Select(sel);

            if (dr1.Length == 0)
            {
                return(mapping);
            }
            if (dr1[0] != null)
            {
                mapping = PopulateMapping(dr1[0]);
            }
            return(mapping);
        }
Esempio n. 6
0
        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;
        }
Esempio n. 7
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);
                }
            });
        }