-Working on observer, timeManager and Looper sync. Bitwise flags in looper currently not working

main
Harry van Haaren 2013-05-15 04:05:36 +01:00
parent 42465a7b18
commit de2ddc8657
7 changed files with 83 additions and 50 deletions

View File

@ -19,21 +19,21 @@ using namespace std;
static void button_callback(Fl_Widget *w, void *data) { static void button_callback(Fl_Widget *w, void *data) {
int track = *(int*)data; int track = *(int*)data;
cout << "Button " << *(int*)data << w->label() << " clicked" << endl; cout << "Button " << *(int*)data << " " << w->label() << " clicked" << endl;
if ( strcmp( w->label() , "Rec" ) == 0 ) if ( strcmp( w->label() , "Rec" ) == 0 )
{ {
EventLooperState e = EventLooperState(track,Looper::STATE_RECORDING); EventLooperState e = EventLooperState(track,Looper::STATE_RECORD_QUEUED);
writeToDspRingbuffer( &e ); writeToDspRingbuffer( &e );
} }
else if ( strcmp( w->label() , "Play" ) == 0 ) else if ( strcmp( w->label() , "Play" ) == 0 )
{ {
EventLooperState e = EventLooperState(track,Looper::STATE_PLAYING); EventLooperState e = EventLooperState(track,Looper::STATE_PLAY_QUEUED);
writeToDspRingbuffer( &e ); writeToDspRingbuffer( &e );
} }
else if ( strcmp( w->label() , "Stop" ) == 0 ) else if ( strcmp( w->label() , "Stop" ) == 0 )
{ {
EventLooperState e = EventLooperState(track,Looper::STATE_STOPPED); EventLooperState e = EventLooperState(track,Looper::STATE_STOP_QUEUED);
writeToDspRingbuffer( &e ); writeToDspRingbuffer( &e );
} }
else else

View File

@ -11,7 +11,7 @@ using namespace std;
Gui::Gui() Gui::Gui()
{ {
window = new Fl_Double_Window(650,280); window = new Fl_Double_Window(600,280);
window->color(FL_BLACK); window->color(FL_BLACK);
window->label("Luppp 5"); window->label("Luppp 5");

View File

@ -74,7 +74,7 @@ int Jack::process (jack_nframes_t nframes)
// pre-zero output buffers // pre-zero output buffers
memset( buffers.audio[Buffers::MASTER_OUTPUT], 0, sizeof(float) * nframes ); memset( buffers.audio[Buffers::MASTER_OUTPUT], 0, sizeof(float) * nframes );
for(int i = 0; i < loopers.size(); i++) for(uint i = 0; i < loopers.size(); i++)
loopers.at(i)->process( nframes, &buffers ); loopers.at(i)->process( nframes, &buffers );
/* /*

View File

@ -3,37 +3,23 @@
#include "looper.hxx" #include "looper.hxx"
#include "jack.hxx" #include "jack.hxx"
extern Jack* jack;
void Looper::setState(State s) void Looper::setState(State s)
{ {
// before update, check if we recording, if so, print info // before update, check if we recording, if so, print info
/*
if ( state == STATE_RECORDING ) if ( state == STATE_RECORDING )
{ {
int newBpm = lastWrittenSampleIndex / 44100; int newBpm = 120;// (lastWrittenSampleIndex / (44100/2) ) * 60;
cout << "Looper " << track << " ending record: endPoint @ " << lastWrittenSampleIndex cout << "Looper " << track << " ending record: endPoint @ " << lastWrittenSampleIndex
<< ". Bpm " << newBpm << " perhaps?" << endl; << ". Bpm " << newBpm << " perhaps?" << endl;
jack->getTimeManager()->setBpm( newBpm ); jack->getTimeManager()->setBpm( newBpm );
} }
*/
// quantize?! // quantize?!
state = s; state |= s;
if ( state == STATE_PLAYING ) // setup PLAY
{
endPoint = lastWrittenSampleIndex;
playPoint = 0;
//cout << "State = PLAYING, endPoint = " << endPoint << endl;
}
else if ( state == STATE_RECORDING ) // setup REC
{
//cout << "State = RECORDING" << endl;
playPoint = 0;
endPoint = 0;
lastWrittenSampleIndex = 0;
}
else if ( state == STATE_STOPPED ) //
{
//cout << "State = STOPPED" << endl;
}
} }

View File

@ -8,32 +8,68 @@
#include "observer/observer.hxx" #include "observer/observer.hxx"
class Jack;
extern Jack* jack;
using namespace std; using namespace std;
class Looper : public Observer // for notifications class Looper : public Observer // for notifications
{ {
public: public:
enum State { enum State {
STATE_PLAYING = 0, STATE_PLAYING = 0x01,
STATE_RECORDING, STATE_PLAY_QUEUED = 0x02,
STATE_STOPPED, STATE_RECORDING = 0x03,
STATE_RECORD_QUEUED = 0x04,
STATE_STOPPED = 0x05,
STATE_STOP_QUEUED = 0x06,
}; };
Looper(int t) : Looper(int t) :
track(t), track(t),
state(STATE_STOPPED), state(0),
endPoint (0), endPoint (0),
playPoint (0) playPoint (0),
lastWrittenSampleIndex(0)
{ {
} }
void setFpb(int fpb) void bar()
{ {
cout << "Looper " << track << " got fpb of " << fpb << endl; cout << "Looper " << track << " got bar()" << flush;
cout << endl;
}
void beat()
{
//cout << "Looper " << track << " got beat()" << flush;
if ( state & STATE_PLAY_QUEUED )
{
state = 0;
cout << " Q->Playing ";
state = STATE_PLAYING;
playPoint = 0;
}
if ( state & STATE_RECORD_QUEUED )
{
state = 0;
cout << " Q->Recording ";
state = STATE_RECORDING;
playPoint = 0;
endPoint = 0;
lastWrittenSampleIndex = 0;
}
if ( state & STATE_PLAY_QUEUED )
{
state = 0;
cout << " Q->Stopped ";
state = STATE_STOPPED;
}
cout << endl;
}
void setFpb(int f)
{
fpb = f;
//cout << "Looper " << track << " got fpb of " << fpb << endl;
} }
void setState(State s); void setState(State s);
@ -43,8 +79,9 @@ class Looper : public Observer // for notifications
float* in = buffers->audio[Buffers::MASTER_INPUT]; float* in = buffers->audio[Buffers::MASTER_INPUT];
float* out = buffers->audio[Buffers::MASTER_OUTPUT]; float* out = buffers->audio[Buffers::MASTER_OUTPUT];
if ( state == STATE_PLAYING ) if ( state & STATE_PLAYING )
{ {
cout << "playing" << endl;
for(int i = 0; i < nframes; i++) for(int i = 0; i < nframes; i++)
{ {
if ( playPoint >= endPoint ) if ( playPoint >= endPoint )
@ -55,8 +92,9 @@ class Looper : public Observer // for notifications
} }
} }
else if ( state == STATE_RECORDING ) else if ( state & STATE_RECORDING )
{ {
cout << "recording" << endl;
for(int i = 0; i < nframes; i++) for(int i = 0; i < nframes; i++)
{ {
if ( lastWrittenSampleIndex < 44100 * 60 ) if ( lastWrittenSampleIndex < 44100 * 60 )
@ -65,14 +103,13 @@ class Looper : public Observer // for notifications
} }
} }
} }
// buffers pre-zeroed, so just do nothing
else if ( state == STATE_STOPPED ){}
} }
private: private:
int track; int track;
State state; unsigned int state;
int fpb;
int endPoint, playPoint, lastWrittenSampleIndex; int endPoint, playPoint, lastWrittenSampleIndex;
float sample[44100*60]; float sample[44100*60];

View File

@ -6,6 +6,10 @@ class Observer
{ {
public: public:
virtual void setFpb(int fpb){}; virtual void setFpb(int fpb){};
virtual void bar(){};
virtual void beat(){};
}; };
#endif // LUPPP_OBSERVER_H #endif // LUPPP_OBSERVER_H

View File

@ -15,14 +15,18 @@ class TimeManager
{ {
public: public:
TimeManager(): TimeManager():
oldBeat(0), bpm(120),
bpm(120) oldBeat(0)
{ {
} }
void setBpm(int b) void setBpm(int b)
{ {
bpm = b; bpm = b;
for(uint i = 0; i < observers.size(); i++)
{
observers.at(i)->setFpb(bpm);
}
} }
void registerObserver(Observer* o) void registerObserver(Observer* o)
@ -32,7 +36,6 @@ class TimeManager
void process(Buffers* buffers) void process(Buffers* buffers)
{ {
int framesPerBeat = (int) buffers->samplerate / (bpm / 60.0); int framesPerBeat = (int) buffers->samplerate / (bpm / 60.0);
// time signature? // time signature?
@ -48,14 +51,17 @@ class TimeManager
{ {
if ( beat % (int)buffers->transportPosition->beats_per_bar == 0 ) if ( beat % (int)buffers->transportPosition->beats_per_bar == 0 )
{ {
bpm++; // inform observers of new bar
for(int i = 0; i < observers.size(); i++) for(uint i = 0; i < observers.size(); i++) { observers.at(i)->bar(); }
{
observers.at(i)->setFpb(bpm);
}
buffers->transportPosition->bar++; buffers->transportPosition->bar++;
} }
// inform observers of new beat
for(uint i = 0; i < observers.size(); i++)
{
observers.at(i)->beat();
}
oldBeat = beat; oldBeat = beat;
} }