forked from MaddyGuthridge/Novation-LaunchKey-Mk2-Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpluginswrapper.py
227 lines (160 loc) · 7.53 KB
/
pluginswrapper.py
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
"""
Provides wrapper functions around the plugins module, to allow it to be more tightly-integrated
with the script without repeating code
Author: Miguel Guthridge [hdsq@outlook.com.au]
"""
import plugins
import channels
import internal
import processorhelpers
def _getPluginIndexTuple(plugin_index):
"""Converts an index to a tuple-form index if it isn't already
If plugin_index is -1, it will be replaced with the selected plugin's index
"""
if plugin_index == -1:
plugin_index = internal.window.getPluginIndex()
if type(plugin_index) is tuple:
track_index = plugin_index[0]
plugin_index = plugin_index[1]
else:
track_index = -1
return (track_index, plugin_index)
def getParamIndexByName(name, plugin_index=-1, expected_param_index=-1):
"""Returns the index of a parameter in a plugin given the name of the parameter.
Args:
name (str): Name of the parameter to find.
plugin_index (optional)
* (int): Plugin index to search. Use -1 for currently-selected
plugin's index.
* (tuple: 2 ints): Respectively, mixer track and plugin index to search.
expected_param_index (optional, int): index where the parameter is expected to be.
it is searched first to increase efficiency
Returns:
int: Index of parameter. -1 if not found.
"""
plugin_index = _getPluginIndexTuple(plugin_index)
if plugins.getParamName(expected_param_index, plugin_index[1], plugin_index[0]) == name:
return expected_param_index
for i in range(plugins.getParamCount(plugin_index[1], plugin_index[0])):
if plugins.getParamName(i, plugin_index[1], plugin_index[0]) == name:
return i
return -1
def setParamByName(name, value, plugin_index=-1, expected_param_index=-1, command=None):
"""Sets a parameter in a plugin given the name of the parameter.
Args:
name (str): Name of the parameter to find.
value:
* (float): Value to set the parameter to.
* (int): MIDI value to set the parameter to (will be converted to a float between
0 and 1).
plugin_index (optional)
* (int): Plugin index to search. Use -1 for currently-selected
plugin's index.
* (tuple: 2 ints): Respectively, mixer track and plugin index to search.
expected_param_index (optional, int): index where the parameter is expected to be.
it is searched first to increase efficiency
command (ParsedEvent, optional): Command to add handling message to
Returns:
int: parameter index changed
"""
plugin_index = _getPluginIndexTuple(plugin_index)
param_index = getParamIndexByName(name, plugin_index, expected_param_index)
setParamByIndex(param_index, value, plugin_index, command)
return param_index
def setParamByIndex(param_index, value, plugin_index=-1, command=None):
"""Sets a parameter in a plugin given the name of the parameter.
Args:
param_index (int): index where the parameter is.
value:
* (float): Value to set the parameter to.
* (int): MIDI value to set the parameter to (will be converted to a float between
0 and 1).
plugin_index (optional)
* (int): Plugin index to search. Use -1 for currently-selected
plugin's index.
* (tuple: 2 ints): Respectively, mixer track and plugin index to search.
command (ParsedEvent, optional): Command to add handling message to
"""
if type(value) is int:
value = processorhelpers.toFloat(value)
plugin_index = _getPluginIndexTuple(plugin_index)
# No plugin selected
if plugin_index[1] == -1:
return
plugins.setParamValue(value, param_index, plugin_index[1], plugin_index[0])
if command is not None:
# For generators, use name on channel rack
if plugin_index[0] == -1:
plug_name = channels.getChannelName(plugin_index[1])
else:
plug_name = plugins.getPluginName(plugin_index[1], plugin_index[0])
command.handle(plug_name
+ ": Set "
+ plugins.getParamName(param_index, plugin_index[1], plugin_index[0])
+ " to " + str(round(value * 100)) + "%"
)
def setCCParam(ccNum, value, plugin_index=-1, command=None):
"""Sends a MIDI CC event to the specified plugin
Args:
ccNum (int): CC Number to set
value:
* (float): Value to set the parameter to.
* (int): MIDI value to set the parameter to (will be converted to a float between
0 and 1).
plugin_index (optional)
* (int): Plugin index to search. Use -1 for currently-selected
plugin's index.
* (tuple: 2 ints): Respectively, mixer track and plugin index to search.
command (ParsedEvent, optional): Command to add handling message to
"""
setParamByIndex(ccNum + 4096, value, plugin_index, command)
#
# Getters
#
def getParamByName(name, plugin_index=-1, expected_param_index=-1):
"""Gets a parameter value in a plugin given the name of the parameter.
Args:
name (str): Name of the parameter to find.
plugin_index (optional)
* (int): Plugin index to search. Use -1 for currently-selected
plugin's index.
* (tuple: 2 ints): Respectively, mixer track and plugin index to search.
expected_param_index (optional, int): index where the parameter is expected to be.
it is searched first to increase efficiency
Returns:
int: parameter value
"""
plugin_index = _getPluginIndexTuple(plugin_index)
param_index = getParamIndexByName(name, plugin_index, expected_param_index)
# No plugin selected
if plugin_index[1] == -1:
return expected_param_index
return plugins.getParamValue(param_index, plugin_index[1], plugin_index[0])
def getParamByIndex(param_index, plugin_index=-1):
"""Gets a parameter in a plugin given the index of the parameter.
Args:
param_index (int): index of the parameter.
plugin_index (optional)
* (int): Plugin index to search. Use -1 for currently-selected
plugin's index.
* (tuple: 2 ints): Respectively, mixer track and plugin index to search.
Returns:
int: parameter value
"""
plugin_index = _getPluginIndexTuple(plugin_index)
# No plugin selected
if plugin_index[1] == -1:
return
return plugins.getParamValue(param_index, plugin_index[1], plugin_index[0])
def getCCParam(ccNum, plugin_index=-1):
"""Gets a current MIDI CC value of a plugin.
Args:
ccNum (int): MIDI CC number
plugin_index (optional)
* (int): Plugin index to search. Use -1 for currently-selected
plugin's index.
* (tuple: 2 ints): Respectively, mixer track and plugin index to search.
Returns:
int: parameter value
"""
return getParamByIndex(ccNum + 4096, plugin_index)