1 #define __STDC_FORMAT_MACROS 1
5 #include "ardour/latent.h"
6 #include <gtkmm2ext/utils.h>
8 #include "latency_gui.h"
14 using namespace Gtkmm2ext;
16 using namespace ARDOUR;
19 static const gchar *_unit_strings[] = {
26 std::vector<std::string> LatencyGUI::unit_strings;
29 LatencyGUI::get_label (int&)
31 double const nframes = adjustment.get_value();
34 if (nframes < (sample_rate / 1000.0)) {
35 s << ((nframes64_t) rint (nframes)) << " samples";
37 s << std::fixed << std::setprecision (2) << (nframes / (sample_rate / 1000.0)) << " msecs";
43 LatencyGUI::LatencyGUI (Latent& l, nframes64_t sr, nframes64_t psz)
45 initial_value (_latent.signal_latency()),
48 ignored (new PBD::IgnorableControllable()),
49 /* max 1 second, step by frames, page by msecs */
50 adjustment (initial_value, 0.0, sample_rate, 1.0, sample_rate / 1000.0f),
51 bc (adjustment, ignored),
52 reset_button (_("Reset"))
56 if (unit_strings.empty()) {
57 unit_strings = I18N (_unit_strings);
60 set_popdown_strings (units_combo, unit_strings);
61 units_combo.set_active_text (unit_strings.front());
63 w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
66 w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
68 minus_button.add (*w);
70 hbox1.pack_start (bc, true, true);
72 hbox2.set_homogeneous (false);
73 hbox2.set_spacing (12);
74 hbox2.pack_start (reset_button);
75 hbox2.pack_start (minus_button);
76 hbox2.pack_start (plus_button);
77 hbox2.pack_start (units_combo, true, true);
79 minus_button.signal_clicked().connect (bind (mem_fun (*this, &LatencyGUI::change_latency_from_button), -1));
80 plus_button.signal_clicked().connect (bind (mem_fun (*this, &LatencyGUI::change_latency_from_button), 1));
81 reset_button.signal_clicked().connect (mem_fun (*this, &LatencyGUI::reset));
83 adjustment.signal_value_changed().connect (mem_fun (*this, &LatencyGUI::finish));
85 bc.set_size_request (-1, 25);
86 bc.set_style (BarController::LeftToRight);
87 bc.set_use_parent (true);
88 bc.set_name (X_("PluginSlider"));
91 pack_start (hbox1, true, true);
92 pack_start (hbox2, true, true);
98 nframes64_t new_value = (nframes64_t) adjustment.get_value();
99 if (new_value != initial_value) {
100 _latent.set_user_latency (new_value);
107 _latent.set_user_latency (0);
108 adjustment.set_value (initial_value);
112 LatencyGUI::refresh ()
114 initial_value = _latent.signal_latency();
115 adjustment.set_value (initial_value);
119 LatencyGUI::change_latency_from_button (int dir)
121 Glib::ustring unitstr = units_combo.get_active_text();
124 if (unitstr == unit_strings[0]) {
126 } else if (unitstr == unit_strings[1]) {
127 shift = (sample_rate / 1000.0);
128 } else if (unitstr == unit_strings[2]) {
131 fatal << string_compose (_("programming error: %1 (%2)"), X_("illegal string in latency GUI units combo"), unitstr)
137 adjustment.set_value (adjustment.get_value() + shift);
139 adjustment.set_value (adjustment.get_value() - shift);
143 LatencyDialog::LatencyDialog (const Glib::ustring& title, Latent& l, nframes64_t sr, nframes64_t psz)
144 : ArdourDialog (title, false, true),
148 get_vbox()->pack_start (lwidget);
149 add_button (Stock::CANCEL, RESPONSE_CANCEL);
150 add_button (Stock::APPLY, RESPONSE_REJECT);
151 add_button (Stock::OK, RESPONSE_ACCEPT);
159 case RESPONSE_ACCEPT:
163 case RESPONSE_REJECT: