Add basic MIDI mapping facility
As discussed in this Zulip topic, Matt cox was looking for a way to have Ableton Link become the tempo master in response to a MIDI event. I pointed him at relevant sample code by which he could implement this, but realized it would be a much lighter lift for people in similar situations if I added a lightweight MIDI mapping facility to BLT itself.
Here’s what I’m thinking:
- Add a MIDI Mappings menu item, probably at the bottom of the Triggers menu.
- It opens a window with a list of existing mappings, and an Add button.
- To add a mapping, you pick an existing MIDI input, choose a message and channel, and then edit an expression.
- In the list of mappings, any missing devices get flagged Not found like in the Triggers window.
- The expression gets called with
device,channel,noteorcontroller, andvelocityorvalue(you can use either of the synonyms in your code, whichever best reflects the kind of message you expect to receive). You also getglobals, the trigger globals atom, in case you want to interact with it. - At startup, and as MIDI devices are attached, we set up event handlers that scan the mapping list and invoke any matching expressions.
After reviewing the UI and the code some, I decided a better approach would be to add these as a new kind of trigger to the main Triggers window, in the way that Show windows support both tracks and phrase triggers. The refined idea was:
- The Triggers menu would have a New Inbound MIDI Trigger option.
- All such triggers would be at the bottom of the trigger list, with a slightly different color background, and different UI that allowed configuring and learning the incoming message, as well as editing the expression(s) to run for note-on and note-off events.
- We’d have to hook up the expression editors to the window’s close logic, and support the loading and saving of these new types of triggers in a separate section of the preferences for backwards compatibility.
Thinking about all that, and the work needed to hook up the MIDI event handling, made it clear this was going to be a major project, with some significant and risky surgery to the existing functionality, for a pretty small edge use case, so I was thinking I might punt it. But then I had a better idea.
Almost all of this functionality is already implemented in the context of the Beat Pattern UI integration example show file. I can just pull out the parts I need into a simpler show file, and the idea can be you make as many copies of this show file as you need inbound MIDI mappings, and open and configure them, and you are done. Much easier and safer for me to implement, and no risk to people who don’t need the capability. I will pursue that route.
This is now published and documented.