Esempio n. 1
0
        internal MidiTimeCodeMessage(byte[] rawData, TimeSpan timestamp)
        {
            MidiMessageValidators.VerifyMessageLength(rawData, 2, Type);
            MidiMessageValidators.VerifyMessageType(rawData[0], Type);
            MidiMessageValidators.VerifyRange(MidiHelpers.GetFrame(rawData[1]), MidiMessageParameter.Frame);
            MidiMessageValidators.VerifyRange(MidiHelpers.GetFrameValues(rawData[1]), MidiMessageParameter.FrameValues);

            _buffer   = new Storage.Streams.Buffer(rawData);
            Timestamp = timestamp;
        }
Esempio n. 2
0
        internal MidiChannelPressureMessage(byte[] rawData, TimeSpan timestamp)
        {
            MidiMessageValidators.VerifyMessageLength(rawData, 2, MidiMessageType.ChannelPressure);
            MidiMessageValidators.VerifyMessageType(rawData[0], MidiMessageType.ChannelPressure);
            MidiMessageValidators.VerifyRange(MidiHelpers.GetChannel(rawData[0]), MidiMessageParameter.Channel);
            MidiMessageValidators.VerifyRange(rawData[1], MidiMessageParameter.Pressure);

            _buffer   = new Storage.Streams.Buffer(rawData);
            Timestamp = timestamp;
        }
Esempio n. 3
0
        internal MidiNoteOnMessage(byte[] rawData, TimeSpan timestamp)
        {
            MidiMessageValidators.VerifyMessageLength(rawData, 3, Type);
            MidiMessageValidators.VerifyMessageType(rawData[0], Type);
            MidiMessageValidators.VerifyRange(MidiHelpers.GetChannel(rawData[0]), MidiMessageParameter.Channel);
            MidiMessageValidators.VerifyRange(rawData[1], MidiMessageParameter.Note);
            MidiMessageValidators.VerifyRange(rawData[2], MidiMessageParameter.Velocity);

            _buffer   = new Storage.Streams.Buffer(rawData);
            Timestamp = timestamp;
        }
Esempio n. 4
0
        /// <summary>
        /// Gets all MIDI resources needed to use the selected device.
        /// </summary>
        private void Acquire(LPM.MidiDevice device)
        {
            if (device != null)
            {
                // setup the input device
                if (device.CanRead)
                {
                    _inputEndpoint = null;
                    for (var i = 0; i < MonoMac.CoreMidi.Midi.SourceCount; i++)
                    {
                        MidiEndpoint dest = MidiEndpoint.GetSource(i);
                        if (GetDeviceID(dest) == device.ID)
                        {
                            _inputEndpoint = dest;
                            break;
                        }
                    }

                    if (_inputEndpoint == null)
                    {
                        throw new Exception("Could not find MIDI input device " + device.ID);
                    }


                    // setup the device
                    _inputPort.ConnectSource(_inputEndpoint);

                    // send all input events to Receive()
                    _inputPort.MessageReceived += (object sender, MidiPacketsEventArgs e) =>
                    {
                        for (var i = 0; i < e.Packets.Length; i++)
                        {
                            var packet       = e.Packets[i];
                            var managedArray = new byte[packet.Length];
                            Marshal.Copy(packet.Bytes, managedArray, 0, packet.Length);
                            if (managedArray.Length >= 3)
                            {
                                MidiMessageType type;
                                int             channel;
                                MidiHelpers.ParseTypeAndChannel(managedArray[0], out type, out channel);

                                Receive(new MidiMessage()
                                {
                                    //Type = managedArray[0].GetMidiMessageType(),
                                    //Channel = 0,
                                    Type     = type,
                                    Channel  = channel,
                                    Pitch    = (int)managedArray[1],
                                    Velocity = (int)managedArray[2]
                                });
                            }
                        }
                    };
                }
                else
                {
                    _inputEndpoint = null;
                }

                if (device.CanWrite)
                {
                    _outputEndpoint = null;
                    for (var i = 0; i < MonoMac.CoreMidi.Midi.DestinationCount; i++)
                    {
                        MidiEndpoint dest = MidiEndpoint.GetDestination(i);
                        if (GetDeviceID(dest) == device.ID)
                        {
                            _outputEndpoint = dest;
                            break;
                        }
                    }

                    if (_outputEndpoint == null)
                    {
                        throw new Exception("Could not find MIDI output device " + device.ID);
                    }
                }
                else
                {
                    _outputEndpoint = null;
                }
            }
        }