From 78f6fdf16905b84f8569488e79acc8aa41bae716 Mon Sep 17 00:00:00 2001 From: "Jade (Rose) Rowland" Date: Mon, 8 Jan 2024 10:49:26 -0500 Subject: [PATCH] reset for example patterns --- website/src/repl/Repl.jsx | 12 ++++- website/src/repl/panel/PatternsTab.jsx | 6 +-- website/src/repl/tunes.mjs | 62 -------------------------- 3 files changed, 14 insertions(+), 66 deletions(-) diff --git a/website/src/repl/Repl.jsx b/website/src/repl/Repl.jsx index faf4bb07..9cc512ec 100644 --- a/website/src/repl/Repl.jsx +++ b/website/src/repl/Repl.jsx @@ -164,7 +164,17 @@ export function Repl({ embedded = false }) { editorRef.current?.toggle(); }; - const handleUpdate = (id, code) => { + const resetEditor = async () => { + clearCanvas(); + resetLoadedSounds(); + editorRef.current.repl.setCps(1); + await prebake(); // declare default samples + }; + + const handleUpdate = async (id, code, reset = false) => { + if (reset) { + await resetEditor(); + } setViewingPattern(id); editorRef.current.setCode(code); }; diff --git a/website/src/repl/panel/PatternsTab.jsx b/website/src/repl/panel/PatternsTab.jsx index 25e1f575..05385b15 100644 --- a/website/src/repl/panel/PatternsTab.jsx +++ b/website/src/repl/panel/PatternsTab.jsx @@ -51,14 +51,14 @@ export function PatternsTab({ context }) { const examplePatterns = useMemo(() => examplePattern.getAll(), []); const activePattern = useActivePattern(); const viewingPattern = useViewingPattern(); - const updateCodeWindow = (id, code) => { - context.handleUpdate(id, code); + const updateCodeWindow = (id, code, reset = false) => { + context.handleUpdate(id, code, reset); }; const onPatternBtnClick = (id, isExample = false) => { const code = isExample ? examplePatterns[id].code : userPatterns[id].code; // display selected pattern code in the window - updateCodeWindow(id, code); + updateCodeWindow(id, code, isExample); }; const isExample = examplePatterns[viewingPattern] != null; diff --git a/website/src/repl/tunes.mjs b/website/src/repl/tunes.mjs index ef847774..5f68ee93 100644 --- a/website/src/repl/tunes.mjs +++ b/website/src/repl/tunes.mjs @@ -5,9 +5,6 @@ This program is free software: you can redistribute it and/or modify it under th */ export const swimming = `// Koji Kondo - Swimming (Super Mario World) - -setCps(1) - stack( seq( "~", @@ -72,8 +69,6 @@ stack( export const giantSteps = `// John Coltrane - Giant Steps -setCps(1) - let melody = note( "[F#5 D5] [B4 G4] Bb4 [B4 A4]", "[D5 Bb4] [G4 Eb4] F#4 [G4 F4]", @@ -104,9 +99,6 @@ stack( .pianoroll({fold:1})`; export const zeldasRescue = `// Koji Kondo - Princess Zelda's Rescue - -setCps(1) - stack( // melody \`[B3@2 D4] [A3@2 [G3 A3]] [B3@2 D4] [A3] @@ -136,9 +128,6 @@ export const caverave = `// "Caverave" // @license CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/ // @by Felix Roos - -setCps(1) - const keys = x => x.s('sawtooth').cutoff(1200).gain(.5) .attack(0).decay(.16).sustain(.3).release(.1); @@ -185,8 +174,6 @@ export const sampleDrums = `samples({ hh: 'hh/000_hh3closedhh.wav' }, 'https://loophole-letters.vercel.app/samples/tidal/') -setCps(1) - stack( "".color('#F5A623'), "hh*4".color('#673AB7'), @@ -196,9 +183,6 @@ stack( `; export const barryHarris = `// adapted from a Barry Harris excercise - -setCps(1) - "0,2,[7 6]" .add("<0 1 2 3 4 5 7 8>") .scale('C bebop major') @@ -212,8 +196,6 @@ export const blippyRhodes = `// "Blippy Rhodes" // @license CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/ // @by Felix Roos -setCps(1) - samples({ bd: 'samples/tidal/bd/BT0A0D0.wav', sn: 'samples/tidal/sn/ST0T0S3.wav', @@ -257,8 +239,6 @@ export const wavyKalimba = `// "Wavy kalimba" // @license CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/ // @by Felix Roos -setCps(1) - samples({ 'kalimba': { c5:'https://freesound.org/data/previews/536/536549_11935698-lq.mp3' } }) @@ -289,8 +269,6 @@ export const festivalOfFingers = `// "Festival of fingers" // @license CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/ // @by Felix Roos -setCps(1) - const chords = ""; stack( chord(chords).dict('lefthand').voicing().struct("x(3,8,-1)") @@ -314,8 +292,6 @@ export const undergroundPlumber = `// "Underground plumber" // @by Felix Roos // @details inspired by Friendship - Let's not talk about it (1979) :) -setCps(1) - samples({ bd: 'bd/BT0A0D0.wav', sn: 'sn/ST0T0S3.wav', hh: 'hh/000_hh3closedhh.wav', cp: 'cp/HANDCLP0.wav', }, 'https://loophole-letters.vercel.app/samples/tidal/') @@ -343,8 +319,6 @@ export const bridgeIsOver = `// "Bridge is over" // @license CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/ // @by Felix Roos, bassline by BDP - The Bridge Is Over -setCps(1) - samples({mad:'https://freesound.org/data/previews/22/22274_109943-lq.mp3'}) stack( stack( @@ -365,8 +339,6 @@ export const goodTimes = `// "Good times" // @license CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/ // @by Felix Roos -setCps(1) - const scale = cat('C3 dorian','Bb2 major').slow(4); stack( n("2*4".add(12)).off(1/8, add(2)) @@ -389,8 +361,6 @@ export const echoPiano = `// "Echo piano" // @license CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/ // @by Felix Roos -setCps(1) - n("<0 2 [4 6](3,4,2) 3*2>").color('salmon') .off(1/4, x=>x.add(2).color('green')) .off(1/2, x=>x.add(6).color('steelblue')) @@ -401,9 +371,6 @@ n("<0 2 [4 6](3,4,2) 3*2>").color('salmon') .pianoroll()`; export const sml1 = `// Hirokazu Tanaka - World 1-1 - -setCps(1) - stack( // melody note(\`< @@ -442,8 +409,6 @@ export const randomBells = `// "Random bells" // @license CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/ // @by Felix Roos -setCps(1) - samples({ bell: { c6: 'https://freesound.org/data/previews/411/411089_5121236-lq.mp3' }, bass: { d2: 'https://freesound.org/data/previews/608/608286_13074022-lq.mp3' } @@ -467,8 +432,6 @@ export const waa2 = `// "Waa2" // @license CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/ // @by Felix Roos -setCps(1) - note( "a4 [a3 c3] a3 c3" .sub("<7 12 5 12>".slow(2)) @@ -487,8 +450,6 @@ export const hyperpop = `// "Hyperpop" // @license CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/ // @by Felix Roos -setCps(1) - const lfo = cosine.slow(15); const lfo2 = sine.slow(16); const filter1 = x=>x.cutoff(lfo2.range(300,3000)); @@ -544,8 +505,6 @@ export const festivalOfFingers3 = `// "Festival of fingers 3" // @license CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/ // @by Felix Roos -setCps(1) - n("[-7*3],0,2,6,[8 7]") .echoWith( 4, // echo 4 times @@ -569,8 +528,6 @@ export const meltingsubmarine = `// "Melting submarine" // @by Felix Roos await samples('github:tidalcycles/Dirt-Samples/master/') -setCps(1) - stack( s("bd:5,[~ ],hh27(3,4,1)") // drums .speed(perlin.range(.7,.9)) // random sample speed variation @@ -652,7 +609,6 @@ bd: ['bd/BT0AADA.wav','bd/BT0AAD0.wav','bd/BT0A0DA.wav','bd/BT0A0D3.wav','bd/BT0 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/'); -setCps(1) note("<8(3,8) <7 7*2> [4 5@3] 8>".sub(1) // sub 1 -> 1-indexed .layer( @@ -675,7 +631,6 @@ export const chop = `// "Chop" // @by Felix Roos samples({ p: 'https://cdn.freesound.org/previews/648/648433_11943129-lq.mp3' }) -setCps(1) s("p") .loopAt(32) @@ -701,8 +656,6 @@ export const orbit = `// "Orbit" // @license CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/ // @by Felix Roos -setCps(1) - stack( s("bd ") .delay(.5) @@ -720,8 +673,6 @@ export const belldub = `// "Belldub" // @by Felix Roos samples({ bell: {b4:'https://cdn.freesound.org/previews/339/339809_5121236-lq.mp3'}}) -setCps(1) - // "Hand Bells, B, Single.wav" by InspectorJ (www.jshaw.co.uk) of Freesound.org stack( // bass @@ -761,7 +712,6 @@ export const dinofunk = `// "Dinofunk" samples({bass:'https://cdn.freesound.org/previews/614/614637_2434927-hq.mp3', dino:{b4:'https://cdn.freesound.org/previews/316/316403_5123851-hq.mp3'}}) setVoicingRange('lefthand', ['c3','a4']) -setCps(1) stack( s('bass').loopAt(8).clip(1), @@ -786,8 +736,6 @@ export const sampleDemo = `// "Sample demo" // @license CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/ // @by Felix Roos -setCps(1) - stack( // percussion s("[woodblock:1 woodblock:2*2] snare_rim:0,gong/8,brakedrum:1(3,8),~@3 cowbell:3") @@ -806,8 +754,6 @@ export const holyflute = `// "Holy flute" // @license CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/ // @by Felix Roos -setCps(1) - "c3 eb3(3,8) c4/2 g3*2" .superimpose( x=>x.slow(2).add(12), @@ -849,8 +795,6 @@ export const amensister = `// "Amensister" // @license CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/ // @by Felix Roos -setCps(1) - await samples('github:tidalcycles/Dirt-Samples/master') stack( @@ -889,8 +833,6 @@ export const juxUndTollerei = `// "Jux und tollerei" // @license CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/ // @by Felix Roos -setCps(1) - note("c3 eb3 g3 bb3").palindrome() .s('sawtooth') .jux(x=>x.rev().color('green').s('sawtooth')) @@ -906,8 +848,6 @@ export const csoundDemo = `// "CSound demo" // @license with CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/ // @by Felix Roos -setCps(1) - await loadCsound\` instr CoolSynth iduration = p3 @@ -945,7 +885,6 @@ export const loungeSponge = `// "Lounge sponge" // @by Felix Roos, livecode.orc by Steven Yi await loadOrc('github:kunstmusik/csound-live-code/master/livecode.orc') -setCps(1) stack( chord("/2").dict('lefthand').voicing() @@ -966,7 +905,6 @@ export const arpoon = `// "Arpoon" // @by Felix Roos await samples('github:tidalcycles/Dirt-Samples/master') -setCps(1) n("[0,3] 2 [1,3] 2".fast(3).lastOf(4, fast(2))).clip(2) .offset("<<1 2> 2 1 1>")