diff --git a/example.maxpat b/example.maxpat index da1938a..1e5b07d 100644 --- a/example.maxpat +++ b/example.maxpat @@ -3,14 +3,14 @@ "fileversion" : 1, "appversion" : { "major" : 8, - "minor" : 5, - "revision" : 6, + "minor" : 6, + "revision" : 2, "architecture" : "x64", "modernui" : 1 } , "classnamespace" : "box", - "rect" : [ 112.0, 87.0, 1344.0, 869.0 ], + "rect" : [ 34.0, 76.0, 981.0, 763.0 ], "bglocked" : 0, "openinpresentation" : 0, "default_fontsize" : 12.0, @@ -39,6 +39,65 @@ "subpatcher_template" : "", "assistshowspatchername" : 0, "boxes" : [ { + "box" : { + "id" : "obj-54", + "maxclass" : "newobj", + "numinlets" : 0, + "numoutlets" : 1, + "outlettype" : [ "" ], + "patching_rect" : [ 44.0, 528.5, 49.0, 22.0 ], + "text" : "r reload" + } + + } +, { + "box" : { + "id" : "obj-50", + "maxclass" : "comment", + "numinlets" : 1, + "numoutlets" : 0, + "patching_rect" : [ 233.5, 589.0, 150.0, 20.0 ], + "text" : "user definted LFO shape" + } + + } +, { + "box" : { + "id" : "obj-48", + "maxclass" : "newobj", + "numinlets" : 1, + "numoutlets" : 1, + "outlettype" : [ "" ], + "patching_rect" : [ 118.0, 606.5, 109.0, 22.0 ], + "text" : "prepend userWave" + } + + } +, { + "box" : { + "candicane2" : [ 0.145098, 0.203922, 0.356863, 1.0 ], + "candicane3" : [ 0.290196, 0.411765, 0.713726, 1.0 ], + "candicane4" : [ 0.439216, 0.619608, 0.070588, 1.0 ], + "candicane5" : [ 0.584314, 0.827451, 0.431373, 1.0 ], + "candicane6" : [ 0.733333, 0.035294, 0.788235, 1.0 ], + "candicane7" : [ 0.878431, 0.243137, 0.145098, 1.0 ], + "candicane8" : [ 0.027451, 0.447059, 0.501961, 1.0 ], + "contdata" : 1, + "id" : "obj-33", + "maxclass" : "multislider", + "numinlets" : 1, + "numoutlets" : 2, + "outlettype" : [ "", "" ], + "parameter_enable" : 0, + "patching_rect" : [ 118.0, 528.5, 162.0, 52.0 ], + "peakcolor" : [ 0.498039, 0.498039, 0.498039, 1.0 ], + "setminmax" : [ 0.0, 127.0 ], + "settype" : 0, + "size" : 50 + } + + } +, { "box" : { "id" : "obj-86", "maxclass" : "message", @@ -70,8 +129,8 @@ "numinlets" : 2, "numoutlets" : 1, "outlettype" : [ "" ], - "patching_rect" : [ 586.0, 713.0, 89.0, 35.0 ], - "text" : "harmoniclarity 5.770587" + "patching_rect" : [ 586.0, 713.0, 89.0, 36.0 ], + "text" : "harmoniclarity 40.156651" } } @@ -83,8 +142,8 @@ "numinlets" : 2, "numoutlets" : 1, "outlettype" : [ "" ], - "patching_rect" : [ 491.0, 713.0, 85.0, 35.0 ], - "text" : "event_length 64.229413" + "patching_rect" : [ 491.0, 713.0, 85.0, 36.0 ], + "text" : "event_length 29.843349" } } @@ -96,8 +155,8 @@ "numinlets" : 2, "numoutlets" : 1, "outlettype" : [ "" ], - "patching_rect" : [ 385.0, 715.0, 84.0, 35.0 ], - "text" : "metriclarity 84.617504" + "patching_rect" : [ 385.0, 715.0, 84.0, 36.0 ], + "text" : "metriclarity 22.176645" } } @@ -120,7 +179,7 @@ "maxclass" : "comment", "numinlets" : 1, "numoutlets" : 0, - "patching_rect" : [ 1066.052632331848145, 53.0, 99.894735336303711, 87.0 ], + "patching_rect" : [ 1066.052632331848145, 53.0, 99.894735336303711, 89.0 ], "text" : "You can use Hz, seconds, ms, hh:mm:ss, or bars.beats.ticks for the period/frequency" } @@ -132,8 +191,7 @@ "maxclass" : "comment", "numinlets" : 1, "numoutlets" : 0, - "patching_rect" : [ 1181.315790414810181, 40.0, 78.0, 114.0 ], - "presentation_linecount" : 8, + "patching_rect" : [ 1181.315790414810181, 40.0, 81.0, 117.0 ], "text" : "Min and max must be ADDED to the center value to determine the true bounds. " } @@ -145,7 +203,7 @@ "maxclass" : "comment", "numinlets" : 1, "numoutlets" : 0, - "patching_rect" : [ 913.0, 107.0, 150.0, 60.0 ], + "patching_rect" : [ 913.0, 107.0, 150.0, 62.0 ], "text" : "center values are read only, they must be configured by an upstream value" } @@ -229,7 +287,7 @@ "maxclass" : "newobj", "numinlets" : 1, "numoutlets" : 0, - "patching_rect" : [ 200.0, 807.0, 51.0, 22.0 ], + "patching_rect" : [ 939.0, 69.0, 51.0, 22.0 ], "text" : "s reload" } @@ -241,57 +299,10 @@ "numinlets" : 1, "numoutlets" : 5, "outlettype" : [ "preset", "int", "preset", "int", "" ], - "patching_rect" : [ 190.0, 752.0, 100.0, 40.0 ], + "patching_rect" : [ 934.0, 27.0, 100.0, 40.0 ], "pattrstorage" : "storage" } - } -, { - "box" : { - "id" : "obj-28", - "maxclass" : "newobj", - "numinlets" : 1, - "numoutlets" : 1, - "outlettype" : [ "" ], - "patching_rect" : [ 460.0, 789.0, 116.0, 22.0 ], - "saved_object_attributes" : { - "client_rect" : [ 4, 87, 990, 730 ], - "parameter_enable" : 0, - "parameter_mappable" : 0, - "storage_rect" : [ 583, 69, 1034, 197 ] - } -, - "text" : "pattrstorage storage", - "varname" : "storage" - } - - } -, { - "box" : { - "id" : "obj-26", - "maxclass" : "newobj", - "numinlets" : 1, - "numoutlets" : 3, - "outlettype" : [ "", "", "" ], - "patching_rect" : [ 643.0, 770.0, 40.0, 22.0 ], - "restore" : [ { - "data" : { - "enumArrays" : [ [ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], [ "2", "4", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1" ], [ "2", "4", 2, "2", "2", "2", "2", "2", "2", "2" ], [ "scale", "meter", "NONE", "attenuation", "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 ] ], [ [ "major", "minor", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "4 4", "3 4", "7 8", "2 4", "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", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ] ] ], - "modArrays" : [ [ 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], [ "1", "4", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1" ], [ "Sine", "Tri", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine" ], [ "metriclarity", "meter", "event_length", "harmoniclarity", "NONE", "NONE", "NONE", "NONE", "NONE", "NONE", "NONE", "NONE", "NONE", "NONE", "NONE", "NONE", "NONE", "NONE", "NONE", "NONE" ], [ "1hz", "0.4.0", "3s", "00:00:03", "1hz", "1hz", "1hz", "1hz", "1hz", "1hz", "1hz", "1hz", "1hz", "1hz", "1hz", "1hz", "1hz", "1hz", "1hz", "1hz" ], [ "20", "0", "20", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" ], [ "80", "2", "70", "50", "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" ] ] - } - - } - ], - "saved_object_attributes" : { - "parameter_enable" : 0, - "parameter_mappable" : 0 - } -, - "text" : "pattr", - "varname" : "u560003760" - } - } , { "box" : { @@ -307,11 +318,12 @@ "id" : "obj-25", "maxclass" : "newobj", "numinlets" : 2, - "numoutlets" : 4, - "outlettype" : [ "dictionary", "", "", "" ], + "numoutlets" : 5, + "outlettype" : [ "dictionary", "", "", "", "" ], "patching_rect" : [ 773.0, 808.0, 166.0, 22.0 ], "saved_object_attributes" : { "embed" : 1, + "legacy" : 1, "parameter_enable" : 0, "parameter_mappable" : 0 } @@ -363,7 +375,7 @@ "maxclass" : "comment", "numinlets" : 1, "numoutlets" : 0, - "patching_rect" : [ 137.5, 440.0, 246.0, 64.0 ], + "patching_rect" : [ 137.5, 440.0, 246.0, 66.0 ], "text" : "this param is sent in its already enumerated form, so it will first be turned into a number halfway between the enumeration boundaries" } @@ -388,7 +400,7 @@ "numoutlets" : 1, "outlettype" : [ "" ], "patching_rect" : [ 949.0, 647.0, 156.0, 22.0 ], - "text" : "meter 4 4" + "text" : "meter 3 4" } } @@ -435,7 +447,7 @@ "maxclass" : "comment", "numinlets" : 1, "numoutlets" : 0, - "patching_rect" : [ 504.0, 546.5, 268.0, 33.0 ], + "patching_rect" : [ 504.0, 546.5, 268.0, 34.0 ], "text" : "we can only output symbols from jweb, so this turns them into lists" } @@ -459,7 +471,7 @@ "maxclass" : "comment", "numinlets" : 1, "numoutlets" : 0, - "patching_rect" : [ 548.52631402015686, 80.0, 150.0, 33.0 ], + "patching_rect" : [ 548.52631402015686, 80.0, 150.0, 34.0 ], "text" : "see below for why we use separate names..." } @@ -471,7 +483,7 @@ "maxclass" : "comment", "numinlets" : 1, "numoutlets" : 0, - "patching_rect" : [ 781.0, 17.0, 150.0, 47.0 ], + "patching_rect" : [ 781.0, 17.0, 150.0, 48.0 ], "text" : "self explanatory. Warning-will overwrite whatever is saved." } @@ -483,7 +495,7 @@ "maxclass" : "comment", "numinlets" : 1, "numoutlets" : 0, - "patching_rect" : [ 1261.315790414810181, 47.0, 78.0, 100.0 ], + "patching_rect" : [ 1261.315790414810181, 47.0, 78.0, 103.0 ], "text" : "You can use the `phase` control to phase offset two LFOs of the same frequency" } @@ -496,7 +508,7 @@ "maxclass" : "comment", "numinlets" : 1, "numoutlets" : 0, - "patching_rect" : [ 161.5, 261.0, 197.0, 78.0 ], + "patching_rect" : [ 161.5, 261.0, 197.0, 79.0 ], "text" : "This parameter is defined in the enumerators but not the modulators. It will be enumerated and immediately output" } @@ -521,7 +533,7 @@ "maxclass" : "comment", "numinlets" : 1, "numoutlets" : 0, - "patching_rect" : [ 159.0, 347.0, 254.0, 51.0 ], + "patching_rect" : [ 159.0, 347.0, 254.0, 52.0 ], "text" : "This parameter is not defined by either the Modulators or Enumerators, so it will be passed directly to the output" } @@ -534,7 +546,7 @@ "maxclass" : "comment", "numinlets" : 1, "numoutlets" : 0, - "patching_rect" : [ 159.0, 190.0, 197.0, 64.0 ], + "patching_rect" : [ 159.0, 190.0, 197.0, 66.0 ], "text" : "This parameter is defined in the modulators, and when sent will act as the center value for that LFO" } @@ -546,7 +558,7 @@ "maxclass" : "comment", "numinlets" : 1, "numoutlets" : 0, - "patching_rect" : [ 45.0, 564.0, 254.0, 154.0 ], + "patching_rect" : [ 59.0, 634.0, 254.0, 158.0 ], "text" : "The operation runs\n\nInput > Denumeration > Modulators > Enumerators > Output\n\nA parameter from the input not established by a Modulator will be passed directly to the Enumerators\n\nLikewise, the Enumerators will pass not established parameters" } @@ -592,11 +604,12 @@ "id" : "obj-4", "maxclass" : "newobj", "numinlets" : 2, - "numoutlets" : 4, - "outlettype" : [ "dictionary", "", "", "" ], + "numoutlets" : 5, + "outlettype" : [ "dictionary", "", "", "", "" ], "patching_rect" : [ 980.368419170379639, 726.0, 97.0, 22.0 ], "saved_object_attributes" : { "embed" : 0, + "legacy" : 1, "parameter_enable" : 0, "parameter_mappable" : 0 } @@ -612,7 +625,7 @@ "maxclass" : "comment", "numinlets" : 1, "numoutlets" : 0, - "patching_rect" : [ 504.0, 6.0, 150.0, 33.0 ], + "patching_rect" : [ 504.0, 6.0, 150.0, 34.0 ], "text" : "required due to the asynchronous operation" } @@ -624,7 +637,7 @@ "maxclass" : "comment", "numinlets" : 1, "numoutlets" : 0, - "patching_rect" : [ 773.0, 692.0, 150.0, 114.0 ], + "patching_rect" : [ 773.0, 692.0, 150.0, 117.0 ], "text" : "Storage for the matrix. Unfortunately, jsweb dictionary handling isn't great, so we can't use it like a native dict object and need to do this wild hack for usage with pattrstorage" } @@ -750,13 +763,6 @@ "source" : [ "obj-22", 0 ] } - } -, { - "patchline" : { - "destination" : [ "obj-25", 0 ], - "source" : [ "obj-26", 1 ] - } - } , { "patchline" : { @@ -785,6 +791,13 @@ "source" : [ "obj-32", 1 ] } + } +, { + "patchline" : { + "destination" : [ "obj-48", 0 ], + "source" : [ "obj-33", 0 ] + } + } , { "patchline" : { @@ -877,6 +890,13 @@ "source" : [ "obj-47", 4 ] } + } +, { + "patchline" : { + "destination" : [ "obj-2", 0 ], + "source" : [ "obj-48", 0 ] + } + } , { "patchline" : { @@ -891,6 +911,13 @@ "source" : [ "obj-52", 0 ] } + } +, { + "patchline" : { + "destination" : [ "obj-33", 0 ], + "source" : [ "obj-54", 0 ] + } + } , { "patchline" : { diff --git a/lfogui.js b/lfogui.js index ee5aeff..29946c1 100644 --- a/lfogui.js +++ b/lfogui.js @@ -45,6 +45,8 @@ function MasterLfoHandler(){ /// MODULATOR ARRAYS + const [userDefinedWave, setUserDefinedWave] = React.useState(Array(50).fill(0)); + const [modVisibleArr, setModVisibleArr] = React.useState(initVisArr); const [modInstanceNumArr, setModInstanceNumArr] = React.useState(Array(MAXLFOS).fill('1')); @@ -198,7 +200,7 @@ function MasterLfoHandler(){ function handleTick(event) { let time = (Date.now() - firstUpdateTime) / 1000; - operateModulators(modVisibleArr, modInstanceNumArr, djParamArr, modCenterVals, freqArr, minArr, maxArr, shapeArr, phaseArr, time, bpm, beatsInMeasure); + operateModulators(modVisibleArr, modInstanceNumArr, djParamArr, modCenterVals, freqArr, minArr, maxArr, shapeArr, phaseArr, userDefinedWave, time, bpm, beatsInMeasure); } function handleBpm(event) { @@ -209,6 +211,10 @@ function MasterLfoHandler(){ setBeatsInMeasure(parseFloat(event.detail[0]) * parseFloat(event.detail[1])/ 4); } + function handleChangeUserWave(event){ + setUserDefinedWave(event.detail); + } + window.addEventListener('loadDict', handleLoad); window.addEventListener('saveDict', handleSave); @@ -217,6 +223,7 @@ function MasterLfoHandler(){ window.addEventListener('enum', handleEnum); window.addEventListener('tempo', handleBpm); window.addEventListener('timesig', handleTimeSig); + window.addEventListener('userWave', handleChangeUserWave); return () => { window.removeEventListener('loadDict', handleLoad); @@ -226,6 +233,7 @@ function MasterLfoHandler(){ window.removeEventListener('enum', handleEnum); window.removeEventListener('tempo', handleBpm); window.removeEventListener('timesig', handleTimeSig); + window.removeEventListener('userWave', handleChangeUserWave); }; }, [...allModArrays, ...allEnumArrays, ...allEnumMats, modCenterVals, render, bpm, beatsInMeasure]); @@ -432,6 +440,16 @@ if (!DEBUG){ window.dispatchEvent(new CustomEvent('timesig', {'detail' : [top, bottom]})); }); + window.max.bindInlet("userWave", (...points) => { + window.dispatchEvent(new CustomEvent('userWave', {'detail' : points})); + }); + + +/* window.max.binInlet("userWave", (...points) => { + window.dispatchEvent(new CustomEvent('userWave', {'detail' : [points]})); + log("received user points"); + }); */ + setInterval(() => { window.dispatchEvent(new CustomEvent('tick')); }, 200); diff --git a/modulators.js b/modulators.js index 23e7e0d..483c889 100644 --- a/modulators.js +++ b/modulators.js @@ -2,7 +2,7 @@ // MODULATORS ///////////////////////// -var SHAPETYPES = ["Sine", "SawUp", "SawDown", "Tri", "Square"]; +var SHAPETYPES = ["Sine", "SawUp", "SawDown", "Tri", "Square", "Custom"]; var INSTANCEOPTIONS = ["1", "2", "3", "4"]; @@ -44,7 +44,7 @@ function LfoRow(props){ }; } -function indexWave(type, phase){ +function indexWave(type, phase, userDefinedWave){ switch (type){ case "Sine": return (Math.sin(phase * Math.PI * 2) / 2) + 0.5; @@ -56,10 +56,12 @@ function indexWave(type, phase){ return phase > 0.5? (1-phase) * 2 : phase * 2; case "Square": return +(phase > 0.5); + case "Custom": + return parseFloat(userDefinedWave[Math.floor(phase * 50)]) / 127 } } -function operateModulators(visibleArr, instanceNumArr, paramNames, centers, freqs, mins, maxs, waveTypes, phaseArr, currTime, bpm, beatsInMeasure){ +function operateModulators(visibleArr, instanceNumArr, paramNames, centers, freqs, mins, maxs, waveTypes, phaseArr, userDefinedWave, currTime, bpm, beatsInMeasure){ for (let i=0; i