@toneflix/studio 0.3.1 → 0.4.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/README.md CHANGED
@@ -1,18 +1,20 @@
1
1
  # Toneflix Studio
2
2
 
3
- ![A multitrack timeline with drums, bass, keys and vocal clips](https://raw.githubusercontent.com/toneflix/studio/main/docs/public/screenshot.png)
3
+ ![A multitrack timeline with a take recording onto the vocal track and an Echo plugin window open](https://raw.githubusercontent.com/toneflix/studio/main/docs/public/screenshot.png)
4
4
 
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
8
  - **Hear every edit.** Playback follows the timeline as you work, with a mixer, effects, loops, a metronome and mixdown to WAV.
9
+ - **Record over the mix.** Arm a track and record a voice or instrument while the music plays. Takes land where they were performed, with the waveform drawn as you go.
10
+ - **Plugins, live.** Put Web Audio Module plugins on any track or the master and hear them as you play, with their own editors. They are saved with the project and printed into the mix.
9
11
  - **Fast with big sessions.** Waveforms are drawn in the background and cached on the device, so long recordings open instantly the next time.
10
12
  - **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.
11
13
  - **Open by design.** MIT licensed. Project exchange with the desktop DAWs musicians already use is on the roadmap.
12
14
 
13
15
  Read the docs and try the playground at **[toneflix.github.io/studio](https://toneflix.github.io/studio/)**.
14
16
 
15
- > Status: early. The timeline, waveforms and playback are here. Recording comes next.
17
+ > Status: early. The timeline, waveforms, playback and recording are here. Project exchange with desktop DAWs is planned.
16
18
 
17
19
  ## Use
18
20
 
@@ -57,6 +59,7 @@ timeline.on('change', ({ state, final }) => final && save(state));
57
59
  | Ctrl/Cmd + wheel | Zoom around the pointer |
58
60
  | S, Delete, Ctrl+D, Ctrl+A | Split at the playhead, delete, duplicate, select all |
59
61
  | Arrows | Nudge by the snap step, or move up and down a lane |
62
+ | + above the headers, click a track name | Add a track; rename, duplicate, move or delete one from its menu |
60
63
  | Ctrl+Z, Ctrl+Shift+Z | Undo and redo |
61
64
 
62
65
  Where clips overlap on a lane, the one that starts later is on top and is the one heard. `audibleRanges(clips)` gives the heard part of each clip, for players and mix renderers.
@@ -71,11 +74,11 @@ Install `@toneflix/studio` for everything, or only the parts your app uses. Ever
71
74
  | [`@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 |
72
75
  | [`@toneflix/studio-waveforms`](packages/waveforms) | `Waveforms`, `PeaksWorker`, `PeaksCache` and `drawWaveform`: peaks off the main thread, cached on the device |
73
76
  | [`@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 |
77
+ | [`@toneflix/studio-recorder`](packages/recorder) | `Recorder`: records a microphone or line input onto a track, lined up with what was playing |
78
+ | [`@toneflix/studio-plugins`](packages/plugins) | `PluginRack`: Web Audio Module (WAM 2) plugins on tracks and the master, live, with their editors, saved with the project and in the mixdown |
79
+ | [`@toneflix/studio-controls`](packages/controls) | `StudioToolbar`, `trackStrip` and `StudioMixer`: playback, recording and editing buttons, track arm, mute, solo and volume, and a mixer with plugin slots, with Lucide icons you can replace |
75
80
  | [`@toneflix/studio-timeline`](packages/timeline) | `StudioTimeline`, the editor view. Restyle it with the `--tfs-*` CSS variables or fill track headers with `renderHeader` |
76
81
 
77
- Recording will arrive as its own package.
78
-
79
82
  ## Develop
80
83
 
81
84
  ```sh
package/dist/index.d.ts CHANGED
@@ -2,5 +2,8 @@ export * from '@toneflix/studio-core';
2
2
  export * from '@toneflix/studio-waveforms';
3
3
  export * from '@toneflix/studio-timeline';
4
4
  export * from '@toneflix/studio-audio';
5
+ export * from '@toneflix/studio-plugins';
6
+ export * from '@toneflix/studio-recorder';
5
7
  export * from '@toneflix/studio-controls';
6
8
  export * from './playback.ts';
9
+ export * from './recording.ts';
package/dist/index.js CHANGED
@@ -2,5 +2,8 @@ export * from '@toneflix/studio-core';
2
2
  export * from '@toneflix/studio-waveforms';
3
3
  export * from '@toneflix/studio-timeline';
4
4
  export * from '@toneflix/studio-audio';
5
+ export * from '@toneflix/studio-plugins';
6
+ export * from '@toneflix/studio-recorder';
5
7
  export * from '@toneflix/studio-controls';
6
8
  export * from './playback.js';
9
+ export * from './recording.js';
@@ -0,0 +1,18 @@
1
+ import type { Recorder, Take } from '@toneflix/studio-recorder';
2
+ import type { StudioTimeline } from '@toneflix/studio-timeline';
3
+ import { type Waveforms } from '@toneflix/studio-waveforms';
4
+ export interface LinkRecorderOptions {
5
+ /** Works out the finished take's waveform; it keeps the one drawn while recording without it */
6
+ waveforms?: Waveforms;
7
+ /** Name of the clip a take makes, from its number in this session */
8
+ name?: (take: number) => string;
9
+ /** Called with each finished take, for example to upload it */
10
+ onTake?: (take: Take) => void;
11
+ }
12
+ /**
13
+ * Shows recording on a timeline: the take grows as a clip with its waveform while
14
+ * recording, and lands as one undo step. Editing is paused while recording, and
15
+ * a deleted track is disarmed.
16
+ * Returns a function that unlinks them.
17
+ */
18
+ export declare const linkRecorder: (timeline: StudioTimeline, recorder: Recorder, options?: LinkRecorderOptions) => () => void;
@@ -0,0 +1,80 @@
1
+ import { addClips, makeClip } from '@toneflix/studio-core';
2
+ import { computePeakData, makePeaks } from '@toneflix/studio-waveforms';
3
+ /** Samples per peak of the waveform drawn while recording */
4
+ const LIVE_PEAK = 256;
5
+ /**
6
+ * Shows recording on a timeline: the take grows as a clip with its waveform while
7
+ * recording, and lands as one undo step. Editing is paused while recording, and
8
+ * a deleted track is disarmed.
9
+ * Returns a function that unlinks them.
10
+ */
11
+ export const linkRecorder = (timeline, recorder, options = {}) => {
12
+ const name = options.name ?? ((n) => `Take ${n}`);
13
+ let count = 0;
14
+ let live = null;
15
+ let frame = 0;
16
+ const peaks = () => {
17
+ if (!live || !live.peaks)
18
+ return undefined;
19
+ return makePeaks(live.data.subarray(0, live.peaks * 2), LIVE_PEAK, live.sampleRate, Math.round(live.duration * live.sampleRate));
20
+ };
21
+ const draw = () => {
22
+ frame = 0;
23
+ if (!live)
24
+ return;
25
+ const { id, clip, track, start, duration } = live;
26
+ timeline.setSource({ id, duration }, peaks());
27
+ timeline.model.draft('Record', (state) => addClips(state, [makeClip({ id: clip, track, source: id, name: name(count), start, offset: 0, duration })]));
28
+ };
29
+ const unlisten = [
30
+ timeline.on('change', ({ state, final }) => {
31
+ // A deleted track can't stay armed
32
+ if (final && recorder.armed && !state.tracks.some((track) => track.id === recorder.armed))
33
+ recorder.arm(null);
34
+ }),
35
+ recorder.on('start', ({ id, track }) => {
36
+ count++;
37
+ live = { id, clip: `${id}-clip`, track, start: 0, duration: 0, sampleRate: 0, data: new Int16Array(4096), peaks: 0, readonly: timeline.readonly };
38
+ timeline.setOptions({ readonly: true });
39
+ }),
40
+ recorder.on('data', ({ id, start, duration, channels, sampleRate }) => {
41
+ if (!live || live.id !== id)
42
+ return;
43
+ const add = computePeakData(channels, LIVE_PEAK);
44
+ if (live.peaks * 2 + add.length > live.data.length) {
45
+ const grown = new Int16Array(Math.max(live.data.length * 2, live.peaks * 2 + add.length));
46
+ grown.set(live.data);
47
+ live.data = grown;
48
+ }
49
+ live.data.set(add, live.peaks * 2);
50
+ live.peaks += add.length / 2;
51
+ Object.assign(live, { start, duration, sampleRate });
52
+ frame ||= requestAnimationFrame(draw);
53
+ }),
54
+ recorder.on('stop', ({ take }) => {
55
+ cancelAnimationFrame(frame);
56
+ frame = 0;
57
+ const was = live;
58
+ live = null;
59
+ if (!was)
60
+ return;
61
+ timeline.setOptions({ readonly: was.readonly });
62
+ if (!take) {
63
+ timeline.model.cancel();
64
+ return;
65
+ }
66
+ Object.assign(was, { start: take.start, duration: take.duration });
67
+ live = was;
68
+ draw();
69
+ live = null;
70
+ timeline.model.commit('Record');
71
+ options.waveforms?.get(`take:${take.id}`, () => take.buffer).then((final) => timeline.setSource({ id: take.id }, final));
72
+ options.onTake?.(take);
73
+ }),
74
+ ];
75
+ return () => {
76
+ cancelAnimationFrame(frame);
77
+ for (const off of unlisten)
78
+ off();
79
+ };
80
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toneflix/studio",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
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,11 +38,13 @@
38
38
  "LICENSE"
39
39
  ],
40
40
  "dependencies": {
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"
41
+ "@toneflix/studio-audio": "^0.4.0",
42
+ "@toneflix/studio-controls": "^0.4.0",
43
+ "@toneflix/studio-core": "^0.4.0",
44
+ "@toneflix/studio-plugins": "^0.4.0",
45
+ "@toneflix/studio-recorder": "^0.4.0",
46
+ "@toneflix/studio-timeline": "^0.4.0",
47
+ "@toneflix/studio-waveforms": "^0.4.0"
46
48
  },
47
49
  "engines": {
48
50
  "node": ">=22.18"