Old 09-08-2015, 12:00 PM   #1
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default Lua : Folder Rec-Arm arms child Tracks

Latest version of the script,based on SPK77 (90%) code and modified to work with monitoring also and some other features

When folder is rec-armed its input is disabled to avoid double monitoring or recording on the folder track.After rec-disarming folder input is reverted to what was set before.Individual tracks within the folder can be armed or disarmed individually (regardless of the folder arming) and the same for monitoring.

It would be cool if SKP77 would approve this to be in ReaScript tool in his repository
https://stash.reaper.fm/27319/FolderR...o_children.lua

Last edited by Sexan; 04-15-2016 at 08:36 AM.
Sexan is offline   Reply With Quote
Old 09-08-2015, 12:30 PM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,874
Default

Nice job :O
X-Raym is offline   Reply With Quote
Old 09-09-2015, 02:56 AM   #3
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

Edit: news in first post

Last edited by Sexan; 09-09-2015 at 06:03 AM.
Sexan is offline   Reply With Quote
Old 09-11-2015, 01:16 AM   #4
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

edit...

Last edited by Sexan; 04-15-2016 at 08:31 AM.
Sexan is offline   Reply With Quote
Old 09-11-2015, 11:29 AM   #5
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

new update:
-Childs can be monitor enabled individually and globally
-Folder restores last selected input after monitor enabled(when monitor enabled it goes to non-input so cuz of feedback)

https://stash.reaper.fm/25092/SmartRe...dersUPDATE.lua
Sexan is offline   Reply With Quote
Old 09-20-2015, 07:03 AM   #6
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

edit...

Last edited by Sexan; 04-15-2016 at 08:31 AM.
Sexan is offline   Reply With Quote
Old 09-21-2015, 12:18 AM   #7
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,581
Default

(subscribe!)
__________________
Puzzle Factory Sound Studios, London [Website] [Instagram]
[AMD 5800X, 32Gb RAM, Win10x64, NVidia GTX1080ti, UAD2-OCTO, FireFaceUCX, REAPER x64]
[Feature request: More details in Undo History]
daxliniere is offline   Reply With Quote
Old 09-21-2015, 07:05 AM   #8
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

Pleeeaaaaaseeee anyone por favor!
Sexan is offline   Reply With Quote
Old 09-28-2015, 11:12 AM   #9
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

I tried a different approach...

I recently found these functions:
  • reaper.GetProjectStateChangeCount
  • reaper.Undo_CanUndo2

We can monitor for rec arm button presses (and many other things)...

...this means that it's possible to (greatly) reduce the cpu usage with this "method"



Here's an example:
Code:
function msg(m)
  reaper.ShowConsoleMsg(tostring(m) .. "\n")
end

local last_proj_change_count = reaper.GetProjectStateChangeCount(0)


-- Returns a track's folder depth
function get_track_folder_depth(track_index)
  local folder_depth = 0
  for i=0, track_index do -- loop from start of tracks to "track_index"... 
    local track = reaper.GetTrack(0, i)
    folder_depth = folder_depth + reaper.GetMediaTrackInfo_Value(track, "I_FOLDERDEPTH") -- ...to get the actual folder depth
  end
  return folder_depth
end


-----------------------
-- on_rec_arm_change --
-----------------------
--  this function is called when rec arm button is pressed on some track

function on_rec_arm_change(track_pointer, track_index)
  -- If this function is called, we know that:
  --   last touched track is a folder track (parent)
  --   rec-arm button was clicked on that track
  
 
  -- call "get_track_folder_depth" to get the actual folder depth
  local parent_folder_depth = get_track_folder_depth(track_index)
  
  local parent_rec_arm = reaper.GetMediaTrackInfo_Value(track_pointer, "I_RECARM") -- get (parent) track's rec arm state
  
  -- loop from" parent track index" to end of tracks (break when last child is found)
  for i = track_index + 1, reaper.CountTracks(0) do
    child_track = reaper.GetTrack(0, i-1)
    reaper.SetMediaTrackInfo_Value(child_track, "I_RECARM", parent_rec_arm)
  
    child_track_folder_depth = parent_folder_depth + reaper.GetMediaTrackInfo_Value(child_track, "I_FOLDERDEPTH")
    if child_track_folder_depth < parent_folder_depth then
      break -- break when last child is found
    end  
  end

  reaper.UpdateArrange()                -- update arrange view
  reaper.TrackList_AdjustWindows(false) -- update tracklist
end



-----------------------------
-- on_project_state_change --
-----------------------------
--  this function is called when project state changes

function on_project_state_change(last_action)
  local last_a = last_action
  -- if last action (that changed the project state) was "Toggle Track Record Arming"...
  if last_action == "Toggle Track Record Arming" then
    local last_touched_track = reaper.GetLastTouchedTrack() -- get last touched track's "track pointer"
    local last_touched_track_name, flags = reaper.GetTrackState(last_touched_track)
    local last_touched_track_index = reaper.CSurf_TrackToID(last_touched_track, false) - 1 -- get track index from "last touched track"
   
    -- Check if last_touched_track was a folder track
    if flags&1 ~= 1 then -- if last_touched track was not a folder (parent)...
      return -- ...return to main function...
    end
    
    msg("Rec arm was pressed on track named: " .. last_touched_track_name)
    msg("Track number: " .. last_touched_track_index+1 .. "\n")
    
    on_rec_arm_change(last_touched_track, last_touched_track_index) -- ...(else) call "on_rec_arm_change"
  end
end


----------
-- Main --
----------

function main()
  local proj_change_count = reaper.GetProjectStateChangeCount(0)
  if proj_change_count > last_proj_change_count then
    local last_action = reaper.Undo_CanUndo2(0) -- get last action
    if last_action ~= nil then
      msg("--------------------------------")
      msg("Last action: " .. last_action)
      on_project_state_change(last_action) -- call "on_project_state_change" to update something if needed
    end
    last_proj_change_count = proj_change_count -- store "Project State Change Count" for the next pass
  end
  reaper.defer(main)    
end

main()
spk77 is offline   Reply With Quote
Old 09-28-2015, 01:12 PM   #10
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

AWESOME!!!!!!!!! Would you please implement monitoring and inputs?
Thank you !
Sexan is offline   Reply With Quote
Old 09-28-2015, 01:36 PM   #11
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,874
Default

@spk77

the code snippet for knowing what last action is used is pretty useful !
It doesn't work with all actions I tested but it is very coo, even just for copy pasting action names for writing a tutorial !
X-Raym is offline   Reply With Quote
Old 09-29-2015, 02:01 AM   #12
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

edit...

Last edited by Sexan; 04-15-2016 at 08:25 AM.
Sexan is offline   Reply With Quote
Old 04-15-2016, 08:30 AM   #13
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

Latest version of the script,based on SPK77 (90%) code and modified to work with monitoring also and some other features

When folder is rec-armed its input is disabled to avoid double monitoring or recording on the folder track.After rec-disarming folder input is reverted to what was set before.Individual tracks within the folder can be armed or disarmed individually (regardless of the folder arming) and the same for monitoring.

It would be cool if SKP77 would approve this to be in ReaPack tool in his repository
https://stash.reaper.fm/27319/FolderR...o_children.lua

Last edited by Sexan; 04-15-2016 at 08:37 AM.
Sexan is offline   Reply With Quote
Old 12-13-2017, 07:28 PM   #14
Plant
Human being with feelings
 
Join Date: Jun 2009
Posts: 21
Default

Hi! Can't make last version work.
Previous (https://stash.reaper.fm/25092/SmartRe...dersUPDATE.lua)
is ok, but it automatically sets the same input for all child tracks.
Plant is offline   Reply With Quote
Old 12-14-2017, 07:56 AM   #15
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

Quote:
Originally Posted by Plant View Post
Hi! Can't make last version work.
Previous (https://stash.reaper.fm/25092/SmartRe...dersUPDATE.lua)
is ok, but it automatically sets the same input for all child tracks.
Yeah its broken, somewhere in some Reaper updates they changed the way actions are displayed. For example they used to be "Toggle Track Record" and now its "Toggle track record". Will fix it soon
Sexan is offline   Reply With Quote
Old 12-22-2019, 06:13 AM   #16
HurdyGuigui
Human being with feelings
 
Join Date: Nov 2014
Posts: 17
Default

Hello,
I tried different versions and couldn't make it work. Are all of them broken? I would use this a lot.

Thank you
HurdyGuigui is offline   Reply With Quote
Old 09-19-2020, 01:22 AM   #17
HurdyGuigui
Human being with feelings
 
Join Date: Nov 2014
Posts: 17
Default

Quote:
Originally Posted by Sexan View Post
Yeah its broken, somewhere in some Reaper updates they changed the way actions are displayed. For example they used to be "Toggle Track Record" and now its "Toggle track record". Will fix it soon
I did those changes and it is working now . Submited a pull request on your gihub.

EDIT : Also changed the condition of change detection in the main() function because it didn't work across tabs, because each tab has its own GetProjectStateChangeCount(0) counter.
So instead of :
if proj_change_count > last_proj_change_count then
I did :
if proj_change_count ~= last_proj_change_count then
Seems to work flawlessly now !

Last edited by HurdyGuigui; 09-19-2020 at 02:34 AM. Reason: Some more changes
HurdyGuigui is offline   Reply With Quote
Old 09-19-2020, 05:52 AM   #18
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

Will merge but just fix this also:

Code:
local last_action = reaper.Undo_CanUndo2(0)
to
Code:
local last_action = reaper.Undo_CanUndo2(0):lower()
this way all action names will be lowercase so there will not be any issue later

And after you need to change every action name to lowercase:

Code:
    if last_a ==  "toggle track record arming" then
Sexan is offline   Reply With Quote
Old 09-20-2020, 06:35 AM   #19
HurdyGuigui
Human being with feelings
 
Join Date: Nov 2014
Posts: 17
Default

Quote:
Originally Posted by Sexan View Post
Will merge but just fix this also:

Code:
local last_action = reaper.Undo_CanUndo2(0)
to
Code:
local last_action = reaper.Undo_CanUndo2(0):lower()
this way all action names will be lowercase so there will not be any issue later

And after you need to change every action name to lowercase:

Code:
    if last_a ==  "toggle track record arming" then
Smart . I just did it
HurdyGuigui is offline   Reply With Quote
Old 10-07-2020, 06:22 AM   #20
mozart999uk
Human being with feelings
 
Join Date: Nov 2010
Posts: 1,721
Default

Sorry for being dense, I just tried this "folder record monitor arming childs ", but couldn't make it work.

Is that the right script?
mozart999uk is offline   Reply With Quote
Old 10-28-2020, 04:04 PM   #21
mauflows
Human being with feelings
 
Join Date: Oct 2020
Posts: 2
Default

I also don't see any updates. Is this the right repository? https://github.com/ReaTeam/ReaScript...20Children.lua
mauflows is offline   Reply With Quote
Old 04-09-2021, 11:22 AM   #22
Buy One
Human being with feelings
 
Buy One's Avatar
 
Join Date: Sep 2019
Posts: 1,131
Default

Until merged the updated version can be downloaded here

Last edited by Buy One; 04-09-2021 at 12:47 PM.
Buy One is online now   Reply With Quote
Old 03-20-2023, 05:04 PM   #23
Edson
Human being with feelings
 
Join Date: Mar 2023
Posts: 2
Default

Quote:
Originally Posted by Sexan View Post
Latest version of the script,based on SPK77 (90%) code and modified to work with monitoring also and some other features

When folder is rec-armed its input is disabled to avoid double monitoring or recording on the folder track.After rec-disarming folder input is reverted to what was set before.Individual tracks within the folder can be armed or disarmed individually (regardless of the folder arming) and the same for monitoring.

It would be cool if SKP77 would approve this to be in ReaScript tool in his repository
https://stash.reaper.fm/27319/Folder...o_children.lua

Please friend I'm new to Reaper could you help me to use the script
Edson is offline   Reply With Quote
Old 03-20-2023, 05:05 PM   #24
Edson
Human being with feelings
 
Join Date: Mar 2023
Posts: 2
Default

Quote:
Originally Posted by spk77 View Post
I tried a different approach...

I recently found these functions:
  • reaper.GetProjectStateChangeCount
  • reaper.Undo_CanUndo2

We can monitor for rec arm button presses (and many other things)...

...this means that it's possible to (greatly) reduce the cpu usage with this "method"



Here's an example:
Code:
function msg(m)
  reaper.ShowConsoleMsg(tostring(m) .. "\n")
end

local last_proj_change_count = reaper.GetProjectStateChangeCount(0)


-- Returns a track's folder depth
function get_track_folder_depth(track_index)
  local folder_depth = 0
  for i=0, track_index do -- loop from start of tracks to "track_index"... 
    local track = reaper.GetTrack(0, i)
    folder_depth = folder_depth + reaper.GetMediaTrackInfo_Value(track, "I_FOLDERDEPTH") -- ...to get the actual folder depth
  end
  return folder_depth
end


-----------------------
-- on_rec_arm_change --
-----------------------
--  this function is called when rec arm button is pressed on some track

function on_rec_arm_change(track_pointer, track_index)
  -- If this function is called, we know that:
  --   last touched track is a folder track (parent)
  --   rec-arm button was clicked on that track
  
 
  -- call "get_track_folder_depth" to get the actual folder depth
  local parent_folder_depth = get_track_folder_depth(track_index)
  
  local parent_rec_arm = reaper.GetMediaTrackInfo_Value(track_pointer, "I_RECARM") -- get (parent) track's rec arm state
  
  -- loop from" parent track index" to end of tracks (break when last child is found)
  for i = track_index + 1, reaper.CountTracks(0) do
    child_track = reaper.GetTrack(0, i-1)
    reaper.SetMediaTrackInfo_Value(child_track, "I_RECARM", parent_rec_arm)
  
    child_track_folder_depth = parent_folder_depth + reaper.GetMediaTrackInfo_Value(child_track, "I_FOLDERDEPTH")
    if child_track_folder_depth < parent_folder_depth then
      break -- break when last child is found
    end  
  end

  reaper.UpdateArrange()                -- update arrange view
  reaper.TrackList_AdjustWindows(false) -- update tracklist
end



-----------------------------
-- on_project_state_change --
-----------------------------
--  this function is called when project state changes

function on_project_state_change(last_action)
  local last_a = last_action
  -- if last action (that changed the project state) was "Toggle Track Record Arming"...
  if last_action == "Toggle Track Record Arming" then
    local last_touched_track = reaper.GetLastTouchedTrack() -- get last touched track's "track pointer"
    local last_touched_track_name, flags = reaper.GetTrackState(last_touched_track)
    local last_touched_track_index = reaper.CSurf_TrackToID(last_touched_track, false) - 1 -- get track index from "last touched track"
   
    -- Check if last_touched_track was a folder track
    if flags&1 ~= 1 then -- if last_touched track was not a folder (parent)...
      return -- ...return to main function...
    end
    
    msg("Rec arm was pressed on track named: " .. last_touched_track_name)
    msg("Track number: " .. last_touched_track_index+1 .. "\n")
    
    on_rec_arm_change(last_touched_track, last_touched_track_index) -- ...(else) call "on_rec_arm_change"
  end
end


----------
-- Main --
----------

function main()
  local proj_change_count = reaper.GetProjectStateChangeCount(0)
  if proj_change_count > last_proj_change_count then
    local last_action = reaper.Undo_CanUndo2(0) -- get last action
    if last_action ~= nil then
      msg("--------------------------------")
      msg("Last action: " .. last_action)
      on_project_state_change(last_action) -- call "on_project_state_change" to update something if needed
    end
    last_proj_change_count = proj_change_count -- store "Project State Change Count" for the next pass
  end
  reaper.defer(main)    
end

main()




Please friend I'm new to Reaper could you help me to use the script
Edson 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:50 AM.


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