Old 06-06-2023, 07:47 PM   #1
AudioBabble
Human being with feelings
 
AudioBabble's Avatar
 
Join Date: Dec 2021
Location: Jupiter Island
Posts: 924
Default Ultraschall shuttle script

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?
AudioBabble is offline   Reply With Quote
Old 06-07-2023, 02:46 AM   #2
fernsehmuell
Human being with feelings
 
Join Date: Jun 2016
Location: Wacken
Posts: 15
Default

Hello,

i wrote these scripts a long time ago
You should look at the init function of the reverse script. When it starts it’s sets the speed to 1. You could check if the forward script is running and get it‘s speed and set it here accordingly.

If i find the time i can have a look.
fernsehmuell is offline   Reply With Quote
Old 06-07-2023, 08:07 AM   #3
AudioBabble
Human being with feelings
 
AudioBabble's Avatar
 
Join Date: Dec 2021
Location: Jupiter Island
Posts: 924
Default

Quote:
Originally Posted by fernsehmuell View Post
Hello,

i wrote these scripts a long time ago
You should look at the init function of the reverse script. When it starts it’s sets the speed to 1. You could check if the forward script is running and get it‘s speed and set it here accordingly.

If i find the time i can have a look.
Thanks for the pointer, I will see if I can figure something out. No doubt I'll be reporting back!
AudioBabble is offline   Reply With Quote
Old 06-07-2023, 09:47 AM   #4
AudioBabble
Human being with feelings
 
AudioBabble's Avatar
 
Join Date: Dec 2021
Location: Jupiter Island
Posts: 924
Default

Ok... I have to admit this is pretty advanced stuff for me!

One thing that does interest me is how/where is the function that allows reverse playing in the first place? -- if I understand correctly, this is not something Reaper is normally capable of doing?

EDIT: ^^not sure where I got that idea (maybe from a very old post?)

anyway -- now I see it's basically the get_position and check_position functions in the reverse script -- as simple as moving the cursor with reaper.MoveEditCursor

Glad it's not some magic voodoo... things are slowly starting to make sense!

Last edited by AudioBabble; 06-07-2023 at 11:33 AM.
AudioBabble is offline   Reply With Quote
Old 06-07-2023, 11:17 AM   #5
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

It's some time ago, since I did it, but I think you need to turn on the scrub-option in the preferences. It's correctly if dragging the edit cursor on its triangle makes Reaper output sound.

Then use the MoveEditCursor-function with playseek-parameter set to on, but I don't remember how it's done. Should be documented in the Api-reference though.
Negative timeoffset makes it negative...
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine 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 07:39 AM.


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