reaper-oss / sws

The SWS extension is a collection of features that seamlessly integrate into REAPER, the Digital Audio Workstation (DAW) software by Cockos, Inc
https://www.sws-extension.org/
MIT License
448 stars 85 forks source link

BR_GetMouseCursorContext() - Envelope point detection broken in AI's #922

Open nofishonfriday opened 6 years ago

nofishonfriday commented 6 years ago

In AI's it returns env_segment when it should return env_point.

Alt Text

Test script I'm using:

function msg(m)
  return reaper.ShowConsoleMsg(tostring(m) .. "\n")
end

lastDetailsOut = -1

function GetMouseCursorDetails()

  windowOut, segmentOut, detailsOut = reaper.BR_GetMouseCursorContext()

  if lastDetailsOut ~= detailsOut then
    msg("detailsOut: " .. detailsOut)
  end

  lastDetailsOut = detailsOut

  reaper.defer(GetMouseCursorDetails)
end

GetMouseCursorDetails()
cfillion commented 6 years ago

BR_Envelope::Build seems to be the function needing an update to include points from AIs.

Unless we update BR_GetMouseCursorContext to have a unique context for AIs instead of being just "envelope" (#915)? No idea what the best way to do that would be though.

nofishonfriday commented 6 years ago

Thanks @cfillion.

Unless we update BR_GetMouseCursorContext to have a unique context for AIs instead of being just "envelope" (#915)?

Actually I (tried to) start working on this when I noticed it's currently broken for envelope points in AI. The logic for AI detection could be s.th. like this I thought: If (mouse cursor within AI) and not (mouse cursor over env_segment or env_point) => details_out = automation_item. (last priority check, so to say). Early test:

Alt Text

The "good thing" with this approach would be that env_point and env_segment detection wouldn't need to change to distinct if they are within AI or not. What do you and the others think ?

edit: Current relevant REAPER bug: https://forum.cockos.com/showthread.php?t=199142

(I'd expect that native API functions CountEnvelopePoints() and GetEnvelopePoint() which BR_Envelope::Build() uses would work as they did before the introduction of AI's when this bug is fixed, otherwise it would break all older scripts using this, so it would also fix this issue 'by itself'. But let's see how it goes. Anyway I'll halt further work on this until it's fixed in REAPER.)

Thanks for the thumbs up btw. :)

nofishonfriday commented 6 years ago

CountEnvelopePointsEx() is fixed in R5.78pre1. Also needs fixing in SWS though as CountEnvelopePoints() still only returns nr. of points outside AIs. I guess we'd now have to loop through all AIs to count all points on an envelope (inluding those in AIs) ?

nofishonfriday commented 6 years ago

Fix approach pushed, seems to work but not totally happy regarding efficiency (see my comment). If anyone has ideas for something better I'm all ears. :)

cfillion commented 6 years ago

It doesn't look too bad to me. Perhaps sorting can be avoided if there is no AIs?

nofishonfriday commented 6 years ago

Good point, I'll put that in, thanks. Not too happy about the nested loop to get all points in AIs either (edit: O(N2) ! :D), but seems there's no other way ? Meanwhile I've also asked in the scripers forum, let's see if other ideas come up: https://forum.cockos.com/showthread.php?t=204337

If not, I think we may go with this...

nofishonfriday commented 6 years ago

It's not as straight forward as I initially thought. Seems like BR_Envelope::Commit() would also need a rather big rewrite to account for AIs. Closing the related PR (#967) as it's not merge-ready.

mbrozzo commented 2 weeks ago

Hello, I would like to use the details output of BR_GetMouseCursorContext to act on envelope points in AIs. Any news on this?