Old 06-19-2020, 03:02 PM   #1
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,581
Default 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.
__________________
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 06-19-2020, 07:33 PM   #2
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

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?
__________________
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
Old 06-20-2020, 06:50 AM   #3
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,581
Default

Hey Mespotine!
Yes, the area below the ruler and to the right of the TCP.

Quote:
Originally Posted by Meo-Ada Mespotine View Post
If yes, only the items who are completely visible or also those, who are just partially visible?
Completely visible would be my preference.
__________________
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 06-20-2020, 06:53 AM   #4
vitalker
Human being with feelings
 
vitalker's Avatar
 
Join Date: Dec 2012
Posts: 13,333
Default

Quote:
Originally Posted by daxliniere View Post
and to the right of the TCP.
To the left, if you moved TCP to right side.
vitalker is offline   Reply With Quote
Old 06-20-2020, 06:55 AM   #5
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,581
Default

Quote:
Originally Posted by vitalker View Post
To the left, if you moved TCP to right side.
I just KNEW someone would say that!
__________________
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 06-20-2020, 07:09 AM   #6
vitalker
Human being with feelings
 
vitalker's Avatar
 
Join Date: Dec 2012
Posts: 13,333
Default

Quote:
Originally Posted by daxliniere View Post
I just KNEW someone would say that!
Sorry, just joking.
vitalker is offline   Reply With Quote
Old 06-20-2020, 09:19 AM   #7
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

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" )
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)

Last edited by amagalma; 06-20-2020 at 10:25 PM.
amagalma is offline   Reply With Quote
Old 06-20-2020, 09:26 AM   #8
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

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" )
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)

Last edited by amagalma; 06-20-2020 at 10:26 PM.
amagalma is offline   Reply With Quote
Old 06-20-2020, 10:44 AM   #9
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

^^ Shouldn't it also take into account when items are scrolled vertically out of view (e.g. lots of tracks)?
nofish is offline   Reply With Quote
Old 06-20-2020, 01:42 PM   #10
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

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
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 06-20-2020, 01:53 PM   #11
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

I meant not because speed but as I understood it, it's also part of Dax' request, but maybe I misunderstood, we'll see.
nofish is offline   Reply With Quote
Old 06-20-2020, 02:36 PM   #12
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Ah, yes!.. You are right! I ll post the other version tomorrow! Ready to sleep now ...
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 06-20-2020, 10:27 PM   #13
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Updated the code
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 06-20-2020, 10:36 PM   #14
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

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.
__________________
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
Old 06-20-2020, 10:46 PM   #15
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

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()
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...

Last edited by Meo-Ada Mespotine; 06-20-2020 at 11:26 PM. Reason: improved and shortened code
Meo-Ada Mespotine is online now   Reply With Quote
Old 06-20-2020, 11:03 PM   #16
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Quote:
Originally Posted by amagalma View Post
Updated the code
You gotta be kidding me, I was just finished with it...

__________________
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
Old 06-21-2020, 03:06 AM   #17
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
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
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 06-21-2020, 05:41 AM   #18
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

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)
__________________
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
Old 06-22-2020, 07:22 AM   #19
daxliniere
Human being with feelings
 
daxliniere's Avatar
 
Join Date: Nov 2008
Location: London, UK
Posts: 2,581
Default

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.
__________________
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 06-22-2020, 09:17 AM   #20
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

@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
__________________
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
Old 06-22-2020, 02:41 PM   #21
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

I am puzzled.. Which script? I can't understand how it relates?..
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 06-22-2020, 06:41 PM   #22
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Wait, I messed up the thread. It was one of Edgemeal's scripts in the Set TCP thread..

It's late I guess XD
__________________
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
Old 07-01-2020, 10:52 AM   #23
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
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
__________________
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 03:36 AM.


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