How To Compare Track Objects???

This is driving me nuts:
I cannot find a way to compare Track objects! == does not work and can change of course (as can the index in the tracks list).

So, how can I check a track versus another one?

Two tracks would never be the same, unless you are talking about pattern-tracks, not song-tracks?
Pattern-tracks are the individual tracks inside each pattern, like a slot in the matrix[].tracks[]
– instead of[]

No, I am talking about

I need to check where a Track which reference I have is in the[]!

(Background: I add a notifier on song load to each track.name_observable that needs to check it’s own position in the tracks[] list, because tracks do unfortunately not have unique ids!)

Ah, if you want to maintain track references, you need to use the notifier.

 local song =  

This could produce output like this:

– insert a track
[index] => 5
[type] => insert

– delete a track
[index] => 5
[type] => remove

– swap two tracks
[index1] => 4
[index2] => 5
[type] => swap

You don’t need to look for “specialnames” if you always know where to look for the track

But that doesn’t solve my problem, does it?
Each track calls my function when it is renamed, but in this function I have to reference to the track that is renamed, thus “self” somehow.
There is now way to do something like this: find(, my_track), because a Track object has no __eq function defined (for whatever reason).

So I still do not know how to solve my problem.

The whole problem is that the way you would do it in any other language does not work here:

my_track = Track()
my_track2 = my_track
my_track == my_track2 – This does not work in the renoise API. It should yield True!

Okay, so let me phrase it differently:
The problem is that while I know where to look for the track (given it’s old name for instance), the TRACK ITSELF does not know its position in[], and I cannot figure out how to look for this position, given only the track.

Rename it to a none default track name is the only answer.

This can be solved if you maintain an own list of track objects, which can contain any values/ids you like. On startup you setup the notifiers for the name and insert/remove/swap actions and use them to keep your internal list of track objects updated. I have done a similar task already in my snapshots tool, maybe you can strip it down to your needs.

It contains also code to save data along a song and restore it on song load, which may be useful instead of saving your track comments into the song comments field.

Thanks for all the replies. I made it work now for my script by hacking around it, but I really don’t see why one cannot compare Track objects with each other. This seems like a flaw in the API to me!

Comparison operators of Renoise class objects (song, tracks, instruments and so on) should not compare object identity only, but object contents. Instead, I’ll let the global “rawequal” function compare object identity for such objects.

So you can do something like (in the next API update):

print(rawequal(, // -> true  
print(rawequal([1],[1])) // -> true  
print(rawequal([1],[2])) // -> false  
print(rawequal([1],[1])) // -> false  

Sounds good to me!