Advertisement
Guest User

Untitled

a guest
Jan 1st, 2013
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.45 KB | None | 0 0
  1.  
  2. miditable = {}          
  3. for i=0,256 do
  4.     miditable[i] = 0    
  5. end
  6.  
  7. -- menu entries
  8. renoise.tool():add_menu_entry {
  9.   name = "Main Menu:Tools:mytool:start",
  10.   invoke = function() start() end
  11. }
  12.  
  13. renoise.tool():add_menu_entry {
  14.   name = "Main Menu:Tools:mytool:stop",
  15.   invoke = function() stop() end
  16. }
  17.  
  18. -- create some handy shortcuts
  19. local OscMessage = renoise.Osc.Message
  20. local OscBundle = renoise.Osc.Bundle
  21.  
  22. -- open a socket connection to the server
  23. local client, socket_error = renoise.Socket.create_client(
  24.   "localhost", 8000, renoise.Socket.PROTOCOL_UDP)
  25.    
  26. if (socket_error) then
  27.   renoise.app():show_warning(("Failed to start the " ..
  28.     "OSC client. Error: '%s'"):format(socket_error))
  29.   return
  30. end
  31.  
  32. running = 0
  33. randval = 0
  34.  
  35. function start ()
  36.     running = 1
  37.     myfunc()
  38. end
  39.  
  40. function stop ()
  41.     running = 0
  42. end
  43.  
  44. function map (val,startin,endin,startout,endout)
  45.     return (val - startin) * (endout - startout) / (endin - startin) + startout;
  46. end
  47.  
  48. -- renoise.song().instruments[].samples[].transpose, _observable -- [number, -120 - 120]
  49.  
  50. function myfunc ()
  51.  
  52.   randval = math.random(-1,7)
  53.  
  54.   client:send(
  55.     OscMessage(
  56.       "/renoise/trigger/note_on",{
  57.       {tag="i",value=randval},
  58.       {tag="i",value=randval+1},
  59.       {tag="i",value=math.random(119)},
  60.       {tag="i",value=100}
  61.       }
  62.     )
  63.   )
  64.   mytimer()
  65. end
  66.  
  67. function mytimer ()
  68.   if (renoise.tool():has_timer(myfunc)) then                
  69.     renoise.tool():remove_timer(myfunc)
  70.   end
  71.   if(running == 1) then
  72.         renoise.tool():add_timer(myfunc, math.random(100))
  73.     end
  74.     -- print(map(miditable[0],0,127,100,1000))
  75.     -- print(miditable[0])
  76. end
  77.  
  78. rprint(renoise.Midi.available_input_devices())
  79.  
  80. local inputs = renoise.Midi.available_input_devices()
  81. local midi_device = nil
  82.  
  83. if not table.is_empty(inputs) then
  84.   local device_name = inputs[5]
  85.  
  86.   local function midi_callback(message)
  87.     assert(#message == 3)
  88.     assert(message[1] >= 0 and message[1] <= 0xff)
  89.     assert(message[2] >= 0 and message[2] <= 0xff)    
  90.     assert(message[3] >= 0 and message[3] <= 0xff)
  91.    
  92.     miditable[message[2]] = message[3]
  93.    
  94.     -- rprint(miditable)
  95.    
  96.     print(("%s: got MIDI %X %X %X"):format(device_name, message[1], message[2], message[3]))
  97.   end
  98.  
  99.   -- note: sysex callback would be a optional 2nd arg...
  100.   midi_device = renoise.Midi.create_input_device(
  101.     device_name, midi_callback)
  102.  
  103.   -- stop dumping with 'midi_device:close()' ...
  104. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement