Skip to content
Snippets Groups Projects
Commit b994d86c authored by moon2's avatar moon2 :speech_balloon:
Browse files

minor upgrades to payload apps

parent a6008d7d
No related branches found
No related tags found
No related merge requests found
......@@ -23,11 +23,11 @@ class App(Application):
self.focused_widget = 1
self.active = False
self.num_widgets = 5
self.overhang = -20
self.overhang = -30
self.line_height = 24
self.input.buttons.app.left.repeat_enable(800, 300)
self.input.buttons.app.right.repeat_enable(800, 300)
self.mid_x = 42
self.mid_x = 55
self.led_accumulator_ms = 0
self.blueish = False
......@@ -106,17 +106,50 @@ class App(Application):
ctx.text(choices[a] + " ")
return no
def draw_boolean(self, label, value, on_str="on", off_str="off"):
def draw_boolean(
self,
label,
value,
on_str="on",
off_str="off",
val_col=(1, 1, 1),
on_hint=None,
off_hint=None,
):
ctx = self.ctx
if ctx is None:
return
self.draw_widget(label)
if self.widget_no == self.focused_widget and self.active:
value = not value
self.active = False
ctx.save()
ctx.rgb(*val_col)
if value:
ctx.text(on_str)
else:
ctx.text(off_str)
ctx.restore()
if self.widget_no == self.focused_widget:
if value:
hint = on_hint
else:
hint = off_hint
if hint is not None:
ctx.save()
ctx.font_size -= 4
ctx.text_align = ctx.CENTER
ctx.rgb(0.9, 0.9, 0.9)
lines = hint.split("\n")
self.y -= 3
for line in lines:
ctx.move_to(0, self.y)
ctx.text(line)
self.y += self.line_height - 5
ctx.restore()
if self.y > 115:
self.focus_widget_pos_max = self.y
return value
def draw_number(self, label, step_size, no, unit=""):
......@@ -217,7 +250,11 @@ class App(Application):
leds.set_slew_rate(settings.num_leds_speed.value)
tmp = self.draw_boolean(
"menu LEDs", settings.onoff_leds_random_menu.value, "random", "user"
"menu LEDs",
settings.onoff_leds_random_menu.value,
on_str="rng",
off_str="user",
off_hint="set pattern with LED Painter",
)
if tmp != settings.onoff_leds_random_menu.value:
settings.onoff_leds_random_menu.set_value(tmp)
......
......@@ -55,12 +55,14 @@ class Drawable:
def at_last_widget(self):
return self.focus_widget >= (self.num_widgets - 1)
def draw_heading(self, label, col=(0.8, 0.8, 0.8), embiggen=6, margin=2):
def draw_heading(
self, label, col=(0.8, 0.8, 0.8), embiggen=6, top_margin=2, bot_margin=2
):
ctx = self.ctx
if ctx is None:
return
self.widget_no += 1
self.y += embiggen + margin
self.y += embiggen + top_margin
if self.widget_no == self.focus_widget:
if self.focus_widget > self.focus_widget_prev:
self.focus_widget += 1
......@@ -75,7 +77,7 @@ class Drawable:
ctx.font_size += embiggen
ctx.text(label)
ctx.restore()
self.y += self.line_height + embiggen + margin
self.y += self.line_height + embiggen + bot_margin
def draw_widget(self, label):
ctx = self.ctx
......@@ -156,7 +158,7 @@ class Drawable:
ctx.text(choices[a] + " ")
return no
def draw_number(self, label, step_size, no, unit="", val_col=(0.8, 0.8, 0.8)):
def draw_number(self, label, step_size, no, unit="", val_col=(1.0, 1.0, 1.0)):
ctx = self.ctx
if ctx is None:
return
......@@ -194,7 +196,7 @@ class Drawable:
value,
on_str="on",
off_str="off",
val_col=(0.8, 0.8, 0.8),
val_col=(1.0, 1.0, 1.0),
on_hint=None,
off_hint=None,
):
......@@ -438,8 +440,10 @@ class InputMenu(Submenu):
def __init__(self, press):
super().__init__(press)
self.num_widgets = 11
self.overhang = -85
self.overhang = -89
self.mid_x = 0
self.focus_pos_limit_max = 80
self.focus_pos_limit_last = 100
def _draw(self, ctx):
self.ctx = ctx
......@@ -451,7 +455,7 @@ class InputMenu(Submenu):
not_allow_col = (0.8, 0.3, 0.3)
not_avail_col = (0.6, 0.6, 0.6)
self.draw_heading("line in", embiggen=5, margin=0)
self.draw_heading("line in", embiggen=5, top_margin=5, bot_margin=-4)
if audio.line_in_get_allowed():
if audio.input_engine_get_source_avail(audio.INPUT_SOURCE_LINE_IN):
col = avail_col
......@@ -480,7 +484,7 @@ class InputMenu(Submenu):
audio.line_in_set_gain_dB(tmp)
settings.num_line_in_gain_db.set_value(audio.line_in_get_gain_dB())
self.draw_heading("headset mic", embiggen=5, margin=0)
self.draw_heading("headset mic", embiggen=5, top_margin=5, bot_margin=-4)
if audio.headset_mic_get_allowed():
if audio.input_engine_get_source_avail(audio.INPUT_SOURCE_HEADSET_MIC):
......@@ -510,7 +514,7 @@ class InputMenu(Submenu):
tmp = audio.headset_mic_set_gain_dB(tmp)
settings.num_headset_mic_gain_db.set_value(tmp)
self.draw_heading("onboard mic", embiggen=5, margin=0)
self.draw_heading("onboard mic", embiggen=5, top_margin=5, bot_margin=-4)
if audio.onboard_mic_get_allowed():
col = avail_col
......
......@@ -23,12 +23,42 @@ class TinySampler(Application):
self.has_data_stored = [False] * 5
self.ct_prev = captouch.read()
self.mode = 0
self._num_modes = 3
self._num_modes = 6
self._mode = 0
self.press_event = [False] * 10
self.release_event = [False] * 10
self.pitch_shift = [0] * 5
def _check_mode_avail(self, mode):
if mode == 0:
return audio.input_engine_get_source_avail(audio.INPUT_SOURCE_ONBOARD_MIC)
if mode == 1:
return audio.input_engine_get_source_avail(audio.INPUT_SOURCE_LINE_IN)
if mode == 2:
return audio.input_engine_get_source_avail(audio.INPUT_SOURCE_HEADSET_MIC)
return True
@property
def mode(self):
return self._mode
@mode.setter
def mode(self, val):
val = val % self._num_modes
if self.mode == 0:
if val < 3:
direction = 1
else:
direction = -1
elif val > self.mode:
direction = 1
else:
direction = -1
while not self._check_mode_avail(val):
val = (val + direction) % self._num_modes
self._mode = val
def _build_synth(self):
if self.blm is None:
self.blm = bl00mbox.Channel("tiny sampler")
......@@ -79,7 +109,49 @@ class TinySampler(Application):
ctx.stroke()
ctx.restore()
def draw_mode_0(self, ctx):
def draw_play_mode(self, ctx):
ctx.save()
dist = 90
ctx.line_width = 5
for i in range(5):
if not self.has_data[i]:
ctx.rgb(0.4, 0.4, 0.4)
elif self.is_playing[i] and audio.input_thru_get_mute():
ctx.rgb(0.2, 0.2, 0.9)
else:
ctx.rgb(0.8, 0.8, 0.8)
ctx.move_to(0, -dist)
ctx.rel_line_to(0, -8)
ctx.rel_line_to(11, 8)
ctx.rel_line_to(-11, 8)
ctx.rel_line_to(0, -8)
ctx.fill()
ctx.move_to(0, 12 - dist)
ctx.rel_line_to(11, 0)
ctx.stroke()
ctx.move_to(0, 0)
ctx.rotate(6.28 / 10)
if not self.has_data[i]:
ctx.rgb(0.4, 0.4, 0.4)
elif self.is_playing[i] and not audio.input_thru_get_mute():
ctx.rgb(0.2, 0.9, 0.2)
else:
ctx.rgb(0.8, 0.8, 0.8)
ctx.move_to(-7, -dist)
ctx.rel_line_to(0, -8)
ctx.rel_line_to(11, 8)
ctx.rel_line_to(-11, 8)
ctx.rel_line_to(0, -8)
ctx.fill()
ctx.move_to(0, 0)
ctx.rotate(6.28 / 10)
ctx.restore()
def draw_rec_mode(self, ctx):
ctx.save()
dist = 90
ctx.line_width = 5
......@@ -110,7 +182,7 @@ class TinySampler(Application):
ctx.rotate(6.28 / 10)
ctx.restore()
def draw_mode_1(self, ctx):
def draw_save_mode(self, ctx):
ctx.save()
dist = 80
text_shift = 5
......@@ -138,7 +210,7 @@ class TinySampler(Application):
ctx.rotate(6.28 / 10 + 2 * rot_over)
ctx.restore()
def draw_mode_2(self, ctx):
def draw_pitch_mode(self, ctx):
ctx.save()
dist = 80
text_shift = 5
......@@ -165,12 +237,31 @@ class TinySampler(Application):
ctx.rgb(0.1, 0.5, 0.6)
ctx.line_width = 6
self.draw_two_petal_group(ctx, stop=5)
if self.mode < 3:
self.draw_rec_mode(ctx)
if self.mode == 3:
self.draw_play_mode(ctx)
elif self.mode == 4:
self.draw_save_mode(ctx)
elif self.mode == 5:
self.draw_pitch_mode(ctx)
ctx.text_align = ctx.CENTER
ctx.gray(0.8)
ctx.font_size = 18
if self.mode == 0:
self.draw_mode_0(ctx)
ctx.move_to(0, 0)
ctx.text("onboard")
ctx.move_to(0, ctx.font_size)
ctx.text("mic")
elif self.mode == 1:
self.draw_mode_1(ctx)
ctx.move_to(0, ctx.font_size / 2)
ctx.text("line in")
elif self.mode == 2:
self.draw_mode_2(ctx)
ctx.move_to(0, 0)
ctx.text("headset")
ctx.move_to(0, ctx.font_size)
ctx.text("mic")
def think(self, ins: InputState, delta_ms: int) -> None:
super().think(ins, delta_ms)
......@@ -186,10 +277,10 @@ class TinySampler(Application):
if self.blm is None:
return
if self.input.buttons.app.left.pressed:
self.mode = (self.mode - 1) % self._num_modes
self.mode -= 1
release_all = True
elif self.input.buttons.app.right.pressed:
self.mode = (self.mode + 1) % self._num_modes
self.mode += 1
release_all = True
else:
release_all = False
......@@ -208,20 +299,15 @@ class TinySampler(Application):
self.release_event[i] = True
if self.mode == 0:
if self.orig_source == audio.INPUT_SOURCE_NONE:
if audio.input_engine_get_source_avail(audio.INPUT_SOURCE_ONBOARD_MIC):
audio.input_engine_set_source(audio.INPUT_SOURCE_ONBOARD_MIC)
else:
audio.input_engine_set_source(audio.INPUT_SOURCE_AUTO)
else:
if audio.input_engine_get_source_avail(self.orig_source):
audio.input_engine_set_source(audio.self.orig_source)
else:
audio.input_engine_set_source(audio.INPUT_SOURCE_AUTO)
elif self.mode == 1:
audio.input_engine_set_source(audio.INPUT_SOURCE_LINE_IN)
elif self.mode == 2:
audio.input_engine_set_source(audio.INPUT_SOURCE_HEADSET_MIC)
else:
audio.input_engine_set_source(audio.INPUT_SOURCE_NONE)
if self.mode == 0 or release_all:
if self.mode < 3 or release_all:
for i in range(5):
if not self.is_recording[i]:
if self.press_event[i * 2]:
......@@ -240,7 +326,24 @@ class TinySampler(Application):
self.samplers[i].signals.rec_trigger.stop()
self.is_recording[i] = False
self.has_data[i] = True
elif self.mode == 1 or release_all:
if self.mode == 3 or release_all:
for i in range(5):
if self.press_event[i * 2]:
self.samplers[i].signals.trigger.start()
self.is_playing[i] = True
audio.input_thru_set_mute(True)
if self.release_event[i * 2]:
self.samplers[i].signals.trigger.stop()
self.is_playing[i] = False
audio.input_thru_set_mute(False)
for i in range(5):
if self.press_event[i * 2 + 1]:
self.samplers[i].signals.trigger.start()
self.is_playing[i] = True
if self.release_event[i * 2 + 1]:
self.samplers[i].signals.trigger.stop()
self.is_playing[i] = False
elif self.mode == 4 or release_all:
for i in range(5):
if self.press_event[i * 2]:
self.has_data_stored[i] = self.samplers[i].load(
......@@ -254,7 +357,7 @@ class TinySampler(Application):
"tiny_sample_" + str(i) + ".wav", overwrite=True
):
self.has_data_stored[i] = True
elif self.mode == 2 or release_all:
elif self.mode == 5 or release_all:
for i in range(5):
if self.press_event[i * 2]:
self.samplers[i].plugins.sampler.signals.pitch_shift.tone += 1
......@@ -282,13 +385,14 @@ class TinySampler(Application):
def on_enter(self, vm) -> None:
super().on_enter(vm)
self.mode = 0
self.orig_source = audio.input_engine_get_source()
self.orig_thru_mute = audio.input_thru_get_mute()
if self.blm is None:
self._build_synth()
def on_exit(self) -> None:
audio.input_engine_set_source(self.orig_source)
audio.input_thru_set_mute(self.orig_thru_mute)
for i in range(5):
if self.is_recording[i]:
self.samplers[i].signals.rec_trigger.stop()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment