Ejemplo n.º 1
0
        public int[] GetKnobNumbers(MidiChannel channel)
        {
            MidiDriver.Refresh();
            var cs      = _channelArray[(int)channel];
            var numbers = new int[cs._knobMap.Count];

            cs._knobMap.Keys.CopyTo(numbers, 0);
            return(numbers);
        }
Ejemplo n.º 2
0
        public int GetSysex(MidiSysex id)
        {
            MidiDriver.Refresh();

            int index = (int)id;

            if (index >= _sysexMem.Length)
            {
                return(0);
            }

            return(_sysexMem[index]);
        }
Ejemplo n.º 3
0
        public float GetKey(MidiChannel channel, int noteNumber)
        {
            MidiDriver.Refresh();
            var v = _channelArray[(int)channel]._noteArray[noteNumber];

            if (v > 1)
            {
                return(v - 1);
            }
            if (v > 0)
            {
                return(v);
            }
            return(0.0f);
        }
Ejemplo n.º 4
0
        public float GetKnob(MidiChannel channel, int knobNumber, float defaultValue)
        {
            MidiDriver.Refresh();
            var cs = _channelArray[(int)channel];

            if (_midiMap)
            {
                knobNumber = _midiMap.JackValue(knobNumber);
            }
            if (cs._knobMap.ContainsKey(knobNumber))
            {
                return(cs._knobMap[knobNumber]);
            }
            return(defaultValue);
        }
Ejemplo n.º 5
0
        void Update()
        {
            Refresh();

            // Update the note state array.
            foreach (var cs in _channelArray)
            {
                for (var i = 0; i < 128; i++)
                {
                    var x = cs._noteArray[i];
                    if (x > 1)
                    {
                        cs._noteArray[i] = x - 1; // Key down -> Hold.
                    }
                    else if (x < 0)
                    {
                        cs._noteArray[i] = 0; // Key up -> Off.
                    }
                }
            }

            MidiDriver.Refresh();

            // Process the message queue.
            while (true)
            {
                if (msgQueue.Count == 0)
                {
                    break;
                }

                // Pop from the queue.
                MidiMessage message = msgQueue.Dequeue();

                // Split the first byte.
                var statusCode    = message.status >> 4;
                var channelNumber = message.status & 0xf;

                // Note on message?
                if (statusCode == 9)
                {
                    var velocity = 1.0f / 127 * message.data2 + 1;
                    _channelArray[channelNumber]._noteArray[message.data1]        = velocity;
                    _channelArray[(int)MidiChannel.All]._noteArray[message.data1] = velocity;
                    if (noteOnDelegate != null)
                    {
                        noteOnDelegate((MidiChannel)channelNumber, message.data1, velocity - 1);
                    }
                }

                // Note off message?
                if (statusCode == 8 || (statusCode == 9 && message.data2 == 0))
                {
                    _channelArray[channelNumber]._noteArray[message.data1]        = -1;
                    _channelArray[(int)MidiChannel.All]._noteArray[message.data1] = -1;
                    if (noteOffDelegate != null)
                    {
                        noteOffDelegate((MidiChannel)channelNumber, message.data1);
                    }
                }

                // CC message?
                if (statusCode == 0xb)
                {
                    // Normalize the value.
                    var level = 1.0f / 127 * message.data2;
                    // Update the channel if it already exists, or add a new channel.
                    int knobNumber = message.data1;
                    if (_midiMap)
                    {
                        knobNumber = _midiMap.JackValue(knobNumber);
                    }
                    _channelArray[channelNumber]._knobMap[knobNumber] = level;
                    // Do again for All-ch.
                    _channelArray[(int)MidiChannel.All]._knobMap[knobNumber] = level;
                    if (knobDelegate != null)
                    {
                        knobDelegate((MidiChannel)channelNumber, knobNumber, level);
                    }
                }

                // System message?
                if (statusCode == 0xf)
                {
                    if (channelNumber == 0)
                    {
                        if (message.data1 >= _sysexMem.Length)
                        {
                            return;
                        }

                        _sysexMem[message.data1] = message.data2;

                        if (sysexDelegate != null)
                        {
                            sysexDelegate((MidiSysex)message.data1, message.data2);
                        }
                    }
                    else
                    {
                        if (message.status == (byte)MidiRealtime.Clock)
                        {
                            if (realtimeDelegate != null)
                            {
                                realtimeDelegate(MidiRealtime.Clock);
                            }
                        }

                        if (message.status == (byte)MidiRealtime.Start)
                        {
                            _isPlaying = true;

                            if (realtimeDelegate != null)
                            {
                                realtimeDelegate(MidiRealtime.Start);
                            }
                        }

                        if (message.status == (byte)MidiRealtime.Continue)
                        {
                            _isPlaying = true;

                            if (realtimeDelegate != null)
                            {
                                realtimeDelegate(MidiRealtime.Continue);
                            }
                        }

                        if (message.status == (byte)MidiRealtime.Stop)
                        {
                            _isPlaying = false;

                            if (realtimeDelegate != null)
                            {
                                realtimeDelegate(MidiRealtime.Stop);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
 public bool IsPlaying()
 {
     MidiDriver.Refresh();
     return(_isPlaying);
 }
Ejemplo n.º 7
0
 public bool GetKeyUp(MidiChannel channel, int noteNumber)
 {
     MidiDriver.Refresh();
     return(_channelArray[(int)channel]._noteArray[noteNumber] < 0);
 }