Old 08-09-2020, 08:43 AM   #1
Coachz
Human being with feelings
 
Coachz's Avatar
 
Join Date: Oct 2010
Location: Charleston, SC
Posts: 12,791
Default Scroll track to top of arrange view ?

Is it possible to scroll a selected track to the top of the arrange view ? Thanks buds !
Coachz is offline   Reply With Quote
Old 08-09-2020, 09:12 AM   #2
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 7,431
Default

There is the
Code:
Track: Vertical scroll selected tracks into view (40913)
Maybe that will work?

I use in the same script the track height and lock came from
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
Fabian is offline   Reply With Quote
Old 08-09-2020, 09:16 AM   #3
Coachz
Human being with feelings
 
Coachz's Avatar
 
Join Date: Oct 2010
Location: Charleston, SC
Posts: 12,791
Default

Quote:
Originally Posted by Fabian View Post
There is the
Code:
Track: Vertical scroll selected tracks into view (40913)
Maybe that will work?

I use in the same script the track height and lock came from
Thanks but that just puts the track(s) in the middle and not top of the view.
Coachz is offline   Reply With Quote
Old 08-09-2020, 10:14 AM   #4
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
Default

Check out this post from spk77,
https://forum.cockos.com/showpost.ph...&postcount=870

and some stuff I posted,
https://forum.cockos.com/showpost.ph...36&postcount=2

Last edited by Edgemeal; 08-09-2020 at 10:29 AM.
Edgemeal is offline   Reply With Quote
Old 08-09-2020, 10:53 AM   #5
Coachz
Human being with feelings
 
Coachz's Avatar
 
Join Date: Oct 2010
Location: Charleston, SC
Posts: 12,791
Default

Edgemeal, you come through again ! I used the code from the first example and got the track number from the selected track and it works great. Thanks again. You really rock.

Code:
-- clear console
reaper.ShowConsoleMsg("")

-- create simpler console messager
function Msg(param)
    reaper.ShowConsoleMsg(param.."\n")
end

function bool2string(b) return b and "true" or "false" end 

--debug  = true  -- disable main messages
--debug  = false  -- disable main messages


local floor = math.floor

function scroll_to_track(track_id, relative_y_pos, include_envelopes)
  relative_y_pos = relative_y_pos or 0 -- default position is "top"
  local p = "I_WNDH" -- Exclude envelope lane heights
  if not include_envelopes then -- Include envelope lane heights
    p = "I_TCPH"
  end
  -- Ignore hidden tracks
  if not reaper.IsTrackVisible(track_id, true) then
    return false
  end
  local tcp_y = reaper.GetMediaTrackInfo_Value(track_id, "I_TCPY")
  local tcp_h = reaper.GetMediaTrackInfo_Value(track_id, p)
  local arrange_id = reaper.JS_Window_FindChildByID(reaper.GetMainHwnd(), 0x3E8)
  local ok, ar_vsb_position, ar_vsb_page, ar_vsb_min, ar_vsb_max, ar_vsb_trackPos = reaper.JS_Window_GetScrollInfo(arrange_id, "v")
  if ok then
    ok = reaper.JS_Window_SetScrollPos(arrange_id, "v", tcp_y + ar_vsb_position - floor(relative_y_pos*(ar_vsb_page-tcp_h)))
  end
  return ok
end


selected_trk = reaper.GetSelectedTrack( 0, 0 )
tracknumber = reaper.GetMediaTrackInfo_Value(selected_trk, 'IP_TRACKNUMBER')


-- Example: scroll to selected track
local tr = reaper.GetTrack(0, tracknumber-1) -- Get track
if tr then
 -- Desc: scroll_to_track(track_id, relative_y_pos, include_envelopes)
  scroll_to_track(tr)
  --scroll_to_track(tr, 0.5, false)
  --scroll_to_track(tr, 1, false)
  --scroll_to_track(tr, 1, true)
end

Last edited by Coachz; 08-15-2023 at 07:04 AM.
Coachz is offline   Reply With Quote
Old 08-11-2020, 05:10 AM   #6
Skorobagatko
Human being with feelings
 
Skorobagatko's Avatar
 
Join Date: Mar 2017
Location: Ukraine, Kyiv
Posts: 546
Default

Quote:
Originally Posted by Coachz View Post
Edgemeal, you come through again ! I used the code from the first example and got the track number from the selected track and it works great. Thanks again. You really rock.

Code:
-- clear console
reaper.ShowConsoleMsg("")

-- create simpler console messager
function Msg(param)
    reaper.ShowConsoleMsg(param.."\n")
end

function bool2string(b) return b and "true" or "false" end 

--debug  = true  -- disable main messages
--debug  = false  -- disable main messages


local floor = math.floor

function scroll_to_track(track_id, relative_y_pos, include_envelopes)
  relative_y_pos = relative_y_pos or 0 -- default position is "top"
  local p = "I_WNDH" -- Exclude envelope lane heights
  if not include_envelopes then -- Include envelope lane heights
    p = "I_TCPH"
  end
  -- Ignore hidden tracks
  if not reaper.IsTrackVisible(track_id, true) then
    return false
  end
  local tcp_y = reaper.GetMediaTrackInfo_Value(track_id, "I_TCPY")
  local tcp_h = reaper.GetMediaTrackInfo_Value(track_id, p)
  local arrange_id = reaper.JS_Window_FindChildByID(reaper.GetMainHwnd(), 0x3E8)
  local ok, ar_vsb_position, ar_vsb_page, ar_vsb_min, ar_vsb_max, ar_vsb_trackPos = reaper.JS_Window_GetScrollInfo(arrange_id, "v")
  if ok then
    ok = reaper.JS_Window_SetScrollPos(arrange_id, "v", tcp_y + ar_vsb_position - floor(relative_y_pos*(ar_vsb_page-tcp_h)))
  end
  return ok
end


selected_trk = reaper.GetSelectedTrack( 0, 0 )
tracknumber = reaper.GetMediaTrackInfo_Value(selected_trk, 'IP_TRACKNUMBER')


-- Example: scroll to selected track
local tr = reaper.GetTrack(0, tracknumber-1) -- Get track
if tr then
 -- Desc: scroll_to_track(track_id, relative_y_pos, include_envelopes)
  scroll_to_track(tr)
  --scroll_to_track(tr, 0.5, false)
  --scroll_to_track(tr, 1, false)
  --scroll_to_track(tr, 1, true)
end
Thanks for sharing!
Skorobagatko 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 06:32 AM.


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