@zsherman/sound 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/CHANGELOG.md +7 -0
- package/LICENSE +373 -0
- package/README.md +16 -2
- package/dist/dom/engine/cues.js +69 -0
- package/dist/dom/engine/engine.js +104 -0
- package/dist/dom/engine/index.js +4 -0
- package/dist/dom/engine/synth.js +172 -0
- package/dist/dom/engine/types.js +0 -0
- package/dist/dom/index.js +9 -0
- package/dist/dom/sound-provider/index.js +1 -0
- package/dist/dom/sound-provider/sound-provider.js +75 -0
- package/dist/dom/themes/glass.js +47 -0
- package/dist/dom/themes/index.js +5 -0
- package/dist/dom/themes/mechanical.js +46 -0
- package/dist/dom/themes/score.js +210 -0
- package/dist/dom/themes/soft.js +28 -0
- package/dist/solid/engine/cues.jsx +69 -0
- package/dist/solid/engine/engine.jsx +104 -0
- package/dist/solid/engine/index.jsx +4 -0
- package/dist/solid/engine/synth.jsx +172 -0
- package/dist/solid/engine/types.jsx +0 -0
- package/dist/solid/index.jsx +9 -0
- package/dist/solid/sound-provider/index.jsx +1 -0
- package/dist/solid/sound-provider/sound-provider.jsx +66 -0
- package/dist/solid/themes/glass.jsx +47 -0
- package/dist/solid/themes/index.jsx +5 -0
- package/dist/solid/themes/mechanical.jsx +46 -0
- package/dist/solid/themes/score.jsx +210 -0
- package/dist/solid/themes/soft.jsx +28 -0
- package/dist/types/engine/cues.d.ts +21 -0
- package/dist/types/engine/engine.d.ts +42 -0
- package/dist/types/engine/index.d.ts +6 -0
- package/dist/types/engine/synth.d.ts +28 -0
- package/dist/types/engine/types.d.ts +65 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/sound-provider/index.d.ts +2 -0
- package/dist/types/sound-provider/sound-provider.d.ts +55 -0
- package/dist/types/themes/glass.d.ts +7 -0
- package/dist/types/themes/index.d.ts +5 -0
- package/dist/types/themes/mechanical.d.ts +7 -0
- package/dist/types/themes/score.d.ts +14 -0
- package/dist/types/themes/soft.d.ts +6 -0
- package/docs/api.json +55 -0
- package/docs/llms.txt +39 -0
- package/docs/search-index.json +25 -0
- package/docs/sound-provider.md +152 -0
- package/docs/sounds.md +203 -0
- package/package.json +51 -4
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { roomShare } from "./cues.js";
|
|
2
|
+
// src/engine/synth.ts
|
|
3
|
+
/** The most layers one cue plays; a theme's extra layers are ignored. */
|
|
4
|
+
const MAX_LAYERS = 12;
|
|
5
|
+
/** What emphasis does to a cue: its level, its length, its room, and its accent layers. */
|
|
6
|
+
const EMPHASIS = {
|
|
7
|
+
subtle: {
|
|
8
|
+
gain: .6,
|
|
9
|
+
decay: .75,
|
|
10
|
+
room: .5,
|
|
11
|
+
accent: 0
|
|
12
|
+
},
|
|
13
|
+
normal: {
|
|
14
|
+
gain: 1,
|
|
15
|
+
decay: 1,
|
|
16
|
+
room: 1,
|
|
17
|
+
accent: 1
|
|
18
|
+
},
|
|
19
|
+
strong: {
|
|
20
|
+
gain: 1.15,
|
|
21
|
+
decay: 1.25,
|
|
22
|
+
room: 1.6,
|
|
23
|
+
accent: 1.5
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
/** The level an envelope falls to before its last few milliseconds go linearly to zero (about −66 dB). */
|
|
27
|
+
const FLOOR = 5e-4;
|
|
28
|
+
/** The linear fade after the floor, so a voice never stops on a non-zero sample (a click). */
|
|
29
|
+
const FADE = .006;
|
|
30
|
+
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
31
|
+
const hz = (f) => clamp(f, 20, 16e3);
|
|
32
|
+
/** A small seeded generator, so noise and the room are the same on every render (tests compare them). */
|
|
33
|
+
function random(seed) {
|
|
34
|
+
let s = seed >>> 0;
|
|
35
|
+
return () => {
|
|
36
|
+
s = s + 1831565813 >>> 0;
|
|
37
|
+
let t = s;
|
|
38
|
+
t = Math.imul(t ^ t >>> 15, t | 1);
|
|
39
|
+
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
|
|
40
|
+
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const noiseBuffers = /* @__PURE__ */ new WeakMap();
|
|
44
|
+
/** A second of white noise per context, looped by every noise layer. */
|
|
45
|
+
function noise(ctx) {
|
|
46
|
+
let buffer = noiseBuffers.get(ctx);
|
|
47
|
+
if (!buffer) {
|
|
48
|
+
buffer = ctx.createBuffer(1, ctx.sampleRate, ctx.sampleRate);
|
|
49
|
+
const data = buffer.getChannelData(0);
|
|
50
|
+
const next = random(7);
|
|
51
|
+
for (let i = 0; i < data.length; i++) data[i] = next() * 2 - 1;
|
|
52
|
+
noiseBuffers.set(ctx, buffer);
|
|
53
|
+
}
|
|
54
|
+
return buffer;
|
|
55
|
+
}
|
|
56
|
+
/** The shared room: a short stereo tail of decaying noise, about 0.7 s, darker as it fades. */
|
|
57
|
+
function roomImpulse(ctx) {
|
|
58
|
+
const length = Math.round(ctx.sampleRate * .7);
|
|
59
|
+
const buffer = ctx.createBuffer(2, length, ctx.sampleRate);
|
|
60
|
+
for (let c = 0; c < 2; c++) {
|
|
61
|
+
const data = buffer.getChannelData(c);
|
|
62
|
+
const next = random(11 + c);
|
|
63
|
+
let low = 0;
|
|
64
|
+
for (let i = 0; i < length; i++) {
|
|
65
|
+
const t = i / length;
|
|
66
|
+
low += (next() * 2 - 1 - low) * (.6 - .5 * t);
|
|
67
|
+
data[i] = low * Math.pow(1 - t, 3) * (i < ctx.sampleRate * .008 ? i / (ctx.sampleRate * .008) : 1);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return buffer;
|
|
71
|
+
}
|
|
72
|
+
/** Builds the master chain on a context: master gain → limiter → speakers, and the room into the master. */
|
|
73
|
+
function createBus(ctx, limiter = true) {
|
|
74
|
+
const input = ctx.createGain();
|
|
75
|
+
if (limiter) {
|
|
76
|
+
const limit = ctx.createDynamicsCompressor();
|
|
77
|
+
limit.threshold.value = -8;
|
|
78
|
+
limit.knee.value = 4;
|
|
79
|
+
limit.ratio.value = 16;
|
|
80
|
+
limit.attack.value = .001;
|
|
81
|
+
limit.release.value = .12;
|
|
82
|
+
input.connect(limit).connect(ctx.destination);
|
|
83
|
+
} else input.connect(ctx.destination);
|
|
84
|
+
const room = ctx.createGain();
|
|
85
|
+
const convolver = ctx.createConvolver();
|
|
86
|
+
convolver.buffer = roomImpulse(ctx);
|
|
87
|
+
room.connect(convolver).connect(input);
|
|
88
|
+
return {
|
|
89
|
+
input,
|
|
90
|
+
room
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/** How long a cue's layers ring, in seconds, before the room's tail. */
|
|
94
|
+
function cueDuration(theme, cue, options = {}) {
|
|
95
|
+
const decay = EMPHASIS[options.emphasis ?? "normal"].decay;
|
|
96
|
+
let end = 0;
|
|
97
|
+
for (const layer of theme.cues[cue].slice(0, 12)) end = Math.max(end, (layer.at ?? 0) + (layer.a ?? .002) + layer.d * decay + FADE);
|
|
98
|
+
return end;
|
|
99
|
+
}
|
|
100
|
+
/** One layer's nodes, scheduled from `start`. Returns when it ends. */
|
|
101
|
+
function voice(ctx, out, layer, start, pitch, decay, level, back) {
|
|
102
|
+
const a = Math.max(layer.a ?? .002, .001);
|
|
103
|
+
const d = Math.max(layer.d * decay, .005);
|
|
104
|
+
const peak = clamp(layer.peak, 0, .5) * level;
|
|
105
|
+
const end = start + a + d;
|
|
106
|
+
let from = hz(layer.f * pitch);
|
|
107
|
+
let to = layer.to === void 0 ? from : hz(layer.to * pitch);
|
|
108
|
+
if (back) [from, to] = [to, from];
|
|
109
|
+
const glide = Math.max(layer.glide ?? a + d, .001);
|
|
110
|
+
const env = ctx.createGain();
|
|
111
|
+
env.gain.setValueAtTime(0, start);
|
|
112
|
+
env.gain.linearRampToValueAtTime(peak, start + a);
|
|
113
|
+
env.gain.exponentialRampToValueAtTime(Math.min(FLOOR, peak / 2 || FLOOR), end);
|
|
114
|
+
env.gain.linearRampToValueAtTime(0, end + FADE);
|
|
115
|
+
let source;
|
|
116
|
+
let frequency;
|
|
117
|
+
if (layer.kind === "tone") {
|
|
118
|
+
const osc = ctx.createOscillator();
|
|
119
|
+
osc.type = layer.wave;
|
|
120
|
+
source = osc;
|
|
121
|
+
frequency = osc.frequency;
|
|
122
|
+
osc.connect(env);
|
|
123
|
+
} else {
|
|
124
|
+
const src = ctx.createBufferSource();
|
|
125
|
+
src.buffer = noise(ctx);
|
|
126
|
+
src.loop = true;
|
|
127
|
+
const filter = ctx.createBiquadFilter();
|
|
128
|
+
filter.type = layer.filter;
|
|
129
|
+
filter.Q.value = clamp(layer.q ?? 1, 1e-4, 40);
|
|
130
|
+
source = src;
|
|
131
|
+
frequency = filter.frequency;
|
|
132
|
+
src.connect(filter).connect(env);
|
|
133
|
+
}
|
|
134
|
+
frequency.setValueAtTime(from, start);
|
|
135
|
+
if (to !== from) frequency.exponentialRampToValueAtTime(to, start + glide);
|
|
136
|
+
env.connect(out);
|
|
137
|
+
source.start(start);
|
|
138
|
+
source.stop(end + FADE + .01);
|
|
139
|
+
return end + FADE;
|
|
140
|
+
}
|
|
141
|
+
/** Plays a cue on `bus` at `when` (the context's clock). Returns when its layers end. */
|
|
142
|
+
function scheduleCue(ctx, bus, theme, cue, options, when, volume, humanize) {
|
|
143
|
+
const emphasis = EMPHASIS[options.emphasis ?? "normal"];
|
|
144
|
+
const back = options.direction === "back";
|
|
145
|
+
const semitones = (options.pitch ?? 0) + (options.value === void 0 ? 0 : (clamp(options.value, 0, 1) - .5) * 12) + (back ? -2 : 0) + (humanize ? (Math.random() - .5) * .3 : 0);
|
|
146
|
+
const pitch = Math.pow(2, semitones / 12);
|
|
147
|
+
const level = volume * volume * theme.gain * emphasis.gain * (humanize ? .95 + Math.random() * .1 : 1);
|
|
148
|
+
const cueBus = ctx.createGain();
|
|
149
|
+
cueBus.connect(bus.input);
|
|
150
|
+
const send = ctx.createGain();
|
|
151
|
+
send.gain.value = clamp(theme.room * emphasis.room * roomShare(cue), 0, 1);
|
|
152
|
+
cueBus.connect(send).connect(bus.room);
|
|
153
|
+
let end = when;
|
|
154
|
+
for (const layer of theme.cues[cue].slice(0, 12)) {
|
|
155
|
+
const accent = layer.accent ? emphasis.accent : 1;
|
|
156
|
+
if (accent === 0) continue;
|
|
157
|
+
end = Math.max(end, voice(ctx, cueBus, layer, when + (layer.at ?? 0), pitch, emphasis.decay, level * accent, back));
|
|
158
|
+
}
|
|
159
|
+
return end;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Renders a cue to an `AudioBuffer` without a speaker (an `OfflineAudioContext`): for tests, waveforms, or a
|
|
163
|
+
* WAV file. No humanizing, so a render is the same every time. Browser only.
|
|
164
|
+
*/
|
|
165
|
+
async function renderCue(theme, cue, options = {}) {
|
|
166
|
+
const sampleRate = options.sampleRate ?? 48e3;
|
|
167
|
+
const seconds = cueDuration(theme, cue, options) + (theme.room > 0 ? .75 : .02);
|
|
168
|
+
const ctx = new OfflineAudioContext(2, Math.ceil(seconds * sampleRate), sampleRate);
|
|
169
|
+
scheduleCue(ctx, createBus(ctx, options.limiter ?? true), options.theme ?? theme, cue, options, 0, options.volume ?? 1, false);
|
|
170
|
+
return ctx.startRendering();
|
|
171
|
+
}
|
|
172
|
+
export { MAX_LAYERS, createBus, cueDuration, renderCue, scheduleCue };
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { defineTheme, score } from "./themes/score.js";
|
|
2
|
+
import { soft } from "./themes/soft.js";
|
|
3
|
+
import { cueFamilies, cueNames } from "./engine/cues.js";
|
|
4
|
+
import { cueDuration, renderCue } from "./engine/synth.js";
|
|
5
|
+
import { createSoundEngine } from "./engine/engine.js";
|
|
6
|
+
import { mechanical } from "./themes/mechanical.js";
|
|
7
|
+
import { glass } from "./themes/glass.js";
|
|
8
|
+
import { SoundProvider, useSound } from "./sound-provider/sound-provider.js";
|
|
9
|
+
export { SoundProvider, createSoundEngine, cueDuration, cueFamilies, cueNames, defineTheme, glass, mechanical, renderCue, score, soft, useSound };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SoundProvider, useSound } from "./sound-provider.js";
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createSoundEngine } from "../engine/engine.js";
|
|
2
|
+
import { createComponent } from "@solidjs/web";
|
|
3
|
+
import { CueContext } from "@zsherman/kit/cues";
|
|
4
|
+
import { createContext, createEffect, onSettled, useContext } from "solid-js";
|
|
5
|
+
// src/sound-provider/sound-provider.tsx
|
|
6
|
+
const SoundContext = createContext(null);
|
|
7
|
+
/**
|
|
8
|
+
* Turns on the kit's sounds: inside it, components play their cues (a Switch `toggle-on`, a Dialog `open`, a
|
|
9
|
+
* toast `success`). Without it the kit is silent and none of the engine is in the bundle. No sound plays
|
|
10
|
+
* before the person's first tap, click or key press on the page.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* <SoundProvider muted={!soundOn()}>
|
|
14
|
+
* <App />
|
|
15
|
+
* </SoundProvider>
|
|
16
|
+
*/
|
|
17
|
+
function SoundProvider(props) {
|
|
18
|
+
const outer = useContext(SoundContext);
|
|
19
|
+
let settings = {};
|
|
20
|
+
createEffect(() => ({
|
|
21
|
+
muted: props.muted,
|
|
22
|
+
volume: props.volume,
|
|
23
|
+
theme: props.theme,
|
|
24
|
+
cues: props.cues,
|
|
25
|
+
engine: props.engine
|
|
26
|
+
}), (next) => {
|
|
27
|
+
settings = next;
|
|
28
|
+
});
|
|
29
|
+
let own;
|
|
30
|
+
const engine = () => settings.engine ?? outer?.engine() ?? (own ??= createSoundEngine());
|
|
31
|
+
onSettled(() => () => own?.dispose());
|
|
32
|
+
const play = (cue, options = {}) => {
|
|
33
|
+
if (settings.muted) return;
|
|
34
|
+
const mapped = settings.cues?.[cue];
|
|
35
|
+
if (mapped === false) return;
|
|
36
|
+
const next = {
|
|
37
|
+
...options,
|
|
38
|
+
volume: (settings.volume ?? 1) * (options.volume ?? 1),
|
|
39
|
+
theme: options.theme ?? settings.theme
|
|
40
|
+
};
|
|
41
|
+
if (outer && !settings.engine) outer.play(mapped ?? cue, next);
|
|
42
|
+
else engine().play(mapped ?? cue, next);
|
|
43
|
+
};
|
|
44
|
+
const cuePlayer = (cue, options) => play(cue, options);
|
|
45
|
+
return createComponent(SoundContext, {
|
|
46
|
+
value: {
|
|
47
|
+
play,
|
|
48
|
+
engine
|
|
49
|
+
},
|
|
50
|
+
get children() {
|
|
51
|
+
return createComponent(CueContext, {
|
|
52
|
+
value: cuePlayer,
|
|
53
|
+
get children() {
|
|
54
|
+
return props.children;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Plays cues from your own code: a sent message, a finished upload, a game. Call `play` from the handler, after
|
|
62
|
+
* the visible change.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* const sound = useSound();
|
|
66
|
+
* <Button onClick={() => { save(); sound.play("success"); }}>Save</Button>
|
|
67
|
+
*/
|
|
68
|
+
function useSound() {
|
|
69
|
+
const context = useContext(SoundContext);
|
|
70
|
+
return {
|
|
71
|
+
play: (cue, options) => context?.play(cue, options),
|
|
72
|
+
engine: () => context?.engine()
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export { SoundProvider, useSound };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { CEILING, defineTheme } from "./score.js";
|
|
2
|
+
// src/themes/glass.ts
|
|
3
|
+
/**
|
|
4
|
+
* Glass: bright struck bars that ring. Tones go up a fifth and last longer, with the inharmonic partials of a
|
|
5
|
+
* free bar (2.76× and 5.4×) dying away first; noise rings through narrow filters; a larger room. For calm,
|
|
6
|
+
* airy products and moments that should feel light.
|
|
7
|
+
*/
|
|
8
|
+
const glass = /* @__PURE__ */ defineTheme("glass", .3, .85, (layer) => {
|
|
9
|
+
if (layer.kind === "noise") return [{
|
|
10
|
+
...layer,
|
|
11
|
+
f: Math.min(layer.f * 1.6, CEILING),
|
|
12
|
+
to: layer.to && Math.min(layer.to * 1.6, 12e3),
|
|
13
|
+
q: (layer.q ?? 1) * 6,
|
|
14
|
+
peak: layer.peak * .6
|
|
15
|
+
}];
|
|
16
|
+
const f = layer.f * 1.5;
|
|
17
|
+
const to = layer.to && layer.to * 1.5;
|
|
18
|
+
const layers = [{
|
|
19
|
+
...layer,
|
|
20
|
+
wave: "sine",
|
|
21
|
+
f,
|
|
22
|
+
to,
|
|
23
|
+
a: Math.max(layer.a ?? 0, .002),
|
|
24
|
+
d: layer.d * 1.5
|
|
25
|
+
}];
|
|
26
|
+
for (const [ratio, level, decay] of [[
|
|
27
|
+
2.76,
|
|
28
|
+
.35,
|
|
29
|
+
.5
|
|
30
|
+
], [
|
|
31
|
+
5.4,
|
|
32
|
+
.12,
|
|
33
|
+
.25
|
|
34
|
+
]]) {
|
|
35
|
+
if (f * ratio > 12e3 || layer.accent && ratio > 3) continue;
|
|
36
|
+
layers.push({
|
|
37
|
+
...layer,
|
|
38
|
+
wave: "sine",
|
|
39
|
+
f: f * ratio,
|
|
40
|
+
to: to && to * ratio,
|
|
41
|
+
peak: layer.peak * level,
|
|
42
|
+
d: layer.d * 1.5 * decay
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return layers;
|
|
46
|
+
});
|
|
47
|
+
export { glass };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { CEILING, defineTheme } from "./score.js";
|
|
2
|
+
// src/themes/mechanical.ts
|
|
3
|
+
/**
|
|
4
|
+
* Mechanical: dry keycaps and switches. Each tone becomes a contact click (narrow noise) over a short
|
|
5
|
+
* triangle body and a low thock; transients halve, and there's almost no room. For tools, terminals and
|
|
6
|
+
* dense, fast UI.
|
|
7
|
+
*/
|
|
8
|
+
const mechanical = /* @__PURE__ */ defineTheme("mechanical", .03, 1.6, (layer) => {
|
|
9
|
+
if (layer.kind === "noise") return [{
|
|
10
|
+
...layer,
|
|
11
|
+
q: (layer.q ?? 1) * 1.5,
|
|
12
|
+
d: layer.d * .6,
|
|
13
|
+
peak: layer.peak * 1.3
|
|
14
|
+
}];
|
|
15
|
+
const click = {
|
|
16
|
+
kind: "noise",
|
|
17
|
+
filter: "bandpass",
|
|
18
|
+
f: Math.min(layer.f * 2.5, CEILING),
|
|
19
|
+
q: 3,
|
|
20
|
+
at: layer.at,
|
|
21
|
+
d: .008,
|
|
22
|
+
peak: layer.peak * .7,
|
|
23
|
+
accent: layer.accent
|
|
24
|
+
};
|
|
25
|
+
const body = {
|
|
26
|
+
...layer,
|
|
27
|
+
wave: layer.wave === "sine" ? "triangle" : layer.wave,
|
|
28
|
+
a: .001,
|
|
29
|
+
d: layer.d * .5
|
|
30
|
+
};
|
|
31
|
+
const thock = {
|
|
32
|
+
...layer,
|
|
33
|
+
wave: "square",
|
|
34
|
+
f: layer.f * .5,
|
|
35
|
+
to: layer.to && layer.to * .5,
|
|
36
|
+
a: .001,
|
|
37
|
+
d: Math.min(layer.d * .3, .03),
|
|
38
|
+
peak: layer.peak * .18
|
|
39
|
+
};
|
|
40
|
+
return layer.accent ? [click, body] : [
|
|
41
|
+
click,
|
|
42
|
+
body,
|
|
43
|
+
thock
|
|
44
|
+
];
|
|
45
|
+
});
|
|
46
|
+
export { mechanical };
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// src/themes/score.ts
|
|
2
|
+
const tone = (f, d, peak, more = {}) => ({
|
|
3
|
+
kind: "tone",
|
|
4
|
+
wave: "sine",
|
|
5
|
+
f,
|
|
6
|
+
d,
|
|
7
|
+
peak,
|
|
8
|
+
...more
|
|
9
|
+
});
|
|
10
|
+
const noise = (filter, f, d, peak, more = {}) => ({
|
|
11
|
+
kind: "noise",
|
|
12
|
+
filter,
|
|
13
|
+
f,
|
|
14
|
+
d,
|
|
15
|
+
peak,
|
|
16
|
+
...more
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Every theme plays the same gestures: the same notes, rhythm and sweeps per cue, so a cue means one thing
|
|
20
|
+
* whichever theme plays it (on rises and off falls; success resolves upward, error falls and darkens). A
|
|
21
|
+
* theme's voice decides the timbre. Outcome cues (warning, error, denied) are triangles, a little buzzier
|
|
22
|
+
* than the rest, so they don't read as confirmations.
|
|
23
|
+
*/
|
|
24
|
+
const score = {
|
|
25
|
+
tap: [tone(1100, .045, .3, {
|
|
26
|
+
to: 850,
|
|
27
|
+
glide: .03
|
|
28
|
+
}), noise("bandpass", 3200, .012, .08, { q: 1.2 })],
|
|
29
|
+
type: [tone(1900, .022, .12), noise("highpass", 4500, .008, .07)],
|
|
30
|
+
tick: [tone(1400, .028, .18)],
|
|
31
|
+
drag: [tone(520, .07, .2, { to: 700 }), noise("bandpass", 1800, .03, .04, { q: .8 })],
|
|
32
|
+
drop: [tone(720, .09, .28, {
|
|
33
|
+
to: 430,
|
|
34
|
+
glide: .05
|
|
35
|
+
}), noise("lowpass", 900, .03, .1)],
|
|
36
|
+
"toggle-on": [tone(660, .06, .22), tone(990, .09, .22, { at: .045 })],
|
|
37
|
+
"toggle-off": [tone(990, .05, .2), tone(660, .08, .2, { at: .04 })],
|
|
38
|
+
check: [tone(1320, .07, .22), tone(2640, .04, .06, { accent: true })],
|
|
39
|
+
uncheck: [tone(990, .05, .18)],
|
|
40
|
+
select: [tone(1175, .08, .22), tone(2350, .05, .06, { accent: true })],
|
|
41
|
+
open: [tone(440, .16, .18, {
|
|
42
|
+
to: 880,
|
|
43
|
+
glide: .12,
|
|
44
|
+
a: .01
|
|
45
|
+
}), noise("bandpass", 1200, .14, .05, {
|
|
46
|
+
to: 3e3,
|
|
47
|
+
glide: .12,
|
|
48
|
+
q: .8,
|
|
49
|
+
a: .02
|
|
50
|
+
})],
|
|
51
|
+
close: [tone(880, .12, .17, {
|
|
52
|
+
to: 440,
|
|
53
|
+
glide: .1,
|
|
54
|
+
a: .005
|
|
55
|
+
}), noise("bandpass", 3e3, .1, .05, {
|
|
56
|
+
to: 1200,
|
|
57
|
+
glide: .1,
|
|
58
|
+
q: .8
|
|
59
|
+
})],
|
|
60
|
+
expand: [tone(620, .08, .18, {
|
|
61
|
+
to: 930,
|
|
62
|
+
glide: .06
|
|
63
|
+
})],
|
|
64
|
+
collapse: [tone(930, .08, .18, {
|
|
65
|
+
to: 620,
|
|
66
|
+
glide: .06
|
|
67
|
+
})],
|
|
68
|
+
navigate: [tone(880, .05, .16), tone(1320, .07, .14, { at: .035 })],
|
|
69
|
+
success: [
|
|
70
|
+
tone(784, .12, .22),
|
|
71
|
+
tone(1175, .22, .22, { at: .08 }),
|
|
72
|
+
tone(2350, .12, .05, {
|
|
73
|
+
at: .08,
|
|
74
|
+
accent: true
|
|
75
|
+
})
|
|
76
|
+
],
|
|
77
|
+
warning: [tone(698, .1, .18, { wave: "triangle" }), tone(698, .12, .16, {
|
|
78
|
+
at: .14,
|
|
79
|
+
wave: "triangle"
|
|
80
|
+
})],
|
|
81
|
+
error: [tone(466, .13, .22, { wave: "triangle" }), tone(349, .22, .22, {
|
|
82
|
+
at: .1,
|
|
83
|
+
wave: "triangle"
|
|
84
|
+
})],
|
|
85
|
+
denied: [tone(220, .08, .3, {
|
|
86
|
+
to: 190,
|
|
87
|
+
wave: "triangle"
|
|
88
|
+
}), noise("lowpass", 500, .05, .08)],
|
|
89
|
+
notify: [
|
|
90
|
+
tone(1047, .22, .2),
|
|
91
|
+
tone(1319, .3, .18, { at: .1 }),
|
|
92
|
+
tone(2637, .16, .04, {
|
|
93
|
+
at: .1,
|
|
94
|
+
accent: true
|
|
95
|
+
})
|
|
96
|
+
],
|
|
97
|
+
send: [tone(520, .11, .16, {
|
|
98
|
+
to: 1500,
|
|
99
|
+
glide: .1
|
|
100
|
+
}), noise("highpass", 2500, .1, .04, {
|
|
101
|
+
to: 7e3,
|
|
102
|
+
glide: .1
|
|
103
|
+
})],
|
|
104
|
+
receive: [tone(988, .08, .18), tone(1480, .14, .18, { at: .06 })],
|
|
105
|
+
copy: [tone(1568, .04, .16), tone(2093, .06, .14, { at: .035 })],
|
|
106
|
+
delete: [noise("bandpass", 1600, .14, .14, {
|
|
107
|
+
to: 380,
|
|
108
|
+
glide: .12,
|
|
109
|
+
q: 1.2
|
|
110
|
+
}), tone(320, .1, .18, {
|
|
111
|
+
to: 180,
|
|
112
|
+
wave: "triangle"
|
|
113
|
+
})],
|
|
114
|
+
complete: [
|
|
115
|
+
tone(1047, .16, .16),
|
|
116
|
+
tone(1319, .16, .15, { at: .06 }),
|
|
117
|
+
tone(1568, .18, .15, { at: .12 }),
|
|
118
|
+
tone(2093, .28, .14, {
|
|
119
|
+
at: .18,
|
|
120
|
+
accent: true
|
|
121
|
+
})
|
|
122
|
+
],
|
|
123
|
+
mute: [tone(523, .07, .2), tone(392, .1, .18, { at: .05 })],
|
|
124
|
+
unmute: [tone(392, .06, .18), tone(523, .1, .2, { at: .05 })],
|
|
125
|
+
"muted-speaking": [tone(440, .05, .16, { wave: "triangle" }), tone(440, .06, .14, {
|
|
126
|
+
at: .1,
|
|
127
|
+
wave: "triangle"
|
|
128
|
+
})],
|
|
129
|
+
"participant-join": [tone(587, .12, .15), tone(880, .18, .14, { at: .09 })],
|
|
130
|
+
"participant-leave": [tone(880, .1, .14), tone(587, .16, .14, { at: .09 })],
|
|
131
|
+
"call-join": [
|
|
132
|
+
tone(523, .14, .17),
|
|
133
|
+
tone(659, .14, .16, { at: .08 }),
|
|
134
|
+
tone(784, .22, .16, { at: .16 }),
|
|
135
|
+
tone(1568, .14, .04, {
|
|
136
|
+
at: .16,
|
|
137
|
+
accent: true
|
|
138
|
+
})
|
|
139
|
+
],
|
|
140
|
+
"call-leave": [
|
|
141
|
+
tone(784, .12, .16),
|
|
142
|
+
tone(659, .12, .16, { at: .08 }),
|
|
143
|
+
tone(523, .22, .17, { at: .16 })
|
|
144
|
+
],
|
|
145
|
+
knock: [
|
|
146
|
+
noise("lowpass", 900, .03, .14),
|
|
147
|
+
tone(240, .05, .22, { wave: "triangle" }),
|
|
148
|
+
noise("lowpass", 900, .03, .13, { at: .14 }),
|
|
149
|
+
tone(240, .05, .2, {
|
|
150
|
+
at: .14,
|
|
151
|
+
wave: "triangle"
|
|
152
|
+
})
|
|
153
|
+
],
|
|
154
|
+
"hand-raise": [
|
|
155
|
+
tone(659, .1, .18),
|
|
156
|
+
tone(988, .2, .16, { at: .07 }),
|
|
157
|
+
tone(1976, .12, .04, {
|
|
158
|
+
at: .07,
|
|
159
|
+
accent: true
|
|
160
|
+
})
|
|
161
|
+
],
|
|
162
|
+
"recording-start": [
|
|
163
|
+
tone(880, .07, .17),
|
|
164
|
+
tone(880, .07, .17, { at: .12 }),
|
|
165
|
+
tone(1175, .24, .17, { at: .24 })
|
|
166
|
+
],
|
|
167
|
+
"recording-stop": [tone(1175, .08, .16), tone(880, .2, .16, { at: .1 })],
|
|
168
|
+
"share-start": [tone(500, .15, .16, {
|
|
169
|
+
to: 1e3,
|
|
170
|
+
glide: .12,
|
|
171
|
+
a: .008
|
|
172
|
+
}), noise("bandpass", 1500, .12, .04, {
|
|
173
|
+
to: 3500,
|
|
174
|
+
glide: .12,
|
|
175
|
+
q: .8,
|
|
176
|
+
a: .015
|
|
177
|
+
})],
|
|
178
|
+
"share-stop": [tone(1e3, .13, .15, {
|
|
179
|
+
to: 500,
|
|
180
|
+
glide: .1,
|
|
181
|
+
a: .005
|
|
182
|
+
}), noise("bandpass", 3500, .1, .04, {
|
|
183
|
+
to: 1500,
|
|
184
|
+
glide: .1,
|
|
185
|
+
q: .8
|
|
186
|
+
})],
|
|
187
|
+
reconnecting: [tone(659, .12, .18, { wave: "triangle" }), tone(494, .2, .18, {
|
|
188
|
+
at: .1,
|
|
189
|
+
wave: "triangle"
|
|
190
|
+
})],
|
|
191
|
+
reconnected: [
|
|
192
|
+
tone(494, .08, .17),
|
|
193
|
+
tone(659, .08, .16, { at: .07 }),
|
|
194
|
+
tone(988, .2, .15, { at: .14 })
|
|
195
|
+
]
|
|
196
|
+
};
|
|
197
|
+
/** A theme from the shared score and a voice. */
|
|
198
|
+
function defineTheme(name, room, gain, voice) {
|
|
199
|
+
const cues = {};
|
|
200
|
+
for (const [cue, layers] of Object.entries(score)) cues[cue] = layers.flatMap(voice);
|
|
201
|
+
return {
|
|
202
|
+
name,
|
|
203
|
+
room,
|
|
204
|
+
gain,
|
|
205
|
+
cues
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
/** Partials above this are dropped: small speakers don't play them, and they only sting. */
|
|
209
|
+
const CEILING = 12e3;
|
|
210
|
+
export { CEILING, defineTheme, score };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineTheme } from "./score.js";
|
|
2
|
+
// src/themes/soft.ts
|
|
3
|
+
/**
|
|
4
|
+
* Soft: warm mallets in a small room. Each tone gets a quiet second harmonic that dies first, so it reads as
|
|
5
|
+
* struck; noise is darker and lower. The default, for most products.
|
|
6
|
+
*/
|
|
7
|
+
const soft = /* @__PURE__ */ defineTheme("soft", .16, 1, (layer) => {
|
|
8
|
+
if (layer.kind === "noise") return [{
|
|
9
|
+
...layer,
|
|
10
|
+
f: layer.f * .8,
|
|
11
|
+
to: layer.to && layer.to * .8,
|
|
12
|
+
peak: layer.peak * .7
|
|
13
|
+
}];
|
|
14
|
+
const body = {
|
|
15
|
+
...layer,
|
|
16
|
+
a: Math.max(layer.a ?? 0, .003),
|
|
17
|
+
d: layer.d * 1.1
|
|
18
|
+
};
|
|
19
|
+
const overtone = layer.f * 2;
|
|
20
|
+
return overtone > 12e3 ? [body] : [body, {
|
|
21
|
+
...body,
|
|
22
|
+
f: overtone,
|
|
23
|
+
to: layer.to && layer.to * 2,
|
|
24
|
+
peak: layer.peak * .15,
|
|
25
|
+
d: layer.d * .45
|
|
26
|
+
}];
|
|
27
|
+
});
|
|
28
|
+
export { soft };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// src/engine/cues.ts
|
|
2
|
+
/** Every cue, by family, in the order the docs list them. */
|
|
3
|
+
const cueFamilies = {
|
|
4
|
+
input: [
|
|
5
|
+
"tap",
|
|
6
|
+
"type",
|
|
7
|
+
"tick",
|
|
8
|
+
"drag",
|
|
9
|
+
"drop"
|
|
10
|
+
],
|
|
11
|
+
selection: [
|
|
12
|
+
"toggle-on",
|
|
13
|
+
"toggle-off",
|
|
14
|
+
"check",
|
|
15
|
+
"uncheck",
|
|
16
|
+
"select"
|
|
17
|
+
],
|
|
18
|
+
navigation: [
|
|
19
|
+
"open",
|
|
20
|
+
"close",
|
|
21
|
+
"expand",
|
|
22
|
+
"collapse",
|
|
23
|
+
"navigate"
|
|
24
|
+
],
|
|
25
|
+
feedback: [
|
|
26
|
+
"success",
|
|
27
|
+
"warning",
|
|
28
|
+
"error",
|
|
29
|
+
"denied"
|
|
30
|
+
],
|
|
31
|
+
communication: [
|
|
32
|
+
"notify",
|
|
33
|
+
"send",
|
|
34
|
+
"receive"
|
|
35
|
+
],
|
|
36
|
+
editing: [
|
|
37
|
+
"copy",
|
|
38
|
+
"delete",
|
|
39
|
+
"complete"
|
|
40
|
+
],
|
|
41
|
+
call: [
|
|
42
|
+
"mute",
|
|
43
|
+
"unmute",
|
|
44
|
+
"muted-speaking",
|
|
45
|
+
"participant-join",
|
|
46
|
+
"participant-leave",
|
|
47
|
+
"call-join",
|
|
48
|
+
"call-leave",
|
|
49
|
+
"knock",
|
|
50
|
+
"hand-raise",
|
|
51
|
+
"recording-start",
|
|
52
|
+
"recording-stop",
|
|
53
|
+
"share-start",
|
|
54
|
+
"share-stop",
|
|
55
|
+
"reconnecting",
|
|
56
|
+
"reconnected"
|
|
57
|
+
]
|
|
58
|
+
};
|
|
59
|
+
/** Every cue's name. */
|
|
60
|
+
const cueNames = Object.values(cueFamilies).flat();
|
|
61
|
+
/**
|
|
62
|
+
* The shortest gap between two plays of one cue, in ms; a play inside it is dropped. Keys repeat and sliders
|
|
63
|
+
* step faster than the rest, and their cues are shorter. People join and leave in bursts (a meeting's start,
|
|
64
|
+
* a breakout room closing): one cue for the burst, not one per person.
|
|
65
|
+
*/
|
|
66
|
+
const cooldown = (cue) => cue === "type" || cue === "tick" ? 40 : cue === "participant-join" || cue === "participant-leave" || cue === "hand-raise" ? 1500 : 60;
|
|
67
|
+
/** Keys and slider steps repeat fast: they reach the room at a quarter, so their tails don't pile up. */
|
|
68
|
+
const roomShare = (cue) => cue === "type" || cue === "tick" ? .25 : 1;
|
|
69
|
+
export { cooldown, cueFamilies, cueNames, roomShare };
|