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.
Files changed (218) hide show
  1. apps/__init__.py +5 -0
  2. apps/about/__init__.py +257 -0
  3. apps/about/app.json +1 -0
  4. apps/about/credits.py +12 -0
  5. apps/about/facts.py +398 -0
  6. apps/about/fonts/OFL.txt +93 -0
  7. apps/about/fonts/latin1_14.bin +0 -0
  8. apps/about/fonts/latin1_16.bin +0 -0
  9. apps/about/fonts/latin1_24.bin +0 -0
  10. apps/about/fonts/latin1_32.bin +0 -0
  11. apps/about/fonts/latin1_40.bin +0 -0
  12. apps/backline/__init__.py +58 -0
  13. apps/backline/app.json +1 -0
  14. apps/backline/app.py +475 -0
  15. apps/backline/art.py +717 -0
  16. apps/backline/ask.py +781 -0
  17. apps/backline/box.py +502 -0
  18. apps/backline/cast.py +137 -0
  19. apps/backline/desk/__init__.py +329 -0
  20. apps/backline/desk/editor.py +331 -0
  21. apps/backline/desk/grid.py +154 -0
  22. apps/backline/desk/look.py +169 -0
  23. apps/backline/desk/pedals.py +102 -0
  24. apps/backline/desk/perform.py +157 -0
  25. apps/backline/desk/prompt.py +210 -0
  26. apps/backline/desk/strip.py +159 -0
  27. apps/backline/desk_main.py +226 -0
  28. apps/backline/engine.py +622 -0
  29. apps/backline/floor.py +509 -0
  30. apps/backline/footswitch.py +119 -0
  31. apps/backline/glyphs.py +82 -0
  32. apps/backline/kits.py +428 -0
  33. apps/backline/midipedal.py +362 -0
  34. apps/backline/page_data.py +413 -0
  35. apps/backline/parts.py +145 -0
  36. apps/backline/pedal.py +107 -0
  37. apps/backline/remote.py +134 -0
  38. apps/backline/songs/ballad_68.json +1 -0
  39. apps/backline/songs/bossa.json +1 -0
  40. apps/backline/songs/country_train.json +1 -0
  41. apps/backline/songs/funk.json +1 -0
  42. apps/backline/songs/metal.json +1 -0
  43. apps/backline/songs/pop.json +1 -0
  44. apps/backline/songs/rock.json +1 -0
  45. apps/backline/songs/shuffle.json +1 -0
  46. apps/battery/__init__.py +101 -0
  47. apps/battery/app.json +1 -0
  48. apps/bit_world/act_deck.py +683 -0
  49. apps/bit_world/act_game.py +762 -0
  50. apps/bit_world/act_pet.py +1032 -0
  51. apps/bit_world/app.json +1 -0
  52. apps/bit_world/bit_output.py +45 -0
  53. apps/bit_world/bit_palette.py +503 -0
  54. apps/bit_world/bit_sound.py +431 -0
  55. apps/bit_world/bit_sprites.py +632 -0
  56. apps/bit_world/bit_world.py +534 -0
  57. apps/btreceiver/__init__.py +690 -0
  58. apps/btreceiver/app.json +1 -0
  59. apps/btreceiver/chime.py +155 -0
  60. apps/btreceiver/demo.py +529 -0
  61. apps/btreceiver/screen.py +633 -0
  62. apps/camera/__init__.py +316 -0
  63. apps/camera/app.json +1 -0
  64. apps/card/__init__.py +113 -0
  65. apps/card/app.json +1 -0
  66. apps/cast/__init__.py +631 -0
  67. apps/cast/app.json +1 -0
  68. apps/cast/receivers.py +193 -0
  69. apps/chess/__init__.py +18 -0
  70. apps/chess/app.json +1 -0
  71. apps/chess/app.py +922 -0
  72. apps/chess/art.py +323 -0
  73. apps/chess/ble.py +411 -0
  74. apps/chess/engine.py +925 -0
  75. apps/chess/game.py +327 -0
  76. apps/chess/net.py +261 -0
  77. apps/clock/__init__.py +38 -0
  78. apps/clock/app.json +1 -0
  79. apps/detect/__init__.py +214 -0
  80. apps/detect/app.json +1 -0
  81. apps/fmsynth/__init__.py +41 -0
  82. apps/fmsynth/algorithms.py +61 -0
  83. apps/fmsynth/app.json +1 -0
  84. apps/fmsynth/app.py +355 -0
  85. apps/fmsynth/editor.py +206 -0
  86. apps/fmsynth/engine.py +257 -0
  87. apps/fmsynth/meters.py +262 -0
  88. apps/fmsynth/midi.py +375 -0
  89. apps/fmsynth/panel_view.py +1071 -0
  90. apps/fmsynth/patches/fmsynth-01.syx +0 -0
  91. apps/fmsynth/settings.py +138 -0
  92. apps/fmsynth/voice.py +398 -0
  93. apps/gamepad/__init__.py +685 -0
  94. apps/gamepad/app.json +1 -0
  95. apps/gamepad/pad.py +94 -0
  96. apps/gamepad/watch.py +352 -0
  97. apps/hidden/__init__.py +72 -0
  98. apps/hidden/app.json +1 -0
  99. apps/home/__init__.py +483 -0
  100. apps/home/app.json +1 -0
  101. apps/home/main.py +36 -0
  102. apps/homeassistant/__init__.py +213 -0
  103. apps/homeassistant/api.py +104 -0
  104. apps/homeassistant/app.json +1 -0
  105. apps/huey/__init__.py +287 -0
  106. apps/huey/acting.py +184 -0
  107. apps/huey/actor.py +194 -0
  108. apps/huey/app.json +1 -0
  109. apps/huey/client.py +125 -0
  110. apps/huey/servers.py +121 -0
  111. apps/huey/settings.example.json +8 -0
  112. apps/huey/settings.py +97 -0
  113. apps/huey/turn.py +504 -0
  114. apps/huey/voice.py +217 -0
  115. apps/info/__init__.py +810 -0
  116. apps/info/app.json +1 -0
  117. apps/lora/__init__.py +62 -0
  118. apps/lora/app.json +1 -0
  119. apps/manifest.py +71 -0
  120. apps/medialink_baby_monitor/__init__.py +222 -0
  121. apps/medialink_baby_monitor/app.json +1 -0
  122. apps/medialink_doorbell/__init__.py +251 -0
  123. apps/medialink_doorbell/app.json +1 -0
  124. apps/medialink_hands_free/__init__.py +217 -0
  125. apps/medialink_hands_free/app.json +1 -0
  126. apps/medialink_surveillance_camera/__init__.py +258 -0
  127. apps/medialink_surveillance_camera/app.json +1 -0
  128. apps/medialink_video_doorbell/__init__.py +289 -0
  129. apps/medialink_video_doorbell/app.json +1 -0
  130. apps/medialink_videophone/__init__.py +273 -0
  131. apps/medialink_videophone/app.json +1 -0
  132. apps/medialink_walkie_talkie/__init__.py +228 -0
  133. apps/medialink_walkie_talkie/app.json +1 -0
  134. apps/midicontroller/__init__.py +774 -0
  135. apps/midicontroller/app.json +1 -0
  136. apps/midicontroller/links.py +421 -0
  137. apps/midicontroller/surface.py +343 -0
  138. apps/midiengine/__init__.py +977 -0
  139. apps/midiengine/app.json +1 -0
  140. apps/midiengine/banks.py +85 -0
  141. apps/midiengine/midiin.py +165 -0
  142. apps/midiengine/player.py +392 -0
  143. apps/midiengine/umidiparser.py +1413 -0
  144. apps/mp3/__init__.py +240 -0
  145. apps/mp3/app.json +1 -0
  146. apps/perch/__init__.py +119 -0
  147. apps/perch/app.json +1 -0
  148. apps/perch/huey.py +481 -0
  149. apps/perch/huey_props.py +386 -0
  150. apps/perch/huey_shift.py +42 -0
  151. apps/perch/huey_views.py +296 -0
  152. apps/perch/scene_bench.py +680 -0
  153. apps/perch/scene_coast.py +479 -0
  154. apps/perch/scene_desk.py +492 -0
  155. apps/perch/stage.py +1274 -0
  156. apps/perch/vec.py +366 -0
  157. apps/repl/__init__.py +325 -0
  158. apps/repl/app.json +1 -0
  159. apps/roku/__init__.py +156 -0
  160. apps/roku/app.json +1 -0
  161. apps/rokucam/__init__.py +362 -0
  162. apps/rokucam/app.json +1 -0
  163. apps/security/__init__.py +261 -0
  164. apps/security/app.json +1 -0
  165. apps/settings/__init__.py +221 -0
  166. apps/settings/app.json +1 -0
  167. apps/shell/__init__.py +33 -0
  168. apps/shell/app.json +1 -0
  169. apps/spotify/__init__.py +669 -0
  170. apps/spotify/app.json +1 -0
  171. apps/spotify/screen.py +82 -0
  172. apps/steps/__init__.py +58 -0
  173. apps/steps/app.json +1 -0
  174. apps/stompbox/__init__.py +31 -0
  175. apps/stompbox/app.json +1 -0
  176. apps/stompbox/app.py +668 -0
  177. apps/stompbox/boards.json +20 -0
  178. apps/stompbox/effects.py +241 -0
  179. apps/stompbox/engine.py +340 -0
  180. apps/stompbox/footswitch.py +331 -0
  181. apps/stompbox/inputs.py +449 -0
  182. apps/stompbox/meter.py +72 -0
  183. apps/stompbox/outputs.py +135 -0
  184. apps/stompbox/pedals.txt +45 -0
  185. apps/stompbox/presets.py +106 -0
  186. apps/stompbox/styles.py +135 -0
  187. apps/stompbox/ui.py +817 -0
  188. apps/stompbox/wavfile.py +73 -0
  189. apps/synthstation/__init__.py +20 -0
  190. apps/synthstation/app.json +1 -0
  191. apps/synthstation/audio.py +397 -0
  192. apps/synthstation/catalog.py +50 -0
  193. apps/synthstation/meters.py +136 -0
  194. apps/synthstation/midi.py +380 -0
  195. apps/synthstation/pads.py +177 -0
  196. apps/synthstation/parts.py +128 -0
  197. apps/synthstation/station.py +1069 -0
  198. apps/system/__init__.py +11 -0
  199. apps/system/app.json +1 -0
  200. apps/touchcal/__init__.py +324 -0
  201. apps/touchcal/app.json +1 -0
  202. apps/touchcal/fit.py +262 -0
  203. apps/wake/__init__.py +268 -0
  204. apps/wake/app.json +1 -0
  205. apps/wake/feed.py +155 -0
  206. apps/watch/__init__.py +355 -0
  207. apps/watch/app.json +1 -0
  208. apps/watch/faces.py +35 -0
  209. apps/watch/wheel.py +157 -0
  210. apps/weather/__init__.py +278 -0
  211. apps/weather/app.json +1 -0
  212. apps/weather/icons.py +172 -0
  213. apps/weather/sizing.py +71 -0
  214. apps/weather/zippad.py +172 -0
  215. omnipython_apps-0.1.4.dev8.dist-info/METADATA +33 -0
  216. omnipython_apps-0.1.4.dev8.dist-info/RECORD +218 -0
  217. omnipython_apps-0.1.4.dev8.dist-info/WHEEL +5 -0
  218. omnipython_apps-0.1.4.dev8.dist-info/top_level.txt +1 -0
@@ -0,0 +1,329 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """Backline's desk view: perform and edit a song from a bigger screen.
5
+
6
+ Two tabs under one header, and a prompt sheet (`prompt.PromptSheet`) the
7
+ header's sparkle button opens, to ask for a groove in words. Perform (`perform.Perform`) is the floor view's
8
+ face, larger, with the song's form, the songs, the tempo and the kit.
9
+ Edit (`editor.Editor`) is the step grid of a part, the song library, the
10
+ kits and a mixer, every change landing while the song plays. The header
11
+ shows the part, the bar and beat, and what comes next, on both tabs.
12
+
13
+ Like the floor view, the desk holds nothing but an ``hmilink.Panel``, so
14
+ the same view runs on the box's own screen through ``hmilink.local``, or on
15
+ another computer or board through ``hmilink.tcp`` (`desk_main`). It is laid
16
+ out for 800x480 and larger, from the ``size`` it is given.
17
+
18
+ desk = Desk(screen, (800, 480), panel)
19
+ while True:
20
+ desk.poll()
21
+ """
22
+
23
+ import lvgl as lv
24
+
25
+ from . import look
26
+ from .. import art, glyphs
27
+ from .. import floor as floormod
28
+ from .editor import Editor
29
+ from .perform import Perform
30
+ from .prompt import PromptSheet
31
+
32
+ TABS = (("perform", "PERFORM"), ("edit", "EDIT"))
33
+
34
+
35
+ class _Proxy:
36
+ """What the floor view inside the desk sees as its panel: the desk's
37
+ panel's document, and commands sent through the desk."""
38
+
39
+ def __init__(self, desk):
40
+ self.desk = desk
41
+ self.on_doc = None
42
+ self.on_tele = None
43
+
44
+ @property
45
+ def doc(self):
46
+ return self.desk.panel.doc if self.desk.panel is not None else None
47
+
48
+ @property
49
+ def desc(self):
50
+ return self.desk.panel.desc if self.desk.panel is not None else None
51
+
52
+ def command(self, name, **args):
53
+ self.desk.command(name, **args)
54
+
55
+ def poll(self):
56
+ pass
57
+
58
+
59
+ class Desk:
60
+ """The desk view on ``root``, ``size`` = (width, height), showing ``panel``.
61
+
62
+ With ``on_switch``, a button in the header calls it: the app shows the
63
+ floor view there instead.
64
+ """
65
+
66
+ def __init__(self, root, size, panel, on_switch=None):
67
+ w, h = size
68
+ self.size = size
69
+ self.scale = s = min(w / 800.0, h / 480.0)
70
+ self.m = m = max(6, int(8 * s))
71
+ self.fonts = {"small": look.font(14 * s), "body": look.font(16 * s), "value": look.font(24 * s),
72
+ "title": look.font(24 * s)}
73
+ self.panel = None
74
+ self.panel_proxy = _Proxy(self)
75
+ self.tele = {}
76
+ self.shown = {}
77
+ self.message = ""
78
+ self.refused_until = None # saying why the view stays (`refuse_switch`) until then
79
+ self.tab = None
80
+ self.hidden = False
81
+ self._stale = False # the document changed while hidden: `hide`
82
+ self._held = [] # the events that came while hidden
83
+ self._held_tele = None
84
+
85
+ base = look.plain(lv.obj(root))
86
+ base.set_pos(0, 0)
87
+ base.set_size(w, h)
88
+ base.set_style_bg_color(look.color(look.BG), 0)
89
+ base.set_style_bg_opa(255, 0)
90
+ self.base = base
91
+
92
+ hh = int(52 * s)
93
+ self.header_h = hh
94
+ head = look.box(base, 0, 0, w, hh, look.PANEL, 0, None)
95
+ look.box(base, 0, hh - 1, w, 1, look.LINE, 0, None)
96
+ f = self.fonts
97
+ title = look.text(head, "BACKLINE", f["body"], look.AMBER)
98
+ title.set_style_text_letter_space(3, 0)
99
+ title.align(lv.ALIGN.LEFT_MID, m * 2, 0)
100
+ tx = m * 2 + int(118 * s)
101
+ tw = int(124 * s)
102
+ self.tab_buttons = {}
103
+ for i, (key, name) in enumerate(TABS):
104
+ b = look.button(head, tx + i * (tw + m), m, tw, hh - 2 * m, name, fnt=f["small"],
105
+ on_click=self._tabber(key), radius=6)
106
+ b.get_child(0).set_style_text_letter_space(2, 0)
107
+ self.tab_buttons[key] = b
108
+ rx = tx + 2 * (tw + m) + m
109
+ # The readout: the part, the bar and beat, and what comes next.
110
+ sw = int(30 * s) + m if on_switch is not None else 0
111
+ pw = int(34 * s) + m # the prompt sheet's button
112
+ # Where the desk is cast and how many other screens have joined, as
113
+ # small icons left of the switch; hidden while there are none.
114
+ isz = f["small"].line_height + 2
115
+ iw = 2 * isz + int(26 * s)
116
+ self.readout_w = rw = w - rx - sw - pw - iw - 3 * m
117
+ self.part = look.text(head, "", f["body"], look.DIM, int(rw * 0.34))
118
+ self.part.set_pos(rx, (hh - f["body"].line_height) // 2)
119
+ self.where = look.text(head, "", f["value"], look.TEXT, int(rw * 0.26), lv.TEXT_ALIGN.CENTER)
120
+ self.where.set_pos(rx + int(rw * 0.34), (hh - f["value"].line_height) // 2)
121
+ self.next = look.text(head, "", f["small"], look.DIM, int(rw * 0.40), lv.TEXT_ALIGN.RIGHT)
122
+ self.next.set_pos(rx + int(rw * 0.60), (hh - f["small"].line_height) // 2)
123
+ ix = rx + rw + 2 * m
124
+ self.cast_icon = glyphs.show(head, "cast", isz, look.color(look.DIM))
125
+ self.cast_icon.set_pos(ix, (hh - isz) // 2)
126
+ self.cast_icon.add_flag(lv.obj.FLAG.HIDDEN)
127
+ self.remote_icon = glyphs.show(head, "remote", isz, look.color(look.DIM))
128
+ self.remote_icon.set_pos(ix + isz + 2, (hh - isz) // 2)
129
+ self.remote_icon.add_flag(lv.obj.FLAG.HIDDEN)
130
+ self.remote_count = look.text(head, "", f["small"], look.DIM)
131
+ self.remote_count.set_pos(ix + 2 * isz + 2, (hh - f["small"].line_height) // 2)
132
+ self.switch = None
133
+ bs = int(34 * s)
134
+ if on_switch is not None:
135
+ self.switch = look.button(head, w - bs - m * 2, (hh - bs) // 2, bs, bs, role="floor",
136
+ on_click=on_switch, radius=6)
137
+ self.prompt_button = look.button(head, w - bs - m * 2 - sw, (hh - bs) // 2, bs, bs, role="prompt",
138
+ on_click=self.toggle_prompt, radius=6)
139
+
140
+ body_h = h - hh
141
+ art.pause()
142
+ self.perform = Perform(base, 0, hh, w, body_h, self)
143
+ art.pause()
144
+ self.editor = Editor(base, 0, hh, w, body_h, self)
145
+ art.pause()
146
+ self.prompt = PromptSheet(base, 0, hh, w, body_h, self)
147
+ self.show_tab("perform")
148
+ art.pause()
149
+ self.attach(panel)
150
+
151
+ # -- the panel --
152
+
153
+ def attach(self, panel):
154
+ """Draw from ``panel`` from now on (a new link after the old one went)."""
155
+ self.panel = panel
156
+ if panel is None:
157
+ return
158
+ panel.on_doc = self._doc
159
+ panel.on_op = self._op
160
+ panel.on_tele = self._tele
161
+ panel.on_event = self._event
162
+ panel.on_error = self._error
163
+ if panel.doc is not None:
164
+ self._doc(panel.doc, panel.desc)
165
+
166
+ def poll(self):
167
+ if self.panel is not None:
168
+ self.panel.poll()
169
+
170
+ def command(self, name, **args):
171
+ if self.panel is not None and not self.panel.closed:
172
+ self.panel.command(name, **args)
173
+
174
+ def hide(self):
175
+ """Hide the desk, and let go of the art of the floor view's face on
176
+ the Perform tab (`floor.Floor.hide`) until `show`.
177
+
178
+ While it hides, what the panel says is kept, not shown: the last
179
+ telemetry, that the document changed, and the last event of each
180
+ kind. A song change laid the editor's grid and lists out again,
181
+ twice; on a board that held the song's notes off for over a second,
182
+ for a desk no one saw."""
183
+ self.base.add_flag(lv.obj.FLAG.HIDDEN)
184
+ self.perform.floor.hide()
185
+ self.hidden = True
186
+
187
+ def show(self):
188
+ """Show the desk as the song is now, the Perform tab's face drawn again."""
189
+ if self.hidden:
190
+ self.hidden = False
191
+ stale, self._stale = self._stale, False
192
+ events, self._held = self._held, []
193
+ tele, self._held_tele = self._held_tele, None
194
+ if stale and self.panel is not None and self.panel.doc is not None:
195
+ self._doc(self.panel.doc, self.panel.desc) # ops and all
196
+ for ev in events:
197
+ art.pause()
198
+ self._event(ev)
199
+ if tele is not None:
200
+ self._tele(tele)
201
+ self.perform.floor.show()
202
+ self.base.remove_flag(lv.obj.FLAG.HIDDEN)
203
+
204
+ def toggle_prompt(self):
205
+ """Open the prompt sheet over the tabs, or close it."""
206
+ self.prompt.toggle()
207
+ look.select(self.prompt_button, self.prompt.shown())
208
+
209
+ def typing(self):
210
+ """True while the prompt sheet is open, so the app's keys type words, not pedals."""
211
+ return self.prompt.shown()
212
+
213
+ def pedal(self, which, down):
214
+ """Pedal ``which`` went down or up: tell the device."""
215
+ self.command("pedal", pedal=which, down=down)
216
+
217
+ # -- the tabs --
218
+
219
+ def _tabber(self, key):
220
+ def on_click():
221
+ self.show_tab(key)
222
+
223
+ return on_click
224
+
225
+ def show_tab(self, key):
226
+ """Show tab ``"perform"`` or ``"edit"``."""
227
+ if self.tab is not None and self.prompt.shown():
228
+ self.toggle_prompt()
229
+ if key == self.tab:
230
+ return
231
+ self.tab = key
232
+ for k, b in self.tab_buttons.items():
233
+ look.select(b, k == key)
234
+ if key == "perform":
235
+ self.editor.base.add_flag(lv.obj.FLAG.HIDDEN)
236
+ self.perform.base.remove_flag(lv.obj.FLAG.HIDDEN)
237
+ else:
238
+ self.perform.base.add_flag(lv.obj.FLAG.HIDDEN)
239
+ self.editor.base.remove_flag(lv.obj.FLAG.HIDDEN)
240
+
241
+ # -- what comes from the device --
242
+
243
+ def _doc(self, doc, desc):
244
+ if self.hidden:
245
+ self._stale = True
246
+ return
247
+ self.perform.on_doc(doc, desc or {})
248
+ self.editor.on_doc(doc, desc or {})
249
+ self.prompt.on_doc(desc or {})
250
+
251
+ def _op(self, op):
252
+ if self.hidden:
253
+ self._stale = True # the panel's document holds it
254
+ return
255
+ self.perform.on_op(op)
256
+ self.editor.on_op(op)
257
+
258
+ def _event(self, ev):
259
+ if self.hidden:
260
+ # The last of each kind, in the order they came.
261
+ name = ev.get("name")
262
+ self._held = [e for e in self._held if e.get("name") != name] + [ev]
263
+ return
264
+ self.perform.on_event(ev)
265
+ self.editor.on_event(ev)
266
+ self.prompt.on_event(ev)
267
+
268
+ def _changed(self, key, value):
269
+ if self.shown.get(key) == value:
270
+ return False
271
+ self.shown[key] = value
272
+ return True
273
+
274
+ def _error(self, msg):
275
+ if msg.get("msg"):
276
+ self.shown.pop("next", None)
277
+ self.message = msg["msg"]
278
+ self.next.set_text(self.message.upper())
279
+ self.next.set_style_text_color(look.color(look.BAD), 0)
280
+
281
+ def refuse_switch(self):
282
+ """Say, where the next part goes, that the view changes only while
283
+ the song is stopped: a tap on the switch while a song plays."""
284
+ self.refused_until = art.until(art.SAY_MS)
285
+ self.shown.pop("next", None)
286
+ floormod.fit(self.next, art.STOP_TO_SWITCH, self.next.get_width(), 0)
287
+ self.next.set_style_text_color(look.color(look.BAD), 0)
288
+
289
+ def _tele(self, t):
290
+ if self.hidden:
291
+ self._held_tele = t
292
+ return
293
+ self.tele = t
294
+ playing = t.get("playing")
295
+ role = t.get("role", "stopped")
296
+ color = look.ROLE_COLORS.get(role, look.DIM)
297
+ if self._changed("part", (t.get("part"), color)):
298
+ self.part.set_text((t.get("part") or "Ready").upper())
299
+ self.part.set_style_text_color(look.color(color), 0)
300
+ where = "%d . %d" % (t.get("bar", 1), t.get("beat", 1)) if playing else "- . -"
301
+ if self._changed("where", where):
302
+ self.where.set_text(where)
303
+ if self.switch is not None and self._changed("switch", bool(playing)):
304
+ self.switch.set_style_opa(art.DIM_OPA if playing else 255, 0) # it says why when tapped
305
+ if art.before(self.refused_until):
306
+ pass # `refuse_switch` says why the view stays
307
+ elif not (self.message and not playing): # what the device refused stays until the song plays
308
+ self.message = ""
309
+ nxt = t.get("next") or ""
310
+ if self._changed("next", (nxt, playing, t.get("next_role"))):
311
+ self.next.set_text(("NEXT " + nxt.upper()) if nxt else ("LOOPING" if playing else "TAP A TO START"))
312
+ ncolor = look.ROLE_COLORS.get(t.get("next_role") or "", look.DIM) if nxt else look.DIM
313
+ self.next.set_style_text_color(look.color(art.mix(ncolor, look.TEXT, 0.15)), 0)
314
+ if self._changed("cast", bool(t.get("cast"))):
315
+ if t.get("cast"):
316
+ self.cast_icon.remove_flag(lv.obj.FLAG.HIDDEN)
317
+ else:
318
+ self.cast_icon.add_flag(lv.obj.FLAG.HIDDEN)
319
+ desks = t.get("desks", 0)
320
+ if self._changed("desks", desks):
321
+ for o in (self.remote_icon, self.remote_count):
322
+ if desks:
323
+ o.remove_flag(lv.obj.FLAG.HIDDEN)
324
+ else:
325
+ o.add_flag(lv.obj.FLAG.HIDDEN)
326
+ self.remote_count.set_text("%d" % desks if desks > 1 else "")
327
+ self.perform.on_tele(t)
328
+ self.editor.on_tele(t)
329
+ self.prompt.on_tele(t)
@@ -0,0 +1,331 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """The desk's editor tab: change the song while it plays.
5
+
6
+ On the left, the song's form (tap a part to edit it), the part's step grid
7
+ and a pager for its bars. On the right, the song library, the kits of all
8
+ three kinds, and a mixer: the kit's volume and a fader for each group of
9
+ drums. The Pedals button swaps the mixer for the MIDI switches' map
10
+ (`pedals.Pedals`). Every change is an op or a command through the desk's panel, so it
11
+ reaches the sound at once and every other screen shows it.
12
+
13
+ While Follow is on, the grid shows whatever part plays and turns its bars
14
+ with it; picking a part turns Follow off.
15
+ """
16
+
17
+ import lvgl as lv
18
+
19
+ try:
20
+ from time import ticks_diff, ticks_ms
21
+ except ImportError:
22
+ from multimer import ticks_diff, ticks_ms
23
+
24
+ from . import look
25
+ from .. import parts as song
26
+ from ..floor import text_width
27
+ from .grid import Grid
28
+ from .pedals import Pedals
29
+ from .strip import Strip
30
+
31
+ SEND_MS = 60 # a moving fader sends at most this often
32
+ FADERS = ("volume", "kick", "snare", "hats", "toms", "cymbals", "perc")
33
+ # The faders' names, longest first: the first set whose names all keep
34
+ # FADER_GAP pixels apart under their faders is the one shown.
35
+ FADER_NAMES = (("VOL", "KICK", "SNARE", "HATS", "TOMS", "CYM", "PERC"),
36
+ ("VOL", "KCK", "SNR", "HAT", "TOM", "CYM", "PRC"),
37
+ ("VOL", "BD", "SD", "HH", "TOM", "CY", "PRC"))
38
+ FADER_GAP = 6
39
+
40
+
41
+ def fader_names(slot, fnt):
42
+ """The first of `FADER_NAMES` whose names, each centred in a ``slot``
43
+ pixels wide, keep `FADER_GAP` apart in ``fnt``; else the shortest."""
44
+ for names in FADER_NAMES:
45
+ widths = [text_width(n, fnt) for n in names]
46
+ if max(widths) <= slot and all(slot - (a + b) // 2 >= FADER_GAP for a, b in zip(widths, widths[1:])):
47
+ return names
48
+ return FADER_NAMES[-1]
49
+
50
+
51
+ class Editor:
52
+ """The editor in ``parent`` at ``(x, y)``, ``w`` by ``h``, for ``desk``."""
53
+
54
+ def __init__(self, parent, x, y, w, h, desk):
55
+ self.desk = desk
56
+ s = desk.scale
57
+ m = desk.m
58
+ self.base = look.plain(lv.obj(parent))
59
+ self.base.set_pos(int(x), int(y))
60
+ self.base.set_size(int(w), int(h))
61
+ f = desk.fonts
62
+ rw = int(w * 0.3)
63
+ lw = int(w) - rw - 3 * m
64
+ self.follow = True
65
+ self.block = -1
66
+ self.pattern = -1
67
+ self.bar = 0
68
+ self.bars = 1
69
+ self.cols, self.ticks = 16, song.BAR // 16
70
+ self.voices = []
71
+ self.blocks = []
72
+ self.sent = {}
73
+
74
+ # -- left: the form, the toolbar, the grid --
75
+ sh = int(56 * s)
76
+ self.strip = Strip(self.base, m, m, lw, sh, f["small"], on_pick=self._pick)
77
+ ty = m + sh + m
78
+ th = int(36 * s)
79
+ bar = look.box(self.base, m, ty, lw, th, look.PANEL, 8, look.LINE)
80
+ self.part = look.text(bar, "", f["body"], look.AMBER, int(lw * 0.3))
81
+ self.part.align(lv.ALIGN.LEFT_MID, 10, 0)
82
+ self.info = look.text(bar, "", f["small"], look.DIM, int(lw * 0.22))
83
+ self.info.align(lv.ALIGN.LEFT_MID, int(lw * 0.3) + 14, 0)
84
+ bw = int(th * 1.1)
85
+ fx = lw - int(84 * s) - 4
86
+ self.follow_btn = look.button(bar, fx, 3, int(84 * s), th - 8, "FOLLOW", fnt=f["small"],
87
+ on_click=self._toggle_follow, radius=6)
88
+ look.select(self.follow_btn, True)
89
+ nx = fx - 8 - bw
90
+ self.next_btn = look.button(bar, nx, 3, bw, th - 8, icon="chevron_right", on_click=lambda: self._page(1),
91
+ radius=6)
92
+ self.page = look.text(bar, "", f["small"], look.TEXT, int(78 * s), lv.TEXT_ALIGN.CENTER)
93
+ self.page.set_pos(nx - int(80 * s), (th - 2 - f["small"].line_height) // 2)
94
+ self.prev_btn = look.button(bar, nx - int(82 * s) - bw, 3, bw, th - 8, icon="chevron_left",
95
+ on_click=lambda: self._page(-1), radius=6)
96
+ gy = ty + th + m
97
+ self.grid = Grid(self.base, m, gy, lw, int(h) - gy - m, f["small"], self._tap)
98
+
99
+ # -- right: songs, kits, mixer --
100
+ rx = lw + 2 * m
101
+ y = m
102
+ look.heading(self.base, "Song", f["small"], rx, y, "songs")
103
+ y += f["small"].line_height + 4
104
+ dh = int(38 * s)
105
+ self.songs = look.dropdown(self.base, rx, y, rw, dh, f["body"], self._song)
106
+ y += dh + m
107
+ look.heading(self.base, "Kit", f["small"], rx, y)
108
+ y += f["small"].line_height + 4
109
+ kh = int((int(h) - y) * 0.42)
110
+ self.kits = look.box(self.base, rx, y, rw, kh, look.PANEL, 8, look.LINE)
111
+ self.kits_w = rw
112
+ self.kits.add_flag(lv.obj.FLAG.SCROLLABLE)
113
+ self.kits.set_scroll_dir(lv.DIR.VER)
114
+ self.kit_buttons = {}
115
+ self.kit_list = None
116
+ y += kh + m
117
+ self.mix_heading = look.heading(self.base, "Mixer", f["small"], rx, y)
118
+ pw = int(70 * s)
119
+ self.pedals_btn = look.button(self.base, rx + rw - pw, y - 3, pw, f["small"].line_height + 4, "PEDALS",
120
+ fnt=f["small"], on_click=self._toggle_pedals, radius=4)
121
+ y += f["small"].line_height + 4
122
+ mh = int(h) - y - m
123
+ mixer = look.box(self.base, rx, y, rw, mh, look.PANEL, 8, look.LINE)
124
+ self.mixer = mixer
125
+ self.pedals = Pedals(self.base, rx, y, rw, mh, desk)
126
+ self.pedals.base.add_flag(lv.obj.FLAG.HIDDEN)
127
+ self.faders = {}
128
+ self.fader_labels = []
129
+ n = len(FADERS)
130
+ slot = (rw - 8) // n
131
+ self.fader_names = names = fader_names(slot, f["small"])
132
+ track = int(12 * s)
133
+ knob = track + 2 * max(2, track // 3) # the knob stands out past the track
134
+ top = knob // 2 + 6
135
+ fh = mh - f["small"].line_height - 12 - knob // 2 - top
136
+ for i, key in enumerate(FADERS):
137
+ fx = 4 + i * slot + (slot - track) // 2
138
+ lo, hi = (0, 127) if key == "volume" else (0, 100)
139
+ fd = look.slider(mixer, fx, top, track, fh, lo, hi, self._fader(key))
140
+ fd.add_event_cb(self._fader(key, True), lv.EVENT.RELEASED, None)
141
+ lbl = look.text(mixer, names[i], f["small"], look.DIM, slot, lv.TEXT_ALIGN.CENTER)
142
+ lbl.set_pos(4 + i * slot, mh - f["small"].line_height - 8)
143
+ self.faders[key] = fd
144
+ self.fader_labels.append(lbl)
145
+
146
+ # -- what the editor sends --
147
+
148
+ def _tap(self, pitch, step):
149
+ panel = self.desk.panel
150
+ if panel is None or panel.doc is None or self.pattern < 0:
151
+ return
152
+ op, path, value = song.tap(panel.doc, self.pattern, pitch, step, self.ticks)
153
+ panel.send(op, path, value)
154
+ self.show_cells()
155
+
156
+ def _fader(self, key, final=False):
157
+ path = "/tracks/0/volume" if key == "volume" else "/tracks/0/mix/" + key
158
+
159
+ def on_change(value):
160
+ panel = self.desk.panel
161
+ if panel is None or panel.doc is None:
162
+ return
163
+ if not isinstance(value, int):
164
+ value = self.faders[key].get_value()
165
+ now = ticks_ms()
166
+ if not final and ticks_diff(now, self.sent.get(key, now - SEND_MS)) < SEND_MS:
167
+ return
168
+ self.sent[key] = now
169
+ panel.set(path, value)
170
+
171
+ return on_change
172
+
173
+ def _song(self, index):
174
+ self.desk.command("song", index=index)
175
+
176
+ def _kit(self, spec):
177
+ def on_click(_e):
178
+ self.desk.command("kit", spec=spec)
179
+
180
+ return on_click
181
+
182
+ def _pick(self, i):
183
+ self.follow = False
184
+ look.select(self.follow_btn, False)
185
+ self.show_block(i, 0)
186
+
187
+ def _toggle_pedals(self):
188
+ """Show the pedals' map in the mixer's place, or the mixer again."""
189
+ on = self.mixer.has_flag(lv.obj.FLAG.HIDDEN)
190
+ hide, show = (self.pedals.base, self.mixer) if on else (self.mixer, self.pedals.base)
191
+ hide.add_flag(lv.obj.FLAG.HIDDEN)
192
+ show.remove_flag(lv.obj.FLAG.HIDDEN)
193
+ self.pedals_btn.get_child(0).set_text("PEDALS" if on else "MIXER")
194
+ self.mix_heading.set_text("MIXER" if on else "PEDALS")
195
+
196
+ def _toggle_follow(self):
197
+ self.follow = not self.follow
198
+ look.select(self.follow_btn, self.follow)
199
+
200
+ def _page(self, step):
201
+ self.follow = False
202
+ look.select(self.follow_btn, False)
203
+ self.bar = (self.bar + step) % max(1, self.bars)
204
+ self.grid.bar = self.bar
205
+ self.show_page()
206
+ self.show_cells()
207
+
208
+ # -- what it shows --
209
+
210
+ def show_block(self, i, bar):
211
+ if not 0 <= i < len(self.blocks):
212
+ return
213
+ b = self.blocks[i]
214
+ self.block = i
215
+ self.pattern = b["pattern"]
216
+ self.bars = b["bars"]
217
+ self.bar = bar % self.bars
218
+ self.grid.bar = self.bar
219
+ self.strip.pick(i)
220
+ self.part.set_text(b["label"].upper())
221
+ self.part.set_style_text_color(look.color(look.ROLE_COLORS.get(b["role"], look.AMBER)), 0)
222
+ self.info.set_text("%d BAR%s" % (self.bars, "" if self.bars == 1 else "S"))
223
+ self.show_page()
224
+ self.show_cells()
225
+
226
+ def show_page(self):
227
+ self.page.set_text("BAR %d / %d" % (self.bar + 1, self.bars))
228
+
229
+ def show_cells(self):
230
+ doc = self.desk.panel.doc if self.desk.panel is not None else None
231
+ if doc is None or self.pattern < 0:
232
+ return
233
+ pat = doc["tracks"][0]["patterns"][self.pattern]
234
+ self.grid.show(song.levels(pat, [p for p, _n in self.grid.rows], self.ticks))
235
+
236
+ def rebuild(self, doc, voices):
237
+ """Lay the grid out again for the song's meter and the kit's drums."""
238
+ self.voices = voices
239
+ self.cols, self.ticks = song.columns(doc)
240
+ rows = song.rows(voices, doc)
241
+ beat = song.beat_columns(doc)
242
+ g = self.grid
243
+ if (rows, self.cols, beat) != (g.rows, g.cols, g.beat) or g.head is None:
244
+ g.build(rows, self.cols, beat) # the same grid is only lit again
245
+ g.bar = self.bar
246
+ self.show_cells()
247
+
248
+ def on_doc(self, doc, desc):
249
+ self.blocks = song.blocks(doc)
250
+ self.strip.set_blocks(self.blocks)
251
+ names = desc.get("titles") or [doc.get("name", "")]
252
+ self.songs.set_options("\n".join(names))
253
+ self.set_kits(desc.get("kit_list") or [], desc.get("kit"))
254
+ self.rebuild(doc, desc.get("voices") or [])
255
+ keep = self.block if 0 <= self.block < len(self.blocks) else 0
256
+ self.show_block(keep, self.bar)
257
+ self.show_mix(doc)
258
+ self.pedals.on_map(desc.get("pedals"))
259
+
260
+ def set_kits(self, kit_list, current):
261
+ if kit_list == self.kit_list:
262
+ self.show_kit(current)
263
+ return
264
+ self.kit_list = kit_list
265
+ box = self.kits
266
+ box.clean()
267
+ self.kit_buttons = {}
268
+ f = self.desk.fonts
269
+ s = self.desk.scale
270
+ w = self.kits_w - 14
271
+ y = 6
272
+ bh = int(30 * s)
273
+ for source, title in (("soundfont", "SoundFont"), ("machine", "Drum machines")):
274
+ look.heading(box, title, f["small"], 6, y)
275
+ y += f["small"].line_height + 4
276
+ for k in [k for k in kit_list if k["source"] == source]:
277
+ b = look.button(box, 6, y, w, bh, k["name"], fnt=f["small"], radius=6)
278
+ b.add_event_cb(self._kit(k["spec"]), lv.EVENT.CLICKED, None)
279
+ self.kit_buttons[k["spec"]] = b
280
+ y += bh + 4
281
+ y += 4
282
+ self.show_kit(current)
283
+
284
+ def show_kit(self, spec):
285
+ for k, b in self.kit_buttons.items():
286
+ look.select(b, k == spec)
287
+
288
+ def show_mix(self, doc):
289
+ track = doc["tracks"][0]
290
+ mix = track.get("mix") or {}
291
+ for key, fd in self.faders.items():
292
+ v = track.get("volume", 100) if key == "volume" else mix.get(key, 100)
293
+ if fd.get_value() != v and not fd.has_state(lv.STATE.PRESSED):
294
+ fd.set_value(int(v), False)
295
+
296
+ def on_op(self, op):
297
+ path = op.get("path", "")
298
+ doc = self.desk.panel.doc
299
+ if path.startswith("/tracks/0/patterns/%d/" % self.pattern):
300
+ self.show_cells()
301
+ if path.startswith("/tracks/0/mix") or path == "/tracks/0/volume":
302
+ self.show_mix(doc)
303
+ if path.startswith("/parts") or path.endswith("/bars"):
304
+ self.blocks = song.blocks(doc)
305
+ self.strip.set_blocks(self.blocks)
306
+ self.show_block(min(self.block, len(self.blocks) - 1), self.bar)
307
+
308
+ def on_event(self, ev):
309
+ if ev.get("name") == "pedals":
310
+ self.pedals.on_map(ev)
311
+ if ev.get("name") in ("kit", "song") and "voices" in ev:
312
+ doc = self.desk.panel.doc
313
+ self.show_kit(ev.get("spec", ev.get("kit")))
314
+ if doc is not None:
315
+ self.rebuild(doc, ev["voices"])
316
+
317
+ def on_tele(self, t):
318
+ self.strip.show(t)
319
+ index = t.get("song_index")
320
+ if index is not None and index >= 0 and index != self.songs.get_selected() and not self.songs.is_open():
321
+ self.songs.set_selected(index)
322
+ playing = t.get("playing")
323
+ if playing and self.follow:
324
+ i = song.find(self.blocks, t.get("role"), t.get("number"))
325
+ want_bar = t.get("at", 0) // song.BAR
326
+ if i >= 0 and (i != self.block or want_bar != self.bar):
327
+ self.show_block(i, want_bar)
328
+ if playing and t.get("pattern") == self.pattern and t.get("at", 0) // song.BAR == self.bar:
329
+ self.grid.playhead(int(t.get("at", 0) % song.BAR) // self.ticks)
330
+ else:
331
+ self.grid.playhead(-1)