-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExampleActions.py
225 lines (185 loc) · 11.2 KB
/
ExampleActions.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
"""
ClyphX_Pro allows you to add your own actions that work just like built in actions.
This file demonstrates how that's done.
_________________________________________________________________________________________
NOTES ABOUT FILES/MODULES:
You can create as many of these files as you like, but you must follow these rules:
(1) - All files you create must be placed in this user_actions folder. *See note below.
(2) - The names of your files cannot begin with an underscore.
(3) - Your file should contain a class that extends UserActionsBase and that class should
have the same name as the file (aka module) that contains it. For example, this
file's name is ExampleActions and the name of the class below is also
ExampleActions.
Note that ClyphX_Pro uses sandboxing for importing from user-defined modules. So, if your
module contains errors, it will likely not be imported.
Also note that re-installing/updating Live and/or ClyphX Pro could cause files in this
user_actions folder to be removed. For that reason, it is strongly recommended that you
back up your files in another location after creating or modifying them. *See note below.
****** NEW IN V1.1.1 ******:
It is now possible to place your files in an alternate folder. In this way, your files
will never be removed when re-installing/updating ClyphX Pro. However, they can still
be removed when re-installing/updating Live, so the recommendation about backing up
files still holds.
To use the alternate folder:
(1) - Close Live.
(2) - In Live's Remote Scripts directory, create a folder named _user_actions
(3) - Copy the file named __init__.pyc from this user_actions folder and place it in the
_user_actions folder you created.
(4) - Re-launch Live.
(5) - Create your files as described above, but place them in the _user_actions folder
you created.
PLEASE NOTE: In order for the alternate folder to be used, the import statement in this
file (and all user action files) was changed. So, if you'll be placing files you created
previously in the alternate folder, you'll need to change their import statements.
Instead of this:
from ..UserActionsBase import UserActionsBase
You should use this:
from ClyphX_Pro.clyphx_pro.UserActionsBase import UserActionsBase
_________________________________________________________________________________________
NOTES ABOUT CLASSES:
As mentioned above, files you create should contain a class that extends UserActionsBase.
The class must implement a create_actions method, which is where you'll tell ClyphX_Pro
about the actions your class provides. You can see this in the example class below.
There are several other useful methods that you can optionally override if you like:
(1) - on_track_list_changed(self) - This will be called any time the track list changes
in Live.
(2) - on_scene_list_changed(self) - This will be called any time the scene list changes
in Live.
(3) - on_selected_track_changed(self) - This will be called any time a track is selected
or the track list changes in Live.
(4) - on_selected_scene_changed(self) - This will be called any time a scene is selected
in Live.
(5) - on_control_surface_scripts_changed(self, scripts) - This will be called any time
the list of control surface scripts changes in Live. The scripts argument is a
dict mapping the lower case names of scripts to the script objects themselves.
Additionally, there are a couple of other methods and attributes of UserActionsBase that
you should be aware of and that are demonstrated below:
(1) - self.song() - returns the current Live set object.
(2) - self.canonical_parent - returns the ControlSurface (parent) object that has loaded
the ClyphX_Pro library. Through this object, you can access two useful methods:
(a) - log_message(msg) - Writes a message to Live's Log.txt file.
(b) - show_message(msg) - Shows a message in Live's status bar.
Lastly, through the canonical_parent, you can access the core ClyphX Pro component, which
would allow you to trigger built in ClyphX Pro actions like so:
self.canonical_parent.clyphx_pro_component.trigger_action_list('metro ; 1/mute')
trigger_action_list accepts a single string that specifies the action list to trigger.
_________________________________________________________________________________________
NOTES ABOUT ACTIONS:
Your classes can create 4 types of actions each of which is slightly different, but all
have some common properties.
First of all, you define your actions in your class's create_actions method. There is an
add method corresponding to each of the 4 types of actions you can create. For example,
add_global_action(action_name, method) creates a global action. All 4 add methods take
the same two arguments:
(1) - action_name - The single word, lowercase name to use when accessing the action from
an X-Trigger. This name should not be the same as the name of any built in action.
(2) - method - The method in your class to call when the action has been triggered.
The methods for each type of action need to accept two arguments:
(1) - action_def - This is a dict that contains contents relevant to the type of action.
The contents of this dict differs depending on the type of action, but always
contains the following:
(a) - xtrigger_is_xclip - A boolean indicating whether the action was triggered via
an X-Clip.
(b) - xtrigger - The X-Trigger that triggered the action.
(2) - args - Any arguments that follow the action name. For example, in the case of
'VOL RAMP 4 100', RAMP, 4 and 100 are all arguments following the action name (VOL).
These arguments will be presented to you as a single string and will be converted to
lower case unless one (or more) of the arguments is in quotes. Arguments in quotes
are not converted in any way.
Note that ClyphX_Pro uses sandboxing for dispatching actions. So, if your method contains
errors, it will effectively be ignored.
_________________________________________________________________________________________
GLOBAL ACTIONS:
These actions don't apply to any particular object in Live.
Add method: add_global_action(action_name, method)
Additional action_def contents: No additional content.
_________________________________________________________________________________________
TRACK ACTIONS:
These actions apply to a track in Live and function just like Track Actions, so they'll be
called for each track that is specified.
Add method: add_track_action(action_name, method)
Additional action_def contents:
(1) - track - the track object to operate upon.
_________________________________________________________________________________________
DEVICE ACTIONS:
These actions apply to a device in Live and function just like Device Actions, so they'll
be called for each device that is specified.
Add method: add_device_action(action_name, method)
Additional action_def contents:
(1) - track - the track object containing the device.
(2) - device - the device object to operate upon.
Other notes, the action names for these actions are all preceded by 'user_dev'. So, for
example, if you create a device action named 'my_action', its full name will be
'user_dev my_action'. This allows your actions to apply to ranges of devices just like is
possible with Device Actions. For example: 'user_dev(all) my_action'
_________________________________________________________________________________________
CLIP ACTIONS:
These actions apply to a clip in Live and function just like Clip Actions, so they'll
be called for each clip that is specified.
Add method: add_clip_action(action_name, method)
Additional action_def contents:
(1) - track - the track object containing the clip.
(2) - clip - the clip object to operate upon.
Other notes, the action names for these actions are all preceded by 'user_clip'. So, for
example, if you create a clip action named 'my_action', its full name will be
'user_clip my_action'. This allows your actions to apply to ranges of clips just like is
possible with Clip Actions. For example: 'user_clip(all) my_action'
_________________________________________________________________________________________
"""
# Import UserActionsBase to extend it.
from ClyphX_Pro.clyphx_pro.UserActionsBase import UserActionsBase
# Your class must extend UserActionsBase.
class ExampleActions(UserActionsBase):
""" ExampleActions provides some example actions for demonstration purposes. """
# Your class must implement this method.
def create_actions(self):
"""
Here, we create 4 actions, each a different type:
(1) - ex_global can be triggered via the name 'ex_global', which will call the
method named global_action_example.
(2) - ex_track can be triggered via the name 'ex_track', which will call the
method named track_action_example.
(3) - ex_device can be triggered via the name 'user_dev ex_device', which will
call the method named device_action_example.
(4) - ex_clip can be triggered via the name 'user_clip ex_clip', which will
call the method named clip_action_example.
"""
self.add_global_action("ex_global", self.global_action_example)
self.add_track_action("ex_track", self.track_action_example)
self.add_device_action("ex_device", self.device_action_example)
self.add_clip_action("ex_clip", self.clip_action_example)
def global_action_example(self, action_def, args):
""" Logs whether the action was triggered via an X-Clip and shows 'Hello World'
preceded by any args in Live's status bar. """
self.canonical_parent.log_message(
"X-Trigger is X-Clip=%s" % action_def["xtrigger_is_xclip"]
)
self.canonical_parent.show_message("%s: Hello World" % args)
def track_action_example(self, action_def, args):
""" Sets the volume and/or panning of the track to be the same as the master
track. This obviously does nothing if the track is the master track. """
track = action_def["track"]
master = self.song().master_track
if not args or "vol" in args:
track.mixer_device.volume.value = master.mixer_device.volume.value
if not args or "pan" in args:
track.mixer_device.panning.value = master.mixer_device.panning.value
def device_action_example(self, action_def, _):
""" Resets all of the device's parameters and logs the name of the device.
This method doesn't require any args so we use _ to indicate that. """
device = action_def["device"]
if device:
for p in device.parameters:
if p.is_enabled and not p.is_quantized:
p.value = p.default_value
self.canonical_parent.log_message("Reset device: %s" % device.name)
def clip_action_example(self, action_def, args):
""" Sets the name of the clip to the name specified in args. We consider renaming
the X-Clip that triggered this action an error and so we log that if it
occurs. """
clip = action_def["clip"]
if clip:
if action_def["xtrigger"] != clip:
clip.name = args
else:
self.canonical_parent.log_message("Error: Tried to rename X-Clip!")