|
|
|
09-17-2018, 10:21 AM
|
#1
|
Human being with feelings
Join Date: Oct 2014
Posts: 77
|
Renaming source files from a script
Hi there.
Using Reascript in Python.
I would like to programmatically rename some item's take source file.
I can't seem to do that because the file is in use (presumably by Reaper itself).
Though it must be feasible since actions like "Xenakios/SWS: Rename takes and source files..." (_XENAKIOS_RENMTAKEANDSOURCE) can do that (but can't be used programmatically since they expect a GUI input).
I tried to create a copy of the source file and rename it as I wish, and then create a source with PCM_Source_CreateFromFile. Then I would use SetMediaItemTake_Source to tell the item to use this new source. Then I would call PCM_Source_Destroy on the old source.
The call to SetMediaItemTake_Source returns correctly, but actually changes nothing in the item (item properties still refer to the old file), and PCM_Source_Destroy has reaper crash.
Can someone tell me what the correct (and working) approach would be?
Thanks a lot.
|
|
|
09-17-2018, 10:37 AM
|
#2
|
Human being with feelings
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
|
It should basically work like that. Maybe you got your item and take pointers mixed up somewhere? (Much of the API calls deal with takes and not items.) Can you post your full code?
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
|
|
|
09-17-2018, 10:48 AM
|
#3
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
|
Looks like a bug in the Python API (doesn't work here either).
Code:
source = RPR_PCM_Source_CreateFromFile("/home/cfillion/test.wav")
item = RPR_GetSelectedMediaItem(0, 0)
take = RPR_GetActiveTake(item)
RPR_SetMediaItemTake_Source(take, source)
The same thing in Lua works just fine ( https://forum.cockos.com/showthread.php?p=1889202):
Code:
source = reaper.PCM_Source_CreateFromFile("/home/cfillion/test.wav")
item = reaper.GetSelectedMediaItem(0, 0)
take = reaper.GetActiveTake(item)
reaper.SetMediaItemTake_Source(take, source)
Last edited by cfillion; 09-17-2018 at 11:18 AM.
|
|
|
09-17-2018, 11:16 AM
|
#4
|
Human being with feelings
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,960
|
Offline any items using that source then change SRC and get back online
Last edited by mpl; 09-17-2018 at 11:22 AM.
|
|
|
09-17-2018, 12:40 PM
|
#5
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
I have few scripts to batch rename source files and it there was quite some tricky things to prevent conflict with existing file, but simple case can works with few lines of code (like cfillion code).
|
|
|
09-17-2018, 12:56 PM
|
#6
|
Human being with feelings
Join Date: Oct 2014
Posts: 77
|
Thank you all for your answers.
As cfillion shows, there must be a bug in the python implementation, since the same code works in Lua.
As far as I understand, mpl's suggestion to put items offline before anything could be the right way to let files be unused by reaper and be able to be renamed directly (without a copy involved).
I'll try that tomorrow.
Thank you all.
|
|
|
09-18-2018, 12:56 AM
|
#7
|
Human being with feelings
Join Date: Oct 2014
Posts: 77
|
Hi all.
I tried Cfillion's code and confirm in won't work in Python here either, just like my first attempts seemed to do nothing. It does work in Lua.
I wanted to try to set the item offline as suggested by mpl but actually can't seem to find a way to do so. How can I set an item offline?
Anyway I tested that, setting the item offline by hand in the Item/media menu before hand and restoring it online after running the script. This won't work either. Nothing seems to happen.
Is there a way to call some Lua code from a Python script?
I can always create a lua action and call it from my python script, but can I pass arguments?
Thank you guys
|
|
|
09-18-2018, 02:36 AM
|
#8
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
Quote:
As far as I understand, mpl's suggestion to put items offline before anything could be the right way to let files be unused by reaper and be able to be renamed directly (without a copy involved).
|
It is not just that, you have to put offline the each items which could have the file in one of his takes in every opened projects !
There is native action to put item offline.
But in last SWS release you should have access to dedicated funciton like:
Code:
reaper.NF_TakeFX_SetOffline( take, fx, bool )
|
|
|
09-18-2018, 02:51 AM
|
#9
|
Human being with feelings
Join Date: Oct 2014
Posts: 77
|
Quote:
Originally Posted by X-Raym
It is not just that, you have to put offline the each items which could have the file in one of his takes in every opened projects !
|
Of course, but in my test session there is no other item involved, and so putting offline just this one is enough. But it actually won't work.
Quote:
Originally Posted by X-Raym
But in last SWS release you should have access to dedicated function like:
Code:
reaper.NF_TakeFX_SetOffline( take, fx, bool )
|
Ah, I'll check that, but by its name, I'd think it has to do with the Take's FX, not with the item or take itself...
Thanks
|
|
|
09-18-2018, 06:04 AM
|
#10
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
oops sorry wrong copy paste, but check if it the item function equivalent is not already in sws already.
If not I think the function exists in a sws beta build.
|
|
|
09-18-2018, 08:12 AM
|
#11
|
Human being with feelings
Join Date: Oct 2014
Posts: 77
|
Quote:
Originally Posted by X-Raym
oops sorry wrong copy paste, but check if it the item function equivalent is not already in sws already.
If not I think the function exists in a sws beta build.
|
I couldn't find anything like that.
Besides, there are actions available to set the selected items offline, but I wish I could do that on a specific item.
This would allow me to rename the file without conflicting with the OS, and then set the source of the item to this file.
But again, setting the source to another file doesn't work in Python anyway...
Am I suppose to report a bug for that? If so, where do I do that?
Thanks
|
|
|
09-18-2018, 09:40 AM
|
#12
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
You didnt show us your code.
In python a special line has to be added to import sws functions. The function for setting source file is from sws.
checker reateam template repo for python minimal script.
|
|
|
09-18-2018, 10:04 AM
|
#13
|
Human being with feelings
Join Date: Oct 2014
Posts: 77
|
Quote:
Originally Posted by X-Raym
You didnt show us your code.
In python a special line has to be added to import sws functions. The function for setting source file is from sws.
checker reateam template repo for python minimal script.
|
I have used SWS functions in other scripts with no problem, but it's not the point here.
My test code is just that of Cfillion above. Bare simple, and not using SWS. Working in Lua but not in Pyhon.
The function I use, like Cfillion, for setting source file is RPR_SetMediaItemTake_Source. Which one do you refer to?
Thanks.
|
|
|
09-18-2018, 10:54 AM
|
#14
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
|
SWS has BR_SetTakeSourceFromFile from the time REAPER didn't have SetMediaItemTake_Source yet. It seems to work fine with Python. It runs this code: https://github.com/reaper-oss/sws/bl...pp#L1294-L1318.
Quote:
Originally Posted by X-Raym
But in last SWS release you should have access to dedicated funciton
|
The future function is CF_SetMediaSourceOnline from my PCM_source API pull request.
Quote:
Originally Posted by Cedrik0s
I can always create a lua action and call it from my python script, but can I pass arguments?
|
Only through temporary extstates...
Quote:
Originally Posted by Cedrik0s
Am I suppose to report a bug for that? If so, where do I do that?
|
It appears SetMediaItemTake_Source was broken in Python from the time it was added (in v5): https://forum.cockos.com/showthread.php?t=165074.
|
|
|
09-18-2018, 12:31 PM
|
#15
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,621
|
Just a quick note, has someone considered to report this bug in the proper forum?
Just an idea
Can't do it myself, as I have no experience with Python in Reaper at all, so I can't describe it properly...
Edit: I should have read cfillion's post first
|
|
|
09-19-2018, 07:47 AM
|
#16
|
Human being with feelings
Join Date: Oct 2014
Posts: 77
|
Thanks for your answer cfillion
Quote:
Originally Posted by cfillion
|
Ah very interesting! I had missed that.
Interesting link too!
Quote:
Originally Posted by cfillion
|
Ok, great. Future looks good
Quote:
Originally Posted by cfillion
Only through temporary extstates...
|
I see.
Quote:
Originally Posted by cfillion
|
Oh this is a known problem then, which is good, but still unresolved, which is less good
Thanks a lot for your answer Cfillion.
|
|
|
09-20-2018, 04:05 AM
|
#17
|
Human being with feelings
Join Date: Oct 2014
Posts: 77
|
Hi all.
Just to update you.
I could do what I wanted to thanks to BR_SetTakeSourceFromFile.
The only pity is that I am unable to set offline a specific item, but only the selected ones through the action #40440.
This is ok in my case because I am renaming the sourcefile of an item that has just been recorded by the script. So I only do that on the active take of the selected item.
Of course being able to set offline/online any given item with reascript (independently on the selection) would make it much better and general.
Can I ask for this feature to be added? How?
Thanks,
Cedric.
|
|
|
09-20-2018, 09:52 AM
|
#18
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
|
That's what CF_SetMediaSourceOnline does...
|
|
|
09-20-2018, 10:06 AM
|
#19
|
Human being with feelings
Join Date: Oct 2014
Posts: 77
|
Quote:
Originally Posted by cfillion
That's what CF_SetMediaSourceOnline does...
|
Of course
For some reason I thought it should be added to RPR functions as well...
Thanks cfillion.
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 09:03 AM.
|