2007-12-20 18:25:19 -05:00
|
|
|
/*
|
|
|
|
Copyright (C) 2002 Paul Davis
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/meter.h"
|
2007-12-20 18:25:19 -05:00
|
|
|
|
|
|
|
#include <gtkmm2ext/utils.h>
|
|
|
|
#include <gtkmm2ext/fastmeter.h>
|
|
|
|
#include <gtkmm2ext/barcontroller.h>
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "midi++/manager.h"
|
|
|
|
#include "pbd/fastlog.h"
|
2007-12-20 18:25:19 -05:00
|
|
|
|
|
|
|
#include "ardour_ui.h"
|
2010-12-02 10:51:42 -05:00
|
|
|
#include "global_signals.h"
|
2007-12-20 18:25:19 -05:00
|
|
|
#include "level_meter.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "logmeter.h"
|
|
|
|
#include "gui_thread.h"
|
|
|
|
#include "keyboard.h"
|
|
|
|
#include "public_editor.h"
|
|
|
|
|
|
|
|
#include "i18n.h"
|
|
|
|
|
|
|
|
using namespace ARDOUR;
|
|
|
|
using namespace PBD;
|
|
|
|
using namespace Gtkmm2ext;
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace std;
|
|
|
|
|
2009-12-17 13:24:23 -05:00
|
|
|
LevelMeter::LevelMeter (Session* s)
|
|
|
|
: _meter (0)
|
2009-05-04 13:05:55 -04:00
|
|
|
, meter_length (0)
|
2013-06-28 14:22:09 -04:00
|
|
|
, thin_meter_width(2)
|
2007-12-20 18:25:19 -05:00
|
|
|
{
|
2009-12-17 13:24:23 -05:00
|
|
|
set_session (s);
|
2007-12-20 18:25:19 -05:00
|
|
|
set_spacing (1);
|
2012-04-25 08:58:19 -04:00
|
|
|
Config->ParameterChanged.connect (_parameter_connection, invalidator (*this), boost::bind (&LevelMeter::parameter_changed, this, _1), gui_context());
|
2009-12-11 18:29:48 -05:00
|
|
|
UI::instance()->theme_changed.connect (sigc::mem_fun(*this, &LevelMeter::on_theme_changed));
|
|
|
|
ColorsChanged.connect (sigc::mem_fun (*this, &LevelMeter::color_handler));
|
2008-04-11 10:06:50 -04:00
|
|
|
max_peak = minus_infinity();
|
2013-07-06 20:00:43 -04:00
|
|
|
meter_type = MeterPeak;
|
2007-12-20 18:25:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LevelMeter::on_theme_changed()
|
|
|
|
{
|
|
|
|
style_changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
LevelMeter::~LevelMeter ()
|
|
|
|
{
|
|
|
|
for (vector<MeterInfo>::iterator i = meters.begin(); i != meters.end(); i++) {
|
2008-12-18 14:31:00 -05:00
|
|
|
delete (*i).meter;
|
2007-12-20 18:25:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-08 11:07:28 -05:00
|
|
|
void
|
2009-05-16 22:08:13 -04:00
|
|
|
LevelMeter::set_meter (PeakMeter* meter)
|
2008-12-08 11:07:28 -05:00
|
|
|
{
|
2009-05-04 13:05:55 -04:00
|
|
|
_configuration_connection.disconnect();
|
2013-07-07 07:34:36 -04:00
|
|
|
_meter_type_connection.disconnect();
|
|
|
|
|
2009-05-16 22:08:13 -04:00
|
|
|
_meter = meter;
|
2009-12-17 13:24:23 -05:00
|
|
|
|
2009-05-16 22:08:13 -04:00
|
|
|
if (_meter) {
|
2012-04-25 08:58:19 -04:00
|
|
|
_meter->ConfigurationChanged.connect (_configuration_connection, invalidator (*this), boost::bind (&LevelMeter::configuration_changed, this, _1, _2), gui_context());
|
2013-07-07 07:34:36 -04:00
|
|
|
_meter->TypeChanged.connect (_meter_type_connection, invalidator (*this), boost::bind (&LevelMeter::meter_type_changed, this, _1), gui_context());
|
2009-05-16 22:08:13 -04:00
|
|
|
}
|
2008-12-08 11:07:28 -05:00
|
|
|
}
|
|
|
|
|
2008-04-11 10:06:50 -04:00
|
|
|
float
|
2007-12-20 18:25:19 -05:00
|
|
|
LevelMeter::update_meters ()
|
|
|
|
{
|
|
|
|
vector<MeterInfo>::iterator i;
|
|
|
|
uint32_t n;
|
2009-05-16 22:08:13 -04:00
|
|
|
|
|
|
|
if (!_meter) {
|
|
|
|
return 0.0f;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2013-07-05 08:55:07 -04:00
|
|
|
uint32_t nmidi = _meter->input_streams().n_midi();
|
2013-07-04 18:43:31 -04:00
|
|
|
|
2007-12-20 18:25:19 -05:00
|
|
|
for (n = 0, i = meters.begin(); i != meters.end(); ++i, ++n) {
|
|
|
|
if ((*i).packed) {
|
2013-07-07 20:26:17 -04:00
|
|
|
const float mpeak = _meter->meter_level(n, MeterMaxPeak);
|
2013-07-06 10:32:36 -04:00
|
|
|
if (mpeak > (*i).max_peak) {
|
|
|
|
(*i).max_peak = mpeak;
|
|
|
|
(*i).meter->set_highlight(mpeak > Config->get_meter_peak());
|
|
|
|
}
|
|
|
|
if (mpeak > max_peak) {
|
|
|
|
max_peak = mpeak;
|
|
|
|
}
|
|
|
|
|
2013-07-04 18:43:31 -04:00
|
|
|
if (n < nmidi) {
|
2013-07-07 20:26:17 -04:00
|
|
|
(*i).meter->set (_meter->meter_level (n, MeterPeak));
|
2013-07-04 18:43:31 -04:00
|
|
|
} else {
|
2013-07-07 20:26:17 -04:00
|
|
|
const float peak = _meter->meter_level (n, meter_type);
|
2013-07-07 19:06:02 -04:00
|
|
|
if (meter_type == MeterPeak) {
|
|
|
|
(*i).meter->set (log_meter (peak));
|
|
|
|
} else {
|
|
|
|
(*i).meter->set (log_meter (peak), log_meter(_meter->meter_level(n, MeterPeak)));
|
|
|
|
}
|
2013-07-04 18:43:31 -04:00
|
|
|
}
|
2007-12-20 18:25:19 -05:00
|
|
|
}
|
|
|
|
}
|
2008-04-11 10:06:50 -04:00
|
|
|
return max_peak;
|
2007-12-20 18:25:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-05-15 21:22:43 -04:00
|
|
|
LevelMeter::parameter_changed (string p)
|
2007-12-20 18:25:19 -05:00
|
|
|
{
|
2009-12-11 18:29:48 -05:00
|
|
|
ENSURE_GUI_THREAD (*this, &LevelMeter::parameter_changed, p)
|
2007-12-20 18:25:19 -05:00
|
|
|
|
2009-05-15 21:22:43 -04:00
|
|
|
if (p == "meter-hold") {
|
2007-12-20 18:25:19 -05:00
|
|
|
vector<MeterInfo>::iterator i;
|
|
|
|
uint32_t n;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2007-12-20 18:25:19 -05:00
|
|
|
for (n = 0, i = meters.begin(); i != meters.end(); ++i, ++n) {
|
|
|
|
(*i).meter->set_hold_count ((uint32_t) floor(Config->get_meter_hold()));
|
|
|
|
}
|
|
|
|
}
|
2013-07-05 16:18:04 -04:00
|
|
|
else if (p == "meter-line-up-level") {
|
|
|
|
color_changed = true;
|
|
|
|
setup_meters (meter_length, regular_meter_width, thin_meter_width);
|
|
|
|
}
|
2013-07-06 11:10:13 -04:00
|
|
|
else if (p == "meter-peak") {
|
|
|
|
vector<MeterInfo>::iterator i;
|
|
|
|
uint32_t n;
|
|
|
|
|
|
|
|
for (n = 0, i = meters.begin(); i != meters.end(); ++i, ++n) {
|
|
|
|
(*i).max_peak = minus_infinity();
|
|
|
|
}
|
|
|
|
}
|
2007-12-20 18:25:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-07-21 11:55:17 -04:00
|
|
|
LevelMeter::configuration_changed (ChanCount /*in*/, ChanCount /*out*/)
|
2007-12-20 18:25:19 -05:00
|
|
|
{
|
2009-05-04 13:05:55 -04:00
|
|
|
color_changed = true;
|
2013-06-28 14:22:09 -04:00
|
|
|
setup_meters (meter_length, regular_meter_width, thin_meter_width);
|
2009-05-04 13:05:55 -04:00
|
|
|
}
|
2007-12-20 18:25:19 -05:00
|
|
|
|
2013-07-07 07:34:36 -04:00
|
|
|
void
|
|
|
|
LevelMeter::meter_type_changed (MeterType t)
|
|
|
|
{
|
|
|
|
meter_type = t;
|
|
|
|
MeterTypeChanged(t);
|
|
|
|
}
|
|
|
|
|
2009-05-04 13:05:55 -04:00
|
|
|
void
|
|
|
|
LevelMeter::hide_all_meters ()
|
|
|
|
{
|
2007-12-20 18:25:19 -05:00
|
|
|
for (vector<MeterInfo>::iterator i = meters.begin(); i != meters.end(); ++i) {
|
|
|
|
if ((*i).packed) {
|
|
|
|
remove (*((*i).meter));
|
|
|
|
(*i).packed = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-28 14:22:09 -04:00
|
|
|
LevelMeter::setup_meters (int len, int initial_width, int thin_width)
|
2007-12-20 18:25:19 -05:00
|
|
|
{
|
2009-05-16 22:08:13 -04:00
|
|
|
hide_all_meters ();
|
|
|
|
|
2009-05-04 13:05:55 -04:00
|
|
|
if (!_meter) {
|
2009-05-16 22:08:13 -04:00
|
|
|
return; /* do it later or never */
|
2008-12-08 11:07:28 -05:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-05-04 13:05:55 -04:00
|
|
|
int32_t nmidi = _meter->input_streams().n_midi();
|
|
|
|
uint32_t nmeters = _meter->input_streams().n_total();
|
2008-04-11 10:06:50 -04:00
|
|
|
regular_meter_width = initial_width;
|
2013-06-28 14:22:09 -04:00
|
|
|
thin_meter_width = thin_width;
|
2009-05-04 13:05:55 -04:00
|
|
|
meter_length = len;
|
2008-09-10 11:03:30 -04:00
|
|
|
|
2007-12-20 18:25:19 -05:00
|
|
|
guint16 width;
|
|
|
|
|
|
|
|
if (nmeters == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nmeters <= 2) {
|
|
|
|
width = regular_meter_width;
|
|
|
|
} else {
|
|
|
|
width = thin_meter_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (meters.size() < nmeters) {
|
|
|
|
meters.push_back (MeterInfo());
|
|
|
|
}
|
|
|
|
|
|
|
|
//cerr << "LevelMeter::setup_meters() called color_changed = " << color_changed << " colors: " << endl;//DEBUG
|
|
|
|
|
|
|
|
for (int32_t n = nmeters-1; nmeters && n >= 0 ; --n) {
|
2013-07-03 19:29:59 -04:00
|
|
|
uint32_t c[10];
|
2013-07-05 16:18:04 -04:00
|
|
|
float stp[4];
|
2009-05-04 13:05:55 -04:00
|
|
|
if (n < nmidi) {
|
2013-07-03 19:29:59 -04:00
|
|
|
c[0] = ARDOUR_UI::config()->canvasvar_MidiMeterColor0.get();
|
|
|
|
c[1] = ARDOUR_UI::config()->canvasvar_MidiMeterColor1.get();
|
|
|
|
c[2] = ARDOUR_UI::config()->canvasvar_MidiMeterColor2.get();
|
|
|
|
c[3] = ARDOUR_UI::config()->canvasvar_MidiMeterColor3.get();
|
|
|
|
c[4] = ARDOUR_UI::config()->canvasvar_MidiMeterColor4.get();
|
|
|
|
c[5] = ARDOUR_UI::config()->canvasvar_MidiMeterColor5.get();
|
|
|
|
c[6] = ARDOUR_UI::config()->canvasvar_MidiMeterColor6.get();
|
|
|
|
c[7] = ARDOUR_UI::config()->canvasvar_MidiMeterColor7.get();
|
|
|
|
c[8] = ARDOUR_UI::config()->canvasvar_MidiMeterColor8.get();
|
|
|
|
c[9] = ARDOUR_UI::config()->canvasvar_MidiMeterColor9.get();
|
|
|
|
stp[0] = 115.0 * 32.0 / 128.0;
|
|
|
|
stp[1] = 115.0 * 64.0 / 128.0;
|
|
|
|
stp[2] = 115.0 * 100.0 / 128.0;
|
|
|
|
stp[3] = 115.0 * 112.0 / 128.0;
|
2009-05-04 13:05:55 -04:00
|
|
|
} else {
|
2013-07-05 16:18:04 -04:00
|
|
|
switch (Config->get_meter_line_up_level()) {
|
|
|
|
case MeteringLineUp24:
|
|
|
|
stp[0] = 42.0;
|
|
|
|
stp[1] = 77.5;
|
|
|
|
stp[2] = 92.5;
|
|
|
|
stp[3] = 100.0;
|
|
|
|
break;
|
|
|
|
case MeteringLineUp20:
|
|
|
|
stp[0] = 50.0;
|
|
|
|
stp[1] = 77.5;
|
|
|
|
stp[2] = 92.5;
|
|
|
|
stp[3] = 100.0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case MeteringLineUp18:
|
|
|
|
stp[0] = 55.0;
|
|
|
|
stp[1] = 77.5;
|
|
|
|
stp[2] = 92.5;
|
|
|
|
stp[3] = 100.0;
|
|
|
|
break;
|
|
|
|
case MeteringLineUp15:
|
|
|
|
stp[0] = 62.5;
|
|
|
|
stp[1] = 77.5;
|
|
|
|
stp[2] = 92.5;
|
|
|
|
stp[3] = 100.0;
|
|
|
|
break;
|
|
|
|
}
|
2013-07-03 19:29:59 -04:00
|
|
|
c[0] = ARDOUR_UI::config()->canvasvar_MeterColor0.get();
|
|
|
|
c[1] = ARDOUR_UI::config()->canvasvar_MeterColor1.get();
|
|
|
|
c[2] = ARDOUR_UI::config()->canvasvar_MeterColor2.get();
|
|
|
|
c[3] = ARDOUR_UI::config()->canvasvar_MeterColor3.get();
|
|
|
|
c[4] = ARDOUR_UI::config()->canvasvar_MeterColor4.get();
|
|
|
|
c[5] = ARDOUR_UI::config()->canvasvar_MeterColor5.get();
|
|
|
|
c[6] = ARDOUR_UI::config()->canvasvar_MeterColor6.get();
|
|
|
|
c[7] = ARDOUR_UI::config()->canvasvar_MeterColor7.get();
|
|
|
|
c[8] = ARDOUR_UI::config()->canvasvar_MeterColor8.get();
|
|
|
|
c[9] = ARDOUR_UI::config()->canvasvar_MeterColor9.get();
|
2009-05-04 13:05:55 -04:00
|
|
|
}
|
2007-12-20 18:25:19 -05:00
|
|
|
if (meters[n].width != width || meters[n].length != len || color_changed) {
|
|
|
|
delete meters[n].meter;
|
2013-07-01 20:15:04 -04:00
|
|
|
meters[n].meter = new FastMeter ((uint32_t) floor (Config->get_meter_hold()), width, FastMeter::Vertical, len,
|
2013-07-03 19:29:59 -04:00
|
|
|
c[0], c[1], c[2], c[3], c[4],
|
|
|
|
c[5], c[6], c[7], c[8], c[9],
|
2013-07-01 20:15:04 -04:00
|
|
|
ARDOUR_UI::config()->canvasvar_MeterBackgroundBot.get(),
|
2013-07-03 19:29:59 -04:00
|
|
|
ARDOUR_UI::config()->canvasvar_MeterBackgroundTop.get(),
|
2013-07-06 10:30:30 -04:00
|
|
|
0x991122ff, 0x551111ff,
|
2013-07-03 19:29:59 -04:00
|
|
|
stp[0], stp[1], stp[2], stp[3]
|
2013-07-01 20:15:04 -04:00
|
|
|
);
|
2007-12-20 18:25:19 -05:00
|
|
|
meters[n].width = width;
|
|
|
|
meters[n].length = len;
|
2011-11-13 10:12:34 -05:00
|
|
|
meters[n].meter->add_events (Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
|
|
|
|
meters[n].meter->signal_button_press_event().connect (sigc::mem_fun (*this, &LevelMeter::meter_button_press));
|
|
|
|
meters[n].meter->signal_button_release_event().connect (sigc::mem_fun (*this, &LevelMeter::meter_button_release));
|
2007-12-20 18:25:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pack_end (*meters[n].meter, false, false);
|
|
|
|
meters[n].meter->show_all ();
|
|
|
|
meters[n].packed = true;
|
|
|
|
}
|
|
|
|
show();
|
|
|
|
color_changed = false;
|
2008-04-11 10:06:50 -04:00
|
|
|
}
|
|
|
|
|
2013-07-06 20:00:43 -04:00
|
|
|
void
|
|
|
|
LevelMeter::set_type(MeterType t)
|
|
|
|
{
|
|
|
|
meter_type = t;
|
|
|
|
_meter->set_type(t);
|
|
|
|
}
|
|
|
|
|
2011-11-13 10:12:34 -05:00
|
|
|
bool
|
|
|
|
LevelMeter::meter_button_press (GdkEventButton* ev)
|
|
|
|
{
|
|
|
|
return ButtonPress (ev); /* EMIT SIGNAL */
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
LevelMeter::meter_button_release (GdkEventButton* ev)
|
2008-04-11 10:06:50 -04:00
|
|
|
{
|
|
|
|
if (ev->button == 1) {
|
2013-07-06 20:52:37 -04:00
|
|
|
clear_meters (false);
|
2008-04-11 10:06:50 -04:00
|
|
|
}
|
2011-11-13 10:12:34 -05:00
|
|
|
|
2008-04-11 10:06:50 -04:00
|
|
|
return true;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2007-12-20 18:25:19 -05:00
|
|
|
|
2013-07-06 20:52:37 -04:00
|
|
|
void LevelMeter::clear_meters (bool reset_highlight)
|
2007-12-20 18:25:19 -05:00
|
|
|
{
|
|
|
|
for (vector<MeterInfo>::iterator i = meters.begin(); i < meters.end(); i++) {
|
|
|
|
(*i).meter->clear();
|
2013-07-06 10:32:36 -04:00
|
|
|
(*i).max_peak = minus_infinity();
|
2013-07-06 20:52:37 -04:00
|
|
|
if (reset_highlight)
|
|
|
|
(*i).meter->set_highlight(false);
|
2007-12-20 18:25:19 -05:00
|
|
|
}
|
2008-04-11 10:06:50 -04:00
|
|
|
max_peak = minus_infinity();
|
2007-12-20 18:25:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void LevelMeter::hide_meters ()
|
|
|
|
{
|
|
|
|
hide_all_meters();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LevelMeter::color_handler ()
|
|
|
|
{
|
|
|
|
color_changed = true;
|
|
|
|
}
|
|
|
|
|