Пример #1
0
        void SendMessages(bool[] newKeys, bool sustain, byte[] velocities)
        {
            if (device == null)
            {
                return;
            }
            var channel          = Midi.Enums.Channel.Channel1;
            int newVelocityStart = 0;
            int finalVelocity    = 0;

            for (int i = 0; i < 5; i++)
            {
                if (velocities[i] != 0)
                {
                    finalVelocity = i;
                    if (velocityState[i] == velocities[i])
                    {
                        newVelocityStart = i + 1;
                    }
                }
                velocityState[i] = velocities[i];
            }
            for (int i = 0; i < 25; i++)
            {
                var pitch = (Midi.Enums.Pitch)(i + offset);
                if (newKeys[i] && (0 == keyState[i]))
                {
                    device.SendNoteOn(channel, pitch, velocities[Math.Min(newVelocityStart, finalVelocity)]);
                    keyState[i] = velocities[Math.Min(newVelocityStart, finalVelocity)];
                    newVelocityStart++;
                }
                else if (!newKeys[i] && (0 != keyState[i]))
                {
                    device.SendNoteOff(channel, pitch, 0);
                    keyState[i] = 0;
                }
            }
            if (sustain && !sustainState)
            {
                device.SendControlChange(channel, Midi.Enums.Control.SustainPedal, 127);
            }
            else if (!sustain && sustainState)
            {
                device.SendControlChange(channel, Midi.Enums.Control.SustainPedal, 0);
            }
        }
Пример #2
0
 private void Translator_OnControlChange(Midi.Enums.Channel c, Midi.Enums.Control ctrl, int v)
 => device?.SendControlChange(c, ctrl, v);