Example #1
0
        internal void ExecuteCommand(SysExMessage msg)
        {
            bool     isSet = (msg.Command & 1) > 0;
            SysExMsg cmd   = (SysExMsg)(msg.Command >> 1);

            if (_lastCommand.Key != isSet || _lastCommand.Value != cmd)
            {
                Program.Log($"{(isSet ? "SET" : "GET")} {cmd} " + msg.Values.Aggregate(string.Empty,
                                                                                       (s, b) => s + b.ToString("X") + " | ", s => s.TrimEnd(' ', '|')));
                _lastCommand = new KeyValuePair <bool, SysExMsg>(isSet, cmd);
            }
            switch (cmd)
            {
            case SysExMsg.Handshake:
                Answers.Enqueue(SerialMessage(msg.Command, (byte)_currentVersion.Major, (byte)_currentVersion.Minor));
                break;

            case SysExMsg.GetPinCount:
                Answers.Enqueue(SerialMessage(msg.Command, MaxPinCount, 0));
                break;

            case SysExMsg.GetPinValue:
                byte pin = msg.Values[0];

                Answers.Enqueue(pin == byte.MaxValue
                        ? SerialMessage(msg.Command, pin,
                                        Enumerable.Range(0, MaxPinCount).Select(x => GetPinValue((byte)x)).ToArray())
                        : SerialMessage(msg.Command, pin, GetPinValue(pin)));
                break;

            case SysExMsg.Eeprom:
                if (isSet)
                {
                    SaveToEeprom(_fileName, _currentVersion);
                }
                else
                {
                    GetFromEeprom(_fileName, _currentVersion);
                }
                break;

            case SysExMsg.PinType:
                SetOrGetArrayValue(isSet, ref _pinType, msg.Command, msg.Values);
                break;

            case SysExMsg.PinNote:
                SetOrGetArrayValue(isSet, ref _pinNote, msg.Command, msg.Values);
                break;

            case SysExMsg.PinThreshold:
                SetOrGetArrayValue(isSet, ref _pinThreshold, msg.Command, msg.Values);
                break;

            case SysExMsg.PinPitch:
                SetOrGetArrayValue(isSet, ref _pinPitch, msg.Command, msg.Values);
                break;

            case SysExMsg.PinCurve:
                SetOrGetCurve(isSet, msg.Command, msg.Values);
                break;

            case SysExMsg.PinCurveModifications:
                SetOrGetCurveModifications(isSet, msg.Command, msg.Values);
                break;
            }
        }
Example #2
0
 public SysExMessage(SysExMsg command, CommandType type, params byte[] values)
 {
     Command = (byte)((((byte)command) << 1) | (byte)type);
     Values  = values;
 }
Example #3
0
 internal SysExMessage RunCommand(SysExMsg command, CommandType type, params byte[] values)
 {
     return RunCommand(new SysExMessage(command, type, values));
 }