Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1f54d93a00 | |||
| 284f6293a2 | |||
| a2b99f94bd | |||
| 8a0f9c6e36 | |||
| d38a8ab1fa | |||
| 6a451be50c | |||
| dac2996b3d | |||
| d689d71ee6 | |||
| a4a6321afb | |||
| 8b13badb67 | |||
| 15a6747b2c | |||
| a96ff66f63 | |||
| 123323e32b | |||
| 8ca850f9fe | |||
| d77725cf1d | |||
| b016d115f5 | |||
| 1a57a86497 | |||
| d433e68fb2 | |||
| c90bc80e6d | |||
| d3c4fd70dc | |||
| 87cab96893 | |||
| 0248d15470 | |||
| d4801c545e | |||
| ce28acaf18 | |||
| bf0336404d | |||
| 7c3d8e5c8d | |||
| 3dad55e266 | |||
| 3d9ac37efe | |||
| d4619362bd |
@@ -0,0 +1,26 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
public/samples
|
||||
@@ -0,0 +1,22 @@
|
||||
# Usage
|
||||
|
||||
```sh
|
||||
cd iclc2023/slides
|
||||
pnpm i
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
- ctrl+click or ctrl+(left|right) to switch slides
|
||||
|
||||
## Samples
|
||||
|
||||
To make sure all the samples are available, clone:
|
||||
|
||||
```sh
|
||||
cd public/samples
|
||||
git clone https://github.com/ritchse/tidal-drum-machines.git
|
||||
git clone https://github.com/tidalcycles/Dirt-Samples.git
|
||||
git clone https://github.com/felixroos/webaudiofontdata.git
|
||||
```
|
||||
|
||||
or use symlinks..
|
||||
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<!-- <link rel="icon" type="image/svg+xml" href="/vite.svg" /> -->
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Slides</title>
|
||||
</head>
|
||||
<body style="background-color: black">
|
||||
<div id="root">
|
||||
<span style="color: white">loading... </span>
|
||||
</div>
|
||||
<script type="module" src="/src/main.jsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "slides",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@mdx-js/rollup": "^2.3.0",
|
||||
"@nanostores/persistent": "^0.7.0",
|
||||
"@nanostores/react": "^0.4.1",
|
||||
"@strudel.cycles/core": "workspace:*",
|
||||
"@strudel.cycles/react": "workspace:*",
|
||||
"@strudel.cycles/soundfonts": "workspace:*",
|
||||
"@strudel.cycles/tonal": "workspace:*",
|
||||
"@strudel.cycles/csound": "workspace:*",
|
||||
"@strudel.cycles/webaudio": "workspace:*",
|
||||
"@uiw/codemirror-themes-all": "^4.19.8",
|
||||
"escodegen": "^2.0.0",
|
||||
"nanostores": "^0.7.4",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-syntax-highlighter": "^15.5.0",
|
||||
"remark-gfm": "^3.0.1",
|
||||
"vite-plugin-top-level-await": "^1.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/typography": "^0.5.8",
|
||||
"@types/react": "^18.0.28",
|
||||
"@types/react-dom": "^18.0.11",
|
||||
"@vitejs/plugin-react": "^3.1.0",
|
||||
"autoprefixer": "^10.4.14",
|
||||
"postcss": "^8.4.21",
|
||||
"tailwindcss": "^3.2.7",
|
||||
"vite": "^4.2.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
||||
|
After Width: | Height: | Size: 108 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 106 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 62 KiB |
|
After Width: | Height: | Size: 163 KiB |
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 224 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 83 KiB |
|
After Width: | Height: | Size: 244 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 123 KiB |
|
After Width: | Height: | Size: 103 KiB |
@@ -0,0 +1,46 @@
|
||||
import { useState, useCallback } from 'react';
|
||||
import { atomone } from '@uiw/codemirror-themes-all';
|
||||
import { CodeMirror, flash, useKeydown } from '@strudel.cycles/react';
|
||||
import { initAudioOnFirstClick, webaudioOutput } from '@strudel.cycles/webaudio';
|
||||
import { TimeSpan } from '@strudel.cycles/core';
|
||||
|
||||
const initAudio = initAudioOnFirstClick();
|
||||
|
||||
function EventEditor({ code: initialCode }) {
|
||||
const [code, setCode] = useState(initialCode);
|
||||
const [view, setView] = useState();
|
||||
useKeydown(
|
||||
useCallback(
|
||||
async (e) => {
|
||||
if (view?.hasFocus) {
|
||||
if (e.ctrlKey || e.altKey) {
|
||||
if (e.code === 'Enter') {
|
||||
/* if (getAudioContext().state !== 'running') {
|
||||
alert('please click play to initialize the audio. you can use shortcuts after that!');
|
||||
return;
|
||||
} */
|
||||
e.preventDefault();
|
||||
flash(view);
|
||||
let json = JSON.parse(code);
|
||||
if (!Array.isArray(json)) {
|
||||
json = [json];
|
||||
}
|
||||
await initAudio;
|
||||
json.forEach((value) => {
|
||||
const hap = new Hap(new TimeSpan(0, 1), new TimeSpan(0, 1), value);
|
||||
webaudioOutput(hap, 0.01, 1, 1);
|
||||
});
|
||||
} else if (e.key === '.') {
|
||||
stop();
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
[code, view],
|
||||
),
|
||||
);
|
||||
return <CodeMirror value={code} onChange={setCode} theme={atomone} onViewChanged={(v) => setView(v)} fontSize={32} />;
|
||||
}
|
||||
|
||||
export default EventEditor;
|
||||
@@ -0,0 +1,39 @@
|
||||
import EventEditor from './EventEditor.jsx';
|
||||
import Stepper from './Stepper.jsx';
|
||||
|
||||
const snippets = [
|
||||
[`{ "s": "cp", "crush": 4 }`, 'Samples'],
|
||||
[`{ "s": "sawtooth", "note": "e3" }`, 'Oscillators'],
|
||||
[
|
||||
`[
|
||||
{ "s": "gm_epiano2", "note": "c4" },
|
||||
{ "s": "gm_epiano2", "note": "eb4" },
|
||||
{ "s": "gm_epiano2", "note": "g4" }
|
||||
]`,
|
||||
'Soundfonts',
|
||||
],
|
||||
[
|
||||
`{
|
||||
"s": "toys",
|
||||
"cutoff": 2000,
|
||||
"delay": 0.5,
|
||||
"crush": 4
|
||||
}`,
|
||||
'Effects',
|
||||
],
|
||||
];
|
||||
|
||||
function EventsDemo() {
|
||||
return (
|
||||
<Stepper
|
||||
steps={snippets.map(([code, label]) => (
|
||||
<div className="py-4 space-y-4">
|
||||
<h3>{label}</h3>
|
||||
<EventEditor code={code} />
|
||||
</div>
|
||||
))}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default EventsDemo;
|
||||
@@ -0,0 +1,21 @@
|
||||
//import {Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
|
||||
//import { atomDark } from 'react-syntax-highlighter/dist/esm/styles/prism';
|
||||
//import SyntaxHighlighter from 'react-syntax-highlighter';
|
||||
import { atomOneDark } from 'react-syntax-highlighter/dist/esm/styles/hljs';
|
||||
import { Light as SyntaxHighlighter } from 'react-syntax-highlighter';
|
||||
import js from 'react-syntax-highlighter/dist/esm/languages/hljs/javascript';
|
||||
import hs from 'react-syntax-highlighter/dist/esm/languages/hljs/haskell';
|
||||
SyntaxHighlighter.registerLanguage('javascript', js);
|
||||
SyntaxHighlighter.registerLanguage('haskell', hs);
|
||||
|
||||
function Highlight({ code, language = 'javascript' }) {
|
||||
return (
|
||||
<div className="text-[32px] leading-10 rounded-xl overflow-hidden">
|
||||
<SyntaxHighlighter language={language} style={atomOneDark} customStyle={{ padding: '8px 10px' }}>
|
||||
{code}
|
||||
</SyntaxHighlighter>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Highlight;
|
||||
@@ -0,0 +1,38 @@
|
||||
import { SlideRepl } from './SlideRepl.jsx';
|
||||
import Stepper from './Stepper.jsx';
|
||||
|
||||
const snippets = [
|
||||
[`sound("bd [hh sd]")`, `sound(seq("bd", ["hh", "sd"]))`, 'Nested Sequences'], //
|
||||
[`sound("<bd sd>")`, `sound(cat("bd", "sd"))`, 'Cyclewise Sequences'], //
|
||||
[`sound("bd,hh")`, `sound(stack("bd", "hh"))`, 'Stack'], //
|
||||
[`sound("bd@3 sd@1")`, `sound(timeCat([3, "bd"], [1, "sd"]))`, 'Weighted Sequence'], //
|
||||
[`sound("{lt ht mt, bd sd}")`, `sound(polymeter(["lt","ht","mt"], ["bd", "sd"]))`, 'Polymeter'], //
|
||||
[`sound("{bd hh sd ht}%2")`, `sound(polymeterSteps(2, ["bd", "hh", "sd", "ht"]))`, 'Steps per Cycle'],
|
||||
];
|
||||
|
||||
function MiniComparison() {
|
||||
return (
|
||||
<>
|
||||
<h1>User Code: Mini Notation -> JavaScript</h1>
|
||||
<Stepper
|
||||
steps={snippets.map(([a, b, label]) => (
|
||||
<div className="py-4">
|
||||
<h3 className="pb-4">{label}</h3>
|
||||
<div className="space-y-2">
|
||||
<div className="flex space-x-2">
|
||||
<img src="./img/tidalcycles.svg" className={`h-10 mt-2`} />
|
||||
<SlideRepl tune={a} hideHeader />
|
||||
</div>
|
||||
<div className="flex space-x-2">
|
||||
<img src="./img/js.jpg" className={`h-10 mt-2`} />
|
||||
<SlideRepl tune={b} hideHeader />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default MiniComparison;
|
||||
@@ -0,0 +1,50 @@
|
||||
import { SlideRepl } from './SlideRepl.jsx';
|
||||
import Highlight from './Highlight.jsx';
|
||||
import Stepper from './Stepper.jsx';
|
||||
|
||||
const snippets = [
|
||||
[
|
||||
<>
|
||||
{' '}
|
||||
<SlideRepl tune={`s("bd [hh sd]").crush(4).log()`} hideHeader />
|
||||
</>,
|
||||
'Logging Events',
|
||||
],
|
||||
[
|
||||
<>
|
||||
<Highlight
|
||||
code={`let pattern = s("bd [hh sd]").crush(4);
|
||||
let events = pattern.queryArc(0, 1);
|
||||
console.log(events.map(e => e.show()))`}
|
||||
language="javascript"
|
||||
/>
|
||||
<Highlight
|
||||
language="json"
|
||||
code={`[
|
||||
"0/1 -> 1/2 | s:bd crush:4",
|
||||
"1/2 -> 3/4 | s:hh crush:4",
|
||||
"3/4 -> 1/1 | s:sd crush:4"
|
||||
]`}
|
||||
/>
|
||||
</>,
|
||||
'Querying Events Manually',
|
||||
],
|
||||
];
|
||||
|
||||
function QueryDemo() {
|
||||
return (
|
||||
<>
|
||||
<img src="./img/queryflow.png" className="w-[800px]" />
|
||||
<Stepper
|
||||
steps={snippets.map(([snippet, label]) => (
|
||||
<div className="py-4 space-y-4">
|
||||
<h3>{label}</h3>
|
||||
{snippet}
|
||||
</div>
|
||||
))}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default QueryDemo;
|
||||
@@ -0,0 +1,49 @@
|
||||
import { evalScope, controls } from '@strudel.cycles/core';
|
||||
import { initAudioOnFirstClick } from '@strudel.cycles/webaudio';
|
||||
import { MiniRepl as _MiniRepl } from '@strudel.cycles/react';
|
||||
import { prebake } from './prebake';
|
||||
import { atomone } from '@uiw/codemirror-themes-all';
|
||||
import blackscreen from '@strudel.cycles/react/src/themes/blackscreen';
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
await evalScope(
|
||||
controls,
|
||||
import('@strudel.cycles/core'),
|
||||
import('@strudel.cycles/tonal'),
|
||||
import('@strudel.cycles/mini'),
|
||||
import('@strudel.cycles/webaudio'),
|
||||
import('@strudel.cycles/soundfonts'),
|
||||
import('@strudel.cycles/csound'),
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
initAudioOnFirstClick();
|
||||
prebake();
|
||||
}
|
||||
|
||||
export function SlideRepl({
|
||||
tune,
|
||||
drawTime,
|
||||
punchcard,
|
||||
canvasHeight = 100,
|
||||
hideHeader = false,
|
||||
fontSize = 32,
|
||||
disabled = false,
|
||||
}) {
|
||||
return (
|
||||
<div className="not-prose rounded-xl overflow-hidden">
|
||||
<_MiniRepl
|
||||
hideHeader={hideHeader}
|
||||
tune={tune}
|
||||
hideOutsideView={true}
|
||||
drawTime={drawTime}
|
||||
punchcard={punchcard}
|
||||
canvasHeight={canvasHeight}
|
||||
fontSize={fontSize}
|
||||
theme={disabled ? blackscreen : atomone}
|
||||
// theme={themes[theme]}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
import { persistentAtom } from '@nanostores/persistent';
|
||||
import { useStore } from '@nanostores/react'; // or '@nanostores/preact'
|
||||
import useEvent from './useEvent';
|
||||
|
||||
function cx(...classes) {
|
||||
return classes.filter(Boolean).join(' ');
|
||||
}
|
||||
// https://vitejs.dev/guide/features.html#glob-import
|
||||
const slideImports = import.meta.glob('./slides/*.mdx');
|
||||
//const slideImports = import.meta.glob('./slides/*.mdx', { eager: true });
|
||||
console.log('load slides...', slideImports);
|
||||
|
||||
const loadedMDXFiles = await Promise.all(
|
||||
Object.entries(slideImports).map(async ([path, load]) => {
|
||||
//Object.entries(slideImports).map(async ([path, m]) => {
|
||||
const segments = path.split('/');
|
||||
const filename = segments[segments.length - 1].slice(0, -4); // expects .mdx at the end
|
||||
return [filename, (await load()).default];
|
||||
//return [filename, m.default];
|
||||
}),
|
||||
);
|
||||
console.log('load done!');
|
||||
|
||||
const order = [
|
||||
'cover',
|
||||
'whatIsStrudel',
|
||||
'history',
|
||||
'hs2js',
|
||||
|
||||
'usage',
|
||||
'swatch',
|
||||
'repl',
|
||||
//'repl-features',
|
||||
'viz',
|
||||
|
||||
'replflow',
|
||||
|
||||
// User Code
|
||||
'transpilation',
|
||||
'mininotation',
|
||||
// 'mini-comparison', // remove?
|
||||
// Patterns
|
||||
'patterns-events', // remove?
|
||||
// scheduler?
|
||||
// Output
|
||||
'events-audio', // remove?
|
||||
'outputs',
|
||||
// 'csound', // remove?
|
||||
//
|
||||
// pattern alignment?
|
||||
'bad',
|
||||
'good',
|
||||
'future',
|
||||
'end',
|
||||
];
|
||||
// examples swatch
|
||||
// draw examples!!
|
||||
|
||||
const slideEntries = order.map((name) => loadedMDXFiles.find(([file]) => file === name));
|
||||
|
||||
// current slide index is persisted, so it's safe to refresh the browser
|
||||
export const slideIndex = persistentAtom('slideIndex', '0');
|
||||
|
||||
export const prev = () => slideIndex.set((parseInt(slideIndex.get()) - 1 + slideEntries.length) % slideEntries.length);
|
||||
export const next = () => slideIndex.set((parseInt(slideIndex.get()) + 1) % slideEntries.length);
|
||||
|
||||
function Slides() {
|
||||
const activeIndex = parseInt(useStore(slideIndex));
|
||||
|
||||
/*useEvent('click', (e) => {
|
||||
if (!e.ctrlKey) {
|
||||
return;
|
||||
}
|
||||
const leftHalf = e.clientX / document.body.clientWidth < 0.5;
|
||||
if (leftHalf) {
|
||||
prev();
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});*/
|
||||
/*useEvent('keydown', (e) => {
|
||||
if (e.key === 'Home') {
|
||||
prev();
|
||||
} else if (e.key === 'End') {
|
||||
next();
|
||||
}
|
||||
});*/
|
||||
|
||||
return (
|
||||
<div className="w-screen h-screen overflow-hidden relative">
|
||||
{slideEntries.map(([path, Slide], i) => (
|
||||
<div
|
||||
key={i}
|
||||
className={cx(
|
||||
`bg-slate-900 w-full h-full flex justify-center absolute top-0 transition-all ease-in-out duration-500 overflow-auto`,
|
||||
i < activeIndex && '-translate-x-full',
|
||||
i > activeIndex && 'translate-x-full',
|
||||
)}
|
||||
>
|
||||
<div className="prose prose-invert w-[1400px] p-12 max-w-full" style={{ fontSize: '2em' }}>
|
||||
{Math.abs(i - activeIndex) <= 1 && <Slide />}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<div className="text-white text-2xl text-bold cursor-pointer select-none">
|
||||
<div className="fixed left-0 p-4 h-full items-start flex hover:bg-[#00000050]" onClick={() => prev()}>
|
||||
<
|
||||
</div>
|
||||
<div className="fixed right-0 p-4 h-full items-start flex hover:bg-[#00000050]" onClick={() => next()}>
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
<div className="absolute top-0 w-full">
|
||||
<div className="h-[5px] bg-slate-500 w-full z-100">
|
||||
<div
|
||||
style={{ width: ((activeIndex / (slideEntries.length - 1)) * 100).toFixed(0) + '%' }}
|
||||
className="h-full bg-yellow-500"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Slides;
|
||||
@@ -0,0 +1,20 @@
|
||||
import { useState } from 'react';
|
||||
|
||||
function Stepper({ steps }) {
|
||||
const [step, setStep] = useState(1);
|
||||
return (
|
||||
<div className="not-prose">
|
||||
{steps.slice(0, step).map((snippet, i) => {
|
||||
const isActive = i === step - 1;
|
||||
return (
|
||||
<div key={i} className={`border-l-4 pl-8 border-gray-500 ${isActive ? 'border-yellow-500' : ''}`}>
|
||||
{snippet}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
{step < steps.length && <button onClick={() => setStep((r) => r + 1)}>next</button>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Stepper;
|
||||
@@ -0,0 +1,73 @@
|
||||
import { SlideRepl } from './SlideRepl.jsx';
|
||||
import Highlight from './Highlight.jsx';
|
||||
import Stepper from './Stepper.jsx';
|
||||
|
||||
const snippets = [
|
||||
[`sound "bd ~ [sd cp]"`, [`sound("bd ~ [sd cp]")`], 'Mini Notation'], //
|
||||
[`sound "bd ~ [sd cp]" # speed "1 2"`, [`sound("bd ~ [sd cp]").speed("1 2")`], 'Composing Patterns'],
|
||||
[
|
||||
`fast 2 $ sound "bd ~ [sd cp]"`,
|
||||
[`fast(2, sound("bd ~ [sd cp]"))`, `sound("bd ~ [sd cp]").fast(2)`],
|
||||
'Patterns Transformations',
|
||||
],
|
||||
[
|
||||
`speed "1 2 3" + "4 5" # s "bd"`,
|
||||
['speed("1 2 3".add("4 5")).s("bd")', '"1 2 3".add("4 5").speed().s("bd")'],
|
||||
'Pattern Arithmetic',
|
||||
],
|
||||
[
|
||||
`jux rev
|
||||
$ every 3 (fast 2)
|
||||
$ sound "bd sd"`,
|
||||
[
|
||||
`sound("bd sd")
|
||||
.every(3, fast("2"))
|
||||
.jux(rev)`,
|
||||
],
|
||||
'Higher order transformations (with partial application)',
|
||||
],
|
||||
[
|
||||
`jux rev
|
||||
$ every "<3 5>" (fast "1 2")
|
||||
$ sound "bd sd cp mt"`,
|
||||
[
|
||||
`sound("bd sd cp mt")
|
||||
.every("<3 5>", fast("1 2"))
|
||||
.jux(rev)`,
|
||||
],
|
||||
'Patterns all the way down',
|
||||
],
|
||||
];
|
||||
|
||||
function SyntaxComparison() {
|
||||
return (
|
||||
<>
|
||||
<h1>Haskell -> JavaScript</h1>
|
||||
<Stepper
|
||||
steps={snippets
|
||||
.map(([hs, js, label]) => (
|
||||
<div className="py-4 space-y-4">
|
||||
<h3>{label}</h3>
|
||||
<div className="space-y-2">
|
||||
<div className="flex space-x-4">
|
||||
<img src="./img/haskell.png" className="h-10 mt-2" />
|
||||
<Highlight language="haskell" code={hs} />
|
||||
</div>
|
||||
<div>
|
||||
{js.map((c, j) => (
|
||||
<div className="flex space-x-4" key={j}>
|
||||
<img src="./img/js.jpg" className={`h-10 mt-2`} />
|
||||
<SlideRepl tune={c} hideHeader />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
.concat([<>Fluent Interface: Just chain all the things!</>])}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default SyntaxComparison;
|
||||
@@ -0,0 +1,84 @@
|
||||
import { useState, useCallback } from 'react';
|
||||
import { atomone } from '@uiw/codemirror-themes-all';
|
||||
import { CodeMirror, flash, useKeydown } from '@strudel.cycles/react';
|
||||
import { transpiler } from '@strudel.cycles/transpiler';
|
||||
import Highlight from './Highlight';
|
||||
import Stepper from './Stepper';
|
||||
import escodegen from 'escodegen';
|
||||
|
||||
function getTranspiled(code) {
|
||||
return transpiler(code, {
|
||||
addReturn: false,
|
||||
codegenOptions: {
|
||||
format: escodegen.FORMAT_MINIFY,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function TranspilationEditor({ code: initialCode }) {
|
||||
const [code, setCode] = useState(initialCode);
|
||||
const [transpiled, setTranspiled] = useState(getTranspiled(initialCode));
|
||||
const [view, setView] = useState();
|
||||
useKeydown(
|
||||
useCallback(
|
||||
async (e) => {
|
||||
if (view?.hasFocus) {
|
||||
if (e.ctrlKey || e.altKey) {
|
||||
if (e.code === 'Enter') {
|
||||
/* if (getAudioContext().state !== 'running') {
|
||||
alert('please click play to initialize the audio. you can use shortcuts after that!');
|
||||
return;
|
||||
} */
|
||||
e.preventDefault();
|
||||
flash(view);
|
||||
const t = getTranspiled(code);
|
||||
setTranspiled(t);
|
||||
console.log('transpiled', t);
|
||||
} else if (e.key === '.') {
|
||||
stop();
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
[code, view],
|
||||
),
|
||||
);
|
||||
return (
|
||||
<div className="space-y-2 py-2">
|
||||
<CodeMirror
|
||||
value={code}
|
||||
onChange={(v) => {
|
||||
setCode(v);
|
||||
}}
|
||||
theme={atomone}
|
||||
onViewChanged={(v) => setView(v)}
|
||||
fontSize={32}
|
||||
/>
|
||||
<span>⬇️ transpiles to</span>
|
||||
<Highlight language="javascript" code={transpiled} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function TranspilationDemo() {
|
||||
return (
|
||||
<div className="not-prose space-y-8">
|
||||
<Stepper
|
||||
steps={[
|
||||
<>
|
||||
<img src="./img/transpileflow.png" className="h-[500px]" />
|
||||
<ul className="list-decimal pl-8">
|
||||
<li>Parse JS Code with acorn to get AST</li>
|
||||
<li>Modify AST with estree-walker</li>
|
||||
<li>Convert modified AST back to JS with escodegen</li>
|
||||
</ul>
|
||||
</>,
|
||||
<TranspilationEditor code={`"bd [hh sd]"`} />,
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default TranspilationDemo;
|
||||
@@ -0,0 +1,21 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
.cm-activeLine {
|
||||
background-color: transparent !important;
|
||||
}
|
||||
|
||||
.cm-theme {
|
||||
background-color: var(--background);
|
||||
border: 1px solid var(--lineHighlight);
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
.cm-gutters {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
img {
|
||||
@apply rounded-xl overflow-hidden;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import Slides from './Slides';
|
||||
import './index.css';
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')).render(
|
||||
<React.StrictMode>
|
||||
<Slides />
|
||||
</React.StrictMode>,
|
||||
);
|
||||
@@ -0,0 +1,22 @@
|
||||
import { registerSynthSounds, samples } from '@strudel.cycles/webaudio';
|
||||
import { registerSoundfonts } from '@strudel.cycles/soundfonts';
|
||||
|
||||
export async function prebake() {
|
||||
// https://archive.org/details/SalamanderGrandPianoV3
|
||||
// License: CC-by http://creativecommons.org/licenses/by/3.0/ Author: Alexander Holm
|
||||
await Promise.all([
|
||||
registerSynthSounds(),
|
||||
registerSoundfonts(`./samples/webaudiofontdata/sound/`),
|
||||
/* samples(`./piano.json`, `./piano/`, { prebake: true }),
|
||||
samples(`./vcsl.json`, 'github:sgossner/VCSL/master/', { prebake: true }),
|
||||
*/
|
||||
//samples(`./tidal-drum-machines.json`, 'github:ritchse/tidal-drum-machines/main/machines/', {
|
||||
samples(`./tidal-drum-machines.json`, './samples/tidal-drum-machines/machines/', {
|
||||
prebake: true,
|
||||
tag: 'drum-machines',
|
||||
}) /*
|
||||
samples(`./EmuSP12.json`, `./EmuSP12/`, { prebake: true, tag: 'drum-machines' }), */,
|
||||
// samples('github:tidalcycles/Dirt-Samples/master'),
|
||||
samples('./Dirt-Samples.json', './samples/Dirt-Samples/'),
|
||||
]);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
# What's bad
|
||||
|
||||
- Dynamic Typing in JS
|
||||
- Fractions and Hot Paths
|
||||
- Verbose function composition
|
||||
- Method-chaining tradeoffs
|
||||
@@ -0,0 +1,7 @@
|
||||
<div className="flex flex-col justify-between h-full overflow-hidden max-h-screen space-y-8">
|
||||
<h2 className="m-0">Strudel: live coding patterns on the Web</h2>
|
||||
<div className="justify-center flex overflow-hidden not-prose">
|
||||
<img src="./img/strudel_icon.png" className="h-full" />
|
||||
</div>
|
||||
<span>Felix Roos, Alex McLean</span>
|
||||
</div>
|
||||
@@ -0,0 +1,65 @@
|
||||
import { SlideRepl } from '../SlideRepl.jsx';
|
||||
|
||||
# CSound Example
|
||||
|
||||
## Loading ORC instruments
|
||||
|
||||
<SlideRepl
|
||||
tune={`// livecode.orc by Steven Yi
|
||||
await loadOrc('github:kunstmusik/csound-live-code/master/livecode.orc')
|
||||
|
||||
stack(
|
||||
note("<C^7 A7 Dm7 Fm7>/2".voicings('lefthand'))
|
||||
.cutoff(sine.range(500,2000).round().slow(16))
|
||||
.euclidLegato(3,8).csound('FM1'),
|
||||
|
||||
note("<C2 A1 D2 F2>/2").ply(8).csound('Bass')
|
||||
.gain("1 4 1 4"),
|
||||
|
||||
note("0 7 [4 3] 2".fast(2/3)
|
||||
.off(".25 .125", add("<2 4 -3 -1>"))
|
||||
.slow(2).scale('A4 minor'))
|
||||
.legato(.25).csound('SynHarp'),
|
||||
|
||||
s("bd*2,[~ hh]*2,~ cp").bank('RolandTR909')
|
||||
)`}
|
||||
hideHeader
|
||||
/>
|
||||
|
||||
## Synthesis
|
||||
|
||||
<SlideRepl
|
||||
tune={`await loadCsound\`
|
||||
instr CoolSynth
|
||||
iduration = p3
|
||||
ifreq = p4
|
||||
igain = p5
|
||||
ioct = octcps(ifreq)
|
||||
|
||||
kpwm = oscili(.05, 8)
|
||||
asig = vco2(igain, ifreq, 4, .5 + kpwm)
|
||||
asig += vco2(igain, ifreq * 2)
|
||||
|
||||
idepth = 2
|
||||
acut = transegr:a(0, .005, 0, idepth, .06, -4.2, 0.001, .01, -4.2, 0) ; filter envelope
|
||||
asig = zdf_2pole(asig, cpsoct(ioct + acut + 2), 0.5)
|
||||
|
||||
iattack = .01
|
||||
isustain = .5
|
||||
idecay = .1
|
||||
irelease = .1
|
||||
asig *= linsegr:a(0, iattack, 1, idecay, isustain, iduration, isustain, irelease, 0)
|
||||
|
||||
out(asig, asig)
|
||||
|
||||
endin\`
|
||||
|
||||
"<0 2 [4 6](3,4,2) 3\*2>"
|
||||
.off(1/4, add(2))
|
||||
.off(1/2, add(6))
|
||||
.scale('D minor')
|
||||
.note()
|
||||
//.pianoroll()
|
||||
.csound('CoolSynth')`}
|
||||
hideHeader
|
||||
/>
|
||||
@@ -0,0 +1 @@
|
||||
# Strudel Docs
|
||||
@@ -0,0 +1,4 @@
|
||||
# Thanks
|
||||
|
||||
- ICLC organizers
|
||||
- Tidal Community
|
||||
@@ -0,0 +1,7 @@
|
||||
import { SlideRepl } from '../SlideRepl.jsx';
|
||||
import Highlight from '../Highlight.jsx';
|
||||
import EventsDemo from '../EventsDemo.jsx';
|
||||
|
||||
# Webaudio Output: Values -> Sound
|
||||
|
||||
<EventsDemo />
|
||||
@@ -0,0 +1,15 @@
|
||||
import { SlideRepl } from '../SlideRepl.jsx';
|
||||
|
||||
# Pattern Example
|
||||
|
||||
<SlideRepl
|
||||
tune={`"<0 2 [4 6](3,4,1) 3>"
|
||||
.off(1/4, add(2))
|
||||
.off(1/2, add(6))
|
||||
.scale('D minor')
|
||||
.legato(.25)
|
||||
.note().s("sawtooth square")
|
||||
.delay(.8).delaytime(.125)`}
|
||||
hideHeader
|
||||
punchcard
|
||||
/>
|
||||
@@ -0,0 +1,10 @@
|
||||
# Future Outlook
|
||||
|
||||
- (slow) community growth
|
||||
- block based evaluation
|
||||
- live collaboration
|
||||
- more audio backends
|
||||
- interface experiments, e.g.:
|
||||
- alternative syntax, visual notations
|
||||
- time scrubbing
|
||||
- ui controls
|
||||
@@ -0,0 +1,9 @@
|
||||
# What's good
|
||||
|
||||
- Zero-install, multi-platform
|
||||
- works (surprisingly) well on mobile devices
|
||||
- visual feedback good for teaching + learning
|
||||
- loads of potential contributors
|
||||
- instant pattern sharing
|
||||
- two-way flow of features between strudel and tidal
|
||||
- full mini-notation in hydra and gibber
|
||||
@@ -0,0 +1,3 @@
|
||||
# The journey
|
||||
|
||||

|
||||
@@ -0,0 +1,3 @@
|
||||
import SyntaxComparison from '../SyntaxComparison.jsx';
|
||||
|
||||
<SyntaxComparison />
|
||||
@@ -0,0 +1,5 @@
|
||||
import { SlideRepl } from '../SlideRepl.jsx';
|
||||
import Highlight from '../Highlight.jsx';
|
||||
import MiniComparison from '../MiniComparison.jsx';
|
||||
|
||||
<MiniComparison />
|
||||
@@ -0,0 +1,29 @@
|
||||
import Highlight from '../Highlight';
|
||||
import Stepper from '../Stepper';
|
||||
|
||||
# User Code: Mini Notation
|
||||
|
||||
<img src="./img/pegflow.png" />
|
||||
|
||||
<Stepper
|
||||
steps={[
|
||||
<ul className="list-decimal pl-8">
|
||||
<li>Parse Mini Notation to get AST</li>
|
||||
<li>walk AST and construct function calls</li>
|
||||
</ul>,
|
||||
<div className="space-y-2 py-2">
|
||||
<Highlight code={`mini('bd [hh sd]')`} />
|
||||
<span>⬇️ resulting calls</span>
|
||||
<Highlight
|
||||
code={`seq(
|
||||
reify('bd').withLocation([1,1,1], [1,4,4]),
|
||||
seq(
|
||||
reify('hh').withLocation([1,5,5], [1,8,8]),
|
||||
reify('sd').withLocation([1,8,8], [1,10,10]),
|
||||
)
|
||||
)`}
|
||||
/>
|
||||
<span>➡️ location can be used for highlighting</span>
|
||||
</div>,
|
||||
]}
|
||||
/>
|
||||
@@ -0,0 +1,7 @@
|
||||
# What can I pattern?
|
||||
|
||||
- Default: Web Audio API
|
||||
- OSC via osc-js, e.g. SuperDirt
|
||||
- Csound via the Csound WebAssembly build
|
||||
- MIDI via WebMIDI
|
||||
- Serial via WebSerial, e.g. for robot dancing
|
||||
@@ -0,0 +1,5 @@
|
||||
import QueryDemo from '../QueryDemo.jsx';
|
||||
|
||||
# Querying: From Patterns to Events
|
||||
|
||||
<QueryDemo />
|
||||
@@ -0,0 +1,12 @@
|
||||
# REPL: Features
|
||||
|
||||
- Visual Feedback
|
||||
- Example shuffler (Hydra-style)
|
||||
- Tutorial + reference
|
||||
- Shareable links
|
||||
- Sound Browser
|
||||
- Offline Support (+ installable PWA)
|
||||
- Outputs: Web Audio, MIDI, OSC, CSound, Serial, ..
|
||||
- Themes
|
||||
|
||||

|
||||
@@ -0,0 +1,7 @@
|
||||
# REPL - live coding editor
|
||||
|
||||
[strudel.tidalcycles.org](https://strudel.tidalcycles.org/)
|
||||
|
||||
{/* <iframe className="w-full h-[600px]" src="https://strudel.tidalcycles.org/#c2FtcGxlcyh7CiAgYmQ6IFsnYmQvQlQwQUFEQS53YXYnLCdiZC9CVDBBQUQwLndhdicsJ2JkL0JUMEEwREEud2F2JywnYmQvQlQwQTBEMy53YXYnLCdiZC9CVDBBMEQwLndhdicsJ2JkL0JUMEEwQTcud2F2J10sCiAgc2Q6IFsnc2Qvcnl0bS0wMS1jbGFzc2ljLndhdicsJ3NkL3J5dG0tMDAtaGFyZC53YXYnXSwKICBoaDogWydoaDI3LzAwMF9oaDI3Y2xvc2VkaGgud2F2JywnaGgvMDAwX2hoM2Nsb3NlZGhoLndhdiddLAp9LCAnZ2l0aHViOnRpZGFsY3ljbGVzL0RpcnQtU2FtcGxlcy9tYXN0ZXIvJyk7CnN0YWNrKAogIHMoImJkLFt%2BIDxzZCEzIHNkKDMsNCwyKT5dLGhoKjQiKSAvLyBkcnVtcwogIC5zcGVlZChwZXJsaW4ucmFuZ2UoLjcsMSkpIC8vIHJhbmRvbSBzYW1wbGUgc3BlZWQgdmFyaWF0aW9uCiAgLy8uaHVzaCgpCiAgLCI8YTEgYjEqMiBhMSgzLDgpIGUyPiIgLy8gYmFzc2xpbmUKICAub2ZmKDEvOCx4PT54LmFkZCgxMikuZGVncmFkZUJ5KC41KSkgLy8gcmFuZG9tIG9jdGF2ZSBqdW1wcwogIC5hZGQocGVybGluLnJhbmdlKDAsLjUpKSAvLyByYW5kb20gcGl0Y2ggdmFyaWF0aW9uCiAgLnN1cGVyaW1wb3NlKGFkZCguMDUpKSAvLyBhZGQgc2Vjb25kLCBzbGlnaHRseSBkZXR1bmVkIHZvaWNlCiAgLm4oKSAvLyB3cmFwIGluICJuIgogIC5kZWNheSguMTUpLnN1c3RhaW4oMCkgLy8gbWFrZSBlYWNoIG5vdGUgb2YgZXF1YWwgbGVuZ3RoCiAgLnMoJ3Nhd3Rvb3RoJykgLy8gd2F2ZWZvcm0KICAuZ2FpbiguNCkgLy8gdHVybiBkb3duCiAgLmN1dG9mZihzaW5lLnNsb3coNykucmFuZ2UoMzAwLDUwMDApKSAvLyBhdXRvbWF0ZSBjdXRvZmYKICAvLy5odXNoKCkKICAsIjxBbTchMyA8RW03IEU3YjEzIEVtNyBFYm03YjU%2BPiIudm9pY2luZ3MoJ2xlZnRoYW5kJykgLy8gY2hvcmRzCiAgLnN1cGVyaW1wb3NlKHg9PnguYWRkKC4wNCkpIC8vIGFkZCBzZWNvbmQsIHNsaWdodGx5IGRldHVuZWQgdm9pY2UKICAuYWRkKHBlcmxpbi5yYW5nZSgwLC41KSkgLy8gcmFuZG9tIHBpdGNoIHZhcmlhdGlvbgogIC5uKCkgLy8gd3JhcCBpbiAibiIKICAucygnc2F3dG9vdGgnKSAvLyB3YXZlZm9ybQogIC5nYWluKC4xNikgLy8gdHVybiBkb3duCiAgLmN1dG9mZig1MDApIC8vIGZpeGVkIGN1dG9mZgogIC5hdHRhY2soMSkgLy8gc2xvd2x5IGZhZGUgaW4KICAvLy5odXNoKCkKICAsImE0IGM1IDxlNiBhNj4iLnN0cnVjdCgieCg1LDgpIikKICAuc3VwZXJpbXBvc2UoeD0%2BeC5hZGQoLjA0KSkgLy8gYWRkIHNlY29uZCwgc2xpZ2h0bHkgZGV0dW5lZCB2b2ljZQogIC5hZGQocGVybGluLnJhbmdlKDAsLjUpKSAvLyByYW5kb20gcGl0Y2ggdmFyaWF0aW9uCiAgLm4oKSAvLyB3cmFwIGluICJuIgogIC5kZWNheSguMSkuc3VzdGFpbigwKSAvLyBtYWtlIG5vdGVzIHNob3J0CiAgLnMoJ3RyaWFuZ2xlJykgLy8gd2F2ZWZvcm0KICAuZGVncmFkZUJ5KHBlcmxpbi5yYW5nZSgwLC41KSkgLy8gcmFuZG9tbHkgY29udHJvbGxlZCByYW5kb20gcmVtb3ZhbCA6KQogIC5lY2hvV2l0aCg0LC4xMjUsKHgsbik9PnguZ2FpbiguMTUqMS8obisxKSkpIC8vIGVjaG8gbm90ZXMKICAvLy5odXNoKCkKKQogIC5zbG93KDEuNCk%3D" /> */}
|
||||
|
||||

|
||||
@@ -0,0 +1,5 @@
|
||||
# REPL: System Overview
|
||||
|
||||
<center>
|
||||
<img src="./img/strudelflow.png" className="w-[900px]" />
|
||||
</center>
|
||||
@@ -0,0 +1,3 @@
|
||||
# Strudel Docs
|
||||
|
||||

|
||||
@@ -0,0 +1,5 @@
|
||||
# Pattern Swatches
|
||||
|
||||
fork strudel - publish your own patterns with a fixed version
|
||||
|
||||

|
||||
@@ -0,0 +1,5 @@
|
||||
import TranspilationDemo from '../TranspilationDemo';
|
||||
|
||||
# User Code: Transpilation
|
||||
|
||||
<TranspilationDemo />
|
||||
@@ -0,0 +1,14 @@
|
||||
import Highlight from '../Highlight.jsx';
|
||||
|
||||
# Ways to use Strudel
|
||||
|
||||
- "Strudel REPL" at [strudel.tidalcycles.org](https://strudel.tidalcycles.org)
|
||||
- strudel on [flok.cc](https://flok.cc/) for collaboration
|
||||
- `@strudel.cycles/*` npm packages for your own projects
|
||||
- Embeddable [Web Component](https://github.com/tidalcycles/strudel/tree/main/packages/embed#strudelcyclesembed)
|
||||
- Browser Plugin for [Mastodon](https://github.com/mortuosplango/topfenstrudel) + Discourse Plugin:
|
||||
|
||||
<div className="flex">
|
||||
<img src="./img/topfenstrudel.png" />
|
||||
<img src="./img/discourse.png" />
|
||||
</div>
|
||||
@@ -0,0 +1,20 @@
|
||||
import { SlideRepl } from '../SlideRepl.jsx';
|
||||
|
||||
# REPL: Visual Feedback
|
||||
|
||||
Highlighting + Piano Roll
|
||||
|
||||
<SlideRepl
|
||||
hideHeader
|
||||
punchcard
|
||||
canvasHeight={300}
|
||||
fontSize={24}
|
||||
tune={`// Steve Reich - Piano Phase (1967)
|
||||
note("E4 F#4 B4 C#5 D5 F#4 E4 C#5 B4 F#4 D5 C#5")
|
||||
.layer(
|
||||
x=>x.color('#00ff0050').pan(0).fast(1), // left speaker
|
||||
x=>x.color('#ff00ff50').pan(1).fast(1.01) // right speaker
|
||||
)
|
||||
.slow(2).room(.5)
|
||||
`}
|
||||
/>
|
||||
@@ -0,0 +1,28 @@
|
||||
import { SlideRepl } from '../SlideRepl.jsx';
|
||||
|
||||
# What is Strudel
|
||||
|
||||
- TidalCycles faithfully ported to JavaScript
|
||||
- zero-install live coding environment for the browser
|
||||
- free & open source, modular, hackable, sharable, embeddable:
|
||||
|
||||
<SlideRepl
|
||||
hideHeader
|
||||
fontSize={24}
|
||||
tune={`// froos - freakuency - 2023/03/29
|
||||
stack(
|
||||
stack(
|
||||
s("bd, ~ <rim cp>,~ hh*2").off(1/8, x=>x.speed(2).gain(.5)).fast(2),
|
||||
s("oh*6").end(.01).speed(.5).room(.5).fast("1 2")
|
||||
).bank('RolandTR909'),
|
||||
//
|
||||
note("[c a f e](<3 5>,8,<0 1>)".add("0,.1").sub(24)).s('sawtooth').lpf(500),
|
||||
//
|
||||
"[~ <Cm7 Fm7 Bb7 Db7>]*2".voicings('lefthand').note().legato(.2)
|
||||
.echoWith(6, .1, (p,n)=>p.add(note(n*.6)))
|
||||
.lpf(sine.range(300,1000).slow(8)).lpq(6)
|
||||
.add(note(perlin.range(0,.8))).s('gm_epiano2')
|
||||
.mask("<0 1>")
|
||||
).restart("<1@3 1*[4 [8 16]]>")
|
||||
.slow(2)`}
|
||||
/>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { useEffect } from 'react';
|
||||
|
||||
function useEvent(name, onTrigger, useCapture = false) {
|
||||
useEffect(() => {
|
||||
document.addEventListener(name, onTrigger, useCapture);
|
||||
return () => {
|
||||
document.removeEventListener(name, onTrigger, useCapture);
|
||||
};
|
||||
}, [onTrigger]);
|
||||
}
|
||||
|
||||
export default useEvent;
|
||||
@@ -0,0 +1,26 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: [
|
||||
'./index.html',
|
||||
'./src/**/*.{js,ts,jsx,tsx,mdx}',
|
||||
'../../packages/react/src/**/*.{html,js,jsx,md,mdx,ts,tsx}',
|
||||
],
|
||||
theme: {
|
||||
extend: {
|
||||
colors: {
|
||||
// codemirror-theme settings
|
||||
background: 'var(--background)',
|
||||
lineBackground: 'var(--lineBackground)',
|
||||
foreground: 'var(--foreground)',
|
||||
caret: 'var(--caret)',
|
||||
selection: 'var(--selection)',
|
||||
selectionMatch: 'var(--selectionMatch)',
|
||||
gutterBackground: 'var(--gutterBackground)',
|
||||
gutterForeground: 'var(--gutterForeground)',
|
||||
gutterBorder: 'var(--gutterBorder)',
|
||||
lineHighlight: 'var(--lineHighlight)',
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [require('@tailwindcss/typography')],
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import mdx from '@mdx-js/rollup';
|
||||
import gfm from 'remark-gfm';
|
||||
import topLevelAwait from 'vite-plugin-top-level-await';
|
||||
|
||||
const options = {
|
||||
// See https://mdxjs.com/advanced/plugins
|
||||
remarkPlugins: [gfm],
|
||||
rehypePlugins: [],
|
||||
};
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
react(),
|
||||
mdx(options),
|
||||
topLevelAwait({
|
||||
// The export name of top-level await promise for each chunk module
|
||||
promiseExportName: '__tla',
|
||||
// The function to generate import names of top-level await promise in each chunk module
|
||||
promiseImportName: (i) => `__tla_${i}`,
|
||||
}),
|
||||
],
|
||||
build: {
|
||||
target: 'esnext', //browsers can handle the latest ES features
|
||||
},
|
||||
});
|
||||
@@ -16,6 +16,7 @@ export function repl({
|
||||
onToggle,
|
||||
editPattern,
|
||||
}) {
|
||||
const id = s4();
|
||||
const scheduler = new Cyclist({
|
||||
interval,
|
||||
onTrigger: async (hap, deadline, duration, cps) => {
|
||||
@@ -45,7 +46,7 @@ export function repl({
|
||||
let { pattern } = await _evaluate(code, transpiler);
|
||||
|
||||
logger(`[eval] code updated`);
|
||||
pattern = editPattern?.(pattern) || pattern;
|
||||
pattern = editPattern?.(pattern, id) || pattern;
|
||||
scheduler.setPattern(pattern, autostart);
|
||||
afterEval?.({ code, pattern });
|
||||
return pattern;
|
||||
@@ -63,5 +64,11 @@ export function repl({
|
||||
setCps,
|
||||
setcps: setCps,
|
||||
});
|
||||
return { scheduler, evaluate, start, stop, pause, setCps };
|
||||
return { scheduler, evaluate, start, stop, pause, setCps, id };
|
||||
}
|
||||
|
||||
function s4() {
|
||||
return Math.floor((1 + Math.random()) * 0x10000)
|
||||
.toString(16)
|
||||
.substring(1);
|
||||
}
|
||||
|
||||
@@ -58,15 +58,19 @@ const highlightField = StateField.define({
|
||||
haps
|
||||
.map((hap) =>
|
||||
(hap.context.locations || []).map(({ start, end }) => {
|
||||
// const color = hap.context.color || e.value.color || '#FFCA28';
|
||||
const color = hap.context.color || e.value.color;
|
||||
let from = tr.newDoc.line(start.line).from + start.column;
|
||||
let to = tr.newDoc.line(end.line).from + end.column;
|
||||
const l = tr.newDoc.length;
|
||||
if (from > l || to > l) {
|
||||
return; // dont mark outside of range, as it will throw an error
|
||||
}
|
||||
//const mark = Decoration.mark({ attributes: { style: `outline: 2px solid ${color};` } });
|
||||
const mark = Decoration.mark({ attributes: { class: `outline outline-2 outline-foreground` } });
|
||||
let mark;
|
||||
if (color) {
|
||||
mark = Decoration.mark({ attributes: { style: `outline: 4px solid ${color};` } });
|
||||
} else {
|
||||
mark = Decoration.mark({ attributes: { class: `outline outline-2 outline-foreground` } });
|
||||
}
|
||||
return mark.range(from, to);
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -21,6 +21,8 @@ export function MiniRepl({
|
||||
drawTime,
|
||||
punchcard,
|
||||
canvasHeight = 200,
|
||||
fontSize = 18,
|
||||
hideHeader = false,
|
||||
theme,
|
||||
}) {
|
||||
drawTime = drawTime || (punchcard ? [0, 4] : undefined);
|
||||
@@ -47,7 +49,10 @@ export function MiniRepl({
|
||||
} = useStrudel({
|
||||
initialCode: tune,
|
||||
defaultOutput: webaudioOutput,
|
||||
editPattern: (pat) => (punchcard ? pat.punchcard() : pat),
|
||||
editPattern: (pat, id) => {
|
||||
pat = pat.withContext((ctx) => ({ ...ctx, id }));
|
||||
return punchcard ? pat.punchcard() : pat;
|
||||
},
|
||||
getTime,
|
||||
evalOnMount,
|
||||
drawContext,
|
||||
@@ -101,7 +106,7 @@ export function MiniRepl({
|
||||
// const logId = data?.pattern?.meta?.id;
|
||||
if (logId === replId) {
|
||||
setLog((l) => {
|
||||
return l.concat([e.detail]).slice(-10);
|
||||
return l.concat([e.detail]).slice(-8);
|
||||
});
|
||||
}
|
||||
}, []),
|
||||
@@ -109,31 +114,35 @@ export function MiniRepl({
|
||||
|
||||
return (
|
||||
<div className="overflow-hidden rounded-t-md bg-background border border-lineHighlight" ref={ref}>
|
||||
<div className="flex justify-between bg-lineHighlight">
|
||||
<div className="flex">
|
||||
<button
|
||||
className={cx(
|
||||
'cursor-pointer w-16 flex items-center justify-center p-1 border-r border-lineHighlight text-foreground bg-lineHighlight hover:bg-background',
|
||||
started ? 'animate-pulse' : '',
|
||||
)}
|
||||
onClick={() => togglePlay()}
|
||||
>
|
||||
<Icon type={started ? 'stop' : 'play'} />
|
||||
</button>
|
||||
<button
|
||||
className={cx(
|
||||
'w-16 flex items-center justify-center p-1 text-foreground border-lineHighlight bg-lineHighlight',
|
||||
isDirty ? 'text-foreground hover:bg-background cursor-pointer' : 'opacity-50 cursor-not-allowed',
|
||||
)}
|
||||
onClick={() => activateCode()}
|
||||
>
|
||||
<Icon type="refresh" />
|
||||
</button>
|
||||
{!hideHeader && (
|
||||
<div className="flex justify-between bg-lineHighlight">
|
||||
<div className="flex">
|
||||
<button
|
||||
className={cx(
|
||||
'cursor-pointer w-16 flex items-center justify-center p-1 border-r border-lineHighlight text-foreground bg-lineHighlight hover:bg-background',
|
||||
started ? 'animate-pulse' : '',
|
||||
)}
|
||||
onClick={() => togglePlay()}
|
||||
>
|
||||
<Icon type={started ? 'stop' : 'play'} />
|
||||
</button>
|
||||
<button
|
||||
className={cx(
|
||||
'w-16 flex items-center justify-center p-1 text-foreground border-lineHighlight bg-lineHighlight',
|
||||
isDirty ? 'text-foreground hover:bg-background cursor-pointer' : 'opacity-50 cursor-not-allowed',
|
||||
)}
|
||||
onClick={() => activateCode()}
|
||||
>
|
||||
<Icon type="refresh" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{error && <div className="text-right p-1 text-sm text-red-200">{error.message}</div>}
|
||||
</div>
|
||||
)}
|
||||
<div className="overflow-auto relative">
|
||||
{show && <CodeMirror6 value={code} onChange={setCode} onViewChanged={setView} theme={theme} />}
|
||||
{show && (
|
||||
<CodeMirror6 value={code} onChange={setCode} onViewChanged={setView} theme={theme} fontSize={fontSize} />
|
||||
)}
|
||||
{error && <div className="text-right p-1 text-md text-red-200">{error.message}</div>}
|
||||
</div>
|
||||
{drawTime && (
|
||||
<canvas
|
||||
|
||||
@@ -19,8 +19,6 @@ function useStrudel({
|
||||
drawContext,
|
||||
drawTime = [-2, 2],
|
||||
}) {
|
||||
const id = useMemo(() => s4(), []);
|
||||
canvasId = canvasId || `canvas-${id}`;
|
||||
// scheduler
|
||||
const [schedulerError, setSchedulerError] = useState();
|
||||
const [evalError, setEvalError] = useState();
|
||||
@@ -32,7 +30,7 @@ function useStrudel({
|
||||
const shouldPaint = useCallback((pat) => !!(pat?.context?.onPaint && drawContext), [drawContext]);
|
||||
|
||||
// TODO: make sure this hook reruns when scheduler.started changes
|
||||
const { scheduler, evaluate, start, stop, pause, setCps } = useMemo(
|
||||
const { scheduler, evaluate, start, stop, pause, setCps, id } = useMemo(
|
||||
() =>
|
||||
repl({
|
||||
interval,
|
||||
@@ -65,6 +63,8 @@ function useStrudel({
|
||||
}),
|
||||
[defaultOutput, interval, getTime],
|
||||
);
|
||||
|
||||
canvasId = canvasId || `canvas-${id}`;
|
||||
const broadcast = usePostMessage(({ data: { from, type } }) => {
|
||||
if (type === 'start' && from !== id) {
|
||||
// console.log('message', from, type);
|
||||
@@ -158,9 +158,3 @@ function useStrudel({
|
||||
}
|
||||
|
||||
export default useStrudel;
|
||||
|
||||
function s4() {
|
||||
return Math.floor((1 + Math.random()) * 0x10000)
|
||||
.toString(16)
|
||||
.substring(1);
|
||||
}
|
||||
|
||||
@@ -3,13 +3,13 @@ import { getAudioContext, registerSound, getEnvelope } from '@strudel.cycles/web
|
||||
import gm from './gm.mjs';
|
||||
|
||||
let loadCache = {};
|
||||
async function loadFont(name) {
|
||||
async function loadFont(name, base) {
|
||||
if (loadCache[name]) {
|
||||
return loadCache[name];
|
||||
}
|
||||
const load = async () => {
|
||||
// TODO: make soundfont source configurable
|
||||
const url = `https://felixroos.github.io/webaudiofontdata/sound/${name}.js`;
|
||||
const url = `${base}${name}.js`;
|
||||
const preset = await fetch(url).then((res) => res.text());
|
||||
let [_, data] = preset.split('={');
|
||||
return eval('{' + data);
|
||||
@@ -18,7 +18,7 @@ async function loadFont(name) {
|
||||
return loadCache[name];
|
||||
}
|
||||
|
||||
export async function getFontBufferSource(name, value, ac) {
|
||||
export async function getFontBufferSource(name, value, ac, base) {
|
||||
let { note = 'c3', freq } = value;
|
||||
let midi;
|
||||
if (freq) {
|
||||
@@ -31,7 +31,7 @@ export async function getFontBufferSource(name, value, ac) {
|
||||
throw new Error(`unexpected "note" type "${typeof note}"`);
|
||||
}
|
||||
|
||||
const { buffer, zone } = await getFontPitch(name, midi, ac);
|
||||
const { buffer, zone } = await getFontPitch(name, midi, ac, base);
|
||||
const src = ac.createBufferSource();
|
||||
src.buffer = buffer;
|
||||
const baseDetune = zone.originalPitch - 100.0 * zone.coarseTune - zone.fineTune;
|
||||
@@ -55,14 +55,14 @@ export async function getFontBufferSource(name, value, ac) {
|
||||
}
|
||||
|
||||
let bufferCache = {};
|
||||
export async function getFontPitch(name, pitch, ac) {
|
||||
export async function getFontPitch(name, pitch, ac, base) {
|
||||
const key = `${name}:::${pitch}`;
|
||||
if (bufferCache[key]) {
|
||||
return bufferCache[key];
|
||||
}
|
||||
// console.log('load buffer', key);
|
||||
const load = async () => {
|
||||
const preset = await loadFont(name);
|
||||
const preset = await loadFont(name, base);
|
||||
if (!preset) {
|
||||
throw new Error(`Could not load soundfont ${name}`);
|
||||
}
|
||||
@@ -125,7 +125,7 @@ async function getBuffer(zone, audioContext) {
|
||||
}
|
||||
}
|
||||
|
||||
export function registerSoundfonts() {
|
||||
export function registerSoundfonts(base = `https://felixroos.github.io/webaudiofontdata/sound/`) {
|
||||
Object.entries(gm).forEach(([name, fonts]) => {
|
||||
registerSound(
|
||||
name,
|
||||
@@ -134,7 +134,7 @@ export function registerSoundfonts() {
|
||||
const { attack = 0.001, decay = 0.001, sustain = 1, release = 0.001 } = value;
|
||||
const font = fonts[n % fonts.length];
|
||||
const ctx = getAudioContext();
|
||||
const bufferSource = await getFontBufferSource(font, value, ctx);
|
||||
const bufferSource = await getFontBufferSource(font, value, ctx, base);
|
||||
bufferSource.start(time);
|
||||
const { node: envelope, stop: releaseEnvelope } = getEnvelope(attack, decay, sustain, release, 0.3, time);
|
||||
bufferSource.connect(envelope);
|
||||
|
||||
@@ -4,7 +4,7 @@ import { walk } from 'estree-walker';
|
||||
import { isNoteWithOctave } from '@strudel.cycles/core';
|
||||
|
||||
export function transpiler(input, options = {}) {
|
||||
const { wrapAsync = false, addReturn = true, simpleLocs = false } = options;
|
||||
const { wrapAsync = false, addReturn = true, simpleLocs = false, codegenOptions = {} } = options;
|
||||
|
||||
let ast = parse(input, {
|
||||
ecmaVersion: 2022,
|
||||
@@ -47,7 +47,7 @@ export function transpiler(input, options = {}) {
|
||||
argument: expression,
|
||||
};
|
||||
}
|
||||
const output = escodegen.generate(ast);
|
||||
const output = escodegen.generate(ast, codegenOptions);
|
||||
if (wrapAsync) {
|
||||
return `(async ()=>{${output}})()`;
|
||||
}
|
||||
|
||||
@@ -2,5 +2,6 @@ packages:
|
||||
# all packages in direct subdirs of packages/
|
||||
- "packages/*"
|
||||
- "website/"
|
||||
- "iclc2023/slides/"
|
||||
- "packages/core/examples/vite-vanilla-repl"
|
||||
- "packages/react/examples/nano-repl"
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Pattern, noteToMidi, valueToMidi } from '@strudel.cycles/core';
|
||||
import { registerSoundfonts } from '@strudel.cycles/soundfonts';
|
||||
import { registerSynthSounds, samples } from '@strudel.cycles/webaudio';
|
||||
import './piano.mjs';
|
||||
@@ -22,18 +21,3 @@ export async function prebake() {
|
||||
// samples('github:tidalcycles/Dirt-Samples/master'),
|
||||
]);
|
||||
}
|
||||
|
||||
const maxPan = noteToMidi('C8');
|
||||
const panwidth = (pan, width) => pan * width + (1 - width) / 2;
|
||||
|
||||
Pattern.prototype.piano = function () {
|
||||
return this.clip(1)
|
||||
.s('piano')
|
||||
.release(0.1)
|
||||
.fmap((value) => {
|
||||
const midi = valueToMidi(value);
|
||||
// pan by pitch
|
||||
const pan = panwidth(Math.min(Math.round(midi) / maxPan, 1), 0.5);
|
||||
return { ...value, pan: (value.pan || 1) * pan };
|
||||
});
|
||||
};
|
||||
|
||||