Go Back   Cockos Incorporated Forums > REAPER Forums > JSFX and ReaScript Discussion

Reply
 
Thread Tools Display Modes
Old 06-22-2018, 11:31 AM   #1
StepOne
Human being with feelings
 
StepOne's Avatar
 
Join Date: Jan 2008
Location: CA
Posts: 991
Default EEL ReaScript - better method for selecting track name instead of looping?

If I want to select a specific track, I have an eel script that will iterate through the track names until it is found
Code:
function selectTrack(trackName)
    (
      i = 0;
      loop(CountTracks(0),
      track = GetTrack(0, i);
        GetSetMediaTrackInfo_String(track, "P_NAME", #current_track_name, 0); 
        match(trackName, #current_track_name) ? ...Matched Code... : ...Unmatched Code...;
        i += 1;
      );
    );
Is this still the best way to select a specific track? Is there no native method that can directly pull a current track by name without iterating?
__________________
Damn it feels good to be a gangsta.
StepOne is offline   Reply With Quote
Old 06-22-2018, 12:29 PM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 5,007
Default

nope,
but you have to exit the loop when match is found. a while loop may be required here.
X-Raym is offline   Reply With Quote
Old 06-22-2018, 12:33 PM   #3
StepOne
Human being with feelings
 
StepOne's Avatar
 
Join Date: Jan 2008
Location: CA
Posts: 991
Default

Quote:
Originally Posted by X-Raym View Post
nope,
but you have to exit the loop when match is found. a while loop may be required here.
I do understand that, the code I pasted was original code with the intent of also modifying other tracks that were not the specified track name (but indeed unnecessary for my example).
__________________
Damn it feels good to be a gangsta.
StepOne is offline   Reply With Quote
Old 06-22-2018, 01:45 PM   #4
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: The vast, frozen wasteland of western Canadia.
Posts: 5,379
Default

If your script needed to look up a lot of tracks by name, or do it repeatedly, etc, you could store all of the track names and their index numbers in a script table and access that instead so it only has to run the GetMediaTrackInfo loop once at startup.
__________________
Currently working away from home; don't expect timely responses from me.
Default 5.0 Nitpicky Edition / GUI tutorial for Lua / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate / ReaPack
Lokasenna is offline   Reply With Quote
Old 06-22-2018, 03:47 PM   #5
StepOne
Human being with feelings
 
StepOne's Avatar
 
Join Date: Jan 2008
Location: CA
Posts: 991
Default

Quote:
Originally Posted by Lokasenna View Post
If your script needed to look up a lot of tracks by name, or do it repeatedly, etc, you could store all of the track names and their index numbers in a script table and access that instead so it only has to run the GetMediaTrackInfo loop once at startup.
This...this is a great idea. Thank you!
__________________
Damn it feels good to be a gangsta.
StepOne is offline   Reply With Quote
Old 06-22-2018, 04:53 PM   #6
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 5,007
Default

only works if track structure dont change during script execution.
X-Raym is offline   Reply With Quote
Old 06-22-2018, 06:25 PM   #7
StepOne
Human being with feelings
 
StepOne's Avatar
 
Join Date: Jan 2008
Location: CA
Posts: 991
Default

Quote:
Originally Posted by X-Raym View Post
only works if track structure dont change during script execution.
Yes, I am aware of this, thank you.
__________________
Damn it feels good to be a gangsta.
StepOne 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 12:19 PM.


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