Compare commits

...

4 Commits

Author SHA1 Message Date
daslyfe d1dd895d94 Merge branch 'main' into strudel_json 2025-06-27 02:32:36 +02:00
Jade (Rose) Rowland f8124fca80 format again 2025-06-26 20:26:59 -04:00
Jade (Rose) Rowland 95fee04bea format 2025-06-26 20:02:18 -04:00
Jade (Rose) Rowland f60894f2ce working 2025-06-26 19:57:23 -04:00
3 changed files with 55 additions and 2 deletions
+1
View File
@@ -4,6 +4,7 @@
"private": true,
"description": "Port of tidalcycles to javascript",
"scripts": {
"strudeljson": "node ./website/src/repl/create_strudel_json.mjs",
"setup": "pnpm i",
"pretest": "npm run jsdoc-json",
"prebuild": "npm run jsdoc-json",
+52
View File
@@ -0,0 +1,52 @@
import { createInterface } from 'node:readline';
import * as fs from 'node:fs';
const validFileTypes = new Set(['.wav', '.mp3', '.aac', '.m4a']);
/** For automatically creating the strudel JSON that for samples hosted in a remote repo */
async function writeStrudelJson(subpath, hosturl) {
const children = await fs.promises.readdir(subpath, { recursive: true });
const name = subpath.split('/').slice(-1)[0];
const tree = { name, children };
let samples = {
_base: hosturl,
};
const files = tree.children
.filter((path) => {
const extension = path.match(/\.[0-9a-z]+$/i)?.[0];
return validFileTypes.has(extension);
})
.sort((a, b) => a.localeCompare(b));
files.forEach((path) => {
const groupName = path.match(/([^/]+)\/[^/]+$/)[1];
samples[groupName] = samples[groupName] ?? [];
samples[groupName].push(path);
});
const json = JSON.stringify(samples, null, 2);
const filepath = subpath + '/strudel.json';
await fs.promises.writeFile(filepath, json);
console.log(`wrote strudel.json with ${files.length} samples to ${subpath}`);
}
const rl = createInterface({
input: process.stdin,
output: process.stdout,
});
rl.question(`enter sample folder path: `, async (path) => {
rl.question(`enter hosted URL: `, async (hosturl) => {
const githubregex = /github\.com\/([^/]+)\/([^/]+)/;
const githubparams = hosturl.match(githubregex);
if (githubparams) {
const username = githubparams[1];
const repo = githubparams[2];
hosturl = `https://raw.githubusercontent.com/${username}/${repo}/main/`;
console.log('reformatting github URL to: ', hosturl);
}
await writeStrudelJson(path, hosturl);
rl.close();
});
});
+2 -2
View File
@@ -33,7 +33,7 @@ async function loadStrudelJson(subpath) {
});
}
async function writeStrudelJson(subpath) {
export async function writeStrudelJson(subpath) {
const children = await readDir(subpath, { dir, recursive: true });
const name = subpath.split('/').slice(-1)[0];
const tree = { name, children };
@@ -41,7 +41,7 @@ async function writeStrudelJson(subpath) {
let samples = {};
let count = 0;
walkFileTree(tree, (entry, parent) => {
if (['wav', 'mp3'].includes(entry.name.split('.').slice(-1)[0])) {
if (['wav', 'mp3', 'aac', 'm4a'].includes(entry.name.split('.').slice(-1)[0])) {
samples[parent.name] = samples[parent.name] || [];
count += 1;
samples[parent.name].push(entry.subpath.slice(1).concat([entry.name]).join('/'));