ardour
latency_gui.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Paul Davis
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 
18 */
19 
20 #include <inttypes.h>
21 
22 #include <iomanip>
23 #include "ardour/latent.h"
24 #include "pbd/convert.h"
25 #include "pbd/error.h"
26 #include <gtkmm2ext/utils.h>
27 
28 #include "latency_gui.h"
29 
30 #include "i18n.h"
31 
32 using namespace PBD;
33 using namespace Gtk;
34 using namespace Gtkmm2ext;
35 using namespace ARDOUR;
36 
37 
38 static const gchar *_unit_strings[] = {
39  N_("sample"),
40  N_("msec"),
41  N_("period"),
42  0
43 };
44 
45 std::vector<std::string> LatencyGUI::unit_strings;
46 
47 std::string
49 {
50  double const nframes = _latency_gui->adjustment.get_value();
51  std::stringstream s;
52 
53  if (nframes < (_latency_gui->sample_rate / 1000.0)) {
54  const framepos_t nf = (framepos_t) rint (nframes);
55  s << string_compose (P_("%1 sample", "%1 samples", nf), nf);
56  } else {
57  s << std::fixed << std::setprecision (2) << (nframes / (_latency_gui->sample_rate / 1000.0)) << " ms";
58  }
59 
60  return s.str ();
61 }
62 
64  : _latent (l),
65  initial_value (_latent.user_latency()),
66  sample_rate (sr),
67  period_size (psz),
68  ignored (new PBD::IgnorableControllable()),
69  /* max 1 second, step by frames, page by msecs */
70  adjustment (initial_value, 0.0, sample_rate, 1.0, sample_rate / 1000.0f),
71  bc (adjustment, this),
72  reset_button (_("Reset"))
73 {
74  Widget* w;
75 
76  if (unit_strings.empty()) {
78  }
79 
81  units_combo.set_active_text (unit_strings.front());
82 
83  w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
84  w->show ();
85  plus_button.add (*w);
86  w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
87  w->show ();
88  minus_button.add (*w);
89 
90  hbox1.pack_start (bc, true, true);
91 
92  hbox2.set_homogeneous (false);
93  hbox2.set_spacing (12);
94  hbox2.pack_start (reset_button);
95  hbox2.pack_start (minus_button);
96  hbox2.pack_start (plus_button);
97  hbox2.pack_start (units_combo, true, true);
98 
99  minus_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LatencyGUI::change_latency_from_button), -1));
100  plus_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LatencyGUI::change_latency_from_button), 1));
101  reset_button.signal_clicked().connect (sigc::mem_fun (*this, &LatencyGUI::reset));
102 
103  adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &LatencyGUI::finish));
104 
105  bc.set_size_request (-1, 25);
106  bc.set_name (X_("ProcessorControlSlider"));
107 
108  set_spacing (12);
109  pack_start (hbox1, true, true);
110  pack_start (hbox2, true, true);
111 }
112 
113 void
115 {
116  framepos_t new_value = (framepos_t) adjustment.get_value();
117  if (new_value != initial_value) {
118  _latent.set_user_latency (new_value);
119  }
120 }
121 
122 void
124 {
126  adjustment.set_value (initial_value);
127 }
128 
129 void
131 {
133  adjustment.set_value (initial_value);
134 }
135 
136 void
138 {
139  std::string unitstr = units_combo.get_active_text();
140  double shift = 0.0;
141 
142  if (unitstr == unit_strings[0]) {
143  shift = 1;
144  } else if (unitstr == unit_strings[1]) {
145  shift = (sample_rate / 1000.0);
146  } else if (unitstr == unit_strings[2]) {
147  shift = period_size;
148  } else {
149  fatal << string_compose (_("programming error: %1 (%2)"), X_("illegal string in latency GUI units combo"), unitstr)
150  << endmsg;
151  abort(); /*NOTREACHED*/
152  }
153 
154  if (dir > 0) {
155  adjustment.set_value (adjustment.get_value() + shift);
156  } else {
157  adjustment.set_value (adjustment.get_value() - shift);
158  }
159 }
160 
161 LatencyDialog::LatencyDialog (const std::string& title, Latent& l, framepos_t sr, framepos_t psz)
162  : ArdourDialog (title, false, true),
163  lwidget (l, sr, psz)
164 {
165  get_vbox()->pack_start (lwidget);
166  add_button (Stock::CLOSE, RESPONSE_CLOSE);
167 
168  show_all ();
169  run ();
170 }
171 
172 
LIBPBD_API Transmitter fatal
Gtk::Button plus_button
Definition: latency_gui.h:80
LatencyGUI(ARDOUR::Latent &, framepos_t sample_rate, framepos_t period_size)
Definition: latency_gui.cc:63
Definition: ardour_ui.h:130
tuple f
Definition: signals.py:35
LatencyGUI lwidget
Definition: latency_gui.h:98
std::ostream & endmsg(std::ostream &ostr)
Definition: transmitter.h:71
LIBGTKMM2EXT_API void set_popdown_strings(Gtk::ComboBoxText &, const std::vector< std::string > &)
#define P_(Singular, Plural, HowMany)
Definition: i18n.h:41
virtual framecnt_t signal_latency() const =0
#define _(Text)
Definition: i18n.h:11
Gtk::HBox hbox1
Definition: latency_gui.h:76
#define X_(Text)
Definition: i18n.h:13
std::string get_label(double &)
Definition: latency_gui.cc:48
framepos_t period_size
Definition: latency_gui.h:71
LIBARDOUR_API PBD::PropertyDescriptor< float > shift
Definition: region.cc:71
Definition: amp.h:29
Gtk::Button reset_button
Definition: latency_gui.h:81
Gtk::ComboBoxText units_combo
Definition: latency_gui.h:82
int64_t framepos_t
Definition: types.h:66
framepos_t sample_rate
Definition: latency_gui.h:70
#define I18N(Array)
Definition: i18n.h:14
ARDOUR::Latent & _latent
Definition: latency_gui.h:68
void finish()
Definition: latency_gui.cc:114
virtual void set_user_latency(framecnt_t val)
Definition: latent.h:44
Gtk::Button minus_button
Definition: latency_gui.h:79
static const gchar * _unit_strings[]
Definition: latency_gui.cc:38
LatencyBarController bc
Definition: latency_gui.h:75
void change_latency_from_button(int dir)
Definition: latency_gui.cc:137
Definition: debug.h:30
static std::vector< std::string > unit_strings
Definition: latency_gui.h:88
Gtk::Adjustment adjustment
Definition: latency_gui.h:74
void refresh()
Definition: latency_gui.cc:130
Gtk::HBox hbox2
Definition: latency_gui.h:77
void reset()
Definition: latency_gui.cc:123
int64_t framepos_t
framepos_t initial_value
Definition: latency_gui.h:69
std::string string_compose(const std::string &fmt, const T1 &o1)
Definition: compose.h:208
#define N_(Text)
Definition: i18n.h:12
LatencyDialog(const std::string &title, ARDOUR::Latent &, framepos_t sample_rate, framepos_t period_size)
Definition: latency_gui.cc:161