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,683 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
"""Act 3: Solarpunk Reactor & Synth Cyber-Deck (Machine HMI Showcase).
|
|
6
|
+
|
|
7
|
+
Demonstrates an industrial control panel and audio workstation built with
|
|
8
|
+
pygraphics.Draw vector primitives (thick arcs, rotating polygon needles,
|
|
9
|
+
rounded rectangles) and pixel-art tactile controls (rocker switches, throttle
|
|
10
|
+
fader, coolant tank, dual-trace oscilloscope, 16-band spectrum analyzer, and an
|
|
11
|
+
8-pad live synth sequencer matrix).
|
|
12
|
+
|
|
13
|
+
Needs: pygraphics, bit_palette, bit_sprites.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from array import array
|
|
17
|
+
from bit_palette import (
|
|
18
|
+
ABYSS,
|
|
19
|
+
AMBER,
|
|
20
|
+
AQUA_GLOW,
|
|
21
|
+
BRONZE,
|
|
22
|
+
COPPER,
|
|
23
|
+
CORAL,
|
|
24
|
+
CREAM,
|
|
25
|
+
CYAN,
|
|
26
|
+
DARK_MOSS,
|
|
27
|
+
DEEP_SLATE,
|
|
28
|
+
DEEP_TEAL,
|
|
29
|
+
EMERALD,
|
|
30
|
+
KEY,
|
|
31
|
+
FOREST,
|
|
32
|
+
GOLD,
|
|
33
|
+
ICE_CYAN,
|
|
34
|
+
LIME_GLOW,
|
|
35
|
+
MAGENTA,
|
|
36
|
+
MIST,
|
|
37
|
+
NEON_PINK,
|
|
38
|
+
NIGHT,
|
|
39
|
+
ORANGE,
|
|
40
|
+
SILVER,
|
|
41
|
+
SLATE,
|
|
42
|
+
SIN256,
|
|
43
|
+
STEEL,
|
|
44
|
+
SUN_YELLOW,
|
|
45
|
+
TEAL,
|
|
46
|
+
VOID,
|
|
47
|
+
WHITE,
|
|
48
|
+
copy_frame,
|
|
49
|
+
draw_pixel_panel,
|
|
50
|
+
icos,
|
|
51
|
+
isin,
|
|
52
|
+
make_canvas,
|
|
53
|
+
make_draw,
|
|
54
|
+
make_fb,
|
|
55
|
+
rect_sources,
|
|
56
|
+
restore_rect,
|
|
57
|
+
restore_sources,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
# Change these to match your setup.
|
|
61
|
+
# The frame rate at which the FPS dial reads full scale.
|
|
62
|
+
FPS_FULL_SCALE = 60.0
|
|
63
|
+
|
|
64
|
+
SWITCH_NAMES = ("BOOST", "SHLD", "PHASE", "OVRD")
|
|
65
|
+
PAD_NOTES = ("D4", "E4", "F4", "A4", "C5", "D5", "E5", "A5")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class CyberDeckAct:
|
|
69
|
+
"""Render and operate Act 3: Solarpunk Reactor and Synth HMI Console."""
|
|
70
|
+
|
|
71
|
+
# *background* is a (bytearray, FrameBuffer) pair from make_fb at the panel's size to
|
|
72
|
+
# draw the static scene into; left as None, the act makes its own.
|
|
73
|
+
def __init__(self, layout, sprites, sound, background=None):
|
|
74
|
+
self.lay = layout
|
|
75
|
+
self.sprites = sprites
|
|
76
|
+
self.sound = sound
|
|
77
|
+
self.phase = 0
|
|
78
|
+
self.fps = 0.0
|
|
79
|
+
self.auto_ms = 1800
|
|
80
|
+
self.auto_step = 0
|
|
81
|
+
|
|
82
|
+
# Live interactive HMI state shared with SoundEngine.
|
|
83
|
+
self.switches = [True, True, False, False]
|
|
84
|
+
self.throttle = 0.68
|
|
85
|
+
self.pads = [True, False, True, True, False, True, True, True]
|
|
86
|
+
self.state = {
|
|
87
|
+
"boost": self.switches[0],
|
|
88
|
+
"shield": self.switches[1],
|
|
89
|
+
"phase": self.switches[2],
|
|
90
|
+
"overdrive": self.switches[3],
|
|
91
|
+
"throttle": self.throttle,
|
|
92
|
+
"pads": self.pads,
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
# Precompute 6 instrument bay rectangles across the scene.
|
|
96
|
+
w = layout.w
|
|
97
|
+
sy = layout.scene_y
|
|
98
|
+
sh = layout.scene_h
|
|
99
|
+
pad = layout.pad
|
|
100
|
+
top_h = int(sh * 0.50)
|
|
101
|
+
bot_h = sh - top_h - pad * 3
|
|
102
|
+
top_y = sy + pad
|
|
103
|
+
bot_y = top_y + top_h + pad
|
|
104
|
+
|
|
105
|
+
col1_w = int(w * 0.34)
|
|
106
|
+
col2_w = int(w * 0.36)
|
|
107
|
+
col3_w = w - col1_w - col2_w - pad * 4
|
|
108
|
+
|
|
109
|
+
x1 = pad
|
|
110
|
+
x2 = x1 + col1_w + pad
|
|
111
|
+
x3 = x2 + col2_w + pad
|
|
112
|
+
|
|
113
|
+
self.bay_gauges = (x1, top_y, col1_w, top_h)
|
|
114
|
+
self.bay_scope = (x2, top_y, col2_w, top_h)
|
|
115
|
+
self.bay_holo = (x3, top_y, col3_w, top_h)
|
|
116
|
+
|
|
117
|
+
self.bay_switches = (x1, bot_y, col1_w, bot_h)
|
|
118
|
+
self.bay_spectrum = (x2, bot_y, col2_w, bot_h)
|
|
119
|
+
self.bay_pads = (x3, bot_y, col3_w, bot_h)
|
|
120
|
+
|
|
121
|
+
# Compute hit rectangles for switches, throttle slider, and 8 synth pads.
|
|
122
|
+
self.switch_rects = []
|
|
123
|
+
sx, sy_sw, sw_w, sw_h = self.bay_switches
|
|
124
|
+
throttle_w = 28 if layout.compact else 38
|
|
125
|
+
sw_area_w = sw_w - throttle_w - 22
|
|
126
|
+
gap = 4 if layout.compact else 6
|
|
127
|
+
btn_w = (sw_area_w - gap * 3) // 4
|
|
128
|
+
btn_h = sw_h - (28 if layout.compact else 36)
|
|
129
|
+
for i in range(4):
|
|
130
|
+
bx = sx + 8 + i * (btn_w + gap)
|
|
131
|
+
by = sy_sw + (20 if layout.compact else 24)
|
|
132
|
+
self.switch_rects.append((bx, by, btn_w, btn_h))
|
|
133
|
+
|
|
134
|
+
self.throttle_rect = (
|
|
135
|
+
sx + sw_w - throttle_w - 8,
|
|
136
|
+
sy_sw + (20 if layout.compact else 24),
|
|
137
|
+
throttle_w,
|
|
138
|
+
btn_h,
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
self.pad_rects = []
|
|
142
|
+
px, py_p, pw, ph = self.bay_pads
|
|
143
|
+
pad_cols = 4
|
|
144
|
+
pad_rows = 2
|
|
145
|
+
pgap = 4 if layout.compact else 6
|
|
146
|
+
cell_w = (pw - 16 - pgap * (pad_cols - 1)) // pad_cols
|
|
147
|
+
cell_h = (ph - (24 if layout.compact else 30) - pgap) // pad_rows
|
|
148
|
+
for r in range(pad_rows):
|
|
149
|
+
for c in range(pad_cols):
|
|
150
|
+
bx = px + 8 + c * (cell_w + pgap)
|
|
151
|
+
by = py_p + (18 if layout.compact else 22) + r * (cell_h + pgap)
|
|
152
|
+
self.pad_rects.append((bx, by, cell_w, cell_h))
|
|
153
|
+
|
|
154
|
+
# Coolant tank bubble heights, in millionths of the liquid's height, and how fast
|
|
155
|
+
# each rises, in thousandths of the liquid per second at throttle zero.
|
|
156
|
+
self.bubbles = array("i", (150000, 420000, 680000, 850000))
|
|
157
|
+
self._bubble_speed = (350, 430, 510, 590)
|
|
158
|
+
|
|
159
|
+
# Made once, so a frame's repaint allocates none of them: the keys under which a
|
|
160
|
+
# PanelState remembers each switch and pad, the needle polygon, and the readouts,
|
|
161
|
+
# formatted again only when what they show changes.
|
|
162
|
+
self._switch_keys = tuple(("switch", i) for i in range(len(self.switch_rects)))
|
|
163
|
+
self._pad_keys = tuple(("pad", i) for i in range(len(self.pad_rects)))
|
|
164
|
+
self._needle = array("h", [0] * 6)
|
|
165
|
+
self._mw_shown = -1
|
|
166
|
+
self._mw_text = ""
|
|
167
|
+
self._fps_shown = -1
|
|
168
|
+
self._fps_text = ""
|
|
169
|
+
self._attract_tables()
|
|
170
|
+
|
|
171
|
+
# Pre-render the brushed metal chassis and static dial bezels into bg_fb.
|
|
172
|
+
self.bg_buf, self.bg_fb = background or make_fb(w, layout.h, VOID)
|
|
173
|
+
self.bg_view = memoryview(self.bg_buf)
|
|
174
|
+
self.bg_draw = make_draw(self.bg_fb)
|
|
175
|
+
self._build_static_console()
|
|
176
|
+
|
|
177
|
+
# The gauge needles turn in place, so the background under them is prepared once.
|
|
178
|
+
self.gauge_sources = rect_sources(
|
|
179
|
+
self.bg_buf,
|
|
180
|
+
[(cx - rad - 3, cy - rad - 3, rad * 2 + 7, rad * 2 + 7) for cx, cy, rad, _ in self.gauge_centers],
|
|
181
|
+
w,
|
|
182
|
+
layout.h,
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
# The needles' hub, drawn once and then blitted with framebuf, which allocates
|
|
186
|
+
# nothing; a pygraphics without areas=False makes an Area for each circle.
|
|
187
|
+
self._hub = make_canvas(bytearray(11 * 11 * 2), 11, 11)
|
|
188
|
+
self._hub.fill(KEY)
|
|
189
|
+
hub_draw = make_draw(self._hub)
|
|
190
|
+
hub_draw.circle(5, 5, 4, BRONZE, True)
|
|
191
|
+
hub_draw.circle(5, 5, 2, WHITE, True)
|
|
192
|
+
|
|
193
|
+
# In attract mode the throttle follows the phase, so everything it moves is worked
|
|
194
|
+
# out here once per phase, with the same float arithmetic the live path uses. A
|
|
195
|
+
# frame then reads integers, where the live path would box a dozen floats.
|
|
196
|
+
def _attract_tables(self):
|
|
197
|
+
lay = self.lay
|
|
198
|
+
# Index p is phase >> 1, the throttle the operator holds at that phase.
|
|
199
|
+
self._thr_table = tuple(
|
|
200
|
+
max(0.15, min(0.92, 0.62 + ((SIN256[p] * 24) / 102400.0))) for p in range(128)
|
|
201
|
+
)
|
|
202
|
+
# Where the throttle came from: its phase >> 1, or -1 when a pointer set it.
|
|
203
|
+
self._thr_index = -1
|
|
204
|
+
th_tank = self.bay_holo[3] - (26 if lay.compact else 30)
|
|
205
|
+
th_fader = self.throttle_rect[3]
|
|
206
|
+
self._level_table = array("h", (int(th_tank * (0.58 + t * 0.28)) for t in self._thr_table))
|
|
207
|
+
self._fill_table = array(
|
|
208
|
+
"h", (max(0, min(th_fader - 4, int(th_fader * t))) for t in self._thr_table)
|
|
209
|
+
)
|
|
210
|
+
self._permille_table = array("h", (self._permille(t) for t in self._thr_table))
|
|
211
|
+
# Per phase and boost switch: the flux needle's angle and its MW readout. Per
|
|
212
|
+
# phase and both switches: how many TEMP segments light.
|
|
213
|
+
ang = array("B", bytes(512))
|
|
214
|
+
mw = array("h", bytes(1024))
|
|
215
|
+
segs = array("B", bytes(1024))
|
|
216
|
+
for phase in range(256):
|
|
217
|
+
t = self._thr_table[phase >> 1]
|
|
218
|
+
jitter = (SIN256[(phase * 3) & 0xFF] * 3) / 10240.0
|
|
219
|
+
for boost in (0, 1):
|
|
220
|
+
val1 = min(1.0, max(0.05, t * 0.78 + (0.16 if boost else 0.0) + jitter))
|
|
221
|
+
ang[phase * 2 + boost] = (96 + int(val1 * 170)) & 0xFF
|
|
222
|
+
mw[phase * 2 + boost] = int(val1 * 990)
|
|
223
|
+
for ovr in (0, 1):
|
|
224
|
+
val2 = min(1.0, max(0.05, t * 0.72 + (0.14 if ovr else 0.0) - jitter))
|
|
225
|
+
segs[phase * 4 + boost * 2 + ovr] = max(1, min(10, int(((val1 + val2) * 0.5) * 10)))
|
|
226
|
+
self._ang_table = ang
|
|
227
|
+
self._mw_table = mw
|
|
228
|
+
self._segs_table = segs
|
|
229
|
+
|
|
230
|
+
# The throttle in thousandths, for the bubbles' integer arithmetic.
|
|
231
|
+
@staticmethod
|
|
232
|
+
def _permille(t):
|
|
233
|
+
return int(t * 1000.0 + 0.5)
|
|
234
|
+
|
|
235
|
+
# Pre-render the industrial console chassis, rivets, and static gauge arcs.
|
|
236
|
+
def _build_static_console(self):
|
|
237
|
+
fb = self.bg_fb
|
|
238
|
+
d = self.bg_draw
|
|
239
|
+
lay = self.lay
|
|
240
|
+
w = lay.w
|
|
241
|
+
sy = lay.scene_y
|
|
242
|
+
sh = lay.scene_h
|
|
243
|
+
|
|
244
|
+
# Brushed steel chassis background with subtle horizontal scanlines.
|
|
245
|
+
fb.fill_rect(0, sy, w, sh, NIGHT)
|
|
246
|
+
for y in range(sy, sy + sh, 4):
|
|
247
|
+
fb.hline(0, y, w, ABYSS)
|
|
248
|
+
|
|
249
|
+
for rect, border, title, tcol in (
|
|
250
|
+
(self.bay_gauges, CYAN, "REACTOR TELEMETRY", AQUA_GLOW),
|
|
251
|
+
(self.bay_scope, EMERALD, "DUAL-TRACE OSCILLOSCOPE", LIME_GLOW),
|
|
252
|
+
(self.bay_holo, GOLD, "HOLO-CORE & COOLANT", GOLD),
|
|
253
|
+
(self.bay_switches, AMBER, "BREAKER BANK & THROTTLE", GOLD),
|
|
254
|
+
(self.bay_spectrum, CYAN, "16-BAND HARMONIC FFT", AQUA_GLOW),
|
|
255
|
+
(self.bay_pads, NEON_PINK, "SYNTH SEQUENCER MATRIX", NEON_PINK),
|
|
256
|
+
):
|
|
257
|
+
bx, by, bw, bh = rect
|
|
258
|
+
draw_pixel_panel(fb, bx, by, bw, bh, VOID, border, SILVER, ABYSS)
|
|
259
|
+
max_chars = max(8, (bw - 14) // 8)
|
|
260
|
+
fb.text(title[:max_chars], bx + 8, by + 5, tcol)
|
|
261
|
+
|
|
262
|
+
# Pre-render the static multi-zone gauge rings using pygraphics.Draw.arc.
|
|
263
|
+
gx, gy, gw, gh = self.bay_gauges
|
|
264
|
+
r = min(gw // 4 - 6, (gh - 34) // 2)
|
|
265
|
+
r = max(18, r)
|
|
266
|
+
cy = gy + 20 + r + 4
|
|
267
|
+
cx1 = gx + (gw >> 2) + 2
|
|
268
|
+
cx2 = gx + ((gw * 3) >> 2) - 2
|
|
269
|
+
self.gauge_centers = ((cx1, cy, r, "FLUX MW"), (cx2, cy, r, "FPS"))
|
|
270
|
+
thick = 4 if lay.compact else 6
|
|
271
|
+
# The flux dial runs green to red; the FPS dial runs red below 12 fps,
|
|
272
|
+
# gold to 30 fps and green above, scaled to FPS_FULL_SCALE.
|
|
273
|
+
fps_deg = 239 / FPS_FULL_SCALE
|
|
274
|
+
zones = (
|
|
275
|
+
((135, 270, EMERALD), (270, 345, GOLD), (345, 405, CORAL)),
|
|
276
|
+
(
|
|
277
|
+
(135, 135 + int(12 * fps_deg), CORAL),
|
|
278
|
+
(135 + int(12 * fps_deg), 135 + int(30 * fps_deg), GOLD),
|
|
279
|
+
(135 + int(30 * fps_deg), 405, EMERALD),
|
|
280
|
+
),
|
|
281
|
+
)
|
|
282
|
+
for (cx, c_y, rad, label), dial_zones in zip(self.gauge_centers, zones):
|
|
283
|
+
d.circle(cx, c_y, rad + 2, DEEP_SLATE, False)
|
|
284
|
+
for dr in range(thick):
|
|
285
|
+
for a0, a1, zcol in dial_zones:
|
|
286
|
+
d.arc(cx, c_y, rad - dr, a0, a1, zcol)
|
|
287
|
+
lbl_x = cx - (len(label) * 4)
|
|
288
|
+
fb.text(label, lbl_x, c_y + rad + (6 if lay.compact else 10), SILVER)
|
|
289
|
+
|
|
290
|
+
# Pre-render the oscilloscope graticule grid inside bay_scope.
|
|
291
|
+
sx, sy_s, sw, sh_s = self.bay_scope
|
|
292
|
+
ox = sx + 8
|
|
293
|
+
oy = sy_s + (18 if lay.compact else 22)
|
|
294
|
+
ow = sw - 16
|
|
295
|
+
oh = sh_s - (26 if lay.compact else 32)
|
|
296
|
+
self.scope_well = (ox, oy, ow, oh)
|
|
297
|
+
fb.rect(ox - 1, oy - 1, ow + 2, oh + 2, DEEP_TEAL)
|
|
298
|
+
|
|
299
|
+
# Sync the exported state dictionary read by SoundEngine.
|
|
300
|
+
def _sync_state(self):
|
|
301
|
+
self.state["boost"] = self.switches[0]
|
|
302
|
+
self.state["shield"] = self.switches[1]
|
|
303
|
+
self.state["phase"] = self.switches[2]
|
|
304
|
+
self.state["overdrive"] = self.switches[3]
|
|
305
|
+
self.state["throttle"] = self.throttle
|
|
306
|
+
|
|
307
|
+
# Handle pointer down or drag inside the Cyber-Deck console.
|
|
308
|
+
def on_pointer_down(self, x, y, is_drag=False):
|
|
309
|
+
# Check throttle slider first (supports continuous dragging).
|
|
310
|
+
tx, ty, tw, th = self.throttle_rect
|
|
311
|
+
if tx - 6 <= x <= tx + tw + 6 and ty - 4 <= y <= ty + th + 4:
|
|
312
|
+
rel = 1.0 - ((y - ty) / max(1, th))
|
|
313
|
+
self.throttle = max(0.08, min(1.0, rel))
|
|
314
|
+
self._thr_index = -1
|
|
315
|
+
self._sync_state()
|
|
316
|
+
if not is_drag:
|
|
317
|
+
self.sound.sfx_switch(True)
|
|
318
|
+
return True
|
|
319
|
+
|
|
320
|
+
if is_drag:
|
|
321
|
+
return False
|
|
322
|
+
|
|
323
|
+
# Check the 4 tactile breaker switches.
|
|
324
|
+
for i, (bx, by, bw, bh) in enumerate(self.switch_rects):
|
|
325
|
+
if bx <= x < bx + bw and by <= y < by + bh:
|
|
326
|
+
self.switches[i] = not self.switches[i]
|
|
327
|
+
self._sync_state()
|
|
328
|
+
self.sound.sfx_switch(self.switches[i])
|
|
329
|
+
return True
|
|
330
|
+
|
|
331
|
+
# Check the 8 harmonic synth pads.
|
|
332
|
+
for i, (bx, by, bw, bh) in enumerate(self.pad_rects):
|
|
333
|
+
if bx <= x < bx + bw and by <= y < by + bh:
|
|
334
|
+
self.pads[i] = not self.pads[i]
|
|
335
|
+
# Ensure at least two pads stay active so the groove never goes empty.
|
|
336
|
+
if sum(1 for p in self.pads if p) < 2:
|
|
337
|
+
self.pads[i] = True
|
|
338
|
+
self.sound.sfx_pad(i, self.pads[i])
|
|
339
|
+
return True
|
|
340
|
+
|
|
341
|
+
return False
|
|
342
|
+
|
|
343
|
+
# Advance coolant bubbles, gauge oscillation, and attract-mode operator.
|
|
344
|
+
def update(self, dt, auto_mode=True):
|
|
345
|
+
self.phase = (self.phase + 5) & 0xFF
|
|
346
|
+
# Counted in whole ms and integer fractions, so a frame boxes no floats for them.
|
|
347
|
+
dt_ms = round(dt * 1000.0)
|
|
348
|
+
if self._thr_index >= 0:
|
|
349
|
+
speed = 600 + self._permille_table[self._thr_index]
|
|
350
|
+
else:
|
|
351
|
+
speed = 600 + self._permille(self.throttle)
|
|
352
|
+
bubbles = self.bubbles
|
|
353
|
+
for i in range(len(bubbles)):
|
|
354
|
+
# Millionths per frame: speed per mille times rate per mille times dt in ms.
|
|
355
|
+
b = bubbles[i] + (self._bubble_speed[i] * speed // 1000) * dt_ms
|
|
356
|
+
if b >= 1000000:
|
|
357
|
+
b -= 1000000
|
|
358
|
+
bubbles[i] = b
|
|
359
|
+
|
|
360
|
+
# Attract-mode virtual operator: toggle switches, sweep throttle, tap pads.
|
|
361
|
+
if auto_mode:
|
|
362
|
+
self._thr_index = self.phase >> 1
|
|
363
|
+
self.throttle = self._thr_table[self._thr_index]
|
|
364
|
+
self._sync_state()
|
|
365
|
+
self.auto_ms -= dt_ms
|
|
366
|
+
if self.auto_ms <= 0:
|
|
367
|
+
self.auto_ms = 2100
|
|
368
|
+
self.auto_step = (self.auto_step + 1) & 7
|
|
369
|
+
if (self.auto_step & 1) == 0:
|
|
370
|
+
sw_idx = (self.auto_step >> 1) & 3
|
|
371
|
+
self.switches[sw_idx] = not self.switches[sw_idx]
|
|
372
|
+
self._sync_state()
|
|
373
|
+
self.sound.sfx_switch(self.switches[sw_idx])
|
|
374
|
+
else:
|
|
375
|
+
pad_idx = (self.auto_step * 3) & 7
|
|
376
|
+
self.pads[pad_idx] = not self.pads[pad_idx]
|
|
377
|
+
if sum(1 for p in self.pads if p) < 3:
|
|
378
|
+
self.pads[pad_idx] = True
|
|
379
|
+
self.sound.sfx_pad(pad_idx, self.pads[pad_idx])
|
|
380
|
+
|
|
381
|
+
# Render the Cyber-Deck console into the target FrameBuffer and Draw wrapper.
|
|
382
|
+
def draw(self, fb, draw_obj=None, st=None):
|
|
383
|
+
if draw_obj is None:
|
|
384
|
+
draw_obj = make_draw(fb)
|
|
385
|
+
copy_frame(fb, self.bg_fb)
|
|
386
|
+
|
|
387
|
+
self._draw_gauges(fb, draw_obj, True)
|
|
388
|
+
self._draw_oscilloscope(fb)
|
|
389
|
+
self._draw_holo_and_coolant(fb)
|
|
390
|
+
self._draw_switches_and_throttle(fb)
|
|
391
|
+
self._draw_spectrum_analyzer(fb)
|
|
392
|
+
self._draw_synth_pads(fb)
|
|
393
|
+
if st is not None:
|
|
394
|
+
st.sig = {}
|
|
395
|
+
play_slot = self.sound._step_index & 7
|
|
396
|
+
for i in range(len(self.switch_rects)):
|
|
397
|
+
st.sig[self._switch_keys[i]] = self.switches[i]
|
|
398
|
+
for i in range(len(self.pad_rects)):
|
|
399
|
+
st.sig[self._pad_keys[i]] = self._pad_look(i, play_slot)
|
|
400
|
+
|
|
401
|
+
# How pad i looks: 0 off, 1 on, 2 on and playing.
|
|
402
|
+
def _pad_look(self, i, play_slot):
|
|
403
|
+
if not self.pads[i]:
|
|
404
|
+
return 0
|
|
405
|
+
return 2 if i == play_slot else 1
|
|
406
|
+
|
|
407
|
+
# Repaint only what changed since this display buffer was last drawn: the gauge dials
|
|
408
|
+
# get their background back, the wells paint over themselves, and the switches and pads
|
|
409
|
+
# are redrawn when they flip. Which ones flipped is kept as bits, so nothing is allocated.
|
|
410
|
+
def draw_changes(self, fb, draw_obj, st):
|
|
411
|
+
lay = self.lay
|
|
412
|
+
play_slot = self.sound._step_index & 7
|
|
413
|
+
n_switches = len(self.switch_rects)
|
|
414
|
+
n_pads = len(self.pad_rects)
|
|
415
|
+
switch_flips = 0
|
|
416
|
+
for i in range(n_switches):
|
|
417
|
+
if st.changed(self._switch_keys[i], self.switches[i]):
|
|
418
|
+
switch_flips |= 1 << i
|
|
419
|
+
pad_flips = 0
|
|
420
|
+
for i in range(n_pads):
|
|
421
|
+
if st.changed(self._pad_keys[i], self._pad_look(i, play_slot)):
|
|
422
|
+
pad_flips |= 1 << i
|
|
423
|
+
restore_sources(fb, self.gauge_sources)
|
|
424
|
+
for i in range(n_switches):
|
|
425
|
+
if switch_flips >> i & 1:
|
|
426
|
+
restore_rect(fb, self.bg_view, self.switch_rects[i], lay.w, lay.h)
|
|
427
|
+
for i in range(n_pads):
|
|
428
|
+
if pad_flips >> i & 1:
|
|
429
|
+
restore_rect(fb, self.bg_view, self.pad_rects[i], lay.w, lay.h)
|
|
430
|
+
|
|
431
|
+
self._draw_gauges(fb, draw_obj, False)
|
|
432
|
+
self._draw_oscilloscope(fb)
|
|
433
|
+
self._draw_holo_and_coolant(fb)
|
|
434
|
+
for i in range(n_switches):
|
|
435
|
+
if switch_flips >> i & 1:
|
|
436
|
+
self._draw_switch(fb, i)
|
|
437
|
+
self._draw_throttle(fb)
|
|
438
|
+
self._draw_spectrum_analyzer(fb)
|
|
439
|
+
for i in range(n_pads):
|
|
440
|
+
if pad_flips >> i & 1:
|
|
441
|
+
self._draw_synth_pad(fb, i, play_slot)
|
|
442
|
+
|
|
443
|
+
# Render rotating polygon needles and digital readouts for the twin gauges.
|
|
444
|
+
# The TEMP label is drawn only when full, as nothing paints over it.
|
|
445
|
+
def _draw_gauges(self, fb, d, full):
|
|
446
|
+
boost = 1 if self.switches[0] else 0
|
|
447
|
+
ovr = 1 if self.switches[3] else 0
|
|
448
|
+
if self._thr_index == self.phase >> 1:
|
|
449
|
+
ang1 = self._ang_table[self.phase * 2 + boost]
|
|
450
|
+
mw = self._mw_table[self.phase * 2 + boost]
|
|
451
|
+
active_segs = self._segs_table[self.phase * 4 + boost * 2 + ovr]
|
|
452
|
+
else:
|
|
453
|
+
jitter = (isin(self.phase * 3) * 3) / 10240.0
|
|
454
|
+
val1 = min(1.0, max(0.05, self.throttle * 0.78 + (0.16 if boost else 0.0) + jitter))
|
|
455
|
+
val2 = min(1.0, max(0.05, self.throttle * 0.72 + (0.14 if ovr else 0.0) - jitter))
|
|
456
|
+
ang1 = (96 + int(val1 * 170)) & 0xFF
|
|
457
|
+
mw = int(val1 * 990)
|
|
458
|
+
active_segs = max(1, min(10, int(((val1 + val2) * 0.5) * 10)))
|
|
459
|
+
# The second dial shows the frame rate, full scale at FPS_FULL_SCALE.
|
|
460
|
+
fps_val = min(1.0, max(0.0, self.fps / FPS_FULL_SCALE))
|
|
461
|
+
if mw != self._mw_shown:
|
|
462
|
+
self._mw_shown = mw
|
|
463
|
+
self._mw_text = "%03dMW" % mw
|
|
464
|
+
tenths = int(self.fps * 10.0 + 0.5)
|
|
465
|
+
if tenths != self._fps_shown:
|
|
466
|
+
self._fps_shown = tenths
|
|
467
|
+
self._fps_text = "%.1f" % self.fps
|
|
468
|
+
|
|
469
|
+
self._draw_needle(fb, d, 0, ang1, GOLD, self._mw_text)
|
|
470
|
+
self._draw_needle(fb, d, 1, (96 + int(fps_val * 170)) & 0xFF, AQUA_GLOW, self._fps_text)
|
|
471
|
+
|
|
472
|
+
# Draw a segmented Core Temp status bar along the bottom of the telemetry bay.
|
|
473
|
+
gx, gy, gw, gh = self.bay_gauges
|
|
474
|
+
bar_y = gy + gh - (16 if self.lay.compact else 20)
|
|
475
|
+
if bar_y > self.gauge_centers[0][1] + self.gauge_centers[0][2] + 14:
|
|
476
|
+
if full:
|
|
477
|
+
fb.text("TEMP", gx + 8, bar_y, SILVER)
|
|
478
|
+
bx0 = gx + 48
|
|
479
|
+
bw_tot = gw - 58
|
|
480
|
+
segs = 10
|
|
481
|
+
seg_w = max(4, (bw_tot - (segs - 1) * 2) // segs)
|
|
482
|
+
for s in range(segs):
|
|
483
|
+
sx = bx0 + s * (seg_w + 2)
|
|
484
|
+
if s < active_segs:
|
|
485
|
+
scol = CORAL if s >= 8 else (GOLD if s >= 6 else LIME_GLOW)
|
|
486
|
+
else:
|
|
487
|
+
scol = DEEP_SLATE
|
|
488
|
+
fb.fill_rect(sx, bar_y, seg_w, 8, scol)
|
|
489
|
+
|
|
490
|
+
# Draw gauge idx's needle at phase index ang_idx, its hub and its readout txt. A value
|
|
491
|
+
# from 0.0 to 1.0 maps to (96 + int(v * 170)) & 0xFF, about 210 degrees of the dial.
|
|
492
|
+
def _draw_needle(self, fb, d, idx, ang_idx, col, txt):
|
|
493
|
+
cx, cy, rad, _ = self.gauge_centers[idx]
|
|
494
|
+
tip_len = rad - 4
|
|
495
|
+
px = (icos((ang_idx + 64) & 0xFF) * 3) >> 10
|
|
496
|
+
py = (isin((ang_idx + 64) & 0xFF) * 3) >> 10
|
|
497
|
+
poly = self._needle
|
|
498
|
+
poly[0] = cx + ((icos(ang_idx) * tip_len) >> 10)
|
|
499
|
+
poly[1] = cy + ((isin(ang_idx) * tip_len) >> 10)
|
|
500
|
+
poly[2] = cx + px
|
|
501
|
+
poly[3] = cy + py
|
|
502
|
+
poly[4] = cx - px
|
|
503
|
+
poly[5] = cy - py
|
|
504
|
+
fb.poly(0, 0, poly, col, True)
|
|
505
|
+
if fb.__class__ is self._hub.__class__:
|
|
506
|
+
fb.blit(self._hub, cx - 5, cy - 5, KEY)
|
|
507
|
+
else:
|
|
508
|
+
d.circle(cx, cy, 4, BRONZE, True)
|
|
509
|
+
d.circle(cx, cy, 2, WHITE, True)
|
|
510
|
+
fb.text(txt, cx - (len(txt) * 4), cy + (rad >> 1) - 2, WHITE)
|
|
511
|
+
|
|
512
|
+
# Render the dual-trace oscilloscope with fundamental and phase-shifted traces.
|
|
513
|
+
def _draw_oscilloscope(self, fb):
|
|
514
|
+
ox, oy, ow, oh = self.scope_well
|
|
515
|
+
fb.fill_rect(ox, oy, ow, oh, VOID)
|
|
516
|
+
mid_y = oy + (oh >> 1)
|
|
517
|
+
fb.hline(ox, mid_y, ow, NIGHT)
|
|
518
|
+
fb.vline(ox + (ow >> 1), oy, oh, NIGHT)
|
|
519
|
+
|
|
520
|
+
samples = self.sound.scope_samples
|
|
521
|
+
n = len(samples)
|
|
522
|
+
span_w = max(1, ow - 4)
|
|
523
|
+
half_h = max(6, (oh >> 1) - 4)
|
|
524
|
+
p1x = ox + 2
|
|
525
|
+
p1y = mid_y
|
|
526
|
+
p2x = ox + 2
|
|
527
|
+
p2y = mid_y
|
|
528
|
+
phase_shift = 6 if self.switches[2] else 3
|
|
529
|
+
for i in range(n):
|
|
530
|
+
sx = ox + 2 + (i * span_w) // (n - 1)
|
|
531
|
+
s1 = samples[i]
|
|
532
|
+
s2 = samples[(i + phase_shift) % n]
|
|
533
|
+
y1 = mid_y - ((s1 * half_h) // 100)
|
|
534
|
+
y2 = mid_y - ((s2 * (half_h - 3)) // 115)
|
|
535
|
+
if i > 0:
|
|
536
|
+
fb.line(p1x, p1y, sx, y1, AQUA_GLOW)
|
|
537
|
+
fb.line(p2x, p2y, sx, y2, GOLD)
|
|
538
|
+
p1x, p1y = sx, y1
|
|
539
|
+
p2x, p2y = sx, y2
|
|
540
|
+
|
|
541
|
+
# Render the Holo-Bit diagnostic projector and sloshing coolant tank.
|
|
542
|
+
def _draw_holo_and_coolant(self, fb):
|
|
543
|
+
bx, by, bw, bh = self.bay_holo
|
|
544
|
+
tank_w = 24 if self.lay.compact else 34
|
|
545
|
+
tx = bx + bw - tank_w - 8
|
|
546
|
+
ty = by + (18 if self.lay.compact else 22)
|
|
547
|
+
th = bh - (26 if self.lay.compact else 30)
|
|
548
|
+
|
|
549
|
+
# Draw Holo-Bit hovering inside a cyan wireframe projection well.
|
|
550
|
+
hx = bx + 8
|
|
551
|
+
hw = tx - hx - 6
|
|
552
|
+
fb.fill_rect(hx, ty, hw, th, VOID)
|
|
553
|
+
fb.rect(hx, ty, hw, th, DEEP_TEAL)
|
|
554
|
+
scan_y = ty + 2 + ((self.phase * max(1, th - 6)) >> 8)
|
|
555
|
+
fb.hline(hx + 2, scan_y, hw - 4, DEEP_TEAL)
|
|
556
|
+
|
|
557
|
+
bob = (isin(self.phase) * 4) >> 10
|
|
558
|
+
hcx = hx + (hw >> 1)
|
|
559
|
+
hcy = ty + (th >> 1) - 4 + bob
|
|
560
|
+
self.sprites.draw_glow(fb, hcx, hcy, AQUA_GLOW, large=True)
|
|
561
|
+
self.sprites.holo_bit.draw_center(fb, hcx, hcy)
|
|
562
|
+
status = "OVRDRV!" if self.switches[3] else "NOMINAL"
|
|
563
|
+
scol = CORAL if self.switches[3] else LIME_GLOW
|
|
564
|
+
fb.text(status, hx + ((hw - len(status) * 8) >> 1), ty + th - 12, scol)
|
|
565
|
+
|
|
566
|
+
# Draw the vertical Bioluminescent Coolant Tank with rising bubbles.
|
|
567
|
+
fb.fill_rect(tx, ty, tank_w, th, VOID)
|
|
568
|
+
fb.rect(tx, ty, tank_w, th, TEAL)
|
|
569
|
+
if self._thr_index >= 0:
|
|
570
|
+
level_h = self._level_table[self._thr_index]
|
|
571
|
+
else:
|
|
572
|
+
level_h = int(th * (0.58 + self.throttle * 0.28))
|
|
573
|
+
liq_y = ty + th - level_h
|
|
574
|
+
fb.fill_rect(tx + 2, liq_y, tank_w - 4, level_h - 2, FOREST)
|
|
575
|
+
fb.hline(tx + 2, liq_y, tank_w - 4, LIME_GLOW)
|
|
576
|
+
fb.hline(tx + 2, liq_y + 1, tank_w - 4, EMERALD)
|
|
577
|
+
rise = max(4, level_h - 6)
|
|
578
|
+
for idx in range(len(self.bubbles)):
|
|
579
|
+
by_bub = ty + th - 4 - self.bubbles[idx] * rise // 1000000
|
|
580
|
+
bx_bub = tx + 5 + ((idx * 7) % max(4, tank_w - 10))
|
|
581
|
+
fb.fill_rect(bx_bub, by_bub, 3, 3, AQUA_GLOW)
|
|
582
|
+
|
|
583
|
+
# Render the 4 tactile toggle switches and vertical throttle fader.
|
|
584
|
+
def _draw_switches_and_throttle(self, fb):
|
|
585
|
+
for i in range(len(self.switch_rects)):
|
|
586
|
+
self._draw_switch(fb, i)
|
|
587
|
+
self._draw_throttle(fb)
|
|
588
|
+
|
|
589
|
+
# Render one tactile breaker switch.
|
|
590
|
+
def _draw_switch(self, fb, i):
|
|
591
|
+
bx, by, bw, bh = self.switch_rects[i]
|
|
592
|
+
on = self.switches[i]
|
|
593
|
+
border = LIME_GLOW if on else STEEL
|
|
594
|
+
draw_pixel_panel(fb, bx, by, bw, bh, NIGHT, border)
|
|
595
|
+
# Status LED bar at top of switch.
|
|
596
|
+
led_col = LIME_GLOW if on else DEEP_SLATE
|
|
597
|
+
fb.fill_rect(bx + 5, by + 5, bw - 10, 4, led_col)
|
|
598
|
+
# Tactile rocker handle (up when ON, down when OFF).
|
|
599
|
+
rock_h = max(10, (bh - 26) >> 1)
|
|
600
|
+
rock_y = (by + 12) if on else (by + 12 + rock_h)
|
|
601
|
+
rock_col = AQUA_GLOW if on else SLATE
|
|
602
|
+
fb.fill_rect(bx + 5, rock_y, bw - 10, rock_h, rock_col)
|
|
603
|
+
fb.hline(bx + 5, rock_y, bw - 10, WHITE if on else SILVER)
|
|
604
|
+
# Label at bottom of switch.
|
|
605
|
+
lbl = SWITCH_NAMES[i][: max(3, (bw - 4) // 8)]
|
|
606
|
+
fb.text(lbl, bx + ((bw - len(lbl) * 8) >> 1), by + bh - 11, WHITE if on else MIST)
|
|
607
|
+
|
|
608
|
+
# Render the vertical THROTTLE fader track and brass thumb cap.
|
|
609
|
+
def _draw_throttle(self, fb):
|
|
610
|
+
tx, ty, tw, th = self.throttle_rect
|
|
611
|
+
fb.fill_rect(tx, ty, tw, th, VOID)
|
|
612
|
+
fb.rect(tx, ty, tw, th, AMBER)
|
|
613
|
+
if self._thr_index >= 0:
|
|
614
|
+
fill_h = self._fill_table[self._thr_index]
|
|
615
|
+
else:
|
|
616
|
+
fill_h = max(0, min(th - 4, int(th * self.throttle)))
|
|
617
|
+
if fill_h > 2:
|
|
618
|
+
fb.fill_rect(tx + 3, ty + th - fill_h - 2, tw - 6, fill_h, COPPER)
|
|
619
|
+
knob_y = ty + th - fill_h - 5
|
|
620
|
+
knob_y = max(ty + 2, min(ty + th - 10, knob_y))
|
|
621
|
+
fb.fill_rect(tx + 1, knob_y, tw - 2, 8, GOLD)
|
|
622
|
+
fb.hline(tx + 2, knob_y + 1, tw - 4, WHITE)
|
|
623
|
+
|
|
624
|
+
# Render the 16-band real-time FFT spectrum analyzer with peak-hold caps.
|
|
625
|
+
def _draw_spectrum_analyzer(self, fb):
|
|
626
|
+
bx, by, bw, bh = self.bay_spectrum
|
|
627
|
+
wx = bx + 8
|
|
628
|
+
wy = by + (18 if self.lay.compact else 22)
|
|
629
|
+
ww = bw - 16
|
|
630
|
+
wh = bh - (24 if self.lay.compact else 28)
|
|
631
|
+
fb.fill_rect(wx, wy, ww, wh, VOID)
|
|
632
|
+
fb.rect(wx, wy, ww, wh, DEEP_TEAL)
|
|
633
|
+
|
|
634
|
+
bins = self.sound.spectrum_bins
|
|
635
|
+
peaks = self.sound.spectrum_peaks
|
|
636
|
+
n = len(bins)
|
|
637
|
+
step_x = (ww - 6) // n
|
|
638
|
+
bar_w = max(3, step_x - 2)
|
|
639
|
+
max_bar_h = wh - 8
|
|
640
|
+
base_y = wy + wh - 3
|
|
641
|
+
|
|
642
|
+
for i in range(n):
|
|
643
|
+
x = wx + 4 + i * step_x
|
|
644
|
+
h = (bins[i] * max_bar_h) // 100
|
|
645
|
+
ph = (peaks[i] * max_bar_h) // 100
|
|
646
|
+
if h > 0:
|
|
647
|
+
mid_h = min(h, max_bar_h >> 1)
|
|
648
|
+
fb.fill_rect(x, base_y - mid_h, bar_w, mid_h, EMERALD)
|
|
649
|
+
if h > mid_h:
|
|
650
|
+
top_h = h - mid_h
|
|
651
|
+
col = GOLD if h > (max_bar_h * 3) >> 2 else AQUA_GLOW
|
|
652
|
+
fb.fill_rect(x, base_y - h, bar_w, top_h, col)
|
|
653
|
+
peak_y = max(wy + 2, base_y - ph - 2)
|
|
654
|
+
fb.hline(x, peak_y, bar_w, WHITE)
|
|
655
|
+
|
|
656
|
+
# Render the 2x4 harmonic synth pad matrix with live step highlighter.
|
|
657
|
+
def _draw_synth_pads(self, fb):
|
|
658
|
+
play_slot = self.sound._step_index & 7
|
|
659
|
+
for i in range(len(self.pad_rects)):
|
|
660
|
+
self._draw_synth_pad(fb, i, play_slot)
|
|
661
|
+
|
|
662
|
+
# Render one synth pad.
|
|
663
|
+
def _draw_synth_pad(self, fb, i, play_slot):
|
|
664
|
+
bx, by, bw, bh = self.pad_rects[i]
|
|
665
|
+
active = self.pads[i]
|
|
666
|
+
playing = (i == play_slot) and active
|
|
667
|
+
if playing:
|
|
668
|
+
bg = MAGENTA
|
|
669
|
+
border = WHITE
|
|
670
|
+
elif active:
|
|
671
|
+
bg = DEEP_TEAL
|
|
672
|
+
border = AQUA_GLOW
|
|
673
|
+
else:
|
|
674
|
+
bg = NIGHT
|
|
675
|
+
border = SLATE
|
|
676
|
+
draw_pixel_panel(fb, bx, by, bw, bh, bg, border, ICE_CYAN if active else None)
|
|
677
|
+
lbl = PAD_NOTES[i]
|
|
678
|
+
fb.text(
|
|
679
|
+
lbl,
|
|
680
|
+
bx + ((bw - len(lbl) * 8) >> 1),
|
|
681
|
+
by + ((bh - 8) >> 1),
|
|
682
|
+
WHITE if active else STEEL,
|
|
683
|
+
)
|