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 <gtkmm/messagedialog.h>
21 #include <glibmm/objectbase.h>
23 #include <gtkmm2ext/doi.h>
25 #include "ardour/audioengine.h"
26 #include "ardour/mtdm.h"
27 #include "ardour/port_insert.h"
28 #include "ardour/session.h"
30 #include "port_insert_ui.h"
31 #include "gui_thread.h"
34 using namespace ARDOUR;
37 PortInsertUI::PortInsertUI (Gtk::Window* parent, ARDOUR::Session* sess, boost::shared_ptr<ARDOUR::PortInsert> pi)
39 , latency_button (_("Measure Latency"))
40 , input_selector (parent, sess, pi->input())
41 , output_selector (parent, sess, pi->output())
43 latency_hbox.pack_start (latency_button, false, false);
44 latency_hbox.pack_start (latency_display, false, false);
45 latency_hbox.set_spacing (4);
47 output_selector.set_min_height_divisor (2);
48 input_selector.set_min_height_divisor (2);
50 notebook.append_page (output_selector, _("Send/Output"));
51 notebook.append_page (input_selector, _("Return/Input"));
53 notebook.set_current_page (0);
56 pack_start (notebook, true, true);
57 pack_start (latency_hbox, false, false);
59 update_latency_display ();
61 latency_button.signal_toggled().connect (mem_fun (*this, &PortInsertUI::latency_button_toggled));
62 latency_button.set_name (X_("MeasureLatencyButton"));
66 PortInsertUI::update_latency_display ()
68 framecnt_t const sample_rate = AudioEngine::instance()->sample_rate();
69 if (sample_rate == 0) {
70 latency_display.set_text (_("Disconnected from audio engine"));
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);
80 PortInsertUI::check_latency_measurement ()
82 MTDM* mtdm = _pi->mtdm ();
84 if (mtdm->resolve () < 0) {
85 latency_display.set_text (_("No signal detected"));
89 if (mtdm->err () > 0.3) {
95 framecnt_t const sample_rate = AudioEngine::instance()->sample_rate();
97 if (sample_rate == 0) {
98 latency_display.set_text (_("Disconnected from audio engine"));
99 _pi->stop_latency_detection ();
103 snprintf (buf, sizeof (buf), "%10.3lf frames %10.3lf ms", mtdm->del (), mtdm->del () * 1000.0f/sample_rate);
107 if (mtdm->err () > 0.2) {
113 strcat (buf, " (Inv)");
118 _pi->set_measured_latency (rint (mtdm->del()));
119 latency_button.set_active (false);
120 strcat (buf, " (set)");
123 latency_display.set_text (buf);
129 PortInsertUI::latency_button_toggled ()
131 if (latency_button.get_active ()) {
133 _pi->start_latency_detection ();
134 latency_display.set_text (_("Detecting ..."));
135 latency_timeout = Glib::signal_timeout().connect (mem_fun (*this, &PortInsertUI::check_latency_measurement), 250);
138 _pi->stop_latency_detection ();
139 latency_timeout.disconnect ();
140 update_latency_display ();
145 PortInsertUI::redisplay ()
147 input_selector.setup_ports (input_selector.other());
148 output_selector.setup_ports (output_selector.other());
152 PortInsertUI::finished (IOSelector::Result r)
154 input_selector.Finished (r);
155 output_selector.Finished (r);
159 PortInsertWindow::PortInsertWindow (ARDOUR::Session* sess, boost::shared_ptr<ARDOUR::PortInsert> pi)
160 : ArdourDialog ("port insert dialog"),
161 _portinsertui (this, sess, pi)
164 set_name ("IOSelectorWindow");
165 std::string title = _("Port Insert ");
169 get_vbox()->pack_start (_portinsertui);
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);
174 cancel_but->signal_clicked().connect (sigc::mem_fun (*this, &PortInsertWindow::cancel));
175 ok_but->signal_clicked().connect (sigc::mem_fun (*this, &PortInsertWindow::accept));
177 signal_delete_event().connect (sigc::mem_fun (*this, &PortInsertWindow::wm_delete), false);
181 PortInsertWindow::wm_delete (GdkEventAny* /*event*/)
188 PortInsertWindow::on_map ()
190 _portinsertui.redisplay ();
196 PortInsertWindow::cancel ()
198 _portinsertui.finished (IOSelector::Cancelled);
203 PortInsertWindow::accept ()
205 _portinsertui.finished (IOSelector::Accepted);