From 7aaab0c78b4fdd3fe899b08c0cf5e8a8734102ce Mon Sep 17 00:00:00 2001 From: trian-gles <69212477+trian-gles@users.noreply.github.com> Date: Wed, 3 Jul 2024 20:47:57 +0200 Subject: [PATCH] saving and loading --- example.maxpat | 195 +++++++++++++++++++++++++++++++++++++++++-------- lfogui.js | 32 +++++++- 2 files changed, 195 insertions(+), 32 deletions(-) diff --git a/example.maxpat b/example.maxpat index 2593b7a..1f3d717 100644 --- a/example.maxpat +++ b/example.maxpat @@ -10,7 +10,7 @@ } , "classnamespace" : "box", - "rect" : [ 134.0, 134.0, 922.0, 715.0 ], + "rect" : [ 2115.0, 234.0, 922.0, 715.0 ], "bglocked" : 0, "openinpresentation" : 0, "default_fontsize" : 12.0, @@ -39,6 +39,118 @@ "subpatcher_template" : "", "assistshowspatchername" : 0, "boxes" : [ { + "box" : { + "id" : "obj-15", + "maxclass" : "message", + "numinlets" : 2, + "numoutlets" : 1, + "outlettype" : [ "" ], + "patching_rect" : [ 268.0, 377.0, 121.0, 22.0 ], + "text" : "dictionary secret_dict" + } + + } +, { + "box" : { + "data" : { + + } +, + "id" : "obj-4", + "maxclass" : "newobj", + "numinlets" : 2, + "numoutlets" : 5, + "outlettype" : [ "dictionary", "", "", "", "" ], + "patching_rect" : [ 693.0, 69.0, 159.0, 22.0 ], + "saved_object_attributes" : { + "embed" : 1, + "legacy" : 0, + "parameter_enable" : 0, + "parameter_mappable" : 0 + } +, + "text" : "dict localStorage @embed 1" + } + + } +, { + "box" : { + "id" : "obj-11", + "maxclass" : "button", + "numinlets" : 1, + "numoutlets" : 1, + "outlettype" : [ "bang" ], + "parameter_enable" : 0, + "patching_rect" : [ 693.0, 8.0, 24.0, 24.0 ] + } + + } +, { + "box" : { + "id" : "obj-5", + "maxclass" : "dict.view", + "numinlets" : 1, + "numoutlets" : 0, + "patching_rect" : [ 644.0, 392.0, 284.0, 255.0 ] + } + + } +, { + "box" : { + "id" : "obj-10", + "maxclass" : "newobj", + "numinlets" : 1, + "numoutlets" : 0, + "patching_rect" : [ 421.0, 471.0, 91.0, 22.0 ], + "text" : "print @popup 1" + } + + } +, { + "box" : { + "id" : "obj-9", + "maxclass" : "button", + "numinlets" : 1, + "numoutlets" : 1, + "outlettype" : [ "bang" ], + "parameter_enable" : 0, + "patching_rect" : [ 134.0, 232.0, 24.0, 24.0 ] + } + + } +, { + "box" : { + "id" : "obj-7", + "linecount" : 2, + "maxclass" : "message", + "numinlets" : 2, + "numoutlets" : 1, + "outlettype" : [ "" ], + "patching_rect" : [ 121.0, 399.0, 50.0, 36.0 ], + "text" : "dictionary hi" + } + + } +, { + "box" : { + "id" : "obj-1", + "maxclass" : "newobj", + "numinlets" : 2, + "numoutlets" : 5, + "outlettype" : [ "dictionary", "", "", "", "" ], + "patching_rect" : [ 106.0, 289.0, 61.0, 22.0 ], + "saved_object_attributes" : { + "embed" : 0, + "legacy" : 0, + "parameter_enable" : 0, + "parameter_mappable" : 0 + } +, + "text" : "dict hi" + } + + } +, { "box" : { "id" : "obj-6", "linecount" : 2, @@ -68,7 +180,7 @@ "maxclass" : "comment", "numinlets" : 1, "numoutlets" : 0, - "patching_rect" : [ 681.0, 43.0, 150.0, 20.0 ], + "patching_rect" : [ 732.0, 34.0, 150.0, 20.0 ], "text" : "Storage for the matrix" } @@ -96,34 +208,6 @@ "text" : "dump" } - } -, { - "box" : { - "data" : { - "foo" : { - "lfos" : [ "0.2", "1", "3" ], - "matrix" : [ [ "90", "10", "48" ], [ "5", "3", "251" ], [ "-61", "8", "98" ] ], - "paramNames" : [ "carrierFreq", "modFreq", "modDepth" ] - } - - } -, - "id" : "obj-4", - "maxclass" : "newobj", - "numinlets" : 2, - "numoutlets" : 5, - "outlettype" : [ "dictionary", "", "", "", "" ], - "patching_rect" : [ 681.0, 69.0, 159.0, 22.0 ], - "saved_object_attributes" : { - "embed" : 1, - "legacy" : 0, - "parameter_enable" : 0, - "parameter_mappable" : 0 - } -, - "text" : "dict localStorage @embed 1" - } - } , { "box" : { @@ -176,6 +260,29 @@ } ], "lines" : [ { + "patchline" : { + "destination" : [ "obj-2", 0 ], + "order" : 0, + "source" : [ "obj-1", 0 ] + } + + } +, { + "patchline" : { + "destination" : [ "obj-7", 1 ], + "order" : 1, + "source" : [ "obj-1", 0 ] + } + + } +, { + "patchline" : { + "destination" : [ "obj-4", 0 ], + "source" : [ "obj-11", 0 ] + } + + } +, { "patchline" : { "destination" : [ "obj-2", 0 ], "source" : [ "obj-12", 0 ] @@ -195,6 +302,13 @@ "source" : [ "obj-14", 0 ] } + } +, { + "patchline" : { + "destination" : [ "obj-10", 0 ], + "source" : [ "obj-15", 0 ] + } + } , { "patchline" : { @@ -202,6 +316,13 @@ "source" : [ "obj-18", 0 ] } + } +, { + "patchline" : { + "destination" : [ "obj-10", 0 ], + "source" : [ "obj-2", 0 ] + } + } , { "patchline" : { @@ -225,6 +346,20 @@ "source" : [ "obj-3", 0 ] } + } +, { + "patchline" : { + "destination" : [ "obj-5", 0 ], + "source" : [ "obj-4", 0 ] + } + + } +, { + "patchline" : { + "destination" : [ "obj-1", 0 ], + "source" : [ "obj-9", 0 ] + } + } ], "dependency_cache" : [ ], diff --git a/lfogui.js b/lfogui.js index 0ec67df..a35f3e2 100644 --- a/lfogui.js +++ b/lfogui.js @@ -1,7 +1,7 @@ // const { createElement } = require("./react"); -const log = console.log; -// const log = window.max.outlet; +// const log = console.log; +const log = window.max.outlet; const e = React.createElement; @@ -82,6 +82,28 @@ function MasterLfoHandler(){ const allSetters = [setVisibleArr, setShapeArr, setDjParamArr, setFreqArr, setAmpArr, setPhaseArr]; const blankVals = [true, 'Sine', '1', '1', '0']; + React.useEffect(() => { + function handleLoad(event) { + window.max.getDict(event.detail, (dict) => { + + }) + } + + function handleSave(event) { + window.max.setDict(event.detail, {"data" : allArrays}); + } + + + window.addEventListener('loadDict', handleLoad); + + window.addEventListener('saveDict', handleSave); + + return () => { + window.removeEventListener('loadDict', handleLoad); + window.removeEventListener('loadDict', handleSave); + }; + }, []); + createParamChanger = (arr, setArr, index) => { return (event) => { @@ -160,7 +182,13 @@ function MasterLfoHandler(){ } +window.max.bindInlet("load", (dictId) => { + window.dispatchEvent(new CustomEvent('loadDict', {'detail' : dictId})); +}); +window.max.bindInlet("save", (dictId) => { + window.dispatchEvent(new CustomEvent('saveDict', {'detail' : dictId})); +}) const root = ReactDOM.createRoot(document.getElementById('lfo-container')); root.render(e(MasterLfoHandler, null, null)); \ No newline at end of file