2 Copyright (C) 1998-2007 Paul Davis
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 $Id: volume_controller.cc,v 1.4 2000/05/03 15:54:21 pbd Exp $
25 #include "pbd/controllable.h"
26 #include "pbd/stacktrace.h"
28 #include "gtkmm2ext/gui_thread.h"
30 #include "ardour/dB.h"
31 #include "ardour/rc_configuration.h"
32 #include "ardour/utils.h"
34 #include "volume_controller.h"
38 VolumeController::VolumeController (Glib::RefPtr
<Gdk::Pixbuf
> p
,
39 boost::shared_ptr
<PBD::Controllable
> c
,
48 : MotionFeedback (p
, MotionFeedback::Rotary
, c
, def
, step
, page
, "", with_numeric
, subw
, subh
)
51 set_print_func (VolumeController::_dB_printer
, this);
54 value
->set_width_chars (6 + abs ((int) ceil (log10 (step
))));
56 value
->set_width_chars (5); // -NNdB
62 VolumeController::_dB_printer (char buf
[32], const boost::shared_ptr
<PBD::Controllable
>& c
, void* arg
)
64 VolumeController
* vc
= reinterpret_cast<VolumeController
*>(arg
);
65 vc
->dB_printer (buf
, c
);
69 VolumeController::dB_printer (char buf
[32], const boost::shared_ptr
<PBD::Controllable
>& c
)
75 double val
= accurate_coefficient_to_dB (c
->get_value());
79 snprintf (buf
, 32, "+%5.2f dB", val
);
81 snprintf (buf
, 32, "%5.2f dB", val
);
85 snprintf (buf
, 32, "+%2ld dB", lrint (val
));
87 snprintf (buf
, 32, "%2ld dB", lrint (val
));
93 double dB
= accurate_coefficient_to_dB (c
->get_value());
97 snprintf (buf
, 32, "+%5.2f dB", dB
);
99 snprintf (buf
, 32, "%5.2f dB", dB
);
103 snprintf (buf
, 32, "+%2ld dB", lrint (dB
));
105 snprintf (buf
, 32, "%2ld dB", lrint (dB
));
110 snprintf (buf
, sizeof (buf
), "--");
115 VolumeController::to_control_value (double display_value
)
119 /* display value is always clamped to 0.0 .. 1.0 */
120 display_value
= std::max (0.0, std::min (1.0, display_value
));
123 v
= _controllable
->lower() + ((_controllable
->upper() - _controllable
->lower()) * display_value
);
125 v
= slider_position_to_gain_with_max (display_value
, ARDOUR::Config
->get_max_gain());
132 VolumeController::to_display_value (double control_value
)
137 v
= (control_value
- _controllable
->lower ()) / (_controllable
->upper() - _controllable
->lower());
139 v
= gain_to_slider_position_with_max (control_value
, ARDOUR::Config
->get_max_gain());
146 VolumeController::adjust (double control_delta
)
148 double v
= _controllable
->get_value ();
149 double abs_delta
= fabs (control_delta
);
151 /* convert to linear/fractional slider position domain */
152 v
= gain_to_slider_position_with_max (v
, ARDOUR::Config
->get_max_gain());
153 /* adjust in this domain */
155 /* convert back to gain coefficient domain */
156 v
= slider_position_to_gain_with_max (v
, ARDOUR::Config
->get_max_gain());
158 /* now round to some precision in the dB domain */
159 v
= accurate_coefficient_to_dB (v
);
161 if (abs_delta
<= 0.01) {
168 return dB_to_coefficient (v
);