forked from ideoforms/LiveOSC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LiveUtils.py
264 lines (214 loc) · 7.62 KB
/
LiveUtils.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
"""
# LiveUtils, a collection of simple utility functions for controlling Ableton Live
# Copyright (C) 2007 Rob King ([email protected])
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# For questions regarding this module contact
# Rob King <[email protected]> or visit http://www.e-mu.org
"""
import Live
def getSong():
"""Gets a the current Song instance"""
return Live.Application.get_application().get_document()
def continuePlaying():
"""Continues Playing"""
getSong().continue_playing()
def playSelection():
"""Plays the current selection"""
getSong().play_selection()
def jumpBy(time):
"""Jumps the playhead relative to it's current position by time. Stops playback."""
getSong().jump_by(time)
def scrubBy(time):
"""Jumps the playhead relative to it's current position by time. Does not stop playback"""
getSong().scrub_by(time)
def play():
"""Starts Ableton Playing"""
print "playing"
getSong().start_playing()
def stopClips():
"""Stops all currently playing clips"""
getSong().stop_all_clips()
def stop():
"""Stops Ableton"""
getSong().stop_playing()
def currentTime(time = None):
"""Sets/Returns the current song time"""
song = getSong()
if time is not None:
song.current_song_time = time
return getSong().current_song_time
def getScenes():
"""Returns a list of scenes"""
return getSong().scenes
def getScene(num):
"""Returns scene number (num) (starting at 0)"""
return getSong().scenes[num]
def createScene(num):
"""Create a scene at the index (num). -1 creates a scene at the end"""
return getSong().create_scene(num)
def launchScene(scene):
"""Launches scene number (scene)"""
getScene(scene).fire()
def getTracks():
"""Returns a list of tracks"""
return getSong().tracks
def getTrack(num):
"""Returns track number (num) (starting at 0)"""
return getSong().tracks[num]
def stopTrack(trackNumber):
"""Stops all clips in track number (trackNumber)"""
track = getTrack(trackNumber)
track.stop_all_clips()
def getTempo():
"""Returns the current song tempo"""
return getSong().tempo
def setTempo(tempo):
getSong().tempo = tempo
def jumpToNextCue():
getSong().jump_to_next_cue()
def jumpToPrevCue():
getSong().jump_to_prev_cue()
def armTrack(num):
"""Arms track number (num)"""
getTrack(num).arm = 1
def disarmTrack(num):
"""Disarms track number (num)"""
getTrack(num).arm = 0
def toggleArmTrack(num):
"""Toggles the armed state of track number (num)"""
armed = getTrack(num).arm
if armed:
getTrack(num).arm = 0
else:
getTrack(num).arm = 1
def muteTrack(track, ty = 0):
"""Mutes track number (num)"""
if ty == 1:
getSong().return_tracks[track].mute = 1
else:
getTrack(track).mute = 1
def unmuteTrack(track, ty = 0):
"""Unmutes track number (num)"""
if ty == 1:
getSong().return_tracks[track].mute = 0
else:
getTrack(track).mute = 0
def toggleMuteTrack(num):
"""Toggles the muted state of track number (num)"""
muted = getTrack(num).mute
if muted:
getTrack(num).mute = 0
else:
getTrack(num).mute = 1
def soloTrack(track, ty = 0):
"""Solo's track number (num)"""
if ty == 1:
getSong().return_tracks[track].solo = 1
else:
getTrack(track).solo = 1
def unsoloTrack(track, ty = 0):
"""Un-solos track number (num)"""
if ty == 1:
getSong().return_tracks[track].solo = 0
else:
getTrack(track).solo = 0
def toggleSoloTrack(num):
"""Toggles the soloed state of track number (num)"""
soloed = getTrack(num).solo
if soloed:
getTrack(num).solo = 0
else:
getTrack(num).solo = 1
def trackVolume(track, volume = None):
"""Gets/Changes the volume of track (track)
If (volume) is specified, changes the volume of track number
(track) to (volume), a value between 0.0 and 1.0.
"""
if volume != None:
getTrack(track).mixer_device.volume.value = volume
return getTrack(track).mixer_device.volume.value
def trackPan(track, pan = None):
"""Gets/Changes the panning of track number (track)
If (pan) is specified, changes the panning to (pan).
(pan) should be a value between -1.0 to 1.0
"""
if pan != None:
getTrack(track).mixer_device.panning.value = pan
return getTrack(track).mixer_device.panning.value
def trackSend(track, send = None, level=None):
"""Gets/Changes the level of send number (send) on track (track).
If (level) is specified, the level of the send is set to (level),
a value between 0.0 and 1.0
"""
if send == None:
return getTrack(track).mixer_device.sends
if level != None:
getTrack(track).mixer_device.sends[send].value = level
return getTrack(track).mixer_device.sends[send].value
def trackName(track, name = None):
"""Gets/Changes the name of track (track).
If (name) is specified, the track name is changed
"""
if name != None:
getTrack(track).name = name
return str(getTrack(track).name)
def getClipSlots():
"""Gets a 2D list of all the clip slots in the song"""
tracks = getTracks()
clipSlots = []
for track in tracks:
clipSlots.append(track.clip_slots)
return clipSlots
def getClips():
"""Gets a 2D list of all the clip in the song.
If there is no clip in a clip slot, None is returned
"""
tracks = getTracks()
clips = []
for track in getClipSlots():
trackClips = []
for clipSlot in track:
trackClips.append(clipSlot.clip)
clips.append(trackClips)
return clips
def launchClip(track, clip):
"""Launches clip number (clip) in track number (track)"""
getClip(track, clip).fire()
def stopClip(track, clip):
"""Stops clip number (clip) in track (track)"""
getClip(track, clip).stop()
def getClip(track, clip):
"""Returns clip number (clip) in track (track)"""
tracks = getTracks()
return tracks[track].clip_slots[clip].clip
def clipName(track, clip, name = None):
"""Gets/changes the name of clip number (clip) in track (track)
In (name) is specified, the name of the clip is changed
"""
if name != None:
getClip(track, clip).name = name
return str(getClip(track, clip).name)
def clipPitch(track, clip, coarse = None, fine = None):
"""Gets/changes the coarse and fine pitch shift of clip (clip) in track (track).
If (coarse) or (fine) are specified, changes the clip's pitch.
"""
clip = getClip(track, clip)
if coarse != None:
clip.pitch_coarse = coarse
if fine != None:
clip.pitch_fine = fine
return (clip.pitch_coarse, clip.pitch_fine)