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/stop_signal.h>
41 #include <gtkmm2ext/doi.h>
42 #include <gtkmm2ext/window_title.h>
44 #include "ardour/amp.h"
45 #include "ardour/ardour.h"
46 #include "ardour/audio_diskstream.h"
47 #include "ardour/audio_track.h"
48 #include "ardour/audioengine.h"
49 #include "ardour/ladspa_plugin.h"
50 #include "ardour/meter.h"
51 #include "ardour/plugin_insert.h"
52 #include "ardour/port_insert.h"
53 #include "ardour/profile.h"
54 #include "ardour/return.h"
55 #include "ardour/route.h"
56 #include "ardour/send.h"
57 #include "ardour/session.h"
60 #include "ardour_dialog.h"
61 #include "ardour_ui.h"
62 #include "gui_thread.h"
63 #include "io_selector.h"
66 #include "mixer_strip.h"
67 #include "plugin_selector.h"
68 #include "plugin_ui.h"
69 #include "processor_box.h"
70 #include "public_editor.h"
71 #include "return_ui.h"
72 #include "route_processor_selection.h"
78 #ifdef HAVE_AUDIOUNITS
84 using namespace ARDOUR;
88 using namespace Gtkmm2ext;
90 ProcessorBox* ProcessorBox::_current_processor_box = 0;
91 RefPtr<Action> ProcessorBox::paste_action;
92 bool ProcessorBox::get_colors = true;
93 Gdk::Color* ProcessorBox::active_processor_color;
94 Gdk::Color* ProcessorBox::inactive_processor_color;
96 ProcessorBox::ProcessorBox (Session& sess, PluginSelector &plugsel,
97 RouteRedirectSelection & rsel, MixerStrip* parent, bool owner_is_mixer)
99 , _parent_strip (parent)
100 , _owner_is_mixer (owner_is_mixer)
101 , _placement(PreFader)
102 , _plugin_selector(plugsel)
103 , _rr_selection(rsel)
106 active_processor_color = new Gdk::Color;
107 inactive_processor_color = new Gdk::Color;
108 set_color (*active_processor_color, rgba_from_style (
109 "ProcessorSelector", 0xff, 0, 0, 0, "fg", Gtk::STATE_ACTIVE, false ));
110 set_color (*inactive_processor_color, rgba_from_style (
111 "ProcessorSelector", 0xff, 0, 0, 0, "fg", Gtk::STATE_NORMAL, false ));
117 send_action_menu = 0;
118 processor_drag_in_progress = false;
119 no_processor_redisplay = false;
120 ignore_delete = false;
122 model = ListStore::create(columns);
124 RefPtr<TreeSelection> selection = processor_display.get_selection();
125 selection->set_mode (Gtk::SELECTION_MULTIPLE);
126 selection->signal_changed().connect (mem_fun (*this, &ProcessorBox::selection_changed));
128 processor_display.set_data ("processorbox", this);
129 processor_display.set_model (model);
130 processor_display.append_column (X_("notshown"), columns.text);
131 processor_display.set_name ("ProcessorSelector");
132 processor_display.set_headers_visible (false);
133 processor_display.set_reorderable (true);
134 processor_display.set_size_request (-1, 40);
135 processor_display.get_column(0)->set_sizing(TREE_VIEW_COLUMN_FIXED);
136 processor_display.get_column(0)->set_fixed_width(48);
137 processor_display.add_object_drag (columns.processor.index(), "processors");
138 processor_display.set_enable_search (false);
139 processor_display.signal_drop.connect (mem_fun (*this, &ProcessorBox::object_drop));
141 TreeViewColumn* name_col = processor_display.get_column(0);
142 CellRendererText* renderer = dynamic_cast<CellRendererText*>(
143 processor_display.get_column_cell_renderer (0));
144 name_col->add_attribute(renderer->property_foreground_gdk(), columns.color);
146 processor_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
148 model->signal_row_deleted().connect (mem_fun (*this, &ProcessorBox::row_deleted));
150 processor_scroller.add (processor_display);
151 processor_eventbox.add (processor_scroller);
153 processor_scroller.set_size_request (-1, 40);
155 pack_start (processor_eventbox, true, true);
157 processor_display.signal_enter_notify_event().connect (mem_fun(*this, &ProcessorBox::enter_notify), false);
158 processor_display.signal_leave_notify_event().connect (mem_fun(*this, &ProcessorBox::leave_notify), false);
160 processor_display.signal_key_press_event().connect (mem_fun(*this, &ProcessorBox::processor_key_press_event));
161 processor_display.signal_key_release_event().connect (mem_fun(*this, &ProcessorBox::processor_key_release_event));
163 processor_display.signal_button_press_event().connect (
164 mem_fun(*this, &ProcessorBox::processor_button_press_event), false);
165 processor_display.signal_button_release_event().connect (
166 mem_fun(*this, &ProcessorBox::processor_button_release_event));
169 ProcessorBox::~ProcessorBox ()
174 ProcessorBox::set_route (boost::shared_ptr<Route> r)
176 connections.clear ();
180 connections.push_back (_route->processors_changed.connect (
181 mem_fun(*this, &ProcessorBox::redisplay_processors)));
182 connections.push_back (_route->GoingAway.connect (
183 mem_fun (*this, &ProcessorBox::route_going_away)));
184 connections.push_back (_route->NameChanged.connect (
185 mem_fun(*this, &ProcessorBox::route_name_changed)));
187 redisplay_processors ();
191 ProcessorBox::route_going_away ()
193 /* don't keep updating display as processors are deleted */
194 no_processor_redisplay = true;
199 ProcessorBox::object_drop (const list<boost::shared_ptr<Processor> >& procs, Gtk::TreeView* source, Glib::RefPtr<Gdk::DragContext>& context)
201 cerr << "Drop from " << source << " (mine is " << &processor_display << ") action = " << hex << context->get_suggested_action() << dec << endl;
203 for (list<boost::shared_ptr<Processor> >::const_iterator i = procs.begin(); i != procs.end(); ++i) {
204 XMLNode& state = (*i)->get_state ();
206 nlist.push_back (&state);
207 paste_processor_state (nlist);
211 /* since the treeview doesn't take care of this properly, we have to delete the originals
215 if ((context->get_suggested_action() == Gdk::ACTION_MOVE) && source) {
216 ProcessorBox* other = reinterpret_cast<ProcessorBox*> (source->get_data ("processorbox"));
218 cerr << "source was another processor box, delete the selected items\n";
219 other->delete_dragged_processors (procs);
223 context->drag_finish (true, (context->get_suggested_action() == Gdk::ACTION_MOVE), 0);
227 ProcessorBox::update()
229 redisplay_processors ();
234 ProcessorBox::set_width (Width w)
241 redisplay_processors ();
245 ProcessorBox::remove_processor_gui (boost::shared_ptr<Processor> processor)
247 boost::shared_ptr<Send> send;
248 boost::shared_ptr<Return> retrn;
249 boost::shared_ptr<PortInsert> port_insert;
251 if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (processor)) != 0) {
252 PortInsertUI *io_selector = reinterpret_cast<PortInsertUI *> (port_insert->get_gui());
253 port_insert->set_gui (0);
255 } else if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
256 SendUIWindow *sui = reinterpret_cast<SendUIWindow*> (send->get_gui());
259 } else if ((retrn = boost::dynamic_pointer_cast<Return> (processor)) != 0) {
260 ReturnUIWindow *rui = reinterpret_cast<ReturnUIWindow*> (retrn->get_gui());
267 ProcessorBox::build_send_action_menu ()
269 using namespace Menu_Helpers;
271 send_action_menu = new Menu;
272 send_action_menu->set_name ("ArdourContextMenu");
273 MenuList& items = send_action_menu->items();
275 items.push_back (MenuElem (_("New send"), mem_fun(*this, &ProcessorBox::new_send)));
276 items.push_back (MenuElem (_("Show send controls"), mem_fun(*this, &ProcessorBox::show_send_controls)));
280 ProcessorBox::show_send_controls ()
285 ProcessorBox::new_send ()
290 ProcessorBox::show_processor_menu (gint arg)
292 if (processor_menu == 0) {
293 processor_menu = build_processor_menu ();
296 Gtk::MenuItem* plugin_menu_item = dynamic_cast<Gtk::MenuItem*>(ActionManager::get_widget("/processormenu/newplugin"));
298 if (plugin_menu_item) {
299 plugin_menu_item->set_submenu (_plugin_selector.plugin_menu());
302 paste_action->set_sensitive (!_rr_selection.processors.empty());
304 processor_menu->popup (1, arg);
308 ProcessorBox::processor_drag_begin (GdkDragContext *context)
310 processor_drag_in_progress = true;
314 ProcessorBox::processor_drag_end (GdkDragContext *context)
316 processor_drag_in_progress = false;
320 ProcessorBox::enter_notify (GdkEventCrossing* ev)
322 _current_processor_box = this;
323 Keyboard::magic_widget_grab_focus ();
324 processor_display.grab_focus ();
330 ProcessorBox::leave_notify (GdkEventCrossing* ev)
332 switch (ev->detail) {
333 case GDK_NOTIFY_INFERIOR:
336 Keyboard::magic_widget_drop_focus ();
343 ProcessorBox::processor_key_press_event (GdkEventKey *ev)
345 /* do real stuff on key release */
350 ProcessorBox::processor_key_release_event (GdkEventKey *ev)
353 ProcSelection targets;
355 get_selected_processors (targets);
357 if (targets.empty()) {
361 TreeModel::Path path;
362 TreeViewColumn* column;
366 processor_display.get_pointer (x, y);
368 if (processor_display.get_path_at_pos (x, y, path, column, cellx, celly)) {
369 if ((iter = model->get_iter (path))) {
370 targets.push_back ((*iter)[columns.processor]);
375 if (targets.empty()) {
379 switch (ev->keyval) {
382 delete_processors ();
387 for (ProcSelection::iterator i = targets.begin(); i != targets.end(); ++i) {
388 if ((*i)->active()) {
405 ProcessorBox::processor_button_press_event (GdkEventButton *ev)
408 TreeModel::Path path;
409 TreeViewColumn* column;
412 boost::shared_ptr<Processor> processor;
414 bool selected = false;
416 if (processor_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
417 if ((iter = model->get_iter (path))) {
418 processor = (*iter)[columns.processor];
419 selected = processor_display.get_selection()->is_selected (iter);
424 if (processor && (Keyboard::is_edit_event (ev) || (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS))) {
426 if (_session.engine().connected()) {
427 /* XXX giving an error message here is hard, because we may be in the midst of a button press */
428 edit_processor (processor);
432 } else if (processor && ev->button == 1 && selected) {
434 // this is purely informational but necessary
435 ProcessorSelected (processor); // emit
437 } else if (!processor && ev->button == 1 && ev->type == GDK_2BUTTON_PRESS) {
440 _plugin_selector.show_manager ();
448 ProcessorBox::processor_button_release_event (GdkEventButton *ev)
451 TreeModel::Path path;
452 TreeViewColumn* column;
455 boost::shared_ptr<Processor> processor;
458 if (processor_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
459 if ((iter = model->get_iter (path))) {
460 processor = (*iter)[columns.processor];
464 if (processor && Keyboard::is_delete_event (ev)) {
466 Glib::signal_idle().connect (bind (
467 mem_fun(*this, &ProcessorBox::idle_delete_processor),
468 boost::weak_ptr<Processor>(processor)));
471 } else if (Keyboard::is_context_menu_event (ev)) {
473 /* figure out if we are above or below the fader/amp processor,
474 and set the next insert position appropriately.
478 if (_route->processor_is_prefader (processor)) {
479 _placement = PreFader;
481 _placement = PostFader;
484 _placement = PostFader;
487 show_processor_menu (ev->time);
490 } else if (processor && Keyboard::is_button2_event (ev)
492 && (Keyboard::no_modifier_keys_pressed (ev) && ((ev->state & Gdk::BUTTON2_MASK) == Gdk::BUTTON2_MASK))
496 /* button2-click with no/appropriate modifiers */
498 if (processor->active()) {
499 processor->deactivate ();
501 processor->activate ();
511 ProcessorBox::build_processor_menu ()
513 processor_menu = dynamic_cast<Gtk::Menu*>(ActionManager::get_widget("/processormenu") );
514 processor_menu->set_name ("ArdourContextMenu");
518 return processor_menu;
522 ProcessorBox::selection_changed ()
524 bool sensitive = (processor_display.get_selection()->count_selected_rows()) ? true : false;
525 ActionManager::set_sensitive (ActionManager::plugin_selection_sensitive_actions, sensitive);
529 ProcessorBox::select_all_processors ()
531 processor_display.get_selection()->select_all();
535 ProcessorBox::deselect_all_processors ()
537 processor_display.get_selection()->unselect_all();
541 ProcessorBox::choose_plugin ()
543 _plugin_selector.set_interested_object (*this);
547 ProcessorBox::use_plugins (const SelectedPlugins& plugins)
549 for (SelectedPlugins::const_iterator p = plugins.begin(); p != plugins.end(); ++p) {
551 boost::shared_ptr<Processor> processor (new PluginInsert (_session, *p));
553 Route::ProcessorStreams err_streams;
555 if (Config->get_new_plugins_active()) {
556 processor->activate ();
559 if (_route->add_processor (processor, _placement, &err_streams)) {
560 weird_plugin_dialog (**p, err_streams);
561 // XXX SHAREDPTR delete plugin here .. do we even need to care?
564 if (Profile->get_sae()) {
565 processor->activate ();
567 processor->ActiveChanged.connect (bind (
568 mem_fun (*this, &ProcessorBox::show_processor_active),
569 boost::weak_ptr<Processor>(processor)));
575 ProcessorBox::weird_plugin_dialog (Plugin& p, Route::ProcessorStreams streams)
577 ArdourDialog dialog (_("ardour: weird plugin dialog"));
580 string text = string_compose(_("You attempted to add the plugin \"%1\" at index %2.\n"),
581 p.name(), streams.index);
583 bool has_midi = streams.count.n_midi() > 0 || p.get_info()->n_inputs.n_midi() > 0;
584 bool has_audio = streams.count.n_audio() > 0 || p.get_info()->n_inputs.n_audio() > 0;
586 text += _("\nThis plugin has:\n");
588 text += string_compose("\t%1 ", p.get_info()->n_inputs.n_midi()) + _("MIDI input(s)\n");
591 text += string_compose("\t%1 ", p.get_info()->n_inputs.n_audio()) + _("audio input(s)\n");
594 text += _("\nBut at the insertion point, there are:\n");
596 text += string_compose("\t%1 ", streams.count.n_midi()) + _("MIDI channel(s)\n");
599 text += string_compose("\t%1 ", streams.count.n_audio()) + _("audio channel(s)\n");
602 text += _("\nArdour is unable to insert this plugin here.\n");
603 label.set_text(text);
605 dialog.get_vbox()->pack_start (label);
606 dialog.add_button (Stock::OK, RESPONSE_ACCEPT);
608 dialog.set_name (X_("PluginIODialog"));
609 dialog.set_position (Gtk::WIN_POS_MOUSE);
610 dialog.set_modal (true);
617 ProcessorBox::choose_insert ()
619 boost::shared_ptr<Processor> processor (new PortInsert (_session, _route->mute_master()));
620 processor->ActiveChanged.connect (bind (mem_fun(*this, &ProcessorBox::show_processor_active),
621 boost::weak_ptr<Processor>(processor)));
623 _route->add_processor (processor, _placement);
627 ProcessorBox::choose_send ()
629 boost::shared_ptr<Send> send (new Send (_session, _route->mute_master()));
631 /* make an educated guess at the initial number of outputs for the send */
632 ChanCount outs = (_session.master_out())
633 ? _session.master_out()->n_outputs()
634 : _route->n_outputs();
636 /* XXX need processor lock on route */
638 send->output()->ensure_io (outs, false, this);
639 } catch (AudioEngine::PortRegistrationFailure& err) {
640 error << string_compose (_("Cannot set up new send: %1"), err.what()) << endmsg;
644 /* let the user adjust the IO setup before creation */
645 IOSelectorWindow *ios = new IOSelectorWindow (_session, send->output(), true);
648 /* keep a reference to the send so it doesn't get deleted while
649 the IOSelectorWindow is doing its stuff */
650 _processor_being_created = send;
652 ios->selector().Finished.connect (bind (
653 mem_fun(*this, &ProcessorBox::send_io_finished),
654 boost::weak_ptr<Processor>(send), ios));
658 ProcessorBox::send_io_finished (IOSelector::Result r, boost::weak_ptr<Processor> weak_processor, IOSelectorWindow* ios)
660 boost::shared_ptr<Processor> processor (weak_processor.lock());
662 /* drop our temporary reference to the new send */
663 _processor_being_created.reset ();
670 case IOSelector::Cancelled:
671 // processor will go away when all shared_ptrs to it vanish
674 case IOSelector::Accepted:
675 _route->add_processor (processor, _placement);
676 if (Profile->get_sae()) {
677 processor->activate ();
682 delete_when_idle (ios);
686 ProcessorBox::choose_return ()
688 boost::shared_ptr<Return> retrn (new Return (_session));
690 /* assume user just wants a single audio input (sidechain) by default */
691 ChanCount ins(DataType::AUDIO, 1);
693 /* XXX need processor lock on route */
695 retrn->input()->ensure_io (ins, false, this);
696 } catch (AudioEngine::PortRegistrationFailure& err) {
697 error << string_compose (_("Cannot set up new return: %1"), err.what()) << endmsg;
701 /* let the user adjust the IO setup before creation */
702 IOSelectorWindow *ios = new IOSelectorWindow (_session, retrn->output(), true);
705 /* keep a reference to the send so it doesn't get deleted while
706 the IOSelectorWindow is doing its stuff */
707 _processor_being_created = retrn;
709 ios->selector().Finished.connect (bind (
710 mem_fun(*this, &ProcessorBox::return_io_finished),
711 boost::weak_ptr<Processor>(retrn), ios));
715 ProcessorBox::return_io_finished (IOSelector::Result r, boost::weak_ptr<Processor> weak_processor, IOSelectorWindow* ios)
717 boost::shared_ptr<Processor> processor (weak_processor.lock());
719 /* drop our temporary reference to the new return */
720 _processor_being_created.reset ();
727 case IOSelector::Cancelled:
728 // processor will go away when all shared_ptrs to it vanish
731 case IOSelector::Accepted:
732 _route->add_processor (processor, _placement);
733 if (Profile->get_sae()) {
734 processor->activate ();
739 delete_when_idle (ios);
743 ProcessorBox::redisplay_processors ()
745 ENSURE_GUI_THREAD (mem_fun(*this, &ProcessorBox::redisplay_processors));
747 if (no_processor_redisplay) {
751 ignore_delete = true;
753 ignore_delete = false;
755 processor_active_connections.clear ();
756 processor_name_connections.clear ();
758 _route->foreach_processor (mem_fun (*this, &ProcessorBox::add_processor_to_display));
760 build_processor_tooltip (processor_eventbox, _("Inserts, sends & plugins:"));
764 ProcessorBox::add_processor_to_display (boost::weak_ptr<Processor> p)
766 boost::shared_ptr<Processor> processor (p.lock ());
772 if (processor == _route->amp() || !processor->visible()) {
777 Gtk::TreeModel::Row row = *(model->append());
778 row[columns.text] = processor_name (processor);
779 row[columns.processor] = processor;
781 show_processor_active (processor);
783 processor_active_connections.push_back (processor->ActiveChanged.connect (bind (
784 mem_fun(*this, &ProcessorBox::show_processor_active),
785 boost::weak_ptr<Processor>(processor))));
786 processor_name_connections.push_back (processor->NameChanged.connect (bind (
787 mem_fun(*this, &ProcessorBox::show_processor_name),
788 boost::weak_ptr<Processor>(processor))));
792 ProcessorBox::processor_name (boost::weak_ptr<Processor> weak_processor)
794 boost::shared_ptr<Processor> processor (weak_processor.lock());
800 boost::shared_ptr<Send> send;
803 if (!processor->active()) {
807 if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
811 /* grab the send name out of its overall name */
813 string::size_type lbracket, rbracket;
814 lbracket = send->name().find ('[');
815 rbracket = send->name().find (']');
819 name_display += send->name().substr (lbracket+1, lbracket-rbracket-1);
822 name_display += PBD::short_version (send->name().substr (lbracket+1, lbracket-rbracket-1), 4);
830 name_display += processor->display_name();
833 name_display += PBD::short_version (processor->display_name(), 5);
839 if (!processor->active()) {
847 ProcessorBox::build_processor_tooltip (EventBox& box, string start)
851 Gtk::TreeModel::Children children = model->children();
852 for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
853 Gtk::TreeModel::Row row = *iter;
855 tip += row[columns.text];
857 ARDOUR_UI::instance()->tooltips().set_tip (box, tip);
861 ProcessorBox::show_processor_name (boost::weak_ptr<Processor> processor)
863 ENSURE_GUI_THREAD(bind (mem_fun(*this, &ProcessorBox::show_processor_name), processor));
864 show_processor_active (processor);
868 ProcessorBox::show_processor_active (boost::weak_ptr<Processor> weak_processor)
870 boost::shared_ptr<Processor> processor (weak_processor.lock());
876 ENSURE_GUI_THREAD(bind (mem_fun(*this, &ProcessorBox::show_processor_active), weak_processor));
878 Gtk::TreeModel::Children children = model->children();
879 Gtk::TreeModel::Children::iterator iter = children.begin();
881 while (iter != children.end()) {
883 boost::shared_ptr<Processor> r = (*iter)[columns.processor];
885 if (r == processor) {
886 (*iter)[columns.text] = processor_name (r);
888 if (processor->active()) {
889 (*iter)[columns.color] = *active_processor_color;
891 (*iter)[columns.color] = *inactive_processor_color;
901 ProcessorBox::row_deleted (const Gtk::TreeModel::Path& path)
903 if (!ignore_delete) {
904 compute_processor_sort_keys ();
909 ProcessorBox::compute_processor_sort_keys ()
911 Gtk::TreeModel::Children children = model->children();
912 Route::ProcessorList our_processors;
914 for (Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
915 boost::shared_ptr<Processor> p = (*iter)[columns.processor];
916 our_processors.push_back ((*iter)[columns.processor]);
919 if (_route->reorder_processors (our_processors)) {
921 /* reorder failed, so redisplay */
923 redisplay_processors ();
925 /* now tell them about the problem */
927 ArdourDialog dialog (_("ardour: weird plugin dialog"));
931 You cannot reorder this set of processors\n\
932 in that way because the inputs and\n\
933 outputs do not work correctly."));
935 dialog.get_vbox()->pack_start (label);
936 dialog.add_button (Stock::OK, RESPONSE_ACCEPT);
938 dialog.set_name (X_("PluginIODialog"));
939 dialog.set_position (Gtk::WIN_POS_MOUSE);
940 dialog.set_modal (true);
948 ProcessorBox::rename_processors ()
950 ProcSelection to_be_renamed;
952 get_selected_processors (to_be_renamed);
954 if (to_be_renamed.empty()) {
958 for (ProcSelection::iterator i = to_be_renamed.begin(); i != to_be_renamed.end(); ++i) {
959 rename_processor (*i);
964 ProcessorBox::cut_processors ()
966 ProcSelection to_be_removed;
967 XMLNode* node = new XMLNode (X_("cut"));
969 get_selected_processors (to_be_removed);
971 if (to_be_removed.empty()) {
975 no_processor_redisplay = true;
976 for (ProcSelection::iterator i = to_be_removed.begin(); i != to_be_removed.end(); ++i) {
977 // Do not cut inserts
978 if (boost::dynamic_pointer_cast<PluginInsert>((*i)) != 0 ||
979 (boost::dynamic_pointer_cast<Send>((*i)) != 0)) {
981 void* gui = (*i)->get_gui ();
984 static_cast<Gtk::Widget*>(gui)->hide ();
987 XMLNode& child ((*i)->get_state());
989 if (_route->remove_processor (*i) == 0) {
991 node->add_child_nocopy (child);
998 _rr_selection.set (node);
1000 no_processor_redisplay = false;
1001 redisplay_processors ();
1005 ProcessorBox::copy_processors ()
1007 ProcSelection to_be_copied;
1008 XMLNode* node = new XMLNode (X_("copy"));
1010 get_selected_processors (to_be_copied);
1012 if (to_be_copied.empty()) {
1016 for (ProcSelection::iterator i = to_be_copied.begin(); i != to_be_copied.end(); ++i) {
1017 // Do not copy inserts
1018 if (boost::dynamic_pointer_cast<PluginInsert>((*i)) != 0 ||
1019 (boost::dynamic_pointer_cast<Send>((*i)) != 0)) {
1020 node->add_child_nocopy ((*i)->get_state());
1024 _rr_selection.set (node);
1028 ProcessorBox::delete_processors ()
1030 ProcSelection to_be_deleted;
1032 get_selected_processors (to_be_deleted);
1034 if (to_be_deleted.empty()) {
1038 no_processor_redisplay = true;
1040 for (ProcSelection::iterator i = to_be_deleted.begin(); i != to_be_deleted.end(); ++i) {
1042 void* gui = (*i)->get_gui ();
1045 static_cast<Gtk::Widget*>(gui)->hide ();
1048 _route->remove_processor(*i);
1051 no_processor_redisplay = false;
1052 redisplay_processors ();
1056 ProcessorBox::delete_dragged_processors (const list<boost::shared_ptr<Processor> >& procs)
1058 list<boost::shared_ptr<Processor> >::const_iterator x;
1060 no_processor_redisplay = true;
1061 for (x = procs.begin(); x != procs.end(); ++x) {
1063 void* gui = (*x)->get_gui ();
1066 static_cast<Gtk::Widget*>(gui)->hide ();
1069 _route->remove_processor(*x);
1072 no_processor_redisplay = false;
1073 redisplay_processors ();
1077 ProcessorBox::idle_delete_processor (boost::weak_ptr<Processor> weak_processor)
1079 boost::shared_ptr<Processor> processor (weak_processor.lock());
1085 /* NOT copied to _mixer.selection() */
1087 no_processor_redisplay = true;
1088 _route->remove_processor (processor);
1089 no_processor_redisplay = false;
1090 redisplay_processors ();
1096 ProcessorBox::rename_processor (boost::shared_ptr<Processor> processor)
1098 ArdourPrompter name_prompter (true);
1100 name_prompter.set_prompt (_("rename processor"));
1101 name_prompter.set_initial_text (processor->name());
1102 name_prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
1103 name_prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
1104 name_prompter.show_all ();
1106 switch (name_prompter.run ()) {
1108 case Gtk::RESPONSE_ACCEPT:
1109 name_prompter.get_result (result);
1110 if (result.length()) {
1111 processor->set_name (result);
1120 ProcessorBox::paste_processors ()
1122 if (_rr_selection.processors.empty()) {
1126 cerr << "paste from node called " << _rr_selection.processors.get_node().name() << endl;
1128 paste_processor_state (_rr_selection.processors.get_node().children());
1132 ProcessorBox::paste_processor_state (const XMLNodeList& nlist)
1134 XMLNodeConstIterator niter;
1135 list<boost::shared_ptr<Processor> > copies;
1137 cerr << "Pasting processor selection containing " << nlist.size() << endl;
1139 if (nlist.empty()) {
1143 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1144 cerr << "try using " << (*niter)->name() << endl;
1145 XMLProperty const * type = (*niter)->property ("type");
1148 boost::shared_ptr<Processor> p;
1150 if (type->value() == "send") {
1151 XMLNode n (**niter);
1152 Send::make_unique (n, _session);
1153 p.reset (new Send (_session, _route->mute_master(), n));
1155 } else if (type->value() == "meter") {
1156 p = _route->shared_peak_meter();
1158 } else if (type->value() == "main-outs") {
1159 /* do not copy-n-paste main outs */
1162 } else if (type->value() == "amp") {
1163 /* do not copy-n-paste amp */
1166 } else if (type->value() == "intsend" || type->value() == "intreturn") {
1167 /* do not copy-n-paste internal sends&returns */
1170 } else if (type->value() == "listen") {
1171 p.reset (new Delivery (_session, _route->mute_master(), **niter));
1174 p.reset (new PluginInsert (_session, **niter));
1177 copies.push_back (p);
1180 cerr << "plugin insert constructor failed\n";
1184 if (copies.empty()) {
1188 if (_route->add_processors (copies, _placement)) {
1191 "Copying the set of processors on the clipboard failed,\n\
1192 probably because the I/O configuration of the plugins\n\
1193 could not match the configuration of this track.");
1194 MessageDialog am (msg);
1200 ProcessorBox::activate_processor (boost::shared_ptr<Processor> r)
1206 ProcessorBox::deactivate_processor (boost::shared_ptr<Processor> r)
1212 ProcessorBox::get_selected_processors (ProcSelection& processors)
1214 vector<Gtk::TreeModel::Path> pathlist = processor_display.get_selection()->get_selected_rows();
1216 for (vector<Gtk::TreeModel::Path>::iterator iter = pathlist.begin(); iter != pathlist.end(); ++iter) {
1217 processors.push_back ((*(model->get_iter(*iter)))[columns.processor]);
1222 ProcessorBox::for_selected_processors (void (ProcessorBox::*method)(boost::shared_ptr<Processor>))
1224 vector<Gtk::TreeModel::Path> pathlist = processor_display.get_selection()->get_selected_rows();
1226 for (vector<Gtk::TreeModel::Path>::iterator iter = pathlist.begin(); iter != pathlist.end(); ++iter) {
1227 boost::shared_ptr<Processor> processor = (*(model->get_iter(*iter)))[columns.processor];
1228 (this->*method)(processor);
1233 ProcessorBox::all_processors_active (bool state)
1235 _route->all_processors_active (_placement, state);
1239 ProcessorBox::ab_plugins ()
1241 _route->ab_plugins (ab_direction);
1242 ab_direction = !ab_direction;
1247 ProcessorBox::clear_processors ()
1250 vector<string> choices;
1252 if (boost::dynamic_pointer_cast<AudioTrack>(_route) != 0) {
1253 if (_placement == PreFader) {
1254 prompt = _("Do you really want to remove all pre-fader processors from this track?\n"
1255 "(this cannot be undone)");
1257 prompt = _("Do you really want to remove all post-fader processors from this track?\n"
1258 "(this cannot be undone)");
1261 if (_placement == PreFader) {
1262 prompt = _("Do you really want to remove all pre-fader processors from this bus?\n"
1263 "(this cannot be undone)");
1265 prompt = _("Do you really want to remove all post-fader processors from this bus?\n"
1266 "(this cannot be undone)");
1270 choices.push_back (_("Cancel"));
1271 choices.push_back (_("Yes, remove them all"));
1273 Gtkmm2ext::Choice prompter (prompt, choices);
1275 if (prompter.run () == 1) {
1276 _route->clear_processors (_placement);
1281 ProcessorBox::edit_processor (boost::shared_ptr<Processor> processor)
1283 boost::shared_ptr<Send> send;
1284 boost::shared_ptr<Return> retrn;
1285 boost::shared_ptr<PluginInsert> plugin_insert;
1286 boost::shared_ptr<PortInsert> port_insert;
1289 if (boost::dynamic_pointer_cast<AudioTrack>(_route) != 0) {
1291 if (boost::dynamic_pointer_cast<AudioTrack> (_route)->freeze_state() == AudioTrack::Frozen) {
1296 if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
1298 if (!_session.engine().connected()) {
1302 #ifdef OLD_SEND_EDITING
1303 SendUIWindow *send_ui;
1305 if (send->get_gui() == 0) {
1306 send_ui = new SendUIWindow (send, _session);
1308 WindowTitle title(Glib::get_application_name());
1309 title += send->name();
1310 send_ui->set_title (title.get_string());
1312 send->set_gui (send_ui);
1315 send_ui = reinterpret_cast<SendUIWindow *> (send->get_gui());
1320 if (_parent_strip) {
1321 _parent_strip->gain_meter().set_controls (_route, send->meter(), send->amp()->gain_control(), send->amp());
1322 _parent_strip->panner_ui().set_panner (send->panner());
1326 } else if ((retrn = boost::dynamic_pointer_cast<Return> (processor)) != 0) {
1328 if (!_session.engine().connected()) {
1332 boost::shared_ptr<Return> retrn = boost::dynamic_pointer_cast<Return> (processor);
1334 ReturnUIWindow *return_ui;
1336 if (retrn->get_gui() == 0) {
1338 return_ui = new ReturnUIWindow (retrn, _session);
1340 WindowTitle title(Glib::get_application_name());
1341 title += retrn->name();
1342 return_ui->set_title (title.get_string());
1344 send->set_gui (return_ui);
1347 return_ui = reinterpret_cast<ReturnUIWindow *> (retrn->get_gui());
1352 } else if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (processor)) != 0) {
1354 PluginUIWindow *plugin_ui;
1356 /* these are both allowed to be null */
1358 Container* toplevel = get_toplevel();
1359 Window* win = dynamic_cast<Gtk::Window*>(toplevel);
1361 if (plugin_insert->get_gui() == 0) {
1363 plugin_ui = new PluginUIWindow (win, plugin_insert);
1365 WindowTitle title(Glib::get_application_name());
1366 title += generate_processor_title (plugin_insert);
1367 plugin_ui->set_title (title.get_string());
1369 plugin_insert->set_gui (plugin_ui);
1372 plugin_ui = reinterpret_cast<PluginUIWindow *> (plugin_insert->get_gui());
1373 plugin_ui->set_parent (win);
1378 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (processor)) != 0) {
1380 if (!_session.engine().connected()) {
1381 MessageDialog msg ( _("Not connected to JACK - no I/O changes are possible"));
1386 PortInsertWindow *io_selector;
1388 if (port_insert->get_gui() == 0) {
1389 io_selector = new PortInsertWindow (_session, port_insert);
1390 port_insert->set_gui (io_selector);
1393 io_selector = reinterpret_cast<PortInsertWindow *> (port_insert->get_gui());
1396 gidget = io_selector;
1400 if (gidget->is_visible()) {
1401 gidget->get_window()->raise ();
1403 gidget->show_all ();
1410 ProcessorBox::register_actions ()
1412 Glib::RefPtr<Gtk::ActionGroup> popup_act_grp = Gtk::ActionGroup::create(X_("processormenu"));
1413 Glib::RefPtr<Action> act;
1416 ActionManager::register_action (popup_act_grp, X_("newplugin"), _("New Plugin"),
1417 sigc::ptr_fun (ProcessorBox::rb_choose_plugin));
1419 act = ActionManager::register_action (popup_act_grp, X_("newinsert"), _("New Insert"),
1420 sigc::ptr_fun (ProcessorBox::rb_choose_insert));
1421 ActionManager::jack_sensitive_actions.push_back (act);
1422 act = ActionManager::register_action (popup_act_grp, X_("newsend"), _("New Send ..."),
1423 sigc::ptr_fun (ProcessorBox::rb_choose_send));
1424 ActionManager::jack_sensitive_actions.push_back (act);
1425 act = ActionManager::register_action (popup_act_grp, X_("newreturn"), _("New Return ..."),
1426 sigc::ptr_fun (ProcessorBox::rb_choose_return));
1427 ActionManager::jack_sensitive_actions.push_back (act);
1429 ActionManager::register_action (popup_act_grp, X_("clear"), _("Clear"),
1430 sigc::ptr_fun (ProcessorBox::rb_clear));
1432 /* standard editing stuff */
1433 act = ActionManager::register_action (popup_act_grp, X_("cut"), _("Cut"),
1434 sigc::ptr_fun (ProcessorBox::rb_cut));
1435 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1436 act = ActionManager::register_action (popup_act_grp, X_("copy"), _("Copy"),
1437 sigc::ptr_fun (ProcessorBox::rb_copy));
1438 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1440 act = ActionManager::register_action (popup_act_grp, X_("delete"), _("Delete"),
1441 sigc::ptr_fun (ProcessorBox::rb_delete));
1442 ActionManager::plugin_selection_sensitive_actions.push_back(act); // ??
1444 paste_action = ActionManager::register_action (popup_act_grp, X_("paste"), _("Paste"),
1445 sigc::ptr_fun (ProcessorBox::rb_paste));
1446 act = ActionManager::register_action (popup_act_grp, X_("rename"), _("Rename"),
1447 sigc::ptr_fun (ProcessorBox::rb_rename));
1448 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1449 ActionManager::register_action (popup_act_grp, X_("selectall"), _("Select All"),
1450 sigc::ptr_fun (ProcessorBox::rb_select_all));
1451 ActionManager::register_action (popup_act_grp, X_("deselectall"), _("Deselect All"),
1452 sigc::ptr_fun (ProcessorBox::rb_deselect_all));
1455 act = ActionManager::register_action (popup_act_grp, X_("activate"), _("Activate"),
1456 sigc::ptr_fun (ProcessorBox::rb_activate));
1457 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1458 act = ActionManager::register_action (popup_act_grp, X_("deactivate"), _("Deactivate"),
1459 sigc::ptr_fun (ProcessorBox::rb_deactivate));
1460 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1461 ActionManager::register_action (popup_act_grp, X_("activate_all"), _("Activate all"),
1462 sigc::ptr_fun (ProcessorBox::rb_activate_all));
1463 ActionManager::register_action (popup_act_grp, X_("deactivate_all"), _("Deactivate all"),
1464 sigc::ptr_fun (ProcessorBox::rb_deactivate_all));
1467 act = ActionManager::register_action (popup_act_grp, X_("edit"), _("Edit"),
1468 sigc::ptr_fun (ProcessorBox::rb_edit));
1469 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1471 ActionManager::add_action_group (popup_act_grp);
1475 ProcessorBox::rb_choose_plugin ()
1477 if (_current_processor_box == 0) {
1480 _current_processor_box->choose_plugin ();
1484 ProcessorBox::rb_choose_insert ()
1486 if (_current_processor_box == 0) {
1489 _current_processor_box->choose_insert ();
1493 ProcessorBox::rb_choose_send ()
1495 if (_current_processor_box == 0) {
1498 _current_processor_box->choose_send ();
1502 ProcessorBox::rb_choose_return ()
1504 if (_current_processor_box == 0) {
1507 _current_processor_box->choose_return ();
1511 ProcessorBox::rb_clear ()
1513 if (_current_processor_box == 0) {
1517 _current_processor_box->clear_processors ();
1521 ProcessorBox::rb_cut ()
1523 if (_current_processor_box == 0) {
1527 _current_processor_box->cut_processors ();
1531 ProcessorBox::rb_delete ()
1533 if (_current_processor_box == 0) {
1537 _current_processor_box->delete_processors ();
1541 ProcessorBox::rb_copy ()
1543 if (_current_processor_box == 0) {
1546 _current_processor_box->copy_processors ();
1550 ProcessorBox::rb_paste ()
1552 if (_current_processor_box == 0) {
1556 _current_processor_box->paste_processors ();
1560 ProcessorBox::rb_rename ()
1562 if (_current_processor_box == 0) {
1565 _current_processor_box->rename_processors ();
1569 ProcessorBox::rb_select_all ()
1571 if (_current_processor_box == 0) {
1575 _current_processor_box->select_all_processors ();
1579 ProcessorBox::rb_deselect_all ()
1581 if (_current_processor_box == 0) {
1585 _current_processor_box->deselect_all_processors ();
1589 ProcessorBox::rb_activate ()
1591 if (_current_processor_box == 0) {
1595 _current_processor_box->for_selected_processors (&ProcessorBox::activate_processor);
1599 ProcessorBox::rb_deactivate ()
1601 if (_current_processor_box == 0) {
1604 _current_processor_box->for_selected_processors (&ProcessorBox::deactivate_processor);
1608 ProcessorBox::rb_activate_all ()
1610 if (_current_processor_box == 0) {
1614 _current_processor_box->all_processors_active (true);
1618 ProcessorBox::rb_deactivate_all ()
1620 if (_current_processor_box == 0) {
1623 _current_processor_box->all_processors_active (false);
1627 ProcessorBox::rb_edit ()
1629 if (_current_processor_box == 0) {
1633 _current_processor_box->for_selected_processors (&ProcessorBox::edit_processor);
1637 ProcessorBox::route_name_changed ()
1639 ENSURE_GUI_THREAD (mem_fun (*this, &ProcessorBox::route_name_changed));
1641 boost::shared_ptr<Processor> processor;
1642 boost::shared_ptr<PluginInsert> plugin_insert;
1643 boost::shared_ptr<Send> send;
1645 Gtk::TreeModel::Children children = model->children();
1647 for (Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
1648 Gtk::TreeModel::Row row = *iter;
1650 processor= row[columns.processor];
1652 void* gui = processor->get_gui();
1658 /* rename editor windows for sends and plugins */
1660 WindowTitle title (Glib::get_application_name());
1662 if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
1663 title += send->name();
1664 static_cast<Window*>(gui)->set_title (title.get_string());
1665 } else if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (processor)) != 0) {
1666 title += generate_processor_title (plugin_insert);
1667 static_cast<Window*>(gui)->set_title (title.get_string());
1673 ProcessorBox::generate_processor_title (boost::shared_ptr<PluginInsert> pi)
1675 string maker = pi->plugin()->maker() ? pi->plugin()->maker() : "";
1676 string::size_type email_pos;
1678 if ((email_pos = maker.find_first_of ('<')) != string::npos) {
1679 maker = maker.substr (0, email_pos - 1);
1682 if (maker.length() > 32) {
1683 maker = maker.substr (0, 32);
1687 return string_compose(_("%1: %2 (by %3)"), _route->name(), pi->name(), maker);