Skip to content
Snippets Groups Projects

py: use InputController in simple_drums

Merged q3k requested to merge q3k/simple-drums-input-controller into main
Files
2
@@ -51,11 +51,18 @@ class SimpleDrums(Application):
self.kick.sampler.signals.trigger = self.seq.seqs[0].signals.output
self.hat.sampler.signals.trigger = self.seq.seqs[1].signals.output
self.snare.sampler.signals.trigger = self.seq.seqs[2].signals.output
self.ct_prev = captouch.read()
self.track = 0
self.seq.bpm = 80
self.blm.background_mute_override = True
# True if a given track should be highlighted, when a corresponding
# petal is pressed.
self._bar_hightlight = [False for _ in range(4)]
# Disable repeat functionality as we want to detect long holds.
for i in range(10):
self.input.captouch.petals[i].whole.repeat_disable()
def _highlight_petal(self, num: int, r: int, g: int, b: int) -> None:
for i in range(5):
leds.set_rgb((4 * num - i + 2) % 40, r, g, b)
@@ -74,7 +81,7 @@ class SimpleDrums(Application):
dots = []
groupgap = 4
for i in range(4):
if self.ct_prev.petals[4 - i].pressed:
if self._bar_hightlight[i]:
dots.append(
Dot(
48 + groupgap,
@@ -116,16 +123,17 @@ class SimpleDrums(Application):
self._highlight_petal(4 - (st // 4), *rgb)
self._highlight_petal(6 + (st % 4), *rgb)
leds.update()
ct = captouch.read()
petals = self.input.captouch.petals
self._bar_hightlight = [False for _ in range(4)]
for i in range(4):
if ct.petals[4 - i].pressed:
if petals[4 - i].whole.down:
self._bar_hightlight[i] = True
for j in range(4):
if ct.petals[6 + j].pressed and not (
self.ct_prev.petals[6 + j].pressed
):
if petals[6 + j].whole.pressed:
self.seq.trigger_toggle(self.track, i * 4 + j)
if ct.petals[5].pressed and not (self.ct_prev.petals[5].pressed):
self.track = (self.track + 1) % 3
if ct.petals[0].pressed and not (self.ct_prev.petals[0].pressed):
if petals[5].whole.pressed:
self.track = (self.track - 1) % 3
if petals[0].whole.pressed:
self.track = (self.track + 1) % 3
self.ct_prev = ct
Loading