Fix processor box for no crash on click
[ardour.git] / gtk2_ardour / foldback_strip.cc
1 /*
2     Copyright (C) 2000-2006 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 #include <cmath>
20 #include <list>
21 #include <algorithm>
22
23 #include <sigc++/bind.h>
24
25 #include <gtkmm/messagedialog.h>
26
27 #include "pbd/convert.h"
28 #include "pbd/enumwriter.h"
29 #include "pbd/replace_all.h"
30 #include "pbd/stacktrace.h"
31
32 #include "ardour/amp.h"
33 #include "ardour/audioengine.h"
34 #include "ardour/internal_send.h"
35 #include "ardour/io.h"
36 #include "ardour/pannable.h"
37 #include "ardour/panner.h"
38 #include "ardour/panner_shell.h"
39 #include "ardour/panner_manager.h"
40 #include "ardour/port.h"
41 #include "ardour/profile.h"
42 #include "ardour/route.h"
43 #include "ardour/send.h"
44 #include "ardour/session.h"
45 #include "ardour/types.h"
46 #include "ardour/user_bundle.h"
47
48 #include "gtkmm2ext/gtk_ui.h"
49 #include "gtkmm2ext/menu_elems.h"
50 #include "gtkmm2ext/utils.h"
51 #include "gtkmm2ext/doi.h"
52
53 #include "widgets/tooltips.h"
54
55 #include "ardour_window.h"
56 #include "enums_convert.h"
57 #include "foldback_strip.h"
58 #include "mixer_ui.h"
59 #include "keyboard.h"
60 #include "public_editor.h"
61 #include "send_ui.h"
62 #include "io_selector.h"
63 #include "utils.h"
64 #include "gui_thread.h"
65 #include "ui_config.h"
66
67 #include "pbd/i18n.h"
68
69 using namespace ARDOUR;
70 using namespace ArdourWidgets;
71 using namespace PBD;
72 using namespace Gtk;
73 using namespace Gtkmm2ext;
74 using namespace std;
75
76 FoldbackStrip* FoldbackStrip::_entered_foldback_strip;
77 PBD::Signal1<void,FoldbackStrip*> FoldbackStrip::CatchDeletion;
78
79 FoldbackStrip::FoldbackStrip (Mixer_UI& mx, Session* sess, boost::shared_ptr<Route> rt)
80         : SessionHandlePtr (sess)
81         , RouteUI (sess)
82         , _mixer(mx)
83         , _mixer_owned (true)
84         , _pr_selection ()
85         , panners (sess)
86         , button_size_group (Gtk::SizeGroup::create (Gtk::SIZE_GROUP_HORIZONTAL))
87         , mute_solo_table (1, 2)
88         , bottom_button_table (1, 1)
89         , _plugin_insert_cnt (0)
90         , _comment_button (_("Comments"))
91         , fb_level_control (0)
92 //      , _visibility (X_("mixer-element-visibility"))
93 {
94         _session = sess;
95         init ();
96         set_route (rt);
97 }
98
99 void
100 FoldbackStrip::init ()
101 {
102         _entered_foldback_strip= 0;
103         route_ops_menu = 0;
104         route_select_menu = 0;
105         ignore_comment_edit = false;
106         ignore_toggle = false;
107         comment_area = 0;
108         _width_owner = 0;
109
110         /* the length of this string determines the width of the mixer strip when it is set to `wide' */
111         longest_label = "longest label";
112
113
114         output_button.set_text (_("Output"));
115         output_button.set_name ("mixer strip button");
116 //      send_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
117 //      send_scroller.add (send_display);
118
119         send_display.set_flags (CAN_FOCUS);
120         send_display.set_name ("ProcessorList");
121         send_display.set_data ("sendbox", this);
122         send_display.set_size_request (48, -1);
123         send_display.set_spacing (0);
124
125         insert_box = new ProcessorBox (0, boost::bind (&FoldbackStrip::plugin_selector, this), _pr_selection, 0);
126         insert_box->set_no_show_all ();
127         insert_box->show ();
128         insert_box->set_session (_session);
129
130 //      send_scroller.show ();
131         send_display.show ();
132
133         // TODO implement ArdourKnob::on_size_request properly
134         fb_level_control = new ArdourKnob (ArdourKnob::default_elements, ArdourKnob::Detent);
135
136 #define PX_SCALE(px) std::max((float)px, rintf((float)px * UIConfiguration::instance().get_ui_scale()))
137         fb_level_control->set_size_request (PX_SCALE(65), PX_SCALE(65));
138 #undef PX_SCALE
139         fb_level_control->set_tooltip_prefix (_("Level: "));
140         fb_level_control->set_name ("monitor section knob");
141         fb_level_control->set_no_show_all (true);
142
143         bottom_button_table.attach (*fb_level_control, 0, 1, 0, 1,FILL,FILL,20,20); //EXPAND
144
145
146         mute_solo_table.set_homogeneous (true);
147         mute_solo_table.set_spacings (2);
148
149         show_sends_button->set_text (_("Show Sends"));
150
151         show_sends_box.pack_start (*show_sends_button, true, true);
152         show_sends_button->show();
153
154         bottom_button_table.set_spacings (20);
155         bottom_button_table.set_row_spacings (20);
156         bottom_button_table.set_homogeneous (true);
157
158         name_button.set_name ("monitor section button");
159         name_button.set_text_ellipsize (Pango::ELLIPSIZE_END);
160
161         _select_button.set_name ("monitor section button");
162         _select_button.set_text (_("Select Foldback Bus"));
163
164         _comment_button.set_name (X_("mixer strip button"));
165         _comment_button.set_text_ellipsize (Pango::ELLIPSIZE_END);
166         _comment_button.signal_clicked.connect (sigc::mem_fun (*this, &RouteUI::toggle_comment_editor));
167
168         global_vpacker.set_border_width (1);
169
170         global_vpacker.set_spacing (4);
171         global_vpacker.pack_start (_select_button, Gtk::PACK_SHRINK);
172         global_vpacker.pack_start (name_button, Gtk::PACK_SHRINK);
173         global_vpacker.pack_start (_invert_button_box, Gtk::PACK_SHRINK);
174         global_vpacker.pack_start (show_sends_box, Gtk::PACK_SHRINK);
175
176 #ifndef MIXBUS
177         //add a spacer underneath the foldback bus;
178         //this fills the area that is taken up by the scrollbar on the tracks;
179         //and therefore keeps the strip boxes "even" across the bottom
180         int scrollbar_height = 0;
181         {
182                 Gtk::Window window (WINDOW_TOPLEVEL);
183                 HScrollbar scrollbar;
184                 window.add (scrollbar);
185                 scrollbar.set_name ("MixerWindow");
186                 scrollbar.ensure_style();
187                 Gtk::Requisition requisition(scrollbar.size_request ());
188                 scrollbar_height = requisition.height;
189         }
190         spacer.set_size_request (-1, scrollbar_height);
191         global_vpacker.pack_end (spacer, false, false);
192 #endif
193         global_vpacker.pack_end (_comment_button, Gtk::PACK_SHRINK);
194         global_vpacker.pack_end (output_button, Gtk::PACK_SHRINK);
195         global_vpacker.pack_end (mute_solo_table, Gtk::PACK_SHRINK);
196         global_vpacker.pack_end (panners, Gtk::PACK_SHRINK);
197         global_vpacker.pack_end (bottom_button_table, Gtk::PACK_SHRINK);
198 //      global_vpacker.pack_end (*insert_box, true, true);
199         global_vpacker.pack_end (*insert_box, Gtk::PACK_SHRINK);
200
201         global_frame.add (global_vpacker);
202         global_frame.set_shadow_type (Gtk::SHADOW_IN);
203         global_frame.set_name ("BaseFrame");
204
205         add (global_frame);
206
207         /* force setting of visible selected status */
208
209         _selected = true;
210         set_selected (false);
211
212         _packed = false;
213         _embedded = false;
214
215         _session->engine().Stopped.connect (*this, invalidator (*this), boost::bind (&FoldbackStrip::engine_stopped, this), gui_context());
216         _session->engine().Running.connect (*this, invalidator (*this), boost::bind (&FoldbackStrip::engine_running, this), gui_context());
217
218         output_button.set_text_ellipsize (Pango::ELLIPSIZE_MIDDLE);
219
220         output_button.signal_button_press_event().connect (sigc::mem_fun(*this, &FoldbackStrip::output_press), false);
221         output_button.signal_button_release_event().connect (sigc::mem_fun(*this, &FoldbackStrip::output_release), false);
222
223
224         name_button.signal_button_press_event().connect (sigc::mem_fun(*this, &FoldbackStrip::name_button_button_press), false);
225         _select_button.signal_button_press_event().connect (sigc::mem_fun (*this, &FoldbackStrip::select_button_button_press), false);
226
227         _width = Wide;
228
229
230         /* start off as a passthru strip. we'll correct this, if necessary,
231            in update_diskstream_display().
232         */
233
234
235
236         add_events (Gdk::BUTTON_RELEASE_MASK|
237                     Gdk::ENTER_NOTIFY_MASK|
238                     Gdk::LEAVE_NOTIFY_MASK|
239                     Gdk::KEY_PRESS_MASK|
240                     Gdk::KEY_RELEASE_MASK);
241
242         set_flags (get_flags() | Gtk::CAN_FOCUS);
243
244         AudioEngine::instance()->PortConnectedOrDisconnected.connect (
245                 *this, invalidator (*this), boost::bind (&FoldbackStrip::port_connected_or_disconnected, this, _1, _3), gui_context ()
246                 );
247
248         /* Add the widgets under visibility control to the VisibilityGroup; the names used here
249            must be the same as those used in RCOptionEditor so that the configuration changes
250            are recognised when they occur.
251         */
252 /*      _visibility.add (&_invert_button_box, X_("PhaseInvert"), _("Phase Invert"), false);
253         _visibility.add (&output_button, X_("Output"), _("Output"), false);
254         _visibility.add (&_comment_button, X_("Comments"), _("Comments"), false);
255
256         parameter_changed (X_("mixer-element-visibility"));
257         UIConfiguration::instance().ParameterChanged.connect (sigc::mem_fun (*this, &FoldbackStrip::parameter_changed));
258         Config->ParameterChanged.connect (_config_connection, MISSING_INVALIDATOR, boost::bind (&FoldbackStrip::parameter_changed, this, _1), gui_context());
259         _session->config.ParameterChanged.connect (_config_connection, MISSING_INVALIDATOR, boost::bind (&FoldbackStrip::parameter_changed, this, _1), gui_context());
260 */
261         //watch for mouse enter/exit so we can do some stuff
262         signal_enter_notify_event().connect (sigc::mem_fun(*this, &FoldbackStrip::mixer_strip_enter_event ));
263         signal_leave_notify_event().connect (sigc::mem_fun(*this, &FoldbackStrip::mixer_strip_leave_event ));
264
265 }
266
267 FoldbackStrip::~FoldbackStrip ()
268 {
269         CatchDeletion (this);
270         delete fb_level_control;
271         fb_level_control = 0;
272
273         if (this ==_entered_foldback_strip)
274                 _entered_foldback_strip = NULL;
275 }
276
277 bool
278 FoldbackStrip::mixer_strip_enter_event (GdkEventCrossing* /*ev*/)
279 {
280         _entered_foldback_strip = this;
281
282         //although we are triggering on the "enter", to the user it will appear that it is happenin on the "leave"
283         //because the FoldbackStrip control is a parent that encompasses the strip
284         deselect_all_processors();
285
286         return false;
287 }
288
289 bool
290 FoldbackStrip::mixer_strip_leave_event (GdkEventCrossing *ev)
291 {
292         //if we have moved outside our strip, but not into a child view, then deselect ourselves
293         if ( !(ev->detail == GDK_NOTIFY_INFERIOR) ) {
294                 _entered_foldback_strip= 0;
295
296         }
297
298         return false;
299 }
300
301 string
302 FoldbackStrip::name() const
303 {
304         if (_route) {
305                 return _route->name();
306         }
307         return string();
308 }
309
310 void
311 FoldbackStrip::update_fb_level_control ()
312 {
313         fb_level_control->show ();
314         fb_level_control->set_controllable (_route->gain_control());
315 }
316
317 void
318 FoldbackStrip::set_route (boost::shared_ptr<Route> rt)
319 {
320         /// FIX NO route
321         if (!rt) {
322                 RouteUI::self_delete ();
323
324                 return;
325         }
326         if (show_sends_button->get_parent()) {
327                 show_sends_box.remove (*show_sends_button);
328         }
329
330         RouteUI::set_route (rt);
331
332         /* ProcessorBox needs access to _route so that it can read
333            GUI object state.
334         */
335 //      processor_box.set_route (rt);
336         insert_box->set_route (rt);
337
338         revert_to_default_display ();
339
340
341 //      mute_solo_table.attach (gpm.gain_display,0,1,1,2, EXPAND|FILL, EXPAND);
342 //      mute_solo_table.attach (gpm.peak_display,1,2,1,2, EXPAND|FILL, EXPAND);
343
344         if (solo_button->get_parent()) {
345                 mute_solo_table.remove (*solo_button);
346         }
347
348         if (mute_button->get_parent()) {
349                 mute_solo_table.remove (*mute_button);
350         }
351
352         mute_solo_table.attach (*mute_button, 0, 1, 0, 1);
353         mute_solo_table.attach (*solo_button, 1, 2, 0, 1);
354         mute_button->show ();
355         solo_button->show ();
356         show_sends_box.show ();
357
358         spacer.show();
359
360         update_fb_level_control();
361
362         show_sends_box.pack_start (*show_sends_button, true, true);
363         show_sends_button->show();
364
365
366         delete route_ops_menu;
367         route_ops_menu = 0;
368
369         delete route_select_menu;
370         route_select_menu = 0;
371
372         _route->output()->changed.connect (*this, invalidator (*this), boost::bind (&FoldbackStrip::update_output_display, this), gui_context());
373
374         _route->io_changed.connect (route_connections, invalidator (*this), boost::bind (&FoldbackStrip::io_changed_proxy, this), gui_context ());
375
376         if (_route->panner_shell()) {
377                 update_panner_choices();
378                 _route->panner_shell()->Changed.connect (route_connections, invalidator (*this), boost::bind (&FoldbackStrip::connect_to_pan, this), gui_context());
379         }
380
381         _route->comment_changed.connect (route_connections, invalidator (*this), boost::bind (&FoldbackStrip::setup_comment_button, this), gui_context());
382
383         set_stuff_from_route ();
384
385         /* now force an update of all the various elements */
386
387         update_mute_display ();
388         update_solo_display ();
389         name_changed ();
390         comment_changed ();
391
392         connect_to_pan ();
393         panners.setup_pan ();
394         panners.show_all ();
395
396         update_output_display ();
397
398         add_events (Gdk::BUTTON_RELEASE_MASK);
399
400         insert_box->show ();
401
402         Route::FedBy fed_by = _route->fed_by();
403         for (Route::FedBy::iterator i = fed_by.begin(); i != fed_by.end(); ++i) {
404                 if (i->sends_only) {
405                         boost::shared_ptr<Route> s_rt (i->r.lock());
406                         boost::shared_ptr<Send> snd = s_rt->internal_send_for (_route);
407                         //s_rt->DropReferences.connect (*this, MISSING_INVALIDATOR, boost::bind (&FoldbackStrip::fill_sendbox, this), this);
408                         boost::shared_ptr<Processor> processor (snd);
409                         //boost::shared_ptr<PluginInsert> plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (processor);
410 // Ok we have the info... now we need widgets to put it in... I suspect I need a class or three
411 // this doesn't work... and I need to clear it out and rebuild each time.
412                         ArdourWidgets::ArdourButton _button;
413                         _button.set_distinct_led_click (true);
414                         _button.set_fallthrough_to_parent(true);
415                         _button.set_led_left (true);
416 //                      _button.signal_led_clicked.connect (sigc::mem_fun (*this, &FoldbackStrip::led_clicked));
417                         _button.set_text (s_rt->name ());
418
419                         //Gtk::VBox     snd_entry = NULL;
420                         Gtk::VBox       snd_entry;
421                         snd_entry.set_border_width (1);
422                         snd_entry.set_spacing (4);
423                         snd_entry.pack_start (_button, true, true);
424                         send_display.pack_start (snd_entry, true, true);
425                         _button.show ();
426                         snd_entry.show ();
427
428
429                 }
430         }
431
432
433
434         global_frame.show();
435         global_vpacker.show();
436         mute_solo_table.show();
437         bottom_button_table.show();
438         show_sends_box.show_all();
439         //send_scroller.show ();
440         send_display.show ();
441         output_button.show();
442         name_button.show();
443         _select_button.show();
444         _comment_button.show();
445
446         map_frozen();
447
448         show ();
449 }
450
451 void
452 FoldbackStrip::set_stuff_from_route ()
453 {
454         /* if width is not set, it will be set by the MixerUI or editor */
455
456         Width width;
457         if (get_gui_property ("strip-width", width)) {
458 //              set_width_enum (width, this);
459         }
460 }
461
462 void
463 FoldbackStrip::set_packed (bool yn)
464 {
465         _packed = yn;
466         set_gui_property ("visible", _packed);
467 }
468
469
470 struct RouteCompareByName {
471         bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
472                 return a->name().compare (b->name()) < 0;
473         }
474 };
475
476 gint
477 FoldbackStrip::output_release (GdkEventButton *ev)
478 {
479         switch (ev->button) {
480         case 3:
481                 edit_output_configuration ();
482                 break;
483         }
484
485         return false;
486 }
487
488 gint
489 FoldbackStrip::output_press (GdkEventButton *ev)
490 {
491         using namespace Menu_Helpers;
492         if (!ARDOUR_UI_UTILS::engine_is_running ()) {
493                 return true;
494         }
495
496         MenuList& citems = output_menu.items();
497         switch (ev->button) {
498
499         case 3:
500                 return false;  //wait for the mouse-up to pop the dialog
501
502         case 1:
503         {
504                 output_menu.set_name ("ArdourContextMenu");
505                 citems.clear ();
506                 output_menu_bundles.clear ();
507
508                 citems.push_back (MenuElem (_("Disconnect"), sigc::mem_fun (*(static_cast<RouteUI*>(this)), &RouteUI::disconnect_output)));
509
510                 citems.push_back (SeparatorElem());
511                 uint32_t const n_with_separator = citems.size ();
512
513                 ARDOUR::BundleList current = _route->output()->bundles_connected ();
514
515                 boost::shared_ptr<ARDOUR::BundleList> b = _session->bundles ();
516
517                 /* guess the user-intended main type of the route output */
518                 DataType intended_type = guess_main_type(false);
519
520                 /* try adding the master bus first */
521                 boost::shared_ptr<Route> master = _session->master_out();
522                 if (master) {
523                         maybe_add_bundle_to_output_menu (master->input()->bundle(), current, intended_type);
524                 }
525
526                 /* then other routes inputs */
527                 RouteList copy = _session->get_routelist ();
528                 copy.sort (RouteCompareByName ());
529                 for (ARDOUR::RouteList::const_iterator i = copy.begin(); i != copy.end(); ++i) {
530                         maybe_add_bundle_to_output_menu ((*i)->input()->bundle(), current, intended_type);
531                 }
532
533                 /* then try adding user bundles, often labeled/grouped physical inputs */
534                 for (ARDOUR::BundleList::iterator i = b->begin(); i != b->end(); ++i) {
535                         if (boost::dynamic_pointer_cast<UserBundle> (*i)) {
536                                 maybe_add_bundle_to_output_menu (*i, current, intended_type);
537                         }
538                 }
539
540                 /* then all other bundles, including physical outs or other sofware */
541                 for (ARDOUR::BundleList::iterator i = b->begin(); i != b->end(); ++i) {
542                         if (boost::dynamic_pointer_cast<UserBundle> (*i) == 0) {
543                                 maybe_add_bundle_to_output_menu (*i, current, intended_type);
544                         }
545                 }
546
547                 if (citems.size() == n_with_separator) {
548                         /* no routes added; remove the separator */
549                         citems.pop_back ();
550                 }
551
552                 if (!ARDOUR::Profile->get_mixbus()) {
553                         citems.push_back (SeparatorElem());
554
555                         for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) {
556                                 citems.push_back (
557                                                 MenuElem (
558                                                         string_compose (_("Add %1 port"), (*i).to_i18n_string()),
559                                                         sigc::bind (sigc::mem_fun (*this, &FoldbackStrip::add_output_port), *i)
560                                                         )
561                                                 );
562                         }
563                 }
564
565                 citems.push_back (SeparatorElem());
566                 citems.push_back (MenuElem (_("Routing Grid"), sigc::mem_fun (*(static_cast<RouteUI*>(this)), &RouteUI::edit_output_configuration)));
567
568                 Gtkmm2ext::anchored_menu_popup(&output_menu, &output_button, "",
569                                                1, ev->time);
570
571                 break;
572         }
573
574         default:
575                 break;
576         }
577         return TRUE;
578 }
579
580 void
581 FoldbackStrip::bundle_output_chosen (boost::shared_ptr<ARDOUR::Bundle> c)
582 {
583         if (ignore_toggle) {
584                 return;
585         }
586
587         _route->output()->connect_ports_to_bundle (c, true, true, this);
588 }
589
590 void
591 FoldbackStrip::maybe_add_bundle_to_output_menu (boost::shared_ptr<Bundle> b, ARDOUR::BundleList const& /*current*/,
592                                              DataType type)
593 {
594         using namespace Menu_Helpers;
595
596         /* The bundle should be an input one, but not ours */
597         if (b->ports_are_inputs() == false || *b == *_route->input()->bundle()) {
598                 return;
599         }
600
601         /* Don't add the monitor input unless we are Master */
602         boost::shared_ptr<Route> monitor = _session->monitor_out();
603         if ((!_route->is_master()) && monitor && b->has_same_ports (monitor->input()->bundle()))
604                 return;
605
606         /* It should either match exactly our outputs (if |type| is DataType::NIL)
607          * or have the same number of |type| channels than our outputs. */
608         if (type == DataType::NIL) {
609                 if(b->nchannels() != _route->n_outputs())
610                         return;
611         } else {
612                 if (b->nchannels().n(type) != _route->n_outputs().n(type))
613                         return;
614         }
615
616         /* Avoid adding duplicates */
617         list<boost::shared_ptr<Bundle> >::iterator i = output_menu_bundles.begin ();
618         while (i != output_menu_bundles.end() && b->has_same_ports (*i) == false) {
619                 ++i;
620         }
621         if (i != output_menu_bundles.end()) {
622                 return;
623         }
624
625         /* Now add the bundle to the menu */
626         output_menu_bundles.push_back (b);
627
628         MenuList& citems = output_menu.items();
629         citems.push_back (MenuElemNoMnemonic (b->name (), sigc::bind (sigc::mem_fun(*this, &FoldbackStrip::bundle_output_chosen), b)));
630 }
631
632 void
633 FoldbackStrip::connect_to_pan ()
634 {
635         ENSURE_GUI_THREAD (*this, &FoldbackStrip::connect_to_pan)
636
637         panstate_connection.disconnect ();
638         panstyle_connection.disconnect ();
639
640         if (!_route->panner()) {
641                 return;
642         }
643
644         boost::shared_ptr<Pannable> p = _route->pannable ();
645
646         //p->automation_state_changed.connect (panstate_connection, invalidator (*this), boost::bind (&PannerUI::pan_automation_state_changed, &panners), gui_context());
647
648         /* This call reduncant, PannerUI::set_panner() connects to _panshell->Changed itself
649          * However, that only works a panner was previously set.
650          *
651          * PannerUI must remain subscribed to _panshell->Changed() in case
652          * we switch the panner eg. AUX-Send and back
653          * _route->panner_shell()->Changed() vs _panshell->Changed
654          */
655         /*if (panners._panner == 0) {
656                 panners.panshell_changed ();
657         }*/
658         update_panner_choices();
659 }
660
661 void
662 FoldbackStrip::update_panner_choices ()
663 {
664         ENSURE_GUI_THREAD (*this, &FoldbackStrip::update_panner_choices)
665         if (!_route->panner_shell()) { return; }
666
667         uint32_t in = _route->output()->n_ports().n_audio();
668         uint32_t out = in;
669         if (_route->panner()) {
670                 in = _route->panner()->in().n_audio();
671         }
672
673         panners.set_available_panners(PannerManager::instance().PannerManager::get_available_panners(in, out));
674 }
675
676 DataType
677 FoldbackStrip::guess_main_type(bool for_input, bool favor_connected) const
678 {
679         /* The heuristic follows these principles:
680          *  A) If all ports that the user connected are of the same type, then he
681          *     very probably intends to use the IO with that type. A common subcase
682          *     is when the IO has only ports of the same type (connected or not).
683          *  B) If several types of ports are connected, then we should guess based
684          *     on the likeliness of the user wanting to use a given type.
685          *     We assume that the DataTypes are ordered from the most likely to the
686          *     least likely when iterating or comparing them with "<".
687          *  C) If no port is connected, the same logic can be applied with all ports
688          *     instead of connected ones. TODO: Try other ideas, for instance look at
689          *     the last plugin output when |for_input| is false (note: when StrictIO
690          *     the outs of the last plugin should be the same as the outs of the route
691          *     modulo the panner which forwards non-audio anyway).
692          * All of these constraints are respected by the following algorithm that
693          * just returns the most likely datatype found in connected ports if any, or
694          * available ports if any (since if all ports are of the same type, the most
695          * likely found will be that one obviously). */
696
697         boost::shared_ptr<IO> io = for_input ? _route->input() : _route->output();
698
699         /* Find most likely type among connected ports */
700         if (favor_connected) {
701                 DataType type = DataType::NIL; /* NIL is always last so least likely */
702                 for (PortSet::iterator p = io->ports().begin(); p != io->ports().end(); ++p) {
703                         if (p->connected() && p->type() < type)
704                                 type = p->type();
705                 }
706                 if (type != DataType::NIL) {
707                         /* There has been a connected port (necessarily non-NIL) */
708                         return type;
709                 }
710         }
711
712         /* Find most likely type among available ports.
713          * The iterator stops before NIL. */
714         for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
715                 if (io->n_ports().n(*t) > 0)
716                         return *t;
717         }
718
719         /* No port at all, return the most likely datatype by default */
720         return DataType::front();
721 }
722
723 /*
724  * Output port labelling
725  *
726  * Case 1: Each output has one connection, all connections are to system:playback_%i
727  *   out 1 -> system:playback_1
728  *   out 2 -> system:playback_2
729  *   out 3 -> system:playback_3
730  *   Display as: 1/2/3
731  *
732  * Case 2: Each output has one connection, all connections are to ardour:track_x/in 1
733  *   out 1 -> ardour:track_x/in 1
734  *   out 2 -> ardour:track_x/in 2
735  *   Display as: track_x
736  *
737  * Case 3: Each output has one connection, all connections are to Jack client "program x"
738  *   out 1 -> program x:foo
739  *   out 2 -> program x:foo
740  *   Display as: program x
741  *
742  * Case 4: No connections (Disconnected)
743  *   Display as: -
744  *
745  * Default case (unusual routing):
746  *   Display as: *number of connections*
747  *
748  *
749  * Tooltips
750  *
751  * .-----------------------------------------------.
752  * | Mixdown                                       |
753  * | out 1 -> ardour:master/in 1, jamin:input/in 1 |
754  * | out 2 -> ardour:master/in 2, jamin:input/in 2 |
755  * '-----------------------------------------------'
756  * .-----------------------------------------------.
757  * | Guitar SM58                                   |
758  * | Disconnected                                  |
759  * '-----------------------------------------------'
760  */
761
762 void
763 FoldbackStrip::update_io_button ()
764 {
765         ostringstream tooltip;
766         ostringstream label;
767         bool have_label = false;
768
769         uint32_t total_connection_count = 0;
770         uint32_t typed_connection_count = 0;
771         bool each_typed_port_has_one_connection = true;
772
773         DataType dt = guess_main_type(false);
774         boost::shared_ptr<IO> io = _route->output();
775
776         /* Fill in the tooltip. Also count:
777          *  - The total number of connections.
778          *  - The number of main-typed connections.
779          *  - Whether each main-typed port has exactly one connection. */
780
781         tooltip << string_compose (_("<b>OUTPUT</b> from %1"),
782                         Gtkmm2ext::markup_escape_text (_route->name()));
783
784         string arrow = Gtkmm2ext::markup_escape_text(" -> ");
785         vector<string> port_connections;
786         for (PortSet::iterator port = io->ports().begin();
787                                port != io->ports().end();
788                                ++port) {
789                 port_connections.clear();
790                 port->get_connections(port_connections);
791
792                 uint32_t port_connection_count = 0;
793
794                 for (vector<string>::iterator i = port_connections.begin();
795                                               i != port_connections.end();
796                                               ++i) {
797                         ++port_connection_count;
798
799                         if (port_connection_count == 1) {
800                                 tooltip << endl << Gtkmm2ext::markup_escape_text (
801                                                 port->name().substr(port->name().find("/") + 1));
802                                 tooltip << arrow;
803                         } else {
804                                 tooltip << ", ";
805                         }
806
807                         tooltip << Gtkmm2ext::markup_escape_text(*i);
808                 }
809
810                 total_connection_count += port_connection_count;
811                 if (port->type() == dt) {
812                         typed_connection_count += port_connection_count;
813                         each_typed_port_has_one_connection &= (port_connection_count == 1);
814                 }
815
816         }
817
818         if (total_connection_count == 0) {
819                 tooltip << endl << _("Disconnected");
820         }
821
822         if (typed_connection_count == 0) {
823                 label << "-";
824                 have_label = true;
825         }
826
827         /* Are all main-typed channels connected to the same route ? */
828         if (!have_label) {
829                 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
830                 for (ARDOUR::RouteList::const_iterator route = routes->begin();
831                                                        route != routes->end();
832                                                        ++route) {
833                         boost::shared_ptr<IO> dest_io = (*route)->output();
834                         if (io->bundle()->connected_to(dest_io->bundle(),
835                                                        _session->engine(),
836                                                        dt, true)) {
837                                 label << Gtkmm2ext::markup_escape_text ((*route)->name());
838                                 have_label = true;
839                                 break;
840                         }
841                 }
842         }
843
844         /* Are all main-typed channels connected to the same (user) bundle ? */
845         if (!have_label) {
846                 boost::shared_ptr<ARDOUR::BundleList> bundles = _session->bundles ();
847                 for (ARDOUR::BundleList::iterator bundle = bundles->begin();
848                                                   bundle != bundles->end();
849                                                   ++bundle) {
850                         if (boost::dynamic_pointer_cast<UserBundle> (*bundle) == 0)
851                                 continue;
852                         if (io->bundle()->connected_to(*bundle, _session->engine(),
853                                                        dt, true)) {
854                                 label << Gtkmm2ext::markup_escape_text ((*bundle)->name());
855                                 have_label = true;
856                                 break;
857                         }
858                 }
859         }
860
861         /* Is each main-typed channel only connected to a physical output ? */
862         if (!have_label && each_typed_port_has_one_connection) {
863                 ostringstream temp_label;
864                 vector<string> phys;
865                 string playorcapture;
866
867                 _session->engine().get_physical_outputs(dt, phys);
868                 playorcapture = "playback_";
869                 for (PortSet::iterator port = io->ports().begin(dt);
870                                        port != io->ports().end(dt);
871                                        ++port) {
872                         string pn = "";
873                         for (vector<string>::iterator s = phys.begin();
874                                                       s != phys.end();
875                                                       ++s) {
876                                 if (!port->connected_to(*s))
877                                         continue;
878                                 pn = AudioEngine::instance()->get_pretty_name_by_name(*s);
879                                 if (pn.empty()) {
880                                         string::size_type start = (*s).find(playorcapture);
881                                         if (start != string::npos) {
882                                                 pn = (*s).substr(start + playorcapture.size());
883                                         }
884                                 }
885                                 break;
886                         }
887                         if (pn.empty()) {
888                                 temp_label.str(""); /* erase the failed attempt */
889                                 break;
890                         }
891                         if (port != io->ports().begin(dt))
892                                 temp_label << "/";
893                         temp_label << pn;
894                 }
895
896                 if (!temp_label.str().empty()) {
897                         label << temp_label.str();
898                         have_label = true;
899                 }
900         }
901
902         /* Is each main-typed channel connected to a single and different port with
903          * the same client name (e.g. another JACK client) ? */
904         if (!have_label && each_typed_port_has_one_connection) {
905                 string maybe_client = "";
906                 vector<string> connections;
907                 for (PortSet::iterator port = io->ports().begin(dt);
908                                        port != io->ports().end(dt);
909                                        ++port) {
910                         port_connections.clear();
911                         port->get_connections(port_connections);
912                         string connection = port_connections.front();
913
914                         vector<string>::iterator i = connections.begin();
915                         while (i != connections.end() && *i != connection) {
916                                 ++i;
917                         }
918                         if (i != connections.end())
919                                 break; /* duplicate connection */
920                         connections.push_back(connection);
921
922                         connection = connection.substr(0, connection.find(":"));
923                         if (maybe_client.empty())
924                                 maybe_client = connection;
925                         if (maybe_client != connection)
926                                 break;
927                 }
928                 if (connections.size() == io->n_ports().n(dt)) {
929                         label << maybe_client;
930                         have_label = true;
931                 }
932         }
933
934         /* Odd configuration */
935         if (!have_label) {
936                 label << "*" << total_connection_count << "*";
937         }
938
939         if (total_connection_count > typed_connection_count) {
940                 label << "\u2295"; /* circled plus */
941         }
942
943         /* Actually set the properties of the button */
944         char * cstr = new char[tooltip.str().size() + 1];
945         strcpy(cstr, tooltip.str().c_str());
946
947         output_button.set_text (label.str());
948         set_tooltip (&output_button, cstr);
949
950         delete [] cstr;
951 }
952
953 void
954 FoldbackStrip::update_output_display ()
955 {
956         update_io_button ();
957         panners.setup_pan ();
958
959         if (has_audio_outputs ()) {
960                 panners.show_all ();
961         } else {
962                 panners.hide_all ();
963         }
964 }
965
966 void
967 FoldbackStrip::io_changed_proxy ()
968 {
969         Glib::signal_idle().connect_once (sigc::mem_fun (*this, &FoldbackStrip::update_panner_choices));
970 }
971
972 void
973 FoldbackStrip::port_connected_or_disconnected (boost::weak_ptr<Port> wa, boost::weak_ptr<Port> wb)
974 {
975         boost::shared_ptr<Port> a = wa.lock ();
976         boost::shared_ptr<Port> b = wb.lock ();
977
978         if ((a && _route->output()->has_port (a)) || (b && _route->output()->has_port (b))) {
979                 update_output_display ();
980         }
981 }
982
983 void
984 FoldbackStrip::setup_comment_button ()
985 {
986         std::string comment = _route->comment();
987
988         set_tooltip (_comment_button, comment.empty() ? _("Click to add/edit comments") : _route->comment());
989
990         if (comment.empty ()) {
991                 _comment_button.set_name ("generic button");
992                 _comment_button.set_text (_("Comments"));
993                 return;
994         }
995
996         _comment_button.set_name ("comment button");
997
998         string::size_type pos = comment.find_first_of (" \t\n");
999         if (pos != string::npos) {
1000                 comment = comment.substr (0, pos);
1001         }
1002         if (comment.empty()) {
1003                 _comment_button.set_text (_("Comments"));
1004         } else {
1005                 _comment_button.set_text (comment);
1006         }
1007 }
1008
1009 void
1010 FoldbackStrip::show_passthru_color ()
1011 {
1012         //reset_strip_style ();
1013 }
1014
1015
1016 void
1017 FoldbackStrip::help_count_plugins (boost::weak_ptr<Processor> p)
1018 {
1019         boost::shared_ptr<Processor> processor (p.lock ());
1020         if (!processor || !processor->display_to_user()) {
1021                 return;
1022         }
1023         boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
1024 #ifdef MIXBUS
1025         if (pi && pi->is_channelstrip ()) {
1026                 return;
1027         }
1028 #endif
1029         if (pi) {
1030                 ++_plugin_insert_cnt;
1031         }
1032 }
1033 void
1034 FoldbackStrip::build_route_ops_menu ()
1035 {
1036         using namespace Menu_Helpers;
1037         route_ops_menu = new Menu;
1038         route_ops_menu->set_name ("ArdourContextMenu");
1039
1040         MenuList& items = route_ops_menu->items();
1041
1042         items.push_back (MenuElem (_("Comments..."), sigc::mem_fun (*this, &RouteUI::open_comment_editor)));
1043
1044         items.push_back (MenuElem (_("Outputs..."), sigc::mem_fun (*this, &RouteUI::edit_output_configuration)));
1045
1046         items.push_back (SeparatorElem());
1047
1048         items.push_back (MenuElem (_("Save As Template..."), sigc::mem_fun(*this, &RouteUI::save_as_template)));
1049
1050         items.push_back (MenuElem (_("Rename..."), sigc::mem_fun(*this, &RouteUI::route_rename)));
1051
1052         items.push_back (SeparatorElem());
1053         items.push_back (CheckMenuElem (_("Active")));
1054         Gtk::CheckMenuItem* i = dynamic_cast<Gtk::CheckMenuItem *> (&items.back());
1055         i->set_active (_route->active());
1056         i->set_sensitive(! _session->transport_rolling());
1057         i->signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &RouteUI::set_route_active), !_route->active(), false));
1058
1059         items.push_back (SeparatorElem());
1060         items.push_back (CheckMenuElem (_("Protect Against Denormals"), sigc::mem_fun (*this, &RouteUI::toggle_denormal_protection)));
1061         denormal_menu_item = dynamic_cast<Gtk::CheckMenuItem *> (&items.back());
1062         denormal_menu_item->set_active (_route->denormal_protection());
1063
1064         items.push_back (SeparatorElem());
1065         items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &FoldbackStrip::remove_current_fb)));
1066 }
1067
1068 void
1069 FoldbackStrip::build_route_select_menu ()
1070 {
1071         using namespace Menu_Helpers;
1072         route_select_menu = new Menu;
1073         route_select_menu->set_name ("ArdourContextMenu");
1074
1075         MenuList& items = route_select_menu->items();
1076         StripableList fb_list;
1077         _session->get_stripables (fb_list, PresentationInfo::FoldbackBus);
1078         for (StripableList::iterator s = fb_list.begin(); s != fb_list.end(); ++s) {
1079
1080                 boost::shared_ptr<Route> route = boost::dynamic_pointer_cast<Route> ((*s));
1081                 if (route == _route) {
1082                         continue;
1083                 }
1084                 items.push_back (MenuElem (route->name (), sigc::bind (sigc::mem_fun (*this, &FoldbackStrip::set_route), route)));
1085         }
1086
1087 }
1088
1089
1090 gboolean
1091 FoldbackStrip::name_button_button_press (GdkEventButton* ev)
1092 {
1093         if (ev->button == 1 || ev->button == 3) {
1094                 list_route_operations ();
1095
1096                 if (ev->button == 1) {
1097                         Gtkmm2ext::anchored_menu_popup(route_ops_menu, &name_button, "",
1098                                                        1, ev->time);
1099                 } else {
1100                         route_ops_menu->popup (3, ev->time);
1101                 }
1102
1103                 return true;
1104         }
1105
1106         return false;
1107 }
1108
1109 gboolean
1110 FoldbackStrip::select_button_button_press (GdkEventButton* ev)
1111 {
1112         if (ev->button == 1 || ev->button == 3) {
1113                 list_fb_routes ();
1114
1115                 if (ev->button == 1) {
1116                         Gtkmm2ext::anchored_menu_popup(route_select_menu, &_select_button, "",
1117                                                        1, ev->time);
1118                 } else {
1119                         route_select_menu->popup (3, ev->time);
1120                 }
1121
1122                 return true;
1123         }
1124
1125         return false;
1126 }
1127
1128 void
1129 FoldbackStrip::list_route_operations ()
1130 {
1131         delete route_ops_menu;
1132         build_route_ops_menu ();
1133 }
1134
1135 void
1136 FoldbackStrip::list_fb_routes ()
1137 {
1138         delete route_select_menu;
1139         build_route_select_menu ();
1140 }
1141
1142 void
1143 FoldbackStrip::set_selected (bool yn)
1144 {
1145         AxisView::set_selected (yn);
1146
1147         if (selected()) {
1148                 global_frame.set_shadow_type (Gtk::SHADOW_ETCHED_OUT);
1149                 global_frame.set_name ("MixerStripSelectedFrame");
1150         } else {
1151                 global_frame.set_shadow_type (Gtk::SHADOW_IN);
1152                 global_frame.set_name ("MixerStripFrame");
1153         }
1154
1155         global_frame.queue_draw ();
1156
1157 //      if (!yn)
1158 //              processor_box.deselect_all_processors();
1159 }
1160
1161 void
1162 FoldbackStrip::route_property_changed (const PropertyChange& what_changed)
1163 {
1164         if (what_changed.contains (ARDOUR::Properties::name)) {
1165                 name_changed ();
1166         }
1167 }
1168
1169 void
1170 FoldbackStrip::name_changed ()
1171 {
1172
1173         name_button.set_text_ellipsize (Pango::ELLIPSIZE_END);
1174         name_button.set_text (_route->name());
1175
1176         set_tooltip (name_button, Gtkmm2ext::markup_escape_text(_route->name()));
1177
1178 }
1179 /*
1180 void
1181 FoldbackStrip::output_button_resized (Gtk::Allocation& alloc)
1182 {
1183         //output_button.set_layout_ellipsize_width (alloc.get_width() * PANGO_SCALE);
1184 }
1185
1186 void
1187 FoldbackStrip::name_button_resized (Gtk::Allocation& alloc)
1188 {
1189         //name_button.set_layout_ellipsize_width (20);
1190 }
1191
1192 void
1193 FoldbackStrip::comment_button_resized (Gtk::Allocation& alloc)
1194 {
1195         //_comment_button.set_layout_ellipsize_width (alloc.get_width() * PANGO_SCALE);
1196 }
1197 */
1198 void
1199 FoldbackStrip::set_embedded (bool yn)
1200 {
1201         _embedded = yn;
1202 }
1203
1204 void
1205 FoldbackStrip::map_frozen ()
1206 {
1207         ENSURE_GUI_THREAD (*this, &FoldbackStrip::map_frozen)
1208
1209
1210         RouteUI::map_frozen ();
1211 }
1212
1213 void
1214 FoldbackStrip::hide_redirect_editors ()
1215 {
1216         _route->foreach_processor (sigc::mem_fun (*this, &FoldbackStrip::hide_processor_editor));
1217 }
1218
1219 void
1220 FoldbackStrip::hide_processor_editor (boost::weak_ptr<Processor> p)
1221 {
1222         boost::shared_ptr<Processor> processor (p.lock ());
1223         if (!processor) {
1224                 return;
1225         }
1226
1227 //      Gtk::Window* w = processor_box.get_processor_ui (processor);
1228         Gtk::Window* w = insert_box->get_processor_ui (processor);
1229
1230         if (w) {
1231                 w->hide ();
1232         }
1233 }
1234
1235 void
1236 FoldbackStrip::reset_strip_style ()
1237 {
1238                         if (_route->active()) {
1239                                 set_name ("AudioBusStripBase");
1240                         } else {
1241                                 set_name ("AudioBusStripBaseInactive");
1242                         }
1243
1244 }
1245
1246 void
1247 FoldbackStrip::engine_stopped ()
1248 {
1249 }
1250
1251 void
1252 FoldbackStrip::engine_running ()
1253 {
1254 }
1255
1256 void
1257 FoldbackStrip::drop_send ()
1258 {
1259         boost::shared_ptr<Send> current_send;
1260
1261         if (_current_delivery && ((current_send = boost::dynamic_pointer_cast<Send>(_current_delivery)) != 0)) {
1262                 current_send->set_metering (false);
1263         }
1264
1265         send_gone_connection.disconnect ();
1266         output_button.set_sensitive (true);
1267         set_invert_sensitive (true);
1268         mute_button->set_sensitive (true);
1269         solo_button->set_sensitive (true);
1270         _comment_button.set_sensitive (true);
1271         fb_level_control->set_sensitive (true);
1272         set_button_names (); // update solo button visual state
1273 }
1274
1275 void
1276 FoldbackStrip::set_current_delivery (boost::shared_ptr<Delivery> d)
1277 {
1278         _current_delivery = d;
1279         DeliveryChanged (_current_delivery);
1280 }
1281
1282 void
1283 FoldbackStrip::revert_to_default_display ()
1284 {
1285         drop_send ();
1286
1287         set_current_delivery (_route->main_outs ());
1288
1289         panner_ui().set_panner (_route->main_outs()->panner_shell(), _route->main_outs()->panner());
1290         update_panner_choices();
1291         panner_ui().setup_pan ();
1292         panner_ui().set_send_drawing_mode (false);
1293
1294         if (has_audio_outputs ()) {
1295                 panners.show_all ();
1296         } else {
1297                 panners.hide_all ();
1298         }
1299
1300         reset_strip_style ();
1301 }
1302
1303 void
1304 FoldbackStrip::set_button_names ()
1305 {
1306
1307         mute_button->set_text (_("Mute"));
1308
1309         if (_route && _route->solo_safe_control()->solo_safe()) {
1310                 solo_button->set_visual_state (Gtkmm2ext::VisualState (solo_button->visual_state() | Gtkmm2ext::Insensitive));
1311         } else {
1312                 solo_button->set_visual_state (Gtkmm2ext::VisualState (solo_button->visual_state() & ~Gtkmm2ext::Insensitive));
1313         }
1314         if (!Config->get_solo_control_is_listen_control()) {
1315                 solo_button->set_text (_("Solo"));
1316         } else {
1317                 switch (Config->get_listen_position()) {
1318                 case AfterFaderListen:
1319                         solo_button->set_text (_("AFL"));
1320                         break;
1321                 case PreFaderListen:
1322                         solo_button->set_text (_("PFL"));
1323                         break;
1324                 }
1325         }
1326 }
1327
1328 PluginSelector*
1329 FoldbackStrip::plugin_selector()
1330 {
1331         return _mixer.plugin_selector();
1332 }
1333
1334 string
1335 FoldbackStrip::state_id () const
1336 {
1337         return string_compose ("strip %1", _route->id().to_s());
1338 }
1339
1340 void
1341 FoldbackStrip::add_output_port (DataType t)
1342 {
1343         _route->output()->add_port ("", this, t);
1344 }
1345
1346 void
1347 FoldbackStrip::route_active_changed ()
1348 {
1349         reset_strip_style ();
1350 }
1351
1352 void
1353 FoldbackStrip::copy_processors ()
1354 {
1355 //      processor_box.processor_operation (ProcessorBox::ProcessorsCopy);
1356         insert_box->processor_operation (ProcessorBox::ProcessorsCopy);
1357 }
1358
1359 void
1360 FoldbackStrip::cut_processors ()
1361 {
1362 //      processor_box.processor_operation (ProcessorBox::ProcessorsCut);
1363         insert_box->processor_operation (ProcessorBox::ProcessorsCut);
1364 }
1365
1366 void
1367 FoldbackStrip::paste_processors ()
1368 {
1369         insert_box->processor_operation (ProcessorBox::ProcessorsPaste);
1370 }
1371
1372 void
1373 FoldbackStrip::select_all_processors ()
1374 {
1375         insert_box->processor_operation (ProcessorBox::ProcessorsSelectAll);
1376 }
1377
1378 void
1379 FoldbackStrip::deselect_all_processors ()
1380 {
1381 //      processor_box.processor_operation (ProcessorBox::ProcessorsSelectNone);
1382         insert_box->processor_operation (ProcessorBox::ProcessorsSelectNone);
1383 }
1384
1385 bool
1386 FoldbackStrip::delete_processors ()
1387 {
1388         return insert_box->processor_operation (ProcessorBox::ProcessorsDelete);
1389 }
1390
1391 void
1392 FoldbackStrip::toggle_processors ()
1393 {
1394         insert_box->processor_operation (ProcessorBox::ProcessorsToggleActive);
1395 }
1396
1397 void
1398 FoldbackStrip::ab_plugins ()
1399 {
1400         insert_box->processor_operation (ProcessorBox::ProcessorsAB);
1401 }
1402
1403 void
1404 FoldbackStrip::build_sends_menu ()
1405 {
1406         using namespace Menu_Helpers;
1407
1408         sends_menu = new Menu;
1409         sends_menu->set_name ("ArdourContextMenu");
1410         MenuList& items = sends_menu->items();
1411
1412         items.push_back (
1413                 MenuElem(_("Assign all tracks"), sigc::bind (sigc::mem_fun (*this, &RouteUI::create_sends), PreFader, false))
1414                 );
1415
1416         items.push_back (
1417                 MenuElem(_("Assign all tracks and buses (prefader)"), sigc::bind (sigc::mem_fun (*this, &RouteUI::create_sends), PreFader, true))
1418                 );
1419
1420         items.push_back (
1421                 MenuElem(_("Assign selected tracks (prefader)"), sigc::bind (sigc::mem_fun (*this, &RouteUI::create_selected_sends), PreFader, false))
1422                 );
1423
1424         items.push_back (
1425                 MenuElem(_("Assign selected tracks and buses (prefader)"), sigc::bind (sigc::mem_fun (*this, &RouteUI::create_selected_sends), PreFader, true)));
1426
1427         items.push_back (MenuElem(_("Copy track/bus gains to sends"), sigc::mem_fun (*this, &RouteUI::set_sends_gain_from_track)));
1428         items.push_back (MenuElem(_("Set sends gain to -inf"), sigc::mem_fun (*this, &RouteUI::set_sends_gain_to_zero)));
1429         items.push_back (MenuElem(_("Set sends gain to 0dB"), sigc::mem_fun (*this, &RouteUI::set_sends_gain_to_unity)));
1430
1431 }
1432
1433 Gdk::Color
1434 FoldbackStrip::color () const
1435 {
1436         return route_color ();
1437 }
1438
1439 /*bool
1440 FoldbackStrip::marked_for_display () const
1441 {
1442         return !_route->presentation_info().hidden();
1443 }*/
1444
1445 void
1446 FoldbackStrip::remove_current_fb ()
1447 {
1448         StripableList slist;
1449         boost::shared_ptr<Route> next = boost::shared_ptr<Route> ();
1450         boost::shared_ptr<Route> old_route = _route;
1451         _session->get_stripables (slist, PresentationInfo::FoldbackBus);
1452         if (slist.size ()) {
1453                 for (StripableList::iterator s = slist.begin(); s != slist.end(); ++s) {
1454                         if ((*s) != _route) {
1455                                 next = boost::dynamic_pointer_cast<Route> (*s);
1456                                 break;
1457                         }
1458                 }
1459         }
1460         if (next) {
1461                 set_route (next);
1462         }
1463         _session->remove_route (old_route);
1464
1465
1466 }