HISE Logo Forum
    • Categories
    • Register
    • Login

    Preset Component Callbacks Triggering Twice on Startup

    Scheduled Pinned Locked Moved Solved Scripting
    11 Posts 3 Posters 367 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.
    • clevername27C
      clevername27
      last edited by clevername27

      Does anyone know why the callbacks for all my SaveInPreset" components marked " are triggering twice on startup?

      1. Once at onInit (why?)
      2. Once after the preset loads (that one should).

      Thank you.

      EDIT: Whenever I "Recompile All Scripts", things print to the Console in different orders. There doesn't seem to be pattern. Sometimes, Things print before onInit starts, and sometimes after. And maybe code is executing before, because when I print test variables, they're undefined. And then when they're printed again, they're fine. (Or maybe I'm just missing something.)

      EDIT: Turns out the default preset thingy does get called twice.

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

        @clevername27 do you call changed() in the onInit script?

        Something is definitely weird with your initialisation routine…

        A clevername27C 4 Replies Last reply Reply Quote 1
        • A
          aaronventure @Christoph Hart
          last edited by aaronventure

          @Christoph-Hart said in Preset Component Callbacks Triggering Twice on Startup:

          do you call changed() in the onInit script?

          Doesn't this get ignored by default? HISE even tells you it's ignoring the call.

          He might be calling the function itself, though.

          clevername27C 1 Reply Last reply Reply Quote 1
          • clevername27C
            clevername27 @Christoph Hart
            last edited by

            @Christoph-Hart Thanks, I'll double-check.

            1 Reply Last reply Reply Quote 0
            • clevername27C
              clevername27 @aaronventure
              last edited by

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • clevername27C
                clevername27 @Christoph Hart
                last edited by

                @Christoph-Hart I'm not. (I placed a Console.print before each onChanged in my code, to double-check.)

                1 Reply Last reply Reply Quote 0
                • clevername27C
                  clevername27 @Christoph Hart
                  last edited by clevername27

                  @Christoph-Hart (or anyone) Could you pls tell me -

                  • Is there is variable persistence within HISE after programme execution stops?

                  • Is there a difference between code literally being in Interface.js, and being inside an included file (assuming it's in the right sequence)?

                  • What does "setEnableUserPresetPreprocessing" do?

                  • How does HISE define when onInit is complete, so the default preset can be loaded?

                  Thank you.

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

                    @clevername27 Alright, T-Shirt time for the big guy, if you have set a default preset it does in fact load the preset that is stored in the xml first, then load the default preset afterwards, so you actually end up with it being executed twice.

                    Usually it's not a critical issue though, it's just like a angry user smashing the load preset button twice (and most heavyweight operations like samplemap loading are skipped if the value doesn't change).

                    Is there a real issue that this behaviour creates on your end or were you just curious?

                    clevername27C 1 Reply Last reply Reply Quote 2
                    • clevername27C
                      clevername27 @Christoph Hart
                      last edited by clevername27

                      @Christoph-Hart Thank you for your reply and info. I worked around it, and my code is better for it. The console appeared to log the sequence of events differently, seemingly randomly. With your info, plus @ustk's comment in this thread, I sorted things out.


                      For those here by search, looking for a work-around: Declare a global JSON object (at the top of onInit UI) with a flags for when onInit UI is done, and the pre/post callbacks run. Increment callback flags inside the callback (first checking if they're defined), and at the bottom of onInit UI. Then, define a function called something like IsComponentCallbackSafe(component) that returns true or false if OnInit UI is done and the callback cycle has run twice (but no more). (Remember to use IsDefined there as well.) Then, at the top of the callback for each component stored in a preset, do if (IsComponentCallbackSafe(component)) then function body. There's probably a more elegant way to do that, but I like it, because it means I can set other criteria when it's not safe for those callbacks to run. You can also iterate the function through an array of your components, etc.

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

                        @Christoph-Hart is it too much trouble to add an engine.isInitFinished method that we can call and check and never worry about counting flags again?

                        It would switch to true after everything has been loaded or triggered once, twice or however many times.

                        There's a real use case for post init scenarios where all the controls have their values loaded and the control callback did their thing and the engine starts running.

                        Could be niche and for some complex cases but it's definitely there.

                        clevername27C 1 Reply Last reply Reply Quote 1
                        • clevername27C
                          clevername27 @aaronventure
                          last edited by clevername27

                          Maybe…but what if the plugin interface could expand up, instead of just down.? Think about it.

                          I'm just kidding. I don't even understand what you wrote. Is 'callback' even a real word? How is there a tiny picture of me next to my name? This all raises too many questions.

                          1 Reply Last reply Reply Quote 0
                          • clevername27C clevername27 has marked this topic as solved on
                          • First post
                            Last post

                          35

                          Online

                          1.7k

                          Users

                          11.7k

                          Topics

                          102.3k

                          Posts