Track Belongs To Group Or Not

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 =  
local tr =  
local function parent_index(t)  
 local i = 1  
 while + i).type == 1 do  
 i = i + 1  
 local group_index = t + i  
 return group_index  
if tr.type == 1 and tr.group_parent then  

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”.

That magic “1” is a renoise.Track.TRACK_TYPE_SEQUENCER

Thanks taktik.


Here is a temporary workaround for continuing on your project:

function parent_to(track)  
 for tr = track+1, table.count( do  
 if[tr].type == 4 and table.count([tr].members) >= tr - track then  
 return tr  

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, do  
 local track =  
 if (track.type == TRACK_TYPE_GROUP and #track.members >= i - track_index) then  
 return i  

Thank for the advice, both of you!

Thanks to taktik for bringing some sanity. It’s very helpful and educational for someone at my stage.

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 =, 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  
 return parent_index