2013-05-15 02:55:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
#include "looper.hxx"
|
|
|
|
|
|
|
|
#include "jack.hxx"
|
2013-05-16 13:38:46 +01:00
|
|
|
#include "eventhandler.hxx"
|
|
|
|
|
2013-05-15 04:05:36 +01:00
|
|
|
extern Jack* jack;
|
2013-05-15 02:55:51 +01:00
|
|
|
|
|
|
|
void Looper::setState(State s)
|
|
|
|
{
|
2013-05-16 01:38:11 +01:00
|
|
|
// ensure we're not setting eg PLAY_QUEUED, if we're already PLAYING
|
|
|
|
if ( static_cast<int>(s) != static_cast<int>(state) + 1)
|
2013-05-15 02:55:51 +01:00
|
|
|
{
|
2013-05-16 01:38:11 +01:00
|
|
|
cout << "new state " << s << endl;
|
|
|
|
state = s;
|
2013-05-15 02:55:51 +01:00
|
|
|
}
|
|
|
|
}
|
2013-05-16 01:38:11 +01:00
|
|
|
|
2013-05-16 13:38:46 +01:00
|
|
|
void Looper::process(int nframes, Buffers* buffers)
|
|
|
|
{
|
|
|
|
float* in = buffers->audio[Buffers::MASTER_INPUT];
|
|
|
|
float* out = buffers->audio[Buffers::MASTER_OUTPUT];
|
|
|
|
|
|
|
|
if ( state == STATE_PLAYING )
|
|
|
|
{
|
|
|
|
for(int i = 0; i < nframes; i++)
|
|
|
|
{
|
|
|
|
if ( playPoint < endPoint )
|
|
|
|
{
|
|
|
|
out[i] += sample[playPoint++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// update UI
|
|
|
|
EventLooperProgress e(track, float(playPoint) / endPoint );
|
|
|
|
writeToGuiRingbuffer( &e );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ( state == STATE_RECORDING )
|
|
|
|
{
|
|
|
|
cout << "recording " << endl;
|
|
|
|
for(int i = 0; i < nframes; i++)
|
|
|
|
{
|
|
|
|
if ( lastWrittenSampleIndex < 44100 * 60 )
|
|
|
|
{
|
|
|
|
sample[lastWrittenSampleIndex++] = in[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|