2 Copyright (C) 2002 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "ardour/amp.h"
23 #include "ardour/logmeter.h"
24 #include "ardour/route_group.h"
25 #include "ardour/session_route.h"
26 #include "ardour/dB.h"
27 #include "ardour/utils.h"
30 #include <gtkmm/style.h>
31 #include <gdkmm/color.h>
32 #include <gtkmm2ext/utils.h>
33 #include <gtkmm2ext/fastmeter.h>
34 #include <gtkmm2ext/gtk_ui.h>
35 #include "pbd/fastlog.h"
36 #include "pbd/stacktrace.h"
38 #include "gain_meter.h"
39 #include "gui_thread.h"
41 #include "public_editor.h"
43 #include "meter_patterns.h"
46 #include "ui_config.h"
48 #include "ardour/session.h"
49 #include "ardour/route.h"
50 #include "ardour/meter.h"
51 #include "ardour/audio_track.h"
52 #include "ardour/midi_track.h"
53 #include "ardour/dB.h"
57 using namespace ARDOUR;
58 using namespace ARDOUR_UI_UTILS;
60 using namespace Gtkmm2ext;
63 using Gtkmm2ext::Keyboard;
64 using namespace ArdourMeter;
67 reset_cursor_to_default (Gtk::Entry* widget)
69 Glib::RefPtr<Gdk::Window> win = widget->get_text_window ();
71 /* C++ doesn't provide a pointer argument version of this
72 (i.e. you cannot set to NULL to get the default/parent
75 gdk_window_set_cursor (win->gobj(), 0);
80 reset_cursor_to_default_state (Gtk::StateType, Gtk::Entry* widget)
82 reset_cursor_to_default (widget);
85 sigc::signal<void, ARDOUR::AutoState> GainMeterBase::ChangeGainAutomationState;
87 GainMeterBase::GainMeterBase (Session* s, bool horizontal, int fader_length, int fader_girth)
88 : gain_adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain()), // value
91 dB_coeff_step(Config->get_max_gain()) / 10.0, // step increment
92 dB_coeff_step(Config->get_max_gain())) // page increment
93 , gain_automation_style_button ("")
94 , gain_automation_state_button ("")
95 , meter_point_button (_("pre"))
96 , gain_astate_propagate (false)
97 , _data_type (DataType::AUDIO)
99 using namespace Menu_Helpers;
103 ignore_toggle = false;
105 next_release_selects = false;
108 fader_length = rint (fader_length * UIConfiguration::instance().get_ui_scale());
109 fader_girth = rint (fader_girth * UIConfiguration::instance().get_ui_scale());
112 gain_slider = manage (new HSliderController (&gain_adjustment, boost::shared_ptr<PBD::Controllable>(), fader_length, fader_girth));
114 gain_slider = manage (new VSliderController (&gain_adjustment, boost::shared_ptr<PBD::Controllable>(), fader_length, fader_girth));
117 level_meter = new LevelMeterHBox(_session);
119 level_meter->ButtonPress.connect_same_thread (_level_meter_connection, boost::bind (&GainMeterBase::level_meter_button_press, this, _1));
120 meter_metric_area.signal_button_press_event().connect (sigc::mem_fun (*this, &GainMeterBase::level_meter_button_press));
121 meter_metric_area.add_events (Gdk::BUTTON_PRESS_MASK);
123 gain_slider->set_tweaks (PixFader::Tweaks(PixFader::NoButtonForward | PixFader::NoVerticalScroll));
124 gain_slider->StartGesture.connect (sigc::mem_fun (*this, &GainMeter::amp_start_touch));
125 gain_slider->StopGesture.connect (sigc::mem_fun (*this, &GainMeter::amp_stop_touch));
126 gain_slider->set_name ("GainFader");
128 gain_display.set_name ("MixerStripGainDisplay");
129 set_size_request_to_display_given_text (gain_display, "-80.g", 2, 6); /* note the descender */
130 gain_display.signal_activate().connect (sigc::mem_fun (*this, &GainMeter::gain_activated));
131 gain_display.signal_focus_in_event().connect (sigc::mem_fun (*this, &GainMeter::gain_focused), false);
132 gain_display.signal_focus_out_event().connect (sigc::mem_fun (*this, &GainMeter::gain_focused), false);
133 gain_display.set_alignment (0.5);
135 peak_display.set_name ("MixerStripPeakDisplay");
136 set_size_request_to_display_given_text (peak_display, "-80.g", 2, 6); /* note the descender */
137 max_peak = minus_infinity();
138 peak_display.set_text (_("-inf"));
139 peak_display.set_alignment (0.5);
141 /* stuff related to the fact that the peak display is not, in
142 fact, supposed to be a text entry.
144 peak_display.set_events (peak_display.get_events() & ~(Gdk::EventMask (Gdk::LEAVE_NOTIFY_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::POINTER_MOTION_MASK)));
145 peak_display.signal_map().connect (sigc::bind (sigc::ptr_fun (reset_cursor_to_default), &peak_display));
146 peak_display.signal_state_changed().connect (sigc::bind (sigc::ptr_fun (reset_cursor_to_default_state), &peak_display));
147 peak_display.unset_flags (Gtk::CAN_FOCUS);
148 peak_display.set_editable (false);
150 gain_automation_style_button.set_name ("mixer strip button");
151 gain_automation_state_button.set_name ("mixer strip button");
153 set_tooltip (gain_automation_state_button, _("Fader automation mode"));
154 set_tooltip (gain_automation_style_button, _("Fader automation type"));
156 gain_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
157 gain_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
159 gain_automation_state_button.set_size_request(15, 15);
160 gain_automation_style_button.set_size_request(15, 15);
162 gain_astyle_menu.items().push_back (MenuElem (_("Trim")));
163 gain_astyle_menu.items().push_back (MenuElem (_("Abs")));
165 gain_astate_menu.set_name ("ArdourContextMenu");
166 gain_astate_menu.set_reserve_toggle_size(false);
167 gain_astyle_menu.set_name ("ArdourContextMenu");
169 meter_point_button.set_name ("mixer strip button");
171 set_tooltip (&meter_point_button, _("Metering point"));
173 meter_point_button.unset_flags (Gtk::CAN_FOCUS);
175 meter_point_button.set_size_request(15, 15);
177 meter_point_menu.set_name ("ArdourContextMenu");
178 meter_point_menu.set_reserve_toggle_size(false);
180 meter_point_menu.items().clear ();
181 meter_point_menu.items().push_back (MenuElem(_("Input"),
182 sigc::bind (sigc::mem_fun (*this,
183 &GainMeterBase::meter_point_clicked), (MeterPoint) MeterInput)));
184 meter_point_menu.items().push_back (MenuElem(_("Pre Fader"),
185 sigc::bind (sigc::mem_fun (*this,
186 &GainMeterBase::meter_point_clicked), (MeterPoint) MeterPreFader)));
187 meter_point_menu.items().push_back (MenuElem(_("Post Fader"),
188 sigc::bind (sigc::mem_fun (*this,
189 &GainMeterBase::meter_point_clicked), (MeterPoint) MeterPostFader)));
190 meter_point_menu.items().push_back (MenuElem(_("Output"),
191 sigc::bind (sigc::mem_fun (*this,
192 &GainMeterBase::meter_point_clicked), (MeterPoint) MeterOutput)));
193 meter_point_menu.items().push_back (MenuElem(_("Custom"),
194 sigc::bind (sigc::mem_fun (*this,
195 &GainMeterBase::meter_point_clicked), (MeterPoint) MeterCustom)));
196 meter_point_button.signal_button_press_event().connect (sigc::mem_fun (*this, &GainMeter::meter_press), false);
198 gain_adjustment.signal_value_changed().connect (sigc::mem_fun(*this, &GainMeterBase::fader_moved));
199 peak_display.signal_button_release_event().connect (sigc::mem_fun(*this, &GainMeterBase::peak_button_release), false);
200 gain_display.signal_key_press_event().connect (sigc::mem_fun(*this, &GainMeterBase::gain_key_press), false);
202 ResetAllPeakDisplays.connect (sigc::mem_fun(*this, &GainMeterBase::reset_peak_display));
203 ResetRoutePeakDisplays.connect (sigc::mem_fun(*this, &GainMeterBase::reset_route_peak_display));
204 ResetGroupPeakDisplays.connect (sigc::mem_fun(*this, &GainMeterBase::reset_group_peak_display));
205 RedrawMetrics.connect (sigc::mem_fun(*this, &GainMeterBase::redraw_metrics));
207 UI::instance()->theme_changed.connect (sigc::mem_fun(*this, &GainMeterBase::on_theme_changed));
208 UIConfiguration::instance().ColorsChanged.connect (sigc::bind(sigc::mem_fun (*this, &GainMeterBase::color_handler), false));
209 UIConfiguration::instance().DPIReset.connect (sigc::bind(sigc::mem_fun (*this, &GainMeterBase::color_handler), true));
212 GainMeterBase::~GainMeterBase ()
219 GainMeterBase::set_controls (boost::shared_ptr<Route> r,
220 boost::shared_ptr<PeakMeter> pm,
221 boost::shared_ptr<Amp> amp,
222 boost::shared_ptr<GainControl> control)
224 connections.clear ();
225 model_connections.drop_connections ();
227 /* no meter and no control? nothing to do ... */
229 if (!pm && !control) {
230 level_meter->set_meter (0);
231 gain_slider->set_controllable (boost::shared_ptr<PBD::Controllable>());
244 level_meter->set_meter (pm.get());
245 gain_slider->set_controllable (_control);
248 amp->ConfigurationChanged.connect (
249 model_connections, invalidator (*this), boost::bind (&GainMeterBase::setup_gain_adjustment, this), gui_context ()
253 setup_gain_adjustment ();
255 if (!_route || !_route->is_auditioner()) {
257 using namespace Menu_Helpers;
259 gain_astate_menu.items().clear ();
261 gain_astate_menu.items().push_back (MenuElem (S_("Automation|Manual"),
262 sigc::bind (sigc::mem_fun (*this, &GainMeterBase::set_gain_astate), (AutoState) ARDOUR::Off)));
263 gain_astate_menu.items().push_back (MenuElem (_("Play"),
264 sigc::bind (sigc::mem_fun (*this, &GainMeterBase::set_gain_astate), (AutoState) ARDOUR::Play)));
265 gain_astate_menu.items().push_back (MenuElem (_("Write"),
266 sigc::bind (sigc::mem_fun (*this, &GainMeterBase::set_gain_astate), (AutoState) ARDOUR::Write)));
267 gain_astate_menu.items().push_back (MenuElem (_("Touch"),
268 sigc::bind (sigc::mem_fun (*this, &GainMeterBase::set_gain_astate), (AutoState) ARDOUR::Touch)));
270 connections.push_back (gain_automation_style_button.signal_button_press_event().connect (sigc::mem_fun(*this, &GainMeterBase::gain_automation_style_button_event), false));
271 connections.push_back (gain_automation_state_button.signal_button_press_event().connect (sigc::mem_fun(*this, &GainMeterBase::gain_automation_state_button_event), false));
272 connections.push_back (ChangeGainAutomationState.connect (sigc::mem_fun(*this, &GainMeterBase::set_gain_astate)));
274 _control->alist()->automation_state_changed.connect (model_connections, invalidator (*this), boost::bind (&GainMeter::gain_automation_state_changed, this), gui_context());
275 _control->alist()->automation_style_changed.connect (model_connections, invalidator (*this), boost::bind (&GainMeter::gain_automation_style_changed, this), gui_context());
277 gain_automation_state_changed ();
280 _control->Changed.connect (model_connections, invalidator (*this), boost::bind (&GainMeterBase::gain_changed, this), gui_context());
284 update_gain_sensitive ();
287 peak_display.hide ();
289 peak_display.show ();
294 GainMeterBase::set_gain_astate (AutoState as)
296 if (gain_astate_propagate) {
297 gain_astate_propagate = false;
298 ChangeGainAutomationState (as);
301 _amp->set_parameter_automation_state (Evoral::Parameter (GainAutomation), as);
305 GainMeterBase::setup_gain_adjustment ()
311 if (_previous_amp_output_streams == _amp->output_streams ()) {
315 ignore_toggle = true;
317 if (_amp->output_streams().n_midi() <= _amp->output_streams().n_audio()) {
318 _data_type = DataType::AUDIO;
319 gain_adjustment.set_lower (GAIN_COEFF_ZERO);
320 gain_adjustment.set_upper (GAIN_COEFF_UNITY);
321 gain_adjustment.set_step_increment (dB_coeff_step(Config->get_max_gain()) / 10.0);
322 gain_adjustment.set_page_increment (dB_coeff_step(Config->get_max_gain()));
323 gain_slider->set_default_value (gain_to_slider_position (GAIN_COEFF_UNITY));
325 _data_type = DataType::MIDI;
326 gain_adjustment.set_lower (0.0);
327 gain_adjustment.set_upper (2.0);
328 gain_adjustment.set_step_increment (1.0/128.0);
329 gain_adjustment.set_page_increment (10.0/128.0);
330 gain_slider->set_default_value (1.0);
333 ignore_toggle = false;
335 effective_gain_display ();
337 _previous_amp_output_streams = _amp->output_streams ();
341 GainMeterBase::hide_all_meters ()
343 level_meter->hide_meters();
347 GainMeter::hide_all_meters ()
349 GainMeterBase::hide_all_meters ();
353 GainMeterBase::setup_meters (int len)
356 uint32_t meter_channels = 0;
358 meter_channels = _meter->input_streams().n_total();
360 meter_channels = _route->shared_peak_meter()->input_streams().n_total();
365 //meter_ticks1_area.show();
366 //meter_ticks2_area.show();
367 meter_metric_area.show();
368 if (meter_channels == 1) {
373 if (meter_channels > 1) {
376 //meter_ticks1_area.hide();
377 //meter_ticks2_area.hide();
378 meter_metric_area.hide();
381 level_meter->setup_meters(len, meter_width);
385 GainMeterBase::set_type (MeterType t)
387 level_meter->set_type(t);
391 GainMeter::setup_meters (int len)
396 uint32_t meter_channels = 0;
398 meter_channels = _meter->input_streams().n_total();
400 meter_channels = _route->shared_peak_meter()->input_streams().n_total();
402 hbox.set_homogeneous(meter_channels < 7 ? true : false);
406 hbox.set_homogeneous(false);
409 GainMeterBase::setup_meters (len);
413 GainMeter::set_type (MeterType t)
415 GainMeterBase::set_type (t);
419 GainMeterBase::gain_key_press (GdkEventKey* ev)
421 if (key_is_legal_for_numeric_entry (ev->keyval)) {
422 /* drop through to normal handling */
425 /* illegal key for gain entry */
430 GainMeterBase::peak_button_release (GdkEventButton* ev)
432 /* reset peak label */
434 if (ev->button == 1 && Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier|Keyboard::TertiaryModifier)) {
435 ResetAllPeakDisplays ();
436 } else if (ev->button == 1 && Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
438 ResetGroupPeakDisplays (_route->route_group());
441 ResetRoutePeakDisplays (_route.get());
448 GainMeterBase::reset_peak_display ()
451 // catch "reset all" for VCAs
455 level_meter->clear_meters();
456 max_peak = minus_infinity ();
457 peak_display.set_text (_("-inf"));
458 peak_display.set_name ("MixerStripPeakDisplay");
462 GainMeterBase::reset_route_peak_display (Route* route)
464 if (_route && _route.get() == route) {
465 reset_peak_display ();
470 GainMeterBase::reset_group_peak_display (RouteGroup* group)
472 if (_route && group == _route->route_group()) {
473 reset_peak_display ();
478 GainMeterBase::popup_meter_menu (GdkEventButton *ev)
480 using namespace Menu_Helpers;
482 if (meter_menu == 0) {
483 meter_menu = new Gtk::Menu;
484 MenuList& items = meter_menu->items();
486 items.push_back (MenuElem ("-inf .. +0dBFS"));
487 items.push_back (MenuElem ("-10dB .. +0dBFS"));
488 items.push_back (MenuElem ("-4 .. +0dBFS"));
489 items.push_back (SeparatorElem());
490 items.push_back (MenuElem ("-inf .. -2dBFS"));
491 items.push_back (MenuElem ("-10dB .. -2dBFS"));
492 items.push_back (MenuElem ("-4 .. -2dBFS"));
495 meter_menu->popup (1, ev->time);
499 GainMeterBase::gain_focused (GdkEventFocus* ev)
502 gain_display.select_region (0, -1);
504 gain_display.select_region (0, 0);
510 GainMeterBase::gain_activated ()
514 // Use the user's preferred locale/LC_NUMERIC setting
515 if (sscanf (gain_display.get_text().c_str(), "%f", &f) != 1) {
519 /* clamp to displayable values */
520 if (_data_type == DataType::AUDIO) {
522 _control->set_value (dB_to_coefficient(f), Controllable::UseGroup);
524 f = min (fabs (f), 2.0f);
525 _control->set_value (f, Controllable::UseGroup);
528 if (gain_display.has_focus()) {
529 Gtk::Widget* w = gain_display.get_toplevel();
531 Gtk::Window* win = dynamic_cast<Gtk::Window*> (w);
533 /* sigh. gtkmm doesn't wrap get_default_widget() */
536 GtkWidget* f = gtk_window_get_default_widget (win->gobj());
538 gtk_widget_grab_focus (f);
547 GainMeterBase::show_gain ()
551 float v = gain_adjustment.get_value();
553 switch (_data_type) {
554 case DataType::AUDIO:
556 strcpy (buf, _("-inf"));
558 snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain_with_max (v, Config->get_max_gain())));
562 snprintf (buf, sizeof (buf), "%.1f", v);
566 gain_display.set_text (buf);
570 GainMeterBase::fader_moved ()
572 if (!ignore_toggle) {
576 /* convert from adjustment range (0..1) to gain coefficient */
578 if (_data_type == DataType::AUDIO) {
579 value = slider_position_to_gain_with_max (gain_adjustment.get_value(), Config->get_max_gain());
581 value = gain_adjustment.get_value();
584 _control->set_value (value, Controllable::UseGroup);
591 GainMeterBase::effective_gain_display ()
593 gain_t fader_position = 0;
595 switch (_data_type) {
596 case DataType::AUDIO:
597 /* the position of the fader should reflect any master gain,
598 * not just the control's own inherent value
600 fader_position = gain_to_slider_position_with_max (_control->get_value(), Config->get_max_gain());
603 fader_position = _control->get_value ();
607 if (gain_adjustment.get_value() != fader_position) {
608 ignore_toggle = true;
609 gain_adjustment.set_value (fader_position);
610 ignore_toggle = false;
615 GainMeterBase::gain_changed ()
617 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&GainMeterBase::effective_gain_display, this));
621 GainMeterBase::set_meter_strip_name (const char * name)
624 meter_metric_area.set_name (name);
625 sprintf(tmp, "Mark%sLeft", name);
626 meter_ticks1_area.set_name (tmp);
627 sprintf(tmp, "Mark%sRight", name);
628 meter_ticks2_area.set_name (tmp);
632 GainMeterBase::set_fader_name (const char * name)
634 gain_slider->set_name (name);
638 GainMeterBase::update_gain_sensitive ()
640 bool x = !(_control->alist()->automation_state() & Play);
641 static_cast<Gtkmm2ext::SliderController*>(gain_slider)->set_sensitive (x);
645 GainMeterBase::meter_press(GdkEventButton* ev)
650 if (!ignore_toggle) {
651 switch (ev->button) {
653 if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
655 /* Primary+Tertiary-click applies change to all routes */
657 meter_point_change_target = MeterPointChangeAll;
659 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
661 /* Primary-click: apply change to all routes in group */
663 meter_point_change_target = MeterPointChangeGroup;
667 /* click: change just this route */
669 meter_point_change_target = MeterPointChangeSingle;
671 Gtkmm2ext::anchored_menu_popup(&meter_point_menu,
683 GainMeterBase::set_meter_point (Route& route, MeterPoint mp)
685 route.set_meter_point (mp);
689 GainMeterBase::set_route_group_meter_point (Route& route, MeterPoint mp)
691 RouteGroup* route_group;
693 if ((route_group = route.route_group ()) != 0) {
694 route_group->foreach_route (boost::bind (&Route::set_meter_point, _1, mp, false));
696 route.set_meter_point (mp);
701 GainMeterBase::meter_point_clicked (MeterPoint mp)
704 switch (meter_point_change_target) {
705 case MeterPointChangeAll:
706 _session->foreach_route (this, &GainMeterBase::set_meter_point, mp);
708 case MeterPointChangeGroup:
709 set_route_group_meter_point (*_route, mp);
711 case MeterPointChangeSingle:
712 _route->set_meter_point (mp);
719 GainMeterBase::amp_start_touch ()
721 _control->start_touch (_control->session().transport_frame());
725 GainMeterBase::amp_stop_touch ()
727 _control->stop_touch (false, _control->session().transport_frame());
731 GainMeterBase::gain_automation_state_button_event (GdkEventButton *ev)
733 if (ev->type == GDK_BUTTON_RELEASE) {
737 switch (ev->button) {
739 gain_astate_propagate = Keyboard::modifier_state_contains (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier | Keyboard::TertiaryModifier));
740 Gtkmm2ext::anchored_menu_popup(&gain_astate_menu,
741 &gain_automation_state_button,
752 GainMeterBase::gain_automation_style_button_event (GdkEventButton *ev)
754 if (ev->type == GDK_BUTTON_RELEASE) {
758 switch (ev->button) {
760 gain_astyle_menu.popup (1, ev->time);
769 GainMeterBase::astate_string (AutoState state)
771 return _astate_string (state, false);
775 GainMeterBase::short_astate_string (AutoState state)
777 return _astate_string (state, true);
781 GainMeterBase::_astate_string (AutoState state, bool shrt)
787 sstr = (shrt ? "M" : _("M"));
790 sstr = (shrt ? "P" : _("P"));
793 sstr = (shrt ? "T" : _("T"));
796 sstr = (shrt ? "W" : _("W"));
804 GainMeterBase::astyle_string (AutoStyle style)
806 return _astyle_string (style, false);
810 GainMeterBase::short_astyle_string (AutoStyle style)
812 return _astyle_string (style, true);
816 GainMeterBase::_astyle_string (AutoStyle style, bool shrt)
821 /* XXX it might different in different languages */
823 return (shrt ? _("Abs") : _("Abs"));
828 GainMeterBase::gain_automation_style_changed ()
832 gain_automation_style_button.set_text (astyle_string(_control->alist()->automation_style()));
835 gain_automation_style_button.set_text (short_astyle_string(_control->alist()->automation_style()));
841 GainMeterBase::gain_automation_state_changed ()
843 ENSURE_GUI_THREAD (*this, &GainMeterBase::gain_automation_state_changed);
847 gain_automation_state_button.set_text (astate_string(_control->alist()->automation_state()));
850 gain_automation_state_button.set_text (short_astate_string(_control->alist()->automation_state()));
854 const bool automation_watch_required = (_control->alist()->automation_state() != ARDOUR::Off);
856 if (gain_automation_state_button.get_active() != automation_watch_required) {
857 ignore_toggle = true;
858 gain_automation_state_button.set_active (automation_watch_required);
859 ignore_toggle = false;
862 update_gain_sensitive ();
864 gain_watching.disconnect();
866 if (automation_watch_required) {
867 /* start watching automation so that things move */
868 gain_watching = Timers::rapid_connect (sigc::mem_fun (*this, &GainMeterBase::effective_gain_display));
870 /* update once to get the correct value shown as we re-enter off/manual mode */
871 effective_gain_display();
876 GainMeterBase::meter_channels() const
878 if (_meter) { return _meter->input_streams(); }
879 else { return ChanCount(); }
882 GainMeterBase::update_meters()
885 float mpeak = level_meter->update_meters();
887 if (mpeak > max_peak) {
889 if (mpeak <= -200.0f) {
890 peak_display.set_text (_("-inf"));
892 snprintf (buf, sizeof(buf), "%.1f", mpeak);
893 peak_display.set_text (buf);
896 if (mpeak >= UIConfiguration::instance().get_meter_peak()) {
897 peak_display.set_name ("MixerStripPeakDisplayPeak");
901 void GainMeterBase::color_handler(bool /*dpi*/)
907 GainMeterBase::set_width (Width w, int len)
911 if (_width == Wide && _route && _route->shared_peak_meter()->input_streams().n_total() == 1) {
914 level_meter->setup_meters(len, meter_width);
919 GainMeterBase::on_theme_changed()
924 GainMeterBase::redraw_metrics()
926 meter_metric_area.queue_draw ();
927 meter_ticks1_area.queue_draw ();
928 meter_ticks2_area.queue_draw ();
931 #define PX_SCALE(pxmin, dflt) rint(std::max((double)pxmin, (double)dflt * UIConfiguration::instance().get_ui_scale()))
933 GainMeter::GainMeter (Session* s, int fader_length)
934 : GainMeterBase (s, false, fader_length, 24)
935 , gain_display_box(true, 0)
938 if (gain_display.get_parent()) {
939 gain_display.get_parent()->remove (gain_display);
941 gain_display_box.pack_start (gain_display, true, true);
943 if (peak_display.get_parent()) {
944 peak_display.get_parent()->remove (gain_display);
946 gain_display_box.pack_start (peak_display, true, true);
948 meter_metric_area.set_name ("AudioTrackMetrics");
949 meter_metric_area.set_size_request(PX_SCALE(24, 24), -1);
951 gain_automation_style_button.set_name ("mixer strip button");
952 gain_automation_state_button.set_name ("mixer strip button");
954 set_tooltip (gain_automation_state_button, _("Fader automation mode"));
955 set_tooltip (gain_automation_style_button, _("Fader automation type"));
957 gain_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
958 gain_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
960 gain_automation_state_button.set_size_request (PX_SCALE(12, 15), PX_SCALE(12, 15));
961 gain_automation_style_button.set_size_request (PX_SCALE(12, 15), PX_SCALE(12, 15));
963 fader_vbox.set_spacing (0);
964 fader_vbox.pack_start (*gain_slider, true, true);
966 fader_alignment.set (0.5, 0.5, 0.0, 1.0);
967 fader_alignment.add (fader_vbox);
969 hbox.pack_start (fader_alignment, true, true);
971 set_spacing (PX_SCALE(2, 2));
973 pack_start (gain_display_box, Gtk::PACK_SHRINK);
974 pack_start (hbox, true, true);
976 meter_alignment.set (0.5, 0.5, 0.0, 1.0);
977 meter_alignment.add (*level_meter);
979 meter_metric_area.signal_expose_event().connect (
980 sigc::mem_fun(*this, &GainMeter::meter_metrics_expose));
982 meter_ticks1_area.set_size_request (PX_SCALE(3, 3), -1);
983 meter_ticks2_area.set_size_request (PX_SCALE(3, 3), -1);
985 meter_ticks1_area.signal_expose_event().connect (
986 sigc::mem_fun(*this, &GainMeter::meter_ticks1_expose));
987 meter_ticks2_area.signal_expose_event().connect (
988 sigc::mem_fun(*this, &GainMeter::meter_ticks2_expose));
990 meter_hbox.pack_start (meter_ticks1_area, false, false);
991 meter_hbox.pack_start (meter_alignment, false, false);
992 meter_hbox.pack_start (meter_ticks2_area, false, false);
993 meter_hbox.pack_start (meter_metric_area, false, false);
997 GainMeter::~GainMeter () { }
1000 GainMeter::set_controls (boost::shared_ptr<Route> r,
1001 boost::shared_ptr<PeakMeter> meter,
1002 boost::shared_ptr<Amp> amp,
1003 boost::shared_ptr<GainControl> control)
1005 if (meter_hbox.get_parent()) {
1006 hbox.remove (meter_hbox);
1009 // if (gain_automation_state_button.get_parent()) {
1010 // fader_vbox->remove (gain_automation_state_button);
1013 GainMeterBase::set_controls (r, meter, amp, control);
1016 _meter->ConfigurationChanged.connect (
1017 model_connections, invalidator (*this), boost::bind (&GainMeter::meter_configuration_changed, this, _1), gui_context()
1019 _meter->TypeChanged.connect (
1020 model_connections, invalidator (*this), boost::bind (&GainMeter::meter_type_changed, this, _1), gui_context()
1023 meter_configuration_changed (_meter->input_streams ());
1028 _route->active_changed.connect (model_connections, invalidator (*this), boost::bind (&GainMeter::route_active_changed, this), gui_context ());
1029 hbox.pack_start (meter_hbox, true, true);
1033 // if (r && !r->is_auditioner()) {
1034 // fader_vbox->pack_start (gain_automation_state_button, false, false, 0);
1037 gain_display_box.show ();
1038 gain_display.show ();
1039 gain_slider->show ();
1041 fader_alignment.show ();
1047 GainMeter::get_gm_width ()
1049 Gtk::Requisition sz;
1052 meter_metric_area.size_request (sz);
1054 level_meter->size_request (sz);
1057 fader_alignment.size_request (sz);
1059 return max(sz.width * 2, min_w * 2) + 6;
1061 return sz.width + min_w + 6;
1066 GainMeter::meter_metrics_expose (GdkEventExpose *ev)
1069 if (_types.empty()) { _types.push_back(DataType::AUDIO); }
1070 return meter_expose_metrics(ev, MeterPeak, _types, &meter_metric_area);
1072 return meter_expose_metrics(ev, _route->meter_type(), _types, &meter_metric_area);
1076 GainMeter::meter_ticks1_expose (GdkEventExpose *ev)
1079 if (_types.empty()) { _types.push_back(DataType::AUDIO); }
1080 return meter_expose_ticks(ev, MeterPeak, _types, &meter_ticks1_area);
1082 return meter_expose_ticks(ev, _route->meter_type(), _types, &meter_ticks1_area);
1086 GainMeter::meter_ticks2_expose (GdkEventExpose *ev)
1089 if (_types.empty()) { _types.push_back(DataType::AUDIO); }
1090 return meter_expose_ticks(ev, MeterPeak, _types, &meter_ticks2_area);
1092 return meter_expose_ticks(ev, _route->meter_type(), _types, &meter_ticks2_area);
1096 GainMeter::on_style_changed (const Glib::RefPtr<Gtk::Style>&)
1098 gain_display.queue_draw();
1099 peak_display.queue_draw();
1102 boost::shared_ptr<PBD::Controllable>
1103 GainMeterBase::get_controllable()
1108 return boost::shared_ptr<PBD::Controllable>();
1113 GainMeterBase::level_meter_button_press (GdkEventButton* ev)
1115 return static_cast<bool>(LevelMeterButtonPress (ev)); /* EMIT SIGNAL */
1119 GainMeter::meter_configuration_changed (ChanCount c)
1124 for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) {
1125 if (c.get (*i) > 0) {
1126 _types.push_back (*i);
1132 && boost::dynamic_pointer_cast<AudioTrack>(_route) == 0
1133 && boost::dynamic_pointer_cast<MidiTrack>(_route) == 0
1135 if (_route->active()) {
1136 set_meter_strip_name ("AudioBusMetrics");
1138 set_meter_strip_name ("AudioBusMetricsInactive");
1142 (type == (1 << DataType::MIDI))
1143 || (_route && boost::dynamic_pointer_cast<MidiTrack>(_route))
1145 if (!_route || _route->active()) {
1146 set_meter_strip_name ("MidiTrackMetrics");
1148 set_meter_strip_name ("MidiTrackMetricsInactive");
1151 else if (type == (1 << DataType::AUDIO)) {
1152 if (!_route || _route->active()) {
1153 set_meter_strip_name ("AudioTrackMetrics");
1155 set_meter_strip_name ("AudioTrackMetricsInactive");
1158 if (!_route || _route->active()) {
1159 set_meter_strip_name ("AudioMidiTrackMetrics");
1161 set_meter_strip_name ("AudioMidiTrackMetricsInactive");
1166 meter_clear_pattern_cache(4);
1167 on_style_changed(Glib::RefPtr<Gtk::Style>());
1171 GainMeter::route_active_changed ()
1174 meter_configuration_changed (_meter->input_streams ());
1179 GainMeter::meter_type_changed (MeterType t)
1181 _route->set_meter_type(t);