ae1d6c73abc8020da4123d897536697bca95507c
[ardour.git] / gtk2_ardour / processor_box.cc
1 /*
2     Copyright (C) 2000-2004 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #include <cmath>
21 #include <iostream>
22 #include <set>
23
24 #include <sigc++/bind.h>
25
26 #include "pbd/convert.h"
27
28 #include <glibmm/miscutils.h>
29
30 #include <gtkmm/messagedialog.h>
31
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>
39
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"
54
55 #include "actions.h"
56 #include "ardour_dialog.h"
57 #include "ardour_ui.h"
58 #include "gui_thread.h"
59 #include "io_selector.h"
60 #include "keyboard.h"
61 #include "mixer_ui.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"
69 #include "send_ui.h"
70 #include "utils.h"
71
72 #include "i18n.h"
73
74 #ifdef HAVE_AUDIOUNITS
75 class AUPluginUI;
76 #endif
77
78 using namespace std;
79 using namespace sigc;
80 using namespace ARDOUR;
81 using namespace PBD;
82 using namespace Gtk;
83 using namespace Glib;
84 using namespace Gtkmm2ext;
85
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;
91
92 ProcessorBox::ProcessorBox (Placement pcmnt, Session& sess, PluginSelector &plugsel,
93                             RouteRedirectSelection & rsel, MixerStrip* parent, bool owner_is_mixer)
94         : _session(sess)
95         , _parent_strip (parent)
96         , _owner_is_mixer (owner_is_mixer)
97         , _placement(pcmnt)
98         , _plugin_selector(plugsel)
99         , _rr_selection(rsel)
100 {
101         if (get_colors) {
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 ));
108                 get_colors = false;
109         }
110
111         _width = Wide;
112         processor_menu = 0;
113         send_action_menu = 0;
114         processor_drag_in_progress = false;
115         no_processor_redisplay = false;
116         ignore_delete = false;
117
118         model = ListStore::create(columns);
119
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));
123         
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));
135
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);
140
141         processor_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
142
143         model->signal_row_deleted().connect (mem_fun (*this, &ProcessorBox::row_deleted));
144
145         processor_scroller.add (processor_display);
146         processor_eventbox.add (processor_scroller);
147
148         processor_scroller.set_size_request (-1, 40);
149
150         pack_start (processor_eventbox, true, true);
151
152         processor_eventbox.signal_enter_notify_event().connect (bind (
153                         sigc::ptr_fun (ProcessorBox::enter_box),
154                         this));
155
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));
160 }
161
162 ProcessorBox::~ProcessorBox ()
163 {
164 }
165
166 void
167 ProcessorBox::set_route (boost::shared_ptr<Route> r)
168 {
169         connections.clear ();
170
171         _route = r;
172
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)));
179
180         redisplay_processors ();
181 }
182
183 void
184 ProcessorBox::route_going_away ()
185 {
186         /* don't keep updating display as processors are deleted */
187         no_processor_redisplay = true;
188 }
189
190
191 void
192 ProcessorBox::object_drop (const list<boost::shared_ptr<Processor> >& procs, Gtk::TreeView* source, Glib::RefPtr<Gdk::DragContext>& context)
193 {
194         cerr << "Drop from " << source << " (mine is " << &processor_display << ") action = " << hex << context->get_suggested_action() << dec << endl;
195                 
196         for (list<boost::shared_ptr<Processor> >::const_iterator i = procs.begin(); i != procs.end(); ++i) {
197                 XMLNode& state = (*i)->get_state ();
198                 XMLNodeList nlist;
199                 nlist.push_back (&state);
200                 paste_processor_state (nlist);
201                 delete &state;
202         }
203         
204         /* since the treeview doesn't take care of this properly, we have to delete the originals
205            ourselves.
206         */
207
208         if ((context->get_suggested_action() == Gdk::ACTION_MOVE) && source) {
209                 ProcessorBox* other = reinterpret_cast<ProcessorBox*> (source->get_data ("processorbox"));
210                 if (other) {
211                         cerr << "source was another processor box, delete the selected items\n";
212                         other->delete_dragged_processors (procs);
213                 }
214         }
215
216         context->drag_finish (true, (context->get_suggested_action() == Gdk::ACTION_MOVE), 0);
217 }
218
219 void
220 ProcessorBox::update()
221 {
222         redisplay_processors ();
223 }
224
225
226 void
227 ProcessorBox::set_width (Width w)
228 {
229         if (_width == w) {
230                 return;
231         }
232         _width = w;
233
234         redisplay_processors ();
235 }
236
237 void
238 ProcessorBox::remove_processor_gui (boost::shared_ptr<Processor> processor)
239 {
240         boost::shared_ptr<Send> send;
241         boost::shared_ptr<Return> retrn;
242         boost::shared_ptr<PortInsert> port_insert;
243
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);
247                 delete io_selector;
248         } else if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
249                 SendUIWindow *sui = reinterpret_cast<SendUIWindow*> (send->get_gui());
250                 send->set_gui (0);
251                 delete sui;
252         } else if ((retrn = boost::dynamic_pointer_cast<Return> (processor)) != 0) {
253                 ReturnUIWindow *rui = reinterpret_cast<ReturnUIWindow*> (retrn->get_gui());
254                 retrn->set_gui (0);
255                 delete rui;
256         }
257 }
258
259 void
260 ProcessorBox::build_send_action_menu ()
261 {
262         using namespace Menu_Helpers;
263
264         send_action_menu = new Menu;
265         send_action_menu->set_name ("ArdourContextMenu");
266         MenuList& items = send_action_menu->items();
267
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)));
270 }
271
272 void
273 ProcessorBox::show_send_controls ()
274 {
275 }
276
277 void
278 ProcessorBox::new_send ()
279 {
280 }
281
282 void
283 ProcessorBox::show_processor_menu (gint arg)
284 {
285         if (processor_menu == 0) {
286                 processor_menu = build_processor_menu ();
287         }
288
289         Gtk::MenuItem* plugin_menu_item = dynamic_cast<Gtk::MenuItem*>(ActionManager::get_widget("/processormenu/newplugin"));
290
291         if (plugin_menu_item) {
292                 plugin_menu_item->set_submenu (_plugin_selector.plugin_menu());
293         }
294
295         paste_action->set_sensitive (!_rr_selection.processors.empty());
296
297         processor_menu->popup (1, arg);
298 }
299
300 void
301 ProcessorBox::processor_drag_begin (GdkDragContext *context)
302 {
303         processor_drag_in_progress = true;
304 }
305
306 void
307 ProcessorBox::processor_drag_end (GdkDragContext *context)
308 {
309         processor_drag_in_progress = false;
310 }
311
312 bool
313 ProcessorBox::processor_button_press_event (GdkEventButton *ev)
314 {
315         TreeIter iter;
316         TreeModel::Path path;
317         TreeViewColumn* column;
318         int cellx;
319         int celly;
320         boost::shared_ptr<Processor> processor;
321         int ret = false;
322         bool selected = false;
323
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);
328                 }
329
330         }
331
332         if (processor && (Keyboard::is_edit_event (ev) || (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS))) {
333
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);
337                 }
338                 ret = true;
339
340         } else if (processor && ev->button == 1 && selected) {
341
342                 // this is purely informational but necessary
343                 ProcessorSelected (processor); // emit
344
345         } else if (!processor && ev->button == 1 && ev->type == GDK_2BUTTON_PRESS) {
346
347                 choose_plugin ();
348                 _plugin_selector.show_manager ();
349         }
350
351
352         return ret;
353 }
354
355 bool
356 ProcessorBox::processor_button_release_event (GdkEventButton *ev)
357 {
358         TreeIter iter;
359         TreeModel::Path path;
360         TreeViewColumn* column;
361         int cellx;
362         int celly;
363         boost::shared_ptr<Processor> processor;
364         int ret = false;
365
366
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];
370                 }
371         }
372
373         if (processor && Keyboard::is_delete_event (ev)) {
374
375                 Glib::signal_idle().connect (bind (
376                                 mem_fun(*this, &ProcessorBox::idle_delete_processor),
377                                 boost::weak_ptr<Processor>(processor)));
378                 ret = true;
379
380         } else if (Keyboard::is_context_menu_event (ev)) {
381
382                 show_processor_menu(ev->time);
383                 ret = true;
384
385         } else if (processor && Keyboard::is_button2_event (ev)
386 #ifndef GTKOSX
387                    && (Keyboard::no_modifier_keys_pressed (ev) && ((ev->state & Gdk::BUTTON2_MASK) == Gdk::BUTTON2_MASK))
388 #endif
389                 ) {
390
391                 /* button2-click with no/appropriate modifiers */
392
393                 if (processor->active()) {
394                         processor->deactivate ();
395                 } else {
396                         processor->activate ();
397                 }
398                 ret = true;
399
400         }
401
402         return ret;
403 }
404
405 Menu *
406 ProcessorBox::build_processor_menu ()
407 {
408         processor_menu = dynamic_cast<Gtk::Menu*>(ActionManager::get_widget("/processormenu") );
409         processor_menu->set_name ("ArdourContextMenu");
410
411         show_all_children();
412
413         return processor_menu;
414 }
415
416 void
417 ProcessorBox::selection_changed ()
418 {
419         bool sensitive = (processor_display.get_selection()->count_selected_rows()) ? true : false;
420         ActionManager::set_sensitive (ActionManager::plugin_selection_sensitive_actions, sensitive);
421 }
422
423 void
424 ProcessorBox::select_all_processors ()
425 {
426         processor_display.get_selection()->select_all();
427 }
428
429 void
430 ProcessorBox::deselect_all_processors ()
431 {
432         processor_display.get_selection()->unselect_all();
433 }
434
435 void
436 ProcessorBox::choose_plugin ()
437 {
438         _plugin_selector.set_interested_object (*this);
439 }
440
441 void
442 ProcessorBox::use_plugins (const SelectedPlugins& plugins)
443 {
444         for (SelectedPlugins::const_iterator p = plugins.begin(); p != plugins.end(); ++p) {
445
446                 boost::shared_ptr<Processor> processor (new PluginInsert (_session, *p));
447
448                 Route::ProcessorStreams err_streams;
449
450                 if (Config->get_new_plugins_active()) {
451                         processor->activate ();
452                 }
453
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?
457                 } else {
458
459                         if (Profile->get_sae()) {
460                                 processor->activate ();
461                         }
462                         processor->ActiveChanged.connect (bind (
463                                         mem_fun (*this, &ProcessorBox::show_processor_active),
464                                         boost::weak_ptr<Processor>(processor)));
465                 }
466         }
467 }
468
469 void
470 ProcessorBox::weird_plugin_dialog (Plugin& p, Route::ProcessorStreams streams)
471 {
472         ArdourDialog dialog (_("ardour: weird plugin dialog"));
473         Label label;
474
475         string text = string_compose(_("You attempted to add the plugin \"%1\" at index %2.\n"),
476                         p.name(), streams.index);
477
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;
480
481         text += _("\nThis plugin has:\n");
482         if (has_midi) {
483                 text += string_compose("\t%1 ", p.get_info()->n_inputs.n_midi()) + _("MIDI input(s)\n");
484         }
485         if (has_audio) {
486                 text += string_compose("\t%1 ", p.get_info()->n_inputs.n_audio()) + _("audio input(s)\n");
487         }
488
489         text += _("\nBut at the insertion point, there are:\n");
490         if (has_midi) {
491                 text += string_compose("\t%1 ", streams.count.n_midi()) + _("MIDI channel(s)\n");
492         }
493         if (has_audio) {
494                 text += string_compose("\t%1 ", streams.count.n_audio()) + _("audio channel(s)\n");
495         }
496
497         text += _("\nArdour is unable to insert this plugin here.\n");
498         label.set_text(text);
499
500         dialog.get_vbox()->pack_start (label);
501         dialog.add_button (Stock::OK, RESPONSE_ACCEPT);
502
503         dialog.set_name (X_("PluginIODialog"));
504         dialog.set_position (Gtk::WIN_POS_MOUSE);
505         dialog.set_modal (true);
506         dialog.show_all ();
507
508         dialog.run ();
509 }
510
511 void
512 ProcessorBox::choose_insert ()
513 {
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)));
518
519         _route->add_processor (processor, _placement);
520 }
521
522 void
523 ProcessorBox::choose_send ()
524 {
525         boost::shared_ptr<Send> send (new Send (_session, _route->mute_master()));
526
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();
531
532         /* XXX need processor lock on route */
533         try {
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;
537                 return;
538         }
539
540         /* let the user adjust the IO setup before creation */
541         IOSelectorWindow *ios = new IOSelectorWindow (_session, send->output(), true);
542         ios->show_all ();
543
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;
547
548         ios->selector().Finished.connect (bind (
549                         mem_fun(*this, &ProcessorBox::send_io_finished),
550                         boost::weak_ptr<Processor>(send), ios));
551 }
552
553 void
554 ProcessorBox::send_io_finished (IOSelector::Result r, boost::weak_ptr<Processor> weak_processor, IOSelectorWindow* ios)
555 {
556         boost::shared_ptr<Processor> processor (weak_processor.lock());
557
558         /* drop our temporary reference to the new send */
559         _processor_being_created.reset ();
560
561         if (!processor) {
562                 return;
563         }
564
565         switch (r) {
566         case IOSelector::Cancelled:
567                 // processor will go away when all shared_ptrs to it vanish
568                 break;
569
570         case IOSelector::Accepted:
571                 _route->add_processor (processor, _placement);
572                 if (Profile->get_sae()) {
573                         processor->activate ();
574                 }
575                 break;
576         }
577
578         delete_when_idle (ios);
579 }
580
581 void
582 ProcessorBox::choose_return ()
583 {
584         boost::shared_ptr<Return> retrn (new Return (_session));
585
586         /* assume user just wants a single audio input (sidechain) by default */
587         ChanCount ins(DataType::AUDIO, 1);
588
589         /* XXX need processor lock on route */
590         try {
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;
594                 return;
595         }
596
597         /* let the user adjust the IO setup before creation */
598         IOSelectorWindow *ios = new IOSelectorWindow (_session, retrn->output(), true);
599         ios->show_all ();
600
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;
604
605         ios->selector().Finished.connect (bind (
606                         mem_fun(*this, &ProcessorBox::return_io_finished),
607                         boost::weak_ptr<Processor>(retrn), ios));
608 }
609
610 void
611 ProcessorBox::return_io_finished (IOSelector::Result r, boost::weak_ptr<Processor> weak_processor, IOSelectorWindow* ios)
612 {
613         boost::shared_ptr<Processor> processor (weak_processor.lock());
614
615         /* drop our temporary reference to the new return */
616         _processor_being_created.reset ();
617
618         if (!processor) {
619                 return;
620         }
621
622         switch (r) {
623         case IOSelector::Cancelled:
624                 // processor will go away when all shared_ptrs to it vanish
625                 break;
626
627         case IOSelector::Accepted:
628                 _route->add_processor (processor, _placement);
629                 if (Profile->get_sae()) {
630                         processor->activate ();
631                 }
632                 break;
633         }
634
635         delete_when_idle (ios);
636 }
637
638 void
639 ProcessorBox::redisplay_processors ()
640 {
641         ENSURE_GUI_THREAD (mem_fun(*this, &ProcessorBox::redisplay_processors));
642
643         if (no_processor_redisplay) {
644                 return;
645         }
646
647         ignore_delete = true;
648         model->clear ();
649         ignore_delete = false;
650
651         processor_active_connections.clear ();
652         processor_name_connections.clear ();
653
654         _route->foreach_processor (_placement, mem_fun (*this, &ProcessorBox::add_processor_to_display));
655
656         switch (_placement) {
657         case PreFader:
658                 build_processor_tooltip (processor_eventbox, _("Pre-fader inserts, sends & plugins:"));
659                 break;
660         case PostFader:
661                 build_processor_tooltip (processor_eventbox, _("Post-fader inserts, sends & plugins:"));
662                 break;
663         }
664 }
665
666 void
667 ProcessorBox::add_processor_to_display (boost::weak_ptr<Processor> p)
668 {
669         boost::shared_ptr<Processor> processor (p.lock ());
670         if (!processor) {
671                 return;
672         }
673
674         if (processor == _route->amp() || !processor->visible()) {
675                 return;
676         }
677
678         Gtk::TreeModel::Row row = *(model->append());
679         row[columns.text] = processor_name (processor);
680         row[columns.processor] = processor;
681
682         show_processor_active (processor);
683
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))));
690 }
691
692 string
693 ProcessorBox::processor_name (boost::weak_ptr<Processor> weak_processor)
694 {
695         boost::shared_ptr<Processor> processor (weak_processor.lock());
696
697         if (!processor) {
698                 return string();
699         }
700
701         boost::shared_ptr<Send> send;
702         string name_display;
703
704         if (!processor->active()) {
705                 name_display = " (";
706         }
707
708         if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
709
710                 name_display += '>';
711
712                 /* grab the send name out of its overall name */
713
714                 string::size_type lbracket, rbracket;
715                 lbracket = send->name().find ('[');
716                 rbracket = send->name().find (']');
717
718                 switch (_width) {
719                 case Wide:
720                         name_display += send->name().substr (lbracket+1, lbracket-rbracket-1);
721                         break;
722                 case Narrow:
723                         name_display += PBD::short_version (send->name().substr (lbracket+1, lbracket-rbracket-1), 4);
724                         break;
725                 }
726
727         } else {
728
729                 switch (_width) {
730                 case Wide:
731                         name_display += processor->name();
732                         break;
733                 case Narrow:
734                         name_display += PBD::short_version (processor->name(), 5);
735                         break;
736                 }
737
738         }
739
740         if (!processor->active()) {
741                 name_display += ')';
742         }
743
744         return name_display;
745 }
746
747 void
748 ProcessorBox::build_processor_tooltip (EventBox& box, string start)
749 {
750         string tip(start);
751
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;
755                 tip += '\n';
756                 tip += row[columns.text];
757         }
758         ARDOUR_UI::instance()->tooltips().set_tip (box, tip);
759 }
760
761 void
762 ProcessorBox::show_processor_name (boost::weak_ptr<Processor> processor)
763 {
764         ENSURE_GUI_THREAD(bind (mem_fun(*this, &ProcessorBox::show_processor_name), processor));
765         show_processor_active (processor);
766 }
767
768 void
769 ProcessorBox::show_processor_active (boost::weak_ptr<Processor> weak_processor)
770 {
771         boost::shared_ptr<Processor> processor (weak_processor.lock());
772
773         if (!processor) {
774                 return;
775         }
776
777         ENSURE_GUI_THREAD(bind (mem_fun(*this, &ProcessorBox::show_processor_active), weak_processor));
778
779         Gtk::TreeModel::Children children = model->children();
780         Gtk::TreeModel::Children::iterator iter = children.begin();
781
782         while (iter != children.end()) {
783
784                 boost::shared_ptr<Processor> r = (*iter)[columns.processor];
785
786                 if (r == processor) {
787                         (*iter)[columns.text] = processor_name (r);
788
789                         if (processor->active()) {
790                                 (*iter)[columns.color] = *active_processor_color;
791                         } else {
792                                 (*iter)[columns.color] = *inactive_processor_color;
793                         }
794                         break;
795                 }
796
797                 iter++;
798         }
799 }
800
801 void
802 ProcessorBox::row_deleted (const Gtk::TreeModel::Path& path)
803 {
804         if (!ignore_delete) {
805                 compute_processor_sort_keys ();
806         }
807 }
808
809 void
810 ProcessorBox::compute_processor_sort_keys ()
811 {
812         Gtk::TreeModel::Children children = model->children();
813         Route::ProcessorList our_processors;
814
815         for (Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
816                 our_processors.push_back ((*iter)[columns.processor]);
817         }
818
819         if (_route->reorder_processors (our_processors, _placement)) {
820
821                 /* reorder failed, so redisplay */
822
823                 redisplay_processors ();
824
825                 /* now tell them about the problem */
826
827                 ArdourDialog dialog (_("ardour: weird plugin dialog"));
828                 Label label;
829
830                 label.set_text (_("\
831 You cannot reorder this set of processors\n\
832 in that way because the inputs and\n\
833 outputs do not work correctly."));
834
835                 dialog.get_vbox()->pack_start (label);
836                 dialog.add_button (Stock::OK, RESPONSE_ACCEPT);
837
838                 dialog.set_name (X_("PluginIODialog"));
839                 dialog.set_position (Gtk::WIN_POS_MOUSE);
840                 dialog.set_modal (true);
841                 dialog.show_all ();
842
843                 dialog.run ();
844         }
845 }
846
847 void
848 ProcessorBox::rename_processors ()
849 {
850         ProcSelection to_be_renamed;
851
852         get_selected_processors (to_be_renamed);
853
854         if (to_be_renamed.empty()) {
855                 return;
856         }
857
858         for (ProcSelection::iterator i = to_be_renamed.begin(); i != to_be_renamed.end(); ++i) {
859                 rename_processor (*i);
860         }
861 }
862
863 void
864 ProcessorBox::cut_processors ()
865 {
866         ProcSelection to_be_removed;
867         XMLNode* node = new XMLNode (X_("cut"));
868
869         get_selected_processors (to_be_removed);
870
871         if (to_be_removed.empty()) {
872                 return;
873         }
874
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)) {
880
881                         void* gui = (*i)->get_gui ();
882
883                         if (gui) {
884                                 static_cast<Gtk::Widget*>(gui)->hide ();
885                         }
886
887                         XMLNode& child ((*i)->get_state());
888
889                         if (_route->remove_processor (*i) == 0) {
890                                 /* success */
891                                 node->add_child_nocopy (child);
892                         } else {
893                                 delete &child;
894                         }
895                 }
896         }
897
898         _rr_selection.set (node);
899
900         no_processor_redisplay = false;
901         redisplay_processors ();
902 }
903
904 void
905 ProcessorBox::copy_processors ()
906 {
907         ProcSelection to_be_copied;
908         XMLNode* node = new XMLNode (X_("copy"));
909
910         get_selected_processors (to_be_copied);
911
912         if (to_be_copied.empty()) {
913                 return;
914         }
915
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());
921                 }
922         }
923
924         _rr_selection.set (node);
925 }
926
927 void
928 ProcessorBox::delete_processors ()
929 {
930         ProcSelection to_be_deleted;
931
932         get_selected_processors (to_be_deleted);
933
934         if (to_be_deleted.empty()) {
935                 return;
936         }
937
938         no_processor_redisplay = true;
939
940         for (ProcSelection::iterator i = to_be_deleted.begin(); i != to_be_deleted.end(); ++i) {
941
942                 void* gui = (*i)->get_gui ();
943
944                 if (gui) {
945                         static_cast<Gtk::Widget*>(gui)->hide ();
946                 }
947
948                 _route->remove_processor(*i);
949         }
950
951         no_processor_redisplay = false;
952         redisplay_processors ();
953 }
954
955 void
956 ProcessorBox::delete_dragged_processors (const list<boost::shared_ptr<Processor> >& procs)
957 {
958         list<boost::shared_ptr<Processor> >::const_iterator x;
959
960         no_processor_redisplay = true;
961         for (x = procs.begin(); x != procs.end(); ++x) {
962
963                 void* gui = (*x)->get_gui ();
964
965                 if (gui) {
966                         static_cast<Gtk::Widget*>(gui)->hide ();
967                 }
968                 
969                 _route->remove_processor(*x);
970         }
971
972         no_processor_redisplay = false;
973         redisplay_processors ();
974 }
975
976 gint
977 ProcessorBox::idle_delete_processor (boost::weak_ptr<Processor> weak_processor)
978 {
979         boost::shared_ptr<Processor> processor (weak_processor.lock());
980
981         if (!processor) {
982                 return false;
983         }
984
985         /* NOT copied to _mixer.selection() */
986
987         no_processor_redisplay = true;
988         _route->remove_processor (processor);
989         no_processor_redisplay = false;
990         redisplay_processors ();
991
992         return false;
993 }
994
995 void
996 ProcessorBox::rename_processor (boost::shared_ptr<Processor> processor)
997 {
998         ArdourPrompter name_prompter (true);
999         string result;
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 ();
1005
1006         switch (name_prompter.run ()) {
1007
1008         case Gtk::RESPONSE_ACCEPT:
1009         name_prompter.get_result (result);
1010         if (result.length()) {
1011                         processor->set_name (result);
1012                 }
1013                 break;
1014         }
1015
1016         return;
1017 }
1018
1019 void
1020 ProcessorBox::paste_processors ()
1021 {
1022         if (_rr_selection.processors.empty()) {
1023                 return;
1024         }
1025
1026         cerr << "paste from node called " << _rr_selection.processors.get_node().name() << endl;
1027
1028         paste_processor_state (_rr_selection.processors.get_node().children());
1029 }
1030
1031 void
1032 ProcessorBox::paste_processor_state (const XMLNodeList& nlist)
1033 {
1034         XMLNodeConstIterator niter;
1035         list<boost::shared_ptr<Processor> > copies;
1036
1037         cerr << "Pasting processor selection containing " << nlist.size() << endl;
1038
1039         if (nlist.empty()) {
1040                 return;
1041         }
1042
1043         for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1044                 cerr << "try using " << (*niter)->name() << endl;
1045                 XMLProperty const * type = (*niter)->property ("type");
1046                 assert (type);
1047
1048                 boost::shared_ptr<Processor> p;
1049                 try {
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));
1054
1055                         } else if (type->value() == "meter") {
1056                                 p = _route->shared_peak_meter();
1057
1058                         } else if (type->value() == "main-outs") {
1059                                 /* do not copy-n-paste main outs */
1060                                 continue;
1061
1062                         } else if (type->value() == "amp") {
1063                                 /* do not copy-n-paste amp */
1064                                 continue;
1065
1066                         } else if (type->value() == "intsend" || type->value() == "intreturn") {
1067                                 /* do not copy-n-paste internal sends&returns */
1068                                 continue;
1069
1070                         } else if (type->value() == "listen") {
1071                                 p.reset (new Delivery (_session, _route->mute_master(), **niter));
1072                                 
1073                         } else {
1074                                 p.reset (new PluginInsert (_session, **niter));
1075                         }
1076
1077                         copies.push_back (p);
1078                 }
1079                 catch (...) {
1080                         cerr << "plugin insert constructor failed\n";
1081                 }
1082         }
1083
1084         if (copies.empty()) {
1085                 return;
1086         }
1087
1088         if (_route->add_processors (copies, _placement)) {
1089
1090                 string msg = _(
1091                         "Copying the set of processors on the clipboard failed,\n\
1092 probably because the I/O configuration of the plugins\n\
1093 could not match the configuration of this track.");
1094                 MessageDialog am (msg);
1095                 am.run ();
1096         }
1097 }
1098
1099 void
1100 ProcessorBox::activate_processor (boost::shared_ptr<Processor> r)
1101 {
1102         r->activate ();
1103 }
1104
1105 void
1106 ProcessorBox::deactivate_processor (boost::shared_ptr<Processor> r)
1107 {
1108         r->deactivate ();
1109 }
1110
1111 void
1112 ProcessorBox::get_selected_processors (ProcSelection& processors)
1113 {
1114     vector<Gtk::TreeModel::Path> pathlist = processor_display.get_selection()->get_selected_rows();
1115
1116     for (vector<Gtk::TreeModel::Path>::iterator iter = pathlist.begin(); iter != pathlist.end(); ++iter) {
1117             processors.push_back ((*(model->get_iter(*iter)))[columns.processor]);
1118     }
1119 }
1120
1121 void
1122 ProcessorBox::for_selected_processors (void (ProcessorBox::*method)(boost::shared_ptr<Processor>))
1123 {
1124     vector<Gtk::TreeModel::Path> pathlist = processor_display.get_selection()->get_selected_rows();
1125
1126         for (vector<Gtk::TreeModel::Path>::iterator iter = pathlist.begin(); iter != pathlist.end(); ++iter) {
1127                 boost::shared_ptr<Processor> processor = (*(model->get_iter(*iter)))[columns.processor];
1128                 (this->*method)(processor);
1129         }
1130 }
1131
1132 void
1133 ProcessorBox::all_processors_active (bool state)
1134 {
1135         _route->all_processors_active (_placement, state);
1136 }
1137
1138 void
1139 ProcessorBox::ab_plugins ()
1140 {
1141         _route->ab_plugins (ab_direction);
1142         ab_direction = !ab_direction;
1143 }
1144
1145
1146 void
1147 ProcessorBox::clear_processors ()
1148 {
1149         string prompt;
1150         vector<string> choices;
1151
1152         if (boost::dynamic_pointer_cast<AudioTrack>(_route) != 0) {
1153                 if (_placement == PreFader) {
1154                         prompt = _("Do you really want to remove all pre-fader processors from this track?\n"
1155                                    "(this cannot be undone)");
1156                 } else {
1157                         prompt = _("Do you really want to remove all post-fader processors from this track?\n"
1158                                    "(this cannot be undone)");
1159                 }
1160         } else {
1161                 if (_placement == PreFader) {
1162                         prompt = _("Do you really want to remove all pre-fader processors from this bus?\n"
1163                                    "(this cannot be undone)");
1164                 } else {
1165                         prompt = _("Do you really want to remove all post-fader processors from this bus?\n"
1166                                    "(this cannot be undone)");
1167                 }
1168         }
1169
1170         choices.push_back (_("Cancel"));
1171         choices.push_back (_("Yes, remove them all"));
1172
1173         Gtkmm2ext::Choice prompter (prompt, choices);
1174
1175         if (prompter.run () == 1) {
1176                 _route->clear_processors (_placement);
1177         }
1178 }
1179
1180 void
1181 ProcessorBox::edit_processor (boost::shared_ptr<Processor> processor)
1182 {
1183         boost::shared_ptr<Send> send;
1184         boost::shared_ptr<Return> retrn;
1185         boost::shared_ptr<PluginInsert> plugin_insert;
1186         boost::shared_ptr<PortInsert> port_insert;
1187         Window* gidget = 0;
1188
1189         if (boost::dynamic_pointer_cast<AudioTrack>(_route) != 0) {
1190
1191                 if (boost::dynamic_pointer_cast<AudioTrack> (_route)->freeze_state() == AudioTrack::Frozen) {
1192                         return;
1193                 }
1194         }
1195
1196         if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
1197
1198                 if (!_session.engine().connected()) {
1199                         return;
1200                 }
1201
1202 #ifdef OLD_SEND_EDITING
1203                 SendUIWindow *send_ui;
1204
1205                 if (send->get_gui() == 0) {
1206                         send_ui = new SendUIWindow (send, _session);
1207
1208                         WindowTitle title(Glib::get_application_name());
1209                         title += send->name();
1210                         send_ui->set_title (title.get_string());
1211
1212                         send->set_gui (send_ui);
1213
1214                 } else {
1215                         send_ui = reinterpret_cast<SendUIWindow *> (send->get_gui());
1216                 }
1217
1218                 gidget = send_ui;
1219 #else
1220                 if (_parent_strip) {
1221                         _parent_strip->gain_meter().set_controls (_route, send->meter(), send->amp()->gain_control(), send->amp());
1222                         _parent_strip->panner_ui().set_panner (send->panner());
1223                 }
1224 #endif
1225         
1226         } else if ((retrn = boost::dynamic_pointer_cast<Return> (processor)) != 0) {
1227
1228                 if (!_session.engine().connected()) {
1229                         return;
1230                 }
1231
1232                 boost::shared_ptr<Return> retrn = boost::dynamic_pointer_cast<Return> (processor);
1233
1234                 ReturnUIWindow *return_ui;
1235
1236                 if (retrn->get_gui() == 0) {
1237
1238                         return_ui = new ReturnUIWindow (retrn, _session);
1239
1240                         WindowTitle title(Glib::get_application_name());
1241                         title += retrn->name();
1242                         return_ui->set_title (title.get_string());
1243
1244                         send->set_gui (return_ui);
1245
1246                 } else {
1247                         return_ui = reinterpret_cast<ReturnUIWindow *> (retrn->get_gui());
1248                 }
1249
1250                 gidget = return_ui;
1251
1252         } else if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (processor)) != 0) {
1253
1254                 PluginUIWindow *plugin_ui;
1255
1256                 /* these are both allowed to be null */
1257
1258                 Container* toplevel = get_toplevel();
1259                 Window* win = dynamic_cast<Gtk::Window*>(toplevel);
1260
1261                 if (plugin_insert->get_gui() == 0) {
1262
1263                         plugin_ui = new PluginUIWindow (win, plugin_insert);
1264
1265                         WindowTitle title(Glib::get_application_name());
1266                         title += generate_processor_title (plugin_insert);
1267                         plugin_ui->set_title (title.get_string());
1268
1269                         plugin_insert->set_gui (plugin_ui);
1270
1271                 } else {
1272                         plugin_ui = reinterpret_cast<PluginUIWindow *> (plugin_insert->get_gui());
1273                         plugin_ui->set_parent (win);
1274                 }
1275
1276                 gidget = plugin_ui;
1277
1278         } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (processor)) != 0) {
1279
1280                 if (!_session.engine().connected()) {
1281                         MessageDialog msg ( _("Not connected to JACK - no I/O changes are possible"));
1282                         msg.run ();
1283                         return;
1284                 }
1285
1286                 PortInsertWindow *io_selector;
1287
1288                 if (port_insert->get_gui() == 0) {
1289                         io_selector = new PortInsertWindow (_session, port_insert);
1290                         port_insert->set_gui (io_selector);
1291
1292                 } else {
1293                         io_selector = reinterpret_cast<PortInsertWindow *> (port_insert->get_gui());
1294                 }
1295
1296                 gidget = io_selector;
1297         }
1298
1299         if (gidget) {
1300                 if (gidget->is_visible()) {
1301                         gidget->get_window()->raise ();
1302                 } else {
1303                         gidget->show_all ();
1304                         gidget->present ();
1305                 }
1306         }
1307 }
1308
1309 bool
1310 ProcessorBox::enter_box (GdkEventCrossing *ev, ProcessorBox* rb)
1311 {
1312         switch (ev->detail) {
1313         case GDK_NOTIFY_INFERIOR:
1314                 break;
1315
1316         case GDK_NOTIFY_VIRTUAL:
1317                 /* fallthru */
1318
1319         default:
1320                 _current_processor_box = rb;
1321         }
1322
1323         return false;
1324 }
1325
1326 void
1327 ProcessorBox::register_actions ()
1328 {
1329         Glib::RefPtr<Gtk::ActionGroup> popup_act_grp = Gtk::ActionGroup::create(X_("processormenu"));
1330         Glib::RefPtr<Action> act;
1331
1332         /* new stuff */
1333         ActionManager::register_action (popup_act_grp, X_("newplugin"), _("New Plugin"),
1334                         sigc::ptr_fun (ProcessorBox::rb_choose_plugin));
1335
1336         act = ActionManager::register_action (popup_act_grp, X_("newinsert"), _("New Insert"),
1337                         sigc::ptr_fun (ProcessorBox::rb_choose_insert));
1338         ActionManager::jack_sensitive_actions.push_back (act);
1339         act = ActionManager::register_action (popup_act_grp, X_("newsend"), _("New Send ..."),
1340                         sigc::ptr_fun (ProcessorBox::rb_choose_send));
1341         ActionManager::jack_sensitive_actions.push_back (act);
1342         act = ActionManager::register_action (popup_act_grp, X_("newreturn"), _("New Return ..."),
1343                         sigc::ptr_fun (ProcessorBox::rb_choose_return));
1344         ActionManager::jack_sensitive_actions.push_back (act);
1345
1346         ActionManager::register_action (popup_act_grp, X_("clear"), _("Clear"),
1347                         sigc::ptr_fun (ProcessorBox::rb_clear));
1348
1349         /* standard editing stuff */
1350         act = ActionManager::register_action (popup_act_grp, X_("cut"), _("Cut"),
1351                         sigc::ptr_fun (ProcessorBox::rb_cut));
1352         ActionManager::plugin_selection_sensitive_actions.push_back(act);
1353         act = ActionManager::register_action (popup_act_grp, X_("copy"), _("Copy"),
1354                         sigc::ptr_fun (ProcessorBox::rb_copy));
1355         ActionManager::plugin_selection_sensitive_actions.push_back(act);
1356
1357         act = ActionManager::register_action (popup_act_grp, X_("delete"), _("Delete"),
1358                         sigc::ptr_fun (ProcessorBox::rb_delete));
1359         ActionManager::plugin_selection_sensitive_actions.push_back(act); // ??
1360
1361         paste_action = ActionManager::register_action (popup_act_grp, X_("paste"), _("Paste"),
1362                         sigc::ptr_fun (ProcessorBox::rb_paste));
1363         act = ActionManager::register_action (popup_act_grp, X_("rename"), _("Rename"),
1364                         sigc::ptr_fun (ProcessorBox::rb_rename));
1365         ActionManager::plugin_selection_sensitive_actions.push_back(act);
1366         ActionManager::register_action (popup_act_grp, X_("selectall"), _("Select All"),
1367                         sigc::ptr_fun (ProcessorBox::rb_select_all));
1368         ActionManager::register_action (popup_act_grp, X_("deselectall"), _("Deselect All"),
1369                         sigc::ptr_fun (ProcessorBox::rb_deselect_all));
1370
1371         /* activation */
1372         act = ActionManager::register_action (popup_act_grp, X_("activate"), _("Activate"),
1373                         sigc::ptr_fun (ProcessorBox::rb_activate));
1374         ActionManager::plugin_selection_sensitive_actions.push_back(act);
1375         act = ActionManager::register_action (popup_act_grp, X_("deactivate"), _("Deactivate"),
1376                         sigc::ptr_fun (ProcessorBox::rb_deactivate));
1377         ActionManager::plugin_selection_sensitive_actions.push_back(act);
1378         ActionManager::register_action (popup_act_grp, X_("activate_all"), _("Activate all"),
1379                         sigc::ptr_fun (ProcessorBox::rb_activate_all));
1380         ActionManager::register_action (popup_act_grp, X_("deactivate_all"), _("Deactivate all"),
1381                         sigc::ptr_fun (ProcessorBox::rb_deactivate_all));
1382
1383         /* show editors */
1384         act = ActionManager::register_action (popup_act_grp, X_("edit"), _("Edit"),
1385                         sigc::ptr_fun (ProcessorBox::rb_edit));
1386         ActionManager::plugin_selection_sensitive_actions.push_back(act);
1387
1388         ActionManager::add_action_group (popup_act_grp);
1389 }
1390
1391 void
1392 ProcessorBox::rb_choose_plugin ()
1393 {
1394         if (_current_processor_box == 0) {
1395                 return;
1396         }
1397         _current_processor_box->choose_plugin ();
1398 }
1399
1400 void
1401 ProcessorBox::rb_choose_insert ()
1402 {
1403         if (_current_processor_box == 0) {
1404                 return;
1405         }
1406         _current_processor_box->choose_insert ();
1407 }
1408
1409 void
1410 ProcessorBox::rb_choose_send ()
1411 {
1412         if (_current_processor_box == 0) {
1413                 return;
1414         }
1415         _current_processor_box->choose_send ();
1416 }
1417
1418 void
1419 ProcessorBox::rb_choose_return ()
1420 {
1421         if (_current_processor_box == 0) {
1422                 return;
1423         }
1424         _current_processor_box->choose_return ();
1425 }
1426
1427 void
1428 ProcessorBox::rb_clear ()
1429 {
1430         if (_current_processor_box == 0) {
1431                 return;
1432         }
1433
1434         _current_processor_box->clear_processors ();
1435 }
1436
1437 void
1438 ProcessorBox::rb_cut ()
1439 {
1440         if (_current_processor_box == 0) {
1441                 return;
1442         }
1443
1444         _current_processor_box->cut_processors ();
1445 }
1446
1447 void
1448 ProcessorBox::rb_delete ()
1449 {
1450         if (_current_processor_box == 0) {
1451                 return;
1452         }
1453
1454         _current_processor_box->delete_processors ();
1455 }
1456
1457 void
1458 ProcessorBox::rb_copy ()
1459 {
1460         if (_current_processor_box == 0) {
1461                 return;
1462         }
1463         _current_processor_box->copy_processors ();
1464 }
1465
1466 void
1467 ProcessorBox::rb_paste ()
1468 {
1469         if (_current_processor_box == 0) {
1470                 return;
1471         }
1472
1473         _current_processor_box->paste_processors ();
1474 }
1475
1476 void
1477 ProcessorBox::rb_rename ()
1478 {
1479         if (_current_processor_box == 0) {
1480                 return;
1481         }
1482         _current_processor_box->rename_processors ();
1483 }
1484
1485 void
1486 ProcessorBox::rb_select_all ()
1487 {
1488         if (_current_processor_box == 0) {
1489                 return;
1490         }
1491
1492         _current_processor_box->select_all_processors ();
1493 }
1494
1495 void
1496 ProcessorBox::rb_deselect_all ()
1497 {
1498         if (_current_processor_box == 0) {
1499                 return;
1500         }
1501
1502         _current_processor_box->deselect_all_processors ();
1503 }
1504
1505 void
1506 ProcessorBox::rb_activate ()
1507 {
1508         if (_current_processor_box == 0) {
1509                 return;
1510         }
1511
1512         _current_processor_box->for_selected_processors (&ProcessorBox::activate_processor);
1513 }
1514
1515 void
1516 ProcessorBox::rb_deactivate ()
1517 {
1518         if (_current_processor_box == 0) {
1519                 return;
1520         }
1521         _current_processor_box->for_selected_processors (&ProcessorBox::deactivate_processor);
1522 }
1523
1524 void
1525 ProcessorBox::rb_activate_all ()
1526 {
1527         if (_current_processor_box == 0) {
1528                 return;
1529         }
1530
1531         _current_processor_box->all_processors_active (true);
1532 }
1533
1534 void
1535 ProcessorBox::rb_deactivate_all ()
1536 {
1537         if (_current_processor_box == 0) {
1538                 return;
1539         }
1540         _current_processor_box->all_processors_active (false);
1541 }
1542
1543 void
1544 ProcessorBox::rb_edit ()
1545 {
1546         if (_current_processor_box == 0) {
1547                 return;
1548         }
1549
1550         _current_processor_box->for_selected_processors (&ProcessorBox::edit_processor);
1551 }
1552
1553 void
1554 ProcessorBox::route_name_changed ()
1555 {
1556         ENSURE_GUI_THREAD (mem_fun (*this, &ProcessorBox::route_name_changed));
1557
1558         boost::shared_ptr<Processor> processor;
1559         boost::shared_ptr<PluginInsert> plugin_insert;
1560         boost::shared_ptr<Send> send;
1561
1562         Gtk::TreeModel::Children children = model->children();
1563
1564         for (Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
1565                 Gtk::TreeModel::Row row = *iter;
1566
1567                 processor= row[columns.processor];
1568
1569                 void* gui = processor->get_gui();
1570
1571                 if (!gui) {
1572                         continue;
1573                 }
1574
1575                 /* rename editor windows for sends and plugins */
1576
1577                 WindowTitle title (Glib::get_application_name());
1578
1579                 if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
1580                         title += send->name();
1581                         static_cast<Window*>(gui)->set_title (title.get_string());
1582                 } else if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (processor)) != 0) {
1583                         title += generate_processor_title (plugin_insert);
1584                         static_cast<Window*>(gui)->set_title (title.get_string());
1585                 }
1586         }
1587 }
1588
1589 string
1590 ProcessorBox::generate_processor_title (boost::shared_ptr<PluginInsert> pi)
1591 {
1592         string maker = pi->plugin()->maker() ? pi->plugin()->maker() : "";
1593         string::size_type email_pos;
1594
1595         if ((email_pos = maker.find_first_of ('<')) != string::npos) {
1596                 maker = maker.substr (0, email_pos - 1);
1597         }
1598
1599         if (maker.length() > 32) {
1600                 maker = maker.substr (0, 32);
1601                 maker += " ...";
1602         }
1603
1604         return string_compose(_("%1: %2 (by %3)"), _route->name(), pi->name(), maker);
1605 }
1606