Beispiel #1
0
        /// <summary>
        /// Begin monitoring MIDI messages. You must implement the handler manually.
        /// Before this method is called, add your handler with:
        /// [InstanceOfMidiMonitor].MidiInDevice.MessageReceived += new EventHandler<MidiInMessageEventArgs>([HandlerMethod]);
        /// </summary>
        public void StartMidiMonitoring()
        {
            if (MidiInDevice == null)
            {
                throw new InvalidOperationException("No MIDI device selected.");
            }

            MidiInDevice.Start();
            Monitoring = true;
        }
Beispiel #2
0
        //add device
        static void addDevice(uint port)
        {
            //create reference to RtMidi device
            IntPtr reference = MidiInternal.rtmidi_in_create_default();

            //get port count
            //not using GetPortCount to avoid creating another RtMididevice
            uint count = MidiInternal.rtmidi_get_port_count(reference);

            //check if port number is invalid
            if (port >= count)
            {
                //send error
                Debug.LogError(string.Format("Port Number {0} cannot be used for Midi Input!\nPort range 0-{1}", port,
                                             count - 1));
                //free reference
                freeHandle(reference);

                //quit
                return;
            }

            //get port name
            string name = MidiInternal.rtmidi_get_port_name(reference, port);

            //ignore types
            MidiInternal.rtmidi_in_ignore_types(reference, false, false, false);

            //add port to RtMidi device
            MidiInternal.rtmidi_open_port(reference, port, "LopeaMidi port: " + name);

            //create midi input handle
            MidiInDevice device = new MidiInDevice(port, reference, name);

            //add to array
            if (currdevices == null)
            {
                currdevices    = new MidiInDevice[1];
                currdevices[0] = device;
            }
            else
            {
                var newdevices = new MidiInDevice[currdevices.Length + 1];
                for (int i = 0; i < currdevices.Length; i++)
                {
                    newdevices[i] = currdevices[i];
                }
                newdevices[currdevices.Length] = device;
                currdevices = newdevices;
            }
        }
Beispiel #3
0
 /// <summary>
 /// Dispose of an instance of this class.
 /// </summary>
 public void Dispose()
 {
     if (MidiInDevice != null)
     {
         StopMidiMonitoring();
         try
         {
             MidiInDevice.Dispose();
         }
         finally
         {
             MidiInDevice = null;
         }
     }
 }
Beispiel #4
0
 /// <summary>
 /// Stop monitoring MIDI messages. Before calling this method, remove your handler method with:
 /// [InstanceOfMidiMonitor].MidiInDevice.MessageReceived -= EventHandler<MidiInMessageEventArgs>([HandlerMethod]);
 /// </summary>
 public void StopMidiMonitoring()
 {
     try
     {
         MidiInDevice.Stop();
     }
     catch
     {
         SelectedDevice = null;
     }
     finally
     {
         Monitoring = false;
     }
 }
Beispiel #5
0
        public void initialize()
        {
            int outDeviceCount = midiOutGetNumDevs();

            for (int i = 0; i < outDeviceCount; i++)
            {
                MidiOutCaps moc = new MidiOutCaps();
                midiOutGetDevCaps(i, ref moc, (int)Marshal.SizeOf(typeof(MidiOutCaps)));
                MidiOutDevice outDev = new MidiOutDevice(i, moc);
                outDeviceList.Add(outDev);
            }
            int inDeviceCount = midiInGetNumDevs();

            for (int i = 0; i < inDeviceCount; i++)
            {
                MidiInCaps mic = new MidiInCaps();
                midiInGetDevCaps(i, ref mic, (int)Marshal.SizeOf(typeof(MidiInCaps)));
                MidiInDevice inDev = new MidiInDevice(i, mic);
                inDeviceList.Add(inDev);
            }
        }