From 6f5d096e6d41bdc2c6ba92fa2954e18525df29a2 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Thu, 9 Mar 2023 21:32:40 +0100 Subject: [PATCH] rename setSound to registerSound --- packages/webaudio/sampler.mjs | 4 ++-- packages/webaudio/synth.mjs | 4 ++-- packages/webaudio/webaudio.mjs | 3 +-- website/src/pages/technical-manual/sounds.mdx | 10 +++++----- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/webaudio/sampler.mjs b/packages/webaudio/sampler.mjs index 141dd5f7..e153dd8b 100644 --- a/packages/webaudio/sampler.mjs +++ b/packages/webaudio/sampler.mjs @@ -1,5 +1,5 @@ import { logger, toMidi, valueToMidi } from '@strudel.cycles/core'; -import { getAudioContext, setSound } from './index.mjs'; +import { getAudioContext, registerSound } from './index.mjs'; import { getEnvelope } from './helpers.mjs'; const bufferCache = {}; // string: Promise @@ -150,7 +150,7 @@ export const samples = async (sampleMap, baseUrl = sampleMap._base || '', option }), ); } - setSound(key, (t, hapValue, onended) => onTriggerSample(t, hapValue, onended, value), { + registerSound(key, (t, hapValue, onended) => onTriggerSample(t, hapValue, onended, value), { type: 'sample', samples: value, baseUrl, diff --git a/packages/webaudio/synth.mjs b/packages/webaudio/synth.mjs index f3be1ce6..6d16fae8 100644 --- a/packages/webaudio/synth.mjs +++ b/packages/webaudio/synth.mjs @@ -1,10 +1,10 @@ import { fromMidi, toMidi } from '@strudel.cycles/core'; -import { setSound } from './webaudio.mjs'; +import { registerSound } from './webaudio.mjs'; import { getOscillator, gainNode, getEnvelope } from './helpers.mjs'; export function registerSynthSounds() { ['sine', 'square', 'triangle', 'sawtooth'].forEach((wave) => { - setSound( + registerSound( wave, (t, value, onended) => { // destructure adsr here, because the default should be different for synths and samples diff --git a/packages/webaudio/webaudio.mjs b/packages/webaudio/webaudio.mjs index ce68cb33..8b694e93 100644 --- a/packages/webaudio/webaudio.mjs +++ b/packages/webaudio/webaudio.mjs @@ -14,8 +14,7 @@ import { getFilter, gainNode } from './helpers.mjs'; import { map } from 'nanostores'; export const soundMap = map(); -// onTrigger = ({ hap: Hap, t: number, deadline: number, duration: number, cps: number }) => AudioNode -export function setSound(key, onTrigger, data = {}) { +export function registerSound(key, onTrigger, data = {}) { soundMap.setKey(key, { onTrigger, data }); } export function getSound(s) { diff --git a/website/src/pages/technical-manual/sounds.mdx b/website/src/pages/technical-manual/sounds.mdx index b2f81ca7..ede7a426 100644 --- a/website/src/pages/technical-manual/sounds.mdx +++ b/website/src/pages/technical-manual/sounds.mdx @@ -9,12 +9,12 @@ import { MiniRepl } from '../../docs/MiniRepl'; Let's take a closer look about how sounds are implemented in the webaudio output. -## Registering a sound via setSound +## Registering a sound -All sounds are registered in the sound map, using the the `setSound` function: +All sounds are registered in the sound map, using the the `registerSound` function: ```ts -function setSound( +function registerSound( name: string, // The name of the sound that should be given to `s`, e.g. `mysaw` // The function called by the scheduler to trigger the sound: ( @@ -29,14 +29,14 @@ function setSound( ); ``` -When `setSound` is called, it registers `{ onTrigger, data }` under the given `name` in a [nanostore map](https://github.com/nanostores/nanostores#maps). +When `registerSound` is called, it registers `{ onTrigger, data }` under the given `name` in a [nanostore map](https://github.com/nanostores/nanostores#maps). ### Example This might be a bit abstract, so here is a minimal example: ```js -setSound( +registerSound( 'mysaw', (time, value, onended) => { let { freq } = value; // destructure control params