-Added metronome on / off toggle button

This commit is contained in:
Harry van Haaren 2013-05-15 23:27:31 +01:00
parent a30d540b49
commit 7efd73d71e
7 changed files with 57 additions and 33 deletions

View file

@ -22,6 +22,7 @@ namespace Event
RECORD, RECORD,
LOOPER_STATE, LOOPER_STATE,
METRONOME_ACTIVE,
}; };
}; };
@ -92,20 +93,16 @@ class EventPlaySample : public EventBase
} }
}; };
class EventRecord : public EventBase class EventMetronomeActive : public EventBase
{ {
public: public:
int type() { return int(RECORD); } int type() { return int(METRONOME_ACTIVE); }
uint32_t size() { return sizeof(EventRecord); } uint32_t size() { return sizeof(EventMetronomeActive); }
int track; bool active;
bool record;
EventRecord(int t, bool b) EventMetronomeActive() : active(false) {}
{ EventMetronomeActive(bool a) : active(a) {}
track = t;
record = b;
}
}; };

View file

@ -50,11 +50,11 @@ void handleDspEvents()
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventPlaySample) ); jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventPlaySample) );
//jack->setPlayBuffer( ev.track, ev.bufferID ); //jack->setPlayBuffer( ev.track, ev.bufferID );
} break; } } break; }
case Event::RECORD: { case Event::METRONOME_ACTIVE: {
if ( availableRead >= sizeof(EventRecord) ) { if ( availableRead >= sizeof(EventMetronomeActive) ) {
EventRecord ev(0,0); EventMetronomeActive ev(false);
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventRecord) ); jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventMetronomeActive) );
//jack->setRecord( ev.track, ev.record ); jack->getMetronome()->setActive(ev.active);
} break; } } break; }
case Event::LOOPER_STATE: { case Event::LOOPER_STATE: {
if ( availableRead >= sizeof(EventLooperState) ) { if ( availableRead >= sizeof(EventLooperState) ) {

View file

@ -17,7 +17,7 @@
using namespace std; using namespace std;
static void button_callback(Fl_Widget *w, void *data) { static void gtrack_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;
@ -63,12 +63,12 @@ class GTrack : public Fl_Group
{ {
ID = privateID++; ID = privateID++;
button1.callback( button_callback, &ID ); button1.callback( gtrack_button_callback, &ID );
button2.callback( button_callback, &ID ); button2.callback( gtrack_button_callback, &ID );
button3.callback( button_callback, &ID ); button3.callback( gtrack_button_callback, &ID );
button4.callback( button_callback, &ID ); button4.callback( gtrack_button_callback, &ID );
button5.callback( button_callback, &ID ); button5.callback( gtrack_button_callback, &ID );
button6.callback( button_callback, &ID ); button6.callback( gtrack_button_callback, &ID );
end(); // close the group end(); // close the group
} }

View file

@ -1,6 +1,7 @@
#include "gui.hxx" #include "gui.hxx"
#include "avtk/avtk_image.h" #include "avtk/avtk_image.h"
#include "avtk/avtk_button.h"
#include <sstream> #include <sstream>
@ -9,15 +10,27 @@ int GTrack::privateID = 0;
using namespace std; using namespace std;
Gui::Gui() static void gui_button_callback(Fl_Widget *w, void *data)
{ {
window = new Fl_Double_Window(600,280); Avtk::Button* b = (Avtk::Button*)w;
window->color(FL_BLACK); if ( strcmp( w->label(), "Metronome" ) == 0 )
window->label("Luppp 5"); {
b->value( !b->value() );
EventMetronomeActive e = EventMetronomeActive( b->value() );
writeToDspRingbuffer( &e );
}
}
Gui::Gui() :
window(600,280)
{
window.color(FL_BLACK);
window.label("Luppp 5");
Avtk::Image* header = new Avtk::Image(0,0,600,36,"header.png"); Avtk::Image* header = new Avtk::Image(0,0,600,36,"header.png");
metronomeButton = new Avtk::Button(0,0,200,30,"Metronome");
for (int i = 0; i < 5; i++ ) for (int i = 0; i < 5; i++ )
{ {
stringstream s; stringstream s;
@ -25,16 +38,18 @@ Gui::Gui()
tracks.push_back( new GTrack(8 + i * 118, 40, 110, 230, s.str().c_str() ) ); tracks.push_back( new GTrack(8 + i * 118, 40, 110, 230, s.str().c_str() ) );
} }
metronomeButton->callback( gui_button_callback, 0 );
box = new Fl_Box(655, 5, 200, 60, "BPM = 120"); box = new Fl_Box(655, 5, 200, 60, "BPM = 120");
box->box(FL_UP_BOX); box->box(FL_UP_BOX);
box->labelsize(36); box->labelsize(36);
box->labeltype(FL_SHADOW_LABEL); box->labeltype(FL_SHADOW_LABEL);
window->end(); window.end();
} }
int Gui::show() int Gui::show()
{ {
window->show(); window.show();
return Fl::run(); return Fl::run();
} }

View file

@ -19,9 +19,10 @@ class Gui
int show(); int show();
private: private:
Fl_Double_Window* window; Fl_Double_Window window;
Fl_Box* box; Fl_Box* box;
vector<GTrack*> tracks; Avtk::Button* metronomeButton;
vector<GTrack*> tracks;
}; };
#endif // LUPPP_GUI #endif // LUPPP_GUI

View file

@ -37,6 +37,7 @@ class Jack
loopers.at(t)->setState(s); loopers.at(t)->setState(s);
} }
Metronome* getMetronome(){return &metronome;}
TimeManager* getTimeManager(){return &timeManager;} TimeManager* getTimeManager(){return &timeManager;}
private: private:

View file

@ -17,7 +17,8 @@ class Metronome : public Observer
public: public:
Metronome() : Metronome() :
playPoint (0), playPoint (0),
playBar (false) playBar (false),
active (true)
{ {
// create beat and bar samples // create beat and bar samples
endPoint = (44100.f/441); endPoint = (44100.f/441);
@ -31,6 +32,11 @@ class Metronome : public Observer
} }
} }
void setActive(bool a)
{
active = a;
}
void bar() void bar()
{ {
playPoint = 0; playPoint = 0;
@ -51,6 +57,9 @@ class Metronome : public Observer
void process(int nframes, Buffers* buffers) void process(int nframes, Buffers* buffers)
{ {
if ( not active )
return;
float* out = buffers->audio[Buffers::MASTER_OUTPUT]; float* out = buffers->audio[Buffers::MASTER_OUTPUT];
float* sample = &beatSample[0]; float* sample = &beatSample[0];
@ -69,6 +78,7 @@ class Metronome : public Observer
private: private:
int fpb; int fpb;
bool playBar; bool playBar;
bool active;
int playPoint, endPoint; int playPoint, endPoint;
float barSample[44100]; float barSample[44100];