-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggle_focus_midi.lua
More file actions
101 lines (86 loc) · 3.12 KB
/
toggle_focus_midi.lua
File metadata and controls
101 lines (86 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
function Msg(param)
if false then
reaper.ShowConsoleMsg(tostring(param) .. "\n")
end
end
function GetMidiEditorHwnd()
local arr = reaper.new_array({}, 1)
reaper.JS_MIDIEditor_ArrayAll(arr)
local adr = arr.table()
if adr[1] then
return reaper.JS_Window_HandleFromAddress(adr[1])
end
return nil
end
function ReaticulateMain()
if not ReaticulateCommandId then
ReaticulateCommandId = reaper.NamedCommandLookup("_RSbe259504561f6a52557d2d1c64e52ef13527bf17")
end
if reaper.ReverseNamedCommandLookup(ReaticulateCommandId) then
reaper.Main_OnCommand(ReaticulateCommandId, 0)
else
reaper.ShowConsoleMsg("Invalid action " .. ReaticulateCommandId .. "\n")
end
end
function ReaticulateState(show)
local reaticulate_hwnd = reaper.JS_Window_Find("Reaticulate", true)
-- check if reaticulate is visible
if reaticulate_hwnd then
if show then
-- reaticulate is running but is hidden
if reaper.HasExtState("ovaska", "reaticulate_invisible") then
reaper.DeleteExtState("ovaska", "reaticulate_invisible", false)
reaper.JS_Window_SetOpacity(reaticulate_hwnd, "ALPHA", 1)
end
else
-- reaticulate is running but should be hidden
Msg("Hiding reaticulate")
reaper.SetExtState("ovaska", "reaticulate_invisible", "true", false)
reaper.JS_Window_SetOpacity(reaticulate_hwnd, "ALPHA", 0)
end
else
-- reaticulate is not open
reaper.DeleteExtState("ovaska", "reaticulate_invisible", false)
-- ensure midi editor is focused after reaticulate window pops up
if show then
Msg("Showing reaticulate..")
ReaticulateMain()
reaper.defer(reaper.SN_FocusMIDIEditor)
end
end
end
function EnsureMidiWindowVisible(hwnd)
Msg(reaper.HasExtState("ovaska", "midi_invisible"))
hwnd = hwnd or GetMidiEditorHwnd()
if hwnd and reaper.HasExtState("ovaska", "midi_invisible") then
reaper.DeleteExtState("ovaska", "midi_invisible", false)
reaper.JS_Window_SetOpacity(hwnd, "ALPHA", 1)
end
end
function HideMidiWindow(hwnd)
reaper.SetExtState("ovaska", "midi_invisible", "true", false)
reaper.JS_Window_SetOpacity(hwnd, "ALPHA", 0)
end
function Execute()
local hwnd = GetMidiEditorHwnd()
if hwnd then
if hwnd == reaper.BR_Win32_GetForegroundWindow() then
Msg("Is focused, hiding midi window")
HideMidiWindow(hwnd)
ReaticulateState(false)
reaper.BR_Win32_SetFocus(reaper.GetMainHwnd())
else
Msg("Is open but not focused, focusing")
EnsureMidiWindowVisible(hwnd)
reaper.SN_FocusMIDIEditor()
ReaticulateState(true)
end
else
Msg("Not visible, opening midi editor")
reaper.Main_OnCommand(40716, 0)
ReaticulateState(true)
reaper.defer(EnsureMidiWindowVisible)
end
end
ReaticulateCommandId = nil
Execute()