1 #define __STDC_FORMAT_MACROS 1
4 #include "ardour/latent.h"
5 #include <gtkmm2ext/utils.h>
7 #include "latency_gui.h"
13 using namespace Gtkmm2ext;
15 using namespace ARDOUR;
18 static const gchar *_unit_strings[] = {
25 std::vector<std::string> LatencyGUI::unit_strings;
28 LatencyGUI::latency_printer (char *buf, unsigned int bufsize)
30 double nframes = adjustment.get_value();
32 if (nframes < (sample_rate / 1000.0)) {
33 snprintf (buf, bufsize, "%" PRId64 " samples", (nframes64_t) rint (nframes));
35 snprintf (buf, bufsize, "%.2g msecs" , nframes / (sample_rate / 1000.0));
39 LatencyGUI::LatencyGUI (Latent& l, nframes64_t sr, nframes64_t psz)
41 initial_value (_latent.signal_latency()),
44 ignored (new PBD::IgnorableControllable()),
45 /* max 1 second, step by frames, page by msecs */
46 adjustment (initial_value, 0.0, sample_rate, 1.0, sample_rate / 1000.0f),
47 bc (adjustment, ignored, sigc::mem_fun (*this, &LatencyGUI::latency_printer)),
48 reset_button (_("Reset"))
52 if (unit_strings.empty()) {
53 unit_strings = I18N (_unit_strings);
56 set_popdown_strings (units_combo, unit_strings);
57 units_combo.set_active_text (unit_strings.front());
59 w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
62 w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
64 minus_button.add (*w);
66 hbox1.pack_start (bc, true, true);
68 hbox2.set_homogeneous (false);
69 hbox2.set_spacing (12);
70 hbox2.pack_start (reset_button);
71 hbox2.pack_start (minus_button);
72 hbox2.pack_start (plus_button);
73 hbox2.pack_start (units_combo, true, true);
75 minus_button.signal_clicked().connect (bind (mem_fun (*this, &LatencyGUI::change_latency_from_button), -1));
76 plus_button.signal_clicked().connect (bind (mem_fun (*this, &LatencyGUI::change_latency_from_button), 1));
77 reset_button.signal_clicked().connect (mem_fun (*this, &LatencyGUI::reset));
79 adjustment.signal_value_changed().connect (mem_fun (*this, &LatencyGUI::finish));
81 bc.set_size_request (-1, 25);
82 bc.set_style (BarController::LeftToRight);
83 bc.set_use_parent (true);
84 bc.set_name (X_("PluginSlider"));
87 pack_start (hbox1, true, true);
88 pack_start (hbox2, true, true);
94 nframes64_t new_value = (nframes64_t) adjustment.get_value();
95 if (new_value != initial_value) {
96 _latent.set_user_latency (new_value);
103 _latent.set_user_latency (0);
104 adjustment.set_value (initial_value);
108 LatencyGUI::refresh ()
110 initial_value = _latent.signal_latency();
111 adjustment.set_value (initial_value);
115 LatencyGUI::change_latency_from_button (int dir)
117 Glib::ustring unitstr = units_combo.get_active_text();
120 if (unitstr == unit_strings[0]) {
122 } else if (unitstr == unit_strings[1]) {
123 shift = (sample_rate / 1000.0);
124 } else if (unitstr == unit_strings[2]) {
127 fatal << string_compose (_("programming error: %1 (%2)"), X_("illegal string in latency GUI units combo"), unitstr)
133 adjustment.set_value (adjustment.get_value() + shift);
135 adjustment.set_value (adjustment.get_value() - shift);
139 LatencyDialog::LatencyDialog (const Glib::ustring& title, Latent& l, nframes64_t sr, nframes64_t psz)
140 : ArdourDialog (title, false, true),
144 get_vbox()->pack_start (lwidget);
145 add_button (Stock::CANCEL, RESPONSE_CANCEL);
146 add_button (Stock::APPLY, RESPONSE_REJECT);
147 add_button (Stock::OK, RESPONSE_ACCEPT);
155 case RESPONSE_ACCEPT:
159 case RESPONSE_REJECT: