Skip to content

Commit

Permalink
add script-definable action for when clock tempo changes (monome#1575)
Browse files Browse the repository at this point in the history
* add clock.temo_changed callback

* clean up naming

* reset handler when clocks are cleaned up

* fold in artem's feedback

* remove 'source' pass, remove redundant nils
  • Loading branch information
dndrks authored Jul 5, 2022
1 parent e0c5d3e commit 534a9af
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lua/core/clock.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ clock.sync = function(...)
return coroutine.yield(SCHEDULE_SYNC, ...)
end


-- todo: use c api instead
clock.resume = function(coro_id, ...)
local coro = clock.threads[coro_id]
Expand Down Expand Up @@ -88,6 +87,7 @@ clock.cleanup = function()

clock.transport.start = nil
clock.transport.stop = nil
clock.tempo_change_handler = nil
end

--- select the sync source.
Expand Down Expand Up @@ -124,9 +124,21 @@ end

clock.transport = {}

--- static callback when clock transport is started;
-- user scripts can redefine
-- @static
clock.transport.start = nil

--- static callback when clock transport is stopped;
-- user scripts can redefine
-- @static
clock.transport.stop = nil

--- static callback when clock tempo is adjusted via PARAMETERS > CLOCK > tempo;
-- user scripts can redefine
-- @static
-- @param bpm : the new tempo
clock.tempo_change_handler = nil

clock.internal = {}

Expand Down Expand Up @@ -210,6 +222,9 @@ function clock.add_params()
if source == "internal" then clock.internal.set_tempo(bpm)
elseif source == "link" then clock.link.set_tempo(bpm) end
norns.state.clock.tempo = bpm
if clock.tempo_change_handler ~= nil then
clock.tempo_change_handler(bpm)
end
end)
params:set_save("clock_tempo", false)
params:add_trigger("clock_reset", "reset")
Expand Down Expand Up @@ -340,4 +355,4 @@ end
--------------------------------------------------------------------------------
]]

return clock
return clock

0 comments on commit 534a9af

Please sign in to comment.