2 Copyright (C) 2002-2007 Paul Davis
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.
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.
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.
20 #include <glibmm/objectbase.h>
22 #include <gtkmm/messagedialog.h>
23 #include <gtkmm/stock.h>
25 #include "ardour/audioengine.h"
26 #include "ardour/mtdm.h"
27 #include "ardour/port_insert.h"
28 #include "ardour/session.h"
30 #include "gtkmm2ext/doi.h"
32 #include "port_insert_ui.h"
33 #include "gui_thread.h"
36 using namespace ARDOUR;
39 PortInsertUI::PortInsertUI (Gtk::Window* parent, ARDOUR::Session* sess, boost::shared_ptr<ARDOUR::PortInsert> pi)
41 , latency_button (_("Measure Latency"))
42 , input_selector (parent, sess, pi->input())
43 , output_selector (parent, sess, pi->output())
45 latency_hbox.pack_start (latency_button, false, false);
46 latency_hbox.pack_start (latency_display, false, false);
47 latency_hbox.set_spacing (4);
49 output_selector.set_min_height_divisor (2);
50 input_selector.set_min_height_divisor (2);
52 notebook.append_page (output_selector, _("Send/Output"));
53 notebook.append_page (input_selector, _("Return/Input"));
55 notebook.set_current_page (0);
58 pack_start (notebook, true, true);
59 pack_start (latency_hbox, false, false);
61 update_latency_display ();
63 latency_button.signal_toggled().connect (mem_fun (*this, &PortInsertUI::latency_button_toggled));
64 latency_button.set_name (X_("MeasureLatencyButton"));
68 PortInsertUI::update_latency_display ()
70 samplecnt_t const sample_rate = AudioEngine::instance()->sample_rate();
71 if (sample_rate == 0) {
72 latency_display.set_text (_("Disconnected from audio engine"));
75 snprintf (buf, sizeof (buf), "%10.3lf samples %10.3lf ms",
76 (float)_pi->latency(), (float)_pi->latency() * 1000.0f/sample_rate);
77 latency_display.set_text(buf);
82 PortInsertUI::check_latency_measurement ()
84 MTDM* mtdm = _pi->mtdm ();
86 if (mtdm->resolve () < 0) {
87 latency_display.set_text (_("No signal detected"));
91 if (mtdm->err () > 0.3) {
97 samplecnt_t const sample_rate = AudioEngine::instance()->sample_rate();
99 if (sample_rate == 0) {
100 latency_display.set_text (_("Disconnected from audio engine"));
101 _pi->stop_latency_detection ();
105 snprintf (buf, sizeof (buf), "%10.3lf samples %10.3lf ms", mtdm->del (), mtdm->del () * 1000.0f/sample_rate);
109 if (mtdm->err () > 0.2) {
115 strcat (buf, " (Inv)");
120 _pi->set_measured_latency (rint (mtdm->del()));
121 latency_button.set_active (false);
122 strcat (buf, " (set)");
125 latency_display.set_text (buf);
131 PortInsertUI::latency_button_toggled ()
133 if (latency_button.get_active ()) {
135 _pi->start_latency_detection ();
136 latency_display.set_text (_("Detecting ..."));
137 latency_timeout = Glib::signal_timeout().connect (mem_fun (*this, &PortInsertUI::check_latency_measurement), 250);
140 _pi->stop_latency_detection ();
141 latency_timeout.disconnect ();
142 update_latency_display ();
147 PortInsertUI::redisplay ()
149 input_selector.setup_ports (input_selector.other());
150 output_selector.setup_ports (output_selector.other());
154 PortInsertUI::finished (IOSelector::Result r)
156 input_selector.Finished (r);
157 output_selector.Finished (r);
161 PortInsertWindow::PortInsertWindow (ARDOUR::Session* sess, boost::shared_ptr<ARDOUR::PortInsert> pi)
162 : ArdourDialog ("port insert dialog"),
163 _portinsertui (this, sess, pi)
166 set_name ("IOSelectorWindow");
167 std::string title = _("Port Insert ");
171 get_vbox()->pack_start (_portinsertui);
173 Gtk::Button* cancel_but = add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
174 Gtk::Button* ok_but = add_button (Gtk::Stock::OK, Gtk::RESPONSE_OK);
176 cancel_but->signal_clicked().connect (sigc::mem_fun (*this, &PortInsertWindow::cancel));
177 ok_but->signal_clicked().connect (sigc::mem_fun (*this, &PortInsertWindow::accept));
179 signal_delete_event().connect (sigc::mem_fun (*this, &PortInsertWindow::wm_delete), false);
183 PortInsertWindow::wm_delete (GdkEventAny* /*event*/)
190 PortInsertWindow::on_map ()
192 _portinsertui.redisplay ();
198 PortInsertWindow::cancel ()
200 _portinsertui.finished (IOSelector::Cancelled);
205 PortInsertWindow::accept ()
207 _portinsertui.finished (IOSelector::Accepted);