HISE Logo Forum
    • Categories
    • Register
    • Login

    Tap Tempo function

    Scheduled Pinned Locked Moved Scripting
    7 Posts 4 Posters 355 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
      treynterrio
      last edited by treynterrio

      Hi there, does anyone have an idea how I could script a tap tempo function or if it is even possible? Like the tempo tapper in FL (see picture). To adjust the speed of the effects to the tempo. Thanks

      tap-tempo-estimating-fl-studio.jpeg

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

        @treynterrio You would need to record the time each "tap" occurs and then average the differences and convert that to a tempo value.

        Libre Wave - Freedom respecting instruments and effects
        My Patreon - HISE tutorials
        YouTube Channel - Public HISE tutorials

        T 1 Reply Last reply Reply Quote 0
        • T
          treynterrio @d.healey
          last edited by

          @d-healey said in Tap Tempo function:

          You would need to record the time each "tap" occurs and then average the differences and convert that to a tempo value.

          that sounds complicated :D how could I record the tempo?

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

            @treynterrio Each time the button is clicked you compare the current Engine uptime with the last Engine uptime and store the difference in an array. Then after you've got enough values you average them all and convert that to a tempo.

            To convert them to a tempo you have to calculate the BPM from the average. If my maths is correct it would be BPM = 60 / average tap time.

            Libre Wave - Freedom respecting instruments and effects
            My Patreon - HISE tutorials
            YouTube Channel - Public HISE tutorials

            J 1 Reply Last reply Reply Quote 0
            • J
              johnmike @d.healey
              last edited by

              @d-healey was intrigued by this so I hopped in with ChatGPT and started messing around with it with a bit back and forth I came up with this:

              namespace TapTempo
              {
                  const var tapButton = Content.getComponent("tapButton");
                  const var tapIntervals = []; // Array to store tap intervals
                  const var maxTaps = 4; // Maximum number of taps
                  var lastTapTime = Engine.getUptime(); // Define outside the inline function
                  var currentTime; // Declare these variables outside
                  var interval;
                  var totalInterval;
                  var averageInterval;
                  var bpm;
              
                  inline function onTapButtonControl(component, value)
                  {
                      if (value) // Only process when button is pressed
                      {
                          currentTime = Engine.getUptime(); // Update currentTime
                          interval = currentTime - lastTapTime; // Calculate interval
                          lastTapTime = currentTime;
              
                          // Manually maintain the array size
                          tapIntervals.push(interval); // Add the new interval
              
                          if (tapIntervals.length > maxTaps)
                          {
                              // Create a new array with only the last maxTaps intervals
                              newIntervals = []; // Declare this without 'var' for inline function
                              for (j = tapIntervals.length - maxTaps; j < tapIntervals.length; j++)
                                  newIntervals.push(tapIntervals[j]);
                              tapIntervals = newIntervals; // Assign the trimmed array back
                          }
              
                          if (tapIntervals.length > 1)
                          {
                              totalInterval = 0; // Reset totalInterval
                              for (i = 0; i < tapIntervals.length; i++) 
                                  totalInterval += tapIntervals[i];
                              
                              averageInterval = totalInterval / tapIntervals.length; // Calculate averageInterval
                              bpm = Math.round(60 / averageInterval); // Calculate bpm
                              Engine.setHostBpm(bpm);
                          }
                      }
                  }
              
                  tapButton.setControlCallback(onTapButtonControl);
              }
              
              

              when I tap this button like 2-3 times it slows the bpm down to like 10 or something really really slow...but when I go to tap it again it does nothing but the console throws the error:
              Line 27: Unqualified assignments are not supported anymore. Use var or const var or reg for definitions"

              I know this is a bit of AI generated goop...but im curious as to what the proper way to make this button work..

              orangeO 1 Reply Last reply Reply Quote 0
              • orangeO
                orange @johnmike
                last edited by

                @johnmike https://forum.hise.audio/topic/10873/delay-speed-tap/5?_=1730304075883

                develop Branch / XCode 13.1
                macOS Monterey / M1 Max

                J 1 Reply Last reply Reply Quote 1
                • J
                  johnmike @orange
                  last edited by

                  @orange wow...just should've scrolled back a few days in the forum lol...question...this is connected to a delay...how would I connect it to just the global BPM?

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

                  46

                  Online

                  1.7k

                  Users

                  11.7k

                  Topics

                  101.8k

                  Posts