private void SendSysExArray(List <byte> msgs)
 {
     if (msgs.Count > 1)
     {
         SendBuffer(SysEx.CreateBuffer(_device.Type, msgs.ToArray()));
     }
 }
Exemple #2
0
        public LaunchpadRGBRenderer(MidiDevice device)
        {
            _device = device;

            // Cache id lookups
            var info = DeviceInfo.FromType(device.Type);

            _indexToMidi = new byte[256];
            _midiToIndex = new byte[256];
            for (int i = 0; i < _indexToMidi.Length; i++)
            {
                _indexToMidi[i] = 255;
            }
            for (int i = 0; i < _midiToIndex.Length; i++)
            {
                _midiToIndex[i] = 255;
            }
            for (byte y = 0, i = 0; y < info.Height; y++)
            {
                for (byte x = 0; x < info.Width; x++)
                {
                    byte midi = info.Layout[info.Height - y - 1, x];
                    if (midi != 255)
                    {
                        _indexToMidi[i]    = midi;
                        _midiToIndex[midi] = i;
                        i++;
                    }
                }
            }

            // Register events
            var modeMsg = SysEx.CreateBuffer(1, _device.Type, 0x21);

            modeMsg[7] = 0x01; // Standalone mode
            var layoutMsg = SysEx.CreateBuffer(1, _device.Type, 0x2C);

            layoutMsg[7] = 0x03; // Programmer layout
            var clearMsg = SysEx.CreateBuffer(1, _device.Type, 0x0E);

            clearMsg[7]        = 0x00; // Clear all lights
            _device.Connected += () =>
            {
                SendSysEx(modeMsg);
                SendSysEx(layoutMsg);
                SendSysEx(clearMsg);
                _lightsInvalidated = true;
            };
            _device.Disconnecting += () =>
            {
                SendSysEx(clearMsg);
            };

            // Create buffers
            _lights    = new Light[info.LightCount];
            _normalMsg = SysEx.CreateBuffer(2 * _lights.Length, _device.Type, 0x0A);
            _pulseMsg  = SysEx.CreateBuffer(3 * _lights.Length, _device.Type, 0x28);
            _flashMsg  = SysEx.CreateBuffer(3 * _lights.Length, _device.Type, 0x23);
        }
        public LaunchpadRGBRenderer(MidiDevice device)
        {
            _device = device;

            // Cache id lookups
            var info = DeviceInfo.FromType(device.Type);

            _indexToMidi = new byte[256];
            _midiToIndex = new byte[256];
            for (int i = 0; i < _indexToMidi.Length; i++)
            {
                _indexToMidi[i] = 255;
            }
            for (int i = 0; i < _midiToIndex.Length; i++)
            {
                _midiToIndex[i] = 255;
            }
            for (byte y = 0; y < info.Height; y++)
            {
                for (byte x = 0; x < info.Width; x++)
                {
                    byte midi  = info.MidiLayout[info.Height - y - 1, x];
                    byte index = info.IndexLayout[info.Height - y - 1, x];
                    if (midi != 255 && index != 255)
                    {
                        _indexToMidi[index] = midi;
                        _midiToIndex[midi]  = index;
                    }
                }
            }

            // Register events
            // Mode selection, Standalone mode (default)
            var modeMsg = SysEx.CreateBuffer(_device.Type, new byte[] { 0x21, 0x01 });
            // Standalone Layout select, Programmer
            var layoutMsg = SysEx.CreateBuffer(_device.Type, new byte[] { 0x2C, 0x03 });
            // Set all LEDs, color = 0
            var clearMsg = SysEx.CreateBuffer(_device.Type, new byte[] { 0x0E, 0x0 });

            _device.Connected += () =>
            {
                SendBuffer(modeMsg);
                SendBuffer(layoutMsg);
                SendBuffer(clearMsg);
                _lightsInvalidated = true;
            };
            _device.Disconnecting += () =>
            {
                SendBuffer(clearMsg);
            };

            // Create buffers
            _lights    = new Light[info.LightCount];
            _oldLights = new Light[info.LightCount];
            _clockMsg  = Midi.CreateBuffer(MidiMessageType.MidiClock, 1); // MIDI Clock
        }