Add soundAlias function
This commit is contained in:
parent
ff2c59a2a6
commit
56b1ea3fa5
2 changed files with 21 additions and 0 deletions
|
|
@ -113,6 +113,19 @@ export async function aliasBank(...args) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register an alias for a sound.
|
||||||
|
* @param {string} original - The original sound name
|
||||||
|
* @param {string} alias - The alias to use for the sound
|
||||||
|
*/
|
||||||
|
export function soundAlias(original, alias) {
|
||||||
|
if (getSound(original) == null) {
|
||||||
|
logger('soundAlias: original sound not found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
soundMap.setKey(alias, getSound(original));
|
||||||
|
}
|
||||||
|
|
||||||
export function getSound(s) {
|
export function getSound(s) {
|
||||||
if (typeof s !== 'string') {
|
if (typeof s !== 'string') {
|
||||||
console.warn(`getSound: expected string got "${s}". fall back to triangle`);
|
console.warn(`getSound: expected string got "${s}". fall back to triangle`);
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,14 @@ Furthermore, strudel also loads instrument samples from [VCSL](https://github.co
|
||||||
|
|
||||||
To see which sample names are available, open the `sounds` tab in the [REPL](https://strudel.cc/).
|
To see which sample names are available, open the `sounds` tab in the [REPL](https://strudel.cc/).
|
||||||
|
|
||||||
|
You can also create custom aliases for existing sounds using the `soundAlias` function:
|
||||||
|
|
||||||
|
<MiniRepl
|
||||||
|
client:idle
|
||||||
|
tune={`soundAlias("RolandTR808_bd", "kick")
|
||||||
|
s("kick")`}
|
||||||
|
/>
|
||||||
|
|
||||||
Note that only the sample maps (mapping names to URLs) are loaded initially, while the audio samples themselves are not loaded until they are actually played.
|
Note that only the sample maps (mapping names to URLs) are loaded initially, while the audio samples themselves are not loaded until they are actually played.
|
||||||
This behaviour of loading things only when they are needed is also called `lazy loading`.
|
This behaviour of loading things only when they are needed is also called `lazy loading`.
|
||||||
While it saves resources, it can also lead to sounds not being audible the first time they are triggered, because the sound is still loading.
|
While it saves resources, it can also lead to sounds not being audible the first time they are triggered, because the sound is still loading.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue