fixes for various consistency/settings issues in monitor section; minor edit to PACKA...
[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 "monitor_section.h"
17 #include "public_editor.h"
18 #include "utils.h"
19 #include "volume_controller.h"
20
21 #include "i18n.h"
22
23 using namespace ARDOUR;
24 using namespace Gtk;
25 using namespace Gtkmm2ext;
26 using namespace PBD;
27 using namespace std;
28
29 Glib::RefPtr<ActionGroup> MonitorSection::monitor_actions;
30 Glib::RefPtr<Gdk::Pixbuf> MonitorSection::big_knob_pixbuf;
31 Glib::RefPtr<Gdk::Pixbuf> MonitorSection::little_knob_pixbuf;
32
33 MonitorSection::MonitorSection (Session* s)
34         : AxisView (s)
35         , RouteUI (s)
36         , main_table (2, 3)
37         , meter (s)
38         , _tearoff (0)
39         , gain_adjustment (1.0, 0.0, 1.0, 0.01, 0.1)
40         , gain_control (0)
41         , dim_adjustment (0.2, 0.0, 1.0, 0.01, 0.1) 
42         , dim_control (0)
43         , solo_boost_adjustment (1.0, 1.0, 2.0, 0.01, 0.1) 
44         , solo_boost_control (0)
45         , solo_in_place_button (solo_model_group, _("SiP"))
46         , afl_button (solo_model_group, _("AFL"))
47         , pfl_button (solo_model_group, _("PFL"))
48         , cut_all_button (_("MUTE"))
49         , dim_all_button (_("dim"))
50         , mono_button (_("mono"))
51         , rude_solo_button (_("soloing"))
52
53 {
54         Glib::RefPtr<Action> act;
55
56         if (!monitor_actions) {
57
58                 /* do some static stuff */
59
60                 register_actions ();
61
62         }
63         
64         _route = _session->control_out ();
65
66         if (!_route) {
67                 throw failed_constructor ();
68         }
69
70         _monitor = _route->monitor_control ();
71
72         if (!_monitor) {
73                 throw failed_constructor ();
74         }
75
76         VBox* sub_knob_packer = manage (new VBox);
77         sub_knob_packer->set_spacing (12);
78
79         VBox* spin_packer;
80         Label* spin_label;
81
82         gain_control = new VolumeController (big_knob_pixbuf, &gain_adjustment, true);
83         gain_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &MonitorSection::gain_value_changed));
84         gain_control->spinner().signal_output().connect (sigc::bind (sigc::mem_fun (*this, &MonitorSection::nonlinear_gain_printer), 
85                                                                      &gain_control->spinner()));
86
87         spin_label = manage (new Label (_("Gain (dB)")));
88         spin_packer = manage (new VBox);
89         spin_packer->show ();
90         spin_packer->set_spacing (6);
91         spin_packer->pack_start (*gain_control, false, false);
92         spin_packer->pack_start (*spin_label, false, false);
93
94         sub_knob_packer->pack_start (*spin_packer, false, false);
95                 
96         dim_control = new VolumeController (little_knob_pixbuf, &dim_adjustment, true, 30, 30);
97         dim_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &MonitorSection::dim_level_changed));
98         dim_control->spinner().signal_output().connect (sigc::bind (sigc::mem_fun (*this, &MonitorSection::linear_gain_printer), 
99                                                                     &dim_control->spinner()));
100
101         HBox* dim_packer = manage (new HBox);
102         dim_packer->show ();
103
104         spin_label = manage (new Label (_("Dim Cut (dB)")));
105         spin_packer = manage (new VBox);
106         spin_packer->show ();
107         spin_packer->set_spacing (6);
108         spin_packer->pack_start (*dim_control, false, false);
109         spin_packer->pack_start (*spin_label, false, false); 
110
111         dim_packer->set_spacing (12);
112         dim_packer->pack_start (*spin_packer, false, false);
113
114         VBox* keep_dim_under_vertical_size_control = manage (new VBox);
115         keep_dim_under_vertical_size_control->pack_start (dim_all_button, true, false);
116         keep_dim_under_vertical_size_control->show ();
117         dim_all_button.set_size_request (40,40);
118         dim_all_button.show ();
119
120         dim_packer->pack_start (*keep_dim_under_vertical_size_control, false, false);
121         sub_knob_packer->pack_start (*dim_packer, false, true);
122
123         solo_boost_control = new VolumeController (little_knob_pixbuf, &solo_boost_adjustment, true, 30, 30);
124         solo_boost_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &MonitorSection::solo_boost_changed));
125         solo_boost_control->spinner().signal_output().connect (sigc::bind (sigc::mem_fun (*this, &MonitorSection::linear_gain_printer),
126                                                                            &solo_boost_control->spinner()));
127
128         HBox* solo_packer = manage (new HBox);
129         solo_packer->show ();
130
131         spin_label = manage (new Label (_("Solo Boost (dB)")));
132         spin_packer = manage (new VBox);
133         spin_packer->show ();
134         spin_packer->set_spacing (6);
135         spin_packer->pack_start (*solo_boost_control, false, false);
136         spin_packer->pack_start (*spin_label, false, false); 
137
138         VBox* keep_rude_solo_under_vertical_size_control = manage (new VBox);
139         keep_rude_solo_under_vertical_size_control->show ();
140         keep_rude_solo_under_vertical_size_control->pack_start (rude_solo_button, true, false);
141
142         solo_packer->set_spacing (12);
143         solo_packer->pack_start (*spin_packer, false, false);
144         solo_packer->pack_start (*keep_rude_solo_under_vertical_size_control, true, false);
145
146         rude_solo_button.set_name ("TransportSoloAlert");
147         rude_solo_button.show ();
148
149         ARDOUR_UI::Blink.connect (sigc::mem_fun (*this, &MonitorSection::solo_blink));
150         rude_solo_button.signal_button_press_event().connect (sigc::mem_fun(*this, &MonitorSection::cancel_solo));
151         UI::instance()->set_tip (rude_solo_button, _("When active, something is soloed.\nClick to de-solo everything"));
152
153         sub_knob_packer->pack_start (*solo_packer, false, true);
154
155         knob_packer.pack_start (*sub_knob_packer, false, true);
156
157         sub_knob_packer->show ();
158         knob_packer.show ();
159         gain_control->show_all ();
160         dim_control->show_all ();
161         solo_boost_control->show_all ();
162
163         meter.set_meter (&_route->peak_meter());
164         meter.setup_meters (300, 5);
165         
166         table_knob_packer.pack_start (main_table, true, true);
167         table_knob_packer.pack_start (knob_packer, false, false);
168
169         table_knob_packer.show ();
170
171         solo_model_box.set_spacing (6);
172         solo_model_box.pack_start (solo_in_place_button, false, false);
173         solo_model_box.pack_start (afl_button, false, false);
174         solo_model_box.pack_start (pfl_button, false, false);
175
176         solo_in_place_button.show ();
177         afl_button.show ();
178         pfl_button.show ();
179         solo_model_box.show ();
180
181         act = ActionManager::get_action (X_("Solo"), X_("solo-use-in-place"));
182         if (act) {
183                 act->connect_proxy (solo_in_place_button);
184         } 
185
186         act = ActionManager::get_action (X_("Solo"), X_("solo-use-afl"));
187         if (act) {
188                 act->connect_proxy (afl_button);
189         } 
190
191         act = ActionManager::get_action (X_("Solo"), X_("solo-use-pfl"));
192         if (act) {
193                 act->connect_proxy (pfl_button);
194         } 
195
196         upper_packer.pack_start (solo_model_box, false, false);
197
198         act = ActionManager::get_action (X_("Monitor"), X_("monitor-cut-all"));
199         if (act) {
200                 act->connect_proxy (cut_all_button);
201         } 
202
203         act = ActionManager::get_action (X_("Monitor"), X_("monitor-dim-all"));
204         if (act) {
205                 act->connect_proxy (dim_all_button);
206         } 
207
208         act = ActionManager::get_action (X_("Monitor"), X_("monitor-mono"));
209         if (act) {
210                 act->connect_proxy (mono_button);
211         } 
212
213         cut_all_button.set_size_request (50,50);
214         cut_all_button.show ();
215
216         lower_packer.set_spacing (12);
217         lower_packer.pack_start (mono_button, false, false);
218         lower_packer.pack_start (cut_all_button, false, false);
219
220         vpacker.set_border_width (12);
221         vpacker.set_spacing (12);
222         vpacker.pack_start (upper_packer, false, false);
223         vpacker.pack_start (table_knob_packer, false, false);
224         vpacker.pack_start (lower_packer, false, false);
225
226         VBox* keep_meter_under_control = manage (new VBox);
227         keep_meter_under_control->pack_start (meter, false, false);
228         keep_meter_under_control->show ();
229
230         hpacker.set_border_width (12);
231         hpacker.set_spacing (12);
232         hpacker.pack_start (*keep_meter_under_control, false, false);
233         hpacker.pack_start (vpacker, true, true);
234
235         main_table.show ();
236         hpacker.show ();
237         upper_packer.show ();
238         lower_packer.show ();
239         vpacker.show ();
240         meter.show_all ();
241
242         populate_buttons ();
243         map_state ();
244
245         _tearoff = new TearOff (hpacker);
246
247         /* if torn off, make this a normal window */
248         _tearoff->tearoff_window().set_type_hint (Gdk::WINDOW_TYPE_HINT_NORMAL);
249         _tearoff->tearoff_window().set_title (X_("Monitor"));
250         _tearoff->tearoff_window().signal_key_press_event().connect (sigc::ptr_fun (forward_key_press), false);
251 }
252
253 MonitorSection::~MonitorSection ()
254 {
255         for (ChannelButtons::iterator i = _channel_buttons.begin(); i != _channel_buttons.end(); ++i) {
256                 delete *i;
257         }
258
259         _channel_buttons.clear ();
260
261         delete gain_control;
262         delete dim_control;
263         delete solo_boost_control;
264         delete _tearoff;
265 }
266
267 MonitorSection::ChannelButtonSet::ChannelButtonSet ()
268         : cut (X_(""))
269         , dim (X_(""))
270         , solo (X_(""))
271         , invert (X_(""))
272 {
273         cut.set_name (X_("MixerMuteButton"));
274         dim.set_name (X_("MixerMuteButton"));
275         solo.set_name (X_("MixerSoloButton"));
276
277         gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (cut.gobj()), false);
278         gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (dim.gobj()), false);
279         gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (invert.gobj()), false);
280         gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (solo.gobj()), false);
281 }
282
283 void
284 MonitorSection::populate_buttons ()
285 {
286         Glib::RefPtr<Action> act;
287         uint32_t nchans = _monitor->output_streams().n_audio();
288         
289         main_table.resize (nchans+1, 5);
290         main_table.set_col_spacings (6);
291         main_table.set_row_spacings (6);
292         main_table.set_homogeneous (true);
293
294         Label* l1 = manage (new Label (X_("out")));
295         main_table.attach (*l1, 0, 1, 0, 1, SHRINK|FILL, SHRINK|FILL);
296         l1 = manage (new Label (X_("cut")));
297         main_table.attach (*l1, 1, 2, 0, 1, SHRINK|FILL, SHRINK|FILL);
298         l1 = manage (new Label (X_("dim")));
299         main_table.attach (*l1, 2, 3, 0, 1, SHRINK|FILL, SHRINK|FILL);
300         l1 = manage (new Label (X_("solo")));
301         main_table.attach (*l1, 3, 4, 0, 1, SHRINK|FILL, SHRINK|FILL);
302         l1 = manage (new Label (X_("inv")));
303         main_table.attach (*l1, 4, 5, 0, 1, SHRINK|FILL, SHRINK|FILL);
304
305         const uint32_t row_offset = 1;
306
307         for (uint32_t i = 0; i < nchans; ++i) {
308                 
309                 string l;
310                 char buf[64];
311
312                 if (nchans == 2) {
313                         if (i == 0) {
314                                 l = "L";
315                         } else {
316                                 l = "R";
317                         }
318                 } else {
319                         char buf[32];
320                         snprintf (buf, sizeof (buf), "%d", i+1);
321                         l = buf;
322                 }
323
324                 Label* label = manage (new Label (l));
325                 main_table.attach (*label, 0, 1, i+row_offset, i+row_offset+1, SHRINK|FILL, SHRINK|FILL);
326
327                 ChannelButtonSet* cbs = new ChannelButtonSet;
328
329                 _channel_buttons.push_back (cbs);
330
331                 main_table.attach (cbs->cut, 1, 2, i+row_offset, i+row_offset+1, SHRINK|FILL, SHRINK|FILL);
332                 main_table.attach (cbs->dim, 2, 3, i+row_offset, i+row_offset+1, SHRINK|FILL, SHRINK|FILL); 
333                 main_table.attach (cbs->solo, 3, 4, i+row_offset, i+row_offset+1, SHRINK|FILL, SHRINK|FILL);
334                 main_table.attach (cbs->invert, 4, 5, i+row_offset, i+row_offset+1, SHRINK|FILL, SHRINK|FILL);
335                
336                 snprintf (buf, sizeof (buf), "monitor-cut-%u", i+1);
337                 act = ActionManager::get_action (X_("Monitor"), buf);
338                 if (act) {
339                         act->connect_proxy (cbs->cut);
340                 } 
341
342                 snprintf (buf, sizeof (buf), "monitor-dim-%u", i+1);
343                 act = ActionManager::get_action (X_("Monitor"), buf);
344                 if (act) {
345                         act->connect_proxy (cbs->dim);
346                 }
347
348                 snprintf (buf, sizeof (buf), "monitor-solo-%u", i+1);
349                 act = ActionManager::get_action (X_("Monitor"), buf);
350                 if (act) {
351                         act->connect_proxy (cbs->solo);
352                 }
353
354                 snprintf (buf, sizeof (buf), "monitor-invert-%u", i+1);
355                 act = ActionManager::get_action (X_("Monitor"), buf);
356                 if (act) {
357                         act->connect_proxy (cbs->invert);
358                 }
359         }
360
361         main_table.show_all ();
362 }
363
364 void 
365 MonitorSection::set_button_names ()
366 {
367         rec_enable_button_label.set_text ("rec");
368         mute_button_label.set_text ("rec");
369         solo_button_label.set_text ("rec");
370 }
371
372 Widget&
373 MonitorSection::pack_widget () const
374 {
375         return *_tearoff;
376 }
377
378 void
379 MonitorSection::dim_all ()
380 {
381         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), "monitor-dim-all");
382         if (act) {
383                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
384                 _monitor->set_dim_all (tact->get_active());
385         }
386
387 }
388
389 void
390 MonitorSection::cut_all ()
391 {
392         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), "monitor-cut-all");
393         if (act) {
394                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
395                 _monitor->set_cut_all (tact->get_active());
396         }
397 }
398
399 void
400 MonitorSection::mono ()
401 {
402         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), "monitor-mono");
403         if (act) {
404                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
405                 _monitor->set_mono (tact->get_active());
406         }
407 }
408
409 void
410 MonitorSection::cut_channel (uint32_t chn)
411 {
412         char buf[64];
413         snprintf (buf, sizeof (buf), "monitor-cut-%u", chn);
414
415         --chn; // 0-based in backend
416
417         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), buf);
418         if (act) {
419                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
420                 _monitor->set_cut (chn, tact->get_active());
421         }
422 }
423
424 void
425 MonitorSection::dim_channel (uint32_t chn)
426 {
427         char buf[64];
428         snprintf (buf, sizeof (buf), "monitor-dim-%u", chn);
429
430         --chn; // 0-based in backend
431
432         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), buf);
433         if (act) {
434                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
435                 _monitor->set_dim (chn, tact->get_active());
436         }
437
438 }
439
440 void
441 MonitorSection::solo_channel (uint32_t chn)
442 {
443         char buf[64];
444         snprintf (buf, sizeof (buf), "monitor-solo-%u", chn);
445
446         --chn; // 0-based in backend
447
448         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), buf);
449         if (act) {
450                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
451                 _monitor->set_solo (chn, tact->get_active());
452         }
453
454 }
455
456 void
457 MonitorSection::invert_channel (uint32_t chn)
458 {
459         char buf[64];
460         snprintf (buf, sizeof (buf), "monitor-invert-%u", chn);
461
462         --chn; // 0-based in backend
463
464         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), buf);
465         if (act) {
466                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
467                 _monitor->set_polarity (chn, tact->get_active());
468         } 
469 }
470
471 void
472 MonitorSection::register_actions ()
473 {
474         string action_name;
475         string action_descr;
476
477         monitor_actions = ActionGroup::create (X_("Monitor"));
478         ActionManager::add_action_group (monitor_actions);
479
480         ActionManager::register_toggle_action (monitor_actions, "monitor-mono", "", 
481                                                sigc::mem_fun (*this, &MonitorSection::mono));
482
483         ActionManager::register_toggle_action (monitor_actions, "monitor-cut-all", "", 
484                                                sigc::mem_fun (*this, &MonitorSection::cut_all));
485
486         ActionManager::register_toggle_action (monitor_actions, "monitor-dim-all", "", 
487                                                sigc::mem_fun (*this, &MonitorSection::dim_all));
488
489         /* note the 1-based counting (for naming - backend uses 0-based) */
490
491         for (uint32_t chn = 1; chn <= 16; ++chn) {
492
493                 /* for the time being, do not use the action description because it always
494                    shows up in the buttons, which is undesirable.
495                 */
496
497                 action_name = string_compose (X_("monitor-cut-%1"), chn);
498                 action_descr = string_compose (_("Cut Monitor Chn %1"), chn);
499                 ActionManager::register_toggle_action (monitor_actions, action_name.c_str(), "", 
500                                                        sigc::bind (sigc::mem_fun (*this, &MonitorSection::cut_channel), chn));
501
502                 action_name = string_compose (X_("monitor-dim-%1"), chn);
503                 action_descr = string_compose (_("Dim Monitor Chn %1"), chn+1);
504                 ActionManager::register_toggle_action (monitor_actions, action_name.c_str(), "", 
505                                                        sigc::bind (sigc::mem_fun (*this, &MonitorSection::dim_channel), chn));
506
507                 action_name = string_compose (X_("monitor-solo-%1"), chn);
508                 action_descr = string_compose (_("Solo Monitor Chn %1"), chn);
509                 ActionManager::register_toggle_action (monitor_actions, action_name.c_str(), "", 
510                                                        sigc::bind (sigc::mem_fun (*this, &MonitorSection::solo_channel), chn));
511
512                 action_name = string_compose (X_("monitor-invert-%1"), chn);
513                 action_descr = string_compose (_("Invert Monitor Chn %1"), chn);
514                 ActionManager::register_toggle_action (monitor_actions, action_name.c_str(), "", 
515                                                        sigc::bind (sigc::mem_fun (*this, &MonitorSection::invert_channel), chn));
516
517         }
518
519
520         Glib::RefPtr<ActionGroup> solo_actions = ActionGroup::create (X_("Solo"));
521         RadioAction::Group solo_group;
522
523         ActionManager::register_radio_action (solo_actions, solo_group, "solo-use-in-place", "",
524                                               sigc::mem_fun (*this, &MonitorSection::solo_use_in_place));
525         ActionManager::register_radio_action (solo_actions, solo_group, "solo-use-afl", "",
526                                               sigc::mem_fun (*this, &MonitorSection::solo_use_afl));
527         ActionManager::register_radio_action (solo_actions, solo_group, "solo-use-pfl", "",
528                                               sigc::mem_fun (*this, &MonitorSection::solo_use_pfl));
529
530         ActionManager::add_action_group (solo_actions);
531 }
532
533 void
534 MonitorSection::solo_use_in_place ()
535 {
536         /* this is driven by a toggle on a radio group, and so is invoked twice,
537            once for the item that became inactive and once for the one that became
538            active.
539         */
540
541         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Solo"), X_("solo-use-in-place"));
542
543         if (act) {
544                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (act);
545                 if (ract) {
546                         Config->set_solo_control_is_listen_control (!ract->get_active());
547                 }
548         }
549 }
550
551 void
552 MonitorSection::solo_use_afl ()
553 {
554         /* this is driven by a toggle on a radio group, and so is invoked twice,
555            once for the item that became inactive and once for the one that became
556            active.
557         */
558         
559         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Solo"), X_("solo-use-afl"));
560         if (act) {
561                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (act);
562                 if (ract) {
563                         if (ract->get_active()) {
564                                 Config->set_listen_position (AfterFaderListen);
565                                 Config->set_solo_control_is_listen_control (true);
566                         }
567                 }
568         }
569 }
570
571 void
572 MonitorSection::solo_use_pfl ()
573 {
574         /* this is driven by a toggle on a radio group, and so is invoked twice,
575            once for the item that became inactive and once for the one that became
576            active.
577         */
578
579         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Solo"), X_("solo-use-afl"));
580         if (act) {
581                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (act);
582                 if (ract) {
583                         if (ract->get_active()) {
584                                 Config->set_listen_position (PreFaderListen);
585                                 Config->set_solo_control_is_listen_control (true);
586                         }
587                 }
588         }
589 }
590
591 void
592 MonitorSection::fast_update ()
593 {
594         meter.update_meters ();
595 }
596
597 void
598 MonitorSection::setup_knob_images ()
599 {
600         try {
601                 
602                 big_knob_pixbuf = ::get_icon ("knob");
603                 
604         }  catch (...) {
605                 
606                 error << "No knob image found (or not loadable) at "
607                       << " .... "
608                       << endmsg;
609                 throw failed_constructor ();
610         }
611         
612         try {
613                 
614                 little_knob_pixbuf = ::get_icon ("littleknob");
615                 
616         }  catch (...) {
617                 
618                 error << "No knob image found (or not loadable) at "
619                       << " .... "
620                       << endmsg;
621                 throw failed_constructor ();
622         }
623 }
624
625 void
626 MonitorSection::gain_value_changed ()
627 {
628         _route->set_gain (slider_position_to_gain (gain_adjustment.get_value()), this);
629 }
630
631 void
632 MonitorSection::dim_level_changed ()
633 {
634         _monitor->set_dim_level (dim_adjustment.get_value());
635 }
636
637 void
638 MonitorSection::solo_boost_changed ()
639 {
640         _monitor->set_solo_boost_level (solo_boost_adjustment.get_value());
641 }
642
643 bool
644 MonitorSection::nonlinear_gain_printer (SpinButton* button)
645 {
646         double val = button->get_adjustment()->get_value();
647         char buf[16];
648         snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain (val)));
649         button->set_text (buf);
650         return true;
651 }
652
653 bool
654 MonitorSection::linear_gain_printer (SpinButton* button)
655 {
656         double val = button->get_adjustment()->get_value();
657         char buf[16];
658         snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (val));
659         button->set_text (buf);
660         return true;
661 }
662
663 void
664 MonitorSection::map_state ()
665 {
666         gain_control->get_adjustment()->set_value (gain_to_slider_position (_route->gain_control()->get_value()));
667         dim_control->get_adjustment()->set_value (_monitor->dim_level());
668         solo_boost_control->get_adjustment()->set_value (_monitor->solo_boost_level());
669
670         const char *action_name;
671
672         if (Config->get_solo_control_is_listen_control()) {
673                 switch (Config->get_listen_position()) {
674                 case AfterFaderListen:
675                         action_name = X_("solo-use-afl");
676                         break;
677                 case PreFaderListen:
678                         action_name = X_("solo-use-afl");
679                         break;
680                 }
681         } else {
682                 action_name = X_("solo-use-in-place");
683         }
684         
685         Glib::RefPtr<Action> act;
686         
687         act = ActionManager::get_action (X_("Solo"), action_name);
688         if (act) {
689                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (act);
690                 if (ract) {
691                         ract->set_active (true);
692                 }
693         }
694
695         act = ActionManager::get_action (X_("Monitor"), "monitor-cut-all");
696         if (act) {
697                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
698                 if (tact) {
699                         cerr << "Set monitor cut all action to " << _monitor->cut_all () << endl;
700                         tact->set_active (_monitor->cut_all());
701                 } else {
702                         cerr << " no global cut action\n";
703                 }
704         } else {
705                 cerr << " no global cut action2\n";
706         }
707
708         act = ActionManager::get_action (X_("Monitor"), "monitor-dim-all");
709         if (act) {
710                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
711                 if (tact) {
712                         tact->set_active (_monitor->dim_all());
713                 }
714         }
715         
716         act = ActionManager::get_action (X_("Monitor"), "monitor-mono");
717         if (act) {
718                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
719                 if (tact) {
720                         tact->set_active (_monitor->mono());
721                 }
722         }
723
724         uint32_t nchans = _monitor->output_streams().n_audio();
725
726         assert (nchans == _channel_buttons.size ());
727
728         for (uint32_t n = 0; n < nchans; ++n) {
729
730                 char action_name[32];
731
732                 snprintf (action_name, sizeof (action_name), "monitor-cut-%u", n+1);
733                 act = ActionManager::get_action (X_("Monitor"), action_name);
734                 if (act) {
735                         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
736                         if (tact) {
737                                 tact->set_active (_monitor->cut (n));
738                         }
739                 }
740
741                 snprintf (action_name, sizeof (action_name), "monitor-dim-%u", n+1);
742                 act = ActionManager::get_action (X_("Monitor"), action_name);
743                 if (act) {
744                         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
745                         if (tact) {
746                                 tact->set_active (_monitor->dimmed (n));
747                         }
748                 }
749
750                 snprintf (action_name, sizeof (action_name), "monitor-solo-%u", n+1);
751                 act = ActionManager::get_action (X_("Monitor"), action_name);
752                 if (act) {
753                         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
754                         if (tact) {
755                                 tact->set_active (_monitor->soloed (n));
756                         }
757                 }
758
759                 snprintf (action_name, sizeof (action_name), "monitor-invert-%u", n+1);
760                 act = ActionManager::get_action (X_("Monitor"), action_name);
761                 if (act) {
762                         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
763                         if (tact) {
764                                 tact->set_active (_monitor->inverted (n));
765                         }
766                 }
767         }
768 }
769
770 void
771 MonitorSection::solo_blink (bool onoff)
772 {
773         if (_session == 0) {
774                 return;
775         }
776
777         if (_session->soloing() || _session->listening()) {
778                 if (onoff) {
779                         rude_solo_button.set_state (STATE_ACTIVE);
780                 } else {
781                         rude_solo_button.set_state (STATE_NORMAL);
782                 }
783         } else {
784                 rude_solo_button.set_active (false);
785                 rude_solo_button.set_state (STATE_NORMAL);
786         }
787 }
788
789 bool
790 MonitorSection::cancel_solo (GdkEventButton* ev)
791 {
792         if (_session && _session->soloing()) {
793                 _session->set_solo (_session->get_routes(), false);
794         }
795
796         return true;
797 }