mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-11 13:48:34 +00:00
refactor xen and tone packages
This commit is contained in:
parent
b81a66f07e
commit
27a6ac0c0b
@ -4,18 +4,15 @@ Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/st
|
|||||||
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 <https://www.gnu.org/licenses/>.
|
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 <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Pattern } from '@strudel.cycles/core';
|
import { register } from '@strudel.cycles/core';
|
||||||
import * as _Tone from 'tone';
|
import * as _Tone from 'tone';
|
||||||
|
|
||||||
// import Tone from here, to make sure to get the same AudioContext
|
// import Tone from here, to make sure to get the same AudioContext
|
||||||
export const Tone = _Tone;
|
export const Tone = _Tone;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
AutoFilter,
|
|
||||||
Destination,
|
|
||||||
Filter,
|
Filter,
|
||||||
Gain,
|
Gain,
|
||||||
isNote,
|
|
||||||
Synth,
|
Synth,
|
||||||
PolySynth,
|
PolySynth,
|
||||||
MembraneSynth,
|
MembraneSynth,
|
||||||
@ -49,8 +46,8 @@ export const getDefaultSynth = () => {
|
|||||||
// https://www.charlie-roberts.com/gibberish/playground/
|
// https://www.charlie-roberts.com/gibberish/playground/
|
||||||
|
|
||||||
// with this function, you can play the pattern with any tone synth
|
// with this function, you can play the pattern with any tone synth
|
||||||
Pattern.prototype.tone = function (instrument) {
|
export const tone = register('tone', function (instrument, pat) {
|
||||||
return this.onTrigger((time, hap) => {
|
return pat.onTrigger((time, hap) => {
|
||||||
let note;
|
let note;
|
||||||
let velocity = hap.context?.velocity ?? 0.75;
|
let velocity = hap.context?.velocity ?? 0.75;
|
||||||
if (instrument instanceof PluckSynth) {
|
if (instrument instanceof PluckSynth) {
|
||||||
@ -74,9 +71,7 @@ Pattern.prototype.tone = function (instrument) {
|
|||||||
instrument.triggerAttackRelease(note, hap.duration.valueOf(), time, velocity);
|
instrument.triggerAttackRelease(note, hap.duration.valueOf(), time, velocity);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
|
||||||
Pattern.prototype.define('tone', (type, pat) => pat.tone(type), { composable: true, patternified: false });
|
|
||||||
|
|
||||||
// synth helpers
|
// synth helpers
|
||||||
export const amsynth = (options) => new AMSynth(options);
|
export const amsynth = (options) => new AMSynth(options);
|
||||||
|
|||||||
@ -1,2 +1,4 @@
|
|||||||
import './xen.mjs';
|
import './xen.mjs';
|
||||||
import './tune.mjs';
|
import './tune.mjs';
|
||||||
|
|
||||||
|
export * from './xen.mjs';
|
||||||
|
|||||||
@ -5,18 +5,16 @@ This program is free software: you can redistribute it and/or modify it under th
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Tune from './tunejs.js';
|
import Tune from './tunejs.js';
|
||||||
import { Pattern } from '@strudel.cycles/core';
|
import { register } from '@strudel.cycles/core';
|
||||||
|
|
||||||
Pattern.prototype._tune = function (scale, tonic = 220) {
|
export const tune = register('tune', (scale, pat) => {
|
||||||
const tune = new Tune();
|
const tune = new Tune();
|
||||||
if (!tune.isValidScale(scale)) {
|
if (!tune.isValidScale(scale)) {
|
||||||
throw new Error('not a valid tune.js scale name: "' + scale + '". See http://abbernie.github.io/tune/scales.html');
|
throw new Error('not a valid tune.js scale name: "' + scale + '". See http://abbernie.github.io/tune/scales.html');
|
||||||
}
|
}
|
||||||
tune.loadScale(scale);
|
tune.loadScale(scale);
|
||||||
tune.tonicize(tonic);
|
tune.tonicize(1);
|
||||||
return this._asNumber()._withHap((hap) => {
|
return pat.withHap((hap) => {
|
||||||
return hap.withValue(() => tune.note(hap.value)).setContext({ ...hap.context, type: 'frequency' });
|
return hap.withValue(() => tune.note(hap.value));
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
|
||||||
Pattern.prototype.define('tune', (scale, pat) => pat.tune(scale), { composable: true, patternified: true });
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/st
|
|||||||
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 <https://www.gnu.org/licenses/>.
|
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 <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Pattern, _mod } from '@strudel.cycles/core';
|
import { register, _mod, parseNumeral } from '@strudel.cycles/core';
|
||||||
|
|
||||||
export function edo(name) {
|
export function edo(name) {
|
||||||
if (!/^[1-9]+[0-9]*edo$/.test(name)) {
|
if (!/^[1-9]+[0-9]*edo$/.test(name)) {
|
||||||
@ -48,20 +48,17 @@ function xenOffset(xenScale, offset, index = 0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// scaleNameOrRatios: string || number[], steps?: number
|
// scaleNameOrRatios: string || number[], steps?: number
|
||||||
Pattern.prototype._xen = function (scaleNameOrRatios, steps) {
|
export const xen = register('xen', function (scaleNameOrRatios, pat) {
|
||||||
return this._asNumber()._withHap((hap) => {
|
return pat.withHap((hap) => {
|
||||||
const scale = getXenScale(scaleNameOrRatios);
|
const scale = getXenScale(scaleNameOrRatios);
|
||||||
steps = steps || scale.length;
|
const frequency = xenOffset(scale, parseNumeral(hap.value));
|
||||||
const frequency = xenOffset(scale, hap.value);
|
return hap.withValue(() => frequency);
|
||||||
return hap.withValue(() => frequency).setContext({ ...hap.context, type: 'frequency' });
|
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
|
||||||
Pattern.prototype.tuning = function (steps) {
|
export const tuning = register('tuning', function (ratios, pat) {
|
||||||
return this._asNumber()._withHap((hap) => {
|
return pat.withHap((hap) => {
|
||||||
const frequency = xenOffset(steps, hap.value);
|
const frequency = xenOffset(ratios, parseNumeral(hap.value));
|
||||||
return hap.withValue(() => frequency).setContext({ ...hap.context, type: 'frequency' });
|
return hap.withValue(() => frequency);
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
Pattern.prototype.define('xen', (scale, pat) => pat.xen(scale), { composable: true, patternified: true });
|
|
||||||
// Pattern.prototype.define('tuning', (scale, pat) => pat.xen(scale), { composable: true, patternified: false });
|
|
||||||
|
|||||||
@ -33,7 +33,6 @@ const supabase = createClient(
|
|||||||
|
|
||||||
const modules = [
|
const modules = [
|
||||||
import('@strudel.cycles/core'),
|
import('@strudel.cycles/core'),
|
||||||
// import('@strudel.cycles/tone'),
|
|
||||||
import('@strudel.cycles/tonal'),
|
import('@strudel.cycles/tonal'),
|
||||||
import('@strudel.cycles/mini'),
|
import('@strudel.cycles/mini'),
|
||||||
import('@strudel.cycles/midi'),
|
import('@strudel.cycles/midi'),
|
||||||
@ -46,7 +45,6 @@ const modules = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
evalScope(
|
evalScope(
|
||||||
// Tone,
|
|
||||||
controls, // sadly, this cannot be exported from core direclty
|
controls, // sadly, this cannot be exported from core direclty
|
||||||
{ WebDirt },
|
{ WebDirt },
|
||||||
...modules,
|
...modules,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user