I wrote a Cycle class that lets me cycle trough a list. When it comes to the end of the list it starts again at the beginning.
I use a function pphase1 to play through the pattern 4 times. It all works fine when I call the function but when I pass the function to fork() it just plays the 1st note and then hangs.
(I usually have the class in a separate file but for this I just copied into the py file)
from scamp import *
class Cycle:
def __init__(self, cyc):
self.data = cyc
self.curr = -1
self.len = len(cyc)
def next(self):
self.curr = self.curr + 1
if self.curr >= self.len:
self.curr = 0
return self.data[self.curr]
def curr(self):
if self.curr == -1:
return None
return self.data[self.curr]
def reset(self):
self.curr = -1
s = Session(tempo=72)
piano = s.new_part("piano")
phasing_trope = [64, 66, 71, 73, 74, 66, 64, 73, 71, 66, 74, 73]
trope = Cycle(phasing_trope)
rate = 1/6
reps = 4
def pphase1(pat, reps, amp, inst):
for _ in range(pat.len * reps):
inst.play_note(pat.next(), amp, rate * 1.5, blocking=False)
s.wait(rate)
pphase1(trope, 4, 0.5, piano)
s.wait(1.0)
s.fork(pphase1, args=[trope, 4, 0.5, piano])
s.wait_for_children_to_finish()
s.wait(0.5)