better default tune + fix dirty state

This commit is contained in:
Felix Roos 2022-08-18 15:16:29 +02:00
parent e3e3a8404a
commit 04502b05d4
2 changed files with 43 additions and 3 deletions

View File

@ -1,4 +1,3 @@
import '@strudel.cycles/core';
import controls from '@strudel.cycles/core/controls.mjs';
import { evalScope } from '@strudel.cycles/eval';
import { webaudioOutput } from '@strudel.cycles/webaudio';
@ -7,6 +6,7 @@ import useScheduler from '../../../src/hooks/useScheduler';
import useEvaluator from '../../../src/hooks/useEvaluator';
// import { prebake } from '../../../../../repl/src/prebake.mjs';
// TODO: only import stuff when play is pressed?
await evalScope(
controls,
import('@strudel.cycles/core'),
@ -22,10 +22,50 @@ await evalScope(
import('@strudel.cycles/soundfonts'),
);
const defaultTune = `samples({
bd: ['bd/BT0AADA.wav','bd/BT0AAD0.wav','bd/BT0A0DA.wav','bd/BT0A0D3.wav','bd/BT0A0D0.wav','bd/BT0A0A7.wav'],
sd: ['sd/rytm-01-classic.wav','sd/rytm-00-hard.wav'],
hh: ['hh27/000_hh27closedhh.wav','hh/000_hh3closedhh.wav'],
}, 'github:tidalcycles/Dirt-Samples/master/');
stack(
s("bd,[~ <sd!3 sd(3,4,2)>],hh(3,4)") // drums
.speed(perlin.range(.7,.9)) // random sample speed variation
//.hush()
,"<a1 b1*2 a1(3,8) e2>" // bassline
.off(1/8,x=>x.add(12).degradeBy(.5)) // random octave jumps
.add(perlin.range(0,.5)) // random pitch variation
.superimpose(add(.05)) // add second, slightly detuned voice
.n() // wrap in "n"
.decay(.15).sustain(0) // make each note of equal length
.s('sawtooth') // waveform
.gain(.4) // turn down
.cutoff(sine.slow(7).range(300,5000)) // automate cutoff
//.hush()
,"<Am7!3 <Em7 E7b13 Em7 Ebm7b5>>".voicings() // chords
.superimpose(x=>x.add(.04)) // add second, slightly detuned voice
.add(perlin.range(0,.5)) // random pitch variation
.n() // wrap in "n"
.s('sawtooth') // waveform
.gain(.16) // turn down
.cutoff(500) // fixed cutoff
.attack(1) // slowly fade in
//.hush()
,"a4 c5 <e6 a6>".struct("x(5,8)")
.superimpose(x=>x.add(.04)) // add second, slightly detuned voice
.add(perlin.range(0,.5)) // random pitch variation
.n() // wrap in "n"
.decay(.1).sustain(0) // make notes short
.s('triangle') // waveform
.degradeBy(perlin.range(0,.5)) // randomly controlled random removal :)
.echoWith(4,.125,(x,n)=>x.gain(.15*1/(n+1))) // echo notes
//.hush()
)
.cps(2/3)`;
// await prebake();
function App() {
const [code, setCode] = useState(`"c3 [eb3,g3]".note()`);
const [code, setCode] = useState(defaultTune);
const { evaluate, pattern, isDirty, error: evaluatorError } = useEvaluator({ code });
const { scheduler, error: schedulerError } = useScheduler(pattern, webaudioOutput);
const error = evaluatorError || schedulerError;

View File

@ -15,7 +15,7 @@ function useEvaluator({ code, evalOnMount = true }) {
try {
// TODO: let user inject custom eval function?
const { pattern: _pattern } = await _evaluate(code);
setActiveCode(activeCode);
setActiveCode(code);
setPattern(_pattern);
setError();
} catch (err) {