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"
42 using namespace Gtkmm2ext;
43 using namespace ARDOUR;
46 static const gchar *_unit_strings[] = {
53 std::vector<std::string> LatencyGUI::unit_strings;
56 LatencyBarController::get_label (double&)
58 return ARDOUR_UI_UTILS::samples_as_time_string (
59 _latency_gui->adjustment.get_value(), _latency_gui->sample_rate, true);
62 LatencyGUI::LatencyGUI (Latent& l, samplepos_t sr, samplepos_t psz)
66 , ignored (new PBD::IgnorableControllable())
67 , _ignore_change (false)
68 , adjustment (0, 0.0, sample_rate, 1.0, sample_rate / 1000.0f) /* max 1 second, step by samples, page by msecs */
69 , bc (adjustment, this)
70 , reset_button (_("Reset"))
74 if (unit_strings.empty()) {
75 unit_strings = I18N (_unit_strings);
78 set_popdown_strings (units_combo, unit_strings);
79 units_combo.set_active_text (unit_strings.front());
81 w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
84 w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
86 minus_button.add (*w);
88 hbox1.pack_start (bc, true, true);
90 hbox2.set_homogeneous (false);
91 hbox2.set_spacing (12);
92 hbox2.pack_start (reset_button);
93 hbox2.pack_start (minus_button);
94 hbox2.pack_start (plus_button);
95 hbox2.pack_start (units_combo, true, true);
97 minus_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LatencyGUI::change_latency_from_button), -1));
98 plus_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LatencyGUI::change_latency_from_button), 1));
99 reset_button.signal_clicked().connect (sigc::mem_fun (*this, &LatencyGUI::reset));
101 /* Limit value to adjustment range (max = sample_rate).
102 * Otherwise if the signal_latency() is larger than the adjustment's max,
103 * LatencyGUI::finish() would set the adjustment's max value as custom-latency.
105 adjustment.set_value (std::min (sample_rate, _latent.signal_latency ()));
107 adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &LatencyGUI::finish));
109 bc.set_size_request (-1, 25);
110 bc.set_name (X_("ProcessorControlSlider"));
113 pack_start (hbox1, true, true);
114 pack_start (hbox2, true, true);
118 LatencyGUI::finish ()
120 if (_ignore_change) {
123 samplepos_t new_value = (samplepos_t) adjustment.get_value();
124 _latent.set_user_latency (new_value);
130 _latent.unset_user_latency ();
131 PBD::Unwinder<bool> uw (_ignore_change, true);
132 adjustment.set_value (std::min (sample_rate, _latent.signal_latency ()));
136 LatencyGUI::refresh ()
138 PBD::Unwinder<bool> uw (_ignore_change, true);
139 adjustment.set_value (std::min (sample_rate, _latent.effective_latency ()));
143 LatencyGUI::change_latency_from_button (int dir)
145 std::string unitstr = units_combo.get_active_text();
148 if (unitstr == unit_strings[0]) {
150 } else if (unitstr == unit_strings[1]) {
151 shift = (sample_rate / 1000.0);
152 } else if (unitstr == unit_strings[2]) {
155 fatal << string_compose (_("programming error: %1 (%2)"), X_("illegal string in latency GUI units combo"), unitstr)
157 abort(); /*NOTREACHED*/
161 adjustment.set_value (adjustment.get_value() + shift);
163 adjustment.set_value (adjustment.get_value() - shift);