X-Git-Url: https://main.carlh.net/gitweb/?p=ardour.git;a=blobdiff_plain;f=gtk2_ardour%2Fplugin_pin_dialog.cc;h=d9591732bd2b1ad3372029ca35780c0b10d1d6aa;hp=422cd802bb97d70e170ad68f0eb16f413274caa1;hb=ae0dcdc0c5d13483271065c360e378202d20170a;hpb=5242aeb871d173c80e0ecde567831c7afcbf0fac diff --git a/gtk2_ardour/plugin_pin_dialog.cc b/gtk2_ardour/plugin_pin_dialog.cc index 422cd802bb..d9591732bd 100644 --- a/gtk2_ardour/plugin_pin_dialog.cc +++ b/gtk2_ardour/plugin_pin_dialog.cc @@ -19,41 +19,53 @@ #include -#include -#include #include +#include #include +#include +#include #include "pbd/replace_all.h" #include "gtkmm2ext/utils.h" #include "gtkmm2ext/rgb_macros.h" +#include "gtkmm2ext/menu_elems.h" +#include "widgets/tooltips.h" + +#include "ardour/amp.h" #include "ardour/audioengine.h" +#include "ardour/pannable.h" #include "ardour/plugin.h" #include "ardour/port.h" #include "ardour/profile.h" +#include "ardour/send.h" #include "ardour/session.h" +#include "ardour/value_as_string.h" #include "plugin_pin_dialog.h" #include "gui_thread.h" -#include "tooltips.h" +#include "timers.h" #include "ui_config.h" -#include "i18n.h" +#include "pbd/i18n.h" using namespace ARDOUR; using namespace PBD; using namespace std; using namespace Gtk; using namespace Gtkmm2ext; +using namespace ArdourWidgets; -PluginPinDialog::PluginPinDialog (boost::shared_ptr pi) - : ArdourWindow (string_compose (_("Pin Configuration: %1"), pi->name ())) - , _set_config (_("Manual Config"), ArdourButton::led_default_elements) - , _tgl_sidechain (_("Side Chain"), ArdourButton::led_default_elements) +PluginPinWidget::PluginPinWidget (boost::shared_ptr pi) + : _set_config (_("Manual Config"), ArdourButton::led_default_elements) + , _tgl_sidechain (_("Sidechain"), ArdourButton::led_default_elements) , _add_plugin (_("+")) , _del_plugin (_("-")) + , _add_input_audio (_("+")) + , _del_input_audio (_("-")) + , _add_input_midi (_("+")) + , _del_input_midi (_("-")) , _add_output_audio (_("+")) , _del_output_audio (_("-")) , _add_output_midi (_("+")) @@ -79,15 +91,15 @@ PluginPinDialog::PluginPinDialog (boost::shared_ptr pi) assert (pi->owner ()); // Route _pi->PluginIoReConfigure.connect ( - _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::plugin_reconfigured, this), gui_context () + _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context () ); _pi->PluginMapChanged.connect ( - _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::plugin_reconfigured, this), gui_context () + _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context () ); _pi->PluginConfigChanged.connect ( - _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::plugin_reconfigured, this), gui_context () + _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context () ); _pin_box_size = 2 * ceil (max (8., 10. * UIConfiguration::instance ().get_ui_scale ()) * .5); @@ -97,16 +109,23 @@ PluginPinDialog::PluginPinDialog (boost::shared_ptr pi) _tgl_sidechain.set_name ("pinrouting sidechain"); _set_config.set_name ("pinrouting custom"); - Menu_Helpers::MenuList& citems = reset_menu.items(); + Menu_Helpers::MenuList& citems = reset_menu.items (); reset_menu.set_name ("ArdourContextMenu"); - citems.clear(); - citems.push_back (Menu_Helpers::MenuElem (_("Reset"), sigc::mem_fun (*this, &PluginPinDialog::reset_mapping))); + citems.clear (); + citems.push_back (Menu_Helpers::MenuElem (_("Reset"), sigc::mem_fun (*this, &PluginPinWidget::reset_mapping))); _pm_size_group = SizeGroup::create (SIZE_GROUP_BOTH); _add_plugin.set_tweaks (ArdourButton::Square); _del_plugin.set_tweaks (ArdourButton::Square); - _pm_size_group->add_widget (_add_plugin); - _pm_size_group->add_widget (_del_plugin); + if (_pi->plugin (0)->get_info()->reconfigurable_io ()) { + _pm_size_group->add_widget (_add_input_audio); + _pm_size_group->add_widget (_del_input_audio); + _pm_size_group->add_widget (_add_input_midi); + _pm_size_group->add_widget (_del_input_midi); + } else { + _pm_size_group->add_widget (_add_plugin); + _pm_size_group->add_widget (_del_plugin); + } _pm_size_group->add_widget (_add_output_audio); _pm_size_group->add_widget (_del_output_audio); _pm_size_group->add_widget (_add_output_midi); @@ -126,20 +145,40 @@ PluginPinDialog::PluginPinDialog (boost::shared_ptr pi) /* left side */ tl->pack_start (_set_config, false, false); - box = manage (new HBox ()); - box->set_border_width (2); - box->pack_start (_add_plugin, true, false); - box->pack_start (_del_plugin, true, false); - f = manage (new Frame()); - f->set_label (_("Instances")); - f->add (*box); - tl->pack_start (*f, false, false); + if (_pi->plugin (0)->get_info()->reconfigurable_io ()) { + box = manage (new HBox ()); + box->set_border_width (2); + box->pack_start (_add_input_audio, true, false); + box->pack_start (_del_input_audio, true, false); + f = manage (new Frame ()); + f->set_label (_("Audio Input Pins")); + f->add (*box); + tl->pack_start (*f, false, false); + + box = manage (new HBox ()); + box->set_border_width (2); + box->pack_start (_add_input_midi, true, false); + box->pack_start (_del_input_midi, true, false); + f = manage (new Frame ()); + f->set_label (_("MIDI Input Pins")); + f->add (*box); + tl->pack_start (*f, false, false); + } else { + box = manage (new HBox ()); + box->set_border_width (2); + box->pack_start (_add_plugin, true, false); + box->pack_start (_del_plugin, true, false); + f = manage (new Frame ()); + f->set_label (_("Instances")); + f->add (*box); + tl->pack_start (*f, false, false); + } box = manage (new HBox ()); box->set_border_width (2); box->pack_start (_add_output_audio, true, false); box->pack_start (_del_output_audio, true, false); - f = manage (new Frame()); + f = manage (new Frame ()); f->set_label (_("Audio Out")); f->add (*box); tl->pack_start (*f, false, false); @@ -148,7 +187,7 @@ PluginPinDialog::PluginPinDialog (boost::shared_ptr pi) box->set_border_width (2); box->pack_start (_add_output_midi, true, false); box->pack_start (_del_output_midi, true, false); - f = manage (new Frame()); + f = manage (new Frame ()); f->set_label (_("MIDI Out")); f->add (*box); tl->pack_start (*f, false, false); @@ -156,7 +195,7 @@ PluginPinDialog::PluginPinDialog (boost::shared_ptr pi) tl->pack_start (*manage (new Label ("")), true, true); // invisible separator tl->pack_start (*manage (new HSeparator ()), false, false, 4); _out_presets.disable_scrolling (); - ARDOUR_UI_UTILS::set_tooltip (_out_presets, _("Output Presets")); + ArdourWidgets::set_tooltip (_out_presets, _("Output Presets")); tl->pack_start (_out_presets, false, false); /* right side */ @@ -171,7 +210,7 @@ PluginPinDialog::PluginPinDialog (boost::shared_ptr pi) box->set_spacing (2); box->pack_start (_add_sc_audio, false, false); box->pack_start (_add_sc_midi , false, false); - f = manage (new Frame()); + f = manage (new Frame ()); f->set_label (_("Add Sidechain Input")); f->add (*box); @@ -184,49 +223,92 @@ PluginPinDialog::PluginPinDialog (boost::shared_ptr pi) hbox->pack_start (darea, true, true); hbox->pack_start (*tr, false, false); - VBox* vbox = manage (new VBox ()); - vbox->pack_start (*hbox, true, true); + pack_start (*hbox, true, true); set_border_width (4); - add (*vbox); - vbox->show_all (); + show_all (); plugin_reconfigured (); darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK); - darea.signal_size_request ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_size_request)); - darea.signal_size_allocate ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_size_allocate)); - darea.signal_expose_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_expose_event)); - darea.signal_button_press_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_button_press_event)); - darea.signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_button_release_event)); - darea.signal_motion_notify_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_motion_notify_event)); - - _tgl_sidechain.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinDialog::toggle_sidechain)); - - _set_config.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinDialog::reset_configuration)); - _add_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_plugin_clicked), true)); - _del_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_plugin_clicked), false)); - - _add_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), true, DataType::AUDIO)); - _del_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), false, DataType::AUDIO)); - _add_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), true, DataType::MIDI)); - _del_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), false, DataType::MIDI)); - _add_sc_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_sidechain_port), DataType::AUDIO)); - _add_sc_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_sidechain_port), DataType::MIDI)); - - AudioEngine::instance()->PortConnectedOrDisconnected.connect ( - _io_connection, invalidator (*this), boost::bind (&PluginPinDialog::port_connected_or_disconnected, this, _1, _3), gui_context () + darea.signal_size_request ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_size_request)); + darea.signal_size_allocate ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_size_allocate)); + darea.signal_expose_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_expose_event)); + darea.signal_button_press_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_button_press_event)); + darea.signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_button_release_event)); + darea.signal_motion_notify_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_motion_notify_event)); + + _tgl_sidechain.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinWidget::toggle_sidechain)); + + _set_config.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinWidget::reset_configuration)); + _add_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_plugin_clicked), true)); + _del_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_plugin_clicked), false)); + + _add_input_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), true, DataType::AUDIO)); + _del_input_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), false, DataType::AUDIO)); + _add_input_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), true, DataType::MIDI)); + _del_input_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), false, DataType::MIDI)); + + _add_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), true, DataType::AUDIO)); + _del_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), false, DataType::AUDIO)); + _add_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), true, DataType::MIDI)); + _del_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), false, DataType::MIDI)); + + _add_sc_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_sidechain_port), DataType::AUDIO)); + _add_sc_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_sidechain_port), DataType::MIDI)); + + AudioEngine::instance ()->PortConnectedOrDisconnected.connect ( + _io_connection, invalidator (*this), boost::bind (&PluginPinWidget::port_connected_or_disconnected, this, _1, _3), gui_context () ); } -PluginPinDialog::~PluginPinDialog () +PluginPinWidget::~PluginPinWidget () { delete _sidechain_selector; } void -PluginPinDialog::plugin_reconfigured () +PluginPinWidget::set_session (ARDOUR::Session *s) { - ENSURE_GUI_THREAD (*this, &PluginPinDialog::plugin_reconfigured); + SessionHandlePtr::set_session (s); + plugin_reconfigured (); +} + +void +PluginPinWidget::queue_idle_update () +{ + /* various actions here are directly executed, in the GUI thread, + * with the GUI-thread eventually taking the process and processor lock. + * "connect gui_context()" will call back immediately and this + * signal-handler will run with the locks held. + * + * This will lead to a crash with calling nth_send() which takes + * a processor read-lock while holding a write lock in the same thread. + * + * decouple update to GUI idle. + * + * BUT, do delete existing controls here (in case they're affected by + * the change and hit by the Timer before idle comes around) + */ + for (list::iterator i = _controls.begin (); i != _controls.end (); ++i) { + _sidechain_tbl->remove ((*i)->box); + delete *i; + } + _controls.clear (); + Glib::signal_idle().connect (sigc::mem_fun(*this, &PluginPinWidget::idle_update)); +} + +bool +PluginPinWidget::idle_update () +{ + plugin_reconfigured (); + return false; +} + + +void +PluginPinWidget::plugin_reconfigured () +{ + ENSURE_GUI_THREAD (*this, &PluginPinWidget::plugin_reconfigured); if (_ignore_updates) { return; } @@ -244,19 +326,27 @@ PluginPinDialog::plugin_reconfigured () if (_pi->custom_cfg ()) { _set_config.set_active (true); _add_plugin.set_sensitive (true); + _del_plugin.set_sensitive (_n_plugins > 1); _add_output_audio.set_sensitive (true); _add_output_midi.set_sensitive (true); - _del_plugin.set_sensitive (_n_plugins > 1); _del_output_audio.set_sensitive (_out.n_audio () > 0 && _out.n_total () > 1); _del_output_midi.set_sensitive (_out.n_midi () > 0 && _out.n_total () > 1); + _add_input_audio.set_sensitive (true); + _add_input_midi.set_sensitive (true); + _del_input_audio.set_sensitive (_sinks.n_audio () > 0 && _sinks.n_total () > 1); + _del_input_midi.set_sensitive (_sinks.n_midi () > 0 && _sinks.n_total () > 1); _out_presets.set_sensitive (false); _out_presets.set_text (_("Manual")); } else { _set_config.set_active (false); _add_plugin.set_sensitive (false); + _del_plugin.set_sensitive (false); + _add_input_audio.set_sensitive (false); + _add_input_midi.set_sensitive (false); + _del_input_audio.set_sensitive (false); + _del_input_midi.set_sensitive (false); _add_output_audio.set_sensitive (false); _add_output_midi.set_sensitive (false); - _del_plugin.set_sensitive (false); _del_output_audio.set_sensitive (false); _del_output_midi.set_sensitive (false); _out_presets.set_sensitive (true); @@ -276,7 +366,7 @@ PluginPinDialog::plugin_reconfigured () _hover.reset (); _actor.reset (); _selection.reset (); - _drag_dst.reset(); + _drag_dst.reset (); _dragging = false; _n_inputs = _n_sidechains = 0; @@ -300,6 +390,9 @@ PluginPinDialog::plugin_reconfigured () _elements.push_back (CtrlWidget ("", Output, (i < _out.n_midi () ? DataType::MIDI : DataType::AUDIO), id)); } + _in_map.clear (); + _out_map.clear (); + for (uint32_t n = 0; n < _n_plugins; ++n) { boost::shared_ptr plugin = _pi->plugin (n); for (uint32_t i = 0; i < _sinks.n_total (); ++i) { @@ -315,7 +408,13 @@ PluginPinDialog::plugin_reconfigured () const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, false, idx)); _elements.push_back (CtrlWidget (iod.name, Source, dt, idx, n)); } + _in_map[n] = _pi->input_map (n); + _out_map[n] = _pi->output_map (n); } + _has_midi_bypass = _pi->has_midi_bypass (); + _thru_map = _pi->thru_map (); + + /* cache maps */ /* calc minimum size */ const uint32_t max_ports = std::max (_ins.n_total (), _out.n_total ()); @@ -341,13 +440,17 @@ PluginPinDialog::plugin_reconfigured () } void -PluginPinDialog::refill_sidechain_table () +PluginPinWidget::refill_sidechain_table () { Table_Helpers::TableList& kids = _sidechain_tbl->children (); for (Table_Helpers::TableList::iterator i = kids.begin (); i != kids.end ();) { i = kids.erase (i); } _sidechain_tbl->resize (1, 1); + for (list::iterator i = _controls.begin (); i != _controls.end (); ++i) { + delete *i; + } + _controls.clear (); if (!_pi->has_sidechain () && _sidechain_selector) { return; } @@ -359,29 +462,37 @@ PluginPinDialog::refill_sidechain_table () uint32_t r = 0; PortSet& p (io->ports ()); bool can_remove = p.num_ports () > 1; - for (PortSet::iterator i = p.begin (DataType::MIDI); i != p.end (DataType::MIDI); ++i, ++r) { - add_port_to_table (*i, r, can_remove); + for (PortSet::iterator i = p.begin (DataType::MIDI); i != p.end (DataType::MIDI); ++i) { + r += add_port_to_table (*i, r, can_remove); } - for (PortSet::iterator i = p.begin (DataType::AUDIO); i != p.end (DataType::AUDIO); ++i, ++r) { - add_port_to_table (*i, r, can_remove); + for (PortSet::iterator i = p.begin (DataType::AUDIO); i != p.end (DataType::AUDIO); ++i) { + r += add_port_to_table (*i, r, can_remove); } _sidechain_tbl->show_all (); } void -PluginPinDialog::refill_output_presets () +PluginPinWidget::refill_output_presets () { using namespace Menu_Helpers; - _out_presets.clear_items(); + _out_presets.clear_items (); - _out_presets.AddMenuElem (MenuElem(_("Automatic"), sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::select_output_preset), 0))); + bool need_dropdown = _pi->has_output_presets (); + + if (!need_dropdown) { + _out_presets.set_sensitive (false); + _out_presets.set_text (_("Automatic")); + return; + } + + _out_presets.AddMenuElem (MenuElem (_("Automatic"), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::select_output_preset), 0))); - PluginOutputConfiguration ppc (_pi->plugin (0)->possible_output ()); const uint32_t n_audio = _pi->preset_out ().n_audio (); if (n_audio == 0) { - _out_presets.set_text(_("Automatic")); + _out_presets.set_text (_("Automatic")); } + PluginOutputConfiguration ppc (_pi->plugin (0)->possible_output ()); if (ppc.find (0) != ppc.end ()) { // anyting goes ppc.clear (); @@ -410,75 +521,143 @@ PluginPinDialog::refill_output_presets () tmp = string_compose (P_("%1 Channel", "%1 Channels", *i), *i); break; } - _out_presets.AddMenuElem (MenuElem(tmp, sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::select_output_preset), *i))); + _out_presets.AddMenuElem (MenuElem (tmp, sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::select_output_preset), *i))); if (n_audio == *i) { - _out_presets.set_text(tmp); + _out_presets.set_text (tmp); } } } -void -PluginPinDialog::add_port_to_table (boost::shared_ptr p, uint32_t r, bool can_remove) +std::string +PluginPinWidget::port_label (const std::string& portname, bool strip) +{ + // compare to MixerStrip::update_io_button() + string lpn (PROGRAM_NAME); + boost::to_lower (lpn); + std::string program_port_prefix = lpn + ":"; // e.g. "ardour:" + + std::string pn = AudioEngine::instance ()->get_pretty_name_by_name (portname); + if (!pn.empty ()) { + string::size_type slash = pn.find ("/"); + if (slash != string::npos) { + pn = pn.substr (0, slash); + } + return pn; + } + std::string label (portname); + if (label.find ("system:capture_") == 0) { + if (label.empty ()) { + label = portname.substr (15); + } + } else if (label.find ("system:midi_capture_") == 0) { + if (label.empty ()) { + // "system:midi_capture_123" -> "123" + label = "M " + portname.substr (20); + } + } else if (label.find (program_port_prefix) == 0) { + label = label.substr (program_port_prefix.size ()); + if (strip) { + string::size_type slash = label.find ("/"); + if (slash != string::npos) { + label = label.substr (0, slash); + } + } + } + return label; +} + +uint32_t +PluginPinWidget::add_port_to_table (boost::shared_ptr p, uint32_t r, bool can_remove) { std::string lbl; - std::string tip = p->name (); + std::string tip = Gtkmm2ext::markup_escape_text (p->name ()); std::vector cns; + bool single_source = true; p->get_connections (cns); - // TODO proper labels, see MixerStrip::update_io_button() + for (std::vector::const_iterator i = cns.begin (); i != cns.end (); ++i) { + if (lbl.empty ()) { + lbl = port_label (*i, true); + continue; + } + if (port_label (*i, true) != lbl) { + lbl = "..."; + single_source = false; + break; + } + } + if (cns.size () == 0) { lbl = "-"; - } else if (cns.size () > 1) { - lbl = "..."; + single_source = false; + } else if (cns.size () == 1) { tip += " <- "; + lbl = port_label (cns[0], false); } else { - string lpn (PROGRAM_NAME); - boost::to_lower (lpn); - std::string program_port_prefix = lpn + ":"; // e.g. "ardour:" - - lbl = cns[0]; tip += " <- "; - if (lbl.find ("system:capture_") == 0) { - lbl = AudioEngine::instance ()->get_pretty_name_by_name (lbl); - if (lbl.empty ()) { - lbl = cns[0].substr (15); - } - } else if (lbl.find("system:midi_capture_") == 0) { - lbl = AudioEngine::instance ()->get_pretty_name_by_name (lbl); - if (lbl.empty ()) { - // "system:midi_capture_123" -> "123" - lbl = "M " + cns[0].substr (20); - } - } else if (lbl.find (program_port_prefix) == 0) { - lbl = lbl.substr (program_port_prefix.size()); - } } - for (std::vector::const_iterator i = cns.begin(); i != cns.end(); ++i) { + replace_all (lbl, "_", " "); + + for (std::vector::const_iterator i = cns.begin (); i != cns.end (); ++i) { tip += *i; tip += " "; } - replace_all (lbl, "_", " "); ArdourButton *pb = manage (new ArdourButton (lbl)); pb->set_text_ellipsize (Pango::ELLIPSIZE_MIDDLE); pb->set_layout_ellipsize_width (108 * PANGO_SCALE); - ARDOUR_UI_UTILS::set_tooltip (*pb, tip); + ArdourWidgets::set_tooltip (*pb, tip); _sidechain_tbl->attach (*pb, 0, 1, r, r +1 , EXPAND|FILL, SHRINK); - pb->signal_button_press_event ().connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::sc_input_press), boost::weak_ptr (p)), false); - pb->signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::sc_input_release), false); + pb->signal_button_press_event ().connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::sc_input_press), boost::weak_ptr (p)), false); + pb->signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::sc_input_release), false); pb = manage (new ArdourButton ("-")); - _sidechain_tbl->attach (*pb, 1, 2, r, r +1 , FILL, SHRINK); + _sidechain_tbl->attach (*pb, 1, 2, r, r + 1, FILL, SHRINK); if (can_remove) { - pb->signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::remove_port), boost::weak_ptr (p))); + pb->signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::remove_port), boost::weak_ptr (p))); } else { pb->set_sensitive (false); } + + uint32_t rv = 1; + + if (single_source && _session) { + /* check if it's an Ardour Send feeding.. */ + boost::shared_ptr routes = _session->get_routes (); + for (ARDOUR::RouteList::const_iterator i = routes->begin (); i != routes->end (); ++i) { + uint32_t nth = 0; + boost::shared_ptr proc; + /* nth_send () takes a processor read-lock */ + while ((proc = (*i)->nth_send (nth))) { + boost::shared_ptr send = boost::dynamic_pointer_cast (proc); + if (!send || !send->output ()) { + ++nth; + continue; + } + if (!send->output ()->connected_to (p->name ())) { + ++nth; + continue; + } + /* if processor goes away, we're notified by the port disconnect, + * there should be no need to explicily connect to proc->DropReferences + */ + set p = proc->what_can_be_automated (); + for (set::iterator i = p.begin (); i != p.end (); ++i) { + Control* c = new Control (proc->automation_control (*i), _("Send")); + _controls.push_back (c); + ++r; ++rv; + _sidechain_tbl->attach (c->box, 0, 2, r, r + 1, EXPAND|FILL, SHRINK); + } + break; + } + } + } + return rv; } void -PluginPinDialog::update_element_pos () +PluginPinWidget::update_element_pos () { /* layout sizes */ _innerwidth = _width - 2. * _margin_x; @@ -551,7 +730,7 @@ PluginPinDialog::update_element_pos () } void -PluginPinDialog::set_color (cairo_t* cr, bool midi) +PluginPinWidget::set_color (cairo_t* cr, bool midi) { // see also gtk2_ardour/processor_box.cc static const uint32_t audio_port_color = 0x4A8A0EFF; // Green @@ -571,7 +750,7 @@ PluginPinDialog::set_color (cairo_t* cr, bool midi) } void -PluginPinDialog::draw_io_pin (cairo_t* cr, const CtrlWidget& w) +PluginPinWidget::draw_io_pin (cairo_t* cr, const CtrlWidget& w) { if (w.e->sc) { const double dy = w.h * .5; @@ -617,7 +796,7 @@ PluginPinDialog::draw_io_pin (cairo_t* cr, const CtrlWidget& w) } void -PluginPinDialog::draw_plugin_pin (cairo_t* cr, const CtrlWidget& w) +PluginPinWidget::draw_plugin_pin (cairo_t* cr, const CtrlWidget& w) { const double dx = w.w * .5; const double dy = w.h * .5; @@ -649,7 +828,7 @@ PluginPinDialog::draw_plugin_pin (cairo_t* cr, const CtrlWidget& w) } cairo_fill (cr); - if ((w.prelight || w.e == _selection) && !w.name.empty()) { + if ((w.prelight || w.e == _selection) && !w.name.empty ()) { int text_width; int text_height; Glib::RefPtr layout; @@ -668,14 +847,14 @@ PluginPinDialog::draw_plugin_pin (cairo_t* cr, const CtrlWidget& w) } double -PluginPinDialog::pin_x_pos (uint32_t i, double x0, double width, uint32_t n_total, uint32_t n_midi, bool midi) +PluginPinWidget::pin_x_pos (uint32_t i, double x0, double width, uint32_t n_total, uint32_t n_midi, bool midi) { if (!midi) { i += n_midi; } return rint (x0 + (i + 1) * width / (1. + n_total)) - .5; } -const PluginPinDialog::CtrlWidget& -PluginPinDialog::get_io_ctrl (CtrlType ct, DataType dt, uint32_t id, uint32_t ip) const +const PluginPinWidget::CtrlWidget& +PluginPinWidget::get_io_ctrl (CtrlType ct, DataType dt, uint32_t id, uint32_t ip) const { for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) { if (i->e->ct == ct && i->e->dt == dt && i->e->id == id && i->e->ip == ip) { @@ -692,7 +871,7 @@ PluginPinDialog::get_io_ctrl (CtrlType ct, DataType dt, uint32_t id, uint32_t ip } void -PluginPinDialog::edge_coordinates (const CtrlWidget& w, double &x, double &y) +PluginPinWidget::edge_coordinates (const CtrlWidget& w, double &x, double &y) { switch (w.e->ct) { case Input: @@ -720,10 +899,11 @@ PluginPinDialog::edge_coordinates (const CtrlWidget& w, double &x, double &y) } void -PluginPinDialog::draw_connection (cairo_t* cr, double x0, double x1, double y0, double y1, bool midi, bool horiz, bool dashed) +PluginPinWidget::draw_connection (cairo_t* cr, double x0, double x1, double y0, double y1, bool midi, bool horiz, bool dashed) { const double bz = 2 * _pin_box_size; - const double bc = (dashed && x0 == x1) ? 1.25 * _pin_box_size : 0; + double bc = (dashed && x0 == x1) ? 1.25 * _pin_box_size : 0; + if (x0 > _width * .5) { bc *= -1; } cairo_move_to (cr, x0, y0); if (horiz) { @@ -746,7 +926,7 @@ PluginPinDialog::draw_connection (cairo_t* cr, double x0, double x1, double y0, } void -PluginPinDialog::draw_connection (cairo_t* cr, const CtrlWidget& w0, const CtrlWidget& w1, bool dashed) +PluginPinWidget::draw_connection (cairo_t* cr, const CtrlWidget& w0, const CtrlWidget& w1, bool dashed) { double x0, x1, y0, y1; edge_coordinates (w0, x0, y0); @@ -757,7 +937,7 @@ PluginPinDialog::draw_connection (cairo_t* cr, const CtrlWidget& w0, const CtrlW bool -PluginPinDialog::darea_expose_event (GdkEventExpose* ev) +PluginPinWidget::darea_expose_event (GdkEventExpose* ev) { Gtk::Allocation a = darea.get_allocation (); double const width = a.get_width (); @@ -789,25 +969,6 @@ PluginPinDialog::darea_expose_event (GdkEventExpose* ev) cairo_set_source_rgb (cr, .3, .3, .3); cairo_fill (cr); - /* draw midi-bypass (behind) */ - if (_pi->has_midi_bypass ()) { - const CtrlWidget& cw0 = get_io_ctrl (Input, DataType::MIDI, 0); - const CtrlWidget& cw1 = get_io_ctrl (Output, DataType::MIDI, 0); - draw_connection (cr, cw0, cw1, true); - } - - /* thru connections */ - const ChanMapping::Mappings thru_map = _pi->thru_map ().mappings (); - for (ChanMapping::Mappings::const_iterator t = thru_map.begin (); t != thru_map.end (); ++t) { - for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) { - const CtrlWidget& cw0 = get_io_ctrl (Output, t->first, c->first); - const CtrlWidget& cw1 = get_io_ctrl (Input, t->first, c->second); - if (!(_dragging && cw1.e == _selection && cw0.e == _drag_dst)) { - draw_connection (cr, cw1, cw0, true); - } - } - } - /* labels */ Glib::RefPtr layout; layout = Pango::Layout::create (get_pango_context ()); @@ -835,15 +996,22 @@ PluginPinDialog::darea_expose_event (GdkEventExpose* ev) cairo_set_source_rgba (cr, 1., 1., 1., 1.); pango_cairo_show_layout (cr, layout->gobj ()); - if (_pi->signal_latency () > 0) { - // TODO: this needs a better location also format to msec (and cache) +#ifndef NDEBUG + if (_pi->signal_latency () > 0 || !_pi->inplace()) { layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE); - layout->set_text (string_compose (_("Latency %1 spl"), _pi->signal_latency ())); + if (_pi->signal_latency () > 0 && !_pi->inplace()) { + layout->set_text (string_compose (_("Latency %1 spl%2 %3"), _pi->signal_latency (), ", ", _("no-inplace"))); + } else if (_pi->signal_latency () > 0) { + layout->set_text (string_compose (_("Latency %1 spl"), _pi->signal_latency ())); + } else { + layout->set_text (_("no-inplace")); + } layout->get_pixel_size (text_width, text_height); cairo_move_to (cr, _margin_x + _pin_box_size * .5, _margin_y + 2); cairo_set_source_rgba (cr, 1., 1., 1., 1.); pango_cairo_show_layout (cr, layout->gobj ()); } +#endif if (_pi->strict_io () && !Profile->get_mixbus ()) { layout->set_text (_("Strict I/O")); @@ -861,6 +1029,24 @@ PluginPinDialog::darea_expose_event (GdkEventExpose* ev) pango_cairo_show_layout (cr, layout->gobj ()); } + /* draw midi-bypass (behind) */ + if (_has_midi_bypass) { + const CtrlWidget& cw0 = get_io_ctrl (Input, DataType::MIDI, 0); + const CtrlWidget& cw1 = get_io_ctrl (Output, DataType::MIDI, 0); + draw_connection (cr, cw0, cw1, true); + } + + /* thru connections */ + const ChanMapping::Mappings thru_map (_thru_map.mappings ()); + for (ChanMapping::Mappings::const_iterator t = thru_map.begin (); t != thru_map.end (); ++t) { + for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) { + const CtrlWidget& cw0 = get_io_ctrl (Output, t->first, c->first); + const CtrlWidget& cw1 = get_io_ctrl (Input, t->first, c->second); + if (!(_dragging && cw1.e == _selection && cw0.e == _drag_dst)) { + draw_connection (cr, cw1, cw0, true); + } + } + } /* plugins & connection wires */ for (uint32_t i = 0; i < _n_plugins; ++i) { @@ -872,14 +1058,14 @@ PluginPinDialog::darea_expose_event (GdkEventExpose* ev) cairo_fill (cr); layout->set_width (1.9 * _bxw2 * PANGO_SCALE); - layout->set_text (string_compose (_("Plugin #%1"), i + 1)); + layout->set_text (string_compose (_("Instance #%1"), i + 1)); layout->get_pixel_size (text_width, text_height); cairo_move_to (cr, x0 - text_width * .5, yc - text_height * .5); cairo_set_source_rgba (cr, 1., 1., 1., 1.); pango_cairo_show_layout (cr, layout->gobj ()); - const ChanMapping::Mappings in_map = _pi->input_map (i).mappings (); - const ChanMapping::Mappings out_map = _pi->output_map (i).mappings (); + const ChanMapping::Mappings in_map = _in_map[i].mappings (); + const ChanMapping::Mappings out_map = _out_map[i].mappings (); for (ChanMapping::Mappings::const_iterator t = in_map.begin (); t != in_map.end (); ++t) { for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) { @@ -944,20 +1130,20 @@ PluginPinDialog::darea_expose_event (GdkEventExpose* ev) } void -PluginPinDialog::darea_size_request (Gtk::Requisition* req) +PluginPinWidget::darea_size_request (Gtk::Requisition* req) { req->width = _min_width; req->height = _min_height; } void -PluginPinDialog::darea_size_allocate (Gtk::Allocation&) +PluginPinWidget::darea_size_allocate (Gtk::Allocation&) { _position_valid = false; } bool -PluginPinDialog::drag_type_matches (const CtrlElem& e) +PluginPinWidget::drag_type_matches (const CtrlElem& e) { if (!_dragging || !_selection) { return true; @@ -975,13 +1161,13 @@ PluginPinDialog::drag_type_matches (const CtrlElem& e) } void -PluginPinDialog::start_drag (const CtrlElem& e, double x, double y) +PluginPinWidget::start_drag (const CtrlElem& e, double x, double y) { assert (_selection == e); _drag_dst.reset (); if (e->ct == Sink) { bool valid; - const ChanMapping& map (_pi->input_map (e->ip)); + const ChanMapping& map (_in_map[e->ip]); uint32_t idx = map.get (e->dt, e->id, &valid); if (valid) { const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0); @@ -992,7 +1178,7 @@ PluginPinDialog::start_drag (const CtrlElem& e, double x, double y) else if (e->ct == Output) { for (uint32_t i = 0; i < _n_plugins; ++i) { bool valid; - const ChanMapping& map (_pi->output_map (i)); + const ChanMapping& map (_out_map[i]); uint32_t idx = map.get_src (e->dt, e->id, &valid); if (valid) { const CtrlWidget& cw = get_io_ctrl (Source, e->dt, idx, i); @@ -1003,7 +1189,7 @@ PluginPinDialog::start_drag (const CtrlElem& e, double x, double y) } if (!_drag_dst) { bool valid; - const ChanMapping& map (_pi->thru_map ()); + const ChanMapping& map (_thru_map); uint32_t idx = map.get (e->dt, e->id, &valid); if (valid) { const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0); @@ -1018,7 +1204,7 @@ PluginPinDialog::start_drag (const CtrlElem& e, double x, double y) } bool -PluginPinDialog::darea_motion_notify_event (GdkEventMotion* ev) +PluginPinWidget::darea_motion_notify_event (GdkEventMotion* ev) { bool changed = false; _hover.reset (); @@ -1046,7 +1232,7 @@ PluginPinDialog::darea_motion_notify_event (GdkEventMotion* ev) } bool -PluginPinDialog::darea_button_press_event (GdkEventButton* ev) +PluginPinWidget::darea_button_press_event (GdkEventButton* ev) { if (ev->type != GDK_BUTTON_PRESS) { return false; @@ -1060,8 +1246,9 @@ PluginPinDialog::darea_button_press_event (GdkEventButton* ev) _actor.reset (); if (_selection) { start_drag (_selection, ev->x, ev->y); + } else { + darea.queue_draw (); } - darea.queue_draw (); } else if (_selection && _hover && _selection != _hover) { if (_selection->dt != _hover->dt) { _actor.reset (); } else if (_selection->ct == Input && _hover->ct == Sink) { _actor = _hover; } @@ -1073,8 +1260,9 @@ PluginPinDialog::darea_button_press_event (GdkEventButton* ev) if (!_actor) { _selection = _hover; start_drag (_selection, ev->x, ev->y); + } else { + darea.queue_draw (); } - darea.queue_draw (); } else if (_hover) { _selection = _hover; _actor.reset (); @@ -1097,7 +1285,7 @@ PluginPinDialog::darea_button_press_event (GdkEventButton* ev) } bool -PluginPinDialog::darea_button_release_event (GdkEventButton* ev) +PluginPinWidget::darea_button_release_event (GdkEventButton* ev) { if (_dragging && _selection && _drag_dst && _drag_dst == _hover) { // select click. (or re-connect same) @@ -1157,7 +1345,7 @@ PluginPinDialog::darea_button_release_event (GdkEventButton* ev) } void -PluginPinDialog::handle_input_action (const CtrlElem &s, const CtrlElem &i) +PluginPinWidget::handle_input_action (const CtrlElem &s, const CtrlElem &i) { const int pc = s->ip; bool valid; @@ -1187,7 +1375,7 @@ PluginPinDialog::handle_input_action (const CtrlElem &s, const CtrlElem &i) } void -PluginPinDialog::disconnect_other_outputs (uint32_t skip_pc, DataType dt, uint32_t id) +PluginPinWidget::disconnect_other_outputs (uint32_t skip_pc, DataType dt, uint32_t id) { _ignore_updates = true; for (uint32_t n = 0; n < _n_plugins; ++n) { @@ -1206,7 +1394,7 @@ PluginPinDialog::disconnect_other_outputs (uint32_t skip_pc, DataType dt, uint32 } void -PluginPinDialog::disconnect_other_thru (DataType dt, uint32_t id) +PluginPinWidget::disconnect_other_thru (DataType dt, uint32_t id) { _ignore_updates = true; bool valid; @@ -1220,7 +1408,7 @@ PluginPinDialog::disconnect_other_thru (DataType dt, uint32_t id) } void -PluginPinDialog::handle_output_action (const CtrlElem &s, const CtrlElem &o) +PluginPinWidget::handle_output_action (const CtrlElem &s, const CtrlElem &o) { const uint32_t pc = s->ip; bool valid; @@ -1255,7 +1443,7 @@ PluginPinDialog::handle_output_action (const CtrlElem &s, const CtrlElem &o) } void -PluginPinDialog::handle_thru_action (const CtrlElem &o, const CtrlElem &i) +PluginPinWidget::handle_thru_action (const CtrlElem &o, const CtrlElem &i) { bool valid; ChanMapping thru_map (_pi->thru_map ()); @@ -1277,7 +1465,7 @@ PluginPinDialog::handle_thru_action (const CtrlElem &o, const CtrlElem &i) } bool -PluginPinDialog::handle_disconnect (const CtrlElem &e, bool no_signal) +PluginPinWidget::handle_disconnect (const CtrlElem &e, bool no_signal) { _ignore_updates = true; bool changed = false; @@ -1365,14 +1553,14 @@ PluginPinDialog::handle_disconnect (const CtrlElem &e, bool no_signal) } void -PluginPinDialog::toggle_sidechain () +PluginPinWidget::toggle_sidechain () { - if (_session && _session->actively_recording()) { return; } + if (_session && _session->actively_recording ()) { return; } _route ()->add_remove_sidechain (_pi, !_pi->has_sidechain ()); } void -PluginPinDialog::connect_sidechain () +PluginPinWidget::connect_sidechain () { if (!_session) { return; } @@ -1388,63 +1576,79 @@ PluginPinDialog::connect_sidechain () } void -PluginPinDialog::reset_configuration () +PluginPinWidget::reset_configuration () { if (_set_config.get_active ()) { _route ()->reset_plugin_insert (_pi); } else { - _route ()->customize_plugin_insert (_pi, _n_plugins, _out); + _route ()->customize_plugin_insert (_pi, _n_plugins, _out, _sinks); } } void -PluginPinDialog::reset_mapping () +PluginPinWidget::reset_mapping () { _pi->reset_map (); } void -PluginPinDialog::select_output_preset (uint32_t n_audio) +PluginPinWidget::select_output_preset (uint32_t n_audio) { - if (_session && _session->actively_recording()) { return; } + if (_session && _session->actively_recording ()) { return; } ChanCount out (DataType::AUDIO, n_audio); _route ()->plugin_preset_output (_pi, out); } void -PluginPinDialog::add_remove_plugin_clicked (bool add) +PluginPinWidget::add_remove_plugin_clicked (bool add) { - if (_session && _session->actively_recording()) { return; } + if (_session && _session->actively_recording ()) { return; } ChanCount out = _out; + ChanCount sinks = _sinks; assert (add || _n_plugins > 0); - _route ()->customize_plugin_insert (_pi, _n_plugins + (add ? 1 : -1), out); + _route ()->customize_plugin_insert (_pi, _n_plugins + (add ? 1 : -1), out, sinks); } void -PluginPinDialog::add_remove_port_clicked (bool add, ARDOUR::DataType dt) +PluginPinWidget::add_remove_port_clicked (bool add, ARDOUR::DataType dt) { - if (_session && _session->actively_recording()) { return; } + if (_session && _session->actively_recording ()) { return; } ChanCount out = _out; + ChanCount sinks = _sinks; assert (add || out.get (dt) > 0); out.set (dt, out.get (dt) + (add ? 1 : -1)); - _route ()->customize_plugin_insert (_pi, _n_plugins, out); + _route ()->customize_plugin_insert (_pi, _n_plugins, out, sinks); } void -PluginPinDialog::add_sidechain_port (DataType dt) +PluginPinWidget::add_remove_inpin_clicked (bool add, ARDOUR::DataType dt) { - if (_session && _session->actively_recording()) { return; } + if (_session && _session->actively_recording ()) { return; } + ChanCount out = _out; + ChanCount sinks = _sinks; + assert (add || sinks.get (dt) > 0); + sinks.set (dt, sinks.get (dt) + (add ? 1 : -1)); + _route ()->customize_plugin_insert (_pi, _n_plugins, out, sinks); +} + +void +PluginPinWidget::add_sidechain_port (DataType dt) +{ + if (_session && _session->actively_recording ()) { return; } boost::shared_ptr io = _pi->sidechain_input (); if (!io) { return; } + + // this triggers a PluginIoReConfigure with process and processor write lock held + // from /this/ thread. io->add_port ("", this, dt); } void -PluginPinDialog::remove_port (boost::weak_ptr wp) +PluginPinWidget::remove_port (boost::weak_ptr wp) { - if (_session && _session->actively_recording()) { return; } + if (_session && _session->actively_recording ()) { return; } boost::shared_ptr p = wp.lock (); boost::shared_ptr io = _pi->sidechain_input (); if (!io || !p) { @@ -1454,9 +1658,9 @@ PluginPinDialog::remove_port (boost::weak_ptr wp) } void -PluginPinDialog::disconnect_port (boost::weak_ptr wp) +PluginPinWidget::disconnect_port (boost::weak_ptr wp) { - if (_session && _session->actively_recording()) { return; } + if (_session && _session->actively_recording ()) { return; } boost::shared_ptr p = wp.lock (); boost::shared_ptr io = _pi->sidechain_input (); if (!io || !p) { @@ -1466,9 +1670,9 @@ PluginPinDialog::disconnect_port (boost::weak_ptr wp) } void -PluginPinDialog::connect_port (boost::weak_ptr wp0, boost::weak_ptr wp1) +PluginPinWidget::connect_port (boost::weak_ptr wp0, boost::weak_ptr wp1) { - if (_session && _session->actively_recording()) { return; } + if (_session && _session->actively_recording ()) { return; } boost::shared_ptr p0 = wp0.lock (); boost::shared_ptr p1 = wp1.lock (); boost::shared_ptr io = _pi->sidechain_input (); @@ -1481,10 +1685,55 @@ PluginPinDialog::connect_port (boost::weak_ptr wp0, boost::weak_pt p0->connect (p1->name ()); } +void +PluginPinWidget::add_send_from (boost::weak_ptr wp, boost::weak_ptr wr) +{ + if (_session && _session->actively_recording ()) { return; } + boost::shared_ptr p = wp.lock (); + boost::shared_ptr r = wr.lock (); + boost::shared_ptr io = _pi->sidechain_input (); + if (!p || !r || !io || !_session) { + return; + } + + boost::shared_ptr sendpan (new Pannable (*_session)); + boost::shared_ptr send (new Send (*_session, r->pannable (), r->mute_master ())); + const ChanCount& outs (r->amp ()->input_streams ()); + try { + Glib::Threads::Mutex::Lock lm (AudioEngine::instance ()->process_lock ()); + send->output()->ensure_io (outs, false, this); + } catch (AudioEngine::PortRegistrationFailure& err) { + error << string_compose (_("Cannot set up new send: %1"), err.what ()) << endmsg; + return; + } + + std::string sendname = send->name (); + string::size_type last_letter = sendname.find_last_not_of ("0123456789"); + if (last_letter != string::npos) { + send->output ()->set_pretty_name (string_compose (_("SC %1 (%2)"), + r->name (), + sendname.substr (last_letter + 1))); + } + + _ignore_updates = true; + p->disconnect_all (); + + DataType dt = p->type (); + PortSet& ps (send->output ()->ports ()); + for (PortSet::iterator i = ps.begin (dt); i != ps.end (dt); ++i) { + p->connect (&(**i)); + } + + send->set_remove_on_disconnect (true); + r->add_processor (send, PreFader); + _ignore_updates = false; + queue_idle_update (); +} + bool -PluginPinDialog::sc_input_release (GdkEventButton *ev) +PluginPinWidget::sc_input_release (GdkEventButton *ev) { - if (_session && _session->actively_recording()) { return false; } + if (_session && _session->actively_recording ()) { return false; } if (ev->button == 3) { connect_sidechain (); } @@ -1493,26 +1742,26 @@ PluginPinDialog::sc_input_release (GdkEventButton *ev) struct RouteCompareByName { bool operator() (boost::shared_ptr a, boost::shared_ptr b) { - return a->name().compare (b->name()) < 0; + return a->name ().compare (b->name ()) < 0; } }; bool -PluginPinDialog::sc_input_press (GdkEventButton *ev, boost::weak_ptr wp) +PluginPinWidget::sc_input_press (GdkEventButton *ev, boost::weak_ptr wp) { using namespace Menu_Helpers; - if (!_session || _session->actively_recording()) { return false; } - if (!_session->engine().connected()) { return false; } + if (!_session || _session->actively_recording ()) { return false; } + if (!_session->engine ().connected ()) { return false; } if (ev->button == 1) { - MenuList& citems = input_menu.items(); + MenuList& citems = input_menu.items (); input_menu.set_name ("ArdourContextMenu"); - citems.clear(); + citems.clear (); boost::shared_ptr p = wp.lock (); if (p && p->connected ()) { - citems.push_back (MenuElem (_("Disconnect"), sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::disconnect_port), wp))); - citems.push_back (SeparatorElem()); + citems.push_back (MenuElem (_("Disconnect"), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::disconnect_port), wp))); + citems.push_back (SeparatorElem ()); } #if 0 @@ -1529,25 +1778,25 @@ PluginPinDialog::sc_input_press (GdkEventButton *ev, boost::weak_ptrtype (), wp); } if (added > 0) { - citems.push_back (SeparatorElem()); + citems.push_back (SeparatorElem ()); } - citems.push_back (MenuElem (_("Routing Grid"), sigc::mem_fun (*this, &PluginPinDialog::connect_sidechain))); + citems.push_back (MenuElem (_("Routing Grid"), sigc::mem_fun (*this, &PluginPinWidget::connect_sidechain))); input_menu.popup (1, ev->time); } return false; } uint32_t -PluginPinDialog::maybe_add_route_to_input_menu (boost::shared_ptr r, DataType dt, boost::weak_ptr wp) +PluginPinWidget::maybe_add_route_to_input_menu (boost::shared_ptr r, DataType dt, boost::weak_ptr wp) { uint32_t added = 0; using namespace Menu_Helpers; - if (r->output () == _route()->output()) { + if (r->output () == _route ()->output ()) { return added; } @@ -1555,27 +1804,37 @@ PluginPinDialog::maybe_add_route_to_input_menu (boost::shared_ptr r, Data return added; } - MenuList& citems = input_menu.items(); - const IOVector& iov (r->all_outputs()); + MenuList& citems = input_menu.items (); - for (IOVector::const_iterator o = iov.begin(); o != iov.end(); ++o) { - boost::shared_ptr op = o->lock(); - if (!op) { + /*check if there's already a send.. */ + bool already_present = false; + uint32_t nth = 0; + boost::shared_ptr proc; + /* Note: nth_send () takes a processor read-lock */ + while ((proc = r->nth_send (nth))) { + boost::shared_ptr send = boost::dynamic_pointer_cast (proc); + if (!send || !send->output ()) { + ++nth; continue; } - PortSet& p (op->ports ()); - for (PortSet::iterator i = p.begin (dt); i != p.end (dt); ++i) { - std::string n = i->name (); - replace_all (n, "_", " "); - citems.push_back (MenuElem (n, sigc::bind (sigc::mem_fun(*this, &PluginPinDialog::connect_port), wp, boost::weak_ptr (*i)))); - ++added; + if (send->output ()->connected_to (_pi->sidechain_input ())) { + // only if (send->remove_on_disconnect ()) ?? + already_present = true; + break; } + ++nth; + } + /* we're going to create the new send pre-fader, so check the route amp's data type. */ + const ChanCount& rc (r->amp ()->input_streams ()); + if (!already_present && rc.get (dt) > 0) { + citems.push_back (MenuElemNoMnemonic (r->name (), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_send_from), wp, boost::weak_ptr (r)))); + ++added; } return added; } void -PluginPinDialog::port_connected_or_disconnected (boost::weak_ptr w0, boost::weak_ptr w1) +PluginPinWidget::port_connected_or_disconnected (boost::weak_ptr w0, boost::weak_ptr w1) { boost::shared_ptr p0 = w0.lock (); boost::shared_ptr p1 = w1.lock (); @@ -1584,9 +1843,209 @@ PluginPinDialog::port_connected_or_disconnected (boost::weak_ptr w if (!io) { return; } if (p0 && io->has_port (p0)) { - plugin_reconfigured (); + queue_idle_update (); } else if (p1 && io->has_port (p1)) { - plugin_reconfigured (); + queue_idle_update (); + } +} + +/* lifted from ProcessorEntry::Control */ +PluginPinWidget::Control::Control (boost::shared_ptr c, string const & n) + : _control (c) + , _adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain ()), 0, 1, 0.01, 0.1) + , _slider (&_adjustment, boost::shared_ptr (), 0, max (13.f, rintf (13.f * UIConfiguration::instance ().get_ui_scale ()))) + , _slider_persistant_tooltip (&_slider) + , _ignore_ui_adjustment (false) + , _name (n) +{ + _slider.set_controllable (c); + box.set_padding (0, 0, 4, 4); + + _slider.set_name ("ProcessorControlSlider"); + _slider.set_text (_name); + + box.add (_slider); + _slider.show (); + + const ARDOUR::ParameterDescriptor& desc = c->desc (); + double const lo = c->internal_to_interface (desc.lower); + double const up = c->internal_to_interface (desc.upper); + double const normal = c->internal_to_interface (desc.normal); + double const smallstep = c->internal_to_interface (desc.lower + desc.smallstep); + double const largestep = c->internal_to_interface (desc.lower + desc.largestep); + + _adjustment.set_lower (lo); + _adjustment.set_upper (up); + _adjustment.set_step_increment (smallstep); + _adjustment.set_page_increment (largestep); + _slider.set_default_value (normal); + + _adjustment.signal_value_changed ().connect (sigc::mem_fun (*this, &Control::slider_adjusted)); + // dup. currently timers are used :( + //c->Changed.connect (_connection, MISSING_INVALIDATOR, boost::bind (&Control::control_changed, this), gui_context ()); + + // yuck, do we really need to do this? + // according to c404374 this is only needed for send automation + timer_connection = Timers::rapid_connect (sigc::mem_fun (*this, &Control::control_changed)); + + control_changed (); + set_tooltip (); + + /* We're providing our own PersistentTooltip */ + set_no_tooltip_whatsoever (_slider); +} + +PluginPinWidget::Control::~Control () +{ + timer_connection.disconnect (); +} + +void +PluginPinWidget::Control::set_tooltip () +{ + boost::shared_ptr c = _control.lock (); + if (!c) { + return; + } + std::string tt = _name + ": " + ARDOUR::value_as_string (c->desc(), c->get_value ()); + string sm = Gtkmm2ext::markup_escape_text (tt); + _slider_persistant_tooltip.set_tip (sm); +} + +void +PluginPinWidget::Control::slider_adjusted () +{ + if (_ignore_ui_adjustment) { + return; + } + boost::shared_ptr c = _control.lock (); + if (!c) { + return; + } + c->set_value ( c->interface_to_internal (_adjustment.get_value ()) , Controllable::NoGroup); + set_tooltip (); +} + + +void +PluginPinWidget::Control::control_changed () +{ + boost::shared_ptr c = _control.lock (); + if (!c) { + return; + } + + _ignore_ui_adjustment = true; + + // as long as rapid timers are used, only update the tooltip + // if the value has changed. + const double nval = c->internal_to_interface (c->get_value ()); + if (_adjustment.get_value () != nval) { + _adjustment.set_value (nval); + set_tooltip (); + } + + _ignore_ui_adjustment = false; +} + + + +PluginPinDialog::PluginPinDialog (boost::shared_ptr pi) + : ArdourWindow (string_compose (_("Pin Configuration: %1"), pi->name ())) +{ + ppw.push_back (PluginPinWidgetPtr(new PluginPinWidget (pi))); + add (*ppw.back()); +} + + +PluginPinDialog::PluginPinDialog (boost::shared_ptr r) + : ArdourWindow (string_compose (_("Pin Configuration: %1"), r->name ())) + , _route (r) + , _height_mapped (false) +{ + vbox = manage (new VBox ()); + vbox->signal_size_allocate().connect (sigc::mem_fun (*this, &PluginPinDialog::map_height)); + scroller = manage (new ScrolledWindow); + scroller->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC); + scroller->set_shadow_type (Gtk::SHADOW_NONE); + scroller->show (); + vbox->show (); + scroller->add (*vbox); + add (*scroller); + + + _route->foreach_processor (sigc::mem_fun (*this, &PluginPinDialog::add_processor)); + + _route->processors_changed.connect ( + _route_connections, invalidator (*this), boost::bind (&PluginPinDialog::route_processors_changed, this, _1), gui_context() + ); + + _route->DropReferences.connect ( + _route_connections, invalidator (*this), boost::bind (&PluginPinDialog::route_going_away, this), gui_context() + ); +} +void +PluginPinDialog::set_session (ARDOUR::Session *s) +{ + SessionHandlePtr::set_session (s); + for (PluginPinWidgetList::iterator i = ppw.begin(); i != ppw.end(); ++i) { + (*i)->set_session (s); + } +} + +void +PluginPinDialog::map_height (Gtk::Allocation&) +{ + if (!_height_mapped) { + scroller->set_size_request (-1, std::min (600, 2 + vbox->get_height())); + _height_mapped = true; + } +} + +void +PluginPinDialog::route_processors_changed (ARDOUR::RouteProcessorChange) +{ + ppw.clear (); + _height_mapped = false; + scroller->remove (); + vbox = manage (new VBox ()); + vbox->signal_size_allocate().connect (sigc::mem_fun (*this, &PluginPinDialog::map_height)); + scroller->add (*vbox); + _route->foreach_processor (sigc::mem_fun (*this, &PluginPinDialog::add_processor)); + vbox->show (); +} + +void +PluginPinDialog::route_going_away () +{ + ppw.clear (); + _route.reset (); + remove (); +} + +void +PluginPinDialog::add_processor (boost::weak_ptr p) +{ + boost::shared_ptr proc = p.lock (); + if (!proc || !proc->display_to_user ()) { + return; + } + boost::shared_ptr pi = boost::dynamic_pointer_cast (proc); +#ifdef MIXBUS + if (pi && pi->is_channelstrip ()) { + pi.reset (); + } +#endif + if (pi) { + ppw.push_back (PluginPinWidgetPtr(new PluginPinWidget (pi))); + vbox->pack_start (*ppw.back()); + } else { + HBox* hbox = manage (new HBox ()); + hbox->pack_start (*manage (new HSeparator ())); + hbox->pack_start (*manage (new Label (proc->display_name ()))); + hbox->pack_start (*manage (new HSeparator ())); + vbox->pack_start (*hbox, false, false); + hbox->show_all (); } }