Exemple #1
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 LaunchpadSRenderer(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
            var layoutMsg = Midi.CreateBuffer(MidiMessageType.ControlModeChange, 1);

            layoutMsg[1] = 0x00;
            layoutMsg[2] = 0x01; // X-Y layout
            var clearMsg = Midi.CreateBuffer(MidiMessageType.ControlModeChange, 1);

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

            // Create buffers
            _lights       = new Light[info.LightCount];
            _normalMsg    = Midi.CreateBuffer(MidiMessageType.NoteOn, 3, _lights.Length);
            _flashMsg     = Midi.CreateBuffer(MidiMessageType.NoteOn, 3, _lights.Length);
            _bufferMsg    = Midi.CreateBuffer(MidiMessageType.ControlModeChange, 1);
            _bufferMsg[2] = 32; // Simple
        }
        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
        }
        public LaunchpadSRenderer(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 layoutMsg = Midi.CreateBuffer(MidiMessageType.ControlModeChange, 1);

            layoutMsg[1] = 0x00;
            layoutMsg[2] = 0x01; // X-Y layout
            var brightnessMsg = Midi.CreateBuffer(MidiMessageType.ControlModeChange, 1);

            //layoutMsg[1] = 0x1E; // Brightness
            //layoutMsg[2] = 0x00; // 1/3 (max "safe")
            layoutMsg[1] = 0x1F; // Brightness
            layoutMsg[2] = 0x00; // 9/3
            var clearMsg = Midi.CreateBuffer(MidiMessageType.ControlModeChange, 1);

            clearMsg[1]        = 0x00;
            clearMsg[2]        = 0x00; // Clear all lights
            _device.Connected += () =>
            {
                SendMidi(layoutMsg);
                SendMidi(brightnessMsg);
                SendMidi(clearMsg);
                _lightsInvalidated = true;
            };
            _device.Disconnecting += () =>
            {
                SendMidi(clearMsg);
            };

            // Create buffers
            _lights        = new Light[info.LightCount];
            _noteOn        = Midi.CreateBuffer(MidiMessageType.NoteOn, 1);
            _noteOff       = Midi.CreateBuffer(MidiMessageType.NoteOff, 1);
            _topNoteOn     = Midi.CreateBuffer(MidiMessageType.ControlModeChange, 1);
            _topNoteOff    = Midi.CreateBuffer(MidiMessageType.ControlModeChange, 1);
            _topNoteOff[2] = 0x0C;
        }
Exemple #5
0
        public LaunchpadDevice(MidiDevice device)
        {
            _device   = device;
            _sendLock = new SemaphoreSlim(1, 1);
            _info     = DeviceInfo.FromType(device.Type);
            _renderer = _info.RendererFactory(_device);

            // Cache id lookups
            _posMap          = new MidiPosition[Width, Height];
            _midiMap         = new MidiPosition[256];
            _systemButtonMap = new MidiPosition[256];

            var empty = new MidiPosition(255, 255, 255, 255, 255, null);

            for (byte y = 0; y < Height; y++)
            {
                for (byte x = 0; x < Width; x++)
                {
                    _posMap[x, y] = empty;
                }
            }
            for (int i = 0; i < _midiMap.Length; i++)
            {
                _midiMap[i] = empty;
            }
            for (int i = 0; i < _systemButtonMap.Length; i++)
            {
                _systemButtonMap[i] = empty;
            }

            for (byte y = 0; y < Height; y++)
            {
                for (byte x = 0; x < Width; x++)
                {
                    byte midi = _info.Layout[Height - y - 1, x];
                    if (midi != 255)
                    {
                        var  systemButton = _info.SystemButtons.TryGetValue(midi, out var systemButtonVal) ? systemButtonVal : (SystemButton?)null;
                        byte buttonX      = x >= _info.InnerOffsetX && x < _info.InnerOffsetX + 8 ? (byte)(x - _info.InnerOffsetX) : (byte)255;
                        byte buttonY      = y >= _info.InnerOffsetY && y < _info.InnerOffsetY + 8 ? (byte)(y - _info.InnerOffsetY) : (byte)255;
                        var  info         = new MidiPosition(midi, buttonX, buttonY, x, y, systemButton);
                        _posMap[x, y]       = info;
                        _midiMap[info.Midi] = info;
                        if (systemButton.HasValue)
                        {
                            _systemButtonMap[(byte)info.SystemButton.Value] = info;
                        }
                    }
                }
            }

            // Register events
            _device.ButtonDown += (type, midiId) =>
            {
                if (type == MidiMessageType.ControlModeChange && (Type == DeviceType.LaunchpadS || Type == DeviceType.LaunchpadMini))
                {
                    midiId += 100; // Adjust for overlapping midi codes
                }
                _queuedEvents.Enqueue(new LaunchpadEvent(EventType.ButtonDown, _midiMap[midiId]));
            };
            _device.ButtonUp += (type, midiId) =>
            {
                if (type == MidiMessageType.ControlModeChange && (Type == DeviceType.LaunchpadS || Type == DeviceType.LaunchpadMini))
                {
                    midiId += 100; // Adjust for overlapping midi codes
                }
                _queuedEvents.Enqueue(new LaunchpadEvent(EventType.ButtonUp, _midiMap[midiId]));
            };
        }