View Single Post
Old 01-07-2020, 09:44 AM   #882
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,596
Default

Julian again I need a little assistance this time for OSX...

Unlike before V6 core reaper changes (track UI changes), now the script detects tracks out of the box, which was not the case before (did not detect them since tracks Y position was calculated via JS_API.

So this is only a matter of inverting the coordinates then?

This is the main and only function that stores all tracks coordinates and the rest of the script just reads it, so I assume it only needs modification here in order to work with OSX:

Code:
local TBH
function GetTracksXYH()
   TBH = {}
   local _, x_view_start, y_view_start, x_view_end, y_view_end = reaper.JS_Window_GetRect(track_window)
   -- ONLY ADD MASTER TRACK IF VISIBLE IN TCP
   if reaper.GetMasterTrackVisibility() == 1 then
      local master_tr = reaper.GetMasterTrack(0)
      local m_tr_h = reaper.GetMediaTrackInfo_Value(master_tr, "I_TCPH")
      local m_tr_t = reaper.GetMediaTrackInfo_Value(master_tr, "I_TCPY") + y_view_start
      local m_tr_b = m_tr_t + m_tr_h
      TBH[master_tr] = {t = m_tr_t, b = m_tr_b, h = m_tr_h} 
   end
   for i = 1, reaper.CountTracks(0) do
      local tr = reaper.GetTrack(0, i - 1)
      local tr_h = reaper.GetMediaTrackInfo_Value(tr, "I_TCPH")
      local tr_t = reaper.GetMediaTrackInfo_Value(tr, "I_TCPY") + y_view_start
      local tr_b = tr_t + tr_h
      TBH[tr] = {t = tr_t, b = tr_b, h = tr_h}
      for j = 1, reaper.CountTrackEnvelopes(tr) do
         local env = reaper.GetTrackEnvelope(tr, j - 1)
         local env_h = reaper.GetEnvelopeInfo_Value(env, "I_TCPH")
         local env_t = reaper.GetEnvelopeInfo_Value(env, "I_TCPY") + tr_t
         local env_b = env_t + env_h
         TBH[env] = {t = env_t, b = env_b, h = env_h}
      end
   end
end
My brain is little stuck ATM what am I supposed to do? Subtract track top and bot with the height of the window?

and btw this is the drawing code in case I need to add something here also:
Code:
function Element:draw()
  local _, x_view_start, y_view_start = reaper.JS_Window_GetRect(track_window)
  reaper.JS_Composite(track_window, self.x - x_view_start, self.y - y_view_start, self.w, self.h, self.bm, 0, 0, 1, 1)
  refresh_reaper()
end
where self.y is just tr_t

EDIT:
Figured I need to reverse the track bottom
Code:
tr_b = tr_t - tr_h
right now everything is "fine" tracks are exactly on same pixels as the mouse is, coordinates now match. But where is the problem? What API expects "normal" in this case "inverted" coordinates? I guess mouse also needs to be inverted?

EDIT:
I really hope there is some simple solution to this, because I've modified a lot of calculating code and inverted lots of things to many functions to get right coordinates but still got nowhere

Last edited by Sexan; 01-07-2020 at 12:54 PM.
Sexan is offline   Reply With Quote