4.0.0 • Published 5 months ago

beatbox.js-export v4.0.0

Weekly downloads
18
License
-
Repository
github
Last release
5 months ago

beatbox.js-export

beatbox.js-export allows exporting beatbox.js patterns as MP3 or WAV files.

It relies on the following libraries:

Usage

import { Beatbox } from "beatbox.js";
import { exportMP3, exportWAV } from "beatbox.js-export";
import saveAs from "save-as";

// See beatbox.js documentation. Note that the "repeat" parameter is ignored in the context of exporting.
var player = new Beatbox(pattern, beatLength, repeat);

let blob = await exportMP3(player, (progress) => {
	// progress is a number between 0 and 1
});
saveAs(blob, "song.mp3");

blob = await exportWAV(player, (progress) => {
	// progress is a number between 0 and 1
});
saveAs(blob, "song.wav");

Cancel

Returning false from the progress function will cancel the export and cause the export function to return undefined.

let canceled = false;
document.getElementById("cancel-button").addEventListener("click", () => {
	canceled = true;
});

const blob = await exportMP3(player, (progress) => {
    if (canceled)
		return false;
});
if (blob)
	saveAs(blob, "song.mp3");

The progress function can also be async. In that case, the export will pause until the async function returns. You can for example introduce some delays if you need some animation to run:

await exportMP3(player, async (progress) => {
	await new Promise((resolve) => { setTimeout(resolve, 30); });
});

Migrating from v1 to v2

  • beatbox.js-export 2.x needs beatbox.js 2.x.
  • Instead of injecting methods into the Beatbox class, beatbox.js-export now exports its own functions.
  • beatbox.js-export 2.x does not use Aurora.js to decode audio files anymore, but uses the WebAudio API directly. This means that you don’t have to load a specific codec anymore, but rather use an audio format that the browser supports.
  • The progress function can return false to cancel the export. It is not recommended to return a non-resolving promise anymore.
4.0.0

5 months ago

3.0.0

1 year ago

2.0.1

1 year ago

2.0.0

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago