Old 10-13-2018, 02:32 PM   #1
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,752
Default js_ReaScriptAPI extension

I have uploaded a new extension that may be of interest to other scripters: "js_ReaScriptAPI".

It can be installed via ReaPack (if ReaTeam/Extensions is not listed among your default repositories, you can add the repository manually with this URL), or via direct download (copy the file to REAPER's /UserPlugins directory).

The idea behind this extension is to make all the useful and powerful functions that are available to C++ extensions available to ReaScripts too. (The resulting ReaScript API is therefore not the result of my own amazing programming skills, but is mostly just an interface to existing C++ functions.)

The online documentation for the corresponding C++ functions is probably the best place to learn how to use these functions. For example, Window messages and Drawing with GDI.

I have tried to make most functions cross-platform applicable, but I am not able to test the extension on MacOS, so let me know if anything doesn't work as expected.

Many thanks to cfillion, Xenakios and nofish, who helped me a *lot* to figure out the esoteric and undocumented mysteries of REAPER extensions.


Here are a few examples:


Attach "pin on top" button to script GUIs

FR: add 'always on top' pin for EEL script GUI's

Code:
w = reaper.JS_Window_Find("MIDI Inspector", true)
if w then reaper.JS_Window_AttachTopmostPin(w) end




Drawing inside REAPER windows

FR: Lasso Select for midi notes





Load custom cursors

FR: ReaScript: Allow scripts to change mouse cursor

Code:
-- Load REAPER's native "arpeggiate" cursor
reaper.JS_Mouse_SetCursor(reaper.JS_Mouse_LoadCursor(502)) 
-- Prevent REAPER from changing cursor back, by intercepting "SETCURSOR" messages
reaper.JS_WindowMessage_Intercept(window, "WM_SETCURSOR", false)




Take control of mouse clicks and mousewheel

By intercepting mouse and mousewheel messages, scripts can be controlled with the mouse, without activating REAPER's own mouse modifier actions.

For example, in my own "Mouse editing" CC scripts, I use code like the following to block the mouse from interacting with the piano roll while the script is running:
Code:
tIntercepts = { WM_LBUTTONDOWN   = false,
	        WM_LBUTTONUP     = false,
	        WM_LBUTTONDBLCLK = false,
	        WM_MBUTTONDOWN   = false,
	        WM_MBUTTONUP     = false,
	        WM_MBUTTONDBLCLK = false,
	        WM_RBUTTONDOWN   = false,
	        WM_RBUTTONUP     = false,
	        WM_RBUTTONDBLCLK = false,
	        WM_MOUSEWHEEL    = false,
	        WM_MOUSEHWHEEL   = false,
	        WM_MOUSEMOVE     = false,
	        WM_SETCURSOR     = false
	      }
midiview = reaper.JS_Window_FromPoint(reaper.GetMousePosition())
for key, value in pairs(tIntercepts) do
    OK = reaper.JS_WindowMessage_Intercept(midiview, key, value)
end
The scripts can then use JS_WindowMessage_Peek to track mouse events while running:
Code:
peekOK, _, time, keys, rotate, x, y = reaper.JS_WindowMessage_Peek(midiview, "WM_MOUSEWHEEL")
if peekOK and time ~= prevTime then
    -- mousewheel has moved since last defer cycle
end
peekOK, _, time, keys, _, x, y = reaper.JS_WindowMessage_Peek(midiview, "WM_LBUTTONDOWN")
if peekOK and time ~= prevTime then
    -- Left button has been pressed
end


MediaExplorer_OnCommand

Send commands to any window, similar to Main_OnCommand and MIDIEditor_OnCommand:
Code:
-- Action 1011 = Autoplay: Toggle on/off
me = reaper.JS_Window_Find("Media Explorer", true)
reaper.JS_WindowMessage_Send(me, "WM_COMMAND", 1011, 0, 0, 0)


Keep the Mixer window out of the way

FR: Plugin windows always on top, Mixer window always behind

The API offers several functions for getting and setting the Z order and focus of windows, so one possible solution for the FR is discussed here:
Move Mixer out of the way: example of Win32/SWELL in ReaScript.



Track mouse events outside script GUI

FR: Exposure of mouse state-functions for non gfx.ini-created windows

In addition to the WindowMessage functions, which are specific to a single target window, the mouse can be tracked using JS_Mouse_GetState:
Code:
-- Flag 0b00000001+0b00010000 = left mouse button + alt key
if reaper.JS_Mouse_GetState(0x0011) = 0x0011 then
   --...
end


Frameless script GUIs

FR: Stylish ReaScript GUIs: Transparent backgrounds and no titlebars

Unfortunately, even with C++ functions, I have not been able to change script GUIs' window style to "frameless" without getting ugly artefacts. However, scripts can fake a frameless style by using the GDI functions to draw over the entire window area, including the frame:


Last edited by juliansader; 01-19-2019 at 06:15 PM.
juliansader is offline   Reply With Quote
Old 10-13-2018, 02:35 PM   #2
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 2,525
Default

Interesting, looks cool!
__________________
SoundCloud | MPL Scripts discussion | ReaPack | Donate
mpl is offline   Reply With Quote
Old 10-13-2018, 03:08 PM   #3
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,751
Default

Holy cow, didn't see THAT coming! Mouse lasso, always on top... Geez Julian, you never cease to amaze me!
__________________
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 10-13-2018, 03:56 PM   #4
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 6,032
Default

Many thx ! This may bring a lot of useful things !



C++ function were recently exposed in SWS but because pull request are very long to be merged, having your extension will definitly be useful
Though I dont see the function for getting bitdepth, which is accessible for C++ and was wating for mege in SWS, is it missing ?



Ill try to add your functions in my reascript doc.
X-Raym is offline   Reply With Quote
Old 10-13-2018, 03:59 PM   #5
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,751
Default

Quote:
Originally Posted by X-Raym View Post
Ill try to add your functions in my reascript doc.
Merci X-Raym!!!
__________________
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 10-13-2018, 04:31 PM   #6
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,498
Default

AMAZING!!! :O


Well done! A lot of useful stuff in there opening great possibilities!
amagalma is offline   Reply With Quote
Old 10-14-2018, 07:10 AM   #7
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,046
Default

Quote:
Originally Posted by X-Raym View Post
Though I dont see the function for getting bitdepth, which is accessible for C++ and was wating for mege in SWS, is it missing ?
This came from cfillion and is still waiting for merge in SWS.
https://github.com/reaper-oss/sws/pull/1011
nofish is offline   Reply With Quote
Old 10-13-2018, 02:32 PM   #8
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,752
Default js_ReaScriptAPI extension

JS_Byte
JS_Double
JS_GDI_Blit
JS_GDI_CreateFillBrush
JS_GDI_CreateFont
JS_GDI_CreatePen
JS_GDI_DeleteObject
JS_GDI_DrawText
JS_GDI_FillEllipse
JS_GDI_FillPolygon
JS_GDI_FillRect
JS_GDI_FillRoundRect
JS_GDI_GetClientDC
JS_GDI_GetScreenDC
JS_GDI_GetSysColor
JS_GDI_GetTextColor
JS_GDI_GetWindowDC
JS_GDI_Line
JS_GDI_Polyline
JS_GDI_ReleaseDC
JS_GDI_SelectObject
JS_GDI_SetPixel
JS_GDI_SetTextBkColor
JS_GDI_SetTextBkMode
JS_GDI_SetTextColor
JS_GDI_StretchBlit
JS_Int
JS_LICE_Arc
JS_LICE_Bezier
JS_LICE_Blit
JS_LICE_Circle
JS_LICE_Clear
JS_LICE_CreateBitmap
JS_LICE_CreateFont
JS_LICE_DestroyBitmap
JS_LICE_DestroyFont
JS_LICE_DrawChar
JS_LICE_DrawText
JS_LICE_FillCircle
JS_LICE_FillPolygon
JS_LICE_FillRect
JS_LICE_FillTriangle
JS_LICE_GetDC
JS_LICE_GetHeight
JS_LICE_GetPixel
JS_LICE_GetWidth
JS_LICE_GradRect
JS_LICE_IsFlipped
JS_LICE_Line
JS_LICE_LoadPNG
JS_LICE_PutPixel
JS_LICE_Resize
JS_LICE_RotatedBlit
JS_LICE_RoundRect
JS_LICE_ScaledBlit
JS_LICE_SetFontBkColor
JS_LICE_SetFontColor
JS_LICE_SetFontFromGDI
JS_MIDIEditor_ArrayAll
JS_MIDIEditor_ListAll
JS_Mouse_GetState
JS_Mouse_LoadCursor
JS_Mouse_LoadCursorFromFile
JS_Mouse_SetCursor
JS_Mouse_SetPosition
JS_PtrFromStr
JS_ReaScriptAPI_Version
JS_WindowMessage_Intercept
JS_WindowMessage_InterceptList
JS_WindowMessage_ListIntercepts
JS_WindowMessage_Peek
JS_WindowMessage_Post
JS_WindowMessage_Release
JS_WindowMessage_ReleaseAll
JS_WindowMessage_ReleaseWindow
JS_WindowMessage_Send
JS_Window_AddressFromHandle
JS_Window_ArrayAllChild
JS_Window_ArrayAllTop
JS_Window_ArrayFind
JS_Window_AttachResizeGrip
JS_Window_AttachTopmostPin
JS_Window_ClientToScreen
JS_Window_Destroy
JS_Window_Enable
JS_Window_Find
JS_Window_FindChild
JS_Window_FromPoint
JS_Window_GetClientRect
JS_Window_GetFocus
JS_Window_GetForeground
JS_Window_GetLongPtr
JS_Window_GetParent
JS_Window_GetRect
JS_Window_GetRelated
JS_Window_GetScrollInfo
JS_Window_GetTitle
JS_Window_HandleFromAddress
JS_Window_IsChild
JS_Window_IsVisible
JS_Window_IsWindow
JS_Window_ListAllChild
JS_Window_ListAllTop
JS_Window_ListFind
JS_Window_Move
JS_Window_RemoveXPStyle
JS_Window_Resize
JS_Window_ScreenToClient
JS_Window_SetFocus
JS_Window_SetForeground
JS_Window_SetPosition
JS_Window_SetScrollPos
JS_Window_SetTitle
JS_Window_SetZOrder
JS_Window_Show

New by Xenakios!
Xen_AudioWriter_Create
Xen_AudioWriter_Destroy
Xen_AudioWriter_Write

Last edited by juliansader; 10-14-2018 at 08:49 AM.
juliansader is offline   Reply With Quote
Old 10-14-2018, 03:57 AM   #9
InfiniteDimensionality
Human being with feelings
 
Join Date: Jun 2017
Posts: 176
Default

Cool,

I wonder if you could extend it a little bit?

Writing in some languages sucks or does not offer as much performance.

Could you potentially extend your plugin to load other plugin compiled in other languages(such as c++/d/haskell/etc)?

The idea is this:

1. You have a context variable that allows any plugin to use to access the methods and variables(an interface basically).

2. You compile the source code when it changes by monitoring any changes and recompiling and loading(this might work only when restarting reaper without some special hot plugging capabilities). You just run a compile string on the code.

3. You load the code, run any setup routines(similar to dll loading). Run some main function(possibly in another thread) and pass it the context.

This then makes it much easier to write programs and even debug them(e.g., with windows one could use VS to debug the program while it is in reaper).

It would allow for much more freedom than using reapers built in scripting, which isn't bad but isn't great(mainly the dev part such as using IDE's and such).

It would also make writing plugins easier in some ways.

Most of the work shouldn't be too difficult(it can be done easily but might be hard to do well).
InfiniteDimensionality is offline   Reply With Quote
Old 10-14-2018, 04:46 AM   #10
NextLevel
Human being with feelings
 
Join Date: Dec 2014
Posts: 410
Default

@juliansader,

Noticed a little typo in the "MediaExplorer_OnCommand" example.

The line "m = reaper.JS_Window_Find("Media Explorer", true)"
should be "me = reaper.JS_Window_Find("Media Explorer", true)"

This extension is going to open up some nice possibilities, so thank you so much!

Just added your "pin to top" example to Lokasenna's Radial Menu.., yea!!!
NextLevel is offline   Reply With Quote
Old 10-14-2018, 04:50 AM   #11
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 6,032
Default

Quote:
Could you potentially extend your plugin to load other plugin compiled in other languages(such as c++/d/haskell/etc)?
ReaScript already supports Lua and Python, I don't think there is a lot of demand for other languages.



Quote:
Most of the work shouldn't be too difficult
You seems to have a lot of knowledge about programming, so why no you take a try to do this ?
Juliansader extension is open source, you can work from there.
X-Raym is offline   Reply With Quote
Old 10-14-2018, 06:54 AM   #12
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,046
Default

Amazing. Kudos for the work you've put into this!

Quote:
Originally Posted by juliansader View Post
Attach "pin on top" button to script GUIs

FR: add 'always on top' pin for EEL script GUI's
I'd tend to suggest all ReaScripters having scripts with GUI's to update their scripts to add the 'always on top' pin.

Last edited by nofish; 10-14-2018 at 07:36 AM.
nofish is offline   Reply With Quote
Old 10-23-2018, 01:48 PM   #13
TonE
Human being with feelings
 
Join Date: Feb 2009
Location: Reaper HAS send control via midi !!!
Posts: 1,838
Default

Quote:
Originally Posted by juliansader View Post
I have uploaded a new extension that may be of interest to other scripters: "js_ReaScriptAPI".
Does this allow docking of trackey hackey and patterns in wine? Now lua scripts can not be docked in wine.
TonE is offline   Reply With Quote
Old 10-25-2018, 07:09 AM   #14
nappies
Human being with feelings
 
nappies's Avatar
 
Join Date: Dec 2017
Posts: 129
Default

Very useful and promising thing! Thank you for your hard work juliansader!
I didn’t really dive into the new API, but what I saw was very impressive!
Is it possible to intercept the left mouse click on TCP solo button and make an exclusive solo( by deafult while code running ) for example?
nappies is offline   Reply With Quote
Old 10-26-2018, 01:01 PM   #15
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,498
Default

Julian, I followed your example in post #46 trying to mimick mouseclicks but it works the first time and fails all the other times. Any idea why?
This is the test code:


Code:
reaper.ShowConsoleMsg("This message should always be cleared\n")
local RSwindow = reaper.JS_Window_Find("ReaScript console output", true)
local _, leftX, topY, rightX, bottomY = reaper.JS_Window_GetRect(RSwindow)
-- "clear" button
local buttonX = rightX - 114
local buttonY = bottomY -27
-- Get button window
local buttonWindow = reaper.JS_Window_FromPoint(buttonX, buttonY)
_, leftX, topY, rightX, bottomY = reaper.JS_Window_GetRect(buttonWindow)
-- Post click message
reaper.JS_WindowMessage_Post(buttonWindow, "WM_LBUTTONDOWN", 0x0001, 0, buttonX-leftX, buttonY-topY)
reaper.JS_WindowMessage_Post(buttonWindow, "WM_LBUTTONUP", 0x0000, 0, buttonX-leftX, buttonY-topY)
P.S. If I close the Console window and run the script again, it works. But if I keep running the script with the console window being open, then it fails.
P.S.2. Ok, I found it.. For it to work, I must first focus the button window using
Code:
reaper.ShowConsoleMsg("This message should always be cleared\n")
local RSwindow = reaper.JS_Window_Find("ReaScript console output", true)
local _, leftX, topY, rightX, bottomY = reaper.JS_Window_GetRect(RSwindow)
-- Get "clear" button window
local buttonWindow = reaper.JS_Window_FromPoint(rightX - 114, bottomY -27)
-- Post click message
reaper.JS_Window_SetFocus( buttonWindow )
reaper.JS_WindowMessage_Send(buttonWindow, "WM_LBUTTONDOWN", 0x0001, 0, 10, 10)
reaper.JS_WindowMessage_Send(buttonWindow, "WM_LBUTTONUP", 0x0000, 0, 10,10)
before the WindowMessage Posts

Last edited by amagalma; 10-26-2018 at 01:11 PM.
amagalma is offline   Reply With Quote
Old 10-27-2018, 03:19 PM   #16
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,450
Default

Is this possible without flickering?


Code:
W,H = 5000,5000
local bmp = reaper.JS_LICE_CreateBitmap( true, W, H )
local bmpDC = reaper.JS_LICE_GetDC(bmp )
reaper.JS_LICE_FillRect( bmp, 0, 0, W, H, 0x99009999, 1, "ADD" )

local track_window = reaper.Window_Find("trackview", true) -- GET TRACK VIEW
local track_window_dc =  reaper.JS_GDI_GetWindowDC( track_window )

function main()
reaper.JS_GDI_Blit(track_window_dc, X_start, Y_start, bmpDC, 0, 0, W, H )
reaper.defer(main)
end
main()
This is the short versions of whats going on,but rectangle is constantly updated when window is moved,scrolled etc
Sexan is offline   Reply With Quote
Old 10-27-2018, 04:20 PM   #17
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,752
Default

I also posted about this some time ago:
SWELL/GDI and LICE: Is it possible to draw inside REAPER's window without flickering?, but I didn't get any answers, so I asked Justin on askjf.com:
Quote:
Question: Is it possible for a REAPER script or extension to use swell/GDI to draw basic shapes such as lines inside other REAPER/swell windows, without flickering? Flickering is not unexpected, since the script and window paint their stuff alternately and separately. I have tried blocking WM_PAINT messages, and then sending my own WM_PAINT once per defer cycle, but t
Asked by Julian (54.39.119.x) on September 20 2018, 9:41am
Reply on September 20 2018, 2:20pm:

It's probably possible via subclassing, but it would get messy/tricky.
juliansader is offline   Reply With Quote
Old 11-28-2018, 01:09 AM   #18
Aleksandr_Oleynik
Human being with feelings
 
Join Date: Jan 2013
Location: Kiev, Ukraine
Posts: 62
Default

Quote:
Originally Posted by juliansader View Post
I have uploaded a new extension that may be of interest to other scripters: "js_ReaScriptAPI".
Hello juliansader!

Could you, please, add to your "js_ReaScriptAPI" a function to receive and send OSC-messages (OSC Client and Server)?
I use Reaper and LUA for creating live setups and I really need a function to hear outgoing OSC-commands with LUA-script (with specific port and IP and send OSC-messages to a specific port and IP).

The Reaper itself supports OSC, but today there’s no way to send OSC from script and to receive OSC to a script.

I would be very thankful for this help. And ready to pay for your time in any reasonable amount.

Best regards,
Aleksandr
Aleksandr_Oleynik is offline   Reply With Quote
Old 12-02-2018, 04:08 AM   #19
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,752
Default

I have uploaded v0.96 of the extension to its repository. [EDIT: Now v0.961.]

The reason why this update was somewhat delayed, is that I was trying to figure out how to return long strings (for example, if dozens of files are selected in an Open File dialog) and strings that contain \0 characters (for example, packed Lua strings). Fortunately, Justin noticed my threads, and the upcoming version of REAPER will allow API functions to return such strings. The extension will therefore require an up-to-date version of REAPER.

The update is not yet available via ReaPack, but in the meantime if anyone is interested in testing the new functions, it can be downloaded and installed manually. It requires one of the recent dev versions of REAPER.

New functions:

* FindChildByID: (Thanks to amagalma for reminding me about this.) IDs seem to be a more reliable cross-platform way of getting child windows (such as the arrange view within the main window, or the piano roll within an MIDI editor), than searching by title ("trackview" or "midiview") or by Z order.

* Localize: If searching for standard windows such as "Actions" or "Navigator" by window title, localized (translated) titles should be used.

* Several ListView functions: Useful for finding selected items in any list window, such as the FX chain.

* Open files, save file and select folder dialogs.

Changed functions:

* All the "List" functions that previously stored long strings in ExtStates. These functions now return the long strings directly.

Last edited by juliansader; 12-03-2018 at 02:51 AM.
juliansader is offline   Reply With Quote
Old 12-02-2018, 04:29 AM   #20
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 6,032
Default

Quote:
* Open files, save file and select folder dialogs.
Finally !!!


Thx !
X-Raym is offline   Reply With Quote
Old 12-02-2018, 04:59 PM   #21
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 3,107
Default

Great stuff! Thanks for all your hard work!

Would the listview functions be any good for getting the command id of the selected item in the action list?
__________________
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 12-03-2018, 02:58 AM   #22
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,752
Default

Quote:
Originally Posted by lb0 View Post
Would the listview functions be any good for getting the command id of the selected item in the action list?
I have uploaded a quick update v0.961, and now you can: if the commandID is visible in the Actions list, you can get it as subitem 3:
Code:
commandID = reaper.JS_ListView_GetItemText(window, index, 3)
juliansader is offline   Reply With Quote
Old 12-16-2018, 05:11 AM   #23
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,498
Default

How could I paste the text in the clipboard to a focused window?
For example, with Spy++ I get this code when pasting into a window:
Code:
<000001> 00250490 P WM_CHAR chCharCode:'22' (22) cRepeat:1 ScanCode:2F fExtended:0 fAltDown:0 fRepeat:0 fUp:0 [wParam:00000016 lParam:002F0001]
I have tried this but it does not work:
Code:
reaper.JS_WindowMessage_Send( windowHWND, "WM_CHAR", 0x0016, 0x0000, 0x0001, 0x002F)
Any ideas?

Last edited by amagalma; 12-16-2018 at 06:30 AM.
amagalma is offline   Reply With Quote
Old 12-16-2018, 10:08 AM   #24
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 1,374
Default

EDIT
You got me wondering about sending text and clicking buttons now.
Since there is no support for "BM_CLICK" or "WM_SETTEXT"

EDIT 2
This seems OK for "BM_CLICK" on Windows..
Code:
-- Send button click message, a.k.a. "BM_CLICK".
reaper.JS_WindowMessage_Send(button_hWnd, "0x00F5", 0, 0, 0, 0)
CODE REMOVED! TRY AGAIN!

Last edited by Edgemeal; 01-02-2019 at 07:22 PM. Reason: EDIT 2
Edgemeal is offline   Reply With Quote
Old 12-17-2018, 05:59 AM   #25
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,498
Default

Quote:
Originally Posted by Edgemeal View Post
This seems to work OK, tho not sure its actually correct.

Code:
local hWnd_action = reaper.JS_Window_Find("Actions", true)
if hWnd_action ~= nil then
  -- Get handle to Filter editbox in Actions window,
  local hWnd_filter = reaper.JS_Window_FindChildByID(hWnd_action, 1324)
  -- send it an "A" Char
  ret = reaper.JS_WindowMessage_Post(hWnd_filter, "WM_CHAR", string.byte("A"), 0,0,0) 
end

Yes, simple characters work, but Ctrl+V etc do not.



Quote:
Code:
function JS_Send_Text(hWnd, str)
  for char in string.gmatch(str, "%U") do 
    ret = reaper.JS_WindowMessage_Post(hWnd, "WM_CHAR", string.byte(char), 0, 0, 0) 
    if ret ~= true then break end -- something went wrong?, abort loop!
  end
end

For some reason, this works up to 64 characters. If they are more than 64, it truncates the start.
amagalma is offline   Reply With Quote
Old 12-17-2018, 04:24 AM   #26
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 6,032
Default

Do you think we can get selected media files from Media Explorer and start doing some Media Explorer script ? :P
X-Raym is offline   Reply With Quote
Old 01-18-2019, 02:40 PM   #27
tparker24
Human being with feelings
 
Join Date: Dec 2017
Posts: 53
Default Can't get started

I wanted to try ReaScriptAPI, but am having problems just getting started:

1) I couldn't find it on ReaPack.

2) I saw the files on GitHub, but don't know how/where to install them.

3) I want to use this from python, but couldn't find the normal .py interface file.


Can you help me out?
tparker24 is offline   Reply With Quote
Old 01-19-2019, 09:50 AM   #28
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,046
Default

Quote:
Originally Posted by tparker24 View Post
1) I couldn't find it on ReaPack.
It should be listed in ReaPack as 'js_ReaScriptAPI: API functions for ReaScripts' and the repository where it's hosted (ReaTeam/Extensions) should be enabled by default in ReaPack afaik.
If you don't see it, maybe try 'Synchronize packages' ?
nofish is offline   Reply With Quote
Old 01-19-2019, 10:15 AM   #29
tparker24
Human being with feelings
 
Join Date: Dec 2017
Posts: 53
Default

Quote:
Originally Posted by nofish View Post
It should be listed in ReaPack as 'js_ReaScriptAPI: API functions for ReaScripts' and the repository where it's hosted (ReaTeam/Extensions) should be enabled by default in ReaPack afaik.
If you don't see it, maybe try 'Synchronize packages' ?
Still no luck.

I searched for "js_reascript" and then for "js_rea", but got no results. ("js_re" did show a bunch, but nothing with reascript).

My settings are "Display: All" and "All Packages". I didn't see "Synchronize packages", but I did try "Refresh repositories", without any success.
tparker24 is offline   Reply With Quote
Old 01-19-2019, 10:24 AM   #30
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 1,374
Default

Quote:
Originally Posted by tparker24 View Post
I searched for "js_reascript" and then for "js_rea", but got no results. ("js_re" did show a bunch, but nothing with reascript).
Manage Repositories > "ReaTeam Extensions" is enabled? > Sync again.
Edgemeal is offline   Reply With Quote
Old 01-19-2019, 10:32 AM   #31
tparker24
Human being with feelings
 
Join Date: Dec 2017
Posts: 53
Default

Quote:
Originally Posted by Edgemeal View Post
Manage Repositories > "ReaTeam Extensions" is enabled? > Sync again.
Yes, they're all enabled. Did yet another "Refresh repositories", but still no luck.

I vaguely remember something about it being removed from Reapack ... could you perhaps give it a try?
tparker24 is offline   Reply With Quote
Old 01-19-2019, 11:12 AM   #32
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,046
Default

Quote:
Originally Posted by tparker24 View Post
I didn't see "Synchronize packages"
It's a dedicated menu entry in Reaper under ReaPack menu (here at least).



(I have ReaMenu installed, so it might look a bit different on your side.)

Last edited by nofish; 01-19-2019 at 11:18 AM.
nofish is offline   Reply With Quote
Old 01-19-2019, 11:20 AM   #33
tparker24
Human being with feelings
 
Join Date: Dec 2017
Posts: 53
Default

Quote:
Originally Posted by nofish View Post
It's a dedicated menu entry in Reaper (here at least).



(I have ReaMenu installed, so it might look a bit different on your side.)
Thanks. I also found that in Actions.

I imagine that Synchronize does the same thing as "Refresh repositories" (which is under the packages dropdown in the browser).
tparker24 is offline   Reply With Quote
Old 01-26-2019, 07:30 AM   #34
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 6,032
Default

@juliansader
Excellent, here is my final string:


Code:
'csv files (.csv)\0*.csv\0All Files (*.*)\0*.*\0

Per default, just entering a File name will create a file without extension, the save doesn't force the extension based on the actual filter list, it would be nice if it could :P


Else, I suppose it could be handle by the script itself, but as this will be a common case, I worth having it default if possible, don't you think ?




BTW? \0 as seperator character is a very nice thing..... I really which GetUserInput to be like that, cause if you enter CSV in a multi line input window of this type, it just mess everything.
X-Raym is offline   Reply With Quote
Old 01-28-2019, 10:19 AM   #35
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,555
Default

I think I've found an issue JS_Mouse_GetState(), while using it on Mac(though I don't know, whether its a Mac-problem or a general problem).

I tried to write a script with it to get mouse-click-events in the ruler, which worked fine on Windows. However, when I tried the same script on Mac, it couldn't detect mouseclicks, when they were too short.
I think its because my Mac is much faster than my Windows-computer, so I think the mouseclicks are inbetween two defer-cycles and can't be detected because of that. Could be on Windows too, but I haven't noticed such a problem yet.

Anyway, as deferred ReaScripts can only run about 30 times per second and when they are run quick, the amount of time could be too short to notice mouseclicks.

So I think, the function should work something like that:
a background-thread constantly listens to the mouse-events/keyboard modifier-states.
When I run the JS_Mouse_GetState-function, it will return the current mouse-state(as usual) and in addition a csv-string, that contains all mousestates that happened since last time calling JS_Mouse_GetState or at least since the last defer-cycle.
That way, I couldn't miss any of them, no matter how short they are.

I have no idea how easy or hard this would be to implement, but it would improve heavily on Mouse-State-Management.


With that, I could add to my API a Mouse-Event-defer-script, that returns the mouseclicks(including dragging and doubleclick) in specific HWNDs, which would improve using mouse-states heavily(my dream is to program a clickable UI in the VideoProcessor-window).

Quote:
Originally Posted by X-Raym View Post
BTW? \0 as seperator character is a very nice thing..... I really which GetUserInput to be like that, cause if you enter CSV in a multi line input window of this type, it just mess everything.
Yep, that's really clever to do
__________________
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 04-16-2019, 05:11 AM   #36
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 189
Default

I have a question about JS_Dialog_BrowseForOpenFiles. I set the argue "allowMultiple " to true. But when I selected a bunch of files, it only returned a path, but without any filenames. Did I do anything wrong?

Code:
retval,  filenames = reaper.JS_Dialog_BrowseForOpenFiles("a", "E:/test/", "*.txt", "*.txt", true)

Last edited by dsyrock; 04-16-2019 at 05:18 AM.
dsyrock is offline   Reply With Quote
Old 04-16-2019, 05:26 AM   #37
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 6,032
Default

@dyrock


You have to parse the results with null characte (the code snippet is on this thread),
If I remeber correctly, IDE console and message cobsole doesnt display characters after a null.
But maybe it is another problem.
X-Raym is offline   Reply With Quote
Old 04-16-2019, 11:14 AM   #38
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,752
Default

Quote:
Originally Posted by dsyrock View Post
I have a question about JS_Dialog_BrowseForOpenFiles. I set the argue "allowMultiple " to true. But when I selected a bunch of files, it only returned a path, but without any filenames. Did I do anything wrong?
As X-Raym mentioned, please check out the discussion here, and some other posts earlier in the thread.

Zero-separated strings have confused other new users too, so I should probably mention something in the API help.
juliansader is offline   Reply With Quote
Old 04-16-2019, 06:36 PM   #39
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 189
Default

Quote:
Originally Posted by juliansader View Post
As X-Raym mentioned, please check out the discussion here, and some other posts earlier in the thread.

Zero-separated strings have confused other new users too, so I should probably mention something in the API help.
Thanks, juliansader and X-raym!
dsyrock is offline   Reply With Quote
Old 04-16-2019, 10:46 PM   #40
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 189
Default

@juliansader

One more thing about JS_Dialog_BrowseForOpenFiles:

I run this script

Code:
local check,  names = reaper.JS_Dialog_BrowseForOpenFiles("", "E:/test/", "*.txt", "*.txt", true)

for v in names:gmatch("[^\0]*") do

  reaper.ShowConsoleMsg(v .. "\n")

end
As you mentioned before, when I seleted multy files, the first result in this script is the file path "E:\test\". I tried it on win8.1 and win10, it showed the path correctly. But When I tried it on Win8.0, the result was "E:\test", a "\"at the end was missing.

Last edited by dsyrock; 04-17-2019 at 12:21 AM.
dsyrock 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:22 PM.


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