Midi was released in 1982 and is one of the most successful hardware communication protocols in the world. The simple nature of the protocol makes it easy to implement and even more important, easy to understand for humans.
This makes it a perfect example for the first event based library in VL using the MIDI-Toolkit developed by Leslie Sanford.
Instead of having all settings on one node, functionality is now separate to allow arbitrary combinations.
Device nodes have an enum input for the input/output device driver you want to use. You can have many of them, even for the same driver. Under the hood they will share the actual device driver resource. The driver is opened only if it is necessary, for example if there is an event sink listening to it.
The dynamic device enum will update as soon as a midi device is connected or disconnected to the machine. So no restart required on configuration change:
MidiIn has one observable output for all midi messages received on the given device. MidiOut has one input that accepts an observable to send midi messages to the given device.
Following the midi message structure, there are filters that allow you to select only the messages you are interested in. For example only midi clock messages, or messages on a specific midi channel:
For all midi message types there are specific nodes to read the message content or construct new messages. These are mostly the native methods of the MidiToolkit library.
You can process a midi message (in fact any event) directly as it occurs. The new ForEach region in the Reactive category executes it's patch for each event that is passed in and can transform the event into a different message type and decide whether to pass the current event on via the Keep output.
This is part of a bigger programming paradigm that was also polished for the new midi nodes. Definitely check out for the blog post on Reactive Programming.
At some point all async input event handling in the background will be over and you want to leave the observable world and have the processed values in the main loop. For that there are several options:
For supereasy controller value input there is ControllerState or NoteState:
For more advanced scenarios refer to the Reactive nodes HoldLatest, S+H or Sampler which provide ways to pass event values safely to the mainloop.
If you want to generate midi messages in the mainloop you also have a simple node that generates controller message events:
For other messages use the Reactive nodes ToObservable which create an event source that you can use to send events from the mainloop.
Since VL makes a difference between a single value and a spread of values, some nodes come in 'plural' version to allow listening for example for multiple channels at one.
wow that's massive! thanks!
wohoo, thrilled about reactive announcement
One question, shouldn't ControllerState also have a channel input?
EDIT: aaaaahh, ChannelFilter
@sunep yes, we had that at first but then decided against it because of more modularity and less complex nodes. Since most midi nodes are patched you can easily copy the Controller node and add the channel pin on your own if you need that often in a project.
..But how can I get a midi clock in?
hello @ddf seems i overlooked this. midi clock messages are called SystemRealtimeMessages. in latest alpha you also have the driver timestamp per message, this makes calculating the midi clock quite precise. i've planned to add an example to the midi lib on how to do this, i'll let you know.
hello @ddf upcoming alpha will have MidiClock in/out nodes. just wait a few days... if you want to handle the messages yourself, use the MessageSplitter and check the RealtimeMessages with a ForEach reactive for MessageType Clock...
Thanks @tonfilm !
Sending tones of midicontroller to a Device needs tones of cpu timings. I was wondering if i can do the midioutput as a asynctask or async loop. Maybe someone know how to build a midi out that runs async
more like this @ddf
anonymous user login