Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tap Tempo.
I need a tap tempo using a key.

So the trigger will be "T".

I guess I'd like it to start the macro when "T" is pressed the first time and then record the time between clicks and then average those times. It'll need to timeout after not receiving a click for an amount of time. From there I want it to flash the NumLock light on a keyboard in accordance to the tempo.

jimmy Vig
So I need a function for tap tempo and I can figure it out, so I need help.

Minimum Tempo
Maximum Tempo
Required Taps
Timeout Length


Ultimately this function will be sending midi to a soft synth program that will adjust the tempo parameter. So the final "tempo" will be expressed between 0-127 (which will probably be offset in the synth program to affect the tempo between 40bpm and 180bpm)

Function SecondsToMIDI
Copy      Help
double seconds=0.36

double MaxTempo=180
double MinTempo=40

double MaxMIDI=127
double MinMIDI=0

int MIDI=((60/seconds)-MinTempo)*(MaxMIDI/(MaxTempo-MinTempo))

out MIDI

The number of times the trigger needs to be activated should be variable. (e.g. requires 3 taps to lock in a tempo)
*This is the biggest trouble is getting a function to start with a trigger and then keep track of time between triggering again and the number of times it has been triggered.

There will need to be a timeout length (probably calculated by the slowest tempo), so

An averaging function would be nice
if times to trigger is 4, then keeps track of all times and then on the 4 tap, averages them and uses that value
if the trigger is hit a 5th time, a new value is averaged and output. Same for 6th, 7th, etc until the timeout length is met (i.e. user has stopped hitting the button)

If the averaging function is turned off, the tempo would be calculated between the last two hits and converted to midi.

Any help on this? I've tried a few different things. Also, I'm looking at reading the MTC data in the MIDI. Anything about that?

Here is what I have worked out. I haven't really tested it, but should be ok.
Any ideas to make this better?

Function TapTempo
Trigger `     Help - how to add the trigger to the macro
Copy      Help
;;Declare in init2
#compile "__MidiOut"
MidiOut midi.Open(-1)

double NeededTaps=3
double MinTempo=60
double MaxTempo=187
double WaitMax=(60/MinTempo)*1000

int+ g_InsertKeyTime
int+ Counter
ARRAY(double)+ Clicks
if GetTickCount-g_InsertKeyTime<WaitMax
,if Counter>=NeededTaps-1
,,for int'i 0 NeededTaps-1
,,,double TotalTime=TotalTime+Clicks[i]
,,double Average=TotalTime/Clicks.len
,,double OSD=(GetTickCount-g_InsertKeyTime)
,,int MIDI=((Average)-MinTempo)*(127/(MaxTempo-MinTempo))
,,if MIDI>127
,,midi.SendB(0xB0 0 MIDI);;Sends MIDI value to CC0 on channel 1
,,OnScreenDisplay F"BPM:    {Average}[]MIDI:    {MIDI}" OSD/1000

Forum Jump:

Users browsing this thread: 1 Guest(s)