Skip to content

Commit ab3b912

Browse files
committed
fix(storybook): Align playground datalists with demo
1 parent bf9ebb6 commit ab3b912

7 files changed

Lines changed: 80 additions & 24 deletions

File tree

storybook/src/app/SoundTouchPlayground.tsx

Lines changed: 74 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ export function SoundTouchPlayground({
9090
const pitchSemitonesListId = `${idPrefix}-pitch-semitones`;
9191

9292
const ensureGraph = async (): Promise<void> => {
93-
if (audioContextRef.current && soundTouchNodeRef.current && gainNodeRef.current) {
93+
if (
94+
audioContextRef.current &&
95+
soundTouchNodeRef.current &&
96+
gainNodeRef.current
97+
) {
9498
return;
9599
}
96100

@@ -118,7 +122,8 @@ export function SoundTouchPlayground({
118122
if (sourceMode === 'buffer') {
119123
const response = await fetch(track.url);
120124
const arrayBuffer = await response.arrayBuffer();
121-
audioBufferRef.current = await audioContextRef.current!.decodeAudioData(arrayBuffer);
125+
audioBufferRef.current =
126+
await audioContextRef.current!.decodeAudioData(arrayBuffer);
122127
setDuration(audioBufferRef.current.duration);
123128
setCurrentTime(0);
124129
sourceOffsetRef.current = 0;
@@ -136,9 +141,8 @@ export function SoundTouchPlayground({
136141
elementRef.current.playbackRate = rate;
137142

138143
if (!elementSourceNodeRef.current) {
139-
elementSourceNodeRef.current = audioContextRef.current!.createMediaElementSource(
140-
elementRef.current,
141-
);
144+
elementSourceNodeRef.current =
145+
audioContextRef.current!.createMediaElementSource(elementRef.current);
142146
elementSourceNodeRef.current.connect(soundTouchNodeRef.current!);
143147
}
144148

@@ -198,8 +202,12 @@ export function SoundTouchPlayground({
198202
if (sourceMode === 'buffer') {
199203
const elapsed =
200204
sourceOffsetRef.current +
201-
(audioContextRef.current!.currentTime - startAtContextTimeRef.current) * rate;
202-
const next = loopEnabled && duration > 0 ? elapsed % duration : Math.min(elapsed, duration);
205+
(audioContextRef.current!.currentTime - startAtContextTimeRef.current) *
206+
rate;
207+
const next =
208+
loopEnabled && duration > 0
209+
? elapsed % duration
210+
: Math.min(elapsed, duration);
203211
setCurrentTime(next);
204212
if (!loopEnabled && elapsed >= duration) {
205213
setIsPlaying(false);
@@ -262,7 +270,8 @@ export function SoundTouchPlayground({
262270
setStatus('Playing');
263271
rafIdRef.current = window.requestAnimationFrame(tick);
264272
} catch (error) {
265-
const message = error instanceof Error ? error.message : 'Unknown audio error';
273+
const message =
274+
error instanceof Error ? error.message : 'Unknown audio error';
266275
setStatus(`Error: ${message}`);
267276
}
268277
};
@@ -271,7 +280,9 @@ export function SoundTouchPlayground({
271280
if (sourceMode === 'buffer') {
272281
if (isPlaying) {
273282
sourceOffsetRef.current +=
274-
(audioContextRef.current!.currentTime - startAtContextTimeRef.current) * rate;
283+
(audioContextRef.current!.currentTime -
284+
startAtContextTimeRef.current) *
285+
rate;
275286
}
276287
if (duration > 0) {
277288
sourceOffsetRef.current = loopEnabled
@@ -294,7 +305,10 @@ export function SoundTouchPlayground({
294305
}
295306

296307
const bounds = event.currentTarget.getBoundingClientRect();
297-
const ratio = Math.min(1, Math.max(0, (event.clientX - bounds.left) / bounds.width));
308+
const ratio = Math.min(
309+
1,
310+
Math.max(0, (event.clientX - bounds.left) / bounds.width),
311+
);
298312
const nextTime = ratio * duration;
299313

300314
if (sourceMode === 'buffer') {
@@ -355,18 +369,40 @@ export function SoundTouchPlayground({
355369
}, []);
356370

357371
return (
358-
<div style={{ fontFamily: 'ui-sans-serif, system-ui, sans-serif', padding: '1rem', maxWidth: 920 }}>
372+
<div
373+
style={{
374+
fontFamily: 'ui-sans-serif, system-ui, sans-serif',
375+
padding: '1rem',
376+
maxWidth: 920,
377+
}}
378+
>
359379
<h3 style={{ marginTop: 0 }}>{title}</h3>
360380
<p style={{ marginTop: 0, color: '#4b5563' }}>
361-
Source: <strong>{sourceMode === 'buffer' ? 'Manual buffer load' : 'HTML audio element'}</strong> | Buffer:
381+
Source:{' '}
382+
<strong>
383+
{sourceMode === 'buffer'
384+
? 'Manual buffer load'
385+
: 'HTML audio element'}
386+
</strong>{' '}
387+
| Buffer:
362388
<strong> {sampleBufferType}</strong> | Interpolation:
363389
<strong> {interpolationStrategy}</strong>
364390
</p>
365391

366-
<div style={{ display: 'grid', gap: '0.75rem', gridTemplateColumns: 'repeat(auto-fit,minmax(240px,1fr))' }}>
392+
<div
393+
style={{
394+
display: 'grid',
395+
gap: '0.75rem',
396+
gridTemplateColumns: 'repeat(auto-fit,minmax(240px,1fr))',
397+
}}
398+
>
367399
<label>
368400
Track
369-
<select value={selectedTrackId} onChange={onTrackChange} style={{ display: 'block', width: '100%' }}>
401+
<select
402+
value={selectedTrackId}
403+
onChange={onTrackChange}
404+
style={{ display: 'block', width: '100%' }}
405+
>
370406
{TRACKS.map((item) => (
371407
<option key={item.id} value={item.id}>
372408
{item.label}
@@ -499,11 +535,22 @@ export function SoundTouchPlayground({
499535
</label>
500536
</div>
501537

502-
<div style={{ display: 'flex', gap: '0.5rem', marginTop: '1rem', flexWrap: 'wrap' }}>
538+
<div
539+
style={{
540+
display: 'flex',
541+
gap: '0.5rem',
542+
marginTop: '1rem',
543+
flexWrap: 'wrap',
544+
}}
545+
>
503546
<button type="button" onClick={() => void loadTrack()}>
504547
Load
505548
</button>
506-
<button type="button" onClick={() => void startPlayback()} disabled={isPlaying}>
549+
<button
550+
type="button"
551+
onClick={() => void startPlayback()}
552+
disabled={isPlaying}
553+
>
507554
Play
508555
</button>
509556
<button type="button" onClick={stopPlayback} disabled={!isPlaying}>
@@ -518,13 +565,22 @@ export function SoundTouchPlayground({
518565
onClick={handleSeek}
519566
style={{ width: '100%', cursor: 'pointer' }}
520567
/>
521-
<div style={{ display: 'flex', justifyContent: 'space-between', marginTop: '0.25rem', fontSize: '0.9rem' }}>
568+
<div
569+
style={{
570+
display: 'flex',
571+
justifyContent: 'space-between',
572+
marginTop: '0.25rem',
573+
fontSize: '0.9rem',
574+
}}
575+
>
522576
<span>{formatTime(currentTime)}</span>
523577
<span>{formatTime(duration)}</span>
524578
</div>
525579
</div>
526580

527-
<p style={{ marginBottom: 0, marginTop: '0.75rem', color: '#374151' }}>{status}</p>
581+
<p style={{ marginBottom: 0, marginTop: '0.75rem', color: '#374151' }}>
582+
{status}
583+
</p>
528584
</div>
529585
);
530586
}

storybook/src/docs/audio-worklet/processor-name.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ Most consumers do not need to use this constant directly.
2222
const name = PROCESSOR_NAME;
2323
```
2424

25-
It is mainly useful for diagnostics, custom assertions, or tests that verify expected processor identity.
25+
It is mainly useful for diagnostics, custom assertions, or tests that verify expected processor identity.

storybook/src/docs/audio-worklet/sound-touch-node.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ new SoundTouchNode({
4040

4141
## Static methods
4242

43-
### `register(context, processorUrl)`
43+
### `register(context, processorUrl)`

storybook/src/docs/core/abstract-sample-pipe.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ When `createBuffers` is `true`, both factories are required.
3535
## Notes
3636

3737
- Most applications use concrete subclasses (`Stretch`, `RateTransposer`) rather than using this class directly.
38-
- `clear()` delegates to both buffers when present.
38+
- `clear()` delegates to both buffers when present.

storybook/src/docs/core/circular-sample-buffer.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ new CircularSampleBuffer(capacityFrames?: number)
3737

3838
- Samples are interleaved stereo (`L, R, L, R, ...`).
3939
- `extract(..., consume = true)` both reads and drops frames.
40-
- Out-of-range `readSample` returns `0`.
40+
- Out-of-range `readSample` returns `0`.

storybook/src/docs/core/fifo-sample-buffer.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ new FifoSampleBuffer(maxFrames?: number)
4141
## Notes
4242

4343
- Uses resizable `ArrayBuffer` on supported runtimes.
44-
- `vector` exposes underlying storage for low-level integrations.
44+
- `vector` exposes underlying storage for low-level integrations.

storybook/src/docs/navigation.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ This page provides an overview of the documentation structure for the SoundTouch
3030
- [Simple Filter](./core/simple-filter)
3131
- [SoundTouch](./core/sound-touch)
3232
- [Stretch](./core/stretch)
33-
- [Unregister Interpolation Strategy](./core/unregister-interpolation-strategy)
33+
- [Unregister Interpolation Strategy](./core/unregister-interpolation-strategy)

0 commit comments

Comments
 (0)