Old 06-29-2018, 05:18 AM   #1
tompad
Human being with feelings
 
Join Date: Jan 2010
Location: Fjugesta, Sweden
Posts: 811
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 Some of mine and my friends music projects 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,551
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()
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 06-29-2018, 06:46 AM   #3
tompad
Human being with feelings
 
Join Date: Jan 2010
Location: Fjugesta, Sweden
Posts: 811
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 Some of mine and my friends music projects 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: 12,096
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,551
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.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   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: 8,062
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.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   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: 1,618
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: 12,096
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: 1,618
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: 3,960
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.
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: 1,618
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
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,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
__________________
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
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,551
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.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna 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 02:02 PM.


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