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/io.h"
24 #include "ardour/route.h"
25 #include "ardour/route_group.h"
26 #include "ardour/session.h"
27 #include "ardour/session_route.h"
28 #include "ardour/dB.h"
29 #include "ardour/utils.h"
31 #include <gtkmm/style.h>
32 #include <gdkmm/color.h>
33 #include <gtkmm2ext/utils.h>
34 #include <gtkmm2ext/fastmeter.h>
35 #include <gtkmm2ext/barcontroller.h>
36 #include <gtkmm2ext/gtk_ui.h>
37 #include "midi++/manager.h"
38 #include "pbd/fastlog.h"
39 #include "pbd/stacktrace.h"
41 #include "ardour_ui.h"
42 #include "gain_meter.h"
43 #include "global_signals.h"
45 #include "gui_thread.h"
47 #include "public_editor.h"
50 #include "ardour/session.h"
51 #include "ardour/route.h"
52 #include "ardour/meter.h"
56 using namespace ARDOUR;
58 using namespace Gtkmm2ext;
61 using Gtkmm2ext::Keyboard;
63 sigc::signal<void> GainMeterBase::ResetAllPeakDisplays;
64 sigc::signal<void,RouteGroup*> GainMeterBase::ResetGroupPeakDisplays;
66 GainMeter::MetricPatterns GainMeter::metric_patterns;
67 Glib::RefPtr<Gdk::Pixbuf> GainMeter::slider;
71 GainMeter::setup_slider_pix ()
73 if ((slider = ::get_icon ("fader_belt")) == 0) {
74 throw failed_constructor();
78 GainMeterBase::GainMeterBase (Session* s,
79 const Glib::RefPtr<Gdk::Pixbuf>& pix,
82 : gain_adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain()), 0.0, 1.0, 0.01, 0.1)
83 , gain_automation_style_button ("")
84 , gain_automation_state_button ("")
85 , style_changed (false)
90 using namespace Menu_Helpers;
94 ignore_toggle = false;
96 next_release_selects = false;
100 gain_slider = manage (new HSliderController (pix,
105 gain_slider = manage (new VSliderController (pix,
111 level_meter = new LevelMeter(_session);
113 gain_slider->signal_button_press_event().connect (sigc::mem_fun(*this, &GainMeter::gain_slider_button_press));
114 gain_slider->signal_button_release_event().connect (sigc::mem_fun(*this, &GainMeter::gain_slider_button_release));
115 gain_slider->set_name ("GainFader");
117 gain_display.set_name ("MixerStripGainDisplay");
118 set_size_request_to_display_given_text (gain_display, "-80.g", 2, 6); /* note the descender */
119 gain_display.signal_activate().connect (sigc::mem_fun (*this, &GainMeter::gain_activated));
120 gain_display.signal_focus_in_event().connect (sigc::mem_fun (*this, &GainMeter::gain_focused), false);
121 gain_display.signal_focus_out_event().connect (sigc::mem_fun (*this, &GainMeter::gain_focused), false);
123 peak_display.set_name ("MixerStripPeakDisplay");
124 set_size_request_to_display_given_text (peak_display, "-80.g", 2, 6); /* note the descender */
125 max_peak = minus_infinity();
126 peak_display.set_label (_("-inf"));
127 peak_display.unset_flags (Gtk::CAN_FOCUS);
129 gain_automation_style_button.set_name ("MixerAutomationModeButton");
130 gain_automation_state_button.set_name ("MixerAutomationPlaybackButton");
132 ARDOUR_UI::instance()->set_tip (gain_automation_state_button, _("Fader automation mode"));
133 ARDOUR_UI::instance()->set_tip (gain_automation_style_button, _("Fader automation type"));
135 gain_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
136 gain_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
138 gain_automation_state_button.set_size_request(15, 15);
139 gain_automation_style_button.set_size_request(15, 15);
141 gain_astyle_menu.items().push_back (MenuElem (_("Trim")));
142 gain_astyle_menu.items().push_back (MenuElem (_("Abs")));
144 gain_astate_menu.set_name ("ArdourContextMenu");
145 gain_astyle_menu.set_name ("ArdourContextMenu");
147 gain_adjustment.signal_value_changed().connect (sigc::mem_fun(*this, &GainMeterBase::gain_adjusted));
148 peak_display.signal_button_release_event().connect (sigc::mem_fun(*this, &GainMeterBase::peak_button_release), false);
149 gain_display.signal_key_press_event().connect (sigc::mem_fun(*this, &GainMeterBase::gain_key_press), false);
151 ResetAllPeakDisplays.connect (sigc::mem_fun(*this, &GainMeterBase::reset_peak_display));
152 ResetGroupPeakDisplays.connect (sigc::mem_fun(*this, &GainMeterBase::reset_group_peak_display));
154 UI::instance()->theme_changed.connect (sigc::mem_fun(*this, &GainMeterBase::on_theme_changed));
155 ColorsChanged.connect (sigc::bind(sigc::mem_fun (*this, &GainMeterBase::color_handler), false));
156 DPIReset.connect (sigc::bind(sigc::mem_fun (*this, &GainMeterBase::color_handler), true));
159 GainMeterBase::~GainMeterBase ()
166 GainMeterBase::set_controls (boost::shared_ptr<Route> r,
167 boost::shared_ptr<PeakMeter> pm,
168 boost::shared_ptr<Amp> amp)
170 connections.clear ();
171 model_connections.drop_connections ();
174 level_meter->set_meter (0);
175 gain_slider->set_controllable (boost::shared_ptr<PBD::Controllable>());
186 level_meter->set_meter (pm.get());
187 gain_slider->set_controllable (amp->gain_control());
190 amp->ConfigurationChanged.connect (
191 model_connections, invalidator (*this), ui_bind (&GainMeterBase::setup_gain_adjustment, this), gui_context ()
195 setup_gain_adjustment ();
197 if (!_route || !_route->is_hidden()) {
199 using namespace Menu_Helpers;
201 gain_astate_menu.items().clear ();
203 gain_astate_menu.items().push_back (MenuElem (_("Manual"),
204 sigc::bind (sigc::mem_fun (*(amp.get()), &Automatable::set_parameter_automation_state),
205 Evoral::Parameter(GainAutomation), (AutoState) Off)));
206 gain_astate_menu.items().push_back (MenuElem (_("Play"),
207 sigc::bind (sigc::mem_fun (*(amp.get()), &Automatable::set_parameter_automation_state),
208 Evoral::Parameter(GainAutomation), (AutoState) Play)));
209 gain_astate_menu.items().push_back (MenuElem (_("Write"),
210 sigc::bind (sigc::mem_fun (*(amp.get()), &Automatable::set_parameter_automation_state),
211 Evoral::Parameter(GainAutomation), (AutoState) Write)));
212 gain_astate_menu.items().push_back (MenuElem (_("Touch"),
213 sigc::bind (sigc::mem_fun (*(amp.get()), &Automatable::set_parameter_automation_state),
214 Evoral::Parameter(GainAutomation), (AutoState) Touch)));
216 connections.push_back (gain_automation_style_button.signal_button_press_event().connect (sigc::mem_fun(*this, &GainMeterBase::gain_automation_style_button_event), false));
217 connections.push_back (gain_automation_state_button.signal_button_press_event().connect (sigc::mem_fun(*this, &GainMeterBase::gain_automation_state_button_event), false));
219 boost::shared_ptr<AutomationControl> gc = amp->gain_control();
221 gc->alist()->automation_state_changed.connect (model_connections, invalidator (*this), boost::bind (&GainMeter::gain_automation_state_changed, this), gui_context());
222 gc->alist()->automation_style_changed.connect (model_connections, invalidator (*this), boost::bind (&GainMeter::gain_automation_style_changed, this), gui_context());
224 gain_automation_state_changed ();
227 amp->gain_control()->Changed.connect (model_connections, invalidator (*this), boost::bind (&GainMeterBase::gain_changed, this), gui_context());
231 update_gain_sensitive ();
235 GainMeterBase::setup_gain_adjustment ()
241 if (_previous_amp_output_streams == _amp->output_streams ()) {
245 ignore_toggle = true;
247 if (_amp->output_streams().n_midi() == 0) {
249 gain_adjustment.set_lower (0.0);
250 gain_adjustment.set_upper (1.0);
251 gain_adjustment.set_step_increment (0.01);
252 gain_adjustment.set_page_increment (0.1);
253 gain_slider->set_default_value (gain_to_slider_position (1));
256 gain_adjustment.set_lower (0.0);
257 gain_adjustment.set_upper (2.0);
258 gain_adjustment.set_step_increment (0.05);
259 gain_adjustment.set_page_increment (0.1);
260 gain_slider->set_default_value (1);
263 ignore_toggle = false;
265 effective_gain_display ();
267 _previous_amp_output_streams = _amp->output_streams ();
271 GainMeterBase::hide_all_meters ()
273 level_meter->hide_meters();
277 GainMeter::hide_all_meters ()
279 bool remove_metric_area = false;
281 GainMeterBase::hide_all_meters ();
283 if (remove_metric_area) {
284 if (meter_metric_area.get_parent()) {
285 level_meter->remove (meter_metric_area);
291 GainMeterBase::setup_meters (int len)
293 level_meter->setup_meters(len, 5);
297 GainMeter::setup_meters (int len)
299 if (!meter_metric_area.get_parent()) {
300 level_meter->pack_end (meter_metric_area, false, false);
301 meter_metric_area.show_all ();
303 GainMeterBase::setup_meters (len);
307 GainMeterBase::gain_key_press (GdkEventKey* ev)
309 if (key_is_legal_for_numeric_entry (ev->keyval)) {
310 /* drop through to normal handling */
313 /* illegal key for gain entry */
318 GainMeterBase::peak_button_release (GdkEventButton* ev)
320 /* reset peak label */
322 if (ev->button == 1 && Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier|Keyboard::TertiaryModifier)) {
323 ResetAllPeakDisplays ();
324 } else if (ev->button == 1 && Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
326 ResetGroupPeakDisplays (_route->route_group());
329 reset_peak_display ();
336 GainMeterBase::reset_peak_display ()
339 level_meter->clear_meters();
340 max_peak = -INFINITY;
341 peak_display.set_label (_("-Inf"));
342 peak_display.set_name ("MixerStripPeakDisplay");
346 GainMeterBase::reset_group_peak_display (RouteGroup* group)
348 if (_route && group == _route->route_group()) {
349 reset_peak_display ();
354 GainMeterBase::popup_meter_menu (GdkEventButton *ev)
356 using namespace Menu_Helpers;
358 if (meter_menu == 0) {
359 meter_menu = new Gtk::Menu;
360 MenuList& items = meter_menu->items();
362 items.push_back (MenuElem ("-inf .. +0dBFS"));
363 items.push_back (MenuElem ("-10dB .. +0dBFS"));
364 items.push_back (MenuElem ("-4 .. +0dBFS"));
365 items.push_back (SeparatorElem());
366 items.push_back (MenuElem ("-inf .. -2dBFS"));
367 items.push_back (MenuElem ("-10dB .. -2dBFS"));
368 items.push_back (MenuElem ("-4 .. -2dBFS"));
371 meter_menu->popup (1, ev->time);
375 GainMeterBase::gain_focused (GdkEventFocus* ev)
378 gain_display.select_region (0, -1);
380 gain_display.select_region (0, 0);
386 GainMeterBase::gain_activated ()
390 if (sscanf (gain_display.get_text().c_str(), "%f", &f) == 1) {
392 /* clamp to displayable values */
396 _amp->set_gain (dB_to_coefficient(f), this);
398 if (gain_display.has_focus()) {
399 PublicEditor::instance().reset_focus();
405 GainMeterBase::show_gain ()
409 float v = gain_adjustment.get_value();
413 strcpy (buf, _("-inf"));
415 snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain_with_max (v, Config->get_max_gain())));
418 snprintf (buf, sizeof (buf), "%.1f", v);
421 gain_display.set_text (buf);
425 GainMeterBase::gain_adjusted ()
427 if (!ignore_toggle) {
428 if (_route && _route->amp() == _amp) {
430 _route->set_gain (gain_adjustment.get_value(), this);
432 _route->set_gain (slider_position_to_gain_with_max (gain_adjustment.get_value(), Config->get_max_gain()), this);
435 _amp->set_gain (slider_position_to_gain_with_max (gain_adjustment.get_value(), Config->get_max_gain()), this);
443 GainMeterBase::effective_gain_display ()
448 value = gain_to_slider_position_with_max (_amp->gain(), Config->get_max_gain());
450 value = _amp->gain ();
453 if (gain_adjustment.get_value() != value) {
454 ignore_toggle = true;
455 gain_adjustment.set_value (value);
456 ignore_toggle = false;
461 GainMeterBase::gain_changed ()
463 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&GainMeterBase::effective_gain_display, this));
467 GainMeterBase::set_meter_strip_name (const char * name)
469 meter_metric_area.set_name (name);
473 GainMeterBase::set_fader_name (const char * name)
475 uint32_t rgb_active = rgba_from_style (name, 0xff, 0, 0xff, 0, "bg", STATE_ACTIVE, false);
476 uint32_t rgb_normal = rgba_from_style (name, 0xff, 0xff, 0, 0, "bg", STATE_NORMAL, false);
478 gain_slider->set_border_colors (rgb_normal, rgb_active);
482 GainMeterBase::update_gain_sensitive ()
484 bool x = !(_amp->gain_control()->alist()->automation_state() & Play);
485 static_cast<Gtkmm2ext::SliderController*>(gain_slider)->set_sensitive (x);
489 next_meter_point (MeterPoint mp)
493 return MeterPreFader;
497 return MeterPostFader;
518 GainMeterBase::meter_press(GdkEventButton* ev)
520 wait_for_release = false;
526 if (!ignore_toggle) {
528 if (Keyboard::is_context_menu_event (ev)) {
530 // no menu at this time.
534 if (Keyboard::is_button2_event(ev)) {
536 // Primary-button2 click is the midi binding click
537 // button2-click is "momentary"
539 if (!Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier))) {
540 wait_for_release = true;
541 old_meter_point = _route->meter_point ();
545 if (_route && (ev->button == 1 || Keyboard::is_button2_event (ev))) {
547 if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
549 /* Primary+Tertiary-click applies change to all routes */
551 _session->foreach_route (this, &GainMeterBase::set_meter_point, next_meter_point (_route->meter_point()));
554 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
556 /* Primary-click: solo mix group.
557 NOTE: Primary-button2 is MIDI learn.
560 if (ev->button == 1) {
561 set_route_group_meter_point (*_route, next_meter_point (_route->meter_point()));
566 /* click: change just this route */
570 _route->set_meter_point (next_meter_point (_route->meter_point()));
581 GainMeterBase::meter_release(GdkEventButton*)
583 if (!ignore_toggle) {
584 if (wait_for_release) {
585 wait_for_release = false;
588 set_meter_point (*_route, old_meter_point);
597 GainMeterBase::set_meter_point (Route& route, MeterPoint mp)
599 route.set_meter_point (mp);
603 GainMeterBase::set_route_group_meter_point (Route& route, MeterPoint mp)
605 RouteGroup* route_group;
607 if ((route_group = route.route_group ()) != 0) {
608 route_group->foreach_route (boost::bind (&Route::set_meter_point, _1, mp, false));
610 route.set_meter_point (mp);
615 GainMeterBase::meter_point_clicked ()
623 GainMeterBase::gain_slider_button_press (GdkEventButton* ev)
626 case GDK_BUTTON_PRESS:
627 _amp->gain_control()->start_touch (_amp->session().transport_frame());
637 GainMeterBase::gain_slider_button_release (GdkEventButton* ev)
639 _amp->gain_control()->stop_touch (false, _amp->session().transport_frame());
644 GainMeterBase::gain_automation_state_button_event (GdkEventButton *ev)
646 if (ev->type == GDK_BUTTON_RELEASE) {
650 switch (ev->button) {
652 gain_astate_menu.popup (1, ev->time);
662 GainMeterBase::gain_automation_style_button_event (GdkEventButton *ev)
664 if (ev->type == GDK_BUTTON_RELEASE) {
668 switch (ev->button) {
670 gain_astyle_menu.popup (1, ev->time);
679 GainMeterBase::astate_string (AutoState state)
681 return _astate_string (state, false);
685 GainMeterBase::short_astate_string (AutoState state)
687 return _astate_string (state, true);
691 GainMeterBase::_astate_string (AutoState state, bool shrt)
697 sstr = (shrt ? "M" : _("M"));
700 sstr = (shrt ? "P" : _("P"));
703 sstr = (shrt ? "T" : _("T"));
706 sstr = (shrt ? "W" : _("W"));
714 GainMeterBase::astyle_string (AutoStyle style)
716 return _astyle_string (style, false);
720 GainMeterBase::short_astyle_string (AutoStyle style)
722 return _astyle_string (style, true);
726 GainMeterBase::_astyle_string (AutoStyle style, bool shrt)
731 /* XXX it might different in different languages */
733 return (shrt ? _("Abs") : _("Abs"));
738 GainMeterBase::gain_automation_style_changed ()
742 gain_automation_style_button.set_label (astyle_string(_amp->gain_control()->alist()->automation_style()));
745 gain_automation_style_button.set_label (short_astyle_string(_amp->gain_control()->alist()->automation_style()));
751 GainMeterBase::gain_automation_state_changed ()
753 ENSURE_GUI_THREAD (*this, &GainMeterBase::gain_automation_state_changed)
759 gain_automation_state_button.set_label (astate_string(_amp->gain_control()->alist()->automation_state()));
762 gain_automation_state_button.set_label (short_astate_string(_amp->gain_control()->alist()->automation_state()));
766 x = (_amp->gain_control()->alist()->automation_state() != Off);
768 if (gain_automation_state_button.get_active() != x) {
769 ignore_toggle = true;
770 gain_automation_state_button.set_active (x);
771 ignore_toggle = false;
774 update_gain_sensitive ();
776 /* start watching automation so that things move */
778 gain_watching.disconnect();
781 gain_watching = ARDOUR_UI::RapidScreenUpdate.connect (sigc::mem_fun (*this, &GainMeterBase::effective_gain_display));
786 GainMeterBase::update_meters()
789 float mpeak = level_meter->update_meters();
791 if (mpeak > max_peak) {
793 if (mpeak <= -200.0f) {
794 peak_display.set_label (_("-inf"));
796 snprintf (buf, sizeof(buf), "%.1f", mpeak);
797 peak_display.set_label (buf);
801 peak_display.set_name ("MixerStripPeakDisplayPeak");
806 void GainMeterBase::color_handler(bool dpi)
808 color_changed = true;
809 dpi_changed = (dpi) ? true : false;
814 GainMeterBase::set_width (Width w, int len)
817 level_meter->setup_meters (len);
822 GainMeterBase::on_theme_changed()
824 style_changed = true;
827 GainMeter::GainMeter (Session* s, int fader_length)
828 : GainMeterBase (s, slider, false, fader_length)
829 , gain_display_box(true, 0)
832 gain_display_box.pack_start (gain_display, true, true);
834 meter_metric_area.set_name ("AudioTrackMetrics");
835 set_size_request_to_display_given_text (meter_metric_area, "-127", 0, 0);
837 gain_automation_style_button.set_name ("MixerAutomationModeButton");
838 gain_automation_state_button.set_name ("MixerAutomationPlaybackButton");
840 ARDOUR_UI::instance()->set_tip (gain_automation_state_button, _("Fader automation mode"));
841 ARDOUR_UI::instance()->set_tip (gain_automation_style_button, _("Fader automation type"));
843 gain_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
844 gain_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
846 gain_automation_state_button.set_size_request(15, 15);
847 gain_automation_style_button.set_size_request(15, 15);
849 fader_vbox = manage (new Gtk::VBox());
850 fader_vbox->set_spacing (0);
851 fader_vbox->pack_start (*gain_slider, true, true);
853 fader_alignment.set (0.5, 0.5, 0.0, 1.0);
854 fader_alignment.add (*fader_vbox);
856 hbox.pack_start (fader_alignment, true, true);
860 pack_start (gain_display_box, Gtk::PACK_SHRINK);
861 pack_start (hbox, Gtk::PACK_SHRINK);
863 meter_alignment.set (0.5, 0.5, 0.0, 1.0);
864 meter_alignment.add (*level_meter);
866 meter_metric_area.signal_expose_event().connect (
867 sigc::mem_fun(*this, &GainMeter::meter_metrics_expose));
871 GainMeter::set_controls (boost::shared_ptr<Route> r,
872 boost::shared_ptr<PeakMeter> meter,
873 boost::shared_ptr<Amp> amp)
875 if (meter_alignment.get_parent()) {
876 hbox.remove (meter_alignment);
879 if (peak_display.get_parent()) {
880 gain_display_box.remove (peak_display);
883 if (gain_automation_state_button.get_parent()) {
884 fader_vbox->remove (gain_automation_state_button);
887 GainMeterBase::set_controls (r, meter, amp);
890 _meter->ConfigurationChanged.connect (
891 model_connections, invalidator (*this), ui_bind (&GainMeter::meter_configuration_changed, this, _1), gui_context()
894 meter_configuration_changed (_meter->input_streams ());
899 if we have a non-hidden route (ie. we're not the click or the auditioner),
900 pack some route-dependent stuff.
903 gain_display_box.pack_end (peak_display, true, true);
904 hbox.pack_start (meter_alignment, true, true);
906 if (r && !r->is_hidden()) {
907 fader_vbox->pack_start (gain_automation_state_button, false, false, 0);
915 GainMeter::get_gm_width ()
918 hbox.size_request (sz);
923 GainMeter::render_metrics (Gtk::Widget& w, vector<DataType> types)
925 Glib::RefPtr<Gdk::Window> win (w.get_window());
928 win->get_size (width, height);
930 cairo_surface_t* surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, height);
931 cairo_t* cr = cairo_create (surface);
932 PangoLayout* layout = gtk_widget_create_pango_layout (w.gobj(), "");
934 cairo_move_to (cr, 0, 0);
935 cairo_rectangle (cr, 0, 0, width, height);
937 Gdk::Color c = w.get_style()->get_bg (Gtk::STATE_NORMAL);
938 cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
942 for (vector<DataType>::const_iterator i = types.begin(); i != types.end(); ++i) {
946 if (types.size() > 1) {
947 /* we're overlaying more than 1 set of marks, so use different colours */
950 case DataType::AUDIO:
951 c = w.get_style()->get_fg (Gtk::STATE_NORMAL);
952 cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
955 c = w.get_style()->get_fg (Gtk::STATE_ACTIVE);
956 cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
960 c = w.get_style()->get_fg (Gtk::STATE_NORMAL);
961 cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
967 case DataType::AUDIO:
968 points.push_back (-50);
969 points.push_back (-40);
970 points.push_back (-30);
971 points.push_back (-20);
972 points.push_back (-10);
973 points.push_back (-3);
974 points.push_back (0);
975 points.push_back (4);
979 points.push_back (0);
980 if (types.size() == 1) {
981 points.push_back (32);
983 /* tweak so as not to overlay the -30dB mark */
984 points.push_back (48);
986 points.push_back (64);
987 points.push_back (96);
988 points.push_back (127);
994 for (vector<int>::const_iterator j = points.begin(); j != points.end(); ++j) {
998 case DataType::AUDIO:
999 fraction = log_meter (*j);
1001 case DataType::MIDI:
1002 fraction = *j / 127.0;
1006 gint const pos = height - (gint) floor (height * fraction);
1008 cairo_set_line_width (cr, 1.0);
1009 cairo_move_to (cr, 0, pos);
1010 cairo_line_to (cr, 4, pos);
1013 snprintf (buf, sizeof (buf), "%d", abs (*j));
1014 pango_layout_set_text (layout, buf, strlen (buf));
1016 /* we want logical extents, not ink extents here */
1019 pango_layout_get_pixel_size (layout, &tw, &th);
1021 int p = pos - (th / 2);
1022 p = min (p, height - th);
1025 cairo_move_to (cr, 6, p);
1026 pango_cairo_show_layout (cr, layout);
1030 cairo_pattern_t* pattern = cairo_pattern_create_for_surface (surface);
1031 MetricPatterns::iterator p;
1033 if ((p = metric_patterns.find (w.get_name())) != metric_patterns.end()) {
1034 cairo_pattern_destroy (p->second);
1037 metric_patterns[w.get_name()] = pattern;
1040 cairo_surface_destroy (surface);
1041 g_object_unref (layout);
1047 GainMeter::meter_metrics_expose (GdkEventExpose *ev)
1049 Glib::RefPtr<Gdk::Window> win (meter_metric_area.get_window());
1052 cr = gdk_cairo_create (win->gobj());
1054 /* clip to expose area */
1056 gdk_cairo_rectangle (cr, &ev->area);
1059 cairo_pattern_t* pattern;
1060 MetricPatterns::iterator i = metric_patterns.find (meter_metric_area.get_name());
1062 if (i == metric_patterns.end() || style_changed || dpi_changed) {
1063 pattern = render_metrics (meter_metric_area, _types);
1065 pattern = i->second;
1068 cairo_move_to (cr, 0, 0);
1069 cairo_set_source (cr, pattern);
1072 win->get_size (width, height);
1074 cairo_rectangle (cr, 0, 0, width, height);
1077 style_changed = false;
1078 dpi_changed = false;
1085 boost::shared_ptr<PBD::Controllable>
1086 GainMeterBase::get_controllable()
1089 return _amp->gain_control();
1091 return boost::shared_ptr<PBD::Controllable>();
1096 GainMeter::meter_configuration_changed (ChanCount c)
1100 for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) {
1101 if (c.get (*i) > 0) {
1102 _types.push_back (*i);
1106 style_changed = true;
1107 meter_metric_area.queue_draw ();