HISE Logo Forum
    • Categories
    • Register
    • Login

    Questions about handling persistent data in panels

    Scheduled Pinned Locked Moved Scripting
    14 Posts 5 Posters 429 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • SimonS
      Simon @ustk
      last edited by

      @ustk You can't store strings to value. I believe the example was assuming that when retrieving the value, you'd go

      this.data.values = ["First Item", "Second Item", "Third Item"];
      this.data.setValue(0);
      
      var gimmeTheValue = this.data.values[this.data.getValue()];
      

      More generally I think Christoph was getting at the idea of only storing integers to value whenever possible, and using a lookup table if you need something more complex.

      That said I've been using a panel to store a big ol object with nested objects and arrays, and haven't noticed anything suspicious, so I'm not sure if he knows something we don't or if it's just cleaner that way.

      I tried to provide some clarity to the docs here, feel free to contribute: https://github.com/christophhart/hise_documentation/pull/48

      ustkU VirtualVirginV 2 Replies Last reply Reply Quote 1
      • ustkU
        ustk @Simon
        last edited by

        @Simon Oh absolutely yes! My mistake!
        You can store objects, not strings. My example is very bad, I should have placed the string in an object first ☺

        const var values = ["First Item", "Second Item", "Third Item"]; // script the array if the project allows for it...
        Panel.setValue([values[0]]);
        // or
        Panel.setValue({myVal: values[0]});
        

        Can't help pressing F5 in the forum...

        1 Reply Last reply Reply Quote 0
        • O
          Orvillain
          last edited by

          I would guess you can store references to global objects inside a panel right?

          So you could have a global array, store a reference to it in this.data.values, and then access that array from inside the panel by setting and getting a value?

          So...

          const global_array = [0, 1, 2, 3, 4, 5]
          

          Then later:

          this.data.values = [global_array];
          this.data.setValue(0);
          
          var access_global_array = this.data.values[this.data.getValue()];
          Console.print(access_global_array[3]);
          

          Would something like that work?

          1 Reply Last reply Reply Quote 0
          • VirtualVirginV
            VirtualVirgin @Simon
            last edited by

            @Simon said in Questions about handling persistent data in panels:

            @ustk You can't store strings to value. I believe the example was assuming that when retrieving the value, you'd go

            this.data.values = ["First Item", "Second Item", "Third Item"];
            this.data.setValue(0);
            
            var gimmeTheValue = this.data.values[this.data.getValue()];
            

            More generally I think Christoph was getting at the idea of only storing integers to value whenever possible, and using a lookup table if you need something more complex.

            That said I've been using a panel to store a big ol object with nested objects and arrays, and haven't noticed anything suspicious, so I'm not sure if he knows something we don't or if it's just cleaner that way.

            I tried to provide some clarity to the docs here, feel free to contribute: https://github.com/christophhart/hise_documentation/pull/48

            So I am confused on the purpose of this method...
            If the set/getValue() is only going to be storing an index of an array and not the actual array value, then how does the value "persist" and load on compile?
            "this.data.values" array will just get wiped on compile so if that array is supposed to be dynamic, then none of the changes actually "persist" to get reloaded.

            You can listen to my orchestral mockups here:
            https://www.virtualvirgin.net/

            ustkU 1 Reply Last reply Reply Quote 0
            • ustkU
              ustk @VirtualVirgin
              last edited by ustk

              @VirtualVirgin Then you can set both in an object and recall

              // set
              Panel.setValue({ar: values, idx: 2}); // holds the dynamic values array and the current index
              
              // recall later
              panel.getValue().ar[panel.getValue().idx)]; // "Third Item"
              

              Can't help pressing F5 in the forum...

              1 Reply Last reply Reply Quote 0
              • VirtualVirginV
                VirtualVirgin
                last edited by VirtualVirgin

                So I have become very confused about storing persistent data in panels.
                My recent attempts at persistent panel data are not behaving in ways that I expected in that the data is not persisting.

                Here are two basic snippets-
                In this first one I store a value in the panel's value:

                const Panel1 = Content.getComponent("Panel1");
                Panel1.set("saveInPreset", true);
                
                
                Panel1.setValue
                ({
                	"testValue" : "yes"
                });
                
                
                const testValuePersistence = Panel1.getValue().testValue;
                Console.print("value persistence: " + testValuePersistence);
                
                HiseSnippet 885.3ocsV88aaaCDlxIpnVaEnEnuz2D7SNqAAxtIM0KXXtwIoyXKoB0oACXsnfl5rMQjHEHoxlwP+ed+GrcTR1RtwYsvn0OX362e732czgJICzZoh33c47Tf378tilKLyFLixEjgmPbdh6kf1vES8SAklqMfv3GQMTxwySoZMDQbb15UV2cZtMI+y+7yGSioBFTohPtRxYvuwS3lJsg8+Udb7YzH3RdRMu2u+PlTLPFKyPnska.IkxtlNEtfZcqgK4Wn5YDmevkw1uG7hIcOLnaO3fn8G2sS.saPudGBzCBXi6AztSFyBHN26zHtQpFYnFPSb19XYz7Qyj+onn.Ww07wwfUnCYDV4B0mIiirGQqVxfY73nvE8LMAyRXUGbqhN3icOmGwWpupS9vbC9UQTuA5zXU3s0JvqSc3ETCdqARN0fz1EP5QtiXJdpoxhEOem6PgATSn38TcnT3KowAMbGHE1668RnWCmoPgkQz94AA65iesyQdd3ck13GREPbG+exeQTSAy.YRpTfBsaUXtE5ewu1SCnVM8FXnHTAnTqc8MpLvlwZ9bEMNC7Z+2dMagclBwV9+neq4ftk2Gy8t..KMGtfox.DNkoZZYpZuydKc7HODqZYLrWphaA4MVsULcFf0w+oqMy1BOISvLbovWJtPZfWKZuiGBTuO54+ollLYs1r8JkLNFTElUvz7p8RkhNuV05dmGjbO+if2ejWyO4vPsVVbXnqbXtU5wSyp.yNPp9+fbaQVxXPsqedOaoiHoaUlr6cyjqOnwJHM0bTJFJ3lWmBh6Z7iTxzrr9RTgtZx47OXAm21zHbjYee2hFHIGv0WMQd6vSrazJSClQrJXeyvsG.mSfavUWEiRMcOAzWajo49VRtwC4msn+0xB1Wzedkv65WeD.yjiS9lwaMDiqOjQYwTyp6TradKMfWOqLHaGVEZtYd8Mye0Vz7kBwG4FxMrYqGiMVCFwqguEXrb87CbOcxDfYp.31tm86ea1ESdiLy9z44TihiD.2KxRFgOow.r5BjVXGObZXIxExAVYaGXDHhxE9W7SowNKHGVicVXjjPYJ4GXEze6C.2OWChIQ9ikMcO2J6uFdeB9dzGXrUS0sBr6lF3y1z.2eSC7fMMvmuoAd3lF3K97AZ+6BuLyHSJFaHjyCOMeOkiyoBJx.yYqj+CvT5HbM
                

                In the second one, I comment out the "setValue()" to see if the panel will recall the value that I input:

                const Panel1 = Content.getComponent("Panel1");
                Panel1.set("saveInPreset", true);
                
                /*
                Panel1.setValue
                ({
                	"testValue" : "yes"
                });
                */
                
                const testValuePersistence = Panel1.getValue().testValue;
                Console.print("value persistence: " + testValuePersistence);
                

                The first example prints the value from the panel to show it has been stored.
                The second example comments out the "setValue" then prints the panel's value to see if it persists, and it does not:
                the Console prints "undefined".

                Scratching my head, especially because I have made this feature work in the past...
                There must be something fundamental I am missing.

                You can listen to my orchestral mockups here:
                https://www.virtualvirgin.net/

                1 Reply Last reply Reply Quote 0
                • VirtualVirginV
                  VirtualVirgin
                  last edited by VirtualVirgin

                  Also bizarre, is that if I amend the first example (the one with the "setValue" included) and I try to print the value from the OnController callback,
                  I get "undefined", whereas that same compile will print the value onInit.

                  Screenshot 2025-02-27 at 3.46.38 PM.png

                  Screenshot 2025-02-27 at 3.50.07 PM.png

                  How can that same panel value be both defined and undefined?

                  You can listen to my orchestral mockups here:
                  https://www.virtualvirgin.net/

                  ustkU d.healeyD 2 Replies Last reply Reply Quote 0
                  • ustkU
                    ustk @VirtualVirgin
                    last edited by

                    @VirtualVirgin I don't know if it'll help, but I know it makes a difference wether you recompile the script or the interface. The values are not recalled the same way, so to be sure of your testing procedure, recompile on the interface window

                    Can't help pressing F5 in the forum...

                    1 Reply Last reply Reply Quote 0
                    • d.healeyD
                      d.healey @VirtualVirgin
                      last edited by

                      @VirtualVirgin on init runs before the value is restored, so all you are seeing on line 14 is the value as you set it on line 9. Then on init completes and the stored valued is loaded into the panel which is what you see in your on controller callback - you can use a local variable there instead of a reg.

                      Libre Wave - Freedom respecting instruments and effects
                      My Patreon - HISE tutorials
                      YouTube Channel - Public HISE tutorials

                      VirtualVirginV 1 Reply Last reply Reply Quote 0
                      • VirtualVirginV
                        VirtualVirgin @d.healey
                        last edited by

                        @d-healey said in Questions about handling persistent data in panels:

                        @VirtualVirgin on init runs before the value is restored, so all you are seeing on line 14 is the value as you set it on line 9. Then on init completes and the stored valued is loaded into the panel which is what you see in your on controller callback - you can use a local variable there instead of a reg.

                        Thanks :)
                        So how does that leave the onController recall of the value "undefined"? The reason I added that was to see what happens if I try to recall the value after onInit had completed and the persistent value restoration should be loaded. Why would the value I set for the panel onInit then not be available? Does it mean that it cannot save values that are set onInit and that all of the values that it will restore must be entered dynamically through callbacks after onInit? I am just trying to wrap my head around the mechanics here so I can know what to expect of the feature.

                        You can listen to my orchestral mockups here:
                        https://www.virtualvirgin.net/

                        d.healeyD 1 Reply Last reply Reply Quote 0
                        • d.healeyD
                          d.healey @VirtualVirgin
                          last edited by

                          @VirtualVirgin said in Questions about handling persistent data in panels:

                          Why would the value I set for the panel onInit then not be available?

                          After on init completes the value is overwritten by whatever the last saved value was, since you only ever set the value in on init the last saved value - a value set after on init - will be undefined.

                          Try it with a slider, set it's value in on init, hit compile and you will see the slider ignores the value you've set.

                          @VirtualVirgin said in Questions about handling persistent data in panels:

                          Does it mean that it cannot save values that are set onInit and that all of the values that it will restore must be entered dynamically through callbacks after onInit?

                          Yes

                          See this old thread for more details and examples - https://forum.hise.audio/topic/52/variable-persistence?_=1740706214240

                          Libre Wave - Freedom respecting instruments and effects
                          My Patreon - HISE tutorials
                          YouTube Channel - Public HISE tutorials

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post

                          9

                          Online

                          1.8k

                          Users

                          11.9k

                          Topics

                          103.7k

                          Posts