Merge pull request #1044 from tidalcycles/fix-import

web package fixes
This commit is contained in:
Felix Roos 2024-05-20 23:26:19 +02:00 committed by GitHub
commit 841d897d0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 80 additions and 31 deletions

View File

@ -22,4 +22,4 @@ vite.config.js
reverbGen.mjs
hydra.mjs
jsdoc-synonyms.js
packages/hs2js/src/hs2js.mjs
packages/hs2js/src/hs2js.mjs

View File

@ -1,9 +1,31 @@
<!doctype html>
<script src="https://unpkg.com/@strudel/web@1.0.3"></script>
<button id="play">play</button>
<button id="stop">stop</button>
<script>
strudel.initStrudel();
document.getElementById('play').addEventListener('click', () => evaluate('note("c a f e").jux(rev)'));
document.getElementById('play').addEventListener('stop', () => hush());
</script>
<html>
<head>
<meta charset="UTF-8" />
<!-- <script src="../../packages/web/dist/index.js"></script> -->
<script src="https://unpkg.com/@strudel/web@1.0.3"></script>
</head>
<body style="background: #222">
<button id="play">play</button>
<button id="stop">stop</button>
<script>
strudel.initStrudel();
document.getElementById('play').addEventListener('click', () =>
evaluate(`
//@title washover @by Switch Angel
//@social https://www.instagram.com/_switch_angel/
n("{0 1 3 5 2 }%16")
.add(n(tri.range(0, 6).slow(3)))
.scale("C4:pentatonic")
.sound("sawtooth").att(saw.range(0, 0.05).fast(6))
.release(3).pan(rand).decay(rand.range(0.1, 0.3))
.lpf(tri.range(200, 8000).slow(5)).lpq(0)
.gain(.4).vib(1).vibmod(.1)
.scope({pos:.5})
`),
);
document.getElementById('stop').addEventListener('click', () => strudel.hush());
</script>
</body>
</html>

View File

@ -1,16 +1,24 @@
<!doctype html>
<script src="https://unpkg.com/@strudel/web@1.0.3"></script>
<button id="a">A</button>
<button id="b">B</button>
<button id="c">C</button>
<button id="stop">stop</button>
<script>
initStrudel({
prebake: () => samples('github:tidalcycles/dirt-samples'),
});
const click = (id, action) => document.getElementById(id).addEventListener('click', action);
click('a', () => evaluate(`s('bd,jvbass(3,8)').jux(rev)`));
click('b', () => s('bd*2,hh(3,4),jvbass(5,8,1)').jux(rev).play());
click('c', () => s('bd*2,hh(3,4),jvbass:[0 4](5,8,1)').jux(rev).stack(s('~ sd')).play());
click('stop', () => hush());
</script>
<html>
<head>
<meta charset="UTF-8" />
<!-- <script src="../../packages/web/dist/index.js"></script> -->
<script src="https://unpkg.com/@strudel/web@1.0.3"></script>
</head>
<body style="background: #222">
<button id="a">A</button>
<button id="b">B</button>
<button id="c">C</button>
<button id="stop">stop</button>
<script>
initStrudel({
prebake: () => samples('github:tidalcycles/dirt-samples'),
});
const click = (id, action) => document.getElementById(id).addEventListener('click', action);
click('a', () => evaluate(`s('bd,jvbass(3,8)').jux(rev)`));
click('b', () => s('bd*2,hh(3,4),jvbass(5,8,1)').jux(rev).play());
click('c', () => s('bd*2,hh(3,4),jvbass:[0 4](5,8,1)').jux(rev).stack(s('~ sd')).play());
click('stop', () => hush());
</script>
</body>
</html>

View File

@ -191,7 +191,16 @@ export function getComputedPropertyValue(name) {
return getComputedStyle(document.documentElement).getPropertyValue(name);
}
let theme = {};
let theme = {
background: '#222',
foreground: '#75baff',
caret: '#ffcc00',
selection: 'rgba(128, 203, 196, 0.5)',
selectionMatch: '#036dd626',
lineHighlight: '#00000050',
gutterBackground: 'transparent',
gutterForeground: '#8a919966',
};
export function getTheme() {
return theme;
}

View File

@ -108,7 +108,7 @@ export function pianoroll({
active = getTheme().foreground,
background = 'transparent',
smear = 0,
playheadColor = 'white',
playheadColor = getTheme().foreground,
minMidi = 10,
maxMidi = 90,
autorange = 0,

View File

@ -1,5 +1,5 @@
import { getDrawContext } from '@strudel/draw';
import { controls } from '@strudel/core';
import { controls, getTime, reify } from '@strudel/core';
let latestOptions;
let hydra;
@ -27,6 +27,7 @@ export async function initHydra(options = {}) {
hydraConfig.canvas = canvas;
await import(/* @vite-ignore */ src);
/* eslint-disable-next-line */
hydra = new Hydra(hydraConfig);
if (feedStrudel) {
const { canvas } = getDrawContext();
@ -46,4 +47,4 @@ export function clearHydra() {
globalThis.shape = controls.shape;
}
export const H = (p) => () => p.queryArc(getTime(), getTime())[0].value;
export const H = (p) => () => reify(p).queryArc(getTime(), getTime())[0].value;

View File

@ -72,7 +72,13 @@ document.getElementById('play').addEventListener('stop',
There is a tiny difference between the [Strudel REPL](https://strudel.cc/) and `@strudel/web`.
In the REPL you can use 'single quotes' for regular JS strings and "double quotes" for mini notation patterns.
In `@strudel/web`, it does not matter which types of quotes you're using.
There will probably be an escapte hatch for that in the future.
This difference means that you cannot call pattern methods on raw strings, for example `"1 2 3".slow(2)`.
To make it work you can either:
1. Use the `evaluate` function, which behaves exactly like the Strudel REPL, interpreting double quoted strings as mini notation.
2. wrap the string with `m`: `m("1 2 3").slow(2)`
3. wrap the string in a control function: `n("1 2 3").slow(2)` depending on your context.
## More Examples

View File

@ -5,7 +5,7 @@ export * from '@strudel/transpiler';
export * from '@strudel/mini';
export * from '@strudel/tonal';
export * from '@strudel/webaudio';
import { Pattern, evalScope } from '@strudel/core';
import { Pattern, evalScope, setTime } from '@strudel/core';
import { initAudioOnFirstClick, registerSynthSounds, webaudioScheduler } from '@strudel/webaudio';
// import { registerSoundfonts } from '@strudel/soundfonts';
import { evaluate as _evaluate } from '@strudel/transpiler';
@ -33,11 +33,14 @@ export function initStrudel(options = {}) {
miniAllStrings();
const { prebake, ...schedulerOptions } = options;
scheduler = webaudioScheduler(schedulerOptions);
initDone = (async () => {
await defaultPrebake();
await prebake?.();
return scheduler;
})();
scheduler = webaudioScheduler(schedulerOptions);
setTime(() => scheduler.now());
return initDone;
}
window.initStrudel = initStrudel;