Working with MIDI in Unreal Engine Blueprint

Unreal Engine 4 have built-in support for working with MIDI using a built-in plugin.
We will discuss how to work with it for receiving MIDI events in your UE project.

Note: Sending MIDI messages is declared, but it's unknown how to do it with this plugin, so actually only receiving MIDI events working for now.

We will see how to obtain MIDI events from sliders, faders and buttons from MIDI controllers such as Korg Nano Kontrol or Novation Launch Pad or software such as Ableton Live into your UE project.

Preliminary note: If you need to pass MIDI events from Ableton Live to UE scene in Windows, you need to create virtual MIDI port using free app loopMIDI. On Mac OS virtual MIDI port can be created inside Ableton Live.

изображение.png

Working with MIDI in UE is simple, because it has built-in plugin for this purpose. So, let's start.

1. Activate MIDI plugin
Go to UE's menu Edit - Plugins and activate MIDI Device Support plugin, and then restart the UE Editor.

изображение.png


2. Show list of MIDI devices on the screen

Open Level Blueprint and create there the following patch:
изображение.png


Connect it to Event BeginPlay (all other pathces in this article should be connected there too):

изображение.png


When running the UE project, you should see list of available MIDI devices on the screen:

изображение.png

Please take note on DeviceIDs - this identifiers will be used later to specify which device you want to connect to you UE project.

Note: You may increase Duration value in PrintString node to see the messages for a longer time.


3. Connect to MIDI device
Before making patch for connecting, we must to create a special variable, let's call it MidiDevice:

изображение.png

Set its type MIDIDevice Controller:
изображение.png

This variable will hold link on our MIDI device. Without storing it in a variable, UE Garbage Collector will destroy it after about one minute.
Now, we are ready to make a patch for connecting:

изображение.png

Hint: To create Bind Event to OnMIDIEvent use context node creation: drag a new wire from right blue SET Midi Deice pin, and when dropped, in appeared context menu print Bind - then you see the desired node.

Important note: you must set Device ID to your desired device's ID, shown on the screen above.

4. Receiving data from MIDI device

Make this patch and connect it to Event pin of Bind Event to OnMidiEvent node:

изображение.png

Hint: To create MIDI_Event use context node creation again: drag a new wire from Event and then drop, and in appeared context menu select Custom Event.

This patch prints received values on the screen:

5. Managing events
As you see, each event has channel, control's number and value.
To manage this, let's use Switch on String for performing actions depending on the control's number.

In the following patch we use control 0 for chaging value of a SomeValue. Also we converting MIDI values from its original range 0..127 into float number in a range 0..20:


изображение.png


You can change pins of Switch On String by editing its settings:

Each output pin fires when UE project receives MIDI value from specified control:

изображение.png

So, you can use it for controlling values, moving objects and even starting timelines:
изображение.png

Comments

Popular posts from this blog

Computing ray origin and direction from Model View Projection matrices for raymarching

Forward and backward alpha blending for raymarching

Forward, Deferred and Raytracing rendering in openFrameworks and web