From af90baea33a103f3f3812220894533000d502109 Mon Sep 17 00:00:00 2001 From: W-A-James Date: Sun, 26 Oct 2025 14:28:36 -0500 Subject: [PATCH 1/5] Fix trampling of port env variable --- packages/sampler/sample-server.mjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/sampler/sample-server.mjs b/packages/sampler/sample-server.mjs index 31b83f5a..891ae61f 100644 --- a/packages/sampler/sample-server.mjs +++ b/packages/sampler/sample-server.mjs @@ -9,6 +9,8 @@ import readline from 'readline'; import os from 'os'; const LOG = !!process.env.LOG || false; +// eslint-disable-next-line +const PORT = process.env.PORT || 5432; const VALID_AUDIO_EXTENSIONS = ['wav', 'mp3', 'ogg']; const isAudioFile = (f) => { @@ -54,7 +56,7 @@ async function getBanks(directory, flat = false) { banks[bank].push(subDir); return subDir; }); - banks._base = `http://localhost:5432`; + banks._base = `http://localhost:${PORT}`; return { banks, files }; } @@ -134,8 +136,6 @@ const server = http.createServer(async (req, res) => { readStream.pipe(res); }); -// eslint-disable-next-line -const PORT = process.env.PORT || 5432; const IP_ADDRESS = '0.0.0.0'; let IP; const networkInterfaces = os.networkInterfaces(); From 9fdba6374ce07dc3d210e992ff024de5ecce64bb Mon Sep 17 00:00:00 2001 From: W-A-James Date: Fri, 31 Oct 2025 15:45:27 -0500 Subject: [PATCH 2/5] remove extraneous eslint ignore directive --- packages/sampler/sample-server.mjs | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/sampler/sample-server.mjs b/packages/sampler/sample-server.mjs index 891ae61f..dfba1394 100644 --- a/packages/sampler/sample-server.mjs +++ b/packages/sampler/sample-server.mjs @@ -9,7 +9,6 @@ import readline from 'readline'; import os from 'os'; const LOG = !!process.env.LOG || false; -// eslint-disable-next-line const PORT = process.env.PORT || 5432; const VALID_AUDIO_EXTENSIONS = ['wav', 'mp3', 'ogg']; From d70b758065a0a5f8d500b3a09527e80c6397de6b Mon Sep 17 00:00:00 2001 From: Aria Date: Thu, 20 Nov 2025 12:46:29 -0600 Subject: [PATCH 3/5] Remove base url from sample server and properly handle url schemes --- packages/sampler/sample-server.mjs | 1 - packages/superdough/sampler.mjs | 4 ++-- packages/superdough/util.mjs | 10 ++++++++++ packages/superdough/wavetable.mjs | 7 ++++--- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/sampler/sample-server.mjs b/packages/sampler/sample-server.mjs index dfba1394..1d5a8e7a 100644 --- a/packages/sampler/sample-server.mjs +++ b/packages/sampler/sample-server.mjs @@ -55,7 +55,6 @@ async function getBanks(directory, flat = false) { banks[bank].push(subDir); return subDir; }); - banks._base = `http://localhost:${PORT}`; return { banks, files }; } diff --git a/packages/superdough/sampler.mjs b/packages/superdough/sampler.mjs index 84bac358..aaa1a8e4 100644 --- a/packages/superdough/sampler.mjs +++ b/packages/superdough/sampler.mjs @@ -1,4 +1,4 @@ -import { getCommonSampleInfo } from './util.mjs'; +import { getBaseURL, getCommonSampleInfo } from './util.mjs'; import { registerSound, registerWaveTable } from './index.mjs'; import { getAudioContext } from './audioContext.mjs'; import { getADSRValues, getParamADSR, getPitchEnvelope, getVibratoOscillator } from './helpers.mjs'; @@ -211,7 +211,7 @@ export async function fetchSampleMap(url) { // not a browser return; } - const base = url.split('/').slice(0, -1).join('/'); + const base = getBaseURL(url); if (typeof fetch === 'undefined') { // skip fetch when in node / testing return; diff --git a/packages/superdough/util.mjs b/packages/superdough/util.mjs index 44ec79f7..0c066011 100644 --- a/packages/superdough/util.mjs +++ b/packages/superdough/util.mjs @@ -113,4 +113,14 @@ export function getCommonSampleInfo(hapValue, bank) { /** Selects entries from `source` and renames them via `map` */ export const pickAndRename = (source, map) => { return Object.fromEntries(Object.entries(map).map(([newKey, oldKey]) => [newKey, source[oldKey]])); +} + +export const getBaseURL = (url) => { + try { + // For real URLs + return new URL('.', new URL(url)).href.replace(/\/$/, ''); // removes trailing slash + } catch { + // For pseudo URLS + return url.split('/').slice(0, -1).join('/'); + } }; diff --git a/packages/superdough/wavetable.mjs b/packages/superdough/wavetable.mjs index 01d4eb83..83b7b497 100644 --- a/packages/superdough/wavetable.mjs +++ b/packages/superdough/wavetable.mjs @@ -1,5 +1,5 @@ import { getAudioContext, registerSound } from './index.mjs'; -import { getCommonSampleInfo } from './util.mjs'; +import { getBaseURL, getCommonSampleInfo } from './util.mjs'; import { applyFM, applyParameterModulators, @@ -134,7 +134,7 @@ function githubPath(base, subpath = '') { return `https://raw.githubusercontent.com/${path}/${subpath}`; } -const _processTables = (json, baseUrl, frameLen, options = {}) => { +const _processTables = (json, baseUrl, frameLen) => { baseUrl = json._base || baseUrl; return Object.entries(json).forEach(([key, tables]) => { if (key === '_base') return false; @@ -190,6 +190,7 @@ export const tables = async (url, frameLen, json, options = {}) => { if (url.startsWith('local:')) { url = `http://localhost:5432`; } + const base = getBaseURL(url); if (typeof fetch !== 'function') { // not a browser return; @@ -200,7 +201,7 @@ export const tables = async (url, frameLen, json, options = {}) => { } return fetch(url) .then((res) => res.json()) - .then((json) => _processTables(json, url, frameLen, options)) + .then((json) => _processTables(json, base, frameLen, options)) .catch((error) => { console.error(error); throw new Error(`error loading "${url}"`); From a5c7fcc136f5702d83d5c613fafea9b14476d7d4 Mon Sep 17 00:00:00 2001 From: Aria Date: Tue, 25 Nov 2025 11:26:59 -0600 Subject: [PATCH 4/5] Add back options code (will resolve in another PR) --- packages/superdough/wavetable.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/superdough/wavetable.mjs b/packages/superdough/wavetable.mjs index 83b7b497..3659edcd 100644 --- a/packages/superdough/wavetable.mjs +++ b/packages/superdough/wavetable.mjs @@ -134,7 +134,7 @@ function githubPath(base, subpath = '') { return `https://raw.githubusercontent.com/${path}/${subpath}`; } -const _processTables = (json, baseUrl, frameLen) => { +const _processTables = (json, baseUrl, frameLen, options = {}) => { baseUrl = json._base || baseUrl; return Object.entries(json).forEach(([key, tables]) => { if (key === '_base') return false; From a126bc9b86d22674d40eddc98bd5e37bb234e917 Mon Sep 17 00:00:00 2001 From: W-A-James Date: Tue, 25 Nov 2025 22:20:55 -0500 Subject: [PATCH 5/5] Fix lint --- packages/superdough/util.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/superdough/util.mjs b/packages/superdough/util.mjs index 0c066011..48830541 100644 --- a/packages/superdough/util.mjs +++ b/packages/superdough/util.mjs @@ -113,7 +113,7 @@ export function getCommonSampleInfo(hapValue, bank) { /** Selects entries from `source` and renames them via `map` */ export const pickAndRename = (source, map) => { return Object.fromEntries(Object.entries(map).map(([newKey, oldKey]) => [newKey, source[oldKey]])); -} +}; export const getBaseURL = (url) => { try {