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