omnipython-apps 0.1.4.dev8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- apps/__init__.py +5 -0
- apps/about/__init__.py +257 -0
- apps/about/app.json +1 -0
- apps/about/credits.py +12 -0
- apps/about/facts.py +398 -0
- apps/about/fonts/OFL.txt +93 -0
- apps/about/fonts/latin1_14.bin +0 -0
- apps/about/fonts/latin1_16.bin +0 -0
- apps/about/fonts/latin1_24.bin +0 -0
- apps/about/fonts/latin1_32.bin +0 -0
- apps/about/fonts/latin1_40.bin +0 -0
- apps/backline/__init__.py +58 -0
- apps/backline/app.json +1 -0
- apps/backline/app.py +475 -0
- apps/backline/art.py +717 -0
- apps/backline/ask.py +781 -0
- apps/backline/box.py +502 -0
- apps/backline/cast.py +137 -0
- apps/backline/desk/__init__.py +329 -0
- apps/backline/desk/editor.py +331 -0
- apps/backline/desk/grid.py +154 -0
- apps/backline/desk/look.py +169 -0
- apps/backline/desk/pedals.py +102 -0
- apps/backline/desk/perform.py +157 -0
- apps/backline/desk/prompt.py +210 -0
- apps/backline/desk/strip.py +159 -0
- apps/backline/desk_main.py +226 -0
- apps/backline/engine.py +622 -0
- apps/backline/floor.py +509 -0
- apps/backline/footswitch.py +119 -0
- apps/backline/glyphs.py +82 -0
- apps/backline/kits.py +428 -0
- apps/backline/midipedal.py +362 -0
- apps/backline/page_data.py +413 -0
- apps/backline/parts.py +145 -0
- apps/backline/pedal.py +107 -0
- apps/backline/remote.py +134 -0
- apps/backline/songs/ballad_68.json +1 -0
- apps/backline/songs/bossa.json +1 -0
- apps/backline/songs/country_train.json +1 -0
- apps/backline/songs/funk.json +1 -0
- apps/backline/songs/metal.json +1 -0
- apps/backline/songs/pop.json +1 -0
- apps/backline/songs/rock.json +1 -0
- apps/backline/songs/shuffle.json +1 -0
- apps/battery/__init__.py +101 -0
- apps/battery/app.json +1 -0
- apps/bit_world/act_deck.py +683 -0
- apps/bit_world/act_game.py +762 -0
- apps/bit_world/act_pet.py +1032 -0
- apps/bit_world/app.json +1 -0
- apps/bit_world/bit_output.py +45 -0
- apps/bit_world/bit_palette.py +503 -0
- apps/bit_world/bit_sound.py +431 -0
- apps/bit_world/bit_sprites.py +632 -0
- apps/bit_world/bit_world.py +534 -0
- apps/btreceiver/__init__.py +690 -0
- apps/btreceiver/app.json +1 -0
- apps/btreceiver/chime.py +155 -0
- apps/btreceiver/demo.py +529 -0
- apps/btreceiver/screen.py +633 -0
- apps/camera/__init__.py +316 -0
- apps/camera/app.json +1 -0
- apps/card/__init__.py +113 -0
- apps/card/app.json +1 -0
- apps/cast/__init__.py +631 -0
- apps/cast/app.json +1 -0
- apps/cast/receivers.py +193 -0
- apps/chess/__init__.py +18 -0
- apps/chess/app.json +1 -0
- apps/chess/app.py +922 -0
- apps/chess/art.py +323 -0
- apps/chess/ble.py +411 -0
- apps/chess/engine.py +925 -0
- apps/chess/game.py +327 -0
- apps/chess/net.py +261 -0
- apps/clock/__init__.py +38 -0
- apps/clock/app.json +1 -0
- apps/detect/__init__.py +214 -0
- apps/detect/app.json +1 -0
- apps/fmsynth/__init__.py +41 -0
- apps/fmsynth/algorithms.py +61 -0
- apps/fmsynth/app.json +1 -0
- apps/fmsynth/app.py +355 -0
- apps/fmsynth/editor.py +206 -0
- apps/fmsynth/engine.py +257 -0
- apps/fmsynth/meters.py +262 -0
- apps/fmsynth/midi.py +375 -0
- apps/fmsynth/panel_view.py +1071 -0
- apps/fmsynth/patches/fmsynth-01.syx +0 -0
- apps/fmsynth/settings.py +138 -0
- apps/fmsynth/voice.py +398 -0
- apps/gamepad/__init__.py +685 -0
- apps/gamepad/app.json +1 -0
- apps/gamepad/pad.py +94 -0
- apps/gamepad/watch.py +352 -0
- apps/hidden/__init__.py +72 -0
- apps/hidden/app.json +1 -0
- apps/home/__init__.py +483 -0
- apps/home/app.json +1 -0
- apps/home/main.py +36 -0
- apps/homeassistant/__init__.py +213 -0
- apps/homeassistant/api.py +104 -0
- apps/homeassistant/app.json +1 -0
- apps/huey/__init__.py +287 -0
- apps/huey/acting.py +184 -0
- apps/huey/actor.py +194 -0
- apps/huey/app.json +1 -0
- apps/huey/client.py +125 -0
- apps/huey/servers.py +121 -0
- apps/huey/settings.example.json +8 -0
- apps/huey/settings.py +97 -0
- apps/huey/turn.py +504 -0
- apps/huey/voice.py +217 -0
- apps/info/__init__.py +810 -0
- apps/info/app.json +1 -0
- apps/lora/__init__.py +62 -0
- apps/lora/app.json +1 -0
- apps/manifest.py +71 -0
- apps/medialink_baby_monitor/__init__.py +222 -0
- apps/medialink_baby_monitor/app.json +1 -0
- apps/medialink_doorbell/__init__.py +251 -0
- apps/medialink_doorbell/app.json +1 -0
- apps/medialink_hands_free/__init__.py +217 -0
- apps/medialink_hands_free/app.json +1 -0
- apps/medialink_surveillance_camera/__init__.py +258 -0
- apps/medialink_surveillance_camera/app.json +1 -0
- apps/medialink_video_doorbell/__init__.py +289 -0
- apps/medialink_video_doorbell/app.json +1 -0
- apps/medialink_videophone/__init__.py +273 -0
- apps/medialink_videophone/app.json +1 -0
- apps/medialink_walkie_talkie/__init__.py +228 -0
- apps/medialink_walkie_talkie/app.json +1 -0
- apps/midicontroller/__init__.py +774 -0
- apps/midicontroller/app.json +1 -0
- apps/midicontroller/links.py +421 -0
- apps/midicontroller/surface.py +343 -0
- apps/midiengine/__init__.py +977 -0
- apps/midiengine/app.json +1 -0
- apps/midiengine/banks.py +85 -0
- apps/midiengine/midiin.py +165 -0
- apps/midiengine/player.py +392 -0
- apps/midiengine/umidiparser.py +1413 -0
- apps/mp3/__init__.py +240 -0
- apps/mp3/app.json +1 -0
- apps/perch/__init__.py +119 -0
- apps/perch/app.json +1 -0
- apps/perch/huey.py +481 -0
- apps/perch/huey_props.py +386 -0
- apps/perch/huey_shift.py +42 -0
- apps/perch/huey_views.py +296 -0
- apps/perch/scene_bench.py +680 -0
- apps/perch/scene_coast.py +479 -0
- apps/perch/scene_desk.py +492 -0
- apps/perch/stage.py +1274 -0
- apps/perch/vec.py +366 -0
- apps/repl/__init__.py +325 -0
- apps/repl/app.json +1 -0
- apps/roku/__init__.py +156 -0
- apps/roku/app.json +1 -0
- apps/rokucam/__init__.py +362 -0
- apps/rokucam/app.json +1 -0
- apps/security/__init__.py +261 -0
- apps/security/app.json +1 -0
- apps/settings/__init__.py +221 -0
- apps/settings/app.json +1 -0
- apps/shell/__init__.py +33 -0
- apps/shell/app.json +1 -0
- apps/spotify/__init__.py +669 -0
- apps/spotify/app.json +1 -0
- apps/spotify/screen.py +82 -0
- apps/steps/__init__.py +58 -0
- apps/steps/app.json +1 -0
- apps/stompbox/__init__.py +31 -0
- apps/stompbox/app.json +1 -0
- apps/stompbox/app.py +668 -0
- apps/stompbox/boards.json +20 -0
- apps/stompbox/effects.py +241 -0
- apps/stompbox/engine.py +340 -0
- apps/stompbox/footswitch.py +331 -0
- apps/stompbox/inputs.py +449 -0
- apps/stompbox/meter.py +72 -0
- apps/stompbox/outputs.py +135 -0
- apps/stompbox/pedals.txt +45 -0
- apps/stompbox/presets.py +106 -0
- apps/stompbox/styles.py +135 -0
- apps/stompbox/ui.py +817 -0
- apps/stompbox/wavfile.py +73 -0
- apps/synthstation/__init__.py +20 -0
- apps/synthstation/app.json +1 -0
- apps/synthstation/audio.py +397 -0
- apps/synthstation/catalog.py +50 -0
- apps/synthstation/meters.py +136 -0
- apps/synthstation/midi.py +380 -0
- apps/synthstation/pads.py +177 -0
- apps/synthstation/parts.py +128 -0
- apps/synthstation/station.py +1069 -0
- apps/system/__init__.py +11 -0
- apps/system/app.json +1 -0
- apps/touchcal/__init__.py +324 -0
- apps/touchcal/app.json +1 -0
- apps/touchcal/fit.py +262 -0
- apps/wake/__init__.py +268 -0
- apps/wake/app.json +1 -0
- apps/wake/feed.py +155 -0
- apps/watch/__init__.py +355 -0
- apps/watch/app.json +1 -0
- apps/watch/faces.py +35 -0
- apps/watch/wheel.py +157 -0
- apps/weather/__init__.py +278 -0
- apps/weather/app.json +1 -0
- apps/weather/icons.py +172 -0
- apps/weather/sizing.py +71 -0
- apps/weather/zippad.py +172 -0
- omnipython_apps-0.1.4.dev8.dist-info/METADATA +33 -0
- omnipython_apps-0.1.4.dev8.dist-info/RECORD +218 -0
- omnipython_apps-0.1.4.dev8.dist-info/WHEEL +5 -0
- omnipython_apps-0.1.4.dev8.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
"""Backline's desk page, the one the box serves to a browser on its desk port.
|
|
6
|
+
|
|
7
|
+
Generated by tools/backline/desk_page.py from desk_page.html: edit that, not this.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def page():
|
|
12
|
+
"""What ``hmilink.tcp.serve(port, page=...)`` takes to answer ``GET /``."""
|
|
13
|
+
return lambda: HTML.encode()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
HTML = (
|
|
17
|
+
'<!doctype html>\n'
|
|
18
|
+
'<html lang="en">\n'
|
|
19
|
+
'<head>\n'
|
|
20
|
+
'<meta charset="utf-8">\n'
|
|
21
|
+
'<meta name="viewport" content="width=device-width, initial-scale=1">\n'
|
|
22
|
+
'<title>Backline</title>\n'
|
|
23
|
+
'<!--\n'
|
|
24
|
+
' The desk page a Backline box serves on its desk port. It is one hmilink\n'
|
|
25
|
+
' panel: it opens ws://<box>/ws, takes the song, and sends every edit as a\n'
|
|
26
|
+
' JSON Patch op and every pedal as a command. It applies an op only when the\n'
|
|
27
|
+
" box sends it back numbered, so it always has the box's order; a gap in the\n"
|
|
28
|
+
' numbers means a frame went missing, and it asks for the whole song again.\n'
|
|
29
|
+
'-->\n'
|
|
30
|
+
'<style>\n'
|
|
31
|
+
':root { --bg:#0a0d12; --panel:#121821; --raised:#1a2230; --line:#2a3444; --fg:#dde3ec; --dim:#8792a5; --amber:#ffb703;\n'
|
|
32
|
+
' --intro:#4cc9f0; --main:#ffb703; --fill:#ff6b1a; --transition:#b28dff; --outro:#ff4d6d; --stopped:#7a8698; }\n'
|
|
33
|
+
'* { box-sizing: border-box; }\n'
|
|
34
|
+
'body { margin:0; background:var(--bg); color:var(--fg); font:15px/1.4 system-ui, sans-serif; }\n'
|
|
35
|
+
'header { display:flex; flex-wrap:wrap; gap:14px; align-items:center; padding:10px 16px; background:var(--panel); border-bottom:1px solid var(--line); }\n'
|
|
36
|
+
'h1 { font-size:15px; letter-spacing:3px; color:var(--amber); margin:0 6px 0 0; }\n'
|
|
37
|
+
'button, select, input { background:var(--raised); color:var(--fg); border:1px solid var(--line); border-radius:8px; padding:6px 12px; font:inherit; }\n'
|
|
38
|
+
'button { cursor:pointer; }\n'
|
|
39
|
+
'button:active { border-color:var(--amber); }\n'
|
|
40
|
+
'button.on { border-color:var(--amber); background:#3b3115; }\n'
|
|
41
|
+
'input[type=number] { width:70px; }\n'
|
|
42
|
+
'label { color:var(--dim); display:flex; gap:6px; align-items:center; }\n'
|
|
43
|
+
'#part { font-weight:600; min-width:110px; }\n'
|
|
44
|
+
'#where { font-size:26px; font-variant-numeric:tabular-nums; min-width:80px; text-align:center; }\n'
|
|
45
|
+
'#next { color:var(--dim); min-width:120px; }\n'
|
|
46
|
+
'#status { color:var(--dim); font-size:12px; margin-left:auto; }\n'
|
|
47
|
+
'main { padding:12px 16px; display:grid; gap:14px; }\n'
|
|
48
|
+
'.pedals { display:flex; gap:14px; }\n'
|
|
49
|
+
'.pedal { width:96px; height:96px; border-radius:50%; font-size:28px; font-weight:600; border:3px solid #4b5565;\n'
|
|
50
|
+
' background:radial-gradient(circle at 40% 35%, #2b3443, #07090d); touch-action:none; user-select:none; }\n'
|
|
51
|
+
'.pedal.down { box-shadow:0 0 24px 6px var(--glow); border-color:var(--glow); }\n'
|
|
52
|
+
'#pa { --glow:#ffb703; } #pb { --glow:#4cc9f0; }\n'
|
|
53
|
+
'.strip { display:flex; gap:4px; position:relative; }\n'
|
|
54
|
+
'.block { flex:1 1 0; border:1px solid var(--line); border-radius:6px; padding:10px 4px; text-align:center; font-size:13px;\n'
|
|
55
|
+
' cursor:pointer; position:relative; overflow:hidden; color:var(--c); background:color-mix(in srgb, var(--c) 14%, var(--bg)); }\n'
|
|
56
|
+
'.block.lit { background:color-mix(in srgb, var(--c) 60%, var(--bg)); color:#fff; border:2px solid var(--c); }\n'
|
|
57
|
+
'.block.next { border:2px dashed var(--c); }\n'
|
|
58
|
+
'.block.picked { box-shadow:inset 0 -4px 0 var(--amber); }\n'
|
|
59
|
+
'.playhead { position:absolute; top:0; bottom:0; width:2px; background:#fff; }\n'
|
|
60
|
+
'.bar { display:flex; gap:10px; align-items:center; }\n'
|
|
61
|
+
'.grid { overflow-x:auto; background:var(--panel); border:1px solid var(--line); border-radius:8px; padding:10px; }\n'
|
|
62
|
+
'.row { display:flex; gap:3px; margin-bottom:3px; align-items:center; }\n'
|
|
63
|
+
'.row span { width:96px; flex:none; color:var(--dim); font-size:13px; }\n'
|
|
64
|
+
'.cell { width:30px; height:30px; flex:none; border-radius:4px; background:var(--raised); border:1px solid transparent; cursor:pointer; padding:0; }\n'
|
|
65
|
+
'.cell.beat { margin-left:6px; }\n'
|
|
66
|
+
'.cell.l1 { background:#c89a1a; } .cell.l2 { background:var(--amber); } .cell.l3 { background:#6e5a2a; }\n'
|
|
67
|
+
'.cell.head { border-color:#fff; }\n'
|
|
68
|
+
'#ask { background:var(--panel); border:1px solid var(--line); border-radius:10px; padding:12px; display:grid; gap:10px; }\n'
|
|
69
|
+
'#ask[hidden] { display:none; }\n'
|
|
70
|
+
'#ask h2 { margin:0; font-size:13px; letter-spacing:2px; color:var(--dim); font-weight:600; }\n'
|
|
71
|
+
'.askrow { display:flex; gap:8px; }\n'
|
|
72
|
+
'#prompt { flex:1; min-width:0; }\n'
|
|
73
|
+
'#askstatus { color:var(--dim); font-size:13px; }\n'
|
|
74
|
+
'#askstatus.bad { color:#ff4d6d; }\n'
|
|
75
|
+
'#proposal { border:1px solid var(--line); border-radius:8px; padding:10px; display:grid; gap:6px; background:var(--bg); }\n'
|
|
76
|
+
'#proposal[hidden] { display:none; }\n'
|
|
77
|
+
'#pname { font-size:20px; color:var(--amber); font-weight:600; }\n'
|
|
78
|
+
'#pplan, #pfilled { color:var(--dim); font-size:13px; }\n'
|
|
79
|
+
'</style>\n'
|
|
80
|
+
'</head>\n'
|
|
81
|
+
'<body>\n'
|
|
82
|
+
'<header>\n'
|
|
83
|
+
' <h1>BACKLINE</h1>\n'
|
|
84
|
+
' <select id="song" title="Song"></select>\n'
|
|
85
|
+
' <span id="part">READY</span>\n'
|
|
86
|
+
' <span id="where">- . -</span>\n'
|
|
87
|
+
' <span id="next"></span>\n'
|
|
88
|
+
' <label>Tempo <button id="slower">-</button><input id="tempo" type="number" min="40" max="240" step="1"><button id="faster">+</button></label>\n'
|
|
89
|
+
' <select id="kit" title="Kit"></select>\n'
|
|
90
|
+
' <button id="asker" title="Ask for a groove in words">✦ Ask</button>\n'
|
|
91
|
+
' <span id="status">connecting</span>\n'
|
|
92
|
+
'</header>\n'
|
|
93
|
+
'<main>\n'
|
|
94
|
+
' <section id="ask" hidden>\n'
|
|
95
|
+
' <h2>ASK FOR A GROOVE</h2>\n'
|
|
96
|
+
' <div class="askrow"><input id="prompt" type="text" placeholder="A slow 12-bar blues at 72, 4 times through, slowing in the outro"><button id="askgo">Ask</button></div>\n'
|
|
97
|
+
' <div id="askstatus">Say a style, a tempo, a song to borrow the feel of, and how long to play.</div>\n'
|
|
98
|
+
' <div id="proposal" hidden>\n'
|
|
99
|
+
' <div id="pname"></div><div id="pfacts"></div><div id="pplan"></div>\n'
|
|
100
|
+
' <div class="strip" id="pstrip"></div><div id="pfilled"></div>\n'
|
|
101
|
+
' <div class="askrow"><button id="pplay" class="on">Play</button><button id="pkeep">Keep</button><button id="pdiscard">Discard</button></div>\n'
|
|
102
|
+
' </div>\n'
|
|
103
|
+
' </section>\n'
|
|
104
|
+
' <div class="pedals"><button class="pedal" id="pa">A</button><button class="pedal" id="pb">B</button></div>\n'
|
|
105
|
+
' <div class="strip" id="strip"></div>\n'
|
|
106
|
+
' <div class="bar"><b id="editing"></b><button id="prev"><</button><span id="page"></span><button id="nextbar">></button>\n'
|
|
107
|
+
' <button id="follow" class="on">Follow</button></div>\n'
|
|
108
|
+
' <div class="grid" id="grid"></div>\n'
|
|
109
|
+
'</main>\n'
|
|
110
|
+
'<script>\n'
|
|
111
|
+
'"use strict";\n'
|
|
112
|
+
'const BAR = 384, LEVELS = [0, 96, 124, 56], CORE = [36, 38, 42, 46, 49];\n'
|
|
113
|
+
'const SHORT = { intro: "INTRO", main: "MAIN", fill: "FILL", transition: "TRANS", outro: "OUTRO" };\n'
|
|
114
|
+
'const LABEL = { intro: "Intro", main: "Main", fill: "Fill", transition: "Transition", outro: "Outro" };\n'
|
|
115
|
+
'let ws = null, doc = null, desc = {}, seq = 0, me = null, nextId = 1, syncing = false;\n'
|
|
116
|
+
'let tele = {}, blocks = [], shown = -1, bar = 0, follow = true, voices = [], proposal = null;\n'
|
|
117
|
+
'const stats = { ops: 0, resyncs: 0 };\n'
|
|
118
|
+
'window.backline = { stats, get doc() { return doc; }, get tele() { return tele; }, get ready() { return doc !== null && !syncing; },\n'
|
|
119
|
+
' send, command, get shown() { return shown >= 0 ? blocks[shown] : null; }, get proposal() { return proposal; } };\n'
|
|
120
|
+
'\n'
|
|
121
|
+
'function connect() {\n'
|
|
122
|
+
' ws = new WebSocket((location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/ws");\n'
|
|
123
|
+
' ws.onopen = () => { ws.send(JSON.stringify({ t: "hello", v: 1 })); status("connected"); };\n'
|
|
124
|
+
' ws.onmessage = (e) => { for (const line of String(e.data).split("\\n")) if (line.trim()) handle(JSON.parse(line)); };\n'
|
|
125
|
+
' ws.onclose = () => { status("the box went away; trying again"); doc = null; setTimeout(connect, 1000); };\n'
|
|
126
|
+
'}\n'
|
|
127
|
+
'function status(s) { document.getElementById("status").textContent = s; }\n'
|
|
128
|
+
'\n'
|
|
129
|
+
'function handle(m) {\n'
|
|
130
|
+
' if (m.t === "doc") {\n'
|
|
131
|
+
' doc = m.doc; desc = m.desc || {}; seq = m.seq; me = m.you; syncing = false; voices = desc.voices || [];\n'
|
|
132
|
+
' renderAll(); showProposal(desc.proposal || null);\n'
|
|
133
|
+
' } else if (m.t === "op") {\n'
|
|
134
|
+
' if (doc === null || syncing) return;\n'
|
|
135
|
+
' if (m.seq !== seq + 1) { stats.resyncs++; syncing = true; ws.send(JSON.stringify({ t: "sync" })); return; }\n'
|
|
136
|
+
' seq = m.seq; stats.ops++;\n'
|
|
137
|
+
' apply(doc, m);\n'
|
|
138
|
+
' if (m.path === "/tempo") showTempo();\n'
|
|
139
|
+
' else if (m.path.startsWith("/parts") || m.path.endsWith("/bars")) renderAll();\n'
|
|
140
|
+
' else renderCells();\n'
|
|
141
|
+
' } else if (m.t === "tele") {\n'
|
|
142
|
+
' tele = m.v || {}; showTele();\n'
|
|
143
|
+
' } else if (m.t === "ev") {\n'
|
|
144
|
+
' if ((m.name === "kit" || m.name === "song" || m.name === "proposal") && m.voices) { voices = m.voices; desc.kit = m.spec || m.kit; renderKits(); renderGrid(); }\n'
|
|
145
|
+
' if (m.name === "proposal") {\n'
|
|
146
|
+
' if ("preview" in m) { showProposal(m.preview); if (m.error) askStatus(m.error, true); }\n'
|
|
147
|
+
' else if (m.did === "keep" || m.did === "discard") { showProposal(null); askStatus(ASK_IDLE, false); }\n'
|
|
148
|
+
' }\n'
|
|
149
|
+
' } else if (m.t === "err") {\n'
|
|
150
|
+
' status("the box said: " + m.msg);\n'
|
|
151
|
+
' }\n'
|
|
152
|
+
'}\n'
|
|
153
|
+
'\n'
|
|
154
|
+
'// -- JSON Patch, the three ops hmilink uses --\n'
|
|
155
|
+
'function split(p) { return p.split("/").slice(1).map((k) => k.replace(/~1/g, "/").replace(/~0/g, "~")); }\n'
|
|
156
|
+
'function apply(root, op) {\n'
|
|
157
|
+
' const keys = split(op.path), last = keys.pop();\n'
|
|
158
|
+
' let node = root;\n'
|
|
159
|
+
' for (const k of keys) node = node[Array.isArray(node) ? +k : k];\n'
|
|
160
|
+
' if (Array.isArray(node)) {\n'
|
|
161
|
+
' if (op.op === "add") { if (last === "-") node.push(op.value); else node.splice(+last, 0, op.value); }\n'
|
|
162
|
+
' else if (op.op === "remove") node.splice(+last, 1);\n'
|
|
163
|
+
' else node[+last] = op.value;\n'
|
|
164
|
+
' } else if (op.op === "remove") delete node[last];\n'
|
|
165
|
+
' else node[last] = op.value;\n'
|
|
166
|
+
'}\n'
|
|
167
|
+
'function send(op, path, value) {\n'
|
|
168
|
+
' const m = { t: "op", op, path, id: nextId++ };\n'
|
|
169
|
+
' if (op !== "remove") m.value = value;\n'
|
|
170
|
+
' ws.send(JSON.stringify(m));\n'
|
|
171
|
+
'}\n'
|
|
172
|
+
'function command(name, args) { ws.send(JSON.stringify({ t: "cmd", name, args: args || {} })); }\n'
|
|
173
|
+
'\n'
|
|
174
|
+
"// -- the song: its form, its meter and a part's grid, as the Python desk reads them --\n"
|
|
175
|
+
'function meter() {\n'
|
|
176
|
+
' const [n, d] = String(doc.meter || "4/4").split("/").map(Number);\n'
|
|
177
|
+
' if (!(n >= 1)) return [4, 1];\n'
|
|
178
|
+
' return d === 8 && n % 3 === 0 && n > 3 ? [n, 3] : [n, 1];\n'
|
|
179
|
+
'}\n'
|
|
180
|
+
'function columns() { const [steps, group] = meter(); const cols = steps * (group === 1 ? 4 : 1); return [cols, BAR / cols, group === 1 ? 4 : group]; }\n'
|
|
181
|
+
'function makeBlocks() {\n'
|
|
182
|
+
' const parts = doc.parts || {}, pats = doc.tracks[0].patterns, out = [];\n'
|
|
183
|
+
' const add = (role, number, p) => {\n'
|
|
184
|
+
' if (p == null || p < 0 || p >= pats.length) return;\n'
|
|
185
|
+
' const label = LABEL[role] + (number == null ? "" : " " + (number + 1));\n'
|
|
186
|
+
' out.push({ role, number, pattern: p, bars: Math.max(1, pats[p].bars || 1), label,\n'
|
|
187
|
+
' short: SHORT[role] + (number == null || role === "transition" ? "" : " " + (number + 1)) });\n'
|
|
188
|
+
' };\n'
|
|
189
|
+
' const mains = parts.mains || [0], fills = parts.fills || [];\n'
|
|
190
|
+
' let trans = parts.transitions != null ? parts.transitions : parts.transition;\n'
|
|
191
|
+
' trans = Array.isArray(trans) ? trans : trans == null ? [] : [trans];\n'
|
|
192
|
+
' const each = trans.length === mains.length;\n'
|
|
193
|
+
' add("intro", null, parts.intro);\n'
|
|
194
|
+
' mains.forEach((m, n) => {\n'
|
|
195
|
+
' if (n && trans.length) add("transition", n, each ? trans[n] : trans[0]);\n'
|
|
196
|
+
' add("main", n, m);\n'
|
|
197
|
+
' if (n < fills.length) add("fill", n, fills[n]);\n'
|
|
198
|
+
' });\n'
|
|
199
|
+
' if (each && mains.length > 1) add("transition", 0, trans[0]);\n'
|
|
200
|
+
' add("outro", null, parts.outro);\n'
|
|
201
|
+
' return out;\n'
|
|
202
|
+
'}\n'
|
|
203
|
+
'function find(role, number) { return blocks.findIndex((b) => b.role === role && (b.number === number || role === "intro" || role === "outro")); }\n'
|
|
204
|
+
'function level(v) { return v <= 0 ? 0 : v < 80 ? 3 : v < 112 ? 1 : 2; }\n'
|
|
205
|
+
'function rows() {\n'
|
|
206
|
+
' const names = new Map(voices.map(([p, n]) => [p, n])), used = new Set();\n'
|
|
207
|
+
' for (const pat of doc.tracks[0].patterns) for (const n of pat.notes) used.add(n[2]);\n'
|
|
208
|
+
' const want = new Set([...CORE.filter((p) => names.has(p)), ...used]);\n'
|
|
209
|
+
' return [...want].sort((a, b) => b - a).map((p) => [p, names.get(p) || "Note " + p]);\n'
|
|
210
|
+
'}\n'
|
|
211
|
+
'function tap(index, pitch, step, ticks) {\n'
|
|
212
|
+
' const notes = doc.tracks[0].patterns[index].notes, base = "/tracks/0/patterns/" + index + "/notes";\n'
|
|
213
|
+
' const i = notes.findIndex((n) => n[2] === pitch && n[0] >= step * ticks && n[0] < (step + 1) * ticks);\n'
|
|
214
|
+
' if (i < 0) return send("add", base + "/-", [step * ticks, ticks, pitch, LEVELS[1]]);\n'
|
|
215
|
+
' const now = level(notes[i][3]);\n'
|
|
216
|
+
' if (now === 3) return send("remove", base + "/" + i);\n'
|
|
217
|
+
' send("replace", base + "/" + i + "/3", LEVELS[now === 1 ? 2 : 3]);\n'
|
|
218
|
+
'}\n'
|
|
219
|
+
'\n'
|
|
220
|
+
'// -- the page --\n'
|
|
221
|
+
'function renderAll() {\n'
|
|
222
|
+
' blocks = makeBlocks();\n'
|
|
223
|
+
' if (shown < 0 || shown >= blocks.length) shown = Math.max(0, blocks.findIndex((b) => b.role === "main"));\n'
|
|
224
|
+
' const song = document.getElementById("song");\n'
|
|
225
|
+
' song.textContent = "";\n'
|
|
226
|
+
' (desc.titles || desc.songs || []).forEach((t, i) => { const o = document.createElement("option"); o.value = i; o.textContent = t; song.append(o); });\n'
|
|
227
|
+
' renderKits(); showTempo(); renderStrip(); renderGrid(); showTele();\n'
|
|
228
|
+
'}\n'
|
|
229
|
+
'function renderKits() {\n'
|
|
230
|
+
' const kit = document.getElementById("kit");\n'
|
|
231
|
+
' kit.textContent = "";\n'
|
|
232
|
+
' for (const k of desc.kit_list || []) { const o = document.createElement("option"); o.value = k.spec; o.textContent = k.name; kit.append(o); }\n'
|
|
233
|
+
' if (desc.kit) kit.value = desc.kit;\n'
|
|
234
|
+
'}\n'
|
|
235
|
+
'function showTempo() {\n'
|
|
236
|
+
' const el = document.getElementById("tempo");\n'
|
|
237
|
+
' if (document.activeElement !== el) el.value = Math.round(doc.tempo);\n'
|
|
238
|
+
'}\n'
|
|
239
|
+
'function renderStrip() {\n'
|
|
240
|
+
' const strip = document.getElementById("strip");\n'
|
|
241
|
+
' strip.textContent = "";\n'
|
|
242
|
+
' blocks.forEach((b, i) => {\n'
|
|
243
|
+
' const el = document.createElement("div");\n'
|
|
244
|
+
' el.className = "block" + (i === shown ? " picked" : "");\n'
|
|
245
|
+
' el.style.setProperty("--c", "var(--" + b.role + ")");\n'
|
|
246
|
+
' el.style.flexGrow = b.bars;\n'
|
|
247
|
+
' el.textContent = b.short;\n'
|
|
248
|
+
' el.dataset.block = i;\n'
|
|
249
|
+
' el.onclick = () => { follow = false; showFollow(); shown = i; bar = 0; renderStrip(); renderGrid(); };\n'
|
|
250
|
+
' strip.append(el);\n'
|
|
251
|
+
' });\n'
|
|
252
|
+
'}\n'
|
|
253
|
+
'function renderGrid() {\n'
|
|
254
|
+
' const grid = document.getElementById("grid");\n'
|
|
255
|
+
' grid.textContent = "";\n'
|
|
256
|
+
' const b = blocks[shown];\n'
|
|
257
|
+
' if (!b) return;\n'
|
|
258
|
+
' const [cols, ticks, beat] = columns();\n'
|
|
259
|
+
' bar = Math.min(bar, b.bars - 1);\n'
|
|
260
|
+
' document.getElementById("editing").textContent = b.label.toUpperCase();\n'
|
|
261
|
+
' document.getElementById("page").textContent = "Bar " + (bar + 1) + " / " + b.bars;\n'
|
|
262
|
+
' for (const [pitch, name] of rows()) {\n'
|
|
263
|
+
' const row = document.createElement("div");\n'
|
|
264
|
+
' row.className = "row";\n'
|
|
265
|
+
' const label = document.createElement("span"); label.textContent = name; row.append(label);\n'
|
|
266
|
+
' for (let c = 0; c < cols; c++) {\n'
|
|
267
|
+
' const cell = document.createElement("button");\n'
|
|
268
|
+
' cell.className = "cell" + (c && c % beat === 0 ? " beat" : "");\n'
|
|
269
|
+
' cell.dataset.pitch = pitch; cell.dataset.step = bar * cols + c; cell.dataset.col = c;\n'
|
|
270
|
+
' cell.onclick = () => { tap(b.pattern, pitch, bar * cols + c, ticks); };\n'
|
|
271
|
+
' row.append(cell);\n'
|
|
272
|
+
' }\n'
|
|
273
|
+
' grid.append(row);\n'
|
|
274
|
+
' }\n'
|
|
275
|
+
' renderCells();\n'
|
|
276
|
+
'}\n'
|
|
277
|
+
'function renderCells() {\n'
|
|
278
|
+
' const b = blocks[shown];\n'
|
|
279
|
+
' if (!b) return;\n'
|
|
280
|
+
' const [, ticks] = columns(), notes = doc.tracks[0].patterns[b.pattern].notes, lv = new Map();\n'
|
|
281
|
+
' for (const n of notes) { const k = n[2] + ":" + Math.floor(n[0] / ticks); lv.set(k, Math.max(lv.get(k) || 0, level(n[3]))); }\n'
|
|
282
|
+
' for (const c of document.querySelectorAll(".cell")) {\n'
|
|
283
|
+
' const l = lv.get(c.dataset.pitch + ":" + c.dataset.step) || 0;\n'
|
|
284
|
+
' c.classList.remove("l1", "l2", "l3");\n'
|
|
285
|
+
' if (l) c.classList.add("l" + l);\n'
|
|
286
|
+
' c.dataset.level = l;\n'
|
|
287
|
+
' }\n'
|
|
288
|
+
'}\n'
|
|
289
|
+
'// -- asking for a groove in words: the box asks its chat server, and every panel hears the song --\n'
|
|
290
|
+
'const ASK_IDLE = "Say a style, a tempo, a song to borrow the feel of, and how long to play.";\n'
|
|
291
|
+
'function askStatus(text, bad) { const el = document.getElementById("askstatus"); el.textContent = text; el.classList.toggle("bad", !!bad); }\n'
|
|
292
|
+
'function planText(p) {\n'
|
|
293
|
+
' let text = p.repeat ? (p.repeat === 1 ? "Once through" : p.repeat + " times through") : "Loops until you stop it";\n'
|
|
294
|
+
' if (p.outro_tempo) text += ", the outro slowing to " + Math.round(p.outro_tempo);\n'
|
|
295
|
+
' return text;\n'
|
|
296
|
+
'}\n'
|
|
297
|
+
'function showProposal(p) {\n'
|
|
298
|
+
' proposal = p;\n'
|
|
299
|
+
' const card = document.getElementById("proposal");\n'
|
|
300
|
+
' card.hidden = !p;\n'
|
|
301
|
+
' if (!p) return;\n'
|
|
302
|
+
' document.getElementById("pname").textContent = p.name || "Untitled";\n'
|
|
303
|
+
' const style = p.style ? p.style[0].toUpperCase() + p.style.slice(1) : "";\n'
|
|
304
|
+
' const bits = [style, Math.round(p.tempo) + " BPM", p.meter, p.swing ? "swing " + p.swing + "%" : p.feel !== "straight" ? p.feel : "", p.kit_name || p.kit];\n'
|
|
305
|
+
' document.getElementById("pfacts").textContent = bits.filter((b) => b).join(" \\u2022 ");\n'
|
|
306
|
+
' document.getElementById("pplan").textContent = planText(p);\n'
|
|
307
|
+
' const filled = p.filled || [];\n'
|
|
308
|
+
' document.getElementById("pfilled").textContent = filled.length ? "Filled in: " + filled.join(", ") : "";\n'
|
|
309
|
+
' const strip = document.getElementById("pstrip");\n'
|
|
310
|
+
' strip.textContent = "";\n'
|
|
311
|
+
' for (const b of p.blocks || []) {\n'
|
|
312
|
+
' const el = document.createElement("div");\n'
|
|
313
|
+
' el.className = "block";\n'
|
|
314
|
+
' el.style.setProperty("--c", "var(--" + b.role + ")");\n'
|
|
315
|
+
' el.style.flexGrow = b.bars;\n'
|
|
316
|
+
' el.textContent = b.short + " \\u00b7 " + b.bars;\n'
|
|
317
|
+
' strip.append(el);\n'
|
|
318
|
+
' }\n'
|
|
319
|
+
' askStatus(p.tries > 1 ? "Here it is. (The first answer didn\'t fit; the second did.)" : "Here it is.", false);\n'
|
|
320
|
+
'}\n'
|
|
321
|
+
'function ask() {\n'
|
|
322
|
+
' const text = document.getElementById("prompt").value.trim();\n'
|
|
323
|
+
' if (!text || tele.ask === "asking") return;\n'
|
|
324
|
+
' command("ask", { text });\n'
|
|
325
|
+
' askStatus("Asking for the song... a model on a computer with no GPU can take a few minutes.", false);\n'
|
|
326
|
+
'}\n'
|
|
327
|
+
'function showAsk(t) {\n'
|
|
328
|
+
' if (t.ask === "asking") askStatus("Asking for the song... a model on a computer with no GPU can take a few minutes.", false);\n'
|
|
329
|
+
' else if (t.ask === "failed") askStatus(t.ask_error || "the song didn\'t come", true);\n'
|
|
330
|
+
'}\n'
|
|
331
|
+
'function showFollow() { document.getElementById("follow").classList.toggle("on", follow); }\n'
|
|
332
|
+
'function showTele() {\n'
|
|
333
|
+
' if (!doc) return;\n'
|
|
334
|
+
' const t = tele, playing = !!t.playing;\n'
|
|
335
|
+
' showAsk(t);\n'
|
|
336
|
+
' const part = document.getElementById("part");\n'
|
|
337
|
+
' part.textContent = (t.part || "Ready").toUpperCase();\n'
|
|
338
|
+
' part.style.color = "var(--" + (t.role || "stopped") + ")";\n'
|
|
339
|
+
' document.getElementById("where").textContent = playing ? t.bar + " . " + t.beat : "- . -";\n'
|
|
340
|
+
' document.getElementById("next").textContent = t.next ? "NEXT " + t.next.toUpperCase() : playing ? "LOOPING" : "TAP A TO START";\n'
|
|
341
|
+
' const song = document.getElementById("song");\n'
|
|
342
|
+
' if (t.song_index != null && document.activeElement !== song) {\n'
|
|
343
|
+
' // -1: a song that came back from asking plays; it has an entry of its own until it is kept\n'
|
|
344
|
+
' let asked = song.querySelector("option[value=\'-1\']");\n'
|
|
345
|
+
' if (t.song_index < 0) {\n'
|
|
346
|
+
' if (!asked) { asked = document.createElement("option"); asked.value = "-1"; song.append(asked); }\n'
|
|
347
|
+
' asked.textContent = t.song || "Asked for";\n'
|
|
348
|
+
' } else if (asked) asked.remove();\n'
|
|
349
|
+
' song.value = t.song_index;\n'
|
|
350
|
+
' }\n'
|
|
351
|
+
' for (const [i, el] of [document.getElementById("pa"), document.getElementById("pb")].entries())\n'
|
|
352
|
+
' el.classList.toggle("down", (t.pedals || [])[i] && t.pedals[i] !== "up");\n'
|
|
353
|
+
' const lit = playing ? find(t.role, t.number) : -1, nxt = playing ? find(t.next_role, t.next_number) : -1;\n'
|
|
354
|
+
' if (follow && lit >= 0 && (lit !== shown || Math.floor((t.at || 0) / BAR) !== bar)) {\n'
|
|
355
|
+
' shown = lit; bar = Math.floor((t.at || 0) / BAR); renderStrip(); renderGrid();\n'
|
|
356
|
+
' }\n'
|
|
357
|
+
' const els = document.querySelectorAll(".block");\n'
|
|
358
|
+
' els.forEach((el, i) => { el.classList.toggle("lit", i === lit); el.classList.toggle("next", i === nxt && nxt !== lit); });\n'
|
|
359
|
+
' document.querySelectorAll(".playhead").forEach((h) => h.remove());\n'
|
|
360
|
+
' if (lit >= 0) {\n'
|
|
361
|
+
' const h = document.createElement("div");\n'
|
|
362
|
+
' h.className = "playhead";\n'
|
|
363
|
+
' h.style.left = Math.min(100, 100 * (t.at || 0) / (blocks[lit].bars * BAR)) + "%";\n'
|
|
364
|
+
' els[lit].append(h);\n'
|
|
365
|
+
' }\n'
|
|
366
|
+
' for (const c of document.querySelectorAll(".cell.head")) c.classList.remove("head");\n'
|
|
367
|
+
' const b = blocks[shown];\n'
|
|
368
|
+
' if (playing && b && t.pattern === b.pattern && Math.floor((t.at || 0) / BAR) === bar) {\n'
|
|
369
|
+
' const [, ticks] = columns(), col = Math.floor(((t.at || 0) % BAR) / ticks);\n'
|
|
370
|
+
' for (const c of document.querySelectorAll(\'.cell[data-col="\' + col + \'"]\')) c.classList.add("head");\n'
|
|
371
|
+
' }\n'
|
|
372
|
+
'}\n'
|
|
373
|
+
'\n'
|
|
374
|
+
'for (const [id, which] of [["pa", 0], ["pb", 1]]) {\n'
|
|
375
|
+
' const el = document.getElementById(id);\n'
|
|
376
|
+
' el.onpointerdown = (e) => { el.setPointerCapture(e.pointerId); command("pedal", { pedal: which, down: true }); };\n'
|
|
377
|
+
' el.onpointerup = el.onpointercancel = () => command("pedal", { pedal: which, down: false });\n'
|
|
378
|
+
'}\n'
|
|
379
|
+
'const keys = new Set();\n'
|
|
380
|
+
'document.onkeydown = (e) => {\n'
|
|
381
|
+
' const which = e.key === " " ? 0 : e.key === "b" ? 1 : -1;\n'
|
|
382
|
+
' if (which < 0 || keys.has(e.key) || e.target.tagName === "INPUT") return;\n'
|
|
383
|
+
' keys.add(e.key); e.preventDefault(); command("pedal", { pedal: which, down: true });\n'
|
|
384
|
+
'};\n'
|
|
385
|
+
'document.onkeyup = (e) => {\n'
|
|
386
|
+
' const which = e.key === " " ? 0 : e.key === "b" ? 1 : -1;\n'
|
|
387
|
+
' if (which < 0 || !keys.has(e.key)) return;\n'
|
|
388
|
+
' keys.delete(e.key); command("pedal", { pedal: which, down: false });\n'
|
|
389
|
+
'};\n'
|
|
390
|
+
'document.getElementById("song").onchange = (e) => { if (+e.target.value >= 0) command("song", { index: +e.target.value }); };\n'
|
|
391
|
+
'document.getElementById("kit").onchange = (e) => command("kit", { spec: e.target.value });\n'
|
|
392
|
+
'document.getElementById("tempo").onchange = (e) => send("replace", "/tempo", +e.target.value);\n'
|
|
393
|
+
'document.getElementById("slower").onclick = () => send("replace", "/tempo", Math.round(doc.tempo) - 1);\n'
|
|
394
|
+
'document.getElementById("faster").onclick = () => send("replace", "/tempo", Math.round(doc.tempo) + 1);\n'
|
|
395
|
+
'document.getElementById("prev").onclick = () => { follow = false; showFollow(); const b = blocks[shown]; bar = (bar + b.bars - 1) % b.bars; renderGrid(); };\n'
|
|
396
|
+
'document.getElementById("nextbar").onclick = () => { follow = false; showFollow(); const b = blocks[shown]; bar = (bar + 1) % b.bars; renderGrid(); };\n'
|
|
397
|
+
'document.getElementById("follow").onclick = () => { follow = !follow; showFollow(); };\n'
|
|
398
|
+
'document.getElementById("asker").onclick = () => {\n'
|
|
399
|
+
' const box = document.getElementById("ask");\n'
|
|
400
|
+
' box.hidden = !box.hidden;\n'
|
|
401
|
+
' document.getElementById("asker").classList.toggle("on", !box.hidden);\n'
|
|
402
|
+
' if (!box.hidden) document.getElementById("prompt").focus();\n'
|
|
403
|
+
'};\n'
|
|
404
|
+
'document.getElementById("askgo").onclick = ask;\n'
|
|
405
|
+
'document.getElementById("prompt").onkeydown = (e) => { if (e.key === "Enter") ask(); };\n'
|
|
406
|
+
'document.getElementById("pplay").onclick = () => command("proposal", { do: "play" });\n'
|
|
407
|
+
'document.getElementById("pkeep").onclick = () => command("proposal", { do: "keep" });\n'
|
|
408
|
+
'document.getElementById("pdiscard").onclick = () => command("proposal", { do: "discard" });\n'
|
|
409
|
+
'connect();\n'
|
|
410
|
+
'</script>\n'
|
|
411
|
+
'</body>\n'
|
|
412
|
+
'</html>\n'
|
|
413
|
+
)
|
apps/backline/parts.py
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""What the desk shows of a song, with no screen: its form and a part's steps.
|
|
5
|
+
|
|
6
|
+
`blocks` lays a song's parts out in the order a song goes through them,
|
|
7
|
+
for the song-form strip. The step functions read a part's notes as a grid
|
|
8
|
+
of drums by steps, and turn a tap on a cell into the songmodel op that
|
|
9
|
+
makes it so. Tapping a cell walks it through four levels: off, on, loud,
|
|
10
|
+
soft, and off again.
|
|
11
|
+
|
|
12
|
+
Imports on CPython and MicroPython with nothing but songmodel, so a check
|
|
13
|
+
can run it with numbers alone.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from songmodel import model
|
|
17
|
+
|
|
18
|
+
from .engine import label, meter
|
|
19
|
+
|
|
20
|
+
BAR = model.BAR
|
|
21
|
+
TRACK = "/tracks/0"
|
|
22
|
+
#: The velocity each level of a cell plays at: off, on, loud and soft.
|
|
23
|
+
LEVELS = (0, 96, 124, 56)
|
|
24
|
+
#: The drums every grid shows when the kit has them, used or not.
|
|
25
|
+
CORE = (36, 38, 42, 46, 49)
|
|
26
|
+
SHORT = {"intro": "INTRO", "main": "MAIN", "fill": "FILL", "transition": "TRANS", "outro": "OUTRO"}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def blocks(doc):
|
|
30
|
+
"""The song's parts in the order it plays them: intro, then each main
|
|
31
|
+
with its fill (the transition before the main it leads into), then the
|
|
32
|
+
outro. Each is ``{"role", "number", "pattern", "bars", "label", "short"}``."""
|
|
33
|
+
parts = doc.get("parts") or {}
|
|
34
|
+
patterns = doc["tracks"][0]["patterns"]
|
|
35
|
+
out = []
|
|
36
|
+
|
|
37
|
+
def add(role, number, pattern):
|
|
38
|
+
if pattern is None or not 0 <= pattern < len(patterns):
|
|
39
|
+
return
|
|
40
|
+
short = SHORT[role] + ("" if number is None or role == "transition" else " %d" % (number + 1))
|
|
41
|
+
out.append({"role": role, "number": number, "pattern": pattern,
|
|
42
|
+
"bars": max(1, patterns[pattern].get("bars", 1)),
|
|
43
|
+
"label": label((role, number)), "short": short})
|
|
44
|
+
|
|
45
|
+
mains = list(parts.get("mains") or [0])
|
|
46
|
+
fills = list(parts.get("fills") or [])
|
|
47
|
+
trans = parts.get("transitions", parts.get("transition"))
|
|
48
|
+
trans = list(trans) if isinstance(trans, list) else ([] if trans is None else [trans])
|
|
49
|
+
each = len(trans) == len(mains)
|
|
50
|
+
add("intro", None, parts.get("intro"))
|
|
51
|
+
for n, main in enumerate(mains):
|
|
52
|
+
if n and trans:
|
|
53
|
+
add("transition", n, trans[n] if each else trans[0])
|
|
54
|
+
add("main", n, main)
|
|
55
|
+
if n < len(fills):
|
|
56
|
+
add("fill", n, fills[n])
|
|
57
|
+
if each and len(mains) > 1:
|
|
58
|
+
add("transition", 0, trans[0])
|
|
59
|
+
add("outro", None, parts.get("outro"))
|
|
60
|
+
return out
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def find(blocks_, role, number):
|
|
64
|
+
"""The index of the block for ``role`` and ``number``, or -1."""
|
|
65
|
+
for i, b in enumerate(blocks_):
|
|
66
|
+
if b["role"] == role and (b["number"] == number or role in ("intro", "outro")):
|
|
67
|
+
return i
|
|
68
|
+
return -1
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def columns(doc):
|
|
72
|
+
"""``(columns, ticks)``: a bar's steps on the grid and the ticks in one.
|
|
73
|
+
Sixteenths for a song whose beat is one segment (4/4), else one column
|
|
74
|
+
a segment (12/8's eighths)."""
|
|
75
|
+
steps, group = meter(doc)
|
|
76
|
+
cols = steps * (4 if group == 1 else 1)
|
|
77
|
+
return cols, BAR // cols
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def beat_columns(doc):
|
|
81
|
+
"""How many grid columns make a beat."""
|
|
82
|
+
steps, group = meter(doc)
|
|
83
|
+
return 4 if group == 1 else group
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def rows(voices, doc):
|
|
87
|
+
"""``[(pitch, name)]``, highest first: the kit's drums that the song
|
|
88
|
+
plays or that every grid shows, and any drum the song plays that the kit
|
|
89
|
+
names nothing for."""
|
|
90
|
+
names = dict((int(p), n) for p, n in voices)
|
|
91
|
+
used = set()
|
|
92
|
+
for pat in doc["tracks"][0]["patterns"]:
|
|
93
|
+
for n in pat["notes"]:
|
|
94
|
+
used.add(n[2])
|
|
95
|
+
want = set(p for p in CORE if p in names) | used
|
|
96
|
+
out = []
|
|
97
|
+
for p in sorted(want, reverse=True):
|
|
98
|
+
out.append((p, names.get(p) or "Note %d" % p))
|
|
99
|
+
return out
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def level(velocity):
|
|
103
|
+
"""Which of `LEVELS` a velocity shows as: 1 on, 2 loud, 3 soft."""
|
|
104
|
+
if velocity <= 0:
|
|
105
|
+
return 0
|
|
106
|
+
if velocity < 80:
|
|
107
|
+
return 3
|
|
108
|
+
if velocity < 112:
|
|
109
|
+
return 1
|
|
110
|
+
return 2
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def cell(notes, pitch, step, ticks):
|
|
114
|
+
"""The index in ``notes`` of the note in a cell, or -1."""
|
|
115
|
+
lo = step * ticks
|
|
116
|
+
hi = lo + ticks
|
|
117
|
+
for i, n in enumerate(notes):
|
|
118
|
+
if n[2] == pitch and lo <= n[0] < hi:
|
|
119
|
+
return i
|
|
120
|
+
return -1
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def levels(pattern, pitches, ticks):
|
|
124
|
+
"""``{(pitch, step): level}`` for every note on the grid of ``pattern``."""
|
|
125
|
+
out = {}
|
|
126
|
+
want = set(pitches)
|
|
127
|
+
for n in pattern["notes"]:
|
|
128
|
+
if n[2] in want:
|
|
129
|
+
key = (n[2], int(n[0] // ticks))
|
|
130
|
+
out[key] = max(out.get(key, 0), level(n[3]))
|
|
131
|
+
return out
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def tap(doc, index, pitch, step, ticks):
|
|
135
|
+
"""The op a tap on cell ``(pitch, step)`` of pattern ``index`` sends:
|
|
136
|
+
``(op, path, value)``. Off becomes on, on loud, loud soft, soft off."""
|
|
137
|
+
pat = doc["tracks"][0]["patterns"][index]
|
|
138
|
+
base = "%s/patterns/%d/notes" % (TRACK, index)
|
|
139
|
+
i = cell(pat["notes"], pitch, step, ticks)
|
|
140
|
+
if i < 0:
|
|
141
|
+
return "add", base + "/-", [step * ticks, ticks, pitch, LEVELS[1]]
|
|
142
|
+
now = level(pat["notes"][i][3])
|
|
143
|
+
if now == 3:
|
|
144
|
+
return "remove", "%s/%d" % (base, i), None
|
|
145
|
+
return "replace", "%s/%d/3" % (base, i), LEVELS[2 if now == 1 else 3]
|