Ejemplo n.º 1
0
    /*
     * Getting midi signals from outside and process it
     */
    private void _ReceiveMidiEvents(List<SmfLite.MidiEvent> events)
    {
        if( events == null ) {
            return;
        }
        while( m_midimsgs.Count > nMsgs ) {
            m_midimsgs.Dequeue();
        }

        foreach(SmfLite.MidiEvent e in events ) {
            // Parse the message.
            var message = new MidiBridge.Message (e.status, e.data1, e.data2);
            m_midimsgs.Enqueue(message);

            // 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.0f;
                channelArray [channelNumber].noteArray [message.data1] = velocity;
                channelArray [(int)MidiChannel.All].noteArray [message.data1] = velocity;
            }

            // Note off message?
            if (statusCode == 8 || (statusCode == 9 && message.data2 == 0)) {
                channelArray [channelNumber].noteArray [message.data1] = -1.0f;
                channelArray [(int)MidiChannel.All].noteArray [message.data1] = -1.0f;
            }

            // CC message?
            if (statusCode == 0xb) {
                // Normalize the value.
                var value = 1.0f / 127 * message.data2;

                // Update the channel if it already exists, or add a new channel.
                if (channelArray [channelNumber].knobMap.ContainsKey (message.data1)) {
                    channelArray [channelNumber].knobMap [message.data1].Update (value);
                } else {
                    channelArray [channelNumber].knobMap [message.data1] = new KnobState (value);
                }

                // Do again for All-ch.
                if (channelArray [(int)MidiChannel.All].knobMap.ContainsKey (message.data1)) {
                    channelArray [(int)MidiChannel.All].knobMap [message.data1].Update (value);
                } else {
                    channelArray [(int)MidiChannel.All].knobMap [message.data1] = new KnobState (value);
                }
            }
        }
    }
Ejemplo n.º 2
0
    /*
     * Getting midi signals from outside and process it
     */
    private void _ReceiveMidiEvents(List <SmfLite.MidiEvent> events)
    {
        if (events == null)
        {
            return;
        }
        while (m_midimsgs.Count > nMsgs)
        {
            m_midimsgs.Dequeue();
        }

        foreach (SmfLite.MidiEvent e in events)
        {
            // Parse the message.
            var message = new MidiBridge.Message(e.status, e.data1, e.data2);
            m_midimsgs.Enqueue(message);

            // 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.0f;
                channelArray [channelNumber].noteArray [message.data1]        = velocity;
                channelArray [(int)MidiChannel.All].noteArray [message.data1] = velocity;
            }

            // Note off message?
            if (statusCode == 8 || (statusCode == 9 && message.data2 == 0))
            {
                channelArray [channelNumber].noteArray [message.data1]        = -1.0f;
                channelArray [(int)MidiChannel.All].noteArray [message.data1] = -1.0f;
            }

            // CC message?
            if (statusCode == 0xb)
            {
                // Normalize the value.
                var value = 1.0f / 127 * message.data2;

                // Update the channel if it already exists, or add a new channel.
                if (channelArray [channelNumber].knobMap.ContainsKey(message.data1))
                {
                    channelArray [channelNumber].knobMap [message.data1].Update(value);
                }
                else
                {
                    channelArray [channelNumber].knobMap [message.data1] = new KnobState(value);
                }

                // Do again for All-ch.
                if (channelArray [(int)MidiChannel.All].knobMap.ContainsKey(message.data1))
                {
                    channelArray [(int)MidiChannel.All].knobMap [message.data1].Update(value);
                }
                else
                {
                    channelArray [(int)MidiChannel.All].knobMap [message.data1] = new KnobState(value);
                }
            }
        }
    }