use -r argument with JACK if realtime is not requested in engine dialog (also applied...
[ArdourMidi.git] / gtk2_ardour / latency_gui.cc
blob849edae767dfa726499e5da887dd0b036083ca2c
1 #define __STDC_FORMAT_MACROS 1
2 #include <inttypes.h>
4 #include <iomanip>
5 #include "ardour/latent.h"
6 #include <gtkmm2ext/utils.h>
8 #include "latency_gui.h"
10 #include "i18n.h"
12 using namespace PBD;
13 using namespace Gtk;
14 using namespace Gtkmm2ext;
15 using namespace ARDOUR;
18 static const gchar *_unit_strings[] = {
19 N_("sample"),
20 N_("msec"),
21 N_("period"),
25 std::vector<std::string> LatencyGUI::unit_strings;
27 std::string
28 LatencyBarController::get_label (int&)
30 double const nframes = _latency_gui->adjustment.get_value();
31 std::stringstream s;
33 if (nframes < (_latency_gui->sample_rate / 1000.0)) {
34 s << ((nframes64_t) rint (nframes)) << " samples";
35 } else {
36 s << std::fixed << std::setprecision (2) << (nframes / (_latency_gui->sample_rate / 1000.0)) << " msecs";
39 return s.str ();
42 LatencyGUI::LatencyGUI (Latent& l, nframes64_t sr, nframes64_t psz)
43 : _latent (l),
44 initial_value (_latent.signal_latency()),
45 sample_rate (sr),
46 period_size (psz),
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"))
53 Widget* w;
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));
63 w->show ();
64 plus_button.add (*w);
65 w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
66 w->show ();
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"));
89 set_spacing (12);
90 pack_start (hbox1, true, true);
91 pack_start (hbox2, true, true);
94 void
95 LatencyGUI::finish ()
97 nframes64_t new_value = (nframes64_t) adjustment.get_value();
98 if (new_value != initial_value) {
99 _latent.set_user_latency (new_value);
103 void
104 LatencyGUI::reset ()
106 _latent.set_user_latency (0);
107 adjustment.set_value (initial_value);
110 void
111 LatencyGUI::refresh ()
113 initial_value = _latent.signal_latency();
114 adjustment.set_value (initial_value);
117 void
118 LatencyGUI::change_latency_from_button (int dir)
120 Glib::ustring unitstr = units_combo.get_active_text();
121 double shift = 0.0;
123 if (unitstr == unit_strings[0]) {
124 shift = 1;
125 } else if (unitstr == unit_strings[1]) {
126 shift = (sample_rate / 1000.0);
127 } else if (unitstr == unit_strings[2]) {
128 shift = period_size;
129 } else {
130 fatal << string_compose (_("programming error: %1 (%2)"), X_("illegal string in latency GUI units combo"), unitstr)
131 << endmsg;
132 /*NOTREACHED*/
135 if (dir > 0) {
136 adjustment.set_value (adjustment.get_value() + shift);
137 } else {
138 adjustment.set_value (adjustment.get_value() - shift);
142 LatencyDialog::LatencyDialog (const Glib::ustring& title, Latent& l, nframes64_t sr, nframes64_t psz)
143 : ArdourDialog (title, false, true),
144 lwidget (l, sr, psz)
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);
152 show_all ();
154 while (true) {
155 int ret = run ();
157 switch (ret) {
158 case RESPONSE_ACCEPT:
159 return;
160 break;
162 case RESPONSE_REJECT:
163 lwidget.finish ();
164 break;
165 default:
166 return;