From 6e1da9fb5985d32792fbfab339e5ddb846166844 Mon Sep 17 00:00:00 2001 From: Kieran McAuliffe Date: Mon, 22 Jul 2024 16:03:47 +0200 Subject: [PATCH] phase control --- common.js | 6 +-- enums.js | 2 +- example.maxpat | 110 ++++++++++++++++++++++++++----------------------- lfogui.js | 12 ++---- modulators.js | 12 +++--- 5 files changed, 71 insertions(+), 71 deletions(-) diff --git a/common.js b/common.js index 59c8f6c..c84a876 100644 --- a/common.js +++ b/common.js @@ -16,7 +16,7 @@ function NumberBox(props){ } function TextBox(props){ - return e('input', {type: "text", value: props.value, onChange: props.onChange}); + return e('input', {type: "text", value: props.value, onChange: props.onChange, id: props.id}); } function Option(str, value){ @@ -33,12 +33,12 @@ function Switch(props){ e('span', {className: 'slider round'}, null)) } -function CreateParamChanger(arr, setArr, index){ +function CreateParamChanger(arr, setArr, index, cb=() => {}){ return (event) => { let newArr = arr.slice(); newArr[index] = event.target.value; setArr(newArr); - + cb(); log(`${index} ${event.target.value}`); } } diff --git a/enums.js b/enums.js index 3c39595..0396ad9 100644 --- a/enums.js +++ b/enums.js @@ -52,6 +52,6 @@ function enumerate(name, inval, count, keys, vals){ } - //window.max.outlet(name + " " + output); + window.max.outlet(name + " " + output); } diff --git a/example.maxpat b/example.maxpat index a19b096..e54907d 100644 --- a/example.maxpat +++ b/example.maxpat @@ -39,15 +39,63 @@ "subpatcher_template" : "", "assistshowspatchername" : 0, "boxes" : [ { + "box" : { + "id" : "obj-28", + "linecount" : 2, + "maxclass" : "message", + "numinlets" : 2, + "numoutlets" : 1, + "outlettype" : [ "" ], + "patching_rect" : [ 493.0, 444.0, 161.0, 35.0 ], + "text" : "\"harmoniclarity 0.572005391276114\"" + } + + } +, { + "box" : { + "id" : "obj-19", + "maxclass" : "comment", + "numinlets" : 1, + "numoutlets" : 0, + "patching_rect" : [ 541.52631402015686, 69.0, 150.0, 20.0 ], + "text" : "self explanatory" + } + + } +, { + "box" : { + "id" : "obj-14", + "linecount" : 3, + "maxclass" : "comment", + "numinlets" : 1, + "numoutlets" : 0, + "patching_rect" : [ 817.0, 45.0, 150.0, 47.0 ], + "text" : "self explanatory. Warning-will overwrite whatever is saved." + } + + } +, { + "box" : { + "id" : "obj-11", + "linecount" : 4, + "maxclass" : "comment", + "numinlets" : 1, + "numoutlets" : 0, + "patching_rect" : [ 1054.0, 325.0, 150.0, 60.0 ], + "text" : "You can use the `phase` control to phase offset two LFOs of the same frequency" + } + + } +, { "box" : { "id" : "obj-7", "linecount" : 3, "maxclass" : "comment", "numinlets" : 1, "numoutlets" : 0, - "patching_rect" : [ 89.0, 227.0, 197.0, 47.0 ], + "patching_rect" : [ 109.0, 285.0, 197.0, 47.0 ], "presentation_linecount" : 3, - "text" : "This parameter is defined in the modulators, and when sent will act as the center value for that LFO" + "text" : "This parameter is defined in the enumerators but not the modulators" } } @@ -58,7 +106,7 @@ "numinlets" : 2, "numoutlets" : 1, "outlettype" : [ "" ], - "patching_rect" : [ 126.0, 276.0, 94.0, 22.0 ], + "patching_rect" : [ 146.0, 334.0, 94.0, 22.0 ], "text" : "param scale 1.6" } @@ -94,7 +142,7 @@ "maxclass" : "comment", "numinlets" : 1, "numoutlets" : 0, - "patching_rect" : [ 126.0, 135.0, 197.0, 47.0 ], + "patching_rect" : [ 115.0, 201.0, 197.0, 47.0 ], "text" : "This parameter is defined in the modulators, and when sent will act as the center value for that LFO" } @@ -118,22 +166,10 @@ "numinlets" : 2, "numoutlets" : 1, "outlettype" : [ "" ], - "patching_rect" : [ 146.0, 193.0, 121.0, 22.0 ], + "patching_rect" : [ 135.0, 259.0, 121.0, 22.0 ], "text" : "param metriclarity 40" } - } -, { - "box" : { - "id" : "obj-17", - "linecount" : 2, - "maxclass" : "comment", - "numinlets" : 1, - "numoutlets" : 0, - "patching_rect" : [ 734.0, 39.0, 150.0, 33.0 ], - "text" : "question for Georg: what should `phase` do?" - } - } , { "box" : { @@ -165,7 +201,7 @@ "data" : { "enumArrays" : [ [ 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], [ "2", 2, 2, 2, "2", "2", "2", "2", "2", "2" ], [ "event_length", "meter", "stream", "scale", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation" ] ], "enumMats" : [ [ [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ "0", "1", "2", 3, 4, 5, 6, 7, 8, 9, 10 ], [ "0", "1", "2", 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] ], [ [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "3 4", "7 8", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "0", "1", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "pentatonic", "major", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ] ] ], - "modArrays" : [ [ 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], [ "Sine", "SawUp", "SawDown", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine" ], [ "metriclarity", "stream", "meter", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation" ], [ "1", "0.3", "0.1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1" ], [ "30", "2", "2", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1" ], [ "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" ] ] + "modArrays" : [ [ 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], [ "Sine", "SawUp", "SawDown", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine" ], [ "metriclarity", "stream", "meter", "harmoniclarity", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation" ], [ "0.6", "0.3", "0.1", "0.6", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1" ], [ "30", "2", "2", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1" ], [ "0", "0", "0", "0.5", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" ] ] } } @@ -175,7 +211,7 @@ "numinlets" : 2, "numoutlets" : 4, "outlettype" : [ "dictionary", "", "", "" ], - "patching_rect" : [ 548.0, 604.0, 159.0, 22.0 ], + "patching_rect" : [ 22.0, 102.0, 159.0, 22.0 ], "saved_object_attributes" : { "embed" : 1, "parameter_enable" : 0, @@ -185,17 +221,6 @@ "text" : "dict localStorage @embed 1" } - } -, { - "box" : { - "id" : "obj-10", - "maxclass" : "newobj", - "numinlets" : 1, - "numoutlets" : 0, - "patching_rect" : [ 424.52631402015686, 484.473682403564453, 91.0, 22.0 ], - "text" : "print @popup 1" - } - } , { "box" : { @@ -228,7 +253,7 @@ "maxclass" : "comment", "numinlets" : 1, "numoutlets" : 0, - "patching_rect" : [ 557.0, 520.0, 150.0, 74.0 ], + "patching_rect" : [ 31.0, 18.0, 150.0, 74.0 ], "text" : "Storage for the matrix. Unfortunately, jsweb dictionary handling isn't great, so we can't use it like a native dict object" } @@ -244,18 +269,6 @@ "text" : "loadbang" } - } -, { - "box" : { - "id" : "obj-14", - "maxclass" : "message", - "numinlets" : 2, - "numoutlets" : 1, - "outlettype" : [ "" ], - "patching_rect" : [ 623.789473533630371, 69.0, 39.0, 22.0 ], - "text" : "dump" - } - } , { "box" : { @@ -264,7 +277,7 @@ "numinlets" : 2, "numoutlets" : 1, "outlettype" : [ "" ], - "patching_rect" : [ 328.894735336303711, 69.0, 104.0, 22.0 ], + "patching_rect" : [ 700.894735336303711, 69.0, 104.0, 22.0 ], "text" : "save localStorage" } @@ -301,13 +314,6 @@ "source" : [ "obj-12", 0 ] } - } -, { - "patchline" : { - "destination" : [ "obj-2", 0 ], - "source" : [ "obj-14", 0 ] - } - } , { "patchline" : { @@ -332,7 +338,7 @@ } , { "patchline" : { - "destination" : [ "obj-10", 0 ], + "destination" : [ "obj-28", 1 ], "source" : [ "obj-2", 0 ] } diff --git a/lfogui.js b/lfogui.js index 8e13484..8456e4b 100644 --- a/lfogui.js +++ b/lfogui.js @@ -23,10 +23,9 @@ const ViewModes = Object.freeze({ var modPhases = Array(MAXLFOS).fill(0); var firstUpdateTime = Date.now(); -var lastUpdateTime = Date.now(); -const MODULATORLABELS = ["-type-", "---shape---", "----param----", "freq", "amp", "phase"]; -const ENUMERATORLABELS = ["--parameter--", "-points-"]; +const MODULATORLABELS = ["-type-", "---shape---", "-------param-------", "--freq--", "--amp--", "--phase--"]; +const ENUMERATORLABELS = ["---parameter---", "-# points-"]; function MasterLfoHandler(){ @@ -179,11 +178,8 @@ function MasterLfoHandler(){ } function handleTick(event) { - - let newTime = Date.now() - let delta = (newTime - lastUpdateTime) / 1000; - lastUpdateTime = newTime - operateModulators(modVisibleArr, djParamArr, modCenterVals, freqArr, ampArr, shapeArr, modPhases, delta); + let time = (Date.now() - firstUpdateTime) / 1000; + operateModulators(modVisibleArr, djParamArr, modCenterVals, freqArr, ampArr, shapeArr, phaseArr, time); } diff --git a/modulators.js b/modulators.js index 4bd63c6..9948d8d 100644 --- a/modulators.js +++ b/modulators.js @@ -45,7 +45,7 @@ function indexWave(type, phase){ } } -function operateModulators(visibleArr, paramNames, centers, freqs, amps, waveTypes, phaseArr, delta){ +function operateModulators(visibleArr, paramNames, centers, freqs, amps, waveTypes, phaseArr, time){ for (let i=0; i