mirror of
https://github.com/vale981/openAV-Luppp
synced 2025-03-04 16:51:37 -05:00
-Updated TimeManager
This commit is contained in:
parent
d7c0f4b73f
commit
8e0ca98255
2 changed files with 16 additions and 21 deletions
|
@ -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 );
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue