How to get track_index given a track object?

i think this should be easy, but i haven’t found a way to do this in the docs. basically i have a track object and i’m trying to find it’s track_index… there doesn’t seem to be a property for this, so i’ve been iterating through all the tracks and searching for a match on track.name (but obviously this is failing when tracks have duplicate names).

anyone have a tip on how get this?

sh

You could store the index to begin with, and compare against that?

Indeed this approach might require a slight reworking of your script, but generally it’s always a good thing to remember tracks (and instruments, samples, etc.) by their index instead of referencing the actual object.

The reason is that it makes it easy to verify that the object does indeed exist. When the song data change (for whatever reason), a reference might become invalid but continue to exist for a little while - this is due to how garbage collection and low level API stuff works in general…

thanks for the reply - i’m interested in this approach but might need another nudge. i think what i’m aiming for is close to what you are describing - i’m trying to create a copy of the “structure” of a song using only track_indexes, and then sending that to my visuals program for further processing. the problem i’m running into is when dealing with group tracks and sub groups. so if my song has something like this (renoise track indexes in brackets):

drum_track_group (index 4)
-- kick (index 1)
-- snare (index 2)
-- hats (index 3)
chord_group (index 7)
-- guitar (index 5)
-- pads (index 6)

in order to iterate through the structure, i’m using the track.members and track.group_parent properties - but these only give me references to the track objects themselves (not the index). or, would the solution to be to look at group tracks first, then count backwards to get each sub-track’s index?

I guess it depends on whether you want to support a feature like nested groups or not…then it would of course become a bit more complicated.

But the simple approach would be like the one you suggest: first level are always group indices, second level track indices.

With the proper checks in place (is the group index actually pointing to a group track, the track index pointing to a sequencer track) etc., it should be pretty solid and able guard against itself against unforeseen situations.

This snippet might help, as it returns the parent index of a track index? https://forum.renoise.com/t/track-belongs-to-group-or-not/34496

very helpful thanks!

sh