From 3cefbf80bfd87e19c37c3328426d014da9689a42 Mon Sep 17 00:00:00 2001 From: tyow Date: Thu, 19 Feb 2026 13:59:30 -0500 Subject: [PATCH] moved to sampler --- packages/superdough/sampler.mjs | 25 ++++++++++++++++++++++++- packages/superdough/superdough.mjs | 23 ----------------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/packages/superdough/sampler.mjs b/packages/superdough/sampler.mjs index e7aee294f..d45e1050b 100644 --- a/packages/superdough/sampler.mjs +++ b/packages/superdough/sampler.mjs @@ -1,5 +1,5 @@ import { getBaseURL, getCommonSampleInfo } from './util.mjs'; -import { registerSound, registerWaveTable } from './index.mjs'; +import { registerSound, registerWaveTable, soundMap } from './index.mjs'; import { getAudioContext } from './audioContext.mjs'; import { getADSRValues, @@ -30,6 +30,29 @@ function humanFileSize(bytes, si) { return bytes.toFixed(1) + ' ' + units[u]; } +/** + * Returns the duration, in seconds, of the given sample. + * Has optional param `n` (for instance, the `2` in `s("casio:2")`) + * + * Note: `must` be called with await, otherwise you'll get a pending Promise object. + * + * @name getDuration,getDur + * @tag samples + * @param {string} sampleName + * @param {number} (optional) n + * + * @example + * // Set a patterns cycle length to exactly the length of the sample + * samples('github:tidalcycles/dirt-samples') + * let k = await getDuration('sax') + * s("sax").cps(1/k) + */ +export const getDuration = (s, n = 0) => { + return getSampleBufferSource({ s, n }, soundMap.get(s)[s].data.samples).then((x) => x.bufferDuration); +}; + +export const getDur = getDuration; + export function getSampleInfo(hapValue, bank) { const { speed = 1.0 } = hapValue; const { transpose, url, index, midi, label } = getCommonSampleInfo(hapValue, bank); diff --git a/packages/superdough/superdough.mjs b/packages/superdough/superdough.mjs index 5916aebf0..98d1fb67b 100644 --- a/packages/superdough/superdough.mjs +++ b/packages/superdough/superdough.mjs @@ -85,29 +85,6 @@ export function setGainCurve(newGainCurveFunc) { gainCurveFunc = newGainCurveFunc; } -/** - * Returns the duration, in seconds, of the given sample. - * Has optional param `n` (for instance, the `2` in `s("casio:2")`) - * - * Note: `must` be called with await, otherwise you'll get a pending Promise object. - * - * @name getDuration,getDur - * @tag samples - * @param {string} sampleName - * @param {number} (optional) n - * - * @example - * // Set a patterns cycle length to exactly the length of the sample - * samples('github:tidalcycles/dirt-samples') - * let k = await getDuration('sax') - * s("sax").cps(1/k) - */ -export const getDuration = (s, n = 0) => { - return getSampleBufferSource({ s, n }, soundMap.get(s)[s].data.samples).then((x) => x.bufferDuration); -}; - -export const getDur = getDuration; - function aliasBankMap(aliasMap) { // Make all bank keys lower case for case insensitivity for (const key in aliasMap) {