static uint GetCurrentPortCount() { IntPtr handle = MidiInternal.rtmidi_out_create_default(); //get port count uint count = MidiInternal.rtmidi_get_port_count(handle); //free handle FreeHandle(handle); return(count); }
/// <summary> /// Get the number of midi devices available /// </summary> /// <returns>Number of MIDI devices connected.</returns> public static uint GetPortCount() { //create RTMidiDevice IntPtr handle = MidiInternal.rtmidi_in_create_default(); //get port count uint count = MidiInternal.rtmidi_get_port_count(handle); //free handle freeHandle(handle); return(count); }
//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; } }