mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-11 21:58:37 +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">
|
||||
document.body.style = 'margin: 0';
|
||||
import * as strudel from 'https://cdn.skypack.dev/@strudel.cycles/core';
|
||||
import 'https://cdn.skypack.dev/@strudel.cycles/core/euclid.mjs';
|
||||
import { Scheduler, getAudioContext } from 'https://cdn.skypack.dev/@strudel.cycles/webaudio@0.0.4';
|
||||
// import * as strudel from '@strudel.cycles/core';
|
||||
import * as strudel from '../../core/index.mjs';
|
||||
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;
|
||||
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))
|
||||
.fast(3)
|
||||
.velocity(.5)
|
||||
.osc(cat('sawtooth','square').fast(2))
|
||||
.wave(cat('sawtooth','square').fast(2))
|
||||
.adsr(0.01,.02,.5,0.1)
|
||||
.filter('lowshelf',800,25)
|
||||
.out()`;
|
||||
|
||||
@ -6,6 +6,9 @@
|
||||
"directories": {
|
||||
"example": "examples"
|
||||
},
|
||||
"scripts": {
|
||||
"example": "npx parcel examples/repl.html"
|
||||
},
|
||||
"repository": {
|
||||
"type": "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;
|
||||
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) => {
|
||||
const osc = getAudioContext().createOscillator();
|
||||
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.stop(e.whole.end.valueOf() + lookahead); // release?
|
||||
return osc;
|
||||
@ -68,7 +69,10 @@ Pattern.prototype.out = function () {
|
||||
console.warn('out: no source! call .osc() first');
|
||||
}
|
||||
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/draw.mjs';
|
||||
import '@strudel.cycles/osc/osc.mjs';
|
||||
import '@strudel.cycles/webaudio/webaudio.mjs';
|
||||
import controls from '@strudel.cycles/core/controls.mjs';
|
||||
|
||||
extend(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user