Old 02-27-2018, 12:58 AM   #1
Claudiohbsantos
Human being with feelings
 
Join Date: Aug 2014
Location: New York
Posts: 132
Default Any ideas on how to get item screen position and vertical zoom?

Hey all,

I've been on a pretty disappointing battle to try to get what tracks/items are on screen from a reascript.

To find which items are horizontally on screen I can use reaper.GetSet_ArrangeView2(0,false,0,0) to get start/end time of the Arrange.

But when it comes to figuring out what tracks/items are visible vertically I can't find a way to do it. the SWS action "SWS/S&M: Unselect offscreen items" makes me believe it should be possible, but I can't figure out how. Is that only doable from the extensions API?

This all brings me to the second question: Can anyone think of another way to get the screen position of different elements such as tracks and items?
Claudiohbsantos is offline   Reply With Quote
Old 02-27-2018, 12:19 PM   #2
Claudiohbsantos
Human being with feelings
 
Join Date: Aug 2014
Location: New York
Posts: 132
Default

Ok, of course I figured out part of the solution right after posting this. I can get the height (vertical zoom) of each track with:

reaper.GetMediaTrackInfo_Value(track, "I_WNDH")

Now I'm just trying to figure out how to get the coordinates of the arrange window.

Am I wrong in saying that reaper.my_getViewport(...) only gives me the size and coordinates for the entire display?
Claudiohbsantos is offline   Reply With Quote
Old 03-01-2018, 07:37 PM   #3
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,320
Default

Yes, it only returns the screen-size.

You can't get the y position of the Reaper-window in Lua, but you can trick the GetSet_ArrangeView2 into giving you the x-position of the Reaper-window.

Use the following functions I once wrote for my own function-collection:

Code:
ultraschall={}

function ultraschall.GetReaperWindowPosition_Left()
-- returns position of the left side of Reaper's window
-- Due to Api-limitations: when the reaper-window is too small, it returns a wrong value, up to 72 pixels too high!

  local temp,Technopop=reaper.BR_Win32_GetPrivateProfileString("REAPER", "leftpanewid", "", reaper.GetResourcePath()..ultraschall.Separator.."reaper.ini")
  local temp,ElectricCafe=reaper.BR_Win32_GetPrivateProfileString("REAPER", "dockheight_l", "", reaper.GetResourcePath()..ultraschall.Separator.."reaper.ini")

  local C,D,E,F,G,H,I,J,K,L=reaper.my_getViewport(1,2,3,4,5,6,7,8, true)
  local A1x,A2x= reaper.GetSet_ArrangeView2(0, false, 0,0)

  for i=-E*2,E*2 do
    local T1,T2=reaper.GetSet_ArrangeView2(0, false, i+Technopop,i+Technopop+1)
    if T1==A1x then puh=i end
  end

  return puh-tonumber(ElectricCafe)-10
end

function ultraschall.GetReaperWindowPosition_Right()
-- returns position of the right side of Reaper's window
-- Due to Api-limitations: when the reaper-window is too small, it returns a wrong value, up to 72 pixels too high!

  local temp,Technopop=reaper.BR_Win32_GetPrivateProfileString("REAPER", "leftpanewid", "", reaper.GetResourcePath()..ultraschall.Separator.."reaper.ini")

  local C,D,E,F,G,H,I,J,K,L=reaper.my_getViewport(1,2,3,4,5,6,7,8, true)
  local A1x,A2x= reaper.GetSet_ArrangeView2(0, false, 0,0)

  for i=-E*2,E*2 do
    local T1,T2=reaper.GetSet_ArrangeView2(0, false, i,i+1)
    if T1==A2x then puh=i end
  end

  return puh
end


function ultraschall.ConvertScreen2ClientXCoordinate_ReaperWindow(coordinate)
  -- converts screen-coordinates(from mouseposition, etc) into Reaper's clientwindow-x-coordinate
  local A=ultraschall.GetReaperWindowPosition_Left()
  local B=ultraschall.GetReaperWindowPosition_Right()
  return coordinate-A, B-coordinate
end

function ultraschall.ConvertClient2ScreenXCoordinate_ReaperWindow(coordinate)
  -- converts Reaper's clientwindow-x-coordinate into screen-coordinates(for check with mouseposition, etc)
  local A=ultraschall.GetReaperWindowPosition_Left()
  local B=ultraschall.GetReaperWindowPosition_Right()
  return coordinate+A
end

For the arrange-view itself, you need to look into the reaper.ini
There are some entries for the position of the dockers. If you know them, you can recalculate the position of the arrange-view.
Use BR_Win32_GetPrivateProfileString to get the reaper.ini-entries.

They will be updated, everytime the docker-position is changed(by mouse-dragging for example). They are in relation to Reaper's window, though, not the screen-position.
The functions I posted above should help you with Screen2ReaperclientWindow2Screen-coordinate-conversion, at least for the x-coordinate.

Last edited by mespotine; 03-01-2018 at 07:46 PM. Reason: formatting
mespotine is offline   Reply With Quote
Old 03-01-2018, 08:02 PM   #4
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,320
Default

In addition to that:
If you want to know, if an item is out of view vertically, you can try the function

IsTrackVisible

to check, if the track that contains said item is visible at all. If not, then the item isn't visible as well.
I don't know, if it works the way I think(as it is possible to hide tracks in Reaper, which is different from scrolling them out of view), but it should tell you, if a certain track isn't visible at all.

If that works, then it should be much easier for you to code that without having to do the difficult client2screen-coordinate-conversion...
mespotine is offline   Reply With Quote
Old 03-02-2018, 09:03 PM   #5
Claudiohbsantos
Human being with feelings
 
Join Date: Aug 2014
Location: New York
Posts: 132
Default

Thanks, that's a really interesting way of getting the x position. I'll dive into the .ini to see if I can get a similar workaround for the y position like you said.

As far as I know the "IsTrackVisible" returns whether it is hidden on the tcp or not, not it's visibility on screen. What I figured was to get each visible track height with reaper.GetMediaTrackInfo_Value(track, "I_WNDH") and figure out what's on screen by comparing that to the height of the arrange. Let's see how that goes
Claudiohbsantos is offline   Reply With Quote
Old 03-02-2018, 10:17 PM   #6
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,488
Default

Quote:
Originally Posted by Claudiohbsantos View Post
Thanks, that's a really interesting way of getting the x position. I'll dive into the .ini to see if I can get a similar workaround for the y position like you said.

As far as I know the "IsTrackVisible" returns whether it is hidden on the tcp or not, not it's visibility on screen. What I figured was to get each visible track height with reaper.GetMediaTrackInfo_Value(track, "I_WNDH") and figure out what's on screen by comparing that to the height of the arrange. Let's see how that goes
Don't forget to add (possible) envelope lane heights to total height

Also, track envelopes can be in "envelope lane" or in "media lane".

EDIT: It seems reaper.GetMediaTrackInfo_Value(track, "I_WNDH") includes envelope heights.

It would be nice to get an API function like GetSetTCPScroll(media track): https://forum.cockos.com/showpost.ph...&postcount=265

Last edited by spk77; 03-02-2018 at 10:23 PM.
spk77 is offline   Reply With Quote
Old 03-03-2018, 04:23 AM   #7
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,320
Default

Quote:
Originally Posted by Claudiohbsantos View Post
I'll dive into the .ini to see if I can get a similar workaround for the y position like you said.
That would be awesome! I'm looking to find that for the Reaper-window itself for months now, but couldn't trick Reaper into doing that. Only the x-position...

If you find that or find out how to calculate the arrange-view-dimensions inside of the Reaper-window, please share it with us

Last edited by mespotine; 03-03-2018 at 04:36 AM.
mespotine is offline   Reply With Quote
Old 03-05-2018, 09:02 PM   #8
Claudiohbsantos
Human being with feelings
 
Join Date: Aug 2014
Location: New York
Posts: 132
Default

Ok, I'm stuck on the very next stage and it's starting to drive me up the walls.

What I'm trying to do is a jumpto style kind of selection for reaper. Something similar to this:

https://youtu.be/t67Sn0RGK54?t=29s

I wanted the screen coordinates to place tooltips on top of each item for the selection shortcuts.

Now is the bummer: reaper API native tooltip function only seems to support a single tooltip at a time.

Any idea of how else to place tooltips on the screen?
I've been trying to call autohotkey from the script to display the tooltips but the performance is horrendous.

EDIT:Regarding getting the y positions I'm playing with a few options. Right now I'm just using a compiled autohotkey script for simplicity sake, but the following entries on the ini file seem promising:

Code:
wnd_state=0
wnd_x=1146
wnd_y=0
wnd_w=1146
wnd_h=1440
state seems to be 1 for full-screen and 0 for floating window. Tat paired with the dock positions+heights in the ini should give the arrange position. Only problem then is if the user resizes stuff after opening reaper.

Last edited by Claudiohbsantos; 03-05-2018 at 09:45 PM.
Claudiohbsantos 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:29 AM.


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