Old 09-22-2017, 07:42 PM   #1
elijahlucian
Human being with feelings
 
Join Date: Dec 2006
Posts: 53
Default Have you had any success automating file renaming?

I do quite a bit of voiceover and I am working on automating my file naming. I am just trying to figure out the best way to do it, ideally, I would like to be able for the file to be named once the recording has finished, so it would name it like: projectname + trackname + recordnumber for example.

where I am getting my name from is going to be far more complicated, but I keep running into a wall here..

I can't seem to rename the files in reaper?!

Currently I found out that I can get the file name from takes, but only if there are more than 1 takes on the track... for my purposes takes are really making things hard... I would prefer a non-destructive editing workflow without takes, but that's neither here nor there.

So basically if it doesn't have a take, my script just crashes because GetTakeName doesn't have a "Take" id to use...

but there is no other way to get file names except with takes in the API.. I looked 4 times so far, I will keep trying but I am hoping for a helping hand here
elijahlucian is offline   Reply With Quote
Old 09-22-2017, 07:53 PM   #2
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,964
Default

All media items have at least one take.

This renames/move whatever audio file is used for the first select item's last take to C:\test.wav:

Code:
local item = reaper.GetSelectedMediaItem(0, 0)
local take = reaper.GetMediaItemTake(item, reaper.CountTakes(item) - 1)
local track = reaper.GetMediaItemTrack(item)

local oldSource = reaper.GetMediaItemTake_Source(take)
local oldFilename = reaper.GetMediaSourceFileName(oldSource, '')

local newFilename = 'C:\\test.wav'
os.rename(oldFilename, newFilename)

local newSource = reaper.PCM_Source_CreateFromFile(newFilename)
reaper.SetMediaItemTake_Source(take, newSource)

Last edited by cfillion; 09-23-2017 at 12:17 AM.
cfillion is offline   Reply With Quote
Old 09-22-2017, 11:14 PM   #3
elijahlucian
Human being with feelings
 
Join Date: Dec 2006
Posts: 53
Default

huh. interesting workaround...

so instead of the files staying in reaper, they would then be located elsewhere?
elijahlucian is offline   Reply With Quote
Old 09-23-2017, 12:00 AM   #4
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,964
Default

I'm not sure I know what you mean by "file staying in reaper", but C:\test.wav was just for the example. Replace that by what you want the filename to be: projectname + trackname + recordnumber.

You can extract the directory from the old file name to have an absolute path (so the file stays where it is and doesn't get moved into FL Studio 11 ):

Code:
...
local path = oldFilename:match('^(.+[\\/])')
local newFilename = path .. 'desired_filename.wav'
...
os.rename moves the actual file and SetMediaItemTake_Source tells REAPER about it.

Last edited by cfillion; 09-23-2017 at 12:27 AM.
cfillion is offline   Reply With Quote
Old 09-23-2017, 08:27 AM   #5
elijahlucian
Human being with feelings
 
Join Date: Dec 2006
Posts: 53
Default

Oh, I see, thank you for explaining that bit to me, that's great! I was trying to figure out alternate ways of approaching this.

What I thouhgt was "The script moves the file to my desired location and gets "unlinked" in Reaper"

I didn't see the bit about "SetMediaSource" Thank you for explaining that one!

This is wonderful. I guess I was looking about it the wrong way... I was trying to see if an API existed to directly rename the file all through Reaper's API.

Now I see that I need to think a bit more on the abstract side while scripting, dip out to the OS to do some stuff there, etc.

Thanks!
elijahlucian is offline   Reply With Quote
Old 09-26-2017, 03:29 PM   #6
elijahlucian
Human being with feelings
 
Join Date: Dec 2006
Posts: 53
Default Int buf_sz

Hi cfillion. Thanks for the help with this script but it's having trouble running...

seems to be missing some required args.

apparently python requires different buffer sizes

RPR_GetProjectPathEx(proj, buf, buf_sz)

apparently we need an integer thats buf_sz

but I cant see a reference on this, buf_sz seems to be an unknown thing when it comes to google
elijahlucian is offline   Reply With Quote
Old 09-26-2017, 03:45 PM   #7
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,964
Default

buf & buf_sz are a residue from the C API. In Lua buf_sz is automatically set to 1024, the default underlying buffer size. I don't know what the right value should be for Python scripts but the documentation uses 512 in the (only) example.

Code:
# function returning information in the first parameter (function returns void):
(str) = RPR_GetProjectPath("", 512)
cfillion is offline   Reply With Quote
Old 09-26-2017, 04:48 PM   #8
elijahlucian
Human being with feelings
 
Join Date: Dec 2006
Posts: 53
Default

Quote:
Originally Posted by cfillion View Post
buf & buf_sz are a residue from the C API. In Lua buf_sz is automatically set to 1024, the default underlying buffer size. I don't know what the right value should be for Python scripts but the documentation uses 512 in the (only) example.

Code:
# function returning information in the first parameter (function returns void):
(str) = RPR_GetProjectPath("", 512)
alright. I managed to get a little somewhere on this one... Only problem that I didn't forsee was that (of course) the file is in use by Reaper...

This is why i was hoping to be able to name the media clip like I can in Studio One... Would just make things a lot more simple. Just name the clip that I need then it can be exported as that clip name when the time comes for export.

is there a way to unlink the file temporarily while I rename it?
elijahlucian is offline   Reply With Quote
Old 09-26-2017, 04:55 PM   #9
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,964
Default

Quote:
Originally Posted by elijahlucian View Post
is there a way to unlink the file temporarily while I rename it?
This is only necessary on Windows. There's two actions for that (I thought Audio_Quit/Audio_Init did it, but it doesn't seem to actually be the case):

Item: Set all media offline (40101)
Item: Set all media online (40100)
cfillion is offline   Reply With Quote
Old 09-26-2017, 05:05 PM   #10
elijahlucian
Human being with feelings
 
Join Date: Dec 2006
Posts: 53
Default

Quote:
Originally Posted by cfillion View Post
This is only necessary on Windows. There's two actions for that (I thought Audio_Quit/Audio_Init did it, but it doesn't seem to actually be the case):

Item: Set all media offline (40101)
Item: Set all media online (40100)
dang. doesn't seem to work for me. What I am gonna do is just delete the files from the daw and rename into a folder. I am gonna do all my editing and whatnot in studio one anyways. so this works! Thanks!
elijahlucian 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:03 PM.


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