HISE Logo Forum
    • Categories
    • Register
    • Login

    Dynamically load instruments over the Internet?

    Scheduled Pinned Locked Moved Solved General Questions
    18 Posts 2 Posters 1.1k 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.
    • d.healeyD
      d.healey @bthj
      last edited by

      @bthj I have some videos on Patreon about downloading files which you might find useful, nothing about the JWT stuff though.

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

      bthjB 1 Reply Last reply Reply Quote 0
      • bthjB
        bthj @d.healey
        last edited by

        @d-healey Great! I'll look into those as well.

        bthjB 1 Reply Last reply Reply Quote 1
        • bthjB bthj has marked this topic as solved on
        • bthjB
          bthj @bthj
          last edited by bthj

          Now I have written some code towards this functionality - a milestone for me, as this is the first thing I've actually done with HISE.  Really enjoyable getting to know this project and community.

          What I've done so far is:

          • hardcode a list of sample map IDs, to be dynamically fetched via some API endpoint
          • when not available locally, download the corresponding samples monolith HLAC to the Samples folder
          • then fetch the sample map Base64 encoded and load it into the Sampler

          The task in the last bullet is done every time a sample map is selected (for now via combobox), which wastes a bit of network resources (and I have to choose Tools -> Clear all Samplemaps, so they won't be saved in the archive/xml).  It would be good to save the sample map in the filesystem, like the HLAC monoliths, and maybe just download it as xml rather than base64 encoded, but there doesn't seem to be a Special Location for the SampleMaps folder.  Is there some way to obtain a filesystem reference to that folder, as a target for Server.downloadFile?

          Here's the code I've written so far:

          // sampler
          const var Sampler = Synth.getChildSynth("Sampler").asSampler();
          
          // sample maps array
          const var sampleMaps = [
            "fg_01FFRFAGFF9M9R8D6AWHTX7XB9",
            "fg_01FNAAJA8CXA8CNAXAGVWJN0HA"
          ];  // TODO: fetch samples list from some API endpoint, instead of this hardcode
          
          // Internet communication
          Server.setBaseURL("https://storage.googleapis.com");
          
          // combo box
          const var cmbSampleMap = Content.getComponent("cmbSampleMap");
          cmbSampleMap.set("items", sampleMaps.join("\n"));
          
          
          // sample map selection
          
          // - sample map downloaded as base64 and loaded into a Sampler
          inline function fetchAndLoadSampleMap( sampleMapId ) {
          	local sampleMapBase64FileName = sampleMapId + ".txt";
          	Server.callWithGET( 
          		"/synth_is_samples/map/" + sampleMapBase64FileName, 
          		{}, 
          		function(status, sampleMapBase64) {
          			Console.print("sample response: " + sampleMapBase64);
          			Sampler.loadSampleMapFromBase64( sampleMapBase64 );
          		}
          	);
          }
          
          // - combo box callback with conditional  
          // samples monolith download and  storeage in filesystem
          const var samplesFolder = FileSystem.getFolder(FileSystem.Samples);
          inline function oncmbSampleMapControl(component, value)
          {
          	var sampleMapId = sampleMaps[value-1];
          	
          	// ensure samples monolith is available
          	local samplesFileName = sampleMapId + ".ch1";
          	local samplesFile = samplesFolder.getChildFile( samplesFileName );
          	Console.print("samplesFile: " + samplesFile.isFile());
          	if( ! samplesFile.isFile() ) { // we need to download the file
          		Server.downloadFile(
          			"/synth_is_samples/hlac/" + samplesFileName, 
          			{}, 
          			samplesFile, 
          			function() {
          		    	var message = "";
          		    	message += Engine.doubleToString(
          		    		this.data.numDownloaded / 1024.0 / 1024.0, 1
          		    	);
          				message += "MB / " + Engine.doubleToString(
          					this.data.numTotal / 1024.0 / 1024.0, 1
          				) + "MB";
          		    
          		    Console.print(message);
          			
          			if( this.data.finished && this.data.success ) {
          				Console.print( "Samples loaded" );
          				fetchAndLoadSampleMap( sampleMapId );
          			}
          		});
          	} else { // samples monolith is present, so we can go ahead and load the sample map
          		fetchAndLoadSampleMap( sampleMapId );
          	}
          };
          
          • and a snippet of the project:
          HiseSnippet 2568.3oc4YrsaabbcojWCSZ2Tmf7PeoESYKBnfk4MKqKV0wh5BsUrtAQ5KAoFBi1cH4Ts6NK1YVIwFHfh9Wj25mP+AJPds+M4On8blcWtConTUDRBRPIfL4bl4Lm62FePjvgIkhHqBE6NLjYU3A1cFFnFrw.JOvZ6MsJ76rOidJ6DtmK6HI0OzicjOM7HOA0kGz2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ply Quote 0
          • d.healeyD
            d.healey @bthj
            last edited by

            @bthj Since the samples maps are predefined anyway why not just include them with the plugin instead of downloading them?

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

            bthjB 1 Reply Last reply Reply Quote 0
            • bthjB
              bthj @d.healey
              last edited by bthj

              @d-healey The aim is not to have the sample maps predefined, but generated mechanically.

              For a bit of a context: I'm exploring those possibilities for the synth.is project, where you can evolve sounds[1], render them as sample packs and currently download them along with programmatically generated SFZs[2]. Many things broken there and I aim to continue working on this research project in the coming years, but all are very much welcome to play with this (I know the interactive evolution part is broken, which is a regression resulting from work on quality diversity search for sounds - I welcome requests for accelerated fixes : )

              Just as SFZs can currently be rendered and downloaded, it would be nice to be able to obtain those sounds directly in a plugin.

              [1] https://youtu.be/dm2cgPqQVP0
              [2] https://youtu.be/3eLo8qORiMQ
              (YouTube links here as inlining above was causing problems)

              bthjB 1 Reply Last reply Reply Quote 1
              • bthjB
                bthj @bthj
                last edited by

                The approach I have currently implemented is maybe ok - sample maps are not large so redundant downloading isn't a big problem - but if it is possible to persist them in the plugin folder structure, then it would be interesting to try that out as well.

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

                  @bthj said in Dynamically load instruments over the Internet?:

                  The approach I have currently implemented is maybe ok - sample maps are not large so redundant downloading isn't a big problem - but if it is possible to persist them in the plugin folder structure, then it would be interesting to try that out as well.

                  You could write the string to a file.

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

                  bthjB 1 Reply Last reply Reply Quote 0
                  • bthjB
                    bthj @d.healey
                    last edited by

                    @d-healey Wouldn't it be best placed in the SampleMaps folder? - then I'm wondering how to get a filesystem handle on that folder.

                    bthjB d.healeyD 2 Replies Last reply Reply Quote 0
                    • bthjB
                      bthj @bthj
                      last edited by bthj

                      Tried something like:

                      samplesFolder.getParentDirectory().getChildFile("SampleMaps").getChildFile(sampleMapFileName);
                      

                      which works, so I'll probably go that route, if it isn't some kind of an anti-pattern?

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

                        @bthj said in Dynamically load instruments over the Internet?:

                        @d-healey Wouldn't it be best placed in the SampleMaps folder?

                        There is no sample maps folder once your project is compiled to a plugin, all the sample maps are embedded in the binary.

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

                        bthjB 1 Reply Last reply Reply Quote 0
                        • bthjB
                          bthj @d.healey
                          last edited by

                          @d-healey Thanks for the insight. Then it makes sense that there is no Special Location FileSystem constant for that folder. I'll just download the sample maps to the Samples folder, alongside the monoliths, Base64 encoded for loading with Sampler.loadSampleMapFromBase64.

                          bthjB 1 Reply Last reply Reply Quote 0
                          • bthjB
                            bthj @bthj
                            last edited by

                            The above procedure of downloading the files to FileSystem.Samples works fine, until running on iOS, where the Samples folder seems to be part of the read-only app bundle. So downloading to FileSystem.Documents might be a better idea, but after loading the sample map, the Sampler seems to be fixed on searching for the files in FileSystem.Samples.

                            Is there some way to instruct Sampler to look for the (monolith) samples in FileSystem.Documents?

                            bthjB 1 Reply Last reply Reply Quote 0
                            • bthjB
                              bthj @bthj
                              last edited by

                              Made a couple of changes which solve this issue on iOS, discussed here:

                              Link Preview Image
                              Dynamically download samples on iOS · Issue #265 · christophhart/HISE

                              Downloading samples into the FileSystem.Samples directory doesn't work on an iOS device (though it works on a simulator), where the Samples folder seems to be part of the read-only app bundle. A couple of changes solve this particular is...

                              favicon

                              GitHub (github.com)

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

                              10

                              Online

                              1.7k

                              Users

                              11.8k

                              Topics

                              103.1k

                              Posts