Tap Tempo function
-
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
-
@treynterrio You would need to record the time each "tap" occurs and then average the differences and convert that to a tempo value.
-
@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?
-
@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.
-
@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..
-
-
@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?