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,210 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""The prompt sheet: ask for a groove in words, see the song that comes back, then play, keep or let it go.
|
|
5
|
+
|
|
6
|
+
The desk's header button opens it over the tabs. Type what you want ("a
|
|
7
|
+
slow 12-bar blues at 72, 4 times through, slowing in the outro") and Ask,
|
|
8
|
+
or Enter. The box asks its chat server (`ask`), and the sheet shows the song
|
|
9
|
+
before anyone hears it: its name and style, the tempo, meter and kit, the
|
|
10
|
+
play plan and its form as a strip. Play starts it, Keep puts it among the
|
|
11
|
+
songs, and Discard lets it go and brings back the song from before.
|
|
12
|
+
|
|
13
|
+
It holds nothing of its own: the request goes to the box as the ``ask``
|
|
14
|
+
command and the song comes back to every panel, so the same sheet works on
|
|
15
|
+
the box's screen and on a desk elsewhere.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
import lvgl as lv
|
|
19
|
+
|
|
20
|
+
from . import look
|
|
21
|
+
from .. import ask as askmod
|
|
22
|
+
from .. import glyphs
|
|
23
|
+
from .strip import Strip
|
|
24
|
+
|
|
25
|
+
try:
|
|
26
|
+
from appkit import keys
|
|
27
|
+
except ImportError: # a desk with no appkit: the field takes keys without an on-screen keyboard
|
|
28
|
+
keys = None
|
|
29
|
+
|
|
30
|
+
HINT = "A slow 12-bar blues at 72, 4 times through, slowing in the outro"
|
|
31
|
+
IDLE = "Say a style, a tempo, a song to borrow the feel of, and how long to play."
|
|
32
|
+
ASKING = "Asking for the song... a model on a computer with no GPU can take a few minutes."
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class PromptSheet:
|
|
36
|
+
"""The sheet in ``parent`` at ``(x, y)``, ``w`` by ``h``, for ``desk``; hidden until `show`."""
|
|
37
|
+
|
|
38
|
+
def __init__(self, parent, x, y, w, h, desk):
|
|
39
|
+
self.desk = desk
|
|
40
|
+
s = desk.scale
|
|
41
|
+
m = desk.m
|
|
42
|
+
f = desk.fonts
|
|
43
|
+
w, h = int(w), int(h)
|
|
44
|
+
self.preview = None
|
|
45
|
+
self.state = ""
|
|
46
|
+
self.base = look.box(parent, x, y, w, h, look.BG, 0, None)
|
|
47
|
+
self.base.add_flag(lv.obj.FLAG.CLICKABLE) # taps stay on the sheet
|
|
48
|
+
self.base.add_flag(lv.obj.FLAG.HIDDEN)
|
|
49
|
+
pad = 2 * m
|
|
50
|
+
look.heading(self.base, "Ask for a groove", f["small"], pad + 4, pad, "prompt")
|
|
51
|
+
bs = int(34 * s)
|
|
52
|
+
look.button(self.base, w - pad - bs, pad - 6, bs, bs, icon="close", on_click=desk.toggle_prompt, radius=6)
|
|
53
|
+
|
|
54
|
+
fy = pad + f["small"].line_height + 2 * m
|
|
55
|
+
fh = int(46 * s)
|
|
56
|
+
aw = int(110 * s)
|
|
57
|
+
field = lv.textarea(self.base)
|
|
58
|
+
field.set_pos(pad, fy)
|
|
59
|
+
field.set_size(w - 2 * pad - aw - m, fh)
|
|
60
|
+
field.set_one_line(True)
|
|
61
|
+
field.set_placeholder_text(HINT)
|
|
62
|
+
field.set_style_text_font(f["body"], 0)
|
|
63
|
+
field.set_style_bg_color(look.color(0x05070B), 0)
|
|
64
|
+
field.set_style_bg_opa(255, 0)
|
|
65
|
+
field.set_style_text_color(look.color(look.TEXT), 0)
|
|
66
|
+
field.set_style_border_color(look.color(look.LINE), 0)
|
|
67
|
+
field.set_style_border_color(look.color(look.AMBER), lv.STATE.FOCUSED)
|
|
68
|
+
field.set_style_border_width(1, 0)
|
|
69
|
+
field.set_style_radius(8, 0)
|
|
70
|
+
field.set_style_pad_ver(max(2, (fh - f["body"].line_height) // 2 - 2), 0)
|
|
71
|
+
hint = getattr(lv.PART, "TEXTAREA_PLACEHOLDER", None) # not in every binding
|
|
72
|
+
if hint is not None:
|
|
73
|
+
field.set_style_text_color(look.color(look.FAINT), hint)
|
|
74
|
+
if keys is not None:
|
|
75
|
+
keys.attach(field)
|
|
76
|
+
field.add_event_cb(lambda _e: self.ask(), lv.EVENT.READY, None)
|
|
77
|
+
self.field = field
|
|
78
|
+
self.ask_button = look.button(self.base, w - pad - aw, fy, aw, fh, "ASK", fnt=f["body"], on_click=self.ask)
|
|
79
|
+
look.select(self.ask_button, True)
|
|
80
|
+
|
|
81
|
+
sy = fy + fh + m
|
|
82
|
+
self.status = look.text(self.base, IDLE, f["small"], look.DIM, w - 2 * pad)
|
|
83
|
+
self.status.set_long_mode(lv.label.LONG_MODE.WRAP)
|
|
84
|
+
self.status.set_height(2 * f["small"].line_height + 2)
|
|
85
|
+
self.status.set_pos(pad, sy)
|
|
86
|
+
|
|
87
|
+
# The song that came back.
|
|
88
|
+
cy = sy + 2 * f["small"].line_height + 2 * m
|
|
89
|
+
ch = h - cy - pad
|
|
90
|
+
card = look.box(self.base, pad, cy, w - 2 * pad, ch, look.PANEL, 10, look.LINE)
|
|
91
|
+
card.add_flag(lv.obj.FLAG.HIDDEN)
|
|
92
|
+
self.card = card
|
|
93
|
+
cw = w - 2 * pad
|
|
94
|
+
ip = int(14 * s)
|
|
95
|
+
self.title = look.text(card, "", f["title"], look.AMBER, cw - 2 * ip)
|
|
96
|
+
self.title.set_pos(ip, ip)
|
|
97
|
+
self.facts = look.text(card, "", f["body"], look.TEXT, cw - 2 * ip)
|
|
98
|
+
self.facts.set_pos(ip, ip + f["title"].line_height + 6)
|
|
99
|
+
self.plan = look.text(card, "", f["body"], look.DIM, cw - 2 * ip)
|
|
100
|
+
self.plan.set_pos(ip, ip + f["title"].line_height + f["body"].line_height + 10)
|
|
101
|
+
by = ip + f["title"].line_height + 2 * f["body"].line_height + 22
|
|
102
|
+
bh2 = int(40 * s)
|
|
103
|
+
buttons_y = ch - ip - bh2
|
|
104
|
+
self.filled = look.text(card, "", f["small"], look.FAINT, cw - 2 * ip)
|
|
105
|
+
self.filled.set_pos(ip, buttons_y - f["small"].line_height - m)
|
|
106
|
+
look.heading(card, "Song form", f["small"], ip, by, "form")
|
|
107
|
+
sy2 = by + f["small"].line_height + 2
|
|
108
|
+
self.strip = Strip(card, ip, sy2, cw - 2 * ip, max(30, buttons_y - f["small"].line_height - 2 * m - sy2),
|
|
109
|
+
f["small"])
|
|
110
|
+
bw = int(130 * s)
|
|
111
|
+
self.buttons = {}
|
|
112
|
+
for i, (key, name) in enumerate((("play", "PLAY"), ("keep", "KEEP"), ("discard", "DISCARD"))):
|
|
113
|
+
b = look.button(card, ip + i * (bw + m), buttons_y, bw, bh2, name, fnt=f["body"],
|
|
114
|
+
on_click=self._doer(key), radius=6)
|
|
115
|
+
self.buttons[key] = b
|
|
116
|
+
look.select(self.buttons["play"], True, look.ROLE_COLORS.get("main", look.AMBER))
|
|
117
|
+
|
|
118
|
+
# -- what it sends --
|
|
119
|
+
|
|
120
|
+
def _doer(self, what):
|
|
121
|
+
def on_click():
|
|
122
|
+
self.desk.command("proposal", do=what)
|
|
123
|
+
|
|
124
|
+
return on_click
|
|
125
|
+
|
|
126
|
+
def ask(self):
|
|
127
|
+
"""Send what's in the field to the box."""
|
|
128
|
+
text = self.field.get_text().strip()
|
|
129
|
+
if not text or self.state == "asking":
|
|
130
|
+
return
|
|
131
|
+
if keys is not None:
|
|
132
|
+
keys.hide()
|
|
133
|
+
self.desk.command("ask", text=text)
|
|
134
|
+
self.show_state("asking", "")
|
|
135
|
+
|
|
136
|
+
# -- showing it --
|
|
137
|
+
|
|
138
|
+
def shown(self):
|
|
139
|
+
return not self.base.has_flag(lv.obj.FLAG.HIDDEN)
|
|
140
|
+
|
|
141
|
+
def show(self):
|
|
142
|
+
self.base.remove_flag(lv.obj.FLAG.HIDDEN)
|
|
143
|
+
self.base.move_foreground()
|
|
144
|
+
|
|
145
|
+
def hide(self):
|
|
146
|
+
if keys is not None:
|
|
147
|
+
keys.hide()
|
|
148
|
+
self.base.add_flag(lv.obj.FLAG.HIDDEN)
|
|
149
|
+
|
|
150
|
+
def toggle(self):
|
|
151
|
+
if self.shown():
|
|
152
|
+
self.hide()
|
|
153
|
+
else:
|
|
154
|
+
self.show()
|
|
155
|
+
|
|
156
|
+
def show_state(self, state, error):
|
|
157
|
+
if state == self.state and not error:
|
|
158
|
+
return
|
|
159
|
+
self.state = state
|
|
160
|
+
if state == "asking":
|
|
161
|
+
self.status.set_text(ASKING)
|
|
162
|
+
self.status.set_style_text_color(look.color(look.DIM), 0)
|
|
163
|
+
elif state == "failed":
|
|
164
|
+
self.status.set_text(error or "the song didn't come")
|
|
165
|
+
self.status.set_style_text_color(look.color(look.BAD), 0)
|
|
166
|
+
elif state == "ready" and self.preview is not None:
|
|
167
|
+
tries = self.preview.get("tries", 1)
|
|
168
|
+
self.status.set_text("Here it is." + (" (The first answer didn't fit; the second did.)" if tries > 1 else ""))
|
|
169
|
+
self.status.set_style_text_color(look.color(look.DIM), 0)
|
|
170
|
+
else:
|
|
171
|
+
self.status.set_text(IDLE)
|
|
172
|
+
self.status.set_style_text_color(look.color(look.DIM), 0)
|
|
173
|
+
|
|
174
|
+
def show_preview(self, p):
|
|
175
|
+
"""Show the song `ask.preview` describes, or none."""
|
|
176
|
+
self.preview = p
|
|
177
|
+
if p is None:
|
|
178
|
+
self.card.add_flag(lv.obj.FLAG.HIDDEN)
|
|
179
|
+
return
|
|
180
|
+
self.title.set_text(p.get("name") or "Untitled")
|
|
181
|
+
self.facts.set_text(askmod.facts_text(p, glyphs.DOT))
|
|
182
|
+
plan = askmod.plan_text(p)
|
|
183
|
+
self.plan.set_text(plan[0].upper() + plan[1:])
|
|
184
|
+
self.strip.set_blocks(p.get("blocks") or [])
|
|
185
|
+
filled = p.get("filled") or []
|
|
186
|
+
self.filled.set_text(("Filled in: " + ", ".join(filled)) if filled else "")
|
|
187
|
+
self.card.remove_flag(lv.obj.FLAG.HIDDEN)
|
|
188
|
+
|
|
189
|
+
# -- what comes from the box --
|
|
190
|
+
|
|
191
|
+
def on_doc(self, desc):
|
|
192
|
+
self.show_preview(desc.get("proposal"))
|
|
193
|
+
|
|
194
|
+
def on_event(self, ev):
|
|
195
|
+
if ev.get("name") != "proposal":
|
|
196
|
+
return
|
|
197
|
+
if "preview" in ev:
|
|
198
|
+
self.show_preview(ev["preview"])
|
|
199
|
+
if ev.get("error"):
|
|
200
|
+
self.show_state("failed", ev["error"])
|
|
201
|
+
elif ev.get("did") in ("keep", "discard"):
|
|
202
|
+
self.show_preview(None)
|
|
203
|
+
self.show_state("", "")
|
|
204
|
+
if ev.get("did") == "keep":
|
|
205
|
+
self.field.set_text("")
|
|
206
|
+
|
|
207
|
+
def on_tele(self, t):
|
|
208
|
+
self.show_state(t.get("ask", ""), t.get("ask_error", ""))
|
|
209
|
+
if self.preview is not None and t.get("song") == self.preview.get("name"):
|
|
210
|
+
self.strip.show(t) # the song that came back is the one playing
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""The song-form strip: a song's parts in a row, the one playing lit with
|
|
5
|
+
the playhead moving across it, and the one coming next outlined.
|
|
6
|
+
|
|
7
|
+
Each part is a block as wide as its bars, in its colour from the floor
|
|
8
|
+
view. With ``on_pick``, a tap on a block picks that part (the editor uses
|
|
9
|
+
it to choose the part to edit), and the picked one is underlined.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import lvgl as lv
|
|
13
|
+
|
|
14
|
+
from . import look
|
|
15
|
+
from .. import parts as song
|
|
16
|
+
from .. import art
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Strip:
|
|
20
|
+
"""The strip in ``parent`` at ``(x, y)``, ``w`` by ``h``."""
|
|
21
|
+
|
|
22
|
+
def __init__(self, parent, x, y, w, h, fnt, on_pick=None):
|
|
23
|
+
self.w, self.h = int(w), int(h)
|
|
24
|
+
self.fnt = fnt
|
|
25
|
+
self.on_pick = on_pick
|
|
26
|
+
self.base = look.plain(lv.obj(parent))
|
|
27
|
+
self.base.set_pos(int(x), int(y))
|
|
28
|
+
self.base.set_size(self.w, self.h)
|
|
29
|
+
self.blocks = []
|
|
30
|
+
self.objs = []
|
|
31
|
+
self.lit = -1
|
|
32
|
+
self.next = -1
|
|
33
|
+
self.picked = -1
|
|
34
|
+
self.head = None
|
|
35
|
+
self.tag = None
|
|
36
|
+
self.mark = None
|
|
37
|
+
|
|
38
|
+
def set_blocks(self, blocks):
|
|
39
|
+
"""Lay out ``blocks`` (from `parts.blocks`)."""
|
|
40
|
+
self.base.clean()
|
|
41
|
+
self.blocks = blocks
|
|
42
|
+
self.objs = []
|
|
43
|
+
self.lit = self.next = -1
|
|
44
|
+
n = len(blocks)
|
|
45
|
+
if not n:
|
|
46
|
+
self.head = self.tag = self.mark = None
|
|
47
|
+
return
|
|
48
|
+
gap = max(3, self.w // 160)
|
|
49
|
+
tag_h = self.fnt.line_height
|
|
50
|
+
top = tag_h + 2
|
|
51
|
+
bh = self.h - top - max(4, self.h // 12)
|
|
52
|
+
total = sum(b["bars"] for b in blocks)
|
|
53
|
+
room = self.w - gap * (n - 1)
|
|
54
|
+
# Every block at least wide enough for a short name, the rest by bars.
|
|
55
|
+
least = min(room // n, max(30, room // (2 * n)))
|
|
56
|
+
spare = room - least * n
|
|
57
|
+
x = 0
|
|
58
|
+
rail = look.box(self.base, 0, top + bh // 2 - 1, self.w, 2, look.LINE, 1, None)
|
|
59
|
+
rail.set_style_bg_opa(160, 0)
|
|
60
|
+
for i, b in enumerate(blocks):
|
|
61
|
+
art.pause()
|
|
62
|
+
bw = least + spare * b["bars"] // total if i < n - 1 else self.w - x
|
|
63
|
+
color = look.ROLE_COLORS.get(b["role"], look.DIM)
|
|
64
|
+
o = look.box(self.base, x, top, bw, bh, art.mix(color, look.BG, 0.8), 6, art.mix(color, look.BG, 0.45))
|
|
65
|
+
lbl = look.text(o, b["short"], self.fnt, art.mix(color, look.TEXT, 0.35), bw - 6, lv.TEXT_ALIGN.CENTER)
|
|
66
|
+
lbl.align(lv.ALIGN.CENTER, 0, 0)
|
|
67
|
+
if self.on_pick is not None:
|
|
68
|
+
o.add_flag(lv.obj.FLAG.CLICKABLE)
|
|
69
|
+
o.add_event_cb(self._picker(i), lv.EVENT.CLICKED, None)
|
|
70
|
+
self.objs.append((o, lbl, x, bw, color))
|
|
71
|
+
x += bw + gap
|
|
72
|
+
self.top, self.bh = top, bh
|
|
73
|
+
head = look.box(self.base, 0, top - 2, max(2, self.w // 300), bh + 4, 0xFFFFFF, 1, None)
|
|
74
|
+
head.add_flag(lv.obj.FLAG.HIDDEN)
|
|
75
|
+
self.head = head
|
|
76
|
+
tag = look.text(self.base, "NEXT", self.fnt, look.DIM)
|
|
77
|
+
tag.set_style_text_letter_space(1, 0)
|
|
78
|
+
tag.add_flag(lv.obj.FLAG.HIDDEN)
|
|
79
|
+
self.tag = tag
|
|
80
|
+
mark = look.box(self.base, 0, top + bh + 2, 10, max(3, self.h // 20), look.AMBER, 2, None)
|
|
81
|
+
mark.add_flag(lv.obj.FLAG.HIDDEN)
|
|
82
|
+
self.mark = mark
|
|
83
|
+
if self.picked >= 0:
|
|
84
|
+
p, self.picked = self.picked, -1
|
|
85
|
+
self.pick(min(p, n - 1))
|
|
86
|
+
|
|
87
|
+
def _picker(self, i):
|
|
88
|
+
def on_event(_e):
|
|
89
|
+
self.pick(i)
|
|
90
|
+
self.on_pick(i)
|
|
91
|
+
|
|
92
|
+
return on_event
|
|
93
|
+
|
|
94
|
+
def pick(self, i):
|
|
95
|
+
"""Underline block ``i``, the part being edited."""
|
|
96
|
+
if i == self.picked or self.mark is None:
|
|
97
|
+
return
|
|
98
|
+
self.picked = i
|
|
99
|
+
_o, _l, x, bw, _c = self.objs[i]
|
|
100
|
+
self.mark.set_pos(x + 4, self.top + self.bh + 2)
|
|
101
|
+
self.mark.set_width(max(4, bw - 8))
|
|
102
|
+
self.mark.remove_flag(lv.obj.FLAG.HIDDEN)
|
|
103
|
+
|
|
104
|
+
def _style(self, i, how):
|
|
105
|
+
if not 0 <= i < len(self.objs):
|
|
106
|
+
return
|
|
107
|
+
o, lbl, _x, _bw, color = self.objs[i]
|
|
108
|
+
if how == "lit":
|
|
109
|
+
o.set_style_bg_color(look.color(art.mix(color, look.BG, 0.35)), 0)
|
|
110
|
+
o.set_style_border_color(look.color(color), 0)
|
|
111
|
+
o.set_style_border_width(2, 0)
|
|
112
|
+
lbl.set_style_text_color(look.color(0xFFFFFF), 0)
|
|
113
|
+
elif how == "next":
|
|
114
|
+
o.set_style_bg_color(look.color(art.mix(color, look.BG, 0.75)), 0)
|
|
115
|
+
o.set_style_border_color(look.color(color), 0)
|
|
116
|
+
o.set_style_border_width(2, 0)
|
|
117
|
+
lbl.set_style_text_color(look.color(art.mix(color, look.TEXT, 0.2)), 0)
|
|
118
|
+
else:
|
|
119
|
+
o.set_style_bg_color(look.color(art.mix(color, look.BG, 0.8)), 0)
|
|
120
|
+
o.set_style_border_color(look.color(art.mix(color, look.BG, 0.45)), 0)
|
|
121
|
+
o.set_style_border_width(1, 0)
|
|
122
|
+
lbl.set_style_text_color(look.color(art.mix(color, look.TEXT, 0.35)), 0)
|
|
123
|
+
|
|
124
|
+
def show(self, tele):
|
|
125
|
+
"""Light the part ``tele`` says plays, and move the playhead."""
|
|
126
|
+
if not self.objs:
|
|
127
|
+
return
|
|
128
|
+
playing = tele.get("playing")
|
|
129
|
+
lit = song.find(self.blocks, tele.get("role"), tele.get("number")) if playing else -1
|
|
130
|
+
nxt = song.find(self.blocks, tele.get("next_role"), tele.get("next_number")) if playing else -1
|
|
131
|
+
if nxt == lit:
|
|
132
|
+
nxt = -1
|
|
133
|
+
if lit != self.lit or nxt != self.next:
|
|
134
|
+
for i in (self.lit, self.next):
|
|
135
|
+
self._style(i, "plain")
|
|
136
|
+
self._style(nxt, "next")
|
|
137
|
+
self._style(lit, "lit")
|
|
138
|
+
self.lit, self.next = lit, nxt
|
|
139
|
+
if nxt >= 0:
|
|
140
|
+
_o, _l, x, bw, color = self.objs[nxt]
|
|
141
|
+
self.tag.set_style_text_color(look.color(color), 0)
|
|
142
|
+
self.tag.set_pos(x + 2, 0)
|
|
143
|
+
self.tag.remove_flag(lv.obj.FLAG.HIDDEN)
|
|
144
|
+
else:
|
|
145
|
+
self.tag.add_flag(lv.obj.FLAG.HIDDEN)
|
|
146
|
+
if lit < 0:
|
|
147
|
+
self.head.add_flag(lv.obj.FLAG.HIDDEN)
|
|
148
|
+
return
|
|
149
|
+
_o, _l, x, bw, _c = self.objs[lit]
|
|
150
|
+
length = self.blocks[lit]["bars"] * song.BAR
|
|
151
|
+
frac = min(1.0, max(0.0, tele.get("at", 0) / float(length)))
|
|
152
|
+
self.head.set_x(int(x + 2 + frac * (bw - 4)))
|
|
153
|
+
self.head.remove_flag(lv.obj.FLAG.HIDDEN)
|
|
154
|
+
|
|
155
|
+
def head_x(self):
|
|
156
|
+
"""Where the playhead is, or -1 when it's hidden (for a check)."""
|
|
157
|
+
if self.head is None or self.head.has_flag(lv.obj.FLAG.HIDDEN):
|
|
158
|
+
return -1
|
|
159
|
+
return self.head.get_x()
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Backline's desk on its own: a screen that joins a box somewhere else.
|
|
5
|
+
|
|
6
|
+
On a computer, with this repository's ``apps/`` and ``lib/`` and hmilink on
|
|
7
|
+
the path, and omnipython-desktop for the window::
|
|
8
|
+
|
|
9
|
+
OMNIPYTHON_WIDTH=1280 OMNIPYTHON_HEIGHT=720 python -m backline.desk_main HOST[:9300]
|
|
10
|
+
|
|
11
|
+
The box is a running Backline. With no address, it looks on this computer,
|
|
12
|
+
or at ``$BACKLINE_BOX``. The space bar is pedal A and B is pedal B, as on
|
|
13
|
+
the box. When the box goes away, the desk says so and joins it again when
|
|
14
|
+
it's back.
|
|
15
|
+
|
|
16
|
+
A board can also wait for its box, when the box is a browser playing
|
|
17
|
+
Backline (a browser can connect, but can't be found): ``ble:NAME``
|
|
18
|
+
advertises over Bluetooth as NAME, and ``usb`` listens on a second USB
|
|
19
|
+
serial port (`remote.desk_link`). From the board's REPL, with the app in
|
|
20
|
+
``/apps/backline``::
|
|
21
|
+
|
|
22
|
+
from backline import desk_main
|
|
23
|
+
desk_main.main(["ble:Backline"])
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
import socket
|
|
27
|
+
import sys
|
|
28
|
+
|
|
29
|
+
import hmilink
|
|
30
|
+
import lvgl as lv
|
|
31
|
+
from hmilink import stream, tcp
|
|
32
|
+
|
|
33
|
+
from .desk import Desk
|
|
34
|
+
from . import remote
|
|
35
|
+
|
|
36
|
+
STEP_MS = 30
|
|
37
|
+
RETRY_MS = 3000
|
|
38
|
+
SILENT_MS = 3000 # a box sends telemetry many times a second: this long without any, it has gone
|
|
39
|
+
JOIN_S = 3
|
|
40
|
+
K_SPACE, K_B = 32, 98
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def join(host, port, seconds=JOIN_S):
|
|
44
|
+
"""A panel on the box at ``host``:``port``, giving up after ``seconds``.
|
|
45
|
+
|
|
46
|
+
Raises:
|
|
47
|
+
OSError: The box didn't answer.
|
|
48
|
+
"""
|
|
49
|
+
s = socket.socket()
|
|
50
|
+
s.settimeout(seconds)
|
|
51
|
+
try:
|
|
52
|
+
s.connect(socket.getaddrinfo(host, port)[0][-1])
|
|
53
|
+
except OSError:
|
|
54
|
+
s.close()
|
|
55
|
+
raise
|
|
56
|
+
link = tcp.Link(s)
|
|
57
|
+
link._decided(False) # a panel speaks lines from the start
|
|
58
|
+
return hmilink.Panel(link)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def usb_serial():
|
|
62
|
+
"""A second USB serial port on this board, beside the REPL's, for a
|
|
63
|
+
browser's WebSerial. Needs micropython-lib's ``usb-device-cdc``.
|
|
64
|
+
|
|
65
|
+
A board with one USB port can't be a USB device while it's a USB host,
|
|
66
|
+
and Home starts the host for keyboards. Stop it first with
|
|
67
|
+
``usb.core.stop()``, and plug that port into the computer."""
|
|
68
|
+
import usb.device
|
|
69
|
+
from usb.device.cdc import CDCInterface
|
|
70
|
+
|
|
71
|
+
cdc = CDCInterface(timeout=0)
|
|
72
|
+
usb.device.get().init(cdc, builtin_driver=True)
|
|
73
|
+
return cdc
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def opener(spec, usb=usb_serial, adapter=None):
|
|
77
|
+
"""``(where, connect)`` for a desk spec (`remote.desk_link`): what the
|
|
78
|
+
desk calls its box, and ``connect(host, port)`` for `Remote`, which makes
|
|
79
|
+
a panel on it. ``usb`` makes the USB port, once; ``adapter`` is the
|
|
80
|
+
Bluetooth radio (the board's own when it's left out).
|
|
81
|
+
|
|
82
|
+
Raises:
|
|
83
|
+
ValueError: A TCP port isn't a number.
|
|
84
|
+
"""
|
|
85
|
+
kind, arg = remote.desk_link(spec)
|
|
86
|
+
if kind == "ble":
|
|
87
|
+
from hmilink import ble
|
|
88
|
+
|
|
89
|
+
return "Bluetooth, as %s" % arg, lambda _h, _p: hmilink.Panel(ble.advertise(arg, adapter=adapter))
|
|
90
|
+
if kind == "usb":
|
|
91
|
+
port = []
|
|
92
|
+
|
|
93
|
+
def on_usb(_h, _p):
|
|
94
|
+
if not port:
|
|
95
|
+
port.append(usb())
|
|
96
|
+
return hmilink.Panel(stream.link(port[0]))
|
|
97
|
+
|
|
98
|
+
return "USB", on_usb
|
|
99
|
+
return "%s:%d" % arg, lambda _h, _p: join(arg[0], arg[1])
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class Remote:
|
|
103
|
+
"""A `Desk` on ``screen`` that keeps a link to the box at ``(host, port)``.
|
|
104
|
+
|
|
105
|
+
``connect(host, port)`` makes the panel; ``where`` is what the desk
|
|
106
|
+
calls the box (``host:port`` when it's left out).
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
def __init__(self, screen, size, host, port, connect=join, where=None):
|
|
110
|
+
self.host, self.port = host, port
|
|
111
|
+
self.where = where or "%s:%s" % (host, port)
|
|
112
|
+
self.connect = connect
|
|
113
|
+
self.desk = Desk(screen, size, None)
|
|
114
|
+
self.waited = RETRY_MS
|
|
115
|
+
self.waiting = False
|
|
116
|
+
self.quiet = 0 # ms since the box last said anything
|
|
117
|
+
self._heard = None
|
|
118
|
+
self._try()
|
|
119
|
+
|
|
120
|
+
def _try(self):
|
|
121
|
+
try:
|
|
122
|
+
panel = self.connect(self.host, self.port)
|
|
123
|
+
except OSError as e:
|
|
124
|
+
self.desk._error({"msg": "no box at %s (%s)" % (self.where, e)})
|
|
125
|
+
return
|
|
126
|
+
self.desk.attach(panel)
|
|
127
|
+
if not panel.ready:
|
|
128
|
+
self.waiting = True
|
|
129
|
+
self.desk._error({"msg": "waiting for the box: %s" % self.where})
|
|
130
|
+
|
|
131
|
+
def step(self, ms=STEP_MS):
|
|
132
|
+
"""One pass of the UI loop: the link, and a new try when it's gone."""
|
|
133
|
+
panel = self.desk.panel
|
|
134
|
+
if panel is not None and not panel.closed:
|
|
135
|
+
self.desk.poll()
|
|
136
|
+
self._listen(panel, ms)
|
|
137
|
+
if self.waiting and panel.ready:
|
|
138
|
+
self.waiting = False
|
|
139
|
+
self.desk.message = ""
|
|
140
|
+
self.desk.shown.pop("next", None)
|
|
141
|
+
self.waited = 0
|
|
142
|
+
return
|
|
143
|
+
if panel is not None:
|
|
144
|
+
self.desk.panel = None
|
|
145
|
+
self.desk._error({"msg": "the box went away"})
|
|
146
|
+
self.waited += ms
|
|
147
|
+
if self.waited >= RETRY_MS:
|
|
148
|
+
self.waited = 0
|
|
149
|
+
self._try()
|
|
150
|
+
|
|
151
|
+
def _listen(self, panel, ms):
|
|
152
|
+
"""Close a link the box has gone quiet on. A box that resets leaves
|
|
153
|
+
the desk's socket open with nothing behind it, and the box sends
|
|
154
|
+
telemetry many times a second, so `SILENT_MS` of nothing means it
|
|
155
|
+
has gone; the next pass says so and joins it again."""
|
|
156
|
+
heard = panel.stats["tele"] + panel.stats["ops_in"]
|
|
157
|
+
if heard != self._heard:
|
|
158
|
+
self._heard = heard
|
|
159
|
+
self.quiet = 0
|
|
160
|
+
return
|
|
161
|
+
self.quiet += ms
|
|
162
|
+
if self.quiet >= SILENT_MS:
|
|
163
|
+
self.quiet = 0
|
|
164
|
+
self._heard = None
|
|
165
|
+
panel.close()
|
|
166
|
+
|
|
167
|
+
def close(self):
|
|
168
|
+
if self.desk.panel is not None:
|
|
169
|
+
self.desk.panel.close()
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def start(argv=()):
|
|
173
|
+
"""Open the desk on this computer's display and start it. Returns its
|
|
174
|
+
`Remote`; LVGL's loop runs it from here."""
|
|
175
|
+
argv = list(argv)
|
|
176
|
+
spec = argv[0] if argv else "%s:%d" % remote.target()
|
|
177
|
+
where, connect = opener(spec)
|
|
178
|
+
from display_driver import app # noqa: F401 (the display, on LVGL)
|
|
179
|
+
|
|
180
|
+
disp = lv.display_get_default()
|
|
181
|
+
size = (disp.get_horizontal_resolution(), disp.get_vertical_resolution())
|
|
182
|
+
screen = lv.obj(None)
|
|
183
|
+
lv.screen_load(screen)
|
|
184
|
+
view = Remote(screen, size, spec, None, connect, where)
|
|
185
|
+
view.timer = lv.timer_create(lambda t: view.step(), STEP_MS, None)
|
|
186
|
+
held = set()
|
|
187
|
+
|
|
188
|
+
def key(down):
|
|
189
|
+
def on_key(e):
|
|
190
|
+
k = getattr(e, "key", None)
|
|
191
|
+
if down == (k in held):
|
|
192
|
+
return
|
|
193
|
+
(held.add if down else held.discard)(k)
|
|
194
|
+
if k in (K_SPACE, K_B):
|
|
195
|
+
view.desk.pedal(0 if k == K_SPACE else 1, down)
|
|
196
|
+
|
|
197
|
+
return on_key
|
|
198
|
+
|
|
199
|
+
try:
|
|
200
|
+
import events
|
|
201
|
+
|
|
202
|
+
app.on(events.KEYDOWN, key(True))
|
|
203
|
+
app.on(events.KEYUP, key(False))
|
|
204
|
+
except (ImportError, AttributeError):
|
|
205
|
+
pass
|
|
206
|
+
print("desk: joining the box at %s" % where)
|
|
207
|
+
return view
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def main(argv=None):
|
|
211
|
+
"""Run the desk until the window closes or Ctrl-C."""
|
|
212
|
+
view = start(sys.argv[1:] if argv is None else argv)
|
|
213
|
+
from display_driver import app
|
|
214
|
+
|
|
215
|
+
try:
|
|
216
|
+
app.run()
|
|
217
|
+
except KeyboardInterrupt:
|
|
218
|
+
pass
|
|
219
|
+
finally:
|
|
220
|
+
view.timer.delete()
|
|
221
|
+
view.close()
|
|
222
|
+
return view
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
if __name__ == "__main__":
|
|
226
|
+
main()
|