From b81a66f07e6ca671385a52b79a54aabfa94233c7 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Sat, 10 Dec 2022 21:47:58 +0100 Subject: [PATCH] refactor uses of voicings + fix usages of scaleTranspose --- packages/core/pattern.mjs | 2 +- packages/tonal/voicings.mjs | 1 + repl/src/runtime.mjs | 4 ++-- repl/src/testtunes.mjs | 14 ++++++++++---- repl/src/tunes.mjs | 14 ++++++++------ tutorial/test/__snapshots__/examples.test.mjs.snap | 9 +++++++++ tutorial/tutorial.mdx | 2 +- 7 files changed, 32 insertions(+), 14 deletions(-) diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index 217cafa3..2985741a 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -1533,7 +1533,7 @@ export const { firstOf, every } = register(['firstOf', 'every'], function (n, fu /** * Like layer, but with a single function: - * @name _apply + * @name apply * @memberof Pattern * @example * "".scale('C minor').apply(scaleTranspose("0,2,4")).note() diff --git a/packages/tonal/voicings.mjs b/packages/tonal/voicings.mjs index 8332a087..dcc03924 100644 --- a/packages/tonal/voicings.mjs +++ b/packages/tonal/voicings.mjs @@ -31,6 +31,7 @@ export const voicingDictionaries = { * '7alt': ['3M 7m 10m 13m 15P'], * '7#11': ['7m 10m 13m 15P 17m'], * }, ['C3', 'C6']) + * "".voicings('cookie').note() */ export const addVoicings = (name, dictionary, range = ['F3', 'A4']) => { Object.assign(voicingDictionaries, { [name]: { dictionary, range } }); diff --git a/repl/src/runtime.mjs b/repl/src/runtime.mjs index a07ca2cc..294cde11 100644 --- a/repl/src/runtime.mjs +++ b/repl/src/runtime.mjs @@ -19,8 +19,7 @@ import { mini } from '@strudel.cycles/mini/mini.mjs'; // import euclid from '@strudel.cycles/core/euclid.mjs'; // import '@strudel.cycles/tone/tone.mjs'; // import '@strudel.cycles/midi/midi.mjs'; -import '@strudel.cycles/tonal/voicings.mjs'; -import '@strudel.cycles/tonal/tonal.mjs'; +import * as tonalHelpers from '@strudel.cycles/tonal'; import '@strudel.cycles/xen/xen.mjs'; // import '@strudel.cycles/xen/tune.mjs'; // import '@strudel.cycles/core/euclid.mjs'; @@ -164,6 +163,7 @@ evalScope( uiHelpersMocked, controls, webaudio, + tonalHelpers, /* controls, toneHelpers, voicingHelpers, diff --git a/repl/src/testtunes.mjs b/repl/src/testtunes.mjs index b92d4bd0..2f733d8c 100644 --- a/repl/src/testtunes.mjs +++ b/repl/src/testtunes.mjs @@ -89,10 +89,11 @@ export const whirlyStrudel = `seq(e4, [b2, b3], c4) export const transposedChordsHacked = `stack( "c2 eb2 g2", - "Cm7".voicings(['g2','c4']).slow(2) + "Cm7".voicings('lefthand').slow(2) ).transpose( "<1 2 3 2>".slow(2) ).transpose(5)`; +// range ['g2','c4'] export const scaleTranspose = `"f2,f3,c4,ab4" .scale(seq('F minor', 'F harmonic minor').slow(4)) @@ -102,8 +103,9 @@ export const scaleTranspose = `"f2,f3,c4,ab4" export const struct = `stack( "c2 g2 a2 [e2@2 eb2] d2 a2 g2 [d2 ~ db2]", "[C^7 A7] [Dm7 G7]".struct("[x@2 x] [~@2 x] [~ x@2]@2 [x ~@2] ~ [~@2 x@4]@2") - .voicings(['G3','A4']) + .voicings('lefthand') ).slow(4)`; +// range ['G3','A4'] export const magicSofa = `stack( " " @@ -197,7 +199,7 @@ export const giantStepsReggae = `stack( "B^7 [Fm7 Bb7] Eb^7 [C#m7 F#7]" ) .struct("~ [x ~]".fast(4*8)) - .voicings(['E3', 'G4']), + .voicings('lefthand'), // bass seq( "[B2 D2] [G2 D2] [Eb2 Bb2] [A2 D2]", @@ -208,6 +210,8 @@ export const giantStepsReggae = `stack( .struct("x ~".fast(4*8)) ).slow(25).note()`; +// range ['E3', 'G4'] + // TODO: /* export const xylophoneCalling = `// licensed with CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/ @@ -443,9 +447,11 @@ export const bossaRandom = `const chords = "" const roots = chords.rootNotes(2) stack( - chords.voicings(['F4', 'A5']).struct( + chords.voicings('lefthand').struct( \` x@2 ~ x ~ ~ ~ x | x? ~ ~ x@3 ~ x | x? ~ ~ x ~ x@3\`), roots.struct("x [~ x?0.2] x [~ x?] | x!4 | x@2 ~ ~ ~ x x x").transpose("0 7") ).slow(2).pianoroll().note().piano()`; + +// range ['F4', 'A5'] diff --git a/repl/src/tunes.mjs b/repl/src/tunes.mjs index d604950c..68d30bb1 100644 --- a/repl/src/tunes.mjs +++ b/repl/src/tunes.mjs @@ -81,7 +81,7 @@ stack( "[G^7 Bb7] [Eb^7 F#7] B^7 [Fm7 Bb7]", "Eb^7 [Am7 D7] G^7 [C#m7 F#7]", "B^7 [Fm7 Bb7] Eb^7 [C#m7 F#7]" - ).voicings(['E3', 'G4']), + ).voicings('lefthand'), // bass seq( "[B2 D2] [G2 Bb2] [Eb2 Bb3] [A2 D2]", @@ -90,6 +90,7 @@ stack( "[B2 F#2] [F2 Bb2] [Eb2 Bb3] [C#2 F#2]" ) ).slow(20).note()`; +// range: ['E3', 'G4'] export const zeldasRescue = `// Koji Kondo - Princess Zelda's Rescue stack( @@ -130,10 +131,10 @@ const synths = stack( "/2".scale(timeCat([3,'C minor'],[1,'C melodic minor']) .slow(8)).struct("[~ x]*2") .layer( - scaleTranspose(0).early(0), - scaleTranspose(2).early(1/8), - scaleTranspose(7).early(1/4), - scaleTranspose(8).early(3/8) + x=>x.scaleTranspose(0).early(0), + x=>x.scaleTranspose(2).early(1/8), + x=>x.scaleTranspose(7).early(1/4), + x=>x.scaleTranspose(8).early(3/8) ).apply(thru).note().apply(keys).mask("<~ x>/16"), note("/2".apply(thru)) .struct("[x [~ x] <[~ [~ x]]!3 [x x]>@2]/2".fast(2)) @@ -654,7 +655,7 @@ dino:{b4:'https://cdn.freesound.org/previews/316/316403_5123851-hq.mp3'}}) stack( s('bass').loopAt(8).clip(1), s("bd*2, ~ sd,hh*4"), -note("Abm7".voicings(['c3','a4']).struct("x(3,8,1)".slow(2))), +note("Abm7".voicings('lefthand').struct("x(3,8,1)".slow(2))), "0 1 2 3".scale('ab4 minor pentatonic') .superimpose(x=>x.add(.1)) .sometimes(x=>x.add(12)) @@ -665,6 +666,7 @@ note("Abm7".voicings(['c3','a4']).struct("x(3,8,1)".slow(2))), .degradeBy(.4).room(1), note("").s('dino').delay(.8).slow(8).room(.5) )`; +// ['c3','a4'] export const sampleDemo = `// licensed with CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/ // by Felix Roos diff --git a/tutorial/test/__snapshots__/examples.test.mjs.snap b/tutorial/test/__snapshots__/examples.test.mjs.snap index 64dd5cb6..2ed7cd9e 100644 --- a/tutorial/test/__snapshots__/examples.test.mjs.snap +++ b/tutorial/test/__snapshots__/examples.test.mjs.snap @@ -2352,6 +2352,15 @@ exports[`runs examples > example "room" example index 0 1`] = ` ] `; +exports[`runs examples > example "rootNotes" example index 0 1`] = ` +[ + "[ 0/1 → 1/1 | note:C2 ]", + "[ 1/1 → 2/1 | note:A2 ]", + "[ 2/1 → 3/1 | note:D2 ]", + "[ 3/1 → 4/1 | note:G2 ]", +] +`; + exports[`runs examples > example "round" example index 0 1`] = ` [ "[ 0/1 → 1/3 | note:D3 ]", diff --git a/tutorial/tutorial.mdx b/tutorial/tutorial.mdx index fd3b245d..b468d948 100644 --- a/tutorial/tutorial.mdx +++ b/tutorial/tutorial.mdx @@ -769,7 +769,7 @@ Together with layer, struct and voicings, this can be used to create a basic bac ".layer( - x => x.voicings(['d3','g4']).struct("~ x").note(), + x => x.voicings('lefthand').struct("~ x").note(), x => x.rootNotes(2).note().s('sawtooth').cutoff(800) )`} />