script not responding to midi after a time

Hey guys,

im writing my first script and having two issues with it.
check out the script here: http://pastebin.com/c7t2xh48

basically its firing some osc messages with random values in random time.

now i want to controll the time value via my midi controller. i got midi values working in the script, but after some seconds my script isn’t responding to midi anymore.
if i use only the midi stuff from my script alone it seems that there is no problem. but when i combine the osc sending and the midi midi dies after a time…seems that the other stuff is running further.

the other isue i realised is that i can kill my os when i send to much osc values in an infinite loop :). sure i shouldnt do this but did it once.
renoise then told me that i should kill the script, but renoise couldnt fully kill it and after a time my ubuntu screen got black :(

anny ideas to the first issue?

Hey Guys,

i’ve stripped down everything to a basic tool which only gets midi, prints the midicontroller infos and fires a timer.
No OSC or other stuff. After approx 1000 timer calls midi is stopping printing infos. I attached the tool maybe someone wants to test it.
did i mention that im on linux/ubuntu?

midi_callback is a local function inside an if…end condition. This function ceases to exist when the routine has been finished (condition has been met) and the Lua garbage collect is removing the executed code.
You could better make it a defined function outside the condition.
You should be aware that every variable or constant is local within its own scope. Which includes scopes of conditions and loops.

hallo vV,

i thought about this also. if i do it like atached outside the condition. its happening also:

function myfunc ()  
 if (renoise.tool():has_timer(myfunc)) then   
 renoise.tool():remove_timer(myfunc)  
 end  
 renoise.tool():add_timer(myfunc, 50)  
end  
  
myfunc()  
  
rprint(renoise.Midi.available_input_devices())  
  
local inputs = renoise.Midi.available_input_devices()  
local midi_device = nil  
  
local device_name  
  
if not table.is_empty(inputs) then  
 device_name = inputs[5]  
 -- stop dumping with 'midi_device:close()' ...  
end  
  
  
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)  

Well you are not doing anything else either.
Your code executes and then the scripts stops functioning.
Just add some dummy GUI dialog to keep the stuff in memory.

This works:

  
  
function myfunc ()  
 if (renoise.tool():has_timer(myfunc)) then   
 renoise.tool():remove_timer(myfunc)  
 end  
 renoise.tool():add_timer(myfunc, 50)  
end  
  
myfunc()  
  
rprint(renoise.Midi.available_input_devices())  
  
local inputs = renoise.Midi.available_input_devices()  
local midi_device = nil  
local device_name = nil  
  
if not table.is_empty(inputs) then  
 device_name = inputs[1]  
  
  
 -- stop dumping with 'midi_device:close()' ...  
end  
  
  
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  
  
function script_loop()  
  
 local vb = renoise.ViewBuilder()  
  
 local CONTENT_MARGIN = renoise.ViewBuilder.DEFAULT_CONTROL_MARGIN  
 local BUTTON_WIDTH = 2*renoise.ViewBuilder.DEFAULT_CONTROL_HEIGHT  
  
 -- create the main content column, but don't add any views yet:  
 local dialog_content = vb:column {  
 margin = CONTENT_MARGIN  
 }  
  
 local busy_holder = renoise.app():show_custom_dialog(  
 "Keeping Renoise busy", dialog_content)  
 busy_holder:close()  
  
 midi_device = renoise.Midi.create_input_device(device_name, midi_callback)  
  
end  
  
script_loop()  
  

Don’t forget to set the correct midi devicenumber. (Mine is 1)

thats it. now it works.thank you. i thought the midi device has its own infinite loop. good to know that i have to keep renoise busy.