updated french translation from raphael
[ardour2.git] / gtk2_ardour / level_meter.cc
blobf6680db79c725791817650aebec3ac0a0aca25b3
1 /*
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.
20 #include <limits.h>
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"
38 #include "utils.h"
39 #include "logmeter.h"
40 #include "gui_thread.h"
41 #include "keyboard.h"
42 #include "public_editor.h"
44 #include <ardour/session.h>
45 #include <ardour/route.h>
47 #include "i18n.h"
49 using namespace ARDOUR;
50 using namespace PBD;
51 using namespace Gtkmm2ext;
52 using namespace Gtk;
53 using namespace sigc;
54 using namespace std;
56 //sigc::signal<void> LevelMeter::ResetAllPeakDisplays;
57 //sigc::signal<void,RouteGroup*> LevelMeter::ResetGroupPeakDisplays;
60 LevelMeter::LevelMeter (Session& s)
61 : _session (s)
64 set_spacing (1);
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();
71 void
72 LevelMeter::on_theme_changed()
74 style_changed = true;
77 LevelMeter::~LevelMeter ()
79 for (vector<MeterInfo>::iterator i = meters.begin(); i != meters.end(); i++) {
80 if ((*i).meter) {
81 delete (*i).meter;
86 void
87 LevelMeter::set_io (boost::shared_ptr<IO> io)
89 _io = io;
92 float
93 LevelMeter::update_meters ()
95 vector<MeterInfo>::iterator i;
96 uint32_t n;
97 float peak, mpeak;
99 for (n = 0, i = meters.begin(); i != meters.end(); ++i, ++n) {
100 if ((*i).packed) {
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) {
105 max_peak = mpeak;
109 return max_peak;
112 void
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;
122 uint32_t n;
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()));
130 #undef PARAM_IS
133 void
134 LevelMeter::hide_all_meters ()
137 for (vector<MeterInfo>::iterator i = meters.begin(); i != meters.end(); ++i) {
138 if ((*i).packed) {
139 remove (*((*i).meter));
140 (*i).packed = false;
145 void
146 LevelMeter::setup_meters (int len, int initial_width)
148 if (!_io) {
149 return; /* do it later */
152 regular_meter_width = initial_width;
153 uint32_t nmeters = _io->n_outputs();
154 guint16 width;
156 hide_all_meters ();
158 Route* r;
160 if ((r = dynamic_cast<Route*> (_io.get())) != 0) {
162 switch (r->meter_point()) {
163 case MeterPreFader:
164 case MeterInput:
165 nmeters = r->n_inputs();
166 break;
167 case MeterPostFader:
168 nmeters = r->n_outputs();
169 break;
172 } else {
174 nmeters = _io->n_outputs();
178 if (nmeters == 0) {
179 return;
182 if (nmeters <= 2) {
183 width = regular_meter_width;
184 } else {
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;
215 show();
216 color_changed = false;
219 gint
220 LevelMeter::meter_button_release (GdkEventButton* ev, uint32_t which)
222 if (ev->button == 1) {
223 clear_meters();
225 return true;
229 void LevelMeter::clear_meters ()
231 for (vector<MeterInfo>::iterator i = meters.begin(); i < meters.end(); i++) {
232 (*i).meter->clear();
234 max_peak = minus_infinity();
237 void LevelMeter::hide_meters ()
239 hide_all_meters();
242 void
243 LevelMeter::color_handler ()
245 color_changed = true;