HISE Logo Forum
    • Categories
    • Register
    • Login

    downloadFile & repaint issue

    Scheduled Pinned Locked Moved Scripting
    9 Posts 3 Posters 363 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'm using Server.downloadFile() to update .hxi's, and would like to have the Panel/Button display visual feedback but I'm having some difficulty with the download callback:

      Server.downloadFile(library_updateURLs[this.data.index], {}, download_target, function() 
                      {
                          if (this.data.finished)
                          {
                              Console.print("Finished");
                              this.data.downloading = false; //Swap SVG based on download state
                              expButton[this.data.index].repaint();
                          }
                      });   
      

      The Console Print line works, but the childpanel won't repaint. I assume it's a scope thing, but I've tried

      this.repaint();
      panel[i].repaint(); //The panels are in a loop already
      panel[this.data.index].repaint(); //Where this.data.index is a forced variable of i
      

      And none seem to work.

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

        Okay I see the issue, because the file download callback is on a different thread, the repaint outside the function calls before the download has finished.

        But putting this.repaint() inside the download callback results in an error: function not found.

        DanHD 1 Reply Last reply Reply Quote 0
        • DanHD
          DanH @A Former User
          last edited by

          @iamlamprey not at my computer but pretty certain Dave made a vid about this. Also think there’s a tutorial project from Christoph somewhere too that has this in.

          DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
          https://dhplugins.com/ | https://dcbreaks.com/
          London, UK

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

            The this reference in the callback is not pointing to the panel, you need to pass it in as lambda.

            ? 1 Reply Last reply Reply Quote 0
            • ?
              A Former User @Christoph Hart
              last edited by

              @Christoph-Hart said in downloadFile & repaint issue:

              you need to pass it in as lambda.

              Do you have an example of this handy? :)

              Christoph HartC 1 Reply Last reply Reply Quote 0
              • Christoph HartC
                Christoph Hart @A Former User
                last edited by

                I‘m on the go at the moment but if you search for lambda here in the forum you should find a post where I explain the feature.

                ? 1 Reply Last reply Reply Quote 0
                • ?
                  A Former User @Christoph Hart
                  last edited by

                  @Christoph-Hart I've found the thread but still can't get it repainting

                  Server.downloadFile(library_updateURLs[this.data.index], {}, download_target, function[this]() 
                                  {
                                      if (this.data.finished)         
                                      {
                                          Console.print("Finished");      
                                          this.data.downloading = false;              
                                          this.repaint();
                                      }              
                                  });     
                  

                  I assume literally passing "this" in isn't the right approach lol

                  Christoph HartC 1 Reply Last reply Reply Quote 0
                  • Christoph HartC
                    Christoph Hart @A Former User
                    last edited by

                    @iamlamprey No this is a reserved keyword which you can't pass as lambda.

                    But if you copy it as a normal variable, it should work. Try:

                    // I don't know if you're in an inline function or not, so adapt the keyword
                    // to match the scope
                    varOrLocal thisFromFunction = this;
                    
                    Server.downloadFile(library_updateURLs[this.data.index], {}, download_target, function[thisFromFunction]() 
                                    {
                                        if (this.data.finished)         
                                        {
                                            Console.print("Finished");      
                                            this.data.downloading = false;              
                                            thisFromFunction.repaint();
                                        }              
                                    });     
                    
                    ? 1 Reply Last reply Reply Quote 0
                    • ?
                      A Former User @Christoph Hart
                      last edited by

                      @Christoph-Hart Yep that got it, cheers!

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

                      47

                      Online

                      1.7k

                      Users

                      11.7k

                      Topics

                      101.8k

                      Posts