Depending on a preference value in my tool i want to dynamically enable/disable notifers for devices on each track. Here in the debug output one can see, that a notifier is added for each track successfully pointing all to the same function.
devices notifers enabled
enabled: Kick
enabled: Hats & Cymbal
enabled: distortion
enabled: help clap
enabled: Clap
enabled: Ethnic
enabled: LoFi Break
enabled: bassline
enabled: acid
enabled: pad
enabled: dist 2
enabled: psymelody
enabled: arpeggio
enabled: lead
enabled: long verb + delay
enabled: Mst
enabled: bassline tweak
enabled: bass
devices notifers disabled
*** std::logic_error: 'remove notifier: the given notifier function was not added.'
*** stack traceback:
*** [C]: in function 'remove_notifier'
*** main.lua:132: in function 'init_notifiers'
*** main.lua:274: in function 'preferences_gui'
*** main.lua:49: in function <49><br>
<br>```
<br>
<br>
Here is my current notifier code:<br>
<br>
```lua<br><br>
--[[script initialization]]-----------------------------------------------]]--<br>
<br>
renoise.tool().app_new_document_observable:add_notifier (<br>
function()<br>
delete_snapshots()<br>
init_notifiers()<br>
end<br>
)<br>
<br>
function init_notifiers()<br>
<br>
if not renoise.song().tracks_observable:has_notifier (<br>
function() delete_snapshots() end<br>
) then<br>
<br>
renoise.song().tracks_observable:add_notifier (<br>
function() delete_snapshots() end<br>
)<br>
end<br>
<br>
if prefs.prf_devices.value then<br>
print("devices notifers enabled")<br>
for _, track in ipairs(renoise.song().tracks) do<br>
if not track.devices_observable:has_notifier (<br>
function() delete_snapshots() end<br>
) then<br>
<br>
print("enabled: " .. track.name)<br>
track.devices_observable:add_notifier (<br>
function() delete_snapshots() end<br>
)<br>
end<br>
end<br>
else<br>
print("devices notifers disabled")<br>
for _, track in ipairs(renoise.song().tracks) do<br>
--- if track.devices_observable:has_notifier (<br>
--- function() delete_snapshots() end<br>
--- ) then<br>
<br>
--- isn't executed after a change in the preferences?<br>
print("disabled: " .. track.name)<br>
track.devices_observable:remove_notifier (<br>
function() delete_snapshots() end<br>
)<br>
--- end<br>
end<br>
end<br>
<br>
end<br>
<br>```
<br>
<br>
The weird thing is, that if i include the commented out check for has_notfier, the remove never get's executed. That function was added before successfully, but why does has_notifier return false now instead of executing the remove stuff?</49>