forked from ideoforms/pylive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex-clip-walk.py
executable file
·61 lines (52 loc) · 2.25 KB
/
ex-clip-walk.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
#!/usr/bin/env python3
#------------------------------------------------------------------------
# pylive: ex-clip-walk.py
#
# Demonstrates triggering clips by "walking" between clips in a
# single track.
#
# Requires a Live set with multiple clips in its first track.
#------------------------------------------------------------------------
import live
import time
import threading
import random
import logging
logging.basicConfig(format="%(asctime)-15s %(message)s")
logging.getLogger("live").setLevel(logging.INFO)
#------------------------------------------------------------------------
# Scan the contents of the Live set, and start it playing.
#------------------------------------------------------------------------
set = live.Set()
set.scan()
set.dump()
set.play()
#------------------------------------------------------------------------
# Select the first track.
#------------------------------------------------------------------------
track = set.tracks[0]
if len(track.active_clips) == 0:
raise LiveException("Please open a Live set with at least one clip in the first track")
#------------------------------------------------------------------------
# track.clips is a list of all clipslots on the given Track, some of
# which may be None (as a slot may be empty).
#
# Instead, we use track.active_clips, which returns a list of all
# Clip objects on the Track.
#------------------------------------------------------------------------
clip = random.choice(track.active_clips)
#------------------------------------------------------------------------
# Now, set up an infinite loop in which we play the following or
# previous Clip once per beat. Switch Live's quantization to "1 beat".
#------------------------------------------------------------------------
while True:
set.wait_for_next_beat()
#------------------------------------------------------------------------
# wrap = True: Wrap between the last and first clips of the track.
# allow_gaps = True: Jump over gaps between populated clips.
#------------------------------------------------------------------------
if random.uniform(0, 1) < 0.5:
clip = clip.get_next_clip(wrap=True, allow_gaps=True)
else:
clip = clip.get_prev_clip(wrap=True, allow_gaps=True)
clip.play()