public static bool Initialize() { if (_initialized) { return(true); } var portCount = MidiInput.GetPortCount(); if (portCount == 0) { return(false); } devices = new IntPtr[portCount]; for (uint i = 0; i < portCount; i++) { devices[i] = MidiInternal.rtmidi_in_create_default(); MidiInternal.rtmidi_in_ignore_types(devices[i], true, false, false); MidiInternal.rtmidi_open_port(devices[i], i, "Why am i doing this? " + i); } startTime = EditorApplication.timeSinceStartup; EditorApplication.update += Update; EditorApplication.playModeStateChanged += EditorApplicationOnplayModeStateChanged; _initialized = true; return(true); }
// Start is called before the first frame update void Start() { circles = new List <CircleData>(); circles.Add(new CircleData(0, center)); ptr = MidiInternal.rtmidi_in_create_default(); o = MidiInternal.rtmidi_out_create_default(); MidiInternal.rtmidi_open_port(ptr, 2, "da."); MidiInternal.rtmidi_open_port(o, 2, "yus."); // StartCoroutine(getdata()); }
/// <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; } }
//add device static MidiInDevice CreateDevice(uint port) { //create reference to RtMidi device IntPtr reference = MidiInternal.rtmidi_in_create_default(); //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 return(new MidiInDevice(port, reference, name)); }
/// <summary> /// Gets the name of the port based on the port number given. /// </summary> /// <param name="port">port number to find the name of.</param> /// <returns></returns> public static string GetPortName(uint port) { //check if the value exists... if (port >= portCount) { //if not, print error and return nothing. Debug.LogError("MIDI port given does not exist when trying to find port name!"); return(string.Empty); } //if the system has not been initialized... if (!_initialized) { //create a reference to the port IntPtr refPort = MidiInternal.rtmidi_in_create_default(); //get name string name = MidiInternal.rtmidi_get_port_name(refPort, port); //free port freeHandle(refPort); return(name); } //system has already been initialized, get port name from device return(currdevices[port].name); }