-Loopers playback fixed, loopers now record numBeats themselves, auto syncing length to bar

main
Harry van Haaren 2013-05-16 16:31:22 +01:00
parent c7dac28706
commit cf8a22241e
1 changed files with 28 additions and 13 deletions

View File

@ -9,11 +9,22 @@ extern Jack* jack;
void Looper::setState(State s) void Looper::setState(State s)
{ {
if ( state == STATE_RECORDING )
{
cout << "stopRecordOnBar = true" << endl;
stopRecordOnBar = true;
}
// ensure we're not setting eg PLAY_QUEUED, if we're already PLAYING // ensure we're not setting eg PLAY_QUEUED, if we're already PLAYING
if ( static_cast<int>(s) != static_cast<int>(state) + 1) if ( static_cast<int>(s) != static_cast<int>(state) + 1)
{ {
cout << "new state " << s << endl; cout << "new state " << s << endl;
state = s; state = s;
if (state == STATE_RECORDING)
{
numBeats = 0;
}
} }
} }
@ -35,13 +46,18 @@ void Looper::process(int nframes, Buffers* buffers)
playPoint++; playPoint++;
} }
float prog = (float(playPoint) / fpb * numBeats); float prog = (float(playPoint) / (fpb*numBeats));
/*
if ( track == 0 ) if ( track == 0 )
cout << prog << " fpb*numBeats " << fpb * numBeats << endl; cout << prog << " playPoint " << playPoint << " endPoint " << endPoint
<< " fpb*numBeats " << fpb * numBeats << endl;
*/
EventLooperProgress e(track, prog ); EventLooperProgress e(track, prog );
writeToGuiRingbuffer( &e ); writeToGuiRingbuffer( &e );
} }
// stopRecordOnBar ensures we record right up to the bar measure
else if ( state == STATE_RECORDING || stopRecordOnBar ) else if ( state == STATE_RECORDING || stopRecordOnBar )
{ {
for(int i = 0; i < nframes; i++) for(int i = 0; i < nframes; i++)
@ -59,9 +75,11 @@ void Looper::bar()
{ {
stopRecordOnBar = false; stopRecordOnBar = false;
if ( state == STATE_RECORDING ) if ( playedBeats >= numBeats )
{ {
stopRecordOnBar = true; //cout << "Looper " << track << " restting to 0 " << endl;
playPoint = 0;
playedBeats = 0;
} }
if ( state == STATE_PLAY_QUEUED ) if ( state == STATE_PLAY_QUEUED )
@ -94,23 +112,20 @@ void Looper::bar()
void Looper::beat() void Looper::beat()
{ {
playedBeats++; // only reset if we're on the last beat of a loop if (state == STATE_RECORDING)
if ( playedBeats >= numBeats )
{ {
//cout << "Looper " << track << " restting to 0 " << endl; numBeats++;
playPoint = 0;
playedBeats = 0;
} }
playedBeats++; // only reset if we're on the last beat of a loop
} }
void Looper::setLoopLength(float l) void Looper::setLoopLength(float l)
{ {
numBeats *= l; numBeats *= l;
// avoid the 0 * 2 problem // smallest loop = 4 beats
if ( numBeats < 1 ) if ( numBeats < 4 )
numBeats = 1; numBeats = 4;
char buffer [50]; char buffer [50];
sprintf (buffer, "Looper loop lenght = %i", numBeats ); sprintf (buffer, "Looper loop lenght = %i", numBeats );