IEnumerator ConnectMidiOnStart() { yield return(new WaitUntil(() => MIDI.initialized )); try { for (int i = 0; i < MidiOUTPlugin.GetDeviceCount(); i++) { var deviceName = MidiOUTPlugin.GetDeviceName(i); MidiOUTPlugin.DisconnectDeviceByName(deviceName); //Debug.Log($"DisconnectMidiOut {deviceName}"); } for (int i = 0; i < MidiINPlugin.GetDeviceCount(); i++) { var deviceName = MidiINPlugin.GetDeviceName(i); if (!deviceName.Contains("Session")) { MidiINPlugin.ConnectDeviceByName(deviceName); //Debug.Log($"ConnectMidiIn {deviceName}"); break; } } } catch (Exception e) { Debug.LogWarning("ConnectMidiOnStart " + e); } }
public static int SendShortMessage(int aChannelCommand, int aData1, int aData2, bool through = false) { int channel = (aChannelCommand & 0x0F); int command = (aChannelCommand & 0xF0); // Debug.Log ("-----"); // Debug.Log (channel.ToString("X2")); // Debug.Log (command.ToString("X2")); // Debug.Log (aData1.ToString("X2")); // Debug.Log (aData2.ToString("X2")); // Debug.Log ("-----"); if (command == (int)CommandEnum.ProgramChange) { programEnums[channel] = (ProgramEnum)aData1; if (ignoreProgramMessages) { return(0); } } if (command.IsNoteON()) { channelCache[channel].notes[aData1].on = true; if (applyChannelVolumes) { aData2 = (int)(volumes[channel] * aData2); } } else if (command.IsNoteOFF()) { channelCache[channel].notes[aData1].on = false; } if (ShortMessageEvent != null && fireMidiOutEvents) { ShortMessageEvent(aChannelCommand, aData1, aData2); } if (muteMessages || through) { return(0); } else { if (((1 << channel) & synthChannelMask) != 0) { Synth.SendMidiMessage(aChannelCommand, aData1, aData2); } if (((1 << channel) & channelMask) != 0) { return(MidiOUTPlugin.SendShortMessage((byte)aChannelCommand, (byte)aData1, (byte)aData2)); } else { return(0); } } }
static void CleanUp() { MidiOut.AllPedalsOff(); MidiOut.AllSoundOff(); MidiOut.ResetAllControllers(); MidiINPlugin.DisconnectDevices(); MidiOUTPlugin.DisconnectDevices(); Synth.Stop(); }
void OnGUI() { if (GUILayout.Button("Send SYS EX")) { byte[] data = new byte[6] { 0xF0, 1, 2, 3, 4, 0xF7 }; MidiOUTPlugin.SendData(data); } GUILayout.Label("DATA :" + dataStr); }
IEnumerator Start() { yield return(new WaitUntil(() => MIDI.initialized )); MidiINPlugin.RestoreConnections(); MidiOUTPlugin.RestoreConnections(); Init(); }
void OnGUI() { if (window == null) { window = EditorWindow.GetWindow(typeof(MIDIEditor)) as MIDIEditor; oneFrameDelay = false; return; } if (!midiINInitialized || !midiOUTInitialized) { EditorGUILayout.HelpBox("Initializing MIDI. Please wait....", MessageType.Info); oneFrameDelay = false; return; } if (!oneFrameDelay) { oneFrameDelay = true; return; } if (!oneFrameDelay) { oneFrameDelay = true; EditorGUILayout.HelpBox("Waiting one frame...", MessageType.Info); return; } DrawINOUT(); if (GUILayout.Button("Clear")) { messages = ""; } scrollMessages = GUILayout.BeginScrollView(scrollMessages); messages = GUILayout.TextArea(messages, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); GUILayout.EndScrollView(); if (debug) { GUILayout.Label("Connected IN Devices : " + MidiINPlugin.GetConnectedDeviceCount().ToString()); GUILayout.Label("Connected OUT Devices : " + MidiOUTPlugin.GetConnectedDeviceCount().ToString()); } debug = GUILayout.Toggle(debug, "Debug"); }
public void OnDeviceClick(MidiSelectionUIDeviceButton button) { Debug.Log("Device : " + button.device.ToString() + " " + button.text.text); if (button.connected) { switch (button.device) { case MidiSelectionUIDeviceButton.Device.IN: MidiINPlugin.DisconnectDeviceByName(button.text.text); button.image.color = disconnectedColor; button.connected = false; MidiINPlugin.StoreConnections(); break; case MidiSelectionUIDeviceButton.Device.OUT: MidiOUTPlugin.DisconnectDeviceByName(button.text.text); button.image.color = disconnectedColor; button.connected = false; MidiOUTPlugin.StoreConnections(); break; } } else { switch (button.device) { case MidiSelectionUIDeviceButton.Device.IN: if (MidiINPlugin.ConnectDeviceByName(button.text.text) != null) { button.image.color = connectedColor; button.connected = true; MidiINPlugin.StoreConnections(); } break; case MidiSelectionUIDeviceButton.Device.OUT: if (MidiOUTPlugin.ConnectDeviceByName(button.text.text) != null) { button.image.color = connectedColor; button.connected = true; MidiOUTPlugin.StoreConnections(); } break; } } }
//static void OnTimer (object sender, System.Timers.ElapsedEventArgs e) //{ // Fetch (); //} //static void InitTimer () //{ // timer = new System.Timers.Timer (10); // timer.Elapsed += OnTimer; // timer.Start (); //} //static void FinalizeTimer () //{ // if (timer != null) { // timer.Stop (); // timer.Elapsed -= OnTimer; // timer.Dispose (); // } //} public static void Fetch() { MidiMessage midiMessage = new MidiMessage(); while (MidiINPlugin.PopMessage(out midiMessage) != 0) { midiInMessages.Enqueue(midiMessage); midiOutMessages.Enqueue(midiMessage); midiMessage = new MidiMessage(); } while (midiOutMessages.Count > 0) { if (midiOutMessages.TryDequeue(out midiMessage)) { MidiOUTPlugin.SendShortMessage(midiMessage.command, midiMessage.data1, midiMessage.data2); Synth.SendMidiMessage(midiMessage.command, midiMessage.data1, midiMessage.data2); midiMessage = new MidiMessage(); } } }
static void AutoInit() { if (!MidiINPlugin.initialized) { EditorDispatcher.StartThread((a) => { MidiINPlugin.Init(); MidiINPlugin.Refresh(); EditorDispatcher.Dispatch((b) => { MidiINPlugin.RestoreEditorConnections(); midiINInitialized = true; }, new { a = "" }); }, new { a = "" }); } else { midiINInitialized = true; } if (!MidiOUTPlugin.initialized) { EditorDispatcher.StartThread((a) => { MidiOUTPlugin.Init(); MidiOUTPlugin.Refresh(); EditorDispatcher.Dispatch((b) => { MidiOUTPlugin.RestoreEditorConnections(); midiOUTInitialized = true; }, new { a = "" }); }, new { a = "" }); } else { midiOUTInitialized = true; } EditorApplication.update -= EditorUpdate; EditorApplication.update += EditorUpdate; }
public void HandleClick() { try { //Debug.Log("HandleClick " + Button.name); if (Button.name.Contains("IN CONNECT")) { Debug.Log("MidiINPlugin.ConnectDeviceByName(" + Text.text + ")"); MidiINPlugin.ConnectDeviceByName(Text.text); } if (Button.name.Contains("IN DISCONNECT")) { Debug.Log("MidiINPlugin.DisconnectDeviceByName(" + Text.text + ")"); MidiINPlugin.DisconnectDeviceByName(Text.text); } if (Button.name.Contains("OUT CONNECT")) { Debug.Log("MidiOUTPlugin.ConnectDeviceByName(" + Text.text + ")"); MidiOUTPlugin.ConnectDeviceByName(Text.text); } if (Button.name.Contains("OUT DISCONNECT")) { Debug.Log("MidiOUTPlugin.DisconnectDeviceByName(" + Text.text + ")"); MidiOUTPlugin.DisconnectDeviceByName(Text.text); } GameObject.Find("PanelSetting").GetComponent <PanelSetting>().GetMidiInOut(); } catch (Exception e) { Debug.LogWarning("HandleClick " + e); } }
static IEnumerator InitMidiIO() { if (!MidiINPlugin.initialized) { MidiINPlugin.Init(); } yield return(new WaitUntil(() => MidiINPlugin.Initialized() )); if (!MidiOUTPlugin.initialized) { MidiOUTPlugin.Init(); } yield return(new WaitUntil(() => MidiOUTPlugin.Initialized() )); forceDefaultMidiIn = settings.forceDefaultMidiIn; defaultMidiIn = settings.defaultMidiIn; forceDefaultMidiOut = settings.forceDefaultMidiOut; defaultMidiOut = settings.defaultMidiOut; if (forceDefaultMidiIn) { if (defaultMidiIn >= 0 && defaultMidiIn < MidiINPlugin.GetDeviceCount()) { MidiINPlugin.ConnectDevice(defaultMidiIn); } } else { MidiINPlugin.RestoreConnections(); if (MidiINPlugin.connectedDevices.Count == 0) { if (defaultMidiIn >= 0 && defaultMidiIn < MidiINPlugin.GetDeviceCount()) { MidiINPlugin.ConnectDevice(defaultMidiIn); } } } if (forceDefaultMidiOut) { if (defaultMidiOut >= 0 && defaultMidiOut < MidiOUTPlugin.GetDeviceCount()) { MidiOUTPlugin.ConnectDevice(defaultMidiOut); } } else { MidiOUTPlugin.RestoreConnections(); if (MidiOUTPlugin.connectedDevices.Count == 0) { if (defaultMidiOut >= 0 && defaultMidiOut < MidiOUTPlugin.GetDeviceCount()) { MidiOUTPlugin.ConnectDevice(defaultMidiOut); } } } }
public static void RefreshMidiIO() { MidiINPlugin.Refresh(); MidiOUTPlugin.Refresh(); }
IEnumerator GetMidiOutIe() { yield return(new WaitUntil(() => MIDI.initialized )); listConnectedMidiOut = new List <string>(); //Debug.Log("MidiOUTPlugin.connectedDevices " + MidiOUTPlugin.connectedDevices.Count); foreach (MidiDevice md in MidiOUTPlugin.connectedDevices) { listConnectedMidiOut.Add(md.name); //Debug.Log("MidiINPlugin.connectedDevices " + md.name); } //Debug.LogWarning("GetMidiOutIe"); foreach (Transform child in PanelMidiOut.transform) { Destroy(child.gameObject); } var buttonNoMidi = Instantiate(ButtonMidi, Vector3.zero, Quaternion.identity); buttonNoMidi.transform.SetParent(PanelMidiOut.transform); buttonNoMidi.transform.localScale = Vector3.one; buttonNoMidi.name = "OUT No Midi Out Detected"; buttonNoMidi.GetComponentInChildren <Text>().text = "No Midi Out Detected"; var color = buttonNoMidi.GetComponent <Image>().color; color.a = 0.2f; buttonNoMidi.GetComponent <Image>().color = color; for (int i = 0; i < MidiOUTPlugin.GetDeviceCount(); i++) { if (MidiOUTPlugin.GetDeviceName(i).Contains("Session")) { continue; } buttonNoMidi.SetActive(false); var button = Instantiate(ButtonMidi, Vector3.zero, Quaternion.identity); button.transform.SetParent(PanelMidiOut.transform); button.transform.localScale = Vector3.one; button.GetComponentInChildren <Text>().text = MidiOUTPlugin.GetDeviceName(i).Trim(); if (listConnectedMidiOut.Contains(MidiOUTPlugin.GetDeviceName(i))) { button.name = "OUT DISCONNECT " + MidiOUTPlugin.GetDeviceName(i); color = button.GetComponent <Image>().color; color.a = 1f; button.GetComponent <Image>().color = color; } else { button.name = "OUT CONNECT " + MidiOUTPlugin.GetDeviceName(i); color = button.GetComponent <Image>().color; color.a = 0.2f; button.GetComponent <Image>().color = color; } //Debug.LogWarning(i + ". GetMidiOutIe " + MidiOUTPlugin.GetDeviceName(i) + ""); } }
void DrawINOUT() { backgroundColor = GUI.backgroundColor; int count = MidiINPlugin.deviceNames.Count > MidiOUTPlugin.deviceNames.Count ? MidiINPlugin.deviceNames.Count : MidiOUTPlugin.deviceNames.Count; if (count == 0) { EditorGUILayout.HelpBox("No MIDI connection found!!!", MessageType.Info); } float selectionHeight = count * (lineHeight + 5); float dialogHeight = selectionHeight + 65; Rect defaultRect = new Rect(0, 0, window.position.width, dialogHeight); GUI.BeginGroup(defaultRect); float width = defaultRect.width; float halfWidth = width / 2f; GUI.Box(new Rect(-5f, -5f, defaultRect.width + 10, defaultRect.height + 10), ""); GUILayout.BeginHorizontal(); GUILayout.Box("Midi IN", GUILayout.Width(halfWidth)); GUILayout.Box("Midi OUT", GUILayout.Width(halfWidth)); GUILayout.EndHorizontal(); GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(5)); bool exists = false; for (int i = 0; i < count; i++) { GUILayout.BeginHorizontal(); if (i < MidiINPlugin.deviceNames.Count) { exists = false; foreach (MidiDevice inDevice in MidiINPlugin.connectedEditorDevices) { if (MidiINPlugin.deviceNames [i] == inDevice.name) { exists = true; break; } } GUI.backgroundColor = exists ? Color.green : backgroundColor; if (GUILayout.Button(MidiINPlugin.deviceNames [i], GUILayout.Width(halfWidth), GUILayout.Height(lineHeight))) { if (exists) { MidiINPlugin.DisconnectDeviceByName(MidiINPlugin.deviceNames [i], true); } else { MidiINPlugin.ConnectDevice(i, true); } MidiINPlugin.StoreEditorConnections(); } GUI.backgroundColor = backgroundColor; } else { GUILayout.Label("", GUILayout.Width(halfWidth), GUILayout.Height(lineHeight)); } if (i < MidiOUTPlugin.deviceNames.Count) { exists = false; foreach (MidiDevice outDevice in MidiOUTPlugin.connectedEditorDevices) { if (MidiOUTPlugin.deviceNames [i] == outDevice.name) { exists = true; break; } } GUI.backgroundColor = exists ? Color.green : backgroundColor; if (GUILayout.Button(MidiOUTPlugin.deviceNames [i], GUILayout.Width(halfWidth), GUILayout.Height(lineHeight))) { if (exists) { MidiOUTPlugin.DisconnectDeviceByName(MidiOUTPlugin.deviceNames [i], true); } else { MidiOUTPlugin.ConnectDevice(i, true); } MidiOUTPlugin.StoreEditorConnections(); } GUI.backgroundColor = backgroundColor; } else { GUILayout.Label("", GUILayout.Width(halfWidth), GUILayout.Height(lineHeight)); } GUILayout.EndHorizontal(); } GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(5)); GUILayout.BeginHorizontal(); if (GUILayout.Button("Refresh", GUILayout.Width(halfWidth))) { MidiINPlugin.Refresh(); MidiOUTPlugin.Refresh(); } if (GUILayout.Button("Reset", GUILayout.Width(halfWidth))) { MidiOut.AllSoundOff(); MidiOut.ResetAllControllers(); } GUILayout.EndHorizontal(); GUI.EndGroup(); }
public static int SendData(byte[] aData) { return(MidiOUTPlugin.SendData(aData)); }
void Init() { foreach (MidiSelectionUIDeviceButton button in INs) { Destroy(button.gameObject); } INs = new List <MidiSelectionUIDeviceButton> (); foreach (MidiSelectionUIDeviceButton button in OUTs) { Destroy(button.gameObject); } OUTs = new List <MidiSelectionUIDeviceButton> (); int count = MidiINPlugin.deviceNames.Count > MidiOUTPlugin.deviceNames.Count ? MidiINPlugin.deviceNames.Count : MidiOUTPlugin.deviceNames.Count; _minHeight = count * (int)PREFAB_MidiDeviceButton.GetComponent <LayoutElement> ().preferredHeight + 100; if (_minHeight < minHeight) { _minHeight = minHeight; } _minWidth = minWidth; for (int i = 0; i < MidiINPlugin.GetDeviceCount(); i++) { var go = Instantiate(PREFAB_MidiDeviceButton); go.transform.SetParent(inPanel, false); MidiSelectionUIDeviceButton button = go.GetComponent <MidiSelectionUIDeviceButton> (); button.device = MidiSelectionUIDeviceButton.Device.IN; button.midiSelectionUI = this; button.text.text = MidiINPlugin.GetDeviceName(i); bool connected = false; foreach (MidiDevice device in MidiINPlugin.connectedDevices) { if (device.name == button.text.text) { connected = true; } } button.connected = connected; if (connected) { button.image.color = connectedColor; } else { button.image.color = disconnectedColor; } INs.Add(button); int preferredWidth = (int)button.text.preferredWidth; if (preferredWidth > _minWidth / 2) { _minWidth = 2 * preferredWidth; } } for (int i = 0; i < MidiOUTPlugin.GetDeviceCount(); i++) { var go = Instantiate(PREFAB_MidiDeviceButton); go.transform.SetParent(outPanel, false); MidiSelectionUIDeviceButton button = go.GetComponent <MidiSelectionUIDeviceButton> (); button.device = MidiSelectionUIDeviceButton.Device.OUT; button.midiSelectionUI = this; button.text.text = MidiOUTPlugin.GetDeviceName(i); bool connected = false; foreach (MidiDevice device in MidiOUTPlugin.connectedDevices) { if (device.name == button.text.text) { connected = true; } } button.connected = connected; if (connected) { button.image.color = connectedColor; } else { button.image.color = disconnectedColor; } OUTs.Add(button); int preferredWidth = (int)button.text.preferredWidth; if (preferredWidth > _minWidth / 2) { _minWidth = 2 * preferredWidth; } } _minWidth += 2 * widthMargin; //_minHeight += 2 * heightMargin; midiPanel.SetSize(new Vector2(_minWidth, _minHeight)); }