HISE Logo Forum
    • Categories
    • Register
    • Login

    Broadcaster attachment design pattern

    Scheduled Pinned Locked Moved General Questions
    25 Posts 3 Posters 1.4k 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 @Orvillain
      last edited by

      @Orvillain This error?

      Interface:! Engine3AHDSRControl: BroadcastersBuilder.js (291): Illegal iterator target

      The error is being triggered only for Engine3 so that implies the for loop in general is fine, but there is a more specific issue.

      Free HISE Bootcamp Full Course for beginners.
      YouTube Channel - Public HISE tutorials
      My Patreon - HISE tutorials

      OrvillainO 1 Reply Last reply Reply Quote 0
      • OrvillainO
        Orvillain @d.healey
        last edited by

        @d-healey Yeah, there's some underlying closure thing going on I think.

        Musician - Instrument Designer - Sonic Architect - Creative Product Owner
        Crafting sound at every level. From strings to signal paths, samples to systems.

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

          @Orvillain

          for (engine in engines)
          {
              local capturedEngine = engine;
          
              Globals.broadcasters[engine + "AHDSRControl"].addListener("string", "metadata", function(param, value)
              {
                  BroadcasterCallbacks.controlLinkedAmpEnvParameter(capturedEngine, param, value);
              });
          }
          

          Oh I just realised the issue - the function within your loop doesn't have access to local variables outside of the function. So you'll need to find another structure.

          One workaround is to use a lambda variable, I try to avoid this because I find their use usually indicates a structural issue. But it's a quick and dirty fix.

          function[capturedEngine](param, value)

          Another suggestion is instead of using an array of strings and a for in loop. Just use a for loop that counts from 0 to the number of engines you have. Then you can just declare a NUM_ENGINES constant at the top of your script and use it whenever you need to know the number of engine you have.

          Free HISE Bootcamp Full Course for beginners.
          YouTube Channel - Public HISE tutorials
          My Patreon - HISE tutorials

          OrvillainO 1 Reply Last reply Reply Quote 0
          • OrvillainO
            Orvillain @d.healey
            last edited by

            @d-healey said in Broadcaster attachment design pattern:

            Another suggestion is instead of using an array of strings and a for in loop. Just use a for loop that counts from 0 to the number of engines you have. Then you can just declare a NUM_ENGINES constant at the top of your script and use it whenever you need to know the number of engine you have.

            If I try that, for example (different feature area this time):

            		for (i = 1; i < SharedData.engines.length; i++)
                    {
                        SharedData.broadcasters["Engine" + i + "ModeControl"].addListener("string", "metadata", function(index)
            		{
            			BroadcasterCallbacks.setActiveModeForSlot("Engine" + i, index);
            		});
                    }
            

            Then I get:

            Interface:! BroadcastersBuilder.js (260): Can't reference local variables in nested function body {{SW50ZXJmYWNlfEJyb2FkY2FzdGVyc0J1aWxkZXIuanN8ODQ3MHwyNjB8NTc=}}
            
            

            Musician - Instrument Designer - Sonic Architect - Creative Product Owner
            Crafting sound at every level. From strings to signal paths, samples to systems.

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

              @Orvillain The error is basically saying what I said.

              You can't access a local variable declared outside of the function.

              Free HISE Bootcamp Full Course for beginners.
              YouTube Channel - Public HISE tutorials
              My Patreon - HISE tutorials

              OrvillainO 1 Reply Last reply Reply Quote 0
              • OrvillainO
                Orvillain @d.healey
                last edited by

                @d-healey Indeed, indeed.

                		for (engine in SharedData.engines)
                        {
                            local capturedEngine = engine;
                            SharedData.broadcasters[capturedEngine + "ModeControl"].addListener("string", "metadata", function[capturedEngine](index)
                		{
                			BroadcasterCallbacks.setActiveModeForSlot(capturedEngine, index);
                		});
                        }
                

                This did seem to work however.

                Musician - Instrument Designer - Sonic Architect - Creative Product Owner
                Crafting sound at every level. From strings to signal paths, samples to systems.

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

                  @Orvillain Yep that will do it, it's not the most elegant solution but that's what it's designed for.

                  Free HISE Bootcamp Full Course for beginners.
                  YouTube Channel - Public HISE tutorials
                  My Patreon - HISE tutorials

                  OrvillainO 1 Reply Last reply Reply Quote 1
                  • OrvillainO
                    Orvillain @d.healey
                    last edited by

                    @d-healey More elegant than what I have right now I am thinking!

                    Musician - Instrument Designer - Sonic Architect - Creative Product Owner
                    Crafting sound at every level. From strings to signal paths, samples to systems.

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

                      @Orvillain Yep it will certainly help reduce that repetition

                      Free HISE Bootcamp Full Course for beginners.
                      YouTube Channel - Public HISE tutorials
                      My Patreon - HISE tutorials

                      OrvillainO 1 Reply Last reply Reply Quote 0
                      • OrvillainO
                        Orvillain @d.healey
                        last edited by

                        @d-healey Yeah, I think I can essentially boil down 11 functions down to 3 functions with this. Pretty cool, cheers!

                        Musician - Instrument Designer - Sonic Architect - Creative Product Owner
                        Crafting sound at every level. From strings to signal paths, samples to systems.

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

                        21

                        Online

                        2.0k

                        Users

                        12.7k

                        Topics

                        109.8k

                        Posts