1 #include <gdkmm/pixbuf.h>
3 #include "pbd/compose.h"
6 #include "gtkmm2ext/bindable_button.h"
7 #include "gtkmm2ext/tearoff.h"
8 #include "gtkmm2ext/actions.h"
10 #include "ardour/dB.h"
11 #include "ardour/monitor_processor.h"
12 #include "ardour/route.h"
13 #include "ardour/utils.h"
15 #include "ardour_ui.h"
16 #include "monitor_section.h"
17 #include "public_editor.h"
19 #include "volume_controller.h"
23 using namespace ARDOUR;
25 using namespace Gtkmm2ext;
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;
33 MonitorSection::MonitorSection (Session* s)
39 , gain_adjustment (1.0, 0.0, 1.0, 0.01, 0.1)
41 , dim_adjustment (0.2, 0.0, 1.0, 0.01, 0.1)
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"))
54 Glib::RefPtr<Action> act;
56 if (!monitor_actions) {
58 /* do some static stuff */
64 _route = _session->control_out ();
67 throw failed_constructor ();
70 _monitor = _route->monitor_control ();
73 throw failed_constructor ();
76 VBox* sub_knob_packer = manage (new VBox);
77 sub_knob_packer->set_spacing (12);
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()));
87 spin_label = manage (new Label (_("Gain (dB)")));
88 spin_packer = manage (new VBox);
90 spin_packer->set_spacing (6);
91 spin_packer->pack_start (*gain_control, false, false);
92 spin_packer->pack_start (*spin_label, false, false);
94 sub_knob_packer->pack_start (*spin_packer, false, false);
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()));
101 HBox* dim_packer = manage (new HBox);
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);
111 dim_packer->set_spacing (12);
112 dim_packer->pack_start (*spin_packer, false, false);
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 ();
120 dim_packer->pack_start (*keep_dim_under_vertical_size_control, false, false);
121 sub_knob_packer->pack_start (*dim_packer, false, true);
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()));
128 HBox* solo_packer = manage (new HBox);
129 solo_packer->show ();
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);
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);
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);
146 rude_solo_button.set_name ("TransportSoloAlert");
147 rude_solo_button.show ();
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"));
153 sub_knob_packer->pack_start (*solo_packer, false, true);
155 knob_packer.pack_start (*sub_knob_packer, false, true);
157 sub_knob_packer->show ();
159 gain_control->show_all ();
160 dim_control->show_all ();
161 solo_boost_control->show_all ();
163 meter.set_meter (&_route->peak_meter());
164 meter.setup_meters (300, 5);
166 table_knob_packer.pack_start (main_table, true, true);
167 table_knob_packer.pack_start (knob_packer, false, false);
169 table_knob_packer.show ();
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);
176 solo_in_place_button.show ();
179 solo_model_box.show ();
181 act = ActionManager::get_action (X_("Solo"), X_("solo-use-in-place"));
183 act->connect_proxy (solo_in_place_button);
186 act = ActionManager::get_action (X_("Solo"), X_("solo-use-afl"));
188 act->connect_proxy (afl_button);
191 act = ActionManager::get_action (X_("Solo"), X_("solo-use-pfl"));
193 act->connect_proxy (pfl_button);
196 upper_packer.pack_start (solo_model_box, false, false);
198 act = ActionManager::get_action (X_("Monitor"), X_("monitor-cut-all"));
200 act->connect_proxy (cut_all_button);
203 act = ActionManager::get_action (X_("Monitor"), X_("monitor-dim-all"));
205 act->connect_proxy (dim_all_button);
208 act = ActionManager::get_action (X_("Monitor"), X_("monitor-mono"));
210 act->connect_proxy (mono_button);
213 cut_all_button.set_size_request (50,50);
214 cut_all_button.show ();
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);
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);
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 ();
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);
237 upper_packer.show ();
238 lower_packer.show ();
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);
252 MonitorSection::~MonitorSection ()
256 delete solo_boost_control;
261 MonitorSection::tearoff_key_press_event (GdkEventKey* ev)
263 cerr << "T key event\n";
264 return forward_key_press (ev);
268 MonitorSection::populate_buttons ()
270 Glib::RefPtr<Action> act;
271 uint32_t nchans = _route->monitor_control()->output_streams().n_audio();
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);
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);
290 /* the "all" buttons for cut & dim */
292 Label *la = manage (new Label (X_("all")));
293 main_table.attach (*la, 0, 1, 1, 2, SHRINK|FILL, SHRINK|FILL);
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);
303 act = ActionManager::get_action (X_("Monitor"), X_("monitor-cut-all"));
305 act->connect_proxy (*ca);
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);
315 act = ActionManager::get_action (X_("Monitor"), X_("monitor-dim-all"));
317 act->connect_proxy (*da);
320 uint32_t row_offset = 2;
322 uint32_t row_offset = 1;
325 for (uint32_t i = 0; i < nchans; ++i) {
338 snprintf (buf, sizeof (buf), "%d", i+1);
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);
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);
352 snprintf (buf, sizeof (buf), "monitor-cut-%u", i+1);
353 act = ActionManager::get_action (X_("Monitor"), buf);
355 act->connect_proxy (*c2);
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);
365 snprintf (buf, sizeof (buf), "monitor-dim-%u", i+1);
366 act = ActionManager::get_action (X_("Monitor"), buf);
368 act->connect_proxy (*c3);
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);
378 snprintf (buf, sizeof (buf), "monitor-solo-%u", i+1);
379 act = ActionManager::get_action (X_("Monitor"), buf);
381 act->connect_proxy (*c4);
384 /* Invert (Polarity/Phase) */
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);
391 snprintf (buf, sizeof (buf), "monitor-invert-%u", i+1);
392 act = ActionManager::get_action (X_("Monitor"), buf);
394 act->connect_proxy (*c5);
399 main_table.show_all ();
403 MonitorSection::set_button_names ()
405 rec_enable_button_label.set_text ("rec");
406 mute_button_label.set_text ("rec");
407 solo_button_label.set_text ("rec");
411 MonitorSection::pack_widget () const
417 MonitorSection::dim_all ()
419 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), "monitor-dim-all");
421 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
422 _monitor->set_dim_all (tact->get_active());
428 MonitorSection::cut_all ()
430 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), "monitor-cut-all");
432 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
433 _monitor->set_cut_all (tact->get_active());
438 MonitorSection::mono ()
440 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), "monitor-mono");
442 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
443 _monitor->set_mono (tact->get_active());
448 MonitorSection::cut_channel (uint32_t chn)
451 snprintf (buf, sizeof (buf), "monitor-cut-%u", chn);
453 --chn; // 0-based in backend
455 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), buf);
457 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
458 _monitor->set_cut (chn, tact->get_active());
463 MonitorSection::dim_channel (uint32_t chn)
466 snprintf (buf, sizeof (buf), "monitor-dim-%u", chn);
468 --chn; // 0-based in backend
470 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), buf);
472 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
473 _monitor->set_dim (chn, tact->get_active());
479 MonitorSection::solo_channel (uint32_t chn)
482 snprintf (buf, sizeof (buf), "monitor-solo-%u", chn);
484 --chn; // 0-based in backend
486 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), buf);
488 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
489 _monitor->set_solo (chn, tact->get_active());
495 MonitorSection::invert_channel (uint32_t chn)
499 --chn; // 0-based in backend
501 snprintf (buf, sizeof (buf), "monitor-invert-%u", chn);
502 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), buf);
504 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
505 _monitor->set_polarity (chn, tact->get_active());
511 MonitorSection::register_actions ()
516 monitor_actions = ActionGroup::create (X_("Monitor"));
517 ActionManager::add_action_group (monitor_actions);
519 ActionManager::register_toggle_action (monitor_actions, "monitor-mono", "",
520 sigc::mem_fun (*this, &MonitorSection::mono));
522 ActionManager::register_toggle_action (monitor_actions, "monitor-cut-all", "",
523 sigc::mem_fun (*this, &MonitorSection::cut_all));
525 ActionManager::register_toggle_action (monitor_actions, "monitor-dim-all", "",
526 sigc::mem_fun (*this, &MonitorSection::dim_all));
528 /* note the 1-based counting for naming vs. 0-based for action */
530 for (uint32_t chn = 1; chn <= 16; ++chn) {
532 /* for the time being, do not use the action description because it always
533 shows up in the buttons, which is undesirable.
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));
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));
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));
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));
559 Glib::RefPtr<ActionGroup> solo_actions = ActionGroup::create (X_("Solo"));
560 RadioAction::Group solo_group;
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));
569 ActionManager::add_action_group (solo_actions);
573 MonitorSection::solo_use_in_place ()
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
580 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Solo"), X_("solo-use-in-place"));
583 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (act);
585 Config->set_solo_control_is_listen_control (!ract->get_active());
591 MonitorSection::solo_use_afl ()
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
598 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Solo"), X_("solo-use-afl"));
600 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (act);
602 if (ract->get_active()) {
603 Config->set_listen_position (AfterFaderListen);
604 Config->set_solo_control_is_listen_control (true);
611 MonitorSection::solo_use_pfl ()
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
618 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Solo"), X_("solo-use-afl"));
620 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (act);
622 if (ract->get_active()) {
623 Config->set_listen_position (PreFaderListen);
624 Config->set_solo_control_is_listen_control (true);
631 MonitorSection::fast_update ()
633 meter.update_meters ();
637 MonitorSection::setup_knob_images ()
641 big_knob_pixbuf = ::get_icon ("knob");
645 error << "No knob image found (or not loadable) at "
648 throw failed_constructor ();
653 little_knob_pixbuf = ::get_icon ("littleknob");
657 error << "No knob image found (or not loadable) at "
660 throw failed_constructor ();
665 MonitorSection::gain_value_changed ()
667 _route->set_gain (slider_position_to_gain (gain_adjustment.get_value()), this);
671 MonitorSection::dim_level_changed ()
673 _monitor->set_dim_level (dim_adjustment.get_value());
677 MonitorSection::solo_boost_changed ()
679 _monitor->set_solo_boost_level (solo_boost_adjustment.get_value());
683 MonitorSection::nonlinear_gain_printer (SpinButton* button)
685 double val = button->get_adjustment()->get_value();
687 snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain (val)));
688 button->set_text (buf);
693 MonitorSection::linear_gain_printer (SpinButton* button)
695 double val = button->get_adjustment()->get_value();
697 snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (val));
698 button->set_text (buf);
703 MonitorSection::map_state ()
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());
709 const char *action_name;
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");
717 action_name = X_("solo-use-afl");
721 action_name = X_("solo-use-in-place");
724 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Solo"), action_name);
726 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (act);
728 ract->set_active (true);
734 MonitorSection::solo_blink (bool onoff)
740 if (_session->soloing() || _session->listening()) {
742 rude_solo_button.set_state (STATE_ACTIVE);
744 rude_solo_button.set_state (STATE_NORMAL);
747 rude_solo_button.set_active (false);
748 rude_solo_button.set_state (STATE_NORMAL);
753 MonitorSection::cancel_solo (GdkEventButton* ev)
755 if (_session && _session->soloing()) {
756 _session->set_solo (_session->get_routes(), false);