|
|
|
01-20-2024, 10:23 AM
|
#1961
|
Human being with feelings
Join Date: Apr 2009
Location: Nashville
Posts: 174
|
Could I use this to get and set these options in the MIDI editor?
|
|
|
01-20-2024, 03:20 PM
|
#1962
|
Human being with feelings
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,903
|
Quote:
Originally Posted by Rockum
Could I use this to get and set these options in the MIDI editor?
|
Hope you can follow this (see code comments ).
To set the scale menu item I had to revert to sending keys to the menu
Good luck!
Code:
function msg(str) reaper.ShowConsoleMsg(tostring(str) .. '\n')end
function SetComboBoxIndex(hwnd, index)
local id = reaper.JS_Window_AddressFromHandle(reaper.JS_Window_GetLongPtr(hwnd, "ID"))
reaper.JS_WindowMessage_Send(hwnd, "CB_SETCURSEL", index,0,0,0)
reaper.JS_WindowMessage_Send(reaper.JS_Window_GetParent(hwnd), "WM_COMMAND", id, 1, reaper.JS_Window_AddressFromHandle(hwnd), 0) -- 1 = CBN_SELCHANGE
end
local VK_RIGHT = 0x27 -- RIGHT ARROW key
local VK_DOWN = 0x28 -- DOWN ARROW key
local VK_RETURN = 0x0D -- ENTER key
function PostKey(hwnd, vk_code)
reaper.JS_WindowMessage_Post(hwnd, "WM_KEYDOWN", vk_code, 0,0,0)
reaper.JS_WindowMessage_Post(hwnd, "WM_KEYUP", vk_code, 0,0,0)
end
local is_windows = reaper.GetOS():match('Win')
local class_name = is_windows and '#32768' or '__SWELL_MENU' -- Thanks to FTC
function SelectMenuItem()
local ret, list = reaper.JS_Window_ListAllTop()
for address in string.gmatch(list .. ',', '[^,]+') do
local hwnd = reaper.JS_Window_HandleFromAddress(address)
if reaper.JS_Window_GetClassName(hwnd) == class_name then
-- Send keys to select menu item!
-- EXAMPLE #1: Select menu item "Blues", (7th item in menu)
-- for i = 1, 7 do PostKey(hwnd, VK_DOWN) end
-- PostKey(hwnd, VK_RETURN)
--
-- EXAMPLE #2 Select menu item "Chords > Major 7th"
PostKey(hwnd, VK_DOWN)
PostKey(hwnd, VK_RIGHT)
PostKey(hwnd, VK_DOWN)
PostKey(hwnd, VK_DOWN)
PostKey(hwnd, VK_RETURN)
return -- All done!
end
end
if reaper.time_precise() - init_time > 2 then msg('TimeOut: Menu not found!') return end
reaper.defer(SelectMenuItem)
end
-- NOTE: Testing with "One ME pre-project"
hwnd = reaper.MIDIEditor_GetActive() -- get active MIDI Editor
chk = reaper.JS_Window_FindChildByID(hwnd, 0x4EC) -- get handle to KeySnap checkbox
state = reaper.JS_WindowMessage_Send(chk, "BM_GETCHECK", 0,0,0,0)-- get KeySnap checkbox checked state
--
msg(state) -- 1 = checked, 0 = not checked
-- EXAMPLE to toggle key snap checkbox
--reaper.JS_WindowMessage_Send(chk, "BM_SETCHECK", 1-state, 0,0,0) -- set checkbox checked state
--reaper.JS_WindowMessage_Send(hwnd, "WM_COMMAND", 0x4EC, 0,0,0) -- apply the setting
if state == 1 then
-- get current key & scale settings
cbo_key = reaper.JS_Window_FindChildByID(hwnd, 0x4ED)
cbo_scale = reaper.JS_Window_FindChildByID(hwnd, 0x4EE)
key_txt = reaper.JS_Window_GetTitle(cbo_key)
scale_txt = reaper.JS_Window_GetTitle(cbo_scale)
--
msg(key_txt) msg(scale_txt)
-- Set Key to "A" (index 4)
SetComboBoxIndex(cbo_key, 4)
-- Set Scale: Open scale menu,
reaper.JS_WindowMessage_Post(hwnd, "WM_COMMAND", 0x4EE, 0,0,0)
-- Send keys to menu to make selection
init_time = reaper.time_precise()
SelectMenuItem()
end
|
|
|
01-20-2024, 05:39 PM
|
#1963
|
Human being with feelings
Join Date: Apr 2009
Location: Nashville
Posts: 174
|
Wow that was a lot of work. Thank you for taking the time.
|
|
|
01-21-2024, 02:11 PM
|
#1964
|
Human being with feelings
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,903
|
Quote:
Originally Posted by Rockum
Wow that was a lot of work. Thank you for taking the time.
|
Most of it was copied/pasted from previous scripts/screwing around.
For setting the Key combobox, don't really need function SetComboBoxIndex() since we already have the combo parent and ID, you could simply do it this way..
Code:
-- Set Key to "A" (index 4)
reaper.JS_WindowMessage_Send(cbo_key, "CB_SETCURSEL", 4 ,0,0,0) -- select index 4 in combobox
reaper.JS_WindowMessage_Send(hwnd, "WM_COMMAND", 0x4ED, 1, reaper.JS_Window_AddressFromHandle(cbo_key), 0) -- notify parent of combo index change
Last edited by Edgemeal; 01-22-2024 at 10:10 AM.
|
|
|
Yesterday, 10:29 AM
|
#1965
|
Human being with feelings
Join Date: Sep 2018
Location: China
Posts: 564
|
Is there a way to "reset" the value obtained by reaper.JS_VKeys_GetState? For example, if a key is detected to have a state value of 1, can I forcibly reset it back to 0?
Typically, when a key is pressed, reaper.JS_VKeys_GetState will detect its value as 1, and when released, the value will return to 0.
However, I've noticed a special case. Suppose I set the function of a key to import an audio file (reaper.InsertMedia), when it starts running, an import file popup window will appear. This window impacts the judgment of the key's state by reaper.JS_VKeys_GetState, it erroneously considers the key as still being pressed, even though it has actually been released. It won't be correctly identified until I press it again.
If there's no way to forcibly reset it, is there any way to avoid the impact on the judgment of the key state by the pop-up window when importing an audio file?
|
|
|
Yesterday, 01:37 PM
|
#1966
|
Human being with feelings
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,903
|
Quote:
Originally Posted by dsyrock
However, I've noticed a special case. Suppose I set the function of a key to import an audio file (reaper.InsertMedia), when it starts running, an import file popup window will appear. This window impacts the judgment of the key's state by reaper.JS_VKeys_GetState, it erroneously considers the key as still being pressed, even though it has actually been released. It won't be correctly identified until I press it again.
|
Confirmed. Not sure you can reset the key states, Maybe workaround would be to detect the key's released/Up state?, quick test seems to work OK here,..
Code:
-- If "A" key Up...
if reaper.JS_VKeys_GetUp(reaper.time_precise()-0.1):byte(65) == 1 then
reaper.InsertMedia(file, 1)
end
|
|
|
Yesterday, 07:52 PM
|
#1967
|
Human being with feelings
Join Date: Sep 2018
Location: China
Posts: 564
|
Quote:
Originally Posted by Edgemeal
Confirmed. Not sure you can reset the key states, Maybe workaround would be to detect the key's released/Up state?, quick test seems to work OK here,..
Code:
-- If "A" key Up...
if reaper.JS_VKeys_GetUp(reaper.time_precise()-0.1):byte(65) == 1 then
reaper.InsertMedia(file, 1)
end
|
Thanks for your advise, I will try it later.
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 03:31 AM.
|