Old 04-08-2020, 12:16 PM   #1041
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

Quote:
Originally Posted by juliansader View Post
I notice that the check_mouse_change function returns true whenever the mouse y position changes, which causes lots up extra updates. Perhaps the updates can be limited to when the y position moves into another media or envelope lane?




RoundRect with radius = 0 will draw a non-filled rectangle.

Would you prefer if I make the new behaviour optional? I can add an optional boolean parameter to JS_Composite.
I had issues for some reason when checking tracks, it would not update sometimes even the track changed. I am aware of Y problem...

It would be nice to be an optional for the future, its not documented how do make it (thats why I asked).

Thank you very much.


Regarding Stevie problem. On his two machines on windows, scripts flickers like crazy, also when he uses some your API in his script it flickers for some reason.
Sexan is online now   Reply With Quote
Old 04-08-2020, 12:51 PM   #1042
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by _Stevie_ View Post
@Julian

Sexan and I are pulling out our hair because of this refresh issue (flickering) which is only happening on Windows. Do you know if this is caused by REAPER itself or JS_API? And if you don't know: how could we find out?
Unfortunately I don't know what the problem might be on your computer. Is this a recent issue with the latest extension versions, or has Area51 or my own graphical scripts always flickered?

On both of my two Windows computers, Area51 only flickers slightly when hundreds of areas and ghosts are moved -- and when I remove y-position checking, it becomes very smooth.

As far as I can tell (with my own scripts too) probably the most important consideration for lowering flickering is to keep re-drawing to a minimum.

Another interesting thing that I noticed, is that compositing/blitting from a tiny bitmap is faster than compositing/blitting from a large bitmap, even if the destination image is similar sized. If the source bitmaps are all 1x1 pixel, I can stretch them to 100x100 onscreen and move 50 of them randomly in REAPER's windows without flickering. If the source bitmaps are 1000x1000 pixels, REAPER starts to stagger with only a dozen squares.
juliansader is offline   Reply With Quote
Old 04-08-2020, 12:55 PM   #1043
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

Quote:
Originally Posted by juliansader View Post
Unfortunately I don't know what the problem might be on your computer. Is this a recent issue with the latest extension versions, or has Area51 or my own graphical scripts always flickered?

On both of my two Windows computers, Area51 only flickers slightly when hundreds of areas and ghosts are moved -- and when I remove y-position checking, it becomes very smooth.

As far as I can tell (with my own scripts too) probably the most important consideration for lowering flickering is to keep re-drawing to a minimum.

Another interesting thing that I noticed, is that compositing/blitting from a tiny bitmap is faster than compositing/blitting from a large bitmap, even if the destination image is similar sized. If the source bitmaps are all 1x1 pixel, I can stretch them to 100x100 onscreen and move 50 of them randomly in REAPER's windows without flickering. If the source bitmaps are 1000x1000 pixels, REAPER starts to stagger with only a dozen squares.
No sorry this is not new issue. This was present before, he reported it few times but we were not sure what is causing the problem, we thought it was the script. But now he is noticing it on cursor change API also in his script (10 lines of code). That same code works perfect on his OSX system but on other two (I9 9900something) it flickers (slow refresh)

Regarding pixel stretchinh you told me that long before, thats why areas are 1 pixel stretched,but ghosts are normal. Or this is something even newer that I can use with ghosts?
Sexan is online now   Reply With Quote
Old 04-08-2020, 01:08 PM   #1044
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

BTW did you managed to reproduce my issue? I still need to use Invalidate manually to avoid graphic corruption
Sexan is online now   Reply With Quote
Old 04-08-2020, 01:13 PM   #1045
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Ah, I found something that might be contributing to the flickering: tooltips! I don't know why, but when REAPER draws tooltips over the composited areas, it flickers and doesn't track mouse movement smoothly. Try disabling Options: Show tooltips on media items and envelopes.

Quote:
Originally Posted by Sexan View Post
BTW did you managed to reproduce my issue? I still need to use Invalidate manually to avoid graphic corruption
Unfortunately, so far, tooltips is the only way that I could reproduce "stuck" ghosts.
juliansader is offline   Reply With Quote
Old 04-08-2020, 01:24 PM   #1046
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

Yeah I've also found that before but was affecting envelopes (when over envelope tracks). Unfortunately I have that option already disabled because the envelope updates are quite slow with that option on.
Sexan is online now   Reply With Quote
Old 04-08-2020, 01:44 PM   #1047
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

Ok we found the issue for his flickering:

Code:
reaper.JS_Window_InvalidateRect(track_window, 0, 0, 5000, 5000, false)
What should be the minimal values for refreshing the whole screen, (clients screen size)?

BTW this flickering is also present with your new version, I've send him the script with new API where I do not use invalidate and it still flickers, lowering this number makes flickering dissapear.

EDIT: his resolution is 3440 x 1440

EDIT:2 Its not this...we tried with minimal also....

Last edited by Sexan; 04-08-2020 at 02:18 PM.
Sexan is online now   Reply With Quote
Old 04-08-2020, 05:33 PM   #1048
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by Sexan View Post
Solved it! Will upload soon.
juliansader is offline   Reply With Quote
Old 04-09-2020, 12:51 AM   #1049
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

Awesome!! thank you!

Quote:
Originally Posted by juliansader View Post
I notice that the check_mouse_change function returns true whenever the mouse y position changes, which causes lots up extra updates. Perhaps the updates can be limited to when the y position moves into another media or envelope lane?
I really do not understand why vertical updates lags with this (this is why I went with Y, could not figure it out....)

Code:
local last_m_tr, last_m_p
function check_mouse_change()
   if mouse.p ~= last_m_p or mouse.tr ~= last_m_tr then
      last_m_p = mouse.p
      last_m_tr = mouse.tr
      return true
   end
end
I've tested it and update function passes normal (I've set counter and it increases on every track change), but it only updates on every 2 track change. You need to make 2 track difference for it to update ghosts vertically. And then ghosts are off by 1 track



See DRAWCOUNT changes then it changes track, it passes composite for all ghosts where I do the count, but as you see it does not update (this is with V1 JS_API)

Code:
A_DRAWCOUNT = 0
function Element:draw(w,h)
    reaper.JS_Composite(track_window, self.x, self.y, self.w, self.h, self.bm, 0, 0, w, h)
    A_DRAWCOUNT = A_DRAWCOUNT + 1
end

Last edited by Sexan; 04-09-2020 at 03:05 AM.
Sexan is online now   Reply With Quote
Old 04-09-2020, 06:04 AM   #1050
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
Default

Unfortunately this doesn’t clear the line, when “exiting” the item. Does this mean, I would need to use invalidate again, to destroy the line when not hovering an item? Or is there a more elegant way?

Quote:
Originally Posted by juliansader View Post
I would recommend that you use the Composite functions, since they work better on Linux and macOS (except for that Metal issue -- which is probably not relevant to your script), and you don't have to bother with DCs and GDI objects. Simply create a bitmap of any color at the start of the script, use JS_Composite to link and move the image, and destroy the bitmap when the script terminates.

For example:
Code:
bm = reaper.JS_LICE_CreateBitmap(true, 1, 1)
reaper.JS_LICE_Clear(bm, 0xFFFF0000)

trackview = reaper.JS_Window_FindChildByID(reaper.GetMainHwnd(), 1000)

function loop()
    x, y = reaper.GetMousePosition() -- screen
    if x ~= prev_x or y ~= prev_y then
        prev_x, prev_y = x, y
        item = reaper.GetItemFromPoint( x, y, true )
        if item then
            if item ~= prev_item then
                prev_item = item
                track_y = reaper.GetMediaTrackInfo_Value( reaper.GetMediaItem_Track( item ), "I_TCPY" ) + 
                          reaper.GetMediaItemInfo_Value( item, "I_LASTY" ) -- client
                item_h = reaper.GetMediaItemInfo_Value( item, "I_LASTH" )
            end
            x, y = reaper.JS_Window_ScreenToClient(trackview, x, y)
            reaper.JS_Composite(trackview, x, track_y, 1, item_h, bm, 0, 0, 1, 1)
        end
    end
    reaper.defer(loop)
end

reaper.atexit(function() if bm then reaper.JS_LICE_DestroyBitmap(bm) end end)
loop()
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 04-09-2020, 08:51 AM   #1051
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Quote:
Originally Posted by juliansader View Post
I would recommend that you use the Composite functions, since they work better on Linux and macOS (except for that Metal issue -- which is probably not relevant to your script), and you don't have to bother with DCs and GDI objects. Simply create a bitmap of any color at the start of the script, use JS_Composite to link and move the image, and destroy the bitmap when the script terminates.

For example:
Code:
bm = reaper.JS_LICE_CreateBitmap(true, 1, 1)
reaper.JS_LICE_Clear(bm, 0xFFFF0000)

trackview = reaper.JS_Window_FindChildByID(reaper.GetMainHwnd(), 1000)

function loop()
    x, y = reaper.GetMousePosition() -- screen
    if x ~= prev_x or y ~= prev_y then
        prev_x, prev_y = x, y
        item = reaper.GetItemFromPoint( x, y, true )
        if item then
            if item ~= prev_item then
                prev_item = item
                track_y = reaper.GetMediaTrackInfo_Value( reaper.GetMediaItem_Track( item ), "I_TCPY" ) + 
                          reaper.GetMediaItemInfo_Value( item, "I_LASTY" ) -- client
                item_h = reaper.GetMediaItemInfo_Value( item, "I_LASTH" )
            end
            x, y = reaper.JS_Window_ScreenToClient(trackview, x, y)
            reaper.JS_Composite(trackview, x, track_y, 1, item_h, bm, 0, 0, 1, 1)
        end
    end
    reaper.defer(loop)
end

reaper.atexit(function() if bm then reaper.JS_LICE_DestroyBitmap(bm) end end)
loop()

Thanks Julian! But I can't see how this method is better.. Is it lighter on CPU? Because, otherwise again the line flickers a little bit and stays behind the mouse cursor when moving it fast, like it did with GDI.. I get the same problem with Stevie too, when exiting items from the side. I fiddled a bit with the code but I could not find a solution..
__________________
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 04-09-2020, 03:06 PM   #1052
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by _Stevie_ View Post
Unfortunately this doesn’t clear the line, when “exiting” the item. Does this mean, I would need to use invalidate again, to destroy the line when not hovering an item? Or is there a more elegant way?
When the mouse exists an item, you can either unlink the bitmap, or give it a width or height of zero to hide it. The latter method is probably better when the line will be toggled on and off a lot.

Code:
if item
    ...
else
    reaper.JS_Composite(trackview, 0, 0, 0, 0, bm, 0, 0, 1, 1)
end

Quote:
Originally Posted by amagalma View Post
Thanks Julian! But I can't see how this method is better.. Is it lighter on CPU? Because, otherwise again the line flickers a little bit and stays behind the mouse cursor when moving it fast, like it did with GDI.. I get the same problem with Stevie too, when exiting items from the side. I fiddled a bit with the code but I could not find a solution..
The difference has mainly to do with animated windows: If REAPER itself is busily drawing in the window, GDI will flicker a lot on Windows, and will scarcely be visible at all on macOS and Linux. (At least, on my macOS and Linux computers.)

The line can only track the mouse once every defer cycle, so it will always lag a little behind, unfortunately.
juliansader is offline   Reply With Quote
Old 04-09-2020, 06:34 PM   #1053
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
Default

Quote:
Originally Posted by juliansader View Post
When the mouse exists an item, you can either unlink the bitmap, or give it a width or height of zero to hide it. The latter method is probably better when the line will be toggled on and off a lot.
Awesome, that worked, thanks Julian!

Another thing... I have a main line that will be drawn in the arrange and an additional line that will be drawn (layered), when the mouse hovers an item. As you can see in the GIF, the one in the item changes color, because sometimes it's above or below the arrange line. Is there a way to define top bitmap?

__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 04-09-2020, 06:44 PM   #1054
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

I have uploaded a provisional v1.002 to Github. Please let me know if it works OK.

I managed to get Area51 to work (almost) as smooth as silk on my Windows computers. The key seems to be to get the number of refreshes lower: Not more than 20 refreshes per second, and 10 is even better.

If nothing has changed, avoid refreshing. For example, while dragging areas, don't bother refreshing if the mouse is held down without moving.

So in the Refresh function I changed this:
Code:
function Refresh_reaper()
    -- reaper.JS_Window_InvalidateRect(trackview, 0, 0, 5000, 5000, false)
    mustInvalidate = true
end
And in main() I hacked some checks:
Code:
jsPrevTime = 0
local function Main()
    xpcall(
    function()
        ....
        Draw(Areas_TB) -- DRAWING CLASS
        if mustInvalidate then 
            jsNowTime = reaper.time_precise()
            jsMouseX, jsMouseY = reaper.GetMousePosition()
            if jsNowTime > jsPrevTime+0.1 and (jsMouseX ~= jsPrevMouseX or jsMouseY ~= jsPrevMouseY) then
                jsPrevTime = jsNowTime
                jsPrevMouseX, jsPrevMouseY = jsMouseX, jsMouseY
                reaper.JS_Window_InvalidateRect(track_window, 0, 0, 5000, 5000, false) 
                mustInvalidate = false 
            end
        end
        reaper.defer(Main)
I'm not sure what the effect of the size of the invalid rect would be: Is it best to invalidate the entire window, in which case all bitmaps are blitted; or should only a part of the screen that contains the moving bitmaps be invalidated, in which case the extension will try to find only those bitmaps that overlap with the invalid rect.

EDIT: Perhaps Area51 can adjust the update speed to the number of the areas being dragged? I'm not sure if the numbers are related to the CPU speed or screen refresh rate, but on my Windows computer I can drag about 500 ghosts at 10 refreshes per second without noticeable flicker.

EDIT 2: Or perhaps the extension itself should time updates, when bitmaps are composited.

Last edited by juliansader; 04-09-2020 at 09:07 PM.
juliansader is offline   Reply With Quote
Old 04-09-2020, 09:30 PM   #1055
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

v1.002 needs manual invalidate? Its not in composite like v.1.001? Because it does not work the same.

This is the version that I'm waiting for upload when we sort things out with compositing (made for v1.001). Not working with 1.002

This one has improvements to ghost + moving items (that was just not implemented atm).. Moving now check for update before refresh, like anything else

But I have that latest issue where it lags to update (I'm checking now track under mouse instead of Y) but something is wrong with drawing ghosts (or moving areas) there and I cannot figure out.
https://forum.cockos.com/showpost.ph...postcount=1053

Can you please attach your modified script?

Quote:
Originally Posted by juliansader View Post
EDIT 2: Or perhaps the extension itself should time updates, when bitmaps are composited.

Well for the sake of simplicity (IF ITS POSSIBLE) it would be extremely cool if extension can do that, optional parameter refresh (10-20 or whatever needs to be input there) so we avoid additional code.

Thank you very much

EDIT: Regarding Invalidate size, while still trying to find odd flickering issue on Stevie windows system, we found that Invalidate size has big effect here. If the invalidate is reduced to smaller number (in his case on UHD resolution) invalidate sizes bellow 1000 extremely reduce the flicker he is experiencing.

Last edited by Sexan; 02-13-2023 at 08:15 AM.
Sexan is online now   Reply With Quote
Old 04-10-2020, 12:33 AM   #1056
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by Sexan View Post
v1.002 needs manual invalidate? Its not in composite like v.1.001? Because it does not work the same.
v1.002 offers both alternatives, but as the API help docs advise, the optional autoUpdate is best suited for moving one or a small handful of bitmaps, like amagalma's script. If you have huge numbers of bitmaps that cover the window, don't autoUpdate, and instead call InvalidateRect yourself when your calculations and drawings are all done -- but remember to keep the InvalidateRects to a minimum.


Quote:
Originally Posted by Sexan View Post
Well for the sake of simplicity (IF ITS POSSIBLE) it would be extremely cool if extension can do that, optional parameter refresh (10-20 or whatever needs to be input there) so we avoid additional code.
Done, and it works great! (Touch wood...) Will test a bit more and upload later today.
juliansader is offline   Reply With Quote
Old 04-10-2020, 12:36 AM   #1057
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

Awesome!
If you can test it on that script I've attached that would be great, because that is the "production" script for your latest API which will go live. So I know what I need to adjust/modify, along with tweaks you found/added that are beneficial for the script.

Thank you very much!
Sexan is online now   Reply With Quote
Old 04-10-2020, 04:58 AM   #1058
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

I've uploaded the new dev version to Github so that you and any other interested users can experiment with the new delay "trick".

There is a new function, JS_Composite_Delay with which the time can be set. Try
reaper.JS_Composite_Delay(track_window, 0.1, 0.2, 100)
as starting values for your tests.

In the current "upload" version of Area51 script, since the optional autoUpdate argument is not provided in the JS_Composite and JS_Composit_Unlink functions, autoUpdate is disabled, and you should UNcomment the refresh statements in the Refresh_reaper and Element:draw functions.

Alternatively, you can add the optional autoUpdate=true arguments, in which case the refresh statement are not necessary.

In my own tests, the autoUpdate seems to work slightly better, presumably since the auto-invalidated rect is small, only large enough to cover those bitmaps that moved. I could get very smooth dragging of many ghosts with faster settings: JS_Composite_Delay(track_window, 0.05, 0.15, 100).
juliansader is offline   Reply With Quote
Old 04-10-2020, 05:12 AM   #1059
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

Awesome that ghost drawing bug is fixed!

Code:
function Element:draw(w,h)
    reaper.JS_Composite(track_window, self.x, self.y, self.w, self.h, self.bm, 0, 0, w, h, true)
    reaper.JS_Composite_Delay(track_window, 0.1, 0.2, 100)
I use it like this or at the start of the script or on every deffer cycle?
Sexan is online now   Reply With Quote
Old 04-10-2020, 05:31 AM   #1060
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

Something is really wrong somewhere and I do not know where.

This is all on current dev version,but tried this previous ones also...



This is similar to my last issue where the update lags.

Zooming with mouse wheel.

Now what interesting is that area is IN the position where it should be (you can see cursor change). But graphics are on the wrong place.

What bugs me the most is that draw counter goes up for the number of items or areas or whatever. So it passes JS_Composite, but its not refreshed?

Post #1053 is the easiest way to reproduce it. I literally spend last 2 days trying to fix it, not sure whats the problem

Edit. This gif above is only on latest version, prior versions are ok

Last edited by Sexan; 04-10-2020 at 05:50 AM.
Sexan is online now   Reply With Quote
Old 04-10-2020, 07:20 AM   #1061
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
Default

@Julian: in case you don't mind... would you be able to join the AS51 discord channel? I think this would make it easier to solve issues.
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 04-10-2020, 07:23 AM   #1062
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

Also not sure if this is supposed to happen, but when using delay, it affects reaper also ?
Sexan is online now   Reply With Quote
Old 04-10-2020, 11:14 AM   #1063
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

ok I managed to fix the issues finally.

The problem for some things seems to be that composite does not have enough time to process the bitmap and this is the only reliable way to make all work

Code:
function Draw(tbl)
  local is_view_changed = Arrange_view_info()

  if check_mouse_change() then
    GHOST_UPDATE = (copy or move) and 1
    MOVE_AREA_UPDATE = move and 1
 end

  if is_view_changed and not DRAWING then
    AREAS_UPDATE = 1
    GHOST_UPDATE = copy and 1
  end

  Track(tbl)

  if AREAS_UPDATE and AREAS_UPDATE < 3 then
    AREAS_UPDATE = AREAS_UPDATE + 1
  else
    AREAS_UPDATE = false
  end
  if MOVE_AREA_UPDATE and MOVE_AREA_UPDATE < 3 then
    MOVE_AREA_UPDATE = MOVE_AREA_UPDATE + 1
  else
    MOVE_AREA_UPDATE = false
  end
  if GHOST_UPDATE and GHOST_UPDATE < 3 then
    GHOST_UPDATE = GHOST_UPDATE + 1
  else
    GHOST_UPDATE = false
  end
end
It seems it needs few defer cycles. All my posted issues are now gone with this code.

Something I do not understand is why similar ultra fast actions behave differently regarding calling composite. For example:

If I check previous mouse click state it works fine (if mouse.l_click ~= last_m_lclick). This is pretty fast action.
But if I check if track under mouse changed (if mouse.track ~= last_mouse_track) it does not work.
I also check mouse.p but with snap (converted from mouse.x), so it does not update all the time but only when time changes. this ALSO works, its been working from the beginning.

Code:
local last_m_tr, last_m_p, last_mc
function check_mouse_change()
   if mouse.p ~= last_m_p or mouse.tr ~= last_m_tr or mouse.l_click ~= last_mc then
      last_m_p = mouse.p -- CHECK TIME POSITION WHICH CAN BE IN SNAP OR NOT -- (works from the beginning)
      last_m_tr = mouse.tr -- CHECKS TRACK UNDER MOUSE (WORKS ONLY WITH MODIFICATION)
      last_mc = mouse.l_click -- CHECK IF MOUSE WAS CLICKED (works from the beginning)
      return true
   end
end
I've tried also with time counter but its not reliable, you have to make either long time to be safe or pin point the minimum time

So basically I give few more cycles time for composite API to finish its stuff.

Solved issues post#1064 & #1053 With latest API

Last edited by Sexan; 04-10-2020 at 11:29 AM.
Sexan is online now   Reply With Quote
Old 04-10-2020, 01:42 PM   #1064
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

I'm relieved that you could solve the problem.

I also tried to apply some fix inside the extension -- please try the dev1002b version.


Quote:
Originally Posted by Sexan View Post
Also not sure if this is supposed to happen, but when using delay, it affects reaper also ?
Yes, it is intended to affect REAPER too, when one or more bitmaps are composited onto the window. However, it only affects window drawing, not any other processes. For example, script defer cycles can be much faster than the composite delay.
juliansader is offline   Reply With Quote
Old 04-10-2020, 02:23 PM   #1065
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

Well I cannot spot any bug now (will check 1002b), everything works fine. That drawing problem with ghosts are fixed also.

Really sorry, I could not figure out the source of some problems, changed code back and forward and tried 100 things. The part where I was confused is it would update the screen when mouse X is in snap mode (thats still 1 fast update) but it would not update on track change. Really weird...

Mouse in snap mode is basically exact same change as track change....

Thank you very much for your work and your time!

Last edited by Sexan; 04-10-2020 at 02:31 PM.
Sexan is online now   Reply With Quote
Old 04-10-2020, 02:49 PM   #1066
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

Well 1002b reduced the cycle time needed for everything to update

Version before needs 1 cycle more to behave the same

EDIT: Tested back and forward, seems to be the same, my bad

Last edited by Sexan; 04-10-2020 at 03:10 PM.
Sexan is online now   Reply With Quote
Old 04-10-2020, 03:08 PM   #1067
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

If everything works as intended in the new dev1002b version, no extra code should be needed for scrolling and zooming.


Quote:
Originally Posted by Sexan View Post
Well I cannot spot any bug now (will check 1002b), everything works fine. That drawing problem with ghosts are fixed also.
Is there good news about the flickering on Stevie's computer?
juliansader is offline   Reply With Quote
Old 04-10-2020, 03:14 PM   #1068
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

Quote:
Originally Posted by juliansader View Post
If everything works as intended in the new dev1002b version, no extra code should be needed for scrolling and zooming.




Is there good news about the flickering on Stevie's computer?
Yeah works now without additional code.

Yeah, its not related to API, but its with Reaper in some way...

He accidentally found while trying to record something for me, that when OBS is opened (just opened not doing anything), flicker disappears.

It seems that OBS wakes some CPU state or something else in Windows which Reaper does not. He tested it few times

The flicker is really REALLY horrible, never seen that before. It looks like its refreshing the screen at low rate. you can see flicker constantly while Composite is called

Its exact like this :
https://youtu.be/ZmIKxFBwsDU?t=18

But only on areass and they are being drawn or moved,, anything that need to call Composite frequently

Last edited by Sexan; 04-10-2020 at 03:26 PM.
Sexan is online now   Reply With Quote
Old 04-10-2020, 04:37 PM   #1069
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Quote:
Originally Posted by juliansader View Post
When the mouse exists an item, you can either unlink the bitmap, or give it a width or height of zero to hide it. The latter method is probably better when the line will be toggled on and off a lot.

Code:
if item
    ...
else
    reaper.JS_Composite(trackview, 0, 0, 0, 0, bm, 0, 0, 1, 1)
end

The difference has mainly to do with animated windows: If REAPER itself is busily drawing in the window, GDI will flicker a lot on Windows, and will scarcely be visible at all on macOS and Linux. (At least, on my macOS and Linux computers.)

The line can only track the mouse once every defer cycle, so it will always lag a little behind, unfortunately.

Thanks a lot Julian!


I have uploaded the new script version in ReaPack. Using version 1.001. Now guide lines can be drawn in Midi Editor too. Composite method is soo much better and easier! Thanks!
__________________
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 04-11-2020, 07:41 AM   #1070
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

We can send a command to a window:
Code:
-- Action 1011 = Autoplay: Toggle on/off
me = reaper.JS_Window_Find("Media Explorer", true)
reaper.JS_Window_OnCommand(me, 1011)

How can we track the commands (Reaper commands) that are sent to a window?

Edit: Found it!
Code:
reaper.JS_WindowMessage_Intercept( MainHwnd, "WM_COMMAND", true )
_, _, _, CmdID = reaper.JS_WindowMessage_Peek( MainHwnd, "WM_COMMAND" )
__________________
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; 04-11-2020 at 08:28 AM.
amagalma is offline   Reply With Quote
Old 04-12-2020, 04:42 PM   #1071
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

My script "amagalma_Toggle show editing guide line on item under mouse cursor in Main Window or in MIDI Editor" (in ReaPack) does not work on OSX and I suspect that JS_Window_ScreenToClient may be the culprit. I need your help!

Code:
x, y = reaper.JS_Window_ScreenToClient( windowHWND, x, y )
* On Windows and Linux, screen coordinates are relative to *upper* left corner of the primary display, and the positive Y-axis points downward.
* On macOS, screen coordinates are relative to the *bottom* left corner of the primary display, and the positive Y-axis points upward.
* On all platforms, client coordinates are relative to the upper left corner of the client area.


I am posting a very small part of the script. What should be changed in this code in order to make it work for OSX too? :
Code:
local OSX = reaper.GetOS():find("OSX") and true or false
local MainHwnd = reaper.GetMainHwnd()
local trackview = reaper.JS_Window_FindChildByID(MainHwnd, 1000)
local _, trackview_w, trackview_h = reaper.JS_Window_GetClientSize( trackview )
local x, y = reaper.GetMousePosition() -- screen
x, y = reaper.JS_Window_ScreenToClient(trackview, x, y)
  if 0 <= x and x <= trackview_w and 0 <= y and y <= trackview_h then
    reaper.JS_Composite(trackview, x, 0, 1, vis_tracks_h, bm, 0, 0, 1, 1)
  end
Would this work? :
Code:
screen_height = ({reaper.my_getViewport(0,0,0,0,0,0,0,0, false )})[4]
y = OSX and screen_height - y or y
x, y = reaper.JS_Window_ScreenToClient(trackview, x, y)


Found what is the problem!
Code:
reaper.JS_Window_GetForeground()
and reaper.BR_Win32_GetForegroundWindow()
These functions return the reaper.GetMainHwnd() when working in the main window in Windows! But on OSX/Linux they return the actual window that was last clicked (be it the trackview, the tcp, etc). The same is true for the Active MIDI Editor window etc. In Windows you get the parent, in OSX/Linux you get the child. I think this difference should be added in the documentation!
__________________
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; 04-13-2020 at 04:42 AM.
amagalma is offline   Reply With Quote
Old 04-13-2020, 05:45 PM   #1072
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by amagalma View Post
These functions return the reaper.GetMainHwnd() when working in the main window in Windows! But on OSX/Linux they return the actual window that was last clicked (be it the trackview, the tcp, etc). The same is true for the Active MIDI Editor window etc. In Windows you get the parent, in OSX/Linux you get the child. I think this difference should be added in the documentation!
Already done in v1.001!

(Sexan also encountered this problem a few posts above, and JS_Window_FromPoint seems to be a better bet.)
juliansader is offline   Reply With Quote
Old 04-13-2020, 05:55 PM   #1073
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
Default

Can you comment on the bitmap on top issue?

https://forum.cockos.com/showpost.ph...postcount=1057
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 04-13-2020, 06:07 PM   #1074
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by _Stevie_ View Post
Another thing... I have a main line that will be drawn in the arrange and an additional line that will be drawn (layered), when the mouse hovers an item. As you can see in the GIF, the one in the item changes color, because sometimes it's above or below the arrange line. Is there a way to define top bitmap?
Sorry, not yet!
juliansader is offline   Reply With Quote
Old 04-13-2020, 06:10 PM   #1075
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
Default

Okeee, thanks Julian!
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 04-15-2020, 12:12 PM   #1076
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Julian, the JS_Composite function seems to fail drawing in some OSX systems. Do you have any idea? I have latest version of macOS Catalina installed as a virtual machine, and for me it works. For some other macOS users it works too, but for some not.


Here are two test codes. This doesn't seem to do anything on some OSX systems:
Code:
local trackview = reaper.JS_Window_FindChildByID( reaper.GetMainHwnd(), 1000)
local _, w, h = reaper.JS_Window_GetClientSize( trackview )
local bm_vert = reaper.JS_LICE_CreateBitmap(true, 1, 1)
local bm_hor = reaper.JS_LICE_CreateBitmap(true, 1, 1)
reaper.JS_LICE_Clear(bm_vert, 0xFFFF0000)
reaper.JS_LICE_Clear(bm_hor, 0xFFFF0000)
local floor = math.floor
local start = reaper.time_precise()
local once = true
function redcross()
  if once then
    reaper.JS_Composite(trackview, floor(w/2-40), 0, 80, h, bm_vert, 0, 0, 1, 1)
    reaper.JS_Composite(trackview, floor(w/2-h/2), floor(h/2-40), h, 80, bm_hor, 0, 0, 1, 1)
    once = false
  end
  if reaper.time_precise()-start <=5 then
    reaper.defer(redcross)
  else
    reaper.JS_LICE_DestroyBitmap(bm_vert)
    reaper.JS_LICE_DestroyBitmap(bm_hor)
    reaper.ShowConsoleMsg("script end\n\n")
    return reaper.defer(function() end)
  end
end
redcross()
But this always works:
Code:
local trackview = reaper.JS_Window_FindChildByID( reaper.GetMainHwnd(), 1000)
local _, w, h = reaper.JS_Window_GetClientSize( trackview )
local floor = math.floor
local start = reaper.time_precise()
local more = math.floor(w/150)
local pen = reaper.JS_GDI_CreatePen( more, 16777215 )
w = -more
function draw()
  w = w + more
  local hdc = reaper.JS_GDI_GetClientDC( trackview )
  reaper.JS_GDI_SelectObject( hdc, pen ) 
  reaper.JS_GDI_Line( hdc, w, 0, w, h )
  reaper.JS_GDI_ReleaseDC( trackview, hdc )
  if reaper.time_precise()-start <=5 then
    reaper.defer(draw)
  else
    reaper.UpdateArrange()
    reaper.JS_GDI_DeleteObject( pen )
    reaper.ShowConsoleMsg("script end\n\n")
    return reaper.defer(function() end)
  end
end
draw()

What could be wrong? Does JS_Composite depend on some OS setting?
__________________
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 04-15-2020, 02:12 PM   #1077
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,585
Default

Yeah you need to force classic mode in advanced settings in reaper for OSX
Sexan is online now   Reply With Quote
Old 04-15-2020, 03:05 PM   #1078
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Hi Julian,

Trying to load the Reascript API 1.x from repack doesn't seem to work on Mac.

I'm stuck at version .99 no matter what I do. I clicked on your xml link and pasted that into the "Import Repositories" and I get a quick import dialog with a progress bar for a split second then then it goes away... but I'm still at v.99.

This is the link I used:
https://raw.githubusercontent.com/Re...ster/index.xml

Any ideas?

Thanks.
__________________
Cheers... Andrew K
Reaper v6.80+dev0621 - June 21 2023 • Catalina • Mac Mini 2020 6 core i7 • 64GB RAM • OS: Catalina • 4K monitor • RME RayDAT card with Sync Card and extended Light Pipe.
Thonex is offline   Reply With Quote
Old 04-15-2020, 03:42 PM   #1079
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Quote:
Originally Posted by Sexan View Post
Yeah you need to force classic mode in advanced settings in reaper for OSX

Strange, because it works on my installation and the mode is set to "Automatic (recommended, Metal on 10.11+)"

EDIT: Maybe it works because I have macOS installed in VMware?...
JS_Window_EnableMetal returns always 0 here [ 0 = N/A (Windows and Linux) ]
__________________
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; 04-16-2020 at 05:59 AM.
amagalma is offline   Reply With Quote
Old 04-16-2020, 03:34 PM   #1080
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by amagalma View Post
Julian, the JS_Composite function seems to fail drawing in some OSX systems. Do you have any idea? I have latest version of macOS Catalina installed as a virtual machine, and for me it works. For some other macOS users it works too, but for some not.


Here are two test codes. This doesn't seem to do anything on some OSX systems:
Which version of the extension are they using? Prior to v1.000, the two JS_Composite calls require a subsequent JS_Window_InvalidateRect to trigger the window update.

It shouldn't depend on the graphics setting, AFAIK, since the Metal bug only affects transparency. However, there may be other OSX weirdness that I'm not aware of. [EDIT: Actually, I am aware of other weirdness in Classic mode, but that will be fixed in v1.002 and shouldn't affect this script.]

Since v1.000, JS_Composite automatically updates the window, but I think this was a mistake, and I should have made auto-update an optional boolean parameter.
juliansader 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 04:28 AM.


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