HISE Logo Forum
    • Categories
    • Register
    • Login

    expansionInstallCallback inside a for loop

    Scheduled Pinned Locked Moved Scripting
    6 Posts 2 Posters 173 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 Former User
      last edited by

      I have a custom expansionInstallCallback that shows an Alert Window after successfully installing an Expansion to inform users they need to restart the plugin. It works fine for single installations, but when I put it inside a loop to Batch Install multiple Expansions, it shows the alert window every time.

      Is there a neat way to only show the alert window on the last Expansion install? I'm currently trying to get some sort of counter that keeps track of the number of remaining expansions but haven't been successful with it.

      function expansionInstallCallback(obj)
      {
              if(obj.Status == 2 && isDefined(obj.Expansion))
                  Engine.showMessageBox("Installation Complete", "Library installed successfully, please restart NEAT Player.", 0);
      }
      
      expHandler.setInstallCallback(expansionInstallCallback);
      
      //Bulk Install Method
      
      var num_expansions_remaining = 0;
      
      inline function onButton_BulkInstallControl(component, value)
      {
          if (value)
                 {
                  Engine.showYesNoWindow("Bulk Install", "Please select the folder containing the .hr1 files.", function(response)
                  {
                      if (!response) return;       
                      FileSystem.browseForDirectory(FileSystem.Downloads, function(f)
                      {
                          if (f.isDirectory())
                          {
                              hrList = FileSystem.findFiles(f, "*.hr1", 0);
                              Engine.showYesNoWindow("Target Directory", "Please select the folder to install the samples to.", function(response)
                              {
                                  if (!response) return;       
                                  FileSystem.browseForDirectory(FileSystem.Downloads, function(dir)
                                  {                            
                                      if (dir.isDirectory())
                                      {
                                          num_expansions_remaining = hrList.length;
                                          for (i=0; i<hrList.length; i++)
                                          {
                                              num_expansions_remaining = hrList.length - (i + 1);
                                              expHandler.installExpansionFromPackage(hrList[i], dir);                                        
                                          }
                                      }
                                  });
                              });
                          }
                      });
                  });
                 }
      };
      

      Cheers :)

      d.healeyD 1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey @A Former User
        last edited by

        @iamlamprey Just have a flag called something like installComplete. Set it to false before your install loop, after a successful install set it to true. After all installs complete check the state of the flag, if it's true then you show the alert.

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

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

          Also I think this video will be helpful to you

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

          1 Reply Last reply Reply Quote 1
          • ?
            A Former User @d.healey
            last edited by

            @d-healey said in expansionInstallCallback inside a for loop:

            after a successful install set it to true.

            Yeh that was my first attempt before this counter method, but the expansion install callback is on a different thread so putting the message outside of the callback makes it display instantly after clicking the button.

            Also I think this video will be helpful to you

            I actually like nesting code, I know it's uglier but I generally hate having single-use methods outside of the place they're being used, my brain just likes that more for some reason. :)

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

              Don't use var unless you have to. Use reg for your counter.

              num_expansions_remaining = hrList.length; Try to stick to one naming convention, either use _ or use camelCase (HISE uses camel case so I recommend using the same).

              You need to increase your counter in the expansion callback, once the install is complete. Then you check and see if the counter >= the number of hrs, if it is then you show your message.

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

              ? 1 Reply Last reply Reply Quote 0
              • ?
                A Former User @d.healey
                last edited by

                @d-healey said in expansionInstallCallback inside a for loop:

                Don't use var unless you have to. Use reg for your counter.

                Yeh I'll probably have to start namespacing soon, was trying to avoid it but I'm all out of regs :)

                Got it working (so far):

                var num_expansions_to_install;
                var expansionInstallIndex = 1;
                
                function expansionInstallCallback(obj)
                {
                        if(obj.Status == 2 && isDefined(obj.Expansion))
                        {
                            if (expansionInstallIndex >= num_expansions_to_install)
                            {
                                expansionInstallIndex = 1;
                                Engine.showMessageBox("Installation Complete", "Library installation successful, please restart NEAT Player.", 0);
                            }
                            else
                                expansionInstallIndex++;
                        }       
                }
                
                
                //Single
                
                if (dir.isDirectory())
                {
                    num_expansions_to_install = 1;
                    expansionInstallIndex = 1;
                    expHandler.installExpansionFromPackage(nest.hr, dir);
                }
                
                //Batch
                
                if (dir.isDirectory())
                {
                    num_expansions_to_install = hrList.length;
                    expansionInstallIndex = 1;
                    for (i=0; i<hrList.length; i++)   
                    {
                        expHandler.installExpansionFromPackage(hrList[i], dir);                                          
                    }  
                        
                }
                

                It's a bit clunky but it does the job, cheers!

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

                14

                Online

                1.7k

                Users

                11.8k

                Topics

                102.4k

                Posts