Midi Api - Duplicate Messages In, Weird Syntax Out

Disclaimer: I’m a total noob to Lua (this is my first script) so these might be dumb mistakes on my part. Be gentle :)

I’m noticing two weird things playing with the MIDI API, hoping someone can shed some light.

First, my input callback function is getting called twice on every incoming message. I haven’t packaged a tool yet, I’m just pressing Execute in the Scripting Editor. Not sure if this would change the behavior, but it seems weird. I set up the input device like so: renoise.Midi.create_input_device(inputDeviceName, callbackFunction). It’s a pretty easy workaround, just ignore every second message - but that doesn’t seem right. My device is a Launchpad - I haven’t tried with any other devices yet, but the Launchpad works properly with other applications (and with Renoise directly, and with Duplex)

Second, to get the output “send” function to work, I have to pass the MidiOutputDevice in as the first argument, like this: midiOut.send(midiOut, message). The documentation says I should be able to do it this way: midiOut.send(message), but Lua gives me an error:
*** No matching overload found, candidates:
*** void send(MidiOutputDevice*,custom [class List<long,class DefaultArrayAllocator >] const&)

I’ve managed to work around both these issues, but clearly I’m missing something. Thanks for any tips!

Edit: Also noticing one other thing - sometimes Renoise will spontaneously release my input device. No error in Lua, just a message in the status bar: Released MIDI-In device: “Launchpad”

Hey daxton,

when working with callbacks, its highly recommended to write a small xrnx for this. Executing a testpad script will not automatically kill the old, last running one, but just garbage collect the old one. Aka you can not really rely on which object/callback is now dead and which one not. This will not be a prob when doing this in a XRNX, which only is executed once per song/session.

Regarding midi send and the dot:
Mind the colon. To call methods in Lua, you should do:

  
midiOut:send(message)  
-- which is the same as  
midiOut.send(midiOut, message)   
  

I was getting a bit confused by the same thing i.e. unreleased midi on 2nd 3rd execute etc. and random release while running in testpad.

Might it be worth adding a warning/notice in the docs?

Aha, thanks for the info. Packaging into an xrnx did the trick.