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>
43 #include "ardour/amp.h"
44 #include "ardour/ardour.h"
45 #include "ardour/audio_diskstream.h"
46 #include "ardour/audio_track.h"
47 #include "ardour/audioengine.h"
48 #include "ardour/internal_send.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 ();
178 /* new route: any existing block on processor redisplay must be meaningless */
179 no_processor_redisplay = false;
182 connections.push_back (_route->processors_changed.connect (
183 mem_fun(*this, &ProcessorBox::redisplay_processors)));
184 connections.push_back (_route->GoingAway.connect (
185 mem_fun (*this, &ProcessorBox::route_going_away)));
186 connections.push_back (_route->NameChanged.connect (
187 mem_fun(*this, &ProcessorBox::route_name_changed)));
189 redisplay_processors ();
193 ProcessorBox::route_going_away ()
195 /* don't keep updating display as processors are deleted */
196 no_processor_redisplay = true;
201 ProcessorBox::object_drop (const list<boost::shared_ptr<Processor> >& procs, Gtk::TreeView* source, int x, int y, Glib::RefPtr<Gdk::DragContext>& context)
204 TreeModel::Path path;
205 TreeViewColumn* column;
208 boost::shared_ptr<Processor> p;
210 if (processor_display.get_path_at_pos (x, y, path, column, cellx, celly)) {
211 if ((iter = model->get_iter (path))) {
212 p = (*iter)[columns.processor];
216 for (list<boost::shared_ptr<Processor> >::const_iterator i = procs.begin(); i != procs.end(); ++i) {
217 XMLNode& state = (*i)->get_state ();
219 nlist.push_back (&state);
220 paste_processor_state (nlist, p);
224 /* since the treeview doesn't take care of this properly, we have to delete the originals
228 if ((context->get_suggested_action() == Gdk::ACTION_MOVE) && source) {
229 ProcessorBox* other = reinterpret_cast<ProcessorBox*> (source->get_data ("processorbox"));
231 cerr << "source was another processor box, delete the selected items\n";
232 other->delete_dragged_processors (procs);
236 context->drag_finish (true, (context->get_suggested_action() == Gdk::ACTION_MOVE), 0);
240 ProcessorBox::update()
242 redisplay_processors ();
247 ProcessorBox::set_width (Width w)
254 redisplay_processors ();
258 ProcessorBox::remove_processor_gui (boost::shared_ptr<Processor> processor)
260 boost::shared_ptr<Send> send;
261 boost::shared_ptr<Return> retrn;
262 boost::shared_ptr<PortInsert> port_insert;
264 if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (processor)) != 0) {
265 PortInsertUI *io_selector = reinterpret_cast<PortInsertUI *> (port_insert->get_gui());
266 port_insert->set_gui (0);
268 } else if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
269 SendUIWindow *sui = reinterpret_cast<SendUIWindow*> (send->get_gui());
272 } else if ((retrn = boost::dynamic_pointer_cast<Return> (processor)) != 0) {
273 ReturnUIWindow *rui = reinterpret_cast<ReturnUIWindow*> (retrn->get_gui());
280 ProcessorBox::build_send_action_menu ()
282 using namespace Menu_Helpers;
284 send_action_menu = new Menu;
285 send_action_menu->set_name ("ArdourContextMenu");
286 MenuList& items = send_action_menu->items();
288 items.push_back (MenuElem (_("New send"), mem_fun(*this, &ProcessorBox::new_send)));
289 items.push_back (MenuElem (_("Show send controls"), mem_fun(*this, &ProcessorBox::show_send_controls)));
293 ProcessorBox::show_send_controls ()
298 ProcessorBox::new_send ()
303 ProcessorBox::show_processor_menu (gint arg)
305 if (processor_menu == 0) {
306 processor_menu = build_processor_menu ();
309 Gtk::MenuItem* plugin_menu_item = dynamic_cast<Gtk::MenuItem*>(ActionManager::get_widget("/processormenu/newplugin"));
311 if (plugin_menu_item) {
312 plugin_menu_item->set_submenu (_plugin_selector.plugin_menu());
315 paste_action->set_sensitive (!_rr_selection.processors.empty());
317 processor_menu->popup (1, arg);
321 ProcessorBox::processor_drag_begin (GdkDragContext *)
323 processor_drag_in_progress = true;
327 ProcessorBox::processor_drag_end (GdkDragContext *)
329 processor_drag_in_progress = false;
333 ProcessorBox::enter_notify (GdkEventCrossing*)
335 _current_processor_box = this;
336 Keyboard::magic_widget_grab_focus ();
337 processor_display.grab_focus ();
343 ProcessorBox::leave_notify (GdkEventCrossing* ev)
345 switch (ev->detail) {
346 case GDK_NOTIFY_INFERIOR:
349 Keyboard::magic_widget_drop_focus ();
356 ProcessorBox::processor_key_press_event (GdkEventKey *)
358 /* do real stuff on key release */
363 ProcessorBox::processor_key_release_event (GdkEventKey *ev)
366 ProcSelection targets;
368 get_selected_processors (targets);
370 if (targets.empty()) {
374 TreeModel::Path path;
375 TreeViewColumn* column;
379 processor_display.get_pointer (x, y);
381 if (processor_display.get_path_at_pos (x, y, path, column, cellx, celly)) {
382 if ((iter = model->get_iter (path))) {
383 targets.push_back ((*iter)[columns.processor]);
389 switch (ev->keyval) {
391 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
392 copy_processors (targets);
397 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
398 cut_processors (targets);
403 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
404 if (targets.empty()) {
407 paste_processors (targets.front());
414 delete_processors (targets);
419 for (ProcSelection::iterator i = targets.begin(); i != targets.end(); ++i) {
420 if ((*i)->active()) {
437 ProcessorBox::processor_button_press_event (GdkEventButton *ev)
440 TreeModel::Path path;
441 TreeViewColumn* column;
444 boost::shared_ptr<Processor> processor;
446 bool selected = false;
448 if (processor_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
449 if ((iter = model->get_iter (path))) {
450 processor = (*iter)[columns.processor];
451 selected = processor_display.get_selection()->is_selected (iter);
456 if (processor && (Keyboard::is_edit_event (ev) || (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS))) {
458 if (_session.engine().connected()) {
459 /* XXX giving an error message here is hard, because we may be in the midst of a button press */
460 edit_processor (processor);
464 } else if (processor && ev->button == 1 && selected) {
466 // this is purely informational but necessary for route params UI
467 ProcessorSelected (processor); // emit
469 } else if (!processor && ev->button == 1 && ev->type == GDK_2BUTTON_PRESS) {
472 _plugin_selector.show_manager ();
480 ProcessorBox::processor_button_release_event (GdkEventButton *ev)
483 TreeModel::Path path;
484 TreeViewColumn* column;
487 boost::shared_ptr<Processor> processor;
490 if (processor_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
491 if ((iter = model->get_iter (path))) {
492 processor = (*iter)[columns.processor];
496 if (processor && Keyboard::is_delete_event (ev)) {
498 Glib::signal_idle().connect (bind (
499 mem_fun(*this, &ProcessorBox::idle_delete_processor),
500 boost::weak_ptr<Processor>(processor)));
503 } else if (Keyboard::is_context_menu_event (ev)) {
505 /* figure out if we are above or below the fader/amp processor,
506 and set the next insert position appropriately.
510 if (_route->processor_is_prefader (processor)) {
511 _placement = PreFader;
513 _placement = PostFader;
516 _placement = PostFader;
519 show_processor_menu (ev->time);
522 } else if (processor && Keyboard::is_button2_event (ev)
524 && (Keyboard::no_modifier_keys_pressed (ev) && ((ev->state & Gdk::BUTTON2_MASK) == Gdk::BUTTON2_MASK))
528 /* button2-click with no/appropriate modifiers */
530 if (processor->active()) {
531 processor->deactivate ();
533 processor->activate ();
543 ProcessorBox::build_processor_menu ()
545 processor_menu = dynamic_cast<Gtk::Menu*>(ActionManager::get_widget("/processormenu") );
546 processor_menu->set_name ("ArdourContextMenu");
550 return processor_menu;
554 ProcessorBox::selection_changed ()
556 bool sensitive = (processor_display.get_selection()->count_selected_rows()) ? true : false;
557 ActionManager::set_sensitive (ActionManager::plugin_selection_sensitive_actions, sensitive);
561 ProcessorBox::select_all_processors ()
563 processor_display.get_selection()->select_all();
567 ProcessorBox::deselect_all_processors ()
569 processor_display.get_selection()->unselect_all();
573 ProcessorBox::choose_plugin ()
575 _plugin_selector.set_interested_object (*this);
579 ProcessorBox::use_plugins (const SelectedPlugins& plugins)
581 for (SelectedPlugins::const_iterator p = plugins.begin(); p != plugins.end(); ++p) {
583 boost::shared_ptr<Processor> processor (new PluginInsert (_session, *p));
585 Route::ProcessorStreams err_streams;
587 if (Config->get_new_plugins_active()) {
588 processor->activate ();
591 if (_route->add_processor (processor, _placement, &err_streams)) {
592 weird_plugin_dialog (**p, err_streams);
593 // XXX SHAREDPTR delete plugin here .. do we even need to care?
596 if (Profile->get_sae()) {
597 processor->activate ();
599 processor->ActiveChanged.connect (bind (
600 mem_fun (*this, &ProcessorBox::show_processor_active),
601 boost::weak_ptr<Processor>(processor)));
607 ProcessorBox::weird_plugin_dialog (Plugin& p, Route::ProcessorStreams streams)
609 ArdourDialog dialog (_("ardour: weird plugin dialog"));
612 string text = string_compose(_("You attempted to add the plugin \"%1\" at index %2.\n"),
613 p.name(), streams.index);
615 bool has_midi = streams.count.n_midi() > 0 || p.get_info()->n_inputs.n_midi() > 0;
616 bool has_audio = streams.count.n_audio() > 0 || p.get_info()->n_inputs.n_audio() > 0;
618 text += _("\nThis plugin has:\n");
620 text += string_compose("\t%1 ", p.get_info()->n_inputs.n_midi()) + _("MIDI input(s)\n");
623 text += string_compose("\t%1 ", p.get_info()->n_inputs.n_audio()) + _("audio input(s)\n");
626 text += _("\nBut at the insertion point, there are:\n");
628 text += string_compose("\t%1 ", streams.count.n_midi()) + _("MIDI channel(s)\n");
631 text += string_compose("\t%1 ", streams.count.n_audio()) + _("audio channel(s)\n");
634 text += _("\nArdour is unable to insert this plugin here.\n");
635 label.set_text(text);
637 dialog.get_vbox()->pack_start (label);
638 dialog.add_button (Stock::OK, RESPONSE_ACCEPT);
640 dialog.set_name (X_("PluginIODialog"));
641 dialog.set_position (Gtk::WIN_POS_MOUSE);
642 dialog.set_modal (true);
649 ProcessorBox::choose_insert ()
651 boost::shared_ptr<Processor> processor (new PortInsert (_session, _route->mute_master()));
652 processor->ActiveChanged.connect (bind (mem_fun(*this, &ProcessorBox::show_processor_active),
653 boost::weak_ptr<Processor>(processor)));
655 _route->add_processor (processor, _placement);
659 ProcessorBox::choose_send ()
661 boost::shared_ptr<Send> send (new Send (_session, _route->mute_master()));
663 /* make an educated guess at the initial number of outputs for the send */
664 ChanCount outs = (_session.master_out())
665 ? _session.master_out()->n_outputs()
666 : _route->n_outputs();
668 /* XXX need processor lock on route */
670 send->output()->ensure_io (outs, false, this);
671 } catch (AudioEngine::PortRegistrationFailure& err) {
672 error << string_compose (_("Cannot set up new send: %1"), err.what()) << endmsg;
676 /* let the user adjust the IO setup before creation.
678 Note: this dialog is NOT modal - we just leave it to run and it will
679 return when its Finished signal is emitted - typically when the window
683 IOSelectorWindow *ios = new IOSelectorWindow (_session, send->output(), true);
686 /* keep a reference to the send so it doesn't get deleted while
687 the IOSelectorWindow is doing its stuff
689 _processor_being_created = send;
691 ios->selector().Finished.connect (bind (
692 mem_fun(*this, &ProcessorBox::send_io_finished),
693 boost::weak_ptr<Processor>(send), ios));
698 ProcessorBox::send_io_finished (IOSelector::Result r, boost::weak_ptr<Processor> weak_processor, IOSelectorWindow* ios)
700 boost::shared_ptr<Processor> processor (weak_processor.lock());
702 /* drop our temporary reference to the new send */
703 _processor_being_created.reset ();
710 case IOSelector::Cancelled:
711 // processor will go away when all shared_ptrs to it vanish
714 case IOSelector::Accepted:
715 _route->add_processor (processor, _placement);
716 if (Profile->get_sae()) {
717 processor->activate ();
722 delete_when_idle (ios);
726 ProcessorBox::choose_return ()
728 boost::shared_ptr<Return> retrn (new Return (_session));
730 /* assume user just wants a single audio input (sidechain) by default */
731 ChanCount ins(DataType::AUDIO, 1);
733 /* XXX need processor lock on route */
735 retrn->input()->ensure_io (ins, false, this);
736 } catch (AudioEngine::PortRegistrationFailure& err) {
737 error << string_compose (_("Cannot set up new return: %1"), err.what()) << endmsg;
741 /* let the user adjust the IO setup before creation */
742 IOSelectorWindow *ios = new IOSelectorWindow (_session, retrn->input(), true);
745 /* keep a reference to the return so it doesn't get deleted while
746 the IOSelectorWindow is doing its stuff */
747 _processor_being_created = retrn;
749 ios->selector().Finished.connect (bind (
750 mem_fun(*this, &ProcessorBox::return_io_finished),
751 boost::weak_ptr<Processor>(retrn), ios));
755 ProcessorBox::return_io_finished (IOSelector::Result r, boost::weak_ptr<Processor> weak_processor, IOSelectorWindow* ios)
757 boost::shared_ptr<Processor> processor (weak_processor.lock());
759 /* drop our temporary reference to the new return */
760 _processor_being_created.reset ();
767 case IOSelector::Cancelled:
768 // processor will go away when all shared_ptrs to it vanish
771 case IOSelector::Accepted:
772 _route->add_processor (processor, _placement);
773 if (Profile->get_sae()) {
774 processor->activate ();
779 delete_when_idle (ios);
783 ProcessorBox::redisplay_processors ()
785 ENSURE_GUI_THREAD (mem_fun(*this, &ProcessorBox::redisplay_processors));
787 if (no_processor_redisplay) {
791 ignore_delete = true;
793 ignore_delete = false;
795 processor_active_connections.clear ();
796 processor_name_connections.clear ();
798 _route->foreach_processor (mem_fun (*this, &ProcessorBox::add_processor_to_display));
800 build_processor_tooltip (processor_eventbox, _("Inserts, sends & plugins:"));
804 ProcessorBox::add_processor_to_display (boost::weak_ptr<Processor> p)
806 boost::shared_ptr<Processor> processor (p.lock ());
811 if (!processor->visible()) {
815 Gtk::TreeModel::Row row = *(model->append());
816 row[columns.text] = processor_name (processor);
817 row[columns.processor] = processor;
819 show_processor_active (processor);
821 processor_active_connections.push_back (processor->ActiveChanged.connect (bind (
822 mem_fun(*this, &ProcessorBox::show_processor_active),
823 boost::weak_ptr<Processor>(processor))));
824 processor_name_connections.push_back (processor->NameChanged.connect (bind (
825 mem_fun(*this, &ProcessorBox::show_processor_name),
826 boost::weak_ptr<Processor>(processor))));
830 ProcessorBox::processor_name (boost::weak_ptr<Processor> weak_processor)
832 boost::shared_ptr<Processor> processor (weak_processor.lock());
838 boost::shared_ptr<Send> send;
841 if (!processor->active()) {
845 if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0 &&
846 !boost::dynamic_pointer_cast<InternalSend>(processor)) {
850 /* grab the send name out of its overall name */
852 string::size_type lbracket, rbracket;
853 lbracket = send->name().find ('[');
854 rbracket = send->name().find (']');
858 name_display += send->name().substr (lbracket+1, lbracket-rbracket-1);
861 name_display += PBD::short_version (send->name().substr (lbracket+1, lbracket-rbracket-1), 4);
869 name_display += processor->display_name();
872 name_display += PBD::short_version (processor->display_name(), 5);
878 if (!processor->active()) {
886 ProcessorBox::build_processor_tooltip (EventBox& box, string start)
890 Gtk::TreeModel::Children children = model->children();
891 for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
892 Gtk::TreeModel::Row row = *iter;
894 tip += row[columns.text];
896 ARDOUR_UI::instance()->tooltips().set_tip (box, tip);
900 ProcessorBox::show_processor_name (boost::weak_ptr<Processor> processor)
902 ENSURE_GUI_THREAD(bind (mem_fun(*this, &ProcessorBox::show_processor_name), processor));
903 show_processor_active (processor);
907 ProcessorBox::show_processor_active (boost::weak_ptr<Processor> weak_processor)
909 boost::shared_ptr<Processor> processor (weak_processor.lock());
915 ENSURE_GUI_THREAD(bind (mem_fun(*this, &ProcessorBox::show_processor_active), weak_processor));
917 Gtk::TreeModel::Children children = model->children();
918 Gtk::TreeModel::Children::iterator iter = children.begin();
920 while (iter != children.end()) {
922 boost::shared_ptr<Processor> r = (*iter)[columns.processor];
924 if (r == processor) {
925 (*iter)[columns.text] = processor_name (r);
927 if (processor->active()) {
928 (*iter)[columns.color] = *active_processor_color;
930 (*iter)[columns.color] = *inactive_processor_color;
940 ProcessorBox::row_deleted (const Gtk::TreeModel::Path &)
942 if (!ignore_delete) {
943 compute_processor_sort_keys ();
948 ProcessorBox::compute_processor_sort_keys ()
950 Gtk::TreeModel::Children children = model->children();
951 Route::ProcessorList our_processors;
953 for (Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
954 boost::shared_ptr<Processor> p = (*iter)[columns.processor];
955 our_processors.push_back ((*iter)[columns.processor]);
958 if (_route->reorder_processors (our_processors)) {
960 /* reorder failed, so redisplay */
962 redisplay_processors ();
964 /* now tell them about the problem */
966 ArdourDialog dialog (_("ardour: weird plugin dialog"));
970 You cannot reorder this set of processors\n\
971 in that way because the inputs and\n\
972 outputs do not work correctly."));
974 dialog.get_vbox()->pack_start (label);
975 dialog.add_button (Stock::OK, RESPONSE_ACCEPT);
977 dialog.set_name (X_("PluginIODialog"));
978 dialog.set_position (Gtk::WIN_POS_MOUSE);
979 dialog.set_modal (true);
987 ProcessorBox::rename_processors ()
989 ProcSelection to_be_renamed;
991 get_selected_processors (to_be_renamed);
993 if (to_be_renamed.empty()) {
997 for (ProcSelection::iterator i = to_be_renamed.begin(); i != to_be_renamed.end(); ++i) {
998 rename_processor (*i);
1003 ProcessorBox::cut_processors ()
1005 ProcSelection to_be_removed;
1007 get_selected_processors (to_be_removed);
1011 ProcessorBox::cut_processors (const ProcSelection& to_be_removed)
1013 if (to_be_removed.empty()) {
1017 XMLNode* node = new XMLNode (X_("cut"));
1018 Route::ProcessorList to_cut;
1020 no_processor_redisplay = true;
1021 for (ProcSelection::const_iterator i = to_be_removed.begin(); i != to_be_removed.end(); ++i) {
1022 // Cut only plugins, sends and returns
1023 if (boost::dynamic_pointer_cast<PluginInsert>((*i)) != 0 ||
1024 (boost::dynamic_pointer_cast<Send>((*i)) != 0) ||
1025 (boost::dynamic_pointer_cast<Return>((*i)) != 0)) {
1027 void* gui = (*i)->get_gui ();
1030 static_cast<Gtk::Widget*>(gui)->hide ();
1033 XMLNode& child ((*i)->get_state());
1034 node->add_child_nocopy (child);
1035 to_cut.push_back (*i);
1039 if (_route->remove_processors (to_cut) != 0) {
1041 no_processor_redisplay = false;
1045 _rr_selection.set (node);
1047 no_processor_redisplay = false;
1048 redisplay_processors ();
1052 ProcessorBox::copy_processors ()
1054 ProcSelection to_be_copied;
1055 get_selected_processors (to_be_copied);
1056 copy_processors (to_be_copied);
1060 ProcessorBox::copy_processors (const ProcSelection& to_be_copied)
1062 if (to_be_copied.empty()) {
1066 XMLNode* node = new XMLNode (X_("copy"));
1068 for (ProcSelection::const_iterator i = to_be_copied.begin(); i != to_be_copied.end(); ++i) {
1069 // Copy only plugins, sends, returns
1070 if (boost::dynamic_pointer_cast<PluginInsert>((*i)) != 0 ||
1071 (boost::dynamic_pointer_cast<Send>((*i)) != 0) ||
1072 (boost::dynamic_pointer_cast<Return>((*i)) != 0)) {
1073 node->add_child_nocopy ((*i)->get_state());
1077 _rr_selection.set (node);
1081 ProcessorBox::delete_processors ()
1083 ProcSelection to_be_deleted;
1084 get_selected_processors (to_be_deleted);
1085 delete_processors (to_be_deleted);
1089 ProcessorBox::delete_processors (const ProcSelection& targets)
1091 if (targets.empty()) {
1095 no_processor_redisplay = true;
1097 for (ProcSelection::const_iterator i = targets.begin(); i != targets.end(); ++i) {
1099 void* gui = (*i)->get_gui ();
1102 static_cast<Gtk::Widget*>(gui)->hide ();
1105 _route->remove_processor(*i);
1108 no_processor_redisplay = false;
1109 redisplay_processors ();
1113 ProcessorBox::delete_dragged_processors (const list<boost::shared_ptr<Processor> >& procs)
1115 list<boost::shared_ptr<Processor> >::const_iterator x;
1117 no_processor_redisplay = true;
1118 for (x = procs.begin(); x != procs.end(); ++x) {
1120 void* gui = (*x)->get_gui ();
1123 static_cast<Gtk::Widget*>(gui)->hide ();
1126 _route->remove_processor(*x);
1129 no_processor_redisplay = false;
1130 redisplay_processors ();
1134 ProcessorBox::idle_delete_processor (boost::weak_ptr<Processor> weak_processor)
1136 boost::shared_ptr<Processor> processor (weak_processor.lock());
1142 /* NOT copied to _mixer.selection() */
1144 no_processor_redisplay = true;
1145 _route->remove_processor (processor);
1146 no_processor_redisplay = false;
1147 redisplay_processors ();
1153 ProcessorBox::rename_processor (boost::shared_ptr<Processor> processor)
1155 ArdourPrompter name_prompter (true);
1157 name_prompter.set_prompt (_("rename processor"));
1158 name_prompter.set_initial_text (processor->name());
1159 name_prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
1160 name_prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
1161 name_prompter.show_all ();
1163 switch (name_prompter.run ()) {
1165 case Gtk::RESPONSE_ACCEPT:
1166 name_prompter.get_result (result);
1167 if (result.length()) {
1168 if (_session.route_by_name (result)) {
1169 ARDOUR_UI::instance()->popup_error (_("A track already exists with that name"));
1172 processor->set_name (result);
1181 ProcessorBox::paste_processors ()
1183 if (_rr_selection.processors.empty()) {
1187 paste_processor_state (_rr_selection.processors.get_node().children(), boost::shared_ptr<Processor>());
1191 ProcessorBox::paste_processors (boost::shared_ptr<Processor> before)
1194 if (_rr_selection.processors.empty()) {
1198 paste_processor_state (_rr_selection.processors.get_node().children(), before);
1202 ProcessorBox::paste_processor_state (const XMLNodeList& nlist, boost::shared_ptr<Processor> p)
1204 XMLNodeConstIterator niter;
1205 list<boost::shared_ptr<Processor> > copies;
1207 if (nlist.empty()) {
1211 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1213 XMLProperty const * type = (*niter)->property ("type");
1216 boost::shared_ptr<Processor> p;
1218 if (type->value() == "meter" ||
1219 type->value() == "main-outs" ||
1220 type->value() == "amp" ||
1221 type->value() == "intsend" || type->value() == "intreturn") {
1222 /* do not paste meter, main outs, amp or internal send/returns */
1225 } else if (type->value() == "send") {
1227 XMLNode n (**niter);
1228 Send::make_unique (n, _session);
1229 p.reset (new Send (_session, _route->mute_master(), n));
1231 } else if (type->value() == "return") {
1233 XMLNode n (**niter);
1234 Return::make_unique (n, _session);
1235 p.reset (new Return (_session, **niter));
1238 /* XXX its a bit limiting to assume that everything else
1241 p.reset (new PluginInsert (_session, **niter));
1244 copies.push_back (p);
1248 cerr << "plugin insert constructor failed\n";
1252 if (copies.empty()) {
1256 if (_route->add_processors (copies, p)) {
1259 "Copying the set of processors on the clipboard failed,\n\
1260 probably because the I/O configuration of the plugins\n\
1261 could not match the configuration of this track.");
1262 MessageDialog am (msg);
1268 ProcessorBox::activate_processor (boost::shared_ptr<Processor> r)
1274 ProcessorBox::deactivate_processor (boost::shared_ptr<Processor> r)
1280 ProcessorBox::get_selected_processors (ProcSelection& processors)
1282 vector<Gtk::TreeModel::Path> pathlist = processor_display.get_selection()->get_selected_rows();
1284 for (vector<Gtk::TreeModel::Path>::iterator iter = pathlist.begin(); iter != pathlist.end(); ++iter) {
1285 processors.push_back ((*(model->get_iter(*iter)))[columns.processor]);
1290 ProcessorBox::for_selected_processors (void (ProcessorBox::*method)(boost::shared_ptr<Processor>))
1292 vector<Gtk::TreeModel::Path> pathlist = processor_display.get_selection()->get_selected_rows();
1294 for (vector<Gtk::TreeModel::Path>::iterator iter = pathlist.begin(); iter != pathlist.end(); ++iter) {
1295 boost::shared_ptr<Processor> processor = (*(model->get_iter(*iter)))[columns.processor];
1296 (this->*method)(processor);
1301 ProcessorBox::all_processors_active (bool state)
1303 _route->all_processors_active (_placement, state);
1307 ProcessorBox::ab_plugins ()
1309 _route->ab_plugins (ab_direction);
1310 ab_direction = !ab_direction;
1315 ProcessorBox::clear_processors ()
1318 vector<string> choices;
1320 prompt = string_compose (_("Do you really want to remove all processors from %1?\n"
1321 "(this cannot be undone)"), _route->name());
1323 choices.push_back (_("Cancel"));
1324 choices.push_back (_("Yes, remove them all"));
1326 Gtkmm2ext::Choice prompter (prompt, choices);
1328 if (prompter.run () == 1) {
1329 _route->clear_processors (PreFader);
1330 _route->clear_processors (PostFader);
1335 ProcessorBox::clear_processors (Placement p)
1338 vector<string> choices;
1340 if (p == PreFader) {
1341 prompt = string_compose (_("Do you really want to remove all pre-fader processors from %1?\n"
1342 "(this cannot be undone)"), _route->name());
1344 prompt = string_compose (_("Do you really want to remove all post-fader processors from %1?\n"
1345 "(this cannot be undone)"), _route->name());
1348 choices.push_back (_("Cancel"));
1349 choices.push_back (_("Yes, remove them all"));
1351 Gtkmm2ext::Choice prompter (prompt, choices);
1353 if (prompter.run () == 1) {
1354 _route->clear_processors (p);
1359 ProcessorBox::edit_processor (boost::shared_ptr<Processor> processor)
1361 boost::shared_ptr<Send> send;
1362 boost::shared_ptr<Return> retrn;
1363 boost::shared_ptr<PluginInsert> plugin_insert;
1364 boost::shared_ptr<PortInsert> port_insert;
1367 if (boost::dynamic_pointer_cast<AudioTrack>(_route) != 0) {
1369 if (boost::dynamic_pointer_cast<AudioTrack> (_route)->freeze_state() == AudioTrack::Frozen) {
1374 if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
1376 if (!_session.engine().connected()) {
1380 #ifdef OLD_SEND_EDITING
1381 SendUIWindow *send_ui;
1383 if (send->get_gui() == 0) {
1384 send_ui = new SendUIWindow (send, _session);
1385 send_ui->set_title (send->name());
1386 send->set_gui (send_ui);
1389 send_ui = reinterpret_cast<SendUIWindow *> (send->get_gui());
1394 if (_parent_strip) {
1395 _parent_strip->gain_meter().set_controls (_route, send->meter(), send->amp());
1396 _parent_strip->panner_ui().set_panner (send->panner());
1400 } else if ((retrn = boost::dynamic_pointer_cast<Return> (processor)) != 0) {
1402 if (!_session.engine().connected()) {
1406 boost::shared_ptr<Return> retrn = boost::dynamic_pointer_cast<Return> (processor);
1408 ReturnUIWindow *return_ui;
1410 if (retrn->get_gui() == 0) {
1412 return_ui = new ReturnUIWindow (retrn, _session);
1413 return_ui->set_title (retrn->name ());
1414 send->set_gui (return_ui);
1417 return_ui = reinterpret_cast<ReturnUIWindow *> (retrn->get_gui());
1422 } else if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (processor)) != 0) {
1424 PluginUIWindow *plugin_ui;
1426 /* these are both allowed to be null */
1428 Container* toplevel = get_toplevel();
1429 Window* win = dynamic_cast<Gtk::Window*>(toplevel);
1431 if (plugin_insert->get_gui() == 0) {
1433 plugin_ui = new PluginUIWindow (win, plugin_insert);
1434 plugin_ui->set_title (generate_processor_title (plugin_insert));
1435 plugin_insert->set_gui (plugin_ui);
1438 plugin_ui = reinterpret_cast<PluginUIWindow *> (plugin_insert->get_gui());
1439 plugin_ui->set_parent (win);
1444 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (processor)) != 0) {
1446 if (!_session.engine().connected()) {
1447 MessageDialog msg ( _("Not connected to JACK - no I/O changes are possible"));
1452 PortInsertWindow *io_selector;
1454 if (port_insert->get_gui() == 0) {
1455 io_selector = new PortInsertWindow (_session, port_insert);
1456 port_insert->set_gui (io_selector);
1459 io_selector = reinterpret_cast<PortInsertWindow *> (port_insert->get_gui());
1462 gidget = io_selector;
1466 if (gidget->is_visible()) {
1467 gidget->get_window()->raise ();
1469 gidget->show_all ();
1476 ProcessorBox::register_actions ()
1478 Glib::RefPtr<Gtk::ActionGroup> popup_act_grp = Gtk::ActionGroup::create(X_("processormenu"));
1479 Glib::RefPtr<Action> act;
1482 ActionManager::register_action (popup_act_grp, X_("newplugin"), _("New Plugin"),
1483 sigc::ptr_fun (ProcessorBox::rb_choose_plugin));
1485 act = ActionManager::register_action (popup_act_grp, X_("newinsert"), _("New Insert"),
1486 sigc::ptr_fun (ProcessorBox::rb_choose_insert));
1487 ActionManager::jack_sensitive_actions.push_back (act);
1488 act = ActionManager::register_action (popup_act_grp, X_("newsend"), _("New Send ..."),
1489 sigc::ptr_fun (ProcessorBox::rb_choose_send));
1490 ActionManager::jack_sensitive_actions.push_back (act);
1491 act = ActionManager::register_action (popup_act_grp, X_("newreturn"), _("New Return ..."),
1492 sigc::ptr_fun (ProcessorBox::rb_choose_return));
1493 ActionManager::jack_sensitive_actions.push_back (act);
1495 ActionManager::register_action (popup_act_grp, X_("clear"), _("Clear (all)"),
1496 sigc::ptr_fun (ProcessorBox::rb_clear));
1497 ActionManager::register_action (popup_act_grp, X_("clear_pre"), _("Clear (pre-fader)"),
1498 sigc::ptr_fun (ProcessorBox::rb_clear_pre));
1499 ActionManager::register_action (popup_act_grp, X_("clear_post"), _("Clear (post-fader)"),
1500 sigc::ptr_fun (ProcessorBox::rb_clear_post));
1502 /* standard editing stuff */
1503 act = ActionManager::register_action (popup_act_grp, X_("cut"), _("Cut"),
1504 sigc::ptr_fun (ProcessorBox::rb_cut));
1505 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1506 act = ActionManager::register_action (popup_act_grp, X_("copy"), _("Copy"),
1507 sigc::ptr_fun (ProcessorBox::rb_copy));
1508 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1510 act = ActionManager::register_action (popup_act_grp, X_("delete"), _("Delete"),
1511 sigc::ptr_fun (ProcessorBox::rb_delete));
1512 ActionManager::plugin_selection_sensitive_actions.push_back(act); // ??
1514 paste_action = ActionManager::register_action (popup_act_grp, X_("paste"), _("Paste"),
1515 sigc::ptr_fun (ProcessorBox::rb_paste));
1516 act = ActionManager::register_action (popup_act_grp, X_("rename"), _("Rename"),
1517 sigc::ptr_fun (ProcessorBox::rb_rename));
1518 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1519 ActionManager::register_action (popup_act_grp, X_("selectall"), _("Select All"),
1520 sigc::ptr_fun (ProcessorBox::rb_select_all));
1521 ActionManager::register_action (popup_act_grp, X_("deselectall"), _("Deselect All"),
1522 sigc::ptr_fun (ProcessorBox::rb_deselect_all));
1525 act = ActionManager::register_action (popup_act_grp, X_("activate"), _("Activate"),
1526 sigc::ptr_fun (ProcessorBox::rb_activate));
1527 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1528 act = ActionManager::register_action (popup_act_grp, X_("deactivate"), _("Deactivate"),
1529 sigc::ptr_fun (ProcessorBox::rb_deactivate));
1530 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1531 ActionManager::register_action (popup_act_grp, X_("activate_all"), _("Activate all"),
1532 sigc::ptr_fun (ProcessorBox::rb_activate_all));
1533 ActionManager::register_action (popup_act_grp, X_("deactivate_all"), _("Deactivate all"),
1534 sigc::ptr_fun (ProcessorBox::rb_deactivate_all));
1537 act = ActionManager::register_action (popup_act_grp, X_("edit"), _("Edit"),
1538 sigc::ptr_fun (ProcessorBox::rb_edit));
1539 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1541 ActionManager::add_action_group (popup_act_grp);
1545 ProcessorBox::rb_choose_plugin ()
1547 if (_current_processor_box == 0) {
1550 _current_processor_box->choose_plugin ();
1554 ProcessorBox::rb_choose_insert ()
1556 if (_current_processor_box == 0) {
1559 _current_processor_box->choose_insert ();
1563 ProcessorBox::rb_choose_send ()
1565 if (_current_processor_box == 0) {
1568 _current_processor_box->choose_send ();
1572 ProcessorBox::rb_choose_return ()
1574 if (_current_processor_box == 0) {
1577 _current_processor_box->choose_return ();
1581 ProcessorBox::rb_clear ()
1583 if (_current_processor_box == 0) {
1587 _current_processor_box->clear_processors ();
1592 ProcessorBox::rb_clear_pre ()
1594 if (_current_processor_box == 0) {
1598 _current_processor_box->clear_processors (PreFader);
1603 ProcessorBox::rb_clear_post ()
1605 if (_current_processor_box == 0) {
1609 _current_processor_box->clear_processors (PostFader);
1613 ProcessorBox::rb_cut ()
1615 if (_current_processor_box == 0) {
1619 _current_processor_box->cut_processors ();
1623 ProcessorBox::rb_delete ()
1625 if (_current_processor_box == 0) {
1629 _current_processor_box->delete_processors ();
1633 ProcessorBox::rb_copy ()
1635 if (_current_processor_box == 0) {
1638 _current_processor_box->copy_processors ();
1642 ProcessorBox::rb_paste ()
1644 if (_current_processor_box == 0) {
1648 _current_processor_box->paste_processors ();
1652 ProcessorBox::rb_rename ()
1654 if (_current_processor_box == 0) {
1657 _current_processor_box->rename_processors ();
1661 ProcessorBox::rb_select_all ()
1663 if (_current_processor_box == 0) {
1667 _current_processor_box->select_all_processors ();
1671 ProcessorBox::rb_deselect_all ()
1673 if (_current_processor_box == 0) {
1677 _current_processor_box->deselect_all_processors ();
1681 ProcessorBox::rb_activate ()
1683 if (_current_processor_box == 0) {
1687 _current_processor_box->for_selected_processors (&ProcessorBox::activate_processor);
1691 ProcessorBox::rb_deactivate ()
1693 if (_current_processor_box == 0) {
1696 _current_processor_box->for_selected_processors (&ProcessorBox::deactivate_processor);
1700 ProcessorBox::rb_activate_all ()
1702 if (_current_processor_box == 0) {
1706 _current_processor_box->all_processors_active (true);
1710 ProcessorBox::rb_deactivate_all ()
1712 if (_current_processor_box == 0) {
1715 _current_processor_box->all_processors_active (false);
1719 ProcessorBox::rb_edit ()
1721 if (_current_processor_box == 0) {
1725 _current_processor_box->for_selected_processors (&ProcessorBox::edit_processor);
1729 ProcessorBox::route_name_changed ()
1731 ENSURE_GUI_THREAD (mem_fun (*this, &ProcessorBox::route_name_changed));
1733 boost::shared_ptr<Processor> processor;
1734 boost::shared_ptr<PluginInsert> plugin_insert;
1735 boost::shared_ptr<Send> send;
1737 Gtk::TreeModel::Children children = model->children();
1739 for (Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
1740 Gtk::TreeModel::Row row = *iter;
1742 processor= row[columns.processor];
1744 void* gui = processor->get_gui();
1750 /* rename editor windows for sends and plugins */
1752 if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
1753 static_cast<Window*>(gui)->set_title (send->name ());
1754 } else if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (processor)) != 0) {
1755 static_cast<Window*>(gui)->set_title (generate_processor_title (plugin_insert));
1761 ProcessorBox::generate_processor_title (boost::shared_ptr<PluginInsert> pi)
1763 string maker = pi->plugin()->maker() ? pi->plugin()->maker() : "";
1764 string::size_type email_pos;
1766 if ((email_pos = maker.find_first_of ('<')) != string::npos) {
1767 maker = maker.substr (0, email_pos - 1);
1770 if (maker.length() > 32) {
1771 maker = maker.substr (0, 32);
1775 return string_compose(_("%1: %2 (by %3)"), _route->name(), pi->name(), maker);