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);
132 gain_display.set_alignment (0.5);
134 peak_display.set_name ("MixerStripPeakDisplay");
135 set_size_request_to_display_given_text (peak_display, "-80.g", 2, 6); /* note the descender */
136 max_peak = minus_infinity();
137 peak_display.set_text (_("-inf"));
138 peak_display.set_alignment (0.5);
140 /* stuff related to the fact that the peak display is not, in
141 fact, supposed to be a text entry.
143 peak_display.set_events (peak_display.get_events() & ~(Gdk::EventMask (Gdk::LEAVE_NOTIFY_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::POINTER_MOTION_MASK)));
144 peak_display.signal_map().connect (sigc::bind (sigc::ptr_fun (reset_cursor_to_default), &peak_display));
145 peak_display.signal_state_changed().connect (sigc::bind (sigc::ptr_fun (reset_cursor_to_default_state), &peak_display));
146 peak_display.unset_flags (Gtk::CAN_FOCUS);
147 peak_display.set_editable (false);
149 gain_automation_style_button.set_name ("mixer strip button");
150 gain_automation_state_button.set_name ("mixer strip button");
152 set_tooltip (gain_automation_state_button, _("Fader automation mode"));
153 set_tooltip (gain_automation_style_button, _("Fader automation type"));
155 gain_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
156 gain_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
158 gain_automation_state_button.set_size_request(15, 15);
159 gain_automation_style_button.set_size_request(15, 15);
161 gain_astyle_menu.items().push_back (MenuElem (_("Trim")));
162 gain_astyle_menu.items().push_back (MenuElem (_("Abs")));
164 gain_astate_menu.set_name ("ArdourContextMenu");
165 gain_astate_menu.set_reserve_toggle_size(false);
166 gain_astyle_menu.set_name ("ArdourContextMenu");
168 gain_adjustment.signal_value_changed().connect (sigc::mem_fun(*this, &GainMeterBase::fader_moved));
169 peak_display.signal_button_release_event().connect (sigc::mem_fun(*this, &GainMeterBase::peak_button_release), false);
170 gain_display.signal_key_press_event().connect (sigc::mem_fun(*this, &GainMeterBase::gain_key_press), false);
172 ResetAllPeakDisplays.connect (sigc::mem_fun(*this, &GainMeterBase::reset_peak_display));
173 ResetRoutePeakDisplays.connect (sigc::mem_fun(*this, &GainMeterBase::reset_route_peak_display));
174 ResetGroupPeakDisplays.connect (sigc::mem_fun(*this, &GainMeterBase::reset_group_peak_display));
175 RedrawMetrics.connect (sigc::mem_fun(*this, &GainMeterBase::redraw_metrics));
177 UI::instance()->theme_changed.connect (sigc::mem_fun(*this, &GainMeterBase::on_theme_changed));
178 UIConfiguration::instance().ColorsChanged.connect (sigc::bind(sigc::mem_fun (*this, &GainMeterBase::color_handler), false));
179 UIConfiguration::instance().DPIReset.connect (sigc::bind(sigc::mem_fun (*this, &GainMeterBase::color_handler), true));
182 GainMeterBase::~GainMeterBase ()
189 GainMeterBase::set_controls (boost::shared_ptr<Route> r,
190 boost::shared_ptr<PeakMeter> pm,
191 boost::shared_ptr<Amp> amp,
192 boost::shared_ptr<GainControl> control)
194 connections.clear ();
195 model_connections.drop_connections ();
197 /* no meter and no control? nothing to do ... */
199 if (!pm && !control) {
200 level_meter->set_meter (0);
201 gain_slider->set_controllable (boost::shared_ptr<PBD::Controllable>());
214 level_meter->set_meter (pm.get());
215 gain_slider->set_controllable (_control);
218 amp->ConfigurationChanged.connect (
219 model_connections, invalidator (*this), boost::bind (&GainMeterBase::setup_gain_adjustment, this), gui_context ()
223 setup_gain_adjustment ();
225 if (!_route || !_route->is_auditioner()) {
227 using namespace Menu_Helpers;
229 gain_astate_menu.items().clear ();
231 gain_astate_menu.items().push_back (MenuElem (S_("Automation|Manual"),
232 sigc::bind (sigc::mem_fun (*this, &GainMeterBase::set_gain_astate), (AutoState) ARDOUR::Off)));
233 gain_astate_menu.items().push_back (MenuElem (_("Play"),
234 sigc::bind (sigc::mem_fun (*this, &GainMeterBase::set_gain_astate), (AutoState) ARDOUR::Play)));
235 gain_astate_menu.items().push_back (MenuElem (_("Write"),
236 sigc::bind (sigc::mem_fun (*this, &GainMeterBase::set_gain_astate), (AutoState) ARDOUR::Write)));
237 gain_astate_menu.items().push_back (MenuElem (_("Touch"),
238 sigc::bind (sigc::mem_fun (*this, &GainMeterBase::set_gain_astate), (AutoState) ARDOUR::Touch)));
240 connections.push_back (gain_automation_style_button.signal_button_press_event().connect (sigc::mem_fun(*this, &GainMeterBase::gain_automation_style_button_event), false));
241 connections.push_back (gain_automation_state_button.signal_button_press_event().connect (sigc::mem_fun(*this, &GainMeterBase::gain_automation_state_button_event), false));
242 connections.push_back (ChangeGainAutomationState.connect (sigc::mem_fun(*this, &GainMeterBase::set_gain_astate)));
244 _control->alist()->automation_state_changed.connect (model_connections, invalidator (*this), boost::bind (&GainMeter::gain_automation_state_changed, this), gui_context());
245 _control->alist()->automation_style_changed.connect (model_connections, invalidator (*this), boost::bind (&GainMeter::gain_automation_style_changed, this), gui_context());
247 gain_automation_state_changed ();
250 _control->Changed.connect (model_connections, invalidator (*this), boost::bind (&GainMeterBase::gain_changed, this), gui_context());
254 update_gain_sensitive ();
257 peak_display.hide ();
259 peak_display.show ();
264 GainMeterBase::set_gain_astate (AutoState as)
266 if (gain_astate_propagate) {
267 gain_astate_propagate = false;
268 ChangeGainAutomationState (as);
271 _amp->set_parameter_automation_state (Evoral::Parameter (GainAutomation), as);
275 GainMeterBase::setup_gain_adjustment ()
281 if (_previous_amp_output_streams == _amp->output_streams ()) {
285 ignore_toggle = true;
287 if (_amp->output_streams().n_midi() <= _amp->output_streams().n_audio()) {
288 _data_type = DataType::AUDIO;
289 gain_adjustment.set_lower (GAIN_COEFF_ZERO);
290 gain_adjustment.set_upper (GAIN_COEFF_UNITY);
291 gain_adjustment.set_step_increment (dB_coeff_step(Config->get_max_gain()) / 10.0);
292 gain_adjustment.set_page_increment (dB_coeff_step(Config->get_max_gain()));
293 gain_slider->set_default_value (gain_to_slider_position (GAIN_COEFF_UNITY));
295 _data_type = DataType::MIDI;
296 gain_adjustment.set_lower (0.0);
297 gain_adjustment.set_upper (2.0);
298 gain_adjustment.set_step_increment (1.0/128.0);
299 gain_adjustment.set_page_increment (10.0/128.0);
300 gain_slider->set_default_value (1.0);
303 ignore_toggle = false;
305 effective_gain_display ();
307 _previous_amp_output_streams = _amp->output_streams ();
311 GainMeterBase::hide_all_meters ()
313 level_meter->hide_meters();
317 GainMeter::hide_all_meters ()
319 GainMeterBase::hide_all_meters ();
323 GainMeterBase::setup_meters (int len)
326 uint32_t meter_channels = 0;
328 meter_channels = _meter->input_streams().n_total();
330 meter_channels = _route->shared_peak_meter()->input_streams().n_total();
335 //meter_ticks1_area.show();
336 //meter_ticks2_area.show();
337 meter_metric_area.show();
338 if (meter_channels == 1) {
343 if (meter_channels > 1) {
346 //meter_ticks1_area.hide();
347 //meter_ticks2_area.hide();
348 meter_metric_area.hide();
351 level_meter->setup_meters(len, meter_width);
355 GainMeterBase::set_type (MeterType t)
357 level_meter->set_type(t);
361 GainMeter::setup_meters (int len)
366 uint32_t meter_channels = 0;
368 meter_channels = _meter->input_streams().n_total();
370 meter_channels = _route->shared_peak_meter()->input_streams().n_total();
372 hbox.set_homogeneous(meter_channels < 7 ? true : false);
376 hbox.set_homogeneous(false);
379 GainMeterBase::setup_meters (len);
383 GainMeter::set_type (MeterType t)
385 GainMeterBase::set_type (t);
389 GainMeterBase::gain_key_press (GdkEventKey* ev)
391 if (key_is_legal_for_numeric_entry (ev->keyval)) {
392 /* drop through to normal handling */
395 /* illegal key for gain entry */
400 GainMeterBase::peak_button_release (GdkEventButton* ev)
402 /* reset peak label */
404 if (ev->button == 1 && Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier|Keyboard::TertiaryModifier)) {
405 ResetAllPeakDisplays ();
406 } else if (ev->button == 1 && Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
408 ResetGroupPeakDisplays (_route->route_group());
411 ResetRoutePeakDisplays (_route.get());
418 GainMeterBase::reset_peak_display ()
421 level_meter->clear_meters();
422 max_peak = minus_infinity ();
423 peak_display.set_text (_("-inf"));
424 peak_display.set_name ("MixerStripPeakDisplay");
428 GainMeterBase::reset_route_peak_display (Route* route)
430 if (_route && _route.get() == route) {
431 reset_peak_display ();
436 GainMeterBase::reset_group_peak_display (RouteGroup* group)
438 if (_route && group == _route->route_group()) {
439 reset_peak_display ();
444 GainMeterBase::popup_meter_menu (GdkEventButton *ev)
446 using namespace Menu_Helpers;
448 if (meter_menu == 0) {
449 meter_menu = new Gtk::Menu;
450 MenuList& items = meter_menu->items();
452 items.push_back (MenuElem ("-inf .. +0dBFS"));
453 items.push_back (MenuElem ("-10dB .. +0dBFS"));
454 items.push_back (MenuElem ("-4 .. +0dBFS"));
455 items.push_back (SeparatorElem());
456 items.push_back (MenuElem ("-inf .. -2dBFS"));
457 items.push_back (MenuElem ("-10dB .. -2dBFS"));
458 items.push_back (MenuElem ("-4 .. -2dBFS"));
461 meter_menu->popup (1, ev->time);
465 GainMeterBase::gain_focused (GdkEventFocus* ev)
468 gain_display.select_region (0, -1);
470 gain_display.select_region (0, 0);
476 GainMeterBase::gain_activated ()
481 // Switch to user's preferred locale so that
482 // if they use different LC_NUMERIC conventions,
483 // we will honor them.
486 if (sscanf (gain_display.get_text().c_str(), "%f", &f) != 1) {
491 /* clamp to displayable values */
492 if (_data_type == DataType::AUDIO) {
494 _control->set_value (dB_to_coefficient(f), Controllable::UseGroup);
496 f = min (fabs (f), 2.0f);
497 _control->set_value (f, Controllable::UseGroup);
500 if (gain_display.has_focus()) {
501 Gtk::Widget* w = gain_display.get_toplevel();
503 Gtk::Window* win = dynamic_cast<Gtk::Window*> (w);
505 /* sigh. gtkmm doesn't wrap get_default_widget() */
508 GtkWidget* f = gtk_window_get_default_widget (win->gobj());
510 gtk_widget_grab_focus (f);
519 GainMeterBase::show_gain ()
523 float v = gain_adjustment.get_value();
525 switch (_data_type) {
526 case DataType::AUDIO:
528 strcpy (buf, _("-inf"));
530 snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain_with_max (v, Config->get_max_gain())));
534 snprintf (buf, sizeof (buf), "%.1f", v);
538 gain_display.set_text (buf);
542 GainMeterBase::fader_moved ()
544 if (!ignore_toggle) {
548 /* convert from adjustment range (0..1) to gain coefficient */
550 if (_data_type == DataType::AUDIO) {
551 value = slider_position_to_gain_with_max (gain_adjustment.get_value(), Config->get_max_gain());
553 value = gain_adjustment.get_value();
556 _control->set_value (value, Controllable::UseGroup);
563 GainMeterBase::effective_gain_display ()
565 gain_t fader_position = 0;
567 switch (_data_type) {
568 case DataType::AUDIO:
569 /* the position of the fader should reflect any master gain,
570 * not just the control's own inherent value
572 fader_position = gain_to_slider_position_with_max (_control->get_value(), Config->get_max_gain());
575 fader_position = _control->get_value ();
579 if (gain_adjustment.get_value() != fader_position) {
580 ignore_toggle = true;
581 gain_adjustment.set_value (fader_position);
582 ignore_toggle = false;
587 GainMeterBase::gain_changed ()
589 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&GainMeterBase::effective_gain_display, this));
593 GainMeterBase::set_meter_strip_name (const char * name)
596 meter_metric_area.set_name (name);
597 sprintf(tmp, "Mark%sLeft", name);
598 meter_ticks1_area.set_name (tmp);
599 sprintf(tmp, "Mark%sRight", name);
600 meter_ticks2_area.set_name (tmp);
604 GainMeterBase::set_fader_name (const char * name)
606 gain_slider->set_name (name);
610 GainMeterBase::update_gain_sensitive ()
612 bool x = !(_control->alist()->automation_state() & Play);
613 static_cast<Gtkmm2ext::SliderController*>(gain_slider)->set_sensitive (x);
617 next_meter_point (MeterPoint mp)
621 return MeterPreFader;
625 return MeterPostFader;
641 abort(); /*NOTREACHED*/
646 GainMeterBase::meter_press(GdkEventButton* ev)
648 wait_for_release = false;
654 if (!ignore_toggle) {
656 if (Keyboard::is_context_menu_event (ev)) {
658 // no menu at this time.
662 if (Keyboard::is_button2_event(ev)) {
664 // Primary-button2 click is the midi binding click
665 // button2-click is "momentary"
667 if (!Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier))) {
668 wait_for_release = true;
669 old_meter_point = _route->meter_point ();
673 if (_route && (ev->button == 1 || Keyboard::is_button2_event (ev))) {
675 if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
677 /* Primary+Tertiary-click applies change to all routes */
679 _session->foreach_route (this, &GainMeterBase::set_meter_point, next_meter_point (_route->meter_point()));
682 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
684 /* Primary-click: solo mix group.
685 NOTE: Primary-button2 is MIDI learn.
688 if (ev->button == 1) {
689 set_route_group_meter_point (*_route, next_meter_point (_route->meter_point()));
694 /* click: change just this route */
698 _route->set_meter_point (next_meter_point (_route->meter_point()));
709 GainMeterBase::meter_release(GdkEventButton*)
711 if (!ignore_toggle) {
712 if (wait_for_release) {
713 wait_for_release = false;
716 set_meter_point (*_route, old_meter_point);
725 GainMeterBase::set_meter_point (Route& route, MeterPoint mp)
727 route.set_meter_point (mp);
731 GainMeterBase::set_route_group_meter_point (Route& route, MeterPoint mp)
733 RouteGroup* route_group;
735 if ((route_group = route.route_group ()) != 0) {
736 route_group->foreach_route (boost::bind (&Route::set_meter_point, _1, mp, false));
738 route.set_meter_point (mp);
743 GainMeterBase::meter_point_clicked ()
751 GainMeterBase::amp_start_touch ()
753 _control->start_touch (_control->session().transport_frame());
757 GainMeterBase::amp_stop_touch ()
759 _control->stop_touch (false, _control->session().transport_frame());
763 GainMeterBase::gain_automation_state_button_event (GdkEventButton *ev)
765 if (ev->type == GDK_BUTTON_RELEASE) {
769 switch (ev->button) {
771 gain_astate_propagate = Keyboard::modifier_state_contains (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier | Keyboard::TertiaryModifier));
772 Gtkmm2ext::anchored_menu_popup(&gain_astate_menu,
773 &gain_automation_state_button,
784 GainMeterBase::gain_automation_style_button_event (GdkEventButton *ev)
786 if (ev->type == GDK_BUTTON_RELEASE) {
790 switch (ev->button) {
792 gain_astyle_menu.popup (1, ev->time);
801 GainMeterBase::astate_string (AutoState state)
803 return _astate_string (state, false);
807 GainMeterBase::short_astate_string (AutoState state)
809 return _astate_string (state, true);
813 GainMeterBase::_astate_string (AutoState state, bool shrt)
819 sstr = (shrt ? "M" : _("M"));
822 sstr = (shrt ? "P" : _("P"));
825 sstr = (shrt ? "T" : _("T"));
828 sstr = (shrt ? "W" : _("W"));
836 GainMeterBase::astyle_string (AutoStyle style)
838 return _astyle_string (style, false);
842 GainMeterBase::short_astyle_string (AutoStyle style)
844 return _astyle_string (style, true);
848 GainMeterBase::_astyle_string (AutoStyle style, bool shrt)
853 /* XXX it might different in different languages */
855 return (shrt ? _("Abs") : _("Abs"));
860 GainMeterBase::gain_automation_style_changed ()
864 gain_automation_style_button.set_text (astyle_string(_control->alist()->automation_style()));
867 gain_automation_style_button.set_text (short_astyle_string(_control->alist()->automation_style()));
873 GainMeterBase::gain_automation_state_changed ()
875 ENSURE_GUI_THREAD (*this, &GainMeterBase::gain_automation_state_changed);
879 gain_automation_state_button.set_text (astate_string(_control->alist()->automation_state()));
882 gain_automation_state_button.set_text (short_astate_string(_control->alist()->automation_state()));
886 const bool automation_watch_required = (_control->alist()->automation_state() != ARDOUR::Off);
888 if (gain_automation_state_button.get_active() != automation_watch_required) {
889 ignore_toggle = true;
890 gain_automation_state_button.set_active (automation_watch_required);
891 ignore_toggle = false;
894 update_gain_sensitive ();
896 gain_watching.disconnect();
898 if (automation_watch_required) {
899 /* start watching automation so that things move */
900 gain_watching = Timers::rapid_connect (sigc::mem_fun (*this, &GainMeterBase::effective_gain_display));
902 /* update once to get the correct value shown as we re-enter off/manual mode */
903 effective_gain_display();
908 GainMeterBase::meter_channels() const
910 if (_meter) { return _meter->input_streams(); }
911 else { return ChanCount(); }
914 GainMeterBase::update_meters()
917 float mpeak = level_meter->update_meters();
919 if (mpeak > max_peak) {
921 if (mpeak <= -200.0f) {
922 peak_display.set_text (_("-inf"));
924 snprintf (buf, sizeof(buf), "%.1f", mpeak);
925 peak_display.set_text (buf);
928 if (mpeak >= UIConfiguration::instance().get_meter_peak()) {
929 peak_display.set_name ("MixerStripPeakDisplayPeak");
933 void GainMeterBase::color_handler(bool /*dpi*/)
939 GainMeterBase::set_width (Width w, int len)
943 if (_width == Wide && _route && _route->shared_peak_meter()->input_streams().n_total() == 1) {
946 level_meter->setup_meters(len, meter_width);
951 GainMeterBase::on_theme_changed()
956 GainMeterBase::redraw_metrics()
958 meter_metric_area.queue_draw ();
959 meter_ticks1_area.queue_draw ();
960 meter_ticks2_area.queue_draw ();
963 #define PX_SCALE(pxmin, dflt) rint(std::max((double)pxmin, (double)dflt * UIConfiguration::instance().get_ui_scale()))
965 GainMeter::GainMeter (Session* s, int fader_length)
966 : GainMeterBase (s, false, fader_length, 24)
967 , gain_display_box(true, 0)
970 if (gain_display.get_parent()) {
971 gain_display.get_parent()->remove (gain_display);
973 gain_display_box.pack_start (gain_display, true, true);
975 if (peak_display.get_parent()) {
976 peak_display.get_parent()->remove (gain_display);
978 gain_display_box.pack_start (peak_display, true, true);
980 meter_metric_area.set_name ("AudioTrackMetrics");
981 meter_metric_area.set_size_request(PX_SCALE(24, 24), -1);
983 gain_automation_style_button.set_name ("mixer strip button");
984 gain_automation_state_button.set_name ("mixer strip button");
986 set_tooltip (gain_automation_state_button, _("Fader automation mode"));
987 set_tooltip (gain_automation_style_button, _("Fader automation type"));
989 gain_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
990 gain_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
992 gain_automation_state_button.set_size_request (PX_SCALE(12, 15), PX_SCALE(12, 15));
993 gain_automation_style_button.set_size_request (PX_SCALE(12, 15), PX_SCALE(12, 15));
995 fader_vbox.set_spacing (0);
996 fader_vbox.pack_start (*gain_slider, true, true);
998 fader_alignment.set (0.5, 0.5, 0.0, 1.0);
999 fader_alignment.add (fader_vbox);
1001 hbox.pack_start (fader_alignment, true, true);
1003 set_spacing (PX_SCALE(2, 2));
1005 pack_start (gain_display_box, Gtk::PACK_SHRINK);
1006 pack_start (hbox, true, true);
1008 meter_alignment.set (0.5, 0.5, 0.0, 1.0);
1009 meter_alignment.add (*level_meter);
1011 meter_metric_area.signal_expose_event().connect (
1012 sigc::mem_fun(*this, &GainMeter::meter_metrics_expose));
1014 meter_ticks1_area.set_size_request (PX_SCALE(3, 3), -1);
1015 meter_ticks2_area.set_size_request (PX_SCALE(3, 3), -1);
1017 meter_ticks1_area.signal_expose_event().connect (
1018 sigc::mem_fun(*this, &GainMeter::meter_ticks1_expose));
1019 meter_ticks2_area.signal_expose_event().connect (
1020 sigc::mem_fun(*this, &GainMeter::meter_ticks2_expose));
1022 meter_hbox.pack_start (meter_ticks1_area, false, false);
1023 meter_hbox.pack_start (meter_alignment, false, false);
1024 meter_hbox.pack_start (meter_ticks2_area, false, false);
1025 meter_hbox.pack_start (meter_metric_area, false, false);
1029 GainMeter::~GainMeter () { }
1032 GainMeter::set_controls (boost::shared_ptr<Route> r,
1033 boost::shared_ptr<PeakMeter> meter,
1034 boost::shared_ptr<Amp> amp,
1035 boost::shared_ptr<GainControl> control)
1037 if (meter_hbox.get_parent()) {
1038 hbox.remove (meter_hbox);
1041 // if (gain_automation_state_button.get_parent()) {
1042 // fader_vbox->remove (gain_automation_state_button);
1045 GainMeterBase::set_controls (r, meter, amp, control);
1048 _meter->ConfigurationChanged.connect (
1049 model_connections, invalidator (*this), boost::bind (&GainMeter::meter_configuration_changed, this, _1), gui_context()
1051 _meter->TypeChanged.connect (
1052 model_connections, invalidator (*this), boost::bind (&GainMeter::meter_type_changed, this, _1), gui_context()
1055 meter_configuration_changed (_meter->input_streams ());
1060 _route->active_changed.connect (model_connections, invalidator (*this), boost::bind (&GainMeter::route_active_changed, this), gui_context ());
1061 hbox.pack_start (meter_hbox, true, true);
1065 // if (r && !r->is_auditioner()) {
1066 // fader_vbox->pack_start (gain_automation_state_button, false, false, 0);
1069 gain_display_box.show ();
1070 gain_display.show ();
1071 gain_slider->show ();
1073 fader_alignment.show ();
1079 GainMeter::get_gm_width ()
1081 Gtk::Requisition sz;
1084 meter_metric_area.size_request (sz);
1086 level_meter->size_request (sz);
1089 fader_alignment.size_request (sz);
1091 return max(sz.width * 2, min_w * 2) + 6;
1093 return sz.width + min_w + 6;
1098 GainMeter::meter_metrics_expose (GdkEventExpose *ev)
1101 if (_types.empty()) { _types.push_back(DataType::AUDIO); }
1102 return meter_expose_metrics(ev, MeterPeak, _types, &meter_metric_area);
1104 return meter_expose_metrics(ev, _route->meter_type(), _types, &meter_metric_area);
1108 GainMeter::meter_ticks1_expose (GdkEventExpose *ev)
1111 if (_types.empty()) { _types.push_back(DataType::AUDIO); }
1112 return meter_expose_ticks(ev, MeterPeak, _types, &meter_ticks1_area);
1114 return meter_expose_ticks(ev, _route->meter_type(), _types, &meter_ticks1_area);
1118 GainMeter::meter_ticks2_expose (GdkEventExpose *ev)
1121 if (_types.empty()) { _types.push_back(DataType::AUDIO); }
1122 return meter_expose_ticks(ev, MeterPeak, _types, &meter_ticks2_area);
1124 return meter_expose_ticks(ev, _route->meter_type(), _types, &meter_ticks2_area);
1128 GainMeter::on_style_changed (const Glib::RefPtr<Gtk::Style>&)
1130 gain_display.queue_draw();
1131 peak_display.queue_draw();
1134 boost::shared_ptr<PBD::Controllable>
1135 GainMeterBase::get_controllable()
1140 return boost::shared_ptr<PBD::Controllable>();
1145 GainMeterBase::level_meter_button_press (GdkEventButton* ev)
1147 return static_cast<bool>(LevelMeterButtonPress (ev)); /* EMIT SIGNAL */
1151 GainMeter::meter_configuration_changed (ChanCount c)
1156 for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) {
1157 if (c.get (*i) > 0) {
1158 _types.push_back (*i);
1164 && boost::dynamic_pointer_cast<AudioTrack>(_route) == 0
1165 && boost::dynamic_pointer_cast<MidiTrack>(_route) == 0
1167 if (_route->active()) {
1168 set_meter_strip_name ("AudioBusMetrics");
1170 set_meter_strip_name ("AudioBusMetricsInactive");
1174 (type == (1 << DataType::MIDI))
1175 || (_route && boost::dynamic_pointer_cast<MidiTrack>(_route))
1177 if (!_route || _route->active()) {
1178 set_meter_strip_name ("MidiTrackMetrics");
1180 set_meter_strip_name ("MidiTrackMetricsInactive");
1183 else if (type == (1 << DataType::AUDIO)) {
1184 if (!_route || _route->active()) {
1185 set_meter_strip_name ("AudioTrackMetrics");
1187 set_meter_strip_name ("AudioTrackMetricsInactive");
1190 if (!_route || _route->active()) {
1191 set_meter_strip_name ("AudioMidiTrackMetrics");
1193 set_meter_strip_name ("AudioMidiTrackMetricsInactive");
1198 meter_clear_pattern_cache(4);
1199 on_style_changed(Glib::RefPtr<Gtk::Style>());
1203 GainMeter::route_active_changed ()
1206 meter_configuration_changed (_meter->input_streams ());
1211 GainMeter::meter_type_changed (MeterType t)
1213 _route->set_meter_type(t);