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