|
|
|
06-03-2015, 10:28 PM
|
#1
|
Human being with feelings
Join Date: Oct 2012
Posts: 59
|
passing variables between scripts?
Hi, I'm new to ReaScript. I'm trying to make something involving storing the selected media item's source file, which will then later be recalled and inserted into the project. I want to store the source with one hotkey and then recall/paste it with another. Presumably, I'd need two separate scripts to make that work. How can I pass information between multiple scripts?
|
|
|
06-03-2015, 10:38 PM
|
#2
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,900
|
Hi !
You could use project Exstate. It is a way to store infos (with a type, key + value) right in the .rpp file. This way, infos can be called within different scriots, and even if you close / reopen your project !
The is of course a Get and a Set function for these, check in the API doc how to use them
|
|
|
06-03-2015, 11:00 PM
|
#3
|
Human being with feelings
Join Date: Oct 2012
Posts: 59
|
That looks promising! Thanks for the quick response.
|
|
|
06-04-2015, 05:08 AM
|
#4
|
Human being with feelings
Join Date: Jun 2012
Location: Spain
Posts: 7,268
|
After pasting, you can recall SetProjExtState with a empty string as value, to clean the data so it is not saved in the project.
or use just SetExtState with false as persist parameter just for temporary storage
items or tracks are custom type variable. Not just a string or a number, I don't know how that would work. I would have to investigate this.
|
|
|
06-04-2015, 06:00 AM
|
#5
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,900
|
@heda
Maybe write the GUID as string ?
|
|
|
06-04-2015, 06:07 AM
|
#6
|
Human being with feelings
Join Date: Jun 2012
Location: Spain
Posts: 7,268
|
SetExtState works with the takes
spk77 was using SetExtState in a script to store selected takes.
see here the example
http://forum.cockos.com/showpost.php...08&postcount=4
|
|
|
06-04-2015, 07:48 AM
|
#7
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
(Note: This works in REAPER 5pre only)
Maybe storing the take source filename would be the best way?
The first part (storing) could be something like this:
Store take source filename.lua
PHP Code:
function msg(m)
reaper.ShowConsoleMsg(tostring(m).."\n")
end
function store_take_source_filename()
local item = reaper.GetSelectedMediaItem(0,0) -- get first selected item
-- No selected items
if item == nil then
msg("No item selected")
return end
-- Empty item (no takes in item)
local take = reaper.GetActiveTake(item)
if take == nil then
msg("Empty item?")
return end
-- Active take in selected item is a MIDI take
if reaper.TakeIsMIDI(take) then
msg("Please select an audio take")
return end
local take_source = reaper.GetMediaItemTake_Source(take) -- get media source
local take_source_filename = reaper.GetMediaSourceFileName(take_source, "")
if take_source_filename ~= "" then
reaper.SetExtState("Take source filenames", "file name1", take_source_filename, true)
end
end
store_take_source_filename()
This function could be useful for creating new takes from the stored filename:
PHP Code:
Lua: boolean reaper.BR_SetTakeSourceFromFile(MediaItem_Take take, string filenameIn, boolean inProjectData)
|
|
|
06-04-2015, 08:43 AM
|
#8
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
I saw your other thread:
Hotkeys to insert/stamp media? (press F1 to insert kick, F2 for snare, etc.)
http://forum.cockos.com/showthread.p...88#post1527288
The storing function would need some more information to be stored: source take position in item, source item length etc.
I'll take a look at it
|
|
|
06-05-2015, 12:51 AM
|
#9
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Ok, now it almost works.
Throw items aimlessly around arrange view in sadness and hate.lua
("Create media item from stored take source file name.lua" might be more descriptive name )
|
|
|
06-05-2015, 02:42 AM
|
#10
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,900
|
That name ^^
The action looks very nice to me good work !
|
|
|
06-05-2015, 05:10 AM
|
#11
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Quote:
Originally Posted by X-Raym
That name ^^
The action looks very nice to me good work !
|
It's a script for emo kids
There's a possible bug in GetMediaSourceFileName: - If section or reverse is selected, "GetMediaSourceFileName" returns an empty string.
Code:
Lua: string filenamebuf reaper.GetMediaSourceFileName(PCM_source source, string filenamebuf)
(take media source properties)
|
|
|
06-10-2015, 09:00 AM
|
#12
|
Human being with feelings
Join Date: Dec 2011
Posts: 506
|
I'm very interested in being able to copy an item's source with a hotkey and replace another item's source with it with another hotkey. This would really simplify my workflow.
I wrote a script that works with the copy script previously posted in this thread.
Code:
function msg(m)
reaper.ShowConsoleMsg(tostring(m).."\n")
end
function replace_take_source_file()
reaper.Undo_BeginBlock() -- Begining of the undo block. Leave it at the top of your main function.
stored_source_filename = reaper.GetExtState("Take source filenames", "file name1")
stored_source = reaper.PCM_Source_CreateFromFile(stored_source_filename)
selected_items_count = reaper.CountSelectedMediaItems(0)
for i = 0, selected_items_count - 1 do
item = reaper.GetSelectedMediaItem(0, i) -- Get selected item i
take = reaper.GetActiveTake(item) -- Get the active take
reaper.SetMediaItemTake_Source(take, stored_source) -- Set the take source to the stored source
end
reaper.Undo_EndBlock("Replace selected item's source with copied item source", 0) -- End of the undo block. Leave it at the bottom of your main function.
end
replace_take_source_file()
This works, but it has problems.
Firstly, the graphics of an item are very lazy to reflect the change of a source file.
The biggest problem though, is that if you try to replace the source of multiple items, Reaper will crash if you try to delete any of them afterward. It says something about a pure virtual function.
Is this problem on my end or is it a problem with the API?
|
|
|
06-10-2015, 10:22 AM
|
#13
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
@Alkamist
I can't remember why we can't use PCM_Source_CreateFromFile, but fortunately Breeder made reaper.BR_SetTakeSourceFromFile function:
1.Store source file name (now it doesn't create an undo point)
PHP Code:
function msg(m)
reaper.ShowConsoleMsg(tostring(m).."\n")
end
function store_take_source_filename()
local item = reaper.GetSelectedMediaItem(0,0) -- get first selected item
-- No selected items
if item == nil then
msg("No item selected")
return end
-- Empty item (no takes in item)
local take = reaper.GetActiveTake(item)
if take == nil then
msg("Empty item?")
return end
-- Active take in selected item is a MIDI take
if reaper.TakeIsMIDI(take) then
msg("Please select an audio take")
return end
local take_source = reaper.GetMediaItemTake_Source(take) -- get media source
local take_source_filename = reaper.GetMediaSourceFileName(take_source, "")
if take_source_filename ~= "" then
reaper.SetExtState("Take source filenames", "file name1", take_source_filename, true)
end
end
store_take_source_filename()
(This is a simple version - item/take properties are not "copied" etc.)
2. Replace take sources (selected items, active take)
PHP Code:
function msg(m)
reaper.ShowConsoleMsg(tostring(m).."\n")
end
function replace_take_sources()
if not reaper.HasExtState("Take source filenames", "file name1") then
return
end
local file_name = reaper.GetExtState("Take source filenames", "file name1")
if file_name == "" then
return
end
reaper.Undo_BeginBlock()
local get_act_take = reaper.GetActiveTake
local get_sel_item = reaper.GetSelectedMediaItem
local sel_item_count = reaper.CountSelectedMediaItems(0)
for i=1, sel_item_count do
local take = get_act_take(get_sel_item(0, i-1))
local source_added_ok = reaper.BR_SetTakeSourceFromFile(take, file_name, false)
--msg("Source added: " .. tostring(source_added_ok)) -- debug
end
reaper.UpdateArrange()
reaper.Main_OnCommand(40441, 0) -- rebuild peaks for selected items
reaper.Main_OnCommand(40612, 0) -- Set items length to source length (comment out if not needed)
reaper.Undo_EndBlock("Replace take source(s)", -1)
end
replace_take_sources()
Last edited by spk77; 06-10-2015 at 10:27 AM.
Reason: variables to "local"
|
|
|
06-10-2015, 10:54 AM
|
#14
|
Human being with feelings
Join Date: Dec 2011
Posts: 506
|
@spk77 Thank you for the help! For some reason though, it's telling me that reaper.BR_SetTakeSourceFromFile is unknown. I have the latest SWS extension, and when I tell Reaper to show the ReaScript documentation, that function is there. Any idea what might be going wrong?
|
|
|
06-10-2015, 11:03 AM
|
#15
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Make sure that you have this version of the SWS extensions:
v2.7.1 #0 pre-release build (May 7, 2015)
http://forum.cockos.com/showthread.php?t=153702
("reaper.BR_SetTakeSourceFromFile" and some other sws-reascript functions have been in the API help docs for a long time, but they haven't been working from EEL or Lua. They should work if you download the latest pre-release build of the SWS)
|
|
|
06-10-2015, 11:32 AM
|
#16
|
Human being with feelings
Join Date: Dec 2011
Posts: 506
|
Quote:
Originally Posted by spk77
Make sure that you have this version of the SWS extensions:
v2.7.1 #0 pre-release build (May 7, 2015)
http://forum.cockos.com/showthread.php?t=153702
("reaper.BR_SetTakeSourceFromFile" and some other sws-reascript functions have been in the API help docs for a long time, but they haven't been working from EEL or Lua. They should work if you download the latest pre-release build of the SWS)
|
It works now. Thank you, you are awesome!
Now I just need to figure out how to get it to keep all of the settings like start offset and item edges. That shouldn't be too hard though.
|
|
|
06-10-2015, 11:51 AM
|
#17
|
Human being with feelings
Join Date: Dec 2011
Posts: 506
|
I just realized it already does that. I can just comment out the reaper.Main_OnCommand(40612, 0) line to get it to do what I want. Thanks again! This will really speed up my workflow!
|
|
|
06-10-2015, 12:13 PM
|
#18
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Glad it worked!
I'm trying to make a more complex version which will store: - Source item properties
- Source take properties
- Take media source properties + source filename
Then it would be possible to f.ex create media items with the stored properties, even if the source item/take is deleted from the project. (This is closely related to the script request by tomfrankly.)
Currently these are stored in "reaper-extstate.ini":
PHP Code:
[item1_take1]
take_D_STARTOFFS=4.0
take_D_VOL=1.0
take_D_PAN=0.0
take_D_PANLAW=-1.0
take_D_PLAYRATE=1.0
take_D_PITCH=0.0
take_B_PPITCH=1.0
take_I_CHANMODE=0.0
take_I_PITCHMODE=-1.0
take_I_CUSTOMCOLOR=0.0
item_B_MUTE=0.0
item_B_LOOPSRC=1.0
item_B_ALLTAKESPLAY=0.0
item_B_UISEL=1.0
item_C_BEATATTACHMODE=-1.0
item_C_LOCK=0.0
item_D_VOL=1.0
item_D_POSITION=76.0
item_D_LENGTH=42.814557823129
item_D_SNAPOFFSET=0.0
item_D_FADEINLEN=0.0
item_D_FADEOUTLEN=0.0
item_D_FADEINLEN_AUTO=0.0
item_D_FADEOUTLEN_AUTO=0.0
item_C_FADEINSHAPE=1.0
item_C_FADEOUTSHAPE=1.0
item_I_GROUPID=0.0
item_I_CUSTOMCOLOR=0.0
item_I_CURTAKE=0.0
sourcefilename=C:\Users\Pavillion 11\Desktop\Muistikortilta\MULTIBOOT\REAPER\BIISIT\allstemma3\07-kitara soolo-06 render 001.wav
|
|
|
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 11:45 PM.
|