-Implemented Bar counter, now working

This commit is contained in:
Harry van Haaren 2013-07-27 17:16:37 +01:00
parent a259803b69
commit 5148aec4e5
3 changed files with 92 additions and 14 deletions

View file

@ -41,6 +41,14 @@ class Button : public Fl_Button
label = _label;
_r = 1.0;
_g = 0.48;
_b = 0.0;
_bgr = 0.11;
_bgg = 0.11;
_bgb = 0.11;
highlight = false;
mouseOver = false;
}
@ -50,6 +58,24 @@ class Button : public Fl_Button
int x, y, w, h;
const char* label;
float _r, _g, _b; // foreground colour
float _bgr, _bgg, _bgb; // background colour
float _outr, _outg, _outb; // outline colour
void setColor(float r, float g, float b)
{
_r = r;
_g = g;
_b = b;
}
void setBgColor(float r, float g, float b)
{
_bgr = r;
_bgg = g;
_bgb = b;
}
void draw()
{
if (damage() & FL_DAMAGE_ALL)
@ -59,7 +85,7 @@ class Button : public Fl_Button
cairo_save( cr );
cairo_rectangle( cr, x+1, y+1, w-2, h-2 );
cairo_set_source_rgb( cr,28 / 255.f, 28 / 255.f , 28 / 255.f );
cairo_set_source_rgb( cr, _bgr, _bgg, _bgb );
cairo_fill_preserve(cr);
cairo_set_line_width(cr, 1.3);
@ -67,14 +93,14 @@ class Button : public Fl_Button
if ( highlight )
{
cairo_set_source_rgba(cr, 1.0, 0.48, 0, 0.4);
cairo_set_source_rgba(cr, _r, _g, _b, 0.4);
cairo_fill_preserve(cr);
}
float alpha = 0.6;
if (mouseOver)
alpha = 1;
cairo_set_source_rgba(cr, 1.0, 0.48, 0, alpha);
cairo_set_source_rgba(cr, _r, _g, _b, alpha);
if ( highlight )
cairo_set_line_width(cr, 2.2);
cairo_stroke(cr);

View file

@ -43,6 +43,14 @@ class LightButton : public Fl_Button
_g = 0.48;
_b = 0.0;
_bgr = 0.11;
_bgg = 0.11;
_bgb = 0.11;
_outr = _r;
_outg = _g;
_outb = _b;
label = _label;
_highlight = false;
@ -53,7 +61,9 @@ class LightButton : public Fl_Button
bool _highlight;
int x, y, w, h;
const char* label;
float _r, _g, _b;
float _r, _g, _b; // foreground colour
float _bgr, _bgg, _bgb; // background colour
float _outr, _outg, _outb; // outline colour
void setColor(float r, float g, float b)
{
@ -62,6 +72,13 @@ class LightButton : public Fl_Button
_b = b;
}
void setBgColor(float r, float g, float b)
{
_bgr = r;
_bgg = g;
_bgb = b;
}
void draw()
{
if (damage() & FL_DAMAGE_ALL)
@ -80,7 +97,7 @@ class LightButton : public Fl_Button
cairo_save( cr );
cairo_rectangle( cr, x+1, y+1, w-2, h-2 );
cairo_set_source_rgb( cr,28 / 255.f, 28 / 255.f , 28 / 255.f );
cairo_set_source_rgba( cr, _bgr, _bgg, _bgb, 0.4 );
cairo_fill_preserve(cr);
cairo_set_line_width(cr, 1.5);

View file

@ -68,19 +68,32 @@ class GMasterTrack : public Fl_Group
source(x+5, y+26, 140, 100, ""),
tapTempo(x + 25 + 52, y + 26 + 5, 63, 30,"Tap"),
metronomeButton(x + 10,y + 26 + 5, 63, 30,"Metro"),
tapTempo(x + 25 + 52, y + 26 + 4, 63, 29,"Tap"),
metronomeButton(x + 9,y + 26 + 4, 64, 29,"Metro"),
volume(x+106, y +427, 36, 150, "Vol")
{
ID = privateID++;
bar = 0;
tapTempo.callback( gmastertrack_button_callback, &ID );
metronomeButton.callback( gmastertrack_button_callback, 0 );
tapTempo.setBgColor( 0, 0, 0 );
//metronomeButton.setBgColor( 0, 0, 0 );
metronomeButton.setColor( 0.4, 0.4, 0.4 );
//metronomeButton.setOutlineColor( 0.4, 0.4, 0.4 );
for(int i = 0; i < 4; i++)
{
beatLights[i] = new Avtk::LightButton( x + 10 + 33 * i, y + 26 + 38, 30, 30, "" );
int offset = 0;
/*
if ( i > 1 )
offset = 1;
*/
beatLights[i] = new Avtk::LightButton( x + 9 + 34 * i + offset, y + 25 + 37 , 30, 29, "" );
beatLights[i+4] = new Avtk::LightButton( x + 9 + 34 * i + offset, y + 25 + 37 + 32, 30, 29, "" );
}
beatLights[0]->setColor( 0.0, 1.0 , 0.0 );
@ -88,6 +101,11 @@ class GMasterTrack : public Fl_Group
beatLights[2]->setColor( 1.0, 0.48, 0.0 );
beatLights[3]->setColor( 1.0, 0.0 , 0.0 );
beatLights[4]->setColor( 0.0, 1.0 , 0.0 );
beatLights[5]->setColor( 1.0, 1.0 , 0.0 );
beatLights[6]->setColor( 1.0, 0.48, 0.0 );
beatLights[7]->setColor( 1.0, 0.0 , 0.0 );
volBox.maximum(1.0f);
volBox.minimum(0.0f);
volBox.color( FL_BLACK );
@ -103,16 +121,31 @@ class GMasterTrack : public Fl_Group
end(); // close the group
}
void setBarBeat(int bar, int beat)
void setBarBeat(int b, int beat)
{
cout << bar << " " << beat << endl;
if ( beat % 4 == 0 )
{
bar = bar % 4 + 1;
}
int num = (beat % 4) + 1;
// turn all off, then on again if its lit
for( int i = 0; i < 4; i++)
cout << bar << " " << num << endl;
// turn all off
for( int i = 0; i < 8; i++)
beatLights[i]->value( 0 );
for( int i = 0; i < num; i++)
// bar lights
for( int i = 0; i < bar; i++)
beatLights[i]->value( 1 );
// beat starts at 4
for( int i = 0; i < num; i++)
beatLights[i+4]->value( 1 );
}
~GMasterTrack()
@ -124,6 +157,8 @@ class GMasterTrack : public Fl_Group
private:
int ID;
int bar;
char* title;
Avtk::Background bg;
@ -136,7 +171,7 @@ class GMasterTrack : public Fl_Group
Avtk::Button tapTempo;
Avtk::LightButton metronomeButton;
Avtk::LightButton* beatLights[4];
Avtk::LightButton* beatLights[8];
Avtk::Volume volume;