|
|
|
06-19-2020, 03:02 PM
|
#1
|
Human being with feelings
Join Date: Nov 2008
Location: London, UK
Posts: 2,581
|
REQ: Select items in viewport
It would be great to have a script to Add all items in viewport to selection (current track).
Add all items in viewport to selection (all visible tracks) might also be useful, I suppose.
Thanks in advance for anyone who attempts this!
Cheers,
Dax.
|
|
|
06-19-2020, 07:33 PM
|
#2
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,621
|
What do you mean by viewport? The arrangeview, so all items currently visible in arrangeview?
If yes, only the items who are completely visible or also those, who are just partially visible?
|
|
|
06-20-2020, 06:50 AM
|
#3
|
Human being with feelings
Join Date: Nov 2008
Location: London, UK
Posts: 2,581
|
Hey Mespotine!
Yes, the area below the ruler and to the right of the TCP.
Quote:
Originally Posted by Meo-Ada Mespotine
If yes, only the items who are completely visible or also those, who are just partially visible?
|
Completely visible would be my preference.
|
|
|
06-20-2020, 06:53 AM
|
#4
|
Human being with feelings
Join Date: Dec 2012
Posts: 13,333
|
Quote:
Originally Posted by daxliniere
and to the right of the TCP.
|
To the left, if you moved TCP to right side.
|
|
|
06-20-2020, 06:55 AM
|
#5
|
Human being with feelings
Join Date: Nov 2008
Location: London, UK
Posts: 2,581
|
Quote:
Originally Posted by vitalker
To the left, if you moved TCP to right side.
|
I just KNEW someone would say that!
|
|
|
06-20-2020, 07:09 AM
|
#6
|
Human being with feelings
Join Date: Dec 2012
Posts: 13,333
|
Quote:
Originally Posted by daxliniere
I just KNEW someone would say that!
|
Sorry, just joking.
|
|
|
06-20-2020, 09:19 AM
|
#7
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,451
|
Code:
-- Add all items in viewport to selection (all visible tracks)
-- requires JS_ReaScriptAPI
local tracks_cnt = reaper.GetNumTracks()
reaper.PreventUIRefresh(1)
local _, _, tcp_height = reaper.JS_Window_GetClientSize(
reaper.JS_Window_FindChildByID( reaper.GetMainHwnd(), 0x3E8 ) )
local start_time, end_time = reaper.GetSet_ArrangeView2( 0, false, 0, 0 )
local prev_tr_visible = false
for tr = 0, tracks_cnt-1 do
local track = reaper.GetTrack(0, tr)
local track_pos = reaper.GetMediaTrackInfo_Value( track, "I_TCPY" )
local track_h = track_pos + reaper.GetMediaTrackInfo_Value( track, "I_TCPH" )
if reaper.IsTrackVisible( track, false ) and
track_pos >= 0 and track_h <= tcp_height then
prev_tr_visible = true
local item_cnt = reaper.GetTrackNumMediaItems( track )
local prev_visible = false
for i = 0, item_cnt-1 do
local item = reaper.GetTrackMediaItem( track, i )
local item_start = reaper.GetMediaItemInfo_Value( item, "D_POSITION" )
local item_end = item_start + reaper.GetMediaItemInfo_Value( item, "D_LENGTH" )
if item_start >= start_time and item_end <= end_time then
reaper.SetMediaItemSelected( item, true )
prev_visible = true
else
if prev_visible then break end
end
end
else
if prev_tr_visible then break end
end
end
reaper.PreventUIRefresh(-1)
reaper.UpdateArrange()
reaper.Undo_OnStateChange( "Add all items in viewport to selection" )
Last edited by amagalma; 06-20-2020 at 10:25 PM.
|
|
|
06-20-2020, 09:26 AM
|
#8
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,451
|
Code:
-- Add all items in viewport to selection (selected tracks)
-- requires JS_ReaScriptAPI
local tracks_cnt = reaper.CountSelectedTracks( 0 )
if tracks_cnt == 0 then return end
reaper.PreventUIRefresh(1)
local _, _, tcp_height = reaper.JS_Window_GetClientSize(
reaper.JS_Window_FindChildByID( reaper.GetMainHwnd(), 0x3E8 ) )
local start_time, end_time = reaper.GetSet_ArrangeView2( 0, false, 0, 0 )
local prev_tr_visible = false
for tr = 0, tracks_cnt-1 do
local track = reaper.GetSelectedTrack(0, tr)
local track_pos = reaper.GetMediaTrackInfo_Value( track, "I_TCPY" )
local track_h = track_pos + reaper.GetMediaTrackInfo_Value( track, "I_TCPH" )
if reaper.IsTrackVisible( track, false ) and
track_pos >= 0 and track_h <= tcp_height then
prev_tr_visible = true
local item_cnt = reaper.GetTrackNumMediaItems( track )
local prev_visible = false
for i = 0, item_cnt-1 do
local item = reaper.GetTrackMediaItem( track, i )
local item_start = reaper.GetMediaItemInfo_Value( item, "D_POSITION" )
local item_end = item_start + reaper.GetMediaItemInfo_Value( item, "D_LENGTH" )
if item_start >= start_time and item_end <= end_time then
reaper.SetMediaItemSelected( item, true )
prev_visible = true
else
if prev_visible then break end
end
end
else
if prev_tr_visible then break end
end
end
reaper.PreventUIRefresh(-1)
reaper.UpdateArrange()
reaper.Undo_OnStateChange( "Add all items in viewport to selection" )
Last edited by amagalma; 06-20-2020 at 10:26 PM.
|
|
|
06-20-2020, 10:44 AM
|
#9
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
|
^^ Shouldn't it also take into account when items are scrolled vertically out of view (e.g. lots of tracks)?
|
|
|
06-20-2020, 01:42 PM
|
#10
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,451
|
I've made a version like this, but it didn't offer a considerable speed boost, and with not a lot of tracks it was actually slower.. I ll post it later
|
|
|
06-20-2020, 01:53 PM
|
#11
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
|
I meant not because speed but as I understood it, it's also part of Dax' request, but maybe I misunderstood, we'll see.
|
|
|
06-20-2020, 02:36 PM
|
#12
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,451
|
Ah, yes!.. You are right! I ll post the other version tomorrow! Ready to sleep now ...
|
|
|
06-20-2020, 10:27 PM
|
#13
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,451
|
Updated the code
|
|
|
06-20-2020, 10:36 PM
|
#14
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,621
|
Yes, IsTrackVisible() only returns if a track is set to visible or not, but not, if it's within the visible area of the arrangeview.
|
|
|
06-20-2020, 10:46 PM
|
#15
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,621
|
Ok, this should solve it for all items currently completely visible in the arrangeview.
You need Ultraschall-API(link in my signature), JS-extension and SWS to be installed for this.
Code:
-- Meo-Ada Mespotine - 21.06.2020
--
-- adds all completely visible items in the arrangeview to selected items
--
-- licensed under MIT-license
dofile(reaper.GetResourcePath().."/UserPlugins/ultraschall_api.lua")
if ultraschall==nil then reaper.MB("Sorry, you need to install Ultraschall-API, JS-extension and SWS to use this script", "Error", 0) return end
arrange_view = ultraschall.GetHWND_ArrangeViewAndTimeLine()
retval, left, top, right, bottom = reaper.JS_Window_GetClientRect(arrange_view)
-- find all tracks currently visible
trackstring=""
for i=1, reaper.CountTracks(0) do
track=reaper.GetTrack(0, i-1)
if reaper.GetMediaTrackInfo_Value(track, "I_TCPY")>=0 and reaper.GetMediaTrackInfo_Value(track, "I_TCPY")+reaper.GetMediaTrackInfo_Value(track, "I_WNDH")<=bottom-top then
trackstring=trackstring..i..","
end
end
-- get all items from all visible tracks within the visible start and endposition
start, stop = reaper.GetSet_ArrangeView2(0, false, 0,0)
count, MediaItemArray = ultraschall.GetAllMediaItemsBetween(start, stop, trackstring:sub(1,-2), true)
-- set them selected(additionally)
for i=1, count do reaper.SetMediaItemSelected(MediaItemArray[i], true) end
reaper.UpdateArrange()
And this does the same, but only with visible selected tracks:
Code:
-- Meo-Ada Mespotine - 21.06.2020
--
-- adds all completely visible items in the arrangeview to selected items
-- will only consider items in selected tracks
--
-- licensed under MIT-license
dofile(reaper.GetResourcePath().."/UserPlugins/ultraschall_api.lua")
if ultraschall==nil then reaper.MB("Sorry, you need to install Ultraschall-API, JS-extension and SWS to use this script", "Error", 0) return end
arrange_view = ultraschall.GetHWND_ArrangeViewAndTimeLine()
retval, left, top, right, bottom = reaper.JS_Window_GetClientRect(arrange_view)
-- find all tracks currently visible
trackstring=""
for i=1, reaper.CountTracks(0) do
track=reaper.GetTrack(0, i-1)
if reaper.IsTrackSelected(track)==true and reaper.GetMediaTrackInfo_Value(track, "I_TCPY")>=0 and reaper.GetMediaTrackInfo_Value(track, "I_TCPY")+reaper.GetMediaTrackInfo_Value(track, "I_WNDH")<=bottom-top then
trackstring=trackstring..i..","
end
end
-- get all items from all visible tracks within the visible start and endposition
start, stop = reaper.GetSet_ArrangeView2(0, false, 0,0)
count, MediaItemArray = ultraschall.GetAllMediaItemsBetween(start, stop, trackstring:sub(1,-2), true)
-- set them selected(additionally)
for i=1, count do reaper.SetMediaItemSelected(MediaItemArray[i], true) end
reaper.UpdateArrange()
Last edited by Meo-Ada Mespotine; 06-20-2020 at 11:26 PM.
Reason: improved and shortened code
|
|
|
06-20-2020, 11:03 PM
|
#16
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,621
|
Quote:
Originally Posted by amagalma
Updated the code
|
You gotta be kidding me, I was just finished with it...
|
|
|
06-21-2020, 03:06 AM
|
#17
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,451
|
Quote:
Originally Posted by Meo-Ada Mespotine
You gotta be kidding me, I was just finished with it...
|
I had done it since yesterday.. but anyway, a bit of coding practice, I guess, is never bad! We 've got to keep in shape!
It is also interesting to see how different people can reach the same destination by taking different routes
|
|
|
06-21-2020, 05:41 AM
|
#18
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,621
|
It also helped me to add some new functions to my API and improve some others.
The next version will be able to do the same with these few codelines:
Code:
dofile(reaper.GetResourcePath().."/UserPlugins/ultraschall_api.lua")
trackstring = ultraschall.GetAllVisibleTracks_Arrange(false, true)
start, stop = reaper.GetSet_ArrangeView2(0, false, 0,0)
Acount, AMediaItemArray = ultraschall.GetAllMediaItemsBetween(start, stop, trackstring, true)
retval = ultraschall.SelectMediaItems_MediaItemArray(AMediaItemArray)
|
|
|
06-22-2020, 07:22 AM
|
#19
|
Human being with feelings
Join Date: Nov 2008
Location: London, UK
Posts: 2,581
|
Hey Mespotine and Amagalma! Thank you both so much for writing this code.
I'm sure it'll be helpful.
I'm glad you were able to see the upside of having both worked on it and come up with different solutions. You're both good sports.
Thanks again and all the best,
Dax.
|
|
|
06-22-2020, 09:17 AM
|
#20
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,621
|
@daxliniere
You're welcome
@amagalma
There still was an offset with left being two pixels too big and right 8 pixels too small.
To I fixed this, you just need to exchange these lines in your script:
Quote:
if tcp_r < av_r then
x,y = reaper.JS_Window_ScreenToClient(main, tcp_x+(tcp_r-tcp_x)+2, tcp_y)
reaper.JS_WindowMessage_Send(main, "WM_LBUTTONDOWN", 1, 0, x, y) -- mouse down message at splitter location
reaper.JS_WindowMessage_Send(main, "WM_LBUTTONUP", 0, 0, (tcp_x+width)-main_x-2, y) -- set width, mouse up message
else -- ' TCP is on right side
x,y = reaper.JS_Window_ScreenToClient(main, tcp_x-5, tcp_y)
reaper.JS_WindowMessage_Send(main, "WM_LBUTTONDOWN", 1, 0, x, y)
reaper.JS_WindowMessage_Send(main, "WM_LBUTTONUP", 0, 0, (tcp_r-width)-main_x-8, y)
end
|
I'm not sure, whether this came from the additional toolbars I had at the left on my reaper-instance, so maybe, I bugged this even further
|
|
|
06-22-2020, 02:41 PM
|
#21
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,451
|
I am puzzled.. Which script? I can't understand how it relates?..
|
|
|
06-22-2020, 06:41 PM
|
#22
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,621
|
Wait, I messed up the thread. It was one of Edgemeal's scripts in the Set TCP thread..
It's late I guess XD
|
|
|
07-01-2020, 10:52 AM
|
#23
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,621
|
Quote:
Originally Posted by Meo-Ada Mespotine
It also helped me to add some new functions to my API and improve some others.
The next version will be able to do the same with these few codelines:
Code:
dofile(reaper.GetResourcePath().."/UserPlugins/ultraschall_api.lua")
trackstring = ultraschall.GetAllVisibleTracks_Arrange(false, true)
start, stop = reaper.GetSet_ArrangeView2(0, false, 0,0)
Acount, AMediaItemArray = ultraschall.GetAllMediaItemsBetween(start, stop, trackstring, true)
retval = ultraschall.SelectMediaItems_MediaItemArray(AMediaItemArray)
|
In the latest Ultraschall-API update, I've added the new function GetAllVisibleTracks_Arrange, so the above example works now out of the box.
https://mespotin.uber.space/Ultrasch...Tracks_Arrange
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 03:36 AM.
|