add_effect handler

Hello.

Rather than having a feature request, i thought its better to try it myself and ask how-to:

Is there a way to add handler (invoke function on event) when dsp is added. I want to have vst effects be minimized/collapsed by default.

This is no real code and i don’t know lua yet but its better than to explain it in English witch I am bad at:

function minimize_vst_effect(dsp_effect)
    if dsp_effect.type == 'VST' than
        dsp_effect.minimized = True
    end
end

renoise.app.handlers.add_dsp_effect.append(minimize_vst_effect(dsp_effect))

Im making things up here. Maybe this could be approached in a different way.

You would probably want such a tool to “follow your actions” and not look for devices being added in each and every track?

So, you would start by attaching a notifier here:
renoise.song().selected_track_index_observable

Whenever the track changes, add the following inside the above notifier method
renoise.song().tracks[].devices_observable

This will allow you to handle device events from the current track only.

In general, notifiers and observables are simple to work with, but require a lot of “boilerplate code” to set up.
For example, you need to remove old notifier methods before adding new ones, check when a new song is created etc.

Imagine that you tool had some initialization code which set these listeners, then you could do something like this:

-- reference to the track we are receiving events from...
local curr_track

-- remove and add nofier in one go...
function assign_notifier(obs,fn)
  if not obs:has_notifier(fn) then
    obs:add_notifier(fn)
  end
end

function devices_notifier(action)
  -- do something clever
  -- possible actions: "insert", "remove", "swap"
end

function selected_track_notifier()

  if (curr_track) then
    curr_track:remove_notifier(devices_notifier)
  end

  curr_track = renoise.song().selected_track
  assign(curr_track.devices_observable,
    devices_notifier)

end

function attach_to_song()
  assign(renoise.song().selected_track_observable,
    selected_track_notifier)
end

More info about the observer pattern
https://github.com/renoise/xrnx/blob/master/Documentation/Renoise.Document.API.lua

Thanks - this is great answer

Now that i have learned a little about lua + renoise api,

I will definitely try to implement that…

stay tuned for more questions :slight_smile: