Old 02-14-2019, 04:43 PM   #1
jamesd256
Human being with feelings
 
jamesd256's Avatar
 
Join Date: Dec 2015
Location: Folkestone
Posts: 160
Default Expand and collapse tracks in mixer

Is there anything in the API for explicitly expanding/collapsing folder tracks in the mixer?

Alternatively, anything there for reading the expand state of a mixer track?

I couldn't find either.

If a toggle was enough, I could just call this action:

Mixer: Show/hide children of selected tracks

If there are any other actions to do it (I have SWS) that would be fine too.

Thanks!
jamesd256 is offline   Reply With Quote
Old 02-14-2019, 05:22 PM   #2
jamesd256
Human being with feelings
 
jamesd256's Avatar
 
Join Date: Dec 2015
Location: Folkestone
Posts: 160
Default

I found this:

https://github.com/MichaelPilyavskiy...ackground).lua

It looks as though I could borrow a couple of methods from here and it should work, but no joy (runs OK but doesn't seem to do anything)

Is there some further documentation on how to use SetTrackStateChunk to do this sort of thing?

function ShowChildrenInMCP(tr, is_show, return_state)
local tr_chunk = eugen27771_GetTrackStateChunk(tr)
local BUSCOMP_var1 = tonumber(tr_chunk:match('BUSCOMP (%d+)'))
local BUSCOMP_var2 = tonumber(tr_chunk:match('BUSCOMP %d+ (%d+)'))
if return_state then return BUSCOMP_var2==0 end
local tr_chunk_out = tr_chunk:gsub('BUSCOMP '..BUSCOMP_var1..' %d+', 'BUSCOMP '..BUSCOMP_var1..' '..(is_show and 0 or 1))
if BUSCOMP_var2 ~= (is_show and 0 or 1) then reaper.SetTrackStateChunk(tr, tr_chunk_out,true) end
end

function eugen27771_GetTrackStateChunk(track)
if not track then return end
local fast_str, track_chunk
fast_str = reaper.SNM_CreateFastString("")
if reaper.SNM_GetSetObjectState(track, fast_str, false, false) then track_chunk = reaper.SNM_GetFastString(fast_str) end
reaper.SNM_DeleteFastString(fast_str)
return track_chunk
end

Edit: it's working, just had to understand the method sig of ShowChildrenInMCP properly

Last edited by jamesd256; 02-14-2019 at 05:32 PM.
jamesd256 is offline   Reply With Quote
Old 02-14-2019, 07:10 PM   #3
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 1,365
Default

Seems the second value of BUSCOMP is the MCP folder collapsed state, 0=normal, 1=collapsed. Using some of that mpl code came up with this real quick,..

Code:
function CollapseMCP(tr, state)
  local _, tr_chunk = reaper.GetTrackStateChunk(tr, '') 
  local BUSCOMP_var2 = tonumber(tr_chunk:match('BUSCOMP %d+ (%d+)'))
  if state ~= BUSCOMP_var2 then
    local BUSCOMP_var1 = tonumber(tr_chunk:match('BUSCOMP (%d+)'))
    local tr_chunk_out = tr_chunk:gsub('BUSCOMP '..BUSCOMP_var1..' %d+', 'BUSCOMP '..BUSCOMP_var1..' '..tostring(state))
    reaper.SetTrackStateChunk(tr, tr_chunk_out, false)
  end
end
  
track = reaper.GetSelectedTrack(0,0)
if not track then return end
-- check if parent folder
if reaper.GetMediaTrackInfo_Value(track, "I_FOLDERDEPTH") ~=1 then return end 
-- collapse/expand folder track
CollapseMCP(track, 1) -- 0=expand, 1=collapse

Last edited by Edgemeal; 02-14-2019 at 07:36 PM. Reason: tweak function
Edgemeal is offline   Reply With Quote
Old 02-15-2019, 03:18 AM   #4
jamesd256
Human being with feelings
 
jamesd256's Avatar
 
Join Date: Dec 2015
Location: Folkestone
Posts: 160
Default

Quote:
Originally Posted by Edgemeal View Post
Seems the second value of BUSCOMP is the MCP folder collapsed state, 0=normal, 1=collapsed. Using some of that mpl code came up with this real quick,..

Code:
function CollapseMCP(tr, state)
  local _, tr_chunk = reaper.GetTrackStateChunk(tr, '') 
  local BUSCOMP_var2 = tonumber(tr_chunk:match('BUSCOMP %d+ (%d+)'))
  if state ~= BUSCOMP_var2 then
    local BUSCOMP_var1 = tonumber(tr_chunk:match('BUSCOMP (%d+)'))
    local tr_chunk_out = tr_chunk:gsub('BUSCOMP '..BUSCOMP_var1..' %d+', 'BUSCOMP '..BUSCOMP_var1..' '..tostring(state))
    reaper.SetTrackStateChunk(tr, tr_chunk_out, false)
  end
end
  
track = reaper.GetSelectedTrack(0,0)
if not track then return end
-- check if parent folder
if reaper.GetMediaTrackInfo_Value(track, "I_FOLDERDEPTH") ~=1 then return end 
-- collapse/expand folder track
CollapseMCP(track, 1) -- 0=expand, 1=collapse

I had it fudged and working but now I understand it more clearly so thank you.
jamesd256 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:42 AM.


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