Updated Unity MIDI control
More information and the project code can be found on Github or BitBucket.
UPDATED: This plugin now uses keijiro’s MIDI Jack as a backend, removing the need to run the third-party software MIDI Bridge required by the previous version.
This Unity interface allows you to map MIDI inputs to keyboard buttons - play the mapped input on your instrument to trigger the corresponding key press.
The interface currently supports GetKey
, GetKeyDown
and GetKeyUp
events for all keyboard buttons.
Direct button presses (i.e., using the keyboard rather than a mapped instrument) will still be detected.
Example Use
The following note mappings trigger:
- the ‘x’ key when note number 36 is played on any MIDI channel
- the ‘d’ key when note number 50 is played on MIDI channel 8
- the ‘a’ key when a control knob on channel 22 has a value between 3 (exclusive) and 75 (inclusive) on any MIDI channel
- the ‘b’ key when a control knob on channel 31 has a value between 50 (exclusive) and 100 (inclusive) on MIDI channel 3
These keypresses may be detected programmatically using the following code:
if (UnityMidiControl.Input.InputManager.GetKeyDown("x")) {
Debug.Log("'x' down");
}
if (UnityMidiControl.Input.InputManager.GetKeyDown("d")) {
Debug.Log("'d' down");
}
if (UnityMidiControl.Input.InputManager.GetKeyDown("a")) {
Debug.Log("'a' down");
}
if (UnityMidiControl.Input.InputManager.GetKeyDown("b")) {
Debug.Log("'b' down");
}
Using key codes rather than string arguments will also work:
if (UnityMidiControl.Input.InputManager.GetKeyUp(KeyCode.X)) {
Debug.Log("'x' up");
}
if (UnityMidiControl.Input.InputManager.GetKeyUp(KeyCode.D)) {
Debug.Log("'d' up");
}
if (UnityMidiControl.Input.InputManager.GetKeyUp(KeyCode.A)) {
Debug.Log("'a' up");
}
if (UnityMidiControl.Input.InputManager.GetKeyDown(Keycode.B)) {
Debug.Log("'b' down");
}