1 /***************************************************************************
2  *   Copyright (C) 2011 by Pere R�fols Soler                               *
3  *   sapista2@gmail.com                                                    *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 
21 #ifndef VU_WIDGET_H
22 #define VU_WIDGET_H
23 
24 #include <cmath>
25 #include <string>
26 #include <vector>
27 #include <gtkmm/drawingarea.h>
28 
29 #include <sys/time.h>
30 #define PEAK_CLEAR_TIMEOUT 2000
31 
32 class VUWidget : public Gtk::DrawingArea
33 {
34   public:
35     VUWidget(int iChannels, float fMin, float fMax,  std::string title, bool IsGainReduction = false, bool DrawThreshold = false);
36     ~VUWidget();
37     void setValue(int iChannel, float fValue);
38 
39     //Data accessors
40     void set_value_th(double value);
41     double get_value_th();
42 
43     //signal accessor:
44     typedef sigc::signal<void> signal_FaderChanged;
45     signal_FaderChanged signal_changed();
46 
47 protected:
48   //Override default signal handler:
49   virtual bool on_expose_event(GdkEventExpose* event);
50   virtual bool on_timeout_redraw();
51   virtual bool on_mouse_leave_widget(GdkEventCrossing* event);
52   void clearPeak(int uChannel);
53 
54   //Mouse grab signal handlers
55   virtual bool on_button_press_event(GdkEventButton* event);
56   virtual bool on_button_release_event(GdkEventButton* event);
57   virtual bool on_scrollwheel_event(GdkEventScroll* event);
58   virtual bool on_mouse_motion_event(GdkEventMotion* event);
59 
60   //Surface redraws
61   virtual void redraw_background();
62   virtual void redraw_foreground();
63   virtual void redraw_faderwidget();
64   virtual void redraw_vuwidget();
65 
66   int m_iChannels;
67   float m_fMin; //Min representable value in dB
68   float m_fMax; //Max representable value in dB
69   int m_textdBseparation;  //Integer number of dB for each VU text step
70   bool m_bIsGainReduction;
71   bool bMotionIsConnected;
72   float* m_fValues;
73   float* m_fPeaks;
74   int* m_iBuffCnt;
75 
76   float m_ThFaderValue;
77   int m_iThFaderPositon;
78   bool m_bDrawThreshold;
79   //sigc::connection* m_peak_connections;
80 private:
81     struct timeval *m_start; //Array of timeval start, on for each channel
82     struct timeval *m_end; //Array of timeval end, on for each channel
83 
84     int width;
85     int height;
86     std::string m_Title;
87     sigc::connection m_motion_connection;
88     bool m_redraw_fader, m_redraw_Vu, m_FaderFocus;
89 
90     //Fader change signal
91     signal_FaderChanged m_FaderChangedSignal;
92 
93     //dB to pixels convertion function
94     double dB2Pixels(double dB_in);
95 
96     //Cairo surfaces
97     Cairo::RefPtr<Cairo::ImageSurface> m_background_surface_ptr, m_foreground_surface_ptr, m_fader_surface_ptr, m_vu_surface_ptr;
98 };
99 #endif
100