mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-11 13:48:34 +00:00
rename setSound to registerSound
This commit is contained in:
parent
ff1e6714c6
commit
6f5d096e6d
@ -1,5 +1,5 @@
|
|||||||
import { logger, toMidi, valueToMidi } from '@strudel.cycles/core';
|
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';
|
import { getEnvelope } from './helpers.mjs';
|
||||||
|
|
||||||
const bufferCache = {}; // string: Promise<ArrayBuffer>
|
const bufferCache = {}; // string: Promise<ArrayBuffer>
|
||||||
@ -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',
|
type: 'sample',
|
||||||
samples: value,
|
samples: value,
|
||||||
baseUrl,
|
baseUrl,
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import { fromMidi, toMidi } from '@strudel.cycles/core';
|
import { fromMidi, toMidi } from '@strudel.cycles/core';
|
||||||
import { setSound } from './webaudio.mjs';
|
import { registerSound } from './webaudio.mjs';
|
||||||
import { getOscillator, gainNode, getEnvelope } from './helpers.mjs';
|
import { getOscillator, gainNode, getEnvelope } from './helpers.mjs';
|
||||||
|
|
||||||
export function registerSynthSounds() {
|
export function registerSynthSounds() {
|
||||||
['sine', 'square', 'triangle', 'sawtooth'].forEach((wave) => {
|
['sine', 'square', 'triangle', 'sawtooth'].forEach((wave) => {
|
||||||
setSound(
|
registerSound(
|
||||||
wave,
|
wave,
|
||||||
(t, value, onended) => {
|
(t, value, onended) => {
|
||||||
// destructure adsr here, because the default should be different for synths and samples
|
// destructure adsr here, because the default should be different for synths and samples
|
||||||
|
|||||||
@ -14,8 +14,7 @@ import { getFilter, gainNode } from './helpers.mjs';
|
|||||||
import { map } from 'nanostores';
|
import { map } from 'nanostores';
|
||||||
|
|
||||||
export const soundMap = map();
|
export const soundMap = map();
|
||||||
// onTrigger = ({ hap: Hap, t: number, deadline: number, duration: number, cps: number }) => AudioNode
|
export function registerSound(key, onTrigger, data = {}) {
|
||||||
export function setSound(key, onTrigger, data = {}) {
|
|
||||||
soundMap.setKey(key, { onTrigger, data });
|
soundMap.setKey(key, { onTrigger, data });
|
||||||
}
|
}
|
||||||
export function getSound(s) {
|
export function getSound(s) {
|
||||||
|
|||||||
@ -9,12 +9,12 @@ import { MiniRepl } from '../../docs/MiniRepl';
|
|||||||
|
|
||||||
Let's take a closer look about how sounds are implemented in the webaudio output.
|
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
|
```ts
|
||||||
function setSound(
|
function registerSound(
|
||||||
name: string, // The name of the sound that should be given to `s`, e.g. `mysaw`
|
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:
|
// 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
|
### Example
|
||||||
|
|
||||||
This might be a bit abstract, so here is a minimal example:
|
This might be a bit abstract, so here is a minimal example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
setSound(
|
registerSound(
|
||||||
'mysaw',
|
'mysaw',
|
||||||
(time, value, onended) => {
|
(time, value, onended) => {
|
||||||
let { freq } = value; // destructure control params
|
let { freq } = value; // destructure control params
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user