-Updated TimeManager

This commit is contained in:
Harry van Haaren 2013-12-05 20:17:02 +00:00
parent d7c0f4b73f
commit 8e0ca98255
2 changed files with 16 additions and 21 deletions

View file

@ -22,6 +22,7 @@ TimeManager::TimeManager():
// 120 BPM default // 120 BPM default
fpb = samplerate / 2; fpb = samplerate / 2;
barCounter = 0;
beatCounter = 0; beatCounter = 0;
beatFrameCountdown = fpb; beatFrameCountdown = fpb;
@ -128,27 +129,17 @@ void TimeManager::process(Buffers* buffers)
// tap tempo measurements // tap tempo measurements
frame = buffers->transportFrame; frame = buffers->transportFrame;
//int framesPerBeat = (int) buffers->samplerate / (bpm / 60.0);
// time signature? // time signature?
//buffers->transportPosition->beats_per_bar = 4; //buffers->transportPosition->beats_per_bar = 4;
//buffers->transportPosition->beat_type = 4; //buffers->transportPosition->beat_type = 4;
totalFrameCounter += buffers->nframes; totalFrameCounter += buffers->nframes;
//beatFrameCountdown = beatFrameCountdown - buffers->nframes;
//printf("beatFCd %i, %i\n", beatFrameCountdown, buffers->nframes );
// calculate beat / bar position in nframes // calculate beat / bar position in nframes
int beat = totalFrameCounter / fpb; int beat = totalFrameCounter / fpb;
beatFrameCountdown = totalFrameCounter - (beat*fpb); beatFrameCountdown = totalFrameCounter - (beat*fpb);
if ( beatFrameCountdown < buffers->nframes ) if ( beatFrameCountdown < buffers->nframes )
{ {
beatCounter++; beatCounter++;
@ -170,20 +161,18 @@ void TimeManager::process(Buffers* buffers)
{ {
observers.at(i)->bar(); observers.at(i)->bar();
} }
barCounter++;
//buffers->transportPosition->bar++; //buffers->transportPosition->bar++;
} }
// process frames after beat() // process frames after beat()
// beatFrameCountdown < nframes in this case, so this remaining is a + int
int remaining = long(buffers->nframes) - beatFrameCountdown; int remaining = long(buffers->nframes) - beatFrameCountdown;
/*
char buffer [50]; char buffer [50];
sprintf (buffer, "r: %i, nfr: %i, bFC %li\ttFC %lli", remaining, buffers->nframes, beatFrameCountdown, totalFrameCounter ); sprintf (buffer, "r: %i, nfr: %i, bFC %li\ttFC %lli", remaining, buffers->nframes, beatFrameCountdown, totalFrameCounter );
EventGuiPrint e2( buffer ); EventGuiPrint e2( buffer );
writeToGuiRingbuffer( &e2 ); writeToGuiRingbuffer( &e2 );
*/
if ( remaining > 0 ) if ( remaining > 0 )
{ {
jack->processFrames( remaining ); jack->processFrames( remaining );
@ -191,20 +180,19 @@ void TimeManager::process(Buffers* buffers)
else else
{ {
char buffer [50]; char buffer [50];
sprintf (buffer, "weird negative remaining!! %i", remaining ); sprintf (buffer, "Timing Error: negative samples %i", remaining );
EventGuiPrint e2( buffer ); EventGuiPrint e2( buffer );
writeToGuiRingbuffer( &e2 ); writeToGuiRingbuffer( &e2 );
} }
// write new beat to UI (bar info currently not used) // write new beat to UI (bar info currently not used)
EventTimeBarBeat e( 0, beatCounter ); EventTimeBarBeat e( barCounter, beatCounter );
writeToGuiRingbuffer( &e ); writeToGuiRingbuffer( &e );
beatFrameCountdown = fpb; beatFrameCountdown = fpb;
} }
else else
{ {
//printf("nframes %i\n", buffers->nframes );
jack->processFrames( buffers->nframes ); jack->processFrames( buffers->nframes );
} }

View file

@ -22,10 +22,15 @@ class TimeManager
void setBpmZeroOne(float bpm); void setBpmZeroOne(float bpm);
void setFpb(float f); void setFpb(float f);
/// add a component to be updated for time events
void registerObserver(TimeObserver* o); void registerObserver(TimeObserver* o);
/// call this when a tempo-tap occurs
void tap(); void tap();
/// called to process buffers->nframes samples. If a beat is present, this
/// is handled gracefully, first calling process up to the beat, then doing
/// a beat() event on all TimeObservers, and processing the remaining samples
void process(Buffers* buffers); void process(Buffers* buffers);
/// returns the number of samples till beat if a beat exists in this process /// returns the number of samples till beat if a beat exists in this process
@ -35,15 +40,17 @@ class TimeManager
private: private:
int samplerate; int samplerate;
/// holds the number of frames before a beat /// number of frames per beat
//int nframesToBeat; float fpb;
/// holds the number of frames processed
long long totalFrameCounter; long long totalFrameCounter;
/// counts down frames until the next beat /// counts down frames until the next beat
long beatFrameCountdown; long beatFrameCountdown;
float fpb; /// counts bars / beats processed
int barCounter;
int beatCounter; int beatCounter;
/// tap tempo measurements /// tap tempo measurements