Old 04-16-2020, 03:37 PM   #1081
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by Thonex View Post
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.
The recent versions of ReaPack includes the ReaTeam repository for extensions by default, so it shouldn't be necessary to import anything. Can you find the extension in ReaPack's browser, and which versions does ReaPack offer there?
juliansader is offline   Reply With Quote
Old 04-16-2020, 04:02 PM   #1082
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Quote:
Originally Posted by juliansader View Post
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.
They have to run 1.000 or later because the script won't let them run it otherwise.
Code:
-- Check if JS_ReaScriptAPI >1.000 is installed
if not reaper.APIExists("JS_ReaScriptAPI_Version") then
  local answer = reaper.MB( "You have to install JS_ReaScriptAPI for this script to work. Would you like to open the relative web page in your browser?", "JS_ReaScriptAPI not installed", 4 )
  if answer == 6 then
    local url = "https://forum.cockos.com/showthread.php?t=212174"
     reaper.CF_ShellExecute( url )
  end
  return reaper.defer(function() end)
else
  local version = reaper.JS_ReaScriptAPI_Version()
  if version < 1 then
    reaper.MB( "Your JS_ReaScriptAPI version is " .. version .. "\nPlease update to version 1.000 or higher.", "Older version is installed", 0 )
    return reaper.defer(function() end)
  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 04-16-2020, 04:38 PM   #1083
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Quote:
Originally Posted by juliansader View Post
The recent versions of ReaPack includes the ReaTeam repository for extensions by default, so it shouldn't be necessary to import anything. Can you find the extension in ReaPack's browser, and which versions does ReaPack offer there?
If I'm understanding you correctly, its v1.2.2 by cfillion – February 24 2019

Cheers,

Andrew K
__________________
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-16-2020, 05:28 PM   #1084
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by amagalma View Post
They have to run 1.000 or later because the script won't let them run it otherwise.
Are you referring to the "Toggle show editing guide" script, or to the short redcross script that you posted in this thread? (Is neither of them working on some users' OSX?)

Last edited by juliansader; 04-16-2020 at 05:37 PM.
juliansader is offline   Reply With Quote
Old 04-16-2020, 05:35 PM   #1085
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by Thonex View Post
If I'm understanding you correctly, its v1.2.2 by cfillion – February 24 2019
I was actually referring to the ReaScriptAPI extension:
* In v1.2.2 of ReaPack, the "ReaTeam Extensions" repository is included and activated by default -- please check under Extensions -> ReaPack -> Manage repositories... if it is activated.
* If it is active, you should be able to see the package "js_ReaScriptAPI: API functions for ReaScripts" in the ReaPack browser, with available versions all the way from 0.94 to 1.001. Is this not what you are seeing?
juliansader is offline   Reply With Quote
Old 04-16-2020, 10:04 PM   #1086
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Quote:
Originally Posted by juliansader View Post
Are you referring to the "Toggle show editing guide" script, or to the short redcross script that you posted in this thread? (Is neither of them working on some users' OSX?)
I am referring to both. The "redcross" script is just a simple test script created to make sure that I hadn't messed up something else in the "toggle show guide lines" script which is a lot more elaborate. For some OSX users, neither works.

EDIT. The redcross script is missing the version check, so I can't be sure which version are they running it on.. I'll add it to be sure.
__________________
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-17-2020 at 02:30 AM.
amagalma is offline   Reply With Quote
Old 04-17-2020, 02:06 AM   #1087
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Quote:
Originally Posted by juliansader View Post
I was actually referring to the ReaScriptAPI extension:
* In v1.2.2 of ReaPack, the "ReaTeam Extensions" repository is included and activated by default -- please check under Extensions -> ReaPack -> Manage repositories... if it is activated.
* If it is active, you should be able to see the package "js_ReaScriptAPI: API functions for ReaScripts" in the ReaPack browser, with available versions all the way from 0.94 to 1.001. Is this not what you are seeing?
Thanks for the clarification Julian.

Yes... I see the "ReaTeam Extensions" is activated and "js_ReaScriptAPI: API functions for ReaScripts" version 1.001 but no other prior versions. Not sure if that makes a difference.

Cheers,

Andrew K
__________________
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-17-2020, 02:38 AM   #1088
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Quote:
Originally Posted by amagalma View Post
I am referring to both. The "redcross" script is just a simple test script created to make sure that I hadn't messed up something else in the "toggle show guide lines" script which is a lot more elaborate. For some OSX users, neither works.

EDIT. The redcross script is missing the version check, so I can't be sure which version are they running it on.. I'll add it to be sure.

Updated JS_Composite test here. Could guys on OSX try it and tell me if they see a red cross appearing in the arrange view? 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-17-2020, 09:04 PM   #1089
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

Works here (tried on 10.10, 10.15 VM w/ metal on and 10.15 VM w/ metal off).
cfillion is offline   Reply With Quote
Old 04-18-2020, 02:55 AM   #1090
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Quote:
Originally Posted by cfillion View Post
Works here (tried on 10.10, 10.15 VM w/ metal on and 10.15 VM w/ metal off).

Thank you very much! If you have time, could you try this one too and tell me if a small red cross follows the mouse cursor inside the arrange view. 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-18-2020, 03:35 AM   #1091
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

That one works too.
cfillion is offline   Reply With Quote
Old 04-18-2020, 04:23 AM   #1092
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Quote:
Originally Posted by cfillion View Post
That one works too.

Thanks! Then I have no idea why it doesn't work on some OSX systems!
__________________
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-18-2020, 04:35 AM   #1093
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Several questions regarding the new JS_Composite_Delay:
1) )Does it need to be used every time when a reaper.JS_Composite is called? Or can be set once in the script for the window in question?
2) And if called every time, should it be called before or after the reaper.JS_Composite function?
3) What would be the optimal settings for when the bitmap is hidden? As slow as possible?
Code:
reaper.JS_Composite(trackview, 0, 0, 0, 0, bm, 0, 0, 1, 1, true)
4) What will happen if two or more scripts are running drawing bitmaps on the same window and each one sets a different value for JS_Composite_Delay?

Thanks!
__________________
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-18-2020 at 04:42 AM.
amagalma is offline   Reply With Quote
Old 04-18-2020, 09:27 AM   #1094
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,599
Default

It can be called once per script (as I've tested), but it will also slow down reaper render update.
If the bitmap is hidden there is no need to compose, you should have a check when composite is called.

Your script moves line with mouse cursor ?

Code:
function check_mouse()
  if mouse_x ~= last_m_x then
    last_m_x = mouse_x
    return true
  end
end

DRAW = check_mouse()
HIDDEN = some_variable true or false <-- pseudo code

if DRAW then <-- will pass only when mouse change
 if not HIDDEN then <-- will pass only if hidden is false
   COMPOSITE
 end
end
This will call composite only when you move your mouse and hidden flag is false (it needs to update the line). In your case there is no need to use delay since you are drawing very simple line, not cpu intensive

BTW for your OSX issue

Code:
local main_wnd = reaper.GetMainHwnd() -- GET MAIN WINDOW
local track_window = reaper.JS_Window_FindChildByID(main_wnd, 0x3E8) <-- GET TRACK VIEW 0x3E8 instead of 1000
Code 1000 is not cross platform friendly for trackview, use
Code:
0x3E8
Also convert your mouse to client for drawing

Code:
function To_client(x,y)
   local cx, cy = reaper.JS_Window_ScreenToClient( track_window, x, y )
   return cx, cy
end

function draw()
local cx, cy = To_client(mouse.x, mouse.y)
reaper.JS_Composite(track_window, cx, cy, w, h, bm, 0, 0, w, h, true)
And you are cross platform ready and hopefully OSX issue is resolved!

EDIT: Checked your code, you can draw the cross with only one bitmap then use LICE_RECT two times to draw cross inside of it

Last edited by Sexan; 04-18-2020 at 09:56 AM.
Sexan is offline   Reply With Quote
Old 04-18-2020, 05:27 PM   #1095
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

I have uploaded v1.002:
* Linux and macOS: JS_Window_GetForeground returns top-level window.
* Linux and macOS: Various tweaks in JS_Composite to reduce glitching.
* WindowsOS: New JS_Composite_Delay function to reduce flickering.
* JS_Composite: Auto-update now optional parameter.

Area(51) is very useful as a stress test for JS_Composite. On my systems, it now works smoothly on Windows, Linux and macOS with up to hundreds of ghosts.


Quote:
Originally Posted by amagalma View Post
3) What would be the optimal settings for when the bitmap is hidden? As slow as possible?
Code:
reaper.JS_Composite(trackview, 0, 0, 0, 0, bm, 0, 0, 1, 1, true)
I don't actually know what the optimal setting are, since they may depend on bitmap size, bitmap transparency, CPU speeds, GPU speed and screen refresh rate. (If anyone is interested in testing the settings, please let me know what your results are.)

When the bitmaps are visible, for example Area(51) on my Windows computers, minTime=0.05 maxTime=0.15 bitmaps=100 seem to work well.

If the bitmap is hidden, no blitting will take place, so I don't think you need any delay.


Quote:
Originally Posted by amagalma View Post
4) What will happen if two or more scripts are running drawing bitmaps on the same window and each one sets a different value for JS_Composite_Delay
The most recent setting will be applied. The function returns the previous values, so that a script can reset the setting to the previous values, if necessary.
juliansader is offline   Reply With Quote
Old 04-19-2020, 05:02 AM   #1096
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Thanks to both for your responses!


@Sexan: the script is "Script: amagalma_Toggle show editing guide line on item under mouse cursor in Main Window or in MIDI Editor.lua" in ReaPack, the red-cross one was just a test. I changed the integers to hex as you suggested. I was already using a similar code for drawing or hiding the line. (yes, my script draws just one line )


@Julian: What are Reaper's default values? How can we set them back when script ends, as if we never messed with them?
__________________
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-20-2020, 01:13 AM   #1097
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,599
Default

Julian can this be written to be little efficient ?

Code:
elm.press         = function()  local start = true
                                 for i = 1, #elm.ID do
                                    if reaper.JS_VKeys_GetState(startTime-2):byte(elm.ID[i]) == 0 then start = false break -- WAIT FOR MULTIKEY PRESS IF COMBINATION IS DEFINED
                                    end
                                 end
                                 return start
                                 end

function Element:GetKey()
   local KEY_DOWN = self.press() <---- THIS CALL TAKES LITTLE CPU
   self.mod = modifier_name(reaper.JS_Mouse_GetState(95))

   if KEY_DOWN then
      if self.last_key_up == true and self.last_key_down == false then
         self:onKeyDown(KEY_DOWN)
      elseif self.last_key_up == false and self.last_key_down == true then
         if os.clock() - self.down_time > 0.15 then
            self:onKeyHold()
         end
      end
   elseif not KEY_DOWN and self.last_key_up == false and self.last_key_down == true then
      self:OnKeyUp(KEY_DOWN)
   end
end
I want to reduce the cpu usage a little if possible. Basically the "elm.press" function iterates thru all defined keys and checks if the right combination is pressed.

Last edited by Sexan; 04-20-2020 at 02:37 AM.
Sexan is offline   Reply With Quote
Old 04-20-2020, 12:04 PM   #1098
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by amagalma View Post
@Julian: What are Reaper's default values? How can we set them back when script ends, as if we never messed with them?
Default is no delay, so minTime = maxTime = 0 (and bitmaps is anything > 1).

(Whatever the delay times are, they are only applied if one or more bitmaps are composited onto that window.)
juliansader is offline   Reply With Quote
Old 04-20-2020, 12:13 PM   #1099
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by Sexan View Post
Julian can this be written to be little efficient ?
I would suggest that you call JS_VKeys_GetState and JS_Mouse_GetState only once per defer cycle, and store the results in a string and a number that all functions can access. All the elmress and :GetKey functions can read from the same stored string and number. This should be much faster than calling them every time that you check a key. So elm.press would be:
Code:
for i = 1, #elm.ID do
    if keyState:byte(elm.ID[i]) == 0 then start = false break -- WAIT FOR MULTIKEY PRESS IF COMBINATION IS DEFINED
    end
end
and Element:GetKey would contain:
Code:
function Element:GetKey()
   local KEY_DOWN = self.press() <---- THIS CALL TAKES LITTLE CPU
   self.mod = modifier_name(mouseState&95)
juliansader is offline   Reply With Quote
Old 04-20-2020, 03:32 PM   #1100
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Quote:
Originally Posted by amagalma View Post
Thanks! Then I have no idea why it doesn't work on some OSX systems!

Originally Posted by amagalma
Could the guys on OSX to whom the script is not working, try this script and tell me if they see a red cross appearing in the arrange view? Thanks!




Any ideas why the JS_Composite function doesn't work on some OSX systems? What could they try?
__________________
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-20-2020, 03:55 PM   #1101
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,599
Default

When I try your script, I need to click in arrange in order to see the cross (I'm on WIN)

EDIT: you are missing 11th parameter TRUE for auto refresh, you need manual refresh (JS_Invalidate) without it

Code:
reaper.JS_Composite(trackview, floor(w/2-40), 0, 80, h, bm_vert, 0, 0, 1, 1, true) <--
reaper.JS_Composite(trackview, floor(w/2-h/2), floor(h/2-40), h, 80, bm_hor, 0, 0, 1, 1,true) <--
Sexan is offline   Reply With Quote
Old 04-20-2020, 04:15 PM   #1102
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Quote:
Originally Posted by Sexan View Post
When I try your script, I need to click in arrange in order to see the cross (I'm on WIN)

EDIT: you are missing 11th parameter TRUE for auto refresh, you need manual refresh (JS_Invalidate) without it

Code:
reaper.JS_Composite(trackview, floor(w/2-40), 0, 80, h, bm_vert, 0, 0, 1, 1, true) <--
reaper.JS_Composite(trackview, floor(w/2-h/2), floor(h/2-40), h, 80, bm_hor, 0, 0, 1, 1,true) <--
You are referring to the script in the link or to the toggle guide line script?

The script in the link was for version 1.000 .. hm, but maybe he is trying it with 1.002..
__________________
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-20-2020, 04:47 PM   #1103
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,599
Default

Yeah in the link, well the best is to be on latest, its much better regarding refreshing
Sexan is offline   Reply With Quote
Old 04-20-2020, 10:56 PM   #1104
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Quote:
Originally Posted by Sexan View Post
When I try your script, I need to click in arrange in order to see the cross (I'm on WIN)
It doesn't happen here (win10 x64). Any idea why it happens on your system? How could I make sure that it doesn't happen in any system?
__________________
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-20-2020, 11:03 PM   #1105
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,599
Default

Set 11th parameter as true, you did not set it
Sexan is offline   Reply With Quote
Old 04-21-2020, 02:52 AM   #1106
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Now the OSX test scripts are up to date.


JS_Composite test.lua
ScreenToClient.lua
__________________
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-21-2020, 03:25 AM   #1107
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,599
Default

Quote:
Originally Posted by juliansader View Post
I would suggest that you call JS_VKeys_GetState and JS_Mouse_GetState only once per defer cycle, and store the results in a string and a number that all functions can access. All the elmress and :GetKey functions can read from the same stored string and number. This should be much faster than calling them every time that you check a key.
Not working as expected, keys get "stuck" and not detected especially combo keys (I think that was the reason I've made the way it is ATM). You need to release all the keys and then press the combination again.

For example with this mod you cannot hold CTRL and spam V to copy paste, you need to release CTRL every now and then.

As you see it stops detecting at some point (Im holding ctrl and spam "v")


Code:
function Track_keys()
  local prevCycleTime = thisCycleTime or startTime
  thisCycleTime = reaper.time_precise()
  key_state = reaper.JS_VKeys_GetState(prevCycleTime-2) <-- call once per cycle

  key = {}

  for i = 1, #Key_TB do Key_TB[i]:GetKey() end

  if key.DOWN then exec_func(key.DOWN) end
end

elm.press         = function()  local start = true
                                 for i = 1, #elm.ID do
                                    if key_state:byte(elm.ID[i]) == 0 then start = false break end-- BREAK IF NOT BOTH KEYS ARE PRESSED
                                 end
                                 return start
                                 end

Last edited by Sexan; 04-21-2020 at 03:33 AM.
Sexan is offline   Reply With Quote
Old 04-21-2020, 05:22 AM   #1108
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

I notice a difference between this code and the previous versions: in this code, you use JS_VKeys_GetState(current cycle time - 2), whereas the previous versions, you used JS_VKeys_GetState(script start time - 2).

The new code excludes keys that were first pressed more than 2 seconds ago and are still being held down, such as the Ctrl key in the gif. After two seconds, the scripts will "forget" the Ctrl key.


(BTW, if the script is doing lots of heavy calculations and the defer cycles become slow, it may become possible for a user to click and release a key so quickly that the entire keystroke is completed in-between cycles, so GetState won't detect it. To catch these cases, GetDown may be useful.)
juliansader is offline   Reply With Quote
Old 04-21-2020, 05:40 AM   #1109
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,599
Default

Oh yeah my bad, working fine now thank you. There are no heavy calculations, the script is in IDLE state most of the time when user hits the keys, only after that heavy calculations start (copying 1000 items).

Last edited by Sexan; 04-21-2020 at 05:47 AM.
Sexan is offline   Reply With Quote
Old 04-21-2020, 05:55 AM   #1110
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,599
Default

Sorry for off topic (not JS related) but one more question if its possible to optimize.

My midi drawing is pretty cpu intensive since it needs to iterate thru every note. Can that be improved by using reaper.array() ?

Code:
-- GET MIDI NOTE DATA
function Get_MIDI_notes(item, item_start, item_len)
    local take = reaper.GetActiveTake(item)
    --if not take then return end
    local item_end = item_start + item_len
    local t = {}
    local ret, notecnt = reaper.MIDI_CountEvts(take)
    for i=1, notecnt do
        local retval, selected, muted, startppqpos, endppqpos, chan, pitch, vel = reaper.MIDI_GetNote(take, i-1)
        local startppqpos_to_proj_time = reaper.MIDI_GetProjTimeFromPPQPos(take, startppqpos)
        if startppqpos_to_proj_time < item_start then
            startppqpos_to_proj_time = item_start
        elseif startppqpos_to_proj_time > item_end then
            break
        end
        local endppqpos_to_proj_time = reaper.MIDI_GetProjTimeFromPPQPos(take, endppqpos)
        if endppqpos_to_proj_time > item_end then
            endppqpos_to_proj_time = item_end
        end
        t[#t+1] = startppqpos_to_proj_time
        t[#t+1] = endppqpos_to_proj_time
        t[#t+1] = pitch
    end
    return t
end

-- DRAW MIDI NOTES TO GHOST IMAGE
function Draw_midi(peaks,bm, pos, len, w, h)
	local note_h = Round((h/128)+5)
	local min,max = Min_max(peaks) -- MINIMAL AND MAXIMUIM PITCH IN PEAKS 
	if note_h < 1 then note_h = 1 end
	for i=1, #peaks, 3 do
		local startppq, endppq, pitch = peaks[i], peaks[i+1], peaks[i+2]
		startppq = Round((startppq - pos) / len * w)
		endppq = Round((endppq - pos) / len * w)
		local note_w = Round(endppq - startppq)
		if note_w < 1 then note_w = 1 end
		local y = (min == max) and h/2 or TranslateRange(pitch, max, min, 10, h-20)
		reaper.JS_LICE_FillRect( bm, startppq, Round(y), note_w, note_h, 0xFF00FFFF, 0.5, "COPY" )
	end
end

Last edited by Sexan; 04-21-2020 at 06:12 AM.
Sexan is offline   Reply With Quote
Old 04-21-2020, 01:39 PM   #1111
Triode
Human being with feelings
 
Triode's Avatar
 
Join Date: Jan 2012
Posts: 1,180
Default Turning Full screen off

Hi Julian
When Reaper's video window is displayed it can be in full screen mode. When opened not in this mode, in reaper on mac there is an options menu (on the top bar) that says "Full screen" to switch to it. Can this be accessed by your API in a script to make sure this is turned off when opening?
Many thanks!
__________________
Mixing / Brush and Beater Drums Online: www.outoftheboxsounds.com
Triode is online now   Reply With Quote
Old 04-21-2020, 03:25 PM   #1112
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Quote:
Originally Posted by amagalma View Post
Now the OSX test scripts are up to date.

JS_Composite test.lua
ScreenToClient.lua

Coming back to this. Guy on OSX10.14.6. Both test scripts don't do anything on his system. Latest Reaper, latest JS_ReaScriptAPI. What could he try?
__________________
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-21-2020, 07:20 PM   #1113
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

@juliansader
After having seen amagalma's brilliant theme-tweaker-script, which makes use of an external unzip-tool to work with zipped themes, could you add a way to zip/unzip files from your extension directly?
This would allow some cool things, like creation/extraction of zipped themes, exported configuration-files, working with themeimages from zipped-themes for gui-related stuff by extracing the images directly from the file without having to rely on external zip-tools on older Windows-versions.
__________________
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 04-22-2020, 02:49 AM   #1114
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
@juliansader
After having seen amagalma's brilliant theme-tweaker-script, which makes use of an external unzip-tool to work with zipped themes, could you add a way to zip/unzip files from your extension directly?
This would allow some cool things, like creation/extraction of zipped themes, exported configuration-files, working with themeimages from zipped-themes for gui-related stuff by extracing the images directly from the file without having to rely on external zip-tools on older Windows-versions.

cfillion helped me (well, he did 90% of it ) to make a function for unzipping using PowerShell NET 4.5 methods. It worked super but I abandoned it for two reasons. 1) There is no NET 4.5 on Windows XP, 2) in order to use the script you need lua io.popen which doesn't work on Reaper x86. OSX has unzip built-in, and Linux may have it too. So, out of the box, as we are now, without an external tool, there is:
- full unzip support for OSX
- Windows 7 and later support for Reaper x64 only
- full support or no support at all for Linux, depending on the distribution
__________________
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-22-2020, 03:05 AM   #1115
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Back to JS.. How can I select the first column of a listview?


It supports LVS_REPORT, LVS_EX_FULLROWSELECT.


I tried these but no luck:
Code:
ReaPackhwnd = reaper.JS_Window_Find( "Browse packages", true )
SysList = reaper.JS_Window_FindChildByID( ReaPackhwnd, 0xD4 )
LVM_SETITEMSTATE = 0x102B
LVIS_FOCUSED = 0x0001
LVIS_SELECTED = 0x0002
LVM_SETSELECTIONMARK = 0x1043
reaper.JS_WindowMessage_Send( SysList, LVM_SETITEMSTATE, 0, 0, 0, LVIS_FOCUSED|LVIS_SELECTED )
reaper.JS_WindowMessage_Send( SysList, LVM_SETSELECTIONMARK, 0, 0, 0, 0)
__________________
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-22-2020, 05:15 AM   #1116
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
Back to JS.. How can I select the first column of a listview?

It supports LVS_REPORT, LVS_EX_FULLROWSELECT.
Column or item?

LVS_EX_FULLROWSELECT is just a style flag, so when user selects an item the whole row is selected, otherwise IIRC only the item in first column is selected.

Selecting LV items is not a simple SendMessage call, Julian would need to add that for us, and +1 to that!

FWIW, my 'Action History' app for REAPER (done in VB.Net) uses this (written by other coder), it might a bit more complicated becasue my app is on another process then REAPER, but either way probably requires a LV_ITEM structure..
Code:
Private Sub SelectItem(lv_hWnd As IntPtr, index As Integer, selState As Boolean)
    If Not lv_hWnd.Equals(IntPtr.Zero) Then ' Check listview handle is not invalid
        Dim itemCount As Integer = SendMessage(lv_hWnd, LVM_GETITEMCOUNT, 0, IntPtr.Zero)
        If itemCount < index Then Exit Sub
        Dim procId As Integer
        GetWindowThreadProcessId(lv_hWnd, procId) ' Get the listview process Id
        'Open the process id and set access rights to read and write to the process`s memory
        Dim hProc As IntPtr = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, False, procId)
        Dim lvi As New LV_ITEM ' Create a new LV_ITEM structure to select or unselect the item
        lvi.mask = LVIF_STATE
        lvi.stateMask = LVIS_SELECTED
        If selState Then
            lvi.state = &HF
        Else
            lvi.state = 0
        End If
        ' Reserve space in the processes memory and write the new LV_ITEM structure`s data to it
        Dim LvItemPtr As IntPtr = VirtualAllocEx(hProc, IntPtr.Zero, Marshal.SizeOf(lvi), MEM_COMMIT, PAGE_READWRITE)
        WriteProcessMemory(hProc, LvItemPtr, lvi, Marshal.SizeOf(lvi), 0)
        SendMessage(lv_hWnd, LVM_SETITEMSTATE, index, LvItemPtr) ' Send the message to set the items state
        VirtualFreeEx(hProc, LvItemPtr, 0, MEM_RELEASE) 'Release the processes memory used for the LV_ITEM structure`s data
        CloseHandle(hProc)
    End If
End Sub

Last edited by Edgemeal; 04-22-2020 at 05:24 AM.
Edgemeal is offline   Reply With Quote
Old 04-22-2020, 06:24 AM   #1117
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Quote:
Originally Posted by Edgemeal View Post
Column or item?

LVS_EX_FULLROWSELECT is just a style flag, so when user selects an item the whole row is selected, otherwise IIRC only the item in first column is selected.

Selecting LV items is not a simple SendMessage call, Julian would need to add that for us, and +1 to that!

FWIW, my 'Action History' app for REAPER (done in VB.Net) uses this (written by other coder), it might a bit more complicated becasue my app is on another process then REAPER, but either way probably requires a LV_ITEM structure..
Code:
Private Sub SelectItem(lv_hWnd As IntPtr, index As Integer, selState As Boolean)
    If Not lv_hWnd.Equals(IntPtr.Zero) Then ' Check listview handle is not invalid
        Dim itemCount As Integer = SendMessage(lv_hWnd, LVM_GETITEMCOUNT, 0, IntPtr.Zero)
        If itemCount < index Then Exit Sub
        Dim procId As Integer
        GetWindowThreadProcessId(lv_hWnd, procId) ' Get the listview process Id
        'Open the process id and set access rights to read and write to the process`s memory
        Dim hProc As IntPtr = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, False, procId)
        Dim lvi As New LV_ITEM ' Create a new LV_ITEM structure to select or unselect the item
        lvi.mask = LVIF_STATE
        lvi.stateMask = LVIS_SELECTED
        If selState Then
            lvi.state = &HF
        Else
            lvi.state = 0
        End If
        ' Reserve space in the processes memory and write the new LV_ITEM structure`s data to it
        Dim LvItemPtr As IntPtr = VirtualAllocEx(hProc, IntPtr.Zero, Marshal.SizeOf(lvi), MEM_COMMIT, PAGE_READWRITE)
        WriteProcessMemory(hProc, LvItemPtr, lvi, Marshal.SizeOf(lvi), 0)
        SendMessage(lv_hWnd, LVM_SETITEMSTATE, index, LvItemPtr) ' Send the message to set the items state
        VirtualFreeEx(hProc, LvItemPtr, 0, MEM_RELEASE) 'Release the processes memory used for the LV_ITEM structure`s data
        CloseHandle(hProc)
    End If
End Sub

The first item (row) I meant, sorry! I found a way to do it by virtually clicking on it. But I need to right-click and select an option. But this option doesn't appear if I right-click programmatically. It appears only if I do it manually.
__________________
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-22-2020, 09:57 AM   #1118
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
The first item (row) I meant, sorry! I found a way to do it by virtually clicking on it. But I need to right-click and select an option. But this option doesn't appear if I right-click programmatically. It appears only if I do it manually.
Ya OK, just selecting an item doesn't work, the item I manually right mouse clicked last is the one thats affected. In my own apps I use HitTest info to get what item (or subitem) is at mouse location, can only GUESS reapack is using similar method? I never tried sending LVM_HITTEST message so not sure if that would work and it also requires a structure. Sorry can't be of more help.
Edgemeal is offline   Reply With Quote
Old 04-22-2020, 11:00 PM   #1119
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Quote:
Originally Posted by Edgemeal View Post
Ya OK, just selecting an item doesn't work, the item I manually right mouse clicked last is the one thats affected. In my own apps I use HitTest info to get what item (or subitem) is at mouse location, can only GUESS reapack is using similar method? I never tried sending LVM_HITTEST message so not sure if that would work and it also requires a structure. Sorry can't be of more help.
Thanks Edgemeal! I guess then the only way to force install a package will be if cfillion adds an API for this.
__________________
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-23-2020, 05:37 AM   #1120
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

I am trying to paint over the marker and region area. And I have 2 questions:
1) Why everything gets messed up when I scroll?
2) Is there anything else that should be deleted at exit?
3) Would it be better if I created a window on top of the timeline and draw on the window? But that would not let me click and drag the timeline any more, wouldn't it? Or is there a way to do it? (like Cockos' LICEcap)

Code:
MainHwnd = reaper.GetMainHwnd()
timeline = reaper.JS_Window_FindChildByID( MainHwnd, 0x3ED )
timelineDC = reaper.JS_GDI_GetWindowDC( timeline )
_, left, top, right, bottom = reaper.JS_Window_GetRect( timeline )
width = right - left
height = bottom - top - 40
timelinebm = reaper.JS_LICE_CreateBitmap( true, width, height )
timelinebmDC = reaper.JS_LICE_GetDC( timelinebm )
bm = reaper.JS_LICE_CreateBitmap( true, width, height )
reaper.JS_LICE_Clear( bm, 0x009F0000 )
bmDC = reaper.JS_LICE_GetDC( bm )


start = reaper.time_precise()
function main()
  reaper.JS_GDI_Blit( timelinebmDC, 0, 0, timelineDC, 0, 0, width, height )
  reaper.JS_LICE_Blit( bm, 0, 0, timelinebm, 0, 0, width, height, 0.8, "COPY,ALPHA" )
  reaper.JS_GDI_Blit( timelineDC, 0, 0, bmDC, 0, 0, width, height)
  if reaper.time_precise() - start < 10 then
    reaper.defer(main)
  else
    reaper.JS_GDI_DeleteObject( timelineDC )
    reaper.JS_GDI_DeleteObject( bm )
    reaper.JS_GDI_DeleteObject( bmDC )
    reaper.JS_GDI_DeleteObject( timelinebm )
    reaper.JS_GDI_DeleteObject( timelinebmDC )
    reaper.UpdateTimeline()
    return reaper.defer(function() end)
  end
end

main()
__________________
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-23-2020 at 06:11 AM.
amagalma 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 05:24 AM.


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