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
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
"""Polyphonic synthio soundtrack, robot vocalizer, and SFX engine for Bit World.
|
|
6
|
+
|
|
7
|
+
Drives three distinct procedural musical motifs (Cozy Workshop Rhodes, Sky Ruins
|
|
8
|
+
16-bit Adventure, and Cyber-Deck Harmonic Matrix) alongside expressive robotic
|
|
9
|
+
chirps and reactive sound effects, while exporting real-time waveform and
|
|
10
|
+
spectrum energy for the on-screen visualizers.
|
|
11
|
+
|
|
12
|
+
Needs: audiodsp, synthio, bit_palette.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from array import array
|
|
16
|
+
from math import pi, sin
|
|
17
|
+
import synthio
|
|
18
|
+
from bit_palette import icos, isin, rng_int
|
|
19
|
+
|
|
20
|
+
# Change these to match your setup.
|
|
21
|
+
WAVE_LEN = 256 # Samples per single-cycle wavetable
|
|
22
|
+
WAVE_AMP = 24000 # Peak 16-bit signed amplitude per wavetable
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# Build a warm Rhodes-like additive waveform (fundamental + 2nd + 3rd harmonics).
|
|
26
|
+
def _make_warm_wave():
|
|
27
|
+
return array(
|
|
28
|
+
"h",
|
|
29
|
+
(
|
|
30
|
+
int(
|
|
31
|
+
(0.72 * sin(t) + 0.20 * sin(t * 2.0) + 0.08 * sin(t * 3.0))
|
|
32
|
+
* WAVE_AMP
|
|
33
|
+
)
|
|
34
|
+
for t in (2.0 * pi * i / WAVE_LEN for i in range(WAVE_LEN))
|
|
35
|
+
),
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# Build a bright 25% pulse-like chiptune lead waveform with soft edges.
|
|
40
|
+
def _make_lead_wave():
|
|
41
|
+
out = array("h")
|
|
42
|
+
for i in range(WAVE_LEN):
|
|
43
|
+
phase = i / WAVE_LEN
|
|
44
|
+
raw = 0.75 if phase < 0.28 else -0.45
|
|
45
|
+
smooth = raw + 0.25 * sin(2.0 * pi * phase * 2.0)
|
|
46
|
+
out.append(int(max(-1.0, min(1.0, smooth)) * WAVE_AMP))
|
|
47
|
+
return out
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# Build a punchy triangle-plus-sub waveform for basslines and reactor hum.
|
|
51
|
+
def _make_bass_wave():
|
|
52
|
+
out = array("h")
|
|
53
|
+
for i in range(WAVE_LEN):
|
|
54
|
+
phase = i / WAVE_LEN
|
|
55
|
+
tri = 1.0 - 4.0 * abs(phase - 0.5)
|
|
56
|
+
sub = sin(2.0 * pi * phase)
|
|
57
|
+
out.append(int((0.65 * tri + 0.35 * sub) * WAVE_AMP))
|
|
58
|
+
return out
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
# Build a glassy bell-like waveform for Bit's vocal chirps and crystal chimes.
|
|
62
|
+
def _make_chirp_wave():
|
|
63
|
+
return array(
|
|
64
|
+
"h",
|
|
65
|
+
(
|
|
66
|
+
int(
|
|
67
|
+
(0.58 * sin(t) + 0.27 * sin(t * 3.0) + 0.15 * sin(t * 5.0))
|
|
68
|
+
* WAVE_AMP
|
|
69
|
+
)
|
|
70
|
+
for t in (2.0 * pi * i / WAVE_LEN for i in range(WAVE_LEN))
|
|
71
|
+
),
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
WAVE_WARM = _make_warm_wave()
|
|
76
|
+
WAVE_LEAD = _make_lead_wave()
|
|
77
|
+
WAVE_BASS = _make_bass_wave()
|
|
78
|
+
WAVE_CHIRP = _make_chirp_wave()
|
|
79
|
+
|
|
80
|
+
# Act 1 (Workshop): Cozy F-major-9 / D-minor-9 lo-fi progression (MIDI notes).
|
|
81
|
+
WORKSHOP_BASS = (53, 53, 57, 57, 50, 50, 48, 52)
|
|
82
|
+
WORKSHOP_MELODY = (
|
|
83
|
+
65, 69, 72, 76, 74, 72, 69, 0,
|
|
84
|
+
62, 65, 69, 74, 72, 69, 67, 0,
|
|
85
|
+
65, 69, 72, 77, 76, 72, 69, 65,
|
|
86
|
+
67, 72, 74, 76, 72, 69, 65, 0,
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
# Act 2 (Sky Ruins): Upbeat 16-bit adventure bass and heroic lead (MIDI notes).
|
|
90
|
+
GAME_BASS = (
|
|
91
|
+
45, 57, 45, 57, 48, 60, 48, 60,
|
|
92
|
+
53, 65, 53, 65, 50, 62, 52, 64,
|
|
93
|
+
)
|
|
94
|
+
GAME_MELODY = (
|
|
95
|
+
69, 0, 72, 74, 76, 0, 79, 76,
|
|
96
|
+
74, 72, 69, 72, 74, 0, 0, 0,
|
|
97
|
+
69, 72, 76, 79, 81, 0, 79, 76,
|
|
98
|
+
74, 76, 72, 69, 67, 0, 64, 0,
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
# Act 3 (Cyber-Deck): 8-step Dorian synth arpeggiator scale (MIDI notes).
|
|
102
|
+
DECK_SCALE = (62, 64, 65, 69, 72, 74, 76, 81)
|
|
103
|
+
|
|
104
|
+
# Notes made once and reused in turn, so playing one allocates nothing. At most about
|
|
105
|
+
# fourteen start a second, so a note is reused well after its release has ended.
|
|
106
|
+
NOTE_POOL = 24
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class SoundEngine:
|
|
110
|
+
"""Manage synthio playback, 3-act procedural music, SFX, and visualizers."""
|
|
111
|
+
|
|
112
|
+
def __init__(self, board_peripherals_mod, app=None, device=None):
|
|
113
|
+
self.muted = False
|
|
114
|
+
self.ready = False
|
|
115
|
+
self._warned = False
|
|
116
|
+
self.audio_out = None
|
|
117
|
+
self.synth = None
|
|
118
|
+
# Gate time left in ms for each note in the pool, and how many are held.
|
|
119
|
+
self._notes = None
|
|
120
|
+
self._gate_ms = array("i", [0] * NOTE_POOL)
|
|
121
|
+
self._next_note = 0
|
|
122
|
+
self._held = 0
|
|
123
|
+
self._sfx_queue = []
|
|
124
|
+
self._step_tenths = 0
|
|
125
|
+
self._step_index = 0
|
|
126
|
+
self._phase = 0
|
|
127
|
+
self.last_freq = 220.0
|
|
128
|
+
self._freq_ratio = 1
|
|
129
|
+
self._center_bin = 1
|
|
130
|
+
self._set_last_freq(220.0)
|
|
131
|
+
self.voice_energy = 0
|
|
132
|
+
self.scope_samples = [0] * 32
|
|
133
|
+
self.spectrum_bins = [8] * 16
|
|
134
|
+
self.spectrum_peaks = [16] * 16
|
|
135
|
+
|
|
136
|
+
self.env_warm = synthio.Envelope(
|
|
137
|
+
attack_time=0.015, decay_time=0.22, release_time=0.25, sustain_level=0.45
|
|
138
|
+
)
|
|
139
|
+
self.env_lead = synthio.Envelope(
|
|
140
|
+
attack_time=0.005, decay_time=0.12, release_time=0.12, sustain_level=0.55
|
|
141
|
+
)
|
|
142
|
+
self.env_bass = synthio.Envelope(
|
|
143
|
+
attack_time=0.008, decay_time=0.16, release_time=0.15, sustain_level=0.50
|
|
144
|
+
)
|
|
145
|
+
self.env_sfx = synthio.Envelope(
|
|
146
|
+
attack_time=0.002, decay_time=0.09, release_time=0.08, sustain_level=0.35
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
# The music plays behind the animation, so a buffered output is fine. It
|
|
150
|
+
# carries the sound through a garbage collection, which a busy frame causes.
|
|
151
|
+
if getattr(board_peripherals_mod, "audio_out", None) is None:
|
|
152
|
+
self._warned = True
|
|
153
|
+
print("bit_world: no board_peripherals.audio_out on this board, running silent")
|
|
154
|
+
return
|
|
155
|
+
try:
|
|
156
|
+
# A computer's sound device by name (see bit_world.pick_audio_out),
|
|
157
|
+
# or None for where the board's audio out plays.
|
|
158
|
+
more = {} if device is None else {"device": device}
|
|
159
|
+
self.audio_out = board_peripherals_mod.audio_out(latency="buffered", **more)
|
|
160
|
+
if app is not None and hasattr(self.audio_out, "attach"):
|
|
161
|
+
self.audio_out.attach(app)
|
|
162
|
+
self.synth = synthio.Synthesizer(
|
|
163
|
+
sample_rate=self.audio_out.format.rate,
|
|
164
|
+
channel_count=self.audio_out.format.channels,
|
|
165
|
+
waveform=WAVE_WARM,
|
|
166
|
+
envelope=self.env_warm,
|
|
167
|
+
)
|
|
168
|
+
self._notes = [
|
|
169
|
+
synthio.Note(frequency=220.0, waveform=WAVE_WARM, envelope=self.env_warm)
|
|
170
|
+
for _ in range(NOTE_POOL)
|
|
171
|
+
]
|
|
172
|
+
self.try_unlock()
|
|
173
|
+
except Exception as exc:
|
|
174
|
+
if not self._warned:
|
|
175
|
+
self._warned = True
|
|
176
|
+
print("bit_world: audio hardware unavailable, running silent:", exc)
|
|
177
|
+
|
|
178
|
+
# Attempt to start or unlock the audio transport (needed after first browser gesture).
|
|
179
|
+
def try_unlock(self):
|
|
180
|
+
if self.ready or self.audio_out is None or self.synth is None:
|
|
181
|
+
return self.ready
|
|
182
|
+
try:
|
|
183
|
+
self.audio_out.play(self.synth)
|
|
184
|
+
self.ready = True
|
|
185
|
+
return True
|
|
186
|
+
except Exception:
|
|
187
|
+
self.ready = False
|
|
188
|
+
return False
|
|
189
|
+
|
|
190
|
+
# Toggle mute on or off and release any sounding notes when muted.
|
|
191
|
+
def toggle_mute(self):
|
|
192
|
+
self.muted = not self.muted
|
|
193
|
+
if self.muted:
|
|
194
|
+
self.silence()
|
|
195
|
+
else:
|
|
196
|
+
self.try_unlock()
|
|
197
|
+
self.sfx_switch(True)
|
|
198
|
+
return self.muted
|
|
199
|
+
|
|
200
|
+
# Stop all active notes immediately.
|
|
201
|
+
def silence(self):
|
|
202
|
+
if self.synth is not None:
|
|
203
|
+
try:
|
|
204
|
+
self.synth.release_all()
|
|
205
|
+
except Exception:
|
|
206
|
+
pass
|
|
207
|
+
for k in range(NOTE_POOL):
|
|
208
|
+
self._gate_ms[k] = 0
|
|
209
|
+
self._held = 0
|
|
210
|
+
self._sfx_queue.clear()
|
|
211
|
+
|
|
212
|
+
# Remember the latest note's frequency and what the visualizers derive from it.
|
|
213
|
+
def _set_last_freq(self, freq):
|
|
214
|
+
self.last_freq = freq
|
|
215
|
+
self._freq_ratio = max(1, min(6, int(freq / 160.0)))
|
|
216
|
+
self._center_bin = max(1, min(14, int((freq - 90.0) / 70.0)))
|
|
217
|
+
|
|
218
|
+
# Play the next pooled synthio.Note for duration seconds with this frequency, waveform and amplitude.
|
|
219
|
+
def _spawn_note(self, freq, duration, waveform, envelope, amp=0.22):
|
|
220
|
+
self._set_last_freq(freq)
|
|
221
|
+
self.voice_energy = min(100, self.voice_energy + int(amp * 180))
|
|
222
|
+
if self.muted or not self.ready or self.synth is None or self._notes is None:
|
|
223
|
+
return
|
|
224
|
+
k = self._next_note
|
|
225
|
+
self._next_note = (k + 1) % NOTE_POOL
|
|
226
|
+
try:
|
|
227
|
+
note = self._notes[k]
|
|
228
|
+
if self._gate_ms[k] > 0:
|
|
229
|
+
self.synth.release(note)
|
|
230
|
+
self._held -= 1
|
|
231
|
+
note.frequency = freq
|
|
232
|
+
note.waveform = waveform
|
|
233
|
+
note.envelope = envelope
|
|
234
|
+
note.amplitude = amp
|
|
235
|
+
self.synth.press(note)
|
|
236
|
+
self._gate_ms[k] = max(1, int(duration * 1000.0 + 0.5))
|
|
237
|
+
self._held += 1
|
|
238
|
+
except Exception:
|
|
239
|
+
pass
|
|
240
|
+
|
|
241
|
+
# Play a MIDI note number using the given waveform and envelope.
|
|
242
|
+
def _spawn_midi(self, midi_note, duration, waveform, envelope, amp=0.20):
|
|
243
|
+
if midi_note <= 0:
|
|
244
|
+
return
|
|
245
|
+
freq = synthio.midi_to_hz(midi_note)
|
|
246
|
+
self._spawn_note(freq, duration, waveform, envelope, amp)
|
|
247
|
+
|
|
248
|
+
# Queue an expressive multi-syllable robotic chirp for Bit.
|
|
249
|
+
def chirp(self, mood="happy"):
|
|
250
|
+
if mood == "love":
|
|
251
|
+
seq = ((523, 0.06), (659, 0.06), (784, 0.08), (1046, 0.12))
|
|
252
|
+
elif mood == "sing":
|
|
253
|
+
seq = ((587, 0.08), (659, 0.08), (784, 0.10), (880, 0.12), (784, 0.12))
|
|
254
|
+
elif mood == "scan":
|
|
255
|
+
seq = ((880, 0.04), (440, 0.04), (988, 0.04), (587, 0.06), (1175, 0.08))
|
|
256
|
+
elif mood == "coffee":
|
|
257
|
+
seq = ((440, 0.05), (554, 0.05), (659, 0.05), (880, 0.07), (1108, 0.10))
|
|
258
|
+
elif mood == "sleep":
|
|
259
|
+
seq = ((523, 0.10), (392, 0.12), (330, 0.16))
|
|
260
|
+
else:
|
|
261
|
+
seq = ((587, 0.05), (784, 0.06), (988, 0.09))
|
|
262
|
+
delay = 0.0
|
|
263
|
+
for freq, dur in seq:
|
|
264
|
+
self._sfx_queue.append([delay, freq, dur, WAVE_CHIRP, self.env_sfx, 0.24])
|
|
265
|
+
delay += dur * 0.85
|
|
266
|
+
|
|
267
|
+
# Trigger a rising jetpack boost / jump sound effect.
|
|
268
|
+
def sfx_jump(self):
|
|
269
|
+
self._sfx_queue.append([0.0, 260.0, 0.05, WAVE_LEAD, self.env_sfx, 0.22])
|
|
270
|
+
self._sfx_queue.append([0.04, 390.0, 0.06, WAVE_LEAD, self.env_sfx, 0.22])
|
|
271
|
+
self._sfx_queue.append([0.08, 540.0, 0.08, WAVE_CHIRP, self.env_sfx, 0.18])
|
|
272
|
+
|
|
273
|
+
# Trigger a plasma bolt laser sound effect.
|
|
274
|
+
def sfx_laser(self):
|
|
275
|
+
self._sfx_queue.append([0.0, 1120.0, 0.035, WAVE_LEAD, self.env_sfx, 0.25])
|
|
276
|
+
self._sfx_queue.append([0.03, 680.0, 0.045, WAVE_LEAD, self.env_sfx, 0.22])
|
|
277
|
+
self._sfx_queue.append([0.06, 420.0, 0.05, WAVE_BASS, self.env_sfx, 0.18])
|
|
278
|
+
|
|
279
|
+
# Trigger a sparkling crystal pickup chime.
|
|
280
|
+
def sfx_crystal(self):
|
|
281
|
+
self._sfx_queue.append([0.0, 987.7, 0.06, WAVE_CHIRP, self.env_sfx, 0.25])
|
|
282
|
+
self._sfx_queue.append([0.05, 1318.5, 0.12, WAVE_CHIRP, self.env_warm, 0.25])
|
|
283
|
+
|
|
284
|
+
# Trigger a punchy drone explosion sound effect.
|
|
285
|
+
def sfx_boom(self):
|
|
286
|
+
self._sfx_queue.append([0.0, 145.0, 0.08, WAVE_BASS, self.env_bass, 0.32])
|
|
287
|
+
self._sfx_queue.append([0.04, 98.0, 0.12, WAVE_LEAD, self.env_bass, 0.28])
|
|
288
|
+
self._sfx_queue.append([0.09, 68.0, 0.16, WAVE_BASS, self.env_bass, 0.26])
|
|
289
|
+
|
|
290
|
+
# Trigger a crisp mechanical toggle switch click.
|
|
291
|
+
def sfx_switch(self, state=True):
|
|
292
|
+
f1 = 740.0 if state else 520.0
|
|
293
|
+
f2 = 980.0 if state else 380.0
|
|
294
|
+
self._sfx_queue.append([0.0, f1, 0.025, WAVE_CHIRP, self.env_sfx, 0.20])
|
|
295
|
+
self._sfx_queue.append([0.02, f2, 0.035, WAVE_CHIRP, self.env_sfx, 0.18])
|
|
296
|
+
|
|
297
|
+
# Trigger a harmonic tone when a Cyber-Deck sequencer pad is toggled.
|
|
298
|
+
def sfx_pad(self, pad_idx, active=True):
|
|
299
|
+
midi = DECK_SCALE[pad_idx & 7] + (12 if active else 0)
|
|
300
|
+
self._spawn_midi(midi, 0.11, WAVE_CHIRP, self.env_lead, 0.24)
|
|
301
|
+
|
|
302
|
+
# Advance active note releases, queued SFX, 3-act music sequencer, and visualizers.
|
|
303
|
+
def update(self, dt, act_idx, deck_state=None):
|
|
304
|
+
if dt <= 0.0:
|
|
305
|
+
dt = 0.016
|
|
306
|
+
elif dt > 0.12:
|
|
307
|
+
dt = 0.12
|
|
308
|
+
|
|
309
|
+
# Gates count whole ms and the step tenths of a ms, so a frame boxes no floats for them.
|
|
310
|
+
dt_tenths = int(dt * 10000.0 + 0.5)
|
|
311
|
+
dt_ms = (dt_tenths + 5) // 10
|
|
312
|
+
|
|
313
|
+
# Release any notes whose gate duration has expired.
|
|
314
|
+
if self._held:
|
|
315
|
+
gates = self._gate_ms
|
|
316
|
+
for k in range(NOTE_POOL):
|
|
317
|
+
if gates[k] > 0:
|
|
318
|
+
gates[k] -= dt_ms
|
|
319
|
+
if gates[k] <= 0:
|
|
320
|
+
gates[k] = 0
|
|
321
|
+
self._held -= 1
|
|
322
|
+
try:
|
|
323
|
+
self.synth.release(self._notes[k])
|
|
324
|
+
except Exception:
|
|
325
|
+
pass
|
|
326
|
+
|
|
327
|
+
# Fire any delayed SFX syllables whose countdown has reached zero.
|
|
328
|
+
j = len(self._sfx_queue) - 1
|
|
329
|
+
while j >= 0:
|
|
330
|
+
item = self._sfx_queue[j]
|
|
331
|
+
item[0] -= dt
|
|
332
|
+
if item[0] <= 0.0:
|
|
333
|
+
_, freq, dur, wf, env, amp = self._sfx_queue.pop(j)
|
|
334
|
+
self._spawn_note(freq, dur, wf, env, amp)
|
|
335
|
+
j -= 1
|
|
336
|
+
|
|
337
|
+
# Determine step tempo based on the active act and Cyber-Deck throttle.
|
|
338
|
+
if act_idx == 0:
|
|
339
|
+
step = 2200
|
|
340
|
+
elif act_idx == 1:
|
|
341
|
+
step = 1400
|
|
342
|
+
else:
|
|
343
|
+
throttle = 0.55 if deck_state is None else deck_state.get("throttle", 0.55)
|
|
344
|
+
step = max(900, int(2200.5 - throttle * 1100.0))
|
|
345
|
+
|
|
346
|
+
self._step_tenths += dt_tenths
|
|
347
|
+
if self._step_tenths >= step:
|
|
348
|
+
self._step_tenths -= step
|
|
349
|
+
self._trigger_music_step(act_idx, deck_state)
|
|
350
|
+
self._step_index = (self._step_index + 1) & 0xFF
|
|
351
|
+
|
|
352
|
+
self._update_visualizers()
|
|
353
|
+
|
|
354
|
+
# Trigger one rhythmic step of the current act's procedural soundtrack.
|
|
355
|
+
def _trigger_music_step(self, act_idx, deck_state):
|
|
356
|
+
if not self.ready and not self.muted:
|
|
357
|
+
self.try_unlock()
|
|
358
|
+
step = self._step_index
|
|
359
|
+
if act_idx == 0:
|
|
360
|
+
# Cozy Workshop: warm Rhodes bass on beats and bell melody on 16ths.
|
|
361
|
+
if (step & 3) == 0:
|
|
362
|
+
bass_note = WORKSHOP_BASS[(step >> 2) % len(WORKSHOP_BASS)]
|
|
363
|
+
self._spawn_midi(bass_note, 0.36, WAVE_WARM, self.env_warm, 0.16)
|
|
364
|
+
mel = WORKSHOP_MELODY[step % len(WORKSHOP_MELODY)]
|
|
365
|
+
if mel:
|
|
366
|
+
self._spawn_midi(mel, 0.18, WAVE_CHIRP, self.env_warm, 0.14)
|
|
367
|
+
elif act_idx == 1:
|
|
368
|
+
# Sky Ruins: driving chiptune bassline and heroic pulse lead.
|
|
369
|
+
bass_note = GAME_BASS[step % len(GAME_BASS)]
|
|
370
|
+
self._spawn_midi(bass_note, 0.11, WAVE_BASS, self.env_bass, 0.17)
|
|
371
|
+
mel = GAME_MELODY[step % len(GAME_MELODY)]
|
|
372
|
+
if mel:
|
|
373
|
+
self._spawn_midi(mel, 0.12, WAVE_LEAD, self.env_lead, 0.16)
|
|
374
|
+
else:
|
|
375
|
+
# Cyber-Deck: arpeggiate across active harmonic pads + reactor bass pulse.
|
|
376
|
+
pads = None if deck_state is None else deck_state.get("pads")
|
|
377
|
+
boost = False if deck_state is None else deck_state.get("boost", False)
|
|
378
|
+
overdrive = False if deck_state is None else deck_state.get("overdrive", False)
|
|
379
|
+
slot = step & 7
|
|
380
|
+
if (step & 1) == 0:
|
|
381
|
+
root = 50 if not overdrive else 53
|
|
382
|
+
self._spawn_midi(root + (12 if (step & 2) else 0), 0.13, WAVE_BASS, self.env_bass, 0.17)
|
|
383
|
+
if pads is None or pads[slot]:
|
|
384
|
+
note = DECK_SCALE[slot] + (12 if boost and (step & 1) else 0)
|
|
385
|
+
wf = WAVE_LEAD if overdrive else WAVE_WARM
|
|
386
|
+
self._spawn_midi(note, 0.12, wf, self.env_lead, 0.18)
|
|
387
|
+
|
|
388
|
+
# Synthesize responsive oscilloscope and 16-band spectrum values for HUD widgets.
|
|
389
|
+
def _update_visualizers(self):
|
|
390
|
+
self._phase = (self._phase + 7) & 0xFF
|
|
391
|
+
self.voice_energy = max(0, self.voice_energy - 6)
|
|
392
|
+
base_amp = 24 + min(68, self._held * 22 + (self.voice_energy >> 1))
|
|
393
|
+
freq_ratio = self._freq_ratio
|
|
394
|
+
|
|
395
|
+
for i in range(32):
|
|
396
|
+
p1 = (self._phase + i * freq_ratio * 4) & 0xFF
|
|
397
|
+
p2 = (self._phase * 2 + i * 11) & 0xFF
|
|
398
|
+
val = ((isin(p1) * 7 + icos(p2) * 3) * base_amp) >> 13
|
|
399
|
+
self.scope_samples[i] = max(-95, min(95, val))
|
|
400
|
+
|
|
401
|
+
center_bin = self._center_bin
|
|
402
|
+
for b in range(16):
|
|
403
|
+
dist = abs(b - center_bin)
|
|
404
|
+
harmonic = 28 if (b == (center_bin + 4) & 15) else 0
|
|
405
|
+
target = max(6, base_amp - dist * 11 + harmonic + rng_int(-4, 6))
|
|
406
|
+
if self.muted:
|
|
407
|
+
target = 4
|
|
408
|
+
cur = self.spectrum_bins[b]
|
|
409
|
+
if target > cur:
|
|
410
|
+
cur = min(100, cur + ((target - cur) >> 1) + 4)
|
|
411
|
+
else:
|
|
412
|
+
cur = max(4, cur - 5)
|
|
413
|
+
self.spectrum_bins[b] = cur
|
|
414
|
+
if cur >= self.spectrum_peaks[b]:
|
|
415
|
+
self.spectrum_peaks[b] = cur
|
|
416
|
+
else:
|
|
417
|
+
self.spectrum_peaks[b] = max(cur, self.spectrum_peaks[b] - 2)
|
|
418
|
+
|
|
419
|
+
# Close the audio transport cleanly on application exit.
|
|
420
|
+
def close(self):
|
|
421
|
+
self.silence()
|
|
422
|
+
if self.audio_out is not None:
|
|
423
|
+
if hasattr(self.audio_out, "detach"):
|
|
424
|
+
try:
|
|
425
|
+
self.audio_out.detach()
|
|
426
|
+
except Exception:
|
|
427
|
+
pass
|
|
428
|
+
try:
|
|
429
|
+
self.audio_out.close()
|
|
430
|
+
except Exception:
|
|
431
|
+
pass
|