Esempio n. 1
0
        protected void LoopScan()
        {
            MData data = this.Read();

            if (previous == null)
            {
                previous = data;
            }

            #region Panic: All Notes Off (Select, Home and Start together)
            if (data.SelectMinus && data.Home && data.StartPlus && !holdPanic)
            {
                holdPanic = true;
                int max = (8 * 12) + 25;
                for (int i = 0; i < max; i++)
                {
                    MIDI.SendNoteOff(1, i, 0);
                    MIDI.SendNoteOff(2, i, 0);
                    MIDI.SendNoteOff(3, i, 0);
                    MIDI.SendNoteOff(4, i, 0);
                    MIDI.SendNoteOff(5, i, 0);
                    MIDI.SendNoteOff(6, i, 0);
                }
            }
            else if (!data.SelectMinus && !data.Home && !data.StartPlus && holdPanic)
            {
                holdPanic = false;
            }
            #endregion

            if (data.SelectMinus)
            {
                if (data.Square1 && !holdShift)
                {
                    holdShift = true;
                    Console.WriteLine("Toggle Axis X for ModulationWheel");
                }
                else if (data.Triangle2 && !holdShift)
                {
                    holdShift = true;
                    Console.WriteLine("Toggle Axis Y for Expression");
                }
                else if (data.CircleB && !holdShift)
                {
                    holdShift = true;
                    Console.WriteLine("Toggle Axis Z for Pitch Bend");
                }
                else if (!data.Square1 && !data.Triangle2 && !data.CircleB && holdShift)
                {
                    holdShift = false;
                }
            }
            else     // Not Holding select
            {
                if (data.StartPlus && !holdShift)
                {
                    holdShift = true;
                    SetSynthMode(!synthMode);

                    if (enableLED)
                    {
                        if (synthMode)
                        {
                            this.SetLED(8, true);
                        }
                        else
                        {
                            this.SetLED(1, true);
                        }
                    }
                }
                else if (!data.StartPlus && holdShift)
                {
                    holdShift = false;
                }

                #region Dpad (Pedal) UNSUPPORTED

                /*
                 * if (data.Dpad == 0 && !holdDpad) { //Up - Drum Mapping
                 *  holdDpad = true;
                 *  //Nothing
                 * } else if (data.Dpad == 4 && !holdDpad) { //Down
                 *  holdDpad = true;
                 * } else if (data.Dpad == 6 && !holdDpad) { //Left
                 *  holdDpad = true;
                 * } else if (data.Dpad == 2 && !holdDpad) { //Right
                 *  holdDpad = true;
                 * } else if (data.Dpad == 8 && holdDpad) {
                 *  holdDpad = false;
                 * }
                 *
                 * if (data.Pedal && !holdPedal) {
                 *  holdPedal = true;
                 *  MIDI_OUT.SendControlChange(1, Midi.Control.SustainPedal, 127);
                 * } else if (!data.Pedal && holdPedal) {
                 *  MIDI_OUT.SendControlChange(1, Midi.Control.SustainPedal, 0);
                 *  holdPedal = false;
                 * }
                 */
                #endregion

                #region Program
                if (data.Triangle2 && data.CrossA && !holdDefault)   //Set default
                {
                    holdDefault = true;
                    SetProgram(27);
                    if (enableLED)
                    {
                        new Thread(() => LEDAnimateLRL()).Start();
                    }
                }
                else if (data.Triangle2 && !holdProgram)
                {
                    holdProgram = true;
                    SetProgram(instrument + 1);
                    if (enableLED)
                    {
                        new Thread(() => LEDAnimateLTR()).Start();
                    }
                }
                else if (data.CrossA && !holdProgram)
                {
                    holdProgram = true;
                    SetProgram(instrument - 1);
                    if (enableLED)
                    {
                        new Thread(() => LEDAnimateRTL()).Start();
                    }
                }
                else if (!data.Triangle2 && !data.CrossA && holdProgram)
                {
                    holdProgram = false;
                    holdDefault = false;
                }
                #endregion

                #region Octave
                if (data.CircleB && data.Square1 && !holdDefault)
                {
                    holdDefault = true;
                    SetOctave(3);
                    if (enableLED)
                    {
                        new Thread(() => LEDAnimateLRL()).Start();
                    }
                }
                else if (data.CircleB && !holdOctave)
                {
                    holdOctave = true;
                    SetOctave(octave + 1);
                    if (enableLED)
                    {
                        new Thread(() => LEDAnimateLTR()).Start();
                    }
                }
                else if (data.Square1 && !holdOctave)
                {
                    holdOctave = true;
                    SetOctave(octave - 1);
                    if (enableLED)
                    {
                        new Thread(() => LEDAnimateRTL()).Start();
                    }
                }
                else if (!data.CircleB && !data.Square1 && holdOctave)
                {
                    holdOctave  = false;
                    holdDefault = false;
                }
                #endregion
            } // End: Not holding select

            #region Keys
            if (synthMode)
            {
                for (int i = 0; i < data.Fret.Length; i++)
                {
                    int pitch = (octave * 12) + data.Fret[i] + MData.PitchOffset[i];

                    if (data.Velocity[i] != previous.Velocity[i] || (data.Fret[i] != previous.Fret[i] && data.Fret[i] > 0))
                    {
                        //HeldKey.Add(i, new Tuple<Channel, Pitch>(1, pitch));
                        MIDI.SendNoteOn(1, pitch, data.Velocity[i]);
                    }
                    else if (data.Fret[i] == 0 && previous.Fret[i] != 0 && HeldKey.ContainsKey(i))
                    {
                        MIDI.SendNoteOff(HeldKey[i].Item1, HeldKey[i].Item2, 0);
                        //HeldKey.Remove(i);
                    }
                }
            }
            else
            {
                for (int i = 0; i < data.Fret.Length; i++)
                {
                    int pitch = (octave * 12) + data.Fret[i] + MData.PitchOffset[i];

                    if (data.Velocity[i] != previous.Velocity[i])
                    {
                        if (HeldKey.ContainsKey(i))
                        {
                            MIDI.SendNoteOff(HeldKey[i].Item1, HeldKey[i].Item2, 0);
                            //Console.WriteLine("Note Off: " + ());
                            HeldKey.Remove(i);
                        }

                        HeldKey.Add(i, new Tuple <int, int>(i + 1, pitch));
                        MIDI.SendNoteOn(i + 1, pitch, 80);
                        //Console.WriteLine("Pitch: " + ().ToString());// "Octave: " + Octave;
                    }
                    else if (data.Fret[i] == 0 && previous.Fret[i] != 0 && HeldKey.ContainsKey(i))
                    {
                        MIDI.SendNoteOff(HeldKey[i].Item1, HeldKey[i].Item2, 0);
                        //Console.WriteLine("Note Off: " + ());
                        HeldKey.Remove(i);
                    }
                }
            }
            #endregion

            previous = data;
        }
Esempio n. 2
0
        protected void LoopScan()
        {
            KBData data = this.Read();

            if (previous == null)
            {
                previous = data;
            }

            #region Panic: All Notes Off (Select, Home and Start together)
            if (data.SelectMinus && data.Home && data.StartPlus && !holdPanic)
            {
                holdPanic = true;
                int max = (8 * 12) + 25;
                for (int i = 0; i < max; i++)
                {
                    MIDI.SendNoteOff(1, i);
                }
                for (int i = 0; i < map_drum.Length; i++)
                {
                    MIDI.SendNoteOff(10, map_drum[i]);
                }
            }
            else if (!data.SelectMinus && !data.Home && !data.StartPlus && holdPanic)
            {
                holdPanic = false;
            }
            #endregion

            #region Dpad (Drum / Swap / Pedal)
            if (data.Dpad == 0 && !holdDpad)   //Up - Drum Mapping
            {
                holdDpad = true;
                SetDrumMapping(!drumMapping);

                if (enableLED)
                {
                    if (drumMapping)
                    {
                        this.SetLED(8, true);
                    }
                    else
                    {
                        this.SetLED(1, true);
                    }
                }
            }
            else if (data.Dpad == 4 && !holdDpad)     //Down - Swap Modulation / Pitch Bend
            {
                holdDpad = true;
                SetModPitchBend(!swapModPitchBend);
            }
            else if (data.Dpad == 6 && !holdDpad)     //Left - Reset Pitch Bend
            {
                holdDpad = true;
                MIDI.SendPitchBend(1, 8192);
            }
            else if (data.Dpad == 2 && !holdDpad)     //Right - Reset Modulation
            {
                holdDpad = true;
                MIDI.SendModulation(1, 0);
            }
            else if (data.Dpad == 8 && holdDpad)
            {
                holdDpad = false;
            }

            if (data.Pedal && !holdPedal)
            {
                holdPedal = true;
                MIDI.SendModulation(1, 127);
            }
            else if (!data.Pedal && holdPedal)
            {
                MIDI.SendModulation(1, 0);
                holdPedal = false;
            }
            #endregion

            #region Program
            if (data.Triangle2 && !holdProgram)
            {
                holdProgram = true;
                SetProgram(instrument + 1);
                if (enableLED)
                {
                    new Thread(() => this.LEDAnimateLTR()).Start();
                }
            }
            else if (data.CrossA && !holdProgram)
            {
                holdProgram = true;
                SetProgram(instrument - 1);
                if (enableLED)
                {
                    new Thread(() => this.LEDAnimateRTL()).Start();
                }
            }
            else if (!data.Triangle2 && !data.CrossA && holdProgram)
            {
                holdProgram = false;
            }
            #endregion

            #region Octave
            if (data.CircleB && !holdOctave)
            {
                holdOctave = true;
                SetOctave(octave + 1);
                if (enableLED)
                {
                    new Thread(() => this.LEDAnimateLTR()).Start();
                }
            }
            else if (data.Square1 && !holdOctave)
            {
                holdOctave = true;
                SetOctave(octave - 1);
                if (enableLED)
                {
                    new Thread(() => this.LEDAnimateRTL()).Start();
                }
            }
            else if (!data.CircleB && !data.Square1 && holdOctave)
            {
                holdOctave = false;
            }
            #endregion

            #region Keys
            for (int i = 0; i < data.Key.Length; i++)
            {
                if (data.Key[i] && !previous.Key[i])
                {
                    int pitch = (octave * 12) + i;

                    //Probably only correct when only pressing keys further right of already pressed keys.
                    int velocity = 80;
                    for (int v = data.Velocity.Length - 1; v >= 0; v--)
                    {
                        if (data.Velocity[v] != 0)
                        {
                            velocity = data.Velocity[v];
                            break;
                        }
                    }

                    if (i < map_drum.Length && drumMapping)
                    {
                        HeldKey.Add(i, new Tuple <int, int>(10, map_drum[i])); //Send on channel 10
                        MIDI.SendNoteOn(10, map_drum[i], velocity);
                    }
                    else
                    {
                        HeldKey.Add(i, new Tuple <int, int>(1, pitch));
                        MIDI.SendNoteOn(1, pitch, velocity);
                    }
                }
                else if (!data.Key[i] && previous.Key[i] && HeldKey.ContainsKey(i))
                {
                    MIDI.SendNoteOff(HeldKey[i].Item1, HeldKey[i].Item2);
                    HeldKey.Remove(i);
                }
            }
            #endregion

            #region Slider and Overdrive (Pitch Bend and Modulation)
            if (data.Slider != previous.Slider)
            {
                if ((data.Overdrive && !swapModPitchBend) || (!data.Overdrive && swapModPitchBend))
                {
                    if (data.Slider == 0 && pitchIgnoreZero)
                    {
                        //Ignore
                    }
                    else if (data.Slider == 50 || data.Slider == 0)
                    {
                        MIDI.SendPitchBend(1, 8192);
                    }
                    else
                    {
                        MIDI.SendPitchBend(1, (data.Slider * 140));
                    }
                }
                else
                {
                    if (data.Slider == 0 && modIgnoreZero)
                    {
                        //Ignore
                    }
                    else
                    {
                        MIDI.SendModulation(1, data.Slider);
                    }
                }
            }
            #endregion

            //if (data.Home != previous.Home) Console.WriteLine(data.Home);

            previous = data;
        }