Question About Notifiers: How To Add/Remove Them

I still have problems with notifiers. If I add a notifier like in the code below things will work as expected, but on startup Renoise will always give an error message(but not crash since b7). Am I doing it wrong? Attached tool demonstrates the problem. Install and restart Renoise.

  
renoise.song().instruments_observable:add_notifier(function(notification)   
 print("instrument changed")   
end)  
  

See [Fixed 2.7 Beta] Crash With 2.7 B6 On Restart With Script That Causes please.

On startup, while your tool is loaded by Renoise, there is no song yet. Also songs will be (re)created when loading new songs in Renoise, or when hitting “new Song” in Renoise. So you have to (re)attach notifiers for each new song that gets instantiated. Aka: the value of renoise.song() changes with every new song that you do load/create within Renoise.

In most cases attaching to a song is only needed when your tool actually does something with the song. Like its showing a GUI, does some kind of processing on the currently running song and so on. So you maybe want to add notifiers only then, and not all the time in the background, while your tool does nothing beside sitting in the background and waiting for a job to be done…

Rough overview about a tools lifetime:

  
[S] tool startup  
[R] tool running  
[F] tool finalized  
  
* [S] Renoise starts  
* [S] tool opened, main body of tool is executed  
* [S] initial song loaded/created (app().song valid the first time)  
* [R] ** some functions (keybindings, menu entries, timers or app() notifiers) of your tools may be called (user invokes your tool).  
* [R] ** ...[new songs are maybe loaded/created] (app().song changes)  
* [F] tool is closed  
* [F] Renoise shuts down  
  
add/remove notifiers to songs in [R] only. Add/remove notifiers to the app in [S]/[F] or [R].   
  

If you let us know what exactly your tool does, and you are still unsure how this works, we could give you a few more “practical” tips.

1 Like

Working fine now, never noticed the second half of the message you linked to.

I have to ask one more question. I had a look at this example and saw that it is possible to send data to a notifier on creation. That works fine. But when I want to remove a notifier I first want to check that it is there. If I do this:

  
>>> function notifier(indata, notification) \  
... print("test")  
... end  
...   
>>>   
>>> renoise.song().tracks[3].devices_observable:add_notifier(notifier,{3})  
>>>   
>>> oprint(renoise.song().tracks[3].devices_observable:has_notifier(notifier))  
false  
  

I’m surprised that the result is false. How can I check if a notifier is present?

I don’t know for sure but “notifier” itself is a risky name to use in a lua script don’t know if it is a keyword, but it sounds like one.
does it give the same result with an arbitrary name?

1 Like

Yes, same result regardless of name.

Makes sense, thanks for explaining.