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.
    • ChazroxC
      Chazrox
      last edited by Chazrox

      Can someone please advise on this....

      im trying to learn how to set control callbacks with loops for obvious reasons when dealing with large amounts of components.

      I know i've seen an example of this before somewhere but I cant remember where, so I've been trying to do it from scratch but i've been stuck. Can you please advise?

      Be nice, this is my first time doing this. 😆

      const var SimpleGain1 = Synth.getEffect("Simple Gain1");
      const var SimpleGain2 = Synth.getEffect("Simple Gain2");
      const var SimpleGain3 = Synth.getEffect("Simple Gain3");
      const var SimpleGain4 = Synth.getEffect("Simple Gain4");
      const var SimpleGain5 = Synth.getEffect("Simple Gain5");
      const var SimpleGain6 = Synth.getEffect("Simple Gain6");
      const var SimpleGain7 = Synth.getEffect("Simple Gain7");
      const var SimpleGain8 = Synth.getEffect("Simple Gain8");
      
      const var samplers = [
          AudioLoopPlayer1Sampler,
          AudioLoopPlayer2Sampler,
          AudioLoopPlayer3Sampler,
          AudioLoopPlayer4Sampler,
          AudioLoopPlayer5Sampler,
          AudioLoopPlayer6Sampler,
          AudioLoopPlayer7Sampler,
          AudioLoopPlayer8Sampler
      ];
      
      
      const var SampleVolumeKnobs = [Content.getComponent("knbVolume1"),
                                     Content.getComponent("knbVolume2"),
                                     Content.getComponent("knbVolume3"),
                                     Content.getComponent("knbVolume4"),
                                     Content.getComponent("knbVolume5"),
                                     Content.getComponent("knbVolume6"),
                                     Content.getComponent("knbVolume7"),
                                     Content.getComponent("knbVolume8")];
      
      inline function onSampleVolumeKnobsControl(component, value)
      {
      	for (i = 0; i < samplers.length; i++) // used samplers.length to be difficult. im using this length    somewhere else also so it was convenient 
      	{
      		i.setAttribute(0, value);				
      	}
      };
      
      inline function allSampleVolumeKnobs(component, value)
      {
      	for (i = 0; i < 7; i++)
      	{
      		if (value)
      		{
      			SimpleGain[i].setControlCallback(onSampleVolumeKnobsControl);
      		}
      	}
      }
      

      I have a good feeling that I goofed this. lmao.

      1 Reply Last reply Reply Quote 0
      • OrvillainO
        Orvillain
        last edited by

        Is that the full script? You don't seem to ever be calling allSampleVolumeKnobs ???

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

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

          @Orvillain sheet. lol. See.. I told you im goofing it. all the loops got me in a loop. lol. Im not exactly sure how to go about that at the moment. Im definitely mixed up a little bit but still trying to figure it out.

          LindonL Oli UllmannO 2 Replies Last reply Reply Quote 0
          • LindonL
            Lindon @Chazrox
            last edited by Lindon

            @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);
            }
            
            
            

            HISE Development for hire.
            www.channelrobot.com

            LindonL 1 Reply Last reply Reply Quote 2
            • 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

                                      12

                                      Online

                                      2.0k

                                      Users

                                      12.8k

                                      Topics

                                      111.1k

                                      Posts