mirror of
https://codeberg.org/uzu/strudel
synced 2026-07-17 08:06:50 -04:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5cf9f9fef4 | |||
| e44313f631 |
@@ -10,6 +10,7 @@
|
|||||||
"snapshot": "cd repl && npm run snapshot",
|
"snapshot": "cd repl && npm run snapshot",
|
||||||
"repl": "cd repl && npm run dev",
|
"repl": "cd repl && npm run dev",
|
||||||
"osc": "cd packages/osc && npm run server",
|
"osc": "cd packages/osc && npm run server",
|
||||||
|
"sampler": "cd ./repl/public/samples && node ../../packages/webaudio/sample-server.js",
|
||||||
"build": "rm -rf out && cd repl && npm run build && cd ../tutorial && npm run build",
|
"build": "rm -rf out && cd repl && npm run build && cd ../tutorial && npm run build",
|
||||||
"preview": "npx serve ./out",
|
"preview": "npx serve ./out",
|
||||||
"deploy": "gh-pages -d out",
|
"deploy": "gh-pages -d out",
|
||||||
|
|||||||
@@ -8,3 +8,4 @@ export * from './clockworker.mjs';
|
|||||||
export * from './scheduler.mjs';
|
export * from './scheduler.mjs';
|
||||||
export * from './webaudio.mjs';
|
export * from './webaudio.mjs';
|
||||||
export * from './sampler.mjs';
|
export * from './sampler.mjs';
|
||||||
|
export * from './prebake.mjs';
|
||||||
|
|||||||
Generated
+834
-3636
File diff suppressed because it is too large
Load Diff
@@ -29,5 +29,10 @@
|
|||||||
"homepage": "https://github.com/tidalcycles/strudel#readme",
|
"homepage": "https://github.com/tidalcycles/strudel#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@strudel.cycles/core": "^0.1.2"
|
"@strudel.cycles/core": "^0.1.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"koa": "^2.13.4",
|
||||||
|
"koa-static": "^5.0.0",
|
||||||
|
"@koa/cors": "^3.3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
import { Pattern, toMidi } from '@strudel.cycles/core';
|
||||||
|
import { samples } from '.';
|
||||||
|
|
||||||
|
let baking;
|
||||||
|
|
||||||
|
export function prebake(props) {
|
||||||
|
if (baking) {
|
||||||
|
return baking;
|
||||||
|
}
|
||||||
|
baking = prebaker(props);
|
||||||
|
return baking;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function prebaker(props = {}) {
|
||||||
|
const { baseURL = './samples' } = props; // http://localhost:1234
|
||||||
|
try {
|
||||||
|
samples(
|
||||||
|
{
|
||||||
|
piano: {
|
||||||
|
A0: 'A0v8.mp3',
|
||||||
|
C1: 'C1v8.mp3',
|
||||||
|
Ds1: 'Ds1v8.mp3',
|
||||||
|
Fs1: 'Fs1v8.mp3',
|
||||||
|
A1: 'A1v8.mp3',
|
||||||
|
C2: 'C2v8.mp3',
|
||||||
|
Ds2: 'Ds2v8.mp3',
|
||||||
|
Fs2: 'Fs2v8.mp3',
|
||||||
|
A2: 'A2v8.mp3',
|
||||||
|
C3: 'C3v8.mp3',
|
||||||
|
Ds3: 'Ds3v8.mp3',
|
||||||
|
Fs3: 'Fs3v8.mp3',
|
||||||
|
A3: 'A3v8.mp3',
|
||||||
|
C4: 'C4v8.mp3',
|
||||||
|
Ds4: 'Ds4v8.mp3',
|
||||||
|
Fs4: 'Fs4v8.mp3',
|
||||||
|
A4: 'A4v8.mp3',
|
||||||
|
C5: 'C5v8.mp3',
|
||||||
|
Ds4: 'Ds4v8.mp3',
|
||||||
|
Fs5: 'Fs5v8.mp3',
|
||||||
|
A5: 'A5v8.mp3',
|
||||||
|
C6: 'C6v8.mp3',
|
||||||
|
Ds6: 'Ds6v8.mp3',
|
||||||
|
Fs6: 'Fs6v8.mp3',
|
||||||
|
A6: 'A6v8.mp3',
|
||||||
|
C7: 'C7v8.mp3',
|
||||||
|
Ds7: 'Ds7v8.mp3',
|
||||||
|
Fs7: 'Fs7v8.mp3',
|
||||||
|
A7: 'A7v8.mp3',
|
||||||
|
C8: 'C8v8.mp3',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// https://archive.org/details/SalamanderGrandPianoV3
|
||||||
|
// License: CC-by http://creativecommons.org/licenses/by/3.0/ Author: Alexander Holm
|
||||||
|
baseURL + '/piano/',
|
||||||
|
);
|
||||||
|
|
||||||
|
const maxPan = toMidi('C8');
|
||||||
|
const panwidth = (pan, width) => pan * width + (1 - width) / 2;
|
||||||
|
|
||||||
|
Pattern.prototype.piano = function () {
|
||||||
|
return this.clip(1)
|
||||||
|
.s('piano')
|
||||||
|
.fmap((value) => {
|
||||||
|
// pan by pitch
|
||||||
|
const pan = panwidth(Math.min(toMidi(value.note) / maxPan, 1), 0.5);
|
||||||
|
return { ...value, pan: (value.pan || 1) * pan };
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// ping sample server
|
||||||
|
/* await fetch(samplerURL)
|
||||||
|
.then(() => {
|
||||||
|
console.log(`prebake: Using samples from "${baseURL}"`);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
throw new Error(
|
||||||
|
`sample server not running at "${samplerURL}"... run "npm run sampler" from the strudel project root.`,
|
||||||
|
);
|
||||||
|
}); */
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('prebake error', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// "sampler": "cd ./repl/public/samples && node ../../../packages/webaudio/sample-server.js",
|
||||||
|
// "sampler": "http-server ./repl/public",
|
||||||
|
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import Koa from 'koa'; // CJS: require('koa');
|
||||||
|
import cors from '@koa/cors';
|
||||||
|
import serve from 'koa-static'; // CJS: require('koa-static')
|
||||||
|
const cwd = process.cwd();
|
||||||
|
const yellow = '\x1b[33m%s\x1b[0m';
|
||||||
|
|
||||||
|
// get array of all folders in cwd:
|
||||||
|
const banks = fs.readdirSync(cwd).filter((f) => fs.statSync(path.join(cwd, f)).isDirectory());
|
||||||
|
const app = new Koa();
|
||||||
|
|
||||||
|
app.use(cors());
|
||||||
|
app.use(serve(cwd));
|
||||||
|
app.use((ctx, next) => {
|
||||||
|
return next().then(() => {
|
||||||
|
if (ctx.path === '/') {
|
||||||
|
ctx.body = 'banks: ' + banks.join(', ');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
const port = 1234;
|
||||||
|
app.listen(port);
|
||||||
|
|
||||||
|
console.log(yellow, `strudel sampler running at http://localhost:${port}`);
|
||||||
|
|
||||||
|
// node: get current working directory
|
||||||
|
console.log(yellow, 'cwd: ' + cwd);
|
||||||
|
|
||||||
|
console.log('found banks:');
|
||||||
|
banks.map((c) => console.log(yellow, c));
|
||||||
Reference in New Issue
Block a user