ardour
port_insert_ui.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2007 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 <gtkmm/messagedialog.h>
21 #include <glibmm/objectbase.h>
22 
23 #include <gtkmm2ext/doi.h>
24 
25 #include "ardour/audioengine.h"
26 #include "ardour/mtdm.h"
27 #include "ardour/port_insert.h"
28 #include "ardour/session.h"
29 
30 #include "port_insert_ui.h"
31 #include "gui_thread.h"
32 #include "i18n.h"
33 
34 using namespace ARDOUR;
35 using namespace Gtk;
36 
38  : _pi (pi)
39  , latency_button (_("Measure Latency"))
40  , input_selector (parent, sess, pi->input())
41  , output_selector (parent, sess, pi->output())
42 {
43  latency_hbox.pack_start (latency_button, false, false);
44  latency_hbox.pack_start (latency_display, false, false);
45  latency_hbox.set_spacing (4);
46 
49 
50  notebook.append_page (output_selector, _("Send/Output"));
51  notebook.append_page (input_selector, _("Return/Input"));
52 
53  notebook.set_current_page (0);
54 
55  set_spacing (12);
56  pack_start (notebook, true, true);
57  pack_start (latency_hbox, false, false);
58 
60 
61  latency_button.signal_toggled().connect (mem_fun (*this, &PortInsertUI::latency_button_toggled));
62  latency_button.set_name (X_("MeasureLatencyButton"));
63 }
64 
65 void
67 {
68  framecnt_t const sample_rate = AudioEngine::instance()->sample_rate();
69  if (sample_rate == 0) {
70  latency_display.set_text (_("Disconnected from audio engine"));
71  } else {
72  char buf[64];
73  snprintf (buf, sizeof (buf), "%10.3lf frames %10.3lf ms",
74  (float)_pi->latency(), (float)_pi->latency() * 1000.0f/sample_rate);
75  latency_display.set_text(buf);
76  }
77 }
78 
79 bool
81 {
82  MTDM* mtdm = _pi->mtdm ();
83 
84  if (mtdm->resolve () < 0) {
85  latency_display.set_text (_("No signal detected"));
86  return true;
87  }
88 
89  if (mtdm->err () > 0.3) {
90  mtdm->invert ();
91  mtdm->resolve ();
92  }
93 
94  char buf[128];
95  framecnt_t const sample_rate = AudioEngine::instance()->sample_rate();
96 
97  if (sample_rate == 0) {
98  latency_display.set_text (_("Disconnected from audio engine"));
100  return false;
101  }
102 
103  snprintf (buf, sizeof (buf), "%10.3lf frames %10.3lf ms", mtdm->del (), mtdm->del () * 1000.0f/sample_rate);
104 
105  bool solid = true;
106 
107  if (mtdm->err () > 0.2) {
108  strcat (buf, " ??");
109  solid = false;
110  }
111 
112  if (mtdm->inv ()) {
113  strcat (buf, " (Inv)");
114  solid = false;
115  }
116 
117  if (solid) {
118  _pi->set_measured_latency (rint (mtdm->del()));
119  latency_button.set_active (false);
120  strcat (buf, " (set)");
121  }
122 
123  latency_display.set_text (buf);
124 
125  return true;
126 }
127 
128 void
130 {
131  if (latency_button.get_active ()) {
132 
134  latency_display.set_text (_("Detecting ..."));
135  latency_timeout = Glib::signal_timeout().connect (mem_fun (*this, &PortInsertUI::check_latency_measurement), 250);
136 
137  } else {
139  latency_timeout.disconnect ();
141  }
142 }
143 
144 void
146 {
149 }
150 
151 void
153 {
156 }
157 
158 
160  : ArdourDialog ("port insert dialog"),
161  _portinsertui (this, sess, pi)
162 {
163 
164  set_name ("IOSelectorWindow");
165  std::string title = _("Port Insert ");
166  title += pi->name();
167  set_title (title);
168 
169  get_vbox()->pack_start (_portinsertui);
170 
171  Gtk::Button* cancel_but = add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
172  Gtk::Button* ok_but = add_button (Gtk::Stock::OK, Gtk::RESPONSE_OK);
173 
174  cancel_but->signal_clicked().connect (sigc::mem_fun (*this, &PortInsertWindow::cancel));
175  ok_but->signal_clicked().connect (sigc::mem_fun (*this, &PortInsertWindow::accept));
176 
177  signal_delete_event().connect (sigc::mem_fun (*this, &PortInsertWindow::wm_delete), false);
178 }
179 
180 bool
181 PortInsertWindow::wm_delete (GdkEventAny* /*event*/)
182 {
183  accept ();
184  return false;
185 }
186 
187 void
189 {
191  Window::on_map ();
192 }
193 
194 
195 void
197 {
199  hide ();
200 }
201 
202 void
204 {
206  hide ();
207 }
208 
double del(void)
Definition: mtdm.h:35
bool wm_delete(GdkEventAny *)
bool check_latency_measurement()
Definition: mtdm.h:26
Definition: ardour_ui.h:130
void finished(IOSelector::Result)
double err(void)
Definition: mtdm.h:36
IOSelector input_selector
sigc::connection latency_timeout
void update_latency_display()
void stop_latency_detection()
Definition: port_insert.cc:73
MTDM * mtdm() const
Definition: port_insert.h:72
#define _(Text)
Definition: i18n.h:11
Gtk::Label latency_display
PortInsertUI(Gtk::Window *, ARDOUR::Session *, boost::shared_ptr< ARDOUR::PortInsert >)
PortInsertUI _portinsertui
#define X_(Text)
Definition: i18n.h:13
int64_t framecnt_t
Definition: types.h:76
void invert(void)
Definition: mtdm.h:33
PortInsertWindow(ARDOUR::Session *, boost::shared_ptr< ARDOUR::PortInsert >)
Definition: amp.h:29
void set_min_height_divisor(int f)
Definition: port_matrix.h:79
Gtk::Notebook notebook
int inv(void)
Definition: mtdm.h:34
std::string name() const
void set_measured_latency(framecnt_t)
Definition: port_insert.cc:80
sigc::signal< void, Result > Finished
Definition: port_matrix.h:164
boost::shared_ptr< ARDOUR::PortInsert > _pi
int resolve(void)
Definition: mtdm.cc:93
Gtk::HBox latency_hbox
void start_latency_detection()
Definition: port_insert.cc:63
int other() const
Definition: io_selector.h:52
Gtkmm2ext::StatefulToggleButton latency_button
void setup_ports(int)
Definition: io_selector.cc:109
void latency_button_toggled()
framecnt_t latency() const
Definition: port_insert.cc:86
IOSelector output_selector