2010-08-31 10:16:29 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2010-2011 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2010-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2011-2012 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2013-2017 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2010-08-31 10:16:29 -04:00
|
|
|
|
|
|
|
#include <glibmm/objectbase.h>
|
|
|
|
|
2017-07-16 21:48:18 -04:00
|
|
|
#include <gtkmm/messagedialog.h>
|
|
|
|
#include <gtkmm/stock.h>
|
2010-08-31 10:16:29 -04:00
|
|
|
|
|
|
|
#include "ardour/audioengine.h"
|
|
|
|
#include "ardour/mtdm.h"
|
2012-05-24 02:09:29 -04:00
|
|
|
#include "ardour/port_insert.h"
|
|
|
|
#include "ardour/session.h"
|
2010-08-31 10:16:29 -04:00
|
|
|
|
2017-07-16 21:48:18 -04:00
|
|
|
#include "gtkmm2ext/doi.h"
|
|
|
|
|
2010-08-31 10:16:29 -04:00
|
|
|
#include "port_insert_ui.h"
|
|
|
|
#include "gui_thread.h"
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2010-08-31 10:16:29 -04:00
|
|
|
|
|
|
|
using namespace ARDOUR;
|
|
|
|
using namespace Gtk;
|
|
|
|
|
|
|
|
PortInsertUI::PortInsertUI (Gtk::Window* parent, ARDOUR::Session* sess, boost::shared_ptr<ARDOUR::PortInsert> pi)
|
2017-07-01 12:42:24 -04:00
|
|
|
: _pi (pi)
|
|
|
|
, latency_button (_("Measure Latency"))
|
|
|
|
, input_selector (parent, sess, pi->input())
|
|
|
|
, output_selector (parent, sess, pi->output())
|
2010-08-31 10:16:29 -04:00
|
|
|
{
|
2017-07-01 12:42:24 -04:00
|
|
|
latency_hbox.pack_start (latency_button, false, false);
|
|
|
|
latency_hbox.pack_start (latency_display, false, false);
|
2011-09-19 17:14:59 -04:00
|
|
|
latency_hbox.set_spacing (4);
|
2010-08-31 10:16:29 -04:00
|
|
|
|
|
|
|
output_selector.set_min_height_divisor (2);
|
|
|
|
input_selector.set_min_height_divisor (2);
|
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
notebook.append_page (output_selector, _("Send/Output"));
|
|
|
|
notebook.append_page (input_selector, _("Return/Input"));
|
2010-08-31 10:16:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
notebook.set_current_page (0);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
set_spacing (12);
|
|
|
|
pack_start (notebook, true, true);
|
|
|
|
pack_start (latency_hbox, false, false);
|
2010-08-31 10:16:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
update_latency_display ();
|
2010-08-31 10:16:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
latency_button.signal_toggled().connect (mem_fun (*this, &PortInsertUI::latency_button_toggled));
|
2011-09-19 17:14:59 -04:00
|
|
|
latency_button.set_name (X_("MeasureLatencyButton"));
|
2010-08-31 10:16:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PortInsertUI::update_latency_display ()
|
|
|
|
{
|
2017-09-18 12:39:17 -04:00
|
|
|
samplecnt_t const sample_rate = AudioEngine::instance()->sample_rate();
|
2017-07-01 12:42:24 -04:00
|
|
|
if (sample_rate == 0) {
|
|
|
|
latency_display.set_text (_("Disconnected from audio engine"));
|
|
|
|
} else {
|
|
|
|
char buf[64];
|
2017-09-18 12:39:17 -04:00
|
|
|
snprintf (buf, sizeof (buf), "%10.3lf samples %10.3lf ms",
|
2017-07-01 12:42:24 -04:00
|
|
|
(float)_pi->latency(), (float)_pi->latency() * 1000.0f/sample_rate);
|
|
|
|
latency_display.set_text(buf);
|
|
|
|
}
|
2010-08-31 10:16:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PortInsertUI::check_latency_measurement ()
|
|
|
|
{
|
2017-07-01 12:42:24 -04:00
|
|
|
MTDM* mtdm = _pi->mtdm ();
|
2010-08-31 10:16:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
if (mtdm->resolve () < 0) {
|
|
|
|
latency_display.set_text (_("No signal detected"));
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-31 10:16:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
if (mtdm->err () > 0.3) {
|
|
|
|
mtdm->invert ();
|
|
|
|
mtdm->resolve ();
|
|
|
|
}
|
2010-08-31 10:16:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
char buf[128];
|
2017-09-18 12:39:17 -04:00
|
|
|
samplecnt_t const sample_rate = AudioEngine::instance()->sample_rate();
|
2010-08-31 10:16:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
if (sample_rate == 0) {
|
|
|
|
latency_display.set_text (_("Disconnected from audio engine"));
|
|
|
|
_pi->stop_latency_detection ();
|
|
|
|
return false;
|
|
|
|
}
|
2010-08-31 10:16:29 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
snprintf (buf, sizeof (buf), "%10.3lf samples %10.3lf ms", mtdm->del (), mtdm->del () * 1000.0f/sample_rate);
|
2010-08-31 10:16:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
bool solid = true;
|
2010-08-31 10:16:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
if (mtdm->err () > 0.2) {
|
|
|
|
strcat (buf, " ??");
|
|
|
|
solid = false;
|
|
|
|
}
|
2010-08-31 10:16:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
if (mtdm->inv ()) {
|
|
|
|
strcat (buf, " (Inv)");
|
|
|
|
solid = false;
|
|
|
|
}
|
2010-08-31 10:16:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
if (solid) {
|
|
|
|
_pi->set_measured_latency (rint (mtdm->del()));
|
|
|
|
latency_button.set_active (false);
|
|
|
|
strcat (buf, " (set)");
|
|
|
|
}
|
2010-08-31 10:16:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
latency_display.set_text (buf);
|
2010-08-31 10:16:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
return true;
|
2010-08-31 10:16:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PortInsertUI::latency_button_toggled ()
|
|
|
|
{
|
2017-07-01 12:42:24 -04:00
|
|
|
if (latency_button.get_active ()) {
|
2010-08-31 10:16:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
_pi->start_latency_detection ();
|
|
|
|
latency_display.set_text (_("Detecting ..."));
|
|
|
|
latency_timeout = Glib::signal_timeout().connect (mem_fun (*this, &PortInsertUI::check_latency_measurement), 250);
|
2010-08-31 10:16:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
} else {
|
|
|
|
_pi->stop_latency_detection ();
|
|
|
|
latency_timeout.disconnect ();
|
|
|
|
update_latency_display ();
|
|
|
|
}
|
2010-08-31 10:16:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PortInsertUI::redisplay ()
|
|
|
|
{
|
|
|
|
input_selector.setup_ports (input_selector.other());
|
|
|
|
output_selector.setup_ports (output_selector.other());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PortInsertUI::finished (IOSelector::Result r)
|
|
|
|
{
|
|
|
|
input_selector.Finished (r);
|
|
|
|
output_selector.Finished (r);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PortInsertWindow::PortInsertWindow (ARDOUR::Session* sess, boost::shared_ptr<ARDOUR::PortInsert> pi)
|
|
|
|
: ArdourDialog ("port insert dialog"),
|
|
|
|
_portinsertui (this, sess, pi)
|
|
|
|
{
|
|
|
|
|
|
|
|
set_name ("IOSelectorWindow");
|
2012-05-24 02:09:29 -04:00
|
|
|
std::string title = _("Port Insert ");
|
2010-08-31 10:16:29 -04:00
|
|
|
title += pi->name();
|
|
|
|
set_title (title);
|
|
|
|
|
|
|
|
get_vbox()->pack_start (_portinsertui);
|
|
|
|
|
2011-11-18 19:56:35 -05:00
|
|
|
Gtk::Button* cancel_but = add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
|
|
|
Gtk::Button* ok_but = add_button (Gtk::Stock::OK, Gtk::RESPONSE_OK);
|
|
|
|
|
|
|
|
cancel_but->signal_clicked().connect (sigc::mem_fun (*this, &PortInsertWindow::cancel));
|
|
|
|
ok_but->signal_clicked().connect (sigc::mem_fun (*this, &PortInsertWindow::accept));
|
|
|
|
|
2010-08-31 10:16:29 -04:00
|
|
|
signal_delete_event().connect (sigc::mem_fun (*this, &PortInsertWindow::wm_delete), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PortInsertWindow::wm_delete (GdkEventAny* /*event*/)
|
|
|
|
{
|
|
|
|
accept ();
|
2013-07-07 16:24:15 -04:00
|
|
|
return false;
|
2010-08-31 10:16:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PortInsertWindow::on_map ()
|
|
|
|
{
|
|
|
|
_portinsertui.redisplay ();
|
|
|
|
Window::on_map ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
PortInsertWindow::cancel ()
|
|
|
|
{
|
|
|
|
_portinsertui.finished (IOSelector::Cancelled);
|
|
|
|
hide ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PortInsertWindow::accept ()
|
|
|
|
{
|
|
|
|
_portinsertui.finished (IOSelector::Accepted);
|
|
|
|
hide ();
|
|
|
|
}
|
|
|
|
|