-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) {
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 )
{
EventLooperState e = EventLooperState(track,Looper::STATE_RECORDING);
EventLooperState e = EventLooperState(track,Looper::STATE_RECORD_QUEUED);
writeToDspRingbuffer( &e );
}
else if ( strcmp( w->label() , "Play" ) == 0 )
{
EventLooperState e = EventLooperState(track,Looper::STATE_PLAYING);
EventLooperState e = EventLooperState(track,Looper::STATE_PLAY_QUEUED);
writeToDspRingbuffer( &e );
}
else if ( strcmp( w->label() , "Stop" ) == 0 )
{
EventLooperState e = EventLooperState(track,Looper::STATE_STOPPED);
EventLooperState e = EventLooperState(track,Looper::STATE_STOP_QUEUED);
writeToDspRingbuffer( &e );
}
else

View File

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

View File

@ -74,7 +74,7 @@ int Jack::process (jack_nframes_t nframes)
// pre-zero output buffers
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 );
/*

View File

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

View File

@ -8,32 +8,68 @@
#include "observer/observer.hxx"
class Jack;
extern Jack* jack;
using namespace std;
class Looper : public Observer // for notifications
{
public:
enum State {
STATE_PLAYING = 0,
STATE_RECORDING,
STATE_STOPPED,
STATE_PLAYING = 0x01,
STATE_PLAY_QUEUED = 0x02,
STATE_RECORDING = 0x03,
STATE_RECORD_QUEUED = 0x04,
STATE_STOPPED = 0x05,
STATE_STOP_QUEUED = 0x06,
};
Looper(int t) :
track(t),
state(STATE_STOPPED),
state(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);
@ -43,8 +79,9 @@ class Looper : public Observer // for notifications
float* in = buffers->audio[Buffers::MASTER_INPUT];
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++)
{
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++)
{
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:
int track;
State state;
unsigned int state;
int fpb;
int endPoint, playPoint, lastWrittenSampleIndex;
float sample[44100*60];

View File

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

View File

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