import type { NodeDef } from '../../NodeRegistry'; import { asNumber } from '../../values'; import { exec, num } from '../shared'; import { fxParamsOf } from './PlaySound'; /** * Changes the sound FX parameters of a sound that is already playing (#315). It reaches one voice, * by the number its `Play sound` handed out: every play is a sound of its own, and two objects with * the same engine sound – or one object playing it twice – each keep theirs. */ export const SetSoundFxParameters: NodeDef = { type: 'SetSoundFxParameters', label: 'Set sound FX parameters', category: 'action', description: 'Changes the sound FX parameters of a sound while it plays: the voice a Play sound handed out ' + 'glides to the values from a Sound FX parameters node. Keep the voice in a variable to reach it ' + 'from another event. A parameter not given keeps its value, a voice that has ended is not ' + 'reached. A pitch changes by speed here, so the sound gets shorter or longer while it is moved. ' + 'time: seconds the values take to get there, evenly and on the clock of the sound itself, so ' + 'a sweep sounds the same every time; 0 is a quick glide.', inputs: [ exec(), { ...num('voice'), inline: false }, { key: 'fxParams', label: 'fx params', type: 'fxparams' }, num('time'), ], outputs: [exec()], params: [], run: (ctx, inputs) => { const voice = asNumber(inputs.voice); const time = asNumber(inputs.time); if (voice > 0) ctx.tuneSound(voice, fxParamsOf(inputs.fxParams), Number.isFinite(time) && time > 0 ? time : 0); return { next: 'exec' }; }, };