Old 05-01-2019, 10:53 AM   #441
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,757
Default

Quote:
Originally Posted by lb0 View Post
I would still *love* a way of somehow saving an image (bitmap) to disk (providing a filename - so can be completely automated).
Quote:
Originally Posted by Breeder View Post
Take a screenshot of a project (or maybe just the arrange and mixer window - alt+prtscreen type...maybe all 3...screenshot of the screen, arrange and mixer...that would enough information for later overview), save it in the project audio folder and import into media bay (so it doesn't get deleted on project cleanup)
Is transparency important for your bitmaps?

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.

Last edited by juliansader; 05-01-2019 at 11:47 AM.
juliansader is offline   Reply With Quote
Old 05-01-2019, 01:18 PM   #442
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 3,111
Default

Quote:
Originally Posted by juliansader View Post
Is transparency important for your bitmaps?

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.
Sounds great!

Transparency probably not essential. Thank you for taking the time to look into it.

JPG's should be ok too.

EDIT:

To give you a little perspective on my initial plans for a function like this - In Stripper I can save strip files - and use a strip browser to drag strips in.

The browser will show a thumbnail bitmap from the same folder the strip is located in if it exists. Currently - I have to do a traditional screen grab, crop, and manual save which is time consuming and to be honest - I tend not to bother. With a function such as this - I can create the bitmap of the full size strip (currently would be using reaper's bitmaps - hopefully these can be translated somehow into suitable one's I can use with any potential function - even if I have to first blit it onto the GUI- that would be ok). I'd scale it down to an appropriate size and save it alongside the strip.

Then voila! Pretty pictures for each strip.

I'm sure I could think of many other useful applications too.
__________________
Projects - Reascripts - Lua:
LBX Stripper | LBX Chaos Engine | LBX Floating FX Positioner | LBX SRD Smart Knobs
Donate via Paypal

Last edited by lb0; 05-01-2019 at 01:36 PM.
lb0 is offline   Reply With Quote
Old 05-02-2019, 04:36 AM   #443
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 7,929
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.
Do you mean you have tried linking with a prebuilt libpng? Cockos's WDL comes with the libpng sources to allow Lice to use png images, so it should be possible to just compile the needed source files directly with your project. (There are a lot of needed files, though, because libpng also requires at least zlib too...It would be better if the Reaper API itself had functions to save image files from Lice bitmaps etc.)
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass, Paul(X)Stretch and λ) :
http://xenakios.wordpress.com/
Xenakios is online now   Reply With Quote
Old 05-02-2019, 08:49 AM   #444
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,565
Default

Noticed just yesterday, that the JS_Window_Find-function stopped working on Mac in the 0.980-release. It can't find the Render to File-dialog(maybe others as well?)
I reverted back to 0.972 and everything worked fine again with the same code and conditions.

This might be the case with other such functions as well, but hadn't time to check them yet...
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 05-02-2019, 09:40 AM   #445
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,757
Default

I quickly checked on OSX High Sierra x64 with extension v0.985 and everything seems fine: "Render to File" and all the other windows that I tested, could be found.
juliansader is offline   Reply With Quote
Old 05-02-2019, 09:57 AM   #446
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,565
Default

Ok, I'll give it another try with the latest version.
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 05-02-2019, 12:04 PM   #447
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,757
Default

Quote:
Originally Posted by Xenakios View Post
Do you mean you have tried linking with a prebuilt libpng? Cockos's WDL comes with the libpng sources to allow Lice to use png images, so it should be possible to just compile the needed source files directly with your project.
It seems the libpng/zlib version that comes with WDL is flaky. *grumble grumble*. All I needed to do was to download the newest versions of the source code from the web, and now it works fine.

v0.986 with JS_LICE_WritePNG coming up soon.

EDIT: Uploaded to ReaPack.

Last edited by juliansader; 05-03-2019 at 07:29 AM.
juliansader is offline   Reply With Quote
Old 05-02-2019, 12:31 PM   #448
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,565
Default

Awesome
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 05-02-2019, 12:59 PM   #449
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 3,111
Default

Quote:
Originally Posted by juliansader View Post
It seems the libpng/zlib version that comes with WDL is flaky. *grumble grumble*. All I needed to do was to download the newest versions of the source code from the web, and now it works fine.

v0.986 with JS_LICE_WritePNG coming up soon.
Amazing!! - thank you so much Cannot wait!
__________________
Projects - Reascripts - Lua:
LBX Stripper | LBX Chaos Engine | LBX Floating FX Positioner | LBX SRD Smart Knobs
Donate via Paypal
lb0 is offline   Reply With Quote
Old 05-03-2019, 08:01 AM   #450
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 3,111
Default

Quote:
Originally Posted by juliansader View Post
EDIT: Uploaded to ReaPack.
Thank you! Going to try it out later.

Dumb question - How do LICE bitmaps relate to normal internal Reaper bitmaps? Is there anyway of blitting one to the other or capturing one from the other (or from a window) or simply converting one to t'other (GDI?)?

Or do I need to generate the LICE bitmap from scratch by loading in PNGs and drawing into the LICE bitmap?

Many thanks!!!

EDIT:

Looks like reaper.JS_GDI_Blit might be the best way to grab from screen to LICE bitmap.
__________________
Projects - Reascripts - Lua:
LBX Stripper | LBX Chaos Engine | LBX Floating FX Positioner | LBX SRD Smart Knobs
Donate via Paypal

Last edited by lb0; 05-03-2019 at 08:23 AM.
lb0 is offline   Reply With Quote
Old 05-05-2019, 02:53 PM   #451
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,452
Default

@julian
https://forum.cockos.com/showpost.ph...&postcount=203

Some folks cannot start the script with newest version, are there some changes to JS_VKeys_GetState() ? It returns nil on newest version (I'm still on 0.984 while developing my script, did not update yet)
Sexan is offline   Reply With Quote
Old 05-05-2019, 08:39 PM   #452
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 3,111
Default

Quote:
Originally Posted by Sexan View Post
@julian
https://forum.cockos.com/showpost.ph...&postcount=203

Some folks cannot start the script with newest version, are there some changes to JS_VKeys_GetState() ? It returns nil on newest version (I'm still on 0.984 while developing my script, did not update yet)
I gave it a test the other day and it has a new 'cutoff time' parameter - I simply put a number in the parameter field and your script started ok.

From API doc:

cutoffTime: A key is only regarded as down if it sent a KEYDOWN message after the cut-off time, not followed by KEYUP. (This is useful for excluding old KEYDOWN messages that weren't properly followed by KEYUP.)
If cutoffTime is positive, is it interpreted as absolute time in similar format as time_precise().
If cutoffTime is negative, it is relative to the current time.
__________________
Projects - Reascripts - Lua:
LBX Stripper | LBX Chaos Engine | LBX Floating FX Positioner | LBX SRD Smart Knobs
Donate via Paypal
lb0 is offline   Reply With Quote
Old 05-06-2019, 05:17 AM   #453
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,565
Default

This function among others related to vkeys are missing from the 0.986, at least from the api-docs.
Don't know, if this is intentional.
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 05-06-2019, 07:32 AM   #454
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,757
Default

I'm sorry to see that some users were inconvenienced by the changes.

As I mentioned on a previous page's changelog, the first version of the VKeys functions were completely overhauled in order to fix some problems and improve their functionality.

VKeys_ClearHistory caused interference between scripts when multiple scripts were checking the keyboard simultaneously, and VKeys_GetState were sometimes flummoxed by KEYDOWNs that were sent long ago but never followed by KEYUP.

Also, the new versions should now be first in keyboard processing queue, so will work properly in MIDI editor too. (Global shortcuts are probably still ahead, so may override scripts.)

Please note two remaining potential problems:
* On macOS, some keys (or REAPER's reinterpretation of the keys) send undocumented virtual key codes that fall outside the standard range. The VKeys function cannot yet detect or intercept these. I'm not sure which keys are affected, but the numerical keypad ENTER key is one of them.
* When two keys are held simultaneously, for example Ctrl+A, only one key seems to send repeat KEYDOWNs.
juliansader is offline   Reply With Quote
Old 05-06-2019, 07:35 AM   #455
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,565
Default

What value-ranges are they, when they are invalid? Bigger than 255?
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 05-06-2019, 07:36 AM   #456
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,757
Default

Quote:
Originally Posted by mespotine View Post
What value-ranges are they, when they are invalid? Bigger than 255?
Yes .
juliansader is offline   Reply With Quote
Old 05-06-2019, 07:41 AM   #457
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,565
Default

Could these help(the keycodes for shortcuts in reaper-kb.ini):
https://github.com/Ultraschall/ultra...per-kb_ini.ini

or these(gfx.getkey-returned keyvalues)?
https://github.com/Ultraschall/ultra..._character.ini

I doubt it, but I hope, they could be a base for getting what is happening on Mac, as some of the keycodes are above 255.


Edit: and maybe it's a good idea to add this thread to your signature as well
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 05-06-2019, 07:48 AM   #458
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,452
Default

Quote:
Originally Posted by juliansader View Post
I'm sorry to see that some users were inconvenienced by the changes.

As I mentioned on a previous page's changelog, the first version of the VKeys functions were completely overhauled in order to fix some problems and improve their functionality.

VKeys_ClearHistory caused interference between scripts when multiple scripts were checking the keyboard simultaneously, and VKeys_GetState were sometimes flummoxed by KEYDOWNs that were sent long ago but never followed by KEYUP.

Also, the new versions should now be first in keyboard processing queue, so will work properly in MIDI editor too. (Global shortcuts are probably still ahead, so may override scripts.)

Please note two remaining potential problems:
* On macOS, some keys (or REAPER's reinterpretation of the keys) send undocumented virtual key codes that fall outside the standard range. The VKeys function cannot yet detect or intercept these. I'm not sure which keys are affected, but the numerical keypad ENTER key is one of them.
* When two keys are held simultaneously, for example Ctrl+A, only one key seems to send repeat KEYDOWNs.
No no its not a problem at all, I was just wondering since I've did not update my JS_API (thought maybe there was some error with new version)

BTW can the function grab which key was pressed or I need to make a whole ascii table (which I've partially already done)?

Last edited by Sexan; 05-06-2019 at 07:56 AM.
Sexan is offline   Reply With Quote
Old 05-06-2019, 07:59 AM   #459
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,757
Default

Quote:
Originally Posted by Sexan View Post
BTW can the function grab which key was pressed or I need to make a whole ascii table (which I've partially already done)?
Could you explain a bit more? (By "which key was pressed", do you mean something else than the array returned by the functions?)
juliansader is offline   Reply With Quote
Old 05-06-2019, 08:17 AM   #460
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,452
Default

uh sorry... ATM you need to set some "keys" or table with keys and then check if any of them was returned by function. Is that still the true with new VK_Key implementation?

I've made almost all the ASCII tbl and then check them with VK

Basically this (but with whole table)
Code:
local vk = {
            {code = 0x1B, name = 'ESC', press = false, hold = false, release = true},
            {code = 0x31, name = 'copy', press = false, hold = false, release = true},
            {code = 0x32, name = 'paste', press = false, hold = false, release = true},
            {code = 0x33, name = 'del', press = false, hold = false, release = true}
            }
function keys(tr, pos) 
  local OK, state = reaper.JS_VKeys_GetState()
  for i = 1, #vk do
    if state:byte(vk[i].code) ~= 0 then
Btw I've made my own hold,press,release state thats why that its there .
Maybe I'm going insane from coding so I don't know what I'm typing

And while you are here, how do you do intercepting with VK ? Same as before (JS_WindowMessage_Intercept)?

Last edited by Sexan; 05-06-2019 at 08:27 AM.
Sexan is offline   Reply With Quote
Old 05-06-2019, 09:09 AM   #461
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,565
Default

How can I get the child-id a childhwnd has? I tried to bruteforce them using by doing FindChildById, but this doesn't return all of them. The Flac-outputformat in the Render to File-dialog is missing one of the text-captions using FindChildByID, but returns valid hwnd for all when using the FromPoint-function.
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 05-06-2019, 09:45 AM   #462
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 1,386
Default

Quote:
Originally Posted by mespotine View Post
How can I get the child-id a childhwnd has?
try,...
Code:
id = reaper.JS_Window_GetLongPtr(hwnd, "ID")
Edgemeal is offline   Reply With Quote
Old 05-06-2019, 09:47 AM   #463
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,565
Default

Thnx Edgemeal
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 05-07-2019, 04:37 AM   #464
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,452
Default

I cannot make this work
Code:
view = reaper.JS_Window_FromPoint(reaper.GetMousePosition())
  
  peekOK, _, time, keys, _, x, y = reaper.JS_WindowMessage_Peek(view, "WM_LBUTTONDOWN")
  if peekOK and time ~= prevTime then
      L_press = true
      -- Left button has been pressed
  end
nothing is happening, am I doing something wrong or there were some changes?

Also is there any way to make this little cpu friendly?
Code:
 local retval, found = reaper.JS_Window_ListAllChild(main_wnd)
    for adr in found:gmatch("%w+") do
      local handl = reaper.JS_Window_HandleFromAddress(tonumber(adr))
      for i = 1 ,#tbl do
        if reaper.JS_Window_GetLongPtr(handl, "USER") == tbl[i].track then
          _, _, top, _, bottom = reaper.JS_Window_GetRect(handl)
        end
      end
Not really sure which one in there is a little cpu hungrier

Last edited by Sexan; 05-07-2019 at 05:12 AM.
Sexan is offline   Reply With Quote
Old 05-07-2019, 07:04 AM   #465
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,757
Default

Quote:
Originally Posted by Sexan View Post
I cannot make this work
nothing is happening, am I doing something wrong or there were some changes?
Unlike the VKeys functions, which are constantly updating keystrokes in the background, the WindowMessage functions must first be activated for a specific window. So before you can start Peeking, you must first run reaper.JS_WindowMessage_Intercept(view, "WM_LBUTTONDOWN", true/false), and when the script exists, release the intercept.


Quote:
Originally Posted by Sexan View Post
Also is there any way to make this little cpu friendly?
I will take a look at it.
juliansader is offline   Reply With Quote
Old 05-07-2019, 07:07 AM   #466
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,452
Default

Quote:
Originally Posted by juliansader View Post
Unlike the VKeys functions, which are constantly updating keystrokes in the background, the WindowMessage functions must first be activated for a specific window. So before you can start Peeking, you must first run reaper.JS_WindowMessage_Intercept(view, "WM_LBUTTONDOWN", true), and when the script exists, release the intercept.




I will take a look at it.
Oh yeah, I've forgot... Thank you! Is the same principle with intercepting VKeys? Just instead of WM_ I add VK code? (For WM I need to access mousewheel since I cannot get it from JS_Mouse_GetState,I have some nifty ideas, but everything else will go thru VK)
Sexan is offline   Reply With Quote
Old 05-07-2019, 07:50 AM   #467
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,811
Default

Guys, is there a way to send a mouse click without actually focusing the clicked window?
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is online now   Reply With Quote
Old 05-07-2019, 11:22 AM   #468
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,757
Default

Quote:
Originally Posted by Sexan View Post
Code:
 local retval, found = reaper.JS_Window_ListAllChild(main_wnd)
    for adr in found:gmatch("%w+") do
      local handl = reaper.JS_Window_HandleFromAddress(tonumber(adr))
      for i = 1 ,#tbl do
        if reaper.JS_Window_GetLongPtr(handl, "USER") == tbl[i].track then
          _, _, top, _, bottom = reaper.JS_Window_GetRect(handl)
        end
      end
Not really sure which one in there is a little cpu hungrier
This can indeed be made much faster.

* Firstly, take the GetLongPtr out of the loop. In my 100-track test project, this by itself improved speed from 0.025s to 0.003s:
Code:
      local handl = reaper.JS_Window_HandleFromAddress(tonumber(adr))
      local track = reaper.JS_Window_GetLongPtr(handl, "USER")
      for i = 1 ,#tbl do
        if tbl[i].track == track then
          _, _, top, _, bottom = reaper.JS_Window_GetRect(handl)
        end
      end
* Would it be possible to use the track pointer itself as the key in tbl, so that you don't have to iterate through every track? (Or keep a separate table that maps track pointers to their numbers.) This will improve speed from 0.003s to 0.0015s (the larger the project, the greater the improvement should be):
Code:
for adr in found:gmatch("%w+") do
    local handl = reaper.JS_Window_HandleFromAddress(tonumber(adr))
    local track = reaper.JS_Window_GetLongPtr(handl, "USER")
    if tbl[track] then
        local _, _, top, _, bottom = reaper.JS_Window_GetClientRect(handl)
        tbl[track].top, tbl[track].bottom = top, bottom
    end
end
* Arrays are faster than string lists, and the values inside an array can be directly accessed via JS_Int and JS_Double, or the array can be converted to a table. This will improve speed further to 0.001s:
Code:
a = reaper.new_array({}, 1000) -- or clear an existing array
reaper.JS_Window_ArrayAllChild(reaper.GetMainHwnd(), a)
local t = a.table()
for i, adr in ipairs(t) do
    local handl = reaper.JS_Window_HandleFromAddress(adr)
    local track = reaper.JS_Window_GetLongPtr(handl, "USER")
    if tbl[track] then
        local _, _, top, _, bottom = reaper.JS_Window_GetClientRect(handl)
        tbl[track].top, tbl[track].bottom = top, bottom
    end
end
Altogether, a 25x improvement!

EDIT: Corrected some copy/paste errors in the code.

Last edited by juliansader; 05-07-2019 at 03:37 PM.
juliansader is offline   Reply With Quote
Old 05-07-2019, 11:27 AM   #469
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,757
Default

Quote:
Originally Posted by Sexan View Post
And while you are here, how do you do intercepting with VK ? Same as before (JS_WindowMessage_Intercept)?
No, VKeys_Intercept works quite differently than WindowMessage_Intercept. From the API help:
Quote:
int reaper.JS_VKeys_Intercept(int keyCode, int intercept)

Intercepting (blocking) virtual keys work similar to the native function PreventUIRefresh: Each key has a (non-negative) intercept state, and the key is passed through as usual if the state equals 0, or blocked if the state is greater than 0.

keyCode: The virtual key code of the key, or -1 to change the state of all keys.

intercept: A script can increase the intercept state by passing +1, or lower the state by passing -1. Multiple scripts can block the same key, and the intercept state may reach up to 255. If zero is passed, the intercept state is not changed, but the current state is returned.

Returns: If keyCode refers to a single key, the intercept state of that key is returned. If keyCode = -1, the state of the key that is most strongly blocked (highest intercept state) is returned.
juliansader is offline   Reply With Quote
Old 05-07-2019, 02:45 PM   #470
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,452
Default

Wow, looks like I will be refactoring some stuff. Thank you
Sexan is offline   Reply With Quote
Old 05-07-2019, 07:20 PM   #471
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,757
Default

Another idea: If you keep a record of window addresses that are *not* track panes in another table tNotTracks[], you don't need to get their handles and userdata again. This brings speed down to below 0.6ms!
Code:
a = reaper.new_array({}, 1000) -- or clear an existing array
reaper.JS_Window_ArrayAllChild(reaper.GetMainHwnd(), a)
local t = a.table()
for i = 1, #t do
    local adr = t[i]
    if not tNotTracks[adr] then
        local handl = reaper.JS_Window_HandleFromAddress(adr)
        local user = reaper.JS_Window_GetLongPtr(handl, "USER")
        if tbl[user] then
            local _, _, top, _, bottom = reaper.JS_Window_GetClientRect(handl)
            tbl[user].top, tbl[user].bottom = top, bottom
        else
            tNotTracks[adr] = true
        end
    end
end
juliansader is offline   Reply With Quote
Old 05-08-2019, 04:31 AM   #472
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,452
Default

I still have few problematic functions that I need to figure out how to fix before modifying code. For now I've just made a simple mod ("GetLongPtr out of the loop") to "get_track_y_range" function but something hits cpu extremely hard as soon there are some envelope tracks there (while mouse is down or updating project x-y):
- AS over 50 tracks CPU 0.1%


- AS over 50 tracks one of them all envelope visible (default ones) CPU 6-7%


- This it the same even if there a 1 tracks and has envelopes so the track count does not matter



Since the current way I am getting the range of tracks "GetTrackFromRange(y_t, y_b)" is not the best (its in constant loop while mouse is down), but its the only way that I can efficiently get both track and envelope tracks. There is probably much simpler way to write that function but its not yet came to my mind. It would be much simpler if reaper.GetTrackFromPoint returns envelopes also but it only returns optional number 1 if envelope is under mouse

https://github.com/GoranKovac/ReaScr...ree/master/WIP
I would really appreciate if you can check it, if and when you have time




EDIT: Fixed the issue.... was my bad in other script

Last edited by Sexan; 05-09-2019 at 03:58 AM.
Sexan is offline   Reply With Quote
Old 05-08-2019, 06:23 AM   #473
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 1,386
Default

Quote:
Originally Posted by _Stevie_ View Post
Guys, is there a way to send a mouse click without actually focusing the clicked window?
How are you sending a mouse click now?

I've used this in a few scripts (in Windows) and the target window (or parent) doesn't steal the focus,..
Code:
function Post_LMouseDownUp(hwnd, x, y) -- x,y = location to click inside the window
  reaper.JS_WindowMessage_Post(hwnd, "WM_LBUTTONDOWN", 1, 0, x, y)
  reaper.JS_WindowMessage_Post(hwnd, "WM_LBUTTONUP", 0, 0, x, y)
end
If 'JS_WindowMessage_Post' doesn't work on a target window try 'JS_WindowMessage_Send' instead (Send waits for a return, Post doesn't).

If the target window does steal focus then it was probably coded that way, you could save the foreground/active window handles, click the mouse then restore the original foreground window.
Edgemeal is offline   Reply With Quote
Old 05-08-2019, 07:15 AM   #474
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,452
Default

Quote:
Originally Posted by juliansader View Post
Code:
a = reaper.new_array({}, 1000) -- or clear an existing array
reaper.JS_Window_ArrayAllChild(reaper.GetMainHwnd(), a)
local t = a.table()
for i, adr in ipairs(t) do
    local handl = reaper.JS_Window_HandleFromAddress(adr)
    local track = reaper.JS_Window_GetLongPtr(handl, "USER")
    if tbl[track] then
        local _, _, top, _, bottom = reaper.JS_Window_GetClientRect(handl)
        tbl[track].top, tbl[track].bottom = top, bottom
    end
end
This is incredibly fast, the only problem is track (user data) cannot be set as key so it needs guid and then we have ANOTHER problem is envelopes do not have guid...

EDIT: tostring(track)

Last edited by Sexan; 05-08-2019 at 07:28 AM.
Sexan is offline   Reply With Quote
Old 05-08-2019, 07:56 AM   #475
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,565
Default

Quote:
Originally Posted by juliansader View Post
Altogether, a 25x improvement!
I learn so much from you guys...
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 05-08-2019, 09:04 AM   #476
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,811
Default

Quote:
Originally Posted by Edgemeal View Post
How are you sending a mouse click now?
This is actually for a touchscreen. I'm using LBX Stripper on a touchscreen. The buttons I press execute a MIDI command, which will trigger an action in foobar2000 (via an AHK script).

So:
-> pressing a button in LBX Stripper sends MIDI data
-> AHK script converts MIDI message to "paste text" in foobar2000
-> foobar2000 loses focus because touchscreen was used
-> foobar2000 gets focus back because AHK is telling to do so
= result is a constant flickering when executing that action

Could a click on the touchscreen be re-interpreted by LUA to execute a click without changing the focus?
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is online now   Reply With Quote
Old 05-08-2019, 09:24 AM   #477
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,452
Default

Julian I've implemented your new method with array and its so fast it's disgusting...
Before drawing "shadows" of 25+ items would hit cpu pretty bad and stuff starts stuttering, now selected more than 100 items across 50 tracks barely gets 3%. Silky smooth and there is more room to improve it since my item "shadow" code is bad

I've updated the code on git (WIP folder)

Thank you very much!

Last edited by Sexan; 05-08-2019 at 09:41 AM.
Sexan is offline   Reply With Quote
Old 05-08-2019, 10:57 AM   #478
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,057
Default

Quote:
Originally Posted by Sexan View Post
its so fast it's disgusting...
Lol.
nofish is offline   Reply With Quote
Old 05-08-2019, 11:27 AM   #479
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,452
Default

haha

Julian I have another idea and dont know if possible:
instead of blitting for every item which is not fun,is it possible to create one big image with every item ? create little images and compose them to one?

also how can I blit only part of the screen (I want to make item shadows to item images)? I have the code already for item (screen) coordinates

Last edited by Sexan; 05-08-2019 at 11:32 AM.
Sexan is offline   Reply With Quote
Old 05-08-2019, 01:20 PM   #480
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,452
Default

Quote:
Originally Posted by Sexan View Post
- AS over 50 tracks CPU 0.1%

- AS over 50 tracks one of them all envelope visible (default ones) CPU 6-7%

- This it the same even if there a 1 tracks and has envelopes so the track count does not matter

https://github.com/GoranKovac/ReaScr...ree/master/WIP
Improved code and reduced cpu usage to minimum (added checking), but still envelopes spike the CPU while selected

EDIT: Found the issue! lol, the other script had an error... don't know why it was there anyway... reaper.UpdateTimeline(). Now everything silky smooth

Last edited by Sexan; 05-09-2019 at 03:55 AM.
Sexan 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 10:50 AM.


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