From e719cea0de27d7492104e9746d476ce26bf25ae5 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Sun, 27 Feb 2022 11:57:30 +0100 Subject: [PATCH] fix mini repl draw + tutorial --- repl/package.json | 2 +- repl/src/tutorial/MiniRepl.tsx | 4 +++- repl/src/tutorial/tutorial.mdx | 30 +++++++++++++++--------------- repl/src/useRepl.ts | 1 + 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/repl/package.json b/repl/package.json index fa9fcfa2..f7caf925 100644 --- a/repl/package.json +++ b/repl/package.json @@ -7,7 +7,7 @@ "format": "prettier --write \"src/**/*.{js,jsx,ts,tsx}\"", "lint": "prettier --check \"src/**/*.{js,jsx,ts,tsx}\"", "peggy": "peggy -o krill-parser.js --format es ./krill.pegjs", - "tutorial": "parcel src/tutorial/index.html", + "tutorial": "parcel src/tutorial/index.html --no-cache", "build-tutorial": "parcel build src/tutorial/index.html --dist-dir ../docs/tutorial --public-url /tutorial --no-optimize --no-scope-hoist --no-cache" }, "dependencies": { diff --git a/repl/src/tutorial/MiniRepl.tsx b/repl/src/tutorial/MiniRepl.tsx index 4d50c38a..7eba5ca1 100644 --- a/repl/src/tutorial/MiniRepl.tsx +++ b/repl/src/tutorial/MiniRepl.tsx @@ -11,13 +11,15 @@ const defaultSynth = new Tone.PolySynth().chain(new Tone.Gain(0.5), Tone.Destina }, }); +// "balanced" | "interactive" | "playback"; +Tone.setContext(new Tone.Context({ latencyHint: 'playback', lookAhead: 1 })); function MiniRepl({ tune, maxHeight = 500 }) { const [editor, setEditor] = useState(); const { code, setCode, activateCode, activeCode, setPattern, error, cycle, dirty, log, togglePlay, hash } = useRepl({ tune, defaultSynth, autolink: false, - onEvent: useCallback(markEvent(editor), [editor]), + onDraw: useCallback(markEvent(editor), [editor]), }); const lines = code.split('\n').length; const height = Math.min(lines * 30 + 30, maxHeight); diff --git a/repl/src/tutorial/tutorial.mdx b/repl/src/tutorial/tutorial.mdx index 22dada6a..43b06859 100644 --- a/repl/src/tutorial/tutorial.mdx +++ b/repl/src/tutorial/tutorial.mdx @@ -17,12 +17,12 @@ To get a taste of what Strudel can do, check out this track: { - const delay = new FeedbackDelay(1/8, .4).chain(vol(0.5), out); - const kick = new MembraneSynth().chain(vol(.8), out); - const snare = new NoiseSynth().chain(vol(.8), out); - const hihat = new MetalSynth().set(adsr(0, .08, 0, .1)).chain(vol(.3).connect(delay),out); - const bass = new Synth().set({ ...osc('sawtooth'), ...adsr(0, .1, .4) }).chain(lowpass(900), vol(.5), out); - const keys = new PolySynth().set({ ...osc('sawtooth'), ...adsr(0, .5, .2, .7) }).chain(lowpass(1200), vol(.5), out); + const delay = new FeedbackDelay(1/8, .4).chain(vol(0.5), out()); + const kick = new MembraneSynth().chain(vol(.8), out()); + const snare = new NoiseSynth().chain(vol(.8), out()); + const hihat = new MetalSynth().set(adsr(0, .08, 0, .1)).chain(vol(.3).connect(delay),out()); + const bass = new Synth().set({ ...osc('sawtooth'), ...adsr(0, .1, .4) }).chain(lowpass(900), vol(.5), out()); + const keys = new PolySynth().set({ ...osc('sawtooth'), ...adsr(0, .5, .2, .7) }).chain(lowpass(1200), vol(.5), out()); const drums = stack( "c1*2".tone(kick).bypass("<0@7 1>/8"), @@ -371,12 +371,12 @@ To make the sounds more interesting, we can use Tone.js instruments ands effects @@ -411,7 +411,7 @@ Shortcut for Tone.Destination. Intended to be used with Tone's .chain: This alone is not really useful, so read on.. @@ -422,7 +422,7 @@ Helper that returns a Gain Node with the given volume. Intended to be used with ### osc(type) @@ -431,7 +431,7 @@ Helper to set the waveform of a synth, monosynth or polysynth: The base types are `sine`, `square`, `sawtooth`, `triangle`. You can also append a number between 1 and 32 to reduce the harmonic partials. @@ -442,7 +442,7 @@ Helper that returns a Filter Node of type lowpass with the given cutoff. Intende ### highpass(cutoff) @@ -451,7 +451,7 @@ Helper that returns a Filter Node of type highpass with the given cutoff. Intend ### adsr(attack, decay?, sustain?, release?) @@ -460,7 +460,7 @@ Helper to set the envelope of a Tone.js instrument. Intended to be used with Ton ### Experimental: Patternification @@ -574,7 +574,7 @@ Together with edit, struct and voicings, this can be used to create a basic back ".edit( x => x.voicings(['d3','g4']).struct("~ x"), - x => x.rootNotes(2).tone(synth(osc('sawtooth4')).chain(out)) + x => x.rootNotes(2).tone(synth(osc('sawtooth4')).chain(out())) )`} /> diff --git a/repl/src/useRepl.ts b/repl/src/useRepl.ts index 0a418fd3..c792db0d 100644 --- a/repl/src/useRepl.ts +++ b/repl/src/useRepl.ts @@ -86,6 +86,7 @@ function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw }: any) try { return pattern?.query(span) || []; } catch (err: any) { + console.warn(err); err.message = 'query error: ' + err.message; setError(err); return [];