remove some debug output
[ardour.git] / gtk2_ardour / monitor_section.cc
1 #include <gdkmm/pixbuf.h>
2
3 #include "pbd/compose.h"
4 #include "pbd/error.h"
5
6 #include "gtkmm2ext/bindable_button.h"
7 #include "gtkmm2ext/tearoff.h"
8 #include "gtkmm2ext/actions.h"
9
10 #include "ardour/dB.h"
11 #include "ardour/monitor_processor.h"
12 #include "ardour/route.h"
13 #include "ardour/utils.h"
14
15 #include "ardour_ui.h"
16 #include "gui_thread.h"
17 #include "monitor_section.h"
18 #include "public_editor.h"
19 #include "utils.h"
20 #include "volume_controller.h"
21
22 #include "i18n.h"
23
24 using namespace ARDOUR;
25 using namespace Gtk;
26 using namespace Gtkmm2ext;
27 using namespace PBD;
28 using namespace std;
29
30 Glib::RefPtr<ActionGroup> MonitorSection::monitor_actions;
31 Glib::RefPtr<Gdk::Pixbuf> MonitorSection::big_knob_pixbuf;
32 Glib::RefPtr<Gdk::Pixbuf> MonitorSection::little_knob_pixbuf;
33
34 MonitorSection::MonitorSection (Session* s)
35         : AxisView (s)
36         , RouteUI (s)
37         , main_table (2, 3)
38         , _tearoff (0)
39         , gain_adjustment (0.781787, 0.0, 1.0, 0.01, 0.1) // initial value is unity gain
40         , gain_control (0)
41         , dim_adjustment (0.2, 0.0, 1.0, 0.01, 0.1) // upper+lower will be reset to match model
42         , dim_control (0)
43         , solo_boost_adjustment (1.0, 1.0, 3.0, 0.01, 0.1)  // upper and lower will be reset to match model
44         , solo_boost_control (0)
45         , solo_cut_adjustment (0.0, 0.0, 1.0, 0.01, 0.1) // upper and lower will be reset to match model
46         , solo_cut_control (0)
47         , solo_in_place_button (solo_model_group, _("SiP"))
48         , afl_button (solo_model_group, _("AFL"))
49         , pfl_button (solo_model_group, _("PFL"))
50         , cut_all_button (_("MUTE"))
51         , dim_all_button (_("dim"))
52         , mono_button (_("mono"))
53         , rude_solo_button (_("soloing"))
54         , rude_audition_button (_("auditioning"))
55         , exclusive_solo_button (_("Exclusive"))
56         , solo_mute_override_button (_("Solo/Mute"))
57 {
58         Glib::RefPtr<Action> act;
59
60         if (!monitor_actions) {
61
62                 /* do some static stuff */
63
64                 register_actions ();
65
66         }
67         
68         set_session (s);
69
70         VBox* spin_packer;
71         Label* spin_label;
72
73         /* Dim */
74
75         dim_control = new VolumeController (little_knob_pixbuf, &dim_adjustment, false, 30, 30);
76
77         HBox* dim_packer = manage (new HBox);
78         dim_packer->show ();
79
80         spin_label = manage (new Label (_("Dim Cut")));
81         spin_packer = manage (new VBox);
82         spin_packer->show ();
83         spin_packer->set_spacing (6);
84         spin_packer->pack_start (*dim_control, false, false);
85         spin_packer->pack_start (*spin_label, false, false); 
86
87         dim_packer->set_spacing (12);
88         dim_packer->pack_start (*spin_packer, true, true);
89
90         /* Rude Solo */
91
92         rude_solo_button.set_name ("TransportSoloAlert");
93         rude_solo_button.show ();
94
95         rude_audition_button.set_name ("TransportAuditioningAlert");
96         rude_audition_button.show ();
97
98         ARDOUR_UI::Blink.connect (sigc::mem_fun (*this, &MonitorSection::do_blink));
99
100         rude_solo_button.signal_button_press_event().connect (sigc::mem_fun(*this, &MonitorSection::cancel_solo), false);
101         UI::instance()->set_tip (rude_solo_button, _("When active, something is soloed.\nClick to de-solo everything"));
102
103         rude_audition_button.signal_button_press_event().connect (sigc::mem_fun(*this, &MonitorSection::cancel_audition), false);
104         UI::instance()->set_tip (rude_audition_button, _("When active, auditioning is active.\nClick to stop the audition"));
105
106         solo_model_box.set_spacing (6);
107         solo_model_box.pack_start (solo_in_place_button, false, false);
108         solo_model_box.pack_start (afl_button, false, false);
109         solo_model_box.pack_start (pfl_button, false, false);
110
111         solo_in_place_button.show ();
112         afl_button.show ();
113         pfl_button.show ();
114         solo_model_box.show ();
115
116         act = ActionManager::get_action (X_("Solo"), X_("solo-use-in-place"));
117         if (act) {
118                 act->connect_proxy (solo_in_place_button);
119         } 
120
121         act = ActionManager::get_action (X_("Solo"), X_("solo-use-afl"));
122         if (act) {
123                 act->connect_proxy (afl_button);
124         } 
125
126         act = ActionManager::get_action (X_("Solo"), X_("solo-use-pfl"));
127         if (act) {
128                 act->connect_proxy (pfl_button);
129         } 
130
131         /* Solo Boost */
132
133         solo_boost_control = new VolumeController (little_knob_pixbuf, &solo_boost_adjustment, false, 30, 30);
134
135         HBox* solo_packer = manage (new HBox);
136         solo_packer->set_spacing (12);
137         solo_packer->show ();
138
139         spin_label = manage (new Label (_("Solo Boost")));
140         spin_packer = manage (new VBox);
141         spin_packer->show ();
142         spin_packer->set_spacing (6);
143         spin_packer->pack_start (*solo_boost_control, false, false);
144         spin_packer->pack_start (*spin_label, false, false); 
145
146         solo_packer->pack_start (*spin_packer, true, true);
147
148         /* Solo (SiP) cut */
149
150         solo_cut_control = new VolumeController (little_knob_pixbuf, &solo_cut_adjustment, false, 30, 30);
151
152         spin_label = manage (new Label (_("SiP Cut")));
153         spin_packer = manage (new VBox);
154         spin_packer->show ();
155         spin_packer->set_spacing (6);
156         spin_packer->pack_start (*solo_cut_control, false, false);
157         spin_packer->pack_start (*spin_label, false, false); 
158
159         solo_packer->pack_start (*spin_packer, true, true);
160
161         exclusive_solo_button.set_name (X_("MonitorOptButton"));
162         ARDOUR_UI::instance()->set_tip (&exclusive_solo_button, _("Exclusive solo means that only 1 solo is active at a time"));
163
164         act = ActionManager::get_action (X_("Monitor"), X_("toggle-exclusive-solo"));
165         if (act) {
166                 act->connect_proxy (exclusive_solo_button);
167         } 
168
169         solo_mute_override_button.set_name (X_("MonitorOptButton"));
170         ARDOUR_UI::instance()->set_tip (&solo_mute_override_button, _("If enabled, solo will override mute\n(a soloed & muted track or bus will be audible)"));
171         
172         act = ActionManager::get_action (X_("Monitor"), X_("toggle-mute-overrides-solo"));
173         if (act) {
174                 act->connect_proxy (solo_mute_override_button);
175         } 
176
177         HBox* solo_opt_box = manage (new HBox);
178         solo_opt_box->set_spacing (12);
179         solo_opt_box->set_homogeneous (true);
180         solo_opt_box->pack_start (exclusive_solo_button);
181         solo_opt_box->pack_start (solo_mute_override_button);
182         solo_opt_box->show ();
183         
184         upper_packer.set_spacing (12);
185         upper_packer.pack_start (rude_solo_button, false, false);
186         upper_packer.pack_start (rude_audition_button, false, false);
187         upper_packer.pack_start (solo_model_box, false, false);
188         upper_packer.pack_start (*solo_opt_box, false, false);
189         upper_packer.pack_start (*solo_packer, false, false);
190
191         act = ActionManager::get_action (X_("Monitor"), X_("monitor-cut-all"));
192         if (act) {
193                 act->connect_proxy (cut_all_button);
194         } 
195
196         act = ActionManager::get_action (X_("Monitor"), X_("monitor-dim-all"));
197         if (act) {
198                 act->connect_proxy (dim_all_button);
199         } 
200
201         act = ActionManager::get_action (X_("Monitor"), X_("monitor-mono"));
202         if (act) {
203                 act->connect_proxy (mono_button);
204         } 
205
206         cut_all_button.set_name (X_("MonitorMuteButton"));
207         cut_all_button.unset_flags (Gtk::CAN_FOCUS);
208         cut_all_button.set_size_request (50,50);
209         cut_all_button.show ();
210
211         HBox* bbox = manage (new HBox);
212
213         bbox->set_spacing (12);
214         bbox->pack_start (mono_button, true, true);
215         bbox->pack_start (dim_all_button, true, true);
216
217         dim_all_button.set_name (X_("MonitorDimButton"));
218         dim_all_button.unset_flags (Gtk::CAN_FOCUS);
219         mono_button.set_name (X_("MonitorMonoButton"));
220         mono_button.unset_flags (Gtk::CAN_FOCUS);
221
222         lower_packer.set_spacing (12);
223         lower_packer.pack_start (*bbox, false, false);
224         lower_packer.pack_start (cut_all_button, false, false);
225
226         /* Gain */
227
228         gain_control = new VolumeController (big_knob_pixbuf, &gain_adjustment, false, 80, 80);
229
230         spin_label = manage (new Label (_("Gain")));
231         spin_packer = manage (new VBox);
232         spin_packer->show ();
233         spin_packer->set_spacing (6);
234         spin_packer->pack_start (*gain_control, false, false);
235         spin_packer->pack_start (*spin_label, false, false);
236
237         lower_packer.pack_start (*spin_packer, true, true);
238
239         vpacker.set_border_width (12);
240         vpacker.set_spacing (12);
241         vpacker.pack_start (upper_packer, false, false);
242         vpacker.pack_start (*dim_packer, false, false);
243         vpacker.pack_start (main_table, false, false);
244         vpacker.pack_start (lower_packer, false, false);
245
246         hpacker.set_border_width (12);
247         hpacker.set_spacing (12);
248         hpacker.pack_start (vpacker, true, true);
249
250         gain_control->show_all ();
251         dim_control->show_all ();
252         solo_boost_control->show_all ();
253
254         main_table.show ();
255         hpacker.show ();
256         upper_packer.show ();
257         lower_packer.show ();
258         vpacker.show ();
259
260         populate_buttons ();
261         map_state ();
262         assign_controllables ();
263
264         _tearoff = new TearOff (hpacker);
265
266         /* if torn off, make this a normal window */
267         _tearoff->tearoff_window().set_type_hint (Gdk::WINDOW_TYPE_HINT_NORMAL);
268         _tearoff->tearoff_window().set_title (X_("Monitor"));
269         _tearoff->tearoff_window().signal_key_press_event().connect (sigc::ptr_fun (forward_key_press), false);
270
271         /* catch changes that affect us */
272
273         Config->ParameterChanged.connect (config_connection, invalidator (*this), ui_bind (&MonitorSection::parameter_changed, this, _1), gui_context());
274 }
275
276 MonitorSection::~MonitorSection ()
277 {
278         for (ChannelButtons::iterator i = _channel_buttons.begin(); i != _channel_buttons.end(); ++i) {
279                 delete *i;
280         }
281
282         _channel_buttons.clear ();
283
284         delete gain_control;
285         delete dim_control;
286         delete solo_boost_control;
287         delete _tearoff;
288 }
289
290 void
291 MonitorSection::set_session (Session* s)
292 {
293         AxisView::set_session (s);
294
295         if (_session) {
296
297                 _route = _session->monitor_out ();
298
299                 if (_route) {
300                         /* session with control outs */
301                         _monitor = _route->monitor_control ();
302                         assign_controllables ();
303                 } else { 
304                         /* session with no control outs */
305                         _monitor.reset ();
306                         _route.reset ();
307                 }
308                 
309                         
310         } else {
311                 /* no session */
312                 _monitor.reset ();
313                 _route.reset ();
314                 control_connections.drop_connections ();
315         }
316
317         /* both might be null */
318 }
319
320 MonitorSection::ChannelButtonSet::ChannelButtonSet ()
321         : cut (X_(""))
322         , dim (X_(""))
323         , solo (X_(""))
324         , invert (X_(""))
325 {
326         cut.set_name (X_("MonitorMuteButton"));
327         dim.set_name (X_("MonitorDimButton"));
328         solo.set_name (X_("MixerSoloButton"));
329         invert.set_name (X_("MonitorInvertButton"));
330
331         gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (cut.gobj()), false);
332         gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (dim.gobj()), false);
333         gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (invert.gobj()), false);
334         gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (solo.gobj()), false);
335
336         cut.unset_flags (Gtk::CAN_FOCUS);
337         dim.unset_flags (Gtk::CAN_FOCUS);
338         solo.unset_flags (Gtk::CAN_FOCUS);
339         invert.unset_flags (Gtk::CAN_FOCUS);
340 }
341
342 void
343 MonitorSection::populate_buttons ()
344 {
345         if (!_monitor) {
346                 return;
347         }
348
349         Glib::RefPtr<Action> act;
350         uint32_t nchans = _monitor->output_streams().n_audio();
351         
352         main_table.resize (nchans+1, 5);
353         main_table.set_col_spacings (6);
354         main_table.set_row_spacings (6);
355         main_table.set_homogeneous (true);
356
357         Label* l1 = manage (new Label (X_("out")));
358         main_table.attach (*l1, 0, 1, 0, 1, SHRINK|FILL, SHRINK|FILL);
359         l1 = manage (new Label (X_("cut")));
360         main_table.attach (*l1, 1, 2, 0, 1, SHRINK|FILL, SHRINK|FILL);
361         l1 = manage (new Label (X_("dim")));
362         main_table.attach (*l1, 2, 3, 0, 1, SHRINK|FILL, SHRINK|FILL);
363         l1 = manage (new Label (X_("solo")));
364         main_table.attach (*l1, 3, 4, 0, 1, SHRINK|FILL, SHRINK|FILL);
365         l1 = manage (new Label (X_("inv")));
366         main_table.attach (*l1, 4, 5, 0, 1, SHRINK|FILL, SHRINK|FILL);
367
368         const uint32_t row_offset = 1;
369
370         for (uint32_t i = 0; i < nchans; ++i) {
371                 
372                 string l;
373                 char buf[64];
374
375                 if (nchans == 2) {
376                         if (i == 0) {
377                                 l = "L";
378                         } else {
379                                 l = "R";
380                         }
381                 } else {
382                         char buf[32];
383                         snprintf (buf, sizeof (buf), "%d", i+1);
384                         l = buf;
385                 }
386
387                 Label* label = manage (new Label (l));
388                 main_table.attach (*label, 0, 1, i+row_offset, i+row_offset+1, SHRINK|FILL, SHRINK|FILL);
389
390                 ChannelButtonSet* cbs = new ChannelButtonSet;
391
392                 _channel_buttons.push_back (cbs);
393
394                 main_table.attach (cbs->cut, 1, 2, i+row_offset, i+row_offset+1, SHRINK|FILL, SHRINK|FILL);
395                 main_table.attach (cbs->dim, 2, 3, i+row_offset, i+row_offset+1, SHRINK|FILL, SHRINK|FILL); 
396                 main_table.attach (cbs->solo, 3, 4, i+row_offset, i+row_offset+1, SHRINK|FILL, SHRINK|FILL);
397                 main_table.attach (cbs->invert, 4, 5, i+row_offset, i+row_offset+1, SHRINK|FILL, SHRINK|FILL);
398                
399                 snprintf (buf, sizeof (buf), "monitor-cut-%u", i+1);
400                 act = ActionManager::get_action (X_("Monitor"), buf);
401                 if (act) {
402                         act->connect_proxy (cbs->cut);
403                 } 
404
405                 snprintf (buf, sizeof (buf), "monitor-dim-%u", i+1);
406                 act = ActionManager::get_action (X_("Monitor"), buf);
407                 if (act) {
408                         act->connect_proxy (cbs->dim);
409                 }
410
411                 snprintf (buf, sizeof (buf), "monitor-solo-%u", i+1);
412                 act = ActionManager::get_action (X_("Monitor"), buf);
413                 if (act) {
414                         act->connect_proxy (cbs->solo);
415                 }
416
417                 snprintf (buf, sizeof (buf), "monitor-invert-%u", i+1);
418                 act = ActionManager::get_action (X_("Monitor"), buf);
419                 if (act) {
420                         act->connect_proxy (cbs->invert);
421                 }
422         }
423
424         main_table.show_all ();
425 }
426
427 void 
428 MonitorSection::set_button_names ()
429 {
430         rec_enable_button_label.set_text ("rec");
431         mute_button_label.set_text ("rec");
432         solo_button_label.set_text ("rec");
433 }
434
435 void
436 MonitorSection::toggle_exclusive_solo ()
437 {
438         if (!_monitor) {
439                 return;
440         }
441
442         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), "toggle-exclusive-solo");
443         if (act) {
444                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
445                 Config->set_exclusive_solo (tact->get_active());
446         }
447
448 }
449
450
451 void
452 MonitorSection::toggle_mute_overrides_solo ()
453 {
454         if (!_monitor) {
455                 return;
456         }
457
458         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), "toggle-mute-overrides-solo");
459         if (act) {
460                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
461                 Config->set_solo_mute_override (tact->get_active());
462         }
463 }
464
465 void
466 MonitorSection::dim_all ()
467 {
468         if (!_monitor) {
469                 return;
470         }
471
472         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), "monitor-dim-all");
473         if (act) {
474                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
475                 _monitor->set_dim_all (tact->get_active());
476         }
477
478 }
479
480 void
481 MonitorSection::cut_all ()
482 {
483         if (!_monitor) {
484                 return;
485         }
486
487         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), "monitor-cut-all");
488         if (act) {
489                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
490                 _monitor->set_cut_all (tact->get_active());
491         }
492 }
493
494 void
495 MonitorSection::mono ()
496 {
497         if (!_monitor) {
498                 return;
499         }
500
501         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), "monitor-mono");
502         if (act) {
503                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
504                 _monitor->set_mono (tact->get_active());
505         }
506 }
507
508 void
509 MonitorSection::cut_channel (uint32_t chn)
510 {
511         if (!_monitor) {
512                 return;
513         }
514
515         char buf[64];
516         snprintf (buf, sizeof (buf), "monitor-cut-%u", chn);
517
518         --chn; // 0-based in backend
519
520         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), buf);
521         if (act) {
522                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
523                 _monitor->set_cut (chn, tact->get_active());
524         }
525 }
526
527 void
528 MonitorSection::dim_channel (uint32_t chn)
529 {
530         if (!_monitor) {
531                 return;
532         }
533
534         char buf[64];
535         snprintf (buf, sizeof (buf), "monitor-dim-%u", chn);
536
537         --chn; // 0-based in backend
538
539         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), buf);
540         if (act) {
541                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
542                 _monitor->set_dim (chn, tact->get_active());
543         }
544
545 }
546
547 void
548 MonitorSection::solo_channel (uint32_t chn)
549 {
550         if (!_monitor) {
551                 return;
552         }
553
554         char buf[64];
555         snprintf (buf, sizeof (buf), "monitor-solo-%u", chn);
556
557         --chn; // 0-based in backend
558
559         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), buf);
560         if (act) {
561                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
562                 _monitor->set_solo (chn, tact->get_active());
563         }
564
565 }
566
567 void
568 MonitorSection::invert_channel (uint32_t chn)
569 {
570         if (!_monitor) {
571                 return;
572         }
573
574         char buf[64];
575         snprintf (buf, sizeof (buf), "monitor-invert-%u", chn);
576
577         --chn; // 0-based in backend
578
579         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), buf);
580         if (act) {
581                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
582                 _monitor->set_polarity (chn, tact->get_active());
583         } 
584 }
585
586 void
587 MonitorSection::register_actions ()
588 {
589         string action_name;
590         string action_descr;
591         Glib::RefPtr<Action> act;
592
593         monitor_actions = ActionGroup::create (X_("Monitor"));
594         ActionManager::add_action_group (monitor_actions);
595
596         ActionManager::register_toggle_action (monitor_actions, "monitor-mono", "", 
597                                                sigc::mem_fun (*this, &MonitorSection::mono));
598
599         ActionManager::register_toggle_action (monitor_actions, "monitor-cut-all", "", 
600                                                sigc::mem_fun (*this, &MonitorSection::cut_all));
601
602         ActionManager::register_toggle_action (monitor_actions, "monitor-dim-all", "", 
603                                                sigc::mem_fun (*this, &MonitorSection::dim_all));
604
605         act = ActionManager::register_toggle_action (monitor_actions, "toggle-exclusive-solo", "", 
606                                                sigc::mem_fun (*this, &MonitorSection::toggle_exclusive_solo));
607
608         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
609         tact->set_active (Config->get_exclusive_solo());
610
611         act = ActionManager::register_toggle_action (monitor_actions, "toggle-mute-overrides-solo", "", 
612                                                      sigc::mem_fun (*this, &MonitorSection::toggle_mute_overrides_solo));
613         
614         tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
615         tact->set_active (Config->get_solo_mute_override());
616
617         /* map from RC config */
618
619
620
621         /* note the 1-based counting (for naming - backend uses 0-based) */
622
623         for (uint32_t chn = 1; chn <= 16; ++chn) {
624
625                 /* for the time being, do not use the action description because it always
626                    shows up in the buttons, which is undesirable.
627                 */
628
629                 action_name = string_compose (X_("monitor-cut-%1"), chn);
630                 action_descr = string_compose (_("Cut Monitor Chn %1"), chn);
631                 ActionManager::register_toggle_action (monitor_actions, action_name.c_str(), "", 
632                                                        sigc::bind (sigc::mem_fun (*this, &MonitorSection::cut_channel), chn));
633
634                 action_name = string_compose (X_("monitor-dim-%1"), chn);
635                 action_descr = string_compose (_("Dim Monitor Chn %1"), chn+1);
636                 ActionManager::register_toggle_action (monitor_actions, action_name.c_str(), "", 
637                                                        sigc::bind (sigc::mem_fun (*this, &MonitorSection::dim_channel), chn));
638
639                 action_name = string_compose (X_("monitor-solo-%1"), chn);
640                 action_descr = string_compose (_("Solo Monitor Chn %1"), chn);
641                 ActionManager::register_toggle_action (monitor_actions, action_name.c_str(), "", 
642                                                        sigc::bind (sigc::mem_fun (*this, &MonitorSection::solo_channel), chn));
643
644                 action_name = string_compose (X_("monitor-invert-%1"), chn);
645                 action_descr = string_compose (_("Invert Monitor Chn %1"), chn);
646                 ActionManager::register_toggle_action (monitor_actions, action_name.c_str(), "", 
647                                                        sigc::bind (sigc::mem_fun (*this, &MonitorSection::invert_channel), chn));
648
649         }
650
651
652         Glib::RefPtr<ActionGroup> solo_actions = ActionGroup::create (X_("Solo"));
653         RadioAction::Group solo_group;
654
655         ActionManager::register_radio_action (solo_actions, solo_group, "solo-use-in-place", "",
656                                               sigc::mem_fun (*this, &MonitorSection::solo_use_in_place));
657         ActionManager::register_radio_action (solo_actions, solo_group, "solo-use-afl", "",
658                                               sigc::mem_fun (*this, &MonitorSection::solo_use_afl));
659         ActionManager::register_radio_action (solo_actions, solo_group, "solo-use-pfl", "",
660                                               sigc::mem_fun (*this, &MonitorSection::solo_use_pfl));
661
662         ActionManager::add_action_group (solo_actions);
663 }
664
665 void
666 MonitorSection::solo_use_in_place ()
667 {
668         /* this is driven by a toggle on a radio group, and so is invoked twice,
669            once for the item that became inactive and once for the one that became
670            active.
671         */
672
673         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Solo"), X_("solo-use-in-place"));
674
675         if (act) {
676                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (act);
677                 if (ract) {
678                         Config->set_solo_control_is_listen_control (!ract->get_active());
679                 }
680         }
681 }
682
683 void
684 MonitorSection::solo_use_afl ()
685 {
686         /* this is driven by a toggle on a radio group, and so is invoked twice,
687            once for the item that became inactive and once for the one that became
688            active.
689         */
690         
691         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Solo"), X_("solo-use-afl"));
692         if (act) {
693                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (act);
694                 if (ract) {
695                         if (ract->get_active()) {
696                                 Config->set_listen_position (AfterFaderListen);
697                                 Config->set_solo_control_is_listen_control (true);
698                         }
699                 }
700         }
701 }
702
703 void
704 MonitorSection::solo_use_pfl ()
705 {
706         /* this is driven by a toggle on a radio group, and so is invoked twice,
707            once for the item that became inactive and once for the one that became
708            active.
709         */
710
711         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Solo"), X_("solo-use-afl"));
712         if (act) {
713                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (act);
714                 if (ract) {
715                         if (ract->get_active()) {
716                                 Config->set_listen_position (PreFaderListen);
717                                 Config->set_solo_control_is_listen_control (true);
718                         }
719                 }
720         }
721 }
722
723 void
724 MonitorSection::setup_knob_images ()
725 {
726         try {
727                 
728                 big_knob_pixbuf = ::get_icon ("bigknob");
729                 
730         }  catch (...) {
731                 
732                 error << "No knob image found (or not loadable) at "
733                       << " .... "
734                       << endmsg;
735                 throw failed_constructor ();
736         }
737         
738         try {
739                 
740                 little_knob_pixbuf = ::get_icon ("littleknob");
741                 
742         }  catch (...) {
743                 
744                 error << "No knob image found (or not loadable) at "
745                       << " .... "
746                       << endmsg;
747                 throw failed_constructor ();
748         }
749 }
750
751 bool
752 MonitorSection::nonlinear_gain_printer (SpinButton* button)
753 {
754         double val = button->get_adjustment()->get_value();
755         char buf[16];
756         snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain (val)));
757         button->set_text (buf);
758         return true;
759 }
760
761 bool
762 MonitorSection::linear_gain_printer (SpinButton* button)
763 {
764         double val = button->get_adjustment()->get_value();
765         char buf[16];
766         snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (val));
767         button->set_text (buf);
768         return true;
769 }
770
771 void
772 MonitorSection::update_solo_model ()
773 {
774         const char* action_name;
775         Glib::RefPtr<Action> act;
776
777         if (Config->get_solo_control_is_listen_control()) {
778                 switch (Config->get_listen_position()) {
779                 case AfterFaderListen:
780                         action_name = X_("solo-use-afl");
781                         break;
782                 case PreFaderListen:
783                         action_name = X_("solo-use-pfl");
784                         break;
785                 }
786         } else {
787                 action_name = X_("solo-use-in-place");
788         }
789
790         act = ActionManager::get_action (X_("Solo"), action_name);
791         if (act) {
792                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (act);
793                 if (ract) {
794                         ract->set_active (true);
795                 }
796         }
797 }
798
799 void
800 MonitorSection::map_state ()
801 {
802         if (!_route || !_monitor) {
803                 return;
804         }
805
806         gain_control->get_adjustment()->set_value (gain_to_slider_position (_route->gain_control()->get_value()));
807         dim_control->get_adjustment()->set_value (_monitor->dim_level());
808         solo_boost_control->get_adjustment()->set_value (_monitor->solo_boost_level());
809
810         Glib::RefPtr<Action> act;
811
812         update_solo_model ();
813         
814         act = ActionManager::get_action (X_("Monitor"), "monitor-cut-all");
815         if (act) {
816                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
817                 if (tact) {
818                         tact->set_active (_monitor->cut_all());
819                 }
820         }
821
822         act = ActionManager::get_action (X_("Monitor"), "monitor-dim-all");
823         if (act) {
824                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
825                 if (tact) {
826                         tact->set_active (_monitor->dim_all());
827                 }
828         }
829         
830         act = ActionManager::get_action (X_("Monitor"), "monitor-mono");
831         if (act) {
832                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
833                 if (tact) {
834                         tact->set_active (_monitor->mono());
835                 }
836         }
837
838         uint32_t nchans = _monitor->output_streams().n_audio();
839
840         assert (nchans == _channel_buttons.size ());
841
842         for (uint32_t n = 0; n < nchans; ++n) {
843
844                 char action_name[32];
845
846                 snprintf (action_name, sizeof (action_name), "monitor-cut-%u", n+1);
847                 act = ActionManager::get_action (X_("Monitor"), action_name);
848                 if (act) {
849                         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
850                         if (tact) {
851                                 tact->set_active (_monitor->cut (n));
852                         }
853                 }
854
855                 snprintf (action_name, sizeof (action_name), "monitor-dim-%u", n+1);
856                 act = ActionManager::get_action (X_("Monitor"), action_name);
857                 if (act) {
858                         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
859                         if (tact) {
860                                 tact->set_active (_monitor->dimmed (n));
861                         }
862                 }
863
864                 snprintf (action_name, sizeof (action_name), "monitor-solo-%u", n+1);
865                 act = ActionManager::get_action (X_("Monitor"), action_name);
866                 if (act) {
867                         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
868                         if (tact) {
869                                 tact->set_active (_monitor->soloed (n));
870                         }
871                 }
872
873                 snprintf (action_name, sizeof (action_name), "monitor-invert-%u", n+1);
874                 act = ActionManager::get_action (X_("Monitor"), action_name);
875                 if (act) {
876                         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
877                         if (tact) {
878                                 tact->set_active (_monitor->inverted (n));
879                         }
880                 }
881         }
882 }
883
884 void
885 MonitorSection::do_blink (bool onoff)
886 {
887         solo_blink (onoff);
888         audition_blink (onoff);
889 }
890
891 void
892 MonitorSection::audition_blink (bool onoff)
893 {
894         if (_session == 0) {
895                 return;
896         }
897
898         if (_session->is_auditioning()) {
899                 if (onoff) {
900                         rude_audition_button.set_state (STATE_ACTIVE);
901                 } else {
902                         rude_audition_button.set_state (STATE_NORMAL);
903                 }
904         } else {
905                 rude_audition_button.set_active (false);
906                 rude_audition_button.set_state (STATE_NORMAL);
907         }
908 }
909
910 void
911 MonitorSection::solo_blink (bool onoff)
912 {
913         if (_session == 0) {
914                 return;
915         }
916
917         if (_session->soloing() || _session->listening()) {
918                 if (onoff) {
919                         rude_solo_button.set_state (STATE_ACTIVE);
920                 } else {
921                         rude_solo_button.set_state (STATE_NORMAL);
922                 }
923         } else {
924                 // rude_solo_button.set_active (false);
925                 rude_solo_button.set_state (STATE_NORMAL);
926         }
927 }
928
929 bool
930 MonitorSection::cancel_solo (GdkEventButton* ev)
931 {
932         if (_session) {
933                 if (_session->soloing()) {
934                         _session->set_solo (_session->get_routes(), false);
935                 } else if (_session->listening()) {
936                         _session->set_listen (_session->get_routes(), false);
937                 }
938         }
939
940         return true;
941 }
942
943 bool
944 MonitorSection::cancel_audition (GdkEventButton* ev)
945 {
946         if (_session) {
947                 _session->cancel_audition();
948         }
949         return true;
950 }
951
952 void
953 MonitorSection::solo_cut_changed ()
954 {
955         Config->set_solo_mute_gain (slider_position_to_gain (solo_cut_adjustment.get_value()));
956 }
957
958 void
959 MonitorSection::parameter_changed (std::string name)
960 {
961         if (name == "solo-control-is-listen-control" ||
962             name == "listen-position") {
963                 update_solo_model ();
964         } else if (name == "solo-mute-gain") {
965                 solo_cut_adjustment.set_value (gain_to_slider_position (Config->get_solo_mute_gain()));
966         }
967 }
968
969 void
970 MonitorSection::assign_controllables ()
971 {
972         boost::shared_ptr<Controllable> none;
973
974         if (!gain_control) {
975                 /* too early - GUI controls not set up yet */
976                 return;
977         }
978
979         if (_route) {
980                 gain_control->set_controllable (_route->gain_control());
981                 control_link (control_connections, _route->gain_control(), gain_adjustment);
982         } else {
983                 gain_control->set_controllable (none);
984         }
985
986         if (_monitor) {
987
988                 cut_all_button.set_controllable (_monitor->cut_control());
989                 cut_all_button.watch ();
990                 dim_all_button.set_controllable (_monitor->dim_control());
991                 dim_all_button.watch ();
992                 mono_button.set_controllable (_monitor->mono_control());
993                 mono_button.watch ();
994
995                 boost::shared_ptr<Controllable> c (_monitor->dim_level_control ());
996
997                 dim_control->set_controllable (c);
998                 dim_adjustment.set_lower (c->lower());
999                 dim_adjustment.set_upper (c->upper());
1000                 control_link (control_connections, c, dim_adjustment);
1001                 
1002                 c = _monitor->solo_boost_control ();
1003                 solo_boost_control->set_controllable (c);
1004                 solo_boost_adjustment.set_lower (c->lower());
1005                 solo_boost_adjustment.set_upper (c->upper());
1006                 control_link (control_connections, c, solo_boost_adjustment);
1007
1008         } else {
1009
1010                 cut_all_button.set_controllable (none);
1011                 dim_all_button.set_controllable (none);
1012                 mono_button.set_controllable (none);
1013
1014                 dim_control->set_controllable (none);
1015                 solo_boost_control->set_controllable (none);
1016         }
1017 }