From 8e0ca982554c8c69c97e6256b8ecb3c4a307d2ea Mon Sep 17 00:00:00 2001 From: Harry van Haaren Date: Thu, 5 Dec 2013 20:17:02 +0000 Subject: [PATCH] -Updated TimeManager --- src/timemanager.cxx | 24 ++++++------------------ src/timemanager.hxx | 13 ++++++++++--- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/timemanager.cxx b/src/timemanager.cxx index f9fe955..4a3ff70 100644 --- a/src/timemanager.cxx +++ b/src/timemanager.cxx @@ -22,6 +22,7 @@ TimeManager::TimeManager(): // 120 BPM default fpb = samplerate / 2; + barCounter = 0; beatCounter = 0; beatFrameCountdown = fpb; @@ -128,27 +129,17 @@ void TimeManager::process(Buffers* buffers) // tap tempo measurements frame = buffers->transportFrame; - //int framesPerBeat = (int) buffers->samplerate / (bpm / 60.0); - // time signature? //buffers->transportPosition->beats_per_bar = 4; //buffers->transportPosition->beat_type = 4; totalFrameCounter += buffers->nframes; - //beatFrameCountdown = beatFrameCountdown - buffers->nframes; - //printf("beatFCd %i, %i\n", beatFrameCountdown, buffers->nframes ); - - - - // calculate beat / bar position in nframes int beat = totalFrameCounter / fpb; beatFrameCountdown = totalFrameCounter - (beat*fpb); - - if ( beatFrameCountdown < buffers->nframes ) { beatCounter++; @@ -170,20 +161,18 @@ void TimeManager::process(Buffers* buffers) { observers.at(i)->bar(); } + barCounter++; //buffers->transportPosition->bar++; } // process frames after beat() - - // beatFrameCountdown < nframes in this case, so this remaining is a + int int remaining = long(buffers->nframes) - beatFrameCountdown; - + /* char buffer [50]; sprintf (buffer, "r: %i, nfr: %i, bFC %li\ttFC %lli", remaining, buffers->nframes, beatFrameCountdown, totalFrameCounter ); EventGuiPrint e2( buffer ); writeToGuiRingbuffer( &e2 ); - - + */ if ( remaining > 0 ) { jack->processFrames( remaining ); @@ -191,20 +180,19 @@ void TimeManager::process(Buffers* buffers) else { char buffer [50]; - sprintf (buffer, "weird negative remaining!! %i", remaining ); + sprintf (buffer, "Timing Error: negative samples %i", remaining ); EventGuiPrint e2( buffer ); writeToGuiRingbuffer( &e2 ); } // write new beat to UI (bar info currently not used) - EventTimeBarBeat e( 0, beatCounter ); + EventTimeBarBeat e( barCounter, beatCounter ); writeToGuiRingbuffer( &e ); beatFrameCountdown = fpb; } else { - //printf("nframes %i\n", buffers->nframes ); jack->processFrames( buffers->nframes ); } diff --git a/src/timemanager.hxx b/src/timemanager.hxx index 394c0f1..37d0c5f 100644 --- a/src/timemanager.hxx +++ b/src/timemanager.hxx @@ -22,10 +22,15 @@ class TimeManager void setBpmZeroOne(float bpm); void setFpb(float f); + /// add a component to be updated for time events void registerObserver(TimeObserver* o); + /// call this when a tempo-tap occurs 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); /// returns the number of samples till beat if a beat exists in this process @@ -35,15 +40,17 @@ class TimeManager private: int samplerate; - /// holds the number of frames before a beat - //int nframesToBeat; + /// number of frames per beat + float fpb; + /// holds the number of frames processed long long totalFrameCounter; /// counts down frames until the next beat long beatFrameCountdown; - float fpb; + /// counts bars / beats processed + int barCounter; int beatCounter; /// tap tempo measurements