fix: double registering

This commit is contained in:
Felix Roos 2023-08-30 15:32:45 +02:00
parent 1463f27a0f
commit 90cdea3656
4 changed files with 8 additions and 20 deletions

View File

@ -6,7 +6,6 @@ import {
panic, panic,
webaudioOutput, webaudioOutput,
registerSynthSounds, registerSynthSounds,
registerZZFXSounds,
} from '@strudel.cycles/webaudio'; } from '@strudel.cycles/webaudio';
import { registerSoundfonts } from '@strudel.cycles/soundfonts'; import { registerSoundfonts } from '@strudel.cycles/soundfonts';
import { useCallback, useState } from 'react'; import { useCallback, useState } from 'react';
@ -27,7 +26,7 @@ async function init() {
import('@strudel.cycles/osc'), import('@strudel.cycles/osc'),
); );
await Promise.all([loadModules, registerSynthSounds(), registerZZFXSounds(), registerSoundfonts()]); await Promise.all([loadModules, registerSynthSounds(), registerSoundfonts()]);
} }
init(); init();

View File

@ -21,21 +21,6 @@ const fm = (osc, harmonicityRatio, modulationIndex, wave = 'sine') => {
}; };
export function registerSynthSounds() { export function registerSynthSounds() {
['zsine', 'zsaw', 'ztri', 'ztan', 'znoise'].forEach((wave) => {
registerSound(wave, (t, value, onended) => {
const duration = 0.2;
const { node: o } = getZZFX({ s: wave, ...value }, t, duration);
o.onended = () => {
o.disconnect();
onended();
};
return {
node: o,
stop: () => {},
};
});
});
['sine', 'square', 'triangle', 'sawtooth'].forEach((wave) => { ['sine', 'square', 'triangle', 'sawtooth'].forEach((wave) => {
registerSound( registerSound(
wave, wave,

View File

@ -1,4 +1,6 @@
import { ZZFX } from 'zzfx'; import { ZZFX } from 'zzfx';
import { midiToFreq, noteToMidi } from './util.mjs';
import { registerSound, getAudioContext } from './superdough.mjs';
export const getZZFX = (value, t, duration) => { export const getZZFX = (value, t, duration) => {
let { let {
@ -27,8 +29,8 @@ export const getZZFX = (value, t, duration) => {
note = noteToMidi(note); // e.g. c3 => 48 note = noteToMidi(note); // e.g. c3 => 48
} }
// get frequency // get frequency
if (!freq && typeof n === 'number') { if (!freq && typeof note === 'number') {
freq = midiToFreq(n); freq = midiToFreq(note);
} }
const shape = ['zsine', 'ztri', 'zsaw', 'ztan', 'znoise'].indexOf(s) || 0; const shape = ['zsine', 'ztri', 'zsaw', 'ztan', 'znoise'].indexOf(s) || 0;
@ -93,6 +95,7 @@ export const getZZFX = (value, t, duration) => {
}; };
export function registerZZFXSounds() { export function registerZZFXSounds() {
console.log('registerZZFXSounds');
['zsine', 'zsaw', 'ztri', 'ztan', 'znoise'].forEach((wave) => { ['zsine', 'zsaw', 'ztri', 'ztan', 'znoise'].forEach((wave) => {
registerSound(wave, (t, value, onended) => { registerSound(wave, (t, value, onended) => {
const duration = 0.2; const duration = 0.2;

View File

@ -1,5 +1,5 @@
import { Pattern, noteToMidi, valueToMidi } from '@strudel.cycles/core'; import { Pattern, noteToMidi, valueToMidi } from '@strudel.cycles/core';
import { registerSynthSounds, samples } from '@strudel.cycles/webaudio'; import { registerSynthSounds, registerZZFXSounds, samples } from '@strudel.cycles/webaudio';
import './piano.mjs'; import './piano.mjs';
import './files.mjs'; import './files.mjs';
@ -8,6 +8,7 @@ export async function prebake() {
// License: CC-by http://creativecommons.org/licenses/by/3.0/ Author: Alexander Holm // License: CC-by http://creativecommons.org/licenses/by/3.0/ Author: Alexander Holm
await Promise.all([ await Promise.all([
registerSynthSounds(), registerSynthSounds(),
registerZZFXSounds(),
//registerSoundfonts(), //registerSoundfonts(),
// need dynamic import here, because importing @strudel.cycles/soundfonts fails on server: // need dynamic import here, because importing @strudel.cycles/soundfonts fails on server:
// => getting "window is not defined", as soon as "@strudel.cycles/soundfonts" is imported statically // => getting "window is not defined", as soon as "@strudel.cycles/soundfonts" is imported statically