add option to resize meterbridge track-labels
[ardour.git] / gtk2_ardour / level_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_track_meter_h__
21 #define __ardour_gtk_track_meter_h__
22
23 #include <vector>
24
25 #include <gtkmm/box.h>
26 #include <gtkmm/adjustment.h>
27 #include <gtkmm/frame.h>
28 #include <gtkmm/eventbox.h>
29 #include <gtkmm/button.h>
30 #include <gtkmm/table.h>
31 #include <gtkmm/drawingarea.h>
32
33 #include "ardour/types.h"
34 #include "ardour/chan_count.h"
35 #include "ardour/session_handle.h"
36
37 #include <gtkmm2ext/click_box.h>
38 #include <gtkmm2ext/focus_entry.h>
39 #include <gtkmm2ext/slider_controller.h>
40 #include <gtkmm2ext/fastmeter.h>
41
42 #include "enums.h"
43
44 namespace ARDOUR {
45         class Session;
46         class PeakMeter;
47 }
48 namespace Gtk {
49         class Menu;
50 }
51
52 class LevelMeterBase : public ARDOUR::SessionHandlePtr
53 {
54   public:
55         LevelMeterBase (ARDOUR::Session*, PBD::EventLoop::InvalidationRecord* ir,
56                         Gtkmm2ext::FastMeter::Orientation o = Gtkmm2ext::FastMeter::Vertical);
57         virtual ~LevelMeterBase ();
58
59         virtual void set_meter (ARDOUR::PeakMeter* meter);
60
61         void update_gain_sensitive ();
62
63         float update_meters ();
64         void update_meters_falloff ();
65         void clear_meters (bool reset_highlight = true);
66         void hide_meters ();
67         void setup_meters (int len=0, int width=3, int thin=2);
68
69         void set_type (ARDOUR::MeterType);
70         ARDOUR::MeterType get_type () { return meter_type; }
71
72         /** Emitted in the GUI thread when a button is pressed over the meter */
73         PBD::Signal1<bool, GdkEventButton *> ButtonPress;
74         PBD::Signal1<bool, GdkEventButton *> ButtonRelease;
75         PBD::Signal1<void, ARDOUR::MeterType> MeterTypeChanged;
76
77         protected:
78         virtual void mtr_pack(Gtk::Widget &w) = 0;
79         virtual void mtr_remove(Gtk::Widget &w) = 0;
80
81   private:
82         PBD::EventLoop::InvalidationRecord* parent_invalidator;
83         ARDOUR::PeakMeter* _meter;
84         Gtkmm2ext::FastMeter::Orientation _meter_orientation;
85
86         Width _width;
87
88         struct MeterInfo {
89             Gtkmm2ext::FastMeter *meter;
90             gint16                width;
91             int                   length;
92             bool                  packed;
93             float                 max_peak;
94
95             MeterInfo() {
96                     meter = 0;
97                     width = 0;
98                     length = 0;
99                     packed = false;
100                     max_peak = -INFINITY;
101             }
102         };
103
104         guint16                regular_meter_width;
105         int                    meter_length;
106         guint16                thin_meter_width;
107         std::vector<MeterInfo> meters;
108         float                  max_peak;
109         ARDOUR::MeterType      meter_type;
110         ARDOUR::MeterType      visible_meter_type;
111
112         PBD::ScopedConnection _configuration_connection;
113         PBD::ScopedConnection _meter_type_connection;
114         PBD::ScopedConnection _parameter_connection;
115
116         void hide_all_meters ();
117         bool meter_button_press (GdkEventButton *);
118         bool meter_button_release (GdkEventButton *);
119
120         void parameter_changed (std::string);
121         void configuration_changed (ARDOUR::ChanCount in, ARDOUR::ChanCount out);
122         void meter_type_changed (ARDOUR::MeterType);
123
124         void on_theme_changed ();
125         bool style_changed;
126         bool color_changed;
127         void color_handler ();
128 };
129
130 class LevelMeterHBox : public LevelMeterBase, public Gtk::HBox
131 {
132   public:
133         LevelMeterHBox (ARDOUR::Session*);
134         ~LevelMeterHBox();
135
136         protected:
137         void mtr_pack(Gtk::Widget &w);
138         void mtr_remove(Gtk::Widget &w);
139 };
140
141 class LevelMeterVBox : public LevelMeterBase, public Gtk::VBox
142 {
143   public:
144         LevelMeterVBox (ARDOUR::Session*);
145         ~LevelMeterVBox();
146
147         protected:
148         void mtr_pack(Gtk::Widget &w);
149         void mtr_remove(Gtk::Widget &w);
150 };
151
152 #endif /* __ardour_gtk_track_meter_h__ */
153