omnipython-apps 0.1.4.dev8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- apps/__init__.py +5 -0
- apps/about/__init__.py +257 -0
- apps/about/app.json +1 -0
- apps/about/credits.py +12 -0
- apps/about/facts.py +398 -0
- apps/about/fonts/OFL.txt +93 -0
- apps/about/fonts/latin1_14.bin +0 -0
- apps/about/fonts/latin1_16.bin +0 -0
- apps/about/fonts/latin1_24.bin +0 -0
- apps/about/fonts/latin1_32.bin +0 -0
- apps/about/fonts/latin1_40.bin +0 -0
- apps/backline/__init__.py +58 -0
- apps/backline/app.json +1 -0
- apps/backline/app.py +475 -0
- apps/backline/art.py +717 -0
- apps/backline/ask.py +781 -0
- apps/backline/box.py +502 -0
- apps/backline/cast.py +137 -0
- apps/backline/desk/__init__.py +329 -0
- apps/backline/desk/editor.py +331 -0
- apps/backline/desk/grid.py +154 -0
- apps/backline/desk/look.py +169 -0
- apps/backline/desk/pedals.py +102 -0
- apps/backline/desk/perform.py +157 -0
- apps/backline/desk/prompt.py +210 -0
- apps/backline/desk/strip.py +159 -0
- apps/backline/desk_main.py +226 -0
- apps/backline/engine.py +622 -0
- apps/backline/floor.py +509 -0
- apps/backline/footswitch.py +119 -0
- apps/backline/glyphs.py +82 -0
- apps/backline/kits.py +428 -0
- apps/backline/midipedal.py +362 -0
- apps/backline/page_data.py +413 -0
- apps/backline/parts.py +145 -0
- apps/backline/pedal.py +107 -0
- apps/backline/remote.py +134 -0
- apps/backline/songs/ballad_68.json +1 -0
- apps/backline/songs/bossa.json +1 -0
- apps/backline/songs/country_train.json +1 -0
- apps/backline/songs/funk.json +1 -0
- apps/backline/songs/metal.json +1 -0
- apps/backline/songs/pop.json +1 -0
- apps/backline/songs/rock.json +1 -0
- apps/backline/songs/shuffle.json +1 -0
- apps/battery/__init__.py +101 -0
- apps/battery/app.json +1 -0
- apps/bit_world/act_deck.py +683 -0
- apps/bit_world/act_game.py +762 -0
- apps/bit_world/act_pet.py +1032 -0
- apps/bit_world/app.json +1 -0
- apps/bit_world/bit_output.py +45 -0
- apps/bit_world/bit_palette.py +503 -0
- apps/bit_world/bit_sound.py +431 -0
- apps/bit_world/bit_sprites.py +632 -0
- apps/bit_world/bit_world.py +534 -0
- apps/btreceiver/__init__.py +690 -0
- apps/btreceiver/app.json +1 -0
- apps/btreceiver/chime.py +155 -0
- apps/btreceiver/demo.py +529 -0
- apps/btreceiver/screen.py +633 -0
- apps/camera/__init__.py +316 -0
- apps/camera/app.json +1 -0
- apps/card/__init__.py +113 -0
- apps/card/app.json +1 -0
- apps/cast/__init__.py +631 -0
- apps/cast/app.json +1 -0
- apps/cast/receivers.py +193 -0
- apps/chess/__init__.py +18 -0
- apps/chess/app.json +1 -0
- apps/chess/app.py +922 -0
- apps/chess/art.py +323 -0
- apps/chess/ble.py +411 -0
- apps/chess/engine.py +925 -0
- apps/chess/game.py +327 -0
- apps/chess/net.py +261 -0
- apps/clock/__init__.py +38 -0
- apps/clock/app.json +1 -0
- apps/detect/__init__.py +214 -0
- apps/detect/app.json +1 -0
- apps/fmsynth/__init__.py +41 -0
- apps/fmsynth/algorithms.py +61 -0
- apps/fmsynth/app.json +1 -0
- apps/fmsynth/app.py +355 -0
- apps/fmsynth/editor.py +206 -0
- apps/fmsynth/engine.py +257 -0
- apps/fmsynth/meters.py +262 -0
- apps/fmsynth/midi.py +375 -0
- apps/fmsynth/panel_view.py +1071 -0
- apps/fmsynth/patches/fmsynth-01.syx +0 -0
- apps/fmsynth/settings.py +138 -0
- apps/fmsynth/voice.py +398 -0
- apps/gamepad/__init__.py +685 -0
- apps/gamepad/app.json +1 -0
- apps/gamepad/pad.py +94 -0
- apps/gamepad/watch.py +352 -0
- apps/hidden/__init__.py +72 -0
- apps/hidden/app.json +1 -0
- apps/home/__init__.py +483 -0
- apps/home/app.json +1 -0
- apps/home/main.py +36 -0
- apps/homeassistant/__init__.py +213 -0
- apps/homeassistant/api.py +104 -0
- apps/homeassistant/app.json +1 -0
- apps/huey/__init__.py +287 -0
- apps/huey/acting.py +184 -0
- apps/huey/actor.py +194 -0
- apps/huey/app.json +1 -0
- apps/huey/client.py +125 -0
- apps/huey/servers.py +121 -0
- apps/huey/settings.example.json +8 -0
- apps/huey/settings.py +97 -0
- apps/huey/turn.py +504 -0
- apps/huey/voice.py +217 -0
- apps/info/__init__.py +810 -0
- apps/info/app.json +1 -0
- apps/lora/__init__.py +62 -0
- apps/lora/app.json +1 -0
- apps/manifest.py +71 -0
- apps/medialink_baby_monitor/__init__.py +222 -0
- apps/medialink_baby_monitor/app.json +1 -0
- apps/medialink_doorbell/__init__.py +251 -0
- apps/medialink_doorbell/app.json +1 -0
- apps/medialink_hands_free/__init__.py +217 -0
- apps/medialink_hands_free/app.json +1 -0
- apps/medialink_surveillance_camera/__init__.py +258 -0
- apps/medialink_surveillance_camera/app.json +1 -0
- apps/medialink_video_doorbell/__init__.py +289 -0
- apps/medialink_video_doorbell/app.json +1 -0
- apps/medialink_videophone/__init__.py +273 -0
- apps/medialink_videophone/app.json +1 -0
- apps/medialink_walkie_talkie/__init__.py +228 -0
- apps/medialink_walkie_talkie/app.json +1 -0
- apps/midicontroller/__init__.py +774 -0
- apps/midicontroller/app.json +1 -0
- apps/midicontroller/links.py +421 -0
- apps/midicontroller/surface.py +343 -0
- apps/midiengine/__init__.py +977 -0
- apps/midiengine/app.json +1 -0
- apps/midiengine/banks.py +85 -0
- apps/midiengine/midiin.py +165 -0
- apps/midiengine/player.py +392 -0
- apps/midiengine/umidiparser.py +1413 -0
- apps/mp3/__init__.py +240 -0
- apps/mp3/app.json +1 -0
- apps/perch/__init__.py +119 -0
- apps/perch/app.json +1 -0
- apps/perch/huey.py +481 -0
- apps/perch/huey_props.py +386 -0
- apps/perch/huey_shift.py +42 -0
- apps/perch/huey_views.py +296 -0
- apps/perch/scene_bench.py +680 -0
- apps/perch/scene_coast.py +479 -0
- apps/perch/scene_desk.py +492 -0
- apps/perch/stage.py +1274 -0
- apps/perch/vec.py +366 -0
- apps/repl/__init__.py +325 -0
- apps/repl/app.json +1 -0
- apps/roku/__init__.py +156 -0
- apps/roku/app.json +1 -0
- apps/rokucam/__init__.py +362 -0
- apps/rokucam/app.json +1 -0
- apps/security/__init__.py +261 -0
- apps/security/app.json +1 -0
- apps/settings/__init__.py +221 -0
- apps/settings/app.json +1 -0
- apps/shell/__init__.py +33 -0
- apps/shell/app.json +1 -0
- apps/spotify/__init__.py +669 -0
- apps/spotify/app.json +1 -0
- apps/spotify/screen.py +82 -0
- apps/steps/__init__.py +58 -0
- apps/steps/app.json +1 -0
- apps/stompbox/__init__.py +31 -0
- apps/stompbox/app.json +1 -0
- apps/stompbox/app.py +668 -0
- apps/stompbox/boards.json +20 -0
- apps/stompbox/effects.py +241 -0
- apps/stompbox/engine.py +340 -0
- apps/stompbox/footswitch.py +331 -0
- apps/stompbox/inputs.py +449 -0
- apps/stompbox/meter.py +72 -0
- apps/stompbox/outputs.py +135 -0
- apps/stompbox/pedals.txt +45 -0
- apps/stompbox/presets.py +106 -0
- apps/stompbox/styles.py +135 -0
- apps/stompbox/ui.py +817 -0
- apps/stompbox/wavfile.py +73 -0
- apps/synthstation/__init__.py +20 -0
- apps/synthstation/app.json +1 -0
- apps/synthstation/audio.py +397 -0
- apps/synthstation/catalog.py +50 -0
- apps/synthstation/meters.py +136 -0
- apps/synthstation/midi.py +380 -0
- apps/synthstation/pads.py +177 -0
- apps/synthstation/parts.py +128 -0
- apps/synthstation/station.py +1069 -0
- apps/system/__init__.py +11 -0
- apps/system/app.json +1 -0
- apps/touchcal/__init__.py +324 -0
- apps/touchcal/app.json +1 -0
- apps/touchcal/fit.py +262 -0
- apps/wake/__init__.py +268 -0
- apps/wake/app.json +1 -0
- apps/wake/feed.py +155 -0
- apps/watch/__init__.py +355 -0
- apps/watch/app.json +1 -0
- apps/watch/faces.py +35 -0
- apps/watch/wheel.py +157 -0
- apps/weather/__init__.py +278 -0
- apps/weather/app.json +1 -0
- apps/weather/icons.py +172 -0
- apps/weather/sizing.py +71 -0
- apps/weather/zippad.py +172 -0
- omnipython_apps-0.1.4.dev8.dist-info/METADATA +33 -0
- omnipython_apps-0.1.4.dev8.dist-info/RECORD +218 -0
- omnipython_apps-0.1.4.dev8.dist-info/WHEEL +5 -0
- omnipython_apps-0.1.4.dev8.dist-info/top_level.txt +1 -0
apps/stompbox/app.py
ADDED
|
@@ -0,0 +1,668 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
"""The app: the engine, the screen, and what joins them.
|
|
6
|
+
|
|
7
|
+
A computer can set these in its environment; a board needs none of them:
|
|
8
|
+
|
|
9
|
+
STOMPBOX_CLIPS the folder of WAV clips
|
|
10
|
+
STOMPBOX_INPUT the capture endpoint ID Live opens (Windows)
|
|
11
|
+
STOMPBOX_OUT the speaker's endpoint ID (Windows)
|
|
12
|
+
STOMPBOX_LIVE set to anything: open on Live
|
|
13
|
+
STOMPBOX_CLOCK auto, same or two: whether input and speaker share a clock
|
|
14
|
+
STOMPBOX_TARGET the frames a drift resampler holds between two clocks
|
|
15
|
+
STOMPBOX_MIDI the MIDI input the foot controller is on, such as
|
|
16
|
+
windows:FootCtrl (see `footswitch.open_input`)
|
|
17
|
+
|
|
18
|
+
A live input and a speaker on one device share a clock and pass straight
|
|
19
|
+
through. On different devices a drift resampler holds a ring between them.
|
|
20
|
+
While live on Windows the screen shows the latency: what the software path
|
|
21
|
+
holds plus the device engine's period on each side, four times a second.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
import os
|
|
25
|
+
|
|
26
|
+
from appkit import connections
|
|
27
|
+
from appkit import data as appdata
|
|
28
|
+
from appkit import places
|
|
29
|
+
from multimer import ticks_diff, ticks_ms
|
|
30
|
+
|
|
31
|
+
from . import SAMPLE_RATE, effects, engine, footswitch, inputs, meter, outputs, presets, ui
|
|
32
|
+
|
|
33
|
+
try:
|
|
34
|
+
import audiopump
|
|
35
|
+
except ImportError:
|
|
36
|
+
audiopump = None
|
|
37
|
+
|
|
38
|
+
FOLDER = "guitar-clips" # the folder name, on the card, flash and the data root
|
|
39
|
+
|
|
40
|
+
# A board can't run every chain in real time. Nothing fails, the sound just
|
|
41
|
+
# arrives in fragments, so the app measures each pedal as it goes on the board,
|
|
42
|
+
# refuses one that would take the chain past KEEPS_UP on a board, and watches
|
|
43
|
+
# the pump against the clock while it plays.
|
|
44
|
+
WATCH_MS = 1000
|
|
45
|
+
KEEPS_UP = 0.9
|
|
46
|
+
|
|
47
|
+
#: The pedal a new app opens with, when the guitar set has it.
|
|
48
|
+
FIRST_PEDAL = "Overdrive"
|
|
49
|
+
|
|
50
|
+
# The meter's bar is drawn ten times a second and falls a step each time, 20 dB
|
|
51
|
+
# a second, and the clip light stays on for a second after the last clip.
|
|
52
|
+
METER_MS = 100
|
|
53
|
+
CLIP_HOLD_MS = 1000
|
|
54
|
+
|
|
55
|
+
current = None # the running App, for the console
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _env(name):
|
|
59
|
+
fn = getattr(os, "getenv", None)
|
|
60
|
+
return (fn(name) or None) if fn is not None else None
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _home():
|
|
64
|
+
return (_env("USERPROFILE") or _env("HOME") or "").replace("\\", "/")
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def clips_folders():
|
|
68
|
+
"""``$STOMPBOX_CLIPS`` or ``~/music/guitar-clips`` on a computer; on a
|
|
69
|
+
board ``/sd/guitar-clips``, ``/guitar-clips`` and ``/data/guitar-clips``
|
|
70
|
+
(`appkit.places`)."""
|
|
71
|
+
if appdata.desktop():
|
|
72
|
+
return [(_env("STOMPBOX_CLIPS") or _home() + "/music/" + FOLDER).replace("\\", "/")]
|
|
73
|
+
return places.folders(FOLDER)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def is_dir(path):
|
|
77
|
+
try:
|
|
78
|
+
return (os.stat(path)[0] & 0x4000) != 0
|
|
79
|
+
except OSError:
|
|
80
|
+
return False
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def find_clips(folder):
|
|
84
|
+
"""Every WAV in the folder and the folders under it, by name."""
|
|
85
|
+
found = []
|
|
86
|
+
stack = [folder]
|
|
87
|
+
while stack:
|
|
88
|
+
d = stack.pop()
|
|
89
|
+
try:
|
|
90
|
+
names = os.listdir(d)
|
|
91
|
+
except OSError:
|
|
92
|
+
continue
|
|
93
|
+
for n in names:
|
|
94
|
+
p = d + "/" + n
|
|
95
|
+
if is_dir(p):
|
|
96
|
+
stack.append(p)
|
|
97
|
+
elif n.lower().endswith(".wav"):
|
|
98
|
+
found.append(p)
|
|
99
|
+
found.sort(key=lambda p: p.lower())
|
|
100
|
+
return found
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class App:
|
|
104
|
+
def __init__(self, scope):
|
|
105
|
+
self.scope = scope
|
|
106
|
+
#: In a browser the page's microphone is the only input: no clips.
|
|
107
|
+
self.browser = inputs.in_browser()
|
|
108
|
+
self.folders = [] if self.browser else clips_folders()
|
|
109
|
+
self.clips = []
|
|
110
|
+
for folder in self.folders:
|
|
111
|
+
self.clips.extend(find_clips(folder))
|
|
112
|
+
self._heard_mic = False
|
|
113
|
+
self.all_effects = effects.names()
|
|
114
|
+
self.guitar = effects.guitar_set()
|
|
115
|
+
self.show_all = not self.guitar
|
|
116
|
+
#: The slot the editor shows; past the last pedal, the picker.
|
|
117
|
+
self.sel = 0
|
|
118
|
+
self._replacing = False
|
|
119
|
+
self.board_name = None
|
|
120
|
+
self._boards = []
|
|
121
|
+
self.desktop = appdata.desktop()
|
|
122
|
+
self.can_go_live = inputs.live_available()
|
|
123
|
+
self.speaker = _env("STOMPBOX_OUT")
|
|
124
|
+
# A live input wants the pump-driven speaker: through audiodev's
|
|
125
|
+
# player it would sit behind two Python-fed queues.
|
|
126
|
+
self.output = self.make_output(connections.device(scope.follow("audio.out", self._moved)))
|
|
127
|
+
self.engine = engine.Engine(self.output)
|
|
128
|
+
self.screen = None
|
|
129
|
+
self._clip = None # the clip Live took over from
|
|
130
|
+
self._play_t = None
|
|
131
|
+
self._lat = [] # the last second of latency samples
|
|
132
|
+
# None, not 0: ticks_diff against 0 is meaningless where ticks_ms
|
|
133
|
+
# starts near the top of its range (the Windows port does).
|
|
134
|
+
self._lat_t = None
|
|
135
|
+
self._lat_print = None
|
|
136
|
+
# A browser holds the page up whenever the computer is busy, so the
|
|
137
|
+
# pump falls behind there for reasons the pedals have no part in: the
|
|
138
|
+
# load each pedal measured is the figure that holds.
|
|
139
|
+
self._watching = audiopump is not None and not self.desktop and not self.browser
|
|
140
|
+
self._behind = None
|
|
141
|
+
self._watch_t = None
|
|
142
|
+
self._watch_quiet = False
|
|
143
|
+
self._watch_frames = 0
|
|
144
|
+
#: What the meter shows: the bar's lit steps, and the clip light.
|
|
145
|
+
self.level_steps = 0
|
|
146
|
+
self.clip = False
|
|
147
|
+
self._meter_t = None
|
|
148
|
+
self._clip_t = None
|
|
149
|
+
#: The foot controller: one learned switch per pedal.
|
|
150
|
+
self.switches = footswitch.Switches(
|
|
151
|
+
on_press=self._switch_pressed, on_learn=self._switch_learned,
|
|
152
|
+
path=appdata.join(appdata.app_dir("stompbox"), "midi.json"))
|
|
153
|
+
self.midi_ports = []
|
|
154
|
+
self.midi_names = ""
|
|
155
|
+
|
|
156
|
+
def make_output(self, device=None):
|
|
157
|
+
"""The speaker: the pump's own WASAPI one where there is one, else
|
|
158
|
+
the board's output or the computer's *device*. WASAPI is opened by an
|
|
159
|
+
endpoint ID, which the picker doesn't list, so only STOMPBOX_OUT
|
|
160
|
+
picks one there."""
|
|
161
|
+
if outputs.WasapiOutput.available():
|
|
162
|
+
return outputs.WasapiOutput(self.speaker)
|
|
163
|
+
return outputs.DefaultOutput(device=device)
|
|
164
|
+
|
|
165
|
+
def _moved(self, endpoints):
|
|
166
|
+
"""Another sound output was chosen: play on it from here."""
|
|
167
|
+
device = connections.device(endpoints)
|
|
168
|
+
if outputs.WasapiOutput.available() and device is not None:
|
|
169
|
+
self.status("WASAPI speakers are picked with STOMPBOX_OUT here")
|
|
170
|
+
return
|
|
171
|
+
try:
|
|
172
|
+
self.output = self.make_output(device)
|
|
173
|
+
except (OSError, ImportError, ValueError) as e:
|
|
174
|
+
self.status("Can't play on that output: %s" % e)
|
|
175
|
+
return
|
|
176
|
+
self.engine.set_output(self.output)
|
|
177
|
+
if self.screen is not None:
|
|
178
|
+
self.screen.out_label.set_text(self.output.describe())
|
|
179
|
+
|
|
180
|
+
# -- names for the screen ------------------------------------------------
|
|
181
|
+
|
|
182
|
+
def clip_names(self):
|
|
183
|
+
roots = [f.rstrip("/") + "/" for f in self.folders]
|
|
184
|
+
names = []
|
|
185
|
+
for p in self.clips:
|
|
186
|
+
for root in roots:
|
|
187
|
+
if p.startswith(root):
|
|
188
|
+
p = p[len(root):]
|
|
189
|
+
break
|
|
190
|
+
names.append(p)
|
|
191
|
+
return names
|
|
192
|
+
|
|
193
|
+
# -- what the screen asks for --------------------------------------------
|
|
194
|
+
|
|
195
|
+
def pick_clip(self, index):
|
|
196
|
+
if not (0 <= index < len(self.clips)):
|
|
197
|
+
return
|
|
198
|
+
path = self.clips[index]
|
|
199
|
+
try:
|
|
200
|
+
inp = inputs.ClipInput(path)
|
|
201
|
+
except (OSError, ValueError, MemoryError) as e:
|
|
202
|
+
self.status("Can't play that clip: %s" % e)
|
|
203
|
+
return
|
|
204
|
+
self.engine.set_input(inp)
|
|
205
|
+
if self.engine.playing:
|
|
206
|
+
self._play_t = ticks_ms()
|
|
207
|
+
self.status("%s, %d Hz, %.1f s" % (inp.name(), inp.file_rate, inp.seconds))
|
|
208
|
+
|
|
209
|
+
def go_live(self):
|
|
210
|
+
"""The input through the effect, from now on."""
|
|
211
|
+
self._clip = self.engine.input if self.engine.input is not None \
|
|
212
|
+
and self.engine.input.kind == "clip" else self._clip
|
|
213
|
+
target = _env("STOMPBOX_TARGET")
|
|
214
|
+
try:
|
|
215
|
+
inp = inputs.open_live(_env("STOMPBOX_INPUT"), self.speaker,
|
|
216
|
+
_env("STOMPBOX_CLOCK") or "auto",
|
|
217
|
+
int(target) if target else None)
|
|
218
|
+
except (OSError, ImportError, ValueError, TypeError, RuntimeError) as e:
|
|
219
|
+
self.status("Can't open the live input: %s" % e)
|
|
220
|
+
if self.screen is not None:
|
|
221
|
+
self.screen.show_live_button(False)
|
|
222
|
+
return
|
|
223
|
+
self._play_t = None
|
|
224
|
+
self.engine.set_input(inp)
|
|
225
|
+
self.engine.play()
|
|
226
|
+
out = getattr(self.output, "name", "the output")
|
|
227
|
+
if inp.clocks == 1:
|
|
228
|
+
clock = "One clock: straight through"
|
|
229
|
+
else:
|
|
230
|
+
clock = ("Two clocks: a drift resampler holds %.0f ms between them"
|
|
231
|
+
% (inp.target * 1000 / inp.sample_rate))
|
|
232
|
+
route = "%s %s %s" % (inp.name_in, ui.lv.SYMBOL.RIGHT, out)
|
|
233
|
+
print("live:", route, "|", clock)
|
|
234
|
+
if self.screen is not None:
|
|
235
|
+
self.screen.show_live(route, clock)
|
|
236
|
+
self.status("Live, %d Hz" % inp.sample_rate, good=True)
|
|
237
|
+
|
|
238
|
+
def go_clips(self):
|
|
239
|
+
"""Back to the clip Live took over from, stopped."""
|
|
240
|
+
self.engine.stop()
|
|
241
|
+
self.engine.set_input(self._clip)
|
|
242
|
+
self._lat = []
|
|
243
|
+
if self.screen is not None:
|
|
244
|
+
self.screen.show_clips()
|
|
245
|
+
self.screen.show_playing(False)
|
|
246
|
+
self.status("Live is off")
|
|
247
|
+
|
|
248
|
+
def set_live(self, on):
|
|
249
|
+
if on:
|
|
250
|
+
self.go_live()
|
|
251
|
+
else:
|
|
252
|
+
self.go_clips()
|
|
253
|
+
|
|
254
|
+
# -- the board ---------------------------------------------------------------
|
|
255
|
+
|
|
256
|
+
def picker_groups(self):
|
|
257
|
+
"""What the picker offers: the guitar set by group, then, with Show
|
|
258
|
+
all, every other effect under "More"."""
|
|
259
|
+
groups = []
|
|
260
|
+
for group, name in self.guitar:
|
|
261
|
+
if not groups or groups[-1][0] != group:
|
|
262
|
+
groups.append((group, []))
|
|
263
|
+
groups[-1][1].append(name)
|
|
264
|
+
if self.show_all:
|
|
265
|
+
shown = set(n for _, n in self.guitar)
|
|
266
|
+
rest = [n for n in self.all_effects if n not in shown]
|
|
267
|
+
if rest:
|
|
268
|
+
groups.append(("More", rest))
|
|
269
|
+
return groups
|
|
270
|
+
|
|
271
|
+
def _redraw(self):
|
|
272
|
+
if self.screen is None:
|
|
273
|
+
return
|
|
274
|
+
pedals = self.engine.pedals
|
|
275
|
+
self.screen.show_board(pedals, self.sel)
|
|
276
|
+
if self.sel < len(pedals) and not self._replacing:
|
|
277
|
+
self.screen.show_editor(pedals[self.sel])
|
|
278
|
+
else:
|
|
279
|
+
self.screen.show_picker(self.picker_groups(), self.show_all, self._replacing)
|
|
280
|
+
self.screen.show_chain_load(self.engine.load(), self._behind)
|
|
281
|
+
|
|
282
|
+
def select(self, index):
|
|
283
|
+
"""Edit the pedal at *index*; an empty slot opens the picker."""
|
|
284
|
+
self.sel = max(0, min(index, len(self.engine.pedals)))
|
|
285
|
+
self._replacing = False
|
|
286
|
+
self._redraw()
|
|
287
|
+
|
|
288
|
+
def add_pedal(self, name):
|
|
289
|
+
"""Put effect *name* in the selected slot: in place of the pedal
|
|
290
|
+
there when changing it, else after the last one."""
|
|
291
|
+
pedal = effects.Pedal(name)
|
|
292
|
+
try:
|
|
293
|
+
pedal.load = effects.measure(name)
|
|
294
|
+
except (OSError, ValueError, MemoryError, RuntimeError) as e:
|
|
295
|
+
print("couldn't measure %s: %r" % (name, e))
|
|
296
|
+
replacing = self._replacing and self.sel < len(self.engine.pedals)
|
|
297
|
+
if pedal.load is not None:
|
|
298
|
+
others = sum(p.load or 0 for i, p in enumerate(self.engine.pedals)
|
|
299
|
+
if p.on and not (replacing and i == self.sel))
|
|
300
|
+
total = others + pedal.load
|
|
301
|
+
if total > KEEPS_UP and not self.desktop:
|
|
302
|
+
self.status("%s would take the board to %d%% of real time: too much here"
|
|
303
|
+
% (pedal.title, int(total * 100)))
|
|
304
|
+
return
|
|
305
|
+
try:
|
|
306
|
+
if replacing:
|
|
307
|
+
self.engine.replace(self.sel, pedal)
|
|
308
|
+
else:
|
|
309
|
+
self.sel = self.engine.add(pedal)
|
|
310
|
+
except (ValueError, MemoryError, OSError) as e:
|
|
311
|
+
self.status("Can't add %s: %s" % (pedal.title, e))
|
|
312
|
+
return
|
|
313
|
+
self._replacing = False
|
|
314
|
+
self._behind = None
|
|
315
|
+
self._watch_t = None
|
|
316
|
+
self._redraw()
|
|
317
|
+
if pedal.load is not None:
|
|
318
|
+
self.status("%s takes %d%% of real time here" % (pedal.title, int(pedal.load * 100 + 0.5)))
|
|
319
|
+
|
|
320
|
+
def toggle(self, index):
|
|
321
|
+
"""The footswitch: the pedal at *index* in or out of the chain."""
|
|
322
|
+
if not (0 <= index < len(self.engine.pedals)):
|
|
323
|
+
self.select(index)
|
|
324
|
+
return
|
|
325
|
+
p = self.engine.pedals[index]
|
|
326
|
+
self.engine.set_on(index, not p.on)
|
|
327
|
+
self._behind = None
|
|
328
|
+
self._watch_t = None
|
|
329
|
+
if self.screen is not None:
|
|
330
|
+
self.screen.show_pedal_state(index)
|
|
331
|
+
self.screen.show_chain_load(self.engine.load(), None)
|
|
332
|
+
self.status("%s %s" % (p.title, "on" if p.on else "off"), good=p.on)
|
|
333
|
+
|
|
334
|
+
def move_selected(self, step):
|
|
335
|
+
if self.sel >= len(self.engine.pedals):
|
|
336
|
+
return
|
|
337
|
+
self.sel = self.engine.move(self.sel, self.sel + step)
|
|
338
|
+
self._redraw()
|
|
339
|
+
|
|
340
|
+
def remove_selected(self):
|
|
341
|
+
if self.sel >= len(self.engine.pedals):
|
|
342
|
+
return
|
|
343
|
+
p = self.engine.remove(self.sel)
|
|
344
|
+
self.sel = min(self.sel, len(self.engine.pedals))
|
|
345
|
+
self._redraw()
|
|
346
|
+
self.status("%s taken off the board" % p.title)
|
|
347
|
+
|
|
348
|
+
def change_selected(self):
|
|
349
|
+
"""Open the picker to swap the selected pedal for another."""
|
|
350
|
+
if self.sel < len(self.engine.pedals):
|
|
351
|
+
self._replacing = True
|
|
352
|
+
self._redraw()
|
|
353
|
+
|
|
354
|
+
def set_show_all(self, on):
|
|
355
|
+
self.show_all = on or not self.guitar
|
|
356
|
+
self._redraw()
|
|
357
|
+
|
|
358
|
+
def turn(self, key, value):
|
|
359
|
+
"""A knob on the selected pedal."""
|
|
360
|
+
if self.sel < len(self.engine.pedals):
|
|
361
|
+
self.engine.pedals[self.sel].set(key, value)
|
|
362
|
+
if self.screen is not None:
|
|
363
|
+
self.screen.show_pedal_state(self.sel)
|
|
364
|
+
|
|
365
|
+
def set_patch(self, index):
|
|
366
|
+
if self.sel < len(self.engine.pedals):
|
|
367
|
+
p = self.engine.pedals[self.sel]
|
|
368
|
+
p.set_patch(index)
|
|
369
|
+
if self.screen is not None:
|
|
370
|
+
self.screen.show_knobs(p)
|
|
371
|
+
self.screen.show_pedal_state(self.sel)
|
|
372
|
+
|
|
373
|
+
# -- the foot controller -------------------------------------------------------
|
|
374
|
+
|
|
375
|
+
def open_midi(self):
|
|
376
|
+
try:
|
|
377
|
+
self.midi_ports, self.midi_names = footswitch.open_input()
|
|
378
|
+
except (OSError, ImportError, ValueError, IndexError) as e:
|
|
379
|
+
self.midi_ports, self.midi_names = [], ""
|
|
380
|
+
print("stompbox: no MIDI in:", e)
|
|
381
|
+
if self.midi_names:
|
|
382
|
+
print("stompbox: MIDI in from", self.midi_names)
|
|
383
|
+
if self.screen is not None:
|
|
384
|
+
self.screen.show_midi(self.midi_names, self.switches.learned(), False)
|
|
385
|
+
|
|
386
|
+
def learn_switches(self, on):
|
|
387
|
+
"""Learn the controller's switches, pedal 1 to 4, or stop."""
|
|
388
|
+
if not on:
|
|
389
|
+
self.switches.learn(None)
|
|
390
|
+
self.status("MIDI learn stopped")
|
|
391
|
+
elif not self.midi_ports:
|
|
392
|
+
self.status("No MIDI input to learn from: plug the controller in and reopen the app")
|
|
393
|
+
on = False
|
|
394
|
+
else:
|
|
395
|
+
self.switches.learn(0)
|
|
396
|
+
if self.screen is not None:
|
|
397
|
+
self.screen.show_midi(self.midi_names, self.switches.learned(), on)
|
|
398
|
+
|
|
399
|
+
def _switch_learned(self, slot, msg):
|
|
400
|
+
if msg is None:
|
|
401
|
+
self.status("Press the switch for pedal %d" % (slot + 1), good=True)
|
|
402
|
+
return
|
|
403
|
+
print("stompbox: pedal %d's switch is %s" % (slot + 1, footswitch.describe(msg)))
|
|
404
|
+
if self.switches.learning is None:
|
|
405
|
+
self.status("Learned all four switches", good=True)
|
|
406
|
+
if self.screen is not None:
|
|
407
|
+
self.screen.show_midi(self.midi_names, self.switches.learned(), False)
|
|
408
|
+
|
|
409
|
+
def _switch_pressed(self, slot):
|
|
410
|
+
if slot < len(self.engine.pedals):
|
|
411
|
+
self.toggle(slot)
|
|
412
|
+
|
|
413
|
+
# -- boards ------------------------------------------------------------------
|
|
414
|
+
|
|
415
|
+
def boards(self):
|
|
416
|
+
"""The starter boards, then the saved ones: what the menu lists."""
|
|
417
|
+
self._boards = presets.starters() + presets.saved()
|
|
418
|
+
if self.screen is not None:
|
|
419
|
+
self.screen.show_boards([b["name"] for b in self._boards])
|
|
420
|
+
return self._boards
|
|
421
|
+
|
|
422
|
+
def load_board(self, index):
|
|
423
|
+
if not (0 <= index < len(self._boards)):
|
|
424
|
+
return
|
|
425
|
+
board = self._boards[index]
|
|
426
|
+
pedals, missing = presets.pedals(board)
|
|
427
|
+
for p in pedals:
|
|
428
|
+
try:
|
|
429
|
+
p.load = effects.measure(p.name)
|
|
430
|
+
except (OSError, ValueError, MemoryError, RuntimeError):
|
|
431
|
+
p.load = None
|
|
432
|
+
if not self.desktop:
|
|
433
|
+
total = 0.0
|
|
434
|
+
for p in pedals:
|
|
435
|
+
if p.on and p.load is not None:
|
|
436
|
+
total += p.load
|
|
437
|
+
if total > KEEPS_UP:
|
|
438
|
+
p.on = False
|
|
439
|
+
self.engine.set_board(pedals)
|
|
440
|
+
self.board_name = board["name"]
|
|
441
|
+
self.sel = 0
|
|
442
|
+
self._replacing = False
|
|
443
|
+
self._behind = None
|
|
444
|
+
self._watch_t = None
|
|
445
|
+
self._redraw()
|
|
446
|
+
note = "Board: %s" % board["name"]
|
|
447
|
+
if missing:
|
|
448
|
+
note += " (this build has no %s)" % ", ".join(missing)
|
|
449
|
+
off = [p.title for p in pedals if not p.on]
|
|
450
|
+
if off and not self.desktop:
|
|
451
|
+
note += "; left off to keep up: %s" % ", ".join(off)
|
|
452
|
+
self.status(note, good=not missing)
|
|
453
|
+
|
|
454
|
+
def save_board(self, name):
|
|
455
|
+
try:
|
|
456
|
+
presets.save(name, self.engine.pedals)
|
|
457
|
+
except OSError as e:
|
|
458
|
+
self.status("Can't save the board: %s" % e)
|
|
459
|
+
return
|
|
460
|
+
self.board_name = name
|
|
461
|
+
self.boards()
|
|
462
|
+
self.status("Saved the board as %s" % name, good=True)
|
|
463
|
+
|
|
464
|
+
def toggle_play(self):
|
|
465
|
+
if self.engine.playing:
|
|
466
|
+
self.engine.stop()
|
|
467
|
+
self._play_t = None
|
|
468
|
+
else:
|
|
469
|
+
self.engine.play()
|
|
470
|
+
self._play_t = ticks_ms()
|
|
471
|
+
if self.screen is not None:
|
|
472
|
+
self.screen.show_playing(self.engine.playing)
|
|
473
|
+
|
|
474
|
+
def set_loop(self, on):
|
|
475
|
+
self.engine.set_loop(on)
|
|
476
|
+
if self.engine.playing:
|
|
477
|
+
self._play_t = ticks_ms()
|
|
478
|
+
if self.screen is not None:
|
|
479
|
+
self.screen.show_loop(on)
|
|
480
|
+
|
|
481
|
+
def set_master(self, level):
|
|
482
|
+
self.engine.set_master(level)
|
|
483
|
+
if self.screen is not None:
|
|
484
|
+
self.screen.show_master(level)
|
|
485
|
+
|
|
486
|
+
def status(self, text, good=False):
|
|
487
|
+
print(text)
|
|
488
|
+
if self.screen is not None:
|
|
489
|
+
self.screen.show_status(text, good)
|
|
490
|
+
|
|
491
|
+
# -- the loop --------------------------------------------------------------
|
|
492
|
+
|
|
493
|
+
def tick(self):
|
|
494
|
+
try:
|
|
495
|
+
self._tick()
|
|
496
|
+
except Exception as e: # noqa: BLE001 - LVGL swallows a timer's errors
|
|
497
|
+
if not getattr(self, "_tick_err", False):
|
|
498
|
+
self._tick_err = True
|
|
499
|
+
print("tick failed:", repr(e))
|
|
500
|
+
|
|
501
|
+
def _tick(self):
|
|
502
|
+
for port in self.midi_ports:
|
|
503
|
+
self.switches.read_port(port)
|
|
504
|
+
self.engine.service()
|
|
505
|
+
self._meter()
|
|
506
|
+
if self.browser and not self._heard_mic:
|
|
507
|
+
inp = self.engine.input
|
|
508
|
+
if inp is not None and getattr(inp, "listening", False):
|
|
509
|
+
self._heard_mic = True
|
|
510
|
+
self.status("Live, %d Hz" % inp.sample_rate, good=True)
|
|
511
|
+
if self._watching:
|
|
512
|
+
self._watch()
|
|
513
|
+
try:
|
|
514
|
+
self._latency()
|
|
515
|
+
except Exception as e: # noqa: BLE001 - a readout never stops the app
|
|
516
|
+
if not getattr(self, "_lat_err", False):
|
|
517
|
+
self._lat_err = True
|
|
518
|
+
print("latency readout failed:", repr(e))
|
|
519
|
+
s = self.screen
|
|
520
|
+
if s is not None:
|
|
521
|
+
if not self.engine.playing and self._play_t is not None:
|
|
522
|
+
self._play_t = None
|
|
523
|
+
s.show_playing(False)
|
|
524
|
+
inp = self.engine.input
|
|
525
|
+
if self._play_t is not None and inp is not None:
|
|
526
|
+
at = ticks_diff(ticks_ms(), self._play_t) / 1000
|
|
527
|
+
if self.engine.loop and inp.seconds:
|
|
528
|
+
at = at % inp.seconds
|
|
529
|
+
s.show_position("%s / %s" % (_clock(at), _clock(inp.seconds)))
|
|
530
|
+
elif inp is not None and inp.kind == "clip":
|
|
531
|
+
s.show_position("-- / %s" % _clock(inp.seconds))
|
|
532
|
+
|
|
533
|
+
def _meter(self):
|
|
534
|
+
"""Move the level bar and the clip light, ten times a second."""
|
|
535
|
+
now = ticks_ms()
|
|
536
|
+
if self._meter_t is not None and ticks_diff(now, self._meter_t) < METER_MS:
|
|
537
|
+
return
|
|
538
|
+
self._meter_t = now
|
|
539
|
+
level, clipped = self.engine.level()
|
|
540
|
+
# Up at once, down a step at a time, as a peak meter falls.
|
|
541
|
+
steps = max(meter.steps(level), self.level_steps - 1)
|
|
542
|
+
if clipped:
|
|
543
|
+
self._clip_t = now
|
|
544
|
+
elif self._clip_t is not None and ticks_diff(now, self._clip_t) >= CLIP_HOLD_MS:
|
|
545
|
+
self._clip_t = None
|
|
546
|
+
clip = self._clip_t is not None
|
|
547
|
+
if steps == self.level_steps and clip == self.clip:
|
|
548
|
+
return # nothing to redraw
|
|
549
|
+
self.level_steps = steps
|
|
550
|
+
self.clip = clip
|
|
551
|
+
if self.screen is not None:
|
|
552
|
+
self.screen.show_level(steps, clip)
|
|
553
|
+
|
|
554
|
+
def _watch(self):
|
|
555
|
+
"""Measure the chain against the clock while it plays, and say when
|
|
556
|
+
it falls behind: the measurement at adding time is a guess, and this
|
|
557
|
+
is what the board actually does."""
|
|
558
|
+
now = ticks_ms()
|
|
559
|
+
if self._watch_t is None:
|
|
560
|
+
self._watch_t = now
|
|
561
|
+
self._watch_frames = audiopump.now()
|
|
562
|
+
return
|
|
563
|
+
ms = ticks_diff(now, self._watch_t)
|
|
564
|
+
if ms < WATCH_MS:
|
|
565
|
+
return
|
|
566
|
+
speed = (audiopump.now() - self._watch_frames) * 1000 / (ms * SAMPLE_RATE)
|
|
567
|
+
self._watch_t = None
|
|
568
|
+
if speed == 0:
|
|
569
|
+
# No sound yet (a browser waits for a tap), so the next second,
|
|
570
|
+
# which the sound starts part way through, doesn't count either.
|
|
571
|
+
self._watch_quiet = True
|
|
572
|
+
return
|
|
573
|
+
if self._watch_quiet:
|
|
574
|
+
self._watch_quiet = False
|
|
575
|
+
return
|
|
576
|
+
behind = speed if speed < KEEPS_UP else None
|
|
577
|
+
if behind != self._behind and self.screen is not None:
|
|
578
|
+
self.screen.show_chain_load(self.engine.load(), behind)
|
|
579
|
+
if behind is not None and self._behind is None:
|
|
580
|
+
self.status("The board runs at %d%% of real time: switch a pedal off"
|
|
581
|
+
% (speed * 100))
|
|
582
|
+
self._behind = behind
|
|
583
|
+
|
|
584
|
+
def _latency(self):
|
|
585
|
+
"""Sample the latency four times a second and show the last second's
|
|
586
|
+
mean, so the figure moves with the path but doesn't flicker."""
|
|
587
|
+
now = ticks_ms()
|
|
588
|
+
if self._lat_t is not None and ticks_diff(now, self._lat_t) < 250:
|
|
589
|
+
return
|
|
590
|
+
self._lat_t = now
|
|
591
|
+
got = self.engine.latency() if self.engine.input is not None \
|
|
592
|
+
and self.engine.input.kind == "live" else None
|
|
593
|
+
if got is None:
|
|
594
|
+
return
|
|
595
|
+
self._lat.append(got)
|
|
596
|
+
if len(self._lat) > 4:
|
|
597
|
+
self._lat.pop(0)
|
|
598
|
+
n = len(self._lat)
|
|
599
|
+
total = sum(x[0] for x in self._lat) / n
|
|
600
|
+
held = sum(x[1] for x in self._lat) / n
|
|
601
|
+
periods = sum(x[2] for x in self._lat) / n
|
|
602
|
+
inp = self.engine.input
|
|
603
|
+
extra = ""
|
|
604
|
+
if inp.drift is not None:
|
|
605
|
+
extra = ", %+.0f ppm, %d underruns" % (inp.drift.ppm,
|
|
606
|
+
inp.drift.underruns)
|
|
607
|
+
if self.screen is not None:
|
|
608
|
+
self.screen.show_latency(total, held, periods, extra)
|
|
609
|
+
if self._lat_print is None or ticks_diff(now, self._lat_print) >= 5000:
|
|
610
|
+
self._lat_print = now
|
|
611
|
+
print("latency %.1f ms = held %.1f + periods %.1f%s"
|
|
612
|
+
% (total, held, periods, extra))
|
|
613
|
+
|
|
614
|
+
# -- start and stop --------------------------------------------------------
|
|
615
|
+
|
|
616
|
+
def close(self):
|
|
617
|
+
global current
|
|
618
|
+
current = None
|
|
619
|
+
for port in self.midi_ports:
|
|
620
|
+
try:
|
|
621
|
+
port.close()
|
|
622
|
+
except (OSError, AttributeError):
|
|
623
|
+
pass
|
|
624
|
+
self.midi_ports = []
|
|
625
|
+
self.engine.close()
|
|
626
|
+
|
|
627
|
+
def begin(self):
|
|
628
|
+
self.screen = ui.Screen(self, self.scope)
|
|
629
|
+
self.screen.out_label.set_text(self.output.describe())
|
|
630
|
+
names = [n for _, n in self.guitar] or self.all_effects
|
|
631
|
+
first = FIRST_PEDAL if FIRST_PEDAL in names else (names[0] if names else None)
|
|
632
|
+
self.boards()
|
|
633
|
+
self.open_midi()
|
|
634
|
+
if first is not None:
|
|
635
|
+
self.add_pedal(first)
|
|
636
|
+
else:
|
|
637
|
+
self._redraw()
|
|
638
|
+
if self.browser:
|
|
639
|
+
pass
|
|
640
|
+
elif self.clips:
|
|
641
|
+
self.screen.clip_dd.set_selected(0)
|
|
642
|
+
self.pick_clip(0)
|
|
643
|
+
else:
|
|
644
|
+
self.status("No WAV files in %s" % " or ".join(self.folders))
|
|
645
|
+
self.set_loop(True)
|
|
646
|
+
self.set_master(self.engine.master)
|
|
647
|
+
if self.browser:
|
|
648
|
+
self.go_live()
|
|
649
|
+
inp = self.engine.input
|
|
650
|
+
if inp is not None and inp.kind == "live":
|
|
651
|
+
self.status("Tap the page to let Stompbox hear your microphone")
|
|
652
|
+
elif self.can_go_live and _env("STOMPBOX_LIVE"):
|
|
653
|
+
self.screen.show_live_button(True)
|
|
654
|
+
self.go_live()
|
|
655
|
+
self.scope.every(10, lambda t: self.tick())
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
def _clock(seconds):
|
|
659
|
+
s = int(seconds)
|
|
660
|
+
return "%d:%02d" % (s // 60, s % 60)
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
def start(scope):
|
|
664
|
+
global current
|
|
665
|
+
places.hold_card(scope) # read-only, while the app is open
|
|
666
|
+
current = App(scope)
|
|
667
|
+
scope.on_close(current.close)
|
|
668
|
+
current.begin()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[
|
|
2
|
+
{"name": "Clean",
|
|
3
|
+
"pedals": [{"name": "Compressor", "on": true, "patch": 0},
|
|
4
|
+
{"name": "Chorus", "on": true, "patch": 0},
|
|
5
|
+
{"name": "Reverb", "on": true, "patch": 0}]},
|
|
6
|
+
{"name": "Crunch",
|
|
7
|
+
"pedals": [{"name": "NoiseGate", "on": true, "patch": 0},
|
|
8
|
+
{"name": "Overdrive", "on": true, "patch": 0},
|
|
9
|
+
{"name": "CabinetSim", "on": true, "patch": 0},
|
|
10
|
+
{"name": "SlapbackDelay", "on": true, "patch": 0}]},
|
|
11
|
+
{"name": "Lead",
|
|
12
|
+
"pedals": [{"name": "Distortion", "on": true, "patch": 0},
|
|
13
|
+
{"name": "CabinetSim", "on": true, "patch": 0},
|
|
14
|
+
{"name": "DigitalDelay", "on": true, "patch": 0},
|
|
15
|
+
{"name": "Reverb", "on": true, "patch": 0}]},
|
|
16
|
+
{"name": "Ambient",
|
|
17
|
+
"pedals": [{"name": "Compressor", "on": true, "patch": 0},
|
|
18
|
+
{"name": "TapeDelay", "on": true, "patch": 0},
|
|
19
|
+
{"name": "ShimmerHall", "on": true, "patch": 0}]}
|
|
20
|
+
]
|