4track 0.1.5 → 0.1.7

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
@@ -2,6 +2,12 @@
2
2
 
3
3
  A browser-based 4-track audio recorder built with the Web Audio API and SvelteKit. Designed for low-latency recording with overdub support, latency compensation, and sample-accurate multi-track playback — all running entirely client-side with no server required.
4
4
 
5
+ ![4-Track Recorder](img/4track.png)
6
+
7
+ ## Give it a try
8
+
9
+ You can try out the 4 track recorder on [4track.cc](https://www.4track.cc)
10
+
5
11
  ## Installation
6
12
 
7
13
  ```bash
@@ -12,7 +18,7 @@ npm install 4-track-recorder
12
18
 
13
19
  ```svelte
14
20
  <script>
15
- import { FourTrack } from '4-track-recorder'
21
+ import { FourTrack } from "4-track-recorder"
16
22
  </script>
17
23
 
18
24
  <FourTrack />
@@ -28,7 +34,7 @@ Use `bind:save` and `bind:load` to get functions you can call from your own UI:
28
34
 
29
35
  ```svelte
30
36
  <script>
31
- import { FourTrack } from '4-track-recorder'
37
+ import { FourTrack } from "4-track-recorder"
32
38
 
33
39
  let save
34
40
  let load
@@ -37,9 +43,9 @@ Use `bind:save` and `bind:load` to get functions you can call from your own UI:
37
43
  const blob = save()
38
44
  // Download as file
39
45
  const url = URL.createObjectURL(blob)
40
- const a = document.createElement('a')
46
+ const a = document.createElement("a")
41
47
  a.href = url
42
- a.download = 'my-song.4trk'
48
+ a.download = "my-song.4trk"
43
49
  a.click()
44
50
  URL.revokeObjectURL(url)
45
51
  }
@@ -51,7 +57,7 @@ Use `bind:save` and `bind:load` to get functions you can call from your own UI:
51
57
 
52
58
  // Or load directly from a URL
53
59
  function loadFromUrl() {
54
- load('https://example.com/songs/demo.4trk')
60
+ load("https://example.com/songs/demo.4trk")
55
61
  }
56
62
  </script>
57
63
 
@@ -71,10 +77,10 @@ Pass a URL or `File` to `initialProject` to auto-load a project when the compone
71
77
 
72
78
  ## Props
73
79
 
74
- | Prop | Type | Description |
75
- |------|------|-------------|
76
- | `hiddenTracks` | `HiddenTrackConfig[]` | Background audio tracks (e.g. cassette hiss) |
77
- | `onready` | `(detail: { engine: AudioEngine }) => void` | Callback when the engine is initialized |
78
- | `save` | `() => Blob` (bindable) | Bind to get a function that exports the project as a `.4trk` blob |
79
- | `load` | `(source: File \| string) => Promise<void>` (bindable) | Bind to get a function that imports a `.4trk` file or URL |
80
- | `initialProject` | `string \| File` | URL or File to auto-load on mount |
80
+ | Prop | Type | Description |
81
+ | ---------------- | ------------------------------------------------------ | ----------------------------------------------------------------- |
82
+ | `hiddenTracks` | `HiddenTrackConfig[]` | Background audio tracks (e.g. cassette hiss) |
83
+ | `onready` | `(detail: { engine: AudioEngine }) => void` | Callback when the engine is initialized |
84
+ | `save` | `() => Blob` (bindable) | Bind to get a function that exports the project as a `.4trk` blob |
85
+ | `load` | `(source: File \| string) => Promise<void>` (bindable) | Bind to get a function that imports a `.4trk` file or URL |
86
+ | `initialProject` | `string \| File` | URL or File to auto-load on mount |
@@ -1,4 +1,4 @@
1
- import type { AudioEngineConfig } from '../types.js';
1
+ import type { AudioEngineConfig } from "../types.js";
2
2
  export declare const PLAYBACK_TICK_MS = 50;
3
3
  export declare const DEFAULT_CONFIG: AudioEngineConfig;
4
4
  export declare const AUDIO_CONSTRAINTS: MediaTrackConstraints;
@@ -1,15 +1,15 @@
1
1
  // Default configuration and constraints for the audio engine.
2
- import workletUrl from '../assets/recorder-worklet.js?url';
2
+ import workletUrl from "../assets/recorder-worklet.js?url";
3
3
  export const PLAYBACK_TICK_MS = 50;
4
4
  export const DEFAULT_CONFIG = {
5
- sampleRate: 48000, // 44100 | 48000 | 96000
5
+ sampleRate: 32000, // 44100 | 48000 | 96000
6
6
  bitDepth: 16, // 8 = lo-fi, 16 = CD quality, 32 = float (uncompressed)
7
7
  maxSeconds: 180, // max recording length per track (seconds)
8
8
  trackCount: 4, // number of mixer tracks
9
9
  workletUrl,
10
10
  inputFx: [
11
11
  {
12
- type: 'trim',
12
+ type: "trim",
13
13
  enabled: true,
14
14
  default: -1, // initial slider position: -1 (clean) → 1 (full saturation)
15
15
  gainMin: 0.2, // gain at slider -1; lower = quieter clean tone (0.1–1.0)
@@ -81,8 +81,8 @@ export declare class AudioEngine {
81
81
  setInputGain(value: number): void;
82
82
  private startMeters;
83
83
  private stopMeters;
84
- /** Serializes all tracks and settings into a .4trk binary blob. */
85
- exportProject(): Blob;
84
+ /** Serializes all tracks and settings into a compressed .4trk binary blob. */
85
+ exportProject(): Promise<Blob>;
86
86
  /** Loads a .4trk file, restoring all track buffers, mixer settings, and master volume. */
87
87
  importProject(file: File | Blob): Promise<void>;
88
88
  /** Disconnects all audio nodes, closes the AudioContext, and releases media streams. */
@@ -571,7 +571,7 @@ export class AudioEngine {
571
571
  }
572
572
  }
573
573
  // ─── Save / Load ────────────────────────────────────────────────────
574
- /** Serializes all tracks and settings into a .4trk binary blob. */
574
+ /** Serializes all tracks and settings into a compressed .4trk binary blob. */
575
575
  exportProject() {
576
576
  return _exportProject(this.tracks, this.config, this.masterVolume);
577
577
  }
@@ -1,6 +1,6 @@
1
1
  import { Track } from './track.svelte.js';
2
2
  import type { AudioEngineConfig } from '../types.js';
3
- export declare function exportProject(tracks: Track[], config: AudioEngineConfig, masterVolume: number): Blob;
3
+ export declare function exportProject(tracks: Track[], config: AudioEngineConfig, masterVolume: number): Promise<Blob>;
4
4
  export declare function importProject(file: File | Blob, tracks: Track[], ensureContext: () => AudioContext): Promise<{
5
5
  masterVolume: number;
6
6
  }>;
@@ -3,7 +3,7 @@
3
3
  // Uses integer quantization from ./pcm.ts for compact storage.
4
4
  import { Track } from './track.svelte.js';
5
5
  import { quantizePCM, dequantizePCM } from './pcm.js';
6
- export function exportProject(tracks, config, masterVolume) {
6
+ export async function exportProject(tracks, config, masterVolume) {
7
7
  const trackMeta = [];
8
8
  const pcmParts = [];
9
9
  for (const track of tracks) {
@@ -40,10 +40,13 @@ export function exportProject(tracks, config, masterVolume) {
40
40
  const encoder = new TextEncoder();
41
41
  const metaBytes = encoder.encode(JSON.stringify(metadata));
42
42
  const metaLength = new Uint32Array([metaBytes.length]);
43
- return new Blob([metaLength, metaBytes, ...pcmParts], { type: 'application/octet-stream' });
43
+ const raw = new Blob([metaLength, metaBytes, ...pcmParts]);
44
+ const compressed = raw.stream().pipeThrough(new CompressionStream('gzip'));
45
+ return new Response(compressed).blob();
44
46
  }
45
47
  export async function importProject(file, tracks, ensureContext) {
46
- const arrayBuffer = await file.arrayBuffer();
48
+ const decompressed = new Blob([file]).stream().pipeThrough(new DecompressionStream('gzip'));
49
+ const arrayBuffer = await new Response(decompressed).arrayBuffer();
47
50
  const view = new DataView(arrayBuffer);
48
51
  const metaLength = view.getUint32(0, true);
49
52
  const metaBytes = new Uint8Array(arrayBuffer, 4, metaLength);
@@ -1,7 +1,7 @@
1
1
  <script lang="ts">
2
2
  import { AudioEngine } from "../audio/engine.svelte.js"
3
3
  import type { HiddenTrackConfig, LoadStatus } from "../types.js"
4
- import casetteHissUrl from "../assets/casette_hiss.mp3"
4
+ import casetteHissUrl from "../assets/casette_hiss_compressed.mp3"
5
5
  import noiseImg from "../assets/noise_50.jpg"
6
6
  import logoImg from "../assets/logo.svg?url"
7
7
  import openstudioImg from "../assets/openstudio.svg?url"
@@ -26,7 +26,7 @@
26
26
  }: {
27
27
  hiddenTracks?: HiddenTrackConfig[]
28
28
  onready?: (detail: { engine: AudioEngine }) => void
29
- save?: () => Blob
29
+ save?: () => Promise<Blob>
30
30
  load?: (source: File | string) => Promise<void>
31
31
  initialProject?: string | File
32
32
  status?: LoadStatus
@@ -108,13 +108,16 @@
108
108
 
109
109
  {#snippet channelStrip(track, i)}
110
110
  <div
111
- class="channel-lights cell-center"
111
+ class="track{i} channel-lights cell-center"
112
112
  style="grid-area: {i + 3} / 2 / {i + 4} / 3"
113
113
  >
114
114
  <Lights level={track.level} />
115
115
  </div>
116
116
 
117
- <div class="cell-center" style="grid-area: {i + 3} / 3 / {i + 4} / 4">
117
+ <div
118
+ class="track{i} volume cell-center"
119
+ style="grid-area: {i + 3} / 3 / {i + 4} / 4"
120
+ >
118
121
  <Knob
119
122
  min={0}
120
123
  max={1.5}
@@ -123,7 +126,10 @@
123
126
  />
124
127
  </div>
125
128
 
126
- <div class="cell-center" style="grid-area: {i + 3} / 4 / {i + 4} / 5">
129
+ <div
130
+ class="track{i} panning cell-center"
131
+ style="grid-area: {i + 3} / 4 / {i + 4} / 5"
132
+ >
127
133
  <Knob
128
134
  min={-1}
129
135
  max={1}
@@ -232,7 +238,10 @@
232
238
  />
233
239
  </div>
234
240
 
235
- <div class="cell-center" style="grid-area: 4 / 7 / 7 / 8">
241
+ <div
242
+ class="cell-center input-volume"
243
+ style="grid-area: 4 / 7 / 7 / 8"
244
+ >
236
245
  <Slider
237
246
  min={0}
238
247
  max={1.5}
@@ -5,7 +5,7 @@ type $$ComponentProps = {
5
5
  onready?: (detail: {
6
6
  engine: AudioEngine;
7
7
  }) => void;
8
- save?: () => Blob;
8
+ save?: () => Promise<Blob>;
9
9
  load?: (source: File | string) => Promise<void>;
10
10
  initialProject?: string | File;
11
11
  status?: LoadStatus;
@@ -3,8 +3,8 @@
3
3
  <!-- svelte-ignore a11y_no_static_element_interactions -->
4
4
  <script>
5
5
  import { playFx } from "../../fx/soundfx"
6
- import slideSelectIndicatorImg from '../../assets/slideselect-indicator.svg?url'
7
- import slideSelectThumbImg from '../../assets/slideselect-thumb.png'
6
+ import slideSelectIndicatorImg from "../../assets/slideselect-indicator.svg?url"
7
+ import slideSelectThumbImg from "../../assets/slideselect-thumb.png"
8
8
  let dragging = $state(false)
9
9
  let trackEl = $state()
10
10
  let selected_i = $state(4)
@@ -68,7 +68,11 @@
68
68
  })
69
69
  </script>
70
70
 
71
- <div class="slider-holder" style:--bg-slideselect-indicator="url({slideSelectIndicatorImg})" style:--bg-slideselect-thumb="url({slideSelectThumbImg})">
71
+ <div
72
+ class="slider-holder"
73
+ style:--bg-slideselect-indicator="url({slideSelectIndicatorImg})"
74
+ style:--bg-slideselect-thumb="url({slideSelectThumbImg})"
75
+ >
72
76
  <div class="slideselect-indicator"></div>
73
77
  <div
74
78
  bind:this={trackEl}
@@ -117,6 +121,7 @@
117
121
  position: relative;
118
122
  border-radius: 4cqw;
119
123
  background: rgb(100, 100, 100);
124
+ touch-action: none;
120
125
  box-shadow:
121
126
  inset 8cqw 1cqh 12cqw rgba(31, 31, 31, 0.75),
122
127
  inset 2cqw 0.2cqh 2cqw rgba(31, 31, 31, 0.45),
@@ -142,6 +147,7 @@
142
147
  background-size: 100% 100%;
143
148
  position: absolute;
144
149
  border-radius: 1cqh;
150
+ touch-action: none;
145
151
  top: 0%;
146
152
  left: 0;
147
153
  cursor: grab;
@@ -2,10 +2,17 @@
2
2
  <!-- svelte-ignore a11y_interactive_supports_focus -->
3
3
  <!-- svelte-ignore a11y_no_static_element_interactions -->
4
4
  <script>
5
- import sliderIndicatorImg from '../../assets/slider-indicator.svg?url'
6
- import sliderImg from '../../assets/slider.png'
5
+ import sliderIndicatorImg from "../../assets/slider-indicator.svg?url"
6
+ import sliderImg from "../../assets/slider.png"
7
7
 
8
- let { value = $bindable(0), min = 0, max = 1, onchange, btnHeight = 0.35, padding = 1 } = $props()
8
+ let {
9
+ value = $bindable(0),
10
+ min = 0,
11
+ max = 1,
12
+ onchange,
13
+ btnHeight = 0.35,
14
+ padding = 1,
15
+ } = $props()
9
16
  let dragging = $state(false)
10
17
  let trackEl = $state()
11
18
  let startY = $state(0)
@@ -20,7 +27,8 @@
20
27
 
21
28
  // Inverted: top = max, bottom = min (like a real fader)
22
29
  let topPercent = $derived(
23
- padding + ((1 - normalizeValue(value)) * (1 - btnHeight - (2 * padding) / 100) * 100),
30
+ padding +
31
+ (1 - normalizeValue(value)) * (1 - btnHeight - (2 * padding) / 100) * 100,
24
32
  )
25
33
 
26
34
  const start = (event) => {
@@ -48,7 +56,11 @@
48
56
  }
49
57
  </script>
50
58
 
51
- <div class="slider-holder" style:--bg-slider-indicator="url({sliderIndicatorImg})" style:--bg-slider="url({sliderImg})">
59
+ <div
60
+ class="slider-holder"
61
+ style:--bg-slider-indicator="url({sliderIndicatorImg})"
62
+ style:--bg-slider="url({sliderImg})"
63
+ >
52
64
  <div
53
65
  class="slider-indicator"
54
66
  style="height: {(1 - btnHeight) * 100}%; top: {(btnHeight / 2) * 100}%"
@@ -99,6 +111,7 @@
99
111
  height: 100%;
100
112
  position: relative;
101
113
  border-radius: 8cqw;
114
+ touch-action: none;
102
115
  box-shadow:
103
116
  inset 9cqw 2cqh 15cqw rgba(31, 31, 31, 0.75),
104
117
  inset 1.5cqw 0.2cqh 1.5cqw rgba(31, 31, 31, 0.45),
@@ -129,6 +142,7 @@
129
142
  cursor: grab;
130
143
  z-index: 1;
131
144
  border-radius: 10cqw;
145
+ touch-action: none
132
146
  box-shadow:
133
147
  15cqw 1cqh 8cqw rgba(0, 0, 0, 0.4),
134
148
  inset 1.5cqw 0.5cqh 1cqw rgba(255, 252, 252, 0.35);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "4track",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "A 4-track cassette recorder component for Svelte 5",
5
5
  "license": "GPL-3.0-only",
6
6
  "author": "Andre Boekhorst",
Binary file