this must be an easy question, but i can’t seem to find any examples.
i’m basically trying to add notifiers to renoise.song() as soon as renoise loads - but this fails if you put it in the main part of the tool code (i.e. when you load renoise, i assume that there is no song loaded yet, and thus renoise.song() doesn’t exist).
so my question is, where can i add these notifiers so they are initialized as soon as the song loads? tried looking for a song_loaded observable or similar but couldn’t find it.
Try this code at the start of your script, there are probably better ways to do it but this works for me.
-- Notifier handler functions
local notifier = {}
function notifier.add(observable, n_function)
if not observable:has_notifier(n_function) then
observable:add_notifier(n_function)
end
end
function notifier.remove(observable, n_function)
if observable:has_notifier(n_function) then
observable:remove_notifier(n_function)
end
end
-- Set up song opening & closing observables
local new_doc_observable = renoise.tool().app_new_document_observable
local close_doc_observable = renoise.tool().app_release_document_observable
-- Set up notifier functions that are called when song opened or closed
local function open_song()
print("A new song was opened")
end
local function close_song()
print("Song was closed")
end
-- Add the notifiers
notifier.add(new_doc_observable, open_song)
notifier.add(close_doc_observable, close_song)