@avoid.quest/audio 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +70 -2
- package/dist/effects/index.d.ts +266 -0
- package/dist/effects/index.js +744 -0
- package/dist/effects/index.js.map +1 -0
- package/dist/errors-BT9HxDLn.js +74 -0
- package/dist/errors-BT9HxDLn.js.map +1 -0
- package/dist/errors-ChTQFwuZ.d.ts +53 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/midi/index.d.ts +162 -0
- package/dist/midi/index.js +338 -0
- package/dist/midi/index.js.map +1 -0
- package/dist/playback/index.d.ts +349 -0
- package/dist/playback/index.js +1372 -0
- package/dist/playback/index.js.map +1 -0
- package/dist/queue/index.d.ts +144 -0
- package/dist/queue/index.js +1062 -0
- package/dist/queue/index.js.map +1 -0
- package/dist/recognize/index.d.ts +161 -0
- package/dist/recognize/index.js +2816 -0
- package/dist/recognize/index.js.map +1 -0
- package/dist/routing/index.d.ts +140 -0
- package/dist/routing/index.js +678 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/sync/index.d.ts +282 -0
- package/dist/sync/index.js +1103 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/worklet-loader-BvEW0oVO.d.ts +44 -0
- package/dist/worklet-loader-S7R8ZAmP.js +175 -0
- package/dist/worklet-loader-S7R8ZAmP.js.map +1 -0
- package/dist/worklets/couch-live.d.ts +1 -0
- package/dist/worklets/couch-live.js +365 -0
- package/dist/worklets/couch-live.js.map +1 -0
- package/dist/worklets/meter.d.ts +7 -0
- package/dist/worklets/meter.js +80 -0
- package/dist/worklets/meter.js.map +1 -0
- package/package.json +109 -4
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { Effect, Schema, Scope } from "effect";
|
|
2
|
+
import { i as AudioMidiError } from "../errors-BT9HxDLn.js";
|
|
3
|
+
// src/midi/parser.ts
|
|
4
|
+
const MIDI_STATUS_NOTE_OFF = 128;
|
|
5
|
+
const MIDI_STATUS_NOTE_ON = 144;
|
|
6
|
+
const MIDI_STATUS_CC = 176;
|
|
7
|
+
const MidiMessageTypeSchema = Schema.Literals([
|
|
8
|
+
"cc",
|
|
9
|
+
"note-on",
|
|
10
|
+
"note-off"
|
|
11
|
+
]);
|
|
12
|
+
/**
|
|
13
|
+
* Parses a raw 3-byte Web MIDI message into CC (`0xb0`), Note On (`0x90`),
|
|
14
|
+
* or Note Off (`0x80`). Returns `undefined` for unsupported or truncated messages.
|
|
15
|
+
*/
|
|
16
|
+
function parseMidiMessage(data) {
|
|
17
|
+
if (data.length < 3) return;
|
|
18
|
+
const statusByte = data[0] ?? 0;
|
|
19
|
+
const controlByte = (data[1] ?? 0) & 127;
|
|
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";
|
|
27
|
+
if (type === void 0) return;
|
|
28
|
+
return {
|
|
29
|
+
channel,
|
|
30
|
+
control: controlByte,
|
|
31
|
+
normalized: valueByte / 127,
|
|
32
|
+
rawValue: valueByte,
|
|
33
|
+
type
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
// src/midi/transform.ts
|
|
37
|
+
const MIDI_BINDING_SCHEMA_VERSION = 2;
|
|
38
|
+
const MidiCurveSchema = Schema.Literals([
|
|
39
|
+
"linear",
|
|
40
|
+
"log",
|
|
41
|
+
"exp"
|
|
42
|
+
]);
|
|
43
|
+
const MidiActionKindSchema = Schema.Literals(["continuous", "button"]);
|
|
44
|
+
const MidiTransformSchema = Schema.Struct({
|
|
45
|
+
curve: Schema.optional(MidiCurveSchema),
|
|
46
|
+
invert: Schema.optional(Schema.Boolean),
|
|
47
|
+
max: Schema.Finite,
|
|
48
|
+
min: Schema.Finite
|
|
49
|
+
});
|
|
50
|
+
const MidiBindingSchema = Schema.Struct({
|
|
51
|
+
actionKind: MidiActionKindSchema,
|
|
52
|
+
channel: Schema.Int.check(Schema.isBetween({
|
|
53
|
+
maximum: 15,
|
|
54
|
+
minimum: 0
|
|
55
|
+
})),
|
|
56
|
+
control: Schema.Int.check(Schema.isBetween({
|
|
57
|
+
maximum: 127,
|
|
58
|
+
minimum: 0
|
|
59
|
+
})),
|
|
60
|
+
messageType: MidiMessageTypeSchema,
|
|
61
|
+
scope: Schema.NonEmptyString,
|
|
62
|
+
targetId: Schema.NonEmptyString,
|
|
63
|
+
transform: Schema.optional(MidiTransformSchema),
|
|
64
|
+
version: Schema.Literal(2)
|
|
65
|
+
});
|
|
66
|
+
const MidiBindingSetSchema = Schema.Struct({
|
|
67
|
+
bindings: Schema.Array(MidiBindingSchema),
|
|
68
|
+
version: Schema.Literal(2)
|
|
69
|
+
});
|
|
70
|
+
function formatMidiBindingKey(scope, channel, control, messageType) {
|
|
71
|
+
return `${scope}:${channel}:${control}:${messageType}`;
|
|
72
|
+
}
|
|
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
|
+
function applyMidiTransform(rawValue, transform) {
|
|
81
|
+
let v = Math.max(0, Math.min(127, rawValue)) / 127;
|
|
82
|
+
if (transform.invert) v = 1 - v;
|
|
83
|
+
const curve = transform.curve ?? "linear";
|
|
84
|
+
if (curve === "log") v = v <= 0 ? 0 : Math.log1p(v * (Math.E - 1));
|
|
85
|
+
else if (curve === "exp") v = (Math.exp(v) - 1) / (Math.E - 1);
|
|
86
|
+
const mapped = transform.min + v * (transform.max - transform.min);
|
|
87
|
+
const lo = Math.min(transform.min, transform.max);
|
|
88
|
+
const hi = Math.max(transform.min, transform.max);
|
|
89
|
+
return Math.max(lo, Math.min(hi, mapped));
|
|
90
|
+
}
|
|
91
|
+
// src/midi/controller.ts
|
|
92
|
+
const MIDI_BUTTON_DEBOUNCE_MS = 50;
|
|
93
|
+
const MIDI_CONTINUOUS_COALESCE_MS = 33;
|
|
94
|
+
const decodeMidiBindingSet = Schema.decodeUnknownEffect(MidiBindingSetSchema);
|
|
95
|
+
/**
|
|
96
|
+
* Requests Web MIDI access (`sysex: false` by default) wrapped as a typed Effect.
|
|
97
|
+
*/
|
|
98
|
+
function requestMidiAccess(options = {}) {
|
|
99
|
+
return Effect.tryPromise({
|
|
100
|
+
catch: (error) => {
|
|
101
|
+
if (error instanceof AudioMidiError) return error;
|
|
102
|
+
const errName = error instanceof Error ? error.name : "";
|
|
103
|
+
return new AudioMidiError({
|
|
104
|
+
code: errName === "SecurityError" || errName === "NotAllowedError" ? "PERMISSION_DENIED" : "ACCESS_FAILED",
|
|
105
|
+
message: `Web MIDI access failed: ${String(error)}`
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
try: async () => {
|
|
109
|
+
const requester = options.requestMIDIAccess ?? (globalThis.navigator !== void 0 && "requestMIDIAccess" in globalThis.navigator ? globalThis.navigator.requestMIDIAccess.bind(globalThis.navigator) : void 0);
|
|
110
|
+
if (typeof requester !== "function") throw new AudioMidiError({
|
|
111
|
+
code: "UNSUPPORTED",
|
|
112
|
+
message: "Web MIDI API (navigator.requestMIDIAccess) is not supported."
|
|
113
|
+
});
|
|
114
|
+
return await requester({ sysex: options.sysex ?? false });
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function listDevices(access) {
|
|
119
|
+
if (!access) return [];
|
|
120
|
+
const devices = [];
|
|
121
|
+
for (const input of access.inputs.values()) devices.push({
|
|
122
|
+
id: input.id,
|
|
123
|
+
manufacturer: input.manufacturer ?? "",
|
|
124
|
+
name: input.name ?? input.id,
|
|
125
|
+
state: input.state ?? "connected"
|
|
126
|
+
});
|
|
127
|
+
return devices;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Creates a `Scope`-managed Web MIDI controller with:
|
|
131
|
+
* - Non-destructive `addEventListener`/`removeEventListener` MIDI port attachment
|
|
132
|
+
* - Effect `Schema`-validated `importBindings`
|
|
133
|
+
* - CC (`0xb0`), Note On (`0x90`), Note Off (`0x80`) parsing
|
|
134
|
+
* - `Schema`-ranged parameter transforms (`linear`/`log`/`exp`, invert, clamp)
|
|
135
|
+
* - 50 ms button debounce per `targetId` (ignoring `note-off` and velocity `0`)
|
|
136
|
+
* - 33 ms continuous value coalescing
|
|
137
|
+
* - Scoped MIDI Learn (`${scope}:${channel}:${control}:${type}`).
|
|
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;
|
|
173
|
+
};
|
|
174
|
+
const scheduleContinuousFlush = () => {
|
|
175
|
+
if (flushTimer !== void 0 || rafHandle !== void 0) return;
|
|
176
|
+
const elapsed = now() - lastFlushMs;
|
|
177
|
+
const delay = Math.max(0, continuousCoalesceMs - elapsed);
|
|
178
|
+
const attemptFlush = () => {
|
|
179
|
+
flushTimer = void 0;
|
|
180
|
+
rafHandle = void 0;
|
|
181
|
+
if (pendingContinuous.size === 0) return;
|
|
182
|
+
if (now() - lastFlushMs >= continuousCoalesceMs) flushContinuous();
|
|
183
|
+
else scheduleContinuousFlush();
|
|
184
|
+
};
|
|
185
|
+
if (delay === 0 && typeof globalThis.requestAnimationFrame === "function") rafHandle = globalThis.requestAnimationFrame(attemptFlush);
|
|
186
|
+
else flushTimer = setTimeout(attemptFlush, Math.max(1, delay));
|
|
187
|
+
};
|
|
188
|
+
const handleRawMessage = (data, inputId) => {
|
|
189
|
+
const message = parseMidiMessage(data);
|
|
190
|
+
if (!message) return;
|
|
191
|
+
options.onMessage?.(message, inputId);
|
|
192
|
+
if (learnRequest) {
|
|
193
|
+
if (learnRequest.actionKind === "button" && (message.type === "note-off" || message.rawValue === 0)) return;
|
|
194
|
+
const request = learnRequest;
|
|
195
|
+
learnRequest = void 0;
|
|
196
|
+
const binding = {
|
|
197
|
+
actionKind: request.actionKind,
|
|
198
|
+
channel: message.channel,
|
|
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, {
|
|
230
|
+
binding,
|
|
231
|
+
message,
|
|
232
|
+
value
|
|
233
|
+
});
|
|
234
|
+
scheduleContinuousFlush();
|
|
235
|
+
};
|
|
236
|
+
const detachInputs = () => {
|
|
237
|
+
for (const [input, listener] of attachedInputs) {
|
|
238
|
+
input.removeEventListener("midimessage", listener);
|
|
239
|
+
if (typeof input.close === "function") input.close().catch(() => false);
|
|
240
|
+
}
|
|
241
|
+
attachedInputs.clear();
|
|
242
|
+
};
|
|
243
|
+
const syncInputs = (access) => {
|
|
244
|
+
detachInputs();
|
|
245
|
+
for (const input of access.inputs.values()) {
|
|
246
|
+
const onMessage = (event) => {
|
|
247
|
+
if (event.data) handleRawMessage(event.data, input.id);
|
|
248
|
+
};
|
|
249
|
+
input.addEventListener("midimessage", onMessage);
|
|
250
|
+
attachedInputs.set(input, onMessage);
|
|
251
|
+
if (typeof input.open === "function") {
|
|
252
|
+
const openAndVerify = async () => {
|
|
253
|
+
try {
|
|
254
|
+
await input.open?.();
|
|
255
|
+
} catch {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (attachedInputs.get(input) !== onMessage && typeof input.close === "function") try {
|
|
259
|
+
await input.close();
|
|
260
|
+
} catch {}
|
|
261
|
+
};
|
|
262
|
+
openAndVerify();
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
const devices = listDevices(access);
|
|
266
|
+
options.onDevicesChanged?.(devices);
|
|
267
|
+
return devices;
|
|
268
|
+
};
|
|
269
|
+
const disconnectAccess = () => {
|
|
270
|
+
detachInputs();
|
|
271
|
+
if (midiAccess && stateChangeListener) midiAccess.removeEventListener("statechange", stateChangeListener);
|
|
272
|
+
stateChangeListener = void 0;
|
|
273
|
+
midiAccess = void 0;
|
|
274
|
+
};
|
|
275
|
+
const connectAccess = (access) => {
|
|
276
|
+
disconnectAccess();
|
|
277
|
+
midiAccess = access;
|
|
278
|
+
stateChangeListener = () => {
|
|
279
|
+
if (midiAccess === access) syncInputs(access);
|
|
280
|
+
};
|
|
281
|
+
access.addEventListener("statechange", stateChangeListener);
|
|
282
|
+
return syncInputs(access);
|
|
283
|
+
};
|
|
284
|
+
const bind = (binding) => {
|
|
285
|
+
const key = formatMidiBindingKey(binding.scope, binding.channel, binding.control, binding.messageType);
|
|
286
|
+
bindings.set(key, binding);
|
|
287
|
+
};
|
|
288
|
+
const unbind = (key) => bindings.delete(key);
|
|
289
|
+
const importBindings = (input) => decodeMidiBindingSet(input).pipe(Effect.mapError((parseFailure) => new AudioMidiError({
|
|
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;
|
|
302
|
+
disconnectAccess();
|
|
303
|
+
};
|
|
304
|
+
yield* Scope.addFinalizer(yield* Scope.Scope, Effect.sync(() => {
|
|
305
|
+
dispose();
|
|
306
|
+
}));
|
|
307
|
+
return {
|
|
308
|
+
bind,
|
|
309
|
+
cancelLearn: () => {
|
|
310
|
+
learnRequest = void 0;
|
|
311
|
+
},
|
|
312
|
+
connectAccess,
|
|
313
|
+
disconnectAccess,
|
|
314
|
+
dispose,
|
|
315
|
+
exportBindings: () => ({
|
|
316
|
+
bindings: [...bindings.values()],
|
|
317
|
+
version: 2
|
|
318
|
+
}),
|
|
319
|
+
flushContinuous,
|
|
320
|
+
getActiveScope: () => activeScope,
|
|
321
|
+
getBindings: () => [...bindings.values()],
|
|
322
|
+
getDevices: () => listDevices(midiAccess),
|
|
323
|
+
handleRawMessage,
|
|
324
|
+
importBindings,
|
|
325
|
+
isLearning: () => learnRequest !== void 0,
|
|
326
|
+
setActiveScope: (scope) => {
|
|
327
|
+
activeScope = scope;
|
|
328
|
+
},
|
|
329
|
+
startLearn: (request) => {
|
|
330
|
+
learnRequest = request;
|
|
331
|
+
},
|
|
332
|
+
unbind
|
|
333
|
+
};
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
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 };
|
|
337
|
+
|
|
338
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/midi/parser.ts","../../src/midi/transform.ts","../../src/midi/controller.ts"],"sourcesContent":["/* oxlint-disable eslint/no-bitwise */\nimport { Schema } from \"effect\";\n\nexport const MIDI_STATUS_NOTE_OFF = 0x80;\nexport const MIDI_STATUS_NOTE_ON = 0x90;\nexport const MIDI_STATUS_CC = 0xb0;\n\nexport const MidiMessageTypeSchema = Schema.Literals([\n \"cc\",\n \"note-on\",\n \"note-off\",\n]);\nexport type MidiMessageType = typeof MidiMessageTypeSchema.Type;\n\nexport interface ParsedMidiMessage {\n readonly type: MidiMessageType;\n readonly channel: number;\n readonly control: number;\n readonly rawValue: number;\n readonly normalized: number;\n}\n\n/**\n * Parses a raw 3-byte Web MIDI message into CC (`0xb0`), Note On (`0x90`),\n * or Note Off (`0x80`). Returns `undefined` for unsupported or truncated messages.\n */\nexport function parseMidiMessage(\n data: Uint8Array | readonly number[]\n): ParsedMidiMessage | undefined {\n if (data.length < 3) {\n return undefined;\n }\n const statusByte = data[0] ?? 0;\n const controlByte = (data[1] ?? 0) & 0x7f;\n const valueByte = (data[2] ?? 0) & 0x7f;\n\n const statusType = statusByte & 0xf0;\n const channel = statusByte & 0x0f;\n\n let type: MidiMessageType | undefined;\n if (statusType === MIDI_STATUS_CC) {\n type = \"cc\";\n } else if (statusType === MIDI_STATUS_NOTE_ON) {\n type = \"note-on\";\n } else if (statusType === MIDI_STATUS_NOTE_OFF) {\n type = \"note-off\";\n }\n\n if (type === undefined) {\n return undefined;\n }\n\n return {\n channel,\n control: controlByte,\n normalized: valueByte / 127,\n rawValue: valueByte,\n type,\n };\n}\n","import { Schema } from \"effect\";\n\nimport { MidiMessageTypeSchema } from \"./parser.ts\";\nimport type { MidiMessageType } from \"./parser.ts\";\n\nexport const MIDI_BINDING_SCHEMA_VERSION = 2 as const;\n\nexport const MidiCurveSchema = Schema.Literals([\"linear\", \"log\", \"exp\"]);\nexport type MidiCurve = typeof MidiCurveSchema.Type;\n\nexport const MidiActionKindSchema = Schema.Literals([\"continuous\", \"button\"]);\nexport type MidiActionKind = typeof MidiActionKindSchema.Type;\n\nexport const MidiTransformSchema = Schema.Struct({\n curve: Schema.optional(MidiCurveSchema),\n invert: Schema.optional(Schema.Boolean),\n max: Schema.Finite,\n min: Schema.Finite,\n});\nexport type MidiTransform = typeof MidiTransformSchema.Type;\n\nexport const MidiBindingSchema = Schema.Struct({\n actionKind: MidiActionKindSchema,\n channel: Schema.Int.check(Schema.isBetween({ maximum: 15, minimum: 0 })),\n control: Schema.Int.check(Schema.isBetween({ maximum: 127, minimum: 0 })),\n messageType: MidiMessageTypeSchema,\n scope: Schema.NonEmptyString,\n targetId: Schema.NonEmptyString,\n transform: Schema.optional(MidiTransformSchema),\n version: Schema.Literal(MIDI_BINDING_SCHEMA_VERSION),\n});\nexport type MidiBinding = typeof MidiBindingSchema.Type;\n\nexport const MidiBindingSetSchema = Schema.Struct({\n bindings: Schema.Array(MidiBindingSchema),\n version: Schema.Literal(MIDI_BINDING_SCHEMA_VERSION),\n});\nexport type MidiBindingSet = typeof MidiBindingSetSchema.Type;\n\nexport function formatMidiBindingKey(\n scope: string,\n channel: number,\n control: number,\n messageType: MidiMessageType\n): string {\n return `${scope}:${channel}:${control}:${messageType}`;\n}\n\n/**\n * Applies the MIDI value transform pipeline (`rawValue` in `0..127`):\n * 1. Normalize to `[0, 1]`\n * 2. Optional `invert` (`1 - v`)\n * 3. Curve (`linear`, `log`: `Math.log1p(v * (Math.E - 1))`, `exp`: `(Math.exp(v) - 1) / (Math.E - 1)`)\n * 4. Linear map to `[min, max]` and clamp to `[min(min, max), max(min, max)]`.\n */\nexport function applyMidiTransform(\n rawValue: number,\n transform: MidiTransform\n): number {\n const clampedRaw = Math.max(0, Math.min(127, rawValue));\n let v = clampedRaw / 127;\n\n if (transform.invert) {\n v = 1 - v;\n }\n\n const curve = transform.curve ?? \"linear\";\n if (curve === \"log\") {\n v = v <= 0 ? 0 : Math.log1p(v * (Math.E - 1));\n } else if (curve === \"exp\") {\n v = (Math.exp(v) - 1) / (Math.E - 1);\n }\n\n const mapped = transform.min + v * (transform.max - transform.min);\n const lo = Math.min(transform.min, transform.max);\n const hi = Math.max(transform.min, transform.max);\n return Math.max(lo, Math.min(hi, mapped));\n}\n","import { Effect, Schema, Scope } from \"effect\";\n\nimport { AudioMidiError } from \"../errors.ts\";\nimport { parseMidiMessage } from \"./parser.ts\";\nimport type { ParsedMidiMessage } from \"./parser.ts\";\nimport {\n MIDI_BINDING_SCHEMA_VERSION,\n MidiBindingSetSchema,\n applyMidiTransform,\n formatMidiBindingKey,\n} from \"./transform.ts\";\nimport type {\n MidiActionKind,\n MidiBinding,\n MidiBindingSet,\n MidiTransform,\n} from \"./transform.ts\";\n\nexport const MIDI_BUTTON_DEBOUNCE_MS = 50;\nexport const MIDI_CONTINUOUS_COALESCE_MS = 33;\n\nexport interface MidiMessageEventLike {\n readonly data?: Uint8Array | null;\n}\n\nexport interface MidiInputLike {\n readonly id: string;\n readonly name?: string | null;\n readonly manufacturer?: string | null;\n readonly state?: string;\n readonly open?: () => Promise<unknown>;\n readonly close?: () => Promise<unknown>;\n readonly addEventListener: (\n type: \"midimessage\",\n listener: (event: MidiMessageEventLike) => void\n ) => void;\n readonly removeEventListener: (\n type: \"midimessage\",\n listener: (event: MidiMessageEventLike) => void\n ) => void;\n}\n\nexport interface MidiAccessLike {\n readonly inputs: ReadonlyMap<string, MidiInputLike>;\n readonly addEventListener: (\n type: \"statechange\",\n listener: (event: unknown) => void\n ) => void;\n readonly removeEventListener: (\n type: \"statechange\",\n listener: (event: unknown) => void\n ) => void;\n}\n\nexport interface MidiDeviceInfo {\n readonly id: string;\n readonly name: string;\n readonly manufacturer: string;\n readonly state: string;\n}\n\nexport interface MidiLearnRequest {\n readonly scope: string;\n readonly targetId: string;\n readonly actionKind: MidiActionKind;\n readonly transform?: MidiTransform;\n readonly onBound?: (binding: MidiBinding) => void;\n}\n\nexport interface MidiDispatchEvent {\n readonly binding: MidiBinding;\n readonly message: ParsedMidiMessage;\n readonly value: number;\n}\n\nexport interface MidiControllerOptions {\n readonly activeScope?: string;\n readonly buttonDebounceMs?: number;\n readonly continuousCoalesceMs?: number;\n readonly now?: () => number;\n readonly onButton?: (event: MidiDispatchEvent) => void;\n readonly onContinuous?: (event: MidiDispatchEvent) => void;\n readonly onMessage?: (message: ParsedMidiMessage, inputId?: string) => void;\n readonly onDevicesChanged?: (devices: readonly MidiDeviceInfo[]) => void;\n}\n\nexport interface MidiController {\n readonly connectAccess: (access: MidiAccessLike) => readonly MidiDeviceInfo[];\n readonly disconnectAccess: () => void;\n readonly getDevices: () => readonly MidiDeviceInfo[];\n readonly setActiveScope: (scope: string) => void;\n readonly getActiveScope: () => string;\n readonly bind: (binding: MidiBinding) => void;\n readonly unbind: (key: string) => boolean;\n readonly getBindings: () => readonly MidiBinding[];\n readonly exportBindings: () => MidiBindingSet;\n readonly importBindings: (\n input: unknown\n ) => Effect.Effect<readonly MidiBinding[], AudioMidiError>;\n readonly startLearn: (request: MidiLearnRequest) => void;\n readonly cancelLearn: () => void;\n readonly isLearning: () => boolean;\n readonly handleRawMessage: (\n data: Uint8Array | readonly number[],\n inputId?: string\n ) => void;\n readonly flushContinuous: () => number;\n readonly dispose: () => void;\n}\n\nconst decodeMidiBindingSet = Schema.decodeUnknownEffect(MidiBindingSetSchema);\n\n/**\n * Requests Web MIDI access (`sysex: false` by default) wrapped as a typed Effect.\n */\nexport function requestMidiAccess(\n options: {\n readonly sysex?: boolean;\n readonly requestMIDIAccess?: (opts?: {\n sysex?: boolean;\n }) => Promise<MidiAccessLike>;\n } = {}\n): Effect.Effect<MidiAccessLike, AudioMidiError> {\n return Effect.tryPromise({\n catch: (error) => {\n if (error instanceof AudioMidiError) {\n return error;\n }\n const errName = error instanceof Error ? error.name : \"\";\n return new AudioMidiError({\n code:\n errName === \"SecurityError\" || errName === \"NotAllowedError\"\n ? \"PERMISSION_DENIED\"\n : \"ACCESS_FAILED\",\n message: `Web MIDI access failed: ${String(error)}`,\n });\n },\n try: async () => {\n const requester =\n options.requestMIDIAccess ??\n (globalThis.navigator !== undefined &&\n \"requestMIDIAccess\" in globalThis.navigator\n ? (\n globalThis.navigator as Navigator & {\n requestMIDIAccess: (opts?: {\n sysex?: boolean;\n }) => Promise<MidiAccessLike>;\n }\n ).requestMIDIAccess.bind(globalThis.navigator)\n : undefined);\n\n if (typeof requester !== \"function\") {\n throw new AudioMidiError({\n code: \"UNSUPPORTED\",\n message:\n \"Web MIDI API (navigator.requestMIDIAccess) is not supported.\",\n });\n }\n return await requester({ sysex: options.sysex ?? false });\n },\n });\n}\n\nfunction listDevices(access: MidiAccessLike | undefined): MidiDeviceInfo[] {\n if (!access) {\n return [];\n }\n const devices: MidiDeviceInfo[] = [];\n for (const input of access.inputs.values()) {\n devices.push({\n id: input.id,\n manufacturer: input.manufacturer ?? \"\",\n name: input.name ?? input.id,\n state: input.state ?? \"connected\",\n });\n }\n return devices;\n}\n\n/**\n * Creates a `Scope`-managed Web MIDI controller with:\n * - Non-destructive `addEventListener`/`removeEventListener` MIDI port attachment\n * - Effect `Schema`-validated `importBindings`\n * - CC (`0xb0`), Note On (`0x90`), Note Off (`0x80`) parsing\n * - `Schema`-ranged parameter transforms (`linear`/`log`/`exp`, invert, clamp)\n * - 50 ms button debounce per `targetId` (ignoring `note-off` and velocity `0`)\n * - 33 ms continuous value coalescing\n * - Scoped MIDI Learn (`${scope}:${channel}:${control}:${type}`).\n */\nexport function createMidiController(\n options: MidiControllerOptions = {}\n): Effect.Effect<MidiController, never, Scope.Scope> {\n return Effect.gen(function* () {\n const buttonDebounceMs =\n options.buttonDebounceMs ?? MIDI_BUTTON_DEBOUNCE_MS;\n const continuousCoalesceMs =\n options.continuousCoalesceMs ?? MIDI_CONTINUOUS_COALESCE_MS;\n const now = options.now ?? (() => Date.now());\n\n let activeScope = options.activeScope ?? \"global\";\n let midiAccess: MidiAccessLike | undefined;\n let stateChangeListener: ((event: unknown) => void) | undefined;\n const attachedInputs = new Map<\n MidiInputLike,\n (event: MidiMessageEventLike) => void\n >();\n const bindings = new Map<string, MidiBinding>();\n const lastButtonTriggerMs = new Map<string, number>();\n const pendingContinuous = new Map<string, MidiDispatchEvent>();\n let learnRequest: MidiLearnRequest | undefined;\n let lastFlushMs = 0;\n let flushTimer: ReturnType<typeof setTimeout> | undefined;\n let rafHandle: number | undefined;\n\n const cancelScheduledFlush = (): void => {\n if (flushTimer !== undefined) {\n clearTimeout(flushTimer);\n flushTimer = undefined;\n }\n if (\n rafHandle !== undefined &&\n typeof globalThis.cancelAnimationFrame === \"function\"\n ) {\n globalThis.cancelAnimationFrame(rafHandle);\n rafHandle = undefined;\n }\n };\n\n const flushContinuous = (): number => {\n cancelScheduledFlush();\n if (pendingContinuous.size === 0) {\n return 0;\n }\n const batch = [...pendingContinuous.values()];\n pendingContinuous.clear();\n lastFlushMs = now();\n for (const event of batch) {\n options.onContinuous?.(event);\n }\n return batch.length;\n };\n\n const scheduleContinuousFlush = (): void => {\n if (flushTimer !== undefined || rafHandle !== undefined) {\n return;\n }\n const elapsed = now() - lastFlushMs;\n const delay = Math.max(0, continuousCoalesceMs - elapsed);\n\n const attemptFlush = (): void => {\n flushTimer = undefined;\n rafHandle = undefined;\n if (pendingContinuous.size === 0) {\n return;\n }\n const sinceLast = now() - lastFlushMs;\n if (sinceLast >= continuousCoalesceMs) {\n flushContinuous();\n } else {\n scheduleContinuousFlush();\n }\n };\n\n if (\n delay === 0 &&\n typeof globalThis.requestAnimationFrame === \"function\"\n ) {\n rafHandle = globalThis.requestAnimationFrame(attemptFlush);\n } else {\n flushTimer = setTimeout(attemptFlush, Math.max(1, delay));\n }\n };\n\n const handleRawMessage = (\n data: Uint8Array | readonly number[],\n inputId?: string\n ): void => {\n const message = parseMidiMessage(data);\n if (!message) {\n return;\n }\n options.onMessage?.(message, inputId);\n\n // MIDI Learn captures the next qualifying message\n if (learnRequest) {\n if (\n learnRequest.actionKind === \"button\" &&\n (message.type === \"note-off\" || message.rawValue === 0)\n ) {\n return;\n }\n const request = learnRequest;\n learnRequest = undefined;\n const binding: MidiBinding = {\n actionKind: request.actionKind,\n channel: message.channel,\n control: message.control,\n messageType: message.type,\n scope: request.scope,\n targetId: request.targetId,\n transform: request.transform,\n version: MIDI_BINDING_SCHEMA_VERSION,\n };\n const key = formatMidiBindingKey(\n binding.scope,\n binding.channel,\n binding.control,\n binding.messageType\n );\n bindings.set(key, binding);\n request.onBound?.(binding);\n return;\n }\n\n const scopedKey = formatMidiBindingKey(\n activeScope,\n message.channel,\n message.control,\n message.type\n );\n const binding =\n bindings.get(scopedKey) ??\n (activeScope === \"global\"\n ? undefined\n : bindings.get(\n formatMidiBindingKey(\n \"global\",\n message.channel,\n message.control,\n message.type\n )\n ));\n if (!binding) {\n return;\n }\n\n if (binding.actionKind === \"button\") {\n if (message.type === \"note-off\" || message.rawValue === 0) {\n return;\n }\n const currentMs = now();\n const prevMs = lastButtonTriggerMs.get(binding.targetId);\n if (prevMs !== undefined && currentMs - prevMs < buttonDebounceMs) {\n return;\n }\n lastButtonTriggerMs.set(binding.targetId, currentMs);\n const value = binding.transform\n ? applyMidiTransform(message.rawValue, binding.transform)\n : message.normalized;\n options.onButton?.({ binding, message, value });\n return;\n }\n\n const value = binding.transform\n ? applyMidiTransform(message.rawValue, binding.transform)\n : message.normalized;\n pendingContinuous.set(binding.targetId, { binding, message, value });\n scheduleContinuousFlush();\n };\n\n const detachInputs = (): void => {\n for (const [input, listener] of attachedInputs) {\n input.removeEventListener(\"midimessage\", listener);\n if (typeof input.close === \"function\") {\n void input.close().catch(() => false);\n }\n }\n attachedInputs.clear();\n };\n\n const syncInputs = (access: MidiAccessLike): readonly MidiDeviceInfo[] => {\n detachInputs();\n for (const input of access.inputs.values()) {\n const onMessage = (event: MidiMessageEventLike): void => {\n if (event.data) {\n handleRawMessage(event.data, input.id);\n }\n };\n input.addEventListener(\"midimessage\", onMessage);\n attachedInputs.set(input, onMessage);\n if (typeof input.open === \"function\") {\n const openAndVerify = async (): Promise<void> => {\n try {\n await input.open?.();\n } catch {\n return;\n }\n if (\n attachedInputs.get(input) !== onMessage &&\n typeof input.close === \"function\"\n ) {\n try {\n await input.close();\n } catch {\n // Ignore close failures on detached ports\n }\n }\n };\n void openAndVerify();\n }\n }\n const devices = listDevices(access);\n options.onDevicesChanged?.(devices);\n return devices;\n };\n\n const disconnectAccess = (): void => {\n detachInputs();\n if (midiAccess && stateChangeListener) {\n midiAccess.removeEventListener(\"statechange\", stateChangeListener);\n }\n stateChangeListener = undefined;\n midiAccess = undefined;\n };\n\n const connectAccess = (\n access: MidiAccessLike\n ): readonly MidiDeviceInfo[] => {\n disconnectAccess();\n midiAccess = access;\n stateChangeListener = (): void => {\n if (midiAccess === access) {\n syncInputs(access);\n }\n };\n access.addEventListener(\"statechange\", stateChangeListener);\n return syncInputs(access);\n };\n\n const bind = (binding: MidiBinding): void => {\n const key = formatMidiBindingKey(\n binding.scope,\n binding.channel,\n binding.control,\n binding.messageType\n );\n bindings.set(key, binding);\n };\n\n const unbind = (key: string): boolean => bindings.delete(key);\n\n const importBindings = (\n input: unknown\n ): Effect.Effect<readonly MidiBinding[], AudioMidiError> =>\n decodeMidiBindingSet(input).pipe(\n Effect.mapError(\n (parseFailure) =>\n new AudioMidiError({\n code: \"INVALID_BINDING\",\n message: `Invalid MIDI binding set: ${String(parseFailure)}`,\n })\n ),\n Effect.map((validated) => {\n bindings.clear();\n for (const binding of validated.bindings) {\n bind(binding);\n }\n return [...bindings.values()];\n })\n );\n\n const dispose = (): void => {\n cancelScheduledFlush();\n pendingContinuous.clear();\n lastButtonTriggerMs.clear();\n learnRequest = undefined;\n disconnectAccess();\n };\n\n yield* Scope.addFinalizer(\n yield* Scope.Scope,\n Effect.sync(() => {\n dispose();\n })\n );\n\n return {\n bind,\n cancelLearn: () => {\n learnRequest = undefined;\n },\n connectAccess,\n disconnectAccess,\n dispose,\n exportBindings: () => ({\n bindings: [...bindings.values()],\n version: MIDI_BINDING_SCHEMA_VERSION,\n }),\n flushContinuous,\n getActiveScope: () => activeScope,\n getBindings: () => [...bindings.values()],\n getDevices: () => listDevices(midiAccess),\n handleRawMessage,\n importBindings,\n isLearning: () => learnRequest !== undefined,\n setActiveScope: (scope) => {\n activeScope = scope;\n },\n startLearn: (request) => {\n learnRequest = request;\n },\n unbind,\n };\n });\n}\n"],"mappings":";;;AAGA,MAAa,uBAAuB;AACpC,MAAa,sBAAsB;AACnC,MAAa,iBAAiB;AAE9B,MAAa,wBAAwB,OAAO,SAAS;CACnD;CACA;CACA;AACF,CAAC;;;;;AAeD,SAAgB,iBACd,MAC+B;CAC/B,IAAI,KAAK,SAAS,GAChB;CAEF,MAAM,aAAa,KAAK,MAAM;CAC9B,MAAM,eAAe,KAAK,MAAM,KAAK;CACrC,MAAM,aAAa,KAAK,MAAM,KAAK;CAEnC,MAAM,aAAa,aAAa;CAChC,MAAM,UAAU,aAAa;CAE7B,IAAI;CACJ,IAAI,eAAA,KACF,OAAO;MACF,IAAI,eAAA,KACT,OAAO;MACF,IAAI,eAAA,KACT,OAAO;CAGT,IAAI,SAAS,KAAA,GACX;CAGF,OAAO;EACL;EACA,SAAS;EACT,YAAY,YAAY;EACxB,UAAU;EACV;CACF;AACF;;ACtDA,MAAa,8BAA8B;AAE3C,MAAa,kBAAkB,OAAO,SAAS;CAAC;CAAU;CAAO;AAAK,CAAC;AAGvE,MAAa,uBAAuB,OAAO,SAAS,CAAC,cAAc,QAAQ,CAAC;AAG5E,MAAa,sBAAsB,O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