Old 01-14-2018, 04:13 AM   #1
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,691
Default LUA: Play offset in seconds

This script is for post production users (or anyone else who need this) made for this request
https://forum.cockos.com/showthread.php?t=171241

Script simulates pre-roll but in seconds, not related with BPM since native pre-roll cannot do this.



There are 2 scripts:
1. Main script which always runs in background
2. Script with GUI where you enter the offset in seconds

Main script
Code:
local off_cur,time

function main()
local store = reaper.GetExtState( "playoffset", "time" )
  if store ~= "" then time = store else time = 0 end
local state = reaper.GetPlayState() -- GET TRANSPORT STATE
cur_pos = reaper.GetCursorPosition() -- GET EDIT CURSOR POSITION IN STOP MODE 
if state == 0 then -- IF STOPED
  stop_pos = cur_pos
  if last_state ~= nil then -- IF PREVIOUS STATE WAS PLAY OR RECORD
    reaper.SetEditCurPos(store_cur,1, 1 ) -- RESTORE ORIGINAL EDIT CURSOR POSITION
    last_state = nil -- RESET LAST TRANSPORT STATE
    store_cur = nil -- RESET STORED EDIT CURSOR POSITION
  else
    store_cur = cur_pos -- STORE ORIGINAL EDIT CURSOR POSITION
    off_cur = cur_pos - time -- OFFSET CURSOR
  end
else
  play_pos = cur_pos + time-- GET EDIT CURSOR POSITION IN PLAY OR RECORD MODE    
end  

if state ~= 0 and off_cur then
  reaper.SetEditCurPos( off_cur,1, 1 ) -- MOVE CURSOR WITH OFFSET
  last_state = state  -- SAVE LAST TRANSPORT STATE (PLAY OR RECORD)
  off_cur = nil
end

reaper.defer(main)
end
main()
Input script:
Code:
local time
local store = reaper.GetExtState( "playoffset", "time" )
  if store then
    time = store
  end
  
local retval, value = reaper.GetUserInputs("PlayCursor Offset", 1, "Offset (seconds)", time)
if retval == true then 
  time = value 
  reaper.SetExtState( "playoffset", "time", time, 0)
end
Both script will be available on ReaPack my repo but I need to install it again (I'm lazy) since I got new system.

Post bugs,FR etc

Last edited by Sexan; 01-14-2018 at 06:06 AM.
Sexan is offline   Reply With Quote
Old 01-14-2018, 04:20 AM   #2
mlprod
Human being with feelings
 
Join Date: Jul 2015
Location: Stockholm, Sweden
Posts: 1,344
Default

Sorry if this is considering hijacking, but I am just wondering if its possible to do the same but for online rendering?
__________________
Magnus Lindberg Productions - VRTKL Audio - Redmount Studios
magnuslindberg.com
mlprod is offline   Reply With Quote
Old 01-14-2018, 04:25 AM   #3
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,691
Default

Sorry that is not possible...

Edit: Just a second I think its possible
Sexan is offline   Reply With Quote
Old 01-14-2018, 04:40 AM   #4
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,691
Default

Here you go:
Code:
function main()
local retval, offset = reaper.GetUserInputs("Render Offset", 1, "Offset (seconds)", 1)
local tstart, tend = reaper.GetSet_LoopTimeRange(false, false, 0, 0, false) -- Get TimeSelection
reaper.GetSet_LoopTimeRange(true, false, tstart-offset, tend, false) -- offset time selection start
reaper.Main_OnCommand(41824,0) -- render with recent settings
reaper.GetSet_LoopTimeRange(true, false, tstart, tend, false) -- restore original 
end
main()

You must set your render settings before you use this script since its calling a action that uses "Recent Render Settings"
Sexan is offline   Reply With Quote
Old 01-14-2018, 05:53 AM   #5
mlprod
Human being with feelings
 
Join Date: Jul 2015
Location: Stockholm, Sweden
Posts: 1,344
Default

Wow nice!
Is it possible that the resulting file will actually start at the original time sel start, so that it doesnt actually render during pre-roll?
__________________
Magnus Lindberg Productions - VRTKL Audio - Redmount Studios
magnuslindberg.com
mlprod is offline   Reply With Quote
Old 01-14-2018, 05:59 AM   #6
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,691
Default

Not sure if I've understood you. You want to render WITH pre-roll or you just want to LISTEN the pre-roll without rendering it (renders the original section)?

In case you want to just listen the pre roll, and not render it then the original script will do that while rendering online (btw I'm PRETTY sure this should not be happening (from Reapers side) but ok the side effect is nice)

Last edited by Sexan; 01-14-2018 at 06:14 AM.
Sexan is offline   Reply With Quote
Old 01-14-2018, 06:27 AM   #7
mlprod
Human being with feelings
 
Join Date: Jul 2015
Location: Stockholm, Sweden
Posts: 1,344
Default

Wow that is indeed a nice side effect. For me it doesnt seem to work like that, the cursor starts from the start of the project for some reason. (running scrips number 2 at 2 seconds)

EDIT: I see the edit corsor needs to be at the start of time sel.
But for me now, the resulting file instead is 2 seconds longer (after end of time sel).
__________________
Magnus Lindberg Productions - VRTKL Audio - Redmount Studios
magnuslindberg.com
mlprod is offline   Reply With Quote
Old 01-14-2018, 06:57 AM   #8
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,691
Default

Yeah I see it now, I think its not possible to do it (thats why this for some reason is working/breaking reaper render settings).Sorry
Sexan is offline   Reply With Quote
Old 01-14-2018, 08:12 AM   #9
Ice
Human being with feelings
 
Join Date: Aug 2014
Posts: 887
Default

Very cool - 1 really basic question.

How do we stop a script that runs like this in the background? I guess I could toggle it to be 0 seconds but I'm still curious how to stop these.

And thanks!
Ice is offline   Reply With Quote
Old 01-14-2018, 08:17 AM   #10
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,691
Default

well you cannot stop it. I've made it this way so you do not need to bind another key for it. If you want I can make it to be on activate,so basically it will be another "play/stop" shortcut.

But If you mean how to terminate a running background scripts then :
Open actions menu and at the bottom you will see running scripts,click on it and terminate
Sexan is offline   Reply With Quote
Old 01-14-2018, 09:29 AM   #11
mlprod
Human being with feelings
 
Join Date: Jul 2015
Location: Stockholm, Sweden
Posts: 1,344
Default

Quote:
Originally Posted by Sexan View Post
Yeah I see it now, I think its not possible to do it (thats why this for some reason is working/breaking reaper render settings).Sorry
Thanks anyway for trying!
__________________
Magnus Lindberg Productions - VRTKL Audio - Redmount Studios
magnuslindberg.com
mlprod 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 06:37 AM.


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