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