Old 01-25-2020, 05:25 AM   #921
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Quote:
Originally Posted by amagalma View Post
That is the window that tweaks the colors of a theme.
Theme development: Show theme tweak/configuration window, action 41930
Oh OK, thats an owner-drawn listbox (SPY++ says LBS_OWNERDRAWFIXED style), I don't know how you go about reading item text from those.

EDIT
To be able to use LB_GETTEXT like I was seems that owner-drawn listbox would also need to have the LBS_HASSTRINGS flag set which it doesn't.

List Box Styles,
https://docs.microsoft.com/en-us/win...ist-box-styles


I'm not a Win32 API guru either, so...

Last edited by Edgemeal; 01-26-2020 at 03:29 PM.
Edgemeal is offline   Reply With Quote
Old 01-25-2020, 07:42 AM   #922
Dafarkias
Human being with feelings
 
Dafarkias's Avatar
 
Join Date: Feb 2019
Location: Southern Vermont
Posts: 864
Default

Quote:
Originally Posted by juliansader View Post
Could you elaborate? (Do you mean that when the mixer is in the foreground, GetState does not detect any key strokes?)
Sorry for not making that clear, yes.

For me, when the mixer is focused, the VKeys code I shared does not receive any input.
__________________

Support my feature request!
Dafarkias is offline   Reply With Quote
Old 01-25-2020, 10:35 AM   #923
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by Dafarkias View Post
Sorry for not making that clear, yes.

For me, when the mixer is focused, the VKeys code I shared does not receive any input.
Good catch. I will submit a bug report.
juliansader is offline   Reply With Quote
Old 01-25-2020, 01:41 PM   #924
Dafarkias
Human being with feelings
 
Dafarkias's Avatar
 
Join Date: Feb 2019
Location: Southern Vermont
Posts: 864
Default

Quote:
Originally Posted by juliansader View Post
Good catch. I will submit a bug report.
That's a bug?

Hm.

I guess I just figured that I was missing something or just wasn't using the function properly...
__________________

Support my feature request!
Dafarkias is offline   Reply With Quote
Old 01-28-2020, 04:49 AM   #925
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

How to know if particular keys are being held down during defer?


Example/pseudo code:
Code:
function main()
  --[[
  OK = check if alt + shift are being pressed
  --]]
  if OK then
    reaper.defer(main)
  else
    reaper.ShowConsoleMsg("You released Alt+Shift")
    return
  end
end
__________________
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 01-28-2020, 10:26 AM   #926
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by amagalma View Post
How to know if particular keys are being held down during defer?
You can either use JS_VKeys_GetState (which is similar to the Win32 function GetKeyboardState) or, for modifier keys only, JS_Mouse_GetState:

Code:
if reaper.JS_VKeys_GetState(scriptStartTime):byte(x) ~= 0 then ...
or

Code:
if reaper.JS_Mouse_GetState(24) == 24 then ... -- 8:Shift, 16:Alt
juliansader is offline   Reply With Quote
Old 01-28-2020, 03:05 PM   #927
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Quote:
Originally Posted by juliansader View Post
You can either use JS_VKeys_GetState (which is similar to the Win32 function GetKeyboardState) or, for modifier keys only, JS_Mouse_GetState:

Code:
if reaper.JS_VKeys_GetState(scriptStartTime):byte(x) ~= 0 then ...
or

Code:
if reaper.JS_Mouse_GetState(24) == 24 then ... -- 8:Shift, 16:Alt

Thanks!!


If for example I want to check if "o" is being pressed then the code would be:
Code:
if reaper.JS_VKeys_GetState(scriptStartTime):byte("o") ~= 0 then

Correct?
__________________
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 01-28-2020, 03:36 PM   #928
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Quote:
Originally Posted by amagalma View Post
Correct?
Think you need to use a virtual key code,
https://docs.microsoft.com/en-us/win...tual-key-codes

so something like,
VK_O = 0x4F -- 'O' key
... :byte(VK_O) ~= 0 then ...
Edgemeal is offline   Reply With Quote
Old 01-29-2020, 05:53 AM   #929
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Quote:
Originally Posted by Edgemeal View Post
Think you need to use a virtual key code,
https://docs.microsoft.com/en-us/win...tual-key-codes

so something like,
VK_O = 0x4F -- 'O' key
... :byte(VK_O) ~= 0 then ...

Thank you Edgemeal!!

Another question:

How can I know what key triggered the current script so that I can check if it is still being held down? For example I have set my script to work with mousewheel+Alt+Shift and have hard-coded in the script to check if Alt+Shift are being held (as julian showed me):
Code:
if reaper.JS_Mouse_GetState(24) == 24 then ... -- 8:Shift, 16:Alt
How could my script know the modifiers that triggered it without hard-coding it inside?
pseudo-code:
Code:
modifiers_that_triggered_script = xxxx
if reaper.JS_Mouse_GetState(modifiers_that_triggered_script ) == modifiers_that_triggered_script then
__________________
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; 01-29-2020 at 06:05 AM.
amagalma is offline   Reply With Quote
Old 01-29-2020, 06:31 AM   #930
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Found it!


Just this code outside of the defer:
Code:
for i = 60, 0, -4  do
  modifiers = reaper.JS_Mouse_GetState(i)
  if modifiers ~= 0 then break end
end
And this inside:
Code:
reaper.JS_Mouse_GetState(modifiers) == modifiers
__________________
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 01-30-2020, 06:40 AM   #931
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Is there a code-snippet available, from which I can learn, how to save parts of the screen as pngs?

Basically my question is, how do I create a bitmap from the screen's contents, so I can use JS_LICE_WritePNG?
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...

Last edited by Meo-Ada Mespotine; 01-30-2020 at 07:02 AM.
Meo-Ada Mespotine is offline   Reply With Quote
Old 01-30-2020, 02:40 PM   #932
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Quote:
Originally Posted by mespotine View Post
Basically my question is, how do I create a bitmap from the screen's contents, so I can use JS_LICE_WritePNG?
Excellent question! I messed around with that a little bit before, PNG's look OK but I was never really sure I'm doing it correctly , would love to get Julian's feedback!

Capture screen area to PNG,..
Updated, Requires API v0.999
Code:
function CaptureScreenArea(x,y,w,h,filename)
  scrnDC = reaper.JS_GDI_GetScreenDC() --< Only available on Windows!
  destBmp = reaper.JS_LICE_CreateBitmap(true,w,h)
  destDC = reaper.JS_LICE_GetDC(destBmp)
  reaper.JS_GDI_Blit(destDC, 0, 0, scrnDC, x, y, w, h)
  reaper.JS_LICE_WritePNG(filename, destBmp, false)
  reaper.JS_LICE_DestroyBitmap(destBmp)
  reaper.JS_GDI_ReleaseDC(scrnDC)
end

Capture a window to PNG,..
* On Windows 10 it captures only the target app window, even when behind other windows!
Code:
function GetBounds(hwnd)
  local _, left, top, right, bottom = reaper.JS_Window_GetRect(hwnd)
  return left, top, right-left, bottom-top
end

function CaptureWindow(windowTitle, filename, win10) 
  window = reaper.JS_Window_FindTop(windowTitle, true)
  if not window then reaper.MB('Window not found!','Capture Error',0) return end
  sourceHDC = reaper.JS_GDI_GetWindowDC(window)
  _,_,w,h = GetBounds(window)
  srcx,srcy = 0,0
  if win10 then srcx=7 w=w-14 h=h-7 end -- workaround for invisible Win10 borders.
  dest_bmp = reaper.JS_LICE_CreateBitmap(true,w,h)
  destDC = reaper.JS_LICE_GetDC(dest_bmp)
  -- copy source to dest & write PNG
  reaper.JS_GDI_Blit(destDC, 0, 0, sourceHDC, srcx, srcy, w, h)
  reaper.JS_LICE_WritePNG(filename, dest_bmp, false) 
  -- clean up resources
  reaper.JS_GDI_ReleaseDC(window, sourceHDC)
  reaper.JS_LICE_DestroyBitmap(dest_bmp)
end

Last edited by Edgemeal; 02-08-2020 at 04:12 PM. Reason: Update for JS_API v0.999
Edgemeal is offline   Reply With Quote
Old 01-30-2020, 03:14 PM   #933
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 Edgemeal View Post
Excellent question! I messed around with that a little bit before, PNG's look OK but I was never really sure I'm doing it correctly , would love to get Julian's feedback!

Capture screen area to PNG,..
Code:
function CaptureScreenArea(x,y,w,h,filename)
  sourceHDC = reaper.JS_GDI_GetScreenDC()
  destBmp = reaper.JS_LICE_CreateBitmap(true,w,h)
  destDC = reaper.JS_LICE_GetDC(destBmp)
  reaper.JS_GDI_Blit(destDC, 0, 0, sourceHDC, x, y, w, h)
  reaper.JS_LICE_WritePNG(filename, destBmp, false)
  reaper.JS_LICE_DestroyBitmap(destBmp)
end

Capture a window to PNG,..
Code:
function GetBounds(hwnd)
  local _, left, top, right, bottom = reaper.JS_Window_GetRect(hwnd)
  return left, top, right-left, bottom-top
end

function CaptureWindow(windowTitle, filename, win10) 
  window = reaper.JS_Window_FindTop(windowTitle, true)
  if not window then reaper.MB('Window not found!','Capture Error',0) return end
  sourceHDC = reaper.JS_GDI_GetWindowDC(window)
  _,_,w,h = GetBounds(window)
  srcx,srcy = 0,0
  if win10 then srcx=7 w=w-14 h=h-7 end -- workaround for invisible Win10 borders.
  dest_bmp = reaper.JS_LICE_CreateBitmap(true,w,h)
  destDC = reaper.JS_LICE_GetDC(dest_bmp)
  -- copy source to dest & write PNG
  reaper.JS_GDI_Blit(destDC, 0, 0, sourceHDC, srcx, srcy, w, h)
  reaper.JS_LICE_WritePNG(filename, dest_bmp, false) 
  -- clean up resources
  reaper.JS_GDI_ReleaseDC(window, sourceHDC)
  reaper.JS_LICE_DestroyBitmap(dest_bmp)
end
Thank You, Savior of the Universe
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 01-30-2020, 03:23 PM   #934
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 juliansader View Post

I have spent an embarrassing amount of time trying to get png writing to work, but I can't get libpng to link properly.

However, this afternoon I tried writing jpegs with jpeglib, and it compiled and worked immediately.
From some time ago: would it be possible to add jpg support as well? This would help us tons at Ultraschall.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 01-31-2020, 03:31 AM   #935
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by Edgemeal View Post
Excellent question! I messed around with that a little bit before, PNG's look OK but I was never really sure I'm doing it correctly , would love to get Julian's feedback!
This is indeed the correct way to do it, AFAIK.

I just realized that there is no API function to release screen DCs, and I will add it in the next update.
juliansader is offline   Reply With Quote
Old 01-31-2020, 06:58 AM   #936
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

@edgemeal
Works great
I will add slightly altered versions of your functions to my Ultraschall-Api, if that's ok.
I think they are real nice to have in the first place.

One more thing: when I capture a window, that is hidden by another window, I will capture the overlapping window instead or at least as well. Is there a chance to get the content of the window regardless of being hidden behind other windows?
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 01-31-2020, 12:27 PM   #937
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Quote:
Originally Posted by juliansader View Post
This is indeed the correct way to do it, AFAIK.

I just realized that there is no API function to release screen DCs, and I will add it in the next update.
Thanks for the reply! I was wondering about that, looking at it again today I see the GDI Object counter for reaper.exe increments everytime I call the CaptureScreenArea function, so ya looks like it has a leak!
Edgemeal is offline   Reply With Quote
Old 01-31-2020, 12:28 PM   #938
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Quote:
Originally Posted by mespotine View Post
@edgemeal
One more thing: when I capture a window, that is hidden by another window, I will capture the overlapping window instead or at least as well. Is there a chance to get the content of the window regardless of being hidden behind other windows?
If you use the CaptureWindow function the source window can be completely behind other windows, or not completely visible in desktop area and the capture should be only the source window, at least thats the way it works here on Win10.
Edgemeal is offline   Reply With Quote
Old 02-02-2020, 09:15 AM   #939
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Hmm...maybe something changed since Windows 7 as I had numerous problems with it.

Will investigate into it further. Maybe I'm just holding it wrong.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 02-02-2020, 10:47 AM   #940
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Quote:
Originally Posted by mespotine View Post
Hmm...maybe something changed since Windows 7 as I had numerous problems with it.

Will investigate into it further. Maybe I'm just holding it wrong.
Not sure how Julian's API is doing it but 10+ years ago I used BitBlt and StretchBlt in many Windows apps where I'd blit parts of hidden images to create new images without a problem.

So can only guess you're using JS_GDI_GetScreenDC() instead of JS_GDI_GetWindowDC(hwnd).
Edgemeal is offline   Reply With Quote
Old 02-04-2020, 02:36 PM   #941
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

I experimented with the problem further and it seems, that at least on Windows 7, the capturing of the gfx.init-window is not entirely possible.
Run the code and move windows on top of the gfx.init-window. You'll see the problems in the written pngs very quickly, as you can see the windows on top of the gfx.init-window in the written pngs.

I've looked into Julian's code and it seems, that this isn't a problem in his code, so I suspect, there's a WDL-bug somewhere.

Code:
-- This script will attempt to save a screenshot of the gfx-window once a second.
-- Just move some windows in front of the gfx-window to see the effect.
-- It captures the right window, BUT: also what's before it.
-- Maybe this is a Reaper-bug?

-- Set this output path and run the program.
-- In this path, all screenshots will be stored.
output_path="c:\\temp\\A2/"



-- the function for capturing, which is mostly your code, slightly altered(and simplified for this demo)
-- still, the bug remains

ultraschall={}
function ultraschall.CaptureWindowAsPNG(windowTitle, filename_with_path, x, y, w, h, win10)
  local window
  
  window = reaper.JS_Window_FindTop(windowTitle, true)
  
  local sourceHDC = reaper.JS_GDI_GetWindowDC(window)
  
  local _, Aleft, Atop, Aright, Abottom = reaper.JS_Window_GetRect(window)
  Aright=Aright-Aleft
  Abottom=Abottom-Atop
  if x==nil then x=0 end
  if y==nil then y=0 end
  if w==nil then w=Aright end
  if h==nil then h=Abottom end
  
  if win10 then srcx=7 w=w-14 h=h-7 end -- workaround for invisible Win10 borders.
  local dest_bmp = reaper.JS_LICE_CreateBitmap(true,w,h)
  local destDC = reaper.JS_LICE_GetDC(dest_bmp)
  -- copy source to dest & write PNG
  reaper.JS_GDI_Blit(destDC, 0, 0, sourceHDC, x, y, w, h)
  local writeable = reaper.JS_LICE_WritePNG(filename_with_path, dest_bmp, false)
  -- clean up resources
  reaper.JS_GDI_ReleaseDC(window, sourceHDC)
  reaper.JS_LICE_DestroyBitmap(dest_bmp)
  if writeable==false then return 8 end
  return writeable
end




-- window
gfx.init("Tudelu bugtest")

-- prepare some variables and stuff
B=gfx.loadimg(1, reaper.GetResourcePath().."/data/track_icons/group.png")
gfx.x=-50
gfx.y=-300
gfx.blit(1,14,0)
gfx.setfont(1, "Arial", 50, 0)
counter=0
index=0


-- the main-defer-loop, which stores a screenshot of the gfx-window every second
function main()
  counter=counter+1
  if counter==30 then
    index=index+1
    if index<10 then zero="0" else zero="" end
    A=ultraschall.CaptureWindowAsPNG("Tudelu bugtest", output_path..zero..index..".png", 0, 0, gfx.w, gfx.h, true)
    counter=0
  end
  reaper.defer(main)
end

main()
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 02-04-2020, 03:20 PM   #942
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Quote:
Originally Posted by mespotine View Post
I experimented with the problem further and it seems, that at least on Windows 7, the capturing of the gfx.init-window is not entirely possible.
Ya OK, I tried the script on Win10 and is OK, but on Win7 I can see other windows that cover the source window.
Edgemeal is offline   Reply With Quote
Old 02-04-2020, 03:37 PM   #943
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Ok, then I'll add a note to the function's description, that it doesn't work on Windows 7 without issues.

@juliansader
Do you have an idea, what the problem could be? Shall I bugreport it?
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 02-05-2020, 12:19 AM   #944
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

This is a Windows issue, not WDL, so unfortunately the bug cannot be reported to Cockos.

When I first started with the JS_Composite function, I also tried blitting from overlapped windows using GDI, and encountered the same problem. I then read somewhere that this behavior changed sometime around Windows XP: In the olden days, you could blit hidden parts of windows, but not in recent versions of Windows. I am actually surprised that it works (again) in Windows 10.

Perhaps it has something to do with windows styles? (Perhaps check whether the "overlapped" style has any effect?)
juliansader is offline   Reply With Quote
Old 02-05-2020, 11:39 AM   #945
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

I must of been thinking of the PrintWindow function, that can capture windows behind other windows, my notes show I tested it in WinXP and Win7, and just now in Win10 and still works, one minor drawback is it ignores a windows opacity setting.
Edgemeal is offline   Reply With Quote
Old 02-05-2020, 01:05 PM   #946
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

(Just a thing I noticed)
AHK source code seems to be very well documented - maybe it would be a useful resource for this extension.
https://github.com/Lexikos/AutoHotke.../master/source

Last edited by spk77; 02-05-2020 at 01:27 PM.
spk77 is offline   Reply With Quote
Old 02-05-2020, 01:09 PM   #947
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 Edgemeal View Post
I must of been thinking of the PrintWindow function, that can capture windows behind other windows, my notes show I tested it in WinXP and Win7, and just now in Win10 and still works, one minor drawback is it ignores a windows opacity setting.
Would this be addable to JS-extension? This sounds like exactly what I need.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 02-05-2020, 04:15 PM   #948
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Hmm, we've tried using my demo script under MacOS but for some reason, they only write black images, so there seems to be a problem with capturing the contents of the gfx-window.

tested on Reaper 6.03, Catalina 10.15.3
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 02-08-2020, 03:26 PM   #949
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

I've update the extension to v0.999:
* JS_Window functions: On Linux and macOS, don't crash if handle is invalid.
* JS_Mouse_LoadCursorFromFile: On Windows, accept Unicode paths.
* JS_GDI_ReleaseDC: Can release screen HDCs.

Regarding the JS_Window functions:

Windows' own Win32 functions handle invalid HWNDs gracefully, but WDL/swell crashes (as I dramatically warned in the API documentation). When I first uploaded the extension, WDL/swell did not have a working IsWindow function, and reaper.ValidatePtr(hwnd, "HWND") did not yet exist, so I coded my own IsWindow function. My function work accurately, but was pretty slow, so I didn't want to run it each and every time a window-related function was called. Instead, scripts had to check IsWindow themselves, at strategic times.

REAPER's new ValidatePtr with "HWND" is quite fast -- a fraction of a microsecond -- so I think it is unlikely to affect performance, and I therefore added it to all the window-related functions on macOS and Linux. Hopefully it would prevent a few crashes and make the extension API feel more stable.
juliansader is offline   Reply With Quote
Old 02-08-2020, 03:55 PM   #950
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Quote:
Originally Posted by juliansader View Post
I've update the extension to v0.999:
Thanks for the updates!

Updated CaptureScreenArea function (API v0.999), no more leak!
Code:
function CaptureScreenArea(x,y,w,h,filename)
  scrnDC = reaper.JS_GDI_GetScreenDC() --< Only available on Windows!
  destBmp = reaper.JS_LICE_CreateBitmap(true,w,h)
  destDC = reaper.JS_LICE_GetDC(destBmp)
  reaper.JS_GDI_Blit(destDC, 0, 0, scrnDC, x, y, w, h)
  reaper.JS_LICE_WritePNG(filename, destBmp, false)
  reaper.JS_LICE_DestroyBitmap(destBmp)
  reaper.JS_GDI_ReleaseDC(scrnDC)
end
Edgemeal is offline   Reply With Quote
Old 02-09-2020, 02:44 PM   #951
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 4,171
Default

Quote:
Originally Posted by juliansader View Post
I've update the extension to v0.999:
Ooh - SetParent - thank you so much...

I'll have a play with that No idea whether it will do what I want it to do - and I may just end up breaking things - but will try a few things out. Much appreciated!
__________________
Projects - Reascripts - Lua:
Smart Knobs 2 | LBX Stripper | LBX Floating FX Positioner
Donate via Paypal | LBX Tools Website
lb0 is offline   Reply With Quote
Old 02-10-2020, 07:42 AM   #952
rstockm
Human being with feelings
 
rstockm's Avatar
 
Join Date: May 2012
Location: Berlin, Germany
Posts: 171
Default

Quote:
Originally Posted by Edgemeal View Post
Thanks for the updates!

Updated CaptureScreenArea function (API v0.999), no more leak!
Code:
function CaptureScreenArea(x,y,w,h,filename)
  scrnDC = reaper.JS_GDI_GetScreenDC() --< Only available on Windows!
  destBmp = reaper.JS_LICE_CreateBitmap(true,w,h)
  destDC = reaper.JS_LICE_GetDC(destBmp)
  reaper.JS_GDI_Blit(destDC, 0, 0, scrnDC, x, y, w, h)
  reaper.JS_LICE_WritePNG(filename, destBmp, false)
  reaper.JS_LICE_DestroyBitmap(destBmp)
  reaper.JS_GDI_ReleaseDC(scrnDC)
end
I figure this will not/never work on MacOS?
rstockm is offline   Reply With Quote
Old 02-15-2020, 02:54 PM   #953
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by rstockm View Post
I figure this will not/never work on MacOS?
On Linux and macOS, standard WDL/swell functions provided by REAPER only have access to windows created by WDL/swell itself, so unfortunately it is unlikely to ever work on the whole screen.

(Unless of course if some macOS wizard on the forums can figure out custom code to accomplish it.)
juliansader is offline   Reply With Quote
Old 02-22-2020, 04:00 AM   #954
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by mespotine View Post
Hmm, we've tried using my demo script under MacOS but for some reason, they only write black images, so there seems to be a problem with capturing the contents of the gfx-window.

tested on Reaper 6.03, Catalina 10.15.3
Is Metal enabled in your REAPER preferences? Perhaps the OSX blitting bug that I recently encountered is not limited to writing *to* Metal windows, but also reading *from* them.
juliansader is offline   Reply With Quote
Old 02-26-2020, 03:07 PM   #955
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default Use track color in JS_Lice_ functions?

Is it possible to match a track color for JS_Lice commands?
Trying to do something like,...

Code:
color = reaper.GetTrackColor(track)
bm = reaper.JS_LICE_CreateBitmap(true, w, h)
reaper.JS_Composite(window, 0, 0, w, h, bm, 0, 0, w, h)
reaper.JS_LICE_Clear(bm, color) -- ? How to match track color ?
Edgemeal is offline   Reply With Quote
Old 02-26-2020, 11:11 PM   #956
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Try:
Code:
local r, g, b = reaper.ColorFromNative(reaper.GetTrackColor(track))
color_for_LICE = 0xFF000000 | (r<<16) | (g<<8) | b
juliansader is offline   Reply With Quote
Old 02-27-2020, 07:49 AM   #957
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 juliansader View Post
Is Metal enabled in your REAPER preferences? Perhaps the OSX blitting bug that I recently encountered is not limited to writing *to* Metal windows, but also reading *from* them.
Oh, good point. Will have a try...
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 02-27-2020, 09:58 AM   #958
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Made no difference, as Metal was enabled.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 02-27-2020, 12:58 PM   #959
cohler
Banned
 
Join Date: Dec 2018
Posts: 642
Default js_ReaScriptAPI is BROKEN by Reaper 6.04

js_ReaScriptAPI appears to be broken by Reaper 6.04. Various calls have stopped working.

Anybody know anything about this?
cohler is offline   Reply With Quote
Old 02-27-2020, 01:06 PM   #960
cohler
Banned
 
Join Date: Dec 2018
Posts: 642
Default js_ReaScriptAPI broken by Reaper 6.04

Hi Julian,

Your ReaScriptAPI is FANTASTIC! But it is apparently broken by Reaper 6.04. Any idea when it can be fixed? Or when Reaper 6.04 can be fixed?
cohler 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 02:27 AM.


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