Skip to content
Snippets Groups Projects
Commit bc57ce02 authored by rorist's avatar rorist
Browse files

Fixed bpm and don't use sleep for the seq

parent 822f449e
Branches
No related tags found
No related merge requests found
......@@ -40,6 +40,8 @@ class EndlessSequencer(Application):
# 'close.wav' ]
self.current_sample = None
self.current_note = 0
self.startTime = time.ticks_ms()
self.bpm = 120
#self.sample_names = ['kick.wav', 'snare.wav', 'cowbell.wav', 'hihat.wav', 'silence.wav']
#self.app_path = '/flash/sys/apps/seq/'
......@@ -135,6 +137,7 @@ class EndlessSequencer(Application):
print(' seq {}'.format(self.sample_names[sample_id]))
self.notes.append(sample_id)
self.play_sample(sample_id)
time.sleep(0.2)
# Light petal
for i in range(10):
......@@ -162,25 +165,35 @@ class EndlessSequencer(Application):
if len(self.notes) > 0 and not ct.petals[0].pressed:
self.play_seq()
def next_bpm(self):
# taken from binarybrain code
beatTime = 60.0 * 1000.0 / self.bpm
curRelTime = time.ticks_diff(time.ticks_ms(), self.startTime)
return curRelTime / beatTime > 1
def play_sample(self, i):
self.current_sample = i
if i < len(self.samples):
if self.DEBUG and i in self.sample_names:
print (self.sample_names[i])
self.samples[i].signals.trigger.start()
time.sleep(0.2)
def play_seq(self):
if self.DEBUG:
print("PLAY SEQ")
if self.next_bpm():
self.startTime = time.ticks_ms()
if self.current_note == len(self.notes): self.current_note = 0
if self.DEBUG:
print(" play note {}".format(i))
self.play_sample(self.notes[self.current_note])
self.play_sample(self.notes[self.current_note])
self.current_note += 1
else:
if self.DEBUG:
print(" wait")
if __name__ == "__main__":
import st3m.run
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment