From ce09443e483169801badbcb91141b743535d4798 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Tue, 4 Jul 2023 23:43:49 +0200 Subject: [PATCH] delete tone --- README.md | 2 +- index.mjs | 1 - packages/core/pianoroll.mjs | 2 +- packages/core/ui.mjs | 2 +- packages/react/vite.config.js | 1 - packages/tone/README.md | 34 ---- packages/tone/index.mjs | 1 - packages/tone/package.json | 40 ----- packages/tone/test/tone.test.mjs | 18 --- packages/tone/tone.mjs | 106 ------------ packages/tone/vite.config.js | 19 --- test/runtime.mjs | 6 - undocumented.json | 23 --- website/src/docs/old.mdx | 152 ------------------ .../src/pages/technical-manual/packages.mdx | 2 +- 15 files changed, 4 insertions(+), 405 deletions(-) delete mode 100644 packages/tone/README.md delete mode 100644 packages/tone/index.mjs delete mode 100644 packages/tone/package.json delete mode 100644 packages/tone/test/tone.test.mjs delete mode 100644 packages/tone/tone.mjs delete mode 100644 packages/tone/vite.config.js delete mode 100644 website/src/docs/old.mdx diff --git a/README.md b/README.md index ece22323..0949b687 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ There are multiple npm packages you can use to use strudel, or only parts of it, - [`core`](./packages/core/): tidal pattern engine - [`mini`](./packages/mini): mini notation parser + core binding - [`transpiler`](./packages/transpiler): user code transpiler -- [`tone`](./packages/tone): bindings for Tone.js instruments and effects +- [`webaudio`](./packages/webaudio): webaudio output - [`osc`](./packages/osc): bindings to communicate via OSC - [`midi`](./packages/midi): webmidi bindings - [`serial`](./packages/serial): webserial bindings diff --git a/index.mjs b/index.mjs index 3130b993..fea3ffeb 100644 --- a/index.mjs +++ b/index.mjs @@ -9,7 +9,6 @@ export * from './packages/react/index.mjs'; export * from './packages/serial/index.mjs'; export * from './packages/soundfonts/index.mjs'; export * from './packages/tonal/index.mjs'; -export * from './packages/tone/index.mjs'; export * from './packages/transpiler/index.mjs'; export * from './packages/webaudio/index.mjs'; export * from './packages/webdirt/index.mjs'; diff --git a/packages/core/pianoroll.mjs b/packages/core/pianoroll.mjs index 02aac373..2c16eb7d 100644 --- a/packages/core/pianoroll.mjs +++ b/packages/core/pianoroll.mjs @@ -1,6 +1,6 @@ /* pianoroll.mjs - -Copyright (C) 2022 Strudel contributors - see +Copyright (C) 2022 Strudel contributors - see This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ diff --git a/packages/core/ui.mjs b/packages/core/ui.mjs index df8230ec..141d3c83 100644 --- a/packages/core/ui.mjs +++ b/packages/core/ui.mjs @@ -1,6 +1,6 @@ /* ui.mjs - -Copyright (C) 2022 Strudel contributors - see +Copyright (C) 2022 Strudel contributors - see This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ diff --git a/packages/react/vite.config.js b/packages/react/vite.config.js index 7a1fb082..be289dab 100644 --- a/packages/react/vite.config.js +++ b/packages/react/vite.config.js @@ -22,7 +22,6 @@ export default defineConfig({ ...Object.keys(peerDependencies), ...Object.keys(dependencies), // TODO: find out which of below names are obsolete now - '@strudel.cycles/tone', '@strudel.cycles/transpiler', 'acorn', '@strudel.cycles/core', diff --git a/packages/tone/README.md b/packages/tone/README.md deleted file mode 100644 index 90e4385f..00000000 --- a/packages/tone/README.md +++ /dev/null @@ -1,34 +0,0 @@ -# @strudel.cycles/tone - -This package adds Tone.js functions to strudel Patterns. - -## Deprecation Note - -This package will not be developed further. Consider using `@strudel.cycles/webaudio` as a replacement. - -## Install - -```sh -npm i @strudel.cycles/tone --save -``` - -## Example - -The following example will create a pattern and play it back with tone.js: - -```js -import { sequence, stack, State, TimeSpan } from '@strudel.cycles/core'; -import { Tone, polysynth, osc, out } from '@strudel.cycles/tone'; - -const pattern = sequence('c3', ['eb3', stack('g3', 'bb3')]).tone(polysynth().set(osc('sawtooth4')).chain(out())); - -document.getElementById('play').addEventListener('click', async () => { - await Tone.start(); - Tone.getTransport().stop(); - const events = pattern.query(new State(new TimeSpan(0, 4))).filter((e) => e.whole.begin.equals(e.part.begin)); - events.forEach((event) => - Tone.getTransport().schedule((time) => event.context.onTrigger(time, event), event.whole.begin.valueOf()), - ); - Tone.getTransport().start('+0.1'); -}); -``` diff --git a/packages/tone/index.mjs b/packages/tone/index.mjs deleted file mode 100644 index 021d7718..00000000 --- a/packages/tone/index.mjs +++ /dev/null @@ -1 +0,0 @@ -export * from './tone.mjs'; diff --git a/packages/tone/package.json b/packages/tone/package.json deleted file mode 100644 index 583b2821..00000000 --- a/packages/tone/package.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "name": "@strudel.cycles/tone", - "version": "0.8.0", - "description": "Tone.js API for strudel", - "main": "index.mjs", - "type": "module", - "publishConfig": { - "main": "dist/index.js", - "module": "dist/index.mjs" - }, - "scripts": { - "build": "vite build", - "prepublishOnly": "npm run build" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/tidalcycles/strudel.git" - }, - "keywords": [ - "tidalcycles", - "strudel", - "pattern", - "livecoding", - "algorave" - ], - "author": "Felix Roos ", - "license": "AGPL-3.0-or-later", - "bugs": { - "url": "https://github.com/tidalcycles/strudel/issues" - }, - "homepage": "https://github.com/tidalcycles/strudel#readme", - "dependencies": { - "@strudel.cycles/core": "workspace:*", - "tone": "^14.7.77" - }, - "devDependencies": { - "vite": "^4.3.3", - "vitest": "^0.28.0" - } -} diff --git a/packages/tone/test/tone.test.mjs b/packages/tone/test/tone.test.mjs deleted file mode 100644 index 42feb676..00000000 --- a/packages/tone/test/tone.test.mjs +++ /dev/null @@ -1,18 +0,0 @@ -/* -tone.test.mjs - -Copyright (C) 2022 Strudel contributors - see -This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ - -import '../tone.mjs'; -import { pure } from '@strudel.cycles/core'; -import { describe, it, expect } from 'vitest'; - -describe('tone', () => { - it('Should have working tone function', () => { - // const s = synth().chain(out()); // TODO: mock audio context? - // assert.deepStrictEqual(s, new Tone.Synth().chain(out())); - const s = {}; - expect(pure('c3').tone(s).firstCycleValues).toEqual(['c3']); - }); -}); diff --git a/packages/tone/tone.mjs b/packages/tone/tone.mjs deleted file mode 100644 index d57c1f2a..00000000 --- a/packages/tone/tone.mjs +++ /dev/null @@ -1,106 +0,0 @@ -/* -tone.mjs - -Copyright (C) 2022 Strudel contributors - see -This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ - -import { register } from '@strudel.cycles/core'; -import * as _Tone from 'tone'; - -// import Tone from here, to make sure to get the same AudioContext -export const Tone = _Tone; - -const { - Filter, - Gain, - Synth, - PolySynth, - MembraneSynth, - MetalSynth, - MonoSynth, - AMSynth, - DuoSynth, - FMSynth, - NoiseSynth, - PluckSynth, - Sampler, - getDestination, - Players, -} = Tone; -import { getPlayableNoteValue } from '@strudel.cycles/core/util.mjs'; - -// "balanced" | "interactive" | "playback"; -// Tone.setContext(new Tone.Context({ latencyHint: 'playback', lookAhead: 1 })); -export const getDefaultSynth = () => { - const s = new PolySynth().chain(new Gain(0.5), getDestination()); - s.set({ - oscillator: { type: 'triangle' }, - envelope: { - release: 0.01, - }, - }); - return s; -}; - -// what about -// https://www.charlie-roberts.com/gibberish/playground/ - -// with this function, you can play the pattern with any tone synth -export const tone = register('tone', function (instrument, pat) { - return pat.onTrigger((time, hap) => { - let note; - let velocity = hap.context?.velocity ?? 0.75; - if (instrument instanceof PluckSynth) { - note = getPlayableNoteValue(hap); - instrument.triggerAttack(note, time); - } else if (instrument instanceof NoiseSynth) { - instrument.triggerAttackRelease(hap.duration.valueOf(), time); // noise has no value - } else if (instrument instanceof Sampler) { - note = getPlayableNoteValue(hap); - instrument.triggerAttackRelease(note, hap.duration.valueOf(), time, velocity); - } else if (instrument instanceof Players) { - if (!instrument.has(hap.value)) { - throw new Error(`name "${hap.value}" not defined for players`); - } - const player = instrument.player(hap.value); - // velocity ? - player.start(time); - player.stop(time + hap.duration.valueOf()); - } else { - note = getPlayableNoteValue(hap); - instrument.triggerAttackRelease(note, hap.duration.valueOf(), time, velocity); - } - }); -}); - -// synth helpers -export const amsynth = (options) => new AMSynth(options); -export const duosynth = (options) => new DuoSynth(options); -export const fmsynth = (options) => new FMSynth(options); -export const membrane = (options) => new MembraneSynth(options); -export const metal = (options) => new MetalSynth(options); -export const monosynth = (options) => new MonoSynth(options); -export const noise = (options) => new NoiseSynth(options); -export const pluck = (options) => new PluckSynth(options); -export const polysynth = (options) => new PolySynth(options); -export const sampler = (options, baseUrl) => - new Promise((resolve) => { - const s = new Sampler(options, () => resolve(s), baseUrl); - }); -export const players = (options, baseUrl = '') => { - options = !baseUrl - ? options - : Object.fromEntries(Object.entries(options).map(([key, value]) => [key, baseUrl + value])); - return new Promise((resolve) => { - const s = new Players(options, () => resolve(s)); - }); -}; -export const synth = (options) => new Synth(options); - -// effect helpers -export const vol = (v) => new Gain(v); -export const lowpass = (v) => new Filter(v, 'lowpass'); -export const highpass = (v) => new Filter(v, 'highpass'); -export const adsr = (a, d = 0.1, s = 0.4, r = 0.01) => ({ envelope: { attack: a, decay: d, sustain: s, release: r } }); -export const osc = (type) => ({ oscillator: { type } }); -export const out = () => getDestination(); diff --git a/packages/tone/vite.config.js b/packages/tone/vite.config.js deleted file mode 100644 index 0fc63a6b..00000000 --- a/packages/tone/vite.config.js +++ /dev/null @@ -1,19 +0,0 @@ -import { defineConfig } from 'vite'; -import { dependencies } from './package.json'; -import { resolve } from 'path'; - -// https://vitejs.dev/config/ -export default defineConfig({ - plugins: [], - build: { - lib: { - entry: resolve(__dirname, 'index.mjs'), - formats: ['es', 'cjs'], - fileName: (ext) => ({ es: 'index.mjs', cjs: 'index.js' }[ext]), - }, - rollupOptions: { - external: [...Object.keys(dependencies)], - }, - target: 'esnext', - }, -}); diff --git a/test/runtime.mjs b/test/runtime.mjs index 777b3d83..43097c6d 100644 --- a/test/runtime.mjs +++ b/test/runtime.mjs @@ -10,20 +10,14 @@ import * as webaudio from '@strudel.cycles/webaudio'; import controls from '@strudel.cycles/core/controls.mjs'; // import gist from '@strudel.cycles/core/gist.js'; import { mini, m } from '@strudel.cycles/mini/mini.mjs'; -// import * as toneHelpers from '@strudel.cycles/tone/tone.mjs'; // import * as voicingHelpers from '@strudel.cycles/tonal/voicings.mjs'; -// import * as uiHelpers from '@strudel.cycles/tone/ui.mjs'; -// import * as drawHelpers from '@strudel.cycles/tone/draw.mjs'; // import euclid from '@strudel.cycles/core/euclid.mjs'; -// import '@strudel.cycles/tone/tone.mjs'; // import '@strudel.cycles/midi/midi.mjs'; import * as tonalHelpers from '@strudel.cycles/tonal'; import '@strudel.cycles/xen/xen.mjs'; // import '@strudel.cycles/xen/tune.mjs'; // import '@strudel.cycles/core/euclid.mjs'; // import '@strudel.cycles/core/speak.mjs'; // window is not defined -// import '@strudel.cycles/tone/pianoroll.mjs'; -// import '@strudel.cycles/tone/draw.mjs'; // import '@strudel.cycles/osc/osc.mjs'; // import '@strudel.cycles/webaudio/webaudio.mjs'; // import '@strudel.cycles/serial/serial.mjs'; diff --git a/undocumented.json b/undocumented.json index e8536abd..0892bbbf 100644 --- a/undocumented.json +++ b/undocumented.json @@ -188,29 +188,6 @@ "setVoicingRange" ], "/home/felix/projects/strudel/packages/tonal/index.mjs": [], - "/home/felix/projects/strudel/packages/tone/tone.mjs": [ - "Tone", - "getDefaultSynth", - "tone", - "amsynth", - "duosynth", - "fmsynth", - "membrane", - "metal", - "monosynth", - "noise", - "pluck", - "polysynth", - "sampler", - "players", - "synth", - "vol", - "lowpass", - "highpass", - "adsr", - "out" - ], - "/home/felix/projects/strudel/packages/tone/index.mjs": [], "/home/felix/projects/strudel/packages/transpiler/transpiler.mjs": [ "transpiler" ], diff --git a/website/src/docs/old.mdx b/website/src/docs/old.mdx deleted file mode 100644 index c11e8e58..00000000 --- a/website/src/docs/old.mdx +++ /dev/null @@ -1,152 +0,0 @@ -# Old APIs - -These APIs are outdated and might break in the future. - -## Webdirt API (deprecated) - -You can use the powerful sampling engine [Webdirt](https://github.com/dktr0/WebDirt) with Strudel. - -{{ 'Pattern.webdirt' | jsdoc }} - -
-
- -## Tone API (deprecated) - -The Tone API uses Tone.js instruments ands effects to create sounds. - - - -### tone(instrument) - -To change the instrument of a pattern, you can pass any [Tone.js Source](https://tonejs.github.io/docs/14.7.77/index.html) to .tone: - - - -While this works, it is a little bit verbose. To simplify things, all Tone Synths have a shortcut: - -```js -const amsynth = (options) => new AMSynth(options); -const duosynth = (options) => new DuoSynth(options); -const fmsynth = (options) => new FMSynth(options); -const membrane = (options) => new MembraneSynth(options); -const metal = (options) => new MetalSynth(options); -const monosynth = (options) => new MonoSynth(options); -const noise = (options) => new NoiseSynth(options); -const pluck = (options) => new PluckSynth(options); -const polysynth = (options) => new PolySynth(options); -const synth = (options) => new Synth(options); -const sampler = (options, baseUrl?) => new Sampler(options); // promisified, see below -const players = (options, baseUrl?) => new Sampler(options); // promisified, see below -``` - -### sampler - -With sampler, you can create tonal instruments from samples: - - - saw.struct("x*8").mul(16).round() - .legato(4).scale('D dorian').slow(2) - .tone(kalimba.toDestination()) -)`} -/> - -The sampler function promisifies [Tone.js Sampler](https://tonejs.github.io/docs/14.7.77/Sampler). - -Note that this function currently only works with this promise notation, but in the future, -it will be possible to use async instruments in a synchronous fashion. - -### players - -With players, you can create sound banks: - - - "bd hh sn hh".tone(drums.toDestination()) -) - `} -/> - -The sampler function promisifies [Tone.js Players](https://tonejs.github.io/docs/14.7.77/Players). - -Note that this function currently only works with this promise notation, but in the future, -it will be possible to use async instruments in a synchronous fashion. - -### out - -Shortcut for Tone.Destination. Intended to be used with Tone's .chain: - - - -This alone is not really useful, so read on.. - -### vol(volume) - -Helper that returns a Gain Node with the given volume. Intended to be used with Tone's .chain: - - - -### osc(type) - -Helper to set the waveform of a synth, monosynth or polysynth: - - - -The base types are `sine`, `square`, `sawtooth`, `triangle`. You can also append a number between 1 and 32 to reduce the harmonic partials. - -### lowpass(cutoff) - -Helper that returns a Filter Node of type lowpass with the given cutoff. Intended to be used with Tone's .chain: - - - -### highpass(cutoff) - -Helper that returns a Filter Node of type highpass with the given cutoff. Intended to be used with Tone's .chain: - - - -### adsr - -Helper to set the envelope of a Tone.js instrument. Intended to be used with Tone's .set: - - diff --git a/website/src/pages/technical-manual/packages.mdx b/website/src/pages/technical-manual/packages.mdx index 9c36e9a1..d6f38dcf 100644 --- a/website/src/pages/technical-manual/packages.mdx +++ b/website/src/pages/technical-manual/packages.mdx @@ -53,7 +53,7 @@ These packages provide bindings for different ways to output strudel patterns: ### No Longer Maintained - [eval](https://www.npmjs.com/package/@strudel.cycles/eval): old code transpiler -- [tone](https://github.com/tidalcycles/strudel/tree/main/packages/tone#strudelcyclestone): bindings for Tone.js instruments and effects +- [tone](https://www.npmjs.com/package/@strudel.cycles/tone): bindings for Tone.js instruments and effects - [webdirt](https://github.com/tidalcycles/strudel/tree/main/packages/webdirt): webdirt bindings, replaced by webaudio package ## Tools