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/wavfile.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
"""Read a PCM WAV into an int16 array, on any Python we run on."""
|
|
6
|
+
|
|
7
|
+
import array
|
|
8
|
+
import struct
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def read(path):
|
|
12
|
+
"""(sample_rate, channel_count, samples): 16-bit PCM, or 24/32-bit and
|
|
13
|
+
8-bit PCM converted to 16, or 32-bit float. Mono stays mono."""
|
|
14
|
+
with open(path, "rb") as f:
|
|
15
|
+
head = f.read(12)
|
|
16
|
+
if len(head) < 12 or head[0:4] != b"RIFF" or head[8:12] != b"WAVE":
|
|
17
|
+
raise ValueError("not a WAV file")
|
|
18
|
+
fmt = None
|
|
19
|
+
while True:
|
|
20
|
+
chunk = f.read(8)
|
|
21
|
+
if len(chunk) < 8:
|
|
22
|
+
raise ValueError("WAV has no data chunk")
|
|
23
|
+
cid = chunk[0:4]
|
|
24
|
+
size = struct.unpack("<I", chunk[4:8])[0]
|
|
25
|
+
if cid == b"fmt ":
|
|
26
|
+
body = f.read(size + (size & 1))
|
|
27
|
+
tag, ch, rate = struct.unpack("<HHI", body[0:8])
|
|
28
|
+
bits = struct.unpack("<H", body[14:16])[0]
|
|
29
|
+
if tag == 0xFFFE and size >= 26: # WAVE_FORMAT_EXTENSIBLE
|
|
30
|
+
tag = struct.unpack("<H", body[24:26])[0]
|
|
31
|
+
fmt = (tag, ch, rate, bits)
|
|
32
|
+
elif cid == b"data":
|
|
33
|
+
if fmt is None:
|
|
34
|
+
raise ValueError("WAV data before fmt")
|
|
35
|
+
data = f.read(size)
|
|
36
|
+
break
|
|
37
|
+
else:
|
|
38
|
+
f.seek(size + (size & 1), 1)
|
|
39
|
+
tag, ch, rate, bits = fmt
|
|
40
|
+
return rate, ch, _to_int16(data, tag, bits)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _to_int16(data, tag, bits):
|
|
44
|
+
if tag == 1 and bits == 16:
|
|
45
|
+
return array.array("h", data[: len(data) // 2 * 2])
|
|
46
|
+
out = array.array("h")
|
|
47
|
+
if tag == 1 and bits == 8:
|
|
48
|
+
for b in data:
|
|
49
|
+
out.append((b - 128) << 8)
|
|
50
|
+
elif tag == 1 and bits in (24, 32):
|
|
51
|
+
step = bits // 8
|
|
52
|
+
for i in range(0, len(data) - step + 1, step):
|
|
53
|
+
out.append(struct.unpack("<h", data[i + step - 2:i + step])[0])
|
|
54
|
+
elif tag == 3 and bits == 32:
|
|
55
|
+
for i in range(0, len(data) - 3, 4):
|
|
56
|
+
v = struct.unpack("<f", data[i:i + 4])[0]
|
|
57
|
+
v = -1.0 if v < -1.0 else (1.0 if v > 1.0 else v)
|
|
58
|
+
out.append(int(v * 32767))
|
|
59
|
+
else:
|
|
60
|
+
raise ValueError("unsupported WAV format %d/%d-bit" % (tag, bits))
|
|
61
|
+
return out
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def write(path, sample_rate, channel_count, pcm):
|
|
65
|
+
"""Write int16 PCM bytes as a WAV."""
|
|
66
|
+
n = len(pcm)
|
|
67
|
+
with open(path, "wb") as f:
|
|
68
|
+
f.write(b"RIFF" + struct.pack("<I", 36 + n) + b"WAVEfmt ")
|
|
69
|
+
f.write(struct.pack("<IHHIIHH", 16, 1, channel_count, sample_rate,
|
|
70
|
+
sample_rate * channel_count * 2,
|
|
71
|
+
channel_count * 2, 16))
|
|
72
|
+
f.write(b"data" + struct.pack("<I", n))
|
|
73
|
+
f.write(pcm)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Synth Station: pick an instrument, then play it from a MIDI keyboard.
|
|
5
|
+
|
|
6
|
+
An appkit app. The menu lists audioinstruments' instruments; the one you
|
|
7
|
+
pick plays through the board's audio out, from every MIDI keyboard the
|
|
8
|
+
program can reach, with the instrument panel as its front panel and a live
|
|
9
|
+
readout of what rendering it costs. Importing this does nothing; appkit
|
|
10
|
+
calls ``main(scope)``.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
__all__ = ["main"]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def main(scope):
|
|
17
|
+
"""Run Synth Station on *scope*; returns the running app."""
|
|
18
|
+
from .station import Station
|
|
19
|
+
|
|
20
|
+
return Station(scope)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name": "synthstation", "title": "Synth Station", "category": "Audio", "icon": "piano", "color": "#6A2C8C"}
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""The sound out, and what rendering it costs.
|
|
5
|
+
|
|
6
|
+
On a board whose ``board_peripherals`` publishes ``AUDIO_OUT`` with an I2S
|
|
7
|
+
wire, and whose firmware has the audio pump's I2S driver, the instrument's
|
|
8
|
+
output goes to the pump, which pulls it on its own core and writes each
|
|
9
|
+
block straight into I2S. The codec is powered through the board's
|
|
10
|
+
``audio_power`` when it has one. Anywhere else (a desktop) it plays through
|
|
11
|
+
the board config's ``audio_out``, which uses the pump too where there is
|
|
12
|
+
one. On a computer that's the sound device chosen for ``audio.out`` (the
|
|
13
|
+
connections picker, or `endpointkit.select`), and the instrument moves
|
|
14
|
+
there while it plays when the choice changes.
|
|
15
|
+
|
|
16
|
+
`Output.load` reads the pump's status block: how long a block of
|
|
17
|
+
audio took to render, as a share of how long it lasts, and how many times
|
|
18
|
+
the speaker ran dry since the instrument started. Where ``audio_out`` plays
|
|
19
|
+
through the pump, it reads the pump's own status block, so a board that
|
|
20
|
+
plays that way gets the same readout and the same voice cap.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
import struct
|
|
24
|
+
import sys
|
|
25
|
+
from array import array
|
|
26
|
+
|
|
27
|
+
RATE = 48000
|
|
28
|
+
CHANNELS = 2
|
|
29
|
+
#: Codec volume, 0 to 100, on a board that has one.
|
|
30
|
+
VOLUME = 85
|
|
31
|
+
#: The I2S DMA ring, in descriptors of so many frames. 4 x 128 is 10.7 ms
|
|
32
|
+
#: of latency at 48 kHz: short enough to play, long enough to ride out a
|
|
33
|
+
#: screen redraw.
|
|
34
|
+
DMA_DESC = 4
|
|
35
|
+
DMA_FRAME = 128
|
|
36
|
+
|
|
37
|
+
#: A browser's queue, in 10 ms chunks, and how far a stall may catch up, which
|
|
38
|
+
#: has to clear the queue or the first stall cuts the queue back to it. 40 ms
|
|
39
|
+
#: plays well on a keyboard; 120 ms rode out more but was too slow to play.
|
|
40
|
+
BROWSER_LOOKAHEAD = 4
|
|
41
|
+
BROWSER_CATCHUP = 6
|
|
42
|
+
|
|
43
|
+
#: What :meth:`Output.levels` looks at: the newest 100 ms, every 40th frame, which
|
|
44
|
+
#: is enough for a meter and costs the app about a millisecond.
|
|
45
|
+
LEVEL_FRAMES = 4800
|
|
46
|
+
LEVEL_STEP = 40
|
|
47
|
+
#: The pump's tap holds this much, more than the app reads between two looks.
|
|
48
|
+
TAP_FRAMES = 8192
|
|
49
|
+
|
|
50
|
+
_BLOCKS_FOREVER = 0x7FFFFFFF
|
|
51
|
+
# The status block's words (audiodsp's audiopump).
|
|
52
|
+
_BLOCKS, _BYTES, _PULL_US, _SINK_BYTES, _MAX_PULL_US, _DMA_BYTES = 0, 1, 12, 15, 20, 21
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class Output:
|
|
56
|
+
"""Plays one instrument at a time.
|
|
57
|
+
|
|
58
|
+
*scope* is the app's scope: the desktop output runs its service on the
|
|
59
|
+
app's timers. Construct it once; `start` and `stop` swap
|
|
60
|
+
instruments; `close` powers the codec down.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
def __init__(self, scope, rate=RATE, channels=CHANNELS):
|
|
64
|
+
self.scope = scope
|
|
65
|
+
self.rate = rate
|
|
66
|
+
self.channels = channels
|
|
67
|
+
self.instrument = None
|
|
68
|
+
self._out = None
|
|
69
|
+
self._status = None
|
|
70
|
+
self._powered = False
|
|
71
|
+
#: The codec volume asked for since opening, or None for the default.
|
|
72
|
+
self.volume = None
|
|
73
|
+
self._wire = None
|
|
74
|
+
self._power = None
|
|
75
|
+
self._dma_at_start = 0
|
|
76
|
+
self._starved = 0
|
|
77
|
+
self._base = 0
|
|
78
|
+
self._last = None
|
|
79
|
+
self._driver_last = None
|
|
80
|
+
self._gov = None
|
|
81
|
+
self._block_us = None
|
|
82
|
+
self._owner = None
|
|
83
|
+
self._tap = None
|
|
84
|
+
self._level_buf = None
|
|
85
|
+
self.underruns = 0
|
|
86
|
+
self.load_pct = None
|
|
87
|
+
self.worst_pct = None
|
|
88
|
+
import board_peripherals as bp
|
|
89
|
+
|
|
90
|
+
self._bp = bp
|
|
91
|
+
try:
|
|
92
|
+
import audiopump
|
|
93
|
+
except ImportError:
|
|
94
|
+
audiopump = None
|
|
95
|
+
try:
|
|
96
|
+
import _audioif # the pump's I2S driver, on a board
|
|
97
|
+
except ImportError:
|
|
98
|
+
_audioif = None
|
|
99
|
+
# The I2S driver's own count of silence, for when audio_out plays
|
|
100
|
+
# through the pump into this board's I2S.
|
|
101
|
+
self._driver_count = getattr(_audioif, "i2s_starved_bytes", None)
|
|
102
|
+
wire = getattr(getattr(bp, "AUDIO_OUT", None), "wire", None)
|
|
103
|
+
if wire is not None and _audioif is not None and hasattr(_audioif, "i2s_start"):
|
|
104
|
+
self._audioif = _audioif
|
|
105
|
+
self._pump = audiopump
|
|
106
|
+
self._wire = wire
|
|
107
|
+
self._power = getattr(bp, "audio_power", None)
|
|
108
|
+
else:
|
|
109
|
+
self._audioif = None
|
|
110
|
+
self._pump = audiopump
|
|
111
|
+
#: The computer's sound device chosen for ``audio.out``, or None for its default.
|
|
112
|
+
self.device = None
|
|
113
|
+
follow = getattr(scope, "follow", None)
|
|
114
|
+
if follow is not None and self._wire is None:
|
|
115
|
+
from appkit import connections
|
|
116
|
+
|
|
117
|
+
self._device_of = connections.device
|
|
118
|
+
self.device = connections.device(follow("audio.out", self._moved))
|
|
119
|
+
|
|
120
|
+
def _moved(self, endpoints):
|
|
121
|
+
"""Another sound output was chosen: the instrument plays on there."""
|
|
122
|
+
self.device = self._device_of(endpoints)
|
|
123
|
+
if self.instrument is not None and self._out is not None:
|
|
124
|
+
self.start(self.instrument)
|
|
125
|
+
|
|
126
|
+
@property
|
|
127
|
+
def on_board(self):
|
|
128
|
+
"""True when this drives the board's I2S itself."""
|
|
129
|
+
return self._wire is not None
|
|
130
|
+
|
|
131
|
+
@property
|
|
132
|
+
def can_play(self):
|
|
133
|
+
"""True when there's somewhere to play: the board's own I2S, or the
|
|
134
|
+
board config's ``audio_out``."""
|
|
135
|
+
return self._wire is not None or getattr(self._bp, "audio_out", None) is not None
|
|
136
|
+
|
|
137
|
+
def start(self, inst):
|
|
138
|
+
"""Play *inst*'s output, replacing whatever was playing."""
|
|
139
|
+
self.stop()
|
|
140
|
+
self.underruns = 0
|
|
141
|
+
self._starved = 0
|
|
142
|
+
self._base = 0
|
|
143
|
+
self._last = None
|
|
144
|
+
self._driver_last = None
|
|
145
|
+
self._gov = None
|
|
146
|
+
self._block_us = None
|
|
147
|
+
self._owner = None
|
|
148
|
+
self.load_pct = None
|
|
149
|
+
self.worst_pct = None
|
|
150
|
+
if self._wire is not None:
|
|
151
|
+
if self._power is not None and not self._powered:
|
|
152
|
+
self._power(True, volume=VOLUME if self.volume is None else self.volume)
|
|
153
|
+
self._powered = True
|
|
154
|
+
w = self._wire
|
|
155
|
+
self._audioif.i2s_start(
|
|
156
|
+
w.port, w.sck, w.ws, w.sd, self.rate, bits=16, channels=self.channels,
|
|
157
|
+
mclk=-1 if w.mck is None else w.mck, mclk_fs=w.mck_fs,
|
|
158
|
+
dma_desc=DMA_DESC, dma_frame=DMA_FRAME)
|
|
159
|
+
self._status = bytearray(self._pump.STATUS_BYTES)
|
|
160
|
+
self._dma_at_start = self._dma()
|
|
161
|
+
self._pump.spawn(inst.output, _BLOCKS_FOREVER, self._status, sink=True, timeout_ms=500)
|
|
162
|
+
else:
|
|
163
|
+
from audiodev import AudioFormat
|
|
164
|
+
|
|
165
|
+
# A computer's default output buffers for playback, too long for keys.
|
|
166
|
+
kwargs = {}
|
|
167
|
+
if sys.platform == "webassembly":
|
|
168
|
+
kwargs = {"lookahead_chunks": BROWSER_LOOKAHEAD, "max_catchup_chunks": BROWSER_CATCHUP}
|
|
169
|
+
if self.device is not None:
|
|
170
|
+
kwargs["device"] = self.device
|
|
171
|
+
out = self._bp.audio_out(AudioFormat(self.rate, self.channels, 16), latency="low", **kwargs)
|
|
172
|
+
out.attach(self.scope) # its service() on the app's timer
|
|
173
|
+
if self.volume is not None:
|
|
174
|
+
out.set_volume(self.volume)
|
|
175
|
+
out.play(inst.output)
|
|
176
|
+
self._out = out
|
|
177
|
+
self._attach_tap()
|
|
178
|
+
self.instrument = inst
|
|
179
|
+
|
|
180
|
+
def stop(self):
|
|
181
|
+
"""Silence. The instrument is left as it is, not deinitialised."""
|
|
182
|
+
self.instrument = None
|
|
183
|
+
if self._tap is not None:
|
|
184
|
+
self._pump.tap(None)
|
|
185
|
+
if self._wire is not None:
|
|
186
|
+
if self._status is not None:
|
|
187
|
+
self._pump.shutdown() # stops the pump task and closes I2S
|
|
188
|
+
self._status = None
|
|
189
|
+
return
|
|
190
|
+
out = self._out
|
|
191
|
+
self._out = None
|
|
192
|
+
if out is not None:
|
|
193
|
+
out.stop()
|
|
194
|
+
out.detach()
|
|
195
|
+
out.close()
|
|
196
|
+
|
|
197
|
+
def _attach_tap(self):
|
|
198
|
+
pump = self._pump
|
|
199
|
+
if pump is None or not hasattr(pump, "Tap"):
|
|
200
|
+
return
|
|
201
|
+
if self._tap is None:
|
|
202
|
+
self._tap = pump.Tap(frames=TAP_FRAMES, channel_count=self.channels)
|
|
203
|
+
self._level_buf = array("h", bytes(LEVEL_FRAMES * self.channels * 2))
|
|
204
|
+
pump.tap(self._tap)
|
|
205
|
+
|
|
206
|
+
def levels(self):
|
|
207
|
+
"""The newest audio's left and right peaks, 0.0 to 1.0.
|
|
208
|
+
|
|
209
|
+
Both 0.0 when nothing new has gone out, or where there's no tap.
|
|
210
|
+
"""
|
|
211
|
+
if self._tap is None:
|
|
212
|
+
return 0.0, 0.0
|
|
213
|
+
buf = self._level_buf
|
|
214
|
+
channels = self.channels
|
|
215
|
+
samples = self._tap.readinto(buf) // 2
|
|
216
|
+
left = right = 0
|
|
217
|
+
for i in range(0, samples - channels + 1, LEVEL_STEP * channels):
|
|
218
|
+
v = buf[i]
|
|
219
|
+
if v < 0:
|
|
220
|
+
v = -v
|
|
221
|
+
if v > left:
|
|
222
|
+
left = v
|
|
223
|
+
v = buf[i + channels - 1]
|
|
224
|
+
if v < 0:
|
|
225
|
+
v = -v
|
|
226
|
+
if v > right:
|
|
227
|
+
right = v
|
|
228
|
+
return left / 32768, right / 32768
|
|
229
|
+
|
|
230
|
+
def set_volume(self, percent):
|
|
231
|
+
"""The codec's volume, 0 to 100, now and for the next instrument."""
|
|
232
|
+
self.volume = percent
|
|
233
|
+
if self._powered:
|
|
234
|
+
self._power(True, volume=percent)
|
|
235
|
+
elif self._out is not None:
|
|
236
|
+
self._out.set_volume(percent)
|
|
237
|
+
|
|
238
|
+
def close(self):
|
|
239
|
+
self.stop()
|
|
240
|
+
if self._powered:
|
|
241
|
+
self._powered = False
|
|
242
|
+
try:
|
|
243
|
+
self._power(False)
|
|
244
|
+
except Exception:
|
|
245
|
+
pass
|
|
246
|
+
|
|
247
|
+
def _dma(self):
|
|
248
|
+
if hasattr(self._audioif, "i2s_dma_bytes"):
|
|
249
|
+
return self._audioif.i2s_dma_bytes()
|
|
250
|
+
return 0
|
|
251
|
+
|
|
252
|
+
def _pump_owner(self):
|
|
253
|
+
"""audiodev's pump owner, once ``audio_out`` plays through the pump."""
|
|
254
|
+
out = self._out
|
|
255
|
+
if out is None or not getattr(out, "pumped", False):
|
|
256
|
+
return None
|
|
257
|
+
if self._owner is None:
|
|
258
|
+
try:
|
|
259
|
+
from audiodev import pump
|
|
260
|
+
|
|
261
|
+
self._owner = pump.owner()
|
|
262
|
+
except Exception:
|
|
263
|
+
return None
|
|
264
|
+
return self._owner
|
|
265
|
+
|
|
266
|
+
def _status_block(self):
|
|
267
|
+
if self._status is not None:
|
|
268
|
+
return self._status
|
|
269
|
+
owner = self._pump_owner()
|
|
270
|
+
if owner is None:
|
|
271
|
+
return None
|
|
272
|
+
try:
|
|
273
|
+
return owner.status()
|
|
274
|
+
except Exception:
|
|
275
|
+
return None
|
|
276
|
+
|
|
277
|
+
def load(self):
|
|
278
|
+
"""Update ``load_pct``, ``worst_pct`` and ``underruns``; return them.
|
|
279
|
+
|
|
280
|
+
``load_pct`` is the render time of the blocks since the last call as
|
|
281
|
+
a percentage of the time they last: over 100 can't keep up.
|
|
282
|
+
``worst_pct`` is the slowest single block since `start`.
|
|
283
|
+
``underruns`` counts the calls between which the speaker ran out of
|
|
284
|
+
audio (on a board), or blocks the output had no room for (on a
|
|
285
|
+
desktop). Both loads are None until there's something to measure.
|
|
286
|
+
"""
|
|
287
|
+
status = self._status_block()
|
|
288
|
+
if status is None or self._pump is None:
|
|
289
|
+
return self.load_pct, self.worst_pct, self.underruns
|
|
290
|
+
# What the DMA has clocked out is read before the pump's counters, not
|
|
291
|
+
# after: if this thread is held up between the two reads, the bytes
|
|
292
|
+
# the pump wrote meanwhile must not look like silence. Read the other
|
|
293
|
+
# way round, a 200 ms pause here was reported as 200 ms starved.
|
|
294
|
+
dma_now = self._dma() if self._status is not None else 0
|
|
295
|
+
w = struct.unpack_from("<%dQ" % self._pump.STATUS_WORDS, status)
|
|
296
|
+
blocks, nbytes, pull_us = w[_BLOCKS], w[_BYTES], w[_PULL_US]
|
|
297
|
+
last = self._last
|
|
298
|
+
self._last = (blocks, nbytes, pull_us)
|
|
299
|
+
if last is not None and blocks > last[0]:
|
|
300
|
+
frames = (nbytes - last[1]) // (self.channels * 2)
|
|
301
|
+
if frames > 0:
|
|
302
|
+
self.load_pct = (pull_us - last[2]) * self.rate // (frames * 10000)
|
|
303
|
+
block_frames = frames // (blocks - last[0])
|
|
304
|
+
if block_frames:
|
|
305
|
+
self.worst_pct = w[_MAX_PULL_US] * self.rate // (block_frames * 10000)
|
|
306
|
+
driver_count = getattr(self._audioif, "i2s_starved_bytes", None) if self._status is not None else None
|
|
307
|
+
if driver_count is not None:
|
|
308
|
+
# The I2S driver counts, in its own interrupt, every descriptor
|
|
309
|
+
# that went out with no audio in it and every stretch the DMA was
|
|
310
|
+
# stopped. That is the silence itself. The byte totals compared
|
|
311
|
+
# below miss most of a flash write, which holds off the very
|
|
312
|
+
# interrupt that counts the bytes clocked out: 64 KB written to
|
|
313
|
+
# a board's flash cost 750 to 920 ms of sound and they showed 80
|
|
314
|
+
# to 220.
|
|
315
|
+
starved = driver_count()
|
|
316
|
+
if starved > self._starved:
|
|
317
|
+
self._starved = starved
|
|
318
|
+
self.underruns += 1
|
|
319
|
+
return self.load_pct, self.worst_pct, self.underruns
|
|
320
|
+
if self._status is not None:
|
|
321
|
+
dma = dma_now - self._dma_at_start
|
|
322
|
+
else:
|
|
323
|
+
# Through audio_out the pump counts what its own I2S clocked out;
|
|
324
|
+
# a desktop's pump never touches I2S and leaves this at 0.
|
|
325
|
+
dma = w[_DMA_BYTES] if self._pump.STATUS_WORDS > _DMA_BYTES else 0
|
|
326
|
+
if dma and self._status is None and self._driver_count is not None:
|
|
327
|
+
# audio_out plays through the pump into this board's I2S, so the
|
|
328
|
+
# driver's count is the silence. The byte totals below are
|
|
329
|
+
# published at different moments of a block: their difference
|
|
330
|
+
# swings by about a block while nothing is missing, and every new
|
|
331
|
+
# high in that swing read as a 1 ms underrun.
|
|
332
|
+
starved = self._driver_count()
|
|
333
|
+
prev = self._driver_last
|
|
334
|
+
self._driver_last = starved
|
|
335
|
+
if prev is not None:
|
|
336
|
+
# The count starts again from 0 when the channel reopens.
|
|
337
|
+
rise = starved - prev if starved >= prev else starved
|
|
338
|
+
if rise:
|
|
339
|
+
self._starved += rise
|
|
340
|
+
self.underruns += 1
|
|
341
|
+
return self.load_pct, self.worst_pct, self.underruns
|
|
342
|
+
if dma:
|
|
343
|
+
# On a board the DMA clocks out silence when the pump is late:
|
|
344
|
+
# bytes it sent that the pump never wrote are a gap you heard.
|
|
345
|
+
gap = dma - w[_SINK_BYTES]
|
|
346
|
+
if gap > self._starved:
|
|
347
|
+
self._starved = gap
|
|
348
|
+
# The ring clocks silence before the first block lands:
|
|
349
|
+
# that's the start, not a gap.
|
|
350
|
+
if last is not None:
|
|
351
|
+
self.underruns += 1
|
|
352
|
+
else:
|
|
353
|
+
self._base = gap
|
|
354
|
+
else:
|
|
355
|
+
owner = self._pump_owner()
|
|
356
|
+
if owner is not None:
|
|
357
|
+
try:
|
|
358
|
+
self.underruns = owner.health().get("dropped", 0)
|
|
359
|
+
except Exception:
|
|
360
|
+
pass
|
|
361
|
+
return self.load_pct, self.worst_pct, self.underruns
|
|
362
|
+
|
|
363
|
+
def pull_us(self):
|
|
364
|
+
"""Mean render time of a block since the last call, in microseconds.
|
|
365
|
+
|
|
366
|
+
None when nothing plays through the pump, or no block has landed
|
|
367
|
+
since the last call. The pump renders on its own core, so this is
|
|
368
|
+
what the instrument costs, whoever is late.
|
|
369
|
+
"""
|
|
370
|
+
status = self._status_block()
|
|
371
|
+
if status is None or self._pump is None:
|
|
372
|
+
return None
|
|
373
|
+
w = struct.unpack_from("<%dQ" % self._pump.STATUS_WORDS, status)
|
|
374
|
+
last = self._gov
|
|
375
|
+
self._gov = (w[_BLOCKS], w[_PULL_US], w[_BYTES])
|
|
376
|
+
if last is None or w[_BLOCKS] <= last[0]:
|
|
377
|
+
return None
|
|
378
|
+
blocks = w[_BLOCKS] - last[0]
|
|
379
|
+
frames = (w[_BYTES] - last[2]) // (self.channels * 2 * blocks)
|
|
380
|
+
if frames > 0 and self._status is None:
|
|
381
|
+
# audio_out chose the block; on our own I2S it's DMA_FRAME.
|
|
382
|
+
self._block_us = frames * 1000000 // self.rate
|
|
383
|
+
return (w[_PULL_US] - last[1]) // blocks
|
|
384
|
+
|
|
385
|
+
def block_us(self):
|
|
386
|
+
"""How long one block of the pump lasts, in microseconds.
|
|
387
|
+
|
|
388
|
+
Measured from the blocks `pull_us` last read; until then, the block
|
|
389
|
+
this drives I2S with itself.
|
|
390
|
+
"""
|
|
391
|
+
if self._block_us is not None:
|
|
392
|
+
return self._block_us
|
|
393
|
+
return DMA_FRAME * 1000000 // self.rate
|
|
394
|
+
|
|
395
|
+
def starved_ms(self):
|
|
396
|
+
"""On a board, the silence heard since `start`, in ms."""
|
|
397
|
+
return (self._starved - self._base) * 1000 // (self.rate * self.channels * 2)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Which instruments the menu lists, in which order.
|
|
5
|
+
|
|
6
|
+
Every instrument in ``audioinstruments.ALL`` has a small module of
|
|
7
|
+
constants (its face) that names it and its category, so the whole list is
|
|
8
|
+
built without creating any of them.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
#: Which tab a face's first CATEGORIES entry lands on; anything else is a synth.
|
|
12
|
+
TABS = {"Drum": "Drums", "Piano": "Keys", "Synth": "Synths"}
|
|
13
|
+
TAB_ORDER = ("Drums", "Keys", "Synths")
|
|
14
|
+
#: The instrument picked when nothing has been saved.
|
|
15
|
+
DEFAULT = "electric_piano"
|
|
16
|
+
#: What a choice saved under an instrument's old name means now.
|
|
17
|
+
RENAMED = {
|
|
18
|
+
"andromeda": "polya6", "arp2600": "patch2600", "b3": "tonewheel3", "clavinet": "clavichord",
|
|
19
|
+
"cp70": "electric_grand70", "cs80": "poly80", "farfisa": "compact_organ", "juno106": "poly106",
|
|
20
|
+
"jupiter8": "poly8", "minimoog": "mono_synth", "ms20": "duo20", "music_easel": "west_coast_synth",
|
|
21
|
+
"obxa": "polyxa", "odyssey": "duosynth", "pianet": "reed_piano", "polysix": "poly6",
|
|
22
|
+
"prophet5": "poly5", "rhodes": "electric_piano", "sh101": "mono101", "solina": "string_ensemble",
|
|
23
|
+
"taurus": "bass_pedals", "tb303": "acid303", "vox_continental": "combo_organ", "vp330": "vocoder330",
|
|
24
|
+
"wasp": "hybrid_mono", "wurlitzer": "reed_piano200a", "cr78": "rhythm78",
|
|
25
|
+
"simmons_sdsv": "electronic_drums5", "tr606": "rhythm606", "tr808": "rhythm808", "tr909": "rhythm909",
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def catalog(ai):
|
|
30
|
+
"""``((tab, ((module, display name), ...)), ...)`` for package *ai*.
|
|
31
|
+
|
|
32
|
+
The tabs come in ``TAB_ORDER`` and the instruments on each sorted by
|
|
33
|
+
name; an empty tab is left out.
|
|
34
|
+
"""
|
|
35
|
+
tabs = {tab: [] for tab in TAB_ORDER}
|
|
36
|
+
for name in ai.ALL:
|
|
37
|
+
face = ai.load(name)
|
|
38
|
+
categories = getattr(face, "CATEGORIES", ())
|
|
39
|
+
tab = TABS.get(categories[0] if categories else "", "Synths")
|
|
40
|
+
tabs[tab].append((name, face.DISPLAY_NAME))
|
|
41
|
+
return tuple((tab, tuple(sorted(tabs[tab], key=lambda item: item[1].lower()))) for tab in TAB_ORDER if tabs[tab])
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def find(entries, name):
|
|
45
|
+
"""``(tab, display name)`` of instrument *name* in a catalog, or ``(None, name)``."""
|
|
46
|
+
for tab, items in entries:
|
|
47
|
+
for module, display in items:
|
|
48
|
+
if module == name:
|
|
49
|
+
return tab, display
|
|
50
|
+
return None, name
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""The panel's small meters: one bar each for left and right, and a light that
|
|
5
|
+
flashes when a note comes in over MIDI.
|
|
6
|
+
|
|
7
|
+
Together they say which side a silence is on: the light with no bars is a note
|
|
8
|
+
the instrument didn't sound, and neither means nothing arrived. The bars show
|
|
9
|
+
what the board sends the codec, so the codec's volume doesn't move them.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import math
|
|
13
|
+
|
|
14
|
+
import lvgl as lv
|
|
15
|
+
|
|
16
|
+
#: The peaks an empty and a full bar stand for.
|
|
17
|
+
FLOOR_DB = -60.0
|
|
18
|
+
TOP_DB = 0.0
|
|
19
|
+
#: A bar's steps, 3 dB each. Every redraw of the panel slows the pump a little,
|
|
20
|
+
#: because the framebuffer shares memory with the audio's buffers, so the meters
|
|
21
|
+
#: draw ten times a second and a held note stays still within a step.
|
|
22
|
+
BAR_TOP = 20
|
|
23
|
+
TICK_MS = 100
|
|
24
|
+
#: Taken off per tick: a bar falls in a second, and the light goes out in 200 ms,
|
|
25
|
+
#: so that hits at 120 bpm stay apart.
|
|
26
|
+
BAR_DECAY = 2
|
|
27
|
+
LIGHT_DECAY = 64
|
|
28
|
+
#: The softest note's flash, of 127, so that it can still be seen.
|
|
29
|
+
LIGHT_FLOOR = 64
|
|
30
|
+
|
|
31
|
+
#: Sizes on an 800 wide panel. The light's column is as wide as its legend.
|
|
32
|
+
BAR_W = 9
|
|
33
|
+
BAR_GAP = 5
|
|
34
|
+
LIGHT_GAP = 4
|
|
35
|
+
LIGHT_W = 40
|
|
36
|
+
|
|
37
|
+
BAR_ON = 0x35C24A
|
|
38
|
+
TROUGH = 0x101114
|
|
39
|
+
LIGHT_ON = 0xFF5A36
|
|
40
|
+
LEGEND = 0x8A8D93
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def bar_height(peak):
|
|
44
|
+
"""A peak in 0.0 to 1.0 as a bar's height in 0 to `BAR_TOP`."""
|
|
45
|
+
if peak <= 0:
|
|
46
|
+
return 0
|
|
47
|
+
db = 20 * math.log10(peak)
|
|
48
|
+
return max(0, min(BAR_TOP, int((db - FLOOR_DB) * BAR_TOP / (TOP_DB - FLOOR_DB))))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _legend(parent, text, x, y, w):
|
|
52
|
+
label = lv.label(parent)
|
|
53
|
+
label.set_text(text)
|
|
54
|
+
label.set_style_text_color(lv.color_hex(LEGEND), 0)
|
|
55
|
+
label.set_style_text_font(getattr(lv, "font_montserrat_12", lv.font_montserrat_14), 0)
|
|
56
|
+
label.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
|
|
57
|
+
label.set_width(w)
|
|
58
|
+
label.set_pos(x, y)
|
|
59
|
+
return label
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class Meters:
|
|
63
|
+
"""The bars and the light, drawn on *parent* at (*x*, *y*), `width`
|
|
64
|
+
wide and *h* high."""
|
|
65
|
+
|
|
66
|
+
@staticmethod
|
|
67
|
+
def width(s):
|
|
68
|
+
"""How wide they draw, for a panel whose sizes go through *s*."""
|
|
69
|
+
return 2 * s(BAR_W) + s(BAR_GAP) + s(LIGHT_GAP) + s(LIGHT_W)
|
|
70
|
+
|
|
71
|
+
def __init__(self, parent, x, y, h, s):
|
|
72
|
+
bar_w = s(BAR_W)
|
|
73
|
+
gap = s(BAR_GAP)
|
|
74
|
+
bars_h = h - s(16)
|
|
75
|
+
self.bars = []
|
|
76
|
+
self._shown = [0, 0]
|
|
77
|
+
self._light = 0
|
|
78
|
+
self._lit = 0
|
|
79
|
+
for i, name in enumerate(("L", "R")):
|
|
80
|
+
at = x + i * (bar_w + gap)
|
|
81
|
+
bar = lv.bar(parent)
|
|
82
|
+
bar.set_size(bar_w, bars_h)
|
|
83
|
+
bar.set_pos(at, y)
|
|
84
|
+
bar.set_range(0, BAR_TOP)
|
|
85
|
+
bar.set_value(0, False)
|
|
86
|
+
bar.set_style_bg_color(lv.color_hex(TROUGH), lv.PART.MAIN)
|
|
87
|
+
bar.set_style_bg_opa(255, lv.PART.MAIN)
|
|
88
|
+
bar.set_style_bg_color(lv.color_hex(BAR_ON), lv.PART.INDICATOR)
|
|
89
|
+
bar.set_style_radius(2, lv.PART.MAIN)
|
|
90
|
+
bar.set_style_radius(2, lv.PART.INDICATOR)
|
|
91
|
+
bar.remove_flag(lv.obj.FLAG.CLICKABLE)
|
|
92
|
+
self.bars.append(bar)
|
|
93
|
+
_legend(parent, name, at - gap // 2, y + bars_h + 1, bar_w + gap)
|
|
94
|
+
size = s(14)
|
|
95
|
+
light_x = x + 2 * bar_w + gap + s(LIGHT_GAP)
|
|
96
|
+
socket = lv.obj(parent)
|
|
97
|
+
socket.remove_style_all()
|
|
98
|
+
socket.set_size(size, size)
|
|
99
|
+
socket.set_pos(light_x + (s(LIGHT_W) - size) // 2, y + (bars_h - size) // 2)
|
|
100
|
+
socket.set_style_radius(size // 2, 0)
|
|
101
|
+
socket.set_style_bg_color(lv.color_hex(TROUGH), 0)
|
|
102
|
+
socket.set_style_bg_opa(255, 0)
|
|
103
|
+
socket.remove_flag(lv.obj.FLAG.CLICKABLE)
|
|
104
|
+
lit = lv.obj(socket)
|
|
105
|
+
lit.remove_style_all()
|
|
106
|
+
lit.set_size(size, size)
|
|
107
|
+
lit.set_style_radius(size // 2, 0)
|
|
108
|
+
lit.set_style_bg_color(lv.color_hex(LIGHT_ON), 0)
|
|
109
|
+
lit.set_style_bg_opa(0, 0)
|
|
110
|
+
lit.remove_flag(lv.obj.FLAG.CLICKABLE)
|
|
111
|
+
self.lit = lit
|
|
112
|
+
_legend(parent, "MIDI", light_x, y + bars_h + 1, s(LIGHT_W))
|
|
113
|
+
|
|
114
|
+
def strike(self, velocity):
|
|
115
|
+
"""A note came in."""
|
|
116
|
+
self._light = max(self._light, LIGHT_FLOOR + velocity * (127 - LIGHT_FLOOR) // 127)
|
|
117
|
+
|
|
118
|
+
def tick(self, left, right):
|
|
119
|
+
"""Show the newest peaks, 0.0 to 1.0: a bar jumps up and falls slowly."""
|
|
120
|
+
shown = self._shown
|
|
121
|
+
for i, peak in enumerate((left, right)):
|
|
122
|
+
height = bar_height(peak)
|
|
123
|
+
if height < shown[i]:
|
|
124
|
+
# A step's wobble isn't worth a redraw, but silence is empty.
|
|
125
|
+
if height == shown[i] - 1 and height:
|
|
126
|
+
height = shown[i]
|
|
127
|
+
else:
|
|
128
|
+
height = max(height, shown[i] - BAR_DECAY)
|
|
129
|
+
if height != shown[i]:
|
|
130
|
+
shown[i] = height
|
|
131
|
+
self.bars[i].set_value(height, False)
|
|
132
|
+
light = self._light
|
|
133
|
+
if light != self._lit:
|
|
134
|
+
self._lit = light
|
|
135
|
+
self.lit.set_style_bg_opa(light * 2, 0)
|
|
136
|
+
self._light = max(0, light - LIGHT_DECAY)
|