Do Midi Callbacks Actually Work?

Has anyone successfully used Midi callbacks in LUA scripting? I was easily able to get OSC working (which I’d consider more challenging), but midi callbacks won’t fire… I saw a similar thread (in beginners) so I’m starting to wonder if this is actually a bug. I used two of the examples from the Midi.lua snippet (first is procedural, the other is class based). I’m using Renoise 2.8.2 on Linux.

Many tools are using them, like for example Duplex. There was a bug with crippled MIDI sysex in Lua callbacks, but this got fixed for r3 too.
If you can share the tool you’re working on we maybe can help getting them work for you…

Great, that’s encouraging! Well, what I’m working on ultimately is a tool for performance of multiple songs controlled by a MIDI pedal (mentioned in another thread). Right now though, I’m just trying to experiment with MIDI in Renoise scripting to see how it works. For what it’s worth, I have programming experience and have worked with MIDI before. That being said I’ve never worked with Lua or Renoise tools, so it’s foreign to me. All I’ve tried to do so far is get the example code from the MIDI snippet to work. Here’s the simple scenario I have set up:

  1. I start Renoise (2.8.2 64bit Linux) using Jack for audio and with the --scripting-dev option
  2. I start vmpk (a virtual midi piano)
  3. I go to Preferences and make sure the piano shows up as port A input for MIDI
  4. I load a virtual instrument and play the piano to make sure it’s connected to Renoise
  5. I go into the Scripting terminal and create a simple MIDI test script under User Scripts using the MIDI snippet code (see code below)
  6. I hit “Execute”

At this point the terminal opens and prints:

Renoise MIDI In Port A

So it seems that a device was found and the callback should be set. Yet when I send MIDI messages and Renoise receives them (I hear sound) nothing is printed to the terminal. Here is the code:


local inputs = renoise.Midi.available_input_devices()
local midi_device = nil

if not table.is_empty(inputs) then
local device_name = inputs[1]

print(device_name)

local function midi_callback(message)
assert(#message == 3)
assert(message[1] >= 0 and message[1] <= 0xff)
assert(message[2] >= 0 and message[2] <= 0xff)
assert(message[3] >= 0 and message[3] <= 0xff)

print(("%s: got MIDI %X %X %X"):format(device_name,
message[1], message[2], message[3]))
end

– note: sysex callback would be a optional 2nd arg…
midi_device = renoise.Midi.create_input_device(
device_name, midi_callback)

– stop dumping with ‘midi_device:close()’ …
end

“Renoise MIDI In Port A” is not the first MIDI device selected in Renoise’s preferences, but a virtual ALSA MIDI device that Renoise creates on Linux.
Lua scripts in Renoise can open any devices, even devices which Renoise else does not use, devices which are not selected in Renoise’s preferences.

So either route vmpk explicitly to “Renoise MIDI In Port A” to make the code above work without changes. Or change “”“local device_name”"" to vmpk’s output device name.

You hit it on the head. Thanks taktik. I had vmpk assigned to that port, but I guess that wasn’t enough? Anyway, using the vmpk input directly works!