From 6679cd60ce023702b383deac773bf5cd6d3f624a Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Sun, 11 Dec 2022 22:45:36 +0100 Subject: [PATCH] scale now supports running on object values with n --- packages/tonal/tonal.mjs | 5 +++-- repl/src/tunes.mjs | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/packages/tonal/tonal.mjs b/packages/tonal/tonal.mjs index dd2445dc..9e47d4a2 100644 --- a/packages/tonal/tonal.mjs +++ b/packages/tonal/tonal.mjs @@ -141,13 +141,14 @@ export const scaleTranspose = register('scaleTranspose', function (offset /* : n export const scale = register('scale', function (scale /* : string */, pat) { return pat.withHap((hap) => { - let note = hap.value; + const isObject = typeof hap.value === 'object'; + let note = isObject ? hap.value.n : hap.value; const asNumber = Number(note); if (!isNaN(asNumber)) { let [tonic, scaleName] = Scale.tokenize(scale); const { pc, oct = 3 } = Note.get(tonic); note = scaleOffset(pc + ' ' + scaleName, asNumber, pc + oct); } - return hap.withValue(() => note).setContext({ ...hap.context, scale }); + return hap.withValue(() => (isObject ? { ...hap.value, note } : note)).setContext({ ...hap.context, scale }); }); }); diff --git a/repl/src/tunes.mjs b/repl/src/tunes.mjs index a3ba23e5..dddfb6e4 100644 --- a/repl/src/tunes.mjs +++ b/repl/src/tunes.mjs @@ -310,22 +310,43 @@ export const goodTimes = `// licensed with CC BY-NC-SA 4.0 https://creativecommo const scale = cat('C3 dorian','Bb2 major').slow(4); stack( "2*4".add(12).scale(scale) - .off(1/8,x=>x.scaleTranspose("2")).fast(2) + .off(1/8, scaleTranspose("2")).fast(2) .scaleTranspose("<0 1 2 1>").hush(), "<0 1 2 3>(3,8,2)" .scale(scale) - .off(1/4,x=>x.scaleTranspose("2,4")), + .off(1/4, scaleTranspose("2,4")), "<0 4>(5,8)".scale(scale).transpose(-12) ) .velocity(".6 .7".fast(4)) .legato("2") + .scaleTranspose("<0>".slow(4)) + .transpose(5) + .note().piano() + .velocity(.8) + .slow(2) + .pianoroll({maxMidi:100,minMidi:20})`; + +/* // new style notation: +export const goodTimes = `// licensed with CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/ +// by Felix Roos +const scale = cat('C3 dorian','Bb2 major').slow(4); +stack( + n("2*4").add(12) + .off(1/8, add("2")).fast(2) + .add("<0 1 2 1>").hush(), + n("<0 1 2 3>(3,8,2)") + .off(1/4, add("2,4")), + n("<0 4>(5,8)").sub(7) +) .scale(scale) -.scaleTranspose("<0>".slow(4)) -.transpose(5) -.note().piano() -.velocity(.8) -.slow(2) -.pianoroll({maxMidi:100,minMidi:20})`; + .gain(".6 .7".fast(4)) + .legato(2) + .add(note(5)) + .piano() + .mul(gain(.8)) + .slow(2) + .pianoroll({maxMidi:100,minMidi:20})`; +*/ export const echoPiano = `// licensed with CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/ // by Felix Roos