4 #include "ardour/latent.h"
5 #include "pbd/convert.h"
6 #include <gtkmm2ext/utils.h>
8 #include "latency_gui.h"
14 using namespace Gtkmm2ext;
15 using namespace ARDOUR;
18 static const gchar *_unit_strings[] = {
25 std::vector<std::string> LatencyGUI::unit_strings;
28 LatencyBarController::get_label (int&)
30 double const nframes = _latency_gui->adjustment.get_value();
33 if (nframes < (_latency_gui->sample_rate / 1000.0)) {
34 s << ((framepos_t) rint (nframes)) << " samples";
36 s << std::fixed << std::setprecision (2) << (nframes / (_latency_gui->sample_rate / 1000.0)) << " msecs";
42 LatencyGUI::LatencyGUI (Latent& l, framepos_t sr, framepos_t psz)
44 initial_value (_latent.signal_latency()),
47 ignored (new PBD::IgnorableControllable()),
48 /* max 1 second, step by frames, page by msecs */
49 adjustment (initial_value, 0.0, sample_rate, 1.0, sample_rate / 1000.0f),
50 bc (adjustment, this),
51 reset_button (_("Reset"))
55 if (unit_strings.empty()) {
56 unit_strings = I18N (_unit_strings);
59 set_popdown_strings (units_combo, unit_strings);
60 units_combo.set_active_text (unit_strings.front());
62 w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
65 w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
67 minus_button.add (*w);
69 hbox1.pack_start (bc, true, true);
71 hbox2.set_homogeneous (false);
72 hbox2.set_spacing (12);
73 hbox2.pack_start (reset_button);
74 hbox2.pack_start (minus_button);
75 hbox2.pack_start (plus_button);
76 hbox2.pack_start (units_combo, true, true);
78 minus_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LatencyGUI::change_latency_from_button), -1));
79 plus_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LatencyGUI::change_latency_from_button), 1));
80 reset_button.signal_clicked().connect (sigc::mem_fun (*this, &LatencyGUI::reset));
82 adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &LatencyGUI::finish));
84 bc.set_size_request (-1, 25);
85 bc.set_style (BarController::LeftToRight);
86 bc.set_use_parent (true);
87 bc.set_name (X_("PluginSlider"));
90 pack_start (hbox1, true, true);
91 pack_start (hbox2, true, true);
97 framepos_t new_value = (framepos_t) adjustment.get_value();
98 if (new_value != initial_value) {
99 _latent.set_user_latency (new_value);
106 _latent.set_user_latency (0);
107 adjustment.set_value (initial_value);
111 LatencyGUI::refresh ()
113 initial_value = _latent.signal_latency();
114 adjustment.set_value (initial_value);
118 LatencyGUI::change_latency_from_button (int dir)
120 std::string unitstr = units_combo.get_active_text();
123 if (unitstr == unit_strings[0]) {
125 } else if (unitstr == unit_strings[1]) {
126 shift = (sample_rate / 1000.0);
127 } else if (unitstr == unit_strings[2]) {
130 fatal << string_compose (_("programming error: %1 (%2)"), X_("illegal string in latency GUI units combo"), unitstr)
136 adjustment.set_value (adjustment.get_value() + shift);
138 adjustment.set_value (adjustment.get_value() - shift);
142 LatencyDialog::LatencyDialog (const std::string& title, Latent& l, framepos_t sr, framepos_t psz)
143 : ArdourDialog (title, false, true),
147 get_vbox()->pack_start (lwidget);
148 add_button (Stock::CANCEL, RESPONSE_CANCEL);
149 add_button (Stock::APPLY, RESPONSE_REJECT);
150 add_button (Stock::OK, RESPONSE_ACCEPT);
158 case RESPONSE_ACCEPT:
162 case RESPONSE_REJECT: