Old 06-29-2018, 05:18 AM   #1
tompad
Human being with feelings
 
Join Date: Jan 2010
Location: Fjugesta, Sweden
Posts: 376
Default API for Automatic record-arm when selected

Hi!

I am beginner reascripter searching for API for GET/SET tracks
"Automatic record-arm when selected"-function but cant find it.
Is there none??
__________________
ToDoList Obliques MusicMath Donation Mark4celeste Frid i ditt hjärta Eve & the Fisherman on Spotify
tompad is offline   Reply With Quote
Old 06-29-2018, 06:08 AM   #2
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,355
Default

It exists in the API for extensions, but isn't exposed for scripts to use.

However, you can work with the track chunk directly:
Code:
local function Msg(str)
    reaper.ShowConsoleMsg(tostring(str) .. "\n")
end


-- Accepts a multiline string and splits each line into a separate table value
-- Returns the table
local function split_by_line(str)
    
    local t = {}
    for line in string.gmatch(str, "[^\r\n]+") do
        t[#t+1] = line
    end
    
    return t
    
end


-- Accepts an indexed table and a string
-- Returns the first index whose value contains the string
local function find_in_table(t, str)
    
    for i = 1, #t do
        if string.match(t[i], str) then return i end
    end
    
    return nil
    
end


local function Main()

    -- Get a MediaTrack somehow
    local track = reaper.GetSelectedTrack(0, 0)
    if not track then return end
    
    -- Get the chunk
    local ret, chunk = reaper.GetTrackStateChunk(track, "", false)
    if not ret then return end
    
    --[[    The chunk is a string that looks like this:
        
      <TRACK {BF616BDB-CEAD-4D9C-9310-C650B8A0666A}
        NAME ""
        PEAKCOL 16576
        BEAT -1
        AUTOMODE 0
        VOLPAN 1 0 -1 -1 1
        MUTESOLO 0 0 0
        IPHASE 0
        ISBUS 0 0
        BUSCOMP 0 0
        SHOWINMIX 1 0.6667 0.5 1 0.5 0 0 0
        FREEMODE 0
        SEL 0
        REC 0 3 0 0 0 0 0
        AUTO_RECARM 1
        VU 2
        TRACKHEIGHT 0 0 0
        INQ 0 0 0 0.5 100 0 0 100
        NCHAN 2
        FX 1
        TRACKID {BF616BDB-CEAD-4D9C-9310-C650B8A0666A}
        PERF 0
        MIDIOUT -1
        MAINSEND 1 0
      >
      
    ]]--    
    
    -- Convert it to a table to make our lives easier
    chunk = split_by_line(chunk)
    
    local idx = find_in_table(chunk, "AUTO_RECARM")

    
    -- Boolean of the Auto Rec-Arm state
    local state = ( idx and chunk[idx] == "AUTO_RECARM 1" )



    -- Things you can do with it now:
    
    -- Force it to be on
    --[[
    if idx then
        chunk[idx] = "AUTO_RECARM 1"
    else
        table.insert(chunk, #chunk, "AUTO_RECARM 1")
    end
    ]]--
    
    
    -- Force it to be off (just remove the entry)
    --if idx then table.remove(chunk, idx) end


    -- Toggle it
    state = not state
    if state then
        if idx then
            chunk[idx] = "AUTO_RECARM 1"
        else
            table.insert(chunk, #chunk, "AUTO_RECARM 1")
        end
    else
        if idx then table.remove(chunk, idx) end
    end
    
    
    -- We have to use table.insert to avoid overwriting the chunk's final >, or writing
    -- something after it
    
    
    -- Write the new chunk
    -- Change the 'true' to 'false' if you're doing this multiple times and only want
    -- a single undo point for the whole process
    chunk = table.concat(chunk, "\n")
    
    reaper.SetTrackStateChunk( track, chunk, true)
    
    local ret, new = reaper.GetTrackStateChunk(track, "", false)
    
    -- Reaper sometimes doesn't realize it needs to update things when we fiddle with stuff
    reaper.UpdateTimeline()
    
end

Main()
Lokasenna is online now   Reply With Quote
Old 06-29-2018, 06:46 AM   #3
tompad
Human being with feelings
 
Join Date: Jan 2010
Location: Fjugesta, Sweden
Posts: 376
Default

Uhuuuu!

Oh I need to be more clear in my head and read this thru a couple of times!
I think I understand it but need to test it - I'll be back.
Thanks Lokasenna!
__________________
ToDoList Obliques MusicMath Donation Mark4celeste Frid i ditt hjärta Eve & the Fisherman on Spotify
tompad is offline   Reply With Quote
Old 06-29-2018, 09:21 AM   #4
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,114
Default

Quote:
Originally Posted by Lokasenna View Post
It exists in the API for extensions, but isn't exposed for scripts to use.
Which function is this ?
(I may have a look exporting it to ReaScript via SWS)
nofish is offline   Reply With Quote
Old 06-29-2018, 09:44 AM   #5
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,355
Default

Possibly an incorrect assumption on my part - I saw CSURF_EXT_SETAUTORECARM in https://github.com/reaper-oss/sws/bl...eaper_plugin.h when I was looking.
Lokasenna is online now   Reply With Quote
Old 06-30-2018, 02:51 AM   #6
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 7,962
Default

Quote:
Originally Posted by Lokasenna View Post
Possibly an incorrect assumption on my part - I saw CSURF_EXT_SETAUTORECARM in https://github.com/reaper-oss/sws/bl...eaper_plugin.h when I was looking.
That appears to be a callback Reaper makes into a control surface plugin, not a call an extension code itself can make.
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass, Paul(X)Stretch and λ) :
http://xenakios.wordpress.com/
Xenakios is online now   Reply With Quote
Old 06-06-2019, 07:03 PM   #7
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 844
Default

Thread necro. Just wanted to chime in to say I'm looking for this too. It seems to be missing from the API.
tack is online now   Reply With Quote
Old 06-07-2019, 06:48 AM   #8
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,114
Default

You could do chunking, "AUTO_RECARM 1" is added to track state chunk if track is set to automatic record arm.



But proper API is always preferred of course.

edit:
Missed that Lokasenna already mentioned it.
nofish is offline   Reply With Quote
Old 06-07-2019, 06:52 AM   #9
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 844
Default

The problem there is I need to get and set this value over a large project (~100 tracks) and when you're doing a full get/set track state chunk on that many tracks it's sslllooowwwww.
tack is online now   Reply With Quote
Old 06-07-2019, 07:36 AM   #10
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 2,542
Default

Quote:
Originally Posted by tack View Post
The problem there is I need to get and set this value over a large project (~100 tracks) and when you're doing a full get/set track state chunk on that many tracks it's sslllooowwwww.
Open RPP in any text editor and replace all strings at once.
__________________
SoundCloud | MPL Scripts discussion | ReaPack | Donate
mpl is offline   Reply With Quote
Old 06-07-2019, 07:45 AM   #11
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 844
Default

Quote:
Originally Posted by mpl View Post
Open RPP in any text editor and replace all strings at once.
I can have my often-used action first popup a message with instructions, and then spawn notepad to have the user search/and replace manually. Genius!
tack is online now   Reply With Quote
Old 06-08-2019, 02:00 AM   #12
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,621
Default

I think, I've added that to my Ultraschall-Api as well.

Edit:
Get Autorecarm-State:
https://mespotin.uber.space/Ultrasch...utoRecArmState
Set Autorecarm-State:
https://mespotin.uber.space/Ultrasch...utoRecArmState
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 06-08-2019, 06:43 AM   #13
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,355
Default

Quote:
Originally Posted by mespotine View Post
I think, I've added that to my Ultraschall-Api as well.

Edit:
Get Autorecarm-State:
https://mespotin.uber.space/Ultrasch...utoRecArmState
Set Autorecarm-State:
https://mespotin.uber.space/Ultrasch...utoRecArmState
Worth noting that these functions wrap the state chunk stuff, so while they're easier to use it would still have performance issues on large projects.
Lokasenna is online now   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 12:03 PM.


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