2013-05-13 23:04:12 +02:00
|
|
|
|
|
|
|
#ifndef LUPPP_LOOPER_H
|
|
|
|
#define LUPPP_LOOPER_H
|
|
|
|
|
2013-05-17 10:24:24 +02:00
|
|
|
#include <vector>
|
2013-05-13 23:04:12 +02:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "buffers.hxx"
|
2013-07-27 23:36:58 +02:00
|
|
|
#include "audioprocessor.hxx"
|
2013-05-15 03:55:51 +02:00
|
|
|
#include "observer/observer.hxx"
|
|
|
|
|
2013-05-20 02:08:10 +02:00
|
|
|
class AudioBuffer;
|
|
|
|
|
2013-05-13 23:04:12 +02:00
|
|
|
using namespace std;
|
|
|
|
|
2013-07-27 18:50:10 +02:00
|
|
|
/** LooperClip
|
|
|
|
* Represents each clip that a looper can playback. The core of the audio
|
|
|
|
* samples is stored in AudioBuffer objects which are dynamically resized. The
|
|
|
|
* base size of a AudioBuffer is 1 second's worth, after which larger buffers
|
|
|
|
* will be requested.
|
|
|
|
* The transition between AudioBuffer instances is seamless: when the clip is
|
|
|
|
* running out, the new one is requested. Upon its arrival the current data is
|
|
|
|
* copied, and the old buffer is returned for deallocation.
|
|
|
|
*
|
|
|
|
* This system allows for arbitrary length recordings, without huge
|
|
|
|
* pre-allocated buffers while it is still quite simple.
|
|
|
|
*
|
|
|
|
* Each clip has its properties like length and bars/beats, so the Looper knows
|
2013-07-27 19:24:04 +02:00
|
|
|
* to dynamically stretch / process the audio appropriately. Controllers and the
|
|
|
|
* UI are updated from this data.
|
2013-07-27 18:50:10 +02:00
|
|
|
**/
|
|
|
|
class LooperClip
|
|
|
|
{
|
|
|
|
public:
|
2013-07-27 19:24:04 +02:00
|
|
|
enum State {
|
|
|
|
STATE_PLAYING = 0,
|
|
|
|
STATE_PLAY_QUEUED,
|
|
|
|
STATE_RECORDING,
|
|
|
|
STATE_RECORD_QUEUED,
|
|
|
|
STATE_STOPPED,
|
|
|
|
STATE_STOP_QUEUED,
|
|
|
|
};
|
|
|
|
|
2013-07-27 18:50:10 +02:00
|
|
|
LooperClip()
|
|
|
|
{
|
2013-07-27 19:24:04 +02:00
|
|
|
_loaded = false;
|
|
|
|
_buffer = 0;
|
|
|
|
_state = STATE_STOPPED;
|
2013-07-27 18:50:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void setRequestedBuffer( AudioBuffer* ab )
|
|
|
|
{
|
2013-07-27 19:24:04 +02:00
|
|
|
// here we copy the data from the existing buffer into the new one,
|
|
|
|
// and send the old one away to be deallocated.
|
2013-07-27 18:50:10 +02:00
|
|
|
}
|
2013-07-27 19:24:04 +02:00
|
|
|
|
|
|
|
bool loaded(){return _loaded;}
|
|
|
|
State state(){return _state;}
|
|
|
|
|
|
|
|
// Set
|
|
|
|
void clipLength(int l){_clipLenght = l;}
|
2013-07-27 18:50:10 +02:00
|
|
|
|
|
|
|
private:
|
2013-07-27 19:24:04 +02:00
|
|
|
bool _loaded;
|
|
|
|
State _state;
|
|
|
|
AudioBuffer* _buffer;
|
|
|
|
|
|
|
|
// Clip Properties
|
|
|
|
int _clipLenght;
|
2013-07-27 18:50:10 +02:00
|
|
|
};
|
|
|
|
|
2013-07-27 19:24:04 +02:00
|
|
|
/** Looper
|
|
|
|
* The class which reads from LooperClips, and reads/ writes the data using the
|
|
|
|
* track buffer. Scene recording / playback is the essential functionality here.
|
|
|
|
**/
|
2013-07-30 01:56:13 +02:00
|
|
|
class Looper : public Observer, public AudioProcessor
|
2013-05-13 23:04:12 +02:00
|
|
|
{
|
|
|
|
public:
|
2013-07-27 19:24:04 +02:00
|
|
|
|
2013-05-13 23:04:12 +02:00
|
|
|
|
2013-05-17 10:24:24 +02:00
|
|
|
Looper(int t);
|
2013-05-13 23:04:12 +02:00
|
|
|
|
2013-05-20 02:08:10 +02:00
|
|
|
void setSample(int c, AudioBuffer* ab);
|
2013-05-20 00:57:12 +02:00
|
|
|
|
2013-05-18 20:52:12 +02:00
|
|
|
void midi(unsigned char* data);
|
2013-05-18 17:37:03 +02:00
|
|
|
|
2013-05-16 16:17:49 +02:00
|
|
|
void bar();
|
2013-05-16 17:14:14 +02:00
|
|
|
void beat();
|
2013-05-15 05:05:36 +02:00
|
|
|
|
2013-05-16 16:17:49 +02:00
|
|
|
void setFpb(int f) { fpb = f; }
|
2013-05-13 23:04:12 +02:00
|
|
|
|
2013-07-26 03:49:23 +02:00
|
|
|
void setScene( int sc );
|
2013-07-27 19:24:04 +02:00
|
|
|
//void setState( State s);
|
|
|
|
|
2013-05-15 03:55:51 +02:00
|
|
|
|
2013-05-19 03:01:22 +02:00
|
|
|
void updateControllers();
|
2013-05-16 14:38:46 +02:00
|
|
|
void process(int nframes, Buffers* buffers);
|
2013-05-13 23:04:12 +02:00
|
|
|
|
|
|
|
private:
|
2013-05-18 20:52:12 +02:00
|
|
|
const int track;
|
2013-07-27 19:24:04 +02:00
|
|
|
//State state;
|
2013-07-26 03:05:35 +02:00
|
|
|
int scene;
|
2013-05-15 05:05:36 +02:00
|
|
|
|
|
|
|
int fpb;
|
2013-05-18 21:33:13 +02:00
|
|
|
float gain;
|
2013-05-16 02:38:11 +02:00
|
|
|
int numBeats;
|
|
|
|
int playedBeats;
|
2013-05-16 17:14:14 +02:00
|
|
|
bool stopRecordOnBar;
|
2013-05-13 23:04:12 +02:00
|
|
|
|
2013-05-19 03:23:18 +02:00
|
|
|
int endPoint, lastWrittenSampleIndex;
|
|
|
|
float playPoint;
|
2013-07-26 03:05:35 +02:00
|
|
|
float* sample;
|
2013-07-27 19:24:04 +02:00
|
|
|
float* tmpRecordBuffer;
|
2013-05-17 10:24:24 +02:00
|
|
|
|
|
|
|
// Pitch Shifting
|
|
|
|
void pitchShift(int count, float* input, float* output);
|
|
|
|
vector<float> tmpBuffer;
|
|
|
|
int IOTA;
|
|
|
|
float fVec0[65536];
|
|
|
|
float semitoneShift;
|
|
|
|
float windowSize;
|
|
|
|
float fRec0[2];
|
|
|
|
float crossfadeSize;
|
|
|
|
float fSamplingFreq;
|
2013-07-30 19:34:47 +02:00
|
|
|
|
|
|
|
int uiUpdateConstant;
|
|
|
|
int uiUpdateCounter;
|
2013-05-13 23:04:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LUPPP_LOOPER_H
|