|
|
|
11-06-2020, 07:45 AM
|
#1
|
Human being with feelings
Join Date: Oct 2011
Posts: 2,924
|
Script to focus main or midi window under mouse. Need help.
Hello,
There is an issue with this script: after having focused on a plug-in, it can't work any more. To enable it again, we have to click on the main or midi window. A solution, please?
function Main()
local win = {}
local _, list = reaper.JS_MIDIEditor_ListAll()
for adr in list:gmatch("[^,]+") do
win[#win+1] = reaper.JS_Window_HandleFromAddress(adr)
end
win[#win+1] = reaper.GetMainHwnd()
local x, y = reaper.GetMousePosition()
local child = reaper.JS_Window_FromPoint(x, y)
for i = 1, #win do
local parent = child
while parent ~= nil do
if parent == win[i] then
reaper.JS_Window_SetFocus(parent)
return
end
parent = reaper.JS_Window_GetParent(parent)
end
end
end
Main()
reaper.defer(function () end)
|
|
|
11-06-2020, 08:55 AM
|
#2
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
What are you trying to do? To focus the MIDI Editor window under the mouse?
|
|
|
11-06-2020, 09:01 AM
|
#3
|
Human being with feelings
Join Date: Oct 2011
Posts: 2,924
|
|
|
|
11-06-2020, 09:26 AM
|
#4
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Did it very fast but should work:
corrected code in post #9
Code:
local win = {}
win[reaper.GetMainHwnd()] = true
local start = reaper.time_precise()
function Main()
local time = reaper.time_precise()
if time >= start + 0.2 then
start = time
local _, list = reaper.JS_MIDIEditor_ListAll()
for adr in list:gmatch("[^,]+") do
local hwnd = reaper.JS_Window_HandleFromAddress(adr)
if not win[hwnd] then
win[hwnd] = true
end
end
local x, y = reaper.GetMousePosition()
local child = reaper.JS_Window_FromPoint(x, y)
if win[child] then
reaper.JS_Window_SetFocus(child)
else
local parent = reaper.JS_Window_GetParent(parent)
local tries = 0
while parent ~= nil do
tries = tries + 1
if tries == 5 then break end
if win[parent] then
reaper.JS_Window_SetFocus(parent)
break
else
parent = reaper.JS_Window_GetParent(parent)
end
end
end
end
reaper.defer(Main)
end
Last edited by amagalma; 11-06-2020 at 12:05 PM.
|
|
|
11-06-2020, 09:33 AM
|
#5
|
Human being with feelings
Join Date: Oct 2011
Posts: 2,924
|
Thx you. Sadly, it doesn't work. I would like to be able to focus the window which is under the mouse cursor (FX track window, main window, midi window). So I have linked your script to L, but when i press L, it doesn't focus on the good window.
|
|
|
11-06-2020, 10:11 AM
|
#6
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
I thought you were trying to automatically focus the window under the mouse, if it was the main or a midi editor. That is what the script does, no need to press anything.
If you need to press a key to focus a window, why not just click it?
|
|
|
11-06-2020, 10:45 AM
|
#7
|
Human being with feelings
Join Date: Oct 2011
Posts: 2,924
|
Quote:
I thought you were trying to automatically focus the window under the mouse, if it was the main or a midi editor.
|
Yes. But I want a script which i will execute with an action. I don't want to have to activate any script at the start of Reaper.
Quote:
That is what the script does, no need to press anything.
|
Ok, I have installed your script inside the main action. I have started your script, but it doesn't automatically focus. When my mouse in under the main or the midi editor, it happens nothing. My midi editor and FX track are docked.
To be clear, what I want:
I have setted "grid : set to 1" to G, inside main action and midi action. So, if the main window is focused and if I press G, it will change the main grid. If the midi editor is focused and if I press G, it will change the midi editor grid. So, I would like to make a custom action like this :
- Script to focus main or midi window under mouse
- grid : set to 1
So I have not to click on the good window to execute the good action.
Last edited by ovnis; 11-06-2020 at 11:00 AM.
|
|
|
11-06-2020, 11:20 AM
|
#8
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,630
|
The script will not work in the midi editor unless you add it as action to the midi-editor-section(and add the shortcut there) as well, when you want to run it via shortcut.
If I understood it correctly.
|
|
|
11-06-2020, 12:03 PM
|
#9
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Try this (edited):
Code:
local win = {}
local main_hwnd = reaper.GetMainHwnd()
local start = reaper.time_precise()
local frequency = 1/7
function Main()
local time = reaper.time_precise()
local focused_win = reaper.JS_Window_GetFocus()
if time >= start + frequency then
start = time
local _, list = reaper.JS_MIDIEditor_ListAll()
for adr in list:gmatch("[^,]+") do
local hwnd = reaper.JS_Window_HandleFromAddress(adr)
if not win[hwnd] then
win[hwnd] = true
end
end
local x, y = reaper.GetMousePosition()
local window = reaper.JS_Window_FromPoint(x, y)
if (win[window] or window == main_hwnd) and window ~= focused_win then
reaper.JS_Window_SetFocus(window)
else
local parent = reaper.JS_Window_GetParent( window )
if reaper.JS_Window_GetClassName( parent ) == "REAPERmidieditorwnd" and
parent ~= focused_win
then
reaper.JS_Window_SetFocus(window)
elseif (parent == main_hwnd or win[parent]) and parent ~= focused_win then
reaper.JS_Window_SetFocus(parent)
end
end
end
reaper.defer(Main)
end
Main()
This automatically focuses main or midi editor under mouse. It does not focus automatically any other window.
Last edited by amagalma; 11-06-2020 at 01:26 PM.
|
|
|
11-06-2020, 12:30 PM
|
#10
|
Human being with feelings
Join Date: Oct 2011
Posts: 2,924
|
From main focused to midi > OK
From main focused to midi docked > issue
From midi focused (docked or not) to main > issue
From FX window focused (docked or not) to main or midi docked > issue (it will always focus on the midi window no docked)
Last edited by ovnis; 11-06-2020 at 12:37 PM.
|
|
|
11-06-2020, 12:58 PM
|
#11
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Yes.. I think maybe it will be just easier to make a script with all the windows that can be focused (either specifying them by name, or class) and check if the window at point is one of them.
Edit. Try the code above.. still doesn't work when ME is docked but works in other occasions..
Last edited by amagalma; 11-06-2020 at 01:17 PM.
|
|
|
11-06-2020, 01:22 PM
|
#12
|
Human being with feelings
Join Date: Oct 2011
Posts: 2,924
|
Quote:
Originally Posted by amagalma
still doesn't work when ME is docked but works in other occasions..
|
Nop.
From midi focused (docked or not) to main > issue
From FX window focused (docked or not) to main or midi docked > issue (it will always focus on the midi window no docked)
|
|
|
11-06-2020, 01:26 PM
|
#13
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
|
|
|
11-06-2020, 01:40 PM
|
#14
|
Human being with feelings
Join Date: Oct 2011
Posts: 2,924
|
It's impossible to focus the main window (midi editor is always focused). And to work with docked editor midi is very important for me.
Last edited by ovnis; 11-06-2020 at 01:46 PM.
|
|
|
11-06-2020, 01:49 PM
|
#15
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Last version for today:
Code:
local win = {}
local main_hwnd = reaper.GetMainHwnd()
local start = reaper.time_precise()
local frequency = 1/7
local classes = {
REAPERTCPDisplay = true,
REAPERTrackListWindow = true,
REAPERVirtWndDlgHost = true,
REAPERTimeDisplay = true,
REAPERmidieditorwnd = true
}
function Main()
local time = reaper.time_precise()
local focused_win = reaper.JS_Window_GetFocus()
if time >= start + frequency then
start = time
local _, list = reaper.JS_MIDIEditor_ListAll()
for adr in list:gmatch("[^,]+") do
local hwnd = reaper.JS_Window_HandleFromAddress(adr)
if not win[hwnd] then
win[hwnd] = true
end
end
local x, y = reaper.GetMousePosition()
local window = reaper.JS_Window_FromPoint(x, y)
if (win[window] or window == main_hwnd) and window ~= focused_win then
reaper.JS_Window_SetFocus(window)
CASE = 1
else
local parent = reaper.JS_Window_GetParent( window )
if classes[reaper.JS_Window_GetClassName( parent )] or
classes[reaper.JS_Window_GetClassName( window )] and
parent ~= focused_win
then
reaper.JS_Window_SetFocus(window)
CASE = 2
elseif ( win[parent]) and parent ~= focused_win then
reaper.JS_Window_SetFocus(parent)
CASE = 3
end
end
end
reaper.defer(Main)
end
Main()
|
|
|
11-06-2020, 02:15 PM
|
#16
|
Human being with feelings
Join Date: Oct 2011
Posts: 2,924
|
Great! It works. Thx you very much!
Last edited by ovnis; 11-06-2020 at 02:42 PM.
|
|
|
11-06-2020, 02:46 PM
|
#17
|
Human being with feelings
Join Date: Oct 2011
Posts: 2,924
|
There is one issue: inside the main window, after having opened, routing window and envelope window disappear. Maybe because, the main window is always focused?
To solve this issue, it could be possible to have a script which focused the window only once?
custom action:
-the script
-the action
Or maybe a script which stops to focus, once it knows that the good window is already focused ?
Last edited by ovnis; 11-06-2020 at 03:21 PM.
|
|
|
11-07-2020, 01:01 AM
|
#18
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Quote:
Originally Posted by ovnis
To solve this issue, it could be possible to have a script which focused the window only once?
|
Code:
local window = reaper.JS_Window_FromPoint(reaper.GetMousePosition())
if window then
reaper.JS_Window_SetFocus(window)
end
reaper.defer(function() end)
|
|
|
11-07-2020, 03:36 AM
|
#19
|
Human being with feelings
Join Date: Oct 2011
Posts: 2,924
|
Hello, thanks for your time!
This last script doesn't work from FX window to midi window. The main window is always focused.
And this solution with your long script?
Quote:
Or maybe a script which stops to focus, once it knows that the good window is already focused?
|
Or an another idea?
Last edited by ovnis; 11-07-2020 at 05:07 AM.
|
|
|
11-07-2020, 10:09 AM
|
#20
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
If all this is in order to save you from clicking once with the mouse, have you considered using this action in your custom actions?:
SWS/S&M: Left mouse click at cursor position (use w/o modifier)
|
|
|
11-07-2020, 11:32 AM
|
#21
|
Human being with feelings
Join Date: Oct 2011
Posts: 2,924
|
Hi, I've already test this but it's not good because it can unintentionally select notes, track, item or create note if we click fast. I've tested with the middle mouse button with ICUE, too. But, that works for the main window but not for the midi editor. I have tested with the right click then delete (to close the contextual menu), but sometimes, there are glitchs.
Your last long script is almost perfect! You can't improve it?
The issue with your long script: inside the main window, after having opened, routing window and envelope window disappear if the mouse cursor is outside the two windows.
When the main window is focused, routing window and envelope window disappear.
If the mouse cursor stays on routing window or envelope window : OK
It the mouse cursor is outside the two windows : issue. Window vanishes.
There should be 2 scripts? One which is started at the start of Reaper and scans continuously the position of the mouse over windows and a second script which is launched when we want to focus a window (a custom action with this second script + the action)?
Last edited by ovnis; 11-07-2020 at 11:52 AM.
|
|
|
11-08-2020, 01:31 AM
|
#22
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Try this:
Code:
local win = {}
local main_hwnd = reaper.GetMainHwnd()
local start = reaper.time_precise()
local frequency = 1/7
local classes = {
REAPERTCPDisplay = true,
REAPERTrackListWindow = true,
REAPERVirtWndDlgHost = true,
REAPERTimeDisplay = true,
REAPERmidieditorwnd = true
}
function Main()
local time = reaper.time_precise()
local focused_win = reaper.JS_Window_GetFocus()
local title = reaper.JS_Window_GetTitle( focused_win )
local title_parent = reaper.JS_Window_GetTitle( reaper.JS_Window_GetParent( focused_win ) )
if title:find"Envelopes for " or title_parent:find"Envelopes for "
or title:find"Routing for track " or title_parent:find"Routing for track "
or title:find"Outputs for Master Track" or title_parent:find"Outputs for Master Track"
or reaper.JS_Window_GetClassName( focused_win ) == "Edit"
then
start = time
end
if time >= start + frequency then
start = time
local _, list = reaper.JS_MIDIEditor_ListAll()
for adr in list:gmatch("[^,]+") do
local hwnd = reaper.JS_Window_HandleFromAddress(adr)
if not win[hwnd] then
win[hwnd] = true
end
end
local x, y = reaper.GetMousePosition()
local window = reaper.JS_Window_FromPoint(x, y)
if (win[window] or window == main_hwnd) and window ~= focused_win then
reaper.JS_Window_SetFocus(window)
else
local parent = reaper.JS_Window_GetParent( window )
if classes[reaper.JS_Window_GetClassName( parent )] or
classes[reaper.JS_Window_GetClassName( window )] and
parent ~= focused_win
then
reaper.JS_Window_SetFocus(window)
elseif ( win[parent]) and parent ~= focused_win then
reaper.JS_Window_SetFocus(parent)
end
end
end
reaper.defer(Main)
end
Main()
Last edited by amagalma; 11-08-2020 at 04:18 AM.
|
|
|
11-08-2020, 03:36 AM
|
#23
|
Human being with feelings
Join Date: Mar 2017
Location: Ukraine, Kyiv
Posts: 546
|
Quote:
Originally Posted by amagalma
Try this:
Code:
function Main()
local time = reaper.time_precise()
local focused_win = reaper.JS_Window_GetFocus()
local title = reaper.JS_Window_GetTitle( focused_win )
local title_parent = reaper.JS_Window_GetTitle( reaper.JS_Window_GetParent( focused_win ) )
if title:find"Envelopes for " or title_parent:find"Envelopes for "
or title:find"Routing for track " or title_parent:find"Routing for track "
or title:find"Outputs for Master Track" or title_parent:find"Outputs for Master Track"
or reaper.JS_Window_GetClassName( focused_win ) == "Edit"
then
start = time
end
if time >= start + frequency then
start = time
local _, list = reaper.JS_MIDIEditor_ListAll()
for adr in list:gmatch("[^,]+") do
local hwnd = reaper.JS_Window_HandleFromAddress(adr)
if not win[hwnd] then
win[hwnd] = true
end
end
local x, y = reaper.GetMousePosition()
local window = reaper.JS_Window_FromPoint(x, y)
if (win[window] or window == main_hwnd) and window ~= focused_win then
reaper.JS_Window_SetFocus(window)
else
local parent = reaper.JS_Window_GetParent( window )
if classes[reaper.JS_Window_GetClassName( parent )] or
classes[reaper.JS_Window_GetClassName( window )] and
parent ~= focused_win
then
reaper.JS_Window_SetFocus(window)
elseif ( win[parent]) and parent ~= focused_win then
reaper.JS_Window_SetFocus(parent)
end
end
end
reaper.defer(Main)
end
Main()
|
|
|
|
11-08-2020, 04:19 AM
|
#24
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Oops.. sorry! I didn't copy paste the whole of it!
Now the whole thing is up there
|
|
|
11-08-2020, 05:17 AM
|
#25
|
Human being with feelings
Join Date: Oct 2011
Posts: 2,924
|
Hi, it's almost perfect. But
routing window or envelope window to main or ME: issue. Theses windows are not focused when we want to use an action.
Last edited by ovnis; 11-08-2020 at 05:29 AM.
|
|
|
11-08-2020, 05:29 AM
|
#26
|
Human being with feelings
Join Date: Oct 2011
Posts: 2,924
|
Maybe 2 scripts will be a good idea?
A continue script which will scan continuously the position of the mouse over windows and one script (it will focus the good window with the help of the first script) which will be activate when we want to use an action inside a custom action (the script + the action).
|
|
|
11-08-2020, 06:46 AM
|
#27
|
Human being with feelings
Join Date: Mar 2017
Location: Ukraine, Kyiv
Posts: 546
|
Quote:
Originally Posted by ovnis
Hi, it's almost perfect. But
routing window or envelope window to main or ME: issue. Theses windows are not focused when we want to use an action.
|
Can you please provide an example more specificly about the actions you try to use?
|
|
|
11-08-2020, 08:22 AM
|
#28
|
Human being with feelings
Join Date: Oct 2011
Posts: 2,924
|
Set the grid, for exemple.
|
|
|
12-19-2020, 03:17 PM
|
#29
|
Human being with feelings
Join Date: Oct 2011
Posts: 2,924
|
Hello amagalma!
I have found an issue with the scrip (pan window disapears when the mouse cursor is outside):
|
|
|
01-08-2021, 08:26 PM
|
#30
|
Human being with feelings
Join Date: Oct 2011
Posts: 2,924
|
Hello, there is an issue with the snap/grid settings window, too:
|
|
|
01-09-2021, 02:01 AM
|
#31
|
Human being with feelings
Join Date: Mar 2017
Location: Ukraine, Kyiv
Posts: 546
|
Quote:
Originally Posted by ovnis
Hello, there is an issue with the snap/grid settings window, too:
|
Try this action: Script: Archie_Pref; Toggle Allow snap grid,track envelope,routing windows to stay open.lua
|
|
|
03-02-2021, 11:01 AM
|
#32
|
Human being with feelings
Join Date: Mar 2017
Location: Ukraine, Kyiv
Posts: 546
|
Hi amagalma! Could you please look at the issues which ovnis described?
|
|
|
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 11:19 PM.
|