2011-02-11 13:02:15 -05:00
|
|
|
/*
|
|
|
|
Copyright (C) 1998-2007 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.
|
|
|
|
|
|
|
|
$Id: volume_controller.cc,v 1.4 2000/05/03 15:54:21 pbd Exp $
|
|
|
|
*/
|
|
|
|
|
2011-06-17 17:47:20 -04:00
|
|
|
#include <algorithm>
|
|
|
|
|
2011-02-11 13:02:15 -05:00
|
|
|
#include <string.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
#include "pbd/controllable.h"
|
2011-06-17 17:47:20 -04:00
|
|
|
#include "pbd/stacktrace.h"
|
2011-02-11 13:02:15 -05:00
|
|
|
|
|
|
|
#include "gtkmm2ext/gui_thread.h"
|
2011-06-17 17:47:20 -04:00
|
|
|
|
|
|
|
#include "ardour/dB.h"
|
2011-06-19 19:02:55 -04:00
|
|
|
#include "ardour/rc_configuration.h"
|
2011-02-11 13:02:15 -05:00
|
|
|
#include "ardour/utils.h"
|
|
|
|
|
|
|
|
#include "volume_controller.h"
|
|
|
|
|
|
|
|
using namespace Gtk;
|
|
|
|
|
|
|
|
VolumeController::VolumeController (Glib::RefPtr<Gdk::Pixbuf> p,
|
2011-06-17 17:47:20 -04:00
|
|
|
boost::shared_ptr<PBD::Controllable> c,
|
|
|
|
double def,
|
|
|
|
double step,
|
|
|
|
double page,
|
2011-02-11 13:02:15 -05:00
|
|
|
bool with_numeric,
|
2011-06-17 17:47:20 -04:00
|
|
|
int subw,
|
|
|
|
int subh,
|
2011-06-19 19:02:55 -04:00
|
|
|
bool linear)
|
2011-06-17 17:47:20 -04:00
|
|
|
|
|
|
|
: MotionFeedback (p, MotionFeedback::Rotary, c, def, step, page, "", with_numeric, subw, subh)
|
|
|
|
, _linear (linear)
|
2011-06-01 13:00:29 -04:00
|
|
|
{
|
2011-06-17 17:47:20 -04:00
|
|
|
set_print_func (VolumeController::_dB_printer, this);
|
|
|
|
|
|
|
|
if (step < 1.0) {
|
|
|
|
value->set_width_chars (6 + abs ((int) ceil (log10 (step))));
|
|
|
|
} else {
|
|
|
|
value->set_width_chars (5); // -NNdB
|
|
|
|
}
|
|
|
|
|
2011-02-11 13:02:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-06-17 17:47:20 -04:00
|
|
|
VolumeController::_dB_printer (char buf[32], const boost::shared_ptr<PBD::Controllable>& c, void* arg)
|
2011-02-11 13:02:15 -05:00
|
|
|
{
|
2011-06-17 17:47:20 -04:00
|
|
|
VolumeController* vc = reinterpret_cast<VolumeController*>(arg);
|
|
|
|
vc->dB_printer (buf, c);
|
2011-02-11 13:02:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-06-17 17:47:20 -04:00
|
|
|
VolumeController::dB_printer (char buf[32], const boost::shared_ptr<PBD::Controllable>& c)
|
2011-02-11 13:02:15 -05:00
|
|
|
{
|
2011-06-17 17:47:20 -04:00
|
|
|
if (c) {
|
|
|
|
|
|
|
|
if (_linear) {
|
2011-06-19 19:02:55 -04:00
|
|
|
|
|
|
|
double val = accurate_coefficient_to_dB (c->get_value());
|
|
|
|
|
2011-06-17 17:47:20 -04:00
|
|
|
if (step_inc < 1.0) {
|
2011-06-19 19:02:55 -04:00
|
|
|
if (val >= 0.0) {
|
|
|
|
snprintf (buf, 32, "+%5.2f dB", val);
|
|
|
|
} else {
|
|
|
|
snprintf (buf, 32, "%5.2f dB", val);
|
|
|
|
}
|
2011-06-17 17:47:20 -04:00
|
|
|
} else {
|
2011-06-19 19:02:55 -04:00
|
|
|
if (val >= 0.0) {
|
|
|
|
snprintf (buf, 32, "+%2ld dB", lrint (val));
|
|
|
|
} else {
|
|
|
|
snprintf (buf, 32, "%2ld dB", lrint (val));
|
|
|
|
}
|
2011-06-17 17:47:20 -04:00
|
|
|
}
|
2011-06-19 19:02:55 -04:00
|
|
|
|
2011-06-17 17:47:20 -04:00
|
|
|
} else {
|
|
|
|
|
2011-06-19 19:02:55 -04:00
|
|
|
double dB = accurate_coefficient_to_dB (c->get_value());
|
2011-06-17 17:47:20 -04:00
|
|
|
|
|
|
|
if (step_inc < 1.0) {
|
2011-06-19 19:02:55 -04:00
|
|
|
if (dB >= 0.0) {
|
|
|
|
snprintf (buf, 32, "+%5.2f dB", dB);
|
|
|
|
} else {
|
|
|
|
snprintf (buf, 32, "%5.2f dB", dB);
|
|
|
|
}
|
2011-06-17 17:47:20 -04:00
|
|
|
} else {
|
2011-06-19 19:02:55 -04:00
|
|
|
if (dB >= 0.0) {
|
|
|
|
snprintf (buf, 32, "+%2ld dB", lrint (dB));
|
|
|
|
} else {
|
|
|
|
snprintf (buf, 32, "%2ld dB", lrint (dB));
|
|
|
|
}
|
2011-06-17 17:47:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
snprintf (buf, sizeof (buf), "--");
|
|
|
|
}
|
2011-02-11 13:02:15 -05:00
|
|
|
}
|
|
|
|
|
2011-06-17 17:47:20 -04:00
|
|
|
double
|
|
|
|
VolumeController::to_control_value (double display_value)
|
2011-02-11 13:02:15 -05:00
|
|
|
{
|
2011-06-17 17:47:20 -04:00
|
|
|
double v;
|
|
|
|
|
|
|
|
/* display value is always clamped to 0.0 .. 1.0 */
|
|
|
|
display_value = std::max (0.0, std::min (1.0, display_value));
|
|
|
|
|
|
|
|
if (_linear) {
|
|
|
|
v = _controllable->lower() + ((_controllable->upper() - _controllable->lower()) * display_value);
|
|
|
|
} else {
|
2011-06-19 19:02:55 -04:00
|
|
|
v = slider_position_to_gain_with_max (display_value, ARDOUR::Config->get_max_gain());
|
2011-06-17 17:47:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return v;
|
2011-02-11 13:02:15 -05:00
|
|
|
}
|
|
|
|
|
2011-06-17 17:47:20 -04:00
|
|
|
double
|
|
|
|
VolumeController::to_display_value (double control_value)
|
|
|
|
{
|
|
|
|
double v;
|
|
|
|
|
2011-06-19 19:02:55 -04:00
|
|
|
// if (_linear) {
|
2011-06-17 17:47:20 -04:00
|
|
|
v = (control_value - _controllable->lower ()) / (_controllable->upper() - _controllable->lower());
|
2011-06-19 19:02:55 -04:00
|
|
|
// } else {
|
|
|
|
// v = gain_to_slider_position_with_max (control_value, ARDOUR::Config->get_max_gain());
|
|
|
|
// }
|
2011-02-11 13:02:15 -05:00
|
|
|
|
2011-06-17 17:47:20 -04:00
|
|
|
return v;
|
|
|
|
}
|
2011-06-19 19:02:55 -04:00
|
|
|
|
|
|
|
double
|
|
|
|
VolumeController::adjust (double control_delta)
|
|
|
|
{
|
|
|
|
return std::max (_controllable->lower(), std::min (_controllable->upper(), _controllable->get_value() + control_delta));
|
|
|
|
}
|
|
|
|
|