HISE Logo Forum
    • Categories
    • Register
    • Login

    Constant file ID

    Scheduled Pinned Locked Moved General Questions
    35 Posts 4 Posters 1.7k 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.
    • A
      arminh @Casey Kolb
      last edited by

      @Lunacy-Audio but no matter where i put array data it always have random position.

      For example, we have audio files list (no matter if sorting works or not :D ):

      • 1.wav - cmb value = 1
      • 2.wav - cmb value = 2
      • 10.wav - cmb value = 3

      but if we add sample 3 it will looks like

      • 1.wav - cmb value = 1
      • 2.wav - cmb value = 2
      • 3.wav - cmb value = 3
      • 10.wav - cmb value = 4

      and that's the problem.

      Casey KolbC 1 Reply Last reply Reply Quote 0
      • Casey KolbC
        Casey Kolb
        last edited by Casey Kolb

        Think about it like this:

        1. The user uploads two files called "MyAudio1.wav" and ""MyAudio2.wav".
        2. You save the file names in the external JSON with an object like the one below. You'll need a different ID for each.
        {
          {
            "name": "MyAudio1.wav",
            "id": 1
          },
          {
            "name": "MyAudio2.wav",
            "id": 2
          },
        }
        
        1. In HISE, you set the value of a hidden slider (saved in preset) to 1, indicating the current file is "MyAudio1.wav"
        2. Update the visible combobox items to include the new audio files
        3. When the user changes the combobox selection, retrieve the actual text of the selection using ScriptComboBox.getItemText() and find the matching ID based in the external JSON on that text.
        4. Save the new ID in the slider.

        In this case, the combobox is purely a visual component, unrelated to the preset restoring. When the preset is restored, it will look at the hidden slider value and find the right audio file to load based on the external JSON.

        1 Reply Last reply Reply Quote 0
        • Casey KolbC
          Casey Kolb @arminh
          last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • A
            arminh
            last edited by

            @Lunacy-Audio i thought about creating json but this requires additional actions from the user. Not all of us are so technical :D

            1 Reply Last reply Reply Quote 0
            • Casey KolbC
              Casey Kolb
              last edited by

              The user never has to do anything. You make the JSON file in the HISEScript either using the new File API or Engine.dumpAsJSON(var object, String fileName)

              1 Reply Last reply Reply Quote 0
              • Casey KolbC
                Casey Kolb
                last edited by

                The important thing is that you never change the IDs after you've registered them. This is how you avoid breaking any previous presets.

                A 1 Reply Last reply Reply Quote 0
                • A
                  arminh @Casey Kolb
                  last edited by

                  @Lunacy-Audio you know how to push data to current file? because when i trying do this by writeObject i getting brand new file.

                  1 Reply Last reply Reply Quote 0
                  • Casey KolbC
                    Casey Kolb
                    last edited by

                    Yup, Engine.dumpAsJSON(myNewFile, "../myNewFile.xml"); works great but will overwrite the file if it's already there.

                    You just need to import the file first with Engine.loadFromJSON("../myNewFile.xml"); and then append any changes before resaving it.

                    1 Reply Last reply Reply Quote 0
                    • A
                      arminh
                      last edited by arminh

                      @Lunacy-Audio ok thanks, i made a little progress

                      I can finally create xml with data but in file it has only last file from FileSystem array

                      for (f in files)
                      {
                          var id = parseInt(Math.random()*10000);
                          var p = f.toString(OnlyExtension);
                          var obj = {
                              path: p,
                              id: id,
                          };
                          Engine.dumpAsJSON(obj, "../files.xml");
                      };
                      

                      This overwrites the files instead of adding a new entry.

                      1 Reply Last reply Reply Quote 0
                      • Casey KolbC
                        Casey Kolb
                        last edited by Casey Kolb

                        Right, take another look at that code. You only want to dump the JSON after the for loop is finished. At the moment, it's writing a new file with the object every single iteration. You need something more like this. Also be wary, the random ID is a bit deadly because there's always a change you'll get duplicate IDs.

                        var obj = {};
                        for (f in files)
                        {
                            var id = parseInt(Math.random()*10000);
                            var p = f.toString(OnlyExtension);
                            obj[id] = p;
                        };
                        Engine.dumpAsJSON(obj, "../files.xml");
                        
                        A 1 Reply Last reply Reply Quote 0
                        • A
                          arminh @Casey Kolb
                          last edited by

                          @Lunacy-Audio i wan't just test it with this random id, in normal project i'll use letters and numbers to be sure that repeat chance will be really low

                          Casey KolbC 1 Reply Last reply Reply Quote 0
                          • A
                            arminh
                            last edited by

                            @Lunacy-Audio unfortunately i still have one object in xml :(

                            1 Reply Last reply Reply Quote 0
                            • Casey KolbC
                              Casey Kolb @arminh
                              last edited by

                              This post is deleted!
                              1 Reply Last reply Reply Quote 0
                              • A
                                arminh
                                last edited by arminh

                                @Lunacy-Audio obj outside for should be array :) and then in for loop we push obj to this arr, now i'm curios what's happen when i add new file and what's happen with id

                                ID chaning everytime.

                                The worst thing is that the order of the objects is also disturbed.

                                1 Reply Last reply Reply Quote 0
                                • A
                                  arminh
                                  last edited by

                                  This post is deleted!
                                  1 Reply Last reply Reply Quote 0
                                  • Casey KolbC
                                    Casey Kolb
                                    last edited by Casey Kolb

                                    Oops yeah there was a typo in my code. Was accidentally redeclaring the obj.

                                    Yeah, the ID will change every time if you're randomizing it. You need to check whether or not the file already exists in the external JSON and if it does, ignore it and make sure you don't use that ID again. That snippet above is just a really basic example, but you'll need to do some more checks in order to find out which ID to use next and which files have already been stored, etc.

                                    1 Reply Last reply Reply Quote 0
                                    • Christoph HartC
                                      Christoph Hart
                                      last edited by

                                      Why don‘t you just sort the array of filenames alphabetically? I think the API call has even a parameter for that.

                                      1 Reply Last reply Reply Quote 0
                                      • Christoph HartC
                                        Christoph Hart
                                        last edited by

                                        Ah nevermind, it hasn‘t. I‘ll add this.

                                        A 1 Reply Last reply Reply Quote 0
                                        • A
                                          arminh
                                          last edited by

                                          I think this method still dosnt make sense because id and file path will be different for every user. :v

                                          1 Reply Last reply Reply Quote 0
                                          • A
                                            arminh @Christoph Hart
                                            last edited by

                                            @Christoph-Hart maybe you have an idea how to do this or its even possible in hise?

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

                                            12

                                            Online

                                            1.8k

                                            Users

                                            11.9k

                                            Topics

                                            103.9k

                                            Posts