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.
24 #include <sigc++/bind.h>
26 #include "pbd/convert.h"
28 #include <glibmm/miscutils.h>
30 #include <gtkmm/messagedialog.h>
32 #include <gtkmm2ext/gtk_ui.h>
33 #include <gtkmm2ext/utils.h>
34 #include <gtkmm2ext/choice.h>
35 #include <gtkmm2ext/utils.h>
36 #include <gtkmm2ext/stop_signal.h>
37 #include <gtkmm2ext/doi.h>
38 #include <gtkmm2ext/window_title.h>
40 #include "ardour/amp.h"
41 #include "ardour/ardour.h"
42 #include "ardour/audio_diskstream.h"
43 #include "ardour/audio_track.h"
44 #include "ardour/audioengine.h"
45 #include "ardour/ladspa_plugin.h"
46 #include "ardour/meter.h"
47 #include "ardour/plugin_insert.h"
48 #include "ardour/port_insert.h"
49 #include "ardour/profile.h"
50 #include "ardour/return.h"
51 #include "ardour/route.h"
52 #include "ardour/send.h"
53 #include "ardour/session.h"
56 #include "ardour_dialog.h"
57 #include "ardour_ui.h"
58 #include "gui_thread.h"
59 #include "io_selector.h"
62 #include "mixer_strip.h"
63 #include "plugin_selector.h"
64 #include "plugin_ui.h"
65 #include "processor_box.h"
66 #include "public_editor.h"
67 #include "return_ui.h"
68 #include "route_processor_selection.h"
74 #ifdef HAVE_AUDIOUNITS
80 using namespace ARDOUR;
84 using namespace Gtkmm2ext;
86 ProcessorBox* ProcessorBox::_current_processor_box = 0;
87 RefPtr<Action> ProcessorBox::paste_action;
88 bool ProcessorBox::get_colors = true;
89 Gdk::Color* ProcessorBox::active_processor_color;
90 Gdk::Color* ProcessorBox::inactive_processor_color;
92 ProcessorBox::ProcessorBox (Placement pcmnt, Session& sess, PluginSelector &plugsel,
93 RouteRedirectSelection & rsel, MixerStrip* parent, bool owner_is_mixer)
95 , _parent_strip (parent)
96 , _owner_is_mixer (owner_is_mixer)
98 , _plugin_selector(plugsel)
102 active_processor_color = new Gdk::Color;
103 inactive_processor_color = new Gdk::Color;
104 set_color (*active_processor_color, rgba_from_style (
105 "ProcessorSelector", 0xff, 0, 0, 0, "fg", Gtk::STATE_ACTIVE, false ));
106 set_color (*inactive_processor_color, rgba_from_style (
107 "ProcessorSelector", 0xff, 0, 0, 0, "fg", Gtk::STATE_NORMAL, false ));
113 send_action_menu = 0;
114 processor_drag_in_progress = false;
115 no_processor_redisplay = false;
116 ignore_delete = false;
118 model = ListStore::create(columns);
120 RefPtr<TreeSelection> selection = processor_display.get_selection();
121 selection->set_mode (Gtk::SELECTION_MULTIPLE);
122 selection->signal_changed().connect (mem_fun (*this, &ProcessorBox::selection_changed));
124 processor_display.set_data ("processorbox", this);
125 processor_display.set_model (model);
126 processor_display.append_column (X_("notshown"), columns.text);
127 processor_display.set_name ("ProcessorSelector");
128 processor_display.set_headers_visible (false);
129 processor_display.set_reorderable (true);
130 processor_display.set_size_request (-1, 40);
131 processor_display.get_column(0)->set_sizing(TREE_VIEW_COLUMN_FIXED);
132 processor_display.get_column(0)->set_fixed_width(48);
133 processor_display.add_object_drag (columns.processor.index(), "processors");
134 processor_display.signal_drop.connect (mem_fun (*this, &ProcessorBox::object_drop));
136 TreeViewColumn* name_col = processor_display.get_column(0);
137 CellRendererText* renderer = dynamic_cast<CellRendererText*>(
138 processor_display.get_column_cell_renderer (0));
139 name_col->add_attribute(renderer->property_foreground_gdk(), columns.color);
141 processor_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
143 model->signal_row_deleted().connect (mem_fun (*this, &ProcessorBox::row_deleted));
145 processor_scroller.add (processor_display);
146 processor_eventbox.add (processor_scroller);
148 processor_scroller.set_size_request (-1, 40);
150 pack_start (processor_eventbox, true, true);
152 processor_eventbox.signal_enter_notify_event().connect (bind (
153 sigc::ptr_fun (ProcessorBox::enter_box),
156 processor_display.signal_button_press_event().connect (
157 mem_fun(*this, &ProcessorBox::processor_button_press_event), false);
158 processor_display.signal_button_release_event().connect (
159 mem_fun(*this, &ProcessorBox::processor_button_release_event));
162 ProcessorBox::~ProcessorBox ()
167 ProcessorBox::set_route (boost::shared_ptr<Route> r)
169 connections.clear ();
173 connections.push_back (_route->processors_changed.connect (
174 mem_fun(*this, &ProcessorBox::redisplay_processors)));
175 connections.push_back (_route->GoingAway.connect (
176 mem_fun (*this, &ProcessorBox::route_going_away)));
177 connections.push_back (_route->NameChanged.connect (
178 mem_fun(*this, &ProcessorBox::route_name_changed)));
180 redisplay_processors ();
184 ProcessorBox::route_going_away ()
186 /* don't keep updating display as processors are deleted */
187 no_processor_redisplay = true;
192 ProcessorBox::object_drop (const list<boost::shared_ptr<Processor> >& procs, Gtk::TreeView* source, Glib::RefPtr<Gdk::DragContext>& context)
194 cerr << "Drop from " << source << " (mine is " << &processor_display << ") action = " << hex << context->get_suggested_action() << dec << endl;
196 for (list<boost::shared_ptr<Processor> >::const_iterator i = procs.begin(); i != procs.end(); ++i) {
197 XMLNode& state = (*i)->get_state ();
199 nlist.push_back (&state);
200 paste_processor_state (nlist);
204 /* since the treeview doesn't take care of this properly, we have to delete the originals
208 if ((context->get_suggested_action() == Gdk::ACTION_MOVE) && source) {
209 ProcessorBox* other = reinterpret_cast<ProcessorBox*> (source->get_data ("processorbox"));
211 cerr << "source was another processor box, delete the selected items\n";
212 other->delete_dragged_processors (procs);
216 context->drag_finish (true, (context->get_suggested_action() == Gdk::ACTION_MOVE), 0);
220 ProcessorBox::update()
222 redisplay_processors ();
227 ProcessorBox::set_width (Width w)
234 redisplay_processors ();
238 ProcessorBox::remove_processor_gui (boost::shared_ptr<Processor> processor)
240 boost::shared_ptr<Send> send;
241 boost::shared_ptr<Return> retrn;
242 boost::shared_ptr<PortInsert> port_insert;
244 if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (processor)) != 0) {
245 PortInsertUI *io_selector = reinterpret_cast<PortInsertUI *> (port_insert->get_gui());
246 port_insert->set_gui (0);
248 } else if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
249 SendUIWindow *sui = reinterpret_cast<SendUIWindow*> (send->get_gui());
252 } else if ((retrn = boost::dynamic_pointer_cast<Return> (processor)) != 0) {
253 ReturnUIWindow *rui = reinterpret_cast<ReturnUIWindow*> (retrn->get_gui());
260 ProcessorBox::build_send_action_menu ()
262 using namespace Menu_Helpers;
264 send_action_menu = new Menu;
265 send_action_menu->set_name ("ArdourContextMenu");
266 MenuList& items = send_action_menu->items();
268 items.push_back (MenuElem (_("New send"), mem_fun(*this, &ProcessorBox::new_send)));
269 items.push_back (MenuElem (_("Show send controls"), mem_fun(*this, &ProcessorBox::show_send_controls)));
273 ProcessorBox::show_send_controls ()
278 ProcessorBox::new_send ()
283 ProcessorBox::show_processor_menu (gint arg)
285 if (processor_menu == 0) {
286 processor_menu = build_processor_menu ();
289 Gtk::MenuItem* plugin_menu_item = dynamic_cast<Gtk::MenuItem*>(ActionManager::get_widget("/processormenu/newplugin"));
291 if (plugin_menu_item) {
292 plugin_menu_item->set_submenu (_plugin_selector.plugin_menu());
295 paste_action->set_sensitive (!_rr_selection.processors.empty());
297 processor_menu->popup (1, arg);
301 ProcessorBox::processor_drag_begin (GdkDragContext *context)
303 processor_drag_in_progress = true;
307 ProcessorBox::processor_drag_end (GdkDragContext *context)
309 processor_drag_in_progress = false;
313 ProcessorBox::processor_button_press_event (GdkEventButton *ev)
316 TreeModel::Path path;
317 TreeViewColumn* column;
320 boost::shared_ptr<Processor> processor;
322 bool selected = false;
324 if (processor_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
325 if ((iter = model->get_iter (path))) {
326 processor = (*iter)[columns.processor];
327 selected = processor_display.get_selection()->is_selected (iter);
332 if (processor && (Keyboard::is_edit_event (ev) || (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS))) {
334 if (_session.engine().connected()) {
335 /* XXX giving an error message here is hard, because we may be in the midst of a button press */
336 edit_processor (processor);
340 } else if (processor && ev->button == 1 && selected) {
342 // this is purely informational but necessary
343 ProcessorSelected (processor); // emit
345 } else if (!processor && ev->button == 1 && ev->type == GDK_2BUTTON_PRESS) {
348 _plugin_selector.show_manager ();
356 ProcessorBox::processor_button_release_event (GdkEventButton *ev)
359 TreeModel::Path path;
360 TreeViewColumn* column;
363 boost::shared_ptr<Processor> processor;
367 if (processor_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
368 if ((iter = model->get_iter (path))) {
369 processor = (*iter)[columns.processor];
373 if (processor && Keyboard::is_delete_event (ev)) {
375 Glib::signal_idle().connect (bind (
376 mem_fun(*this, &ProcessorBox::idle_delete_processor),
377 boost::weak_ptr<Processor>(processor)));
380 } else if (Keyboard::is_context_menu_event (ev)) {
382 show_processor_menu(ev->time);
385 } else if (processor && Keyboard::is_button2_event (ev)
387 && (Keyboard::no_modifier_keys_pressed (ev) && ((ev->state & Gdk::BUTTON2_MASK) == Gdk::BUTTON2_MASK))
391 /* button2-click with no/appropriate modifiers */
393 if (processor->active()) {
394 processor->deactivate ();
396 processor->activate ();
406 ProcessorBox::build_processor_menu ()
408 processor_menu = dynamic_cast<Gtk::Menu*>(ActionManager::get_widget("/processormenu") );
409 processor_menu->set_name ("ArdourContextMenu");
413 return processor_menu;
417 ProcessorBox::selection_changed ()
419 bool sensitive = (processor_display.get_selection()->count_selected_rows()) ? true : false;
420 ActionManager::set_sensitive (ActionManager::plugin_selection_sensitive_actions, sensitive);
424 ProcessorBox::select_all_processors ()
426 processor_display.get_selection()->select_all();
430 ProcessorBox::deselect_all_processors ()
432 processor_display.get_selection()->unselect_all();
436 ProcessorBox::choose_plugin ()
438 _plugin_selector.set_interested_object (*this);
442 ProcessorBox::use_plugins (const SelectedPlugins& plugins)
444 for (SelectedPlugins::const_iterator p = plugins.begin(); p != plugins.end(); ++p) {
446 boost::shared_ptr<Processor> processor (new PluginInsert (_session, *p));
448 Route::ProcessorStreams err_streams;
450 if (Config->get_new_plugins_active()) {
451 processor->activate ();
454 if (_route->add_processor (processor, _placement, &err_streams)) {
455 weird_plugin_dialog (**p, err_streams);
456 // XXX SHAREDPTR delete plugin here .. do we even need to care?
459 if (Profile->get_sae()) {
460 processor->activate ();
462 processor->ActiveChanged.connect (bind (
463 mem_fun (*this, &ProcessorBox::show_processor_active),
464 boost::weak_ptr<Processor>(processor)));
470 ProcessorBox::weird_plugin_dialog (Plugin& p, Route::ProcessorStreams streams)
472 ArdourDialog dialog (_("ardour: weird plugin dialog"));
475 string text = string_compose(_("You attempted to add the plugin \"%1\" at index %2.\n"),
476 p.name(), streams.index);
478 bool has_midi = streams.count.n_midi() > 0 || p.get_info()->n_inputs.n_midi() > 0;
479 bool has_audio = streams.count.n_audio() > 0 || p.get_info()->n_inputs.n_audio() > 0;
481 text += _("\nThis plugin has:\n");
483 text += string_compose("\t%1 ", p.get_info()->n_inputs.n_midi()) + _("MIDI input(s)\n");
486 text += string_compose("\t%1 ", p.get_info()->n_inputs.n_audio()) + _("audio input(s)\n");
489 text += _("\nBut at the insertion point, there are:\n");
491 text += string_compose("\t%1 ", streams.count.n_midi()) + _("MIDI channel(s)\n");
494 text += string_compose("\t%1 ", streams.count.n_audio()) + _("audio channel(s)\n");
497 text += _("\nArdour is unable to insert this plugin here.\n");
498 label.set_text(text);
500 dialog.get_vbox()->pack_start (label);
501 dialog.add_button (Stock::OK, RESPONSE_ACCEPT);
503 dialog.set_name (X_("PluginIODialog"));
504 dialog.set_position (Gtk::WIN_POS_MOUSE);
505 dialog.set_modal (true);
512 ProcessorBox::choose_insert ()
514 boost::shared_ptr<Processor> processor (new PortInsert (_session, _route->mute_master()));
515 processor->ActiveChanged.connect (bind (
516 mem_fun(*this, &ProcessorBox::show_processor_active),
517 boost::weak_ptr<Processor>(processor)));
519 _route->add_processor (processor, _placement);
523 ProcessorBox::choose_send ()
525 boost::shared_ptr<Send> send (new Send (_session, _route->mute_master()));
527 /* make an educated guess at the initial number of outputs for the send */
528 ChanCount outs = (_session.master_out())
529 ? _session.master_out()->n_outputs()
530 : _route->n_outputs();
532 /* XXX need processor lock on route */
534 send->output()->ensure_io (outs, false, this);
535 } catch (AudioEngine::PortRegistrationFailure& err) {
536 error << string_compose (_("Cannot set up new send: %1"), err.what()) << endmsg;
540 /* let the user adjust the IO setup before creation */
541 IOSelectorWindow *ios = new IOSelectorWindow (_session, send->output(), true);
544 /* keep a reference to the send so it doesn't get deleted while
545 the IOSelectorWindow is doing its stuff */
546 _processor_being_created = send;
548 ios->selector().Finished.connect (bind (
549 mem_fun(*this, &ProcessorBox::send_io_finished),
550 boost::weak_ptr<Processor>(send), ios));
554 ProcessorBox::send_io_finished (IOSelector::Result r, boost::weak_ptr<Processor> weak_processor, IOSelectorWindow* ios)
556 boost::shared_ptr<Processor> processor (weak_processor.lock());
558 /* drop our temporary reference to the new send */
559 _processor_being_created.reset ();
566 case IOSelector::Cancelled:
567 // processor will go away when all shared_ptrs to it vanish
570 case IOSelector::Accepted:
571 _route->add_processor (processor, _placement);
572 if (Profile->get_sae()) {
573 processor->activate ();
578 delete_when_idle (ios);
582 ProcessorBox::choose_return ()
584 boost::shared_ptr<Return> retrn (new Return (_session));
586 /* assume user just wants a single audio input (sidechain) by default */
587 ChanCount ins(DataType::AUDIO, 1);
589 /* XXX need processor lock on route */
591 retrn->input()->ensure_io (ins, false, this);
592 } catch (AudioEngine::PortRegistrationFailure& err) {
593 error << string_compose (_("Cannot set up new return: %1"), err.what()) << endmsg;
597 /* let the user adjust the IO setup before creation */
598 IOSelectorWindow *ios = new IOSelectorWindow (_session, retrn->output(), true);
601 /* keep a reference to the send so it doesn't get deleted while
602 the IOSelectorWindow is doing its stuff */
603 _processor_being_created = retrn;
605 ios->selector().Finished.connect (bind (
606 mem_fun(*this, &ProcessorBox::return_io_finished),
607 boost::weak_ptr<Processor>(retrn), ios));
611 ProcessorBox::return_io_finished (IOSelector::Result r, boost::weak_ptr<Processor> weak_processor, IOSelectorWindow* ios)
613 boost::shared_ptr<Processor> processor (weak_processor.lock());
615 /* drop our temporary reference to the new return */
616 _processor_being_created.reset ();
623 case IOSelector::Cancelled:
624 // processor will go away when all shared_ptrs to it vanish
627 case IOSelector::Accepted:
628 _route->add_processor (processor, _placement);
629 if (Profile->get_sae()) {
630 processor->activate ();
635 delete_when_idle (ios);
639 ProcessorBox::redisplay_processors ()
641 ENSURE_GUI_THREAD (mem_fun(*this, &ProcessorBox::redisplay_processors));
643 if (no_processor_redisplay) {
647 ignore_delete = true;
649 ignore_delete = false;
651 processor_active_connections.clear ();
652 processor_name_connections.clear ();
654 _route->foreach_processor (_placement, mem_fun (*this, &ProcessorBox::add_processor_to_display));
656 switch (_placement) {
658 build_processor_tooltip (processor_eventbox, _("Pre-fader inserts, sends & plugins:"));
661 build_processor_tooltip (processor_eventbox, _("Post-fader inserts, sends & plugins:"));
667 ProcessorBox::add_processor_to_display (boost::weak_ptr<Processor> p)
669 boost::shared_ptr<Processor> processor (p.lock ());
674 if (processor == _route->amp() || !processor->visible()) {
678 Gtk::TreeModel::Row row = *(model->append());
679 row[columns.text] = processor_name (processor);
680 row[columns.processor] = processor;
682 show_processor_active (processor);
684 processor_active_connections.push_back (processor->ActiveChanged.connect (bind (
685 mem_fun(*this, &ProcessorBox::show_processor_active),
686 boost::weak_ptr<Processor>(processor))));
687 processor_name_connections.push_back (processor->NameChanged.connect (bind (
688 mem_fun(*this, &ProcessorBox::show_processor_name),
689 boost::weak_ptr<Processor>(processor))));
693 ProcessorBox::processor_name (boost::weak_ptr<Processor> weak_processor)
695 boost::shared_ptr<Processor> processor (weak_processor.lock());
701 boost::shared_ptr<Send> send;
704 if (!processor->active()) {
708 if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
712 /* grab the send name out of its overall name */
714 string::size_type lbracket, rbracket;
715 lbracket = send->name().find ('[');
716 rbracket = send->name().find (']');
720 name_display += send->name().substr (lbracket+1, lbracket-rbracket-1);
723 name_display += PBD::short_version (send->name().substr (lbracket+1, lbracket-rbracket-1), 4);
731 name_display += processor->name();
734 name_display += PBD::short_version (processor->name(), 5);
740 if (!processor->active()) {
748 ProcessorBox::build_processor_tooltip (EventBox& box, string start)
752 Gtk::TreeModel::Children children = model->children();
753 for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
754 Gtk::TreeModel::Row row = *iter;
756 tip += row[columns.text];
758 ARDOUR_UI::instance()->tooltips().set_tip (box, tip);
762 ProcessorBox::show_processor_name (boost::weak_ptr<Processor> processor)
764 ENSURE_GUI_THREAD(bind (mem_fun(*this, &ProcessorBox::show_processor_name), processor));
765 show_processor_active (processor);
769 ProcessorBox::show_processor_active (boost::weak_ptr<Processor> weak_processor)
771 boost::shared_ptr<Processor> processor (weak_processor.lock());
777 ENSURE_GUI_THREAD(bind (mem_fun(*this, &ProcessorBox::show_processor_active), weak_processor));
779 Gtk::TreeModel::Children children = model->children();
780 Gtk::TreeModel::Children::iterator iter = children.begin();
782 while (iter != children.end()) {
784 boost::shared_ptr<Processor> r = (*iter)[columns.processor];
786 if (r == processor) {
787 (*iter)[columns.text] = processor_name (r);
789 if (processor->active()) {
790 (*iter)[columns.color] = *active_processor_color;
792 (*iter)[columns.color] = *inactive_processor_color;
802 ProcessorBox::row_deleted (const Gtk::TreeModel::Path& path)
804 if (!ignore_delete) {
805 compute_processor_sort_keys ();
810 ProcessorBox::compute_processor_sort_keys ()
812 Gtk::TreeModel::Children children = model->children();
813 Route::ProcessorList our_processors;
815 for (Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
816 our_processors.push_back ((*iter)[columns.processor]);
819 if (_route->reorder_processors (our_processors, _placement)) {
821 /* reorder failed, so redisplay */
823 redisplay_processors ();
825 /* now tell them about the problem */
827 ArdourDialog dialog (_("ardour: weird plugin dialog"));
831 You cannot reorder this set of processors\n\
832 in that way because the inputs and\n\
833 outputs do not work correctly."));
835 dialog.get_vbox()->pack_start (label);
836 dialog.add_button (Stock::OK, RESPONSE_ACCEPT);
838 dialog.set_name (X_("PluginIODialog"));
839 dialog.set_position (Gtk::WIN_POS_MOUSE);
840 dialog.set_modal (true);
848 ProcessorBox::rename_processors ()
850 ProcSelection to_be_renamed;
852 get_selected_processors (to_be_renamed);
854 if (to_be_renamed.empty()) {
858 for (ProcSelection::iterator i = to_be_renamed.begin(); i != to_be_renamed.end(); ++i) {
859 rename_processor (*i);
864 ProcessorBox::cut_processors ()
866 ProcSelection to_be_removed;
867 XMLNode* node = new XMLNode (X_("cut"));
869 get_selected_processors (to_be_removed);
871 if (to_be_removed.empty()) {
875 no_processor_redisplay = true;
876 for (ProcSelection::iterator i = to_be_removed.begin(); i != to_be_removed.end(); ++i) {
877 // Do not cut inserts
878 if (boost::dynamic_pointer_cast<PluginInsert>((*i)) != 0 ||
879 (boost::dynamic_pointer_cast<Send>((*i)) != 0)) {
881 void* gui = (*i)->get_gui ();
884 static_cast<Gtk::Widget*>(gui)->hide ();
887 XMLNode& child ((*i)->get_state());
889 if (_route->remove_processor (*i) == 0) {
891 node->add_child_nocopy (child);
898 _rr_selection.set (node);
900 no_processor_redisplay = false;
901 redisplay_processors ();
905 ProcessorBox::copy_processors ()
907 ProcSelection to_be_copied;
908 XMLNode* node = new XMLNode (X_("copy"));
910 get_selected_processors (to_be_copied);
912 if (to_be_copied.empty()) {
916 for (ProcSelection::iterator i = to_be_copied.begin(); i != to_be_copied.end(); ++i) {
917 // Do not copy inserts
918 if (boost::dynamic_pointer_cast<PluginInsert>((*i)) != 0 ||
919 (boost::dynamic_pointer_cast<Send>((*i)) != 0)) {
920 node->add_child_nocopy ((*i)->get_state());
924 _rr_selection.set (node);
928 ProcessorBox::delete_processors ()
930 ProcSelection to_be_deleted;
932 get_selected_processors (to_be_deleted);
934 if (to_be_deleted.empty()) {
938 no_processor_redisplay = true;
940 for (ProcSelection::iterator i = to_be_deleted.begin(); i != to_be_deleted.end(); ++i) {
942 void* gui = (*i)->get_gui ();
945 static_cast<Gtk::Widget*>(gui)->hide ();
948 _route->remove_processor(*i);
951 no_processor_redisplay = false;
952 redisplay_processors ();
956 ProcessorBox::delete_dragged_processors (const list<boost::shared_ptr<Processor> >& procs)
958 list<boost::shared_ptr<Processor> >::const_iterator x;
960 no_processor_redisplay = true;
961 for (x = procs.begin(); x != procs.end(); ++x) {
963 void* gui = (*x)->get_gui ();
966 static_cast<Gtk::Widget*>(gui)->hide ();
969 _route->remove_processor(*x);
972 no_processor_redisplay = false;
973 redisplay_processors ();
977 ProcessorBox::idle_delete_processor (boost::weak_ptr<Processor> weak_processor)
979 boost::shared_ptr<Processor> processor (weak_processor.lock());
985 /* NOT copied to _mixer.selection() */
987 no_processor_redisplay = true;
988 _route->remove_processor (processor);
989 no_processor_redisplay = false;
990 redisplay_processors ();
996 ProcessorBox::rename_processor (boost::shared_ptr<Processor> processor)
998 ArdourPrompter name_prompter (true);
1000 name_prompter.set_prompt (_("rename processor"));
1001 name_prompter.set_initial_text (processor->name());
1002 name_prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
1003 name_prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
1004 name_prompter.show_all ();
1006 switch (name_prompter.run ()) {
1008 case Gtk::RESPONSE_ACCEPT:
1009 name_prompter.get_result (result);
1010 if (result.length()) {
1011 processor->set_name (result);
1020 ProcessorBox::paste_processors ()
1022 if (_rr_selection.processors.empty()) {
1026 cerr << "paste from node called " << _rr_selection.processors.get_node().name() << endl;
1028 paste_processor_state (_rr_selection.processors.get_node().children());
1032 ProcessorBox::paste_processor_state (const XMLNodeList& nlist)
1034 XMLNodeConstIterator niter;
1035 list<boost::shared_ptr<Processor> > copies;
1037 cerr << "Pasting processor selection containing " << nlist.size() << endl;
1039 if (nlist.empty()) {
1043 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1044 cerr << "try using " << (*niter)->name() << endl;
1045 XMLProperty const * type = (*niter)->property ("type");
1048 boost::shared_ptr<Processor> p;
1050 if (type->value() == "send") {
1051 XMLNode n (**niter);
1052 Send::make_unique (n, _session);
1053 p.reset (new Send (_session, _route->mute_master(), n));
1055 } else if (type->value() == "meter") {
1056 p = _route->shared_peak_meter();
1058 } else if (type->value() == "main-outs") {
1059 /* do not copy-n-paste main outs */
1062 } else if (type->value() == "amp") {
1063 /* do not copy-n-paste amp */
1066 } else if (type->value() == "listen") {
1067 p.reset (new Delivery (_session, _route->mute_master(), **niter));
1070 p.reset (new PluginInsert (_session, **niter));
1073 copies.push_back (p);
1076 cerr << "plugin insert constructor failed\n";
1080 if (copies.empty()) {
1084 if (_route->add_processors (copies, _placement)) {
1087 "Copying the set of processors on the clipboard failed,\n\
1088 probably because the I/O configuration of the plugins\n\
1089 could not match the configuration of this track.");
1090 MessageDialog am (msg);
1096 ProcessorBox::activate_processor (boost::shared_ptr<Processor> r)
1102 ProcessorBox::deactivate_processor (boost::shared_ptr<Processor> r)
1108 ProcessorBox::get_selected_processors (ProcSelection& processors)
1110 vector<Gtk::TreeModel::Path> pathlist = processor_display.get_selection()->get_selected_rows();
1112 for (vector<Gtk::TreeModel::Path>::iterator iter = pathlist.begin(); iter != pathlist.end(); ++iter) {
1113 processors.push_back ((*(model->get_iter(*iter)))[columns.processor]);
1118 ProcessorBox::for_selected_processors (void (ProcessorBox::*method)(boost::shared_ptr<Processor>))
1120 vector<Gtk::TreeModel::Path> pathlist = processor_display.get_selection()->get_selected_rows();
1122 for (vector<Gtk::TreeModel::Path>::iterator iter = pathlist.begin(); iter != pathlist.end(); ++iter) {
1123 boost::shared_ptr<Processor> processor = (*(model->get_iter(*iter)))[columns.processor];
1124 (this->*method)(processor);
1129 ProcessorBox::all_processors_active (bool state)
1131 _route->all_processors_active (_placement, state);
1135 ProcessorBox::ab_plugins ()
1137 _route->ab_plugins (ab_direction);
1138 ab_direction = !ab_direction;
1143 ProcessorBox::clear_processors ()
1146 vector<string> choices;
1148 if (boost::dynamic_pointer_cast<AudioTrack>(_route) != 0) {
1149 if (_placement == PreFader) {
1150 prompt = _("Do you really want to remove all pre-fader processors from this track?\n"
1151 "(this cannot be undone)");
1153 prompt = _("Do you really want to remove all post-fader processors from this track?\n"
1154 "(this cannot be undone)");
1157 if (_placement == PreFader) {
1158 prompt = _("Do you really want to remove all pre-fader processors from this bus?\n"
1159 "(this cannot be undone)");
1161 prompt = _("Do you really want to remove all post-fader processors from this bus?\n"
1162 "(this cannot be undone)");
1166 choices.push_back (_("Cancel"));
1167 choices.push_back (_("Yes, remove them all"));
1169 Gtkmm2ext::Choice prompter (prompt, choices);
1171 if (prompter.run () == 1) {
1172 _route->clear_processors (_placement);
1177 ProcessorBox::edit_processor (boost::shared_ptr<Processor> processor)
1179 boost::shared_ptr<Send> send;
1180 boost::shared_ptr<Return> retrn;
1181 boost::shared_ptr<PluginInsert> plugin_insert;
1182 boost::shared_ptr<PortInsert> port_insert;
1185 if (boost::dynamic_pointer_cast<AudioTrack>(_route) != 0) {
1187 if (boost::dynamic_pointer_cast<AudioTrack> (_route)->freeze_state() == AudioTrack::Frozen) {
1192 if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
1194 if (!_session.engine().connected()) {
1198 #ifdef OLD_SEND_EDITING
1199 SendUIWindow *send_ui;
1201 if (send->get_gui() == 0) {
1202 send_ui = new SendUIWindow (send, _session);
1204 WindowTitle title(Glib::get_application_name());
1205 title += send->name();
1206 send_ui->set_title (title.get_string());
1208 send->set_gui (send_ui);
1211 send_ui = reinterpret_cast<SendUIWindow *> (send->get_gui());
1216 if (_parent_strip) {
1217 _parent_strip->gain_meter().set_controls (_route, send->meter(), send->amp()->gain_control(), send->amp());
1218 _parent_strip->panner_ui().set_panner (send->panner());
1222 } else if ((retrn = boost::dynamic_pointer_cast<Return> (processor)) != 0) {
1224 if (!_session.engine().connected()) {
1228 boost::shared_ptr<Return> retrn = boost::dynamic_pointer_cast<Return> (processor);
1230 ReturnUIWindow *return_ui;
1232 if (retrn->get_gui() == 0) {
1234 return_ui = new ReturnUIWindow (retrn, _session);
1236 WindowTitle title(Glib::get_application_name());
1237 title += retrn->name();
1238 return_ui->set_title (title.get_string());
1240 send->set_gui (return_ui);
1243 return_ui = reinterpret_cast<ReturnUIWindow *> (retrn->get_gui());
1248 } else if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (processor)) != 0) {
1250 PluginUIWindow *plugin_ui;
1252 /* these are both allowed to be null */
1254 Container* toplevel = get_toplevel();
1255 Window* win = dynamic_cast<Gtk::Window*>(toplevel);
1257 if (plugin_insert->get_gui() == 0) {
1259 plugin_ui = new PluginUIWindow (win, plugin_insert);
1261 WindowTitle title(Glib::get_application_name());
1262 title += generate_processor_title (plugin_insert);
1263 plugin_ui->set_title (title.get_string());
1265 plugin_insert->set_gui (plugin_ui);
1268 plugin_ui = reinterpret_cast<PluginUIWindow *> (plugin_insert->get_gui());
1269 plugin_ui->set_parent (win);
1274 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (processor)) != 0) {
1276 if (!_session.engine().connected()) {
1277 MessageDialog msg ( _("Not connected to JACK - no I/O changes are possible"));
1282 PortInsertWindow *io_selector;
1284 if (port_insert->get_gui() == 0) {
1285 io_selector = new PortInsertWindow (_session, port_insert);
1286 port_insert->set_gui (io_selector);
1289 io_selector = reinterpret_cast<PortInsertWindow *> (port_insert->get_gui());
1292 gidget = io_selector;
1296 if (gidget->is_visible()) {
1297 gidget->get_window()->raise ();
1299 gidget->show_all ();
1306 ProcessorBox::enter_box (GdkEventCrossing *ev, ProcessorBox* rb)
1308 switch (ev->detail) {
1309 case GDK_NOTIFY_INFERIOR:
1312 case GDK_NOTIFY_VIRTUAL:
1316 _current_processor_box = rb;
1323 ProcessorBox::register_actions ()
1325 Glib::RefPtr<Gtk::ActionGroup> popup_act_grp = Gtk::ActionGroup::create(X_("processormenu"));
1326 Glib::RefPtr<Action> act;
1329 ActionManager::register_action (popup_act_grp, X_("newplugin"), _("New Plugin"),
1330 sigc::ptr_fun (ProcessorBox::rb_choose_plugin));
1332 act = ActionManager::register_action (popup_act_grp, X_("newinsert"), _("New Insert"),
1333 sigc::ptr_fun (ProcessorBox::rb_choose_insert));
1334 ActionManager::jack_sensitive_actions.push_back (act);
1335 act = ActionManager::register_action (popup_act_grp, X_("newsend"), _("New Send ..."),
1336 sigc::ptr_fun (ProcessorBox::rb_choose_send));
1337 ActionManager::jack_sensitive_actions.push_back (act);
1338 act = ActionManager::register_action (popup_act_grp, X_("newreturn"), _("New Return ..."),
1339 sigc::ptr_fun (ProcessorBox::rb_choose_return));
1340 ActionManager::jack_sensitive_actions.push_back (act);
1342 ActionManager::register_action (popup_act_grp, X_("clear"), _("Clear"),
1343 sigc::ptr_fun (ProcessorBox::rb_clear));
1345 /* standard editing stuff */
1346 act = ActionManager::register_action (popup_act_grp, X_("cut"), _("Cut"),
1347 sigc::ptr_fun (ProcessorBox::rb_cut));
1348 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1349 act = ActionManager::register_action (popup_act_grp, X_("copy"), _("Copy"),
1350 sigc::ptr_fun (ProcessorBox::rb_copy));
1351 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1353 act = ActionManager::register_action (popup_act_grp, X_("delete"), _("Delete"),
1354 sigc::ptr_fun (ProcessorBox::rb_delete));
1355 ActionManager::plugin_selection_sensitive_actions.push_back(act); // ??
1357 paste_action = ActionManager::register_action (popup_act_grp, X_("paste"), _("Paste"),
1358 sigc::ptr_fun (ProcessorBox::rb_paste));
1359 act = ActionManager::register_action (popup_act_grp, X_("rename"), _("Rename"),
1360 sigc::ptr_fun (ProcessorBox::rb_rename));
1361 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1362 ActionManager::register_action (popup_act_grp, X_("selectall"), _("Select All"),
1363 sigc::ptr_fun (ProcessorBox::rb_select_all));
1364 ActionManager::register_action (popup_act_grp, X_("deselectall"), _("Deselect All"),
1365 sigc::ptr_fun (ProcessorBox::rb_deselect_all));
1368 act = ActionManager::register_action (popup_act_grp, X_("activate"), _("Activate"),
1369 sigc::ptr_fun (ProcessorBox::rb_activate));
1370 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1371 act = ActionManager::register_action (popup_act_grp, X_("deactivate"), _("Deactivate"),
1372 sigc::ptr_fun (ProcessorBox::rb_deactivate));
1373 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1374 ActionManager::register_action (popup_act_grp, X_("activate_all"), _("Activate all"),
1375 sigc::ptr_fun (ProcessorBox::rb_activate_all));
1376 ActionManager::register_action (popup_act_grp, X_("deactivate_all"), _("Deactivate all"),
1377 sigc::ptr_fun (ProcessorBox::rb_deactivate_all));
1380 act = ActionManager::register_action (popup_act_grp, X_("edit"), _("Edit"),
1381 sigc::ptr_fun (ProcessorBox::rb_edit));
1382 ActionManager::plugin_selection_sensitive_actions.push_back(act);
1384 ActionManager::add_action_group (popup_act_grp);
1388 ProcessorBox::rb_choose_plugin ()
1390 if (_current_processor_box == 0) {
1393 _current_processor_box->choose_plugin ();
1397 ProcessorBox::rb_choose_insert ()
1399 if (_current_processor_box == 0) {
1402 _current_processor_box->choose_insert ();
1406 ProcessorBox::rb_choose_send ()
1408 if (_current_processor_box == 0) {
1411 _current_processor_box->choose_send ();
1415 ProcessorBox::rb_choose_return ()
1417 if (_current_processor_box == 0) {
1420 _current_processor_box->choose_return ();
1424 ProcessorBox::rb_clear ()
1426 if (_current_processor_box == 0) {
1430 _current_processor_box->clear_processors ();
1434 ProcessorBox::rb_cut ()
1436 if (_current_processor_box == 0) {
1440 _current_processor_box->cut_processors ();
1444 ProcessorBox::rb_delete ()
1446 if (_current_processor_box == 0) {
1450 _current_processor_box->delete_processors ();
1454 ProcessorBox::rb_copy ()
1456 if (_current_processor_box == 0) {
1459 _current_processor_box->copy_processors ();
1463 ProcessorBox::rb_paste ()
1465 if (_current_processor_box == 0) {
1469 _current_processor_box->paste_processors ();
1473 ProcessorBox::rb_rename ()
1475 if (_current_processor_box == 0) {
1478 _current_processor_box->rename_processors ();
1482 ProcessorBox::rb_select_all ()
1484 if (_current_processor_box == 0) {
1488 _current_processor_box->select_all_processors ();
1492 ProcessorBox::rb_deselect_all ()
1494 if (_current_processor_box == 0) {
1498 _current_processor_box->deselect_all_processors ();
1502 ProcessorBox::rb_activate ()
1504 if (_current_processor_box == 0) {
1508 _current_processor_box->for_selected_processors (&ProcessorBox::activate_processor);
1512 ProcessorBox::rb_deactivate ()
1514 if (_current_processor_box == 0) {
1517 _current_processor_box->for_selected_processors (&ProcessorBox::deactivate_processor);
1521 ProcessorBox::rb_activate_all ()
1523 if (_current_processor_box == 0) {
1527 _current_processor_box->all_processors_active (true);
1531 ProcessorBox::rb_deactivate_all ()
1533 if (_current_processor_box == 0) {
1536 _current_processor_box->all_processors_active (false);
1540 ProcessorBox::rb_edit ()
1542 if (_current_processor_box == 0) {
1546 _current_processor_box->for_selected_processors (&ProcessorBox::edit_processor);
1550 ProcessorBox::route_name_changed ()
1552 ENSURE_GUI_THREAD (mem_fun (*this, &ProcessorBox::route_name_changed));
1554 boost::shared_ptr<Processor> processor;
1555 boost::shared_ptr<PluginInsert> plugin_insert;
1556 boost::shared_ptr<Send> send;
1558 Gtk::TreeModel::Children children = model->children();
1560 for (Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
1561 Gtk::TreeModel::Row row = *iter;
1563 processor= row[columns.processor];
1565 void* gui = processor->get_gui();
1571 /* rename editor windows for sends and plugins */
1573 WindowTitle title (Glib::get_application_name());
1575 if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
1576 title += send->name();
1577 static_cast<Window*>(gui)->set_title (title.get_string());
1578 } else if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (processor)) != 0) {
1579 title += generate_processor_title (plugin_insert);
1580 static_cast<Window*>(gui)->set_title (title.get_string());
1586 ProcessorBox::generate_processor_title (boost::shared_ptr<PluginInsert> pi)
1588 string maker = pi->plugin()->maker() ? pi->plugin()->maker() : "";
1589 string::size_type email_pos;
1591 if ((email_pos = maker.find_first_of ('<')) != string::npos) {
1592 maker = maker.substr (0, email_pos - 1);
1595 if (maker.length() > 32) {
1596 maker = maker.substr (0, 32);
1600 return string_compose(_("%1: %2 (by %3)"), _route->name(), pi->name(), maker);