HISE Logo Forum
    • Categories
    • Register
    • Login

    Trigger animation only on value changes

    Scheduled Pinned Locked Moved General Questions
    5 Posts 3 Posters 231 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.
    • M
      Mighty23
      last edited by

      I'm looping a filmstrip animation following the example in the documentation. I would like to be able to change this type of animation so that it triggers only when the value of the knob changes, while at the moment the animation is more intense at higher values ​​​​and stops when the value is at zero.

      Current Implementation:

      // ANIMATION
      const var Panel1 = Content.getComponent("Panel1");
      
      reg index = 0; // index of the filmstrip 
      reg total_frames = 5; // total frames in the filmstrip
      reg frame_height = 1000; // the height(y) of each frame
      
      
      Panel1.loadImage("{PROJECT_FOLDER}filmstripFire.png", "dot");
      
      Panel1.setPaintRoutine(function(g){
          
          g.drawImage("dot", [0, 0, this.get("width"), this.get("height")], 0, index * frame_height);
      });
      
      Panel1.setTimerCallback(function(){
          index = (index + 1) % total_frames;
          this.repaint();
      });
      
      inline function onknbFeedbackControl(component, value)
      {
      	script_fx1.setAttribute(script_fx1.Feedback, value);
      	// trig animation
      	if (value) //  >> I need a new logic << 
      	    {  
      	        Panel1.startTimer(10);
      	    }
      	    else
      	    {
      	        Panel1.stopTimer();
      	    }
      		
      };
      

      Free Party, Free Tekno & Free Software too

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

        I recommend using a value change broadcaster.

        M 1 Reply Last reply Reply Quote 0
        • M
          Mighty23 @aaronventure
          last edited by

          @aaronventure Thanks for your reply but after reading the documentation I don't think I'll be able to make it happen. So I have to choose an option that I can be able to understand and reuse.

          My goal remains to trigger the animation only when the value changes:

          // ANIMATION
          const var Panel1 = Content.getComponent("Panel1");
          
          reg index = 0; // index of the filmstrip 
          reg total_frames = 5; // total frames in the filmstrip
          reg frame_height = 1000; // the height(y) of each frame
          
          Panel1.loadImage("{PROJECT_FOLDER}filmstripFire.png", "dot");
          
          Panel1.setPaintRoutine(function(g){
              g.drawImage("dot", [0, 0, this.get("width"), this.get("height")], 0, index * frame_height);
          });
          
          reg numCycles = 30; // Number of cycles to complete
          reg currentCycle = 0; // Current cycle counter
          
          Panel1.setTimerCallback(function(){
              index = (index + 1) % total_frames;
              this.repaint();
          
              // Check if we completed a cycle
              if (index == 0) 
              {
                  currentCycle++;
                  // Stop timer after completing the specified number of cycles
                  if (currentCycle >= numCycles)
                  {
                      Panel1.stopTimer();
                      currentCycle = 0; // Reset cycle counter
                  }
              }
          });
          
          // Variable to keep track of the previous knob value
          reg prevKnobValue = -1;
          inline function onknbFeedbackControl(component, value)
          {
          
          	script_fx3.setAttribute(script_fx3.Feedback, value);
          
          	// trig animation
          	if (value != prevKnobValue)
          	    {  
          	        Panel1.startTimer(100);
          	    }
          	    else
          	    {
          	        Panel1.stopTimer();
          	    }
          	
          		// Update the previous knob value
          		prevKnobValue = value;
          };
          Content.getComponent("knbFeedback").setControlCallback(onknbFeedbackControl);
          

          in this version the animation is triggered when the vst starts and (sometimes) does a shorter animation when the values ​​change. I could say I'm close to the solution but I can't make the animation "longer" when the "feedback" value changes.

          Free Party, Free Tekno & Free Software too

          ulrikU 1 Reply Last reply Reply Quote 0
          • ulrikU
            ulrik @Mighty23
            last edited by

            @Mighty23 if you remove this from your "onknbFeedbackControl", will it work?

            else
            {
                Panel1.stopTimer();
            }
            

            Hise Develop branch
            MacOs 15.3.1, Xcode 16.2
            http://musikboden.se

            M 1 Reply Last reply Reply Quote 1
            • M
              Mighty23 @ulrik
              last edited by

              @ulrik This solves the problem completely, thanks. By commenting that line I can get the desired result

              Free Party, Free Tekno & Free Software too

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

              15

              Online

              1.7k

              Users

              11.8k

              Topics

              103.0k

              Posts