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,
|
2015-10-04 14:51:05 -04:00
|
|
|
int subw,
|
2011-06-17 17:47:20 -04:00
|
|
|
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);
|
2011-06-20 10:20:01 -04:00
|
|
|
value->set_width_chars (8);
|
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
|
2015-10-04 14:51:05 -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) {
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-06-17 17:47:20 -04:00
|
|
|
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 {
|
2015-10-05 10:17:49 -04:00
|
|
|
|
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 {
|
2012-05-23 22:54:10 -04:00
|
|
|
snprintf (buf, 32, "--");
|
2011-06-17 17:47:20 -04:00
|
|
|
}
|
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 {
|
2014-06-25 15:03:47 -04:00
|
|
|
v = ARDOUR::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-20 09:58:33 -04:00
|
|
|
if (_linear) {
|
2011-06-17 17:47:20 -04:00
|
|
|
v = (control_value - _controllable->lower ()) / (_controllable->upper() - _controllable->lower());
|
2011-06-20 09:58:33 -04:00
|
|
|
} else {
|
2014-06-25 15:03:47 -04:00
|
|
|
v = ARDOUR::gain_to_slider_position_with_max (control_value, _controllable->upper());
|
2011-06-20 09:58:33 -04:00
|
|
|
}
|
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)
|
|
|
|
{
|
2011-06-20 21:36:20 -04:00
|
|
|
double v;
|
|
|
|
|
|
|
|
if (!_linear) {
|
|
|
|
/* we map back into the linear/fractional slider position,
|
|
|
|
* because this kind of control goes all the way down
|
|
|
|
* to -inf dB, and we want this occur in a reasonable way in
|
|
|
|
* terms of user interaction. if we leave the adjustment in the
|
|
|
|
* gain coefficient domain (or dB domain), the lower end of the
|
|
|
|
* control range (getting close to -inf dB) takes forever.
|
|
|
|
*/
|
2013-08-31 21:19:13 -04:00
|
|
|
#if 0
|
2011-06-20 21:36:20 -04:00
|
|
|
/* convert to linear/fractional slider position domain */
|
2014-06-25 15:03:47 -04:00
|
|
|
v = ARDOUR::gain_to_slider_position_with_max (_controllable->get_value (), _controllable->upper());
|
2011-06-20 21:36:20 -04:00
|
|
|
/* increment in this domain */
|
|
|
|
v += control_delta;
|
|
|
|
/* clamp to appropriate range for linear/fractional slider domain */
|
|
|
|
v = std::max (0.0, std::min (1.0, v));
|
|
|
|
/* convert back to gain coefficient domain */
|
2014-06-25 15:03:47 -04:00
|
|
|
v = ARDOUR::slider_position_to_gain_with_max (v, _controllable->upper());
|
2011-06-20 21:36:20 -04:00
|
|
|
/* clamp in controller domain */
|
|
|
|
v = std::max (_controllable->lower(), std::min (_controllable->upper(), v));
|
|
|
|
/* convert to dB domain */
|
|
|
|
v = accurate_coefficient_to_dB (v);
|
|
|
|
/* round up/down to nearest 0.1dB */
|
|
|
|
if (control_delta > 0.0) {
|
|
|
|
v = ceil (v * 10.0) / 10.0;
|
|
|
|
} else {
|
|
|
|
v = floor (v * 10.0) / 10.0;
|
|
|
|
}
|
|
|
|
/* and return it */
|
|
|
|
return dB_to_coefficient (v);
|
2013-08-31 21:19:13 -04:00
|
|
|
#else
|
|
|
|
/* ^^ Above algorithm is not symmetric. Scroll up to steps, scoll down two steps, -> different gain.
|
|
|
|
*
|
|
|
|
* see ./libs/gtkmm2ext/gtkmm2ext/motionfeedback.h and gtk2_ardour/monitor_section.cc:
|
|
|
|
* min-delta (corr) = MIN(0.01 * page inc, 1 * size_inc) // (gain_control uses size_inc=0.01, page_inc=0.1)
|
|
|
|
* range corr: 0..2 -> -inf..+6dB
|
|
|
|
* step sizes [0.01, 0.10, 0.20] * page_inc, [1,2,10,100] * step_inc. [1,2,10,100] * page_inc
|
|
|
|
*
|
|
|
|
* 0.001, 0.01, 0.02, 0.1, .2, 1, 10
|
|
|
|
* -> 1k steps between -inf..0dB
|
|
|
|
* -> 1k steps between 0..+dB
|
|
|
|
*
|
|
|
|
* IOW:
|
|
|
|
* the range is from *0 (-inf dB) to *2.0 ( +6dB)
|
|
|
|
* the knob is configured to to go in steps of 0.001 - that's 2000 steps between 0 and 2.
|
|
|
|
* or 1000 steps between 0 and 1.
|
|
|
|
*
|
|
|
|
* we cannot round to .01dB steps because
|
|
|
|
* There are only 600 possible values between +0db and +6dB when going in steps of .01dB
|
|
|
|
* 1000/600 = 1.66666...
|
|
|
|
*
|
|
|
|
******
|
|
|
|
* idea: make the 'controllable use a fixed range of dB.
|
|
|
|
* do a 1:1 mapping between values. :et's stick with the range of 0..2 in 0.001 steps
|
|
|
|
*
|
|
|
|
* "-80" becomes 0 and "+6" becomes 2000. (NB +6dB is actually 1995, but we clamp that to the top)
|
|
|
|
*
|
|
|
|
* This approach is better (more consistet) but not good. At least the dial does not annoy me as much
|
|
|
|
* anymore as it did before.
|
|
|
|
*
|
|
|
|
* const double stretchfactor = rint((_controllable->upper() - _controllable->lower()) / 0.001); // 2000;
|
|
|
|
* const double logfactor = stretchfactor / ((20.0 * log10( _controllable->upper())) + 80.0); // = 23.250244732
|
|
|
|
*/
|
|
|
|
v = _controllable->get_value ();
|
|
|
|
/* assume everything below -60dB is silent (.001 ^= -60dB)
|
|
|
|
* but map range -80db..+6dB to a scale of 0..2000
|
|
|
|
* 80db was motivated because 2000/((20.0 * log(1)) + 80.0) is an integer value. "0dB" is included on the scale.
|
|
|
|
* but this leaves a dead area at the bottom of the meter..
|
|
|
|
*/
|
|
|
|
double arange = (v >= 0.001) ? ( ((20.0 * log10(v)) + 80.0) * 23.250244732 ) : ( 0 );
|
|
|
|
/* add the delta */
|
|
|
|
v = rint(arange) + rint(control_delta * 1000.0); // (min steps is 1.0/0.001 == 1000.0)
|
|
|
|
/* catch bottom -80..-60 db in one step */
|
|
|
|
if (v < 466) v = (control_delta > 0) ? 0.001 : 0;
|
|
|
|
/* reverse operation (pow(10, .05 * ((v / 23.250244732) - 80.0)))
|
|
|
|
* can be simplified to :*/
|
|
|
|
else v = pow(10, (v * 0.00215051499) - 4.0);
|
|
|
|
/* clamp value in coefficient domain */
|
|
|
|
v = std::max (_controllable->lower(), std::min (_controllable->upper(), v));
|
|
|
|
return v;
|
|
|
|
#endif
|
2011-06-20 09:58:33 -04:00
|
|
|
} else {
|
2011-06-20 21:36:20 -04:00
|
|
|
double mult;
|
|
|
|
|
|
|
|
if (control_delta < 0.0) {
|
|
|
|
mult = -1.0;
|
|
|
|
} else {
|
|
|
|
mult = 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fabs (control_delta) < 0.05) {
|
|
|
|
control_delta = mult * 0.05;
|
|
|
|
} else {
|
|
|
|
control_delta = mult * 0.1;
|
|
|
|
}
|
|
|
|
|
|
|
|
v = _controllable->get_value();
|
|
|
|
|
|
|
|
if (v == 0.0) {
|
|
|
|
/* if we don't special case this, we can't escape from
|
|
|
|
the -infinity dB black hole.
|
|
|
|
*/
|
|
|
|
if (control_delta > 0.0) {
|
|
|
|
v = dB_to_coefficient (-100 + control_delta);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
static const double dB_minus_200 = dB_to_coefficient (-200.0);
|
|
|
|
static const double dB_minus_100 = dB_to_coefficient (-100.0);
|
|
|
|
static const double dB_minus_50 = dB_to_coefficient (-50.0);
|
|
|
|
static const double dB_minus_20 = dB_to_coefficient (-20.0);
|
|
|
|
|
|
|
|
if (control_delta < 0 && v < dB_minus_200) {
|
|
|
|
v = 0.0;
|
|
|
|
} else {
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
/* non-linear scaling as the dB level gets low
|
2011-06-20 21:36:20 -04:00
|
|
|
so that we can hit -inf and get back out of
|
|
|
|
it appropriately.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (v < dB_minus_100) {
|
|
|
|
control_delta *= 1000.0;
|
|
|
|
} else if (v < dB_minus_50) {
|
|
|
|
control_delta *= 100.0;
|
|
|
|
} else if (v < dB_minus_20) {
|
|
|
|
control_delta *= 10.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
v = accurate_coefficient_to_dB (v);
|
|
|
|
v += control_delta;
|
|
|
|
v = dB_to_coefficient (v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::max (_controllable->lower(), std::min (_controllable->upper(), v));
|
|
|
|
}
|
2011-06-20 09:58:33 -04:00
|
|
|
|
|
|
|
}
|