2 Copyright (C) 2000-2004 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.
21 #include "gtk2ardour-config.h"
28 #include <sigc++/bind.h>
30 #include "pbd/convert.h"
32 #include <glibmm/miscutils.h>
34 #include <gtkmm/messagedialog.h>
36 #include <gtkmm2ext/gtk_ui.h>
37 #include <gtkmm2ext/utils.h>
38 #include <gtkmm2ext/choice.h>
39 #include <gtkmm2ext/utils.h>
40 #include <gtkmm2ext/doi.h>
42 #include "ardour/amp.h"
43 #include "ardour/audio_track.h"
44 #include "ardour/audioengine.h"
45 #include "ardour/internal_return.h"
46 #include "ardour/internal_send.h"
47 #include "ardour/plugin_insert.h"
48 #include "ardour/port_insert.h"
49 #include "ardour/profile.h"
50 #include "ardour/return.h"
51 #include "ardour/route.h"
52 #include "ardour/send.h"
53 #include "ardour/session.h"
54 #include "ardour/types.h"
57 #include "ardour_dialog.h"
58 #include "ardour_ui.h"
59 #include "gui_thread.h"
60 #include "io_selector.h"
63 #include "mixer_strip.h"
64 #include "plugin_selector.h"
65 #include "plugin_ui.h"
66 #include "port_insert_ui.h"
67 #include "processor_box.h"
68 #include "public_editor.h"
69 #include "return_ui.h"
70 #include "route_processor_selection.h"
76 #ifdef AUDIOUNIT_SUPPORT
81 using namespace ARDOUR;
85 using namespace Gtkmm2ext;
87 ProcessorBox* ProcessorBox::_current_processor_box = 0;
88 RefPtr<Action> ProcessorBox::paste_action;
89 RefPtr<Action> ProcessorBox::cut_action;
90 RefPtr<Action> ProcessorBox::rename_action;
91 RefPtr<Action> ProcessorBox::edit_action;
92 RefPtr<Action> ProcessorBox::edit_generic_action;
94 ProcessorEntry::ProcessorEntry (ProcessorBox* parent, boost::shared_ptr<Processor> p, Width w)
95 : _button (ArdourButton::led_default_elements)
96 , _position (PreFader)
100 , _visual_state (Gtk::STATE_NORMAL)
104 _button.set_diameter (3);
105 _button.set_distinct_led_click (true);
106 _button.set_led_left (true);
107 _button.signal_led_clicked.connect (sigc::mem_fun (*this, &ProcessorEntry::led_clicked));
108 _button.set_text (name (_width));
112 _vbox.pack_start (_button, true, true);
114 _button.set_active (_processor->active());
117 _processor->ActiveChanged.connect (active_connection, invalidator (*this), boost::bind (&ProcessorEntry::processor_active_changed, this), gui_context());
118 _processor->PropertyChanged.connect (name_connection, invalidator (*this), boost::bind (&ProcessorEntry::processor_property_changed, this, _1), gui_context());
120 set<Evoral::Parameter> p = _processor->what_can_be_automated ();
121 for (set<Evoral::Parameter>::iterator i = p.begin(); i != p.end(); ++i) {
123 Control* c = new Control (_processor->automation_control (*i), _processor->describe_parameter (*i));
125 _controls.push_back (c);
127 if (boost::dynamic_pointer_cast<Amp> (_processor) == 0) {
128 /* Add non-Amp controls to the processor box */
129 _vbox.pack_start (c->box);
132 if (boost::dynamic_pointer_cast<Send> (_processor)) {
133 /* Don't label send faders */
141 _vbox.set_size_request (-1, _button.size_request().height);
145 ProcessorEntry::~ProcessorEntry ()
147 for (list<Control*>::iterator i = _controls.begin(); i != _controls.end(); ++i) {
153 ProcessorEntry::action_widget ()
159 ProcessorEntry::widget ()
165 ProcessorEntry::drag_text () const
171 ProcessorEntry::set_position (Position p)
178 ProcessorEntry::set_visual_state (Gtkmm2ext::VisualState s, bool yn)
181 _button.set_visual_state (Gtkmm2ext::VisualState (_button.visual_state() | s));
183 _button.set_visual_state (Gtkmm2ext::VisualState (_button.visual_state() & ~s));
188 ProcessorEntry::setup_visuals ()
192 _button.set_name ("processor prefader");
196 _button.set_name ("processor fader");
200 _button.set_name ("processor postfader");
206 boost::shared_ptr<Processor>
207 ProcessorEntry::processor () const
213 ProcessorEntry::set_enum_width (Width w)
216 _button.set_text (name (_width));
220 ProcessorEntry::led_clicked()
223 if (_button.get_active ()) {
224 _processor->deactivate ();
226 _processor->activate ();
232 ProcessorEntry::processor_active_changed ()
235 _button.set_active (_processor->active());
240 ProcessorEntry::processor_property_changed (const PropertyChange& what_changed)
242 if (what_changed.contains (ARDOUR::Properties::name)) {
243 _button.set_text (name (_width));
249 ProcessorEntry::setup_tooltip ()
252 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (_processor);
254 if (pi->plugin()->has_editor()) {
255 ARDOUR_UI::instance()->set_tip (_button,
256 string_compose (_("<b>%1</b>\nDouble-click to show GUI.\nAlt+double-click to show generic GUI."), name (Wide)));
258 ARDOUR_UI::instance()->set_tip (_button,
259 string_compose (_("<b>%1</b>\nDouble-click to show generic GUI."), name (Wide)));
264 ARDOUR_UI::instance()->set_tip (_button, string_compose ("<b>%1</b>", name (Wide)));
268 ProcessorEntry::name (Width w) const
270 boost::shared_ptr<Send> send;
277 if ((send = boost::dynamic_pointer_cast<Send> (_processor)) != 0 &&
278 !boost::dynamic_pointer_cast<InternalSend>(_processor)) {
282 /* grab the send name out of its overall name */
284 string::size_type lbracket, rbracket;
285 lbracket = send->name().find ('[');
286 rbracket = send->name().find (']');
290 name_display += send->name().substr (lbracket+1, lbracket-rbracket-1);
293 name_display += PBD::short_version (send->name().substr (lbracket+1, lbracket-rbracket-1), 4);
301 name_display += _processor->display_name();
304 name_display += PBD::short_version (_processor->display_name(), 5);
314 ProcessorEntry::show_all_controls ()
316 for (list<Control*>::iterator i = _controls.begin(); i != _controls.end(); ++i) {
317 (*i)->set_visible (true);
320 _parent->update_gui_object_state (this);
324 ProcessorEntry::hide_all_controls ()
326 for (list<Control*>::iterator i = _controls.begin(); i != _controls.end(); ++i) {
327 (*i)->set_visible (false);
330 _parent->update_gui_object_state (this);
334 ProcessorEntry::add_control_state (XMLNode* node) const
336 for (list<Control*>::const_iterator i = _controls.begin(); i != _controls.end(); ++i) {
337 (*i)->add_state (node);
342 ProcessorEntry::set_control_state (XMLNode const * node)
344 for (list<Control*>::const_iterator i = _controls.begin(); i != _controls.end(); ++i) {
345 (*i)->set_state (node);
350 ProcessorEntry::state_id () const
352 return string_compose ("processor %1", _processor->id().to_s());
356 ProcessorEntry::hide_things ()
358 for (list<Control*>::iterator i = _controls.begin(); i != _controls.end(); ++i) {
359 (*i)->hide_things ();
365 ProcessorEntry::build_controls_menu ()
367 using namespace Menu_Helpers;
368 Menu* menu = manage (new Menu);
369 MenuList& items = menu->items ();
372 MenuElem (_("Show All Controls"), sigc::mem_fun (*this, &ProcessorEntry::show_all_controls))
376 MenuElem (_("Hide All Controls"), sigc::mem_fun (*this, &ProcessorEntry::hide_all_controls))
379 if (!_controls.empty ()) {
380 items.push_back (SeparatorElem ());
383 for (list<Control*>::iterator i = _controls.begin(); i != _controls.end(); ++i) {
384 items.push_back (CheckMenuElem ((*i)->name ()));
385 CheckMenuItem* c = dynamic_cast<CheckMenuItem*> (&items.back ());
386 c->set_active ((*i)->visible ());
387 c->signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &ProcessorEntry::toggle_control_visibility), *i));
394 ProcessorEntry::toggle_control_visibility (Control* c)
396 c->set_visible (!c->visible ());
397 _parent->update_gui_object_state (this);
400 ProcessorEntry::Control::Control (boost::shared_ptr<AutomationControl> c, string const & n)
402 , _adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain()), 0, 1, 0.01, 0.1)
403 , _slider (&_adjustment, 0, 13, false)
404 , _slider_persistant_tooltip (&_slider)
405 , _button (ArdourButton::Element (ArdourButton::Text | ArdourButton::Indicator))
406 , _ignore_ui_adjustment (false)
410 _slider.set_controllable (c);
413 _button.set_text (_name);
414 _button.set_led_left (true);
415 _button.set_name ("processor control button");
416 box.pack_start (_button);
419 _button.signal_clicked.connect (sigc::mem_fun (*this, &Control::button_clicked));
420 _button.signal_led_clicked.connect (sigc::mem_fun (*this, &Control::button_clicked));
421 c->Changed.connect (_connection, MISSING_INVALIDATOR, boost::bind (&Control::control_changed, this), gui_context ());
425 _slider.set_name ("PluginSlider");
426 _slider.set_text (_name);
428 box.pack_start (_slider);
431 double const lo = c->internal_to_interface (c->lower ());
432 double const up = c->internal_to_interface (c->upper ());
434 _adjustment.set_lower (lo);
435 _adjustment.set_upper (up);
436 _adjustment.set_step_increment ((up - lo) / 100);
437 _adjustment.set_page_increment ((up - lo) / 10);
438 _slider.set_default_value (c->internal_to_interface (c->normal ()));
440 _adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &Control::slider_adjusted));
441 c->Changed.connect (_connection, MISSING_INVALIDATOR, boost::bind (&Control::control_changed, this), gui_context ());
444 ARDOUR_UI::RapidScreenUpdate.connect (sigc::mem_fun (*this, &Control::control_changed));
449 /* We're providing our own PersistentTooltip */
450 set_no_tooltip_whatsoever (_slider);
454 ProcessorEntry::Control::set_tooltip ()
456 boost::shared_ptr<AutomationControl> c = _control.lock ();
465 s << (c->get_value() > 0.5 ? _("on") : _("off"));
467 s << setprecision(2) << fixed;
468 s << c->internal_to_user (c->get_value ());
471 string sm = Glib::Markup::escape_text (s.str());
473 ARDOUR_UI::instance()->set_tip (_label, sm);
474 _slider_persistant_tooltip.set_tip (sm);
475 ARDOUR_UI::instance()->set_tip (_button, sm);
479 ProcessorEntry::Control::slider_adjusted ()
481 if (_ignore_ui_adjustment) {
485 boost::shared_ptr<AutomationControl> c = _control.lock ();
491 c->set_value (c->interface_to_internal (_adjustment.get_value ()));
496 ProcessorEntry::Control::button_clicked ()
498 boost::shared_ptr<AutomationControl> c = _control.lock ();
504 bool const n = _button.get_active ();
506 c->set_value (n ? 0 : 1);
507 _button.set_active (!n);
511 ProcessorEntry::Control::control_changed ()
513 boost::shared_ptr<AutomationControl> c = _control.lock ();
518 _ignore_ui_adjustment = true;
522 _button.set_active (c->get_value() > 0.5);
526 _adjustment.set_value (c->internal_to_interface (c->get_value ()));
530 s.setf (ios::fixed, ios::floatfield);
531 s << c->internal_to_user (c->get_value ());
534 _ignore_ui_adjustment = false;
538 ProcessorEntry::Control::add_state (XMLNode* node) const
540 XMLNode* c = new XMLNode (X_("Object"));
541 c->add_property (X_("id"), state_id ());
542 c->add_property (X_("visible"), _visible);
543 node->add_child_nocopy (*c);
547 ProcessorEntry::Control::set_state (XMLNode const * node)
549 XMLNode* n = GUIObjectState::get_node (node, state_id ());
551 XMLProperty* p = n->property (X_("visible"));
552 set_visible (p && string_is_affirmative (p->value ()));
559 ProcessorEntry::Control::set_visible (bool v)
570 /** Called when the Editor might have re-shown things that
574 ProcessorEntry::Control::hide_things ()
582 ProcessorEntry::Control::hide_label ()
588 ProcessorEntry::Control::state_id () const
590 boost::shared_ptr<AutomationControl> c = _control.lock ();
593 return string_compose (X_("control %1"), c->id().to_s ());
596 BlankProcessorEntry::BlankProcessorEntry (ProcessorBox* b, Width w)
597 : ProcessorEntry (b, boost::shared_ptr<Processor>(), w)
601 PluginInsertProcessorEntry::PluginInsertProcessorEntry (ProcessorBox* b, boost::shared_ptr<ARDOUR::PluginInsert> p, Width w)
602 : ProcessorEntry (b, p, w)
605 p->SplittingChanged.connect (
606 _splitting_connection, invalidator (*this), boost::bind (&PluginInsertProcessorEntry::plugin_insert_splitting_changed, this), gui_context()
609 _splitting_icon.set_size_request (-1, 12);
611 _vbox.pack_start (_splitting_icon);
612 _vbox.reorder_child (_splitting_icon, 0);
614 plugin_insert_splitting_changed ();
618 PluginInsertProcessorEntry::plugin_insert_splitting_changed ()
620 if (_plugin_insert->splitting ()) {
621 _splitting_icon.set_branches(_plugin_insert->output_streams().n_audio());
622 _splitting_icon.show ();
624 _splitting_icon.hide ();
629 PluginInsertProcessorEntry::hide_things ()
631 ProcessorEntry::hide_things ();
632 plugin_insert_splitting_changed ();
636 PluginInsertProcessorEntry::setup_visuals ()
640 _splitting_icon.set_name ("ProcessorPreFader");
644 _splitting_icon.set_name ("ProcessorFader");
648 _splitting_icon.set_name ("ProcessorPostFader");
652 ProcessorEntry::setup_visuals ();
656 PluginInsertProcessorEntry::SplittingIcon::on_expose_event (GdkEventExpose* ev)
658 cairo_t* cr = gdk_cairo_create (get_window()->gobj());
660 cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
663 cairo_set_line_width (cr, 1.5);
664 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
666 Gtk::Allocation a = get_allocation();
667 double const width = a.get_width();
668 double const height = a.get_height();
670 Gdk::Color const bg = get_style()->get_bg (STATE_NORMAL);
671 cairo_set_source_rgb (cr, bg.get_red_p (), bg.get_green_p (), bg.get_blue_p ());
673 cairo_rectangle (cr, 0, 0, width, height);
676 Gdk::Color const fg = get_style()->get_fg (STATE_NORMAL);
677 cairo_set_source_rgb (cr, fg.get_red_p (), fg.get_green_p (), fg.get_blue_p ());
679 const float si_l = rintf(width * 0.2) + .5f;
680 const float si_c = rintf(width * 0.5) + .5f;
681 const float si_r = rintf(width * 0.8) + .5f;
682 const float si_m = rintf(height * 0.5) + .5f;
684 cairo_move_to (cr, si_l, height);
685 cairo_line_to (cr, si_l, si_m);
686 cairo_line_to (cr, si_r, si_m);
687 cairo_line_to (cr, si_r, height);
690 cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
692 for (uint32_t i = 2; i < _branches; ++i) {
693 const float si_b = rintf(width * (.2f + .6f * (i - 1.f) / (_branches - 1.f))) + .5f;
694 cairo_move_to (cr, si_b, height);
695 cairo_line_to (cr, si_b, si_m);
699 cairo_move_to (cr, si_c, si_m);
700 cairo_line_to (cr, si_c, 0);
706 ProcessorBox::ProcessorBox (ARDOUR::Session* sess, boost::function<PluginSelector*()> get_plugin_selector,
707 RouteProcessorSelection& rsel, MixerStrip* parent, bool owner_is_mixer)
708 : _parent_strip (parent)
709 , _owner_is_mixer (owner_is_mixer)
710 , ab_direction (true)
711 , _get_plugin_selector (get_plugin_selector)
713 , _visible_prefader_processors (0)
714 , _rr_selection(rsel)
715 , _redisplay_pending (false)
722 no_processor_redisplay = false;
724 processor_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
725 processor_scroller.add (processor_display);
726 pack_start (processor_scroller, true, true);
728 processor_display.set_flags (CAN_FOCUS);
729 processor_display.set_name ("ProcessorList");
730 processor_display.set_data ("processorbox", this);
731 processor_display.set_size_request (48, -1);
732 processor_display.set_spacing (2);
734 processor_display.signal_enter_notify_event().connect (sigc::mem_fun(*this, &ProcessorBox::enter_notify), false);
735 processor_display.signal_leave_notify_event().connect (sigc::mem_fun(*this, &ProcessorBox::leave_notify), false);
737 processor_display.ButtonPress.connect (sigc::mem_fun (*this, &ProcessorBox::processor_button_press_event));
738 processor_display.ButtonRelease.connect (sigc::mem_fun (*this, &ProcessorBox::processor_button_release_event));
740 processor_display.Reordered.connect (sigc::mem_fun (*this, &ProcessorBox::reordered));
741 processor_display.DropFromAnotherBox.connect (sigc::mem_fun (*this, &ProcessorBox::object_drop));
743 processor_scroller.show ();
744 processor_display.show ();
747 parent->DeliveryChanged.connect (
748 _mixer_strip_connections, invalidator (*this), boost::bind (&ProcessorBox::mixer_strip_delivery_changed, this, _1), gui_context ()
752 ARDOUR_UI::instance()->set_tip (processor_display, _("Right-click to add/remove/edit\nplugins,inserts,sends and more"));
755 ProcessorBox::~ProcessorBox ()
757 /* it may appear as if we should delete processor_menu but that is a
758 * pointer to a widget owned by the UI Manager, and has potentially
759 * be returned to many other ProcessorBoxes. GTK doesn't really make
760 * clear the ownership of this widget, which is a menu and thus is
761 * never packed into any container other than an implict GtkWindow.
763 * For now, until or if we ever get clarification over the ownership
764 * story just let it continue to exist. At worst, its a small memory leak.
769 ProcessorBox::set_route (boost::shared_ptr<Route> r)
775 _route_connections.drop_connections();
777 /* new route: any existing block on processor redisplay must be meaningless */
778 no_processor_redisplay = false;
781 _route->processors_changed.connect (
782 _route_connections, invalidator (*this), boost::bind (&ProcessorBox::route_processors_changed, this, _1), gui_context()
785 _route->DropReferences.connect (
786 _route_connections, invalidator (*this), boost::bind (&ProcessorBox::route_going_away, this), gui_context()
789 _route->PropertyChanged.connect (
790 _route_connections, invalidator (*this), boost::bind (&ProcessorBox::route_property_changed, this, _1), gui_context()
793 redisplay_processors ();
797 ProcessorBox::route_going_away ()
799 /* don't keep updating display as processors are deleted */
800 no_processor_redisplay = true;
805 ProcessorBox::object_drop(DnDVBox<ProcessorEntry>* source, ProcessorEntry* position, Glib::RefPtr<Gdk::DragContext> const & context)
807 boost::shared_ptr<Processor> p;
809 p = position->processor ();
811 /* dropped on the blank entry (which will be before the
812 fader), so use the first non-blank child as our
813 `dropped on' processor */
814 list<ProcessorEntry*> c = processor_display.children ();
815 list<ProcessorEntry*>::iterator i = c.begin ();
816 while (dynamic_cast<BlankProcessorEntry*> (*i)) {
817 assert (i != c.end ());
821 assert (i != c.end ());
822 p = (*i)->processor ();
827 list<ProcessorEntry*> children = source->selection ();
828 list<boost::shared_ptr<Processor> > procs;
829 for (list<ProcessorEntry*>::const_iterator i = children.begin(); i != children.end(); ++i) {
830 if ((*i)->processor ()) {
831 procs.push_back ((*i)->processor ());
835 for (list<boost::shared_ptr<Processor> >::const_iterator i = procs.begin(); i != procs.end(); ++i) {
836 XMLNode& state = (*i)->get_state ();
838 nlist.push_back (&state);
839 paste_processor_state (nlist, p);
843 /* since the dndvbox doesn't take care of this properly, we have to delete the originals
847 if ((context->get_suggested_action() == Gdk::ACTION_MOVE) && source) {
848 ProcessorBox* other = reinterpret_cast<ProcessorBox*> (source->get_data ("processorbox"));
850 other->delete_dragged_processors (procs);
856 ProcessorBox::set_width (Width w)
864 list<ProcessorEntry*> children = processor_display.children ();
865 for (list<ProcessorEntry*>::iterator i = children.begin(); i != children.end(); ++i) {
866 (*i)->set_enum_width (w);
873 ProcessorBox::build_possible_aux_menu ()
875 boost::shared_ptr<RouteList> rl = _session->get_routes_with_internal_returns();
878 /* No aux sends if there are no busses */
882 using namespace Menu_Helpers;
883 Menu* menu = manage (new Menu);
884 MenuList& items = menu->items();
886 for (RouteList::iterator r = rl->begin(); r != rl->end(); ++r) {
887 if (!_route->internal_send_for (*r) && *r != _route) {
888 items.push_back (MenuElem ((*r)->name(), sigc::bind (sigc::ptr_fun (ProcessorBox::rb_choose_aux), boost::weak_ptr<Route>(*r))));
896 ProcessorBox::show_processor_menu (int arg)
898 if (processor_menu == 0) {
899 processor_menu = build_processor_menu ();
900 processor_menu->signal_unmap().connect (sigc::mem_fun (*this, &ProcessorBox::processor_menu_unmapped));
903 /* Sort out the plugin submenu */
905 Gtk::MenuItem* plugin_menu_item = dynamic_cast<Gtk::MenuItem*>(ActionManager::get_widget("/ProcessorMenu/newplugin"));
907 if (plugin_menu_item) {
908 plugin_menu_item->set_submenu (*_get_plugin_selector()->plugin_menu());
911 /* And the aux submenu */
913 Gtk::MenuItem* aux_menu_item = dynamic_cast<Gtk::MenuItem*>(ActionManager::get_widget("/ProcessorMenu/newaux"));
916 Menu* m = build_possible_aux_menu();
917 if (m && !m->items().empty()) {
918 aux_menu_item->set_submenu (*m);
919 aux_menu_item->set_sensitive (true);
921 /* stupid gtkmm: we need to pass a null reference here */
922 gtk_menu_item_set_submenu (aux_menu_item->gobj(), 0);
923 aux_menu_item->set_sensitive (false);
927 ProcessorEntry* single_selection = 0;
928 if (processor_display.selection().size() == 1) {
929 single_selection = processor_display.selection().front();
932 /* And the controls submenu */
934 Gtk::MenuItem* controls_menu_item = dynamic_cast<Gtk::MenuItem*>(ActionManager::get_widget("/ProcessorMenu/controls"));
936 if (controls_menu_item) {
937 if (single_selection) {
938 Menu* m = single_selection->build_controls_menu ();
939 if (m && !m->items().empty()) {
940 controls_menu_item->set_submenu (*m);
941 controls_menu_item->set_sensitive (true);
943 gtk_menu_item_set_submenu (controls_menu_item->gobj(), 0);
944 controls_menu_item->set_sensitive (false);
949 /* Sensitise actions as approprioate */
951 cut_action->set_sensitive (can_cut());
952 paste_action->set_sensitive (!_rr_selection.processors.empty());
954 const bool sensitive = !processor_display.selection().empty();
955 ActionManager::set_sensitive (ActionManager::plugin_selection_sensitive_actions, sensitive);
956 edit_action->set_sensitive (one_processor_can_be_edited ());
957 edit_generic_action->set_sensitive (one_processor_can_be_edited ());
959 boost::shared_ptr<PluginInsert> pi;
960 if (single_selection) {
961 pi = boost::dynamic_pointer_cast<PluginInsert> (single_selection->processor ());
964 /* allow editing with an Ardour-generated UI for plugin inserts with editors */
965 edit_action->set_sensitive (pi && pi->plugin()->has_editor ());
967 /* disallow rename for multiple selections, for plugin inserts and for the fader */
968 rename_action->set_sensitive (single_selection && !pi && !boost::dynamic_pointer_cast<Amp> (single_selection->processor ()));
970 processor_menu->popup (1, arg);
972 /* Add a placeholder gap to the processor list to indicate where a processor would be
973 inserted were one chosen from the menu.
976 processor_display.get_pointer (x, y);
977 _placement = processor_display.add_placeholder (y);
979 if (_visible_prefader_processors == 0 && _placement > 0) {
985 ProcessorBox::enter_notify (GdkEventCrossing*)
987 _current_processor_box = this;
992 ProcessorBox::leave_notify (GdkEventCrossing*)
998 ProcessorBox::processor_operation (ProcessorOperation op)
1000 ProcSelection targets;
1002 get_selected_processors (targets);
1004 if (targets.empty()) {
1007 processor_display.get_pointer (x, y);
1009 pair<ProcessorEntry *, double> const pointer = processor_display.get_child_at_position (y);
1011 if (pointer.first && pointer.first->processor()) {
1012 targets.push_back (pointer.first->processor ());
1017 case ProcessorsSelectAll:
1018 processor_display.select_all ();
1021 case ProcessorsCopy:
1022 copy_processors (targets);
1026 cut_processors (targets);
1029 case ProcessorsPaste:
1030 if (targets.empty()) {
1031 paste_processors ();
1033 paste_processors (targets.front());
1037 case ProcessorsDelete:
1038 delete_processors (targets);
1041 case ProcessorsToggleActive:
1042 for (ProcSelection::iterator i = targets.begin(); i != targets.end(); ++i) {
1043 if ((*i)->active()) {
1044 (*i)->deactivate ();
1060 ProcessorWindowProxy*
1061 ProcessorBox::find_window_proxy (boost::shared_ptr<Processor> processor) const
1063 for (list<ProcessorWindowProxy*>::const_iterator i = _processor_window_info.begin(); i != _processor_window_info.end(); ++i) {
1064 boost::shared_ptr<Processor> p = (*i)->processor().lock();
1066 if (p && p == processor) {
1077 ProcessorBox::processor_button_press_event (GdkEventButton *ev, ProcessorEntry* child)
1079 boost::shared_ptr<Processor> processor;
1081 processor = child->processor ();
1085 bool selected = processor_display.selected (child);
1087 if (processor && (Keyboard::is_edit_event (ev) || (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS))) {
1089 if (_session->engine().connected()) {
1090 /* XXX giving an error message here is hard, because we may be in the midst of a button press */
1092 if (!one_processor_can_be_edited ()) return true;
1094 if (Keyboard::modifier_state_equals (ev->state, Keyboard::SecondaryModifier)) {
1095 generic_edit_processor (processor);
1097 edit_processor (processor);
1103 } else if (processor && ev->button == 1 && selected) {
1105 // this is purely informational but necessary for route params UI
1106 ProcessorSelected (processor); // emit
1108 } else if (!processor && ev->button == 1 && ev->type == GDK_2BUTTON_PRESS) {
1111 _get_plugin_selector()->show_manager ();
1118 ProcessorBox::processor_button_release_event (GdkEventButton *ev, ProcessorEntry* child)
1120 boost::shared_ptr<Processor> processor;
1122 processor = child->processor ();
1125 if (processor && Keyboard::is_delete_event (ev)) {
1127 Glib::signal_idle().connect (sigc::bind (
1128 sigc::mem_fun(*this, &ProcessorBox::idle_delete_processor),
1129 boost::weak_ptr<Processor>(processor)));
1131 } else if (Keyboard::is_context_menu_event (ev)) {
1133 show_processor_menu (ev->time);
1135 } else if (processor && Keyboard::is_button2_event (ev)
1137 && (Keyboard::no_modifier_keys_pressed (ev) && ((ev->state & Gdk::BUTTON2_MASK) == Gdk::BUTTON2_MASK))
1141 /* button2-click with no/appropriate modifiers */
1143 if (processor->active()) {
1144 processor->deactivate ();
1146 processor->activate ();
1154 ProcessorBox::build_processor_menu ()
1156 processor_menu = dynamic_cast<Gtk::Menu*>(ActionManager::get_widget("/ProcessorMenu") );
1157 processor_menu->set_name ("ArdourContextMenu");
1158 return processor_menu;
1162 ProcessorBox::select_all_processors ()
1164 processor_display.select_all ();
1168 ProcessorBox::deselect_all_processors ()
1170 processor_display.select_none ();
1174 ProcessorBox::choose_plugin ()
1176 _get_plugin_selector()->set_interested_object (*this);
1179 /** @return true if an error occurred, otherwise false */
1181 ProcessorBox::use_plugins (const SelectedPlugins& plugins)
1183 for (SelectedPlugins::const_iterator p = plugins.begin(); p != plugins.end(); ++p) {
1185 boost::shared_ptr<Processor> processor (new PluginInsert (*_session, *p));
1187 Route::ProcessorStreams err_streams;
1189 if (_route->add_processor_by_index (processor, _placement, &err_streams, Config->get_new_plugins_active ())) {
1190 weird_plugin_dialog (**p, err_streams);
1192 // XXX SHAREDPTR delete plugin here .. do we even need to care?
1195 if (Profile->get_sae()) {
1196 processor->activate ();
1205 ProcessorBox::weird_plugin_dialog (Plugin& p, Route::ProcessorStreams streams)
1207 ArdourDialog dialog (_("Plugin Incompatibility"));
1210 string text = string_compose(_("You attempted to add the plugin \"%1\" in slot %2.\n"),
1211 p.name(), streams.index);
1213 bool has_midi = streams.count.n_midi() > 0 || p.get_info()->n_inputs.n_midi() > 0;
1214 bool has_audio = streams.count.n_audio() > 0 || p.get_info()->n_inputs.n_audio() > 0;
1216 text += _("\nThis plugin has:\n");
1218 uint32_t const n = p.get_info()->n_inputs.n_midi ();
1219 text += string_compose (ngettext ("\t%1 MIDI input\n", "\t%1 MIDI inputs\n", n), n);
1222 uint32_t const n = p.get_info()->n_inputs.n_audio ();
1223 text += string_compose (ngettext ("\t%1 audio input\n", "\t%1 audio inputs\n", n), n);
1226 text += _("\nbut at the insertion point, there are:\n");
1228 uint32_t const n = streams.count.n_midi ();
1229 text += string_compose (ngettext ("\t%1 MIDI channel\n", "\t%1 MIDI channels\n", n), n);
1232 uint32_t const n = streams.count.n_audio ();
1233 text += string_compose (ngettext ("\t%1 audio channel\n", "\t%1 audio channels\n", n), n);
1236 text += string_compose (_("\n%1 is unable to insert this plugin here.\n"), PROGRAM_NAME);
1237 label.set_text(text);
1239 dialog.get_vbox()->pack_start (label);
1240 dialog.add_button (Stock::OK, RESPONSE_ACCEPT);
1242 dialog.set_name (X_("PluginIODialog"));
1243 dialog.set_modal (true);
1250 ProcessorBox::choose_insert ()
1252 boost::shared_ptr<Processor> processor (new PortInsert (*_session, _route->pannable(), _route->mute_master()));
1253 _route->add_processor_by_index (processor, _placement);
1256 /* Caller must not hold process lock */
1258 ProcessorBox::choose_send ()
1260 boost::shared_ptr<Send> send (new Send (*_session, _route->pannable(), _route->mute_master()));
1262 /* make an educated guess at the initial number of outputs for the send */
1263 ChanCount outs = (_session->master_out())
1264 ? _session->master_out()->n_outputs()
1265 : _route->n_outputs();
1267 /* XXX need processor lock on route */
1269 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock());
1270 send->output()->ensure_io (outs, false, this);
1271 } catch (AudioEngine::PortRegistrationFailure& err) {
1272 error << string_compose (_("Cannot set up new send: %1"), err.what()) << endmsg;
1276 /* let the user adjust the IO setup before creation.
1278 Note: this dialog is NOT modal - we just leave it to run and it will
1279 return when its Finished signal is emitted - typically when the window
1283 IOSelectorWindow *ios = new IOSelectorWindow (_session, send->output(), true);
1286 /* keep a reference to the send so it doesn't get deleted while
1287 the IOSelectorWindow is doing its stuff
1289 _processor_being_created = send;
1291 ios->selector().Finished.connect (sigc::bind (
1292 sigc::mem_fun(*this, &ProcessorBox::send_io_finished),
1293 boost::weak_ptr<Processor>(send), ios));
1298 ProcessorBox::send_io_finished (IOSelector::Result r, boost::weak_ptr<Processor> weak_processor, IOSelectorWindow* ios)
1300 boost::shared_ptr<Processor> processor (weak_processor.lock());
1302 /* drop our temporary reference to the new send */
1303 _processor_being_created.reset ();
1310 case IOSelector::Cancelled:
1311 // processor will go away when all shared_ptrs to it vanish
1314 case IOSelector::Accepted:
1315 _route->add_processor_by_index (processor, _placement);
1316 if (Profile->get_sae()) {
1317 processor->activate ();
1322 delete_when_idle (ios);
1326 ProcessorBox::return_io_finished (IOSelector::Result r, boost::weak_ptr<Processor> weak_processor, IOSelectorWindow* ios)
1328 boost::shared_ptr<Processor> processor (weak_processor.lock());
1330 /* drop our temporary reference to the new return */
1331 _processor_being_created.reset ();
1338 case IOSelector::Cancelled:
1339 // processor will go away when all shared_ptrs to it vanish
1342 case IOSelector::Accepted:
1343 _route->add_processor_by_index (processor, _placement);
1344 if (Profile->get_sae()) {
1345 processor->activate ();
1350 delete_when_idle (ios);
1354 ProcessorBox::choose_aux (boost::weak_ptr<Route> wr)
1360 boost::shared_ptr<Route> target = wr.lock();
1366 _session->add_internal_send (target, _placement, _route);
1370 ProcessorBox::route_processors_changed (RouteProcessorChange c)
1372 if (c.type == RouteProcessorChange::MeterPointChange && c.meter_visibly_changed == false) {
1373 /* the meter has moved, but it was and still is invisible to the user, so nothing to do */
1377 redisplay_processors ();
1381 ProcessorBox::redisplay_processors ()
1383 ENSURE_GUI_THREAD (*this, &ProcessorBox::redisplay_processors);
1386 if (no_processor_redisplay) {
1390 processor_display.clear ();
1392 _visible_prefader_processors = 0;
1395 _route->foreach_processor (sigc::bind (sigc::mem_fun (*this, &ProcessorBox::help_count_visible_prefader_processors),
1396 &_visible_prefader_processors, &fader_seen));
1398 if (_visible_prefader_processors == 0) { // fader only
1399 BlankProcessorEntry* bpe = new BlankProcessorEntry (this, _width);
1400 processor_display.add_child (bpe);
1403 _route->foreach_processor (sigc::mem_fun (*this, &ProcessorBox::add_processor_to_display));
1405 for (ProcessorWindowProxies::iterator i = _processor_window_info.begin(); i != _processor_window_info.end(); ++i) {
1406 (*i)->marked = false;
1409 _route->foreach_processor (sigc::mem_fun (*this, &ProcessorBox::maybe_add_processor_to_ui_list));
1411 /* trim dead wood from the processor window proxy list */
1413 ProcessorWindowProxies::iterator i = _processor_window_info.begin();
1414 while (i != _processor_window_info.end()) {
1415 ProcessorWindowProxies::iterator j = i;
1418 if (!(*i)->valid()) {
1420 WM::Manager::instance().remove (*i);
1422 _processor_window_info.erase (i);
1424 } else if (!(*i)->marked) {
1426 /* this processor is no longer part of this processor
1429 * that could be because it was deleted or it could be
1430 * because the route being displayed in the parent
1433 * The latter only happens with the editor mixer strip.
1436 if (is_editor_mixer_strip()) {
1438 /* editor mixer strip .. DO NOTHING
1440 * note: the processor window stays visible if
1441 * it is already visible
1445 WM::Manager::instance().remove (*i);
1447 _processor_window_info.erase (i);
1454 setup_entry_positions ();
1457 /** Add a ProcessorWindowProxy for a processor to our list, if that processor does
1458 * not already have one.
1461 ProcessorBox::maybe_add_processor_to_ui_list (boost::weak_ptr<Processor> w)
1463 boost::shared_ptr<Processor> p = w.lock ();
1468 ProcessorWindowProxies::iterator i = _processor_window_info.begin ();
1469 while (i != _processor_window_info.end()) {
1471 boost::shared_ptr<Processor> t = (*i)->processor().lock ();
1474 /* this processor is already on the list; done */
1475 (*i)->marked = true;
1482 /* not on the list; add it */
1485 if (_parent_strip) {
1486 if (_parent_strip->mixer_owned()) {
1495 ProcessorWindowProxy* wp = new ProcessorWindowProxy (
1496 string_compose ("%1-%2-%3", loc, _route->id(), p->id()),
1500 const XMLNode* ui_xml = _session->extra_xml (X_("UI"));
1503 wp->set_state (*ui_xml);
1508 /* if the processor already has an existing UI,
1509 note that so that we don't recreate it
1512 void* existing_ui = p->get_ui ();
1515 wp->use_window (*(reinterpret_cast<Gtk::Window*>(existing_ui)));
1518 _processor_window_info.push_back (wp);
1519 WM::Manager::instance().register_window (wp);
1523 ProcessorBox::help_count_visible_prefader_processors (boost::weak_ptr<Processor> p, uint32_t* cnt, bool* amp_seen)
1525 boost::shared_ptr<Processor> processor (p.lock ());
1527 if (processor && processor->display_to_user()) {
1529 if (boost::dynamic_pointer_cast<Amp>(processor)) {
1540 ProcessorBox::add_processor_to_display (boost::weak_ptr<Processor> p)
1542 boost::shared_ptr<Processor> processor (p.lock ());
1544 if (!processor || !processor->display_to_user()) {
1548 boost::shared_ptr<PluginInsert> plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (processor);
1549 ProcessorEntry* e = 0;
1550 if (plugin_insert) {
1551 e = new PluginInsertProcessorEntry (this, plugin_insert, _width);
1553 e = new ProcessorEntry (this, processor, _width);
1556 /* Set up this entry's state from the GUIObjectState */
1557 XMLNode* proc = entry_gui_object_state (e);
1559 e->set_control_state (proc);
1562 if (boost::dynamic_pointer_cast<Send> (processor)) {
1563 /* Always show send controls */
1564 e->show_all_controls ();
1567 processor_display.add_child (e);
1571 ProcessorBox::reordered ()
1573 compute_processor_sort_keys ();
1574 setup_entry_positions ();
1578 ProcessorBox::setup_entry_positions ()
1580 list<ProcessorEntry*> children = processor_display.children ();
1581 bool pre_fader = true;
1583 for (list<ProcessorEntry*>::iterator i = children.begin(); i != children.end(); ++i) {
1584 if (boost::dynamic_pointer_cast<Amp>((*i)->processor())) {
1586 (*i)->set_position (ProcessorEntry::Fader);
1589 (*i)->set_position (ProcessorEntry::PreFader);
1591 (*i)->set_position (ProcessorEntry::PostFader);
1598 ProcessorBox::compute_processor_sort_keys ()
1600 list<ProcessorEntry*> children = processor_display.children ();
1601 Route::ProcessorList our_processors;
1603 for (list<ProcessorEntry*>::iterator i = children.begin(); i != children.end(); ++i) {
1604 if ((*i)->processor()) {
1605 our_processors.push_back ((*i)->processor ());
1609 if (_route->reorder_processors (our_processors)) {
1610 /* Reorder failed, so report this to the user. As far as I can see this must be done
1611 in an idle handler: it seems that the redisplay_processors() that happens below destroys
1612 widgets that were involved in the drag-and-drop on the processor list, which causes problems
1613 when the drag is torn down after this handler function is finished.
1615 Glib::signal_idle().connect_once (sigc::mem_fun (*this, &ProcessorBox::report_failed_reorder));
1620 ProcessorBox::report_failed_reorder ()
1622 /* reorder failed, so redisplay */
1624 redisplay_processors ();
1626 /* now tell them about the problem */
1628 ArdourDialog dialog (_("Plugin Incompatibility"));
1631 label.set_text (_("\
1632 You cannot reorder these plugins/sends/inserts\n\
1633 in that way because the inputs and\n\
1634 outputs will not work correctly."));
1636 dialog.get_vbox()->set_border_width (12);
1637 dialog.get_vbox()->pack_start (label);
1638 dialog.add_button (Stock::OK, RESPONSE_ACCEPT);
1640 dialog.set_name (X_("PluginIODialog"));
1641 dialog.set_modal (true);
1648 ProcessorBox::rename_processors ()
1650 ProcSelection to_be_renamed;
1652 get_selected_processors (to_be_renamed);
1654 if (to_be_renamed.empty()) {
1658 for (ProcSelection::iterator i = to_be_renamed.begin(); i != to_be_renamed.end(); ++i) {
1659 rename_processor (*i);
1664 ProcessorBox::can_cut () const
1666 vector<boost::shared_ptr<Processor> > sel;
1668 get_selected_processors (sel);
1670 /* cut_processors () does not cut inserts */
1672 for (vector<boost::shared_ptr<Processor> >::const_iterator i = sel.begin (); i != sel.end (); ++i) {
1674 if (boost::dynamic_pointer_cast<PluginInsert>((*i)) != 0 ||
1675 (boost::dynamic_pointer_cast<Send>((*i)) != 0) ||
1676 (boost::dynamic_pointer_cast<Return>((*i)) != 0)) {
1685 ProcessorBox::cut_processors (const ProcSelection& to_be_removed)
1687 if (to_be_removed.empty()) {
1691 XMLNode* node = new XMLNode (X_("cut"));
1692 Route::ProcessorList to_cut;
1694 no_processor_redisplay = true;
1695 for (ProcSelection::const_iterator i = to_be_removed.begin(); i != to_be_removed.end(); ++i) {
1696 // Cut only plugins, sends and returns
1697 if (boost::dynamic_pointer_cast<PluginInsert>((*i)) != 0 ||
1698 (boost::dynamic_pointer_cast<Send>((*i)) != 0) ||
1699 (boost::dynamic_pointer_cast<Return>((*i)) != 0)) {
1701 Window* w = get_processor_ui (*i);
1707 XMLNode& child ((*i)->get_state());
1708 node->add_child_nocopy (child);
1709 to_cut.push_back (*i);
1713 if (_route->remove_processors (to_cut) != 0) {
1715 no_processor_redisplay = false;
1719 _rr_selection.set (node);
1721 no_processor_redisplay = false;
1722 redisplay_processors ();
1726 ProcessorBox::copy_processors (const ProcSelection& to_be_copied)
1728 if (to_be_copied.empty()) {
1732 XMLNode* node = new XMLNode (X_("copy"));
1734 for (ProcSelection::const_iterator i = to_be_copied.begin(); i != to_be_copied.end(); ++i) {
1735 // Copy only plugins, sends, returns
1736 if (boost::dynamic_pointer_cast<PluginInsert>((*i)) != 0 ||
1737 (boost::dynamic_pointer_cast<Send>((*i)) != 0) ||
1738 (boost::dynamic_pointer_cast<Return>((*i)) != 0)) {
1739 node->add_child_nocopy ((*i)->get_state());
1743 _rr_selection.set (node);
1747 ProcessorBox::delete_processors (const ProcSelection& targets)
1749 if (targets.empty()) {
1753 no_processor_redisplay = true;
1755 for (ProcSelection::const_iterator i = targets.begin(); i != targets.end(); ++i) {
1757 Window* w = get_processor_ui (*i);
1763 _route->remove_processor(*i);
1766 no_processor_redisplay = false;
1767 redisplay_processors ();
1771 ProcessorBox::delete_dragged_processors (const list<boost::shared_ptr<Processor> >& procs)
1773 list<boost::shared_ptr<Processor> >::const_iterator x;
1775 no_processor_redisplay = true;
1776 for (x = procs.begin(); x != procs.end(); ++x) {
1778 Window* w = get_processor_ui (*x);
1784 _route->remove_processor(*x);
1787 no_processor_redisplay = false;
1788 redisplay_processors ();
1792 ProcessorBox::idle_delete_processor (boost::weak_ptr<Processor> weak_processor)
1794 boost::shared_ptr<Processor> processor (weak_processor.lock());
1800 /* NOT copied to _mixer.selection() */
1802 no_processor_redisplay = true;
1803 _route->remove_processor (processor);
1804 no_processor_redisplay = false;
1805 redisplay_processors ();
1811 ProcessorBox::rename_processor (boost::shared_ptr<Processor> processor)
1813 ArdourPrompter name_prompter (true);
1815 name_prompter.set_title (_("Rename Processor"));
1816 name_prompter.set_prompt (_("New name:"));
1817 name_prompter.set_initial_text (processor->name());
1818 name_prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
1819 name_prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
1820 name_prompter.show_all ();
1822 switch (name_prompter.run ()) {
1824 case Gtk::RESPONSE_ACCEPT:
1825 name_prompter.get_result (result);
1826 if (result.length()) {
1829 string test = result;
1831 while (tries < 100) {
1832 if (_session->io_name_is_legal (test)) {
1838 test = string_compose ("%1-%2", result, tries);
1842 processor->set_name (result);
1845 ARDOUR_UI::instance()->popup_error
1846 (string_compose (_("At least 100 IO objects exist with a name like %1 - name not changed"), result));
1856 ProcessorBox::paste_processors ()
1858 if (_rr_selection.processors.empty()) {
1862 paste_processor_state (_rr_selection.processors.get_node().children(), boost::shared_ptr<Processor>());
1866 ProcessorBox::paste_processors (boost::shared_ptr<Processor> before)
1869 if (_rr_selection.processors.empty()) {
1873 paste_processor_state (_rr_selection.processors.get_node().children(), before);
1877 ProcessorBox::paste_processor_state (const XMLNodeList& nlist, boost::shared_ptr<Processor> p)
1879 XMLNodeConstIterator niter;
1880 list<boost::shared_ptr<Processor> > copies;
1882 if (nlist.empty()) {
1886 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1888 XMLProperty const * type = (*niter)->property ("type");
1889 XMLProperty const * role = (*niter)->property ("role");
1892 boost::shared_ptr<Processor> p;
1894 if (type->value() == "meter" ||
1895 type->value() == "main-outs" ||
1896 type->value() == "amp" ||
1897 type->value() == "intreturn") {
1898 /* do not paste meter, main outs, amp or internal returns */
1901 } else if (type->value() == "intsend") {
1903 /* aux sends are OK, but those used for
1904 * other purposes, are not.
1909 if (role->value() != "Aux") {
1913 XMLNode n (**niter);
1914 InternalSend* s = new InternalSend (*_session, _route->pannable(), _route->mute_master(),
1915 boost::shared_ptr<Route>(), Delivery::Aux);
1917 IOProcessor::prepare_for_reset (n, s->name());
1919 if (s->set_state (n, Stateful::loading_state_version)) {
1926 } else if (type->value() == "send") {
1928 XMLNode n (**niter);
1929 Send* s = new Send (*_session, _route->pannable(), _route->mute_master());
1931 IOProcessor::prepare_for_reset (n, s->name());
1933 if (s->set_state (n, Stateful::loading_state_version)) {
1940 } else if (type->value() == "return") {
1942 XMLNode n (**niter);
1943 Return* r = new Return (*_session);
1945 IOProcessor::prepare_for_reset (n, r->name());
1947 if (r->set_state (n, Stateful::loading_state_version)) {
1954 } else if (type->value() == "port") {
1956 XMLNode n (**niter);
1957 PortInsert* pi = new PortInsert (*_session, _route->pannable (), _route->mute_master ());
1959 IOProcessor::prepare_for_reset (n, pi->name());
1961 if (pi->set_state (n, Stateful::loading_state_version)) {
1968 /* XXX its a bit limiting to assume that everything else
1972 p.reset (new PluginInsert (*_session));
1973 p->set_state (**niter, Stateful::current_state_version);
1976 copies.push_back (p);
1980 error << _("plugin insert constructor failed") << endmsg;
1984 if (copies.empty()) {
1988 if (_route->add_processors (copies, p)) {
1991 "Copying the set of processors on the clipboard failed,\n\
1992 probably because the I/O configuration of the plugins\n\
1993 could not match the configuration of this track.");
1994 MessageDialog am (msg);
2000 ProcessorBox::get_selected_processors (ProcSelection& processors) const
2002 const list<ProcessorEntry*> selection = processor_display.selection ();
2003 for (list<ProcessorEntry*>::const_iterator i = selection.begin(); i != selection.end(); ++i) {
2004 processors.push_back ((*i)->processor ());
2009 ProcessorBox::for_selected_processors (void (ProcessorBox::*method)(boost::shared_ptr<Processor>))
2011 list<ProcessorEntry*> selection = processor_display.selection ();
2012 for (list<ProcessorEntry*>::iterator i = selection.begin(); i != selection.end(); ++i) {
2013 (this->*method) ((*i)->processor ());
2018 ProcessorBox::all_visible_processors_active (bool state)
2020 _route->all_visible_processors_active (state);
2024 ProcessorBox::ab_plugins ()
2026 _route->ab_plugins (ab_direction);
2027 ab_direction = !ab_direction;
2032 ProcessorBox::clear_processors ()
2035 vector<string> choices;
2037 prompt = string_compose (_("Do you really want to remove all processors from %1?\n"
2038 "(this cannot be undone)"), _route->name());
2040 choices.push_back (_("Cancel"));
2041 choices.push_back (_("Yes, remove them all"));
2043 Gtkmm2ext::Choice prompter (_("Remove processors"), prompt, choices);
2045 if (prompter.run () == 1) {
2046 _route->clear_processors (PreFader);
2047 _route->clear_processors (PostFader);
2052 ProcessorBox::clear_processors (Placement p)
2055 vector<string> choices;
2057 if (p == PreFader) {
2058 prompt = string_compose (_("Do you really want to remove all pre-fader processors from %1?\n"
2059 "(this cannot be undone)"), _route->name());
2061 prompt = string_compose (_("Do you really want to remove all post-fader processors from %1?\n"
2062 "(this cannot be undone)"), _route->name());
2065 choices.push_back (_("Cancel"));
2066 choices.push_back (_("Yes, remove them all"));
2068 Gtkmm2ext::Choice prompter (_("Remove processors"), prompt, choices);
2070 if (prompter.run () == 1) {
2071 _route->clear_processors (p);
2076 ProcessorBox::processor_can_be_edited (boost::shared_ptr<Processor> processor)
2078 boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack> (_route);
2079 if (at && at->freeze_state() == AudioTrack::Frozen) {
2084 boost::dynamic_pointer_cast<Send> (processor) ||
2085 boost::dynamic_pointer_cast<Return> (processor) ||
2086 boost::dynamic_pointer_cast<PluginInsert> (processor) ||
2087 boost::dynamic_pointer_cast<PortInsert> (processor)
2096 ProcessorBox::one_processor_can_be_edited ()
2098 list<ProcessorEntry*> selection = processor_display.selection ();
2099 list<ProcessorEntry*>::iterator i = selection.begin();
2100 while (i != selection.end() && processor_can_be_edited ((*i)->processor()) == false) {
2104 return (i != selection.end());
2108 ProcessorBox::get_editor_window (boost::shared_ptr<Processor> processor, bool use_custom)
2110 boost::shared_ptr<Send> send;
2111 boost::shared_ptr<InternalSend> internal_send;
2112 boost::shared_ptr<Return> retrn;
2113 boost::shared_ptr<PluginInsert> plugin_insert;
2114 boost::shared_ptr<PortInsert> port_insert;
2117 /* This method may or may not return a Window, but if it does not it
2118 * will modify the parent mixer strip appearance layout to allow
2119 * "editing" the @param processor that was passed in.
2121 * So for example, if the processor is an Amp (gain), the parent strip
2122 * will be forced back into a model where the fader controls the main gain.
2123 * If the processor is a send, then we map the send controls onto the
2126 * Plugins and others will return a window for control.
2129 if (boost::dynamic_pointer_cast<AudioTrack>(_route) != 0) {
2131 if (boost::dynamic_pointer_cast<AudioTrack> (_route)->freeze_state() == AudioTrack::Frozen) {
2136 if (boost::dynamic_pointer_cast<Amp> (processor)) {
2138 if (_parent_strip) {
2139 _parent_strip->revert_to_default_display ();
2142 } else if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
2144 if (!_session->engine().connected()) {
2148 if (boost::dynamic_pointer_cast<InternalSend> (processor) == 0) {
2150 gidget = new SendUIWindow (send, _session);
2153 } else if ((retrn = boost::dynamic_pointer_cast<Return> (processor)) != 0) {
2155 if (boost::dynamic_pointer_cast<InternalReturn> (retrn)) {
2156 /* no GUI for these */
2160 if (!_session->engine().connected()) {
2164 boost::shared_ptr<Return> retrn = boost::dynamic_pointer_cast<Return> (processor);
2166 ReturnUIWindow *return_ui;
2167 Window* w = get_processor_ui (retrn);
2171 return_ui = new ReturnUIWindow (retrn, _session);
2172 return_ui->set_title (retrn->name ());
2173 set_processor_ui (send, return_ui);
2176 return_ui = dynamic_cast<ReturnUIWindow *> (w);
2181 } else if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (processor)) != 0) {
2183 PluginUIWindow *plugin_ui;
2185 /* these are both allowed to be null */
2187 Window* w = get_processor_ui (plugin_insert);
2190 plugin_ui = new PluginUIWindow (plugin_insert, false, use_custom);
2191 plugin_ui->set_title (generate_processor_title (plugin_insert));
2192 set_processor_ui (plugin_insert, plugin_ui);
2195 plugin_ui = dynamic_cast<PluginUIWindow *> (w);
2200 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (processor)) != 0) {
2202 if (!_session->engine().connected()) {
2203 MessageDialog msg ( _("Not connected to audio engine - no I/O changes are possible"));
2208 PortInsertWindow *io_selector;
2210 Window* w = get_processor_ui (port_insert);
2213 io_selector = new PortInsertWindow (_session, port_insert);
2214 set_processor_ui (port_insert, io_selector);
2217 io_selector = dynamic_cast<PortInsertWindow *> (w);
2220 gidget = io_selector;
2227 ProcessorBox::get_generic_editor_window (boost::shared_ptr<Processor> processor)
2229 boost::shared_ptr<PluginInsert> plugin_insert
2230 = boost::dynamic_pointer_cast<PluginInsert>(processor);
2232 if (!plugin_insert) {
2236 PluginUIWindow* win = new PluginUIWindow (plugin_insert, true, false);
2237 win->set_title (generate_processor_title (plugin_insert));
2243 ProcessorBox::register_actions ()
2245 Glib::RefPtr<Gtk::ActionGroup> popup_act_grp = Gtk::ActionGroup::create(X_("ProcessorMenu"));
2246 Glib::RefPtr<Action> act;
2249 ActionManager::register_action (popup_act_grp, X_("newplugin"), _("New Plugin"),
2250 sigc::ptr_fun (ProcessorBox::rb_choose_plugin));
2252 act = ActionManager::register_action (popup_act_grp, X_("newinsert"), _("New Insert"),
2253 sigc::ptr_fun (ProcessorBox::rb_choose_insert));
2254 ActionManager::engine_sensitive_actions.push_back (act);
2255 act = ActionManager::register_action (popup_act_grp, X_("newsend"), _("New External Send ..."),
2256 sigc::ptr_fun (ProcessorBox::rb_choose_send));
2257 ActionManager::engine_sensitive_actions.push_back (act);
2259 ActionManager::register_action (popup_act_grp, X_("newaux"), _("New Aux Send ..."));
2261 ActionManager::register_action (popup_act_grp, X_("controls"), _("Controls"));
2263 ActionManager::register_action (popup_act_grp, X_("clear"), _("Clear (all)"),
2264 sigc::ptr_fun (ProcessorBox::rb_clear));
2265 ActionManager::register_action (popup_act_grp, X_("clear_pre"), _("Clear (pre-fader)"),
2266 sigc::ptr_fun (ProcessorBox::rb_clear_pre));
2267 ActionManager::register_action (popup_act_grp, X_("clear_post"), _("Clear (post-fader)"),
2268 sigc::ptr_fun (ProcessorBox::rb_clear_post));
2270 /* standard editing stuff */
2271 cut_action = ActionManager::register_action (popup_act_grp, X_("cut"), _("Cut"),
2272 sigc::ptr_fun (ProcessorBox::rb_cut));
2273 ActionManager::plugin_selection_sensitive_actions.push_back(cut_action);
2274 act = ActionManager::register_action (popup_act_grp, X_("copy"), _("Copy"),
2275 sigc::ptr_fun (ProcessorBox::rb_copy));
2276 ActionManager::plugin_selection_sensitive_actions.push_back(act);
2278 act = ActionManager::register_action (popup_act_grp, X_("delete"), _("Delete"),
2279 sigc::ptr_fun (ProcessorBox::rb_delete));
2280 ActionManager::plugin_selection_sensitive_actions.push_back(act); // ??
2282 paste_action = ActionManager::register_action (popup_act_grp, X_("paste"), _("Paste"),
2283 sigc::ptr_fun (ProcessorBox::rb_paste));
2284 rename_action = ActionManager::register_action (popup_act_grp, X_("rename"), _("Rename"),
2285 sigc::ptr_fun (ProcessorBox::rb_rename));
2286 ActionManager::register_action (popup_act_grp, X_("selectall"), _("Select All"),
2287 sigc::ptr_fun (ProcessorBox::rb_select_all));
2288 ActionManager::register_action (popup_act_grp, X_("deselectall"), _("Deselect All"),
2289 sigc::ptr_fun (ProcessorBox::rb_deselect_all));
2291 /* activation etc. */
2293 ActionManager::register_action (popup_act_grp, X_("activate_all"), _("Activate All"),
2294 sigc::ptr_fun (ProcessorBox::rb_activate_all));
2295 ActionManager::register_action (popup_act_grp, X_("deactivate_all"), _("Deactivate All"),
2296 sigc::ptr_fun (ProcessorBox::rb_deactivate_all));
2297 ActionManager::register_action (popup_act_grp, X_("ab_plugins"), _("A/B Plugins"),
2298 sigc::ptr_fun (ProcessorBox::rb_ab_plugins));
2301 edit_action = ActionManager::register_action (
2302 popup_act_grp, X_("edit"), _("Edit..."),
2303 sigc::ptr_fun (ProcessorBox::rb_edit));
2305 edit_generic_action = ActionManager::register_action (
2306 popup_act_grp, X_("edit-generic"), _("Edit with generic controls..."),
2307 sigc::ptr_fun (ProcessorBox::rb_edit_generic));
2309 ActionManager::add_action_group (popup_act_grp);
2313 ProcessorBox::rb_edit_generic ()
2315 if (_current_processor_box == 0) {
2319 _current_processor_box->for_selected_processors (&ProcessorBox::generic_edit_processor);
2323 ProcessorBox::rb_ab_plugins ()
2325 if (_current_processor_box == 0) {
2329 _current_processor_box->ab_plugins ();
2333 ProcessorBox::rb_choose_plugin ()
2335 if (_current_processor_box == 0) {
2338 _current_processor_box->choose_plugin ();
2342 ProcessorBox::rb_choose_insert ()
2344 if (_current_processor_box == 0) {
2347 _current_processor_box->choose_insert ();
2351 ProcessorBox::rb_choose_send ()
2353 if (_current_processor_box == 0) {
2356 _current_processor_box->choose_send ();
2360 ProcessorBox::rb_choose_aux (boost::weak_ptr<Route> wr)
2362 if (_current_processor_box == 0) {
2366 _current_processor_box->choose_aux (wr);
2370 ProcessorBox::rb_clear ()
2372 if (_current_processor_box == 0) {
2376 _current_processor_box->clear_processors ();
2381 ProcessorBox::rb_clear_pre ()
2383 if (_current_processor_box == 0) {
2387 _current_processor_box->clear_processors (PreFader);
2392 ProcessorBox::rb_clear_post ()
2394 if (_current_processor_box == 0) {
2398 _current_processor_box->clear_processors (PostFader);
2402 ProcessorBox::rb_cut ()
2404 if (_current_processor_box == 0) {
2408 _current_processor_box->processor_operation (ProcessorsCut);
2412 ProcessorBox::rb_delete ()
2414 if (_current_processor_box == 0) {
2418 _current_processor_box->processor_operation (ProcessorsDelete);
2422 ProcessorBox::rb_copy ()
2424 if (_current_processor_box == 0) {
2427 _current_processor_box->processor_operation (ProcessorsCopy);
2431 ProcessorBox::rb_paste ()
2433 if (_current_processor_box == 0) {
2437 _current_processor_box->processor_operation (ProcessorsPaste);
2441 ProcessorBox::rb_rename ()
2443 if (_current_processor_box == 0) {
2446 _current_processor_box->rename_processors ();
2450 ProcessorBox::rb_select_all ()
2452 if (_current_processor_box == 0) {
2456 _current_processor_box->processor_operation (ProcessorsSelectAll);
2460 ProcessorBox::rb_deselect_all ()
2462 if (_current_processor_box == 0) {
2466 _current_processor_box->deselect_all_processors ();
2470 ProcessorBox::rb_activate_all ()
2472 if (_current_processor_box == 0) {
2476 _current_processor_box->all_visible_processors_active (true);
2480 ProcessorBox::rb_deactivate_all ()
2482 if (_current_processor_box == 0) {
2485 _current_processor_box->all_visible_processors_active (false);
2489 ProcessorBox::rb_edit ()
2491 if (_current_processor_box == 0) {
2495 _current_processor_box->for_selected_processors (&ProcessorBox::edit_processor);
2499 ProcessorBox::edit_aux_send (boost::shared_ptr<Processor> processor)
2501 if (boost::dynamic_pointer_cast<InternalSend> (processor) == 0) {
2505 if (_parent_strip) {
2506 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
2507 if (_parent_strip->current_delivery() == send) {
2508 _parent_strip->revert_to_default_display ();
2510 _parent_strip->show_send(send);
2517 ProcessorBox::edit_processor (boost::shared_ptr<Processor> processor)
2522 if (edit_aux_send (processor)) {
2526 ProcessorWindowProxy* proxy = find_window_proxy (processor);
2529 proxy->set_custom_ui_mode (true);
2535 ProcessorBox::generic_edit_processor (boost::shared_ptr<Processor> processor)
2540 if (edit_aux_send (processor)) {
2544 ProcessorWindowProxy* proxy = find_window_proxy (processor);
2547 proxy->set_custom_ui_mode (false);
2553 ProcessorBox::route_property_changed (const PropertyChange& what_changed)
2555 if (!what_changed.contains (ARDOUR::Properties::name)) {
2559 ENSURE_GUI_THREAD (*this, &ProcessorBox::route_property_changed, what_changed);
2561 boost::shared_ptr<Processor> processor;
2562 boost::shared_ptr<PluginInsert> plugin_insert;
2563 boost::shared_ptr<Send> send;
2565 list<ProcessorEntry*> children = processor_display.children();
2567 for (list<ProcessorEntry*>::iterator iter = children.begin(); iter != children.end(); ++iter) {
2569 processor = (*iter)->processor ();
2575 Window* w = get_processor_ui (processor);
2581 /* rename editor windows for sends and plugins */
2583 if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
2584 w->set_title (send->name ());
2585 } else if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (processor)) != 0) {
2586 w->set_title (generate_processor_title (plugin_insert));
2592 ProcessorBox::generate_processor_title (boost::shared_ptr<PluginInsert> pi)
2594 string maker = pi->plugin()->maker() ? pi->plugin()->maker() : "";
2595 string::size_type email_pos;
2597 if ((email_pos = maker.find_first_of ('<')) != string::npos) {
2598 maker = maker.substr (0, email_pos - 1);
2601 if (maker.length() > 32) {
2602 maker = maker.substr (0, 32);
2606 SessionObject* owner = pi->owner();
2609 return string_compose(_("%1: %2 (by %3)"), owner->name(), pi->name(), maker);
2611 return string_compose(_("%1 (by %2)"), pi->name(), maker);
2615 /** @param p Processor.
2616 * @return the UI window for \a p.
2619 ProcessorBox::get_processor_ui (boost::shared_ptr<Processor> p) const
2621 list<ProcessorWindowProxy*>::const_iterator i = _processor_window_info.begin ();
2622 while (i != _processor_window_info.end()) {
2623 boost::shared_ptr<Processor> t = (*i)->processor().lock ();
2625 return (*i)->get ();
2634 /** Make a note of the UI window that a processor is using.
2635 * @param p Processor.
2636 * @param w UI window.
2639 ProcessorBox::set_processor_ui (boost::shared_ptr<Processor> p, Gtk::Window* w)
2641 list<ProcessorWindowProxy*>::iterator i = _processor_window_info.begin ();
2645 while (i != _processor_window_info.end()) {
2646 boost::shared_ptr<Processor> t = (*i)->processor().lock ();
2648 (*i)->use_window (*w);
2655 /* we shouldn't get here, because the ProcessorUIList should always contain
2656 an entry for each processor.
2662 ProcessorBox::mixer_strip_delivery_changed (boost::weak_ptr<Delivery> w)
2664 boost::shared_ptr<Delivery> d = w.lock ();
2669 list<ProcessorEntry*> children = processor_display.children ();
2670 list<ProcessorEntry*>::const_iterator i = children.begin();
2671 while (i != children.end() && (*i)->processor() != d) {
2675 if (i == children.end()) {
2676 processor_display.set_active (0);
2678 processor_display.set_active (*i);
2682 /** Called to repair the damage of Editor::show_window doing a show_all() */
2684 ProcessorBox::hide_things ()
2686 list<ProcessorEntry*> c = processor_display.children ();
2687 for (list<ProcessorEntry*>::iterator i = c.begin(); i != c.end(); ++i) {
2688 (*i)->hide_things ();
2693 ProcessorBox::processor_menu_unmapped ()
2695 processor_display.remove_placeholder ();
2699 ProcessorBox::entry_gui_object_state (ProcessorEntry* entry)
2701 if (!_parent_strip) {
2705 GUIObjectState& st = _parent_strip->gui_object_state ();
2707 XMLNode* strip = st.get_or_add_node (_parent_strip->state_id ());
2709 return st.get_or_add_node (strip, entry->state_id());
2713 ProcessorBox::update_gui_object_state (ProcessorEntry* entry)
2715 XMLNode* proc = entry_gui_object_state (entry);
2720 /* XXX: this is a bit inefficient; we just remove all child nodes and re-add them */
2721 proc->remove_nodes_and_delete (X_("Object"));
2722 entry->add_control_state (proc);
2726 ProcessorBox::is_editor_mixer_strip() const
2728 return _parent_strip && !_parent_strip->mixer_owned();
2731 ProcessorWindowProxy::ProcessorWindowProxy (string const & name, ProcessorBox* box, boost::weak_ptr<Processor> processor)
2732 : WM::ProxyBase (name, string())
2734 , _processor_box (box)
2735 , _processor (processor)
2737 , want_custom (false)
2740 boost::shared_ptr<Processor> p = _processor.lock ();
2744 p->DropReferences.connect (going_away_connection, MISSING_INVALIDATOR, boost::bind (&ProcessorWindowProxy::processor_going_away, this), gui_context());
2747 ProcessorWindowProxy::~ProcessorWindowProxy()
2749 /* processor window proxies do not own the windows they create with
2750 * ::get(), so set _window to null before the normal WindowProxy method
2757 ProcessorWindowProxy::processor_going_away ()
2762 /* should be no real reason to do this, since the object that would
2763 send DropReferences is about to be deleted, but lets do it anyway.
2765 going_away_connection.disconnect();
2768 ARDOUR::SessionHandlePtr*
2769 ProcessorWindowProxy::session_handle()
2776 ProcessorWindowProxy::valid() const
2782 ProcessorWindowProxy::get_state () const
2785 node = &ProxyBase::get_state();
2786 node->add_property (X_("custom-ui"), is_custom? X_("yes") : X_("no"));
2791 ProcessorWindowProxy::set_state (const XMLNode& node)
2793 XMLNodeList children = node.children ();
2794 XMLNodeList::const_iterator i = children.begin ();
2795 while (i != children.end()) {
2796 XMLProperty* prop = (*i)->property (X_("name"));
2797 if ((*i)->name() == X_("Window") && prop && prop->value() == _name) {
2803 if (i != children.end()) {
2805 if ((prop = (*i)->property (X_("custom-ui"))) != 0) {
2806 want_custom = PBD::string_is_affirmative (prop->value ());
2810 ProxyBase::set_state(node);
2814 ProcessorWindowProxy::get (bool create)
2816 boost::shared_ptr<Processor> p = _processor.lock ();
2821 if (_window && (is_custom != want_custom)) {
2822 /* drop existing window - wrong type */
2831 is_custom = want_custom;
2832 _window = _processor_box->get_editor_window (p, is_custom);
2843 ProcessorWindowProxy::toggle ()
2845 if (_window && (is_custom != want_custom)) {
2846 /* drop existing window - wrong type */
2849 is_custom = want_custom;
2851 WM::ProxyBase::toggle ();