From e28afcd2cd32119ceec9400de2412abb7fecc72b Mon Sep 17 00:00:00 2001 From: Harry van Haaren Date: Sat, 20 Apr 2013 12:20:46 +0100 Subject: [PATCH] -Gtrack added, denormals taken care of --- src/avtk/avtk_button.h | 116 +++++++++++++++++++++++++++++++++++++++++ src/denormals.hxx | 34 ++++++++++++ src/gtrack.hxx | 32 ++++++++++++ src/gui.cxx | 9 +++- src/gui.hxx | 4 ++ src/main.cxx | 5 +- 6 files changed, 197 insertions(+), 3 deletions(-) create mode 100644 src/avtk/avtk_button.h create mode 100644 src/denormals.hxx create mode 100644 src/gtrack.hxx diff --git a/src/avtk/avtk_button.h b/src/avtk/avtk_button.h new file mode 100644 index 0000000..f45b106 --- /dev/null +++ b/src/avtk/avtk_button.h @@ -0,0 +1,116 @@ + +#ifndef AVTK_BUTTON_H +#define AVTK_BUTTON_H + +#include + +class AvtkButton : public Fl_Button +{ + public: + AvtkButton(int _x, int _y, int _w, int _h, const char *_label=0): + Fl_Button(_x, _y, _w, _h, _label) + { + x = _x; + y = _y; + w = _w; + h = _h; + + label = _label; + + highlight = false; + mouseOver = false; + } + + bool mouseOver; + bool highlight; + int x, y, w, h; + const char* label; + + void draw() + { + if (damage() & FL_DAMAGE_ALL) + { + cairo_t *cr = Fl::cairo_cc(); + + 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_fill_preserve(cr); + + cairo_set_line_width(cr, 1.5); + cairo_rectangle( cr, x+1, y+1, w-2, h-2 ); + + if ( highlight ) + { + cairo_set_source_rgba(cr, 1.0, 0.48, 0, 0.4); + cairo_fill_preserve(cr); + } + + float alpha = 0.7; + if (mouseOver) + alpha = 1; + cairo_set_source_rgba(cr, 1.0, 0.48, 0, alpha); + cairo_stroke(cr); + + cairo_restore( cr ); + + draw_label(); + } + } + + void resize(int X, int Y, int W, int H) + { + Fl_Widget::resize(X,Y,W,H); + x = X; + y = Y; + w = W; + h = H; + redraw(); + } + + int handle(int event) + { + switch(event) { + case FL_PUSH: + highlight = 1; + redraw(); + return 1; + case FL_DRAG: { + int t = Fl::event_inside(this); + if (t != highlight) { + highlight = t; + redraw(); + } + } + return 1; + case FL_ENTER: + mouseOver = true; + redraw(); + return 1; + case FL_LEAVE: + mouseOver = false; + redraw(); + return 1; + case FL_RELEASE: + if (highlight) { + highlight = 0; + redraw(); + do_callback(); + } + return 1; + case FL_SHORTCUT: + if ( test_shortcut() ) + { + do_callback(); + return 1; + } + return 0; + default: + return Fl_Widget::handle(event); + } + } +}; + +#endif // AVTK_BUTTON_H + diff --git a/src/denormals.hxx b/src/denormals.hxx new file mode 100644 index 0000000..37af540 --- /dev/null +++ b/src/denormals.hxx @@ -0,0 +1,34 @@ +#ifndef LUPPP_DENORMALS_H +#define LUPPP_DENORMALS_H + +#include + +#ifdef __SSE__ +/* On Intel set FZ (Flush to Zero) and DAZ (Denormals Are Zero) + flags to avoid costly denormals */ +#ifdef __SSE3__ +#include +inline void AVOIDDENORMALS() +{ + //std::cout << "Denormals: FZ DAZ using SSE3" << std::endl; + _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); + _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); +} +#else +#include +inline void AVOIDDENORMALS() +{ + //std::cout << "Denormals: FZ" << std::endl; + _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); +} +#endif //__SSE3__ + +#else +inline void AVOIDDENORMALS() +{ + std::cout << "Denormals: Warning! No protection" << std::endl; +} +#endif //__SSE__ + +#endif // LUPPP_DENORMALS_H + diff --git a/src/gtrack.hxx b/src/gtrack.hxx new file mode 100644 index 0000000..7745317 --- /dev/null +++ b/src/gtrack.hxx @@ -0,0 +1,32 @@ + +#ifndef LUPPP_G_TRACK_H +#define LUPPP_G_TRACK_H + +#include +#include +#include + +#include "avtk/avtk_button.h" + +class GTrack : public Fl_Group +{ + public: + GTrack(int x, int y, int w, int h ) : + Fl_Group(x, y, w, h), + button(x + 5, y + 5, 100, 20,"Quit"), + button2(x + 5, y + 25, 100, 20,"2"), + button3(x + 5, y + 45, 100, 20,"3") + //slider(x, y + 50, w, 20) + { + end(); // close the group + } + + + private: + AvtkButton button; + AvtkButton button2; + AvtkButton button3; +}; + +#endif // LUPPP_G_TRACK_H + diff --git a/src/gui.cxx b/src/gui.cxx index 0f178cd..d98517b 100644 --- a/src/gui.cxx +++ b/src/gui.cxx @@ -4,11 +4,16 @@ Gui::Gui() { - window = new Fl_Window(340,180); - box = new Fl_Box(20,40,300,100,"Luppp 5"); + window = new Fl_Window(640,280); + window->color(FL_BLACK); + box = new Fl_Box(5, 5, 200, 60, "Luppp 5"); box->box(FL_UP_BOX); box->labelsize(36); box->labeltype(FL_SHADOW_LABEL); + + track = new GTrack(5,80,200,200); + track2 = new GTrack(120,80,200,200); + window->end(); } diff --git a/src/gui.hxx b/src/gui.hxx index e7d7ff0..16dad6d 100644 --- a/src/gui.hxx +++ b/src/gui.hxx @@ -6,6 +6,8 @@ #include #include +#include "gtrack.hxx" + class Gui { public: @@ -15,6 +17,8 @@ class Gui private: Fl_Window* window; Fl_Box* box; + GTrack* track; + GTrack* track2; }; #endif // LUPPP_GUI diff --git a/src/main.cxx b/src/main.cxx index cc3f9c2..9307c13 100644 --- a/src/main.cxx +++ b/src/main.cxx @@ -10,6 +10,7 @@ #include "gui.hxx" #include "jack.hxx" #include "event.hxx" +#include "denormals.hxx" char* processDspMem = 0; @@ -22,6 +23,9 @@ Jack* jack = 0; int main() { + // setup the environment + AVOIDDENORMALS(); + // allocate data to read from processDspMem = (char*)malloc( sizeof(EventBase) ); processOscMem = (char*)malloc( sizeof(EventBase) ); @@ -31,7 +35,6 @@ int main() jack = new Jack(); - jack->activate(); Gui gui;