Fixed overflow issue. Code originally meant to truncate the 64 bit integer did not...
[ardour.git] / gtk2_ardour / gain_meter.h
1 /*
2     Copyright (C) 2002 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __ardour_gtk_gain_meter_h__
21 #define __ardour_gtk_gain_meter_h__
22
23 #include <vector>
24 #include <map>
25
26 #include <gtkmm/box.h>
27 #include <gtkmm/adjustment.h>
28 #include <gtkmm/frame.h>
29 #include <gtkmm/eventbox.h>
30 #include <gtkmm/button.h>
31 #include <gtkmm/table.h>
32 #include <gtkmm/drawingarea.h>
33
34 #include <ardour/types.h>
35
36 #include <gtkmm2ext/click_box.h>
37 #include <gtkmm2ext/focus_entry.h>
38 #include <gtkmm2ext/slider_controller.h>
39
40 #include "enums.h"
41 #include "level_meter.h"
42
43 namespace ARDOUR {
44         class IO;
45         class Session;
46         class Route;
47         class RouteGroup;
48 }
49 namespace Gtkmm2ext {
50         class FastMeter;
51         class BarController;
52 }
53 namespace Gtk {
54         class Menu;
55 }
56
57 class GainMeterBase : virtual public sigc::trackable
58 {
59   public:
60         GainMeterBase (boost::shared_ptr<ARDOUR::IO>, ARDOUR::Session&, const Glib::RefPtr<Gdk::Pixbuf>& pix,
61                        bool horizontal);
62         virtual ~GainMeterBase ();
63
64         void update_gain_sensitive ();
65         void update_meters ();
66         void effective_gain_display ();
67         void set_width (Width, int len=0);
68         void set_meter_strip_name (const char * name);
69         void set_fader_name (const char * name);
70
71         virtual void setup_meters (int len=0);
72
73         PBD::Controllable& get_controllable() { return _io->gain_control(); }
74         LevelMeter& get_level_meter() const { return *level_meter; }
75         Gtkmm2ext::SliderController& get_gain_slider() const { return *gain_slider; }
76         
77   protected:
78
79         friend class MixerStrip;
80         boost::shared_ptr<ARDOUR::IO> _io;
81         ARDOUR::Session& _session;
82
83         bool ignore_toggle;
84         bool next_release_selects;
85
86         Gtkmm2ext::SliderController *gain_slider;
87         Gtk::Adjustment              gain_adjustment;
88         Gtkmm2ext::FocusEntry        gain_display;
89         Gtk::Button                  peak_display;
90         Gtk::DrawingArea             meter_metric_area;
91         LevelMeter                  *level_meter;
92
93         sigc::connection gain_watching;
94
95         Gtk::Button gain_automation_style_button;
96         Gtk::ToggleButton gain_automation_state_button;
97
98         Gtk::Menu gain_astate_menu;
99         Gtk::Menu gain_astyle_menu;
100
101         gint gain_automation_style_button_event (GdkEventButton *);
102         gint gain_automation_state_button_event (GdkEventButton *);
103         gint pan_automation_style_button_event (GdkEventButton *);
104         gint pan_automation_state_button_event (GdkEventButton *);
105
106         void gain_automation_state_changed();
107         void gain_automation_style_changed();
108
109         std::string astate_string (ARDOUR::AutoState);
110         std::string short_astate_string (ARDOUR::AutoState);
111         std::string _astate_string (ARDOUR::AutoState, bool);
112
113         std::string astyle_string (ARDOUR::AutoStyle);
114         std::string short_astyle_string (ARDOUR::AutoStyle);
115         std::string _astyle_string (ARDOUR::AutoStyle, bool);
116
117         Width _width;
118
119         void show_gain ();
120         void gain_activated ();
121         bool gain_focused (GdkEventFocus*);
122
123         float       max_peak;
124         
125         void gain_adjusted ();
126         void gain_changed (void *);
127         
128         void meter_point_clicked ();
129         void gain_unit_changed ();
130         
131         virtual void hide_all_meters ();
132
133         gint meter_button_press (GdkEventButton*, uint32_t);
134
135         bool peak_button_release (GdkEventButton*);
136         bool gain_key_press (GdkEventKey*);
137         
138         Gtk::Menu* meter_menu;
139         void popup_meter_menu (GdkEventButton*);
140
141         gint start_gain_touch (GdkEventButton*);
142         gint end_gain_touch (GdkEventButton*);
143
144         void set_mix_group_meter_point (ARDOUR::Route&, ARDOUR::MeterPoint);
145         void set_meter_point (ARDOUR::Route&, ARDOUR::MeterPoint);
146         gint meter_release (GdkEventButton*);
147         gint meter_press (GdkEventButton*);
148         bool wait_for_release;
149         ARDOUR::MeterPoint old_meter_point;
150
151         void parameter_changed (const char*);
152
153         void reset_peak_display ();
154         void reset_group_peak_display (ARDOUR::RouteGroup*);
155
156         static sigc::signal<void> ResetAllPeakDisplays;
157         static sigc::signal<void,ARDOUR::RouteGroup*> ResetGroupPeakDisplays;
158
159         void on_theme_changed ();
160         bool style_changed;
161         bool dpi_changed;
162         bool color_changed;
163         void color_handler(bool);
164 };
165
166 class GainMeter : public GainMeterBase, public Gtk::VBox
167 {
168   public:
169         GainMeter (boost::shared_ptr<ARDOUR::IO>, ARDOUR::Session&);
170         ~GainMeter () {}
171
172         int get_gm_width ();
173         void setup_meters (int len=0);
174
175         static void setup_slider_pix ();
176
177   protected:
178         void hide_all_meters ();
179
180         gint meter_metrics_expose (GdkEventExpose *);
181
182         static std::map<std::string,Glib::RefPtr<Gdk::Pixmap> > metric_pixmaps;
183         static Glib::RefPtr<Gdk::Pixmap> render_metrics (Gtk::Widget&);
184
185   private:
186         Gtk::HBox  gain_display_box;
187         Gtk::HBox  fader_box;
188         Gtk::VBox* fader_vbox;
189         Gtk::HBox  hbox;
190
191         static Glib::RefPtr<Gdk::Pixbuf> slider;
192 };
193
194 #endif /* __ardour_gtk_gain_meter_h__ */
195