mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-24 12:08:28 +00:00
make webaudio compatible with repl
+ rename osc to wave + migrate repl.html
This commit is contained in:
parent
e0e3ab941e
commit
f210c4425b
@ -11,9 +11,12 @@ Loading...</textarea
|
|||||||
>
|
>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
document.body.style = 'margin: 0';
|
document.body.style = 'margin: 0';
|
||||||
import * as strudel from 'https://cdn.skypack.dev/@strudel.cycles/core';
|
// import * as strudel from '@strudel.cycles/core';
|
||||||
import 'https://cdn.skypack.dev/@strudel.cycles/core/euclid.mjs';
|
import * as strudel from '../../core/index.mjs';
|
||||||
import { Scheduler, getAudioContext } from 'https://cdn.skypack.dev/@strudel.cycles/webaudio@0.0.4';
|
import * as util from '../../core/util.mjs';
|
||||||
|
import '@strudel.cycles/core/euclid.mjs';
|
||||||
|
// import { Scheduler, getAudioContext } from 'https://cdn.skypack.dev/@strudel.cycles/webaudio@0.0.4';
|
||||||
|
import { Scheduler, getAudioContext } from '../index.mjs';
|
||||||
|
|
||||||
const { cat, State, TimeSpan } = strudel;
|
const { cat, State, TimeSpan } = strudel;
|
||||||
Object.assign(window, strudel); // add strudel to eval scope
|
Object.assign(window, strudel); // add strudel to eval scope
|
||||||
@ -31,7 +34,7 @@ Loading...</textarea
|
|||||||
.mul(slowcat(1,3/2,4/3,5/3).slow(8))
|
.mul(slowcat(1,3/2,4/3,5/3).slow(8))
|
||||||
.fast(3)
|
.fast(3)
|
||||||
.velocity(.5)
|
.velocity(.5)
|
||||||
.osc(cat('sawtooth','square').fast(2))
|
.wave(cat('sawtooth','square').fast(2))
|
||||||
.adsr(0.01,.02,.5,0.1)
|
.adsr(0.01,.02,.5,0.1)
|
||||||
.filter('lowshelf',800,25)
|
.filter('lowshelf',800,25)
|
||||||
.out()`;
|
.out()`;
|
||||||
|
|||||||
@ -6,6 +6,9 @@
|
|||||||
"directories": {
|
"directories": {
|
||||||
"example": "examples"
|
"example": "examples"
|
||||||
},
|
},
|
||||||
|
"scripts": {
|
||||||
|
"example": "npx parcel examples/repl.html"
|
||||||
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/tidalcycles/strudel.git"
|
"url": "git+https://github.com/tidalcycles/strudel.git"
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { Pattern } from '@strudel.cycles/core';
|
import { Pattern, getFrequency } from '@strudel.cycles/core';
|
||||||
|
|
||||||
let audioContext;
|
let audioContext;
|
||||||
export const getAudioContext = () => {
|
export const getAudioContext = () => {
|
||||||
@ -30,11 +30,12 @@ Pattern.prototype.withAudioNode = function (createAudioNode) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Pattern.prototype._osc = function (type) {
|
Pattern.prototype._wave = function (type) {
|
||||||
return this.withAudioNode((e) => {
|
return this.withAudioNode((e) => {
|
||||||
const osc = getAudioContext().createOscillator();
|
const osc = getAudioContext().createOscillator();
|
||||||
osc.type = type;
|
osc.type = type;
|
||||||
osc.frequency.value = e.value; // expects frequency..
|
const f = getFrequency(e);
|
||||||
|
osc.frequency.value = f; // expects frequency..
|
||||||
osc.start(e.whole.begin.valueOf() + lookahead);
|
osc.start(e.whole.begin.valueOf() + lookahead);
|
||||||
osc.stop(e.whole.end.valueOf() + lookahead); // release?
|
osc.stop(e.whole.end.valueOf() + lookahead); // release?
|
||||||
return osc;
|
return osc;
|
||||||
@ -68,7 +69,10 @@ Pattern.prototype.out = function () {
|
|||||||
console.warn('out: no source! call .osc() first');
|
console.warn('out: no source! call .osc() first');
|
||||||
}
|
}
|
||||||
node?.connect(master);
|
node?.connect(master);
|
||||||
|
})._withEvent((event) => {
|
||||||
|
const onTrigger = (_, e) => e.context?.createAudioNode?.(e);
|
||||||
|
return event.setContext({ ...event.context, onTrigger });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Pattern.prototype.define('osc', (type, pat) => pat.osc(type), { patternified: true });
|
Pattern.prototype.define('wave', (type, pat) => pat.wave(type), { patternified: true });
|
||||||
|
|||||||
@ -30,6 +30,7 @@ import '@strudel.cycles/core/speak.mjs';
|
|||||||
import '@strudel.cycles/tone/pianoroll.mjs';
|
import '@strudel.cycles/tone/pianoroll.mjs';
|
||||||
import '@strudel.cycles/tone/draw.mjs';
|
import '@strudel.cycles/tone/draw.mjs';
|
||||||
import '@strudel.cycles/osc/osc.mjs';
|
import '@strudel.cycles/osc/osc.mjs';
|
||||||
|
import '@strudel.cycles/webaudio/webaudio.mjs';
|
||||||
import controls from '@strudel.cycles/core/controls.mjs';
|
import controls from '@strudel.cycles/core/controls.mjs';
|
||||||
|
|
||||||
extend(
|
extend(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user