HISE Logo Forum
    • Categories
    • Register
    • Login

    Setting ControlCallback w/ Loops ?

    Scheduled Pinned Locked Moved Solved Scripting
    17 Posts 5 Posters 61 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.
    • Oli UllmannO
      Oli Ullmann @Chazrox
      last edited by

      @Chazrox
      Or even shorter...

      const TheGains = Synth.getAllEffects("Simple Gain");
      const SampleVolumeKnobs = Content.getAllComponents("knbVolume");
      
      for(k in SampleVolumeKnobs)
      	k.setControlCallback(onSampleVolumeKnobsControl);
      
      d.healeyD ChazroxC 2 Replies Last reply Reply Quote 2
      • d.healeyD
        d.healey @Oli Ullmann
        last edited by d.healey

        @Oli-Ullmann

        Or even shorter...

        // Don't do this, I'm being silly
        for (k in Content.getAllComponents("knbVolume")) k.setControlCallback(onSampleVolumeKnobsControl);
        

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

        Oli UllmannO LindonL 2 Replies Last reply Reply Quote 3
        • Oli UllmannO
          Oli Ullmann @d.healey
          last edited by

          @d-healey
          😂 MASTER OF THE UNIVERSE LEVEL! 😀

          1 Reply Last reply Reply Quote 1
          • ChazroxC
            Chazrox @Oli Ullmann
            last edited by

            @Lindon @Oli-Ullmann @d-healey 💀

            Thank Yous! ha. 🤛

            1 Reply Last reply Reply Quote 0
            • LindonL
              Lindon @d.healey
              last edited by

              @d-healey said in Setting ControlCallback w/ Loops ?:

              @Oli-Ullmann

              Or even shorter...

              // Don't do this, I'm being silly
              for (k in Content.getAllComponents("knbVolume")) k.setControlCallback(onSampleVolumeKnobsControl);
              

              I always thought there was "no guarantee of ordering" in getAllComponents.....

              HISE Development for hire.
              www.channelrobot.com

              d.healeyD Oli UllmannO 2 Replies Last reply Reply Quote 0
              • d.healeyD
                d.healey @Lindon
                last edited by

                @Lindon I think it grabs them in the order they are in the component list. I never really thought about it though but I haven't ran into any issues.

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

                LindonL 1 Reply Last reply Reply Quote 0
                • LindonL
                  Lindon @d.healey
                  last edited by Lindon

                  @d-healey yeah..maybe then , however your suggestion makes the callback difficult in that there is no indexOf(component) to show you which one is being called on...unless theres some fu I dont know about...oh I just noticed your "dont do this comment..>"....

                  HISE Development for hire.
                  www.channelrobot.com

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

                    @Lindon I did put a disclaimer not to use it. :)

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

                    1 Reply Last reply Reply Quote 1
                    • LindonL
                      Lindon @Lindon
                      last edited by Lindon

                      @Lindon said in Setting ControlCallback w/ Loops ?:

                      @Chazrox

                      const TheGains = [];
                      const  SampleVolumeKnobs = [];
                      
                      const NUM_COMPONENTS = 8;
                      
                      for(i = 0; i< NUM_COMPONENTS; i++)
                      {
                          TheGains[i] = Synth.getEffect("Simple Gain" + (i+1));
                      
                          SampleVolumeKnobs[i] = Content.getComponent("knbVolume" + (i+1));
                          SampleVolumeKnobs[i].setControlCallback(onSampleVolumeKnobsControl);
                      }
                      
                      
                      

                      @Chazrox ...and now your call back looks like this:

                      inline function onSampleVolumeKnobsControl(component, value)
                      {
                      	pos = SampleVolumeKnobs.indexOf(component);  //tells us which control is being called...
                             TheGains[pos].setAttribute(TheGains[pos].Gain, value);
                      };
                      

                      HISE Development for hire.
                      www.channelrobot.com

                      ChazroxC 1 Reply Last reply Reply Quote 1
                      • ChazroxC
                        Chazrox @Lindon
                        last edited by

                        @Lindon Thank You 🙏 Im gonna try this in a bit and get back to you. Appreciate it! Love the energy. ⚡

                        1 Reply Last reply Reply Quote 0
                        • Oli UllmannO
                          Oli Ullmann @Lindon
                          last edited by

                          @Lindon
                          Yes, the components will be added in the order specified in the component list.

                          As for the index, I use a function that I call first in the callback and that returns the index. Something like this:

                          inline function getIndexAsInt(component)
                          {
                          	local index = component.getId().replace("knbVolume", "").getIntValue();
                          	return index;
                          }
                          
                          inline function getIndexAsString(component)
                          {
                          	local index = component.getId().replace("knbVolume", "");
                          	return index;
                          }
                          

                          The return value can then be used in the callback to determine the correct component....

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

                            @Oli-Ullmann said in Setting ControlCallback w/ Loops ?:

                            local index = component.getId().replace("knbVolume", "").getIntValue();

                            If you are storing all your components in an array you can get the index directly using indexOf

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

                            Oli UllmannO 1 Reply Last reply Reply Quote 1
                            • Oli UllmannO
                              Oli Ullmann @d.healey
                              last edited by

                              @d-healey
                              Yes, that's right! Thanks for the tip! :-)

                              1 Reply Last reply Reply Quote 0
                              • ChazroxC Chazrox has marked this topic as solved
                              • First post
                                Last post

                              14

                              Online

                              2.0k

                              Users

                              12.8k

                              Topics

                              111.1k

                              Posts