public static void Initialize() { if (_init) { return; } //both midi in and midi out have the same ports uint portCount = MidiInput.GetPortCount(); //check if there are no midi devices available if (portCount == 0) { //print warning Debug.LogError("MIDIOUT: No Midi Output Devices Found!"); //leave return; } //setup output device handles OutPorts = new IntPtr[portCount]; for (uint i = 0; i < portCount; i++) { OutPorts[i] = MidiInternal.rtmidi_out_create_default(); MidiInternal.rtmidi_open_port(OutPorts[i], i, "LopeaMidi: Out " + i); } _handler = new GameObject("Midi Output"); _handler.hideFlags = HideFlags.HideInHierarchy; _handler.AddComponent <MidiOutput>(); _init = true; }
//Inside this update function is the hotswapping support for MIDI output devices. void Update() { uint current = GetCurrentPortCount(); if (current != portCount) { if (current == 0) { Shutdown(); } else { for (int i = 0; i < OutPorts.Length; i++) { MidiInternal.rtmidi_out_free(OutPorts[i]); OutPorts[i] = IntPtr.Zero; } count = current; OutPorts = new IntPtr[portCount]; for (uint i = 0; i < portCount; i++) { OutPorts[i] = MidiInternal.rtmidi_out_create_default(); MidiInternal.rtmidi_open_port(OutPorts[i], i, "LopeaMidi: Out " + i); } } } }
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()); }
//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)); }