HISE Logo Forum
    • Categories
    • Register
    • Login

    Fade out audio on button press

    Scheduled Pinned Locked Moved Scripting
    15 Posts 4 Posters 577 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.
    • T
      tomekslesicki @Christoph Hart
      last edited by

      @Christoph-Hart Thank you! Now, a side question because my brain doesn't comprehend this.

      I have some other actions I'd like to perform on the fade button. How can I set the timer so that it works like this:

      • Button pressed: 1s fade
      • Wait 1s
      • Rest of the action

      Thank you!

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

        Is this other action something on the UI? And is the event triggered by a control callback?

        T 1 Reply Last reply Reply Quote 0
        • T
          tomekslesicki @Christoph Hart
          last edited by

          @Christoph-Hart yeah, if’s on the UI. In fact, the fade is implemented in this context on an FX plugin:

          • if slider changes value
          • it activates the fade button
          • now the script should wait until the audio fades
          • convolution file is swapped
          • fade button gets new value, the audio fades back up

          It’s really there to hide clicks during the convolution swap. The fade should be very short (I can figure how to do this with the snippet you posted earlier so all good here) but generally speaking, I need some smoother experience without clicks in the audio.

          1 Reply Last reply Reply Quote 0
          • T
            tomekslesicki
            last edited by

            I already have the ir swap and button change working, just need the wait part

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

              Try a UI timer

              Link Preview Image
              HISE | Docs

              favicon

              (docs.hise.audio)

              1. Fade out the signal, start the timer with the same duration as the fade-out
              2. In the first timer callback, swap the ir
              3. In the second callback, stop the timer and fade in the signal again.

              You need a variable that stores the state (and change the state in each timer callback callback)

              1 Reply Last reply Reply Quote 1
              • T
                tomekslesicki
                last edited by

                Ok, almost there! It works great EXCEPT that it double triggers the fade button when moving the master slider. I'm pretty sure it's something obvious at this point?

                reg fade = true;
                
                const var FadeTimer = Engine.createTimerObject();
                
                const var Master = Content.getComponent("Master");
                const var FadeOutButton = Content.getComponent("FadeOutButton");
                
                
                inline function onMasterControl(component, value)
                { 
                            
                        // Filtr 1
                        if (value == 1)
                        {               
                            FadeTimer.setTimerCallback(function()
                            {
                                if(fade)
                                {
                                    fade = false;
                                    FadeOutButton.setValue(0);
                                    FadeOutButton.changed();
                                    Convo.setFile("{PROJECT_FOLDER}IR1.wav");
                                    Console.print("Swap");
                                }
                                else
                                {
                                    Console.print("Fadein");
                                    fade = true;
                                    FadeTimer.stopTimer();
                                    FadeOutButton.setValue(1);
                                    FadeOutButton.changed();
                                } 
                            });
                            FadeTimer.startTimer(50);
                        }
                
                        // Value 2
                        if (value == 2)
                        {
                                // Something else
                        }
                };
                
                Content.getComponent("Master").setControlCallback(onMasterControl);
                
                1 Reply Last reply Reply Quote 0
                • T
                  tomekslesicki
                  last edited by

                  @Christoph-Hart maybe I’m calling the var change in the wrong spot? The fade works great when I turn the knob but it also fires again once I release the mouse

                  1 Reply Last reply Reply Quote 0
                  • T
                    tomekslesicki
                    last edited by

                    Still can't figure it out, maybe it's just that my logic is tired. The script above works except that it the fade action again once the mouse is released.

                    @Christoph-Hart save me, please! ;-)

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

                      • Try to save the value argument of the onMasterControl in a reg variable and only fire the logic if it changes. This prevents multiple callbacks with the same value to fire multiple times.
                      • put the setTimerCallback() outside of the control callback.
                      • if you just select different IR's based on the slider's position, use an array with the names and then just pick up the one you want - this is especially true if you move the function declaration out of the value branch.
                      • before you call startTimer(), make sure to set the fade variable back to true.

                      So your control callback should only look like this:

                      inline function onMasterControl(component, value)
                      {
                          if(value != storedValue)
                          {
                              storedValue = value;
                              fade = true;
                              callFadeOutNow(); // no need to wait for the timer...
                              FadeTimer.startTimer(50);
                          }
                      }
                      
                      T 1 Reply Last reply Reply Quote 0
                      • T
                        tomekslesicki @Christoph Hart
                        last edited by

                        @Christoph-Hart thank you!

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

                        63

                        Online

                        1.7k

                        Users

                        11.7k

                        Topics

                        102.1k

                        Posts