mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-11 13:48:40 +00:00
add nanFallback for better errors
This commit is contained in:
parent
eb0301d74e
commit
281ad5fac9
@ -1,4 +1,4 @@
|
||||
import { noteToMidi, valueToMidi } from './util.mjs';
|
||||
import { noteToMidi, valueToMidi, nanFallback } from './util.mjs';
|
||||
import { getAudioContext, registerSound } from './index.mjs';
|
||||
import { getEnvelope } from './helpers.mjs';
|
||||
import { logger } from './logger.mjs';
|
||||
@ -33,6 +33,7 @@ export const getSampleBufferSource = async (s, n, note, speed, freq, bank, resol
|
||||
const ac = getAudioContext();
|
||||
let sampleUrl;
|
||||
if (Array.isArray(bank)) {
|
||||
n = nanFallback(n, 0);
|
||||
sampleUrl = bank[n % bank.length];
|
||||
} else {
|
||||
const midiDiff = (noteA) => noteToMidi(noteA) - midi;
|
||||
|
||||
@ -7,7 +7,7 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
import './feedbackdelay.mjs';
|
||||
import './reverb.mjs';
|
||||
import './vowel.mjs';
|
||||
import { clamp } from './util.mjs';
|
||||
import { clamp, nanFallback } from './util.mjs';
|
||||
import workletsUrl from './worklets.mjs?url';
|
||||
import { getFilter, gainNode } from './helpers.mjs';
|
||||
import { map } from 'nanostores';
|
||||
@ -168,6 +168,7 @@ export const superdough = async (value, deadline, hapDuration) => {
|
||||
size = 2,
|
||||
velocity = 1,
|
||||
} = value;
|
||||
gain = nanFallback(gain, 1);
|
||||
gain *= velocity; // legacy fix for velocity
|
||||
let toDisconnect = []; // audio nodes that will be disconnected when the source has ended
|
||||
const onended = () => {
|
||||
|
||||
@ -51,3 +51,11 @@ export const valueToMidi = (value, fallbackValue) => {
|
||||
}
|
||||
return fallbackValue;
|
||||
};
|
||||
|
||||
export function nanFallback(value, fallback) {
|
||||
if (isNaN(Number(value))) {
|
||||
logger(`"${value}" is not a number, falling back to ${fallback}`, 'warning');
|
||||
return fallback;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user