From 45847fbae4f49547bf599eab5e4258010d2d2b4e Mon Sep 17 00:00:00 2001 From: trian-gles <69212477+trian-gles@users.noreply.github.com> Date: Tue, 3 Sep 2024 11:34:32 +0200 Subject: [PATCH] phase calculated from ticks --- example.maxpat | 89 ++++++++++++++++++++++++++++++++++++-------------- lfogui.js | 27 +++++++-------- modulators.js | 41 ++++++++++++----------- 3 files changed, 98 insertions(+), 59 deletions(-) diff --git a/example.maxpat b/example.maxpat index 1e5b07d..2619f50 100644 --- a/example.maxpat +++ b/example.maxpat @@ -10,7 +10,7 @@ } , "classnamespace" : "box", - "rect" : [ 34.0, 76.0, 981.0, 763.0 ], + "rect" : [ 34.0, 76.0, 1155.0, 763.0 ], "bglocked" : 0, "openinpresentation" : 0, "default_fontsize" : 12.0, @@ -39,6 +39,44 @@ "subpatcher_template" : "", "assistshowspatchername" : 0, "boxes" : [ { + "box" : { + "fontname" : "Arial", + "fontsize" : 13.0, + "id" : "obj-29", + "maxclass" : "newobj", + "numinlets" : 2, + "numoutlets" : 1, + "outlettype" : [ "bang" ], + "patching_rect" : [ 465.0, 141.0, 210.0, 23.0 ], + "text" : "metro @interval 40 ticks @active 1" + } + + } +, { + "box" : { + "id" : "obj-28", + "maxclass" : "button", + "numinlets" : 1, + "numoutlets" : 1, + "outlettype" : [ "bang" ], + "parameter_enable" : 0, + "patching_rect" : [ 826.0, 79.0, 24.0, 24.0 ] + } + + } +, { + "box" : { + "id" : "obj-3", + "maxclass" : "newobj", + "numinlets" : 1, + "numoutlets" : 1, + "outlettype" : [ "" ], + "patching_rect" : [ 817.0, 147.0, 80.0, 22.0 ], + "text" : "prepend ticks" + } + + } +, { "box" : { "id" : "obj-54", "maxclass" : "newobj", @@ -156,7 +194,7 @@ "numoutlets" : 1, "outlettype" : [ "" ], "patching_rect" : [ 385.0, 715.0, 84.0, 36.0 ], - "text" : "metriclarity 22.176645" + "text" : "metriclarity 0.5" } } @@ -244,18 +282,6 @@ "text" : "prepend timesig" } - } -, { - "box" : { - "id" : "obj-52", - "maxclass" : "newobj", - "numinlets" : 1, - "numoutlets" : 1, - "outlettype" : [ "" ], - "patching_rect" : [ 545.0, 135.0, 89.0, 22.0 ], - "text" : "prepend tempo" - } - } , { "box" : { @@ -299,8 +325,7 @@ "numinlets" : 1, "numoutlets" : 5, "outlettype" : [ "preset", "int", "preset", "int", "" ], - "patching_rect" : [ 934.0, 27.0, 100.0, 40.0 ], - "pattrstorage" : "storage" + "patching_rect" : [ 934.0, 27.0, 100.0, 40.0 ] } } @@ -784,6 +809,27 @@ "source" : [ "obj-27", 1 ] } + } +, { + "patchline" : { + "destination" : [ "obj-47", 0 ], + "source" : [ "obj-28", 0 ] + } + + } +, { + "patchline" : { + "destination" : [ "obj-47", 0 ], + "source" : [ "obj-29", 0 ] + } + + } +, { + "patchline" : { + "destination" : [ "obj-2", 0 ], + "source" : [ "obj-3", 0 ] + } + } , { "patchline" : { @@ -886,8 +932,8 @@ } , { "patchline" : { - "destination" : [ "obj-52", 0 ], - "source" : [ "obj-47", 4 ] + "destination" : [ "obj-3", 0 ], + "source" : [ "obj-47", 7 ] } } @@ -904,13 +950,6 @@ "source" : [ "obj-5", 0 ] } - } -, { - "patchline" : { - "destination" : [ "obj-2", 0 ], - "source" : [ "obj-52", 0 ] - } - } , { "patchline" : { diff --git a/lfogui.js b/lfogui.js index 29946c1..24281fa 100644 --- a/lfogui.js +++ b/lfogui.js @@ -52,7 +52,7 @@ function MasterLfoHandler(){ const [modCenterVals, setModCenterVals] = React.useState({'1':{}, '2':{}, '3':{}, '4':{}}); - const [bpm, setBpm] = React.useState(100); + const [ticks, setTicks] = React.useState(0); const [beatsInMeasure, setBeatsInMeasure] = React.useState(4); const [shapeArr, setShapeArr] = React.useState(Array(MAXLFOS).fill('Sine')); @@ -200,11 +200,8 @@ function MasterLfoHandler(){ function handleTick(event) { let time = (Date.now() - firstUpdateTime) / 1000; - operateModulators(modVisibleArr, modInstanceNumArr, djParamArr, modCenterVals, freqArr, minArr, maxArr, shapeArr, phaseArr, userDefinedWave, time, bpm, beatsInMeasure); - } - - function handleBpm(event) { - setBpm(event.detail); + + operateModulators(modVisibleArr, modInstanceNumArr, djParamArr, modCenterVals, freqArr, minArr, maxArr, shapeArr, phaseArr, userDefinedWave, time, beatsInMeasure, ticks); } function handleTimeSig(event) { @@ -215,15 +212,19 @@ function MasterLfoHandler(){ setUserDefinedWave(event.detail); } + function handleMaxTicks(event){ + setTicks(event.detail); + } + window.addEventListener('loadDict', handleLoad); window.addEventListener('saveDict', handleSave); window.addEventListener('tick', handleTick); window.addEventListener('param', handleParam); window.addEventListener('enum', handleEnum); - window.addEventListener('tempo', handleBpm); window.addEventListener('timesig', handleTimeSig); window.addEventListener('userWave', handleChangeUserWave); + window.addEventListener('maxTicks', handleMaxTicks); return () => { window.removeEventListener('loadDict', handleLoad); @@ -231,11 +232,11 @@ function MasterLfoHandler(){ window.removeEventListener('tick', handleTick); window.removeEventListener('param', handleParam); window.removeEventListener('enum', handleEnum); - window.removeEventListener('tempo', handleBpm); window.removeEventListener('timesig', handleTimeSig); window.removeEventListener('userWave', handleChangeUserWave); + window.removeEventListener('maxTicks', handleMaxTicks); }; - }, [...allModArrays, ...allEnumArrays, ...allEnumMats, modCenterVals, render, bpm, beatsInMeasure]); + }, [...allModArrays, ...allEnumArrays, ...allEnumMats, modCenterVals, render, beatsInMeasure, ticks]); function CheckLinked(inst, param, checkInstArr, checkParamArr){ @@ -432,14 +433,14 @@ if (!DEBUG){ window.dispatchEvent(new CustomEvent('param', {'detail' : [inst, paramName, val]})); }); - window.max.bindInlet("tempo", (val) => { - window.dispatchEvent(new CustomEvent('tempo', {'detail' : val})); - }); - window.max.bindInlet("timesig", (top, bottom) => { window.dispatchEvent(new CustomEvent('timesig', {'detail' : [top, bottom]})); }); + window.max.bindInlet("ticks", (val) => { + window.dispatchEvent(new CustomEvent('maxTicks', {'detail' : val})); + }); + window.max.bindInlet("userWave", (...points) => { window.dispatchEvent(new CustomEvent('userWave', {'detail' : points})); }); diff --git a/modulators.js b/modulators.js index fc8b991..dc4a778 100644 --- a/modulators.js +++ b/modulators.js @@ -66,7 +66,7 @@ function indexWave(type, phase, userDefinedWave){ } } -function operateModulators(visibleArr, instanceNumArr, paramNames, centers, freqs, mins, maxs, waveTypes, phaseArr, userDefinedWave, currTime, bpm, beatsInMeasure){ +function operateModulators(visibleArr, instanceNumArr, paramNames, centers, freqs, mins, maxs, waveTypes, phaseArr, userDefinedWave, currTime, beatsInMeasure, ticks){ for (let i=0; i