Skip to content

Commit

Permalink
arpegg.py: Remove the old arpegg.run() code.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpwe committed Apr 16, 2024
1 parent 9f00fcc commit 2db916c
Showing 1 changed file with 6 additions and 31 deletions.
37 changes: 6 additions & 31 deletions tulip/shared/py/arpegg.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class ArpeggiatorSynth:
hold = False
octaves = 1
direction = "up"
period_ms = 125
# Velocity for all the notes generated by the sequencer.
velocity = 0.5
# Notes at or above the split_note are always passed through live, not sequenced.
Expand Down Expand Up @@ -74,49 +73,27 @@ def _update_full_sequence(self):
# Semaphore to the run loop to start going.
self.running = True

def next_note(self):
def next_note(self, step=None):
if step is None:
step = self.current_step + 1
if self.current_note:
self.synth.note_off(self.current_note)
self.current_note = None
if self.full_sequence:
if self.direction == "rand":
self.current_step = random.randint(0, len(self.full_sequence) - 1)
else:
self.current_step = (self.current_step + 1) % len(self.full_sequence)
self.current_step = step % len(self.full_sequence)
self.current_note = self.full_sequence[self.current_step]
self.synth.note_on(self.current_note, self.velocity)
else:
self.running = False

def run(self):
# Endless function that will emit sequencer notes when there are arpeggiate_base_notes.
while True:
if not self.running:
time.sleep_ms(10) # Break up the loop a little
else:
# self.running started sequence.
# Another brief pause to let all keys go down
time.sleep_ms(10)
# Cycle the notes as long as we have them.
while self.running:
self.next_note()
time.sleep_ms(self.period_ms)

def control_change(self, control, value):
#if not self.active:
# return self.synth.control_change(control, value)
if control == self.rate_control_num:
self.period_ms = 25 + 5 * value # 25 to 665 ms
elif control == self.octaves_control_num:
self.cycle_octaves()
elif control == self.direction_control_num:
self.cycle_direction()
else:
self.synth.control_change(control, value)
self._update_full_sequence()
return self.synth.control_change(control, value)

def program_change(self, patch_number):
self.synth.program_change(patch_number)
return self.synth.program_change(patch_number)

@property
def num_voices(self):
Expand Down Expand Up @@ -152,8 +129,6 @@ def set(self, arg, val=None):
self.hold = val
# Copy across the current_active_notes after a change in hold.
self.arpeggiate_base_notes = set(self.current_active_notes)
elif arg == 'arp_rate':
self.period_ms = int(1000 / (2.0 ** (5 * val))) # 1 Hz to 32 Hz
elif arg == 'octaves':
self.octaves = val
elif arg == 'direction':
Expand Down

0 comments on commit 2db916c

Please sign in to comment.