HISE Logo Forum
    • Categories
    • Register
    • Login

    Read & Write JSON file || Basics

    Scheduled Pinned Locked Moved Solved Scripting
    31 Posts 3 Posters 376 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.
    • LindonL
      Lindon @Chazrox
      last edited by

      @Chazrox said in Read & Write JSON file || Basics:

      So are all array api's available for these too?

      Arrays are just arrays - so yes the array API is applicable to them...but your array elements are "complex" objects so heaven knows how stuff like sort would work - if at all....

      HISE Development for hire.
      www.channelrobot.com

      ChazroxC d.healeyD 2 Replies Last reply Reply Quote 1
      • ChazroxC
        Chazrox @Lindon
        last edited by

        @Lindon Ok. I'll do some reading on that too.

        @Lindon said in Read & Write JSON file || Basics:

        heaven knows...

        😆

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

          @Lindon said in Read & Write JSON file || Basics:

          but your array elements are "complex" objects so heaven knows how stuff like sort would work - if at all....

          Custom sort function

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

          ChazroxC 1 Reply Last reply Reply Quote 0
          • ChazroxC
            Chazrox @d.healey
            last edited by Chazrox

            @d-healey

            can you take a look at this please?
            // Im trying to add 'newPreset' to 'AttackTablePresets'

            
            const var AttackTablePresets = 
            {
            		
            	"name": "36...............vOLVxe+....9izwDzO...f+....9C...vO", 
            	"name2": "36...............vOLVxe+....9izwDzO...f+....9C...vO", 
            	"name3": "36...............vOLVxe+....9izwDzO...f+....9C...vO"
            		
            };
            
            // SAVE PRESET BUTTON CONTROLS
            inline function onSaveOkControl(component, value)
            {	
            
            	
            	if (value)
            	{
            		local tableData0 = TableEnvelope1Pro.exportAsBase64(0);		
            		local newPreset = {Newshit : tableData0};
            		
            		AttackTablePresets.insert(newPreset); 
            
            // Im trying to add 'newPreset' to 'AttackTablePresets'
            		
            		Console.print("START TRACE" + trace(myObjectSet) + "END TRACE");
            	}
            };
            Content.getComponent("SaveOk").setControlCallback(onSaveOkControl);
            
            d.healeyD 1 Reply Last reply Reply Quote 0
            • d.healeyD
              d.healey @Chazrox
              last edited by d.healey

              @Chazrox

              const myObj = {"name": "Dave", "age": 38, "country": "England"};
              
              // To add something new you can use dot notation
              myObj.newKey = newValue;
              
              // Or you can use bracket notation - only really needed if you have spaces in the key or are using a variable to hold the key
              myObj["newKey"] = newValue;
              

              @Chazrox said in Read & Write JSON file || Basics:

              AttackTablePresets.insert(newPreset);

              This is for arrays, not objects. I think Lindon confused you :)

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

              ChazroxC 1 Reply Last reply Reply Quote 0
              • ChazroxC
                Chazrox @d.healey
                last edited by

                @d-healey oh wow..how do I find the rest of the dot.functions?

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

                  @Chazrox It's not a function, it's accessing the property of the object.

                  Just like when you use .length to find out how many characters are in a string or elements in an array. If it doesn't have () at the end then it's not a function.

                  You're going to love my scripting course :)

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

                  ChazroxC 2 Replies Last reply Reply Quote 0
                  • ChazroxC
                    Chazrox @d.healey
                    last edited by

                    @d-healey

                    @d-healey said in Read & Write JSON file || Basics:

                    You're going to love my scripting course :)

                    I cant wait! Im there!

                    When I say I watch all of your videos...

                    I mean it. lol. (muuuultiple times and still learning always)
                    Screenshot 2025-07-09 at 5.16.17 AM.png

                    1 Reply Last reply Reply Quote 1
                    • ChazroxC
                      Chazrox @d.healey
                      last edited by Chazrox

                      @d-healey

                      I combined everything to try to do everything at once..

                      1. export table state
                      2. push new preset to 'AttackTablePresets'
                      3. push 'name' to combobox.

                      this is working so far...but my presets in the combobox keep disappearing every couple of times I press save.

                      Screenshot 2025-07-09 at 5.55.29 AM.png

                      see it saved a few presets, but at some random point it just dissapears.

                      // SAVE PRESET BUTTON CONTROLS
                      inline function onSaveOkControl(component, value)
                      {	
                      	local f = FileSystem.getFolder(FileSystem.Desktop).getChildFile("myFile.json"); 
                      	f.writeObject(AttackTablePresets);
                      	
                      	if (value)
                      	{
                      		
                      		local tableData0 = TableEnvelope1Pro.exportAsBase64(0);
                      		local presetNameNOW = PresetNameToSave.get("text");
                      
                      		AttackTablePresets[presetNameNOW] = tableData0;
                      		
                      		local keyList = [];
                      		
                      		for (k in AttackTablePresets)
                      		{
                      			keyList.push(k);
                      		}
                      		
                      		PresetList.set("items", keyList.join("\n"));
                      	}
                      };
                      Content.getComponent("SaveOk").setControlCallback(onSaveOkControl);
                      
                      
                      d.healeyD 1 Reply Last reply Reply Quote 0
                      • d.healeyD
                        d.healey @Chazrox
                        last edited by

                        @Chazrox got a minimal snippet?

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

                        ChazroxC 2 Replies Last reply Reply Quote 0
                        • ChazroxC
                          Chazrox @d.healey
                          last edited by

                          @d-healey comin up! 🙏

                          1 Reply Last reply Reply Quote 0
                          • ChazroxC
                            Chazrox @d.healey
                            last edited by Chazrox

                            @d-healey 🙏 !

                            HiseSnippet 1881.3oc2X0saabbEdVItJlzN+UTT2qpmJfBP23vPJJwXAihHRJJG0JJxHRoD.2fzQ6NTbrVNy5cFJIhTC3Gjh9.zGgdQQtrW1K5CR508B2yL6Rt6RRQwnD2f1k.R67y4b9N+My4rsCDNToTDfrx0cjOEYcO6Ni3p906SXbz96hrdW6NjKX7yvcIm5QknZi7IRI0EYYs5S0axJaFj44a+jZDOB2gFOEBchf4POfMfohms8N+Nlm2dDWZW1fD6dyc12QvqK7DCA.spcQjOw4bxYzCI5sshM5SIx9Hqes8Fazy4wEK93xk2pHgT1kP1rDs71zdU54rUwsK5d5VEgeUPVq0vkoDAcTDE.dqUqIbG0ou3Rdn.NgIYfZoGTB0Ajb3zn58YdtsGacjHjk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5EP0ggUtj0N5zUj0aMIvGvQZ.1lvodQ.z7dIzUS.2q9rcFEiT9NWxbU8mLw27G2oOkcVefo1VbXB8wKiK1L6Z2+92+0nTytgd5G7fG75H+8DLYeywKI.0II.0qdwNLYSw.fMj.XZqURx2ro00CHmFoq+D6oOHOo.NOs.N8rXk50vidZ8I9wyBSXlMs8A4lv97KhHBd2tG8xTp+ZKa.eLF+lKmxHnOYWWs5G+3sys4VUxs0ValSKmAjqzhOyTV76di4GWSTvqd13n.aq+FLNVCcgQNCkJQj2VGOtxTNeXK+azLQJk+m+Ii4Kogt7e8O+uzy4O9rl8c0p2TUKlRmt2Ml5YLEUrPn2r5CB8W5Ms9.trWuD5iozf84tzqFefar98VWWz7crMumzm8GjI8YeVrN92SoiwQkks6K70ckpDXWwPMpT8YRrzHKrtPDBVRgqKbCqeo.F56bl1kfF0DtC8Hpzcuo6qMZA3xrTsLoaKhKYpQI6686PKcEWXKcKKDee61LkS+4iwUlCFgSfeSfwnFgea6F85Ak5FCvL168E21tdWdw+Ngh+t1cfRzLsrYD9OyLF+451IeJkSCzFuRK3KW7OV1ubg+R+kKZ4n.w2Mfvk9BYJF2gNf0ERRjIm7XIz1M8EGo8lImutfDL2k91OYOPImKMcHpgAlvhpCDC4pTgAql1OjY4p6JcFQh8OmOKQleD9RI+vjV8iXlepOlSz2h6csS07WTl+zmAmDiMEbgeeAm4jzmeDUEvN6LZPRjOW0Irssjw0GQ8nDYpP8D81s62ihPi3bB9rb0T9C22OakkLr391QpLjyi+9DcjY4hNtgVXVRT+ysGag+eJXuvq1V8+uuZ6HwPETTSSBjupK96vgC5.2n3PAoyglcj5hfVQeqP33h5wgWovcMCzE7GsXI8XqnEKMdw+qHiADm.wW4D1joNS6NlY.8la9R9YsapGimSasCfqC9JGmzrZFB231RX4aKgadaIbqaKgUtsD9w2VBe7MSn915pCglLBSMQnlsaDd3sUCt9jbSFA5+.uZhhU
                            

                            Edited because I forgot to declare the tables in the example.

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

                              @Chazrox

                              So this is what I'm seeing.

                              • You click save
                              • You write the presets object to a JSON file - you have this outside of the if statement so this happens on both button on and button off
                              • You grab the table data and add it to the object
                              • You repopulate the combo box list.

                              I don't see an issue with the list being reset when clicking the save button, but I don't see anywhere you are loading the presets back from the file, so the combobox will clear on compile.

                              Also you probably want to save the object to the file after you've added the new value.

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

                              ChazroxC 2 Replies Last reply Reply Quote 1
                              • ChazroxC
                                Chazrox @d.healey
                                last edited by

                                @d-healey ok. Let me look into it now. Thank You.

                                1 Reply Last reply Reply Quote 0
                                • ChazroxC
                                  Chazrox @d.healey
                                  last edited by

                                  @d-healey going in circles lol Im looking thru api's but I honestly am not sure what category im supposed to be under. Im reading up on 3 different types of objects right now and im not sure which is best.

                                  d.healeyD 1 Reply Last reply Reply Quote 0
                                  • ChazroxC Chazrox has marked this topic as unsolved
                                  • d.healeyD
                                    d.healey @Chazrox
                                    last edited by

                                    @Chazrox

                                    Write out in English step by step what behaviour you want. Then we figure out how to translate that into code.

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

                                    ChazroxC 2 Replies Last reply Reply Quote 0
                                    • ChazroxC
                                      Chazrox @d.healey
                                      last edited by

                                      @d-healey yoo! I figured it out and went crazy......one sec....

                                      1 Reply Last reply Reply Quote 1
                                      • ChazroxC
                                        Chazrox @d.healey
                                        last edited by

                                        @d-healey Booom! Thank You very much sir! I feel like I unlocked a whole new world. haha. Thank You @Lindon ! 🙏

                                        Features:
                                        Save
                                        Delete
                                        Rename
                                        Randomize
                                        Previous Preset
                                        Next Preset

                                        (Saved to .json)

                                        Table Preset Browser Working.gif

                                        1 Reply Last reply Reply Quote 2
                                        • ChazroxC Chazrox has marked this topic as solved
                                        • First post
                                          Last post

                                        23

                                        Online

                                        1.8k

                                        Users

                                        12.1k

                                        Topics

                                        105.7k

                                        Posts