-Added metronome on / off toggle button

main
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,
LOOPER_STATE,
METRONOME_ACTIVE,
};
};
@ -92,20 +93,16 @@ class EventPlaySample : public EventBase
}
};
class EventRecord : public EventBase
class EventMetronomeActive : public EventBase
{
public:
int type() { return int(RECORD); }
uint32_t size() { return sizeof(EventRecord); }
int type() { return int(METRONOME_ACTIVE); }
uint32_t size() { return sizeof(EventMetronomeActive); }
int track;
bool record;
bool active;
EventRecord(int t, bool b)
{
track = t;
record = b;
}
EventMetronomeActive() : active(false) {}
EventMetronomeActive(bool a) : active(a) {}
};

View File

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

View File

@ -17,7 +17,7 @@
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;
cout << "Button " << *(int*)data << " " << w->label() << " clicked" << endl;
@ -63,12 +63,12 @@ class GTrack : public Fl_Group
{
ID = privateID++;
button1.callback( button_callback, &ID );
button2.callback( button_callback, &ID );
button3.callback( button_callback, &ID );
button4.callback( button_callback, &ID );
button5.callback( button_callback, &ID );
button6.callback( button_callback, &ID );
button1.callback( gtrack_button_callback, &ID );
button2.callback( gtrack_button_callback, &ID );
button3.callback( gtrack_button_callback, &ID );
button4.callback( gtrack_button_callback, &ID );
button5.callback( gtrack_button_callback, &ID );
button6.callback( gtrack_button_callback, &ID );
end(); // close the group
}

View File

@ -1,6 +1,7 @@
#include "gui.hxx"
#include "avtk/avtk_image.h"
#include "avtk/avtk_button.h"
#include <sstream>
@ -9,15 +10,27 @@ int GTrack::privateID = 0;
using namespace std;
Gui::Gui()
static void gui_button_callback(Fl_Widget *w, void *data)
{
window = new Fl_Double_Window(600,280);
window->color(FL_BLACK);
window->label("Luppp 5");
Avtk::Button* b = (Avtk::Button*)w;
if ( strcmp( w->label(), "Metronome" ) == 0 )
{
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");
metronomeButton = new Avtk::Button(0,0,200,30,"Metronome");
for (int i = 0; i < 5; i++ )
{
stringstream s;
@ -25,16 +38,18 @@ Gui::Gui()
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->box(FL_UP_BOX);
box->labelsize(36);
box->labeltype(FL_SHADOW_LABEL);
window->end();
window.end();
}
int Gui::show()
{
window->show();
window.show();
return Fl::run();
}

View File

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

View File

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

View File

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