|
|
|
11-29-2022, 10:04 AM
|
#41
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,612
|
Quote:
Originally Posted by ferropop
Super curious about this but can't get any of it to work.
Set up my code to solve a Window Focus issue that's been driving me crazy. I have an action to Play From Mouse Cursor which is incredibly useful - both a "from nearest gridline" and "no snap" versions. Unfortunately I had to create different sets for Arrange and MIDI Editor, and the quirk is that it operates on the currently focused window independent of your mouse position. So if you were just working in MIDI Editor and mouse over Arrange and run the action, it's still operating on MIDI Editor.
I just want the MIDI Editor version to run when mouse is over MIDI Editor, and Arrange when cursor is over Arrange.
|
Why not modifying the script in question?
The following code-example shows you, how to differentiate between the two:
Code:
function main()
local x,y=reaper.GetMousePosition()
local hwnd=reaper.JS_Window_FromPoint(x,y)
if hwnd==reaper.MIDIEditor_GetActive() or
reaper.JS_Window_GetParent(hwnd)==reaper.MIDIEditor_GetActive() then
-- do what you want to achieve with the midi-editor
reaper.ClearConsole()
reaper.ShowConsoleMsg("MIDI")
else
-- do what you want to the arrangeview
reaper.ClearConsole()
reaper.ShowConsoleMsg("Not Midi")
end
reaper.defer(main)
end
main()
Needs JS-extension to be installed. Maybe you can adapt it for your script...
|
|
|
11-29-2022, 11:02 AM
|
#42
|
Human being with feelings
Join Date: Jan 2016
Location: Los Angeles, CA
Posts: 3,112
|
Quote:
Originally Posted by Meo-Ada Mespotine
Why not modifying the script in question?
The following code-example shows you, how to differentiate between the two:
Code:
function main()
local x,y=reaper.GetMousePosition()
local hwnd=reaper.JS_Window_FromPoint(x,y)
if hwnd==reaper.MIDIEditor_GetActive() or
reaper.JS_Window_GetParent(hwnd)==reaper.MIDIEditor_GetActive() then
-- do what you want to achieve with the midi-editor
reaper.ClearConsole()
reaper.ShowConsoleMsg("MIDI")
else
-- do what you want to the arrangeview
reaper.ClearConsole()
reaper.ShowConsoleMsg("Not Midi")
end
reaper.defer(main)
end
main()
Needs JS-extension to be installed. Maybe you can adapt it for your script...
|
Oh wow thanks Mespotine! This is really great and will help in de-duplicating so much stuff!
Last edited by ferropop; 11-29-2022 at 11:37 AM.
|
|
|
11-29-2022, 11:37 AM
|
#43
|
Human being with feelings
Join Date: Jan 2016
Location: Los Angeles, CA
Posts: 3,112
|
If you don't mind helping troubleshoot - it seems that this action is running nonstop in a loop, instead of just once. Am I missing something?
Code:
function main()
local x,y=reaper.GetMousePosition()
local hwnd=reaper.JS_Window_FromPoint(x,y)
if hwnd==reaper.MIDIEditor_GetActive() or
reaper.JS_Window_GetParent(hwnd)==reaper.MIDIEditor_GetActive() then
-- do what you want to achieve with the midi-editor
--reaper.ClearConsole()
--reaper.ShowConsoleMsg("MIDI")
reaper.Main_OnCommand(reaper.NamedCommandLookup('_d1c480df03c95a4d9432cd0c63872985'), 0)
else
-- do what you want to the arrangeview
reaper.Main_OnCommand(reaper.NamedCommandLookup('_9001005b43df8445a7111931a05ca0f5'), 0)
--reaper.Main_OnCommand(RPR_NamedCommandLookup(command_id), 0) -- Unsolo all tracks
--reaper.ShowConsoleMsg("Not Midi")
end
reaper.defer(main)
end
main()
|
|
|
11-29-2022, 11:42 AM
|
#44
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,612
|
Yes...wait a sec, I give you a variant that runs only once:
Code:
local x,y=reaper.GetMousePosition()
local hwnd=reaper.JS_Window_FromPoint(x,y)
if hwnd==reaper.MIDIEditor_GetActive() or
reaper.JS_Window_GetParent(hwnd)==reaper.MIDIEditor_GetActive() then
-- do what you want to achieve with the midi-editor
--reaper.ClearConsole()
--reaper.ShowConsoleMsg("MIDI")
reaper.Main_OnCommand(reaper.NamedCommandLookup('_d1c480df03c95a4d9432cd0c63872985'), 0)
else
-- do what you want to the arrangeview
reaper.Main_OnCommand(reaper.NamedCommandLookup('_9001005b43df8445a7111931a05ca0f5'), 0)
--reaper.Main_OnCommand(RPR_NamedCommandLookup(command_id), 0) -- Unsolo all tracks
--reaper.ShowConsoleMsg("Not Midi")
end
Does this do it?
|
|
|
11-29-2022, 11:52 AM
|
#45
|
Human being with feelings
Join Date: Jan 2016
Location: Los Angeles, CA
Posts: 3,112
|
Quote:
Originally Posted by Meo-Ada Mespotine
Yes...wait a sec, I give you a variant that runs only once:
Does this do it?
|
Works perfectly when mousing over Arrange, but not over MIDI Editor.
ps thank you so much!
|
|
|
11-29-2022, 11:57 AM
|
#46
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,612
|
Can you try this one and see, if the console outputs MIDI ?
Code:
local x,y=reaper.GetMousePosition()
local hwnd=reaper.JS_Window_FromPoint(x,y)
if hwnd==reaper.MIDIEditor_GetActive() or
reaper.JS_Window_GetParent(hwnd)==reaper.MIDIEditor_GetActive() or
reaper.JS_Window_GetParent(reaper.JS_Window_GetParent(hwnd))==reaper.MIDIEditor_GetActive()
then
-- do what you want to achieve with the midi-editor
reaper.ClearConsole()
reaper.ShowConsoleMsg("MIDI")
reaper.Main_OnCommand(reaper.NamedCommandLookup('_d1c480df03c95a4d9432cd0c63872985'), 0)
else
-- do what you want to the arrangeview
reaper.Main_OnCommand(reaper.NamedCommandLookup('_9001005b43df8445a7111931a05ca0f5'), 0)
reaper.Main_OnCommand(RPR_NamedCommandLookup(command_id), 0) -- Unsolo all tracks
reaper.ShowConsoleMsg("Not Midi")
end
|
|
|
11-29-2022, 12:55 PM
|
#47
|
Human being with feelings
Join Date: Jan 2016
Location: Los Angeles, CA
Posts: 3,112
|
yes but still doesn't work on the MIDI Editor.
I'm on the right path - should be using MIDIEditor_on_command instead of MAIN (for the MIDI part)... but their parameters are different so just working it out.
Not a scripter haha, just kinda mucking around here.
|
|
|
11-29-2022, 01:33 PM
|
#48
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,612
|
Better use MIDIEditor_LastFocused_OnCommand. It's easier to use.
|
|
|
11-29-2022, 02:05 PM
|
#49
|
Human being with feelings
Join Date: Jan 2016
Location: Los Angeles, CA
Posts: 3,112
|
Quote:
Originally Posted by Meo-Ada Mespotine
Better use MIDIEditor_LastFocused_OnCommand. It's easier to use.
|
Thank you! It's basically working, but one interesting quirk:
if running fresh after opening Reaper, for some reason it's incorrectly returning MIDI to the console, even though a MIDI editor hasn't even been created and it's actually over arrange. Once creating some MIDI and opening midi editor, the script works perfectly.
|
|
|
11-29-2022, 02:40 PM
|
#50
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,612
|
Ok, I rewrote it from scratch. This one should work.
Code:
main_command=reaper.NamedCommandLookup('_9001005b43df8445a7111931a05ca0f5')
midi_command=reaper.NamedCommandLookup('_d1c480df03c95a4d9432cd0c63872985')
local x,y=reaper.GetMousePosition()
hwnd=reaper.JS_Window_FromPoint(x,y)
hwnd2=reaper.JS_Window_GetParent(hwnd)
midihwnd=reaper.MIDIEditor_GetActive()
if midihwnd==nil then
reaper.ClearConsole()
reaper.ShowConsoleMsg("Not MIDI")
reaper.Main_OnCommand(main_command, 0)
elseif hwnd==midihwnd or hwnd2==midihwnd then
reaper.ClearConsole()
reaper.ShowConsoleMsg("MIDI")
reaper.MIDIEditor_LastFocused_OnCommand(midi_command, false)
else
reaper.ClearConsole()
reaper.ShowConsoleMsg("Not MIDI")
reaper.Main_OnCommand(main_command, 0)
end
Going to bed now, but I hope, I got it....
|
|
|
11-29-2022, 02:49 PM
|
#51
|
Human being with feelings
Join Date: Jan 2016
Location: Los Angeles, CA
Posts: 3,112
|
Quote:
Originally Posted by Meo-Ada Mespotine
Ok, I rewrote it from scratch. This one should work.
Going to bed now, but I hope, I got it....
|
Legend, thank you again! It works!
Now on to fix the Media Explorer play action . This template is perfect, much appreciated and hopefully helps others out there.
|
|
|
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 06:55 PM.
|