generated from cfillion/reapack-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added DoomSquirrel_Performance Arm track for MIDI *
- Loading branch information
1 parent
8c404b1
commit 42629bd
Showing
3 changed files
with
374 additions
and
0 deletions.
There are no files selected for viewing
150 changes: 150 additions & 0 deletions
150
Tracks/DoomSquirrel_Performance Arm track for MIDI (sequential name).lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
-- @description DoomSquirrel_Performance Arm track for MIDI (sequential name) | ||
-- @author DoomSquirrel | ||
-- @license GPL v3 | ||
-- @about | ||
-- #Performance Arm track for MIDI (sequential name) | ||
-- **Performance Arm** means: | ||
-- - Arms the selected track for recording, sets its monitoring, and sets its input. | ||
-- - Unsets record arming, monitoring (and optionally sets the input to default) for the previously Performance Armed track(s). | ||
-- | ||
-- The intended use for this action is to assign sequential hotkey ranges to it, | ||
-- for example: _Numeric Keys 1-0_ or _Function Keys F1-F12_. | ||
-- Then, when you press the hotkey, it **_Performance Arms_** a track containing an instrument, | ||
-- and if the name of the track contains the string given in the TRACK_NAME_Q User setting, | ||
-- based on the sequential order of those tracks, disregarding other tracks. | ||
-- | ||
-- So, if you have 4 tracks, with tracks 2, 3 & 4 containing instruments, | ||
-- and with tracks 2 & 4 named "Instrument 1-perf" and "Instrument 2-perf" respectively, | ||
-- pressing 1 will Performance Arm track 2, and pressing 2 will Performance Arm track 4. | ||
-- | ||
-- Check USER SETTINGS for configuration options. | ||
-- | ||
-- For advanced modification of this script, you can customize the accepted key ranges in the **_getIdxByKey()_** function. | ||
-- Virtual-Key Codes reference: https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes | ||
-- | ||
--**Default Hotkey:** Numeric Keys 1-0 / Function Keys F1-F12 | ||
-- @repository | ||
-- https://github.com/tuomiorava/REAPER-ReaScripts | ||
-- @links | ||
-- My music = http://iki.fi/atolonen | ||
-- @donation | ||
-- Donate via PayPal https://www.paypal.com/donate/?hosted_button_id=2BEA2GHZMAW9A | ||
-- @version 1.0 | ||
-- @changelog | ||
-- Initial release | ||
|
||
---------------------------- | ||
--- USER SETTINGS ---------- | ||
---------------------------- | ||
|
||
-- The track name qualifier (this should apper somewhere in the track name) | ||
TRACK_NAME_Q = "perf" | ||
|
||
-- The input to set when Performance Arming a track | ||
RECINPUT_ACTIVE = 4096+0x7E0 -- Default = 4096+0x7E0: MIDI Keyboard: All Channels | ||
-- The input to set when un-Performance Arming previously active track | ||
RECINPUT_DEFAULT = nil -- Default = nil, 0: Input:Mono / In 1 | ||
|
||
-- The selected track idx (order number amongst all instrument tracks) | ||
SELECTED_IDX = nil -- When nil, gets the idx from the pressed hotkey | ||
|
||
---------------------------- | ||
--- END OF USER SETTINGS --- | ||
---------------------------- | ||
|
||
function IsInstrument(track, fx) | ||
local fx_instr = reaper.TrackFX_GetInstrument(track) | ||
return fx_instr >= fx | ||
end | ||
|
||
function HasInstrument(track) | ||
for tr_i = 1, reaper.TrackFX_GetCount(track) do | ||
local retval, buf = reaper.TrackFX_GetFXName(track, tr_i-1, '' ) | ||
if IsInstrument(track, tr_i-1) or buf:match('Reaticulate') then | ||
return true | ||
end | ||
end | ||
|
||
return false | ||
end | ||
|
||
function getIdxByKey() | ||
-- Note: Shortcut scope must be set to Normal or keys will not be detected! | ||
local state = reaper.JS_VKeys_GetState(0) | ||
for i = 48, 255 do | ||
if state:byte(i) == 1 then | ||
if (i ~= 91) then -- Disregard Win key | ||
-- Numeric keys | ||
if (i > 47 and i < 58) then | ||
SELECTED_IDX = i-48 | ||
break | ||
end | ||
-- Numeric keypad keys | ||
if (i > 95 and i < 106) then | ||
SELECTED_IDX = i-96 | ||
break | ||
end | ||
-- Function keys | ||
if (i > 111 and i < 136) then | ||
SELECTED_IDX = i-111 | ||
break | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
function performanceArmTrack(selIdx) | ||
local tr_match_i = 0 | ||
local trCount = reaper.CountTracks(0) | ||
|
||
if (not selIdx or selIdx < 1 or selIdx >= trCount) then | ||
return | ||
end | ||
|
||
for i = 0, trCount do | ||
local tr = reaper.GetTrack(0, i) | ||
|
||
if (tr) then | ||
local _, trName = reaper.GetTrackName(tr) | ||
local hasInst = HasInstrument(tr) | ||
|
||
if (hasInst and string.find(trName, TRACK_NAME_Q)) then | ||
tr_match_i = tr_match_i + 1 | ||
end | ||
|
||
if (hasInst and tr_match_i == selIdx and string.find(trName, TRACK_NAME_Q)) then | ||
reaper.SetTrackUIRecArm(tr, 1, 0) | ||
reaper.SetTrackUIInputMonitor(tr, 2, 0) | ||
|
||
-- Set input if it wasn't already MIDI | ||
local i_RecInputVal = reaper.GetMediaTrackInfo_Value(tr, 'I_RECINPUT') | ||
if (i_RecInputVal < 4096) then | ||
reaper.SetMediaTrackInfo_Value(tr, 'I_RECINPUT', RECINPUT_ACTIVE ) | ||
end | ||
else | ||
local i_RecArmVal = reaper.GetMediaTrackInfo_Value(tr, 'I_RECARM') | ||
local i_RecMonVal = reaper.GetMediaTrackInfo_Value(tr, 'I_RECMON') | ||
|
||
if (i_RecArmVal == 1) then | ||
-- If track was Performance Armed (and wasn't MIDI), and RECINPUT_DEFAULT is set | ||
-- set input to default | ||
local i_RecInputVal = reaper.GetMediaTrackInfo_Value(tr, 'I_RECINPUT') | ||
if (RECINPUT_DEFAULT and i_RecInputVal < 4096 | ||
and (i_RecMonVal == 1 or i_RecMonVal == 2)) then | ||
reaper.SetMediaTrackInfo_Value(tr, 'I_RECINPUT', RECINPUT_DEFAULT) | ||
end | ||
|
||
reaper.SetTrackUIRecArm(tr, 0, 0) | ||
reaper.SetTrackUIInputMonitor(tr, 0, 0) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
if (not SELECTED_IDX) then | ||
getIdxByKey() | ||
end | ||
|
||
performanceArmTrack(SELECTED_IDX) |
144 changes: 144 additions & 0 deletions
144
Tracks/DoomSquirrel_Performance Arm track for MIDI (sequential).lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
-- @description DoomSquirrel_Performance Arm track for MIDI (sequential) | ||
-- @author DoomSquirrel | ||
-- @license GPL v3 | ||
-- @about | ||
-- #Performance Arm track for MIDI (sequential) | ||
-- **Performance Arm** means: | ||
-- - Arms the selected track for recording, sets its monitoring, and sets its input. | ||
-- - Unsets record arming, monitoring (and optionally sets the input to default) for the previously Performance Armed track(s). | ||
-- | ||
-- The intended use for this action is to assign sequential hotkey ranges to it, | ||
-- for example: _Numeric Keys 1-0_ or _Function Keys F1-F12_. | ||
-- Then, when you press the hotkey, it **_Performance Arms_** a track containing an instrument | ||
-- based on the sequential order of those tracks, disregarding other tracks. | ||
-- | ||
-- So, if you have 4 tracks, with tracks 2 & 4 containing instruments, | ||
-- pressing 1 will Performance Arm track 2, and pressing 2 will Performance Arm track 4. | ||
-- | ||
-- Check USER SETTINGS for configuration options. | ||
-- | ||
-- For advanced modification of this script, you can customize the accepted key ranges in the **_getIdxByKey()_** function. | ||
-- Virtual-Key Codes reference: https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes | ||
-- | ||
--**Default Hotkey:** Numeric Keys 1-0 / Function Keys F1-F12 | ||
-- @repository | ||
-- https://github.com/tuomiorava/REAPER-ReaScripts | ||
-- @links | ||
-- My music = http://iki.fi/atolonen | ||
-- @donation | ||
-- Donate via PayPal https://www.paypal.com/donate/?hosted_button_id=2BEA2GHZMAW9A | ||
-- @version 1.0 | ||
-- @changelog | ||
-- Initial release | ||
|
||
---------------------------- | ||
--- USER SETTINGS ---------- | ||
---------------------------- | ||
|
||
-- The input to set when Performance Arming a track | ||
RECINPUT_ACTIVE = 4096+0x7E0 -- Default = 4096+0x7E0: MIDI Keyboard: All Channels | ||
-- The input to set when un-Performance Arming previously active track | ||
RECINPUT_DEFAULT = nil -- Default = nil, 0: Input:Mono / In 1 | ||
|
||
-- The selected track idx (order number amongst all instrument tracks) | ||
SELECTED_IDX = nil -- When nil, gets the idx from the pressed hotkey | ||
|
||
---------------------------- | ||
--- END OF USER SETTINGS --- | ||
---------------------------- | ||
|
||
function IsInstrument(track, fx) | ||
local fx_instr = reaper.TrackFX_GetInstrument(track) | ||
return fx_instr >= fx | ||
end | ||
|
||
function HasInstrument(track) | ||
for tr_i = 1, reaper.TrackFX_GetCount(track) do | ||
local retval, buf = reaper.TrackFX_GetFXName(track, tr_i-1, '' ) | ||
if IsInstrument(track, tr_i-1) or buf:match('Reaticulate') then | ||
return true | ||
end | ||
end | ||
|
||
return false | ||
end | ||
|
||
function getIdxByKey() | ||
-- Note: Shortcut scope must be set to Normal or keys will not be detected! | ||
local state = reaper.JS_VKeys_GetState(0) | ||
for i = 48, 255 do | ||
if state:byte(i) == 1 then | ||
if (i ~= 91) then -- Disregard Win key | ||
-- Numeric keys | ||
if (i > 47 and i < 58) then | ||
SELECTED_IDX = i-48 | ||
break | ||
end | ||
-- Numeric keypad keys | ||
if (i > 95 and i < 106) then | ||
SELECTED_IDX = i-96 | ||
break | ||
end | ||
-- Function keys | ||
if (i > 111 and i < 136) then | ||
SELECTED_IDX = i-111 | ||
break | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
function performanceArmTrack(selIdx) | ||
local tr_match_i = 0 | ||
local trCount = reaper.CountTracks(0) | ||
|
||
if (not selIdx or selIdx < 1 or selIdx >= trCount) then | ||
return | ||
end | ||
|
||
for i = 0, trCount do | ||
local tr = reaper.GetTrack(0, i) | ||
|
||
if (tr) then | ||
local hasInst = HasInstrument(tr) | ||
|
||
if (hasInst) then | ||
tr_match_i = tr_match_i + 1 | ||
end | ||
|
||
if (hasInst and tr_match_i == selIdx) then | ||
reaper.SetTrackUIRecArm(tr, 1, 0) | ||
reaper.SetTrackUIInputMonitor(tr, 2, 0) | ||
|
||
-- Set input if it wasn't already MIDI | ||
local i_RecInputVal = reaper.GetMediaTrackInfo_Value(tr, 'I_RECINPUT') | ||
if (i_RecInputVal < 4096) then | ||
reaper.SetMediaTrackInfo_Value(tr, 'I_RECINPUT', RECINPUT_ACTIVE ) | ||
end | ||
else | ||
local i_RecArmVal = reaper.GetMediaTrackInfo_Value(tr, 'I_RECARM') | ||
local i_RecMonVal = reaper.GetMediaTrackInfo_Value(tr, 'I_RECMON') | ||
|
||
if (i_RecArmVal == 1) then | ||
-- If track was Performance Armed (and wasn't MIDI), and RECINPUT_DEFAULT is set | ||
-- set input to default | ||
local i_RecInputVal = reaper.GetMediaTrackInfo_Value(tr, 'I_RECINPUT') | ||
if (RECINPUT_DEFAULT and i_RecInputVal < 4096 | ||
and (i_RecMonVal == 1 or i_RecMonVal == 2)) then | ||
reaper.SetMediaTrackInfo_Value(tr, 'I_RECINPUT', RECINPUT_DEFAULT) | ||
end | ||
|
||
reaper.SetTrackUIRecArm(tr, 0, 0) | ||
reaper.SetTrackUIInputMonitor(tr, 0, 0) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
if (not SELECTED_IDX) then | ||
getIdxByKey() | ||
end | ||
|
||
performanceArmTrack(SELECTED_IDX) |
80 changes: 80 additions & 0 deletions
80
Tracks/DoomSquirrel_Performance Arm track for MIDI (under mouse).lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
-- @description DoomSquirrel_Performance Arm track for MIDI (under mouse) | ||
-- @author DoomSquirrel | ||
-- @license GPL v3 | ||
-- @about | ||
-- #Performance Arm track for MIDI (under mouse) | ||
-- **Performance Arm** means: | ||
-- - Arms the selected track for recording, sets its monitoring, and sets its input. | ||
-- - Unsets record arming, monitoring (and optionally sets the input to default) for the previously Performance Armed track(s). | ||
-- | ||
-- Check USER SETTINGS for configuration options. | ||
-- | ||
--**Default Hotkey:** Ctrl + Shift + R | ||
-- @repository | ||
-- https://github.com/tuomiorava/REAPER-ReaScripts | ||
-- @links | ||
-- My music = http://iki.fi/atolonen | ||
-- @donation | ||
-- Donate via PayPal https://www.paypal.com/donate/?hosted_button_id=2BEA2GHZMAW9A | ||
-- @version 1.0 | ||
-- @changelog | ||
-- Initial release | ||
|
||
---------------------------- | ||
--- USER SETTINGS ---------- | ||
---------------------------- | ||
|
||
-- The input to set when Performance Arming a track | ||
RECINPUT_ACTIVE = 4096+0x7E0 -- Default = 4096+0x7E0: MIDI Keyboard: All Channels | ||
-- The input to set when un-Performance Arming previously active track | ||
RECINPUT_DEFAULT = nil -- Default = nil, 0: Input:Mono / In 1 | ||
|
||
---------------------------- | ||
--- END OF USER SETTINGS --- | ||
---------------------------- | ||
|
||
local mousetr = reaper.GetTrackFromPoint(reaper.GetMousePosition()) | ||
if (mousetr) then | ||
_, mouseTrName = reaper.GetTrackName(mousetr) | ||
end | ||
|
||
function performanceArmTrack() | ||
local trCount = reaper.CountTracks(0) | ||
|
||
for i = 0, trCount do | ||
local tr = reaper.GetTrack(0, i) | ||
|
||
if (tr) then | ||
local _, trName = reaper.GetTrackName(tr) | ||
|
||
if (trName == mouseTrName) then | ||
reaper.SetTrackUIRecArm(tr, 1, 0) | ||
reaper.SetTrackUIInputMonitor(tr, 2, 0) | ||
|
||
-- Set input if it wasn't already MIDI | ||
local i_RecInputVal = reaper.GetMediaTrackInfo_Value(tr, 'I_RECINPUT') | ||
if (i_RecInputVal < 4096) then | ||
reaper.SetMediaTrackInfo_Value(tr, 'I_RECINPUT', RECINPUT_ACTIVE ) | ||
end | ||
else | ||
local i_RecArmVal = reaper.GetMediaTrackInfo_Value(tr, 'I_RECARM') | ||
local i_RecMonVal = reaper.GetMediaTrackInfo_Value(tr, 'I_RECMON') | ||
|
||
if (i_RecArmVal == 1) then | ||
-- If track was Performance Armed (and wasn't MIDI), and RECINPUT_DEFAULT is set | ||
-- set input to default | ||
local i_RecInputVal = reaper.GetMediaTrackInfo_Value(tr, 'I_RECINPUT') | ||
if (RECINPUT_DEFAULT and i_RecInputVal < 4096 | ||
and (i_RecMonVal == 1 or i_RecMonVal == 2)) then | ||
reaper.SetMediaTrackInfo_Value(tr, 'I_RECINPUT', RECINPUT_DEFAULT) | ||
end | ||
|
||
reaper.SetTrackUIRecArm(tr, 0, 0) | ||
reaper.SetTrackUIInputMonitor(tr, 0, 0) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
performanceArmTrack() |