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/route_group.h"
24 #include "ardour/session_route.h"
25 #include "ardour/dB.h"
26 #include "ardour/utils.h"
29 #include <gtkmm/style.h>
30 #include <gdkmm/color.h>
31 #include <gtkmm2ext/utils.h>
32 #include <gtkmm2ext/fastmeter.h>
33 #include <gtkmm2ext/gtk_ui.h>
34 #include "pbd/fastlog.h"
35 #include "pbd/stacktrace.h"
37 #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 , gain_astate_propagate (false)
96 , _data_type (DataType::AUDIO)
98 using namespace Menu_Helpers;
102 ignore_toggle = false;
104 next_release_selects = false;
107 fader_length = rint (fader_length * UIConfiguration::instance().get_ui_scale());
108 fader_girth = rint (fader_girth * UIConfiguration::instance().get_ui_scale());
111 gain_slider = manage (new HSliderController (&gain_adjustment, boost::shared_ptr<PBD::Controllable>(), fader_length, fader_girth));
113 gain_slider = manage (new VSliderController (&gain_adjustment, boost::shared_ptr<PBD::Controllable>(), fader_length, fader_girth));
116 level_meter = new LevelMeterHBox(_session);
118 level_meter->ButtonPress.connect_same_thread (_level_meter_connection, boost::bind (&GainMeterBase::level_meter_button_press, this, _1));
119 meter_metric_area.signal_button_press_event().connect (sigc::mem_fun (*this, &GainMeterBase::level_meter_button_press));
120 meter_metric_area.add_events (Gdk::BUTTON_PRESS_MASK);
122 gain_slider->set_tweaks (PixFader::Tweaks(PixFader::NoButtonForward | PixFader::NoVerticalScroll));
123 gain_slider->StartGesture.connect (sigc::mem_fun (*this, &GainMeter::amp_start_touch));
124 gain_slider->StopGesture.connect (sigc::mem_fun (*this, &GainMeter::amp_stop_touch));
125 gain_slider->set_name ("GainFader");
127 gain_display.set_name ("MixerStripGainDisplay");
128 set_size_request_to_display_given_text (gain_display, "-80.g", 2, 6); /* note the descender */
129 gain_display.signal_activate().connect (sigc::mem_fun (*this, &GainMeter::gain_activated));
130 gain_display.signal_focus_in_event().connect (sigc::mem_fun (*this, &GainMeter::gain_focused), false);
131 gain_display.signal_focus_out_event().connect (sigc::mem_fun (*this, &GainMeter::gain_focused), false);
133 peak_display.set_name ("MixerStripPeakDisplay");
134 set_size_request_to_display_given_text (peak_display, "-80.g", 2, 6); /* note the descender */
135 max_peak = minus_infinity();
136 peak_display.set_text (_("-inf"));
138 /* stuff related to the fact that the peak display is not, in
139 fact, supposed to be a text entry.
141 peak_display.set_events (peak_display.get_events() & ~(Gdk::EventMask (Gdk::LEAVE_NOTIFY_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::POINTER_MOTION_MASK)));
142 peak_display.signal_map().connect (sigc::bind (sigc::ptr_fun (reset_cursor_to_default), &peak_display));
143 peak_display.signal_state_changed().connect (sigc::bind (sigc::ptr_fun (reset_cursor_to_default_state), &peak_display));
144 peak_display.unset_flags (Gtk::CAN_FOCUS);
145 peak_display.set_editable (false);
147 gain_automation_style_button.set_name ("mixer strip button");
148 gain_automation_state_button.set_name ("mixer strip button");
150 set_tooltip (gain_automation_state_button, _("Fader automation mode"));
151 set_tooltip (gain_automation_style_button, _("Fader automation type"));
153 gain_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
154 gain_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
156 gain_automation_state_button.set_size_request(15, 15);
157 gain_automation_style_button.set_size_request(15, 15);
159 gain_astyle_menu.items().push_back (MenuElem (_("Trim")));
160 gain_astyle_menu.items().push_back (MenuElem (_("Abs")));
162 gain_astate_menu.set_name ("ArdourContextMenu");
163 gain_astyle_menu.set_name ("ArdourContextMenu");
165 gain_adjustment.signal_value_changed().connect (sigc::mem_fun(*this, &GainMeterBase::fader_moved));
166 peak_display.signal_button_release_event().connect (sigc::mem_fun(*this, &GainMeterBase::peak_button_release), false);
167 gain_display.signal_key_press_event().connect (sigc::mem_fun(*this, &GainMeterBase::gain_key_press), false);
169 ResetAllPeakDisplays.connect (sigc::mem_fun(*this, &GainMeterBase::reset_peak_display));
170 ResetRoutePeakDisplays.connect (sigc::mem_fun(*this, &GainMeterBase::reset_route_peak_display));
171 ResetGroupPeakDisplays.connect (sigc::mem_fun(*this, &GainMeterBase::reset_group_peak_display));
172 RedrawMetrics.connect (sigc::mem_fun(*this, &GainMeterBase::redraw_metrics));
174 UI::instance()->theme_changed.connect (sigc::mem_fun(*this, &GainMeterBase::on_theme_changed));
175 UIConfiguration::instance().ColorsChanged.connect (sigc::bind(sigc::mem_fun (*this, &GainMeterBase::color_handler), false));
176 UIConfiguration::instance().DPIReset.connect (sigc::bind(sigc::mem_fun (*this, &GainMeterBase::color_handler), true));
179 GainMeterBase::~GainMeterBase ()
186 GainMeterBase::set_controls (boost::shared_ptr<Route> r,
187 boost::shared_ptr<PeakMeter> pm,
188 boost::shared_ptr<Amp> amp,
189 boost::shared_ptr<GainControl> control)
191 connections.clear ();
192 model_connections.drop_connections ();
194 /* no meter and no control? nothing to do ... */
196 if (!pm && !control) {
197 level_meter->set_meter (0);
198 gain_slider->set_controllable (boost::shared_ptr<PBD::Controllable>());
211 level_meter->set_meter (pm.get());
212 gain_slider->set_controllable (_control);
215 amp->ConfigurationChanged.connect (
216 model_connections, invalidator (*this), boost::bind (&GainMeterBase::setup_gain_adjustment, this), gui_context ()
220 setup_gain_adjustment ();
222 if (!_route || !_route->is_auditioner()) {
224 using namespace Menu_Helpers;
226 gain_astate_menu.items().clear ();
228 gain_astate_menu.items().push_back (MenuElem (S_("Automation|Manual"),
229 sigc::bind (sigc::mem_fun (*this, &GainMeterBase::set_gain_astate), (AutoState) ARDOUR::Off)));
230 gain_astate_menu.items().push_back (MenuElem (_("Play"),
231 sigc::bind (sigc::mem_fun (*this, &GainMeterBase::set_gain_astate), (AutoState) ARDOUR::Play)));
232 gain_astate_menu.items().push_back (MenuElem (_("Write"),
233 sigc::bind (sigc::mem_fun (*this, &GainMeterBase::set_gain_astate), (AutoState) ARDOUR::Write)));
234 gain_astate_menu.items().push_back (MenuElem (_("Touch"),
235 sigc::bind (sigc::mem_fun (*this, &GainMeterBase::set_gain_astate), (AutoState) ARDOUR::Touch)));
237 connections.push_back (gain_automation_style_button.signal_button_press_event().connect (sigc::mem_fun(*this, &GainMeterBase::gain_automation_style_button_event), false));
238 connections.push_back (gain_automation_state_button.signal_button_press_event().connect (sigc::mem_fun(*this, &GainMeterBase::gain_automation_state_button_event), false));
239 connections.push_back (ChangeGainAutomationState.connect (sigc::mem_fun(*this, &GainMeterBase::set_gain_astate)));
241 _control->alist()->automation_state_changed.connect (model_connections, invalidator (*this), boost::bind (&GainMeter::gain_automation_state_changed, this), gui_context());
242 _control->alist()->automation_style_changed.connect (model_connections, invalidator (*this), boost::bind (&GainMeter::gain_automation_style_changed, this), gui_context());
244 gain_automation_state_changed ();
247 _control->Changed.connect (model_connections, invalidator (*this), boost::bind (&GainMeterBase::gain_changed, this), gui_context());
251 update_gain_sensitive ();
254 peak_display.hide ();
256 peak_display.show ();
261 GainMeterBase::set_gain_astate (AutoState as)
263 if (gain_astate_propagate) {
264 gain_astate_propagate = false;
265 ChangeGainAutomationState (as);
268 _amp->set_parameter_automation_state (Evoral::Parameter (GainAutomation), as);
272 GainMeterBase::setup_gain_adjustment ()
278 if (_previous_amp_output_streams == _amp->output_streams ()) {
282 ignore_toggle = true;
284 if (_amp->output_streams().n_midi() <= _amp->output_streams().n_audio()) {
285 _data_type = DataType::AUDIO;
286 gain_adjustment.set_lower (GAIN_COEFF_ZERO);
287 gain_adjustment.set_upper (GAIN_COEFF_UNITY);
288 gain_adjustment.set_step_increment (dB_coeff_step(Config->get_max_gain()) / 10.0);
289 gain_adjustment.set_page_increment (dB_coeff_step(Config->get_max_gain()));
290 gain_slider->set_default_value (gain_to_slider_position (GAIN_COEFF_UNITY));
292 _data_type = DataType::MIDI;
293 gain_adjustment.set_lower (0.0);
294 gain_adjustment.set_upper (2.0);
295 gain_adjustment.set_step_increment (1.0/128.0);
296 gain_adjustment.set_page_increment (10.0/128.0);
297 gain_slider->set_default_value (1.0);
300 ignore_toggle = false;
302 effective_gain_display ();
304 _previous_amp_output_streams = _amp->output_streams ();
308 GainMeterBase::hide_all_meters ()
310 level_meter->hide_meters();
314 GainMeter::hide_all_meters ()
316 GainMeterBase::hide_all_meters ();
320 GainMeterBase::setup_meters (int len)
323 uint32_t meter_channels = 0;
325 meter_channels = _meter->input_streams().n_total();
327 meter_channels = _route->shared_peak_meter()->input_streams().n_total();
332 //meter_ticks1_area.show();
333 //meter_ticks2_area.show();
334 meter_metric_area.show();
335 if (meter_channels == 1) {
340 if (meter_channels > 1) {
343 //meter_ticks1_area.hide();
344 //meter_ticks2_area.hide();
345 meter_metric_area.hide();
348 level_meter->setup_meters(len, meter_width);
352 GainMeterBase::set_type (MeterType t)
354 level_meter->set_type(t);
358 GainMeter::setup_meters (int len)
363 uint32_t meter_channels = 0;
365 meter_channels = _meter->input_streams().n_total();
367 meter_channels = _route->shared_peak_meter()->input_streams().n_total();
369 hbox.set_homogeneous(meter_channels < 7 ? true : false);
373 hbox.set_homogeneous(false);
376 GainMeterBase::setup_meters (len);
380 GainMeter::set_type (MeterType t)
382 GainMeterBase::set_type (t);
386 GainMeterBase::gain_key_press (GdkEventKey* ev)
388 if (key_is_legal_for_numeric_entry (ev->keyval)) {
389 /* drop through to normal handling */
392 /* illegal key for gain entry */
397 GainMeterBase::peak_button_release (GdkEventButton* ev)
399 /* reset peak label */
401 if (ev->button == 1 && Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier|Keyboard::TertiaryModifier)) {
402 ResetAllPeakDisplays ();
403 } else if (ev->button == 1 && Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
405 ResetGroupPeakDisplays (_route->route_group());
408 ResetRoutePeakDisplays (_route.get());
415 GainMeterBase::reset_peak_display ()
418 level_meter->clear_meters();
419 max_peak = minus_infinity ();
420 peak_display.set_text (_("-inf"));
421 peak_display.set_name ("MixerStripPeakDisplay");
425 GainMeterBase::reset_route_peak_display (Route* route)
427 if (_route && _route.get() == route) {
428 reset_peak_display ();
433 GainMeterBase::reset_group_peak_display (RouteGroup* group)
435 if (_route && group == _route->route_group()) {
436 reset_peak_display ();
441 GainMeterBase::popup_meter_menu (GdkEventButton *ev)
443 using namespace Menu_Helpers;
445 if (meter_menu == 0) {
446 meter_menu = new Gtk::Menu;
447 MenuList& items = meter_menu->items();
449 items.push_back (MenuElem ("-inf .. +0dBFS"));
450 items.push_back (MenuElem ("-10dB .. +0dBFS"));
451 items.push_back (MenuElem ("-4 .. +0dBFS"));
452 items.push_back (SeparatorElem());
453 items.push_back (MenuElem ("-inf .. -2dBFS"));
454 items.push_back (MenuElem ("-10dB .. -2dBFS"));
455 items.push_back (MenuElem ("-4 .. -2dBFS"));
458 meter_menu->popup (1, ev->time);
462 GainMeterBase::gain_focused (GdkEventFocus* ev)
465 gain_display.select_region (0, -1);
467 gain_display.select_region (0, 0);
473 GainMeterBase::gain_activated ()
478 // Switch to user's preferred locale so that
479 // if they use different LC_NUMERIC conventions,
480 // we will honor them.
483 if (sscanf (gain_display.get_text().c_str(), "%f", &f) != 1) {
488 /* clamp to displayable values */
489 if (_data_type == DataType::AUDIO) {
491 _control->set_value (dB_to_coefficient(f), Controllable::UseGroup);
493 f = min (fabs (f), 2.0f);
494 _control->set_value (f, Controllable::UseGroup);
497 if (gain_display.has_focus()) {
498 Gtk::Widget* w = gain_display.get_toplevel();
500 Gtk::Window* win = dynamic_cast<Gtk::Window*> (w);
502 /* sigh. gtkmm doesn't wrap get_default_widget() */
505 GtkWidget* f = gtk_window_get_default_widget (win->gobj());
507 gtk_widget_grab_focus (f);
516 GainMeterBase::show_gain ()
520 float v = gain_adjustment.get_value();
522 switch (_data_type) {
523 case DataType::AUDIO:
525 strcpy (buf, _("-inf"));
527 snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain_with_max (v, Config->get_max_gain())));
531 snprintf (buf, sizeof (buf), "%.1f", v);
535 gain_display.set_text (buf);
539 GainMeterBase::fader_moved ()
541 if (!ignore_toggle) {
545 /* convert from adjustment range (0..1) to gain coefficient */
547 if (_data_type == DataType::AUDIO) {
548 value = slider_position_to_gain_with_max (gain_adjustment.get_value(), Config->get_max_gain());
550 value = gain_adjustment.get_value();
553 _control->set_value (value, Controllable::UseGroup);
560 GainMeterBase::effective_gain_display ()
562 gain_t fader_position = 0;
564 switch (_data_type) {
565 case DataType::AUDIO:
566 /* the position of the fader should reflect any master gain,
567 * not just the control's own inherent value
569 fader_position = gain_to_slider_position_with_max (_control->get_value(), Config->get_max_gain());
572 fader_position = _control->get_value ();
576 if (gain_adjustment.get_value() != fader_position) {
577 ignore_toggle = true;
578 gain_adjustment.set_value (fader_position);
579 ignore_toggle = false;
584 GainMeterBase::gain_changed ()
586 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&GainMeterBase::effective_gain_display, this));
590 GainMeterBase::set_meter_strip_name (const char * name)
593 meter_metric_area.set_name (name);
594 sprintf(tmp, "Mark%sLeft", name);
595 meter_ticks1_area.set_name (tmp);
596 sprintf(tmp, "Mark%sRight", name);
597 meter_ticks2_area.set_name (tmp);
601 GainMeterBase::set_fader_name (const char * name)
603 gain_slider->set_name (name);
607 GainMeterBase::update_gain_sensitive ()
609 bool x = !(_control->alist()->automation_state() & Play);
610 static_cast<Gtkmm2ext::SliderController*>(gain_slider)->set_sensitive (x);
614 next_meter_point (MeterPoint mp)
618 return MeterPreFader;
622 return MeterPostFader;
638 abort(); /*NOTREACHED*/
643 GainMeterBase::meter_press(GdkEventButton* ev)
645 wait_for_release = false;
651 if (!ignore_toggle) {
653 if (Keyboard::is_context_menu_event (ev)) {
655 // no menu at this time.
659 if (Keyboard::is_button2_event(ev)) {
661 // Primary-button2 click is the midi binding click
662 // button2-click is "momentary"
664 if (!Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier))) {
665 wait_for_release = true;
666 old_meter_point = _route->meter_point ();
670 if (_route && (ev->button == 1 || Keyboard::is_button2_event (ev))) {
672 if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
674 /* Primary+Tertiary-click applies change to all routes */
676 _session->foreach_route (this, &GainMeterBase::set_meter_point, next_meter_point (_route->meter_point()));
679 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
681 /* Primary-click: solo mix group.
682 NOTE: Primary-button2 is MIDI learn.
685 if (ev->button == 1) {
686 set_route_group_meter_point (*_route, next_meter_point (_route->meter_point()));
691 /* click: change just this route */
695 _route->set_meter_point (next_meter_point (_route->meter_point()));
706 GainMeterBase::meter_release(GdkEventButton*)
708 if (!ignore_toggle) {
709 if (wait_for_release) {
710 wait_for_release = false;
713 set_meter_point (*_route, old_meter_point);
722 GainMeterBase::set_meter_point (Route& route, MeterPoint mp)
724 route.set_meter_point (mp);
728 GainMeterBase::set_route_group_meter_point (Route& route, MeterPoint mp)
730 RouteGroup* route_group;
732 if ((route_group = route.route_group ()) != 0) {
733 route_group->foreach_route (boost::bind (&Route::set_meter_point, _1, mp, false));
735 route.set_meter_point (mp);
740 GainMeterBase::meter_point_clicked ()
748 GainMeterBase::amp_start_touch ()
750 _control->start_touch (_control->session().transport_frame());
754 GainMeterBase::amp_stop_touch ()
756 _control->stop_touch (false, _control->session().transport_frame());
760 GainMeterBase::gain_automation_state_button_event (GdkEventButton *ev)
762 if (ev->type == GDK_BUTTON_RELEASE) {
766 switch (ev->button) {
768 gain_astate_propagate = Keyboard::modifier_state_contains (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier | Keyboard::TertiaryModifier));
769 gain_astate_menu.popup (1, ev->time);
779 GainMeterBase::gain_automation_style_button_event (GdkEventButton *ev)
781 if (ev->type == GDK_BUTTON_RELEASE) {
785 switch (ev->button) {
787 gain_astyle_menu.popup (1, ev->time);
796 GainMeterBase::astate_string (AutoState state)
798 return _astate_string (state, false);
802 GainMeterBase::short_astate_string (AutoState state)
804 return _astate_string (state, true);
808 GainMeterBase::_astate_string (AutoState state, bool shrt)
814 sstr = (shrt ? "M" : _("M"));
817 sstr = (shrt ? "P" : _("P"));
820 sstr = (shrt ? "T" : _("T"));
823 sstr = (shrt ? "W" : _("W"));
831 GainMeterBase::astyle_string (AutoStyle style)
833 return _astyle_string (style, false);
837 GainMeterBase::short_astyle_string (AutoStyle style)
839 return _astyle_string (style, true);
843 GainMeterBase::_astyle_string (AutoStyle style, bool shrt)
848 /* XXX it might different in different languages */
850 return (shrt ? _("Abs") : _("Abs"));
855 GainMeterBase::gain_automation_style_changed ()
859 gain_automation_style_button.set_text (astyle_string(_control->alist()->automation_style()));
862 gain_automation_style_button.set_text (short_astyle_string(_control->alist()->automation_style()));
868 GainMeterBase::gain_automation_state_changed ()
870 ENSURE_GUI_THREAD (*this, &GainMeterBase::gain_automation_state_changed);
874 gain_automation_state_button.set_text (astate_string(_control->alist()->automation_state()));
877 gain_automation_state_button.set_text (short_astate_string(_control->alist()->automation_state()));
881 const bool automation_watch_required = (_control->alist()->automation_state() != ARDOUR::Off);
883 if (gain_automation_state_button.get_active() != automation_watch_required) {
884 ignore_toggle = true;
885 gain_automation_state_button.set_active (automation_watch_required);
886 ignore_toggle = false;
889 update_gain_sensitive ();
891 gain_watching.disconnect();
893 if (automation_watch_required) {
894 /* start watching automation so that things move */
895 gain_watching = Timers::rapid_connect (sigc::mem_fun (*this, &GainMeterBase::effective_gain_display));
897 /* update once to get the correct value shown as we re-enter off/manual mode */
898 effective_gain_display();
903 GainMeterBase::meter_channels() const
905 if (_meter) { return _meter->input_streams(); }
906 else { return ChanCount(); }
909 GainMeterBase::update_meters()
912 float mpeak = level_meter->update_meters();
914 if (mpeak > max_peak) {
916 if (mpeak <= -200.0f) {
917 peak_display.set_text (_("-inf"));
919 snprintf (buf, sizeof(buf), "%.1f", mpeak);
920 peak_display.set_text (buf);
923 if (mpeak >= UIConfiguration::instance().get_meter_peak()) {
924 peak_display.set_name ("MixerStripPeakDisplayPeak");
928 void GainMeterBase::color_handler(bool /*dpi*/)
934 GainMeterBase::set_width (Width w, int len)
938 if (_width == Wide && _route && _route->shared_peak_meter()->input_streams().n_total() == 1) {
941 level_meter->setup_meters(len, meter_width);
946 GainMeterBase::on_theme_changed()
951 GainMeterBase::redraw_metrics()
953 meter_metric_area.queue_draw ();
954 meter_ticks1_area.queue_draw ();
955 meter_ticks2_area.queue_draw ();
958 #define PX_SCALE(pxmin, dflt) rint(std::max((double)pxmin, (double)dflt * UIConfiguration::instance().get_ui_scale()))
960 GainMeter::GainMeter (Session* s, int fader_length)
961 : GainMeterBase (s, false, fader_length, 24)
962 , gain_display_box(true, 0)
965 gain_display_box.set_border_width (0);
967 if (gain_display.get_parent()) {
968 gain_display.get_parent()->remove (gain_display);
970 gain_display_box.pack_start (gain_display, true, true);
972 if (peak_display.get_parent()) {
973 peak_display.get_parent()->remove (gain_display);
975 gain_display_box.pack_start (peak_display, true, true);
977 meter_metric_area.set_name ("AudioTrackMetrics");
978 meter_metric_area.set_size_request(PX_SCALE(24, 24), -1);
980 gain_automation_style_button.set_name ("mixer strip button");
981 gain_automation_state_button.set_name ("mixer strip button");
983 set_tooltip (gain_automation_state_button, _("Fader automation mode"));
984 set_tooltip (gain_automation_style_button, _("Fader automation type"));
986 gain_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
987 gain_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
989 gain_automation_state_button.set_size_request (PX_SCALE(12, 15), PX_SCALE(12, 15));
990 gain_automation_style_button.set_size_request (PX_SCALE(12, 15), PX_SCALE(12, 15));
992 fader_vbox.set_spacing (0);
993 fader_vbox.pack_start (*gain_slider, true, true);
995 fader_alignment.set (0.5, 0.5, 0.0, 1.0);
996 fader_alignment.add (fader_vbox);
998 hbox.pack_start (fader_alignment, true, true);
1000 set_spacing (PX_SCALE(2, 2));
1002 pack_start (gain_display_box, Gtk::PACK_SHRINK);
1003 pack_start (hbox, true, true);
1005 meter_alignment.set (0.5, 0.5, 0.0, 1.0);
1006 meter_alignment.add (*level_meter);
1008 meter_metric_area.signal_expose_event().connect (
1009 sigc::mem_fun(*this, &GainMeter::meter_metrics_expose));
1011 meter_ticks1_area.set_size_request (PX_SCALE(3, 3), -1);
1012 meter_ticks2_area.set_size_request (PX_SCALE(3, 3), -1);
1014 meter_ticks1_area.signal_expose_event().connect (
1015 sigc::mem_fun(*this, &GainMeter::meter_ticks1_expose));
1016 meter_ticks2_area.signal_expose_event().connect (
1017 sigc::mem_fun(*this, &GainMeter::meter_ticks2_expose));
1019 meter_hbox.pack_start (meter_ticks1_area, false, false);
1020 meter_hbox.pack_start (meter_alignment, false, false);
1021 meter_hbox.pack_start (meter_ticks2_area, false, false);
1022 meter_hbox.pack_start (meter_metric_area, false, false);
1026 GainMeter::~GainMeter () { }
1029 GainMeter::set_controls (boost::shared_ptr<Route> r,
1030 boost::shared_ptr<PeakMeter> meter,
1031 boost::shared_ptr<Amp> amp,
1032 boost::shared_ptr<GainControl> control)
1034 if (meter_hbox.get_parent()) {
1035 hbox.remove (meter_hbox);
1038 // if (gain_automation_state_button.get_parent()) {
1039 // fader_vbox->remove (gain_automation_state_button);
1042 GainMeterBase::set_controls (r, meter, amp, control);
1045 _meter->ConfigurationChanged.connect (
1046 model_connections, invalidator (*this), boost::bind (&GainMeter::meter_configuration_changed, this, _1), gui_context()
1048 _meter->TypeChanged.connect (
1049 model_connections, invalidator (*this), boost::bind (&GainMeter::meter_type_changed, this, _1), gui_context()
1052 meter_configuration_changed (_meter->input_streams ());
1057 _route->active_changed.connect (model_connections, invalidator (*this), boost::bind (&GainMeter::route_active_changed, this), gui_context ());
1058 hbox.pack_start (meter_hbox, true, true);
1062 // if (r && !r->is_auditioner()) {
1063 // fader_vbox->pack_start (gain_automation_state_button, false, false, 0);
1066 gain_display_box.show ();
1067 gain_display.show ();
1068 gain_slider->show ();
1070 fader_alignment.show ();
1076 GainMeter::get_gm_width ()
1078 Gtk::Requisition sz;
1081 meter_metric_area.size_request (sz);
1083 level_meter->size_request (sz);
1086 fader_alignment.size_request (sz);
1088 return max(sz.width * 2, min_w * 2) + 6;
1090 return sz.width + min_w + 6;
1095 GainMeter::meter_metrics_expose (GdkEventExpose *ev)
1098 if (_types.empty()) { _types.push_back(DataType::AUDIO); }
1099 return meter_expose_metrics(ev, MeterPeak, _types, &meter_metric_area);
1101 return meter_expose_metrics(ev, _route->meter_type(), _types, &meter_metric_area);
1105 GainMeter::meter_ticks1_expose (GdkEventExpose *ev)
1108 if (_types.empty()) { _types.push_back(DataType::AUDIO); }
1109 return meter_expose_ticks(ev, MeterPeak, _types, &meter_ticks1_area);
1111 return meter_expose_ticks(ev, _route->meter_type(), _types, &meter_ticks1_area);
1115 GainMeter::meter_ticks2_expose (GdkEventExpose *ev)
1118 if (_types.empty()) { _types.push_back(DataType::AUDIO); }
1119 return meter_expose_ticks(ev, MeterPeak, _types, &meter_ticks2_area);
1121 return meter_expose_ticks(ev, _route->meter_type(), _types, &meter_ticks2_area);
1125 GainMeter::on_style_changed (const Glib::RefPtr<Gtk::Style>&)
1127 gain_display.queue_draw();
1128 peak_display.queue_draw();
1131 boost::shared_ptr<PBD::Controllable>
1132 GainMeterBase::get_controllable()
1137 return boost::shared_ptr<PBD::Controllable>();
1142 GainMeterBase::level_meter_button_press (GdkEventButton* ev)
1144 return static_cast<bool>(LevelMeterButtonPress (ev)); /* EMIT SIGNAL */
1148 GainMeter::meter_configuration_changed (ChanCount c)
1153 for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) {
1154 if (c.get (*i) > 0) {
1155 _types.push_back (*i);
1161 && boost::dynamic_pointer_cast<AudioTrack>(_route) == 0
1162 && boost::dynamic_pointer_cast<MidiTrack>(_route) == 0
1164 if (_route->active()) {
1165 set_meter_strip_name ("AudioBusMetrics");
1167 set_meter_strip_name ("AudioBusMetricsInactive");
1171 (type == (1 << DataType::MIDI))
1172 || (_route && boost::dynamic_pointer_cast<MidiTrack>(_route))
1174 if (!_route || _route->active()) {
1175 set_meter_strip_name ("MidiTrackMetrics");
1177 set_meter_strip_name ("MidiTrackMetricsInactive");
1180 else if (type == (1 << DataType::AUDIO)) {
1181 if (!_route || _route->active()) {
1182 set_meter_strip_name ("AudioTrackMetrics");
1184 set_meter_strip_name ("AudioTrackMetricsInactive");
1187 if (!_route || _route->active()) {
1188 set_meter_strip_name ("AudioMidiTrackMetrics");
1190 set_meter_strip_name ("AudioMidiTrackMetricsInactive");
1195 meter_clear_pattern_cache(4);
1196 on_style_changed(Glib::RefPtr<Gtk::Style>());
1200 GainMeter::route_active_changed ()
1203 meter_configuration_changed (_meter->input_streams ());
1208 GainMeter::meter_type_changed (MeterType t)
1210 _route->set_meter_type(t);