@toneflix/studio 0.3.2 → 0.5.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
 
@@ -52,11 +54,15 @@ timeline.on('change', ({ state, final }) => final && save(state));
52
54
  | Drag a clip edge | Trims it, up to the ends of its audio |
53
55
  | Drag a corner handle | Fade in or out |
54
56
  | Click, Shift or Ctrl/Cmd click | Select, add to or toggle the selection |
55
- | Drag on an empty lane or the ruler | Selects a time range; with Shift, selects the clips inside it |
57
+ | Drag on an empty lane | Selects the clips the box touches (Shift adds to the selection) |
58
+ | Drag on the ruler | Selects a time range across all tracks |
56
59
  | Alt while dragging | Turns snapping off |
57
60
  | Ctrl/Cmd + wheel | Zoom around the pointer |
58
61
  | S, Delete, Ctrl+D, Ctrl+A | Split at the playhead, delete, duplicate, select all |
59
62
  | Arrows | Nudge by the snap step, or move up and down a lane |
63
+ | + above the headers, click a track name | Add a track; rename, duplicate, move or delete one from its menu |
64
+ | Markers and tempo in the ruler | Right-click the ruler to add a marker or tempo change, or double-click above the bar numbers for a marker; drag to move, click a marker to jump there, click a tempo to set it or the meter |
65
+ | Track menu, Show volume/pan automation | Opens a lane under the track: click to add points, drag to move, double-click to remove |
60
66
  | Ctrl+Z, Ctrl+Shift+Z | Undo and redo |
61
67
 
62
68
  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.
@@ -70,12 +76,14 @@ Install `@toneflix/studio` for everything, or only the parts your app uses. Ever
70
76
  | [`@toneflix/studio`](packages/studio) | Everything below, from one import |
71
77
  | [`@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
78
  | [`@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 |
79
+ | [`@toneflix/studio-audio`](packages/audio) | `AudioEngine`: playback with a mixer, effects, volume and pan automation, loops, a metronome and offline mixdown |
80
+ | [`@toneflix/studio-recorder`](packages/recorder) | `Recorder`: records a microphone or line input onto a track, lined up with what was playing |
81
+ | [`@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 |
82
+ | [`@toneflix/studio-wams`](packages/wams) | `curatedWams` and `curatedWamSource`: reviewed Web Audio Module effects, served pinned from jsDelivr |
83
+ | [`@toneflix/studio-exchange`](packages/exchange) | `saveProject` and `openProject`: sessions in the app's own format with plugins, or to and from REAPER, with tracks, clips, fades, automation, markers, tempo and the audio |
84
+ | [`@toneflix/studio-controls`](packages/controls) | `StudioToolbar`, `trackStrip`, `StudioMixer` and `StudioBrowser`: playback, recording and editing buttons, track arm, mute, solo and volume, a mixer with plugin slots, and a browser of sounds and plugins from any source, with Lucide icons you can replace |
75
85
  | [`@toneflix/studio-timeline`](packages/timeline) | `StudioTimeline`, the editor view. Restyle it with the `--tfs-*` CSS variables or fill track headers with `renderHeader` |
76
86
 
77
- Recording will arrive as its own package.
78
-
79
87
  ## Develop
80
88
 
81
89
  ```sh
package/dist/index.d.ts CHANGED
@@ -2,5 +2,10 @@ 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';
7
+ export * from '@toneflix/studio-exchange';
5
8
  export * from '@toneflix/studio-controls';
9
+ export * from '@toneflix/studio-wams';
6
10
  export * from './playback.ts';
11
+ export * from './recording.ts';
package/dist/index.js CHANGED
@@ -2,5 +2,10 @@ 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';
7
+ export * from '@toneflix/studio-exchange';
5
8
  export * from '@toneflix/studio-controls';
9
+ export * from '@toneflix/studio-wams';
6
10
  export * from './playback.js';
11
+ 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.2",
3
+ "version": "0.5.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,15 @@
38
38
  "LICENSE"
39
39
  ],
40
40
  "dependencies": {
41
- "@toneflix/studio-audio": "^0.3.2",
42
- "@toneflix/studio-controls": "^0.3.2",
43
- "@toneflix/studio-core": "^0.3.2",
44
- "@toneflix/studio-timeline": "^0.3.2",
45
- "@toneflix/studio-waveforms": "^0.3.2"
41
+ "@toneflix/studio-audio": "^0.5.0",
42
+ "@toneflix/studio-controls": "^0.5.0",
43
+ "@toneflix/studio-core": "^0.5.0",
44
+ "@toneflix/studio-exchange": "^0.5.0",
45
+ "@toneflix/studio-plugins": "^0.5.0",
46
+ "@toneflix/studio-recorder": "^0.5.0",
47
+ "@toneflix/studio-timeline": "^0.5.0",
48
+ "@toneflix/studio-wams": "^0.5.0",
49
+ "@toneflix/studio-waveforms": "^0.5.0"
46
50
  },
47
51
  "engines": {
48
52
  "node": ">=22.18"