2 * Copyright (C) 2007-2017 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2008-2011 David Robillard <d@drobilla.net>
4 * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
5 * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <gtkmm/stock.h>
27 #include "pbd/convert.h"
28 #include "pbd/error.h"
29 #include "pbd/unwind.h"
31 #include "ardour/latent.h"
33 #include "gtkmm2ext/utils.h"
35 #include "latency_gui.h"
41 using namespace Gtkmm2ext;
42 using namespace ARDOUR;
45 static const gchar *_unit_strings[] = {
52 std::vector<std::string> LatencyGUI::unit_strings;
55 LatencyBarController::get_label (double&)
57 double const nframes = _latency_gui->adjustment.get_value();
60 if (nframes < (_latency_gui->sample_rate / 1000.0)) {
61 const samplepos_t nf = (samplepos_t) rint (nframes);
62 s << string_compose (P_("%1 sample", "%1 samples", nf), nf);
64 s << std::fixed << std::setprecision (2) << (nframes / (_latency_gui->sample_rate / 1000.0)) << " ms";
70 LatencyGUI::LatencyGUI (Latent& l, samplepos_t sr, samplepos_t psz)
74 , ignored (new PBD::IgnorableControllable())
75 , _ignore_change (false)
76 , adjustment (0, 0.0, sample_rate, 1.0, sample_rate / 1000.0f) /* max 1 second, step by samples, page by msecs */
77 , bc (adjustment, this)
78 , reset_button (_("Reset"))
82 if (unit_strings.empty()) {
83 unit_strings = I18N (_unit_strings);
86 set_popdown_strings (units_combo, unit_strings);
87 units_combo.set_active_text (unit_strings.front());
89 w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
92 w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
94 minus_button.add (*w);
96 hbox1.pack_start (bc, true, true);
98 hbox2.set_homogeneous (false);
99 hbox2.set_spacing (12);
100 hbox2.pack_start (reset_button);
101 hbox2.pack_start (minus_button);
102 hbox2.pack_start (plus_button);
103 hbox2.pack_start (units_combo, true, true);
105 minus_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LatencyGUI::change_latency_from_button), -1));
106 plus_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LatencyGUI::change_latency_from_button), 1));
107 reset_button.signal_clicked().connect (sigc::mem_fun (*this, &LatencyGUI::reset));
109 /* Limit value to adjustment range (max = sample_rate).
110 * Otherwise if the signal_latency() is larger than the adjustment's max,
111 * LatencyGUI::finish() would set the adjustment's max value as custom-latency.
113 adjustment.set_value (std::min (sample_rate, _latent.signal_latency ()));
115 adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &LatencyGUI::finish));
117 bc.set_size_request (-1, 25);
118 bc.set_name (X_("ProcessorControlSlider"));
121 pack_start (hbox1, true, true);
122 pack_start (hbox2, true, true);
126 LatencyGUI::finish ()
128 if (_ignore_change) {
131 samplepos_t new_value = (samplepos_t) adjustment.get_value();
132 _latent.set_user_latency (new_value);
138 _latent.unset_user_latency ();
139 PBD::Unwinder<bool> uw (_ignore_change, true);
140 adjustment.set_value (std::min (sample_rate, _latent.signal_latency ()));
144 LatencyGUI::refresh ()
146 PBD::Unwinder<bool> uw (_ignore_change, true);
147 adjustment.set_value (std::min (sample_rate, _latent.effective_latency ()));
151 LatencyGUI::change_latency_from_button (int dir)
153 std::string unitstr = units_combo.get_active_text();
156 if (unitstr == unit_strings[0]) {
158 } else if (unitstr == unit_strings[1]) {
159 shift = (sample_rate / 1000.0);
160 } else if (unitstr == unit_strings[2]) {
163 fatal << string_compose (_("programming error: %1 (%2)"), X_("illegal string in latency GUI units combo"), unitstr)
165 abort(); /*NOTREACHED*/
169 adjustment.set_value (adjustment.get_value() + shift);
171 adjustment.set_value (adjustment.get_value() - shift);
175 LatencyDialog::LatencyDialog (const std::string& title, Latent& l, samplepos_t sr, samplepos_t psz)
176 : ArdourDialog (title, false, true),
179 get_vbox()->pack_start (lwidget);
180 add_button (Stock::CLOSE, RESPONSE_CLOSE);