omnipython-applibs 0.1.2.dev16__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.
Files changed (143) hide show
  1. appkit/__init__.py +52 -0
  2. appkit/__init__.pyi +17 -0
  3. appkit/data.py +149 -0
  4. appkit/data.pyi +25 -0
  5. appkit/foreground.py +357 -0
  6. appkit/foreground.pyi +45 -0
  7. appkit/home.py +19 -0
  8. appkit/home.pyi +8 -0
  9. appkit/hover.py +59 -0
  10. appkit/hover.pyi +13 -0
  11. appkit/index.py +199 -0
  12. appkit/index.pyi +30 -0
  13. appkit/launcher.py +1075 -0
  14. appkit/launcher.pyi +96 -0
  15. appkit/manifest.py +75 -0
  16. appkit/manifest.pyi +8 -0
  17. appkit/net.py +167 -0
  18. appkit/net.pyi +34 -0
  19. appkit/places.py +202 -0
  20. appkit/places.pyi +39 -0
  21. appkit/py.typed +0 -0
  22. appkit/scope.py +636 -0
  23. appkit/scope.pyi +110 -0
  24. appkit/shell.py +121 -0
  25. appkit/shell.pyi +32 -0
  26. appkit/worker.py +409 -0
  27. appkit/worker.pyi +83 -0
  28. controlkit/__init__.py +19 -0
  29. controlkit/__init__.pyi +10 -0
  30. controlkit/_draw.py +88 -0
  31. controlkit/_safe.py +29 -0
  32. controlkit/dotmatrix.py +101 -0
  33. controlkit/dotmatrix.pyi +23 -0
  34. controlkit/encoder.py +297 -0
  35. controlkit/encoder.pyi +55 -0
  36. controlkit/font5x7.py +22 -0
  37. controlkit/font5x7.pyi +11 -0
  38. controlkit/lamp_button.py +92 -0
  39. controlkit/lamp_button.pyi +40 -0
  40. controlkit/meter.py +86 -0
  41. controlkit/meter.pyi +30 -0
  42. controlkit/mock.py +116 -0
  43. controlkit/mock.pyi +35 -0
  44. controlkit/pad_grid.py +113 -0
  45. controlkit/pad_grid.pyi +41 -0
  46. controlkit/py.typed +0 -0
  47. controlkit/slider.py +185 -0
  48. controlkit/slider.pyi +49 -0
  49. controlkit/sprites.py +279 -0
  50. controlkit/sprites.pyi +22 -0
  51. controlkit/theme.py +120 -0
  52. controlkit/theme.pyi +15 -0
  53. deskkit/__init__.py +74 -0
  54. deskkit/__init__.pyi +18 -0
  55. deskkit/forecast.py +261 -0
  56. deskkit/forecast.pyi +40 -0
  57. deskkit/localtime.py +215 -0
  58. deskkit/localtime.pyi +33 -0
  59. deskkit/py.typed +0 -0
  60. deskkit/shell.py +113 -0
  61. deskkit/shell.pyi +33 -0
  62. omnipython_applibs-0.1.2.dev16.dist-info/METADATA +90 -0
  63. omnipython_applibs-0.1.2.dev16.dist-info/RECORD +143 -0
  64. omnipython_applibs-0.1.2.dev16.dist-info/WHEEL +5 -0
  65. omnipython_applibs-0.1.2.dev16.dist-info/licenses/LICENSE +21 -0
  66. omnipython_applibs-0.1.2.dev16.dist-info/top_level.txt +9 -0
  67. programkit/__init__.py +27 -0
  68. programkit/__init__.pyi +8 -0
  69. programkit/board.py +56 -0
  70. programkit/board.pyi +20 -0
  71. programkit/press.py +63 -0
  72. programkit/press.pyi +17 -0
  73. programkit/py.typed +0 -0
  74. programkit/rows.py +149 -0
  75. programkit/rows.pyi +34 -0
  76. sayso/__init__.py +109 -0
  77. sayso/__init__.pyi +124 -0
  78. sayso/auth.py +811 -0
  79. sayso/auth.pyi +102 -0
  80. sayso/client.py +1286 -0
  81. sayso/client.pyi +138 -0
  82. sayso/keepalive.py +371 -0
  83. sayso/keepalive.pyi +53 -0
  84. sayso/local.py +85 -0
  85. sayso/local.pyi +28 -0
  86. sayso/object_specs.py +706 -0
  87. sayso/object_specs.pyi +8 -0
  88. sayso/objects.py +411 -0
  89. sayso/objects.pyi +854 -0
  90. sayso/py.typed +0 -0
  91. sayso/schema_coverage.py +210 -0
  92. sayso/schema_coverage.pyi +13 -0
  93. sayso/transport.py +426 -0
  94. sayso/transport.pyi +47 -0
  95. songmodel/__init__.py +30 -0
  96. songmodel/__init__.pyi +9 -0
  97. songmodel/link.py +189 -0
  98. songmodel/link.pyi +53 -0
  99. songmodel/model.py +238 -0
  100. songmodel/model.pyi +40 -0
  101. songmodel/page.html +225 -0
  102. songmodel/page_data.py +236 -0
  103. songmodel/page_data.pyi +6 -0
  104. songmodel/py.typed +0 -0
  105. soundmodule/__init__.py +7 -0
  106. soundmodule/__init__.pyi +6 -0
  107. soundmodule/engine.py +1001 -0
  108. soundmodule/engine.pyi +196 -0
  109. soundmodule/names.py +298 -0
  110. soundmodule/names.pyi +30 -0
  111. soundmodule/pipes.py +105 -0
  112. soundmodule/pipes.pyi +31 -0
  113. soundmodule/py.typed +0 -0
  114. soundmodule/run.py +249 -0
  115. soundmodule/run.pyi +49 -0
  116. spectrum/__init__.py +72 -0
  117. spectrum/__init__.pyi +30 -0
  118. spectrum/analyzer.py +231 -0
  119. spectrum/analyzer.pyi +67 -0
  120. spectrum/fake_music.py +201 -0
  121. spectrum/fake_music.pyi +36 -0
  122. spectrum/pump_levels.py +126 -0
  123. spectrum/pump_levels.pyi +46 -0
  124. spectrum/py.typed +0 -0
  125. spectrum/spectrum_view.py +403 -0
  126. spectrum/spectrum_view.pyi +80 -0
  127. touchkit/__init__.py +4 -0
  128. touchkit/__init__.pyi +4 -0
  129. touchkit/cam.py +146 -0
  130. touchkit/cam.pyi +35 -0
  131. touchkit/clock.py +18 -0
  132. touchkit/clock.pyi +6 -0
  133. touchkit/ecp.py +134 -0
  134. touchkit/ecp.pyi +28 -0
  135. touchkit/net.py +347 -0
  136. touchkit/net.pyi +27 -0
  137. touchkit/py.typed +0 -0
  138. touchkit/settings.py +85 -0
  139. touchkit/settings.pyi +17 -0
  140. touchkit/shell.py +268 -0
  141. touchkit/shell.pyi +42 -0
  142. touchkit/ui.py +167 -0
  143. touchkit/ui.pyi +53 -0
spectrum/analyzer.pyi ADDED
@@ -0,0 +1,67 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """The spectrum analyzer as a widget any app can put on its screen."""
5
+
6
+ from typing import Any, Callable, Literal, Protocol
7
+
8
+ from .spectrum_view import SpectrumView as SpectrumView, band_count_for as band_count_for
9
+
10
+ class _LevelSource(Protocol):
11
+ """A source of band levels: `levels(t)` gives one 0..1 level per band."""
12
+
13
+ def levels(self, t: float) -> list[float]: ...
14
+
15
+ class _Display(Protocol):
16
+ """A display driver."""
17
+
18
+ width: int
19
+ height: int
20
+ def blit_rect(self, buf: Any, x: int, y: int, w: int, h: int) -> Any: ...
21
+
22
+ class _Timer(Protocol):
23
+ def deinit(self) -> Any: ...
24
+
25
+ FRAME_MS: int
26
+ REPORT_S: int
27
+
28
+ def levels_for(audio_out: Any) -> Callable[[int], _LevelSource]:
29
+ """Levels of whatever an audiodev `AudioOut` is playing, for `Spectrum`."""
30
+
31
+ class Spectrum:
32
+ """A spectrum analyzer drawn on `display_drv`, fed by `source`."""
33
+
34
+ display_drv: _Display
35
+ x: int
36
+ y: int
37
+ view: SpectrumView
38
+ source: _LevelSource
39
+ report: bool
40
+ last_report: str
41
+ timer: _Timer | None
42
+ present_rows: bool
43
+ present_all: bool
44
+ def __init__(
45
+ self,
46
+ display_drv: _Display,
47
+ source: _LevelSource | Callable[[int], _LevelSource],
48
+ *,
49
+ bands: int | None = None,
50
+ height: int | None = None,
51
+ y: int | None = None,
52
+ x: int = 0,
53
+ width: int | None = None,
54
+ style: Literal["smooth", "segmented"] = "smooth",
55
+ report: bool = False,
56
+ ) -> None: ...
57
+ def start(self, app: Any, period_ms: int = ...) -> Spectrum:
58
+ """Paint the meter's background and start drawing from `app`'s timer.
59
+
60
+ `app` is anything with an `every(callback, period=ms)` that returns a timer.
61
+ """
62
+ def stop(self) -> None:
63
+ """Stop drawing; the last frame stays on the panel."""
64
+ def tick(self, _: Any = None) -> None:
65
+ """Draw one frame."""
66
+ def capture(self, path: str) -> tuple[int, int]:
67
+ """Write the meter's rows to `path` as raw little-endian RGB565; returns its width and height."""
spectrum/fake_music.py ADDED
@@ -0,0 +1,201 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ """
6
+ fake_music.py -- band levels that move like a band playing, with no audio.
7
+
8
+ A stand-in for the real source (band levels published from C where the audio
9
+ passes). ``FakeMusic(n).levels(t)`` returns ``n`` levels in 0..1 for time ``t``
10
+ seconds, over log-spaced bands from 20 Hz to 20 kHz, mapped from -54..0 dB.
11
+
12
+ What it plays, at 120 BPM in an 8-second loop (four bars):
13
+
14
+ * a kick on every beat, a thump around 55 Hz that dies in a tenth of a second;
15
+ * a snare on beats 2 and 4, a broad crack centred near 1.5 kHz with some body;
16
+ * closed hats on the eighths and an open hat before each bar, fizz above 5 kHz
17
+ with a different sparkle on every hit;
18
+ * a bass line and a three-note pad following the chords (Am, F, C, G);
19
+ * a lead line hopping round a pentatonic scale, with vibrato;
20
+ * a pink-ish tilt over the lot, falling about 3 dB an octave above 150 Hz.
21
+
22
+ Bar two ends in a dead stop (3.5 s to 4.25 s) so the bars and the peak caps
23
+ can be seen falling, then a breakdown of pad, lead and hats until 5.5 s, when
24
+ the drums and bass come back in.
25
+
26
+ Deterministic: every loop replays the same numbers from a seeded xorshift, so
27
+ a capture is repeatable and loops cleanly.
28
+ """
29
+
30
+ import math
31
+
32
+ from .spectrum_view import band_centres
33
+
34
+ BEAT = 0.5 # seconds, 120 BPM
35
+ LOOP = 8.0
36
+ FLOOR_DB = -54.0
37
+
38
+ # Chord per bar: bass root, pad notes (Hz).
39
+ CHORDS = (
40
+ (55.00, (220.0, 261.6, 329.6)), # Am
41
+ (43.65, (174.6, 220.0, 261.6)), # F
42
+ (65.41, (196.0, 261.6, 329.6)), # C
43
+ (49.00, (196.0, 246.9, 293.7)), # G
44
+ )
45
+ PENTA = (440.0, 523.3, 587.3, 659.3, 784.0, 880.0, 1046.5, 1174.7)
46
+
47
+
48
+ class XorShift:
49
+ def __init__(self, seed):
50
+ self.s = seed & 0xFFFFFFFF or 1
51
+
52
+ def next(self):
53
+ s = self.s
54
+ s ^= (s << 13) & 0xFFFFFFFF
55
+ s ^= s >> 17
56
+ s ^= (s << 5) & 0xFFFFFFFF
57
+ self.s = s
58
+ return s
59
+
60
+ def uniform(self):
61
+ return self.next() / 4294967296.0
62
+
63
+
64
+ def _gauss(x):
65
+ return math.exp(-x * x)
66
+
67
+
68
+ class FakeMusic:
69
+ def __init__(self, bands, seed=2026):
70
+ self.n = bands
71
+ self.seed = seed
72
+ fc = band_centres(bands)
73
+ self.oct = [math.log(f / 20.0) / math.log(2) for f in fc] # octaves above 20 Hz
74
+ self.bw_oct = math.log(1000) / math.log(2) / bands
75
+ # Width of a partial's smear across bands, in octaves.
76
+ self.sigma = max(0.16, self.bw_oct * 0.6)
77
+ self.tilt = [10 ** (-0.3 * max(0.0, math.log(f / 150.0) / math.log(2))) for f in fc]
78
+ # Fixed spectral shapes (linear power per band) of the noisy sounds.
79
+ self.snare_w = [
80
+ 0.5 * _gauss((o - self._o(1500)) / 1.6) + 0.35 * _gauss((o - self._o(200)) / 0.4)
81
+ for o in self.oct
82
+ ]
83
+ self.hat_w = [
84
+ (1 / (1 + math.exp(-(o - self._o(6000)) * 3.0))) * _gauss((o - self._o(11000)) / 1.4)
85
+ for o in self.oct
86
+ ]
87
+ self.room_w = [
88
+ _gauss((o - self._o(400)) / 3.0) for o in self.oct
89
+ ] # reverb wash under everything
90
+ self.kick_click_w = [_gauss((o - self._o(3500)) / 0.8) for o in self.oct]
91
+ self._p = [0.0] * bands
92
+ self._rng = XorShift(seed)
93
+ self._loop = -1
94
+ self._sparkle = [1.0] * bands
95
+ self._hat_n = -1
96
+
97
+ @staticmethod
98
+ def _o(hz):
99
+ return math.log(hz / 20.0) / math.log(2)
100
+
101
+ def _partial(self, hz, power):
102
+ """Add a pitched partial, smeared over the bands within reach of it."""
103
+ if hz <= 20 or hz >= 20000 or power <= 0:
104
+ return
105
+ o = self._o(hz)
106
+ sig = self.sigma
107
+ centre = o / self.bw_oct - 0.5
108
+ reach = int(2.5 * sig / self.bw_oct) + 1
109
+ lo = max(0, int(centre) - reach)
110
+ hi = min(self.n, int(centre) + reach + 2)
111
+ p, oc = self._p, self.oct
112
+ for i in range(lo, hi):
113
+ d = (oc[i] - o) / sig
114
+ p[i] += power * math.exp(-d * d)
115
+
116
+ def levels(self, t):
117
+ n = self.n
118
+ p = self._p
119
+ for i in range(n):
120
+ p[i] = 0.0
121
+ loop = int(t // LOOP)
122
+ tl = t - loop * LOOP
123
+ if loop != self._loop:
124
+ self._loop = loop
125
+ self._rng = XorShift(self.seed)
126
+ self._hat_n = -1
127
+ rng = self._rng
128
+
129
+ stop = 3.5 <= tl < 4.25
130
+ breakdown = 4.25 <= tl < 5.5
131
+ drums = not stop and not breakdown
132
+ bar = int(tl // (4 * BEAT)) % 4
133
+ beat_t = tl % BEAT
134
+ beat_i = int(tl // BEAT) % 4
135
+ root, pad = CHORDS[bar]
136
+ out = [FLOOR_DB] * n
137
+ if stop:
138
+ return [0.0] * n
139
+
140
+ # Room wash: quiet, keeps the floor alive while the band plays.
141
+ room = 0.000006 + 0.000006 * rng.uniform()
142
+ for i in range(n):
143
+ p[i] += room * self.room_w[i]
144
+
145
+ if drums:
146
+ k = math.exp(-beat_t / 0.09)
147
+ kick_hz = 50 + 70 * math.exp(-beat_t / 0.02)
148
+ self._partial(kick_hz, 1.0 * k)
149
+ self._partial(kick_hz * 2, 0.25 * k)
150
+ click = 0.02 * math.exp(-beat_t / 0.01)
151
+ for i in range(n):
152
+ p[i] += click * self.kick_click_w[i]
153
+ if beat_i in (1, 3):
154
+ s = 0.18 * math.exp(-beat_t / 0.11)
155
+ for i in range(n):
156
+ p[i] += s * self.snare_w[i]
157
+ # Bass: eighth notes pumping on the chord root, octave on the offbeat.
158
+ e_t = tl % (BEAT / 2)
159
+ off = int(tl // (BEAT / 2)) & 1
160
+ b = 0.35 * (0.25 + 0.75 * math.exp(-e_t / 0.18))
161
+ f = root * (2 if off else 1)
162
+ for h in range(1, 5):
163
+ self._partial(f * h, b / (h * h))
164
+
165
+ # Hats: closed on the eighths, open on the last offbeat of each bar.
166
+ e_n = int(tl // (BEAT / 2))
167
+ e_t = tl % (BEAT / 2)
168
+ if e_n != self._hat_n:
169
+ self._hat_n = e_n
170
+ for i in range(n):
171
+ self._sparkle[i] = 0.35 + 1.3 * rng.uniform()
172
+ open_hat = (e_n % 8) == 7
173
+ acc = 1.0 if (e_n & 1) else 0.55
174
+ hat = 0.5 * acc * math.exp(-e_t / (0.2 if open_hat else 0.035))
175
+ sp = self._sparkle
176
+ for i in range(n):
177
+ p[i] += hat * self.hat_w[i] * sp[i]
178
+
179
+ # Pad: swells in on each bar.
180
+ bar_t = tl % (4 * BEAT)
181
+ swell = 0.02 * (1 - math.exp(-bar_t / 0.4)) * (1.4 if breakdown else 1.0)
182
+ for note in pad:
183
+ for h in range(1, 4):
184
+ self._partial(note * h, swell / (h * h))
185
+
186
+ # Lead: a new pentatonic note every sixteenth-ish, with vibrato.
187
+ step = int(tl / 0.375)
188
+ note = PENTA[(step * 5 + bar * 3 + (step >> 2)) % len(PENTA)]
189
+ n_t = tl - step * 0.375
190
+ vib = 1 + 0.012 * math.sin(2 * math.pi * 5.5 * tl)
191
+ lead = 0.05 * (0.35 + 0.65 * math.exp(-n_t / 0.25))
192
+ for h in range(1, 6):
193
+ self._partial(note * vib * h, lead / h)
194
+
195
+ # To 0..1 over -60..0 dB, with the tilt applied.
196
+ tilt = self.tilt
197
+ for i in range(n):
198
+ v = p[i] * tilt[i]
199
+ if v > 1e-6:
200
+ out[i] = 10 * math.log10(v)
201
+ return [(d - FLOOR_DB) / -FLOOR_DB for d in out]
@@ -0,0 +1,36 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """Band levels that move like a band playing, with no audio."""
5
+
6
+ from .spectrum_view import band_centres as band_centres
7
+
8
+ BEAT: float
9
+ LOOP: float
10
+ FLOOR_DB: float
11
+ CHORDS: tuple[tuple[float, tuple[float, float, float]], ...]
12
+ PENTA: tuple[float, ...]
13
+
14
+ class XorShift:
15
+ """A seeded xorshift random number generator."""
16
+
17
+ s: int
18
+ def __init__(self, seed: int) -> None: ...
19
+ def next(self) -> int: ...
20
+ def uniform(self) -> float: ...
21
+
22
+ class FakeMusic:
23
+ """Band levels for time `t` seconds, over log-spaced bands."""
24
+
25
+ n: int
26
+ seed: int
27
+ oct: list[float]
28
+ bw_oct: float
29
+ sigma: float
30
+ tilt: list[float]
31
+ snare_w: list[float]
32
+ hat_w: list[float]
33
+ room_w: list[float]
34
+ kick_click_w: list[float]
35
+ def __init__(self, bands: int, seed: int = 2026) -> None: ...
36
+ def levels(self, t: float) -> list[float]: ...
@@ -0,0 +1,126 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ """
6
+ pump_levels.py -- band levels from audiodsp's audiometer, fed in C.
7
+
8
+ The real source behind the same interface as ``fake_music.FakeMusic``:
9
+ ``TapLevels(n).levels(t)`` returns ``n`` levels in 0..1, and Python never sees
10
+ a sample. ``TapLevels`` meters any stream audiodsp's pump plays (a file, the
11
+ drum machine, a USB sound card playing through the pump) through the pump's
12
+ tap, read in C each time the levels are. ``PumpLevels`` is the meter both
13
+ are built on, for a source of your own.
14
+
15
+ It needs a firmware with audiodsp's ``audiometer``. With no audio flowing the
16
+ levels stop advancing, and after ``STALE_MS`` this returns zeros so the bars
17
+ fall.
18
+
19
+ The mapping from dB to bar height is here, not in C, because it's a matter of
20
+ taste: ``FLOOR_DB`` is an empty bar, ``TOP_DB`` a full one, and ``TILT_DB``
21
+ lifts the top octaves a little per octave above ``TILT_FROM_HZ``, since music
22
+ has far less energy up there than a bar chart would like.
23
+ """
24
+
25
+ from multimer import ticks_diff, ticks_ms
26
+
27
+ import audiometer
28
+
29
+ from .spectrum_view import HIGH_HZ, LOW_HZ, band_centres
30
+
31
+ FLOOR_DB = -66.0
32
+ TOP_DB = -6.0
33
+ TILT_DB = 3.0 # per octave
34
+ TILT_FROM_HZ = 1000.0
35
+ STALE_MS = 150
36
+
37
+
38
+ class PumpLevels:
39
+ """A meter on ``source``, an ``audiopump.Tap`` at ``rate``; TapLevels
40
+ makes the tap."""
41
+
42
+ def __init__(self, bands, low_hz=LOW_HZ, high_hz=HIGH_HZ, source=None, rate=48000):
43
+ if source is None:
44
+ raise TypeError("PumpLevels needs a source: TapLevels(bands) meters the pump")
45
+ self.bands = bands
46
+ self.meter = audiometer.Meter(bands, low_hz=low_hz, high_hz=high_hz)
47
+ self.meter.attach(source, rate)
48
+ self._buf = bytearray(bands)
49
+ self._out = [0.0] * bands
50
+ self._seq = -1
51
+ self._fresh = ticks_ms()
52
+ self.peak_db = -100.0
53
+ self.rms_db = -100.0
54
+ self.track = None # set to track_start() to record per-band extremes
55
+ # Per band: offset (tilt) in half-dB units, folded into one scale.
56
+ import math
57
+
58
+ span = 2.0 * (TOP_DB - FLOOR_DB)
59
+ self._scale = 1.0 / span
60
+ self._offset = []
61
+ for hz in band_centres(bands):
62
+ tilt = TILT_DB * math.log(hz / TILT_FROM_HZ) / math.log(2) if hz > TILT_FROM_HZ else 0
63
+ # level = (byte + 2*tilt - 2*(FLOOR_DB + 100)) / span
64
+ self._offset.append(2.0 * tilt - 2.0 * (FLOOR_DB + 100.0))
65
+
66
+ def raw(self):
67
+ """(seq, levels bytes, peak, rms) straight from C."""
68
+ return self.meter.levels(self._buf)
69
+
70
+ def levels(self, t=None):
71
+ seq, buf, pk, rms = self.meter.levels(self._buf)
72
+ out = self._out
73
+ now = ticks_ms()
74
+ if seq != self._seq:
75
+ self._seq = seq
76
+ self._fresh = now
77
+ sc, off = self._scale, self._offset
78
+ for i in range(self.bands):
79
+ out[i] = (buf[i] + off[i]) * sc
80
+ tr = self.track
81
+ if tr and buf[0] | buf[self.bands // 2] | buf[-1]:
82
+ hi, lo, tot = tr[0], tr[1], tr[2]
83
+ for i in range(self.bands):
84
+ b = buf[i]
85
+ if b > hi[i]:
86
+ hi[i] = b
87
+ if b < lo[i]:
88
+ lo[i] = b
89
+ tot[i] += b
90
+ tr[3] += 1
91
+ self.peak_db = pk / 2 - 100
92
+ self.rms_db = rms / 2 - 100
93
+ elif ticks_diff(now, self._fresh) > STALE_MS:
94
+ for i in range(self.bands):
95
+ out[i] = 0.0
96
+ self.peak_db = self.rms_db = -100.0
97
+ return out
98
+
99
+ def track_start(self):
100
+ """Record each band's loudest, quietest and summed raw level (half-dB
101
+ bytes) over every fresh analysis from now on, while audio flows."""
102
+ n = self.bands
103
+ self.track = [bytearray(n), bytearray(b"\xff" * n), [0] * n, 0]
104
+ return self.track
105
+
106
+ def close(self):
107
+ self.meter.deinit()
108
+
109
+
110
+ class TapLevels(PumpLevels):
111
+ """Any audiopump stream, through the pump's tap: ``TapLevels(n, rate)``.
112
+
113
+ Attaches a tap of its own unless one is given. The pump has one tap at a
114
+ time, and each reader keeps its own place in it, so a tap someone else
115
+ attached (castfast's audio feed, say) can be shared.
116
+ """
117
+
118
+ def __init__(self, bands, rate=48000, low_hz=LOW_HZ, high_hz=HIGH_HZ, tap=None, channels=2):
119
+ if tap is None:
120
+ from audiodev import pump
121
+
122
+ mod = pump.module()
123
+ tap = mod.Tap(frames=4096, channel_count=channels)
124
+ mod.tap(tap)
125
+ self.tap = tap
126
+ super().__init__(bands, low_hz, high_hz, source=tap, rate=rate)
@@ -0,0 +1,46 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """Band levels from audiodsp's audiometer, fed in C."""
5
+
6
+ from typing import Any
7
+
8
+ from .spectrum_view import HIGH_HZ as HIGH_HZ, LOW_HZ as LOW_HZ, band_centres as band_centres
9
+
10
+ FLOOR_DB: float
11
+ TOP_DB: float
12
+ TILT_DB: float
13
+ TILT_FROM_HZ: float
14
+ STALE_MS: int
15
+
16
+ class PumpLevels:
17
+ """A meter on `source`, an `audiopump.Tap` at `rate`."""
18
+
19
+ bands: int
20
+ meter: Any
21
+ peak_db: float
22
+ rms_db: float
23
+ track: list[Any] | None
24
+ def __init__(
25
+ self, bands: int, low_hz: float = ..., high_hz: float = ..., source: Any = None, rate: int = 48000
26
+ ) -> None: ...
27
+ def raw(self) -> tuple[int, bytearray, int, int]:
28
+ """`(seq, levels bytes, peak, rms)` straight from C."""
29
+ def levels(self, t: float | None = None) -> list[float]: ...
30
+ def track_start(self) -> list[Any]:
31
+ """Record each band's loudest, quietest and summed raw level from now on."""
32
+ def close(self) -> None: ...
33
+
34
+ class TapLevels(PumpLevels):
35
+ """Any audiopump stream, through the pump's tap."""
36
+
37
+ tap: Any
38
+ def __init__(
39
+ self,
40
+ bands: int,
41
+ rate: int = 48000,
42
+ low_hz: float = ...,
43
+ high_hz: float = ...,
44
+ tap: Any = None,
45
+ channels: int = 2,
46
+ ) -> None: ...
spectrum/py.typed ADDED
File without changes