@toneflix/studio 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,20 +5,23 @@
5
5
  **The studio engine for the web.** Give any web app a real multitrack editor. Your users arrange, cut and shape audio as freely as in a desktop DAW, right in the browser.
6
6
 
7
7
  - **Edit without limits.** Split anything, drag clips anywhere, layer them and move them between tracks. Nothing snaps back unless you ask it to.
8
+ - **Hear every edit.** Playback follows the timeline as you work, with a mixer, effects, loops, a metronome and mixdown to WAV.
8
9
  - **Fast with big sessions.** Waveforms are drawn in the background and cached on the device, so long recordings open instantly the next time.
9
- - **Fits any stack.** No framework and no dependencies. Restyle it with CSS variables and drop in your own track controls.
10
+ - **Fits any stack.** No framework and no dependencies. Use the built-in toolbar and track controls, swap their icons for your own, or build your own UI on the same API.
10
11
  - **Open by design.** MIT licensed. Project exchange with the desktop DAWs musicians already use is on the roadmap.
11
12
 
12
13
  Read the docs and try the playground at **[toneflix.github.io/studio](https://toneflix.github.io/studio/)**.
13
14
 
14
- > Status: early. This release has the timeline and waveforms. Playback and recording come next.
15
+ > Status: early. The timeline, waveforms and playback are here. Recording comes next.
15
16
 
16
17
  ## Use
17
18
 
18
19
  ```ts
19
- import { StudioTimeline, Waveforms, makeClip, uid } from '@toneflix/studio';
20
+ import { AudioEngine, StudioTimeline, Waveforms, linkPlayback, makeClip, uid } from '@toneflix/studio';
20
21
 
21
- const timeline = new StudioTimeline(document.getElementById('editor')!, {
22
+ const engine = new AudioEngine();
23
+
24
+ const timeline = new StudioTimeline('#editor', {
22
25
  grid: { bpm: 120, meter: [4, 4], snap: 'beat' },
23
26
  createTrack: () => ({ id: uid('t'), name: 'New stem' }),
24
27
  });
@@ -30,8 +33,13 @@ timeline.load({
30
33
 
31
34
  // Peaks are worked out in a worker and kept in Cache Storage, so a stem is analysed once per device
32
35
  const waveforms = new Waveforms();
33
- const peaks = await waveforms.get('vox.wav:v1', () => audioContext.decodeAudioData(bytes));
34
- timeline.setSource({ id: 'vox.wav', duration: 12 }, peaks);
36
+ const audio = await engine.context.decodeAudioData(bytes);
37
+ const peaks = await waveforms.get('vox.wav:v1', () => audio);
38
+ timeline.setSource({ id: 'vox.wav', duration: audio.duration }, peaks);
39
+
40
+ // Play it: edits are heard at once, the playhead follows, Space plays and pauses
41
+ engine.setBuffer('vox.wav', audio);
42
+ linkPlayback(timeline, engine);
35
43
 
36
44
  timeline.on('change', ({ state, final }) => final && save(state));
37
45
  ```
@@ -62,9 +70,11 @@ Install `@toneflix/studio` for everything, or only the parts your app uses. Ever
62
70
  | [`@toneflix/studio`](packages/studio) | Everything below, from one import |
63
71
  | [`@toneflix/studio-core`](packages/core) | Tracks, clips, pure edits (`splitClips`, `moveClips`, `trimStart`, `setFades`…), snapping, `TimelineModel` and `History`. No DOM or audio, so it also runs on servers and in tests |
64
72
  | [`@toneflix/studio-waveforms`](packages/waveforms) | `Waveforms`, `PeaksWorker`, `PeaksCache` and `drawWaveform`: peaks off the main thread, cached on the device |
73
+ | [`@toneflix/studio-audio`](packages/audio) | `AudioEngine`: playback with a mixer, effects, loops, a metronome and offline mixdown |
74
+ | [`@toneflix/studio-controls`](packages/controls) | `StudioToolbar` and `trackStrip`: playback and editing buttons and track mute, solo and volume, with Lucide icons you can replace |
65
75
  | [`@toneflix/studio-timeline`](packages/timeline) | `StudioTimeline`, the editor view. Restyle it with the `--tfs-*` CSS variables or fill track headers with `renderHeader` |
66
76
 
67
- Playback and recording will arrive as their own packages.
77
+ Recording will arrive as its own package.
68
78
 
69
79
  ## Develop
70
80
 
package/dist/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
1
  export * from '@toneflix/studio-core';
2
2
  export * from '@toneflix/studio-waveforms';
3
3
  export * from '@toneflix/studio-timeline';
4
+ export * from '@toneflix/studio-audio';
5
+ export * from '@toneflix/studio-controls';
6
+ export * from './playback.ts';
package/dist/index.js CHANGED
@@ -1,3 +1,6 @@
1
1
  export * from '@toneflix/studio-core';
2
2
  export * from '@toneflix/studio-waveforms';
3
3
  export * from '@toneflix/studio-timeline';
4
+ export * from '@toneflix/studio-audio';
5
+ export * from '@toneflix/studio-controls';
6
+ export * from './playback.js';
@@ -0,0 +1,11 @@
1
+ import type { AudioEngine } from '@toneflix/studio-audio';
2
+ import type { StudioTimeline } from '@toneflix/studio-timeline';
3
+ export interface LinkPlaybackOptions {
4
+ /** Space plays and pauses while the timeline has focus */
5
+ space?: boolean;
6
+ }
7
+ /**
8
+ * Keeps an engine and a timeline together: finished edits play at once, clicking the
9
+ * ruler seeks, and the playhead follows playback. Returns a function that unlinks them.
10
+ */
11
+ export declare const linkPlayback: (timeline: StudioTimeline, engine: AudioEngine, options?: LinkPlaybackOptions) => () => void;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Keeps an engine and a timeline together: finished edits play at once, clicking the
3
+ * ruler seeks, and the playhead follows playback. Returns a function that unlinks them.
4
+ */
5
+ export const linkPlayback = (timeline, engine, options = {}) => {
6
+ let frame = 0;
7
+ const follow = () => {
8
+ timeline.setTime(engine.time);
9
+ frame = engine.isPlaying ? requestAnimationFrame(follow) : 0;
10
+ };
11
+ const onKey = (e) => {
12
+ if (e.key !== ' ' || e.repeat || e.ctrlKey || e.metaKey || e.altKey)
13
+ return;
14
+ if (e.target instanceof HTMLElement && (e.target.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT', 'BUTTON'].includes(e.target.tagName)))
15
+ return;
16
+ e.preventDefault();
17
+ engine.toggle();
18
+ };
19
+ engine.load(timeline.state);
20
+ timeline.setLoop(engine.loop);
21
+ const unlink = [
22
+ timeline.on('change', ({ state, final }) => final && engine.load(state)),
23
+ timeline.on('seek', ({ time }) => engine.seek(time)),
24
+ engine.on('play', () => {
25
+ cancelAnimationFrame(frame);
26
+ follow();
27
+ }),
28
+ engine.on('pause', ({ time }) => timeline.setTime(time)),
29
+ engine.on('seek', ({ time }) => timeline.setTime(time)),
30
+ engine.on('end', ({ time }) => timeline.setTime(time)),
31
+ engine.on('loop', ({ loop }) => timeline.setLoop(loop)),
32
+ ];
33
+ if (options.space ?? true)
34
+ timeline.root.addEventListener('keydown', onKey);
35
+ return () => {
36
+ cancelAnimationFrame(frame);
37
+ for (const off of unlink)
38
+ off();
39
+ timeline.root.removeEventListener('keydown', onKey);
40
+ };
41
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toneflix/studio",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "The studio engine for the web: multitrack audio editing that feels like a desktop DAW, in any browser app. Includes every Toneflix Studio package.",
5
5
  "license": "MIT",
6
6
  "author": "Toneflix <code@toneflix.com.ng>",
@@ -38,9 +38,11 @@
38
38
  "LICENSE"
39
39
  ],
40
40
  "dependencies": {
41
- "@toneflix/studio-core": "^0.2.0",
42
- "@toneflix/studio-waveforms": "^0.2.0",
43
- "@toneflix/studio-timeline": "^0.2.0"
41
+ "@toneflix/studio-audio": "^0.3.1",
42
+ "@toneflix/studio-controls": "^0.3.1",
43
+ "@toneflix/studio-core": "^0.3.1",
44
+ "@toneflix/studio-timeline": "^0.3.1",
45
+ "@toneflix/studio-waveforms": "^0.3.1"
44
46
  },
45
47
  "engines": {
46
48
  "node": ">=22.18"