From 7482e1d3f399880d7b25f5387f46ab612429c469 Mon Sep 17 00:00:00 2001 From: tuomiorava Date: Thu, 18 Jul 2024 15:11:22 +0300 Subject: [PATCH] Updated DoomSquirrel_Performance Arm track for MIDI * = Scroll track into view --- ...e Arm track for MIDI (sequential name).lua | 83 ++++++++++++++++- ...rmance Arm track for MIDI (sequential).lua | 89 +++++++++++++++++-- ...mance Arm track for MIDI (under mouse).lua | 83 ++++++++++++++++- 3 files changed, 240 insertions(+), 15 deletions(-) diff --git a/Tracks/DoomSquirrel_Performance Arm track for MIDI (sequential name).lua b/Tracks/DoomSquirrel_Performance Arm track for MIDI (sequential name).lua index ed0c990..a2e172e 100644 --- a/Tracks/DoomSquirrel_Performance Arm track for MIDI (sequential name).lua +++ b/Tracks/DoomSquirrel_Performance Arm track for MIDI (sequential name).lua @@ -29,10 +29,9 @@ -- My music = http://iki.fi/atolonen -- @donation -- Donate via PayPal https://www.paypal.com/donate/?hosted_button_id=2BEA2GHZMAW9A --- @version 1.3 +-- @version 1.4 -- @changelog --- Customizable rocord monitoring mode (RECMON_ACTIVE) --- Allow Performance Arming when project has only one track +-- Scroll track into view (customizable with the *_SCROLL_TRACK_TO_VIEW & *_ALWAYS_SCROLL_TO_* User Settings) ---------------------------- --- USER SETTINGS ---------- @@ -49,6 +48,12 @@ RECINPUT_DEFAULT = nil -- Default = nil, 0: Input:Mono / In 1 -- The record monitoring to set when Performance Arming a track RECMON_ACTIVE = 1 -- Default = 1: On +-- Whether to scroll the Performance Armed track into view +TCP_SCROLL_TRACK_TO_VIEW = true -- For Track Control Panel +TCP_ALWAYS_SCROLL_TO_TOP = false -- If true, always scrolls the Performance Armed track to the top of the arrange view. If false: only scrolls when the track is out of view +MCP_SCROLL_TRACK_TO_VIEW = true -- For Mixer Control Panel +MCP_ALWAYS_SCROLL_TO_LEFT = false -- If true, always scrolls the Performance Armed track to the left of the mixer view. If false: only scrolls when the track is out of view + -- The selected track idx (order number amongst all instrument tracks) SELECTED_IDX = nil -- When nil, gets the idx from the pressed hotkey @@ -72,6 +77,67 @@ function HasInstrument(track) return false end +function getClientWidth(hwnd) + local _, l, t, r, b = reaper.JS_Window_GetClientRect(hwnd) + return r-l +end + +function getClientHeight(hwnd) + local _, l, t, r, b = reaper.JS_Window_GetClientRect(hwnd) + return b-t +end + +function tcp_isTrackInView(track) + local arrangeHWND = reaper.JS_Window_FindChildByID(reaper.GetMainHwnd(), 0x3E8) + local arrange_height = getClientHeight(arrangeHWND) + local track_tcpy = reaper.GetMediaTrackInfo_Value(track, "I_TCPY") + local track_wndh = reaper.GetMediaTrackInfo_Value(track, "I_WNDH") + + if (track_tcpy > 0 and (track_tcpy + track_wndh < arrange_height)) then + return true + else + return false + end +end + +function mcp_isTrackInView(track) + local mixerHWND, _ = reaper.BR_Win32_GetMixerHwnd() + if (not mixerHWND) then + return false + end + + -- Deduct Master track width from available mixer width + mtr_mcpw = 0 + local mtrvis = reaper.GetMasterTrackVisibility() + + if (mtrvis ~= 2) then + mtr_mcpw = reaper.GetMediaTrackInfo_Value(reaper.GetMasterTrack(0), "I_MCPW") + end + + local track_mcpx = reaper.GetMediaTrackInfo_Value(track, "I_MCPX") + local track_mcpw = reaper.GetMediaTrackInfo_Value(track, "I_MCPW") + local mixer_width = getClientWidth(mixerHWND) + + if (track_mcpx > 0 and (track_mcpx + track_mcpw < (mixer_width - mtr_mcpw))) then + return true + else + return false + end +end + +function tcp_scrollTrackToTop(track) + reaper.PreventUIRefresh(1) + + local arrangeHWND = reaper.JS_Window_FindChildByID(reaper.GetMainHwnd(), 0x3E8) + local _, scroll_pos = reaper.JS_Window_GetScrollInfo(arrangeHWND, "v") + local track_tcpy = reaper.GetMediaTrackInfo_Value(track, "I_TCPY") + reaper.JS_Window_SetScrollPos(arrangeHWND, "v", track_tcpy + scroll_pos) + + reaper.PreventUIRefresh(-1) +end + + + function getIdxByKey() -- Note: Shortcut scope must be set to Normal or keys will not be detected! local state = reaper.JS_VKeys_GetState(0) @@ -126,6 +192,13 @@ function performanceArmTrack(selIdx) if (i_RecInputVal < 4096) then reaper.SetMediaTrackInfo_Value(tr, 'I_RECINPUT', RECINPUT_ACTIVE ) end + + if (TCP_SCROLL_TRACK_TO_VIEW and (TCP_ALWAYS_SCROLL_TO_TOP or not tcp_isTrackInView(tr))) then + tcp_scrollTrackToTop(tr) + end + if (MCP_SCROLL_TRACK_TO_VIEW and (MCP_ALWAYS_SCROLL_TO_LEFT or not mcp_isTrackInView(tr))) then + reaper.SetMixerScroll(tr) + end else local i_RecArmVal = reaper.GetMediaTrackInfo_Value(tr, 'I_RECARM') local i_RecMonVal = reaper.GetMediaTrackInfo_Value(tr, 'I_RECMON') @@ -147,8 +220,10 @@ function performanceArmTrack(selIdx) end end +reaper.Undo_BeginBlock() if (not SELECTED_IDX) then getIdxByKey() end -performanceArmTrack(SELECTED_IDX) \ No newline at end of file +performanceArmTrack(SELECTED_IDX) +reaper.Undo_EndBlock("Performance Arm track for MIDI (sequential name)", -1) \ No newline at end of file diff --git a/Tracks/DoomSquirrel_Performance Arm track for MIDI (sequential).lua b/Tracks/DoomSquirrel_Performance Arm track for MIDI (sequential).lua index ffee510..786cd1e 100644 --- a/Tracks/DoomSquirrel_Performance Arm track for MIDI (sequential).lua +++ b/Tracks/DoomSquirrel_Performance Arm track for MIDI (sequential).lua @@ -27,10 +27,9 @@ -- My music = http://iki.fi/atolonen -- @donation -- Donate via PayPal https://www.paypal.com/donate/?hosted_button_id=2BEA2GHZMAW9A --- @version 1.3 +-- @version 1.4 -- @changelog --- Customizable rocord monitoring mode (RECMON_ACTIVE) --- Allow Performance Arming when project has only one track +-- Scroll track into view (customizable with the *_SCROLL_TRACK_TO_VIEW & *_ALWAYS_SCROLL_TO_* User Settings) ---------------------------- --- USER SETTINGS ---------- @@ -44,6 +43,12 @@ RECINPUT_DEFAULT = nil -- Default = nil, 0: Input:Mono / In 1 -- The record monitoring to set when Performance Arming a track RECMON_ACTIVE = 1 -- Default = 1: On +-- Whether to scroll the Performance Armed track into view +TCP_SCROLL_TRACK_TO_VIEW = true -- For Track Control Panel +TCP_ALWAYS_SCROLL_TO_TOP = false -- If true, always scrolls the Performance Armed track to the top of the arrange view. If false: only scrolls when the track is out of view +MCP_SCROLL_TRACK_TO_VIEW = true -- For Mixer Control Panel +MCP_ALWAYS_SCROLL_TO_LEFT = false -- If true, always scrolls the Performance Armed track to the left of the mixer view. If false: only scrolls when the track is out of view + -- The selected track idx (order number amongst all instrument tracks) SELECTED_IDX = nil -- When nil, gets the idx from the pressed hotkey @@ -51,10 +56,6 @@ SELECTED_IDX = nil -- When nil, gets the idx from the pressed hotkey --- END OF USER SETTINGS --- ---------------------------- -local function Msg(v) - reaper.ShowConsoleMsg(tostring(v).."\n") -end - function IsInstrument(track, fx) local fx_instr = reaper.TrackFX_GetInstrument(track) return fx_instr >= fx @@ -71,6 +72,67 @@ function HasInstrument(track) return false end +function getClientWidth(hwnd) + local _, l, t, r, b = reaper.JS_Window_GetClientRect(hwnd) + return r-l +end + +function getClientHeight(hwnd) + local _, l, t, r, b = reaper.JS_Window_GetClientRect(hwnd) + return b-t +end + +function tcp_isTrackInView(track) + local arrangeHWND = reaper.JS_Window_FindChildByID(reaper.GetMainHwnd(), 0x3E8) + local arrange_height = getClientHeight(arrangeHWND) + local track_tcpy = reaper.GetMediaTrackInfo_Value(track, "I_TCPY") + local track_wndh = reaper.GetMediaTrackInfo_Value(track, "I_WNDH") + + if (track_tcpy > 0 and (track_tcpy + track_wndh < arrange_height)) then + return true + else + return false + end +end + +function mcp_isTrackInView(track) + local mixerHWND, _ = reaper.BR_Win32_GetMixerHwnd() + if (not mixerHWND) then + return false + end + + -- Deduct Master track width from available mixer width + mtr_mcpw = 0 + local mtrvis = reaper.GetMasterTrackVisibility() + + if (mtrvis ~= 2) then + mtr_mcpw = reaper.GetMediaTrackInfo_Value(reaper.GetMasterTrack(0), "I_MCPW") + end + + local track_mcpx = reaper.GetMediaTrackInfo_Value(track, "I_MCPX") + local track_mcpw = reaper.GetMediaTrackInfo_Value(track, "I_MCPW") + local mixer_width = getClientWidth(mixerHWND) + + if (track_mcpx > 0 and (track_mcpx + track_mcpw < (mixer_width - mtr_mcpw))) then + return true + else + return false + end +end + +function tcp_scrollTrackToTop(track) + reaper.PreventUIRefresh(1) + + local arrangeHWND = reaper.JS_Window_FindChildByID(reaper.GetMainHwnd(), 0x3E8) + local _, scroll_pos = reaper.JS_Window_GetScrollInfo(arrangeHWND, "v") + local track_tcpy = reaper.GetMediaTrackInfo_Value(track, "I_TCPY") + reaper.JS_Window_SetScrollPos(arrangeHWND, "v", track_tcpy + scroll_pos) + + reaper.PreventUIRefresh(-1) +end + + + function getIdxByKey() -- Note: Shortcut scope must be set to Normal or keys will not be detected! local state = reaper.JS_VKeys_GetState(0) @@ -124,6 +186,13 @@ function performanceArmTrack(selIdx) if (i_RecInputVal < 4096) then reaper.SetMediaTrackInfo_Value(tr, 'I_RECINPUT', RECINPUT_ACTIVE ) end + + if (TCP_SCROLL_TRACK_TO_VIEW and (TCP_ALWAYS_SCROLL_TO_TOP or not tcp_isTrackInView(tr))) then + tcp_scrollTrackToTop(tr) + end + if (MCP_SCROLL_TRACK_TO_VIEW and (MCP_ALWAYS_SCROLL_TO_LEFT or not mcp_isTrackInView(tr))) then + reaper.SetMixerScroll(tr) + end else local i_RecArmVal = reaper.GetMediaTrackInfo_Value(tr, 'I_RECARM') local i_RecMonVal = reaper.GetMediaTrackInfo_Value(tr, 'I_RECMON') @@ -145,8 +214,12 @@ function performanceArmTrack(selIdx) end end + + +reaper.Undo_BeginBlock() if (not SELECTED_IDX) then getIdxByKey() end -performanceArmTrack(SELECTED_IDX) \ No newline at end of file +performanceArmTrack(SELECTED_IDX) +reaper.Undo_EndBlock("Performance Arm track for MIDI (sequential)", -1) \ No newline at end of file diff --git a/Tracks/DoomSquirrel_Performance Arm track for MIDI (under mouse).lua b/Tracks/DoomSquirrel_Performance Arm track for MIDI (under mouse).lua index c509aca..5c9aee4 100644 --- a/Tracks/DoomSquirrel_Performance Arm track for MIDI (under mouse).lua +++ b/Tracks/DoomSquirrel_Performance Arm track for MIDI (under mouse).lua @@ -16,9 +16,9 @@ -- My music = http://iki.fi/atolonen -- @donation -- Donate via PayPal https://www.paypal.com/donate/?hosted_button_id=2BEA2GHZMAW9A --- @version 1.3 +-- @version 1.4 -- @changelog --- Customizable rocord monitoring mode (RECMON_ACTIVE) +-- Scroll track into view (customizable with the *_SCROLL_TRACK_TO_VIEW & *_ALWAYS_SCROLL_TO_* User Settings) ---------------------------- --- USER SETTINGS ---------- @@ -32,6 +32,12 @@ RECINPUT_DEFAULT = nil -- Default = nil, 0: Input:Mono / In 1 -- The record monitoring to set when Performance Arming a track RECMON_ACTIVE = 1 -- Default = 1: On +-- Whether to scroll the Performance Armed track into view +TCP_SCROLL_TRACK_TO_VIEW = true -- For Track Control Panel +TCP_ALWAYS_SCROLL_TO_TOP = false -- If true, always scrolls the Performance Armed track to the top of the arrange view. If false: only scrolls when the track is out of view +MCP_SCROLL_TRACK_TO_VIEW = true -- For Mixer Control Panel +TCP_ALWAYS_SCROLL_TO_LEFT = false -- If true, always scrolls the Performance Armed track to the left of the mixer view. If false: only scrolls when the track is out of view + ---------------------------- --- END OF USER SETTINGS --- ---------------------------- @@ -41,7 +47,69 @@ if (mousetr) then _, mouseTrName = reaper.GetTrackName(mousetr) end +function getClientWidth(hwnd) + local _, l, t, r, b = reaper.JS_Window_GetClientRect(hwnd) + return r-l +end + +function getClientHeight(hwnd) + local _, l, t, r, b = reaper.JS_Window_GetClientRect(hwnd) + return b-t +end + +function tcp_isTrackInView(track) + local arrangeHWND = reaper.JS_Window_FindChildByID(reaper.GetMainHwnd(), 0x3E8) + local arrange_height = getClientHeight(arrangeHWND) + local track_tcpy = reaper.GetMediaTrackInfo_Value(track, "I_TCPY") + local track_wndh = reaper.GetMediaTrackInfo_Value(track, "I_WNDH") + + if (track_tcpy > 0 and (track_tcpy + track_wndh < arrange_height)) then + return true + else + return false + end +end + +function mcp_isTrackInView(track) + local mixerHWND, _ = reaper.BR_Win32_GetMixerHwnd() + if (not mixerHWND) then + return false + end + + -- Deduct Master track width from available mixer width + mtr_mcpw = 0 + local mtrvis = reaper.GetMasterTrackVisibility() + + if (mtrvis ~= 2) then + mtr_mcpw = reaper.GetMediaTrackInfo_Value(reaper.GetMasterTrack(0), "I_MCPW") + end + + local track_mcpx = reaper.GetMediaTrackInfo_Value(track, "I_MCPX") + local track_mcpw = reaper.GetMediaTrackInfo_Value(track, "I_MCPW") + local mixer_width = getClientWidth(mixerHWND) + + if (track_mcpx > 0 and (track_mcpx + track_mcpw < (mixer_width - mtr_mcpw))) then + return true + else + return false + end +end + +function tcp_scrollTrackToTop(track) + reaper.PreventUIRefresh(1) + + local arrangeHWND = reaper.JS_Window_FindChildByID(reaper.GetMainHwnd(), 0x3E8) + local _, scroll_pos = reaper.JS_Window_GetScrollInfo(arrangeHWND, "v") + local track_tcpy = reaper.GetMediaTrackInfo_Value(track, "I_TCPY") + reaper.JS_Window_SetScrollPos(arrangeHWND, "v", track_tcpy + scroll_pos) + + reaper.PreventUIRefresh(-1) +end + + + function performanceArmTrack() + local mcctx = reaper.BR_GetMouseCursorContext() local trCount = reaper.CountTracks(0) for i = 0, trCount do @@ -59,6 +127,13 @@ function performanceArmTrack() if (i_RecInputVal < 4096) then reaper.SetMediaTrackInfo_Value(tr, 'I_RECINPUT', RECINPUT_ACTIVE ) end + + if (TCP_SCROLL_TRACK_TO_VIEW and (TCP_ALWAYS_SCROLL_TO_TOP or not tcp_isTrackInView(tr)) and mcctx == "mcp") then + tcp_scrollTrackToTop(tr) + end + if (MCP_SCROLL_TRACK_TO_VIEW and (MCP_ALWAYS_SCROLL_TO_LEFT or not mcp_isTrackInView(tr)) and (mcctx == "tcp" or mcctx == "arrange")) then + reaper.SetMixerScroll(tr) + end else local i_RecArmVal = reaper.GetMediaTrackInfo_Value(tr, 'I_RECARM') local i_RecMonVal = reaper.GetMediaTrackInfo_Value(tr, 'I_RECMON') @@ -80,4 +155,6 @@ function performanceArmTrack() end end -performanceArmTrack() \ No newline at end of file +reaper.Undo_BeginBlock() +performanceArmTrack() +reaper.Undo_EndBlock("Performance Arm track for MIDI (under mouse)", -1) \ No newline at end of file