save/restore monitor processor state; key handling in torn off monitor section window
[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         /* if torn off, make this a normal window */
247         _tearoff->tearoff_window().set_type_hint (Gdk::WINDOW_TYPE_HINT_NORMAL);
248         _tearoff->tearoff_window().set_title (X_("Monitor"));
249         _tearoff->tearoff_window().signal_key_press_event().connect (sigc::mem_fun (*this, &MonitorSection::tearoff_key_press_event), false);
250 }
251
252 MonitorSection::~MonitorSection ()
253 {
254         delete gain_control;
255         delete dim_control;
256         delete solo_boost_control;
257         delete _tearoff;
258 }
259
260 bool
261 MonitorSection::tearoff_key_press_event (GdkEventKey* ev)
262 {
263         cerr << "T key event\n";
264         return forward_key_press (ev);
265 }
266
267 void
268 MonitorSection::populate_buttons ()
269 {
270         Glib::RefPtr<Action> act;
271         uint32_t nchans = _route->monitor_control()->output_streams().n_audio();
272         
273         main_table.resize (nchans+1, 5);
274         main_table.set_col_spacings (6);
275         main_table.set_row_spacings (6);
276         main_table.set_homogeneous (true);
277
278         Label* l1 = manage (new Label (X_("out")));
279         main_table.attach (*l1, 0, 1, 0, 1, SHRINK|FILL, SHRINK|FILL);
280         l1 = manage (new Label (X_("cut")));
281         main_table.attach (*l1, 1, 2, 0, 1, SHRINK|FILL, SHRINK|FILL);
282         l1 = manage (new Label (X_("dim")));
283         main_table.attach (*l1, 2, 3, 0, 1, SHRINK|FILL, SHRINK|FILL);
284         l1 = manage (new Label (X_("solo")));
285         main_table.attach (*l1, 3, 4, 0, 1, SHRINK|FILL, SHRINK|FILL);
286         l1 = manage (new Label (X_("inv")));
287         main_table.attach (*l1, 4, 5, 0, 1, SHRINK|FILL, SHRINK|FILL);
288
289 #if 0
290         /* the "all" buttons for cut & dim */
291         
292         Label *la = manage (new Label (X_("all")));
293         main_table.attach (*la, 0, 1, 1, 2, SHRINK|FILL, SHRINK|FILL);
294
295
296         /* cut all */
297
298         BindableToggleButton* ca = manage (new BindableToggleButton (X_("")));
299         ca->set_name (X_("MixerMuteButton"));
300         gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (ca->gobj()), false);
301         main_table.attach (*ca, 1, 2, 1, 2, SHRINK|FILL, SHRINK|FILL);
302
303         act = ActionManager::get_action (X_("Monitor"), X_("monitor-cut-all"));
304         if (act) {
305                 act->connect_proxy (*ca);
306         } 
307
308         /* dim all */
309
310         BindableToggleButton* da = manage (new BindableToggleButton (X_("")));
311         da->set_name (X_("MixerMuteButton"));
312         gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (da->gobj()), false);
313         main_table.attach (*da, 2, 3, 1, 2, SHRINK|FILL, SHRINK|FILL);
314
315         act = ActionManager::get_action (X_("Monitor"), X_("monitor-dim-all"));
316         if (act) {
317                 act->connect_proxy (*da);
318         } 
319
320         uint32_t row_offset = 2;
321 #else
322         uint32_t row_offset = 1;
323 #endif
324
325         for (uint32_t i = 0; i < nchans; ++i) {
326                 
327                 string l;
328                 char buf[64];
329
330                 if (nchans == 2) {
331                         if (i == 0) {
332                                 l = "L";
333                         } else {
334                                 l = "R";
335                         }
336                 } else {
337                         char buf[32];
338                         snprintf (buf, sizeof (buf), "%d", i+1);
339                         l = buf;
340                 }
341
342                 Label* c1 = manage (new Label (l));
343                 main_table.attach (*c1, 0, 1, i+row_offset, i+row_offset+1, SHRINK|FILL, SHRINK|FILL);
344                 
345                 /* Cut */
346
347                 BindableToggleButton* c2 = manage (new BindableToggleButton (X_("")));
348                 c2->set_name (X_("MixerMuteButton"));
349                 gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (c2->gobj()), false);
350                 main_table.attach (*c2, 1, 2, i+row_offset, i+row_offset+1, SHRINK|FILL, SHRINK|FILL);
351                 
352                 snprintf (buf, sizeof (buf), "monitor-cut-%u", i+1);
353                 act = ActionManager::get_action (X_("Monitor"), buf);
354                 if (act) {
355                         act->connect_proxy (*c2);
356                 } 
357
358                 /* Dim */
359
360                 BindableToggleButton* c3 = manage (new BindableToggleButton (X_("")));
361                 c3->set_name (X_("MixerMuteButton"));
362                 gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (c2->gobj()), false);
363                 main_table.attach (*c3, 2, 3, i+row_offset, i+row_offset+1, SHRINK|FILL, SHRINK|FILL);
364
365                 snprintf (buf, sizeof (buf), "monitor-dim-%u", i+1);
366                 act = ActionManager::get_action (X_("Monitor"), buf);
367                 if (act) {
368                         act->connect_proxy (*c3);
369                 }
370
371                 /* Solo */
372
373                 BindableToggleButton* c4 = manage (new BindableToggleButton (X_("")));
374                 c4->set_name (X_("MixerSoloButton"));
375                 gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (c2->gobj()), false);
376                 main_table.attach (*c4, 3, 4, i+row_offset, i+row_offset+1, SHRINK|FILL, SHRINK|FILL);
377
378                 snprintf (buf, sizeof (buf), "monitor-solo-%u", i+1);
379                 act = ActionManager::get_action (X_("Monitor"), buf);
380                 if (act) {
381                         act->connect_proxy (*c4);
382                 }
383
384                 /* Invert (Polarity/Phase) */
385
386                 BindableToggleButton* c5 = manage (new BindableToggleButton (X_("")));
387                 c5->set_name (X_("MixerPhaseInvertButton"));
388                 gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (c2->gobj()), false);
389                 main_table.attach (*c5, 4, 5, i+row_offset, i+row_offset+1, SHRINK|FILL, SHRINK|FILL);
390
391                 snprintf (buf, sizeof (buf), "monitor-invert-%u", i+1);
392                 act = ActionManager::get_action (X_("Monitor"), buf);
393                 if (act) {
394                         act->connect_proxy (*c5);
395                 }
396
397         }
398
399         main_table.show_all ();
400 }
401
402 void 
403 MonitorSection::set_button_names ()
404 {
405         rec_enable_button_label.set_text ("rec");
406         mute_button_label.set_text ("rec");
407         solo_button_label.set_text ("rec");
408 }
409
410 Widget&
411 MonitorSection::pack_widget () const
412 {
413         return *_tearoff;
414 }
415
416 void
417 MonitorSection::dim_all ()
418 {
419         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), "monitor-dim-all");
420         if (act) {
421                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
422                 _monitor->set_dim_all (tact->get_active());
423         }
424
425 }
426
427 void
428 MonitorSection::cut_all ()
429 {
430         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), "monitor-cut-all");
431         if (act) {
432                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
433                 _monitor->set_cut_all (tact->get_active());
434         }
435 }
436
437 void
438 MonitorSection::mono ()
439 {
440         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), "monitor-mono");
441         if (act) {
442                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
443                 _monitor->set_mono (tact->get_active());
444         }
445 }
446
447 void
448 MonitorSection::cut_channel (uint32_t chn)
449 {
450         char buf[64];
451         snprintf (buf, sizeof (buf), "monitor-cut-%u", chn);
452
453         --chn; // 0-based in backend
454
455         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), buf);
456         if (act) {
457                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
458                 _monitor->set_cut (chn, tact->get_active());
459         }
460 }
461
462 void
463 MonitorSection::dim_channel (uint32_t chn)
464 {
465         char buf[64];
466         snprintf (buf, sizeof (buf), "monitor-dim-%u", chn);
467
468         --chn; // 0-based in backend
469
470         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), buf);
471         if (act) {
472                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
473                 _monitor->set_dim (chn, tact->get_active());
474         }
475
476 }
477
478 void
479 MonitorSection::solo_channel (uint32_t chn)
480 {
481         char buf[64];
482         snprintf (buf, sizeof (buf), "monitor-solo-%u", chn);
483
484         --chn; // 0-based in backend
485
486         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), buf);
487         if (act) {
488                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
489                 _monitor->set_solo (chn, tact->get_active());
490         }
491
492 }
493
494 void
495 MonitorSection::invert_channel (uint32_t chn)
496 {
497         char buf[64];
498
499         --chn; // 0-based in backend
500
501         snprintf (buf, sizeof (buf), "monitor-invert-%u", chn);
502         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), buf);
503         if (act) {
504                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
505                 _monitor->set_polarity (chn, tact->get_active());
506         }
507
508 }
509
510 void
511 MonitorSection::register_actions ()
512 {
513         string action_name;
514         string action_descr;
515
516         monitor_actions = ActionGroup::create (X_("Monitor"));
517         ActionManager::add_action_group (monitor_actions);
518
519         ActionManager::register_toggle_action (monitor_actions, "monitor-mono", "", 
520                                                sigc::mem_fun (*this, &MonitorSection::mono));
521
522         ActionManager::register_toggle_action (monitor_actions, "monitor-cut-all", "", 
523                                                sigc::mem_fun (*this, &MonitorSection::cut_all));
524
525         ActionManager::register_toggle_action (monitor_actions, "monitor-dim-all", "", 
526                                                sigc::mem_fun (*this, &MonitorSection::dim_all));
527
528         /* note the 1-based counting for naming vs. 0-based for action */
529
530         for (uint32_t chn = 1; chn <= 16; ++chn) {
531
532                 /* for the time being, do not use the action description because it always
533                    shows up in the buttons, which is undesirable.
534                 */
535
536                 action_name = string_compose (X_("monitor-cut-%1"), chn);
537                 action_descr = string_compose (_("Cut Monitor Chn %1"), chn);
538                 ActionManager::register_toggle_action (monitor_actions, action_name.c_str(), "", 
539                                                        sigc::bind (sigc::mem_fun (*this, &MonitorSection::cut_channel), chn));
540
541                 action_name = string_compose (X_("monitor-dim-%1"), chn);
542                 action_descr = string_compose (_("Dim Monitor Chn %1"), chn+1);
543                 ActionManager::register_toggle_action (monitor_actions, action_name.c_str(), "", 
544                                                        sigc::bind (sigc::mem_fun (*this, &MonitorSection::dim_channel), chn));
545
546                 action_name = string_compose (X_("monitor-solo-%1"), chn);
547                 action_descr = string_compose (_("Solo Monitor Chn %1"), chn);
548                 ActionManager::register_toggle_action (monitor_actions, action_name.c_str(), "", 
549                                                        sigc::bind (sigc::mem_fun (*this, &MonitorSection::solo_channel), chn));
550
551                 action_name = string_compose (X_("monitor-invert-%1"), chn);
552                 action_descr = string_compose (_("Invert Monitor Chn %1"), chn);
553                 ActionManager::register_toggle_action (monitor_actions, action_name.c_str(), "", 
554                                                        sigc::bind (sigc::mem_fun (*this, &MonitorSection::invert_channel), chn));
555
556         }
557
558
559         Glib::RefPtr<ActionGroup> solo_actions = ActionGroup::create (X_("Solo"));
560         RadioAction::Group solo_group;
561
562         ActionManager::register_radio_action (solo_actions, solo_group, "solo-use-in-place", "",
563                                               sigc::mem_fun (*this, &MonitorSection::solo_use_in_place));
564         ActionManager::register_radio_action (solo_actions, solo_group, "solo-use-afl", "",
565                                               sigc::mem_fun (*this, &MonitorSection::solo_use_afl));
566         ActionManager::register_radio_action (solo_actions, solo_group, "solo-use-pfl", "",
567                                               sigc::mem_fun (*this, &MonitorSection::solo_use_pfl));
568
569         ActionManager::add_action_group (solo_actions);
570 }
571
572 void
573 MonitorSection::solo_use_in_place ()
574 {
575         /* this is driven by a toggle on a radio group, and so is invoked twice,
576            once for the item that became inactive and once for the one that became
577            active.
578         */
579
580         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Solo"), X_("solo-use-in-place"));
581
582         if (act) {
583                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (act);
584                 if (ract) {
585                         Config->set_solo_control_is_listen_control (!ract->get_active());
586                 }
587         }
588 }
589
590 void
591 MonitorSection::solo_use_afl ()
592 {
593         /* this is driven by a toggle on a radio group, and so is invoked twice,
594            once for the item that became inactive and once for the one that became
595            active.
596         */
597         
598         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Solo"), X_("solo-use-afl"));
599         if (act) {
600                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (act);
601                 if (ract) {
602                         if (ract->get_active()) {
603                                 Config->set_listen_position (AfterFaderListen);
604                                 Config->set_solo_control_is_listen_control (true);
605                         }
606                 }
607         }
608 }
609
610 void
611 MonitorSection::solo_use_pfl ()
612 {
613         /* this is driven by a toggle on a radio group, and so is invoked twice,
614            once for the item that became inactive and once for the one that became
615            active.
616         */
617
618         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Solo"), X_("solo-use-afl"));
619         if (act) {
620                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (act);
621                 if (ract) {
622                         if (ract->get_active()) {
623                                 Config->set_listen_position (PreFaderListen);
624                                 Config->set_solo_control_is_listen_control (true);
625                         }
626                 }
627         }
628 }
629
630 void
631 MonitorSection::fast_update ()
632 {
633         meter.update_meters ();
634 }
635
636 void
637 MonitorSection::setup_knob_images ()
638 {
639         try {
640                 
641                 big_knob_pixbuf = ::get_icon ("knob");
642                 
643         }  catch (...) {
644                 
645                 error << "No knob image found (or not loadable) at "
646                       << " .... "
647                       << endmsg;
648                 throw failed_constructor ();
649         }
650         
651         try {
652                 
653                 little_knob_pixbuf = ::get_icon ("littleknob");
654                 
655         }  catch (...) {
656                 
657                 error << "No knob image found (or not loadable) at "
658                       << " .... "
659                       << endmsg;
660                 throw failed_constructor ();
661         }
662 }
663
664 void
665 MonitorSection::gain_value_changed ()
666 {
667         _route->set_gain (slider_position_to_gain (gain_adjustment.get_value()), this);
668 }
669
670 void
671 MonitorSection::dim_level_changed ()
672 {
673         _monitor->set_dim_level (dim_adjustment.get_value());
674 }
675
676 void
677 MonitorSection::solo_boost_changed ()
678 {
679         _monitor->set_solo_boost_level (solo_boost_adjustment.get_value());
680 }
681
682 bool
683 MonitorSection::nonlinear_gain_printer (SpinButton* button)
684 {
685         double val = button->get_adjustment()->get_value();
686         char buf[16];
687         snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain (val)));
688         button->set_text (buf);
689         return true;
690 }
691
692 bool
693 MonitorSection::linear_gain_printer (SpinButton* button)
694 {
695         double val = button->get_adjustment()->get_value();
696         char buf[16];
697         snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (val));
698         button->set_text (buf);
699         return true;
700 }
701
702 void
703 MonitorSection::map_state ()
704 {
705         gain_control->get_adjustment()->set_value (gain_to_slider_position (_route->gain_control()->get_value()));
706         dim_control->get_adjustment()->set_value (_monitor->dim_level());
707         solo_boost_control->get_adjustment()->set_value (_monitor->solo_boost_level());
708
709         const char *action_name;
710
711         if (Config->get_solo_control_is_listen_control()) {
712                 switch (Config->get_listen_position()) {
713                 case AfterFaderListen:
714                         action_name = X_("solo-use-afl");
715                         break;
716                 case PreFaderListen:
717                         action_name = X_("solo-use-afl");
718                         break;
719                 }
720         } else {
721                 action_name = X_("solo-use-in-place");
722         }
723         
724         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Solo"), action_name);
725         if (act) {
726                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (act);
727                 if (ract) {
728                         ract->set_active (true);
729                 }
730         }
731 }
732
733 void
734 MonitorSection::solo_blink (bool onoff)
735 {
736         if (_session == 0) {
737                 return;
738         }
739
740         if (_session->soloing() || _session->listening()) {
741                 if (onoff) {
742                         rude_solo_button.set_state (STATE_ACTIVE);
743                 } else {
744                         rude_solo_button.set_state (STATE_NORMAL);
745                 }
746         } else {
747                 rude_solo_button.set_active (false);
748                 rude_solo_button.set_state (STATE_NORMAL);
749         }
750 }
751
752 bool
753 MonitorSection::cancel_solo (GdkEventButton* ev)
754 {
755         if (_session && _session->soloing()) {
756                 _session->set_solo (_session->get_routes(), false);
757         }
758
759         return true;
760 }