Ejemplo n.º 1
0
        public void ControllerEventHandler(XInput.GamepadEx state)
        {
            var newState = ProcessState(state);

            if (lastState == null)
            {
                lastState = newState;
                return;
            }
            if (state.wButtons.HasFlag(XInput.Buttons.A))
            {
                OnControlChange?.Invoke(Channel.Channel1, Control.AllNotesOff, 0);
            }
            for (int i = 0; i < 6; i++)
            {
                if (lastState.Velocities[i] != newState.Velocities[i])
                {
                    newPitches[i] = (byte)(newState.Frets[i] + StandardTuning[i]);
                    OnNoteOff?.Invoke(Channel.Channel1, (Pitch)lastPitches[i]);
                    OnNoteOn?.Invoke(Channel.Channel1, (Pitch)newPitches[i], newState.Velocities[i]);
                }
            }
            // swap note buffers
            var temp = lastPitches;

            lastPitches = newPitches;
            newPitches  = temp;
            // swap guitar state
            lastState = newState;
        }
Ejemplo n.º 2
0
        void SendMessages(bool[] newKeys, bool sustain, byte[] velocities)
        {
            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]))
                {
                    OnNoteOn?.Invoke(Channel, pitch, velocities[Math.Min(newVelocityStart, finalVelocity)]);
                    keyState[i] = velocities[Math.Min(newVelocityStart, finalVelocity)];
                    newVelocityStart++;
                }
                else if (!newKeys[i] && (0 != keyState[i]))
                {
                    OnNoteOff?.Invoke(Channel, pitch);
                    keyState[i] = 0;
                }
            }
            if (sustain && !sustainState)
            {
                OnControlChange?.Invoke(Channel, Midi.Enums.Control.SustainPedal, 127);
            }
            else if (!sustain && sustainState)
            {
                OnControlChange?.Invoke(Channel, Midi.Enums.Control.SustainPedal, 0);
            }
        }
Ejemplo n.º 3
0
 void SendMessages(Drums newState, XInput.GamepadEx state)
 {
     foreach (Drums d in Enum.GetValues(typeof(Drums)))
     {
         var note = DrumNoteMap[d](newState);
         if (newState.HasFlag(d) && !drumState.HasFlag(d))
         {
             var velocity = VelocityFunctions[d](state);
             if (velocity > 127)
             {
                 velocity = 127;
             }
             if (velocity < 32)
             {
                 velocity = 32;
             }
             OnNoteOn?.Invoke(Channel, (Midi.Enums.Pitch)note, velocity);
         }
         else if (!newState.HasFlag(d) && drumState.HasFlag(d))
         {
             OnNoteOff?.Invoke(Channel, (Midi.Enums.Pitch)note);
         }
     }
 }
Ejemplo n.º 4
0
 private void NoteOn(NoteEventArgs noteEventArgs)
 {
     _pressedNotes.Add(noteEventArgs.NoteAbsolute);
     OnNoteOn?.Invoke(this, noteEventArgs);
 }
Ejemplo n.º 5
0
 public void NotePressedFromUI(NoteEventArgs noteEventArgs)
 {
     OnNoteOn?.Invoke(this, noteEventArgs);
 }