Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 02-23-2024, 04:53 AM   #1
Logutin
Human being with feelings
 
Logutin's Avatar
 
Join Date: Apr 2020
Posts: 16
Default Understanding Item Order with GetTrackMediaItem() in Reaper

Hello everyone!

I’ve been using the GetTrackMediaItem() function in my scripts, and I’ve noticed that it consistently returns items sorted by their position on the track. However, I’m curious about whether relying on this behavior is safe and predictable. Are there any potential pitfalls or unexpected scenarios I should be aware of when using this function? Could a user or another script modify this default behavior?

In other words, do I need to perform an additional check to ensure that the items I retrieve from GetTrackMediaItem() are correctly sorted?

I came across an additional check in one script written by a skilled scripter, which piqued my interest.

Thank you in advance for your insights!
__________________
Slava Logutin
https://soundcloud.com/logutin
Logutin is offline   Reply With Quote
Old 02-23-2024, 10:10 AM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

Hi,
there is absolutely no randomness in how API function behaves.

Bit if you want to move items, store them in a table before, and then loop in your table to do your position offset.
X-Raym is offline   Reply With Quote
Old 02-23-2024, 05:28 PM   #3
Logutin
Human being with feelings
 
Logutin's Avatar
 
Join Date: Apr 2020
Posts: 16
Default

Quote:
Originally Posted by X-Raym View Post
Hi,
there is absolutely no randomness in how API function behaves.

Bit if you want to move items, store them in a table before, and then loop in your table to do your position offset.
Thank you for your answer (and, of course, for all your scripts, documentation, and tutorials that I am happy to use). I am indeed doing exactly that now. I retrieve information about item positions and then move them. And I’m accomplishing this within a single for loop. Your advice has made me realize that I might encounter unpredictable behavior if I retrieve items and simultaneously change their positions in the same loop. I’ll take your guidance to heart and revise my code accordingly. Thanks once again!
__________________
Slava Logutin
https://soundcloud.com/logutin
Logutin is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 01:59 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.