Hello, I am very excited to use Scamp. It is such a good alternative and continuation of other algorithmic environments that I have used but are no longer well maintained. One thing I can’t really get used to with Scamp is the different handling of rhythmic values and rests. I’m used to using both as equal values in lists, only differentiated by a positive or negative sign. This works ok for solo stuff, but when forking, the individual processes start to run out of sync. (In versions I tried before the interruptions of the baby clock interrupted the main clock, which is why i came up with own clocks for each s.fork). Does anyone have any ideas on how to bring more discipline in the mess? (See below.)
Geen
from scamp import *
s = Session()
vi = s.new_part("violin")
cb = s.new_part("contrabass")
va = s.new_part("viola")
def pitch_walk(pitch_ges, steps, start_index, lower_limit, upper_limit, total_values):
current_index = start_index
step_count = 0
while step_count < total_values:
if current_index < lower_limit or current_index > upper_limit:
current_index = start_index
yield pitch_ges[current_index]
step_count += 1
current_index += steps[step_count % len(steps)]
def play_instrument(clock, instrument, pitch_ges, steps, start_index, lower_limit, upper_limit, total_values, durs, env):
generator = pitch_walk(pitch_ges, steps, start_index, lower_limit, upper_limit, total_values)
dur_index = 0
for pitch in generator:
current_dur = durs[dur_index % len(durs)] # Cycle through the durations
print(f"Playing pitch: {pitch}, duration: {current_dur}")
if current_dur > 0: # Only play if duration is positive
instrument.play_note(pitch, env, current_dur) # Play the note with the specified duration and envelope
clock.wait(current_dur) # Wait for the duration of the note to pass
else:
print(f"Pausing for: {-current_dur}")
clock.wait(-current_dur) # Wait for the absolute value of the negative duration
dur_index += 1
clock.wait(0)
print("Finished playing instrument part.")
pitch_ges = pitch_ges = list(range(12, 121))
steps1 = [1]
steps2 = [2]
durs0 = [1, -3]
durs1 = [-1, 1, -1]
durs2 = [-2, 2] # Rhythmic durations where any negative value represents a pause
env1 = [0.5, 0.7, 0.5]
clock1 = s.fork(play_instrument, args=[cb, pitch_ges, steps1, 40, 40, 60, 80, durs0, env1])
clock2 = s.fork(play_instrument, args=[va, pitch_ges, steps1, 58, 58, 78, 80, durs1, env1])
clock2 = s.fork(play_instrument, args=[vi, pitch_ges, steps2, 74, 74, 94, 80, durs2, env1])
s.wait_for_children_to_finish()