Last active
August 14, 2021 02:32
-
-
Save kshoji/c4b7ea9b2af0be7f21d148ed54d9564c to your computer and use it in GitHub Desktop.
MIDI Plugin for Mobile devices examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void OnMidiInputDeviceAttached(string deviceId) | |
{ | |
// will be called when a new Input device connected | |
// Input device can receive MIDI events | |
} | |
public void OnMidiOutputDeviceAttached(string deviceId) | |
{ | |
// will be called when a new Output device connected | |
// Output device can send MIDI events | |
Debug.Log($"MIDI device attached. deviceId: {deviceId}, name: {MidiManager.Instance.GetDeviceName(deviceId)}"); | |
} | |
public void OnMidiInputDeviceDetached(string deviceId) | |
{ | |
// will be called when a Input device disconnected | |
} | |
public void OnMidiOutputDeviceDetached(string deviceId) | |
{ | |
// will be called when a Output device disconnected | |
Debug.Log($"MIDI device detached. deviceId: {deviceId}, name: {MidiManager.Instance.GetDeviceName(deviceId)}"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void Awake() | |
{ | |
// Register an GameObject to receive MIDI events | |
MidiManager.Instance.RegisterEventHandleObject(gameObject); | |
// Initialize MidiManager | |
MidiManager.Instance.InitializeMidi(() => | |
{ | |
// Start to scan Bluetooth LE MIDI devices | |
MidiManager.Instance.StartScanBluetoothMidiDevices(0); // 0: scans infinite | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MidiSampleScene : MonoBehaviour, IMidiNoteOnEventHandler, IMidiDeviceEventHandler | |
{ | |
// Event Handler called on MIDI Note On event received | |
public void OnMidiNoteOn(string deviceId, int group, int channel, int note, int velocity) | |
{ | |
Debug.Log($"OnMidiNoteOn channel: {channel}, note: {note}, velocity: {velocity}"); | |
} | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (GUILayout.Button("NoteOn")) | |
{ | |
// Sending MIDI Note On event when the button clicked | |
MidiManager.Instance.SendMidiNoteOn(deviceIds[deviceIdIndex], 0, channel, noteNumber, velocity); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment