Skip to content
Snippets Groups Projects
Commit 94e4923e authored by q3k's avatar q3k
Browse files

py/harmonic: port to newer API version

parent aa25b0b5
No related branches found
No related tags found
No related merge requests found
from synth import tinysynth from synth import tinysynth
from hardware import * from hardware import *
import leds
chords = [ chords = [
[-4, 0, 3, 8, 10], [-4, 0, 3, 8, 10],
...@@ -9,74 +11,52 @@ chords = [ ...@@ -9,74 +11,52 @@ chords = [
[3, 7, 10, 14, 15], [3, 7, 10, 14, 15],
] ]
chord_index = 3
chord = chords[3]
synths = []
def set_chord(i):
global chord_index
global chord
if i != chord_index:
chord_index = i
for j in range(40):
hue = int(72 * (i + 0.5)) % 360
set_led_hsv(j, hue, 1, 0.2)
chord = chords[i]
update_leds()
def run():
global chord_index
global chord
global synths
for i in range(10):
if get_captouch(i):
if i % 2:
k = int((i - 1) / 2)
set_chord(k)
else:
k = int(i / 2)
synths[k].tone(chord[k])
synths[k].start()
def init():
global chord_index
global chord
global synths
for i in range(5):
synths += [tinysynth(440, 1)]
for synth in synths:
synth.decay(100)
synth.waveform(1)
def foreground():
global chord_index
global chord
global synths
tmp = chord_index
chord_index = -1
set_chord(tmp)
from st3m.application import Application from st3m.application import Application
class HarmonicApp(Application): class HarmonicApp(Application):
def on_init(self): def on_init(self):
init() self.color_intensity = 0
# foreground() self.chord_index = None
self.chord = None
self.synths = [
tinysynth(440, 1) for i in range(5)
]
for synth in self.synths:
synth.decay(100)
synth.waveform(1)
self._set_chord(3)
def _set_chord(self, i):
hue = int(72 * (i + 0.5)) % 360
if i != self.chord_index:
self.chord_index = i
for j in range(40):
leds.set_hsv(j, hue, 1, 0.2)
self.chord = chords[i]
leds.update()
def on_foreground(self): def on_foreground(self):
# foreground()
pass pass
def on_draw(self, ctx):
i = self.color_intensity
ctx.rgb(i, i, i).rectangle(-120, -120, 240, 240).fill()
def main_foreground(self): def main_foreground(self):
run() if self.color_intensity > 0:
self.color_intensity -= self.color_intensity / 20
for i in range(10):
if get_captouch(i):
if i % 2:
k = int((i - 1) / 2)
self._set_chord(k)
else:
k = int(i / 2)
self.synths[k].tone(self.chord[k])
self.synths[k].start()
self.color_intensity = 1.0
app = HarmonicApp("harmonic") app = HarmonicApp("harmonic")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment