mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-23 11:38:37 +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 { getAudioContext, registerSound } from './index.mjs';
|
||||||
import { getEnvelope } from './helpers.mjs';
|
import { getEnvelope } from './helpers.mjs';
|
||||||
import { logger } from './logger.mjs';
|
import { logger } from './logger.mjs';
|
||||||
@ -33,6 +33,7 @@ export const getSampleBufferSource = async (s, n, note, speed, freq, bank, resol
|
|||||||
const ac = getAudioContext();
|
const ac = getAudioContext();
|
||||||
let sampleUrl;
|
let sampleUrl;
|
||||||
if (Array.isArray(bank)) {
|
if (Array.isArray(bank)) {
|
||||||
|
n = nanFallback(n, 0);
|
||||||
sampleUrl = bank[n % bank.length];
|
sampleUrl = bank[n % bank.length];
|
||||||
} else {
|
} else {
|
||||||
const midiDiff = (noteA) => noteToMidi(noteA) - midi;
|
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 './feedbackdelay.mjs';
|
||||||
import './reverb.mjs';
|
import './reverb.mjs';
|
||||||
import './vowel.mjs';
|
import './vowel.mjs';
|
||||||
import { clamp } from './util.mjs';
|
import { clamp, nanFallback } from './util.mjs';
|
||||||
import workletsUrl from './worklets.mjs?url';
|
import workletsUrl from './worklets.mjs?url';
|
||||||
import { getFilter, gainNode } from './helpers.mjs';
|
import { getFilter, gainNode } from './helpers.mjs';
|
||||||
import { map } from 'nanostores';
|
import { map } from 'nanostores';
|
||||||
@ -168,6 +168,7 @@ export const superdough = async (value, deadline, hapDuration) => {
|
|||||||
size = 2,
|
size = 2,
|
||||||
velocity = 1,
|
velocity = 1,
|
||||||
} = value;
|
} = value;
|
||||||
|
gain = nanFallback(gain, 1);
|
||||||
gain *= velocity; // legacy fix for velocity
|
gain *= velocity; // legacy fix for velocity
|
||||||
let toDisconnect = []; // audio nodes that will be disconnected when the source has ended
|
let toDisconnect = []; // audio nodes that will be disconnected when the source has ended
|
||||||
const onended = () => {
|
const onended = () => {
|
||||||
|
|||||||
@ -51,3 +51,11 @@ export const valueToMidi = (value, fallbackValue) => {
|
|||||||
}
|
}
|
||||||
return 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