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