2013-05-13 23:04:12 +02:00
|
|
|
|
|
|
|
#ifndef LUPPP_LOOPER_H
|
|
|
|
#define LUPPP_LOOPER_H
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "buffers.hxx"
|
|
|
|
|
2013-05-15 03:55:51 +02:00
|
|
|
#include "observer/observer.hxx"
|
|
|
|
|
2013-05-13 23:04:12 +02:00
|
|
|
using namespace std;
|
|
|
|
|
2013-05-15 03:55:51 +02:00
|
|
|
class Looper : public Observer // for notifications
|
2013-05-13 23:04:12 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum State {
|
2013-05-15 05:05:36 +02:00
|
|
|
STATE_PLAYING = 0x01,
|
|
|
|
STATE_PLAY_QUEUED = 0x02,
|
|
|
|
STATE_RECORDING = 0x03,
|
|
|
|
STATE_RECORD_QUEUED = 0x04,
|
|
|
|
STATE_STOPPED = 0x05,
|
|
|
|
STATE_STOP_QUEUED = 0x06,
|
2013-05-13 23:04:12 +02:00
|
|
|
};
|
|
|
|
|
2013-05-15 03:17:08 +02:00
|
|
|
Looper(int t) :
|
|
|
|
track(t),
|
2013-05-15 05:20:10 +02:00
|
|
|
state(STATE_STOPPED),
|
2013-05-13 23:04:12 +02:00
|
|
|
endPoint (0),
|
2013-05-15 05:05:36 +02:00
|
|
|
playPoint (0),
|
|
|
|
lastWrittenSampleIndex(0)
|
2013-05-13 23:04:12 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-15 05:05:36 +02:00
|
|
|
void bar()
|
2013-05-13 23:04:12 +02:00
|
|
|
{
|
2013-05-15 23:48:43 +02:00
|
|
|
//cout << "Looper " << track << " got bar()" << flush;
|
2013-05-15 05:20:10 +02:00
|
|
|
playPoint = 0;
|
|
|
|
|
|
|
|
if ( state == STATE_PLAY_QUEUED )
|
2013-05-15 05:05:36 +02:00
|
|
|
{
|
2013-05-15 23:48:43 +02:00
|
|
|
cout << " Q->Playing endpoint = " << endPoint << endl;
|
2013-05-15 05:05:36 +02:00
|
|
|
state = STATE_PLAYING;
|
|
|
|
playPoint = 0;
|
2013-05-15 05:20:10 +02:00
|
|
|
endPoint = lastWrittenSampleIndex;
|
2013-05-15 05:05:36 +02:00
|
|
|
}
|
2013-05-15 05:20:10 +02:00
|
|
|
if ( state == STATE_RECORD_QUEUED )
|
2013-05-15 05:05:36 +02:00
|
|
|
{
|
2013-05-15 23:48:43 +02:00
|
|
|
cout << " Q->Recording " << endl;
|
2013-05-15 05:05:36 +02:00
|
|
|
state = STATE_RECORDING;
|
|
|
|
playPoint = 0;
|
|
|
|
endPoint = 0;
|
|
|
|
lastWrittenSampleIndex = 0;
|
|
|
|
}
|
2013-05-15 05:20:10 +02:00
|
|
|
if ( state == STATE_PLAY_QUEUED )
|
2013-05-15 05:05:36 +02:00
|
|
|
{
|
2013-05-15 23:48:43 +02:00
|
|
|
cout << " Q->Stopped " << endl;
|
2013-05-15 05:05:36 +02:00
|
|
|
state = STATE_STOPPED;
|
2013-05-15 05:20:10 +02:00
|
|
|
endPoint = lastWrittenSampleIndex;
|
2013-05-15 05:05:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-15 05:20:10 +02:00
|
|
|
void beat()
|
|
|
|
{
|
|
|
|
//cout << "Looper " << track << " got beat()" << flush;
|
|
|
|
}
|
|
|
|
|
2013-05-15 05:05:36 +02:00
|
|
|
void setFpb(int f)
|
|
|
|
{
|
|
|
|
fpb = f;
|
|
|
|
//cout << "Looper " << track << " got fpb of " << fpb << endl;
|
2013-05-13 23:04:12 +02:00
|
|
|
}
|
|
|
|
|
2013-05-15 03:55:51 +02:00
|
|
|
void setState(State s);
|
|
|
|
|
2013-05-13 23:04:12 +02:00
|
|
|
void process(int nframes, Buffers* buffers)
|
|
|
|
{
|
|
|
|
float* in = buffers->audio[Buffers::MASTER_INPUT];
|
|
|
|
float* out = buffers->audio[Buffers::MASTER_OUTPUT];
|
|
|
|
|
2013-05-15 05:20:10 +02:00
|
|
|
if ( state == STATE_PLAYING )
|
2013-05-13 23:04:12 +02:00
|
|
|
{
|
|
|
|
for(int i = 0; i < nframes; i++)
|
|
|
|
{
|
2013-05-15 05:20:10 +02:00
|
|
|
if ( playPoint < endPoint )
|
2013-05-13 23:04:12 +02:00
|
|
|
{
|
2013-05-15 05:20:10 +02:00
|
|
|
out[i] += sample[playPoint++];
|
2013-05-13 23:04:12 +02:00
|
|
|
}
|
2013-05-15 05:20:10 +02:00
|
|
|
|
2013-05-13 23:04:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-15 05:20:10 +02:00
|
|
|
else if ( state == STATE_RECORDING )
|
2013-05-13 23:04:12 +02:00
|
|
|
{
|
2013-05-15 05:20:10 +02:00
|
|
|
cout << "recording " << endl;
|
2013-05-13 23:04:12 +02:00
|
|
|
for(int i = 0; i < nframes; i++)
|
|
|
|
{
|
|
|
|
if ( lastWrittenSampleIndex < 44100 * 60 )
|
|
|
|
{
|
|
|
|
sample[lastWrittenSampleIndex++] = in[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-05-15 03:17:08 +02:00
|
|
|
int track;
|
2013-05-15 05:20:10 +02:00
|
|
|
State state;
|
2013-05-15 05:05:36 +02:00
|
|
|
|
|
|
|
int fpb;
|
2013-05-13 23:04:12 +02:00
|
|
|
|
|
|
|
int endPoint, playPoint, lastWrittenSampleIndex;
|
|
|
|
float sample[44100*60];
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LUPPP_LOOPER_H
|