2 Copyright (C) 2002 Paul Davis
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.
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.
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.
22 #include <ardour/io.h>
23 #include <ardour/route.h>
24 #include <ardour/route_group.h>
25 #include <ardour/session.h>
26 #include <ardour/session_route.h>
27 #include <ardour/dB.h>
29 #include <gtkmm2ext/utils.h>
30 #include <gtkmm2ext/fastmeter.h>
31 #include <gtkmm2ext/stop_signal.h>
32 #include <gtkmm2ext/barcontroller.h>
33 #include <midi++/manager.h>
34 #include <pbd/fastlog.h>
36 #include "ardour_ui.h"
37 #include "level_meter.h"
40 #include "gui_thread.h"
42 #include "public_editor.h"
44 #include <ardour/session.h>
45 #include <ardour/route.h>
49 using namespace ARDOUR
;
51 using namespace Gtkmm2ext
;
56 //sigc::signal<void> LevelMeter::ResetAllPeakDisplays;
57 //sigc::signal<void,RouteGroup*> LevelMeter::ResetGroupPeakDisplays;
60 LevelMeter::LevelMeter (Session
& s
)
65 Config
->ParameterChanged
.connect (mem_fun (*this, &LevelMeter::parameter_changed
));
66 UI::instance()->theme_changed
.connect (mem_fun(*this, &LevelMeter::on_theme_changed
));
67 ColorsChanged
.connect (mem_fun (*this, &LevelMeter::color_handler
));
68 max_peak
= minus_infinity();
72 LevelMeter::on_theme_changed()
77 LevelMeter::~LevelMeter ()
79 for (vector
<MeterInfo
>::iterator i
= meters
.begin(); i
!= meters
.end(); i
++) {
87 LevelMeter::set_io (boost::shared_ptr
<IO
> io
)
93 LevelMeter::update_meters ()
95 vector
<MeterInfo
>::iterator i
;
99 for (n
= 0, i
= meters
.begin(); i
!= meters
.end(); ++i
, ++n
) {
101 peak
= _io
->peak_input_power (n
);
102 (*i
).meter
->set (log_meter (peak
));
103 mpeak
= _io
->max_peak_power(n
);
104 if (mpeak
> max_peak
) {
113 LevelMeter::parameter_changed(const char* parameter_name
)
115 #define PARAM_IS(x) (!strcmp (parameter_name, (x)))
117 ENSURE_GUI_THREAD (bind (mem_fun(*this, &LevelMeter::parameter_changed
), parameter_name
));
119 if (PARAM_IS ("meter-hold")) {
121 vector
<MeterInfo
>::iterator i
;
124 for (n
= 0, i
= meters
.begin(); i
!= meters
.end(); ++i
, ++n
) {
126 (*i
).meter
->set_hold_count ((uint32_t) floor(Config
->get_meter_hold()));
134 LevelMeter::hide_all_meters ()
137 for (vector
<MeterInfo
>::iterator i
= meters
.begin(); i
!= meters
.end(); ++i
) {
139 remove (*((*i
).meter
));
146 LevelMeter::setup_meters (int len
, int initial_width
)
149 return; /* do it later */
152 regular_meter_width
= initial_width
;
153 uint32_t nmeters
= _io
->n_outputs();
160 if ((r
= dynamic_cast<Route
*> (_io
.get())) != 0) {
162 switch (r
->meter_point()) {
165 nmeters
= r
->n_inputs();
168 nmeters
= r
->n_outputs();
174 nmeters
= _io
->n_outputs();
183 width
= regular_meter_width
;
185 width
= thin_meter_width
;
188 while (meters
.size() < nmeters
) {
189 meters
.push_back (MeterInfo());
193 int b
= ARDOUR_UI::config()->canvasvar_MeterColorBase
.get();
194 int m
= ARDOUR_UI::config()->canvasvar_MeterColorMid
.get();
195 int t
= ARDOUR_UI::config()->canvasvar_MeterColorTop
.get();
196 int c
= ARDOUR_UI::config()->canvasvar_MeterColorClip
.get();
198 //cerr << "LevelMeter::setup_meters() called color_changed = " << color_changed << " colors: " << endl;//DEBUG
200 for (int32_t n
= nmeters
-1; nmeters
&& n
>= 0 ; --n
) {
201 if (meters
[n
].width
!= width
|| meters
[n
].length
!= len
|| color_changed
) {
202 delete meters
[n
].meter
;
203 meters
[n
].meter
= new FastMeter ((uint32_t) floor (Config
->get_meter_hold()), width
, FastMeter::Vertical
, len
, b
, m
, t
, c
);
204 //cerr << "LevelMeter::setup_meters() w:l = " << width << ":" << len << endl;//DEBUG
205 meters
[n
].width
= width
;
206 meters
[n
].length
= len
;
207 meters
[n
].meter
->add_events (Gdk::BUTTON_RELEASE_MASK
);
208 meters
[n
].meter
->signal_button_release_event().connect (bind (mem_fun(*this, &LevelMeter::meter_button_release
), n
));
211 pack_end (*meters
[n
].meter
, false, false);
212 meters
[n
].meter
->show_all ();
213 meters
[n
].packed
= true;
216 color_changed
= false;
220 LevelMeter::meter_button_release (GdkEventButton
* ev
, uint32_t which
)
222 if (ev
->button
== 1) {
229 void LevelMeter::clear_meters ()
231 for (vector
<MeterInfo
>::iterator i
= meters
.begin(); i
< meters
.end(); i
++) {
234 max_peak
= minus_infinity();
237 void LevelMeter::hide_meters ()
243 LevelMeter::color_handler ()
245 color_changed
= true;