-Tap tempo now resets after 5 seconds un-tapped. Also uses 4th beat to calculate average

main
Harry van Haaren 2013-05-18 16:30:27 +01:00
parent 163a4b7a28
commit 7473e8d215
1 changed files with 9 additions and 2 deletions

View File

@ -12,7 +12,6 @@
using namespace std; using namespace std;
// inherits from ObserverSubject // inherits from ObserverSubject
class TimeManager class TimeManager
{ {
@ -57,6 +56,13 @@ class TimeManager
void tap() void tap()
{ {
// reset tap tempo to "first tap" if more than 5 secs elapsed since last tap
int sr = 44100;
if ( tapTempo[0] < frame - sr * 5 )
{
tapTempoPos = 0;
}
if ( tapTempoPos < 3 ) if ( tapTempoPos < 3 )
{ {
tapTempo[tapTempoPos] = frame; tapTempo[tapTempoPos] = frame;
@ -67,8 +73,9 @@ class TimeManager
// calculate frames per tap // calculate frames per tap
int tapFpb1 = tapTempo[1] - tapTempo[0]; int tapFpb1 = tapTempo[1] - tapTempo[0];
int tapFpb2 = tapTempo[2] - tapTempo[1]; int tapFpb2 = tapTempo[2] - tapTempo[1];
int tapFpb3 = frame - tapTempo[2]; // last tap, until now
int average = (tapFpb1 + tapFpb2) / 2; int average = (tapFpb1 + tapFpb2 + tapFpb3) / 3;
char buffer [50]; char buffer [50];
sprintf (buffer, "TM, tap() average = %i", average ); sprintf (buffer, "TM, tap() average = %i", average );