audiora 1.0.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.
@@ -0,0 +1,183 @@
1
+ import { BlockData, NoteData, ScaleDefinition } from "./types";
2
+ import { clamp, midiToFreq, freqToMidi } from "./utils";
3
+ import { SCALES } from "./constants";
4
+ import { State } from "./State";
5
+ import { BlockGrid } from "./ImageProcessor";
6
+
7
+ export abstract class BaseScanStrategy {
8
+ abstract advance(seq: Sequencer, cols: number, rows: number): void;
9
+ abstract reset(seq: Sequencer, grid: BlockGrid): void;
10
+ }
11
+
12
+ class LinearScan extends BaseScanStrategy {
13
+ advance(seq: Sequencer, cols: number, rows: number): void {
14
+ seq.x++;
15
+ if (seq.x >= cols) {
16
+ seq.x = 0;
17
+ seq.y = (seq.y + 1) % rows;
18
+ }
19
+ }
20
+ reset(seq: Sequencer, _grid: BlockGrid): void {
21
+ seq.x = 0;
22
+ seq.y = 0;
23
+ }
24
+ }
25
+
26
+ class VerticalScan extends BaseScanStrategy {
27
+ advance(seq: Sequencer, cols: number, rows: number): void {
28
+ seq.y++;
29
+ if (seq.y >= rows) {
30
+ seq.y = 0;
31
+ seq.x = (seq.x + 1) % cols;
32
+ }
33
+ }
34
+ reset(seq: Sequencer, _grid: BlockGrid): void {
35
+ seq.x = 0;
36
+ seq.y = 0;
37
+ }
38
+ }
39
+
40
+ class ZigzagScan extends BaseScanStrategy {
41
+ advance(seq: Sequencer, cols: number, rows: number): void {
42
+ seq.x += seq.dx;
43
+ if (seq.x >= cols) {
44
+ seq.x = cols - 1;
45
+ seq.dx = -1;
46
+ seq.y = (seq.y + 1) % rows;
47
+ } else if (seq.x < 0) {
48
+ seq.x = 0;
49
+ seq.dx = 1;
50
+ seq.y = (seq.y + 1) % rows;
51
+ }
52
+ }
53
+ reset(seq: Sequencer, _grid: BlockGrid): void {
54
+ seq.x = 0;
55
+ seq.y = 0;
56
+ seq.dx = 1;
57
+ }
58
+ }
59
+
60
+ class DriftScan extends BaseScanStrategy {
61
+ advance(seq: Sequencer, cols: number, rows: number): void {
62
+ const l = seq.lastL ?? 50;
63
+ let dx = 0, dy = 0;
64
+
65
+ if (Math.random() < 0.05) {
66
+ seq.x = Math.floor(Math.random() * cols);
67
+ seq.y = Math.floor(Math.random() * rows);
68
+ return;
69
+ }
70
+
71
+ if (l > 60) dx = 1;
72
+ else if (l < 40) dx = -1;
73
+ else dy = Math.random() < 0.5 ? 1 : -1;
74
+
75
+ if (Math.random() < 0.15) {
76
+ dx = Math.floor(Math.random() * 3) - 1;
77
+ dy = Math.floor(Math.random() * 3) - 1;
78
+ }
79
+
80
+ seq.x = (seq.x + dx + cols) % cols;
81
+ seq.y = (seq.y + dy + rows) % rows;
82
+ }
83
+ reset(seq: Sequencer, _grid: BlockGrid): void {
84
+ seq.x = 0;
85
+ seq.y = 0;
86
+ }
87
+ }
88
+
89
+ class SpiralScan extends BaseScanStrategy {
90
+ advance(seq: Sequencer, _cols: number, _rows: number): void {
91
+ const path = seq.grid.spiralPath;
92
+ if (!path.length) return;
93
+ seq.spiralIdx = (seq.spiralIdx + 1) % path.length;
94
+ const sp = path[seq.spiralIdx];
95
+ seq.x = sp.x;
96
+ seq.y = sp.y;
97
+ }
98
+ reset(seq: Sequencer, grid: BlockGrid): void {
99
+ seq.spiralIdx = 0;
100
+ if (grid.spiralPath.length) {
101
+ seq.x = grid.spiralPath[0].x;
102
+ seq.y = grid.spiralPath[0].y;
103
+ } else {
104
+ seq.x = 0;
105
+ seq.y = 0;
106
+ }
107
+ }
108
+ }
109
+
110
+ export class ScanStrategyFactory {
111
+ private static strategies: Record<string, BaseScanStrategy> = {
112
+ linear: new LinearScan(),
113
+ vertical: new VerticalScan(),
114
+ zigzag: new ZigzagScan(),
115
+ drift: new DriftScan(),
116
+ spiral: new SpiralScan(),
117
+ };
118
+
119
+ public static get(mode: string): BaseScanStrategy {
120
+ return this.strategies[mode] ?? this.strategies["linear"];
121
+ }
122
+ }
123
+
124
+ export class Sequencer {
125
+ public x: number = 0;
126
+ public y: number = 0;
127
+ public dx: number = 1;
128
+ public visX: number = 0;
129
+ public visY: number = 0;
130
+ public renderX: number = 0;
131
+ public renderY: number = 0;
132
+ public visIdx: number = 0;
133
+ public nextTime: number = 0;
134
+ public raf: number | null = null;
135
+ public lastL: number = 50;
136
+ public active: boolean = false;
137
+ public spiralIdx: number = 0;
138
+ public activateAt: number = 0;
139
+
140
+ constructor(public readonly grid: BlockGrid) {}
141
+
142
+ public resetPosition(state: State): void {
143
+ const strategy = ScanStrategyFactory.get(state.scan_mode);
144
+ strategy.reset(this, this.grid);
145
+ this.dx = 1;
146
+ this.visX = 0;
147
+ this.visY = 0;
148
+ this.renderX = 0;
149
+ this.renderY = 0;
150
+ this.visIdx = 0;
151
+ this.lastL = 50;
152
+ this.active = false;
153
+ this.spiralIdx = 0;
154
+ this.activateAt = 0;
155
+ }
156
+
157
+ public currentBlockIdx(): number {
158
+ const idx = this.y * this.grid.cols + this.x;
159
+ if (!isFinite(idx)) return 0;
160
+ return clamp(idx, 0, this.grid.list.length - 1);
161
+ }
162
+
163
+ public advance(state: State): void {
164
+ const cols = this.grid.cols;
165
+ const rows = this.grid.rows;
166
+ if (cols <= 0 || rows <= 0) return;
167
+ const strategy = ScanStrategyFactory.get(state.scan_mode);
168
+ strategy.advance(this, cols, rows);
169
+ }
170
+
171
+ public clampToGrid(): void {
172
+ this.x = Math.min(this.x, Math.max(0, this.grid.cols - 1));
173
+ this.y = Math.min(this.y, Math.max(0, this.grid.rows - 1));
174
+ }
175
+
176
+ public static mapBlockToNote(block: BlockData, sc: ScaleDefinition, state: State): NoteData {
177
+ const interval = sc.intervals[block.degree % sc.intervals.length] + 12 * block.oct;
178
+ const hueDetune = block.pan * 5;
179
+ const freq = midiToFreq(freqToMidi(state.base_note) + interval + hueDetune / 100);
180
+ const pan = block.pan * state.pan_amount;
181
+ return { freq, vel: block.vel, brightness: block.l / 100, pan };
182
+ }
183
+ }
@@ -0,0 +1,105 @@
1
+ import { State } from "./State";
2
+ import { AudioEngine } from "./AudioEngine";
3
+ import { Synthesizer } from "./Synthesizer";
4
+ import { Sequencer } from "./Scanner";
5
+ import { BlockGrid } from "./ImageProcessor";
6
+ import { SCALES } from "./constants";
7
+ import { clamp, midiToFreq, freqToMidi } from "./utils";
8
+
9
+ export class Scheduler {
10
+ private raf: number | null = null;
11
+
12
+ constructor(
13
+ private readonly state: State,
14
+ private readonly engine: AudioEngine,
15
+ private readonly synth: Synthesizer,
16
+ private readonly seq: Sequencer,
17
+ private readonly grid: BlockGrid
18
+ ) {}
19
+
20
+ public start(): void {
21
+ if (!this.engine.ctx) return;
22
+ this.seq.nextTime = this.engine.ctx.currentTime + 0.03;
23
+ if (this.raf) cancelAnimationFrame(this.raf);
24
+ this.tick();
25
+ }
26
+
27
+ public stop(): void {
28
+ if (this.raf) {
29
+ cancelAnimationFrame(this.raf);
30
+ this.raf = null;
31
+ }
32
+ }
33
+
34
+ public resync(): void {
35
+ if (!this.engine.ctx) return;
36
+ const now = this.engine.ctx.currentTime;
37
+ if (this.seq.nextTime < now - 0.02) this.seq.nextTime = now + 0.02;
38
+ }
39
+
40
+ public renderRange(startTime: number, endTime: number): void {
41
+ if (!(this.grid.list.length && this.grid.cols && this.grid.rows)) return;
42
+
43
+ const stepDur = this.synth.getStepDur();
44
+ let time = startTime;
45
+
46
+ while (time < endTime) {
47
+ this.playStep(time);
48
+ if (this.state.timing_mode === "expressive") {
49
+ const speedMod = this.synth.getSpeedMod(this.seq.lastL ?? 50);
50
+ time += stepDur / speedMod;
51
+ } else {
52
+ time += stepDur;
53
+ }
54
+ }
55
+ }
56
+
57
+ private tick = (): void => {
58
+ if (!this.state.playing || !this.engine.ctx) return;
59
+
60
+ const now = this.engine.ctx.currentTime;
61
+ if (this.seq.nextTime < now - 0.02) this.seq.nextTime = now;
62
+
63
+ const stepDur = this.synth.getStepDur();
64
+ const lookahead = clamp(stepDur * 2.5, 0.12, 0.3);
65
+
66
+ if (this.grid.list.length && this.grid.cols && this.grid.rows) {
67
+ while (this.seq.nextTime < now + lookahead) {
68
+ this.playStep(this.seq.nextTime);
69
+ if (this.state.timing_mode === "expressive") {
70
+ const speedMod = this.synth.getSpeedMod(this.seq.lastL ?? 50);
71
+ this.seq.nextTime += stepDur / speedMod;
72
+ } else {
73
+ this.seq.nextTime += stepDur;
74
+ }
75
+ }
76
+ }
77
+
78
+ this.raf = requestAnimationFrame(this.tick);
79
+ };
80
+
81
+ private playStep(time: number): void {
82
+ const sc = this.state.scale ?? SCALES[0];
83
+
84
+ if (this.grid.list.length > 0) {
85
+ const idx = this.seq.currentBlockIdx();
86
+ const block = this.grid.list[idx];
87
+ if (block) {
88
+ this.seq.visIdx = idx;
89
+ this.seq.lastL = block.l;
90
+ const note = Sequencer.mapBlockToNote(block, sc, this.state);
91
+ this.synth.scheduleNote(note.freq, note.vel, note.brightness, note.pan, time);
92
+ }
93
+ } else {
94
+ const deg = Math.floor(((this.seq.x % 64) / 64) * (sc.intervals.length - 1));
95
+ const freq = midiToFreq(freqToMidi(this.state.base_note) + sc.intervals[deg]);
96
+ this.seq.lastL = 50;
97
+ this.synth.scheduleNote(freq, 0.6, 0.5, 0, time);
98
+ }
99
+
100
+ this.seq.visX = this.seq.x;
101
+ this.seq.visY = this.seq.y;
102
+ if (this.seq.activateAt === 0) this.seq.activateAt = time;
103
+ this.seq.advance(this.state);
104
+ }
105
+ }
@@ -0,0 +1,86 @@
1
+ import { PresetData, ScaleDefinition } from "./types";
2
+ import { SCALES, STATE_KEYS } from "./constants";
3
+
4
+ export class State implements PresetData {
5
+ public playing: boolean = false;
6
+ public scale: ScaleDefinition = SCALES[0];
7
+
8
+ public osc_type: string = "triangle";
9
+ public scale_name: string = "Minor";
10
+ public base_note: number = 287;
11
+ public bpm: number = 70;
12
+ public speed: number = 4.2;
13
+ public note_mult: number = 0.15;
14
+ public volume: number = 0.99;
15
+ public vibrato_rate: number = 0;
16
+ public vibrato_depth: number = 50;
17
+ public tremolo_rate: number = 1.8;
18
+ public tremolo_depth: number = 0;
19
+ public fifth_lvl: number = 0.37;
20
+ public oct_lvl: number = 0.63;
21
+ public filter_base: number = 1810;
22
+ public filter_track: number = 0;
23
+ public resonance: number = 2.6;
24
+ public reverb_mix: number = 1.0;
25
+ public reverb_time: number = 3.6;
26
+ public bass_gain: number = 13.5;
27
+ public block_w: number = 23;
28
+ public block_h: number = 13;
29
+ public scan_mode: string = "linear";
30
+ public pan_amount: number = 0.6;
31
+ public timing_mode: string = "expressive";
32
+ public timing_intensity: number = 0.4;
33
+
34
+ public applyPatch(patch: Partial<PresetData>): void {
35
+ if (patch.osc_type) this.osc_type = patch.osc_type;
36
+ if (patch.scale_name) {
37
+ this.scale_name = patch.scale_name;
38
+ this.scale = SCALES.find((s) => s.name === patch.scale_name) ?? SCALES[0];
39
+ }
40
+ if (patch.scan_mode) this.scan_mode = patch.scan_mode;
41
+ if (patch.timing_mode) this.timing_mode = patch.timing_mode;
42
+ if (typeof patch.bpm === "number") this.bpm = patch.bpm;
43
+ if (typeof patch.speed === "number") this.speed = patch.speed;
44
+ if (typeof patch.note_mult === "number") this.note_mult = patch.note_mult;
45
+ if (typeof patch.timing_intensity === "number") this.timing_intensity = patch.timing_intensity;
46
+ if (typeof patch.block_w === "number") this.block_w = patch.block_w;
47
+ if (typeof patch.block_h === "number") this.block_h = patch.block_h;
48
+ }
49
+
50
+ public applyAll(patch: Partial<PresetData>): void {
51
+ STATE_KEYS.forEach((k) => {
52
+ const value = patch[k];
53
+ if (value === undefined) return;
54
+ if (k === "scale_name" && typeof value === "string") {
55
+ this.scale_name = value;
56
+ this.scale = SCALES.find((s) => s.name === value) ?? SCALES[0];
57
+ return;
58
+ }
59
+ (this as unknown as Record<string, unknown>)[k] = value;
60
+ });
61
+ }
62
+
63
+ public capture(): Partial<PresetData> {
64
+ const snap: Record<string, unknown> = {};
65
+ STATE_KEYS.forEach((k) => {
66
+ snap[k] = (this as unknown as Record<string, unknown>)[k];
67
+ });
68
+ return snap as Partial<PresetData>;
69
+ }
70
+
71
+ public setNumeric(key: string, value: number): void {
72
+ (this as unknown as Record<string, unknown>)[key] = value;
73
+ }
74
+
75
+ public getNumeric(key: string): number {
76
+ return (this as unknown as Record<string, unknown>)[key] as number;
77
+ }
78
+
79
+ public getString(key: string): string {
80
+ return (this as unknown as Record<string, unknown>)[key] as string;
81
+ }
82
+
83
+ public setString(key: string, value: string): void {
84
+ (this as unknown as Record<string, unknown>)[key] = value;
85
+ }
86
+ }
@@ -0,0 +1,196 @@
1
+ import { State } from "./State";
2
+ import { AudioEngine } from "./AudioEngine";
3
+ import { clamp } from "./utils";
4
+ import { EXPRESSIVE_RANGE } from "./constants";
5
+
6
+ export class Synthesizer {
7
+ constructor(
8
+ private readonly engine: AudioEngine,
9
+ private readonly state: State
10
+ ) {}
11
+
12
+ private expressiveCurve(l: number): number {
13
+ return 0.75 + Math.pow(l / 100, 1.3) * 0.5;
14
+ }
15
+
16
+ private getIntensity(): number {
17
+ return Math.pow(this.state.timing_intensity ?? 1, 1.5);
18
+ }
19
+
20
+ public getStepDur(): number {
21
+ const bpm = isFinite(this.state.bpm) && this.state.bpm > 0 ? this.state.bpm : 120;
22
+ const spd = isFinite(this.state.speed) && this.state.speed > 0 ? this.state.speed : 1;
23
+ return Math.max(0.05, 60 / bpm / clamp(spd, 0.5, 8));
24
+ }
25
+
26
+ public getSpeedMod(lastL: number): number {
27
+ const baseMod = this.expressiveCurve(lastL);
28
+ return clamp(
29
+ 1 + (baseMod - 1) * this.getIntensity() * EXPRESSIVE_RANGE * 0.6,
30
+ 0.85,
31
+ 1.2
32
+ );
33
+ }
34
+
35
+ public scheduleNote(freq: number, vel: number, brightness: number, pan: number, time: number): number {
36
+ const ctx = this.engine.ctx;
37
+ const dry = this.engine.dry;
38
+ const conv = this.engine.conv;
39
+ if (!ctx || !dry || !conv) return time;
40
+
41
+ const jitterAmt = this.state.speed > 2 ? 0.003 : 0.0005;
42
+ const jitter = (Math.random() - 0.5) * jitterAmt;
43
+ time = Math.max(time + jitter, ctx.currentTime + 0.001);
44
+ if (!isFinite(time)) return time;
45
+
46
+ const p = this.state;
47
+ const stepDur = this.getStepDur();
48
+
49
+ const baseMod = this.expressiveCurve(brightness * 100);
50
+ const durMod = clamp(
51
+ 1 + (baseMod - 1) * this.getIntensity() * EXPRESSIVE_RANGE * 0.75,
52
+ 0.85,
53
+ 1.2
54
+ );
55
+
56
+ const dur = clamp(
57
+ isFinite(stepDur) ? stepDur * p.note_mult * (0.6 + 0.8 * vel) * durMod : 0.2,
58
+ 0.06,
59
+ 2.0
60
+ );
61
+
62
+ const cutoff = p.filter_track === 0
63
+ ? p.filter_base
64
+ : clamp(p.filter_base + brightness * p.filter_track, 40, ctx.sampleRate * 0.45);
65
+
66
+ const filt = ctx.createBiquadFilter();
67
+ filt.type = "lowpass";
68
+ filt.Q.value = p.resonance;
69
+ filt.frequency.setValueAtTime(cutoff, time);
70
+
71
+ const env = ctx.createGain();
72
+ env.gain.setValueAtTime(0, time);
73
+
74
+ const trem = ctx.createGain();
75
+ trem.gain.setValueAtTime(1 - p.tremolo_depth, time);
76
+
77
+ const tremLfo = ctx.createOscillator();
78
+ tremLfo.frequency.setValueAtTime(p.tremolo_rate, time);
79
+
80
+ const tremGain = ctx.createGain();
81
+ tremGain.gain.setValueAtTime(p.tremolo_depth, time);
82
+ tremLfo.connect(tremGain).connect(trem.gain);
83
+
84
+ const bass = ctx.createBiquadFilter();
85
+ bass.type = "lowshelf";
86
+ bass.frequency.setValueAtTime(200, time);
87
+ bass.gain.setValueAtTime(p.bass_gain, time);
88
+
89
+ const panner = ctx.createStereoPanner();
90
+ panner.pan.setValueAtTime(clamp(pan, -1, 1), time);
91
+
92
+ filt.connect(env);
93
+ env.connect(trem);
94
+ trem.connect(bass);
95
+ bass.connect(panner);
96
+ panner.connect(conv);
97
+ panner.connect(dry);
98
+
99
+ const peak = 0.2 + vel * 0.6;
100
+ env.gain.linearRampToValueAtTime(peak, time + 0.01);
101
+ env.gain.setTargetAtTime(peak * 0.6, time + 0.03, 0.05);
102
+ env.gain.setTargetAtTime(0.0001, time + dur * 0.7, 0.1);
103
+
104
+ const src = ctx.createGain();
105
+
106
+ const osc = ctx.createOscillator();
107
+ this.applyWave(osc, ctx);
108
+ osc.frequency.setValueAtTime(freq, time);
109
+
110
+ const osc5 = ctx.createOscillator();
111
+ this.applyWave(osc5, ctx);
112
+ osc5.frequency.setValueAtTime(freq * 1.5, time);
113
+
114
+ const osc8 = ctx.createOscillator();
115
+ this.applyWave(osc8, ctx);
116
+ osc8.frequency.setValueAtTime(freq * 2.0, time);
117
+
118
+ const vib = ctx.createOscillator();
119
+ vib.frequency.setValueAtTime(p.vibrato_rate, time);
120
+
121
+ const vibGain = ctx.createGain();
122
+ vibGain.gain.setValueAtTime(freq * (Math.pow(2, p.vibrato_depth / 1200) - 1), time);
123
+
124
+ vib.connect(vibGain);
125
+ vibGain.connect(osc.frequency);
126
+ vibGain.connect(osc5.frequency);
127
+ vibGain.connect(osc8.frequency);
128
+
129
+ const mix5 = ctx.createGain();
130
+ const mix8 = ctx.createGain();
131
+
132
+ let fifthLevel = clamp(p.fifth_lvl, 0, 1);
133
+ let octLevel = clamp(p.oct_lvl, 0, 1);
134
+
135
+ if (p.osc_type === "bell") {
136
+ fifthLevel *= 0.35;
137
+ octLevel *= 0.25;
138
+ }
139
+
140
+ mix5.gain.setValueAtTime(fifthLevel, time);
141
+ mix8.gain.setValueAtTime(octLevel, time);
142
+
143
+ osc.connect(src);
144
+ osc5.connect(mix5).connect(src);
145
+ osc8.connect(mix8).connect(src);
146
+
147
+ src.connect(filt);
148
+
149
+ const end = time + dur + 0.05;
150
+
151
+ osc.start(time);
152
+ osc.stop(end);
153
+ osc5.start(time);
154
+ osc5.stop(end);
155
+ osc8.start(time);
156
+ osc8.stop(end);
157
+ vib.start(time);
158
+ vib.stop(end);
159
+ tremLfo.start(time);
160
+ tremLfo.stop(time + dur + 0.1);
161
+
162
+ return time;
163
+ }
164
+
165
+ private applyWave(oscillator: OscillatorNode, ctx: BaseAudioContext): void {
166
+ const type = this.state.osc_type;
167
+
168
+ if (["sine", "square", "sawtooth", "triangle"].includes(type)) {
169
+ oscillator.type = type as OscillatorType;
170
+ return;
171
+ }
172
+
173
+ if (type === "pulse") {
174
+ const real = new Float32Array([0, 0, 0, 0, 0, 0, 0, 0]);
175
+ const imag = new Float32Array([0, 1, 0, 0.33, 0, 0.2, 0, 0.14]);
176
+ oscillator.setPeriodicWave(ctx.createPeriodicWave(real, imag));
177
+ return;
178
+ }
179
+
180
+ if (type === "organ") {
181
+ const real = new Float32Array([0, 1, 0.8, 0.6, 0.45, 0.3, 0.2]);
182
+ const imag = new Float32Array(real.length);
183
+ oscillator.setPeriodicWave(ctx.createPeriodicWave(real, imag));
184
+ return;
185
+ }
186
+
187
+ if (type === "bell") {
188
+ const real = new Float32Array([0, 1, 0.9, 0.55, 0.32, 0.18, 0.09, 0.04]);
189
+ const imag = new Float32Array(real.length);
190
+ oscillator.setPeriodicWave(ctx.createPeriodicWave(real, imag));
191
+ return;
192
+ }
193
+
194
+ oscillator.type = "triangle";
195
+ }
196
+ }
@@ -0,0 +1,70 @@
1
+ import { ScaleDefinition, PresetData, FormatFn } from "./types";
2
+
3
+ export const SCALES: ScaleDefinition[] = [
4
+ { name: "Major", intervals: [0, 2, 4, 5, 7, 9, 11, 12] },
5
+ { name: "Minor", intervals: [0, 2, 3, 5, 7, 8, 10, 12] },
6
+ { name: "Pentatonic", intervals: [0, 2, 4, 7, 9, 12] },
7
+ { name: "Blues", intervals: [0, 3, 5, 6, 7, 10, 12] },
8
+ { name: "Chromatic", intervals: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] },
9
+ { name: "Whole Tone", intervals: [0, 2, 4, 6, 8, 10, 12] },
10
+ { name: "Dorian", intervals: [0, 2, 3, 5, 7, 9, 10, 12] },
11
+ { name: "Phrygian", intervals: [0, 1, 3, 5, 7, 8, 10, 12] },
12
+ { name: "Lydian", intervals: [0, 2, 4, 6, 7, 9, 11, 12] },
13
+ { name: "Harmonic Minor", intervals: [0, 2, 3, 5, 7, 8, 11, 12] },
14
+ { name: "In Sen", intervals: [0, 1, 5, 7, 10, 12] },
15
+ ];
16
+
17
+ export const STATE_KEYS: (keyof PresetData)[] = [
18
+ "osc_type", "scale_name", "base_note", "bpm", "speed", "note_mult",
19
+ "volume", "vibrato_rate", "vibrato_depth", "tremolo_rate", "tremolo_depth",
20
+ "fifth_lvl", "oct_lvl", "filter_base", "filter_track", "resonance",
21
+ "reverb_mix", "reverb_time", "bass_gain", "block_w", "block_h",
22
+ "scan_mode", "pan_amount", "timing_mode", "timing_intensity",
23
+ ];
24
+
25
+ export const FORMAT: Record<string, FormatFn> = {
26
+ volume: (v) => `${Math.round(v * 100)}%`,
27
+ bpm: (v) => String(Math.round(v)),
28
+ speed: (v) => `×${v.toFixed(2)}`,
29
+ note_mult: (v) => `×${v.toFixed(2)}`,
30
+ base_note: (v) => `${Math.round(v)} Hz`,
31
+ fifth_lvl: (v) => `${Math.round(v * 100)}%`,
32
+ oct_lvl: (v) => `${Math.round(v * 100)}%`,
33
+ vibrato_rate: (v) => `${v.toFixed(1)} Hz`,
34
+ vibrato_depth: (v) => `${Math.round(v)} ¢`,
35
+ tremolo_rate: (v) => `${v.toFixed(1)} Hz`,
36
+ tremolo_depth: (v) => `${Math.round(v * 100)}%`,
37
+ filter_base: (v) => `${Math.round(v)} Hz`,
38
+ filter_track: (v) => `${Math.round(v)} Hz`,
39
+ resonance: (v) => v.toFixed(2),
40
+ reverb_mix: (v) => `${Math.round(v * 100)}%`,
41
+ reverb_time: (v) => `${v.toFixed(1)} s`,
42
+ bass_gain: (v) => `${v.toFixed(1)} dB`,
43
+ block_w: (v) => `${Math.round(v)} px`,
44
+ block_h: (v) => `${Math.round(v)} px`,
45
+ pan_amount: (v) => `${Math.round(v * 100)}%`,
46
+ timing_intensity: (v) => `${Math.round(v * 100)}%`,
47
+ };
48
+
49
+ export const RANGE_KEYS = Object.keys(FORMAT) as (keyof PresetData)[];
50
+
51
+ export const SELECT_KEYS = STATE_KEYS.filter((k) => !(k in FORMAT));
52
+
53
+ export const KEY = STATE_KEYS.reduce(
54
+ (acc, k) => {
55
+ acc[k] = k;
56
+ return acc;
57
+ },
58
+ {} as Record<string, keyof PresetData>
59
+ ) as { [K in keyof PresetData]: K };
60
+
61
+ export const EXPRESSIVE_RANGE = 1.2;
62
+ export const TWEEN_MS = 1500;
63
+ export const DEFAULT_PRESET = "Haze";
64
+
65
+ export const TWEEN_KEYS: (keyof PresetData)[] = [
66
+ KEY.volume, KEY.base_note, KEY.vibrato_rate, KEY.vibrato_depth,
67
+ KEY.tremolo_rate, KEY.tremolo_depth, KEY.fifth_lvl, KEY.oct_lvl,
68
+ KEY.filter_base, KEY.filter_track, KEY.resonance, KEY.reverb_mix,
69
+ KEY.reverb_time, KEY.bass_gain, KEY.pan_amount,
70
+ ];