omnipython-applibs 0.1.2.dev16__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 (143) hide show
  1. appkit/__init__.py +52 -0
  2. appkit/__init__.pyi +17 -0
  3. appkit/data.py +149 -0
  4. appkit/data.pyi +25 -0
  5. appkit/foreground.py +357 -0
  6. appkit/foreground.pyi +45 -0
  7. appkit/home.py +19 -0
  8. appkit/home.pyi +8 -0
  9. appkit/hover.py +59 -0
  10. appkit/hover.pyi +13 -0
  11. appkit/index.py +199 -0
  12. appkit/index.pyi +30 -0
  13. appkit/launcher.py +1075 -0
  14. appkit/launcher.pyi +96 -0
  15. appkit/manifest.py +75 -0
  16. appkit/manifest.pyi +8 -0
  17. appkit/net.py +167 -0
  18. appkit/net.pyi +34 -0
  19. appkit/places.py +202 -0
  20. appkit/places.pyi +39 -0
  21. appkit/py.typed +0 -0
  22. appkit/scope.py +636 -0
  23. appkit/scope.pyi +110 -0
  24. appkit/shell.py +121 -0
  25. appkit/shell.pyi +32 -0
  26. appkit/worker.py +409 -0
  27. appkit/worker.pyi +83 -0
  28. controlkit/__init__.py +19 -0
  29. controlkit/__init__.pyi +10 -0
  30. controlkit/_draw.py +88 -0
  31. controlkit/_safe.py +29 -0
  32. controlkit/dotmatrix.py +101 -0
  33. controlkit/dotmatrix.pyi +23 -0
  34. controlkit/encoder.py +297 -0
  35. controlkit/encoder.pyi +55 -0
  36. controlkit/font5x7.py +22 -0
  37. controlkit/font5x7.pyi +11 -0
  38. controlkit/lamp_button.py +92 -0
  39. controlkit/lamp_button.pyi +40 -0
  40. controlkit/meter.py +86 -0
  41. controlkit/meter.pyi +30 -0
  42. controlkit/mock.py +116 -0
  43. controlkit/mock.pyi +35 -0
  44. controlkit/pad_grid.py +113 -0
  45. controlkit/pad_grid.pyi +41 -0
  46. controlkit/py.typed +0 -0
  47. controlkit/slider.py +185 -0
  48. controlkit/slider.pyi +49 -0
  49. controlkit/sprites.py +279 -0
  50. controlkit/sprites.pyi +22 -0
  51. controlkit/theme.py +120 -0
  52. controlkit/theme.pyi +15 -0
  53. deskkit/__init__.py +74 -0
  54. deskkit/__init__.pyi +18 -0
  55. deskkit/forecast.py +261 -0
  56. deskkit/forecast.pyi +40 -0
  57. deskkit/localtime.py +215 -0
  58. deskkit/localtime.pyi +33 -0
  59. deskkit/py.typed +0 -0
  60. deskkit/shell.py +113 -0
  61. deskkit/shell.pyi +33 -0
  62. omnipython_applibs-0.1.2.dev16.dist-info/METADATA +90 -0
  63. omnipython_applibs-0.1.2.dev16.dist-info/RECORD +143 -0
  64. omnipython_applibs-0.1.2.dev16.dist-info/WHEEL +5 -0
  65. omnipython_applibs-0.1.2.dev16.dist-info/licenses/LICENSE +21 -0
  66. omnipython_applibs-0.1.2.dev16.dist-info/top_level.txt +9 -0
  67. programkit/__init__.py +27 -0
  68. programkit/__init__.pyi +8 -0
  69. programkit/board.py +56 -0
  70. programkit/board.pyi +20 -0
  71. programkit/press.py +63 -0
  72. programkit/press.pyi +17 -0
  73. programkit/py.typed +0 -0
  74. programkit/rows.py +149 -0
  75. programkit/rows.pyi +34 -0
  76. sayso/__init__.py +109 -0
  77. sayso/__init__.pyi +124 -0
  78. sayso/auth.py +811 -0
  79. sayso/auth.pyi +102 -0
  80. sayso/client.py +1286 -0
  81. sayso/client.pyi +138 -0
  82. sayso/keepalive.py +371 -0
  83. sayso/keepalive.pyi +53 -0
  84. sayso/local.py +85 -0
  85. sayso/local.pyi +28 -0
  86. sayso/object_specs.py +706 -0
  87. sayso/object_specs.pyi +8 -0
  88. sayso/objects.py +411 -0
  89. sayso/objects.pyi +854 -0
  90. sayso/py.typed +0 -0
  91. sayso/schema_coverage.py +210 -0
  92. sayso/schema_coverage.pyi +13 -0
  93. sayso/transport.py +426 -0
  94. sayso/transport.pyi +47 -0
  95. songmodel/__init__.py +30 -0
  96. songmodel/__init__.pyi +9 -0
  97. songmodel/link.py +189 -0
  98. songmodel/link.pyi +53 -0
  99. songmodel/model.py +238 -0
  100. songmodel/model.pyi +40 -0
  101. songmodel/page.html +225 -0
  102. songmodel/page_data.py +236 -0
  103. songmodel/page_data.pyi +6 -0
  104. songmodel/py.typed +0 -0
  105. soundmodule/__init__.py +7 -0
  106. soundmodule/__init__.pyi +6 -0
  107. soundmodule/engine.py +1001 -0
  108. soundmodule/engine.pyi +196 -0
  109. soundmodule/names.py +298 -0
  110. soundmodule/names.pyi +30 -0
  111. soundmodule/pipes.py +105 -0
  112. soundmodule/pipes.pyi +31 -0
  113. soundmodule/py.typed +0 -0
  114. soundmodule/run.py +249 -0
  115. soundmodule/run.pyi +49 -0
  116. spectrum/__init__.py +72 -0
  117. spectrum/__init__.pyi +30 -0
  118. spectrum/analyzer.py +231 -0
  119. spectrum/analyzer.pyi +67 -0
  120. spectrum/fake_music.py +201 -0
  121. spectrum/fake_music.pyi +36 -0
  122. spectrum/pump_levels.py +126 -0
  123. spectrum/pump_levels.pyi +46 -0
  124. spectrum/py.typed +0 -0
  125. spectrum/spectrum_view.py +403 -0
  126. spectrum/spectrum_view.pyi +80 -0
  127. touchkit/__init__.py +4 -0
  128. touchkit/__init__.pyi +4 -0
  129. touchkit/cam.py +146 -0
  130. touchkit/cam.pyi +35 -0
  131. touchkit/clock.py +18 -0
  132. touchkit/clock.pyi +6 -0
  133. touchkit/ecp.py +134 -0
  134. touchkit/ecp.pyi +28 -0
  135. touchkit/net.py +347 -0
  136. touchkit/net.pyi +27 -0
  137. touchkit/py.typed +0 -0
  138. touchkit/settings.py +85 -0
  139. touchkit/settings.pyi +17 -0
  140. touchkit/shell.py +268 -0
  141. touchkit/shell.pyi +42 -0
  142. touchkit/ui.py +167 -0
  143. touchkit/ui.pyi +53 -0
songmodel/page.html ADDED
@@ -0,0 +1,225 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Ostinato</title>
7
+ <!--
8
+ The song page the Ostinato device serves (desktop/device.py). It is one
9
+ hmilink panel: it opens ws://<device>/ws, takes the song, and sends every
10
+ edit as a JSON Patch op. It applies an op only when the device sends it back
11
+ numbered, so it always has the device's order; a gap in the numbers means a
12
+ frame went missing or came late, and it asks for the whole song again.
13
+ -->
14
+ <style>
15
+ :root { --bg:#16181d; --panel:#1f2229; --line:#2c3039; --fg:#e6e6e6; --dim:#8a8f99; --on:#f0a030; --beat:#262a33; --play:#3fb950; }
16
+ @media (prefers-color-scheme: light) { :root { --bg:#f4f4f2; --panel:#fff; --line:#d8d8d4; --fg:#1d1d1d; --dim:#6b6b6b; --beat:#ececea; } }
17
+ * { box-sizing: border-box; }
18
+ body { margin:0; background:var(--bg); color:var(--fg); font:14px/1.4 system-ui, sans-serif; }
19
+ header { display:flex; flex-wrap:wrap; gap:12px; align-items:center; padding:12px 16px; background:var(--panel); border-bottom:1px solid var(--line); }
20
+ header h1 { font-size:16px; margin:0 8px 0 0; }
21
+ button { background:var(--beat); color:var(--fg); border:1px solid var(--line); border-radius:6px; padding:6px 12px; font:inherit; cursor:pointer; }
22
+ button.on { background:var(--play); color:#000; }
23
+ label { color:var(--dim); display:flex; gap:6px; align-items:center; }
24
+ input[type=number] { width:64px; background:var(--bg); color:var(--fg); border:1px solid var(--line); border-radius:4px; padding:4px; font:inherit; }
25
+ main { padding:12px 16px; display:grid; gap:16px; }
26
+ .tracks { display:grid; gap:6px; }
27
+ .track { display:grid; grid-template-columns: minmax(90px,1fr) auto minmax(80px,2fr); gap:10px; align-items:center; background:var(--panel); border:1px solid var(--line); border-radius:6px; padding:6px 10px; cursor:pointer; }
28
+ .track.sel { border-color:var(--on); }
29
+ .track small { color:var(--dim); display:block; }
30
+ .grid { overflow-x:auto; background:var(--panel); border:1px solid var(--line); border-radius:6px; padding:8px; }
31
+ .row { display:flex; gap:2px; margin-bottom:2px; align-items:center; }
32
+ .row span { width:40px; flex:none; color:var(--dim); font-size:12px; }
33
+ .cell { width:22px; height:22px; flex:none; border-radius:3px; background:var(--beat); border:1px solid var(--line); cursor:pointer; padding:0; }
34
+ .cell.bar { margin-left:6px; }
35
+ .cell.on { background:var(--on); }
36
+ .cell.head { outline:2px solid var(--play); }
37
+ #status { color:var(--dim); font-size:12px; margin-left:auto; }
38
+ </style>
39
+ </head>
40
+ <body>
41
+ <header>
42
+ <h1 id="name">Ostinato</h1>
43
+ <button id="play">Play</button>
44
+ <label>Tempo <input id="tempo" type="number" min="40" max="240" step="1"></label>
45
+ <label>Swing <input id="swing" type="number" min="0" max="100" step="1"></label>
46
+ <span id="status">connecting</span>
47
+ </header>
48
+ <main>
49
+ <div class="tracks" id="tracks"></div>
50
+ <div class="grid" id="grid"></div>
51
+ <div id="samples" style="color:var(--dim);font-size:12px"></div>
52
+ </main>
53
+ <script>
54
+ "use strict";
55
+ const DRUMS = [[49, "crash"], [46, "open hat"], [42, "hat"], [39, "clap"], [38, "snare"], [36, "kick"]];
56
+ const NAMES = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"];
57
+ const MELODIC = []; for (let p = 60; p >= 36; p--) MELODIC.push([p, NAMES[p % 12] + (Math.floor(p / 12) - 1)]);
58
+
59
+ let ws = null, doc = null, desc = {}, seq = 0, me = null, nextId = 1;
60
+ let sel = 0, playing = false, tick = null, syncing = false;
61
+ const stats = { ops: 0, resyncs: 0, order: 0 };
62
+ window.ostinato = { stats, get doc() { return doc; }, get seq() { return seq; }, send, command, get ready() { return doc !== null && !syncing; } };
63
+
64
+ function connect() {
65
+ ws = new WebSocket((location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/ws");
66
+ ws.onopen = () => { ws.send(JSON.stringify({ t: "hello", v: 1 })); status("connected"); };
67
+ ws.onmessage = (e) => { for (const line of String(e.data).split("\n")) if (line.trim()) handle(JSON.parse(line)); };
68
+ ws.onclose = () => { status("the device went away; trying again"); doc = null; setTimeout(connect, 1000); };
69
+ }
70
+
71
+ function status(s) { document.getElementById("status").textContent = s; }
72
+
73
+ function handle(m) {
74
+ if (m.t === "doc") {
75
+ doc = m.doc; desc = m.desc || {}; seq = m.seq; me = m.you; syncing = false;
76
+ if (sel >= doc.tracks.length) sel = 0;
77
+ render();
78
+ } else if (m.t === "op") {
79
+ if (doc === null || syncing) return;
80
+ if (m.seq !== seq + 1) {
81
+ // Not the next op: something was lost or came out of order. Take the
82
+ // whole song again rather than guess.
83
+ stats.order++; stats.resyncs++; syncing = true;
84
+ status("op " + m.seq + " came after " + seq + "; taking the song again");
85
+ ws.send(JSON.stringify({ t: "sync" }));
86
+ return;
87
+ }
88
+ seq = m.seq; stats.ops++;
89
+ apply(doc, m);
90
+ render();
91
+ } else if (m.t === "tele") {
92
+ const v = m.v || {};
93
+ playing = !!v.playing; tick = v.tick;
94
+ showTransport(); showHead();
95
+ } else if (m.t === "ev") {
96
+ if (m.name === "transport") { playing = !!m.playing; showTransport(); }
97
+ else if (m.name === "samples") { desc.samples = m.cost; showSamples(); }
98
+ } else if (m.t === "err") {
99
+ status("the device said no: " + m.msg);
100
+ }
101
+ }
102
+
103
+ // -- JSON Patch, the three ops hmilink uses --
104
+ function split(p) { return p.split("/").slice(1).map((k) => k.replace(/~1/g, "/").replace(/~0/g, "~")); }
105
+ function apply(root, op) {
106
+ const keys = split(op.path), last = keys.pop();
107
+ let node = root;
108
+ for (const k of keys) node = node[Array.isArray(node) ? +k : k];
109
+ if (Array.isArray(node)) {
110
+ if (op.op === "add") { if (last === "-") node.push(op.value); else node.splice(+last, 0, op.value); }
111
+ else if (op.op === "remove") node.splice(+last, 1);
112
+ else node[+last] = op.value;
113
+ } else if (op.op === "remove") delete node[last];
114
+ else node[last] = op.value;
115
+ }
116
+
117
+ function send(op, path, value) {
118
+ const m = { t: "op", op, path, id: nextId++ };
119
+ if (op !== "remove") m.value = value;
120
+ ws.send(JSON.stringify(m));
121
+ }
122
+ function command(name, args) { ws.send(JSON.stringify({ t: "cmd", name, args: Object.assign({ by: me }, args || {}) })); }
123
+
124
+ // -- the page --
125
+ function render() {
126
+ document.getElementById("name").textContent = doc.name || "Ostinato";
127
+ for (const k of ["tempo", "swing"]) {
128
+ const el = document.getElementById(k);
129
+ if (document.activeElement !== el) el.value = Math.round(doc[k]);
130
+ }
131
+ const box = document.getElementById("tracks");
132
+ box.textContent = "";
133
+ doc.tracks.forEach((t, i) => {
134
+ const row = document.createElement("div");
135
+ row.className = "track" + (i === sel ? " sel" : "");
136
+ row.dataset.track = i;
137
+ row.innerHTML = "<div><b></b><small></small></div>";
138
+ row.querySelector("b").textContent = t.name;
139
+ row.querySelector("small").textContent = t.instrument + (t.instrument.startsWith("soundfont") ? " " + t.patch : "");
140
+ const mute = document.createElement("button");
141
+ mute.textContent = "Mute"; mute.className = "mute" + (t.mute ? " on" : "");
142
+ mute.onclick = (e) => { e.stopPropagation(); send("replace", "/tracks/" + i + "/mute", !t.mute); };
143
+ const vol = document.createElement("input");
144
+ vol.type = "range"; vol.min = 0; vol.max = 127; vol.value = t.volume; vol.className = "volume";
145
+ vol.onclick = (e) => e.stopPropagation();
146
+ vol.oninput = throttle(() => send("replace", "/tracks/" + i + "/volume", +vol.value), 50);
147
+ row.append(mute, vol);
148
+ row.onclick = () => { sel = i; render(); };
149
+ box.append(row);
150
+ });
151
+ renderGrid(); showTransport(); showSamples();
152
+ }
153
+
154
+ function shown(t) { return t.next ? t.next.pattern : (t.current || 0); }
155
+
156
+ function renderGrid() {
157
+ const grid = document.getElementById("grid");
158
+ grid.textContent = "";
159
+ const t = doc.tracks[sel];
160
+ if (!t) return;
161
+ const p = shown(t), pat = t.patterns[p], step = desc.step || 24, steps = pat.bars * 16;
162
+ const rows = t.kind === "drums" ? DRUMS : MELODIC;
163
+ for (const [pitch, label] of rows) {
164
+ const row = document.createElement("div");
165
+ row.className = "row";
166
+ const name = document.createElement("span"); name.textContent = label; row.append(name);
167
+ for (let s = 0; s < steps; s++) {
168
+ const c = document.createElement("button");
169
+ const at = pat.notes.findIndex((n) => n[0] === s * step && n[2] === pitch);
170
+ c.className = "cell" + (s % 16 === 0 && s ? " bar" : "") + (at >= 0 ? " on" : "");
171
+ c.dataset.step = s; c.dataset.pitch = pitch;
172
+ c.style.opacity = s % 4 === 0 ? 1 : 0.8;
173
+ c.onclick = () => {
174
+ const base = "/tracks/" + sel + "/patterns/" + p + "/notes/";
175
+ const i = pat.notes.findIndex((n) => n[0] === s * step && n[2] === pitch);
176
+ if (i >= 0) send("remove", base + i);
177
+ else send("add", base + "-", [s * step, step, pitch, 100]);
178
+ };
179
+ row.append(c);
180
+ }
181
+ grid.append(row);
182
+ }
183
+ showHead();
184
+ }
185
+
186
+ function showTransport() {
187
+ const b = document.getElementById("play");
188
+ b.textContent = playing ? "Stop" : "Play";
189
+ b.classList.toggle("on", playing);
190
+ }
191
+
192
+ function showHead() {
193
+ for (const c of document.querySelectorAll(".cell.head")) c.classList.remove("head");
194
+ const t = doc && doc.tracks[sel];
195
+ if (!playing || tick == null || !t) return;
196
+ const pat = t.patterns[shown(t)], step = desc.step || 24;
197
+ const s = Math.floor(tick / step) % (pat.bars * 16);
198
+ for (const c of document.querySelectorAll('.cell[data-step="' + s + '"]')) c.classList.add("head");
199
+ }
200
+
201
+ function showSamples() {
202
+ const s = desc.samples, el = document.getElementById("samples");
203
+ if (!s || !s.bytes) { el.textContent = ""; return; }
204
+ const n = Object.values(s.tracks).reduce((a, t) => a + t.samples, 0);
205
+ el.textContent = "SoundFont samples in memory: " + n + ", " + (s.bytes / 1048576).toFixed(1) + " MB" +
206
+ (s.arena ? " of a " + Math.round(s.arena / 1048576) + " MB arena" : "");
207
+ }
208
+
209
+ function throttle(fn, ms) {
210
+ let last = 0, timer = null;
211
+ return () => {
212
+ const now = Date.now();
213
+ clearTimeout(timer);
214
+ if (now - last >= ms) { last = now; fn(); } else timer = setTimeout(() => { last = Date.now(); fn(); }, ms);
215
+ };
216
+ }
217
+
218
+ document.getElementById("play").onclick = () => command(playing ? "stop" : "play", { tick: 0 });
219
+ for (const k of ["tempo", "swing"]) {
220
+ document.getElementById(k).onchange = (e) => send("replace", "/" + k, +e.target.value);
221
+ }
222
+ connect();
223
+ </script>
224
+ </body>
225
+ </html>
songmodel/page_data.py ADDED
@@ -0,0 +1,236 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ """The front panel page, as ``songmodel.page()`` serves it.
6
+
7
+ Generated by tools/songmodel_page.py from page.html: edit that, not this.
8
+ """
9
+
10
+ HTML = (
11
+ '<!doctype html>\n'
12
+ '<html lang="en">\n'
13
+ '<head>\n'
14
+ '<meta charset="utf-8">\n'
15
+ '<meta name="viewport" content="width=device-width, initial-scale=1">\n'
16
+ '<title>Ostinato</title>\n'
17
+ '<!--\n'
18
+ ' The song page the Ostinato device serves (desktop/device.py). It is one\n'
19
+ ' hmilink panel: it opens ws://<device>/ws, takes the song, and sends every\n'
20
+ ' edit as a JSON Patch op. It applies an op only when the device sends it back\n'
21
+ " numbered, so it always has the device's order; a gap in the numbers means a\n"
22
+ ' frame went missing or came late, and it asks for the whole song again.\n'
23
+ '-->\n'
24
+ '<style>\n'
25
+ ':root { --bg:#16181d; --panel:#1f2229; --line:#2c3039; --fg:#e6e6e6; --dim:#8a8f99; --on:#f0a030; --beat:#262a33; --play:#3fb950; }\n'
26
+ '@media (prefers-color-scheme: light) { :root { --bg:#f4f4f2; --panel:#fff; --line:#d8d8d4; --fg:#1d1d1d; --dim:#6b6b6b; --beat:#ececea; } }\n'
27
+ '* { box-sizing: border-box; }\n'
28
+ 'body { margin:0; background:var(--bg); color:var(--fg); font:14px/1.4 system-ui, sans-serif; }\n'
29
+ 'header { display:flex; flex-wrap:wrap; gap:12px; align-items:center; padding:12px 16px; background:var(--panel); border-bottom:1px solid var(--line); }\n'
30
+ 'header h1 { font-size:16px; margin:0 8px 0 0; }\n'
31
+ 'button { background:var(--beat); color:var(--fg); border:1px solid var(--line); border-radius:6px; padding:6px 12px; font:inherit; cursor:pointer; }\n'
32
+ 'button.on { background:var(--play); color:#000; }\n'
33
+ 'label { color:var(--dim); display:flex; gap:6px; align-items:center; }\n'
34
+ 'input[type=number] { width:64px; background:var(--bg); color:var(--fg); border:1px solid var(--line); border-radius:4px; padding:4px; font:inherit; }\n'
35
+ 'main { padding:12px 16px; display:grid; gap:16px; }\n'
36
+ '.tracks { display:grid; gap:6px; }\n'
37
+ '.track { display:grid; grid-template-columns: minmax(90px,1fr) auto minmax(80px,2fr); gap:10px; align-items:center; background:var(--panel); border:1px solid var(--line); border-radius:6px; padding:6px 10px; cursor:pointer; }\n'
38
+ '.track.sel { border-color:var(--on); }\n'
39
+ '.track small { color:var(--dim); display:block; }\n'
40
+ '.grid { overflow-x:auto; background:var(--panel); border:1px solid var(--line); border-radius:6px; padding:8px; }\n'
41
+ '.row { display:flex; gap:2px; margin-bottom:2px; align-items:center; }\n'
42
+ '.row span { width:40px; flex:none; color:var(--dim); font-size:12px; }\n'
43
+ '.cell { width:22px; height:22px; flex:none; border-radius:3px; background:var(--beat); border:1px solid var(--line); cursor:pointer; padding:0; }\n'
44
+ '.cell.bar { margin-left:6px; }\n'
45
+ '.cell.on { background:var(--on); }\n'
46
+ '.cell.head { outline:2px solid var(--play); }\n'
47
+ '#status { color:var(--dim); font-size:12px; margin-left:auto; }\n'
48
+ '</style>\n'
49
+ '</head>\n'
50
+ '<body>\n'
51
+ '<header>\n'
52
+ ' <h1 id="name">Ostinato</h1>\n'
53
+ ' <button id="play">Play</button>\n'
54
+ ' <label>Tempo <input id="tempo" type="number" min="40" max="240" step="1"></label>\n'
55
+ ' <label>Swing <input id="swing" type="number" min="0" max="100" step="1"></label>\n'
56
+ ' <span id="status">connecting</span>\n'
57
+ '</header>\n'
58
+ '<main>\n'
59
+ ' <div class="tracks" id="tracks"></div>\n'
60
+ ' <div class="grid" id="grid"></div>\n'
61
+ ' <div id="samples" style="color:var(--dim);font-size:12px"></div>\n'
62
+ '</main>\n'
63
+ '<script>\n'
64
+ '"use strict";\n'
65
+ 'const DRUMS = [[49, "crash"], [46, "open hat"], [42, "hat"], [39, "clap"], [38, "snare"], [36, "kick"]];\n'
66
+ 'const NAMES = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"];\n'
67
+ 'const MELODIC = []; for (let p = 60; p >= 36; p--) MELODIC.push([p, NAMES[p % 12] + (Math.floor(p / 12) - 1)]);\n'
68
+ '\n'
69
+ 'let ws = null, doc = null, desc = {}, seq = 0, me = null, nextId = 1;\n'
70
+ 'let sel = 0, playing = false, tick = null, syncing = false;\n'
71
+ 'const stats = { ops: 0, resyncs: 0, order: 0 };\n'
72
+ 'window.ostinato = { stats, get doc() { return doc; }, get seq() { return seq; }, send, command, get ready() { return doc !== null && !syncing; } };\n'
73
+ '\n'
74
+ 'function connect() {\n'
75
+ ' ws = new WebSocket((location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/ws");\n'
76
+ ' ws.onopen = () => { ws.send(JSON.stringify({ t: "hello", v: 1 })); status("connected"); };\n'
77
+ ' ws.onmessage = (e) => { for (const line of String(e.data).split("\\n")) if (line.trim()) handle(JSON.parse(line)); };\n'
78
+ ' ws.onclose = () => { status("the device went away; trying again"); doc = null; setTimeout(connect, 1000); };\n'
79
+ '}\n'
80
+ '\n'
81
+ 'function status(s) { document.getElementById("status").textContent = s; }\n'
82
+ '\n'
83
+ 'function handle(m) {\n'
84
+ ' if (m.t === "doc") {\n'
85
+ ' doc = m.doc; desc = m.desc || {}; seq = m.seq; me = m.you; syncing = false;\n'
86
+ ' if (sel >= doc.tracks.length) sel = 0;\n'
87
+ ' render();\n'
88
+ ' } else if (m.t === "op") {\n'
89
+ ' if (doc === null || syncing) return;\n'
90
+ ' if (m.seq !== seq + 1) {\n'
91
+ ' // Not the next op: something was lost or came out of order. Take the\n'
92
+ ' // whole song again rather than guess.\n'
93
+ ' stats.order++; stats.resyncs++; syncing = true;\n'
94
+ ' status("op " + m.seq + " came after " + seq + "; taking the song again");\n'
95
+ ' ws.send(JSON.stringify({ t: "sync" }));\n'
96
+ ' return;\n'
97
+ ' }\n'
98
+ ' seq = m.seq; stats.ops++;\n'
99
+ ' apply(doc, m);\n'
100
+ ' render();\n'
101
+ ' } else if (m.t === "tele") {\n'
102
+ ' const v = m.v || {};\n'
103
+ ' playing = !!v.playing; tick = v.tick;\n'
104
+ ' showTransport(); showHead();\n'
105
+ ' } else if (m.t === "ev") {\n'
106
+ ' if (m.name === "transport") { playing = !!m.playing; showTransport(); }\n'
107
+ ' else if (m.name === "samples") { desc.samples = m.cost; showSamples(); }\n'
108
+ ' } else if (m.t === "err") {\n'
109
+ ' status("the device said no: " + m.msg);\n'
110
+ ' }\n'
111
+ '}\n'
112
+ '\n'
113
+ '// -- JSON Patch, the three ops hmilink uses --\n'
114
+ 'function split(p) { return p.split("/").slice(1).map((k) => k.replace(/~1/g, "/").replace(/~0/g, "~")); }\n'
115
+ 'function apply(root, op) {\n'
116
+ ' const keys = split(op.path), last = keys.pop();\n'
117
+ ' let node = root;\n'
118
+ ' for (const k of keys) node = node[Array.isArray(node) ? +k : k];\n'
119
+ ' if (Array.isArray(node)) {\n'
120
+ ' if (op.op === "add") { if (last === "-") node.push(op.value); else node.splice(+last, 0, op.value); }\n'
121
+ ' else if (op.op === "remove") node.splice(+last, 1);\n'
122
+ ' else node[+last] = op.value;\n'
123
+ ' } else if (op.op === "remove") delete node[last];\n'
124
+ ' else node[last] = op.value;\n'
125
+ '}\n'
126
+ '\n'
127
+ 'function send(op, path, value) {\n'
128
+ ' const m = { t: "op", op, path, id: nextId++ };\n'
129
+ ' if (op !== "remove") m.value = value;\n'
130
+ ' ws.send(JSON.stringify(m));\n'
131
+ '}\n'
132
+ 'function command(name, args) { ws.send(JSON.stringify({ t: "cmd", name, args: Object.assign({ by: me }, args || {}) })); }\n'
133
+ '\n'
134
+ '// -- the page --\n'
135
+ 'function render() {\n'
136
+ ' document.getElementById("name").textContent = doc.name || "Ostinato";\n'
137
+ ' for (const k of ["tempo", "swing"]) {\n'
138
+ ' const el = document.getElementById(k);\n'
139
+ ' if (document.activeElement !== el) el.value = Math.round(doc[k]);\n'
140
+ ' }\n'
141
+ ' const box = document.getElementById("tracks");\n'
142
+ ' box.textContent = "";\n'
143
+ ' doc.tracks.forEach((t, i) => {\n'
144
+ ' const row = document.createElement("div");\n'
145
+ ' row.className = "track" + (i === sel ? " sel" : "");\n'
146
+ ' row.dataset.track = i;\n'
147
+ ' row.innerHTML = "<div><b></b><small></small></div>";\n'
148
+ ' row.querySelector("b").textContent = t.name;\n'
149
+ ' row.querySelector("small").textContent = t.instrument + (t.instrument.startsWith("soundfont") ? " " + t.patch : "");\n'
150
+ ' const mute = document.createElement("button");\n'
151
+ ' mute.textContent = "Mute"; mute.className = "mute" + (t.mute ? " on" : "");\n'
152
+ ' mute.onclick = (e) => { e.stopPropagation(); send("replace", "/tracks/" + i + "/mute", !t.mute); };\n'
153
+ ' const vol = document.createElement("input");\n'
154
+ ' vol.type = "range"; vol.min = 0; vol.max = 127; vol.value = t.volume; vol.className = "volume";\n'
155
+ ' vol.onclick = (e) => e.stopPropagation();\n'
156
+ ' vol.oninput = throttle(() => send("replace", "/tracks/" + i + "/volume", +vol.value), 50);\n'
157
+ ' row.append(mute, vol);\n'
158
+ ' row.onclick = () => { sel = i; render(); };\n'
159
+ ' box.append(row);\n'
160
+ ' });\n'
161
+ ' renderGrid(); showTransport(); showSamples();\n'
162
+ '}\n'
163
+ '\n'
164
+ 'function shown(t) { return t.next ? t.next.pattern : (t.current || 0); }\n'
165
+ '\n'
166
+ 'function renderGrid() {\n'
167
+ ' const grid = document.getElementById("grid");\n'
168
+ ' grid.textContent = "";\n'
169
+ ' const t = doc.tracks[sel];\n'
170
+ ' if (!t) return;\n'
171
+ ' const p = shown(t), pat = t.patterns[p], step = desc.step || 24, steps = pat.bars * 16;\n'
172
+ ' const rows = t.kind === "drums" ? DRUMS : MELODIC;\n'
173
+ ' for (const [pitch, label] of rows) {\n'
174
+ ' const row = document.createElement("div");\n'
175
+ ' row.className = "row";\n'
176
+ ' const name = document.createElement("span"); name.textContent = label; row.append(name);\n'
177
+ ' for (let s = 0; s < steps; s++) {\n'
178
+ ' const c = document.createElement("button");\n'
179
+ ' const at = pat.notes.findIndex((n) => n[0] === s * step && n[2] === pitch);\n'
180
+ ' c.className = "cell" + (s % 16 === 0 && s ? " bar" : "") + (at >= 0 ? " on" : "");\n'
181
+ ' c.dataset.step = s; c.dataset.pitch = pitch;\n'
182
+ ' c.style.opacity = s % 4 === 0 ? 1 : 0.8;\n'
183
+ ' c.onclick = () => {\n'
184
+ ' const base = "/tracks/" + sel + "/patterns/" + p + "/notes/";\n'
185
+ ' const i = pat.notes.findIndex((n) => n[0] === s * step && n[2] === pitch);\n'
186
+ ' if (i >= 0) send("remove", base + i);\n'
187
+ ' else send("add", base + "-", [s * step, step, pitch, 100]);\n'
188
+ ' };\n'
189
+ ' row.append(c);\n'
190
+ ' }\n'
191
+ ' grid.append(row);\n'
192
+ ' }\n'
193
+ ' showHead();\n'
194
+ '}\n'
195
+ '\n'
196
+ 'function showTransport() {\n'
197
+ ' const b = document.getElementById("play");\n'
198
+ ' b.textContent = playing ? "Stop" : "Play";\n'
199
+ ' b.classList.toggle("on", playing);\n'
200
+ '}\n'
201
+ '\n'
202
+ 'function showHead() {\n'
203
+ ' for (const c of document.querySelectorAll(".cell.head")) c.classList.remove("head");\n'
204
+ ' const t = doc && doc.tracks[sel];\n'
205
+ ' if (!playing || tick == null || !t) return;\n'
206
+ ' const pat = t.patterns[shown(t)], step = desc.step || 24;\n'
207
+ ' const s = Math.floor(tick / step) % (pat.bars * 16);\n'
208
+ ' for (const c of document.querySelectorAll(\'.cell[data-step="\' + s + \'"]\')) c.classList.add("head");\n'
209
+ '}\n'
210
+ '\n'
211
+ 'function showSamples() {\n'
212
+ ' const s = desc.samples, el = document.getElementById("samples");\n'
213
+ ' if (!s || !s.bytes) { el.textContent = ""; return; }\n'
214
+ ' const n = Object.values(s.tracks).reduce((a, t) => a + t.samples, 0);\n'
215
+ ' el.textContent = "SoundFont samples in memory: " + n + ", " + (s.bytes / 1048576).toFixed(1) + " MB" +\n'
216
+ ' (s.arena ? " of a " + Math.round(s.arena / 1048576) + " MB arena" : "");\n'
217
+ '}\n'
218
+ '\n'
219
+ 'function throttle(fn, ms) {\n'
220
+ ' let last = 0, timer = null;\n'
221
+ ' return () => {\n'
222
+ ' const now = Date.now();\n'
223
+ ' clearTimeout(timer);\n'
224
+ ' if (now - last >= ms) { last = now; fn(); } else timer = setTimeout(() => { last = Date.now(); fn(); }, ms);\n'
225
+ ' };\n'
226
+ '}\n'
227
+ '\n'
228
+ 'document.getElementById("play").onclick = () => command(playing ? "stop" : "play", { tick: 0 });\n'
229
+ 'for (const k of ["tempo", "swing"]) {\n'
230
+ ' document.getElementById(k).onchange = (e) => send("replace", "/" + k, +e.target.value);\n'
231
+ '}\n'
232
+ 'connect();\n'
233
+ '</script>\n'
234
+ '</body>\n'
235
+ '</html>\n'
236
+ )
@@ -0,0 +1,6 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """The front panel page, as `songmodel.page()` serves it."""
5
+
6
+ HTML: str
songmodel/py.typed ADDED
File without changes
@@ -0,0 +1,7 @@
1
+ # SPDX-FileCopyrightText: 2026 PyDevices
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """The sound module: ``engine`` plays MIDI, ``run`` serves it headless from
5
+ a port, ``pipes`` carries MIDI through files."""
6
+
7
+ __version__ = "0.1.0"
@@ -0,0 +1,6 @@
1
+ # SPDX-FileCopyrightText: 2026 PyDevices
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """The sound module: `engine` plays MIDI, `run` serves it headless from a port, `pipes` carries MIDI through files."""
5
+
6
+ __version__: str