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"
|
|
|
|
|
|
|
|
class Jack;
|
|
|
|
extern Jack* jack;
|
|
|
|
|
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 {
|
|
|
|
STATE_PLAYING = 0,
|
|
|
|
STATE_RECORDING,
|
2013-05-13 23:20:00 +02:00
|
|
|
STATE_STOPPED,
|
2013-05-13 23:04:12 +02:00
|
|
|
};
|
|
|
|
|
2013-05-15 03:17:08 +02:00
|
|
|
Looper(int t) :
|
|
|
|
track(t),
|
2013-05-13 23:20:00 +02:00
|
|
|
state(STATE_STOPPED),
|
2013-05-13 23:04:12 +02:00
|
|
|
endPoint (0),
|
|
|
|
playPoint (0)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-15 03:55:51 +02:00
|
|
|
void setFpb(int fpb)
|
2013-05-13 23:04:12 +02:00
|
|
|
{
|
2013-05-15 03:55:51 +02:00
|
|
|
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];
|
|
|
|
|
|
|
|
if ( state == STATE_PLAYING )
|
|
|
|
{
|
|
|
|
for(int i = 0; i < nframes; i++)
|
|
|
|
{
|
|
|
|
if ( playPoint >= endPoint )
|
|
|
|
{
|
|
|
|
playPoint = 0;
|
|
|
|
}
|
|
|
|
out[i] += sample[playPoint++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ( state == STATE_RECORDING )
|
|
|
|
{
|
|
|
|
for(int i = 0; i < nframes; i++)
|
|
|
|
{
|
|
|
|
if ( lastWrittenSampleIndex < 44100 * 60 )
|
|
|
|
{
|
|
|
|
sample[lastWrittenSampleIndex++] = in[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-13 23:20:00 +02:00
|
|
|
|
|
|
|
// buffers pre-zeroed, so just do nothing
|
|
|
|
else if ( state == STATE_STOPPED ){}
|
2013-05-13 23:04:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-05-15 03:17:08 +02:00
|
|
|
int track;
|
2013-05-13 23:04:12 +02:00
|
|
|
State state;
|
|
|
|
|
|
|
|
int endPoint, playPoint, lastWrittenSampleIndex;
|
|
|
|
float sample[44100*60];
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LUPPP_LOOPER_H
|