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
apps/backline/art.py ADDED
@@ -0,0 +1,717 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """The floor view's vector art, drawn once per screen size by svgio.
5
+
6
+ Each piece is a small SVG document: the panel behind everything, a lit
7
+ segment of the beat ring for each beat, seven-segment digits for the beat
8
+ and the tempo, and the glow of a pedal's lamp. `Picture` draws one into a
9
+ buffer and shows it as an LVGL image, so a beat costs LVGL an image shown
10
+ and one hidden, never a redraw of the art. A piece with see-through parts is
11
+ RGB565A8, three bytes a pixel; the panel covers the screen, so it is RGB565,
12
+ two, and drawn in bands (`bands`) so no one picture needs a big block.
13
+
14
+ The shapes keep to what every svgio draws the same way: paths, circles,
15
+ rectangles, lines, and linear and radial gradients with their stops'
16
+ opacity.
17
+ """
18
+
19
+ import math
20
+
21
+ import lvgl as lv
22
+ import svgio
23
+
24
+ try:
25
+ from time import ticks_add, ticks_diff, ticks_ms
26
+ except ImportError:
27
+ from multimer import ticks_add, ticks_diff, ticks_ms
28
+
29
+ #: What a view says when it's asked for the other view while a song plays,
30
+ #: longest first: the views change only while the song is stopped.
31
+ STOP_TO_SWITCH = ("STOP TO SWITCH VIEWS", "STOP TO SWITCH", "STOP FIRST")
32
+ #: How long it says it.
33
+ SAY_MS = 2000
34
+ #: How bright a control that won't act while the song plays is.
35
+ DIM_OPA = 90
36
+
37
+ _HEAD = '<svg xmlns="http://www.w3.org/2000/svg" width="%d" height="%d" viewBox="0 0 %d %d">'
38
+
39
+ #: The colour each part lights the face in.
40
+ ROLE_COLORS = {
41
+ "stopped": 0x7A8698,
42
+ "intro": 0x4CC9F0,
43
+ "main": 0xFFB703,
44
+ "fill": 0xFF6B1A,
45
+ "transition": 0xB28DFF,
46
+ "outro": 0xFF4D6D,
47
+ "end": 0x7A8698,
48
+ }
49
+ AMBER = 0xFFB703
50
+ GLASS = 0x05070B
51
+ TEMPO_DIGITS = "0123456789 " # the tempo's digits: a blank where it has fewer than three
52
+
53
+ # Which of the seven segments each digit lights: a top, b upper right,
54
+ # c lower right, d bottom, e lower left, f upper left, g middle.
55
+ SEGMENTS = {
56
+ "0": "abcdef", "1": "bc", "2": "abged", "3": "abgcd", "4": "fgbc", "5": "afgcd",
57
+ "6": "afgedc", "7": "abc", "8": "abcdefg", "9": "abcdfg", "-": "g", " ": "",
58
+ }
59
+
60
+
61
+ def hexcolor(rgb):
62
+ return "#%06x" % rgb
63
+
64
+
65
+ def mix(a, b, t):
66
+ """The colour ``t`` of the way from ``a`` to ``b``, each 0xRRGGBB."""
67
+ out = 0
68
+ for shift in (16, 8, 0):
69
+ ca = (a >> shift) & 255
70
+ cb = (b >> shift) & 255
71
+ out |= int(ca + (cb - ca) * t + 0.5) << shift
72
+ return out
73
+
74
+
75
+ #: What `pause` runs: set by `between` while a view switch draws.
76
+ _between = [None]
77
+
78
+
79
+ def between(fn):
80
+ """Run ``fn()`` at each `pause` from now on, or nothing with None.
81
+ Returns what ran before, to put back after.
82
+
83
+ A view switch made from a tap runs inside a timer callback, so the app's
84
+ other timers wait for it. The app passes the function that sequences
85
+ the song's notes here for the length of a switch, so the notes due
86
+ keep playing between one picture and the next."""
87
+ old = _between[0]
88
+ _between[0] = fn
89
+ return old
90
+
91
+
92
+ def pause():
93
+ """A point between two steps of drawing where `between`'s function runs."""
94
+ fn = _between[0]
95
+ if fn is not None:
96
+ fn()
97
+
98
+
99
+ def redraws(fn):
100
+ """Run ``fn()`` each time LVGL starts sending a piece of the screen to
101
+ the display; returns a function that stops it.
102
+
103
+ LVGL draws the screen in one step of its timer, and the app's other
104
+ timers wait for it: a view drawn whole after a switch took a tenth of a
105
+ second on a 720x720 board. It sends the screen a piece at a time, so
106
+ the app passes the function that sequences the song's notes here, and
107
+ they keep their time between the pieces."""
108
+ disp = lv.display_get_default()
109
+ run = [fn]
110
+
111
+ def on_flush(_event):
112
+ if run[0] is not None:
113
+ run[0]()
114
+
115
+ dsc = disp.add_event_cb(on_flush, lv.EVENT.FLUSH_START, None)
116
+
117
+ def stop():
118
+ run[0] = None
119
+ # Where the binding hands back the same event, it comes off the
120
+ # display; where it doesn't (CPython's), it stays and runs nothing.
121
+ for i in range(disp.get_event_count() - 1, -1, -1):
122
+ if disp.get_event_dsc(i) == dsc:
123
+ disp.remove_event(i)
124
+ return
125
+
126
+ return stop
127
+
128
+
129
+ def until(ms):
130
+ """The time ``ms`` from now, for `before`."""
131
+ return ticks_add(ticks_ms(), ms)
132
+
133
+
134
+ def before(t):
135
+ """True until time ``t`` (from `until`); False for None."""
136
+ return t is not None and ticks_diff(t, ticks_ms()) > 0
137
+
138
+
139
+ def image(parent, x, y, w, h):
140
+ """An LVGL image ``w`` by ``h`` at ``(x, y)`` in ``parent``, showing
141
+ nothing until it is given a `Picture`'s ``dsc``."""
142
+ img = lv.image(parent)
143
+ img.set_size(w, h)
144
+ img.set_pos(x, y)
145
+ img.remove_flag(lv.obj.FLAG.CLICKABLE)
146
+ img.remove_flag(lv.obj.FLAG.SCROLLABLE)
147
+ return img
148
+
149
+
150
+ class Picture:
151
+ """An SVG drawn into a buffer, and the LVGL image that shows it.
152
+
153
+ ``svg`` is its text, as a str or bytes-like. With ``alpha`` (the default)
154
+ the buffer is RGB565A8, so what's behind shows through; without, it is
155
+ RGB565, a third smaller, for art that covers its whole box. Pictures
156
+ drawn together can share a ``decoder`` (`decoder`), which saves the heap
157
+ a parse's worth of small blocks each.
158
+ """
159
+
160
+ def __init__(self, parent, svg, width, height, x=0, y=0, alpha=True, decoder=None):
161
+ own = decoder is None
162
+ if own:
163
+ decoder = svgio.SvgDecoder()
164
+ if isinstance(svg, str):
165
+ svg = svg.encode()
166
+ w, h = decoder.open(svg, width=width)
167
+ if (w, h) != (width, height):
168
+ raise ValueError("art drew at %dx%d, not %dx%d" % (w, h, width, height))
169
+ pause() # reading the text and drawing it are a step each
170
+ size = w * h * (3 if alpha else 2)
171
+ self.data = bytearray(size)
172
+ if alpha:
173
+ planes = memoryview(self.data)
174
+ decoder.decode(planes[: w * h * 2], planes[w * h * 2:])
175
+ else:
176
+ decoder.decode(self.data)
177
+ if own and hasattr(decoder, "close"):
178
+ decoder.close()
179
+ pause()
180
+ dsc = lv.image_dsc_t()
181
+ dsc.header.magic = lv.IMAGE_HEADER_MAGIC
182
+ dsc.header.cf = lv.COLOR_FORMAT.RGB565A8 if alpha else lv.COLOR_FORMAT.RGB565
183
+ dsc.header.w = w
184
+ dsc.header.h = h
185
+ dsc.header.stride = w * 2
186
+ dsc.data_size = size
187
+ dsc.data = self.data
188
+ self.dsc = dsc
189
+ self.image = None
190
+ if parent is not None:
191
+ self.image = self.show(parent, x, y)
192
+
193
+ def show(self, parent, x=0, y=0):
194
+ """Another LVGL image of the same pixels, at ``(x, y)`` in ``parent``."""
195
+ header = self.dsc.header
196
+ img = image(parent, x, y, header.w, header.h)
197
+ img.set_src(self.dsc)
198
+ return img
199
+
200
+ @property
201
+ def bytes(self):
202
+ return len(self.data)
203
+
204
+
205
+ #: The working memory a shared decoder (`decoder`) is made with: room for
206
+ #: the panel's parse, its thousands of small blocks. The few large ones a
207
+ #: draw takes spill over. On an ESP32 with PSRAM, and on a desktop, the
208
+ #: memory and what spills come from outside the heap.
209
+ DECODER_MEMORY = 96 * 1024
210
+
211
+
212
+ def decoder():
213
+ """An svgio decoder for many pictures in a row, one at a time.
214
+
215
+ A parse makes thousands of small blocks. On a board whose heap holds a
216
+ view's pictures, finding room for each one took longer than the drawing;
217
+ this decoder makes them in its own memory instead. `close` it when the
218
+ pictures are drawn.
219
+ """
220
+ return svgio.SvgDecoder(memory=DECODER_MEMORY)
221
+
222
+
223
+ BAND = 65536 # the most bytes a band of a screen-sized picture holds (`bands`)
224
+
225
+ _BAND_HEAD = '<svg xmlns="http://www.w3.org/2000/svg" width="%d" height="%d" viewBox="0 %d %d %d"'
226
+ #: The bytes a head gets in a `panel_text`: room for any band's, so a band
227
+ #: is drawn by writing its head over the whole picture's, in place.
228
+ HEAD_ROOM = len(_BAND_HEAD % (99999, 99999, 99999, 99999, 99999)) + 1
229
+
230
+
231
+ def _room_head(width, rows, y):
232
+ """The head of band ``rows`` high at ``y``, padded to `HEAD_ROOM` bytes."""
233
+ head = _BAND_HEAD % (width, rows, y, width, rows)
234
+ return (head + " " * (HEAD_ROOM - 1 - len(head)) + ">").encode()
235
+
236
+
237
+ def panel_text(svg, width, height):
238
+ """``svg``, which starts with its own size (`_HEAD`), as a bytearray
239
+ whose head has room for a band's (`HEAD_ROOM`), for `bands`."""
240
+ head = _HEAD % (width, height, width, height)
241
+ svg = svg.encode() if isinstance(svg, str) else bytes(svg)
242
+ if not svg.startswith(head.encode()):
243
+ raise ValueError("bands() takes an SVG that starts with its own size")
244
+ out = bytearray(HEAD_ROOM + len(svg) - len(head))
245
+ out[:HEAD_ROOM] = _room_head(width, height, 0)
246
+ out[HEAD_ROOM:] = memoryview(svg)[len(head):]
247
+ return out
248
+
249
+
250
+ def bands(parent, svg, width, height, decoder=None):
251
+ """``svg``, which covers its whole box, drawn as RGB565 pictures of a
252
+ band of rows each, top to bottom in ``parent``, none over `BAND` bytes.
253
+
254
+ A picture the size of the screen would need one free block that big,
255
+ and a heap a running app has left in pieces may have the bytes but no
256
+ such block. Each band is the same SVG with its view moved down, so the
257
+ bands are the picture drawn whole, a few pixels a step of rounding
258
+ apart.
259
+
260
+ ``svg`` is best a `panel_text`, or a writable view of one: each band's
261
+ head is then written over its head in place, and put back after, so the
262
+ bands copy no text.
263
+ """
264
+ if not (isinstance(svg, (bytearray, memoryview)) and bytes(svg[:HEAD_ROOM]) == _room_head(width, height, 0)):
265
+ svg = panel_text(svg, width, height)
266
+ step = max(1, BAND // (2 * width))
267
+ out = []
268
+ try:
269
+ for y in range(0, height, step):
270
+ rows = min(step, height - y)
271
+ svg[:HEAD_ROOM] = _room_head(width, rows, y)
272
+ out.append(Picture(parent, svg, width, rows, 0, y, alpha=False, decoder=decoder))
273
+ finally:
274
+ svg[:HEAD_ROOM] = _room_head(width, height, 0)
275
+ return out
276
+
277
+
278
+ def _arc(cx, cy, r, a0, a1):
279
+ """The points of an arc from angle ``a0`` to ``a1`` (degrees, clockwise from 3 o'clock)."""
280
+ p0 = (cx + r * math.cos(math.radians(a0)), cy + r * math.sin(math.radians(a0)))
281
+ p1 = (cx + r * math.cos(math.radians(a1)), cy + r * math.sin(math.radians(a1)))
282
+ return p0, p1
283
+
284
+
285
+ def _band(cx, cy, r_in, r_out, a0, a1):
286
+ """A closed path: the ring between two radii, from angle a0 to a1."""
287
+ (x0, y0), (x1, y1) = _arc(cx, cy, r_out, a0, a1)
288
+ (x2, y2), (x3, y3) = _arc(cx, cy, r_in, a1, a0)
289
+ big = 1 if a1 - a0 > 180 else 0
290
+ return ("M%.2f %.2fA%.2f %.2f 0 %d 1 %.2f %.2fL%.2f %.2fA%.2f %.2f 0 %d 0 %.2f %.2fZ"
291
+ % (x0, y0, r_out, r_out, big, x1, y1, x2, y2, r_in, r_in, big, x3, y3))
292
+
293
+
294
+ class Layout:
295
+ """Where everything goes at one screen size: computed, never measured."""
296
+
297
+ def __init__(self, w, h):
298
+ self.w, self.h = w, h
299
+ self.landscape = w >= h
300
+ m = max(6, int(min(w, h) * 0.045))
301
+ self.m = m
302
+ if self.landscape:
303
+ d = min(h - 2 * m, int(w * 0.48))
304
+ self.ring = (m, (h - d) // 2, d)
305
+ x0 = m + d + 2 * m
306
+ self.col = (x0, m, w - x0 - m, h - 2 * m)
307
+ else:
308
+ d = min(w - 2 * m, int(h * 0.5))
309
+ self.ring = ((w - d) // 2, m, d)
310
+ y0 = m + d + m
311
+ self.col = (m, y0, w - 2 * m, h - y0 - m)
312
+ x, y, d = self.ring
313
+ self.cx = x + d / 2.0
314
+ self.cy = y + d / 2.0
315
+ self.r = d / 2.0
316
+ cx, cy, cw, ch = self.col
317
+ # The column beside the ring, top to bottom: the song, the part's
318
+ # window, the next-up chip, the tempo, the kit, the pedals.
319
+ unit = ch / 100.0
320
+ self.song_y = cy
321
+ self.window = (cx, int(cy + 10 * unit), cw, int(23 * unit))
322
+ self.chip_y = int(cy + 37 * unit)
323
+ self.chip_h = max(18, int(10 * unit))
324
+ self.tempo = (cx, int(cy + 52 * unit), int(cw * 0.6), int(18 * unit))
325
+ self.kit_y = int(cy + 73 * unit)
326
+ self.pedal_r = max(10, int(min(9 * unit, cw / 6.0)))
327
+ self.pedal_y = int(cy + ch - self.pedal_r - max(2, self.pedal_r // 5))
328
+ self.pedal_x = (int(cx + self.pedal_r * 1.3), int(cx + cw - self.pedal_r * 1.3))
329
+ # The ring's bands, as fractions of its radius.
330
+ self.beat_in = 0.66 * self.r
331
+ self.beat_out = 0.84 * self.r
332
+ # Digits: the beat inside the ring, the tempo in its window.
333
+ self.big_h = int(self.r * 0.62)
334
+ self.big_w = int(self.big_h * 0.58)
335
+ tw = self.tempo[3] - 8
336
+ self.small_h = max(14, tw)
337
+ self.small_w = int(self.small_h * 0.58)
338
+ # Three digits and their gaps (`tempo_slots`) fit the window's width
339
+ # too, which on a square screen is the narrower side.
340
+ most = int((self.tempo[2] - 8) / 3.34)
341
+ if self.small_w > most:
342
+ self.small_w = most
343
+ self.small_h = int(most / 0.58)
344
+
345
+ def font(self, share):
346
+ """The largest built-in font no taller than ``share`` of the screen's height."""
347
+ return self.font_px(self.h * share)
348
+
349
+ def font_px(self, want):
350
+ """The largest built-in font no taller than ``want`` pixels (the smallest when none is)."""
351
+ best = None
352
+ for size in (14, 16, 24, 32, 40):
353
+ f = getattr(lv, "font_montserrat_%d" % size, None)
354
+ if f is not None and (best is None or size <= want):
355
+ best = f
356
+ return best or lv.font_get_default()
357
+
358
+
359
+ def panel_svg(lay, steps=4, group=1):
360
+ """Everything that never moves: the panel, the ring's housing and its dim
361
+ track of ``steps`` segments, the part window's glass, the tempo window
362
+ with its ghost digits, and the pedal lamps unlit.
363
+
364
+ It is three parts after the head: `panel_top` and `panel_bottom`, the
365
+ same for every meter, round `panel_ring`, the ticks and the track."""
366
+ return "".join((_HEAD % (lay.w, lay.h, lay.w, lay.h), panel_top(lay), panel_ring(lay, steps, group),
367
+ panel_bottom(lay)))
368
+
369
+
370
+ def panel_top(lay):
371
+ """The panel's gradients, its brushed face and the ring's housing."""
372
+ w, h = lay.w, lay.h
373
+ cx, cy, r = lay.cx, lay.cy, lay.r
374
+ out = ["<defs>"]
375
+ out.append('<linearGradient id="bg" x1="0" y1="0" x2="0" y2="1">'
376
+ '<stop offset="0" stop-color="#1a212d"/><stop offset="0.55" stop-color="#0d1118"/>'
377
+ '<stop offset="1" stop-color="#06080c"/></linearGradient>')
378
+ out.append('<radialGradient id="sheen" gradientUnits="userSpaceOnUse" cx="%.1f" cy="%.1f" r="%.1f">'
379
+ '<stop offset="0" stop-color="#3b4a63" stop-opacity="0.35"/>'
380
+ '<stop offset="1" stop-color="#3b4a63" stop-opacity="0"/></radialGradient>' % (w * 0.7, -h * 0.1, w * 0.7))
381
+ out.append('<linearGradient id="bezel" x1="0" y1="0" x2="0.3" y2="1">'
382
+ '<stop offset="0" stop-color="#5d6878"/><stop offset="0.45" stop-color="#252c37"/>'
383
+ '<stop offset="1" stop-color="#0b0e13"/></linearGradient>')
384
+ out.append('<linearGradient id="bezel2" x1="0" y1="1" x2="0.2" y2="0">'
385
+ '<stop offset="0" stop-color="#4a5466"/><stop offset="1" stop-color="#0c0f14"/></linearGradient>')
386
+ out.append('<radialGradient id="face" cx="0.4" cy="0.3" r="0.8">'
387
+ '<stop offset="0" stop-color="#1c2533"/><stop offset="1" stop-color="#05070a"/></radialGradient>')
388
+ out.append('<radialGradient id="hub" cx="0.5" cy="0.5" r="0.5">'
389
+ '<stop offset="0" stop-color="#ffb703" stop-opacity="0.10"/>'
390
+ '<stop offset="1" stop-color="#ffb703" stop-opacity="0"/></radialGradient>')
391
+ out.append('<linearGradient id="glass" x1="0" y1="0" x2="0" y2="1">'
392
+ '<stop offset="0" stop-color="#0d131c"/><stop offset="1" stop-color="#030406"/></linearGradient>')
393
+ out.append('<linearGradient id="gloss" x1="0" y1="0" x2="0" y2="1">'
394
+ '<stop offset="0" stop-color="#ffffff" stop-opacity="0.10"/>'
395
+ '<stop offset="1" stop-color="#ffffff" stop-opacity="0"/></linearGradient>')
396
+ out.append('<radialGradient id="lens" cx="0.4" cy="0.35" r="0.7">'
397
+ '<stop offset="0" stop-color="#2b3443"/><stop offset="1" stop-color="#07090d"/></radialGradient>')
398
+ out.append('<linearGradient id="chrome" x1="0" y1="0" x2="0" y2="1">'
399
+ '<stop offset="0" stop-color="#c9d2de"/><stop offset="0.5" stop-color="#4b5565"/>'
400
+ '<stop offset="1" stop-color="#1b2029"/></linearGradient>')
401
+ out.append("</defs>")
402
+ out.append('<rect width="%d" height="%d" fill="url(#bg)"/>' % (w, h))
403
+ out.append('<rect width="%d" height="%d" fill="url(#sheen)"/>' % (w, h))
404
+ # Fine horizontal lines across the panel, like brushed metal.
405
+ step = max(3, h // 80)
406
+ for y in range(0, h, step):
407
+ out.append('<line x1="0" y1="%d" x2="%d" y2="%d" stroke="#ffffff" stroke-opacity="0.018"/>' % (y, w, y))
408
+
409
+ # The ring's housing: a bezel, a groove, the face.
410
+ out.append('<circle cx="%.1f" cy="%.1f" r="%.1f" fill="#000000" fill-opacity="0.45"/>' % (cx + 2, cy + 4, r))
411
+ out.append('<circle cx="%.1f" cy="%.1f" r="%.1f" fill="url(#bezel)"/>' % (cx, cy, r))
412
+ out.append('<circle cx="%.1f" cy="%.1f" r="%.1f" fill="url(#bezel2)"/>' % (cx, cy, r * 0.955))
413
+ out.append('<circle cx="%.1f" cy="%.1f" r="%.1f" fill="url(#face)"/>' % (cx, cy, r * 0.93))
414
+ out.append('<circle cx="%.1f" cy="%.1f" r="%.1f" fill="url(#hub)"/>' % (cx, cy, r * 0.62))
415
+ return "".join(out)
416
+
417
+
418
+ def panel_ring(lay, steps=4, group=1):
419
+ """The ring's ticks and its dim track for a bar of ``steps``, ``group`` to a beat."""
420
+ cx, cy, r = lay.cx, lay.cy, lay.r
421
+ out = []
422
+ # Ticks outside the track, a beat's longer: sixteenths where a beat is
423
+ # one segment, else one tick a segment.
424
+ per = 4 if group == 1 else 1
425
+ ticks = steps * per
426
+ for i in range(ticks):
427
+ a = math.radians(-90 + i * 360.0 / ticks)
428
+ major = i % (per * group) == 0
429
+ r0 = r * 0.865
430
+ r1 = r * (0.915 if major else 0.893)
431
+ out.append('<line x1="%.2f" y1="%.2f" x2="%.2f" y2="%.2f" stroke="#c8d0dc" stroke-opacity="%.2f" '
432
+ 'stroke-width="%.1f" stroke-linecap="round"/>'
433
+ % (cx + r0 * math.cos(a), cy + r0 * math.sin(a), cx + r1 * math.cos(a), cy + r1 * math.sin(a),
434
+ 0.75 if major else 0.3, max(1.0, r / 60.0) * (1.6 if major else 1.0)))
435
+ # The dim track, a segment a step.
436
+ for b in range(steps):
437
+ a0, a1 = beat_span(b, steps, group)
438
+ out.append('<path d="%s" fill="#1d2430" stroke="#3a4555" stroke-opacity="0.8" stroke-width="1"/>'
439
+ % _band(cx, cy, lay.beat_in, lay.beat_out, a0, a1))
440
+ return "".join(out)
441
+
442
+
443
+ def panel_bottom(lay):
444
+ """The digit's hairline, the part and tempo windows and the pedal lamps unlit, and the end."""
445
+ cx, cy, r = lay.cx, lay.cy, lay.r
446
+ out = []
447
+ # An inner hairline round the digit.
448
+ out.append('<circle cx="%.1f" cy="%.1f" r="%.1f" fill="none" stroke="#ffffff" stroke-opacity="0.08" '
449
+ 'stroke-width="1"/>' % (cx, cy, r * 0.60))
450
+
451
+ # The part window: glass in a chrome rim.
452
+ x, y, ww, wh = lay.window
453
+ rad = max(4, wh // 6)
454
+ out.append('<rect x="%d" y="%d" width="%d" height="%d" rx="%d" fill="url(#chrome)"/>' % (x - 2, y - 2, ww + 4, wh + 4, rad + 2))
455
+ out.append('<rect x="%d" y="%d" width="%d" height="%d" rx="%d" fill="url(#glass)"/>' % (x, y, ww, wh, rad))
456
+ out.append('<rect x="%d" y="%d" width="%d" height="%d" rx="%d" fill="url(#gloss)"/>' % (x + 2, y + 2, ww - 4, wh // 2, rad))
457
+
458
+ # The tempo window, with dim eights behind the lit digits.
459
+ x, y, tw, th = lay.tempo
460
+ out.append('<rect x="%d" y="%d" width="%d" height="%d" rx="%d" fill="url(#chrome)"/>' % (x - 2, y - 2, tw + 4, th + 4, rad + 2))
461
+ out.append('<rect x="%d" y="%d" width="%d" height="%d" rx="%d" fill="url(#glass)"/>' % (x, y, tw, th, rad))
462
+ for i, dx in enumerate(tempo_slots(lay)):
463
+ out.append(_digit_paths("8", dx, y + (th - lay.small_h) // 2, lay.small_w, lay.small_h, 0x2A1E05, None))
464
+
465
+ # The pedal lamps, unlit.
466
+ for px in lay.pedal_x:
467
+ pr = lay.pedal_r
468
+ out.append('<circle cx="%d" cy="%d" r="%.1f" fill="url(#chrome)"/>' % (px, lay.pedal_y, pr + max(2, pr * 0.18)))
469
+ out.append('<circle cx="%d" cy="%d" r="%.1f" fill="url(#lens)"/>' % (px, lay.pedal_y, pr))
470
+ out.append("</svg>")
471
+ return "".join(out)
472
+
473
+
474
+ def beat_span(step, steps=4, group=1):
475
+ """The angles of ring segment ``step`` (from 0 at the top, clockwise) of
476
+ ``steps``, with a gap each side: a wide one where a beat starts or ends,
477
+ a narrow one between the steps of one beat (12/8's eighths, in threes)."""
478
+ size = 360.0 / steps
479
+ wide = min(5.0, size * 0.2)
480
+ narrow = min(2.0, size * 0.1)
481
+ a0 = -90 + step * size + (wide if step % group == 0 else narrow)
482
+ a1 = -90 + (step + 1) * size - (wide if (step + 1) % group == 0 else narrow)
483
+ return a0, a1
484
+
485
+
486
+ def segment_box(lay, step, steps=4, group=1):
487
+ """The box, in screen pixels, that holds a lit segment and its glow."""
488
+ pad = lay.r * 0.06
489
+ a0, a1 = beat_span(step, steps, group)
490
+ xs = []
491
+ ys = []
492
+ for k in range(9):
493
+ a = math.radians(a0 - 2 + (a1 - a0 + 4) * k / 8.0)
494
+ for rr in (lay.beat_in - pad, lay.beat_out + pad):
495
+ xs.append(lay.cx + rr * math.cos(a))
496
+ ys.append(lay.cy + rr * math.sin(a))
497
+ x0, y0 = int(min(xs)) - 1, int(min(ys)) - 1
498
+ x1, y1 = int(max(xs)) + 2, int(max(ys)) + 2
499
+ return x0, y0, x1 - x0, y1 - y0
500
+
501
+
502
+ def segment_svg(lay, step, steps=4, group=1, color=0xFFF4E0):
503
+ """Segment ``step``'s light: a bright band with a glow round it, in its
504
+ own box (`segment_box`), so it moves nothing else when shown."""
505
+ x0, y0, bw, bh = segment_box(lay, step, steps, group)
506
+ cx, cy = lay.cx - x0, lay.cy - y0
507
+ a0, a1 = beat_span(step, steps, group)
508
+ hot = hexcolor(color)
509
+ out = [_HEAD % (bw, bh, bw, bh), "<defs>"]
510
+ mid = (lay.beat_in + lay.beat_out) / 2
511
+ am = math.radians((a0 + a1) / 2)
512
+ out.append('<radialGradient id="lit" gradientUnits="userSpaceOnUse" cx="%.1f" cy="%.1f" r="%.1f">'
513
+ '<stop offset="0" stop-color="#ffffff"/><stop offset="0.6" stop-color="%s"/>'
514
+ '<stop offset="1" stop-color="%s"/></radialGradient>'
515
+ % (cx + mid * math.cos(am), cy + mid * math.sin(am), lay.r * 0.75, hot, hexcolor(mix(color, 0x000000, 0.35))))
516
+ out.append("</defs>")
517
+ pad = lay.r * 0.055
518
+ for k, opa in ((1.0, 0.10), (0.6, 0.16), (0.3, 0.24)):
519
+ out.append('<path d="%s" fill="%s" fill-opacity="%.2f"/>'
520
+ % (_band(cx, cy, lay.beat_in - pad * k, lay.beat_out + pad * k, a0 - 2 * k, a1 + 2 * k), hot, opa))
521
+ out.append('<path d="%s" fill="url(#lit)"/>' % _band(cx, cy, lay.beat_in, lay.beat_out, a0, a1))
522
+ # A bright line along the outer edge.
523
+ edge = lay.beat_out - max(1.0, lay.r * 0.012)
524
+ (ex0, ey0), (ex1, ey1) = _arc(cx, cy, edge, a0 + 1, a1 - 1)
525
+ out.append('<path d="M%.2f %.2fA%.2f %.2f 0 0 1 %.2f %.2f" fill="none" stroke="#ffffff" stroke-opacity="0.7" '
526
+ 'stroke-width="%.1f"/>' % (ex0, ey0, edge, edge, ex1, ey1, max(1.0, lay.r * 0.012)))
527
+ out.append("</svg>")
528
+ return "".join(out)
529
+
530
+
531
+ def _digit_paths(ch, x, y, w, h, color, glow):
532
+ """The lit segments of ``ch`` as SVG, its box at ``(x, y)``, ``w`` by ``h``."""
533
+ t = max(2.0, w * 0.17) # a segment's thickness
534
+ sl = w * 0.08 # the slant of an italic digit
535
+ g = t * 0.12 # the gap between segments
536
+ half = h / 2.0
537
+
538
+ def pt(px, py):
539
+ # Slant the digit: the top leans right.
540
+ return (x + px + sl * (1 - py / h), y + py)
541
+
542
+ def seg(horizontal, px, py, length):
543
+ if horizontal:
544
+ pts = [(px + g, py), (px + t / 2 + g, py - t / 2), (px + length - t / 2 - g, py - t / 2),
545
+ (px + length - g, py), (px + length - t / 2 - g, py + t / 2), (px + t / 2 + g, py + t / 2)]
546
+ else:
547
+ pts = [(px, py + g), (px + t / 2, py + t / 2 + g), (px + t / 2, py + length - t / 2 - g),
548
+ (px, py + length - g), (px - t / 2, py + length - t / 2 - g), (px - t / 2, py + t / 2 + g)]
549
+ pts = [pt(a, b) for a, b in pts]
550
+ return "M" + "L".join("%.2f %.2f" % p for p in pts) + "Z"
551
+
552
+ lit = SEGMENTS.get(ch, "")
553
+ if not lit:
554
+ return ""
555
+ inner = w - t
556
+ l, rr = t / 2, w - t / 2
557
+ top, bot = t / 2, h - t / 2
558
+ shapes = {
559
+ "a": (True, l, top, inner), "g": (True, l, half, inner), "d": (True, l, bot, inner),
560
+ "f": (False, l, top, half - top), "b": (False, rr, top, half - top),
561
+ "e": (False, l, half, bot - half), "c": (False, rr, half, bot - half),
562
+ }
563
+ d = "".join(seg(*shapes[s]) for s in lit) # only the lit ones are written
564
+ out = []
565
+ if glow is not None:
566
+ out.append('<path d="%s" fill="none" stroke="%s" stroke-opacity="0.22" stroke-width="%.1f" '
567
+ 'stroke-linejoin="round"/>' % (d, hexcolor(glow), t * 0.9))
568
+ out.append('<path d="%s" fill="%s"/>' % (d, hexcolor(color)))
569
+ return "".join(out)
570
+
571
+
572
+ def digit_svg(ch, w, h, color=AMBER):
573
+ """One seven-segment digit, lit, on nothing, with a soft glow: ``w`` by ``h``."""
574
+ pad = max(2, int(w * 0.12))
575
+ body = _digit_paths(ch, pad, pad, w - 2 * pad, h - 2 * pad, mix(color, 0xFFFFFF, 0.25), color)
576
+ return _HEAD % (w, h, w, h) + body + "</svg>"
577
+
578
+
579
+ def tempo_slots(lay):
580
+ """The x of each of the tempo window's three digits."""
581
+ x, _y, tw, _th = lay.tempo
582
+ span = 3 * lay.small_w + 2 * max(2, lay.small_w // 6)
583
+ x0 = x + (tw - span) // 2
584
+ return [x0 + i * (lay.small_w + max(2, lay.small_w // 6)) for i in range(3)]
585
+
586
+
587
+ def glow_svg(r, color):
588
+ """A pedal lamp lit: a hot centre fading to nothing at ``r``."""
589
+ s = int(2 * r)
590
+ c = s / 2.0
591
+ hot = hexcolor(color)
592
+ return (_HEAD % (s, s, s, s)
593
+ + '<defs><radialGradient id="g" cx="0.5" cy="0.5" r="0.5">'
594
+ '<stop offset="0" stop-color="#ffffff"/><stop offset="0.25" stop-color="%s"/>'
595
+ '<stop offset="0.6" stop-color="%s" stop-opacity="0.35"/>'
596
+ '<stop offset="1" stop-color="%s" stop-opacity="0"/></radialGradient></defs>'
597
+ '<circle cx="%.1f" cy="%.1f" r="%.1f" fill="url(#g)"/></svg>' % (hot, hot, hot, c, c, c))
598
+
599
+
600
+ def beat_digits(steps, group):
601
+ """The beat's digits a bar of ``steps``, ``group`` to a beat, shows: a
602
+ dash, and one to each of its beats."""
603
+ return "-123456789"[: 1 + min(9, steps // max(1, group))]
604
+
605
+
606
+ class Texts:
607
+ """The SVG text of one screen size's art (a `Layout`), written the first
608
+ time it is wanted and kept until the view goes.
609
+
610
+ A view that hides lets go of its pictures, and draws them again when it
611
+ shows. On a board, writing the text took longer than drawing it, so the
612
+ text is kept instead: under 50 KB a view, where its pixels are a
613
+ megabyte or more. It is kept end to end in one `svgio.Buffer`, which on
614
+ an ESP32 with PSRAM, and on a desktop, is outside the heap, so the heap
615
+ holds next to nothing more than before and the collector doesn't read
616
+ it. First what every meter shows (`face`), then the ring for one meter
617
+ (`ring`); another meter writes only the parts of it that change. A view
618
+ of the text it gives is good until the next call that writes some.
619
+ """
620
+
621
+ def __init__(self, lay):
622
+ self.lay = lay
623
+ self.meter = None
624
+ self._buf = None # the texts, end to end
625
+ self._ends = [] # where each ends: `face`'s, then `ring`'s
626
+ self._face = 0 # how many of them are `face`'s
627
+ self._ring_at = (0, 0) # where `panel_ring`'s part of the panel is
628
+
629
+ def _text(self, i):
630
+ """A writable view of text ``i``."""
631
+ ends = self._ends
632
+ return memoryview(self._buf)[ends[i - 1] if i else 0:ends[i]]
633
+
634
+ def _keep(self, face, ring):
635
+ """Keep ``face``'s texts and then ``ring``'s: one buffer for them all
636
+ in place of the one there was. A text is bytes-like, or a list of
637
+ pieces written end to end; a piece may be a view of the buffer there
638
+ was, which is read before it goes, so no text is copied on the heap."""
639
+ texts = face + ring
640
+ sizes = [sum(len(p) for p in t) if isinstance(t, list) else len(t) for t in texts]
641
+ buf = svgio.Buffer(sum(sizes))
642
+ view = memoryview(buf)
643
+ ends = [0] * len(texts)
644
+ at = 0
645
+ for i, t in enumerate(texts):
646
+ for p in t if isinstance(t, list) else (t,):
647
+ view[at:at + len(p)] = p
648
+ at += len(p)
649
+ ends[i] = at
650
+ view = None
651
+ old = self._buf
652
+ self._buf, self._ends, self._face = buf, ends, len(face)
653
+ if old is not None:
654
+ old.close()
655
+
656
+ def _texts(self, first, end):
657
+ return [self._text(i) for i in range(first, end)]
658
+
659
+ def face(self, glows):
660
+ """The tempo's digits, ``{ch: text}`` for each of `TEMPO_DIGITS`,
661
+ and a lit lamp's glow for each ``(radius, colour)`` of ``glows``
662
+ (`glow_svg`), in a list. They are written once: a view's lamps
663
+ don't change."""
664
+ glows = list(glows)
665
+ if not self._face:
666
+ lay = self.lay
667
+ face = [digit_svg(ch, lay.small_w, lay.small_h).encode() for ch in TEMPO_DIGITS]
668
+ face += [glow_svg(r, color).encode() for r, color in glows]
669
+ self._keep(face, self._texts(self._face, len(self._ends)))
670
+ n = len(TEMPO_DIGITS)
671
+ return {ch: self._text(i) for i, ch in enumerate(TEMPO_DIGITS)}, [self._text(n + i) for i in range(len(glows))]
672
+
673
+ def ring(self, steps, group):
674
+ """The panel, as a view of a `panel_text`, and each lit segment's
675
+ text, in a list, for a bar of ``steps``, ``group`` to a beat.
676
+ Another meter lets go of the last one's, and keeps the panel's
677
+ parts that don't change with it, and the beat's digits both show."""
678
+ first = self._face
679
+ if self.meter != (steps, group):
680
+ lay = self.lay
681
+ a, b = self._ring_at
682
+ digits = {}
683
+ if self.meter is None:
684
+ top = _room_head(lay.w, lay.h, 0) + panel_top(lay).encode()
685
+ bottom = panel_bottom(lay).encode()
686
+ else:
687
+ panel = self._text(first)
688
+ top, bottom = panel[:a], panel[b:]
689
+ panel = None
690
+ old_steps = self.meter[0]
691
+ for i, ch in enumerate(beat_digits(*self.meter)):
692
+ digits[ch] = self._text(first + 1 + old_steps + i)
693
+ self.meter = None
694
+ mid = panel_ring(lay, steps, group).encode()
695
+ self._ring_at = (len(top), len(top) + len(mid))
696
+ ring = [[top, mid, bottom]]
697
+ top = mid = bottom = None
698
+ ring += [segment_svg(lay, i, steps, group).encode() for i in range(steps)]
699
+ ring += [digits[ch] if ch in digits else digit_svg(ch, lay.big_w, lay.big_h).encode()
700
+ for ch in beat_digits(steps, group)]
701
+ digits = None
702
+ self._keep(self._texts(0, first), ring)
703
+ self.meter = (steps, group)
704
+ return self._text(first), [self._text(first + 1 + i) for i in range(steps)]
705
+
706
+ def big(self, ch):
707
+ """The beat's digit ``ch``, lit (`digit_svg`): kept with the ring
708
+ where its meter shows it, else written now."""
709
+ at = beat_digits(*self.meter).find(ch) if self.meter is not None else -1
710
+ if at < 0:
711
+ lay = self.lay
712
+ return digit_svg(ch, lay.big_w, lay.big_h).encode()
713
+ return self._text(self._face + 1 + self.meter[0] + at)
714
+
715
+ def bytes(self):
716
+ """The bytes of text kept."""
717
+ return len(self._buf) if self._buf is not None else 0