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/session.h"
23 #include "ardour/session_route.h"
24 #include "ardour/dB.h"
25 #include "ardour/meter.h"
27 #include <gtkmm2ext/utils.h>
28 #include <gtkmm2ext/fastmeter.h>
29 #include <gtkmm2ext/barcontroller.h>
30 #include "midi++/manager.h"
31 #include "pbd/fastlog.h"
33 #include "ardour_ui.h"
34 #include "level_meter.h"
37 #include "gui_thread.h"
39 #include "public_editor.h"
41 #include "ardour/session.h"
45 using namespace ARDOUR
;
47 using namespace Gtkmm2ext
;
51 //sigc::signal<void> LevelMeter::ResetAllPeakDisplays;
52 //sigc::signal<void,RouteGroup*> LevelMeter::ResetGroupPeakDisplays;
55 LevelMeter::LevelMeter (Session
* s
)
61 Config
->ParameterChanged
.connect (_parameter_connection
, invalidator (*this), ui_bind (&LevelMeter::parameter_changed
, this, _1
), gui_context());
62 UI::instance()->theme_changed
.connect (sigc::mem_fun(*this, &LevelMeter::on_theme_changed
));
63 ColorsChanged
.connect (sigc::mem_fun (*this, &LevelMeter::color_handler
));
64 max_peak
= minus_infinity();
68 LevelMeter::on_theme_changed()
73 LevelMeter::~LevelMeter ()
75 for (vector
<MeterInfo
>::iterator i
= meters
.begin(); i
!= meters
.end(); i
++) {
81 LevelMeter::set_meter (PeakMeter
* meter
)
83 _configuration_connection
.disconnect();
87 _meter
->ConfigurationChanged
.connect (_configuration_connection
, invalidator (*this), ui_bind (&LevelMeter::configuration_changed
, this, _1
, _2
), gui_context());
92 LevelMeter::update_meters ()
94 vector
<MeterInfo
>::iterator i
;
102 for (n
= 0, i
= meters
.begin(); i
!= meters
.end(); ++i
, ++n
) {
104 peak
= _meter
->peak_power (n
);
105 (*i
).meter
->set (log_meter (peak
));
106 mpeak
= _meter
->max_peak_power(n
);
107 if (mpeak
> max_peak
) {
110 if (mpeak
> max_peak
) {
119 LevelMeter::parameter_changed (string p
)
121 ENSURE_GUI_THREAD (*this, &LevelMeter::parameter_changed
, p
)
123 if (p
== "meter-hold") {
125 vector
<MeterInfo
>::iterator i
;
128 for (n
= 0, i
= meters
.begin(); i
!= meters
.end(); ++i
, ++n
) {
130 (*i
).meter
->set_hold_count ((uint32_t) floor(Config
->get_meter_hold()));
136 LevelMeter::configuration_changed (ChanCount
/*in*/, ChanCount
/*out*/)
138 color_changed
= true;
139 setup_meters (meter_length
, regular_meter_width
);
143 LevelMeter::hide_all_meters ()
145 for (vector
<MeterInfo
>::iterator i
= meters
.begin(); i
!= meters
.end(); ++i
) {
147 remove (*((*i
).meter
));
154 LevelMeter::setup_meters (int len
, int initial_width
)
159 return; /* do it later or never */
162 int32_t nmidi
= _meter
->input_streams().n_midi();
163 uint32_t nmeters
= _meter
->input_streams().n_total();
164 regular_meter_width
= initial_width
;
174 width
= regular_meter_width
;
176 width
= thin_meter_width
;
179 while (meters
.size() < nmeters
) {
180 meters
.push_back (MeterInfo());
183 //cerr << "LevelMeter::setup_meters() called color_changed = " << color_changed << " colors: " << endl;//DEBUG
185 for (int32_t n
= nmeters
-1; nmeters
&& n
>= 0 ; --n
) {
188 b
= ARDOUR_UI::config()->canvasvar_MidiNoteMeterColorBase
.get();
189 m
= ARDOUR_UI::config()->canvasvar_MidiNoteMeterColorMid
.get();
190 t
= ARDOUR_UI::config()->canvasvar_MidiNoteMeterColorTop
.get();
191 c
= ARDOUR_UI::config()->canvasvar_MeterColorClip
.get();
193 b
= ARDOUR_UI::config()->canvasvar_MeterColorBase
.get();
194 m
= ARDOUR_UI::config()->canvasvar_MeterColorMid
.get();
195 t
= ARDOUR_UI::config()->canvasvar_MeterColorTop
.get();
196 c
= ARDOUR_UI::config()->canvasvar_MeterColorClip
.get();
198 if (meters
[n
].width
!= width
|| meters
[n
].length
!= len
|| color_changed
) {
199 delete meters
[n
].meter
;
200 meters
[n
].meter
= new FastMeter ((uint32_t) floor (Config
->get_meter_hold()), width
, FastMeter::Vertical
, len
, b
, m
, t
, c
);
201 //cerr << "LevelMeter::setup_meters() w:l = " << width << ":" << len << endl;//DEBUG
202 meters
[n
].width
= width
;
203 meters
[n
].length
= len
;
204 meters
[n
].meter
->add_events (Gdk::BUTTON_RELEASE_MASK
);
205 meters
[n
].meter
->signal_button_release_event().connect (sigc::bind (sigc::mem_fun(*this, &LevelMeter::meter_button_release
), n
));
208 pack_end (*meters
[n
].meter
, false, false);
209 meters
[n
].meter
->show_all ();
210 meters
[n
].packed
= true;
213 color_changed
= false;
217 LevelMeter::meter_button_release (GdkEventButton
* ev
, uint32_t /*which*/)
219 if (ev
->button
== 1) {
226 void LevelMeter::clear_meters ()
228 for (vector
<MeterInfo
>::iterator i
= meters
.begin(); i
< meters
.end(); i
++) {
231 max_peak
= minus_infinity();
234 void LevelMeter::hide_meters ()
240 LevelMeter::color_handler ()
242 color_changed
= true;