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,93 @@
1
+ Copyright 2011 The Montserrat Project Authors (https://github.com/JulietaUla/Montserrat)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ http://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,58 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """Backline: a drum machine you play with your feet.
5
+
6
+ Pick a song and tap the pedal: the intro plays, then the first groove.
7
+ While it plays, tap for a fill, hold to go through a transition to the
8
+ next groove, and tap twice to play the outro and stop. The second pedal's
9
+ tap plays a crash over the groove, and its hold stops at once. Every
10
+ change waits for the bar line, so the band never loses the one.
11
+
12
+ On a computer the space bar is pedal A and B is pedal B; Left and Right
13
+ choose the song while stopped, and K changes the kit. The two lamps on the
14
+ screen are pedals too. While a song plays, the status bar shows its part
15
+ and tempo; a tap there brings the floor view to the front.
16
+
17
+ On a screen of 640x400 or more, D (or the button in the corner) swaps the
18
+ floor view for the desk view (``desk/``): the same face larger with the
19
+ song's form, and an editor whose step grid, kits and mixer change the song
20
+ while it plays. Other screens join as desks on port 9300: a browser at
21
+ ``http://<box>:9300/``, or another computer with ``python -m
22
+ backline.desk_main HOST``. ``remote.py`` says how to change the port or turn it off.
23
+
24
+ The desk view can also go to a TV or a PC across the room, drawn at
25
+ 1280x720 and cast with castdisplay: set ``cast`` in the app's settings, or
26
+ ``$BACKLINE_CAST``, to ``windows:HOST`` (a PC's Wireless Display app) or
27
+ ``roku:HOST`` (a Roku's Screen mirroring). The sound stays on the box
28
+ (``cast.py``).
29
+
30
+ A MIDI foot controller can be the pedals, over USB, Bluetooth LE, a 5-pin
31
+ cable or a computer's MIDI ports: set ``midi_in`` in the app's settings, or
32
+ ``$BACKLINE_MIDI`` (``midipedal.open_input`` lists the choices). In the
33
+ desk view's editor, the Pedals button shows the four switches: tap one's
34
+ button and press the switch to learn it, then make it pedal A or B (it must
35
+ send a release: a momentary controller change or a note) or one action:
36
+ start, fill, next part, outro, stop or tap tempo. The map is kept in the
37
+ app's ``config.json`` (``midipedal.py``).
38
+
39
+ Songs are songmodel projects in the app's ``songs`` folder, eight styles
40
+ to start with. The desk's sparkle button asks for a new one in words ("a
41
+ slow 12-bar blues at 72, 4 times through, slowing in the outro") from any
42
+ OpenAI-compatible chat server, such as lite-assistant on your own network
43
+ or DeepInfra: set ``base_url``, ``key_file`` and ``chat_model`` in
44
+ ``settings.json`` in the app's data folder (``ask.py``). A song you keep is
45
+ saved in that folder's ``songs``. The songs play on Backline's own SoundFont
46
+ drum kit, fetched once when the app is installed or first started; the kit
47
+ list also has audioinstruments' drum machines and the drum kit of any other
48
+ SoundFont in a ``soundfonts`` folder (``kits.py`` says where it looks).
49
+
50
+ Each view draws from an hmilink panel on the box's own device, so any
51
+ other screen can join it the same way.
52
+ """
53
+
54
+
55
+ def main(scope):
56
+ from . import app
57
+
58
+ app.start(scope)
apps/backline/app.json ADDED
@@ -0,0 +1 @@
1
+ {"name": "backline", "title": "Backline", "category": "Audio", "icon": "queue_music", "color": "#B8860B", "needs": ["svgio", "icons"], "downloads": {"soundfonts/backline-drums.sf2": "https://github.com/PyDevices/lib/releases/download/backline-drums-1/backline-drums.sf2"}}
apps/backline/app.py ADDED
@@ -0,0 +1,475 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """Backline on a screen: the box, its audio output, the floor and desk views and the keys.
5
+
6
+ The package's ``main`` brings this in, so the engine, the kits and the
7
+ songs import without LVGL or an audio output.
8
+ """
9
+
10
+ import gc
11
+ import sys
12
+
13
+ try:
14
+ from time import ticks_diff, ticks_ms
15
+ except ImportError:
16
+ from multimer import ticks_diff, ticks_ms
17
+
18
+ import hmilink
19
+ from appkit import connections
20
+ from hmilink import local, tcp
21
+ from touchkit import ui
22
+
23
+ from . import art
24
+ from . import ask as askmod
25
+ from . import box as boxmod
26
+ from . import floor as floormod
27
+ from . import footswitch, glyphs, kits, midipedal, remote
28
+ from . import page_data
29
+
30
+ SERVICE_MS = 4 # the pedals and the notes due
31
+ UI_MS = 30 # the panel and the screen
32
+ CODEC_VOLUME = 85
33
+ DESKTOPS = ("win32", "linux", "darwin")
34
+ K_SPACE, K_B, K_D, K_K, K_TAB, K_LEFT, K_RIGHT = 32, 98, 100, 107, 9, 1073741904, 1073741903
35
+ DESK_SIZE = (640, 400) # the smallest screen that offers the desk view
36
+
37
+ state = None # for the console
38
+
39
+
40
+ def _clock(out):
41
+ """The frame the output renders next: the pump's count where it pumps,
42
+ else the frames a wall clock says have gone since the start."""
43
+ if getattr(out, "pumped", False):
44
+ import audiopump
45
+
46
+ return audiopump.now
47
+ start = ticks_ms()
48
+ rate = kits.RATE
49
+ return lambda: ticks_diff(ticks_ms(), start) * rate // 1000
50
+
51
+
52
+ def _cast(box, prefs):
53
+ """The desk view cast where the settings say (`remote.cast_target`), or
54
+ None. A cast that can't start says why on the box and the box plays on."""
55
+ try:
56
+ target = remote.cast_target(prefs)
57
+ if target is None:
58
+ return None
59
+ from . import cast
60
+
61
+ caster = cast.start(box.device, target)
62
+ box.cast = target.get("name") or target.get("host") or target["kind"]
63
+ return caster
64
+ except Exception as e: # noqa: BLE001 - said on the screen
65
+ box.error = "no cast: %s" % (e,)
66
+ return None
67
+
68
+
69
+ def _config(scope):
70
+ """The app's ``config.json`` (the MIDI input and the switches' map), or
71
+ an empty dict where there's no data folder."""
72
+ try:
73
+ from touchkit import settings
74
+
75
+ return settings.config(scope, {})
76
+ except Exception: # noqa: BLE001 - no data folder: start from the defaults
77
+ return {}
78
+
79
+
80
+ def _save_config(scope, config):
81
+ """Keep the map for the next start: learning a switch is rare, so it is
82
+ written when it changes."""
83
+ import json
84
+
85
+ try:
86
+ from appkit import data
87
+
88
+ with open(data.join(scope.data_dir, "config.json"), "w") as f:
89
+ json.dump(config, f)
90
+ except (OSError, AttributeError, ValueError, ImportError) as e:
91
+ print("backline: couldn't save the settings:", e)
92
+
93
+
94
+ def _midi_in(box, prefs, config):
95
+ """The MIDI input the switches come in on (`midipedal.open_input`), or
96
+ None. One that won't open says why on the box, and the box plays on."""
97
+ try:
98
+ return midipedal.open_input(spec=prefs.get("midi_in") or config.get("midi_in"))
99
+ except Exception as e: # noqa: BLE001 - said on the screen
100
+ box.error = "no MIDI in: %s" % (e,)
101
+ return None
102
+
103
+
104
+ def _switches(box, prefs, config, scope):
105
+ """The switches on pins the settings name (`footswitch.open_switches`),
106
+ and the function that gives BOOT back to the shell, or None.
107
+
108
+ BOOT goes home in the touch shell, so a box whose footswitch is BOOT
109
+ borrows it while it runs. A switch that won't open, or a shell that
110
+ can't lend BOOT, says why on the box, and the box plays on."""
111
+ named = {}
112
+ for key, _which in footswitch.KEYS:
113
+ named[key] = prefs.get(key) or config.get(key)
114
+ give_back = None
115
+ if "boot_button" in named.values():
116
+ shell = getattr(getattr(scope, "launcher", None), "shell", None)
117
+ if getattr(shell, "boot_pin", None) is not None:
118
+ lend = getattr(shell, "lend_boot", None)
119
+ if lend is None:
120
+ box.error = "no footswitch: BOOT goes home in this shell, which can't lend it"
121
+ return [], None
122
+ give_back = lend()
123
+ try:
124
+ return footswitch.open_switches(named, box.pedal), give_back
125
+ except Exception as e: # noqa: BLE001 - said on the screen
126
+ if give_back is not None:
127
+ give_back()
128
+ box.error = "no footswitch: %s" % (e,)
129
+ return [], None
130
+
131
+
132
+ class Views:
133
+ """The box's own screen: the floor view (``make_floor(on_switch)``), and
134
+ in its place the desk view, made the first time it's asked for by
135
+ ``make_desk(on_switch)``, or never where that is None (a screen under
136
+ `DESK_SIZE`). Each view's ``on_switch`` shows the other, and
137
+ ``on_show()``, when given, runs after either is shown. ``service()``,
138
+ when given, is the box's pass that sequences the song's notes.
139
+
140
+ The view going away lets go of its art first (``hide``) and the heap is
141
+ collected, so the one coming back draws into the room it left: the
142
+ screen holds one view's pictures, not both. On an 8 MB board at 800x480
143
+ both at once didn't fit.
144
+
145
+ While a switch draws, `switching` is True and `poll` does nothing, so
146
+ the app's timer can't read the panels into a view half drawn. A switch
147
+ made from a tap already runs inside a timer, which holds the others
148
+ off; one called from the console doesn't, and there a pass drew the
149
+ floor's ring out of turn and spent the switch's time on the panels.
150
+
151
+ A switch made from a tap holds off the app's other timers too, the
152
+ notes' among them, and on a board the floor took two seconds to draw:
153
+ the notes due in that time were skipped. So the switch runs `service`
154
+ itself between one picture and the next (`art.between`), and `poll`
155
+ between one panel and the next, and between the rows of a desk laid
156
+ out again for another song.
157
+
158
+ The view changes only while the song is stopped (``playing()`` is
159
+ False). Even with those passes, a switch on an ESP32-S31 still held the
160
+ notes up for half a second or more: a heap collection there takes a
161
+ third of a second, and a switch can't break one up.
162
+ """
163
+
164
+ def __init__(self, make_floor, make_desk=None, on_show=None, service=None, playing=None):
165
+ self.shown = "floor"
166
+ self.desk = None
167
+ self.switching = False
168
+ self._make_desk = make_desk
169
+ self._on_show = on_show
170
+ self._service = service
171
+ self._playing = playing
172
+ self.floor = make_floor(self._switch("desk") if make_desk is not None else None)
173
+
174
+ def _switch(self, which):
175
+ return lambda: self.show(which)
176
+
177
+ def show(self, which):
178
+ """Show ``"floor"`` or ``"desk"``; returns False, having shown
179
+ nothing, where it can't.
180
+
181
+ The view changes only while the song is stopped. A switch drew for
182
+ a second or more on a board, and the notes due while it drew were
183
+ skipped, so while a song plays the view showing says why it stays
184
+ (``refuse_switch``) instead."""
185
+ if which == "desk" and self._make_desk is None:
186
+ return False
187
+ if which != self.shown and self._playing is not None and self._playing():
188
+ view = self.desk if self.shown == "desk" else self.floor
189
+ if view is not None:
190
+ view.refuse_switch()
191
+ return False
192
+ self.switching = True
193
+ before = art.between(self._service)
194
+ try:
195
+ self.shown = which
196
+ hide = self.floor if which == "desk" else self.desk
197
+ if hide is not None:
198
+ hide.hide()
199
+ art.pause()
200
+ gc.collect()
201
+ art.pause()
202
+ if which == "desk" and self.desk is None:
203
+ self.desk = self._make_desk(self._switch("floor"))
204
+ (self.desk if which == "desk" else self.floor).show()
205
+ finally:
206
+ art.between(before)
207
+ self.switching = False
208
+ if self._on_show is not None:
209
+ self._on_show()
210
+ return True
211
+
212
+ def poll(self, box):
213
+ """One pass of the screen's work: the box's links, then each view's
214
+ panel. Returns False, having done nothing, while a switch draws."""
215
+ if self.switching:
216
+ return False
217
+ step = self._service or _nothing
218
+ box.poll()
219
+ step()
220
+ before = art.between(self._service) # a song change lays the desk out again
221
+ try:
222
+ self.floor.poll()
223
+ if self.desk is not None:
224
+ step()
225
+ self.desk.poll()
226
+ finally:
227
+ art.between(before)
228
+ return True
229
+
230
+
231
+ def _nothing():
232
+ pass
233
+
234
+
235
+ def start(scope):
236
+ global state
237
+ status = ui.status(scope)
238
+ W, H = scope.size
239
+ # The sound output chosen in the picker: a computer names its device, and
240
+ # a board's audio_out follows the choice itself.
241
+ sound = {"device": None, "playing": None}
242
+
243
+ def open_out():
244
+ from audiodev import AudioFormat
245
+
246
+ live = {"latency": "low"} if sys.platform in DESKTOPS else {}
247
+ if sound["device"] is not None:
248
+ live["device"] = sound["device"]
249
+ return bp.audio_out(AudioFormat(kits.RATE, kits.CHANNELS, 16), **live)
250
+
251
+ def moved(endpoints):
252
+ # Another output was chosen: the box's bus plays on it from here. The
253
+ # old output is let go first, since a board has one I2S port; one
254
+ # that won't open leaves the old device playing again.
255
+ before = sound["device"]
256
+ sound["device"] = connections.device(endpoints)
257
+ play = sound["playing"]
258
+ if play is None:
259
+ return
260
+ old = play["out"]
261
+ try:
262
+ old.stop()
263
+ except Exception: # noqa: BLE001
264
+ pass
265
+ old.detach()
266
+ old.close()
267
+ new = None
268
+ for device in (sound["device"], before):
269
+ sound["device"] = device
270
+ try:
271
+ new = open_out()
272
+ break
273
+ except Exception as e: # noqa: BLE001 - said on the screen
274
+ status.set_text("Can't play on that output: %s" % (e,))
275
+ if new is None:
276
+ sound["playing"] = None
277
+ return
278
+ new.attach(scope)
279
+ new.play(play["bus"], loop=True)
280
+ play["out"] = new
281
+ if state is not None:
282
+ state["out"] = new
283
+
284
+ sound["device"] = connections.device(scope.follow("audio.out", moved))
285
+ try:
286
+ import board_peripherals as bp
287
+
288
+ power = getattr(bp, "audio_power", None)
289
+ if power is not None:
290
+ power(True, volume=CODEC_VOLUME)
291
+ out = open_out()
292
+ except Exception as e: # noqa: BLE001 - said on the screen
293
+ ui.missing(scope, "no audio", "Backline needs an audio output: %s" % (e,))
294
+ return
295
+ prefs = scope.store()
296
+ config = _config(scope)
297
+ # The chat server a song is asked for from: settings.json in the app's
298
+ # data folder, as Huey keeps its own.
299
+ ask_settings, trouble = None, None
300
+ try:
301
+ data = scope.data_dir
302
+ kits.data_folder = data
303
+ ask_settings = askmod.load_settings(data + "/settings.json")
304
+ except (ValueError, AttributeError) as e:
305
+ data, trouble = None, "settings: %s" % (e,)
306
+ try:
307
+ box = boxmod.Box(_clock(out), song=prefs.get("song"), kit=prefs.get("kit"),
308
+ pedal_map=prefs.get("pedals") or config.get("pedals"), worker=getattr(scope, "worker", None),
309
+ ask_settings=ask_settings, user_songs=data + "/songs" if data else None)
310
+ box.error = box.error or trouble
311
+ except Exception as e: # noqa: BLE001
312
+ out.close()
313
+ ui.missing(scope, "can't start", "Backline: %s" % (e,))
314
+ return
315
+ out.attach(scope)
316
+ out.play(box.bus.output, loop=True)
317
+ sound["playing"] = {"out": out, "bus": box.bus.output}
318
+ listener = box.device.add(local.serve())
319
+ port = remote.listen_port(prefs)
320
+ if port:
321
+ try:
322
+ box.device.add(tcp.serve(port, page=page_data.page()))
323
+ except (OSError, ImportError) as e: # ImportError: no socket module (a browser)
324
+ box.error = "desks can't join on port %d: %s" % (port, e)
325
+ name = remote.ble_name(prefs, scope.data_dir)
326
+ if name:
327
+ try:
328
+ from hmilink import ble
329
+
330
+ box.device.add(ble.serve(name))
331
+ except Exception as e: # noqa: BLE001 - said on the screen
332
+ box.error = "no desks over Bluetooth: %s" % (e,)
333
+ panel = hmilink.Panel(local.connect(listener))
334
+ box.poll()
335
+ panel.poll()
336
+ caster = _cast(box, prefs)
337
+ box.midi_in = _midi_in(box, prefs, config)
338
+ box.switches, give_boot_back = _switches(box, prefs, config, scope)
339
+ kept = [box.midi.saved()]
340
+ can_desk = W >= DESK_SIZE[0] and H >= DESK_SIZE[1]
341
+ desk_panel = []
342
+ if can_desk:
343
+ # Read now, before a song can play: on a board, reading the desk's
344
+ # code took over a second the first switch to it couldn't break up.
345
+ from .desk import Desk
346
+
347
+ def make_desk(on_switch):
348
+ desk_panel.append(hmilink.Panel(local.connect(listener)))
349
+ box.poll()
350
+ desk_panel[0].poll()
351
+ art.pause()
352
+ return Desk(scope.root, (W, H), desk_panel[0], on_switch=on_switch)
353
+
354
+ def on_show():
355
+ if own_status:
356
+ status.move_foreground()
357
+
358
+ servicing = [False]
359
+
360
+ def service(_t=None):
361
+ # Also run from inside a switch or a UI pass (`Views`), where called
362
+ # from the console a timer's pass can land in the middle of it.
363
+ if servicing[0]:
364
+ return
365
+ servicing[0] = True
366
+ try:
367
+ box.service()
368
+ finally:
369
+ servicing[0] = False
370
+
371
+ stop_redraws = art.redraws(service)
372
+ views = Views(lambda on_switch: floormod.Floor(scope.root, (W, H), panel, on_switch=on_switch),
373
+ make_desk if can_desk else None, on_show, service,
374
+ lambda: box.engine.transport["playing"])
375
+ floor = views.floor
376
+ show = views.show
377
+ own_status = getattr(scope, "status", None) is None
378
+ if own_status:
379
+ status.move_foreground()
380
+ state = {"box": box, "floor": floor, "out": out, "views": views, "show": show, "cast": caster}
381
+ # On the status bar while a song plays: the part and the tempo. A tap
382
+ # brings the floor view back to the front.
383
+ bar = getattr(scope, "bar", None)
384
+ if bar is not None:
385
+ from appkit.bar import Item
386
+
387
+ bar.add(Item("backline", lambda: glyphs.bar_reading(box.telemetry()), on_click=lambda: show("floor")), scope)
388
+ held = set()
389
+
390
+ def tick(_t):
391
+ if not views.poll(box):
392
+ return
393
+ if caster is not None:
394
+ caster.step()
395
+ t = box.telemetry()
396
+ prefs["song"] = box.songs[box.song_index][0]
397
+ prefs["kit"] = box.engine.kit.spec if box.engine.kit is not None else None
398
+ pedals = box.midi.saved()
399
+ if pedals != kept[0]:
400
+ kept[0] = config["pedals"] = pedals
401
+ _save_config(scope, config)
402
+ prefs["pedals"] = pedals
403
+ # The shell's header has room for the song's place in the list; a
404
+ # label of the app's own, over the view, says only what went wrong.
405
+ status.set_text(t["error"] if own_status else
406
+ t["error"] or ("%s • %d of %d" % (t["song"], t["song_index"] + 1, t["songs"])
407
+ if t["song_index"] >= 0 else t["song"]))
408
+
409
+ def key_down(e):
410
+ k = getattr(e, "key", None)
411
+ if views.desk is not None and views.desk.typing():
412
+ return # the keys are words in the prompt, not pedals
413
+ if k in held:
414
+ return
415
+ held.add(k)
416
+ if k == K_SPACE:
417
+ floor.pedal(0, True)
418
+ elif k == K_B:
419
+ floor.pedal(1, True)
420
+ elif k == K_K:
421
+ panel.command("kit", step=1)
422
+ elif k in (K_D, K_TAB):
423
+ show("floor" if views.shown == "desk" else "desk")
424
+ elif k in (K_LEFT, K_RIGHT) and not box.engine.transport["playing"]:
425
+ panel.command("song", step=1 if k == K_RIGHT else -1)
426
+
427
+ def key_up(e):
428
+ k = getattr(e, "key", None)
429
+ if k not in held:
430
+ return # went down while the prompt had the keys
431
+ held.discard(k)
432
+ if k == K_SPACE:
433
+ floor.pedal(0, False)
434
+ elif k == K_B:
435
+ floor.pedal(1, False)
436
+
437
+ try:
438
+ import events
439
+
440
+ scope.on(events.KEYDOWN, key_down)
441
+ scope.on(events.KEYUP, key_up)
442
+ except ImportError:
443
+ pass
444
+
445
+ def close():
446
+ global state
447
+ state = None
448
+ stop_redraws()
449
+ play, sound["playing"] = sound["playing"], None
450
+ if play is not None: # None when a move found no output to reopen
451
+ out = play["out"]
452
+ try:
453
+ out.stop()
454
+ except Exception: # noqa: BLE001
455
+ pass
456
+ out.detach()
457
+ out.close()
458
+ panel.close()
459
+ if caster is not None:
460
+ caster.close()
461
+ for p in desk_panel:
462
+ p.close()
463
+ box.close() # after the output, so it never pulls a closed kit
464
+ if give_boot_back is not None:
465
+ give_boot_back()
466
+ try:
467
+ power = getattr(bp, "audio_power", None)
468
+ if power is not None:
469
+ power(False)
470
+ except Exception: # noqa: BLE001
471
+ pass
472
+
473
+ scope.on_close(close)
474
+ scope.every(SERVICE_MS, service)
475
+ scope.every(UI_MS, tick)