Skip to content

Instantly share code, notes, and snippets.

@triss
Created September 17, 2014 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save triss/4875cd2eb5d4d83d1832 to your computer and use it in GitHub Desktop.
Save triss/4875cd2eb5d4d83d1832 to your computer and use it in GitHub Desktop.
--[[============================================================================
main.lua
============================================================================]]--
--------------------------------------------------------------------------------
-- tool registration
--------------------------------------------------------------------------------
--renoise.tool():add_menu_entry {
-- name = "Instrument Box:Random Renoise Kit...",
-- invoke = function() random_renoise_kit() end
--}
-- renoise.tool():add_menu_entry {
-- name = "Sample Mappings:Set base note to highest note...",
-- invoke = function() base_note_to_high_note() end
-- }
--------------------------------------------------------------------------------
-- util functions
--------------------------------------------------------------------------------
function rs()
return renoise.song()
end
-- calls a function once through app_idle_observable
function call_by_app_idle(func)
local hook = nil
hook = function()
func()
renoise.tool().app_idle_observable:remove_notifier(hook)
end
renoise.tool().app_idle_observable:add_notifier(hook)
end
--------------------------------------------------------------------------------
-- osc handling
--------------------------------------------------------------------------------
local server, socket_error = renoise.Socket.create_server(
"localhost", 9997, renoise.Socket.PROTOCOL_UDP
)
-- tell me if there was an error setting up OSC
if (socket_error) then
renoise.app():show_warning(("Failed to start the " ..
"OSC server. Error: '%s'"):format(socket_error))
return
end
-- osc responder function
server:run {
socket_message = function(_, data)
local msg, osc_error = renoise.Osc.from_binary_data(data)
-- if message of correct type
if(msg and type(msg) == "Message" and msg.pattern == "/monome/grid/key") then
-- parse it
local x = msg.arguments[1].value
local y = msg.arguments[2].value
local on = msg.arguments[3].value
print(x, y, on)
-- call function that enqueses a pattern maniuplation
if(on == 1 and x < 8) then
retrigger(x, x + 1, y)
end
end
end
}
--------------------------------------------------------------------------------
-- sample jumping
--------------------------------------------------------------------------------
local trigger_queue = {}
function retrigger(instrument_i, track_i, pos)
-- add retrigger to retrigger queue
trigger_queue[track_i] = {instrument_i = instrument_i, pos = pos}
end
function update_pattern(instrument_i, track_i, pos)
local rs = renoise.song()
local song_pos = rs.transport.playback_pos
local pattern_i = rs.sequencer:pattern(song_pos.sequence)
local track = rs:pattern(pattern_i):track(track_i)
track:clear()
local next_line = track:line(song_pos.line + 1)
next_line:note_column(1).note_value = 48
next_line:note_column(1).instrument_value = instrument_i
-- S effect is 28
next_line:effect_column(1).number_value = 28
next_line:effect_column(1).amount_value = pos * 32
end
function pattern_updater()
for track_i, inst_pos in pairs(trigger_queue) do
update_pattern(inst_pos.instrument_i, track_i, inst_pos.pos)
trigger_queue[track_i] = nil
end
end
renoise.tool():add_timer(pattern_updater, 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment