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/internal_send.h"
50 #include "ardour/ladspa_plugin.h"
51 #include "ardour/meter.h"
52 #include "ardour/plugin_insert.h"
53 #include "ardour/port_insert.h"
54 #include "ardour/profile.h"
55 #include "ardour/return.h"
56 #include "ardour/route.h"
57 #include "ardour/send.h"
58 #include "ardour/session.h"
61 #include "ardour_dialog.h"
62 #include "ardour_ui.h"
63 #include "gui_thread.h"
64 #include "io_selector.h"
67 #include "mixer_strip.h"
68 #include "plugin_selector.h"
69 #include "plugin_ui.h"
70 #include "processor_box.h"
71 #include "public_editor.h"
72 #include "return_ui.h"
73 #include "route_processor_selection.h"
79 #ifdef HAVE_AUDIOUNITS
85 using namespace ARDOUR;
89 using namespace Gtkmm2ext;
91 ProcessorBox* ProcessorBox::_current_processor_box = 0;
92 RefPtr<Action> ProcessorBox::paste_action;
93 bool ProcessorBox::get_colors = true;
94 Gdk::Color* ProcessorBox::active_processor_color;
95 Gdk::Color* ProcessorBox::inactive_processor_color;
97 ProcessorBox::ProcessorBox (Session& sess, PluginSelector &plugsel,
98 RouteRedirectSelection & rsel, MixerStrip* parent, bool owner_is_mixer)
100 , _parent_strip (parent)
101 , _owner_is_mixer (owner_is_mixer)
102 , _placement(PreFader)
103 , _plugin_selector(plugsel)
104 , _rr_selection(rsel)
107 active_processor_color = new Gdk::Color;
108 inactive_processor_color = new Gdk::Color;
109 set_color (*active_processor_color, rgba_from_style (
110 "ProcessorSelector", 0xff, 0, 0, 0, "fg", Gtk::STATE_ACTIVE, false ));
111 set_color (*inactive_processor_color, rgba_from_style (
112 "ProcessorSelector", 0xff, 0, 0, 0, "fg", Gtk::STATE_NORMAL, false ));
118 send_action_menu = 0;
119 processor_drag_in_progress = false;
120 no_processor_redisplay = false;
121 ignore_delete = false;
123 model = ListStore::create(columns);
125 RefPtr<TreeSelection> selection = processor_display.get_selection();
126 selection->set_mode (Gtk::SELECTION_MULTIPLE);
127 selection->signal_changed().connect (mem_fun (*this, &ProcessorBox::selection_changed));
129 processor_display.set_data ("processorbox", this);
130 processor_display.set_model (model);
131 processor_display.append_column (X_("notshown"), columns.text);
132 processor_display.set_name ("ProcessorSelector");
133 processor_display.set_headers_visible (false);
134 processor_display.set_reorderable (true);
135 processor_display.set_size_request (-1, 40);
136 processor_display.get_column(0)->set_sizing(TREE_VIEW_COLUMN_FIXED);
137 processor_display.get_column(0)->set_fixed_width(48);
138 processor_display.add_object_drag (columns.processor.index(), "processors");
139 processor_display.set_enable_search (false);
140 processor_display.signal_drop.connect (mem_fun (*this, &ProcessorBox::object_drop));
142 TreeViewColumn* name_col = processor_display.get_column(0);
143 CellRendererText* renderer = dynamic_cast<CellRendererText*>(
144 processor_display.get_column_cell_renderer (0));
145 name_col->add_attribute(renderer->property_foreground_gdk(), columns.color);
147 processor_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
149 model->signal_row_deleted().connect (mem_fun (*this, &ProcessorBox::row_deleted));
151 processor_scroller.add (processor_display);
152 processor_eventbox.add (processor_scroller);
154 processor_scroller.set_size_request (-1, 40);
156 pack_start (processor_eventbox, true, true);
158 processor_display.signal_enter_notify_event().connect (mem_fun(*this, &ProcessorBox::enter_notify), false);
159 processor_display.signal_leave_notify_event().connect (mem_fun(*this, &ProcessorBox::leave_notify), false);
161 processor_display.signal_key_press_event().connect (mem_fun(*this, &ProcessorBox::processor_key_press_event));
162 processor_display.signal_key_release_event().connect (mem_fun(*this, &ProcessorBox::processor_key_release_event));
164 processor_display.signal_button_press_event().connect (
165 mem_fun(*this, &ProcessorBox::processor_button_press_event), false);
166 processor_display.signal_button_release_event().connect (
167 mem_fun(*this, &ProcessorBox::processor_button_release_event));
170 ProcessorBox::~ProcessorBox ()
175 ProcessorBox::set_route (boost::shared_ptr<Route> r)
177 connections.clear ();
181 connections.push_back (_route->processors_changed.connect (
182 mem_fun(*this, &ProcessorBox::redisplay_processors)));
183 connections.push_back (_route->GoingAway.connect (
184 mem_fun (*this, &ProcessorBox::route_going_away)));
185 connections.push_back (_route->NameChanged.connect (
186 mem_fun(*this, &ProcessorBox::route_name_changed)));
188 redisplay_processors ();
192 ProcessorBox::route_going_away ()
194 /* don't keep updating display as processors are deleted */
195 no_processor_redisplay = true;
200 ProcessorBox::object_drop (const list<boost::shared_ptr<Processor> >& procs, Gtk::TreeView* source, int x, int y, Glib::RefPtr<Gdk::DragContext>& context)
203 TreeModel::Path path;
204 TreeViewColumn* column;
207 boost::shared_ptr<Processor> p;
209 if (processor_display.get_path_at_pos (x, y, path, column, cellx, celly)) {
210 if ((iter = model->get_iter (path))) {
211 p = (*iter)[columns.processor];
215 for (list<boost::shared_ptr<Processor> >::const_iterator i = procs.begin(); i != procs.end(); ++i) {
216 XMLNode& state = (*i)->get_state ();
218 nlist.push_back (&state);
219 paste_processor_state (nlist, p);
223 /* since the treeview doesn't take care of this properly, we have to delete the originals
227 if ((context->get_suggested_action() == Gdk::ACTION_MOVE) && source) {
228 ProcessorBox* other = reinterpret_cast<ProcessorBox*> (source->get_data ("processorbox"));
230 cerr << "source was another processor box, delete the selected items\n";
231 other->delete_dragged_processors (procs);
235 context->drag_finish (true, (context->get_suggested_action() == Gdk::ACTION_MOVE), 0);
239 ProcessorBox::update()
241 redisplay_processors ();
246 ProcessorBox::set_width (Width w)
253 redisplay_processors ();
257 ProcessorBox::remove_processor_gui (boost::shared_ptr<Processor> processor)
259 boost::shared_ptr<Send> send;
260 boost::shared_ptr<Return> retrn;
261 boost::shared_ptr<PortInsert> port_insert;
263 if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (processor)) != 0) {
264 PortInsertUI *io_selector = reinterpret_cast<PortInsertUI *> (port_insert->get_gui());
265 port_insert->set_gui (0);
267 } else if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
268 SendUIWindow *sui = reinterpret_cast<SendUIWindow*> (send->get_gui());
271 } else if ((retrn = boost::dynamic_pointer_cast<Return> (processor)) != 0) {
272 ReturnUIWindow *rui = reinterpret_cast<ReturnUIWindow*> (retrn->get_gui());
279 ProcessorBox::build_send_action_menu ()
281 using namespace Menu_Helpers;
283 send_action_menu = new Menu;
284 send_action_menu->set_name ("ArdourContextMenu");
285 MenuList& items = send_action_menu->items();
287 items.push_back (MenuElem (_("New send"), mem_fun(*this, &ProcessorBox::new_send)));
288 items.push_back (MenuElem (_("Show send controls"), mem_fun(*this, &ProcessorBox::show_send_controls)));
292 ProcessorBox::show_send_controls ()
297 ProcessorBox::new_send ()
302 ProcessorBox::show_processor_menu (gint arg)
304 if (processor_menu == 0) {
305 processor_menu = build_processor_menu ();
308 Gtk::MenuItem* plugin_menu_item = dynamic_cast<Gtk::MenuItem*>(ActionManager::get_widget("/processormenu/newplugin"));
310 if (plugin_menu_item) {
311 plugin_menu_item->set_submenu (_plugin_selector.plugin_menu());
314 paste_action->set_sensitive (!_rr_selection.processors.empty());
316 processor_menu->popup (1, arg);
320 ProcessorBox::processor_drag_begin (GdkDragContext *context)
322 processor_drag_in_progress = true;
326 ProcessorBox::processor_drag_end (GdkDragContext *context)
328 processor_drag_in_progress = false;
332 ProcessorBox::enter_notify (GdkEventCrossing* ev)
334 _current_processor_box = this;
335 Keyboard::magic_widget_grab_focus ();
336 processor_display.grab_focus ();
342 ProcessorBox::leave_notify (GdkEventCrossing* ev)
344 switch (ev->detail) {
345 case GDK_NOTIFY_INFERIOR:
348 Keyboard::magic_widget_drop_focus ();
355 ProcessorBox::processor_key_press_event (GdkEventKey *ev)
357 /* do real stuff on key release */
362 ProcessorBox::processor_key_release_event (GdkEventKey *ev)
365 ProcSelection targets;
367 get_selected_processors (targets);
369 if (targets.empty()) {
373 TreeModel::Path path;
374 TreeViewColumn* column;
378 processor_display.get_pointer (x, y);
380 if (processor_display.get_path_at_pos (x, y, path, column, cellx, celly)) {
381 if ((iter = model->get_iter (path))) {
382 targets.push_back ((*iter)[columns.processor]);
388 switch (ev->keyval) {
390 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
391 copy_processors (targets);
396 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
397 cut_processors (targets);
402 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
403 if (targets.empty()) {
406 paste_processors (targets.front());
413 delete_processors (targets);
418 for (ProcSelection::iterator i = targets.begin(); i != targets.end(); ++i) {
419 if ((*i)->active()) {
436 ProcessorBox::processor_button_press_event (GdkEventButton *ev)
439 TreeModel::Path path;
440 TreeViewColumn* column;
443 boost::shared_ptr<Processor> processor;
445 bool selected = false;
447 if (processor_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
448 if ((iter = model->get_iter (path))) {
449 processor = (*iter)[columns.processor];
450 selected = processor_display.get_selection()->is_selected (iter);
455 if (processor && (Keyboard::is_edit_event (ev) || (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS))) {
457 if (_session.engine().connected()) {
458 /* XXX giving an error message here is hard, because we may be in the midst of a button press */
459 edit_processor (processor);
463 } else if (processor && ev->button == 1 && selected) {
465 // this is purely informational but necessary for route params UI
466 ProcessorSelected (processor); // emit
468 } else if (!processor && ev->button == 1 && ev->type == GDK_2BUTTON_PRESS) {
471 _plugin_selector.show_manager ();
479 ProcessorBox::processor_button_release_event (GdkEventButton *ev)
482 TreeModel::Path path;
483 TreeViewColumn* column;
486 boost::shared_ptr<Processor> processor;
489 if (processor_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
490 if ((iter = model->get_iter (path))) {
491 processor = (*iter)[columns.processor];
495 if (processor && Keyboard::is_delete_event (ev)) {
497 Glib::signal_idle().connect (bind (
498 mem_fun(*this, &ProcessorBox::idle_delete_processor),
499 boost::weak_ptr<Processor>(processor)));
502 } else if (Keyboard::is_context_menu_event (ev)) {
504 /* figure out if we are above or below the fader/amp processor,
505 and set the next insert position appropriately.
509 if (_route->processor_is_prefader (processor)) {
510 _placement = PreFader;
512 _placement = PostFader;
515 _placement = PostFader;
518 show_processor_menu (ev->time);
521 } else if (processor && Keyboard::is_button2_event (ev)
523 && (Keyboard::no_modifier_keys_pressed (ev) && ((ev->state & Gdk::BUTTON2_MASK) == Gdk::BUTTON2_MASK))
527 /* button2-click with no/appropriate modifiers */
529 if (processor->active()) {
530 processor->deactivate ();
532 processor->activate ();
542 ProcessorBox::build_processor_menu ()
544 processor_menu = dynamic_cast<Gtk::Menu*>(ActionManager::get_widget("/processormenu") );
545 processor_menu->set_name ("ArdourContextMenu");
549 return processor_menu;
553 ProcessorBox::selection_changed ()
555 bool sensitive = (processor_display.get_selection()->count_selected_rows()) ? true : false;
556 ActionManager::set_sensitive (ActionManager::plugin_selection_sensitive_actions, sensitive);
560 ProcessorBox::select_all_processors ()
562 processor_display.get_selection()->select_all();
566 ProcessorBox::deselect_all_processors ()
568 processor_display.get_selection()->unselect_all();
572 ProcessorBox::choose_plugin ()
574 _plugin_selector.set_interested_object (*this);
578 ProcessorBox::use_plugins (const SelectedPlugins& plugins)
580 for (SelectedPlugins::const_iterator p = plugins.begin(); p != plugins.end(); ++p) {
582 boost::shared_ptr<Processor> processor (new PluginInsert (_session, *p));
584 Route::ProcessorStreams err_streams;
586 if (Config->get_new_plugins_active()) {
587 processor->activate ();
590 if (_route->add_processor (processor, _placement, &err_streams)) {
591 weird_plugin_dialog (**p, err_streams);
592 // XXX SHAREDPTR delete plugin here .. do we even need to care?
595 if (Profile->get_sae()) {
596 processor->activate ();
598 processor->ActiveChanged.connect (bind (
599 mem_fun (*this, &ProcessorBox::show_processor_active),
600 boost::weak_ptr<Processor>(processor)));
606 ProcessorBox::weird_plugin_dialog (Plugin& p, Route::ProcessorStreams streams)
608 ArdourDialog dialog (_("ardour: weird plugin dialog"));
611 string text = string_compose(_("You attempted to add the plugin \"%1\" at index %2.\n"),
612 p.name(), streams.index);
614 bool has_midi = streams.count.n_midi() > 0 || p.get_info()->n_inputs.n_midi() > 0;
615 bool has_audio = streams.count.n_audio() > 0 || p.get_info()->n_inputs.n_audio() > 0;
617 text += _("\nThis plugin has:\n");
619 text += string_compose("\t%1 ", p.get_info()->n_inputs.n_midi()) + _("MIDI input(s)\n");
622 text += string_compose("\t%1 ", p.get_info()->n_inputs.n_audio()) + _("audio input(s)\n");
625 text += _("\nBut at the insertion point, there are:\n");
627 text += string_compose("\t%1 ", streams.count.n_midi()) + _("MIDI channel(s)\n");
630 text += string_compose("\t%1 ", streams.count.n_audio()) + _("audio channel(s)\n");
633 text += _("\nArdour is unable to insert this plugin here.\n");
634 label.set_text(text);
636 dialog.get_vbox()->pack_start (label);
637 dialog.add_button (Stock::OK, RESPONSE_ACCEPT);
639 dialog.set_name (X_("PluginIODialog"));
640 dialog.set_position (Gtk::WIN_POS_MOUSE);
641 dialog.set_modal (true);
648 ProcessorBox::choose_insert ()
650 boost::shared_ptr<Processor> processor (new PortInsert (_session, _route->mute_master()));
651 processor->ActiveChanged.connect (bind (mem_fun(*this, &ProcessorBox::show_processor_active),
652 boost::weak_ptr<Processor>(processor)));
654 _route->add_processor (processor, _placement);
658 ProcessorBox::choose_send ()
660 boost::shared_ptr<Send> send (new Send (_session, _route->mute_master()));
662 /* make an educated guess at the initial number of outputs for the send */
663 ChanCount outs = (_session.master_out())
664 ? _session.master_out()->n_outputs()
665 : _route->n_outputs();
667 /* XXX need processor lock on route */
669 send->output()->ensure_io (outs, false, this);
670 } catch (AudioEngine::PortRegistrationFailure& err) {
671 error << string_compose (_("Cannot set up new send: %1"), err.what()) << endmsg;
675 /* let the user adjust the IO setup before creation */
676 IOSelectorWindow *ios = new IOSelectorWindow (_session, send->output(), true);
679 /* keep a reference to the send so it doesn't get deleted while
680 the IOSelectorWindow is doing its stuff */
681 _processor_being_created = send;
683 ios->selector().Finished.connect (bind (
684 mem_fun(*this, &ProcessorBox::send_io_finished),
685 boost::weak_ptr<Processor>(send), ios));
689 ProcessorBox::send_io_finished (IOSelector::Result r, boost::weak_ptr<Processor> weak_processor, IOSelectorWindow* ios)
691 boost::shared_ptr<Processor> processor (weak_processor.lock());
693 /* drop our temporary reference to the new send */
694 _processor_being_created.reset ();
701 case IOSelector::Cancelled:
702 // processor will go away when all shared_ptrs to it vanish
705 case IOSelector::Accepted:
706 _route->add_processor (processor, _placement);
707 if (Profile->get_sae()) {
708 processor->activate ();
713 delete_when_idle (ios);
717 ProcessorBox::choose_return ()
719 boost::shared_ptr<Return> retrn (new Return (_session));
721 /* assume user just wants a single audio input (sidechain) by default */
722 ChanCount ins(DataType::AUDIO, 1);
724 /* XXX need processor lock on route */
726 retrn->input()->ensure_io (ins, false, this);
727 } catch (AudioEngine::PortRegistrationFailure& err) {
728 error << string_compose (_("Cannot set up new return: %1"), err.what()) << endmsg;
732 /* let the user adjust the IO setup before creation */
733 IOSelectorWindow *ios = new IOSelectorWindow (_session, retrn->output(), true);
736 /* keep a reference to the send so it doesn't get deleted while
737 the IOSelectorWindow is doing its stuff */
738 _processor_being_created = retrn;
740 ios->selector().Finished.connect (bind (
741 mem_fun(*this, &ProcessorBox::return_io_finished),
742 boost::weak_ptr<Processor>(retrn), ios));
746 ProcessorBox::return_io_finished (IOSelector::Result r, boost::weak_ptr<Processor> weak_processor, IOSelectorWindow* ios)
748 boost::shared_ptr<Processor> processor (weak_processor.lock());
750 /* drop our temporary reference to the new return */
751 _processor_being_created.reset ();
758 case IOSelector::Cancelled:
759 // processor will go away when all shared_ptrs to it vanish
762 case IOSelector::Accepted:
763 _route->add_processor (processor, _placement);
764 if (Profile->get_sae()) {
765 processor->activate ();
770 delete_when_idle (ios);
774 ProcessorBox::redisplay_processors ()
776 ENSURE_GUI_THREAD (mem_fun(*this, &ProcessorBox::redisplay_processors));
778 if (no_processor_redisplay) {
782 ignore_delete = true;
784 ignore_delete = false;
786 processor_active_connections.clear ();
787 processor_name_connections.clear ();
789 _route->foreach_processor (mem_fun (*this, &ProcessorBox::add_processor_to_display));
791 build_processor_tooltip (processor_eventbox, _("Inserts, sends & plugins:"));
795 ProcessorBox::add_processor_to_display (boost::weak_ptr<Processor> p)
797 boost::shared_ptr<Processor> processor (p.lock ());
802 if (!processor->visible()) {
806 Gtk::TreeModel::Row row = *(model->append());
807 row[columns.text] = processor_name (processor);
808 row[columns.processor] = processor;
810 show_processor_active (processor);
812 processor_active_connections.push_back (processor->ActiveChanged.connect (bind (
813 mem_fun(*this, &ProcessorBox::show_processor_active),
814 boost::weak_ptr<Processor>(processor))));
815 processor_name_connections.push_back (processor->NameChanged.connect (bind (
816 mem_fun(*this, &ProcessorBox::show_processor_name),
817 boost::weak_ptr<Processor>(processor))));
821 ProcessorBox::processor_name (boost::weak_ptr<Processor> weak_processor)
823 boost::shared_ptr<Processor> processor (weak_processor.lock());
829 boost::shared_ptr<Send> send;
832 if (!processor->active()) {
836 if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0 &&
837 !boost::dynamic_pointer_cast<InternalSend>(processor)) {
841 /* grab the send name out of its overall name */
843 string::size_type lbracket, rbracket;
844 lbracket = send->name().find ('[');
845 rbracket = send->name().find (']');
849 name_display += send->name().substr (lbracket+1, lbracket-rbracket-1);
852 name_display += PBD::short_version (send->name().substr (lbracket+1, lbracket-rbracket-1), 4);
860 name_display += processor->display_name();
863 name_display += PBD::short_version (processor->display_name(), 5);
869 if (!processor->active()) {
877 ProcessorBox::build_processor_tooltip (EventBox& box, string start)
881 Gtk::TreeModel::Children children = model->children();
882 for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
883 Gtk::TreeModel::Row row = *iter;
885 tip += row[columns.text];
887 ARDOUR_UI::instance()->tooltips().set_tip (box, tip);
891 ProcessorBox::show_processor_name (boost::weak_ptr<Processor> processor)
893 ENSURE_GUI_THREAD(bind (mem_fun(*this, &ProcessorBox::show_processor_name), processor));
894 show_processor_active (processor);
898 ProcessorBox::show_processor_active (boost::weak_ptr<Processor> weak_processor)
900 boost::shared_ptr<Processor> processor (weak_processor.lock());
906 ENSURE_GUI_THREAD(bind (mem_fun(*this, &ProcessorBox::show_processor_active), weak_processor));
908 Gtk::TreeModel::Children children = model->children();
909 Gtk::TreeModel::Children::iterator iter = children.begin();
911 while (iter != children.end()) {
913 boost::shared_ptr<Processor> r = (*iter)[columns.processor];
915 if (r == processor) {
916 (*iter)[columns.text] = processor_name (r);
918 if (processor->active()) {
919 (*iter)[columns.color] = *active_processor_color;
921 (*iter)[columns.color] = *inactive_processor_color;
931 ProcessorBox::row_deleted (const Gtk::TreeModel::Path& path)
933 if (!ignore_delete) {
934 compute_processor_sort_keys ();
939 ProcessorBox::compute_processor_sort_keys ()
941 Gtk::TreeModel::Children children = model->children();
942 Route::ProcessorList our_processors;
944 for (Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
945 boost::shared_ptr<Processor> p = (*iter)[columns.processor];
946 our_processors.push_back ((*iter)[columns.processor]);
949 if (_route->reorder_processors (our_processors)) {
951 /* reorder failed, so redisplay */
953 redisplay_processors ();
955 /* now tell them about the problem */
957 ArdourDialog dialog (_("ardour: weird plugin dialog"));
961 You cannot reorder this set of processors\n\
962 in that way because the inputs and\n\
963 outputs do not work correctly."));
965 dialog.get_vbox()->pack_start (label);
966 dialog.add_button (Stock::OK, RESPONSE_ACCEPT);
968 dialog.set_name (X_("PluginIODialog"));
969 dialog.set_position (Gtk::WIN_POS_MOUSE);
970 dialog.set_modal (true);
978 ProcessorBox::rename_processors ()
980 ProcSelection to_be_renamed;
982 get_selected_processors (to_be_renamed);
984 if (to_be_renamed.empty()) {
988 for (ProcSelection::iterator i = to_be_renamed.begin(); i != to_be_renamed.end(); ++i) {
989 rename_processor (*i);
994 ProcessorBox::cut_processors ()
996 ProcSelection to_be_removed;
998 get_selected_processors (to_be_removed);
1002 ProcessorBox::cut_processors (const ProcSelection& to_be_removed)
1004 if (to_be_removed.empty()) {
1008 XMLNode* node = new XMLNode (X_("cut"));
1009 Route::ProcessorList to_cut;
1011 no_processor_redisplay = true;
1012 for (ProcSelection::const_iterator i = to_be_removed.begin(); i != to_be_removed.end(); ++i) {
1013 // Cut only plugins, sends and returns
1014 if (boost::dynamic_pointer_cast<PluginInsert>((*i)) != 0 ||
1015 (boost::dynamic_pointer_cast<Send>((*i)) != 0) ||
1016 (boost::dynamic_pointer_cast<Return>((*i)) != 0)) {
1018 void* gui = (*i)->get_gui ();
1021 static_cast<Gtk::Widget*>(gui)->hide ();
1024 XMLNode& child ((*i)->get_state());
1025 node->add_child_nocopy (child);
1026 to_cut.push_back (*i);
1030 if (_route->remove_processors (to_cut) != 0) {
1032 no_processor_redisplay = false;
1036 _rr_selection.set (node);
1038 no_processor_redisplay = false;
1039 redisplay_processors ();
1043 ProcessorBox::copy_processors ()
1045 ProcSelection to_be_copied;
1046 get_selected_processors (to_be_copied);
1047 copy_processors (to_be_copied);
1051 ProcessorBox::copy_processors (const ProcSelection& to_be_copied)
1053 if (to_be_copied.empty()) {
1057 XMLNode* node = new XMLNode (X_("copy"));
1059 for (ProcSelection::const_iterator i = to_be_copied.begin(); i != to_be_copied.end(); ++i) {
1060 // Copy only plugins, sends, returns
1061 if (boost::dynamic_pointer_cast<PluginInsert>((*i)) != 0 ||
1062 (boost::dynamic_pointer_cast<Send>((*i)) != 0) ||
1063 (boost::dynamic_pointer_cast<Return>((*i)) != 0)) {
1064 node->add_child_nocopy ((*i)->get_state());
1068 _rr_selection.set (node);
1072 ProcessorBox::delete_processors ()
1074 ProcSelection to_be_deleted;
1075 get_selected_processors (to_be_deleted);
1076 delete_processors (to_be_deleted);
1080 ProcessorBox::delete_processors (const ProcSelection& targets)
1082 if (targets.empty()) {
1086 no_processor_redisplay = true;
1088 for (ProcSelection::const_iterator i = targets.begin(); i != targets.end(); ++i) {
1090 void* gui = (*i)->get_gui ();
1093 static_cast<Gtk::Widget*>(gui)->hide ();
1096 _route->remove_processor(*i);
1099 no_processor_redisplay = false;
1100 redisplay_processors ();
1104 ProcessorBox::delete_dragged_processors (const list<boost::shared_ptr<Processor> >& procs)
1106 list<boost::shared_ptr<Processor> >::const_iterator x;
1108 no_processor_redisplay = true;
1109 for (x = procs.begin(); x != procs.end(); ++x) {
1111 void* gui = (*x)->get_gui ();
1114 static_cast<Gtk::Widget*>(gui)->hide ();
1117 _route->remove_processor(*x);
1120 no_processor_redisplay = false;
1121 redisplay_processors ();
1125 ProcessorBox::idle_delete_processor (boost::weak_ptr<Processor> weak_processor)
1127 boost::shared_ptr<Processor> processor (weak_processor.lock());
1133 /* NOT copied to _mixer.selection() */
1135 no_processor_redisplay = true;
1136 _route->remove_processor (processor);
1137 no_processor_redisplay = false;
1138 redisplay_processors ();
1144 ProcessorBox::rename_processor (boost::shared_ptr<Processor> processor)
1146 ArdourPrompter name_prompter (true);
1148 name_prompter.set_prompt (_("rename processor"));
1149 name_prompter.set_initial_text (processor->name());
1150 name_prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
1151 name_prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
1152 name_prompter.show_all ();
1154 switch (name_prompter.run ()) {
1156 case Gtk::RESPONSE_ACCEPT:
1157 name_prompter.get_result (result);
1158 if (result.length()) {
1159 processor->set_name (result);
1168 ProcessorBox::paste_processors ()
1170 if (_rr_selection.processors.empty()) {
1174 paste_processor_state (_rr_selection.processors.get_node().children(), boost::shared_ptr<Processor>());
1178 ProcessorBox::paste_processors (boost::shared_ptr<Processor> before)
1181 if (_rr_selection.processors.empty()) {
1185 paste_processor_state (_rr_selection.processors.get_node().children(), before);
1189 ProcessorBox::paste_processor_state (const XMLNodeList& nlist, boost::shared_ptr<Processor> p)
1191 XMLNodeConstIterator niter;
1192 list<boost::shared_ptr<Processor> > copies;
1194 if (nlist.empty()) {
1198 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1200 XMLProperty const * type = (*niter)->property ("type");
1203 boost::shared_ptr<Processor> p;
1205 if (type->value() == "meter" ||
1206 type->value() == "main-outs" ||
1207 type->value() == "amp" ||
1208 type->value() == "intsend" || type->value() == "intreturn") {
1209 /* do not paste meter, main outs, amp or internal send/returns */
1212 } else if (type->value() == "send") {
1214 XMLNode n (**niter);
1215 Send::make_unique (n, _session);
1216 p.reset (new Send (_session, _route->mute_master(), n));
1218 } else if (type->value() == "return") {
1220 XMLNode n (**niter);
1221 Return::make_unique (n, _session);
1222 p.reset (new Return (_session, **niter));
1225 /* XXX its a bit limiting to assume that everything else
1228 p.reset (new PluginInsert (_session, **niter));
1231 copies.push_back (p);
1235 cerr << "plugin insert constructor failed\n";
1239 if (copies.empty()) {
1243 if (_route->add_processors (copies, p)) {
1246 "Copying the set of processors on the clipboard failed,\n\
1247 probably because the I/O configuration of the plugins\n\
1248 could not match the configuration of this track.");
1249 MessageDialog am (msg);
1255 ProcessorBox::activate_processor (boost::shared_ptr<Processor> r)
1261 ProcessorBox::deactivate_processor (boost::shared_ptr<Processor> r)
1267 ProcessorBox::get_selected_processors (ProcSelection& processors)
1269 vector<Gtk::TreeModel::Path> pathlist = processor_display.get_selection()->get_selected_rows();
1271 for (vector<Gtk::TreeModel::Path>::iterator iter = pathlist.begin(); iter != pathlist.end(); ++iter) {
1272 processors.push_back ((*(model->get_iter(*iter)))[columns.processor]);
1277 ProcessorBox::for_selected_processors (void (ProcessorBox::*method)(boost::shared_ptr<Processor>))
1279 vector<Gtk::TreeModel::Path> pathlist = processor_display.get_selection()->get_selected_rows();
1281 for (vector<Gtk::TreeModel::Path>::iterator iter = pathlist.begin(); iter != pathlist.end(); ++iter) {
1282 boost::shared_ptr<Processor> processor = (*(model->get_iter(*iter)))[columns.processor];
1283 (this->*method)(processor);
1288 ProcessorBox::all_processors_active (bool state)
1290 _route->all_processors_active (_placement, state);
1294 ProcessorBox::ab_plugins ()
1296 _route->ab_plugins (ab_direction);
1297 ab_direction = !ab_direction;
1302 ProcessorBox::clear_processors ()
1305 vector<string> choices;
1307 prompt = string_compose (_("Do you really want to remove all processors from %1?\n"
1308 "(this cannot be undone)"), _route->name());
1310 choices.push_back (_("Cancel"));
1311 choices.push_back (_("Yes, remove them all"));
1313 Gtkmm2ext::Choice prompter (prompt, choices);
1315 if (prompter.run () == 1) {
1316 _route->clear_processors (PreFader);
1317 _route->clear_processors (PostFader);
1322 ProcessorBox::clear_processors (Placement p)
1325 vector<string> choices;
1327 if (p == PreFader) {
1328 prompt = string_compose (_("Do you really want to remove all pre-fader processors from %1?\n"
1329 "(this cannot be undone)"), _route->name());
1331 prompt = string_compose (_("Do you really want to remove all post-fader processors from %1?\n"
1332 "(this cannot be undone)"), _route->name());
1335 choices.push_back (_("Cancel"));
1336 choices.push_back (_("Yes, remove them all"));
1338 Gtkmm2ext::Choice prompter (prompt, choices);
1340 if (prompter.run () == 1) {
1341 _route->clear_processors (p);
1346 ProcessorBox::edit_processor (boost::shared_ptr<Processor> processor)
1348 boost::shared_ptr<Send> send;
1349 boost::shared_ptr<Return> retrn;
1350 boost::shared_ptr<PluginInsert> plugin_insert;
1351 boost::shared_ptr<PortInsert> port_insert;
1354 if (boost::dynamic_pointer_cast<AudioTrack>(_route) != 0) {
1356 if (boost::dynamic_pointer_cast<AudioTrack> (_route)->freeze_state() == AudioTrack::Frozen) {
1361 if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
1363 if (!_session.engine().connected()) {
1367 #ifdef OLD_SEND_EDITING
1368 SendUIWindow *send_ui;
1370 if (send->get_gui() == 0) {
1371 send_ui = new SendUIWindow (send, _session);
1373 WindowTitle title(Glib::get_application_name());
1374 title += send->name();
1375 send_ui->set_title (title.get_string());
1377 send->set_gui (send_ui);
1380 send_ui = reinterpret_cast<SendUIWindow *> (send->get_gui());
1385 if (_parent_strip) {
1386 _parent_strip->gain_meter().set_controls (_route, send->meter(), send->amp());
1387 _parent_strip->panner_ui().set_panner (send->panner());
1391 } else if ((retrn = boost::dynamic_pointer_cast<Return> (processor)) != 0) {
1393 if (!_session.engine().connected()) {
1397 boost::shared_ptr<Return> retrn = boost::dynamic_pointer_cast<Return> (processor);
1399 ReturnUIWindow *return_ui;
1401 if (retrn->get_gui() == 0) {
1403 return_ui = new ReturnUIWindow (retrn, _session);
1405 WindowTitle title(Glib::get_application_name());
1406 title += retrn->name();
1407 return_ui->set_title (title.get_string());
1409 send->set_gui (return_ui);
1412 return_ui = reinterpret_cast<ReturnUIWindow *> (retrn->get_gui());
1417 } else if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (processor)) != 0) {
1419 PluginUIWindow *plugin_ui;
1421 /* these are both allowed to be null */
1423 Container* toplevel = get_toplevel();
1424 Window* win = dynamic_cast<Gtk::Window*>(toplevel);
1426 if (plugin_insert->get_gui() == 0) {
1428 plugin_ui = new PluginUIWindow (win, plugin_insert);
1430 WindowTitle title(Glib::get_application_name());
1431 title += generate_processor_title (plugin_insert);
1432 plugin_ui->set_title (title.get_string());
1434 plugin_insert->set_gui (plugin_ui);
1437 plugin_ui = reinterpret_cast<PluginUIWindow *> (plugin_insert->get_gui());
1438 plugin_ui->set_parent (win);
1443 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (processor)) != 0) {
1445 if (!_session.engine().connected()) {
1446 MessageDialog msg ( _("Not connected to JACK - no I/O changes are possible"));
1451 PortInsertWindow *io_selector;
1453 if (port_insert->get_gui() == 0) {
1454 io_selector = new PortInsertWindow (_session, port_insert);
1455 port_insert->set_gui (io_selector);
1458 io_selector = reinterpret_cast<PortInsertWindow *> (port_insert->get_gui());
1461 gidget = io_selector;
1465 if (gidget->is_visible()) {
1466 gidget->get_window()->raise ();
1468 gidget->show_all ();
1475 ProcessorBox::register_actions ()
1477 Glib::RefPtr<Gtk::ActionGroup> popup_act_grp = Gtk::ActionGroup::create(X_("processormenu"));
1478 Glib::RefPtr<Action> act;
1481 ActionManager::register_action (popup_act_grp, X_("newplugin"), _("New Plugin"),
1482 sigc::ptr_fun (ProcessorBox::rb_choose_plugin));
1484 act = ActionManager::register_action (popup_act_grp, X_("newinsert"), _("New Insert"),
1485 sigc::ptr_fun (ProcessorBox::rb_choose_insert));
1486 ActionManager::jack_sensitive_actions.push_back (act);
1487 act = ActionManager::register_action (popup_act_grp, X_("newsend"), _("New Send ..."),
1488 sigc::ptr_fun (ProcessorBox::rb_choose_send));
1489 ActionManager::jack_sensitive_actions.push_back (act);
1490 act = ActionManager::register_action (popup_act_grp, X_("newreturn"), _("New Return ..."),
1491 sigc::ptr_fun (ProcessorBox::rb_choose_return));
1492 ActionManager::jack_sensitive_actions.push_back (act);
1494 ActionManager::register_action (popup_act_grp, X_("clear"), _("Clear (all)"),
1495 sigc::ptr_fun (ProcessorBox::rb_clear));
1496 ActionManager::register_action (popup_act_grp, X_("clear_pre"), _("Clear (pre-fader)"),
1497 sigc::ptr_fun (ProcessorBox::rb_clear_pre));
1498 ActionManager::register_action (popup_act_grp, X_("clear_post"), _("Clear (post-fader)"),
1499 sigc::ptr_fun (ProcessorBox::rb_clear_post));
1501 /* standard editing stuff */
1502 act = ActionManager::register_action (popup_act_grp, X_("cut"), _("Cut"),
1503 sigc::ptr_fun (ProcessorBox::rb_cut));
1504 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1505 act = ActionManager::register_action (popup_act_grp, X_("copy"), _("Copy"),
1506 sigc::ptr_fun (ProcessorBox::rb_copy));
1507 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1509 act = ActionManager::register_action (popup_act_grp, X_("delete"), _("Delete"),
1510 sigc::ptr_fun (ProcessorBox::rb_delete));
1511 ActionManager::plugin_selection_sensitive_actions.push_back(act); // ??
1513 paste_action = ActionManager::register_action (popup_act_grp, X_("paste"), _("Paste"),
1514 sigc::ptr_fun (ProcessorBox::rb_paste));
1515 act = ActionManager::register_action (popup_act_grp, X_("rename"), _("Rename"),
1516 sigc::ptr_fun (ProcessorBox::rb_rename));
1517 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1518 ActionManager::register_action (popup_act_grp, X_("selectall"), _("Select All"),
1519 sigc::ptr_fun (ProcessorBox::rb_select_all));
1520 ActionManager::register_action (popup_act_grp, X_("deselectall"), _("Deselect All"),
1521 sigc::ptr_fun (ProcessorBox::rb_deselect_all));
1524 act = ActionManager::register_action (popup_act_grp, X_("activate"), _("Activate"),
1525 sigc::ptr_fun (ProcessorBox::rb_activate));
1526 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1527 act = ActionManager::register_action (popup_act_grp, X_("deactivate"), _("Deactivate"),
1528 sigc::ptr_fun (ProcessorBox::rb_deactivate));
1529 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1530 ActionManager::register_action (popup_act_grp, X_("activate_all"), _("Activate all"),
1531 sigc::ptr_fun (ProcessorBox::rb_activate_all));
1532 ActionManager::register_action (popup_act_grp, X_("deactivate_all"), _("Deactivate all"),
1533 sigc::ptr_fun (ProcessorBox::rb_deactivate_all));
1536 act = ActionManager::register_action (popup_act_grp, X_("edit"), _("Edit"),
1537 sigc::ptr_fun (ProcessorBox::rb_edit));
1538 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1540 ActionManager::add_action_group (popup_act_grp);
1544 ProcessorBox::rb_choose_plugin ()
1546 if (_current_processor_box == 0) {
1549 _current_processor_box->choose_plugin ();
1553 ProcessorBox::rb_choose_insert ()
1555 if (_current_processor_box == 0) {
1558 _current_processor_box->choose_insert ();
1562 ProcessorBox::rb_choose_send ()
1564 if (_current_processor_box == 0) {
1567 _current_processor_box->choose_send ();
1571 ProcessorBox::rb_choose_return ()
1573 if (_current_processor_box == 0) {
1576 _current_processor_box->choose_return ();
1580 ProcessorBox::rb_clear ()
1582 if (_current_processor_box == 0) {
1586 _current_processor_box->clear_processors ();
1591 ProcessorBox::rb_clear_pre ()
1593 if (_current_processor_box == 0) {
1597 _current_processor_box->clear_processors (PreFader);
1602 ProcessorBox::rb_clear_post ()
1604 if (_current_processor_box == 0) {
1608 _current_processor_box->clear_processors (PostFader);
1612 ProcessorBox::rb_cut ()
1614 if (_current_processor_box == 0) {
1618 _current_processor_box->cut_processors ();
1622 ProcessorBox::rb_delete ()
1624 if (_current_processor_box == 0) {
1628 _current_processor_box->delete_processors ();
1632 ProcessorBox::rb_copy ()
1634 if (_current_processor_box == 0) {
1637 _current_processor_box->copy_processors ();
1641 ProcessorBox::rb_paste ()
1643 if (_current_processor_box == 0) {
1647 _current_processor_box->paste_processors ();
1651 ProcessorBox::rb_rename ()
1653 if (_current_processor_box == 0) {
1656 _current_processor_box->rename_processors ();
1660 ProcessorBox::rb_select_all ()
1662 if (_current_processor_box == 0) {
1666 _current_processor_box->select_all_processors ();
1670 ProcessorBox::rb_deselect_all ()
1672 if (_current_processor_box == 0) {
1676 _current_processor_box->deselect_all_processors ();
1680 ProcessorBox::rb_activate ()
1682 if (_current_processor_box == 0) {
1686 _current_processor_box->for_selected_processors (&ProcessorBox::activate_processor);
1690 ProcessorBox::rb_deactivate ()
1692 if (_current_processor_box == 0) {
1695 _current_processor_box->for_selected_processors (&ProcessorBox::deactivate_processor);
1699 ProcessorBox::rb_activate_all ()
1701 if (_current_processor_box == 0) {
1705 _current_processor_box->all_processors_active (true);
1709 ProcessorBox::rb_deactivate_all ()
1711 if (_current_processor_box == 0) {
1714 _current_processor_box->all_processors_active (false);
1718 ProcessorBox::rb_edit ()
1720 if (_current_processor_box == 0) {
1724 _current_processor_box->for_selected_processors (&ProcessorBox::edit_processor);
1728 ProcessorBox::route_name_changed ()
1730 ENSURE_GUI_THREAD (mem_fun (*this, &ProcessorBox::route_name_changed));
1732 boost::shared_ptr<Processor> processor;
1733 boost::shared_ptr<PluginInsert> plugin_insert;
1734 boost::shared_ptr<Send> send;
1736 Gtk::TreeModel::Children children = model->children();
1738 for (Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
1739 Gtk::TreeModel::Row row = *iter;
1741 processor= row[columns.processor];
1743 void* gui = processor->get_gui();
1749 /* rename editor windows for sends and plugins */
1751 WindowTitle title (Glib::get_application_name());
1753 if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
1754 title += send->name();
1755 static_cast<Window*>(gui)->set_title (title.get_string());
1756 } else if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (processor)) != 0) {
1757 title += generate_processor_title (plugin_insert);
1758 static_cast<Window*>(gui)->set_title (title.get_string());
1764 ProcessorBox::generate_processor_title (boost::shared_ptr<PluginInsert> pi)
1766 string maker = pi->plugin()->maker() ? pi->plugin()->maker() : "";
1767 string::size_type email_pos;
1769 if ((email_pos = maker.find_first_of ('<')) != string::npos) {
1770 maker = maker.substr (0, email_pos - 1);
1773 if (maker.length() > 32) {
1774 maker = maker.substr (0, 32);
1778 return string_compose(_("%1: %2 (by %3)"), _route->name(), pi->name(), maker);