Lua: explicit reference to a group

Since there are several plugins that come with multichannel support (DrumGizmo, Surge, LSP Sampler,…), I wonder, if there is a way to get a reference to their group, when the corresponding MIDI track is selected.
For example, if I create a 12 channel DrumGizmo track and select it’s MIDI Track - is it somehow possible to get a kind of adress to it’s group of channel tracks?
I hope you got, what I mean… :wink:
Edit: At the moment I’m doing that by iterating through all groups and look for matching strings in their names, but this is not very satisfactory…

I assume that the MIDI track is feeding the other tracks by direct connection, that is, the audio outs of the MIDI track are connected to the audio ins of the other tracks.

In that case…

---Returns true if any output ports of `fromRoute` are connected to any input ports of `toRoute`.
---@param fromRoute ARDOUR.Route
---@param toRoute ARDOUR.Route
---@return boolean
function isRouteConnectedTo(fromRoute, toRoute)
  for i = 0, fromRoute:output():n_ports():n_total() - 1 do
    local fromPort = fromRoute:output():nth(i)
    for j = 0, toRoute:input():n_ports():n_total() - 1 do
      if fromPort:connected_to(toRoute:input():nth(j):name()) then
        return true
      end
    end
  end
end

---Gets the routes for which any input ports are connected to the output ports of `fromRoute`. 
---I.e. The routes that `fromRoute` is feeding via direct connections (not internal sends, etc.).
---@param fromRoute ARDOUR.Route
---@return table
function getRoutesConnectedFrom(fromRoute)
  local toRoutes = {}
  for r in Session:get_routes():iter() do
    if isRouteConnectedTo(fromRoute, r) then
      table.insert(toRoutes, r)
    end
  end
  return toRoutes
end

--test
local r = Session:route_by_name("DrumGizmo")
local t = getRoutesConnectedFrom(r)
for _,v in ipairs(t) do
  print(v:name())
end

It’s not clear from the question whether you’re after this collection of routes or the group (RouteGroup) they’re in. They might be in the one group, they could be in multiple groups, or none.

If the MIDI track was also connected to another track/bus, e.g. a submix bus, then the script would pick that up too.

InternalSends (“Aux sends”) are another way that routes can be connected. InternalSend connections are scripted a different way; the above script will not find those.

1 Like

Thank you, mate… yeah, this pointed me to the right direction.
Indeed, I just thought about direct connections, but I guess, I will have to handle aux sends too. I didn’t even think about these. :wink:
Thank you, from here I will have to do some homework! :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.