Exemple #1
0
        void SendMessages(Drums newState, XInput.GamepadEx state)
        {
            if (device == null)
            {
                return;
            }
            var channel = Midi.Enums.Channel.Channel10;

            foreach (Drums d in Enum.GetValues(typeof(Drums)))
            {
                var note = DrumNoteMap[d];
                if (newState.HasFlag(d) && !drumState.HasFlag(d))
                {
                    var velocity = VelocityFunctions[d](state);
                    if (velocity > 127)
                    {
                        velocity = 127;
                    }
                    if (velocity < 32)
                    {
                        velocity = 32;
                    }
                    device.SendNoteOn(channel, (Midi.Enums.Pitch)note, velocity);
                }
                else if (!newState.HasFlag(d) && drumState.HasFlag(d))
                {
                    device.SendNoteOff(channel, (Midi.Enums.Pitch)note, 0);
                }
            }
        }
Exemple #2
0
 private void PointTrigger(int p)
 {
     if (device?.IsOpen == true)
     {
         device.SendNoteOn(Midi.Enums.Channel.Channel1, (Midi.Enums.Pitch)points[p].p.midiNote, 100);
         device.SendNoteOff(Midi.Enums.Channel.Channel1, (Midi.Enums.Pitch)points[p].p.midiNote, 100);
     }
 }
Exemple #3
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);
            }
        }
Exemple #4
0
 private void Translator_OnNoteOn(Midi.Enums.Channel c, Midi.Enums.Pitch p, int v)
 => device?.SendNoteOn(c, p, v);