I've been looking at 4 scripts on Ultraschall that control the shuttling action:
ultraschall_shuttle_background_script
ultraschall_shuttle_backward
ultraschall_shuttle_forward
ultraschall_shuttle_pause
https://github.com/Ultraschall/ultra...und_script.lua
Currently the shuttle script is set to start playing backwards if J is pressed when playing forward, or to start playing forwards of L is pressed when playing backwards, regardless of the speed of playback.
In Adobe Audition, the same keys are used for shuttling, however if the speed of playing is greater than 1x, then pressing the opposite play direction key first decreases the speed in the direction it is playing until the speed reaches 1x and only then does the direction reverse.
I've posted this on the Ultraschall community board as an FR, but in the meantime I've been looking at the code myself.
Unfortunately, the coding is a bit advanced for me at the moment, although I can kinda see what's going on:
Code:
function playing_reverse_state()
_ ,value=reaper.GetProjExtState(0, "Ultraschall", "Reverse_Play_Shuttle") --check if reverse playing
-- 1 = rev play is active
-- 2 = rev play pressed again -> increase speed
-- 3 = fwd shutle play was pressed (fwd script) -> exit rev-background script and press play
if not tonumber(value) then value="0" end
-- only allow "1","2", and "3" else return 0
if value=="1" then return 1
elseif value=="2" then return 2
elseif value=="3" then return 3
else return 0
end
end
...and
Code:
function runloop() --BACKGROUND Loop
if (reaper.GetPlayState() & 4)==4 then return end --exit if recording!!
if playing_reverse_state()==2 then --increase speed
speed=math.min(speed+1, max_speed)
starttime=reaper.time_precise() --get actual time after speedchange!
reaper.SetProjExtState(0, "Ultraschall", "Reverse_Play_Shuttle", 1) -- store state in datastore
start_position=get_position()
end
if playing_reverse_state()==1 and ( (reaper.GetPlayState() & 1==1) or (reaper.GetPlayState() & 2==2) ) and reaper.GetCursorPosition()>0 then --reverse playing -> move cursor
time_passed=(reaper.time_precise()-starttime) * speed_list[speed]
reaper.MoveEditCursor(start_position-time_passed-reaper.GetCursorPosition(), 0)
reaper.CSurf_OnPlayRateChange(1.0+speed_list[speed]/10000.0+0.00005) -- encode speed in Playratevalue 1x -> 1.0001, 100x -> 1.0100
reaper.defer(runloop) -- restart loop
end
if playing_reverse_state()==3 then --fwd shuttle play was pressed: stop reverse playing and play forward
reaper.Main_OnCommand(40521, 0) -- set play speed to 1
reaper.SetProjExtState(0, "Ultraschall", "Reverse_Play_Shuttle", 0) -- store state in datastore
reaper.Main_OnCommand(1016,0) --stop
reaper.OnPlayButton() --play
ignoreonexit=true
end
end
Somehow, I would like to add more return values to playing_reverse_state() and more conditionals to runloop(), such that if the payrate is greater than 1.0, then if fwd is pressed then the speed is decremented until it reaches 1.0001 (playing backwards at "normal" speed), after which fwd play is triggered.
... and the opposite!
I know it's probably a big ask (and I wish I knew more about lua scripting, but I am trying to learn) -- but was hoping somebody might be able to give me some pointers?