From 16e2c97e0c85dd4799394143b08d2faee2cfc808 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Wed, 13 Apr 2022 23:25:18 +0200 Subject: [PATCH 1/5] export patternify helpers --- packages/core/strudel.mjs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/core/strudel.mjs b/packages/core/strudel.mjs index 5f659e88..8f95f6c7 100644 --- a/packages/core/strudel.mjs +++ b/packages/core/strudel.mjs @@ -708,8 +708,8 @@ class Pattern { } _zoom(s, e) { - e = Fraction(e) - s = Fraction(s) + e = Fraction(e); + s = Fraction(s); const d = e.sub(s); return this.withQuerySpan((span) => span.withCycle((t) => t.mul(d).add(s))) .withEventSpan((span) => span.withCycle((t) => t.sub(s).div(d))) @@ -1202,11 +1202,11 @@ Pattern.prototype.chunkBack = function (...args) { Pattern.prototype.zoom = function (...args) { args = args.map(reify); return patternify2(Pattern.prototype._zoom)(...args, this); -} +}; Pattern.prototype.compress = function (...args) { args = args.map(reify); return patternify2(Pattern.prototype._compress)(...args, this); -} +}; // call this after all Patter.prototype.define calls have been executed! (right before evaluate) Pattern.prototype.bootstrap = function () { @@ -1310,4 +1310,7 @@ export { timeCat, union, when, + patternify2, + patternify3, + patternify4, }; From 1dd19c08317b1f07b7f2b75861a33f30bdce5ae6 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Wed, 13 Apr 2022 23:25:55 +0200 Subject: [PATCH 2/5] add speak output --- packages/core/speak.mjs | 33 +++++++++++++++++++++++++++++++++ repl/src/App.js | 21 ++++++++++++++++----- 2 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 packages/core/speak.mjs diff --git a/packages/core/speak.mjs b/packages/core/speak.mjs new file mode 100644 index 00000000..7acf6d93 --- /dev/null +++ b/packages/core/speak.mjs @@ -0,0 +1,33 @@ +import { Pattern, patternify2 } from './strudel.mjs'; + +const synth = window?.speechSynthesis; +let allVoices = synth?.getVoices(); +// console.log('voices', allVoices); + +function speak(words, lang, voice) { + synth.cancel(); + const utterance = new SpeechSynthesisUtterance(words); + utterance.lang = lang; + allVoices = synth.getVoices(); + const voices = allVoices.filter((v) => v.lang.includes(lang)); + if (typeof voice === 'number') { + utterance.voice = voices[voice % voices.length]; + } else if (typeof voice === 'string') { + utterance.voice = voices.find((voice) => voice.name === voice); + } + // console.log(utterance.voice?.name, utterance.voice?.lang); + speechSynthesis.speak(utterance); +} + +Pattern.prototype._speak = function (lang, voice) { + return this._withEvent((event) => { + const onTrigger = (time, event) => { + speak(event.value, lang, voice); + }; + return event.setContext({ ...event.context, onTrigger }); + }); +}; + +Pattern.prototype.speak = function (lang, voice) { + return patternify2(Pattern.prototype._speak)(reify(lang), reify(voice), this); +}; diff --git a/repl/src/App.js b/repl/src/App.js index 10fdfcd7..1d9d3f61 100644 --- a/repl/src/App.js +++ b/repl/src/App.js @@ -26,17 +26,28 @@ import '@strudel.cycles/tonal/tonal.mjs'; import '@strudel.cycles/xen/xen.mjs'; import '@strudel.cycles/xen/tune.mjs'; import '@strudel.cycles/core/euclid.mjs'; +import '@strudel.cycles/core/speak.mjs'; import '@strudel.cycles/tone/pianoroll.mjs'; import '@strudel.cycles/tone/draw.mjs'; import '@strudel.cycles/osc/osc.mjs'; import controls from '@strudel.cycles/core/controls.mjs'; -extend(Tone, strudel, strudel.Pattern.prototype.bootstrap(), controls, toneHelpers, voicingHelpers, drawHelpers, uiHelpers, { - gist, - euclid, - mini, +extend( Tone, -}); + strudel, + strudel.Pattern.prototype.bootstrap(), + controls, + toneHelpers, + voicingHelpers, + drawHelpers, + uiHelpers, + { + gist, + euclid, + mini, + Tone, + }, +); // eval stuff end const codeParam = window.location.href.split('#')[1]; From 38fe310a7c03beb65953389aacf181a331d96611 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Wed, 13 Apr 2022 23:58:34 +0200 Subject: [PATCH 3/5] fix import --- packages/core/speak.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/speak.mjs b/packages/core/speak.mjs index 7acf6d93..141ef92f 100644 --- a/packages/core/speak.mjs +++ b/packages/core/speak.mjs @@ -1,4 +1,4 @@ -import { Pattern, patternify2 } from './strudel.mjs'; +import { Pattern, patternify2 } from './index.mjs'; const synth = window?.speechSynthesis; let allVoices = synth?.getVoices(); From 02ece1183e027ac09227b2d837d3c3120b271ea2 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Wed, 13 Apr 2022 23:58:44 +0200 Subject: [PATCH 4/5] export patternify --- packages/core/pattern.mjs | 64 ++------------------------------------- 1 file changed, 3 insertions(+), 61 deletions(-) diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index 938a2d96..7e82ec44 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -935,18 +935,18 @@ export function makeComposable(func) { return func; } -const patternify2 = (f) => (pata, patb, pat) => +export const patternify2 = (f) => (pata, patb, pat) => pata .fmap((a) => (b) => f.call(pat, a, b)) .appLeft(patb) .innerJoin(); -const patternify3 = (f) => (pata, patb, patc, pat) => +export const patternify3 = (f) => (pata, patb, patc, pat) => pata .fmap((a) => (b) => (c) => f.call(pat, a, b, c)) .appLeft(patb) .appLeft(patc) .innerJoin(); -const patternify4 = (f) => (pata, patb, patc, patd, pat) => +export const patternify4 = (f) => (pata, patb, patc, patd, pat) => pata .fmap((a) => (b) => (c) => (d) => f.call(pat, a, b, c, d)) .appLeft(patb) @@ -1030,61 +1030,3 @@ Pattern.prototype.define = (name, func, options = {}) => { // Pattern.prototype.define('early', (a, pat) => pat.early(a), { patternified: true, composable: true }); Pattern.prototype.define('hush', (pat) => pat.hush(), { patternified: false, composable: true }); Pattern.prototype.define('bypass', (pat) => pat.bypass(on), { patternified: true, composable: true }); -<<<<<<< HEAD:packages/core/strudel.mjs - -export { - Fraction, - Hap, - Pattern, - TimeSpan, - add, - append, - cat, - chunk, - chunkBack, - div, - early, - echo, - every, - fast, - fastcat, - id, - inv, - invert, - iter, - iterBack, - jux, - juxBy, - late, - linger, - mask, - mul, - off, - ply, - pm, - polymeter, - polymeterSteps, - polyrhythm, - pr, - pure, - range, - range2, - reify, - rev, - sequence, - silence, - slow, - slowcat, - stack, - struct, - sub, - superimpose, - timeCat, - union, - when, - patternify2, - patternify3, - patternify4, -}; -======= ->>>>>>> origin/main:packages/core/pattern.mjs From 61892bdf3de12a25ce477607eb7b596df347dbad Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Wed, 13 Apr 2022 23:58:51 +0200 Subject: [PATCH 5/5] fix minirepl import --- repl/src/tutorial/MiniRepl.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repl/src/tutorial/MiniRepl.jsx b/repl/src/tutorial/MiniRepl.jsx index 8adbd625..7d49c9d5 100644 --- a/repl/src/tutorial/MiniRepl.jsx +++ b/repl/src/tutorial/MiniRepl.jsx @@ -6,7 +6,7 @@ import cx from '../cx'; // eval stuff start import { extend } from '@strudel.cycles/eval'; -import * as strudel from '@strudel.cycles/core/strudel.mjs'; +import * as strudel from '@strudel.cycles/core'; import gist from '@strudel.cycles/core/gist.js'; import { mini } from '@strudel.cycles/mini/mini.mjs'; import { Tone } from '@strudel.cycles/tone';