Skip to content

Commit

Permalink
Merge pull request #769 from tidalcycles/patterns-tab
Browse files Browse the repository at this point in the history
Patterns tab + Refactor Panel
  • Loading branch information
felixroos authored Dec 7, 2023
2 parents c787bb2 + e551dfe commit f8d1e9e
Show file tree
Hide file tree
Showing 16 changed files with 772 additions and 509 deletions.
7 changes: 5 additions & 2 deletions packages/react/src/hooks/useStrudel.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ function useStrudel({
}
});
const activateCode = useCallback(
async (autostart = true) => {
const res = await evaluate(code, autostart);
async (newCode, autostart = true) => {
if (newCode) {
setCode(code);
}
const res = await evaluate(newCode || code, autostart);
broadcast({ type: 'start', from: id });
return res;
},
Expand Down
3 changes: 2 additions & 1 deletion packages/superdough/sampler.mjs
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion packages/superdough/superdough.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 { createFilter, gainNode, getCompressor } from './helpers.mjs';
import { map } from 'nanostores';
Expand Down Expand Up @@ -322,6 +322,7 @@ export const superdough = async (value, deadline, hapDuration) => {
compressorAttack,
compressorRelease,
} = value;
gain = nanFallback(gain, 1);

//music programs/audio gear usually increments inputs/outputs from 1, so imitate that behavior
channels = (Array.isArray(channels) ? channels : [channels]).map((ch) => ch - 1);
Expand Down
10 changes: 10 additions & 0 deletions packages/superdough/util.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { logger } from './logger.mjs';

// currently duplicate with core util.mjs to skip dependency
// TODO: add separate util module?

Expand Down Expand Up @@ -51,3 +53,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

0 comments on commit f8d1e9e

Please sign in to comment.