-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForce Plugin State Render Hook.lua
136 lines (124 loc) · 4.18 KB
/
Force Plugin State Render Hook.lua
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
-- @description Force-enable/disable plugins on master bus during rendering
-- @author Nowu of the North
-- @link
-- @version 1.0
-- @about
-- This script allows you to specify two lists of plugins: one to always enable during rendering,
-- and one to always disable. The original state of the plugins is restored after rendering.
-- Define the lists of plugins to force-enable/disable
local enablePlugins = {}
local disablePlugins = {}
-- Function to save plugin lists to file
local function savePluginLists()
local file = io.open(reaper.GetResourcePath().. "/plugin_lists.txt", "w")
if file then
for i, plugin in ipairs(enablePlugins) do
file:write("enable:".. plugin.. "\n")
end
for i, plugin in ipairs(disablePlugins) do
file:write("disable:".. plugin.. "\n")
end
file:close()
end
end
-- Function to load plugin lists from file
local function loadPluginLists()
local file = io.open(reaper.GetResourcePath().. "/plugin_lists.txt", "r")
if file then
for line in file:lines() do
local type, plugin = line:match("^(%w+):(.+)$")
if type == "enable" then
table.insert(enablePlugins, plugin)
elseif type == "disable" then
table.insert(disablePlugins, plugin)
end
end
file:close()
end
end
-- Load plugin lists from file
loadPluginLists()
-- Function to add plugins to enable/disable lists
local function addPlugins()
local pluginNames = {}
for i = 1, reaper.TrackFX_GetCount(reaper.GetMasterTrack(0)) do
local fxName = reaper.TrackFX_GetFXName(reaper.GetMasterTrack(0), i - 1, "")
table.insert(pluginNames, fxName)
end
local title = "Add Plugins to Lists"
local columns = {
{title = "Plugin", width = 200},
{title = "Enable", width = 100},
{title = "Disable", width = 100}
}
local data = {}
for i, pluginName in ipairs(pluginNames) do
local enable = false
for j, enablePlugin in ipairs(enablePlugins) do
if enablePlugin == pluginName then
enable = true
break
end
end
local disable = false
for j, disablePlugin in ipairs(disablePlugins) do
if disablePlugin == pluginName then
disable = true
break
end
end
table.insert(data, {pluginName, enable, disable})
end
local dialog = reaper.ShowConsoleMsg(title, columns, data)
if dialog then
for i, row in ipairs(dialog) do
if row[2] then
table.insert(enablePlugins, pluginNames[i])
end
if row[3] then
table.insert(disablePlugins, pluginNames[i])
end
end
end
end
-- Function to force-enable/disable plugins
local function forcePluginStates()
for i = 1, reaper.TrackFX_GetCount(reaper.GetMasterTrack(0)) do
local fxName = reaper.TrackFX_GetFXName(reaper.GetMasterTrack(0), i - 1, "")
if table.contains(enablePlugins, fxName) then
reaper.TrackFX_SetEnabled(reaper.GetMasterTrack(0), i - 1, true)
elseif table.contains(disablePlugins, fxName) then
reaper.TrackFX_SetEnabled(reaper.GetMasterTrack(0), i - 1, false)
end
end
end
-- Function to restore original plugin states
local function restoreOriginalStates()
for i = 1, reaper.TrackFX_GetCount(reaper.GetMasterTrack(0)) do
local fxName = reaper.TrackFX_GetFXName(reaper.GetMasterTrack(0), i - 1, "")
local originalState = false
for j, originalPlugin in ipairs(originalPlugins) do
if originalPlugin == fxName then
originalState = true
break
end
end
reaper.TrackFX_SetEnabled(reaper.GetMasterTrack(0), i - 1, originalState)
end
end
-- Save the original state of the plugins
local originalPlugins = {}
for i = 1, reaper.TrackFX_GetCount(reaper.GetMasterTrack(0)) do
local fxName = reaper.TrackFX_GetFXName(reaper.GetMasterTrack(0), i - 1, "")
table.insert(originalPlugins, fxName)
end
-- Set up the rendering hook
reaper.SetRenderHook(function()
forcePluginStates()
reaper.defer(restoreOriginalStates)
end)
-- Create a command to add plugins to lists
reaper.main_OnCommand(40044, 0) -- 40044 is the ID of the "Custom: Add Plugins to Lists" command
function main()
addPlugins()
end