diff --git a/src/looperclip.cxx b/src/looperclip.cxx index 5c9f79d..7f42fa4 100644 --- a/src/looperclip.cxx +++ b/src/looperclip.cxx @@ -158,7 +158,7 @@ void LooperClip::recieveSaveBuffer( AudioBuffer* saveBuffer ) else { char buffer [50]; - sprintf (buffer, "LC:: %i, s: can't save, buf too small",track, scene ); + sprintf (buffer, "LC:: %i, %i: can't save, buf too small",track, scene ); EventGuiPrint e( buffer ); writeToGuiRingbuffer( &e ); Stately::error(""); diff --git a/src/timemanager.cxx b/src/timemanager.cxx index 128c0b3..f9fe955 100644 --- a/src/timemanager.cxx +++ b/src/timemanager.cxx @@ -26,6 +26,8 @@ TimeManager::TimeManager(): beatFrameCountdown = fpb; + totalFrameCounter = 0; + tapTempoPos = 0; tapTempo[0] = 0; tapTempo[1] = 0; @@ -121,12 +123,6 @@ int TimeManager::getNframesToBeat() return beatFrameCountdown; } -bool TimeManager::beatInThisProcess() -{ - return beatInProcess; -} - - void TimeManager::process(Buffers* buffers) { // tap tempo measurements @@ -138,17 +134,25 @@ void TimeManager::process(Buffers* buffers) //buffers->transportPosition->beats_per_bar = 4; //buffers->transportPosition->beat_type = 4; + totalFrameCounter += buffers->nframes; - beatFrameCountdown = beatFrameCountdown - buffers->nframes; + //beatFrameCountdown = beatFrameCountdown - buffers->nframes; //printf("beatFCd %i, %i\n", beatFrameCountdown, buffers->nframes ); - if ( beatFrameCountdown < long(buffers->nframes) ) + + + // calculate beat / bar position in nframes + int beat = totalFrameCounter / fpb; + beatFrameCountdown = totalFrameCounter - (beat*fpb); + + + + + if ( beatFrameCountdown < buffers->nframes ) { beatCounter++; - beatInProcess = true; - // process *upto* beat frame: jack->processFrames( beatFrameCountdown ); @@ -170,15 +174,18 @@ void TimeManager::process(Buffers* buffers) } // process frames after beat() - int remaining = buffers->nframes - beatFrameCountdown; + + // 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 ) { - char buffer [50]; - sprintf (buffer, "remaining %i", remaining ); - EventGuiPrint e2( buffer ); - writeToGuiRingbuffer( &e2 ); - - jack->processFrames( remaining ); } else @@ -193,12 +200,11 @@ void TimeManager::process(Buffers* buffers) EventTimeBarBeat e( 0, beatCounter ); writeToGuiRingbuffer( &e ); - beatFrameCountdown = fpb; + beatFrameCountdown = fpb; } else { //printf("nframes %i\n", buffers->nframes ); - beatInProcess = false; jack->processFrames( buffers->nframes ); } diff --git a/src/timemanager.hxx b/src/timemanager.hxx index e38cd0f..394c0f1 100644 --- a/src/timemanager.hxx +++ b/src/timemanager.hxx @@ -31,17 +31,17 @@ class TimeManager /// returns the number of samples till beat if a beat exists in this process /// Otherwise returns nframes int getNframesToBeat(); - bool beatInThisProcess(); private: int samplerate; /// holds the number of frames before a beat //int nframesToBeat; - bool beatInProcess; + + long long totalFrameCounter; /// counts down frames until the next beat - int beatFrameCountdown; + long beatFrameCountdown; float fpb; int beatCounter;