Old 09-21-2020, 02:25 PM   #1
robgb
Human being with feelings
 
Join Date: Apr 2017
Location: Los Angeles, CA
Posts: 376
Default Record Arm Track by Track Name?

I've searched but have been unable to find a script that does this, and my own attempts have been a disaster.

I'd like to toggle record arm a track, without selecting it, based on the track name. For example, I'd like to toggle record arm a track named GUITAR 1. (I don't want to have to select the track first, or have it selected at all.)

There are Actions that allow you to "Track: Toggle Record for Track #" that do exactly what I want by number, but I'm unable to open those scripts to find out what's going on and possibly modify them. I would simply use track numbers, but if I add new tracks, the numbers change, so I need to do it by name.

Anyone have any ideas?
robgb is offline   Reply With Quote
Old 09-21-2020, 03:14 PM   #2
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
Default

Maybe something like,..

Code:
local ok, search = reaper.GetUserInputs("Toggle track record arm", 1, "Track name:", "")
if not ok then return end
search = search:lower()
for i = 0, reaper.CountTracks()-1 do
  local track = reaper.GetTrack(0, i)
  local _, name = reaper.GetTrackName(track, '') 
  if name:lower() == search then -- toggle track record arm
    reaper.SetMediaTrackInfo_Value(track, "I_RECARM",math.abs(1-reaper.GetMediaTrackInfo_Value(track, "I_RECARM")))
    break -- exit loop (apply to first matching track name only)
  end
end

Last edited by Edgemeal; 09-21-2020 at 03:21 PM.
Edgemeal is offline   Reply With Quote
Old 09-21-2020, 03:31 PM   #3
Zeno
Human being with feelings
 
Zeno's Avatar
 
Join Date: Sep 2018
Location: HH
Posts: 919
Default

Why not use reaconsole?
s 'trackname/number' a
Zeno is online now   Reply With Quote
Old 09-21-2020, 04:57 PM   #4
robgb
Human being with feelings
 
Join Date: Apr 2017
Location: Los Angeles, CA
Posts: 376
Default

Quote:
Originally Posted by Edgemeal View Post
Maybe something like,..

Code:
local ok, search = reaper.GetUserInputs("Toggle track record arm", 1, "Track name:", "")
if not ok then return end
search = search:lower()
for i = 0, reaper.CountTracks()-1 do
  local track = reaper.GetTrack(0, i)
  local _, name = reaper.GetTrackName(track, '') 
  if name:lower() == search then -- toggle track record arm
    reaper.SetMediaTrackInfo_Value(track, "I_RECARM",math.abs(1-reaper.GetMediaTrackInfo_Value(track, "I_RECARM")))
    break -- exit loop (apply to first matching track name only)
  end
end
I'd like to be able to do it without any user input, with the script already directed toward a specific track name.
robgb is offline   Reply With Quote
Old 09-21-2020, 05:09 PM   #5
robgb
Human being with feelings
 
Join Date: Apr 2017
Location: Los Angeles, CA
Posts: 376
Default

Quote:
Originally Posted by Zeno View Post
Why not use reaconsole?
s 'trackname/number' a
I don't want to select the track. I simply want to arm it via scripting.

But this did give me an idea. By using Cycle Commands, I created a new command with CONSOLE a GUITAR, and that seems to work. Thanks.
robgb is offline   Reply With Quote
Old 09-21-2020, 05:20 PM   #6
sonictim
Human being with feelings
 
sonictim's Avatar
 
Join Date: Feb 2020
Location: Los Angeles
Posts: 463
Default

Quote:
Originally Posted by robgb View Post
I'd like to be able to do it without any user input, with the script already directed toward a specific track name.
Like this?
(You will have to substitute whatever Track Name you want to arm in the first line of code)


Code:
local trackname = "Desired Track You want to Record Arm Name"

trackname = trackname:lower()

for i = 0, reaper.CountTracks()-1 do
  local track = reaper.GetTrack(0, i)
  local _, name = reaper.GetTrackName(track, '') 
  if name:lower() == trackname then -- toggle track record arm
    reaper.SetMediaTrackInfo_Value(track, "I_RECARM",math.abs(1-reaper.GetMediaTrackInfo_Value(track, "I_RECARM")))
    break -- exit loop (apply to first matching track name only)
  end
end
(This is just Edgemeal's code again)
sonictim is offline   Reply With Quote
Old 09-21-2020, 05:37 PM   #7
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,629
Default

Try this one. When you run it, it will ask you for the trackname.
If you enter one, it will create three actions in your actionlist, who allow you to arm, unarm and togglearm all tracks with that name(non case sensitive):

Code:
-- Create record-arm-actions, who arm/unarm/togglearm tracks with a certain name.
-- written by Meo-Ada Mespotine 22th of September 2020 - mespotine.de
-- licensed under MIT-license

retval, val = reaper.GetUserInputs("Give me a trackname", 1, "Trackname", "")
if retval==false or val=="" then reaper.MB("No action created", "Aborted", 0) return end

function WriteValueToFile(filename_with_path, value, binarymode, append)
  -- Writes value to filename_with_path
  -- Keep in mind, that you need to escape \ by writing \\, or it will not work
  -- binarymode

  -- check parameters
  if type(filename_with_path)~="string" then return -1 end
  --if type(value)~="string" then return -1 end
  value=tostring(value)
  
  -- prepare variables
  local binary, appendix, file
  if binarymode==nil or binarymode==true then binary="b" else binary="" end
  if append==nil or append==false then appendix="w" else appendix="a" end
  
  -- write file
  file=io.open(filename_with_path,appendix..binary)
  if file==nil then return -1 end
  file:write(value)
  file:close()
  return 1
end

Script=[[
-- recarm all tracks with the name "]]..val..[["
-- automatically generated by a script written by Meo-Ada Mespotine 22th of September 2020
-- licensed under an MIT-license

Trackname="]]..val..[["
for i=0, reaper.CountTracks(0)-1 do
  Track=reaper.GetTrack(0, i)
  retval, CheckTrackName=reaper.GetTrackName(Track)
  if CheckTrackName:lower()==Trackname:lower() then
    reaper.CSurf_OnRecArmChange(Track, 1)
  end
end
]]

WriteValueToFile(reaper.GetResourcePath().."/Scripts/Record_Arm_Tracks_Named_"..val..".lua", Script)

Script=[[
-- recunarm all tracks with the name "]]..val..[["
-- automatically generated by a script written by Meo-Ada Mespotine 22th of September 2020
-- licensed under an MIT-license

Trackname="]]..val..[["
for i=0, reaper.CountTracks(0)-1 do
  Track=reaper.GetTrack(0, i)
  retval, CheckTrackName=reaper.GetTrackName(Track)
  if CheckTrackName:lower()==Trackname:lower() then
    reaper.CSurf_OnRecArmChange(Track, 0)
  end
end
]]
WriteValueToFile(reaper.GetResourcePath().."/Scripts/Record_UnArm_Tracks_Named_"..val..".lua", Script)

Script=[[
-- toggle recarm of all tracks with the name "]]..val..[["
-- automatically generated by a script written by Meo-Ada Mespotine 22th of September 2020
-- licensed under an MIT-license

Trackname="]]..val..[["
for i=0, reaper.CountTracks(0)-1 do
  Track=reaper.GetTrack(0, i)
  retval, CheckTrackName=reaper.GetTrackName(Track)
  if CheckTrackName:lower()==Trackname:lower() then
    reaper.CSurf_OnRecArmChange(Track, -1)
  end
end
]]
WriteValueToFile(reaper.GetResourcePath().."/Scripts/Record_ToggleArm_Tracks_Named_"..val..".lua", Script)

Action=reaper.AddRemoveReaScript(true, 0, reaper.GetResourcePath().."/Scripts/Record_Arm_Tracks_Named_"..val..".lua", true)
Action=reaper.AddRemoveReaScript(true, 0, reaper.GetResourcePath().."/Scripts/Record_UnArm_Tracks_Named_"..val..".lua", true)
Action=reaper.AddRemoveReaScript(true, 0, reaper.GetResourcePath().."/Scripts/Record_ToggleArm_Tracks_Named_"..val..".lua", true)

reaper.MB("Created the following actions in the actionlist:\n\nRecord_Arm_Tracks_Named_"..val..".lua\nRecord_UnArm_Tracks_Named_"..val..".lua\nRecord_ToggleArm_Tracks_Named_"..val..".lua", "Success", 0)
__________________
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 09-21-2020, 11:30 PM   #8
robgb
Human being with feelings
 
Join Date: Apr 2017
Location: Los Angeles, CA
Posts: 376
Default

Quote:
Originally Posted by sonictim View Post
Like this?
(You will have to substitute whatever Track Name you want to arm in the first line of code)


Code:
local trackname = "Desired Track You want to Record Arm Name"

trackname = trackname:lower()

for i = 0, reaper.CountTracks()-1 do
  local track = reaper.GetTrack(0, i)
  local _, name = reaper.GetTrackName(track, '') 
  if name:lower() == trackname then -- toggle track record arm
    reaper.SetMediaTrackInfo_Value(track, "I_RECARM",math.abs(1-reaper.GetMediaTrackInfo_Value(track, "I_RECARM")))
    break -- exit loop (apply to first matching track name only)
  end
end
(This is just Edgemeal's code again)
I tried this earlier and got an error.
robgb is offline   Reply With Quote
Old 09-21-2020, 11:31 PM   #9
robgb
Human being with feelings
 
Join Date: Apr 2017
Location: Los Angeles, CA
Posts: 376
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
Try this one. When you run it, it will ask you for the trackname.
If you enter one, it will create three actions in your actionlist, who allow you to arm, unarm and togglearm all tracks with that name(non case sensitive):

Code:
-- Create record-arm-actions, who arm/unarm/togglearm tracks with a certain name.
-- written by Meo-Ada Mespotine 22th of September 2020 - mespotine.de
-- licensed under MIT-license

retval, val = reaper.GetUserInputs("Give me a trackname", 1, "Trackname", "")
if retval==false or val=="" then reaper.MB("No action created", "Aborted", 0) return end

function WriteValueToFile(filename_with_path, value, binarymode, append)
  -- Writes value to filename_with_path
  -- Keep in mind, that you need to escape \ by writing \\, or it will not work
  -- binarymode

  -- check parameters
  if type(filename_with_path)~="string" then return -1 end
  --if type(value)~="string" then return -1 end
  value=tostring(value)
  
  -- prepare variables
  local binary, appendix, file
  if binarymode==nil or binarymode==true then binary="b" else binary="" end
  if append==nil or append==false then appendix="w" else appendix="a" end
  
  -- write file
  file=io.open(filename_with_path,appendix..binary)
  if file==nil then return -1 end
  file:write(value)
  file:close()
  return 1
end

Script=[[
-- recarm all tracks with the name "]]..val..[["
-- automatically generated by a script written by Meo-Ada Mespotine 22th of September 2020
-- licensed under an MIT-license

Trackname="]]..val..[["
for i=0, reaper.CountTracks(0)-1 do
  Track=reaper.GetTrack(0, i)
  retval, CheckTrackName=reaper.GetTrackName(Track)
  if CheckTrackName:lower()==Trackname:lower() then
    reaper.CSurf_OnRecArmChange(Track, 1)
  end
end
]]

WriteValueToFile(reaper.GetResourcePath().."/Scripts/Record_Arm_Tracks_Named_"..val..".lua", Script)

Script=[[
-- recunarm all tracks with the name "]]..val..[["
-- automatically generated by a script written by Meo-Ada Mespotine 22th of September 2020
-- licensed under an MIT-license

Trackname="]]..val..[["
for i=0, reaper.CountTracks(0)-1 do
  Track=reaper.GetTrack(0, i)
  retval, CheckTrackName=reaper.GetTrackName(Track)
  if CheckTrackName:lower()==Trackname:lower() then
    reaper.CSurf_OnRecArmChange(Track, 0)
  end
end
]]
WriteValueToFile(reaper.GetResourcePath().."/Scripts/Record_UnArm_Tracks_Named_"..val..".lua", Script)

Script=[[
-- toggle recarm of all tracks with the name "]]..val..[["
-- automatically generated by a script written by Meo-Ada Mespotine 22th of September 2020
-- licensed under an MIT-license

Trackname="]]..val..[["
for i=0, reaper.CountTracks(0)-1 do
  Track=reaper.GetTrack(0, i)
  retval, CheckTrackName=reaper.GetTrackName(Track)
  if CheckTrackName:lower()==Trackname:lower() then
    reaper.CSurf_OnRecArmChange(Track, -1)
  end
end
]]
WriteValueToFile(reaper.GetResourcePath().."/Scripts/Record_ToggleArm_Tracks_Named_"..val..".lua", Script)

Action=reaper.AddRemoveReaScript(true, 0, reaper.GetResourcePath().."/Scripts/Record_Arm_Tracks_Named_"..val..".lua", true)
Action=reaper.AddRemoveReaScript(true, 0, reaper.GetResourcePath().."/Scripts/Record_UnArm_Tracks_Named_"..val..".lua", true)
Action=reaper.AddRemoveReaScript(true, 0, reaper.GetResourcePath().."/Scripts/Record_ToggleArm_Tracks_Named_"..val..".lua", true)

reaper.MB("Created the following actions in the actionlist:\n\nRecord_Arm_Tracks_Named_"..val..".lua\nRecord_UnArm_Tracks_Named_"..val..".lua\nRecord_ToggleArm_Tracks_Named_"..val..".lua", "Success", 0)
Thanks! I'll check it out.
robgb is offline   Reply With Quote
Old 09-22-2020, 06:39 AM   #10
robgb
Human being with feelings
 
Join Date: Apr 2017
Location: Los Angeles, CA
Posts: 376
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
Try this one. When you run it, it will ask you for the trackname.
If you enter one, it will create three actions in your actionlist, who allow you to arm, unarm and togglearm all tracks with that name(non case sensitive):

Code:
-- Create record-arm-actions, who arm/unarm/togglearm tracks with a certain name.
-- written by Meo-Ada Mespotine 22th of September 2020 - mespotine.de
-- licensed under MIT-license

retval, val = reaper.GetUserInputs("Give me a trackname", 1, "Trackname", "")
if retval==false or val=="" then reaper.MB("No action created", "Aborted", 0) return end

function WriteValueToFile(filename_with_path, value, binarymode, append)
  -- Writes value to filename_with_path
  -- Keep in mind, that you need to escape \ by writing \\, or it will not work
  -- binarymode

  -- check parameters
  if type(filename_with_path)~="string" then return -1 end
  --if type(value)~="string" then return -1 end
  value=tostring(value)
  
  -- prepare variables
  local binary, appendix, file
  if binarymode==nil or binarymode==true then binary="b" else binary="" end
  if append==nil or append==false then appendix="w" else appendix="a" end
  
  -- write file
  file=io.open(filename_with_path,appendix..binary)
  if file==nil then return -1 end
  file:write(value)
  file:close()
  return 1
end

Script=[[
-- recarm all tracks with the name "]]..val..[["
-- automatically generated by a script written by Meo-Ada Mespotine 22th of September 2020
-- licensed under an MIT-license

Trackname="]]..val..[["
for i=0, reaper.CountTracks(0)-1 do
  Track=reaper.GetTrack(0, i)
  retval, CheckTrackName=reaper.GetTrackName(Track)
  if CheckTrackName:lower()==Trackname:lower() then
    reaper.CSurf_OnRecArmChange(Track, 1)
  end
end
]]

WriteValueToFile(reaper.GetResourcePath().."/Scripts/Record_Arm_Tracks_Named_"..val..".lua", Script)

Script=[[
-- recunarm all tracks with the name "]]..val..[["
-- automatically generated by a script written by Meo-Ada Mespotine 22th of September 2020
-- licensed under an MIT-license

Trackname="]]..val..[["
for i=0, reaper.CountTracks(0)-1 do
  Track=reaper.GetTrack(0, i)
  retval, CheckTrackName=reaper.GetTrackName(Track)
  if CheckTrackName:lower()==Trackname:lower() then
    reaper.CSurf_OnRecArmChange(Track, 0)
  end
end
]]
WriteValueToFile(reaper.GetResourcePath().."/Scripts/Record_UnArm_Tracks_Named_"..val..".lua", Script)

Script=[[
-- toggle recarm of all tracks with the name "]]..val..[["
-- automatically generated by a script written by Meo-Ada Mespotine 22th of September 2020
-- licensed under an MIT-license

Trackname="]]..val..[["
for i=0, reaper.CountTracks(0)-1 do
  Track=reaper.GetTrack(0, i)
  retval, CheckTrackName=reaper.GetTrackName(Track)
  if CheckTrackName:lower()==Trackname:lower() then
    reaper.CSurf_OnRecArmChange(Track, -1)
  end
end
]]
WriteValueToFile(reaper.GetResourcePath().."/Scripts/Record_ToggleArm_Tracks_Named_"..val..".lua", Script)

Action=reaper.AddRemoveReaScript(true, 0, reaper.GetResourcePath().."/Scripts/Record_Arm_Tracks_Named_"..val..".lua", true)
Action=reaper.AddRemoveReaScript(true, 0, reaper.GetResourcePath().."/Scripts/Record_UnArm_Tracks_Named_"..val..".lua", true)
Action=reaper.AddRemoveReaScript(true, 0, reaper.GetResourcePath().."/Scripts/Record_ToggleArm_Tracks_Named_"..val..".lua", true)

reaper.MB("Created the following actions in the actionlist:\n\nRecord_Arm_Tracks_Named_"..val..".lua\nRecord_UnArm_Tracks_Named_"..val..".lua\nRecord_ToggleArm_Tracks_Named_"..val..".lua", "Success", 0)
OKAY, this script is quite ingenious. THANK YOU SO MUCH for this. It's perfect. I've also looked at the scripts it generated to see where I initially went wrong, so it's been educational also.
robgb is offline   Reply With Quote
Old 09-22-2020, 07:39 AM   #11
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,629
Default

You're welcome
__________________
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 09-22-2020, 09:38 AM   #12
lexaproductions
Human being with feelings
 
Join Date: Jan 2013
Posts: 1,128
Default

reaconsole can enable tracks. No need for scripting there.
I think you can even setup a key command with the appropriate letter already setup in the console when opening it.
lexaproductions is offline   Reply With Quote
Old 09-22-2020, 02:58 PM   #13
robgb
Human being with feelings
 
Join Date: Apr 2017
Location: Los Angeles, CA
Posts: 376
Default

Quote:
Originally Posted by lexaproductions View Post
reaconsole can enable tracks. No need for scripting there.
I think you can even setup a key command with the appropriate letter already setup in the console when opening it.
Yes, I figured out how to do it using cycle commands and reaconsole, but I much prefer @Meo-Ada Mespotine's method.
robgb 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 01:12 PM.


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