Old 02-24-2021, 09:07 PM   #1
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 2,227
Default funny delay in track height script

this script figures out the height of the arrange window and divides that number by the number of selected tracks so they can be set to fill the arrange window. work in progress but it's doing something funny. it doesn't display the resized tracks until i click one in the arrange window. i'd have thought the redraw would be pretty much immediate. what's wrong here?

thanks,
babag
Code:
function GetBounds(hwnd)
    ret, left, top, right, bottom = reaper.JS_Window_GetClientRect(hwnd)
    return left, top, right-left, bottom-top
end

function main()
    reaper.Undo_BeginBlock()                                                                    

        local TrxSel                      = reaper.CountSelectedTracks( 0 )                     -- set variable for number of selected tracks in current project ( 0 )

        local mainWin                     = reaper.GetMainHwnd()
        local arrange                     = reaper.JS_Window_FindChildByID( mainWin, 1000 )
        local arr_X, arr_Y, arr_W, arr_H  = GetBounds( arrange )
        local TrxH                        = arr_H / TrxSel
        
        for i                             = 0, TrxSel - 1 do
            local TrkCurr                 = reaper.GetSelectedTrack( 0, i )                     -- set variable for current track
            reaper.SetMediaTrackInfo_Value( TrkCurr, "I_HEIGHTOVERRIDE", TrxH )
          
        end
        
    reaper.Undo_EndBlock( "Loop through selected tracks to set height", -1 )
end


reaper.PreventUIRefresh(1)

main()   -- Execute your main function

reaper.UpdateArrange()                                                                          -- Update the arrangement
reaper.PreventUIRefresh(-1)                                                                     -- Restore UI Refresh. Uncomment it only if the script works.
babag is offline   Reply With Quote
Old 02-24-2021, 09:23 PM   #2
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Instead of reaper.UpdateArrange(), maybe try, reaper.TrackList_AdjustWindows(false)
Edgemeal is offline   Reply With Quote
Old 02-24-2021, 09:35 PM   #3
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 2,227
Default

thanks edgemeal! that works. never seen it before. no idea why everything else i have works with reaper.UpdateArrange() and this one needs something different. curious.

edit:
seems like zero info in the api, not that i can ever rerally understand much of what i see there.

thanks again,
babag
babag is offline   Reply With Quote
Old 02-24-2021, 09:41 PM   #4
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Best to test it and make sure, I would think adjusting height of a track would force reaper to redraw arrange area, but I didn't test.

BTW, If your script only needs size of arrange you might consider using GetClientSize function,..

Code:
local _, arr_W, arr_H = reaper.JS_Window_GetClientSize( arrange )
Edgemeal is offline   Reply With Quote
Old 02-26-2021, 12:58 PM   #5
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 2,227
Default

thanks, edgemeal.

i managed the below. it shows all tracks with unselected ones set to the minimum size and selected ones set to as large as they'll go while still showing all tracks. not practical for large track counts but i do a lot of work with a 7 track template so this is helpful. for brevity, i've taken out lines that were commented. the minimum size is hardcoded at 24. seemed simpler that way. that's maybe another discussion.

thanks again,
babag
Code:
function Msg(variable)
  reaper.ShowConsoleMsg(tostring(variable).."\n")
end

function main()

    reaper.Undo_BeginBlock()                                                                    -- Begining of the undo block. Leave it at the top of your main function.

        local TrxTotal                    = reaper.CountTracks( 0 )
        local TrxSel                      = reaper.CountSelectedTracks( 0 )                     -- set variable for number of selected tracks in current project ( 0 )
        local TrxUnSel                    = TrxTotal - TrxSel

        local mainWin                     = reaper.GetMainHwnd()
        local arrange                     = reaper.JS_Window_FindChildByID( mainWin, 1000 )
        local _, arr_W, arr_H             = reaper.JS_Window_GetClientSize( arrange )
        local minTrxH                     = 24
        local totalMin                    = TrxUnSel * minTrxH
        local totalMax                    = arr_H - totalMin
        local TrxSelNewH                  = totalMax / TrxSel

        for i                             = 0, TrxTotal - 1 do                                    -- loop through selected tracks
  
            local TrkCurr                 = reaper.GetTrack( 0, i )                     -- set variable for current track
            local Selected                = reaper.GetMediaTrackInfo_Value( TrkCurr, "I_SELECTED" )

            if Selected == 1 then
                reaper.SetMediaTrackInfo_Value( TrkCurr, "I_HEIGHTOVERRIDE", TrxSelNewH )
            else
                reaper.SetMediaTrackInfo_Value( TrkCurr, "I_HEIGHTOVERRIDE", minTrxH )
            end
            
        end
        
    reaper.Undo_EndBlock( "Loop through selected tracks to set height", -1 )                    -- End of the undo block. Leave it at the bottom of your main function.

end


reaper.PreventUIRefresh(1)                                                                      -- Prevent UI refreshing. Uncomment it only if the script works.

main()                                                                                          -- Execute your main function

reaper.TrackList_AdjustWindows(false)
reaper.PreventUIRefresh(-1)                                                                     -- Restore UI Refresh. Uncomment it only if the script works.
babag is offline   Reply With Quote
Old 02-26-2021, 01:05 PM   #6
J Reverb
Human being with feelings
 
Join Date: Jul 2009
Posts: 1,071
Default

@babag
Awesome !
Now I immediately want to toggle it
Thanks !
J Reverb is offline   Reply With Quote
Old 02-26-2021, 01:09 PM   #7
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 2,227
Default

that would be great. well beyond me, though. feel free to make it better.

edit:
haven't been able to figure it out but having one that hides the unselected tracks would be useful too i'd think.

maybe this:

B_SHOWINTCP

for reaper.SetMediaTrackInfo_Value?

Last edited by babag; 02-26-2021 at 01:38 PM.
babag is offline   Reply With Quote
Old 02-26-2021, 02:17 PM   #8
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,622
Default

Quote:
Originally Posted by babag View Post
thanks edgemeal! that works. never seen it before. no idea why everything else i have works with reaper.UpdateArrange() and this one needs something different. curious.

edit:
seems like zero info in the api, not that i can ever rerally understand much of what i see there.

thanks again,
babag
You should switch to my docs, where I try to improve on such infos:

https://mespotin.uber.space/Ultrasch..._AdjustWindows
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine 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 08:15 AM.


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