@avoid.quest/audio 0.1.0 → 0.1.1-beta.1
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.
- package/README.md +32 -2
- package/dist/effects/index.d.ts +21 -72
- package/dist/effects/index.js +212 -505
- package/dist/effects/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/midi/index.d.ts +0 -24
- package/dist/midi/index.js +222 -258
- package/dist/midi/index.js.map +1 -1
- package/dist/native-Bern4_PB.js +172 -0
- package/dist/native-Bern4_PB.js.map +1 -0
- package/dist/pcm-buffer-DSzGHbon.js +436 -0
- package/dist/pcm-buffer-DSzGHbon.js.map +1 -0
- package/dist/playback/index.d.ts +63 -115
- package/dist/playback/index.js +906 -1062
- package/dist/playback/index.js.map +1 -1
- package/dist/queue/index.d.ts +8 -19
- package/dist/queue/index.js +461 -960
- package/dist/queue/index.js.map +1 -1
- package/dist/recognize/index.d.ts +37 -74
- package/dist/recognize/index.js +172 -2715
- package/dist/recognize/index.js.map +1 -1
- package/dist/routing/index.d.ts +3 -34
- package/dist/routing/index.js +413 -536
- package/dist/routing/index.js.map +1 -1
- package/dist/shazam-gBrX1NEY.d.ts +27 -0
- package/dist/sync/index.d.ts +9 -77
- package/dist/sync/index.js +320 -542
- package/dist/sync/index.js.map +1 -1
- package/dist/{worklet-loader-BvEW0oVO.d.ts → worklet-loader-BabwPALw.d.ts} +4 -7
- package/dist/{worklet-loader-S7R8ZAmP.js → worklet-loader-f741D1tk.js} +37 -52
- package/dist/worklet-loader-f741D1tk.js.map +1 -0
- package/dist/worklets/couch-live.js +110 -192
- package/dist/worklets/couch-live.js.map +1 -1
- package/dist/worklets/meter.js +14 -20
- package/dist/worklets/meter.js.map +1 -1
- package/dist/worklets/pcm-capture.d.ts +6 -0
- package/dist/worklets/pcm-capture.js +52 -0
- package/dist/worklets/pcm-capture.js.map +1 -0
- package/package.json +18 -4
- package/types/hls-unavailable.d.ts +4 -0
- package/dist/worklet-loader-S7R8ZAmP.js.map +0 -1
package/dist/midi/index.js
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
import { Effect, Schema, Scope } from "effect";
|
|
2
2
|
import { i as AudioMidiError } from "../errors-BT9HxDLn.js";
|
|
3
|
+
// src/midi/access.ts
|
|
4
|
+
const MIDI_BUTTON_DEBOUNCE_MS = 50;
|
|
5
|
+
const MIDI_CONTINUOUS_COALESCE_MS = 33;
|
|
6
|
+
function listMidiDevices(access) {
|
|
7
|
+
return access ? [...access.inputs.values()].map((i) => ({
|
|
8
|
+
id: i.id,
|
|
9
|
+
manufacturer: i.manufacturer ?? "",
|
|
10
|
+
name: i.name ?? i.id,
|
|
11
|
+
state: i.state ?? "connected"
|
|
12
|
+
})) : [];
|
|
13
|
+
}
|
|
14
|
+
function openMidiInputSafely(input, isStillAttached) {
|
|
15
|
+
if (typeof input.open !== "function") return;
|
|
16
|
+
(async () => {
|
|
17
|
+
try {
|
|
18
|
+
await input.open?.();
|
|
19
|
+
if (!isStillAttached()) await input.close?.();
|
|
20
|
+
} catch {}
|
|
21
|
+
})();
|
|
22
|
+
}
|
|
23
|
+
function requestMidiAccess(options = {}) {
|
|
24
|
+
return Effect.tryPromise({
|
|
25
|
+
catch: (error) => {
|
|
26
|
+
if (error instanceof AudioMidiError) return error;
|
|
27
|
+
const name = error instanceof Error ? error.name : "";
|
|
28
|
+
return new AudioMidiError({
|
|
29
|
+
code: name === "SecurityError" || name === "NotAllowedError" ? "PERMISSION_DENIED" : "ACCESS_FAILED",
|
|
30
|
+
message: `Web MIDI access failed: ${String(error)}`
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
try: async () => {
|
|
34
|
+
const nav = globalThis.navigator;
|
|
35
|
+
const req = options.requestMIDIAccess ?? nav?.requestMIDIAccess?.bind(nav);
|
|
36
|
+
if (typeof req !== "function") throw new AudioMidiError({
|
|
37
|
+
code: "UNSUPPORTED",
|
|
38
|
+
message: "Web MIDI API is not supported."
|
|
39
|
+
});
|
|
40
|
+
return await req({ sysex: options.sysex ?? false });
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
3
44
|
// src/midi/parser.ts
|
|
4
45
|
const MIDI_STATUS_NOTE_OFF = 128;
|
|
5
46
|
const MIDI_STATUS_NOTE_ON = 144;
|
|
@@ -9,27 +50,22 @@ const MidiMessageTypeSchema = Schema.Literals([
|
|
|
9
50
|
"note-on",
|
|
10
51
|
"note-off"
|
|
11
52
|
]);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
53
|
+
const STATUS_TO_TYPE = {
|
|
54
|
+
[176]: "cc",
|
|
55
|
+
[128]: "note-off",
|
|
56
|
+
[144]: "note-on"
|
|
57
|
+
};
|
|
16
58
|
function parseMidiMessage(data) {
|
|
17
59
|
if (data.length < 3) return;
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const valueByte = (data[2] ?? 0) & 127;
|
|
21
|
-
const statusType = statusByte & 240;
|
|
22
|
-
const channel = statusByte & 15;
|
|
23
|
-
let type;
|
|
24
|
-
if (statusType === 176) type = "cc";
|
|
25
|
-
else if (statusType === 144) type = "note-on";
|
|
26
|
-
else if (statusType === 128) type = "note-off";
|
|
60
|
+
const status = data[0] ?? 0;
|
|
61
|
+
const type = STATUS_TO_TYPE[status & 240];
|
|
27
62
|
if (type === void 0) return;
|
|
63
|
+
const rawValue = (data[2] ?? 0) & 127;
|
|
28
64
|
return {
|
|
29
|
-
channel,
|
|
30
|
-
control:
|
|
31
|
-
normalized:
|
|
32
|
-
rawValue
|
|
65
|
+
channel: status & 15,
|
|
66
|
+
control: (data[1] ?? 0) & 127,
|
|
67
|
+
normalized: rawValue / 127,
|
|
68
|
+
rawValue,
|
|
33
69
|
type
|
|
34
70
|
};
|
|
35
71
|
}
|
|
@@ -70,267 +106,195 @@ const MidiBindingSetSchema = Schema.Struct({
|
|
|
70
106
|
function formatMidiBindingKey(scope, channel, control, messageType) {
|
|
71
107
|
return `${scope}:${channel}:${control}:${messageType}`;
|
|
72
108
|
}
|
|
73
|
-
/**
|
|
74
|
-
* Applies the MIDI value transform pipeline (`rawValue` in `0..127`):
|
|
75
|
-
* 1. Normalize to `[0, 1]`
|
|
76
|
-
* 2. Optional `invert` (`1 - v`)
|
|
77
|
-
* 3. Curve (`linear`, `log`: `Math.log1p(v * (Math.E - 1))`, `exp`: `(Math.exp(v) - 1) / (Math.E - 1)`)
|
|
78
|
-
* 4. Linear map to `[min, max]` and clamp to `[min(min, max), max(min, max)]`.
|
|
79
|
-
*/
|
|
80
109
|
function applyMidiTransform(rawValue, transform) {
|
|
81
110
|
let v = Math.max(0, Math.min(127, rawValue)) / 127;
|
|
82
111
|
if (transform.invert) v = 1 - v;
|
|
83
|
-
|
|
84
|
-
if (curve === "
|
|
85
|
-
else if (curve === "exp") v = (Math.exp(v) - 1) / (Math.E - 1);
|
|
112
|
+
if (transform.curve === "log") v = v <= 0 ? 0 : Math.log1p(v * (Math.E - 1));
|
|
113
|
+
else if (transform.curve === "exp") v = (Math.exp(v) - 1) / (Math.E - 1);
|
|
86
114
|
const mapped = transform.min + v * (transform.max - transform.min);
|
|
87
|
-
|
|
88
|
-
const hi = Math.max(transform.min, transform.max);
|
|
89
|
-
return Math.max(lo, Math.min(hi, mapped));
|
|
115
|
+
return Math.max(Math.min(transform.min, transform.max), Math.min(Math.max(transform.min, transform.max), mapped));
|
|
90
116
|
}
|
|
91
117
|
// src/midi/controller.ts
|
|
92
|
-
const MIDI_BUTTON_DEBOUNCE_MS = 50;
|
|
93
|
-
const MIDI_CONTINUOUS_COALESCE_MS = 33;
|
|
94
118
|
const decodeMidiBindingSet = Schema.decodeUnknownEffect(MidiBindingSetSchema);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
119
|
+
const isIgnoredBtn = (m) => m.type === "note-off" || m.rawValue === 0;
|
|
120
|
+
function buildMidiController(options = {}) {
|
|
121
|
+
const debounceMs = options.buttonDebounceMs ?? 50;
|
|
122
|
+
const coalesceMs = options.continuousCoalesceMs ?? 33;
|
|
123
|
+
const now = options.now ?? (() => Date.now());
|
|
124
|
+
let activeScope = options.activeScope ?? "global";
|
|
125
|
+
let midiAccess;
|
|
126
|
+
let stateListener;
|
|
127
|
+
const attached = /* @__PURE__ */ new Map();
|
|
128
|
+
const bindings = /* @__PURE__ */ new Map();
|
|
129
|
+
const lastBtnMs = /* @__PURE__ */ new Map();
|
|
130
|
+
const pendingCont = /* @__PURE__ */ new Map();
|
|
131
|
+
let learnReq;
|
|
132
|
+
let lastFlushMs = 0;
|
|
133
|
+
let flushTimer;
|
|
134
|
+
let rafHandle;
|
|
135
|
+
const cancelFlush = () => {
|
|
136
|
+
if (flushTimer !== void 0) {
|
|
137
|
+
clearTimeout(flushTimer);
|
|
138
|
+
flushTimer = void 0;
|
|
115
139
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
function createMidiController(options = {}) {
|
|
140
|
-
return Effect.gen(function* () {
|
|
141
|
-
const buttonDebounceMs = options.buttonDebounceMs ?? 50;
|
|
142
|
-
const continuousCoalesceMs = options.continuousCoalesceMs ?? 33;
|
|
143
|
-
const now = options.now ?? (() => Date.now());
|
|
144
|
-
let activeScope = options.activeScope ?? "global";
|
|
145
|
-
let midiAccess;
|
|
146
|
-
let stateChangeListener;
|
|
147
|
-
const attachedInputs = /* @__PURE__ */ new Map();
|
|
148
|
-
const bindings = /* @__PURE__ */ new Map();
|
|
149
|
-
const lastButtonTriggerMs = /* @__PURE__ */ new Map();
|
|
150
|
-
const pendingContinuous = /* @__PURE__ */ new Map();
|
|
151
|
-
let learnRequest;
|
|
152
|
-
let lastFlushMs = 0;
|
|
153
|
-
let flushTimer;
|
|
154
|
-
let rafHandle;
|
|
155
|
-
const cancelScheduledFlush = () => {
|
|
156
|
-
if (flushTimer !== void 0) {
|
|
157
|
-
clearTimeout(flushTimer);
|
|
158
|
-
flushTimer = void 0;
|
|
159
|
-
}
|
|
160
|
-
if (rafHandle !== void 0 && typeof globalThis.cancelAnimationFrame === "function") {
|
|
161
|
-
globalThis.cancelAnimationFrame(rafHandle);
|
|
162
|
-
rafHandle = void 0;
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
const flushContinuous = () => {
|
|
166
|
-
cancelScheduledFlush();
|
|
167
|
-
if (pendingContinuous.size === 0) return 0;
|
|
168
|
-
const batch = [...pendingContinuous.values()];
|
|
169
|
-
pendingContinuous.clear();
|
|
170
|
-
lastFlushMs = now();
|
|
171
|
-
for (const event of batch) options.onContinuous?.(event);
|
|
172
|
-
return batch.length;
|
|
140
|
+
if (rafHandle !== void 0) {
|
|
141
|
+
globalThis.cancelAnimationFrame?.(rafHandle);
|
|
142
|
+
rafHandle = void 0;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const flushContinuous = () => {
|
|
146
|
+
cancelFlush();
|
|
147
|
+
if (pendingCont.size === 0) return 0;
|
|
148
|
+
const batch = [...pendingCont.values()];
|
|
149
|
+
pendingCont.clear();
|
|
150
|
+
lastFlushMs = now();
|
|
151
|
+
for (const ev of batch) options.onContinuous?.(ev);
|
|
152
|
+
return batch.length;
|
|
153
|
+
};
|
|
154
|
+
const scheduleFlush = () => {
|
|
155
|
+
if (flushTimer !== void 0 || rafHandle !== void 0) return;
|
|
156
|
+
const delay = Math.max(0, coalesceMs - (now() - lastFlushMs));
|
|
157
|
+
const tick = () => {
|
|
158
|
+
flushTimer = void 0;
|
|
159
|
+
rafHandle = void 0;
|
|
160
|
+
if (pendingCont.size === 0) return;
|
|
161
|
+
if (now() - lastFlushMs >= coalesceMs) flushContinuous();
|
|
162
|
+
else scheduleFlush();
|
|
173
163
|
};
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
164
|
+
if (delay === 0 && typeof globalThis.requestAnimationFrame === "function") rafHandle = globalThis.requestAnimationFrame(tick);
|
|
165
|
+
else flushTimer = setTimeout(tick, Math.max(1, delay));
|
|
166
|
+
};
|
|
167
|
+
const bind = (b) => {
|
|
168
|
+
bindings.set(formatMidiBindingKey(b.scope, b.channel, b.control, b.messageType), b);
|
|
169
|
+
};
|
|
170
|
+
const lookup = (m) => bindings.get(formatMidiBindingKey(activeScope, m.channel, m.control, m.type)) ?? (activeScope === "global" ? void 0 : bindings.get(formatMidiBindingKey("global", m.channel, m.control, m.type)));
|
|
171
|
+
const handleRawMessage = (data, inputId) => {
|
|
172
|
+
const message = parseMidiMessage(data);
|
|
173
|
+
if (!message) return;
|
|
174
|
+
options.onMessage?.(message, inputId);
|
|
175
|
+
if (learnReq) {
|
|
176
|
+
if (learnReq.actionKind === "button" && isIgnoredBtn(message)) return;
|
|
177
|
+
const req = learnReq;
|
|
178
|
+
learnReq = void 0;
|
|
179
|
+
const learned = {
|
|
180
|
+
actionKind: req.actionKind,
|
|
181
|
+
channel: message.channel,
|
|
182
|
+
control: message.control,
|
|
183
|
+
messageType: message.type,
|
|
184
|
+
scope: req.scope,
|
|
185
|
+
targetId: req.targetId,
|
|
186
|
+
transform: req.transform,
|
|
187
|
+
version: 2
|
|
184
188
|
};
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
control: message.control,
|
|
200
|
-
messageType: message.type,
|
|
201
|
-
scope: request.scope,
|
|
202
|
-
targetId: request.targetId,
|
|
203
|
-
transform: request.transform,
|
|
204
|
-
version: 2
|
|
205
|
-
};
|
|
206
|
-
const key = formatMidiBindingKey(binding.scope, binding.channel, binding.control, binding.messageType);
|
|
207
|
-
bindings.set(key, binding);
|
|
208
|
-
request.onBound?.(binding);
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
const scopedKey = formatMidiBindingKey(activeScope, message.channel, message.control, message.type);
|
|
212
|
-
const binding = bindings.get(scopedKey) ?? (activeScope === "global" ? void 0 : bindings.get(formatMidiBindingKey("global", message.channel, message.control, message.type)));
|
|
213
|
-
if (!binding) return;
|
|
214
|
-
if (binding.actionKind === "button") {
|
|
215
|
-
if (message.type === "note-off" || message.rawValue === 0) return;
|
|
216
|
-
const currentMs = now();
|
|
217
|
-
const prevMs = lastButtonTriggerMs.get(binding.targetId);
|
|
218
|
-
if (prevMs !== void 0 && currentMs - prevMs < buttonDebounceMs) return;
|
|
219
|
-
lastButtonTriggerMs.set(binding.targetId, currentMs);
|
|
220
|
-
const value = binding.transform ? applyMidiTransform(message.rawValue, binding.transform) : message.normalized;
|
|
221
|
-
options.onButton?.({
|
|
222
|
-
binding,
|
|
223
|
-
message,
|
|
224
|
-
value
|
|
225
|
-
});
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
const value = binding.transform ? applyMidiTransform(message.rawValue, binding.transform) : message.normalized;
|
|
229
|
-
pendingContinuous.set(binding.targetId, {
|
|
189
|
+
bind(learned);
|
|
190
|
+
req.onBound?.(learned);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const binding = lookup(message);
|
|
194
|
+
if (!binding) return;
|
|
195
|
+
const value = binding.transform ? applyMidiTransform(message.rawValue, binding.transform) : message.normalized;
|
|
196
|
+
if (binding.actionKind === "button") {
|
|
197
|
+
if (isIgnoredBtn(message)) return;
|
|
198
|
+
const ts = now();
|
|
199
|
+
const prev = lastBtnMs.get(binding.targetId);
|
|
200
|
+
if (prev !== void 0 && ts - prev < debounceMs) return;
|
|
201
|
+
lastBtnMs.set(binding.targetId, ts);
|
|
202
|
+
options.onButton?.({
|
|
230
203
|
binding,
|
|
231
204
|
message,
|
|
232
205
|
value
|
|
233
206
|
});
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
const
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
pendingCont.set(binding.targetId, {
|
|
210
|
+
binding,
|
|
211
|
+
message,
|
|
212
|
+
value
|
|
213
|
+
});
|
|
214
|
+
scheduleFlush();
|
|
215
|
+
};
|
|
216
|
+
const detachInputs = () => {
|
|
217
|
+
for (const [input, listener] of attached) {
|
|
218
|
+
input.removeEventListener("midimessage", listener);
|
|
219
|
+
if (typeof input.close === "function") input.close().catch(() => false);
|
|
220
|
+
}
|
|
221
|
+
attached.clear();
|
|
222
|
+
};
|
|
223
|
+
const syncInputs = (access) => {
|
|
224
|
+
detachInputs();
|
|
225
|
+
for (const input of access.inputs.values()) {
|
|
226
|
+
const onMsg = (ev) => {
|
|
227
|
+
if (ev.data) handleRawMessage(ev.data, input.id);
|
|
228
|
+
};
|
|
229
|
+
input.addEventListener("midimessage", onMsg);
|
|
230
|
+
attached.set(input, onMsg);
|
|
231
|
+
openMidiInputSafely(input, () => attached.get(input) === onMsg);
|
|
232
|
+
}
|
|
233
|
+
const devices = listMidiDevices(access);
|
|
234
|
+
options.onDevicesChanged?.(devices);
|
|
235
|
+
return devices;
|
|
236
|
+
};
|
|
237
|
+
const disconnectAccess = () => {
|
|
238
|
+
detachInputs();
|
|
239
|
+
if (midiAccess && stateListener) midiAccess.removeEventListener("statechange", stateListener);
|
|
240
|
+
stateListener = void 0;
|
|
241
|
+
midiAccess = void 0;
|
|
242
|
+
};
|
|
243
|
+
const importBindings = (input) => decodeMidiBindingSet(input).pipe(Effect.mapError((failure) => new AudioMidiError({
|
|
244
|
+
code: "INVALID_BINDING",
|
|
245
|
+
message: `Invalid MIDI binding set: ${String(failure)}`
|
|
246
|
+
})), Effect.map((validated) => {
|
|
247
|
+
bindings.clear();
|
|
248
|
+
for (const b of validated.bindings) bind(b);
|
|
249
|
+
return [...bindings.values()];
|
|
250
|
+
}));
|
|
251
|
+
return {
|
|
252
|
+
bind,
|
|
253
|
+
cancelLearn: () => {
|
|
254
|
+
learnReq = void 0;
|
|
255
|
+
},
|
|
256
|
+
connectAccess: (access) => {
|
|
276
257
|
disconnectAccess();
|
|
277
258
|
midiAccess = access;
|
|
278
|
-
|
|
259
|
+
stateListener = () => {
|
|
279
260
|
if (midiAccess === access) syncInputs(access);
|
|
280
261
|
};
|
|
281
|
-
access.addEventListener("statechange",
|
|
262
|
+
access.addEventListener("statechange", stateListener);
|
|
282
263
|
return syncInputs(access);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
code: "INVALID_BINDING",
|
|
291
|
-
message: `Invalid MIDI binding set: ${String(parseFailure)}`
|
|
292
|
-
})), Effect.map((validated) => {
|
|
293
|
-
bindings.clear();
|
|
294
|
-
for (const binding of validated.bindings) bind(binding);
|
|
295
|
-
return [...bindings.values()];
|
|
296
|
-
}));
|
|
297
|
-
const dispose = () => {
|
|
298
|
-
cancelScheduledFlush();
|
|
299
|
-
pendingContinuous.clear();
|
|
300
|
-
lastButtonTriggerMs.clear();
|
|
301
|
-
learnRequest = void 0;
|
|
264
|
+
},
|
|
265
|
+
disconnectAccess,
|
|
266
|
+
dispose: () => {
|
|
267
|
+
cancelFlush();
|
|
268
|
+
pendingCont.clear();
|
|
269
|
+
lastBtnMs.clear();
|
|
270
|
+
learnReq = void 0;
|
|
302
271
|
disconnectAccess();
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
startLearn: (request) => {
|
|
330
|
-
learnRequest = request;
|
|
331
|
-
},
|
|
332
|
-
unbind
|
|
333
|
-
};
|
|
272
|
+
},
|
|
273
|
+
exportBindings: () => ({
|
|
274
|
+
bindings: [...bindings.values()],
|
|
275
|
+
version: 2
|
|
276
|
+
}),
|
|
277
|
+
flushContinuous,
|
|
278
|
+
getActiveScope: () => activeScope,
|
|
279
|
+
getBindings: () => [...bindings.values()],
|
|
280
|
+
getDevices: () => listMidiDevices(midiAccess),
|
|
281
|
+
handleRawMessage,
|
|
282
|
+
importBindings,
|
|
283
|
+
isLearning: () => learnReq !== void 0,
|
|
284
|
+
setActiveScope: (scope) => {
|
|
285
|
+
activeScope = scope;
|
|
286
|
+
},
|
|
287
|
+
startLearn: (req) => {
|
|
288
|
+
learnReq = req;
|
|
289
|
+
},
|
|
290
|
+
unbind: (key) => bindings.delete(key)
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
function createMidiController(options = {}) {
|
|
294
|
+
return Effect.gen(function* () {
|
|
295
|
+
const controller = buildMidiController(options);
|
|
296
|
+
yield* Scope.addFinalizer(yield* Scope.Scope, Effect.sync(controller.dispose));
|
|
297
|
+
return controller;
|
|
334
298
|
});
|
|
335
299
|
}
|
|
336
300
|
export { MIDI_BINDING_SCHEMA_VERSION, MIDI_BUTTON_DEBOUNCE_MS, MIDI_CONTINUOUS_COALESCE_MS, MIDI_STATUS_CC, MIDI_STATUS_NOTE_OFF, MIDI_STATUS_NOTE_ON, MidiActionKindSchema, MidiBindingSchema, MidiBindingSetSchema, MidiCurveSchema, MidiMessageTypeSchema, MidiTransformSchema, applyMidiTransform, createMidiController, formatMidiBindingKey, parseMidiMessage, requestMidiAccess };
|