Old 02-13-2015, 04:27 AM   #1
NextLevel
Human being with feelings
 
Join Date: Dec 2014
Posts: 417
Default help with script

Does anyone know how I could modify my script to set the source as a different sequential file each time the script is ran? So for examp. I have a directory with files named guitar_001 - guitar_100 and each time the script is ran it it should increment through the files.
Note: This script requires REAPER pre. v5 and the sws extension.

Code:
//Sets the source media for selected items and preserves items properties
//Requires SWS extension

items = CountSelectedMediaItems(0);

i=0;
loop(items,
    item = GetSelectedMediaItem(0, i);
    take = GetActiveTake(item);
    extension_api("BR_SetTakeSourceFromFile2",take, "D:/temp WAVs/guitar_001.wav", 0, 1);
    i+=1;
);

UpdateTimeline();
Thank you
NextLevel is offline   Reply With Quote
Old 02-13-2015, 06:31 AM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,900
Default

That seems possible, but you would have to split the path in several variables.
Two will be fixed string (directory path + file name without number, and extension), and one will be an incrementable decimal variable. You mayd add conditions for adding 0 before the incrementation number if needed.
Then, you mix all that together into string in an other variable in the proper order with the match function.

I didnt try it, but this is what I would try.

Do you more specific details (actual code example) or is it ok ?
X-Raym is offline   Reply With Quote
Old 02-13-2015, 07:38 AM   #3
NextLevel
Human being with feelings
 
Join Date: Dec 2014
Posts: 417
Default

Quote:
Originally Posted by X-Raym View Post
Do you more specific details (actual code example) or is it ok ?
Code example would be great!

Thanks
NextLevel is offline   Reply With Quote
Old 02-13-2015, 08:14 AM   #4
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 7,268
Default

try this

Code:
loop(items,
  sprintf(#number,"%03i",i);
  #filename="D:/temp WAVs/guitar_";
  strcat(#filename, #number);
  strcat(#filename, ".wav");
  extension_api("BR_SetTakeSourceFromFile2",take, #filename, 0, 1);
i+=1;
);
heda is offline   Reply With Quote
Old 02-13-2015, 08:30 AM   #5
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,900
Default

I think we can go further with GetUserInput and 5 variables:
Path
Common prefix (guitar- guitar_ etc)
Digit number (if your file is written as 0001 or 00001 for eg)
Offset (if you want to start frm 0, 1 or 1724)
Extension

You would halso add conditions for missing file (error in file name)

I'm not currently at home so I can't write it now ^^
X-Raym is offline   Reply With Quote
Old 02-13-2015, 09:49 AM   #6
NextLevel
Human being with feelings
 
Join Date: Dec 2014
Posts: 417
Default

Thanks heda,

I tried your code and although it's not quite what I was looking for, it will come in handy for a different situation.

What your code did was increment each item so I ended up with item1:guitar_001, item2:guitar_002.., etc.

What I'm looking for is say all items start out as guitar_001, then the script is ran once, they should become guitar_002, then if the script is ran again they become guitar_003.

So I guess what is need, which I didn't think about before is a separate file that stores the increment value, and when the script is ran each time it picks up the value from the file and stores the next value.

Or another idea, is there any way to query/poll the keyboard via a defered script? So what happens is the script is continuously running and for example each time the keyboards 'x' key is pressed then the items are incremented.



@X-Raym,

I like your idea of the offset function, so yes please post when you get a chance.

Thanks guys
NextLevel is offline   Reply With Quote
Old 02-13-2015, 10:04 AM   #7
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 7,268
Default

ah.. sorry I did not understand it.

Then. Instead of storing the variable in a file, you could use GetMediaItemTake_Source to get the current source of one of them. extract the number and add one to it and run the loop to all the items.

edit: But maybe it is easier if this is done using takes in REAPER. Pressing the T key: "Take: Switch items to next take"

Last edited by heda; 02-13-2015 at 10:10 AM.
heda 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 02:36 PM.


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