Here’s some code. When you run it and the selected track is a child of a group, it works.
But when you run it on a normal track, it gives an error.
local tri = renoise.song().selected_track_index
local tr = renoise.song():track(tri)
local function parent_index(t)
local i = 1
while renoise.song():track(t + i).type == 1 do
i = i + 1
end
print(i)
local group_index = t + i
return group_index
end
if tr.type == 1 and tr.group_parent then
print(parent_index(tri))
end
I’m a bit confused. How can I tell if a track belongs to a group or it’s independent?
My experience: I ran into this yesterday. The problem is that group_parent does not return nil but is unavailable when there is no parent. I have suggested it to return nil (but maybe there is some basic lua way of handling this?) Otherwise you could iterate through tracks and make a map of the hierarchy or a simple check, using that to check if any track has tr as a member. I’d suspect this is getting fixed.
I expected the same that group_parent is nil when track has no parent. I had the same workaround in my head about iterating through tracks but I’d better wait and hope it gets fixed.
Yeah, we better wait. The same issue applies to .members. The only “workaround” I see is to create a group for every track on iteration and table.count members to see how many tracks to the left are part of the same group.
“group_parent” indeed always should be valid. Will fix that soon.
“members”, on the other hand only is and should be present for group tracks. Regular tracks can have no “members”. Check with “track(some_number).type == renoise.Track.TRACK_TYPE_GROUP” or type(some_track) == “GroupTrack”.
eeter:
That magic “1” is a renoise.Track.TRACK_TYPE_SEQUENCER
Here is a temporary workaround for continuing on your project:
function parent_to(track)
for tr = track+1, table.count(renoise.song().tracks) do
if renoise.song().tracks[tr].type == 4 and table.count(renoise.song().tracks[tr].members) >= tr - track then
return tr
end
end
end
Sorry for being such a pest, but magic number “4” is renoise.Track.TRACK_TYPE_GROUP.
This can be quite long to type, but you can create shortcuts to it then:
local TRACK_TYPE_GROUP = renoise.Track.TRACK_TYPE_GROUP -- somewhere at the top of the file
function parent_to(track_index)
for i = track_index + 1, #renoise.song().tracks do
local track = renoise.song():track(i)
if (track.type == TRACK_TYPE_GROUP and #track.members >= i - track_index) then
return i
end
end
end
Here is a snippet that returns the parent index to a track. It’s a bit tedious for a basic function imo
function parent_index(track_index)
local s, parent_index = renoise.song(), nil
for i, track in ripairs(s.tracks) do
if track.type == renoise.Track.TRACK_TYPE_GROUP then
if i - #track.members <= track_index and track_index < i then
parent_index = i
end
end
end
return parent_index
end