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