7dc2f4f25f4013b29b07113f64f568b0ea6eb5a2
[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 #ifdef WAF_BUILD
21 #include "gtk2ardour-config.h"
22 #endif
23
24 #include <cmath>
25 #include <iostream>
26 #include <set>
27
28 #include <sigc++/bind.h>
29
30 #include "pbd/convert.h"
31
32 #include <glibmm/miscutils.h>
33
34 #include <gtkmm/messagedialog.h>
35
36 #include <gtkmm2ext/gtk_ui.h>
37 #include <gtkmm2ext/utils.h>
38 #include <gtkmm2ext/choice.h>
39 #include <gtkmm2ext/utils.h>
40 #include <gtkmm2ext/doi.h>
41
42 #include "ardour/amp.h"
43 #include "ardour/ardour.h"
44 #include "ardour/audio_track.h"
45 #include "ardour/audioengine.h"
46 #include "ardour/internal_send.h"
47 #include "ardour/internal_return.h"
48 #include "ardour/ladspa_plugin.h"
49 #include "ardour/meter.h"
50 #include "ardour/plugin_insert.h"
51 #include "ardour/port_insert.h"
52 #include "ardour/profile.h"
53 #include "ardour/return.h"
54 #include "ardour/route.h"
55 #include "ardour/send.h"
56 #include "ardour/session.h"
57 #include "ardour/dB.h"
58
59 #include "actions.h"
60 #include "ardour_dialog.h"
61 #include "ardour_ui.h"
62 #include "gui_thread.h"
63 #include "io_selector.h"
64 #include "keyboard.h"
65 #include "mixer_ui.h"
66 #include "mixer_strip.h"
67 #include "plugin_selector.h"
68 #include "plugin_ui.h"
69 #include "port_insert_ui.h"
70 #include "processor_box.h"
71 #include "public_editor.h"
72 #include "return_ui.h"
73 #include "route_processor_selection.h"
74 #include "send_ui.h"
75 #include "utils.h"
76
77 #include "i18n.h"
78
79 #ifdef HAVE_AUDIOUNITS
80 class AUPluginUI;
81 #endif
82
83 using namespace std;
84 using namespace ARDOUR;
85 using namespace PBD;
86 using namespace Gtk;
87 using namespace Glib;
88 using namespace Gtkmm2ext;
89
90 ProcessorBox* ProcessorBox::_current_processor_box = 0;
91 RefPtr<Action> ProcessorBox::paste_action;
92 RefPtr<Action> ProcessorBox::cut_action;
93 RefPtr<Action> ProcessorBox::rename_action;
94 RefPtr<Action> ProcessorBox::edit_action;
95 Glib::RefPtr<Gdk::Pixbuf> SendProcessorEntry::_slider;
96
97 ProcessorEntry::ProcessorEntry (boost::shared_ptr<Processor> p, Width w)
98         : _position (PreFader)
99         , _processor (p)
100         , _width (w)
101         , _visual_state (Gtk::STATE_NORMAL)
102 {
103         _hbox.pack_start (_active, false, false);
104         _event_box.add (_name);
105         _hbox.pack_start (_event_box, true, true);
106         _vbox.pack_start (_hbox);
107         _frame.add (_vbox);
108
109         /* without this, the border is mis-drawn on some systems */
110         _vbox.set_border_width (1);
111
112         _name.set_alignment (0, 0.5);
113         _name.set_text (name ());
114         _name.set_padding (2, 2);
115
116         if (boost::dynamic_pointer_cast<Amp> (p)) {
117                 /* Fader processor gets a special look */
118                 _event_box.set_name ("ProcessorFader");
119                 _frame.set_name ("ProcessorFaderFrame");
120                 _name.set_padding (2, 4);
121         }
122
123         _active.set_active (_processor->active ());
124         _active.signal_toggled().connect (sigc::mem_fun (*this, &ProcessorEntry::active_toggled));
125
126         _frame.show ();
127         _vbox.show ();
128         _hbox.show ();
129         _event_box.show ();
130         _name.show ();
131         _active.show ();
132         
133         _processor->ActiveChanged.connect (active_connection, invalidator (*this), boost::bind (&ProcessorEntry::processor_active_changed, this), gui_context());
134         _processor->PropertyChanged.connect (name_connection, invalidator (*this), ui_bind (&ProcessorEntry::processor_property_changed, this, _1), gui_context());
135 }
136
137 EventBox&
138 ProcessorEntry::action_widget ()
139 {
140         return _event_box;
141 }
142
143 Gtk::Widget&
144 ProcessorEntry::widget ()
145 {
146         return _frame;
147 }
148
149 string
150 ProcessorEntry::drag_text () const
151 {
152         return name ();
153 }
154
155 void
156 ProcessorEntry::set_visual_state (Gtk::StateType t)
157 {
158         _visual_state = t;
159         setup_visuals ();
160 }
161
162 void
163 ProcessorEntry::set_position (Position p)
164 {
165         _position = p;
166         setup_visuals ();
167 }
168
169 void
170 ProcessorEntry::setup_visuals ()
171 {
172         switch (_position) {
173         case PreFader:
174                 _event_box.set_name ("ProcessorPreFader");
175                 if (_visual_state == Gtk::STATE_NORMAL) {
176                         _frame.set_name ("ProcessorPreFaderFrame");
177                 }
178                 break;
179
180         case Fader:
181                 _event_box.set_name ("ProcessorFader");
182                 if (_visual_state == Gtk::STATE_NORMAL) {
183                         _frame.set_name ("ProcessorFaderFrame");
184                 }
185                 break;
186
187         case PostFader:
188                 _event_box.set_name ("ProcessorPostFader");
189                 if (_visual_state == Gtk::STATE_NORMAL) {
190                         _frame.set_name ("ProcessorPostFaderFrame");
191                 }
192                 break;
193         }
194
195         switch (_visual_state) {
196         case Gtk::STATE_NORMAL:
197                 /* _frame has been set up above */
198                 _event_box.set_state (Gtk::STATE_NORMAL);
199                 break;
200         case Gtk::STATE_SELECTED:
201                 _frame.set_name ("ProcessorFrameSelected");
202                 /* don't change the background of the box when it is selected */
203                 _event_box.set_state (Gtk::STATE_NORMAL);
204                 break;
205         case Gtk::STATE_ACTIVE:
206                 _frame.set_name ("ProcessorFrameActiveSend");
207                 _event_box.set_state (Gtk::STATE_ACTIVE);
208                 break;
209         default:
210                 break;
211         }
212 }
213         
214
215 boost::shared_ptr<Processor>
216 ProcessorEntry::processor () const
217 {
218         return _processor;
219 }
220
221 void
222 ProcessorEntry::set_enum_width (Width w)
223 {
224         _width = w;
225 }
226
227 void
228 ProcessorEntry::active_toggled ()
229 {
230         if (_active.get_active ()) {
231                 if (!_processor->active ()) {
232                         _processor->activate ();
233                 }
234         } else {
235                 if (_processor->active ()) {
236                         _processor->deactivate ();
237                 }
238         }
239 }
240
241 void
242 ProcessorEntry::processor_active_changed ()
243 {
244         if (_active.get_active () != _processor->active ()) {
245                 _active.set_active (_processor->active ());
246         }
247 }
248
249 void
250 ProcessorEntry::processor_property_changed (const PropertyChange& what_changed)
251 {
252         if (what_changed.contains (ARDOUR::Properties::name)) {
253                 _name.set_text (name ());
254         }
255 }
256
257 string
258 ProcessorEntry::name () const
259 {
260         boost::shared_ptr<Send> send;
261         string name_display;
262         
263         if ((send = boost::dynamic_pointer_cast<Send> (_processor)) != 0 &&
264             !boost::dynamic_pointer_cast<InternalSend>(_processor)) {
265                 
266                 name_display += '>';
267                 
268                 /* grab the send name out of its overall name */
269                 
270                 string::size_type lbracket, rbracket;
271                 lbracket = send->name().find ('[');
272                 rbracket = send->name().find (']');
273                 
274                 switch (_width) {
275                 case Wide:
276                         name_display += send->name().substr (lbracket+1, lbracket-rbracket-1);
277                         break;
278                 case Narrow:
279                         name_display += PBD::short_version (send->name().substr (lbracket+1, lbracket-rbracket-1), 4);
280                         break;
281                 }
282                 
283         } else {
284                 
285                 switch (_width) {
286                 case Wide:
287                         name_display += _processor->display_name();
288                         break;
289                 case Narrow:
290                         name_display += PBD::short_version (_processor->display_name(), 5);
291                         break;
292                 }
293                 
294         }
295         
296         return name_display;
297 }
298
299 SendProcessorEntry::SendProcessorEntry (boost::shared_ptr<Send> s, Width w)
300         : ProcessorEntry (s, w),
301           _send (s),
302           /* set the adjustment to a gain of 0dB so that the fader's default value is right */
303           _adjustment (0.781787, 0, 1, 0.01, 0.1),
304           _fader (_slider, &_adjustment, 0, false),
305           _ignore_gain_change (false)
306 {
307         _fader.set_name ("SendFader");
308         _fader.set_controllable (_send->amp()->gain_control ());
309         _vbox.pack_start (_fader);
310
311         _fader.show ();
312
313         _adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &SendProcessorEntry::gain_adjusted));
314         _send->amp()->gain_control()->Changed.connect (send_gain_connection, invalidator (*this), boost::bind (&SendProcessorEntry::show_gain, this), gui_context());
315         show_gain ();
316 }
317
318 void
319 SendProcessorEntry::setup_slider_pix ()
320 {
321         _slider = ::get_icon ("fader_belt_h_thin");
322         assert (_slider);
323 }
324
325 void
326 SendProcessorEntry::show_gain ()
327 {
328         ENSURE_GUI_THREAD (*this, &SendProcessorEntry::show_gain)
329         
330         float const value = gain_to_slider_position (_send->amp()->gain ());
331
332         if (_adjustment.get_value() != value) {
333                 _ignore_gain_change = true;
334                 _adjustment.set_value (value);
335                 _ignore_gain_change = false;
336
337                 stringstream s;
338                 s.precision (1);
339                 s.setf (ios::fixed, ios::floatfield);
340                 s << accurate_coefficient_to_dB (_send->amp()->gain ()) << _("dB");
341                 _fader.set_tooltip_text (s.str ());
342         }
343 }
344
345 void
346 SendProcessorEntry::gain_adjusted ()
347 {
348         if (_ignore_gain_change) {
349                 return;
350         }
351
352         _send->amp()->set_gain (slider_position_to_gain (_adjustment.get_value()), this);
353 }
354
355 void
356 SendProcessorEntry::set_pixel_width (int p)
357 {
358         _fader.set_fader_length (p);
359 }
360
361 PluginInsertProcessorEntry::PluginInsertProcessorEntry (boost::shared_ptr<ARDOUR::PluginInsert> p, Width w)
362         : ProcessorEntry (p, w)
363         , _plugin_insert (p)
364 {
365         p->SplittingChanged.connect (
366                 _splitting_connection, invalidator (*this), ui_bind (&PluginInsertProcessorEntry::plugin_insert_splitting_changed, this), gui_context()
367                 );
368
369         _splitting_icon.set_size_request (-1, 12);
370
371         _vbox.pack_start (_splitting_icon);
372         _vbox.reorder_child (_splitting_icon, 0);
373
374         plugin_insert_splitting_changed ();
375 }
376
377 void
378 PluginInsertProcessorEntry::plugin_insert_splitting_changed ()
379 {
380         if (_plugin_insert->splitting ()) {
381                 _splitting_icon.show ();
382         } else {
383                 _splitting_icon.hide ();
384         }
385 }
386
387 void
388 PluginInsertProcessorEntry::setup_visuals ()
389 {
390         switch (_position) {
391         case PreFader:
392                 _splitting_icon.set_name ("ProcessorPreFader");
393                 break;
394
395         case Fader:
396                 _splitting_icon.set_name ("ProcessorFader");
397                 break;
398
399         case PostFader:
400                 _splitting_icon.set_name ("ProcessorPostFader");
401                 break;
402         }
403
404         ProcessorEntry::setup_visuals ();
405 }
406
407 bool
408 PluginInsertProcessorEntry::SplittingIcon::on_expose_event (GdkEventExpose* ev)
409 {
410         cairo_t* cr = gdk_cairo_create (get_window()->gobj());
411
412         cairo_set_line_width (cr, 1);
413
414         double const width = ev->area.width;
415         double const height = ev->area.height;
416
417         Gdk::Color const bg = get_style()->get_bg (STATE_NORMAL);
418         cairo_set_source_rgb (cr, bg.get_red_p (), bg.get_green_p (), bg.get_blue_p ());
419         
420         cairo_rectangle (cr, 0, 0, width, height);
421         cairo_fill (cr);
422
423         Gdk::Color const fg = get_style()->get_fg (STATE_NORMAL);
424         cairo_set_source_rgb (cr, fg.get_red_p (), fg.get_green_p (), fg.get_blue_p ());
425
426         cairo_move_to (cr, width * 0.3, height);
427         cairo_line_to (cr, width * 0.3, height * 0.5);
428         cairo_line_to (cr, width * 0.7, height * 0.5);
429         cairo_line_to (cr, width * 0.7, height);
430         cairo_move_to (cr, width * 0.5, height * 0.5);
431         cairo_line_to (cr, width * 0.5, 0);
432         cairo_stroke (cr);
433
434         return true;
435 }
436
437 ProcessorBox::ProcessorBox (ARDOUR::Session* sess, boost::function<PluginSelector*()> get_plugin_selector,
438                             RouteRedirectSelection& rsel, MixerStrip* parent, bool owner_is_mixer)
439         : _parent_strip (parent)
440         , _owner_is_mixer (owner_is_mixer)
441         , ab_direction (true)
442         , _get_plugin_selector (get_plugin_selector)
443         , _placement(PreFader)
444         , _rr_selection(rsel)
445 {
446         set_session (sess);
447
448         _width = Wide;
449         processor_menu = 0;
450         send_action_menu = 0;
451         no_processor_redisplay = false;
452
453         processor_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
454         processor_scroller.add (processor_display);
455         pack_start (processor_scroller, true, true);
456
457         processor_display.set_flags (CAN_FOCUS);
458         processor_display.set_name ("ProcessorList");
459         processor_display.set_size_request (48, -1);
460         processor_display.set_data ("processorbox", this);
461         processor_display.set_spacing (2);
462
463         processor_display.signal_enter_notify_event().connect (sigc::mem_fun(*this, &ProcessorBox::enter_notify), false);
464         processor_display.signal_leave_notify_event().connect (sigc::mem_fun(*this, &ProcessorBox::leave_notify), false);
465
466         processor_display.signal_key_press_event().connect (sigc::mem_fun(*this, &ProcessorBox::processor_key_press_event));
467         processor_display.signal_key_release_event().connect (sigc::mem_fun(*this, &ProcessorBox::processor_key_release_event));
468
469         processor_display.ButtonPress.connect (sigc::mem_fun (*this, &ProcessorBox::processor_button_press_event));
470         processor_display.ButtonRelease.connect (sigc::mem_fun (*this, &ProcessorBox::processor_button_release_event));
471
472         processor_display.Reordered.connect (sigc::mem_fun (*this, &ProcessorBox::reordered));
473         processor_display.DropFromAnotherBox.connect (sigc::mem_fun (*this, &ProcessorBox::object_drop));
474         processor_display.SelectionChanged.connect (sigc::mem_fun (*this, &ProcessorBox::selection_changed));
475
476         processor_scroller.show ();
477         processor_display.show ();
478
479         if (parent) {
480                 parent->DeliveryChanged.connect (
481                         _mixer_strip_connections, invalidator (*this), ui_bind (&ProcessorBox::mixer_strip_delivery_changed, this, _1), gui_context ()
482                         );
483         }
484 }
485
486 ProcessorBox::~ProcessorBox ()
487 {
488 }
489
490 void
491 ProcessorBox::set_route (boost::shared_ptr<Route> r)
492 {
493         if (_route == r) {
494                 return;
495         }
496         
497         _route_connections.drop_connections();
498
499         /* new route: any existing block on processor redisplay must be meaningless */
500         no_processor_redisplay = false;
501         _route = r;
502
503         _route->processors_changed.connect (
504                 _route_connections, invalidator (*this), ui_bind (&ProcessorBox::route_processors_changed, this, _1), gui_context()
505                 );
506         
507         _route->DropReferences.connect (
508                 _route_connections, invalidator (*this), boost::bind (&ProcessorBox::route_going_away, this), gui_context()
509                 );
510         
511         _route->PropertyChanged.connect (
512                 _route_connections, invalidator (*this), ui_bind (&ProcessorBox::route_property_changed, this, _1), gui_context()
513                 );
514
515         redisplay_processors ();
516 }
517
518 void
519 ProcessorBox::route_going_away ()
520 {
521         /* don't keep updating display as processors are deleted */
522         no_processor_redisplay = true;
523 }
524
525 void
526 ProcessorBox::object_drop(DnDVBox<ProcessorEntry>* source, ProcessorEntry* position, Glib::RefPtr<Gdk::DragContext> const & context)
527 {
528         boost::shared_ptr<Processor> p;
529         if (position) {
530                 p = position->processor ();
531         }
532
533         list<ProcessorEntry*> children = source->selection ();
534         list<boost::shared_ptr<Processor> > procs;
535         for (list<ProcessorEntry*>::const_iterator i = children.begin(); i != children.end(); ++i) {
536                 procs.push_back ((*i)->processor ());
537         }
538
539         for (list<boost::shared_ptr<Processor> >::const_iterator i = procs.begin(); i != procs.end(); ++i) {
540                 XMLNode& state = (*i)->get_state ();
541                 XMLNodeList nlist;
542                 nlist.push_back (&state);
543                 paste_processor_state (nlist, p);
544                 delete &state;
545         }
546
547         /* since the dndvbox doesn't take care of this properly, we have to delete the originals
548            ourselves.
549         */
550
551         if ((context->get_suggested_action() == Gdk::ACTION_MOVE) && source) {
552                 ProcessorBox* other = reinterpret_cast<ProcessorBox*> (source->get_data ("processorbox"));
553                 if (other) {
554                         cerr << "source was another processor box, delete the selected items\n";
555                         other->delete_dragged_processors (procs);
556                 }
557         }
558 }
559
560 void
561 ProcessorBox::update()
562 {
563         redisplay_processors ();
564 }
565
566 void
567 ProcessorBox::set_width (Width w)
568 {
569         if (_width == w) {
570                 return;
571         }
572         
573         _width = w;
574
575         list<ProcessorEntry*> children = processor_display.children ();
576         for (list<ProcessorEntry*>::iterator i = children.begin(); i != children.end(); ++i) {
577                 (*i)->set_enum_width (w);
578         }
579
580         redisplay_processors ();
581 }
582
583 void
584 ProcessorBox::build_send_action_menu ()
585 {
586         using namespace Menu_Helpers;
587
588         send_action_menu = new Menu;
589         send_action_menu->set_name ("ArdourContextMenu");
590         MenuList& items = send_action_menu->items();
591
592         items.push_back (MenuElem (_("New send"), sigc::mem_fun(*this, &ProcessorBox::new_send)));
593         items.push_back (MenuElem (_("Show send controls"), sigc::mem_fun(*this, &ProcessorBox::show_send_controls)));
594 }
595
596 Gtk::Menu*
597 ProcessorBox::build_possible_aux_menu ()
598 {
599         boost::shared_ptr<RouteList> rl = _session->get_routes_with_internal_returns();
600
601         if (rl->empty()) {
602                 return 0;
603         }
604
605         using namespace Menu_Helpers;
606         Menu* menu = manage (new Menu);
607         MenuList& items = menu->items();
608
609         for (RouteList::iterator r = rl->begin(); r != rl->end(); ++r) {
610                 if (!_route->internal_send_for (*r) && *r != _route) {
611                         items.push_back (MenuElem ((*r)->name(), sigc::bind (sigc::ptr_fun (ProcessorBox::rb_choose_aux), boost::weak_ptr<Route>(*r))));
612                 }
613         }
614
615         return menu;
616 }
617
618 void
619 ProcessorBox::show_send_controls ()
620 {
621 }
622
623 void
624 ProcessorBox::new_send ()
625 {
626 }
627
628 void
629 ProcessorBox::show_processor_menu (gint arg)
630 {
631         if (processor_menu == 0) {
632                 processor_menu = build_processor_menu ();
633         }
634
635         Gtk::MenuItem* plugin_menu_item = dynamic_cast<Gtk::MenuItem*>(ActionManager::get_widget("/processormenu/newplugin"));
636
637         if (plugin_menu_item) {
638                 plugin_menu_item->set_submenu (*_get_plugin_selector()->plugin_menu());
639         }
640
641         Gtk::MenuItem* aux_menu_item = dynamic_cast<Gtk::MenuItem*>(ActionManager::get_widget("/processormenu/newaux"));
642
643         if (aux_menu_item) {
644                 Menu* m = build_possible_aux_menu();
645                 if (m && !m->items().empty()) {
646                         aux_menu_item->set_submenu (*m);
647                         aux_menu_item->set_sensitive (true);
648                 } else {
649                         /* stupid gtkmm: we need to pass a null reference here */
650                         gtk_menu_item_set_submenu (aux_menu_item->gobj(), 0);
651                         aux_menu_item->set_sensitive (false);
652                 }
653         }
654
655         cut_action->set_sensitive (can_cut());
656         paste_action->set_sensitive (!_rr_selection.processors.empty());
657
658         processor_menu->popup (1, arg);
659 }
660
661 bool
662 ProcessorBox::enter_notify (GdkEventCrossing*)
663 {
664         _current_processor_box = this;
665         Keyboard::magic_widget_grab_focus ();
666         processor_display.grab_focus ();
667
668         return false;
669 }
670
671 bool
672 ProcessorBox::leave_notify (GdkEventCrossing* ev)
673 {
674         switch (ev->detail) {
675         case GDK_NOTIFY_INFERIOR:
676                 break;
677         default:
678                 Keyboard::magic_widget_drop_focus ();
679         }
680
681         return false;
682 }
683
684 bool
685 ProcessorBox::processor_key_press_event (GdkEventKey *)
686 {
687         /* do real stuff on key release */
688         return false;
689 }
690
691 bool
692 ProcessorBox::processor_key_release_event (GdkEventKey *ev)
693 {
694         bool ret = false;
695         ProcSelection targets;
696
697         get_selected_processors (targets);
698
699         if (targets.empty()) {
700
701                 int x, y;
702                 processor_display.get_pointer (x, y);
703
704                 pair<ProcessorEntry *, double> const pointer = processor_display.get_child_at_position (y);
705
706                 if (pointer.first) {
707                         targets.push_back (pointer.first->processor ());
708                 }
709         }
710
711
712         switch (ev->keyval) {
713         case GDK_a:
714                 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
715                         processor_display.select_all ();
716                         ret = true;
717                 } 
718                 break;
719
720         case GDK_c:
721                 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
722                         copy_processors (targets);
723                         ret = true;
724                 }
725                 break;
726
727         case GDK_x:
728                 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
729                         cut_processors (targets);
730                         ret = true;
731                 }
732                 break;
733
734         case GDK_v:
735                 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
736                         if (targets.empty()) {
737                                 paste_processors ();
738                         } else {
739                                 paste_processors (targets.front());
740                         }
741                         ret = true;
742                 }
743                 break;
744
745         case GDK_Up:
746                 break;
747
748         case GDK_Down:
749                 break;
750
751         case GDK_Delete:
752         case GDK_BackSpace:
753                 delete_processors (targets);
754                 ret = true;
755                 break;
756
757         case GDK_Return:
758                 for (ProcSelection::iterator i = targets.begin(); i != targets.end(); ++i) {
759                         if ((*i)->active()) {
760                                 (*i)->deactivate ();
761                         } else {
762                                 (*i)->activate ();
763                         }
764                 }
765                 ret = true;
766                 break;
767
768         case GDK_slash:
769                 ab_plugins ();
770                 ret = true;
771                 break;
772
773         default:
774                 break;
775         }
776
777         return ret;
778 }
779
780 bool
781 ProcessorBox::processor_button_press_event (GdkEventButton *ev, ProcessorEntry* child)
782 {
783         boost::shared_ptr<Processor> processor;
784         if (child) {
785                 processor = child->processor ();
786         }
787         
788         int ret = false;
789         bool selected = processor_display.selected (child);
790
791         if (processor && (Keyboard::is_edit_event (ev) || (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS))) {
792
793                 if (_session->engine().connected()) {
794                         /* XXX giving an error message here is hard, because we may be in the midst of a button press */
795                         toggle_edit_processor (processor);
796                 }
797                 ret = true;
798
799         } else if (processor && ev->button == 1 && selected) {
800
801                 // this is purely informational but necessary for route params UI
802                 ProcessorSelected (processor); // emit
803
804         } else if (!processor && ev->button == 1 && ev->type == GDK_2BUTTON_PRESS) {
805
806                 choose_plugin ();
807                 _get_plugin_selector()->show_manager ();
808         }
809
810         return ret;
811 }
812
813 bool
814 ProcessorBox::processor_button_release_event (GdkEventButton *ev, ProcessorEntry* child)
815 {
816         boost::shared_ptr<Processor> processor;
817         if (child) {
818                 processor = child->processor ();
819         }
820         
821         int ret = false;
822
823         if (processor && Keyboard::is_delete_event (ev)) {
824
825                 Glib::signal_idle().connect (sigc::bind (
826                                 sigc::mem_fun(*this, &ProcessorBox::idle_delete_processor),
827                                 boost::weak_ptr<Processor>(processor)));
828                 ret = true;
829
830         } else if (Keyboard::is_context_menu_event (ev)) {
831
832                 /* figure out if we are above or below the fader/amp processor,
833                    and set the next insert position appropriately.
834                 */
835
836                 if (processor) {
837                         if (_route->processor_is_prefader (processor)) {
838                                 _placement = PreFader;
839                         } else {
840                                 _placement = PostFader;
841                         }
842                 } else {
843                         _placement = PostFader;
844                 }
845
846                 show_processor_menu (ev->time);
847                 ret = true;
848
849         } else if (processor && Keyboard::is_button2_event (ev)
850 #ifndef GTKOSX
851                    && (Keyboard::no_modifier_keys_pressed (ev) && ((ev->state & Gdk::BUTTON2_MASK) == Gdk::BUTTON2_MASK))
852 #endif
853                 ) {
854
855                 /* button2-click with no/appropriate modifiers */
856
857                 if (processor->active()) {
858                         processor->deactivate ();
859                 } else {
860                         processor->activate ();
861                 }
862                 ret = true;
863
864         }
865
866         return false;
867 }
868
869 Menu *
870 ProcessorBox::build_processor_menu ()
871 {
872         processor_menu = dynamic_cast<Gtk::Menu*>(ActionManager::get_widget("/processormenu") );
873         processor_menu->set_name ("ArdourContextMenu");
874         return processor_menu;
875 }
876
877 void
878 ProcessorBox::selection_changed ()
879 {
880         bool const sensitive = (processor_display.selection().empty()) ? false : true;
881         ActionManager::set_sensitive (ActionManager::plugin_selection_sensitive_actions, sensitive);
882         edit_action->set_sensitive (one_processor_can_be_edited ());
883
884         /* disallow rename for multiple selections and for plugin inserts */
885         rename_action->set_sensitive (
886                 processor_display.selection().size() == 1 && boost::dynamic_pointer_cast<PluginInsert> (processor_display.selection().front()->processor()) == 0
887                 );
888 }
889
890 void
891 ProcessorBox::select_all_processors ()
892 {
893         processor_display.select_all ();
894 }
895
896 void
897 ProcessorBox::deselect_all_processors ()
898 {
899         processor_display.select_none ();
900 }
901
902 void
903 ProcessorBox::choose_plugin ()
904 {
905         _get_plugin_selector()->set_interested_object (*this);
906 }
907
908 /** @return true if an error occurred, otherwise false */
909 bool
910 ProcessorBox::use_plugins (const SelectedPlugins& plugins)
911 {
912         for (SelectedPlugins::const_iterator p = plugins.begin(); p != plugins.end(); ++p) {
913
914                 boost::shared_ptr<Processor> processor (new PluginInsert (*_session, *p));
915
916                 Route::ProcessorStreams err_streams;
917
918                 if (Config->get_new_plugins_active()) {
919                         processor->activate ();
920                 }
921
922                 if (_route->add_processor (processor, _placement, &err_streams)) {
923                         weird_plugin_dialog (**p, err_streams);
924                         return true;
925                         // XXX SHAREDPTR delete plugin here .. do we even need to care?
926                 } else {
927
928                         if (Profile->get_sae()) {
929                                 processor->activate ();
930                         }
931                 }
932         }
933
934         return false;
935 }
936
937 void
938 ProcessorBox::weird_plugin_dialog (Plugin& p, Route::ProcessorStreams streams)
939 {
940         ArdourDialog dialog (_("Plugin Incompatibility"));
941         Label label;
942
943         string text = string_compose(_("You attempted to add the plugin \"%1\" at index %2.\n"),
944                         p.name(), streams.index);
945
946         bool has_midi  = streams.count.n_midi() > 0 || p.get_info()->n_inputs.n_midi() > 0;
947         bool has_audio = streams.count.n_audio() > 0 || p.get_info()->n_inputs.n_audio() > 0;
948
949         text += _("\nThis plugin has:\n");
950         if (has_midi) {
951                 uint32_t const n = p.get_info()->n_inputs.n_midi ();
952                 text += string_compose (ngettext ("\t%1 MIDI input", "\t%1 MIDI inputs", n), n);
953         }
954         if (has_audio) {
955                 uint32_t const n = p.get_info()->n_inputs.n_audio ();
956                 text += string_compose (ngettext ("\t%1 audio input", "\t%1 audio inputs", n), n);
957         }
958
959         text += _("\nBut at the insertion point, there are:\n");
960         if (has_midi) {
961                 uint32_t const n = streams.count.n_midi ();
962                 text += string_compose (ngettext ("\t%1 MIDI channel\n", "\t%1 MIDI channels\n", n), n);
963         }
964         if (has_audio) {
965                 uint32_t const n = streams.count.n_audio ();
966                 text += string_compose (ngettext ("\t%1 audio channel\n", "\t%1 audio channels\n", n), n);
967         }
968
969         text += string_compose (_("\n%1 is unable to insert this plugin here.\n"), PROGRAM_NAME);
970         label.set_text(text);
971
972         dialog.get_vbox()->pack_start (label);
973         dialog.add_button (Stock::OK, RESPONSE_ACCEPT);
974
975         dialog.set_name (X_("PluginIODialog"));
976         dialog.set_position (Gtk::WIN_POS_MOUSE);
977         dialog.set_modal (true);
978         dialog.show_all ();
979
980         dialog.run ();
981 }
982
983 void
984 ProcessorBox::choose_insert ()
985 {
986         boost::shared_ptr<Processor> processor (new PortInsert (*_session, _route->pannable(), _route->mute_master()));
987         _route->add_processor (processor, _placement);
988 }
989
990 /* Caller must not hold process lock */
991 void
992 ProcessorBox::choose_send ()
993 {
994         boost::shared_ptr<Send> send (new Send (*_session, _route->pannable(), _route->mute_master()));
995
996         /* make an educated guess at the initial number of outputs for the send */
997         ChanCount outs = (_session->master_out())
998                         ? _session->master_out()->n_outputs()
999                         : _route->n_outputs();
1000
1001         /* XXX need processor lock on route */
1002         try {
1003                 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock());
1004                 send->output()->ensure_io (outs, false, this);
1005         } catch (AudioEngine::PortRegistrationFailure& err) {
1006                 error << string_compose (_("Cannot set up new send: %1"), err.what()) << endmsg;
1007                 return;
1008         }
1009
1010         /* let the user adjust the IO setup before creation.
1011
1012            Note: this dialog is NOT modal - we just leave it to run and it will
1013            return when its Finished signal is emitted - typically when the window
1014            is closed.
1015          */
1016
1017         IOSelectorWindow *ios = new IOSelectorWindow (_session, send->output(), true);
1018         ios->show ();
1019
1020         /* keep a reference to the send so it doesn't get deleted while
1021            the IOSelectorWindow is doing its stuff
1022         */
1023         _processor_being_created = send;
1024
1025         ios->selector().Finished.connect (sigc::bind (
1026                         sigc::mem_fun(*this, &ProcessorBox::send_io_finished),
1027                         boost::weak_ptr<Processor>(send), ios));
1028
1029 }
1030
1031 void
1032 ProcessorBox::send_io_finished (IOSelector::Result r, boost::weak_ptr<Processor> weak_processor, IOSelectorWindow* ios)
1033 {
1034         boost::shared_ptr<Processor> processor (weak_processor.lock());
1035
1036         /* drop our temporary reference to the new send */
1037         _processor_being_created.reset ();
1038
1039         if (!processor) {
1040                 return;
1041         }
1042
1043         switch (r) {
1044         case IOSelector::Cancelled:
1045                 // processor will go away when all shared_ptrs to it vanish
1046                 break;
1047
1048         case IOSelector::Accepted:
1049                 _route->add_processor (processor, _placement);
1050                 if (Profile->get_sae()) {
1051                         processor->activate ();
1052                 }
1053                 break;
1054         }
1055
1056         delete_when_idle (ios);
1057 }
1058
1059 void
1060 ProcessorBox::return_io_finished (IOSelector::Result r, boost::weak_ptr<Processor> weak_processor, IOSelectorWindow* ios)
1061 {
1062         boost::shared_ptr<Processor> processor (weak_processor.lock());
1063
1064         /* drop our temporary reference to the new return */
1065         _processor_being_created.reset ();
1066
1067         if (!processor) {
1068                 return;
1069         }
1070
1071         switch (r) {
1072         case IOSelector::Cancelled:
1073                 // processor will go away when all shared_ptrs to it vanish
1074                 break;
1075
1076         case IOSelector::Accepted:
1077                 _route->add_processor (processor, _placement);
1078                 if (Profile->get_sae()) {
1079                         processor->activate ();
1080                 }
1081                 break;
1082         }
1083
1084         delete_when_idle (ios);
1085 }
1086
1087 void
1088 ProcessorBox::choose_aux (boost::weak_ptr<Route> wr)
1089 {
1090         if (!_route) {
1091                 return;
1092         }
1093
1094         boost::shared_ptr<Route> target = wr.lock();
1095
1096         if (!target) {
1097                 return;
1098         }
1099
1100         boost::shared_ptr<RouteList> rlist (new RouteList);
1101         rlist->push_back (_route);
1102
1103         _session->add_internal_sends (target, PreFader, rlist);
1104 }
1105
1106 void
1107 ProcessorBox::route_processors_changed (RouteProcessorChange c)
1108 {
1109         if (c.type == RouteProcessorChange::MeterPointChange && c.meter_visibly_changed == false) {
1110                 /* the meter has moved, but it was and still is invisible to the user, so nothing to do */
1111                 return;
1112         }
1113
1114         redisplay_processors ();
1115 }
1116
1117 void
1118 ProcessorBox::redisplay_processors ()
1119 {
1120         ENSURE_GUI_THREAD (*this, &ProcessorBox::redisplay_processors)
1121
1122         if (no_processor_redisplay) {
1123                 return;
1124         }
1125
1126         processor_display.clear ();
1127
1128         _route->foreach_processor (sigc::mem_fun (*this, &ProcessorBox::add_processor_to_display));
1129
1130         for (list<ProcessorWindowProxy*>::iterator i = _processor_window_proxies.begin(); i != _processor_window_proxies.end(); ++i) {
1131                 (*i)->marked = false;
1132         }
1133                 
1134         _route->foreach_processor (sigc::mem_fun (*this, &ProcessorBox::maybe_add_processor_to_ui_list));
1135
1136         /* trim dead wood from the processor window proxy list */
1137
1138         list<ProcessorWindowProxy*>::iterator i = _processor_window_proxies.begin();
1139         while (i != _processor_window_proxies.end()) {
1140                 list<ProcessorWindowProxy*>::iterator j = i;
1141                 ++j;
1142
1143                 if (!(*i)->marked) {
1144                         ARDOUR_UI::instance()->remove_window_proxy (*i);
1145                         delete *i;
1146                         _processor_window_proxies.erase (i);
1147                 }
1148
1149                 i = j;
1150         }
1151
1152         setup_entry_positions ();
1153 }
1154
1155 /** Add a ProcessorWindowProxy for a processor to our list, if that processor does
1156  *  not already have one.
1157  */
1158 void
1159 ProcessorBox::maybe_add_processor_to_ui_list (boost::weak_ptr<Processor> w)
1160 {
1161         boost::shared_ptr<Processor> p = w.lock ();
1162         if (!p) {
1163                 return;
1164         }
1165
1166         list<ProcessorWindowProxy*>::iterator i = _processor_window_proxies.begin ();
1167         while (i != _processor_window_proxies.end()) {
1168
1169                 boost::shared_ptr<Processor> t = (*i)->processor().lock ();
1170                 
1171                 if (p == t) {
1172                         /* this processor is already on the list; done */
1173                         (*i)->marked = true;
1174                         return;
1175                 }
1176
1177                 ++i;
1178         }
1179
1180         /* not on the list; add it */
1181
1182         string loc;
1183         if (_parent_strip) {
1184                 if (_parent_strip->mixer_owned()) {
1185                         loc = X_("M");
1186                 } else {
1187                         loc = X_("R");
1188                 }
1189         } else {
1190                 loc = X_("P");
1191         }
1192         
1193         ProcessorWindowProxy* wp = new ProcessorWindowProxy (
1194                 string_compose ("%1-%2-%3", loc, _route->id(), p->id()),
1195                 _session->extra_xml (X_("UI")),
1196                 this,
1197                 w);
1198         
1199         wp->marked = true;
1200
1201         /* if the processor already has an existing UI, 
1202            note that so that we don't recreate it
1203         */
1204         
1205         void* existing_ui = p->get_ui ();
1206
1207         if (existing_ui) {
1208                 wp->set (static_cast<Gtk::Window*>(existing_ui));
1209         }
1210
1211         _processor_window_proxies.push_back (wp);
1212         ARDOUR_UI::instance()->add_window_proxy (wp);
1213 }
1214
1215 void
1216 ProcessorBox::add_processor_to_display (boost::weak_ptr<Processor> p)
1217 {
1218         boost::shared_ptr<Processor> processor (p.lock ());
1219
1220         if (!processor || !processor->display_to_user()) {
1221                 return;
1222         }
1223
1224         boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
1225         boost::shared_ptr<PluginInsert> plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (processor);
1226         ProcessorEntry* e = 0;
1227         if (send) {
1228                 e = new SendProcessorEntry (send, _width);
1229         } else if (plugin_insert) {
1230                 e = new PluginInsertProcessorEntry (plugin_insert, _width);
1231         } else {
1232                 e = new ProcessorEntry (processor, _width);
1233         }
1234         
1235         e->set_pixel_width (get_allocation().get_width());
1236         processor_display.add_child (e);
1237 }
1238
1239
1240 void
1241 ProcessorBox::build_processor_tooltip (EventBox& box, string start)
1242 {
1243         string tip(start);
1244
1245         list<ProcessorEntry*> children = processor_display.children ();
1246         for (list<ProcessorEntry*>::iterator i = children.begin(); i != children.end(); ++i) {
1247                 tip += '\n';
1248                 tip += (*i)->processor()->name();
1249         }
1250         
1251         ARDOUR_UI::instance()->set_tip (box, tip);
1252 }
1253
1254 void
1255 ProcessorBox::reordered ()
1256 {
1257         compute_processor_sort_keys ();
1258         setup_entry_positions ();
1259 }
1260
1261 void
1262 ProcessorBox::setup_entry_positions ()
1263 {
1264         list<ProcessorEntry*> children = processor_display.children ();
1265         bool pre_fader = true;
1266         
1267         for (list<ProcessorEntry*>::iterator i = children.begin(); i != children.end(); ++i) {
1268                 if (boost::dynamic_pointer_cast<Amp>((*i)->processor())) {
1269                         pre_fader = false;
1270                         (*i)->set_position (ProcessorEntry::Fader);
1271                 } else {
1272                         if (pre_fader) {
1273                                 (*i)->set_position (ProcessorEntry::PreFader);
1274                         } else {
1275                                 (*i)->set_position (ProcessorEntry::PostFader);
1276                         }
1277                 }
1278         }
1279 }
1280
1281 void
1282 ProcessorBox::compute_processor_sort_keys ()
1283 {
1284         list<ProcessorEntry*> children = processor_display.children ();
1285         Route::ProcessorList our_processors;
1286
1287         for (list<ProcessorEntry*>::iterator iter = children.begin(); iter != children.end(); ++iter) {
1288                 our_processors.push_back ((*iter)->processor ());
1289         }
1290
1291         if (_route->reorder_processors (our_processors)) {
1292                 /* Reorder failed, so report this to the user.  As far as I can see this must be done
1293                    in an idle handler: it seems that the redisplay_processors() that happens below destroys
1294                    widgets that were involved in the drag-and-drop on the processor list, which causes problems
1295                    when the drag is torn down after this handler function is finished.
1296                 */
1297                 Glib::signal_idle().connect_once (sigc::mem_fun (*this, &ProcessorBox::report_failed_reorder));
1298         }
1299 }
1300
1301 void
1302 ProcessorBox::report_failed_reorder ()
1303 {
1304         /* reorder failed, so redisplay */
1305         
1306         redisplay_processors ();
1307         
1308         /* now tell them about the problem */
1309         
1310         ArdourDialog dialog (_("Plugin Incompatibility"));
1311         Label label;
1312         
1313         label.set_text (_("\
1314 You cannot reorder these plugins/sends/inserts\n\
1315 in that way because the inputs and\n\
1316 outputs will not work correctly."));
1317
1318         dialog.get_vbox()->set_border_width (12);
1319         dialog.get_vbox()->pack_start (label);
1320         dialog.add_button (Stock::OK, RESPONSE_ACCEPT);
1321         
1322         dialog.set_name (X_("PluginIODialog"));
1323         dialog.set_position (Gtk::WIN_POS_MOUSE);
1324         dialog.set_modal (true);
1325         dialog.show_all ();
1326         
1327         dialog.run ();
1328 }
1329
1330 void
1331 ProcessorBox::rename_processors ()
1332 {
1333         ProcSelection to_be_renamed;
1334
1335         get_selected_processors (to_be_renamed);
1336
1337         if (to_be_renamed.empty()) {
1338                 return;
1339         }
1340
1341         for (ProcSelection::iterator i = to_be_renamed.begin(); i != to_be_renamed.end(); ++i) {
1342                 rename_processor (*i);
1343         }
1344 }
1345
1346 bool
1347 ProcessorBox::can_cut () const
1348 {
1349         vector<boost::shared_ptr<Processor> > sel;
1350
1351         get_selected_processors (sel);
1352         
1353         /* cut_processors () does not cut inserts */
1354
1355         for (vector<boost::shared_ptr<Processor> >::const_iterator i = sel.begin (); i != sel.end (); ++i) {
1356                 
1357                 if (boost::dynamic_pointer_cast<PluginInsert>((*i)) != 0 ||
1358                     (boost::dynamic_pointer_cast<Send>((*i)) != 0) ||
1359                     (boost::dynamic_pointer_cast<Return>((*i)) != 0)) {
1360                         return true;
1361                 }
1362         }
1363         
1364         return false;
1365 }
1366
1367 void
1368 ProcessorBox::cut_processors ()
1369 {
1370         ProcSelection to_be_removed;
1371
1372         get_selected_processors (to_be_removed);
1373 }
1374
1375 void
1376 ProcessorBox::cut_processors (const ProcSelection& to_be_removed)
1377 {
1378         if (to_be_removed.empty()) {
1379                 return;
1380         }
1381
1382         XMLNode* node = new XMLNode (X_("cut"));
1383         Route::ProcessorList to_cut;
1384
1385         no_processor_redisplay = true;
1386         for (ProcSelection::const_iterator i = to_be_removed.begin(); i != to_be_removed.end(); ++i) {
1387                 // Cut only plugins, sends and returns
1388                 if (boost::dynamic_pointer_cast<PluginInsert>((*i)) != 0 ||
1389                     (boost::dynamic_pointer_cast<Send>((*i)) != 0) ||
1390                     (boost::dynamic_pointer_cast<Return>((*i)) != 0)) {
1391
1392                         Window* w = get_processor_ui (*i);
1393
1394                         if (w) {
1395                                 w->hide ();
1396                         }
1397
1398                         XMLNode& child ((*i)->get_state());
1399                         node->add_child_nocopy (child);
1400                         to_cut.push_back (*i);
1401                 }
1402         }
1403
1404         if (_route->remove_processors (to_cut) != 0) {
1405                 delete node;
1406                 no_processor_redisplay = false;
1407                 return;
1408         }
1409
1410         _rr_selection.set (node);
1411
1412         no_processor_redisplay = false;
1413         redisplay_processors ();
1414 }
1415
1416 void
1417 ProcessorBox::copy_processors ()
1418 {
1419         ProcSelection to_be_copied;
1420         get_selected_processors (to_be_copied);
1421         copy_processors (to_be_copied);
1422 }
1423
1424 void
1425 ProcessorBox::copy_processors (const ProcSelection& to_be_copied)
1426 {
1427         if (to_be_copied.empty()) {
1428                 return;
1429         }
1430
1431         XMLNode* node = new XMLNode (X_("copy"));
1432
1433         for (ProcSelection::const_iterator i = to_be_copied.begin(); i != to_be_copied.end(); ++i) {
1434                 // Copy only plugins, sends, returns
1435                 if (boost::dynamic_pointer_cast<PluginInsert>((*i)) != 0 ||
1436                     (boost::dynamic_pointer_cast<Send>((*i)) != 0) ||
1437                     (boost::dynamic_pointer_cast<Return>((*i)) != 0)) {
1438                         node->add_child_nocopy ((*i)->get_state());
1439                 }
1440         }
1441
1442         _rr_selection.set (node);
1443 }
1444
1445 void
1446 ProcessorBox::delete_processors ()
1447 {
1448         ProcSelection to_be_deleted;
1449         get_selected_processors (to_be_deleted);
1450         delete_processors (to_be_deleted);
1451 }
1452
1453 void
1454 ProcessorBox::delete_processors (const ProcSelection& targets)
1455 {
1456         if (targets.empty()) {
1457                 return;
1458         }
1459
1460         no_processor_redisplay = true;
1461
1462         for (ProcSelection::const_iterator i = targets.begin(); i != targets.end(); ++i) {
1463
1464                 Window* w = get_processor_ui (*i);
1465
1466                 if (w) {
1467                         w->hide ();
1468                 }
1469
1470                 _route->remove_processor(*i);
1471         }
1472
1473         no_processor_redisplay = false;
1474         redisplay_processors ();
1475 }
1476
1477 void
1478 ProcessorBox::delete_dragged_processors (const list<boost::shared_ptr<Processor> >& procs)
1479 {
1480         list<boost::shared_ptr<Processor> >::const_iterator x;
1481
1482         no_processor_redisplay = true;
1483         for (x = procs.begin(); x != procs.end(); ++x) {
1484
1485                 Window* w = get_processor_ui (*x);
1486
1487                 if (w) {
1488                         w->hide ();
1489                 }
1490
1491                 _route->remove_processor(*x);
1492         }
1493
1494         no_processor_redisplay = false;
1495         redisplay_processors ();
1496 }
1497
1498 gint
1499 ProcessorBox::idle_delete_processor (boost::weak_ptr<Processor> weak_processor)
1500 {
1501         boost::shared_ptr<Processor> processor (weak_processor.lock());
1502
1503         if (!processor) {
1504                 return false;
1505         }
1506
1507         /* NOT copied to _mixer.selection() */
1508
1509         no_processor_redisplay = true;
1510         _route->remove_processor (processor);
1511         no_processor_redisplay = false;
1512         redisplay_processors ();
1513
1514         return false;
1515 }
1516
1517 void
1518 ProcessorBox::rename_processor (boost::shared_ptr<Processor> processor)
1519 {
1520         ArdourPrompter name_prompter (true);
1521         string result;
1522         name_prompter.set_title (_("Rename Processor"));
1523         name_prompter.set_prompt (_("New name:"));
1524         name_prompter.set_initial_text (processor->name());
1525         name_prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
1526         name_prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
1527         name_prompter.show_all ();
1528
1529         switch (name_prompter.run ()) {
1530
1531         case Gtk::RESPONSE_ACCEPT:
1532                 name_prompter.get_result (result);
1533                 if (result.length()) {
1534
1535                        int tries = 0;
1536                        string test = result;
1537
1538                        while (tries < 100) {
1539                                if (_session->io_name_is_legal (test)) {
1540                                        result = test;
1541                                        break;
1542                                }
1543                                tries++;
1544
1545                                test = string_compose ("%1-%2", result, tries);
1546                        }
1547
1548                        if (tries < 100) {
1549                                processor->set_name (result);
1550                        } else {
1551                                /* unlikely! */
1552                                ARDOUR_UI::instance()->popup_error
1553                                        (string_compose (_("At least 100 IO objects exist with a name like %1 - name not changed"), result));
1554                        }
1555                 }
1556                 break;
1557         }
1558
1559         return;
1560 }
1561
1562 void
1563 ProcessorBox::paste_processors ()
1564 {
1565         if (_rr_selection.processors.empty()) {
1566                 return;
1567         }
1568
1569         paste_processor_state (_rr_selection.processors.get_node().children(), boost::shared_ptr<Processor>());
1570 }
1571
1572 void
1573 ProcessorBox::paste_processors (boost::shared_ptr<Processor> before)
1574 {
1575
1576         if (_rr_selection.processors.empty()) {
1577                 return;
1578         }
1579
1580         paste_processor_state (_rr_selection.processors.get_node().children(), before);
1581 }
1582
1583 void
1584 ProcessorBox::paste_processor_state (const XMLNodeList& nlist, boost::shared_ptr<Processor> p)
1585 {
1586         XMLNodeConstIterator niter;
1587         list<boost::shared_ptr<Processor> > copies;
1588
1589         if (nlist.empty()) {
1590                 return;
1591         }
1592
1593         for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1594
1595                 XMLProperty const * type = (*niter)->property ("type");
1596                 assert (type);
1597
1598                 boost::shared_ptr<Processor> p;
1599                 try {
1600                         if (type->value() == "meter" ||
1601                             type->value() == "main-outs" ||
1602                             type->value() == "amp" ||
1603                             type->value() == "intsend" || type->value() == "intreturn") {
1604                                 /* do not paste meter, main outs, amp or internal send/returns */
1605                                 continue;
1606
1607                         } else if (type->value() == "send") {
1608
1609                                 XMLNode n (**niter);
1610                                 Send::make_unique (n, *_session);
1611                                 Send* s = new Send (*_session, _route->pannable(), _route->mute_master());
1612                                 if (s->set_state (n, Stateful::loading_state_version)) {
1613                                         delete s;
1614                                         return;
1615                                 }
1616
1617                                 p.reset (s);
1618                                         
1619
1620                         } else if (type->value() == "return") {
1621
1622                                 XMLNode n (**niter);
1623                                 Return::make_unique (n, *_session);
1624                                 Return* r = new Return (*_session);
1625
1626                                 if (r->set_state (n, Stateful::loading_state_version)) {
1627                                         delete r;
1628                                         return;
1629                                 }
1630
1631                                 p.reset (r);
1632
1633                         } else {
1634                                 /* XXX its a bit limiting to assume that everything else
1635                                    is a plugin.
1636                                 */
1637
1638                                 p.reset (new PluginInsert (*_session));
1639                                 p->set_state (**niter, Stateful::current_state_version);
1640                         }
1641
1642                         copies.push_back (p);
1643                 }
1644
1645                 catch (...) {
1646                         cerr << "plugin insert constructor failed\n";
1647                 }
1648         }
1649
1650         if (copies.empty()) {
1651                 return;
1652         }
1653
1654         if (_route->add_processors (copies, p)) {
1655
1656                 string msg = _(
1657                         "Copying the set of processors on the clipboard failed,\n\
1658 probably because the I/O configuration of the plugins\n\
1659 could not match the configuration of this track.");
1660                 MessageDialog am (msg);
1661                 am.run ();
1662         }
1663 }
1664
1665 void
1666 ProcessorBox::activate_processor (boost::shared_ptr<Processor> r)
1667 {
1668         r->activate ();
1669 }
1670
1671 void
1672 ProcessorBox::deactivate_processor (boost::shared_ptr<Processor> r)
1673 {
1674         r->deactivate ();
1675 }
1676
1677 void
1678 ProcessorBox::get_selected_processors (ProcSelection& processors) const
1679 {
1680         const list<ProcessorEntry*> selection = processor_display.selection ();
1681         for (list<ProcessorEntry*>::const_iterator i = selection.begin(); i != selection.end(); ++i) {
1682                 processors.push_back ((*i)->processor ());
1683         }
1684 }
1685
1686 void
1687 ProcessorBox::for_selected_processors (void (ProcessorBox::*method)(boost::shared_ptr<Processor>))
1688 {
1689         list<ProcessorEntry*> selection = processor_display.selection ();
1690         for (list<ProcessorEntry*>::iterator i = selection.begin(); i != selection.end(); ++i) {
1691                 (this->*method) ((*i)->processor ());
1692         }
1693 }
1694
1695 void
1696 ProcessorBox::all_processors_active (bool state)
1697 {
1698         _route->all_processors_active (_placement, state);
1699 }
1700
1701 void
1702 ProcessorBox::ab_plugins ()
1703 {
1704         _route->ab_plugins (ab_direction);
1705         ab_direction = !ab_direction;
1706 }
1707
1708
1709 void
1710 ProcessorBox::clear_processors ()
1711 {
1712         string prompt;
1713         vector<string> choices;
1714
1715         prompt = string_compose (_("Do you really want to remove all processors from %1?\n"
1716                                    "(this cannot be undone)"), _route->name());
1717
1718         choices.push_back (_("Cancel"));
1719         choices.push_back (_("Yes, remove them all"));
1720
1721         Gtkmm2ext::Choice prompter (_("Remove processors"), prompt, choices);
1722
1723         if (prompter.run () == 1) {
1724                 _route->clear_processors (PreFader);
1725                 _route->clear_processors (PostFader);
1726         }
1727 }
1728
1729 void
1730 ProcessorBox::clear_processors (Placement p)
1731 {
1732         string prompt;
1733         vector<string> choices;
1734
1735         if (p == PreFader) {
1736                 prompt = string_compose (_("Do you really want to remove all pre-fader processors from %1?\n"
1737                                            "(this cannot be undone)"), _route->name());
1738         } else {
1739                 prompt = string_compose (_("Do you really want to remove all post-fader processors from %1?\n"
1740                                            "(this cannot be undone)"), _route->name());
1741         }
1742
1743         choices.push_back (_("Cancel"));
1744         choices.push_back (_("Yes, remove them all"));
1745
1746         Gtkmm2ext::Choice prompter (_("Remove processors"), prompt, choices);
1747
1748         if (prompter.run () == 1) {
1749                 _route->clear_processors (p);
1750         }
1751 }
1752
1753 bool
1754 ProcessorBox::processor_can_be_edited (boost::shared_ptr<Processor> processor)
1755 {
1756         boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack> (_route);
1757         if (at && at->freeze_state() == AudioTrack::Frozen) {
1758                 return false;
1759         }
1760
1761         if (
1762                 boost::dynamic_pointer_cast<Send> (processor) ||
1763                 boost::dynamic_pointer_cast<Return> (processor) ||
1764                 boost::dynamic_pointer_cast<PluginInsert> (processor) ||
1765                 boost::dynamic_pointer_cast<PortInsert> (processor)
1766                 ) {
1767                 return true;
1768         }
1769
1770         return false;
1771 }
1772
1773 bool
1774 ProcessorBox::one_processor_can_be_edited ()
1775 {
1776         list<ProcessorEntry*> selection = processor_display.selection ();
1777         list<ProcessorEntry*>::iterator i = selection.begin();
1778         while (i != selection.end() && processor_can_be_edited ((*i)->processor()) == false) {
1779                 ++i;
1780         }
1781
1782         return (i != selection.end());
1783 }
1784
1785 void
1786 ProcessorBox::toggle_edit_processor (boost::shared_ptr<Processor> processor)
1787 {
1788         boost::shared_ptr<Send> send;
1789         boost::shared_ptr<InternalSend> internal_send;
1790         boost::shared_ptr<Return> retrn;
1791         boost::shared_ptr<PluginInsert> plugin_insert;
1792         boost::shared_ptr<PortInsert> port_insert;
1793         Window* gidget = 0;
1794
1795         if (boost::dynamic_pointer_cast<AudioTrack>(_route) != 0) {
1796
1797                 if (boost::dynamic_pointer_cast<AudioTrack> (_route)->freeze_state() == AudioTrack::Frozen) {
1798                         return;
1799                 }
1800         }
1801
1802         if (boost::dynamic_pointer_cast<Amp> (processor)) {
1803
1804                 _parent_strip->revert_to_default_display ();
1805                 
1806         } else if ((internal_send = boost::dynamic_pointer_cast<InternalSend> (processor)) != 0) {
1807
1808                 if (!_session->engine().connected()) {
1809                         return;
1810                 }
1811
1812                 if (_parent_strip) {
1813                         if (boost::dynamic_pointer_cast<Send> (_parent_strip->current_delivery()) == internal_send) {
1814                                 _parent_strip->revert_to_default_display ();
1815                         } else {
1816                                 _parent_strip->show_send (internal_send);
1817                         }
1818                 }
1819
1820         } else if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
1821
1822                 if (!_session->engine().connected()) {
1823                         return;
1824                 }
1825
1826                 SendUIWindow* w = new SendUIWindow (send, _session);
1827                 w->show ();
1828
1829         } else if ((retrn = boost::dynamic_pointer_cast<Return> (processor)) != 0) {
1830
1831                 if (boost::dynamic_pointer_cast<InternalReturn> (retrn)) {
1832                         /* no GUI for these */
1833                         return;
1834                 }
1835
1836                 if (!_session->engine().connected()) {
1837                         return;
1838                 }
1839
1840                 boost::shared_ptr<Return> retrn = boost::dynamic_pointer_cast<Return> (processor);
1841
1842                 ReturnUIWindow *return_ui;
1843                 Window* w = get_processor_ui (retrn);
1844
1845                 if (w == 0) {
1846
1847                         return_ui = new ReturnUIWindow (retrn, _session);
1848                         return_ui->set_title (retrn->name ());
1849                         set_processor_ui (send, return_ui);
1850
1851                 } else {
1852                         return_ui = dynamic_cast<ReturnUIWindow *> (w);
1853                 }
1854
1855                 gidget = return_ui;
1856
1857         } else if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (processor)) != 0) {
1858
1859                 PluginUIWindow *plugin_ui;
1860
1861                 /* these are both allowed to be null */
1862
1863                 Container* toplevel = get_toplevel();
1864                 Window* win = dynamic_cast<Gtk::Window*>(toplevel);
1865
1866                 Window* w = get_processor_ui (plugin_insert);
1867
1868                 if (w == 0) {
1869
1870                         plugin_ui = new PluginUIWindow (win, plugin_insert);
1871                         plugin_ui->set_title (generate_processor_title (plugin_insert));
1872                         set_processor_ui (plugin_insert, plugin_ui);
1873
1874                 } else {
1875                         plugin_ui = dynamic_cast<PluginUIWindow *> (w);
1876                         plugin_ui->set_parent (win);
1877                 }
1878
1879                 gidget = plugin_ui;
1880
1881         } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (processor)) != 0) {
1882
1883                 if (!_session->engine().connected()) {
1884                         MessageDialog msg ( _("Not connected to JACK - no I/O changes are possible"));
1885                         msg.run ();
1886                         return;
1887                 }
1888
1889                 PortInsertWindow *io_selector;
1890
1891                 Window* w = get_processor_ui (port_insert);
1892
1893                 if (w == 0) {
1894                         io_selector = new PortInsertWindow (_session, port_insert);
1895                         set_processor_ui (port_insert, io_selector);
1896
1897                 } else {
1898                         io_selector = dynamic_cast<PortInsertWindow *> (w);
1899                 }
1900
1901                 gidget = io_selector;
1902         }
1903
1904         if (gidget) {
1905                 if (gidget->is_visible()) {
1906                         gidget->hide ();
1907                 } else {
1908                         gidget->show_all ();
1909                         gidget->present ();
1910                 }
1911         }
1912 }
1913
1914 void
1915 ProcessorBox::register_actions ()
1916 {
1917         Glib::RefPtr<Gtk::ActionGroup> popup_act_grp = Gtk::ActionGroup::create(X_("processormenu"));
1918         Glib::RefPtr<Action> act;
1919
1920         /* new stuff */
1921         ActionManager::register_action (popup_act_grp, X_("newplugin"), _("New Plugin"),
1922                         sigc::ptr_fun (ProcessorBox::rb_choose_plugin));
1923
1924         act = ActionManager::register_action (popup_act_grp, X_("newinsert"), _("New Insert"),
1925                         sigc::ptr_fun (ProcessorBox::rb_choose_insert));
1926         ActionManager::jack_sensitive_actions.push_back (act);
1927         act = ActionManager::register_action (popup_act_grp, X_("newsend"), _("New Send ..."),
1928                         sigc::ptr_fun (ProcessorBox::rb_choose_send));
1929         ActionManager::jack_sensitive_actions.push_back (act);
1930
1931         ActionManager::register_action (popup_act_grp, X_("newaux"), _("New Aux Send ..."));
1932
1933         ActionManager::register_action (popup_act_grp, X_("clear"), _("Clear (all)"),
1934                         sigc::ptr_fun (ProcessorBox::rb_clear));
1935         ActionManager::register_action (popup_act_grp, X_("clear_pre"), _("Clear (pre-fader)"),
1936                         sigc::ptr_fun (ProcessorBox::rb_clear_pre));
1937         ActionManager::register_action (popup_act_grp, X_("clear_post"), _("Clear (post-fader)"),
1938                         sigc::ptr_fun (ProcessorBox::rb_clear_post));
1939
1940         /* standard editing stuff */
1941         cut_action = ActionManager::register_action (popup_act_grp, X_("cut"), _("Cut"),
1942                                                      sigc::ptr_fun (ProcessorBox::rb_cut));
1943         ActionManager::plugin_selection_sensitive_actions.push_back(cut_action);
1944         act = ActionManager::register_action (popup_act_grp, X_("copy"), _("Copy"),
1945                         sigc::ptr_fun (ProcessorBox::rb_copy));
1946         ActionManager::plugin_selection_sensitive_actions.push_back(act);
1947
1948         act = ActionManager::register_action (popup_act_grp, X_("delete"), _("Delete"),
1949                         sigc::ptr_fun (ProcessorBox::rb_delete));
1950         ActionManager::plugin_selection_sensitive_actions.push_back(act); // ??
1951
1952         paste_action = ActionManager::register_action (popup_act_grp, X_("paste"), _("Paste"),
1953                         sigc::ptr_fun (ProcessorBox::rb_paste));
1954         rename_action = ActionManager::register_action (popup_act_grp, X_("rename"), _("Rename"),
1955                         sigc::ptr_fun (ProcessorBox::rb_rename));
1956         ActionManager::register_action (popup_act_grp, X_("selectall"), _("Select All"),
1957                         sigc::ptr_fun (ProcessorBox::rb_select_all));
1958         ActionManager::register_action (popup_act_grp, X_("deselectall"), _("Deselect All"),
1959                         sigc::ptr_fun (ProcessorBox::rb_deselect_all));
1960
1961         /* activation etc. */
1962
1963         ActionManager::register_action (popup_act_grp, X_("activate_all"), _("Activate all"),
1964                                         sigc::ptr_fun (ProcessorBox::rb_activate_all));
1965         ActionManager::register_action (popup_act_grp, X_("deactivate_all"), _("Deactivate all"),
1966                                         sigc::ptr_fun (ProcessorBox::rb_deactivate_all));
1967         ActionManager::register_action (popup_act_grp, X_("ab_plugins"), _("A/B Plugins"),
1968                                         sigc::ptr_fun (ProcessorBox::rb_ab_plugins));
1969
1970         /* show editors */
1971         edit_action = ActionManager::register_action (popup_act_grp, X_("edit"), _("Edit..."),
1972                                                       sigc::ptr_fun (ProcessorBox::rb_edit));
1973
1974         ActionManager::add_action_group (popup_act_grp);
1975 }
1976
1977 void
1978 ProcessorBox::rb_ab_plugins ()
1979 {
1980         if (_current_processor_box == 0) {
1981                 return;
1982         }
1983
1984         _current_processor_box->ab_plugins ();
1985 }
1986
1987 void
1988 ProcessorBox::rb_choose_plugin ()
1989 {
1990         if (_current_processor_box == 0) {
1991                 return;
1992         }
1993         _current_processor_box->choose_plugin ();
1994 }
1995
1996 void
1997 ProcessorBox::rb_choose_insert ()
1998 {
1999         if (_current_processor_box == 0) {
2000                 return;
2001         }
2002         _current_processor_box->choose_insert ();
2003 }
2004
2005 void
2006 ProcessorBox::rb_choose_send ()
2007 {
2008         if (_current_processor_box == 0) {
2009                 return;
2010         }
2011         _current_processor_box->choose_send ();
2012 }
2013
2014 void
2015 ProcessorBox::rb_choose_aux (boost::weak_ptr<Route> wr)
2016 {
2017         if (_current_processor_box == 0) {
2018                 return;
2019         }
2020
2021         _current_processor_box->choose_aux (wr);
2022 }
2023
2024 void
2025 ProcessorBox::rb_clear ()
2026 {
2027         if (_current_processor_box == 0) {
2028                 return;
2029         }
2030
2031         _current_processor_box->clear_processors ();
2032 }
2033
2034
2035 void
2036 ProcessorBox::rb_clear_pre ()
2037 {
2038         if (_current_processor_box == 0) {
2039                 return;
2040         }
2041
2042         _current_processor_box->clear_processors (PreFader);
2043 }
2044
2045
2046 void
2047 ProcessorBox::rb_clear_post ()
2048 {
2049         if (_current_processor_box == 0) {
2050                 return;
2051         }
2052
2053         _current_processor_box->clear_processors (PostFader);
2054 }
2055
2056 void
2057 ProcessorBox::rb_cut ()
2058 {
2059         if (_current_processor_box == 0) {
2060                 return;
2061         }
2062
2063         _current_processor_box->cut_processors ();
2064 }
2065
2066 void
2067 ProcessorBox::rb_delete ()
2068 {
2069         if (_current_processor_box == 0) {
2070                 return;
2071         }
2072
2073         _current_processor_box->delete_processors ();
2074 }
2075
2076 void
2077 ProcessorBox::rb_copy ()
2078 {
2079         if (_current_processor_box == 0) {
2080                 return;
2081         }
2082         _current_processor_box->copy_processors ();
2083 }
2084
2085 void
2086 ProcessorBox::rb_paste ()
2087 {
2088         if (_current_processor_box == 0) {
2089                 return;
2090         }
2091
2092         _current_processor_box->paste_processors ();
2093 }
2094
2095 void
2096 ProcessorBox::rb_rename ()
2097 {
2098         if (_current_processor_box == 0) {
2099                 return;
2100         }
2101         _current_processor_box->rename_processors ();
2102 }
2103
2104 void
2105 ProcessorBox::rb_select_all ()
2106 {
2107         if (_current_processor_box == 0) {
2108                 return;
2109         }
2110
2111         _current_processor_box->select_all_processors ();
2112 }
2113
2114 void
2115 ProcessorBox::rb_deselect_all ()
2116 {
2117         if (_current_processor_box == 0) {
2118                 return;
2119         }
2120
2121         _current_processor_box->deselect_all_processors ();
2122 }
2123
2124 void
2125 ProcessorBox::rb_activate_all ()
2126 {
2127         if (_current_processor_box == 0) {
2128                 return;
2129         }
2130
2131         _current_processor_box->all_processors_active (true);
2132 }
2133
2134 void
2135 ProcessorBox::rb_deactivate_all ()
2136 {
2137         if (_current_processor_box == 0) {
2138                 return;
2139         }
2140         _current_processor_box->all_processors_active (false);
2141 }
2142
2143 void
2144 ProcessorBox::rb_edit ()
2145 {
2146         if (_current_processor_box == 0) {
2147                 return;
2148         }
2149
2150         _current_processor_box->for_selected_processors (&ProcessorBox::toggle_edit_processor);
2151 }
2152
2153 void
2154 ProcessorBox::route_property_changed (const PropertyChange& what_changed)
2155 {
2156         if (!what_changed.contains (ARDOUR::Properties::name)) {
2157                 return;
2158         }
2159
2160         ENSURE_GUI_THREAD (*this, &ProcessorBox::route_property_changed, what_changed);
2161
2162         boost::shared_ptr<Processor> processor;
2163         boost::shared_ptr<PluginInsert> plugin_insert;
2164         boost::shared_ptr<Send> send;
2165
2166         list<ProcessorEntry*> children = processor_display.children();
2167
2168         for (list<ProcessorEntry*>::iterator iter = children.begin(); iter != children.end(); ++iter) {
2169
2170                 processor = (*iter)->processor ();
2171
2172                 Window* w = get_processor_ui (processor);
2173
2174                 if (!w) {
2175                         continue;
2176                 }
2177
2178                 /* rename editor windows for sends and plugins */
2179
2180                 if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
2181                         w->set_title (send->name ());
2182                 } else if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (processor)) != 0) {
2183                         w->set_title (generate_processor_title (plugin_insert));
2184                 }
2185         }
2186 }
2187
2188 string
2189 ProcessorBox::generate_processor_title (boost::shared_ptr<PluginInsert> pi)
2190 {
2191         string maker = pi->plugin()->maker() ? pi->plugin()->maker() : "";
2192         string::size_type email_pos;
2193
2194         if ((email_pos = maker.find_first_of ('<')) != string::npos) {
2195                 maker = maker.substr (0, email_pos - 1);
2196         }
2197
2198         if (maker.length() > 32) {
2199                 maker = maker.substr (0, 32);
2200                 maker += " ...";
2201         }
2202
2203         return string_compose(_("%1: %2 (by %3)"), _route->name(), pi->name(), maker);
2204 }
2205
2206 void
2207 ProcessorBox::on_size_allocate (Allocation& a)
2208 {
2209         HBox::on_size_allocate (a);
2210
2211         list<ProcessorEntry*> children = processor_display.children ();
2212         for (list<ProcessorEntry*>::const_iterator i = children.begin(); i != children.end(); ++i) {
2213                 (*i)->set_pixel_width (a.get_width ());
2214         }
2215 }
2216
2217 /** @param p Processor.
2218  *  @return the UI window for \a p.
2219  */
2220 Window *
2221 ProcessorBox::get_processor_ui (boost::shared_ptr<Processor> p) const
2222 {
2223         list<ProcessorWindowProxy*>::const_iterator i = _processor_window_proxies.begin ();
2224         while (i != _processor_window_proxies.end()) {
2225                 boost::shared_ptr<Processor> t = (*i)->processor().lock ();
2226                 if (t && t == p) {
2227                         return (*i)->get ();
2228                 }
2229
2230                 ++i;
2231         }
2232
2233         /* we shouldn't get here, because the ProcessorUIList should always contain
2234            an entry for each processor.
2235         */
2236         assert (false);
2237         return 0;
2238 }
2239
2240 /** Make a note of the UI window that a processor is using.
2241  *  @param p Processor.
2242  *  @param w UI window.
2243  */
2244 void
2245 ProcessorBox::set_processor_ui (boost::shared_ptr<Processor> p, Gtk::Window* w)
2246 {
2247         list<ProcessorWindowProxy*>::iterator i = _processor_window_proxies.begin ();
2248         
2249         p->set_ui (w);
2250         
2251         while (i != _processor_window_proxies.end()) {
2252                 boost::shared_ptr<Processor> t = (*i)->processor().lock ();
2253                 if (t && t == p) {
2254                         (*i)->set (w);
2255                         return;
2256                 }
2257
2258                 ++i;
2259         }
2260
2261         /* we shouldn't get here, because the ProcessorUIList should always contain
2262            an entry for each processor.
2263         */
2264         assert (false);
2265 }
2266
2267 void
2268 ProcessorBox::mixer_strip_delivery_changed (boost::weak_ptr<Delivery> w)
2269 {
2270         boost::shared_ptr<Delivery> d = w.lock ();
2271         if (!d) {
2272                 return;
2273         }
2274
2275         list<ProcessorEntry*> children = processor_display.children ();
2276         list<ProcessorEntry*>::const_iterator i = children.begin();
2277         while (i != children.end() && (*i)->processor() != d) {
2278                 ++i;
2279         }
2280
2281         if (i == children.end()) {
2282                 processor_display.set_active (0);
2283         } else {
2284                 processor_display.set_active (*i);
2285         }
2286 }
2287
2288 ProcessorWindowProxy::ProcessorWindowProxy (
2289         string const & name,
2290         XMLNode const * node,
2291         ProcessorBox* box,
2292         boost::weak_ptr<Processor> processor
2293         )
2294         : WindowProxy<Gtk::Window> (name, node)
2295         , marked (false)
2296         , _processor_box (box)
2297         , _processor (processor)
2298 {
2299
2300 }
2301
2302
2303 void
2304 ProcessorWindowProxy::show ()
2305 {
2306         boost::shared_ptr<Processor> p = _processor.lock ();
2307         if (!p) {
2308                 return;
2309         }
2310
2311         _processor_box->toggle_edit_processor (p);
2312 }
2313