when setting a redirect box to display a given route's redirects, always unset the...
[ardour.git] / gtk2_ardour / redirect_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
23 #include <sigc++/bind.h>
24
25 #include <pbd/convert.h>
26
27 #include <glibmm/miscutils.h>
28
29 #include <gtkmm/messagedialog.h>
30
31 #include <gtkmm2ext/gtk_ui.h>
32 #include <gtkmm2ext/utils.h>
33 #include <gtkmm2ext/choice.h>
34 #include <gtkmm2ext/utils.h>
35 #include <gtkmm2ext/stop_signal.h>
36 #include <gtkmm2ext/doi.h>
37 #include <gtkmm2ext/window_title.h>
38
39 #include <ardour/ardour.h>
40 #include <ardour/session.h>
41 #include <ardour/audioengine.h>
42 #include <ardour/route.h>
43 #include <ardour/audio_track.h>
44 #include <ardour/audio_diskstream.h>
45 #include <ardour/send.h>
46 #include <ardour/insert.h>
47 #include <ardour/ladspa_plugin.h>
48 #include <ardour/connection.h>
49 #include <ardour/session_connection.h>
50 #include <ardour/profile.h>
51
52 #include "ardour_ui.h"
53 #include "ardour_dialog.h"
54 #include "public_editor.h"
55 #include "redirect_box.h"
56 #include "keyboard.h"
57 #include "plugin_selector.h"
58 #include "route_redirect_selection.h"
59 #include "mixer_ui.h"
60 #include "actions.h"
61 #include "plugin_ui.h"
62 #include "send_ui.h"
63 #include "io_selector.h"
64 #include "utils.h"
65 #include "gui_thread.h"
66
67 #include "i18n.h"
68
69 #ifdef HAVE_AUDIOUNITS
70 class AUPluginUI;
71 #endif
72
73 using namespace sigc;
74 using namespace ARDOUR;
75 using namespace PBD;
76 using namespace Gtk;
77 using namespace Glib;
78 using namespace Gtkmm2ext;
79
80 RedirectBox* RedirectBox::_current_redirect_box = 0;
81 RefPtr<Action> RedirectBox::cut_action;
82 RefPtr<Action> RedirectBox::paste_action;
83 bool RedirectBox::get_colors = true;
84 Gdk::Color* RedirectBox::active_redirect_color;
85 Gdk::Color* RedirectBox::inactive_redirect_color;
86
87 RedirectBox::RedirectBox (Placement pcmnt, Session& sess, PluginSelector &plugsel, 
88                           RouteRedirectSelection& rsel, bool owner_is_mixer)
89         : _session(sess), 
90           _owner_is_mixer (owner_is_mixer), 
91           _placement(pcmnt), 
92           _plugin_selector(plugsel),
93           _rr_selection(rsel)
94 {
95         if (get_colors) {
96                 active_redirect_color = new Gdk::Color;
97                 inactive_redirect_color = new Gdk::Color;
98                 set_color (*active_redirect_color, rgba_from_style ("RedirectSelector", 0xff, 0, 0, 0, "fg", Gtk::STATE_ACTIVE, false ));
99                 set_color (*inactive_redirect_color, rgba_from_style ("RedirectSelector", 0xff, 0, 0, 0, "fg", Gtk::STATE_NORMAL, false ));
100                 get_colors = false;
101         }
102
103         _width = Wide;
104         redirect_menu = 0;
105         send_action_menu = 0;
106         redirect_drag_in_progress = false;
107         no_redirect_redisplay = false;
108         ignore_delete = false;
109
110         model = ListStore::create(columns);
111
112         RefPtr<TreeSelection> selection = redirect_display.get_selection();
113         selection->set_mode (Gtk::SELECTION_MULTIPLE);
114         selection->signal_changed().connect (mem_fun (*this, &RedirectBox::selection_changed));
115
116         redirect_display.set_model (model);
117         redirect_display.append_column (X_("notshown"), columns.text);
118         redirect_display.set_name ("RedirectSelector");
119         redirect_display.set_headers_visible (false);
120         redirect_display.set_reorderable (true);
121         redirect_display.set_size_request (-1, 40);
122         redirect_display.get_column(0)->set_sizing(TREE_VIEW_COLUMN_FIXED);
123         redirect_display.get_column(0)->set_fixed_width(48);
124         redirect_display.add_object_drag (columns.redirect.index(), "redirects");
125         redirect_display.signal_drop.connect (mem_fun (*this, &RedirectBox::object_drop));
126
127         TreeViewColumn* name_col = redirect_display.get_column(0);
128         CellRendererText* renderer = dynamic_cast<CellRendererText*>(redirect_display.get_column_cell_renderer (0));
129         name_col->add_attribute(renderer->property_foreground_gdk(), columns.color);
130
131         redirect_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
132         
133         model->signal_row_deleted().connect (mem_fun (*this, &RedirectBox::row_deleted));
134
135         redirect_scroller.add (redirect_display);
136         redirect_eventbox.add (redirect_scroller);
137         
138         redirect_scroller.set_size_request (-1, 40);
139
140         pack_start (redirect_eventbox, true, true);
141
142         redirect_eventbox.signal_enter_notify_event().connect (bind (sigc::ptr_fun (RedirectBox::enter_box), this));
143
144         redirect_display.signal_button_press_event().connect (mem_fun(*this, &RedirectBox::redirect_button_press_event), false);
145         redirect_display.signal_button_release_event().connect (mem_fun(*this, &RedirectBox::redirect_button_release_event));
146 }
147
148 RedirectBox::~RedirectBox ()
149 {
150 }
151
152 void
153 RedirectBox::set_route (boost::shared_ptr<Route> r)
154 {
155
156         connections.clear ();
157
158         /* since we're dealing with a new route, any existing limit on redisplay
159            must be irrelevant.
160         */
161
162         no_redirect_redisplay = false;
163         _route = r;
164
165         connections.push_back (_route->redirects_changed.connect (mem_fun(*this, &RedirectBox::redisplay_redirects)));
166         connections.push_back (_route->GoingAway.connect (mem_fun (*this, &RedirectBox::route_going_away)));
167         connections.push_back (_route->name_changed.connect (mem_fun(*this, &RedirectBox::route_name_changed)));
168
169         redisplay_redirects (0);
170 }
171
172 void
173 RedirectBox::route_going_away ()
174 {
175         /* don't keep updating display as redirects are deleted */
176         no_redirect_redisplay = true;
177 }
178
179 void
180 RedirectBox::object_drop (const list<boost::shared_ptr<Redirect> >& redirects)
181 {
182         paste_redirect_list (redirects);
183 }
184
185 void
186 RedirectBox::update()
187 {
188         redisplay_redirects (0);
189 }
190
191 void
192 RedirectBox::set_width (Width w)
193 {
194         if (_width == w) {
195                 return;
196         }
197         _width = w;
198         if (w == -1) {
199                 abort ();
200         }
201         redisplay_redirects (0);
202 }
203
204 void
205 RedirectBox::remove_redirect_gui (boost::shared_ptr<Redirect> redirect)
206 {
207         boost::shared_ptr<Insert> insert;
208         boost::shared_ptr<Send> send;
209         boost::shared_ptr<PortInsert> port_insert;
210
211         if ((insert = boost::dynamic_pointer_cast<Insert> (redirect)) != 0) {
212
213                 if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (insert)) != 0) {
214                         PortInsertUI *io_selector = reinterpret_cast<PortInsertUI *> (port_insert->get_gui());
215                         port_insert->set_gui (0);
216                         delete io_selector;
217                 } 
218
219         } else if ((send = boost::dynamic_pointer_cast<Send> (insert)) != 0) {
220                 SendUIWindow *sui = reinterpret_cast<SendUIWindow*> (send->get_gui());
221                 send->set_gui (0);
222                 delete sui;
223         }
224 }
225
226 void 
227 RedirectBox::build_send_action_menu ()
228
229 {
230         using namespace Menu_Helpers;
231
232         send_action_menu = new Menu;
233         send_action_menu->set_name ("ArdourContextMenu");
234         MenuList& items = send_action_menu->items();
235
236         items.push_back (MenuElem (_("New send"), mem_fun(*this, &RedirectBox::new_send)));
237         items.push_back (MenuElem (_("Show send controls"), mem_fun(*this, &RedirectBox::show_send_controls)));
238 }
239
240 void
241 RedirectBox::show_send_controls ()
242
243 {
244 }
245
246 void
247 RedirectBox::new_send ()
248
249 {
250 }
251
252 void
253 RedirectBox::show_redirect_menu (gint arg)
254 {
255         if (redirect_menu == 0) {
256                 redirect_menu = build_redirect_menu ();
257         }
258
259         Gtk::MenuItem* plugin_menu_item = dynamic_cast<Gtk::MenuItem*>(ActionManager::get_widget("/redirectmenu/newplugin"));
260
261         if (plugin_menu_item) {
262                 plugin_menu_item->set_submenu (_plugin_selector.plugin_menu());
263         }
264
265         cut_action->set_sensitive (can_cut_redirects ());
266         
267         paste_action->set_sensitive (!_rr_selection.redirects.empty());
268
269         redirect_menu->popup (1, arg);
270 }
271
272 void
273 RedirectBox::redirect_drag_begin (GdkDragContext *context)
274 {
275         redirect_drag_in_progress = true;
276 }
277
278 void
279 RedirectBox::redirect_drag_end (GdkDragContext *context)
280 {
281         redirect_drag_in_progress = false;
282 }
283
284 bool
285 RedirectBox::redirect_button_press_event (GdkEventButton *ev)
286 {
287         TreeIter iter;
288         TreeModel::Path path;
289         TreeViewColumn* column;
290         int cellx;
291         int celly;
292         boost::shared_ptr<Redirect> redirect;
293         int ret = false;
294         bool selected = false;
295
296         if (redirect_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
297                 if ((iter = model->get_iter (path))) {
298                         redirect = (*iter)[columns.redirect];
299                         selected = redirect_display.get_selection()->is_selected (iter);
300                 }
301                 
302         }
303
304         if (redirect && (Keyboard::is_edit_event (ev) || (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS))) {
305                 
306                 if (_session.engine().connected()) {
307                         /* XXX giving an error message here is hard, because we may be in the midst of a button press */
308                         edit_redirect (redirect);
309                 }
310                 ret = true;
311                 
312         } else if (redirect && ev->button == 1 && selected) {
313
314                 // this is purely informational but necessary
315                 RedirectSelected (redirect); // emit
316
317         } else if (!redirect && ev->button == 1 && ev->type == GDK_2BUTTON_PRESS) {
318
319                 choose_plugin ();
320                 _plugin_selector.show_manager ();
321
322         }
323         
324         return ret;
325 }
326
327 bool
328 RedirectBox::redirect_button_release_event (GdkEventButton *ev)
329 {
330         TreeIter iter;
331         TreeModel::Path path;
332         TreeViewColumn* column;
333         int cellx;
334         int celly;
335         boost::shared_ptr<Redirect> redirect;
336         int ret = false;
337
338
339         if (redirect_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
340                 if ((iter = model->get_iter (path))) {
341                         redirect = (*iter)[columns.redirect];
342                 }
343         }
344
345         if (redirect && Keyboard::is_delete_event (ev)) {
346                 
347                 Glib::signal_idle().connect (bind (mem_fun(*this, &RedirectBox::idle_delete_redirect), boost::weak_ptr<Redirect>(redirect)));
348                 ret = true;
349                 
350         } else if (Keyboard::is_context_menu_event (ev)) {
351
352                 show_redirect_menu(ev->time);
353                 ret = true;
354
355         } else if (redirect && Keyboard::is_button2_event (ev)
356 #ifndef GTKOSX
357                    && (Keyboard::no_modifier_keys_pressed (ev) && ((ev->state & Gdk::BUTTON2_MASK) == Gdk::BUTTON2_MASK))
358 #endif 
359                 ) {
360                 
361                 /* button2-click with no modifiers */
362
363                 redirect->set_active (!redirect->active(), this);
364                 ret = true;
365
366         } 
367
368         return ret;
369 }
370
371 Menu *
372 RedirectBox::build_redirect_menu ()
373 {
374         redirect_menu = dynamic_cast<Gtk::Menu*>(ActionManager::get_widget("/redirectmenu") );
375         redirect_menu->set_name ("ArdourContextMenu");
376
377         show_all_children();
378
379         return redirect_menu;
380 }
381
382 void
383 RedirectBox::selection_changed ()
384 {
385         bool sensitive = (redirect_display.get_selection()->count_selected_rows()) ? true : false;
386         ActionManager::set_sensitive (ActionManager::plugin_selection_sensitive_actions, sensitive);
387 }
388
389 void
390 RedirectBox::select_all_redirects ()
391 {
392         redirect_display.get_selection()->select_all();
393 }
394
395 void
396 RedirectBox::deselect_all_redirects ()
397 {
398         redirect_display.get_selection()->unselect_all();
399 }
400
401 void
402 RedirectBox::choose_plugin ()
403 {
404         _plugin_selector.set_interested_object (*this);
405 }
406
407 void
408 RedirectBox::use_plugins (const SelectedPlugins& plugins)
409 {
410         for (SelectedPlugins::const_iterator p = plugins.begin(); p != plugins.end(); ++p) {
411
412                 boost::shared_ptr<Redirect> redirect (new PluginInsert (_session, *p, _placement));
413
414                 uint32_t err_streams;
415
416                 if (Config->get_new_plugins_active()) {
417                         redirect->set_active (true, this);
418                 }
419                 
420                 if (_route->add_redirect (redirect, this, &err_streams)) {
421                         weird_plugin_dialog (**p, err_streams, _route);
422                 } else {
423                         
424                         if (Profile->get_sae()) {
425                                 redirect->set_active (true, 0);
426                         }
427                         redirect->active_changed.connect (bind (mem_fun (*this, &RedirectBox::show_redirect_active_r), boost::weak_ptr<Redirect>(redirect)));
428                 }
429         }
430 }
431
432 void
433 RedirectBox::weird_plugin_dialog (Plugin& p, uint32_t streams, boost::shared_ptr<IO> io)
434 {
435         ArdourDialog dialog (_("ardour: weird plugin dialog"));
436         Label label;
437
438         /* i hate this kind of code */
439
440         if (streams > (unsigned)p.get_info()->n_inputs) {
441                 label.set_text (string_compose (_(
442 "You attempted to add a plugin (%1).\n"
443 "The plugin has %2 inputs\n"
444 "but at the insertion point, there are\n"
445 "%3 active signal streams.\n"
446 "\n"
447 "This makes no sense - you are throwing away\n"
448 "part of the signal."),
449                                          p.name(),
450                                          p.get_info()->n_inputs,
451                                          streams));
452         } else if (streams < (unsigned)p.get_info()->n_inputs) {
453                 label.set_text (string_compose (_(
454 "You attempted to add a plugin (%1).\n"
455 "The plugin has %2 inputs\n"
456 "but at the insertion point there are\n"
457 "only %3 active signal streams.\n"
458 "\n"
459 "This makes no sense - unless the plugin supports\n"
460 "side-chain inputs. A future version of Ardour will\n"
461 "support this type of configuration."),
462                                          p.name(),
463                                          p.get_info()->n_inputs,
464                                          streams));
465         } else {
466                 label.set_text (string_compose (_(
467 "You attempted to add a plugin (%1).\n"
468 "\n"
469 "The I/O configuration doesn't make sense:\n"
470 "\n" 
471 "The plugin has %2 inputs and %3 outputs.\n"
472 "The track/bus has %4 inputs and %5 outputs.\n"
473 "The insertion point, has %6 active signals.\n"
474 "\n"
475 "Ardour does not understand what to do in such situations.\n"),
476                                          p.name(),
477                                          p.get_info()->n_inputs,
478                                          p.get_info()->n_outputs,
479                                          io->n_inputs(),
480                                          io->n_outputs(),
481                                          streams));
482         }
483
484         dialog.set_border_width (PublicEditor::window_border_width);
485
486         label.set_alignment (0.5, 0.5);
487         dialog.get_vbox()->pack_start (label);
488         dialog.add_button (Stock::OK, RESPONSE_ACCEPT);
489
490         dialog.set_name (X_("PluginIODialog"));
491         dialog.set_position (Gtk::WIN_POS_MOUSE);
492         dialog.set_modal (true);
493         dialog.show_all ();
494
495         dialog.run ();
496 }
497
498 void
499 RedirectBox::choose_insert ()
500 {
501         boost::shared_ptr<Redirect> redirect (new PortInsert (_session, _placement));
502         redirect->active_changed.connect (bind (mem_fun(*this, &RedirectBox::show_redirect_active_r), boost::weak_ptr<Redirect>(redirect)));
503         _route->add_redirect (redirect, this);
504 }
505
506 void
507 RedirectBox::choose_send ()
508 {
509         boost::shared_ptr<Send> send (new Send (_session, _placement));
510
511         /* XXX need redirect lock on route */
512
513         try {
514                 send->ensure_io (0, _route->max_redirect_outs(), false, this);
515         } catch (AudioEngine::PortRegistrationFailure& err) {
516                 error << string_compose (_("Cannot set up new send: %1"), err.what()) << endmsg;
517                 return;
518         }
519         
520         IOSelectorWindow *ios = new IOSelectorWindow (_session, send, false, true);
521         
522         ios->show_all ();
523
524         boost::shared_ptr<Redirect> r = boost::static_pointer_cast<Redirect>(send);
525
526         ios->selector().Finished.connect (bind (mem_fun(*this, &RedirectBox::send_io_finished), boost::weak_ptr<Redirect>(r), ios));
527 }
528
529 void
530 RedirectBox::send_io_finished (IOSelector::Result r, boost::weak_ptr<Redirect> weak_redirect, IOSelectorWindow* ios)
531 {
532         boost::shared_ptr<Redirect> redirect (weak_redirect.lock());
533
534         if (!redirect) {
535                 return;
536         }
537
538         switch (r) {
539         case IOSelector::Cancelled:
540                 // redirect will go away when all shared_ptrs to it vanish
541                 break;
542
543         case IOSelector::Accepted:
544                 _route->add_redirect (redirect, this);
545                 if (Profile->get_sae()) {
546                         redirect->set_active (true, 0);
547                 }
548                 break;
549         }
550
551         delete_when_idle (ios);
552 }
553
554 void
555 RedirectBox::redisplay_redirects (void *src)
556 {
557         ENSURE_GUI_THREAD(bind (mem_fun(*this, &RedirectBox::redisplay_redirects), src));
558
559         if (no_redirect_redisplay) {
560                 return;
561         }
562         
563         ignore_delete = true;
564         model->clear ();
565         ignore_delete = false;
566
567         redirect_active_connections.clear ();
568         redirect_name_connections.clear ();
569
570         void (RedirectBox::*pmf)(boost::shared_ptr<Redirect>) = &RedirectBox::add_redirect_to_display;
571         _route->foreach_redirect (this, pmf);
572
573         switch (_placement) {
574         case PreFader:
575                 build_redirect_tooltip(redirect_eventbox, _("Pre-fader inserts, sends & plugins:"));
576                 break;
577         case PostFader:
578                 build_redirect_tooltip(redirect_eventbox, _("Post-fader inserts, sends & plugins:"));
579                 break;
580         }
581 }
582
583 void
584 RedirectBox::add_redirect_to_display (boost::shared_ptr<Redirect> redirect)
585 {
586         if (redirect->placement() != _placement) {
587                 return;
588         }
589         
590         Gtk::TreeModel::Row row = *(model->append());
591
592         row[columns.text] = redirect_name (redirect);
593         row[columns.redirect] = redirect;
594
595         show_redirect_active (redirect);
596
597         redirect_active_connections.push_back (redirect->active_changed.connect (bind (mem_fun(*this, &RedirectBox::show_redirect_active_r), boost::weak_ptr<Redirect>(redirect))));
598         redirect_name_connections.push_back (redirect->name_changed.connect (bind (mem_fun(*this, &RedirectBox::show_redirect_name), boost::weak_ptr<Redirect>(redirect))));
599 }
600
601 string
602 RedirectBox::redirect_name (boost::weak_ptr<Redirect> weak_redirect)
603 {
604         boost::shared_ptr<Redirect> redirect (weak_redirect.lock());
605
606         if (!redirect) {
607                 return string();
608         }
609
610         boost::shared_ptr<Send> send;
611         string name_display;
612
613         if (!redirect->active()) {
614                 name_display = " (";
615         }
616
617         if ((send = boost::dynamic_pointer_cast<Send> (redirect)) != 0) {
618
619                 name_display += '>';
620
621                 /* grab the send name out of its overall name */
622
623                 string::size_type lbracket, rbracket;
624                 lbracket = send->name().find ('[');
625                 rbracket = send->name().find (']');
626
627                 switch (_width) {
628                 case Wide:
629                         name_display += send->name().substr (lbracket+1, lbracket-rbracket-1);
630                         break;
631                 case Narrow:
632                         name_display += PBD::short_version (send->name().substr (lbracket+1, lbracket-rbracket-1), 4);
633                         break;
634                 }
635
636         } else {
637
638                 switch (_width) {
639                 case Wide:
640                         name_display += redirect->name();
641                         break;
642                 case Narrow:
643                         name_display += PBD::short_version (redirect->name(), 5);
644                         break;
645                 }
646
647         }
648
649         if (!redirect->active()) {
650                 name_display += ')';
651         }
652
653         return name_display;
654 }
655
656 void
657 RedirectBox::build_redirect_tooltip (EventBox& box, string start)
658 {
659         string tip(start);
660
661         Gtk::TreeModel::Children children = model->children();
662         for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
663                 Gtk::TreeModel::Row row = *iter;
664                 tip += '\n';
665                 tip += row[columns.text];
666         }
667         ARDOUR_UI::instance()->tooltips().set_tip (box, tip);
668 }
669
670 void
671 RedirectBox::show_redirect_name (void* src, boost::weak_ptr<Redirect> redirect)
672 {
673         ENSURE_GUI_THREAD(bind (mem_fun(*this, &RedirectBox::show_redirect_name), src, redirect));
674         show_redirect_active (redirect);
675 }
676
677 void
678 RedirectBox::show_redirect_active_r (Redirect* r, void *src, boost::weak_ptr<Redirect> weak_redirect)
679 {
680         show_redirect_active (weak_redirect);
681 }
682
683 void
684 RedirectBox::show_redirect_active (boost::weak_ptr<Redirect> weak_redirect)
685 {
686         boost::shared_ptr<Redirect> redirect (weak_redirect.lock());
687         
688         if (!redirect) {
689                 return;
690         }
691
692         ENSURE_GUI_THREAD(bind (mem_fun(*this, &RedirectBox::show_redirect_active), weak_redirect));
693         
694         Gtk::TreeModel::Children children = model->children();
695         Gtk::TreeModel::Children::iterator iter = children.begin();
696
697         while (iter != children.end()) {
698
699                 boost::shared_ptr<Redirect> r = (*iter)[columns.redirect];
700
701                 if (r == redirect) {
702                         
703                         (*iter)[columns.text] = redirect_name (r);
704                         
705                         if (redirect->active()) {
706                                 (*iter)[columns.color] = *active_redirect_color;
707                         } else {
708                                 (*iter)[columns.color] = *inactive_redirect_color;
709                         }
710                         break;
711                 }
712
713                 iter++;
714         }
715 }
716
717 void
718 RedirectBox::row_deleted (const Gtk::TreeModel::Path& path)
719 {
720         if (!ignore_delete) {
721                 compute_redirect_sort_keys ();
722         }
723 }
724
725 void
726 RedirectBox::compute_redirect_sort_keys ()
727 {
728         uint32_t sort_key = 0;
729         Gtk::TreeModel::Children children = model->children();
730
731         for (Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
732                 boost::shared_ptr<Redirect> r = (*iter)[columns.redirect];
733                 r->set_sort_key (sort_key);
734                 sort_key++;
735         }
736
737         if (_route->sort_redirects ()) {
738
739                 redisplay_redirects (0);
740
741                 /* now tell them about the problem */
742
743                 ArdourDialog dialog (_("ardour: weird plugin dialog"));
744                 Label label;
745
746                 label.set_text (_("\
747 You cannot reorder this set of redirects\n\
748 in that way because the inputs and\n\
749 outputs do not work correctly."));
750
751                 dialog.get_vbox()->pack_start (label);
752                 dialog.add_button (Stock::OK, RESPONSE_ACCEPT);
753
754                 dialog.set_name (X_("PluginIODialog"));
755                 dialog.set_position (Gtk::WIN_POS_MOUSE);
756                 dialog.set_modal (true);
757                 dialog.show_all ();
758
759                 dialog.run ();
760         }
761 }
762
763 void
764 RedirectBox::rename_redirects ()
765 {
766         vector<boost::shared_ptr<Redirect> > to_be_renamed;
767         
768         get_selected_redirects (to_be_renamed);
769
770         if (to_be_renamed.empty()) {
771                 return;
772         }
773
774         for (vector<boost::shared_ptr<Redirect> >::iterator i = to_be_renamed.begin(); i != to_be_renamed.end(); ++i) {
775                 rename_redirect (*i);
776         }
777 }
778
779 bool
780 RedirectBox::can_cut_redirects ()
781 {
782         vector<boost::shared_ptr<Redirect> > sel;
783         get_selected_redirects (sel);
784         
785         /* cut_redirects () does not cut inserts or sends */
786         for (vector<boost::shared_ptr<Redirect> >::const_iterator i = sel.begin (); i != sel.end (); ++i) {
787
788                 if (boost::dynamic_pointer_cast<PluginInsert>(*i) != 0) {
789                         return true;
790                 }
791         }
792
793         return false;
794 }
795
796 void
797 RedirectBox::cut_redirects ()
798 {
799         vector<boost::shared_ptr<Redirect> > to_be_removed;
800         
801         get_selected_redirects (to_be_removed);
802
803         if (to_be_removed.empty()) {
804                 return;
805         }
806
807         /* this essentially transfers ownership of the redirect
808            of the redirect from the route to the mixer
809            selection.
810         */
811         
812         _rr_selection.set (to_be_removed);
813
814         no_redirect_redisplay = true;
815         for (vector<boost::shared_ptr<Redirect> >::iterator i = to_be_removed.begin(); i != to_be_removed.end(); ++i) {
816                 // Do not cut inserts or sends
817                 if (boost::dynamic_pointer_cast<PluginInsert>((*i)) != 0) {
818                         void* gui = (*i)->get_gui ();
819                 
820                         if (gui) {
821                                 static_cast<Gtk::Widget*>(gui)->hide ();
822                         }
823                 
824                         if (_route->remove_redirect (*i, this)) {
825                                 /* removal failed */
826                                 _rr_selection.remove (*i);
827                         }
828                 } else {
829                         _rr_selection.remove (*i);
830                 }
831
832         }
833         no_redirect_redisplay = false;
834         redisplay_redirects (this);
835 }
836
837 void
838 RedirectBox::copy_redirects ()
839 {
840         vector<boost::shared_ptr<Redirect> > to_be_copied;
841         vector<boost::shared_ptr<Redirect> > copies;
842
843         get_selected_redirects (to_be_copied);
844
845         if (to_be_copied.empty()) {
846                 return;
847         }
848
849         for (vector<boost::shared_ptr<Redirect> >::iterator i = to_be_copied.begin(); i != to_be_copied.end(); ++i) {
850                 // Do not copy inserts 
851                 if ((boost::dynamic_pointer_cast<PluginInsert>((*i)) != 0) ||
852                     (boost::dynamic_pointer_cast<Send>((*i)) != 0)) {
853                         copies.push_back (Redirect::clone (*i));
854                 }
855         }
856
857         _rr_selection.set (copies);
858
859 }
860
861 void
862 RedirectBox::delete_redirects ()
863 {
864         vector<boost::shared_ptr<Redirect> > to_be_deleted;
865         
866         get_selected_redirects (to_be_deleted);
867
868         if (to_be_deleted.empty()) {
869                 return;
870         }
871
872         for (vector<boost::shared_ptr<Redirect> >::iterator i = to_be_deleted.begin(); i != to_be_deleted.end(); ++i) {
873                 
874                 void* gui = (*i)->get_gui ();
875                 
876                 if (gui) {
877                         static_cast<Gtk::Widget*>(gui)->hide ();
878                 }
879
880                 _route->remove_redirect( *i, this);
881         }
882
883         no_redirect_redisplay = false;
884         redisplay_redirects (this);
885 }
886
887 gint
888 RedirectBox::idle_delete_redirect (boost::weak_ptr<Redirect> weak_redirect)
889 {
890         boost::shared_ptr<Redirect> redirect (weak_redirect.lock());
891
892         if (!redirect) {
893                 return false;
894         }
895
896         /* NOT copied to _mixer.selection() */
897
898         no_redirect_redisplay = true;
899
900         void* gui = redirect->get_gui ();
901         
902         if (gui) {
903                 static_cast<Gtk::Widget*>(gui)->hide ();
904         }
905         
906         _route->remove_redirect (redirect, this);
907         no_redirect_redisplay = false;
908         redisplay_redirects (this);
909
910         return false;
911 }
912
913 void
914 RedirectBox::rename_redirect (boost::shared_ptr<Redirect> redirect)
915 {
916         ArdourPrompter name_prompter (true);
917         string result;
918         name_prompter.set_prompt (_("rename redirect"));
919         name_prompter.set_initial_text (redirect->name());
920         name_prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
921         name_prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
922         name_prompter.show_all ();
923
924         switch (name_prompter.run ()) {
925
926         case Gtk::RESPONSE_ACCEPT:
927                 name_prompter.get_result (result);
928                 if (result.length()) {
929                         if (_session.route_by_name (result)) {
930                                 ARDOUR_UI::instance()->popup_error (_("A track already exists with that name"));
931                                 return;
932                         }
933                         
934                         redirect->set_name (result, this);
935                 }       
936                 break;
937         }
938
939         return;
940 }
941
942 void
943 RedirectBox::cut_redirect (boost::shared_ptr<Redirect> redirect)
944 {
945         /* this essentially transfers ownership of the redirect
946            of the redirect from the route to the mixer
947            selection.
948         */
949
950         _rr_selection.add (redirect);
951         
952         void* gui = redirect->get_gui ();
953
954         if (gui) {
955                 static_cast<Gtk::Widget*>(gui)->hide ();
956         }
957         
958         no_redirect_redisplay = true;
959         if (_route->remove_redirect (redirect, this)) {
960                 _rr_selection.remove (redirect);
961         }
962         no_redirect_redisplay = false;
963         redisplay_redirects (this);
964 }
965
966 void
967 RedirectBox::copy_redirect (boost::shared_ptr<Redirect> redirect)
968 {
969         boost::shared_ptr<Redirect> copy = Redirect::clone (redirect);
970         _rr_selection.add (copy);
971 }
972
973 void
974 RedirectBox::paste_redirects ()
975 {
976         if (_rr_selection.redirects.empty()) {
977                 return;
978         }
979
980         paste_redirect_list (_rr_selection.redirects);
981 }
982
983 void
984 RedirectBox::paste_redirect_list (const list<boost::shared_ptr<Redirect> >& redirects)
985 {
986         list<boost::shared_ptr<Redirect> > copies;
987
988         for (list<boost::shared_ptr<Redirect> >::const_iterator i = redirects.begin(); i != redirects.end(); ++i) {
989
990                 boost::shared_ptr<Redirect> copy = Redirect::clone (*i);
991
992                 copy->set_placement (_placement, this);
993                 copies.push_back (copy);
994         }
995
996         if (_route->add_redirects (copies, this)) {
997
998                 string msg = _(
999                         "Copying the set of redirects on the clipboard failed,\n\
1000 probably because the I/O configuration of the plugins\n\
1001 could not match the configuration of this track.");
1002                 MessageDialog am (msg);
1003                 am.run ();
1004         }
1005 }
1006
1007 void
1008 RedirectBox::activate_redirect (boost::shared_ptr<Redirect> r)
1009 {
1010         r->set_active (true, 0);
1011 }
1012
1013 void
1014 RedirectBox::deactivate_redirect (boost::shared_ptr<Redirect> r)
1015 {
1016         r->set_active (false, 0);
1017 }
1018
1019 void
1020 RedirectBox::get_selected_redirects (vector<boost::shared_ptr<Redirect> >& redirects)
1021 {
1022     vector<Gtk::TreeModel::Path> pathlist = redirect_display.get_selection()->get_selected_rows();
1023  
1024     for (vector<Gtk::TreeModel::Path>::iterator iter = pathlist.begin(); iter != pathlist.end(); ++iter) {
1025             redirects.push_back ((*(model->get_iter(*iter)))[columns.redirect]);
1026     }
1027 }
1028
1029 void
1030 RedirectBox::for_selected_redirects (void (RedirectBox::*pmf)(boost::shared_ptr<Redirect>))
1031 {
1032     vector<Gtk::TreeModel::Path> pathlist = redirect_display.get_selection()->get_selected_rows();
1033
1034         for (vector<Gtk::TreeModel::Path>::iterator iter = pathlist.begin(); iter != pathlist.end(); ++iter) {
1035                 boost::shared_ptr<Redirect> redirect = (*(model->get_iter(*iter)))[columns.redirect];
1036                 (this->*pmf)(redirect);
1037         }
1038 }
1039
1040 void
1041 RedirectBox::clone_redirects ()
1042 {
1043         RouteSelection& routes (_rr_selection.routes);
1044
1045         if (!routes.empty()) {
1046                 if (_route->copy_redirects (*routes.front(), _placement)) {
1047                         string msg = _(
1048 "Copying the set of redirects on the clipboard failed,\n\
1049 probably because the I/O configuration of the plugins\n\
1050 could not match the configuration of this track.");
1051                         MessageDialog am (msg);
1052                         am.run ();
1053                 }
1054         }
1055 }
1056
1057 void
1058 RedirectBox::all_redirects_active (bool state)
1059 {
1060         _route->all_redirects_active (_placement, state);
1061 }
1062
1063 void
1064 RedirectBox::clear_redirects ()
1065 {
1066         string prompt;
1067         vector<string> choices;
1068
1069         if (boost::dynamic_pointer_cast<AudioTrack>(_route) != 0) {
1070                 if (_placement == PreFader) {
1071                         prompt = _("Do you really want to remove all pre-fader redirects from this track?\n"
1072                                    "(this cannot be undone)");
1073                 } else {
1074                         prompt = _("Do you really want to remove all post-fader redirects from this track?\n"
1075                                    "(this cannot be undone)");
1076                 }
1077         } else {
1078                 if (_placement == PreFader) {
1079                         prompt = _("Do you really want to remove all pre-fader redirects from this bus?\n"
1080                                    "(this cannot be undone)");
1081                 } else {
1082                         prompt = _("Do you really want to remove all post-fader redirects from this bus?\n"
1083                                    "(this cannot be undone)");
1084                 }
1085         }
1086
1087         choices.push_back (_("Cancel"));
1088         choices.push_back (_("Yes, remove them all"));
1089
1090         Gtkmm2ext::Choice prompter (prompt, choices);
1091
1092         if (prompter.run () == 1) {
1093                 _route->clear_redirects (_placement, this);
1094         }
1095 }
1096
1097 void
1098 RedirectBox::edit_redirect (boost::shared_ptr<Redirect> redirect)
1099 {
1100         boost::shared_ptr<Insert> insert;
1101
1102         if (boost::dynamic_pointer_cast<AudioTrack>(_route) != 0) {
1103
1104                 if (boost::dynamic_pointer_cast<AudioTrack> (_route)->freeze_state() == AudioTrack::Frozen) {
1105                         return;
1106                 }
1107         }
1108         
1109         if ((insert = boost::dynamic_pointer_cast<Insert> (redirect)) == 0) {
1110                 
1111                 /* it's a send */
1112                 
1113                 if (!_session.engine().connected()) {
1114                         return;
1115                 }
1116
1117                 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (redirect);
1118                 
1119                 SendUIWindow *send_ui;
1120                 
1121                 if (send->get_gui() == 0) {
1122                         
1123                         send_ui = new SendUIWindow (send, _session);
1124
1125                         WindowTitle title(Glib::get_application_name());
1126                         title += send->name();
1127                         send_ui->set_title (title.get_string());
1128
1129                         send->set_gui (send_ui);
1130                         
1131                 } else {
1132                         send_ui = reinterpret_cast<SendUIWindow *> (send->get_gui());
1133                 }
1134                 
1135                 if (send_ui->is_visible()) {
1136                         send_ui->get_window()->raise ();
1137                 } else {
1138                         send_ui->show_all ();
1139                         send_ui->present ();
1140                 }
1141                 
1142         } else {
1143                 
1144                 /* it's an insert */
1145
1146                 boost::shared_ptr<PluginInsert> plugin_insert;
1147                 boost::shared_ptr<PortInsert> port_insert;
1148                 
1149                 if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (insert)) != 0) {
1150                         
1151                         PluginUIWindow *plugin_ui;
1152
1153                         /* these are both allowed to be null */
1154                         
1155                         Container* toplevel = get_toplevel();
1156                         Window* win = dynamic_cast<Gtk::Window*>(toplevel);
1157                         
1158                         if (plugin_insert->get_gui() == 0) {
1159
1160                                 plugin_ui = new PluginUIWindow (win, plugin_insert);
1161                                 
1162                                 WindowTitle title(Glib::get_application_name());
1163                                 title += generate_redirect_title (plugin_insert);
1164                                 plugin_ui->set_title (title.get_string());
1165                                 
1166                                 plugin_insert->set_gui (plugin_ui);
1167
1168                         } else {
1169                                 plugin_ui = reinterpret_cast<PluginUIWindow *> (plugin_insert->get_gui());
1170                                 plugin_ui->set_parent (win);
1171                         }
1172                         
1173                         if (plugin_ui->is_visible()) {
1174                                 plugin_ui->get_window()->raise ();
1175                         } else {
1176                                 plugin_ui->show_all ();
1177                                 plugin_ui->present ();
1178                         }
1179
1180                 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (insert)) != 0) {
1181                         
1182                         if (!_session.engine().connected()) {
1183                                 MessageDialog msg ( _("Not connected to JACK - no I/O changes are possible"));
1184                                 msg.run ();
1185                                 return;
1186                         }
1187
1188                         PortInsertWindow *io_selector;
1189
1190                         if (port_insert->get_gui() == 0) {
1191                                 io_selector = new PortInsertWindow (_session, port_insert);
1192                                 port_insert->set_gui (io_selector);
1193                                 
1194                         } else {
1195                                 io_selector = reinterpret_cast<PortInsertWindow *> (port_insert->get_gui());
1196                         }
1197                         
1198                         if (io_selector->is_visible()) {
1199                                 io_selector->get_window()->raise ();
1200                         } else {
1201                                 io_selector->show_all ();
1202                                 io_selector->present ();
1203                         }
1204                 }
1205         }
1206 }
1207
1208 bool
1209 RedirectBox::enter_box (GdkEventCrossing *ev, RedirectBox* rb)
1210 {
1211         switch (ev->detail) {
1212         case GDK_NOTIFY_INFERIOR:
1213                 break;
1214
1215         case GDK_NOTIFY_VIRTUAL:
1216                 /* fallthru */
1217
1218         default:
1219                 _current_redirect_box = rb;
1220         }
1221
1222         return false;
1223 }
1224
1225 void
1226 RedirectBox::register_actions ()
1227 {
1228         Glib::RefPtr<Gtk::ActionGroup> popup_act_grp = Gtk::ActionGroup::create(X_("redirectmenu"));
1229         Glib::RefPtr<Action> act;
1230
1231         /* new stuff */
1232         ActionManager::register_action (popup_act_grp, X_("newplugin"), _("New Plugin"),  sigc::ptr_fun (RedirectBox::rb_choose_plugin));
1233
1234         act = ActionManager::register_action (popup_act_grp, X_("newinsert"), _("New Insert"),  sigc::ptr_fun (RedirectBox::rb_choose_insert));
1235         ActionManager::jack_sensitive_actions.push_back (act);
1236         act = ActionManager::register_action (popup_act_grp, X_("newsend"), _("New Send ..."),  sigc::ptr_fun (RedirectBox::rb_choose_send));
1237         ActionManager::jack_sensitive_actions.push_back (act);
1238
1239         ActionManager::register_action (popup_act_grp, X_("clear"), _("Clear"),  sigc::ptr_fun (RedirectBox::rb_clear));
1240
1241         /* standard editing stuff */
1242         cut_action = ActionManager::register_action (popup_act_grp, X_("cut"), _("Cut"),  sigc::ptr_fun (RedirectBox::rb_cut));
1243         ActionManager::plugin_selection_sensitive_actions.push_back (cut_action);
1244         act = ActionManager::register_action (popup_act_grp, X_("copy"), _("Copy"),  sigc::ptr_fun (RedirectBox::rb_copy));
1245         ActionManager::plugin_selection_sensitive_actions.push_back(act);
1246
1247         act = ActionManager::register_action (popup_act_grp, X_("delete"), _("Delete"),  sigc::ptr_fun (RedirectBox::rb_delete));
1248         ActionManager::plugin_selection_sensitive_actions.push_back(act); // ??
1249
1250         paste_action = ActionManager::register_action (popup_act_grp, X_("paste"), _("Paste"),  sigc::ptr_fun (RedirectBox::rb_paste));
1251         act = ActionManager::register_action (popup_act_grp, X_("rename"), _("Rename"),  sigc::ptr_fun (RedirectBox::rb_rename));
1252         ActionManager::plugin_selection_sensitive_actions.push_back(act);
1253         ActionManager::register_action (popup_act_grp, X_("selectall"), _("Select All"),  sigc::ptr_fun (RedirectBox::rb_select_all));
1254         ActionManager::register_action (popup_act_grp, X_("deselectall"), _("Deselect All"),  sigc::ptr_fun (RedirectBox::rb_deselect_all));
1255                 
1256         /* activation */
1257         act = ActionManager::register_action (popup_act_grp, X_("activate"), _("Activate"),  sigc::ptr_fun (RedirectBox::rb_activate));
1258         ActionManager::plugin_selection_sensitive_actions.push_back(act);
1259         act = ActionManager::register_action (popup_act_grp, X_("deactivate"), _("Deactivate"),  sigc::ptr_fun (RedirectBox::rb_deactivate));
1260         ActionManager::plugin_selection_sensitive_actions.push_back(act);
1261         ActionManager::register_action (popup_act_grp, X_("activate_all"), _("Activate all"),  sigc::ptr_fun (RedirectBox::rb_activate_all));
1262         ActionManager::register_action (popup_act_grp, X_("deactivate_all"), _("Deactivate all"),  sigc::ptr_fun (RedirectBox::rb_deactivate_all));
1263
1264         /* show editors */
1265         act = ActionManager::register_action (popup_act_grp, X_("edit"), _("Edit"),  sigc::ptr_fun (RedirectBox::rb_edit));
1266         ActionManager::plugin_selection_sensitive_actions.push_back(act);
1267
1268         ActionManager::add_action_group (popup_act_grp);
1269
1270
1271 }
1272
1273 void
1274 RedirectBox::rb_choose_plugin ()
1275 {
1276         if (_current_redirect_box == 0) {
1277                 return;
1278         }
1279         _current_redirect_box->choose_plugin ();
1280 }
1281
1282 void
1283 RedirectBox::rb_choose_insert ()
1284 {
1285         if (_current_redirect_box == 0) {
1286                 return;
1287         }
1288         _current_redirect_box->choose_insert ();
1289 }
1290
1291 void
1292 RedirectBox::rb_choose_send ()
1293 {
1294         if (_current_redirect_box == 0) {
1295                 return;
1296         }
1297         _current_redirect_box->choose_send ();
1298 }
1299
1300 void
1301 RedirectBox::rb_clear ()
1302 {
1303         if (_current_redirect_box == 0) {
1304                 return;
1305         }
1306
1307         _current_redirect_box->clear_redirects ();
1308 }
1309
1310 void
1311 RedirectBox::rb_cut ()
1312 {
1313         if (_current_redirect_box == 0) {
1314                 return;
1315         }
1316
1317         _current_redirect_box->cut_redirects ();
1318 }
1319
1320 void
1321 RedirectBox::rb_delete ()
1322 {
1323         if (_current_redirect_box == 0) {
1324                 return;
1325         }
1326
1327         _current_redirect_box->delete_redirects ();
1328 }
1329
1330 void
1331 RedirectBox::rb_copy ()
1332 {
1333         if (_current_redirect_box == 0) {
1334                 return;
1335         }
1336         _current_redirect_box->copy_redirects ();
1337 }
1338
1339 void
1340 RedirectBox::rb_paste ()
1341 {
1342         if (_current_redirect_box == 0) {
1343                 return;
1344         }
1345
1346         _current_redirect_box->paste_redirects ();
1347 }
1348
1349 void
1350 RedirectBox::rb_rename ()
1351 {
1352         if (_current_redirect_box == 0) {
1353                 return;
1354         }
1355         _current_redirect_box->rename_redirects ();
1356 }
1357
1358 void
1359 RedirectBox::rb_select_all ()
1360 {
1361         if (_current_redirect_box == 0) {
1362                 return;
1363         }
1364
1365         _current_redirect_box->select_all_redirects ();
1366 }
1367
1368 void
1369 RedirectBox::rb_deselect_all ()
1370 {
1371         if (_current_redirect_box == 0) {
1372                 return;
1373         }
1374
1375         _current_redirect_box->deselect_all_redirects ();
1376 }
1377
1378 void
1379 RedirectBox::rb_activate ()
1380 {
1381         if (_current_redirect_box == 0) {
1382                 return;
1383         }
1384
1385         _current_redirect_box->for_selected_redirects (&RedirectBox::activate_redirect);
1386 }
1387
1388 void
1389 RedirectBox::rb_deactivate ()
1390 {
1391         if (_current_redirect_box == 0) {
1392                 return;
1393         }
1394         _current_redirect_box->for_selected_redirects (&RedirectBox::deactivate_redirect);
1395 }
1396
1397 void
1398 RedirectBox::rb_activate_all ()
1399 {
1400         if (_current_redirect_box == 0) {
1401                 return;
1402         }
1403
1404         _current_redirect_box->all_redirects_active (true);
1405 }
1406
1407 void
1408 RedirectBox::rb_deactivate_all ()
1409 {
1410         if (_current_redirect_box == 0) {
1411                 return;
1412         }
1413         _current_redirect_box->all_redirects_active (false);
1414 }
1415
1416 void
1417 RedirectBox::rb_edit ()
1418 {
1419         if (_current_redirect_box == 0) {
1420                 return;
1421         }
1422
1423         _current_redirect_box->for_selected_redirects (&RedirectBox::edit_redirect);
1424 }
1425
1426 void
1427 RedirectBox::route_name_changed (void* src)
1428 {
1429         boost::shared_ptr<Redirect> redirect;
1430         boost::shared_ptr<Insert> insert;
1431         Gtk::TreeModel::Children children = model->children();
1432
1433         for (Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
1434                 Gtk::TreeModel::Row row = *iter;
1435
1436                 redirect= row[columns.redirect];
1437                 
1438                 void* gui = redirect->get_gui();
1439
1440                 if (!gui) {
1441                         continue;
1442                 }
1443
1444                 /* rename editor windows for sends and plugins */
1445
1446                 WindowTitle title (Glib::get_application_name());
1447                 
1448                 if ((insert = boost::dynamic_pointer_cast<Insert> (redirect)) == 0) {
1449                         boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (redirect);
1450                         title += send->name();
1451                         static_cast<Window*>(gui)->set_title (title.get_string());
1452                 } else {
1453                         boost::shared_ptr<PluginInsert> plugin_insert;
1454                         
1455                         if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (insert)) != 0) {
1456                                 title += generate_redirect_title (plugin_insert);
1457                         }
1458                         static_cast<Window*>(gui)->set_title (title.get_string());
1459                 }
1460         }
1461 }
1462
1463 string 
1464 RedirectBox::generate_redirect_title (boost::shared_ptr<PluginInsert> pi)
1465 {
1466         string maker = pi->plugin()->maker() ? pi->plugin()->maker() : "";
1467         string::size_type email_pos;
1468
1469         if ((email_pos = maker.find_first_of ('<')) != string::npos) {
1470                 maker = maker.substr (0, email_pos - 1);
1471         }
1472
1473         if (maker.length() > 32) {
1474                 maker = maker.substr (0, 32);
1475                 maker += " ...";
1476         }
1477
1478         return string_compose(_("%1: %2 (by %3)"), _route->name(), pi->name(), maker);  
1479 }
1480