diff --git a/src/buffers.hxx b/src/buffers.hxx index 6b6c3a7..8970f8f 100644 --- a/src/buffers.hxx +++ b/src/buffers.hxx @@ -2,6 +2,7 @@ #ifndef LUPPP_BUFFERS_H #define LUPPP_BUFFERS_H +#include #include class Buffers diff --git a/src/gui.cxx b/src/gui.cxx index a212e14..fde5930 100644 --- a/src/gui.cxx +++ b/src/gui.cxx @@ -11,19 +11,13 @@ using namespace std; Gui::Gui() { - window = new Fl_Double_Window(600,280); + window = new Fl_Double_Window(650,280); window->color(FL_BLACK); window->label("Luppp 5"); Avtk::Image* header = new Avtk::Image(0,0,600,36,"header.png"); - /* - box = new Fl_Box(5, 5, 200, 60, "Luppp 5"); - box->box(FL_UP_BOX); - box->labelsize(36); - box->labeltype(FL_SHADOW_LABEL); - */ for (int i = 0; i < 5; i++ ) { stringstream s; @@ -31,6 +25,11 @@ Gui::Gui() tracks.push_back( new GTrack(8 + i * 118, 40, 110, 230, s.str().c_str() ) ); } + box = new Fl_Box(655, 5, 200, 60, "BPM = 120"); + box->box(FL_UP_BOX); + box->labelsize(36); + box->labeltype(FL_SHADOW_LABEL); + window->end(); } diff --git a/src/jack.cxx b/src/jack.cxx index b6bf114..1a12a0a 100644 --- a/src/jack.cxx +++ b/src/jack.cxx @@ -48,8 +48,10 @@ Jack::Jack() } for(int i = 0; i < 5; i++) + { loopers.push_back( new Looper(i) ); - + timeManager.registerObserver( loopers.back() ); + } jack_transport_start(client); } diff --git a/src/jack.hxx b/src/jack.hxx index cae95e8..b48195e 100644 --- a/src/jack.hxx +++ b/src/jack.hxx @@ -35,6 +35,8 @@ class Jack { loopers.at(t)->setState(s); } + + TimeManager* getTimeManager(){return &timeManager;} private: Buffers buffers; diff --git a/src/looper.cxx b/src/looper.cxx index e69de29..284b8ac 100644 --- a/src/looper.cxx +++ b/src/looper.cxx @@ -0,0 +1,39 @@ + + +#include "looper.hxx" + +#include "jack.hxx" + +void Looper::setState(State s) +{ + // before update, check if we recording, if so, print info + if ( state == STATE_RECORDING ) + { + int newBpm = lastWrittenSampleIndex / 44100; + 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; + } +} diff --git a/src/looper.hxx b/src/looper.hxx index 5cabad2..ab7f5b4 100644 --- a/src/looper.hxx +++ b/src/looper.hxx @@ -6,9 +6,14 @@ #include "buffers.hxx" +#include "observer/observer.hxx" + +class Jack; +extern Jack* jack; + using namespace std; -class Looper +class Looper : public Observer // for notifications { public: enum State { @@ -26,31 +31,13 @@ class Looper } - void setState(State s) + void setFpb(int fpb) { - // 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; - } - + cout << "Looper " << track << " got fpb of " << fpb << endl; } + void setState(State s); + void process(int nframes, Buffers* buffers) { float* in = buffers->audio[Buffers::MASTER_INPUT]; diff --git a/src/observer/observer.hxx b/src/observer/observer.hxx new file mode 100644 index 0000000..49a10d1 --- /dev/null +++ b/src/observer/observer.hxx @@ -0,0 +1,11 @@ + +#ifndef LUPPP_OBSERVER_H +#define LUPPP_OBSERVER_H + +class Observer +{ + public: + virtual void setFpb(int fpb){}; +}; + +#endif // LUPPP_OBSERVER_H diff --git a/src/timemanager.hxx b/src/timemanager.hxx index e43f31b..0caaddd 100644 --- a/src/timemanager.hxx +++ b/src/timemanager.hxx @@ -6,6 +6,8 @@ #include "buffers.hxx" +#include "observer/observer.hxx" + using namespace std; // inherits from ObserverSubject @@ -13,21 +15,31 @@ class TimeManager { public: TimeManager(): - oldBeat(0) + oldBeat(0), + bpm(120) { } + void setBpm(int b) + { + bpm = b; + } + + void registerObserver(Observer* o) + { + observers.push_back(o); + } + void process(Buffers* buffers) { - /* - float bpm = 160; + int framesPerBeat = (int) buffers->samplerate / (bpm / 60.0); // time signature? buffers->transportPosition->beats_per_bar = 4; buffers->transportPosition->beat_type = 4; - int beatFloat = buffers->transportFrame / framesPerBeat; + int beat = buffers->transportFrame / framesPerBeat; //int beat = int(beat); //int tick = int( (beatFloat - beat) * 1920 ); @@ -35,7 +47,14 @@ class TimeManager if ( beat != oldBeat ) { if ( beat % (int)buffers->transportPosition->beats_per_bar == 0 ) + { + bpm++; + for(int i = 0; i < observers.size(); i++) + { + observers.at(i)->setFpb(bpm); + } buffers->transportPosition->bar++; + } oldBeat = beat; } @@ -48,12 +67,14 @@ class TimeManager buffers->transportPosition->ticks_per_beat = 1920; buffers->transportPosition->beats_per_minute = bpm; - */ } private: + float bpm; int oldBeat; + std::vector observers; + // list of Observers of this TimeManager Subject, "beat", "bar" updates? /* for(int i = 0; i < numObservers; i++ ) diff --git a/wscript b/wscript index 88b6d2f..8cb8fe5 100644 --- a/wscript +++ b/wscript @@ -22,6 +22,7 @@ def build(bld): sources = ['src/gui.cxx', 'src/main.cxx', 'src/jack.cxx', + 'src/looper.cxx', 'src/eventhandlerdsp.cxx'] bld.program(source = sources, target='luppp5', use='JACK NTK')