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"
28 #include <gtkmm/style.h>
29 #include <gdkmm/color.h>
30 #include <gtkmm2ext/utils.h>
31 #include <gtkmm2ext/fastmeter.h>
32 #include <gtkmm2ext/barcontroller.h>
33 #include <gtkmm2ext/gtk_ui.h>
34 #include "midi++/manager.h"
35 #include "pbd/fastlog.h"
36 #include "pbd/stacktrace.h"
38 #include "ardour_ui.h"
39 #include "gain_meter.h"
40 #include "global_signals.h"
42 #include "gui_thread.h"
44 #include "public_editor.h"
47 #include "ardour/session.h"
48 #include "ardour/route.h"
49 #include "ardour/meter.h"
53 using namespace ARDOUR;
55 using namespace Gtkmm2ext;
58 using Gtkmm2ext::Keyboard;
60 sigc::signal<void> GainMeterBase::ResetAllPeakDisplays;
61 sigc::signal<void,RouteGroup*> GainMeterBase::ResetGroupPeakDisplays;
63 GainMeter::MetricPatterns GainMeter::metric_patterns;
65 GainMeterBase::GainMeterBase (Session* s, bool horizontal, int fader_length, int fader_girth)
66 : gain_adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain()), 0.0, 1.0, 0.01, 0.1)
67 , gain_automation_style_button ("")
68 , gain_automation_state_button ("")
69 , style_changed (false)
71 , _data_type (DataType::AUDIO)
74 using namespace Menu_Helpers;
78 ignore_toggle = false;
80 next_release_selects = false;
84 gain_slider = manage (new HSliderController (&gain_adjustment, fader_length, fader_girth, false));
86 gain_slider = manage (new VSliderController (&gain_adjustment, fader_length, fader_girth, false));
89 level_meter = new LevelMeter(_session);
91 level_meter->ButtonPress.connect_same_thread (_level_meter_connection, boost::bind (&GainMeterBase::level_meter_button_press, this, _1));
92 meter_metric_area.signal_button_press_event().connect (sigc::mem_fun (*this, &GainMeterBase::level_meter_button_press));
93 meter_metric_area.add_events (Gdk::BUTTON_PRESS_MASK);
95 gain_slider->signal_button_press_event().connect (sigc::mem_fun(*this, &GainMeter::gain_slider_button_press), false);
96 gain_slider->signal_button_release_event().connect (sigc::mem_fun(*this, &GainMeter::gain_slider_button_release), false);
97 gain_slider->set_name ("GainFader");
99 gain_display.set_name ("MixerStripGainDisplay");
100 set_size_request_to_display_given_text (gain_display, "-80.g", 2, 6); /* note the descender */
101 gain_display.signal_activate().connect (sigc::mem_fun (*this, &GainMeter::gain_activated));
102 gain_display.signal_focus_in_event().connect (sigc::mem_fun (*this, &GainMeter::gain_focused), false);
103 gain_display.signal_focus_out_event().connect (sigc::mem_fun (*this, &GainMeter::gain_focused), false);
105 peak_display.set_name ("MixerStripPeakDisplay");
106 set_size_request_to_display_given_text (peak_display, "-80.g", 2, 6); /* note the descender */
107 max_peak = minus_infinity();
108 peak_display.set_label (_("-inf"));
109 peak_display.unset_flags (Gtk::CAN_FOCUS);
111 gain_automation_style_button.set_name ("mixer strip button");
112 gain_automation_state_button.set_name ("mixer strip button");
114 ARDOUR_UI::instance()->set_tip (gain_automation_state_button, _("Fader automation mode"));
115 ARDOUR_UI::instance()->set_tip (gain_automation_style_button, _("Fader automation type"));
117 gain_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
118 gain_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
120 gain_automation_state_button.set_size_request(15, 15);
121 gain_automation_style_button.set_size_request(15, 15);
123 gain_astyle_menu.items().push_back (MenuElem (_("Trim")));
124 gain_astyle_menu.items().push_back (MenuElem (_("Abs")));
126 gain_astate_menu.set_name ("ArdourContextMenu");
127 gain_astyle_menu.set_name ("ArdourContextMenu");
129 gain_adjustment.signal_value_changed().connect (sigc::mem_fun(*this, &GainMeterBase::gain_adjusted));
130 peak_display.signal_button_release_event().connect (sigc::mem_fun(*this, &GainMeterBase::peak_button_release), false);
131 gain_display.signal_key_press_event().connect (sigc::mem_fun(*this, &GainMeterBase::gain_key_press), false);
133 ResetAllPeakDisplays.connect (sigc::mem_fun(*this, &GainMeterBase::reset_peak_display));
134 ResetGroupPeakDisplays.connect (sigc::mem_fun(*this, &GainMeterBase::reset_group_peak_display));
136 UI::instance()->theme_changed.connect (sigc::mem_fun(*this, &GainMeterBase::on_theme_changed));
137 ColorsChanged.connect (sigc::bind(sigc::mem_fun (*this, &GainMeterBase::color_handler), false));
138 DPIReset.connect (sigc::bind(sigc::mem_fun (*this, &GainMeterBase::color_handler), true));
140 // PBD::ScopedConnection _config_connection;
141 // Config->ParameterChanged.connect ( _config_connection, MISSING_INVALIDATOR, boost::bind(&GainMeterBase::set_flat_buttons, this, _1), gui_context() );
145 GainMeterBase::set_flat_buttons ()
147 printf("set_flat_butt\n");
148 // gain_slider->set_flat_buttons( ARDOUR_UI::config()->flat_buttons.get() );
151 GainMeterBase::~GainMeterBase ()
158 GainMeterBase::set_controls (boost::shared_ptr<Route> r,
159 boost::shared_ptr<PeakMeter> pm,
160 boost::shared_ptr<Amp> amp)
162 connections.clear ();
163 model_connections.drop_connections ();
166 level_meter->set_meter (0);
167 gain_slider->set_controllable (boost::shared_ptr<PBD::Controllable>());
178 level_meter->set_meter (pm.get());
179 gain_slider->set_controllable (amp->gain_control());
182 amp->ConfigurationChanged.connect (
183 model_connections, invalidator (*this), boost::bind (&GainMeterBase::setup_gain_adjustment, this), gui_context ()
187 setup_gain_adjustment ();
189 if (!_route || !_route->is_auditioner()) {
191 using namespace Menu_Helpers;
193 gain_astate_menu.items().clear ();
195 gain_astate_menu.items().push_back (MenuElem (S_("Automation|Manual"),
196 sigc::bind (sigc::mem_fun (*(amp.get()), &Automatable::set_parameter_automation_state),
197 Evoral::Parameter(GainAutomation), (AutoState) ARDOUR::Off)));
198 gain_astate_menu.items().push_back (MenuElem (_("Play"),
199 sigc::bind (sigc::mem_fun (*(amp.get()), &Automatable::set_parameter_automation_state),
200 Evoral::Parameter(GainAutomation), (AutoState) Play)));
201 gain_astate_menu.items().push_back (MenuElem (_("Write"),
202 sigc::bind (sigc::mem_fun (*(amp.get()), &Automatable::set_parameter_automation_state),
203 Evoral::Parameter(GainAutomation), (AutoState) Write)));
204 gain_astate_menu.items().push_back (MenuElem (_("Touch"),
205 sigc::bind (sigc::mem_fun (*(amp.get()), &Automatable::set_parameter_automation_state),
206 Evoral::Parameter(GainAutomation), (AutoState) Touch)));
208 connections.push_back (gain_automation_style_button.signal_button_press_event().connect (sigc::mem_fun(*this, &GainMeterBase::gain_automation_style_button_event), false));
209 connections.push_back (gain_automation_state_button.signal_button_press_event().connect (sigc::mem_fun(*this, &GainMeterBase::gain_automation_state_button_event), false));
211 boost::shared_ptr<AutomationControl> gc = amp->gain_control();
213 gc->alist()->automation_state_changed.connect (model_connections, invalidator (*this), boost::bind (&GainMeter::gain_automation_state_changed, this), gui_context());
214 gc->alist()->automation_style_changed.connect (model_connections, invalidator (*this), boost::bind (&GainMeter::gain_automation_style_changed, this), gui_context());
216 gain_automation_state_changed ();
219 amp->gain_control()->Changed.connect (model_connections, invalidator (*this), boost::bind (&GainMeterBase::gain_changed, this), gui_context());
223 update_gain_sensitive ();
227 GainMeterBase::setup_gain_adjustment ()
233 if (_previous_amp_output_streams == _amp->output_streams ()) {
237 ignore_toggle = true;
239 if (_amp->output_streams().n_midi() == 0) {
240 _data_type = DataType::AUDIO;
241 gain_adjustment.set_lower (0.0);
242 gain_adjustment.set_upper (1.0);
243 gain_adjustment.set_step_increment (0.01);
244 gain_adjustment.set_page_increment (0.1);
245 gain_slider->set_default_value (gain_to_slider_position (1));
247 _data_type = DataType::MIDI;
248 gain_adjustment.set_lower (0.0);
249 gain_adjustment.set_upper (2.0);
250 gain_adjustment.set_step_increment (1.0/128.0);
251 gain_adjustment.set_page_increment (10.0/128.0);
252 gain_slider->set_default_value (1.0);
255 ignore_toggle = false;
257 effective_gain_display ();
259 _previous_amp_output_streams = _amp->output_streams ();
263 GainMeterBase::hide_all_meters ()
265 level_meter->hide_meters();
269 GainMeter::hide_all_meters ()
271 bool remove_metric_area = false;
273 GainMeterBase::hide_all_meters ();
275 if (remove_metric_area) {
276 if (meter_metric_area.get_parent()) {
277 level_meter->remove (meter_metric_area);
283 GainMeterBase::setup_meters (int len)
285 level_meter->setup_meters(len, 5);
289 GainMeter::setup_meters (int len)
291 if (!meter_metric_area.get_parent()) {
292 level_meter->pack_end (meter_metric_area, false, false);
293 meter_metric_area.show_all ();
295 GainMeterBase::setup_meters (len);
299 GainMeterBase::gain_key_press (GdkEventKey* ev)
301 if (key_is_legal_for_numeric_entry (ev->keyval)) {
302 /* drop through to normal handling */
305 /* illegal key for gain entry */
310 GainMeterBase::peak_button_release (GdkEventButton* ev)
312 /* reset peak label */
314 if (ev->button == 1 && Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier|Keyboard::TertiaryModifier)) {
315 ResetAllPeakDisplays ();
316 } else if (ev->button == 1 && Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
318 ResetGroupPeakDisplays (_route->route_group());
321 reset_peak_display ();
328 GainMeterBase::reset_peak_display ()
331 level_meter->clear_meters();
332 max_peak = -INFINITY;
333 peak_display.set_label (_("-Inf"));
334 peak_display.set_name ("MixerStripPeakDisplay");
338 GainMeterBase::reset_group_peak_display (RouteGroup* group)
340 if (_route && group == _route->route_group()) {
341 reset_peak_display ();
346 GainMeterBase::popup_meter_menu (GdkEventButton *ev)
348 using namespace Menu_Helpers;
350 if (meter_menu == 0) {
351 meter_menu = new Gtk::Menu;
352 MenuList& items = meter_menu->items();
354 items.push_back (MenuElem ("-inf .. +0dBFS"));
355 items.push_back (MenuElem ("-10dB .. +0dBFS"));
356 items.push_back (MenuElem ("-4 .. +0dBFS"));
357 items.push_back (SeparatorElem());
358 items.push_back (MenuElem ("-inf .. -2dBFS"));
359 items.push_back (MenuElem ("-10dB .. -2dBFS"));
360 items.push_back (MenuElem ("-4 .. -2dBFS"));
363 meter_menu->popup (1, ev->time);
367 GainMeterBase::gain_focused (GdkEventFocus* ev)
370 gain_display.select_region (0, -1);
372 gain_display.select_region (0, 0);
378 GainMeterBase::gain_activated ()
383 // Switch to user's preferred locale so that
384 // if they use different LC_NUMERIC conventions,
385 // we will honor them.
387 PBD::LocaleGuard lg ("");
388 if (sscanf (gain_display.get_text().c_str(), "%f", &f) != 1) {
393 /* clamp to displayable values */
394 if (_data_type == DataType::AUDIO) {
396 _amp->set_gain (dB_to_coefficient(f), this);
398 f = min (fabs (f), 2.0f);
399 _amp->set_gain (f, this);
402 if (gain_display.has_focus()) {
403 Gtk::Widget* w = gain_display.get_toplevel();
405 Gtk::Window* win = dynamic_cast<Gtk::Window*> (w);
407 /* sigh. gtkmm doesn't wrap get_default_widget() */
410 GtkWidget* f = gtk_window_get_default_widget (win->gobj());
412 gtk_widget_grab_focus (f);
421 GainMeterBase::show_gain ()
425 float v = gain_adjustment.get_value();
427 switch (_data_type) {
428 case DataType::AUDIO:
430 strcpy (buf, _("-inf"));
432 snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain_with_max (v, Config->get_max_gain())));
436 snprintf (buf, sizeof (buf), "%.1f", v);
440 gain_display.set_text (buf);
444 GainMeterBase::gain_adjusted ()
448 /* convert from adjustment range (0..1) to gain coefficient */
450 if (_data_type == DataType::AUDIO) {
451 value = slider_position_to_gain_with_max (gain_adjustment.get_value(), Config->get_max_gain());
453 value = gain_adjustment.get_value();
456 if (!ignore_toggle) {
457 if (_route && _route->amp() == _amp) {
458 _route->set_gain (value, this);
460 _amp->set_gain (value, this);
468 GainMeterBase::effective_gain_display ()
472 switch (_data_type) {
473 case DataType::AUDIO:
474 value = gain_to_slider_position_with_max (_amp->gain(), Config->get_max_gain());
477 value = _amp->gain ();
481 if (gain_adjustment.get_value() != value) {
482 ignore_toggle = true;
483 gain_adjustment.set_value (value);
484 ignore_toggle = false;
489 GainMeterBase::gain_changed ()
491 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&GainMeterBase::effective_gain_display, this));
495 GainMeterBase::set_meter_strip_name (const char * name)
497 meter_metric_area.set_name (name);
501 GainMeterBase::set_fader_name (const char * name)
503 gain_slider->set_name (name);
507 GainMeterBase::update_gain_sensitive ()
509 bool x = !(_amp->gain_control()->alist()->automation_state() & Play);
510 static_cast<Gtkmm2ext::SliderController*>(gain_slider)->set_sensitive (x);
514 next_meter_point (MeterPoint mp)
518 return MeterPreFader;
522 return MeterPostFader;
543 GainMeterBase::meter_press(GdkEventButton* ev)
545 wait_for_release = false;
551 if (!ignore_toggle) {
553 if (Keyboard::is_context_menu_event (ev)) {
555 // no menu at this time.
559 if (Keyboard::is_button2_event(ev)) {
561 // Primary-button2 click is the midi binding click
562 // button2-click is "momentary"
564 if (!Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier))) {
565 wait_for_release = true;
566 old_meter_point = _route->meter_point ();
570 if (_route && (ev->button == 1 || Keyboard::is_button2_event (ev))) {
572 if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
574 /* Primary+Tertiary-click applies change to all routes */
576 _session->foreach_route (this, &GainMeterBase::set_meter_point, next_meter_point (_route->meter_point()));
579 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
581 /* Primary-click: solo mix group.
582 NOTE: Primary-button2 is MIDI learn.
585 if (ev->button == 1) {
586 set_route_group_meter_point (*_route, next_meter_point (_route->meter_point()));
591 /* click: change just this route */
595 _route->set_meter_point (next_meter_point (_route->meter_point()));
606 GainMeterBase::meter_release(GdkEventButton*)
608 if (!ignore_toggle) {
609 if (wait_for_release) {
610 wait_for_release = false;
613 set_meter_point (*_route, old_meter_point);
622 GainMeterBase::set_meter_point (Route& route, MeterPoint mp)
624 route.set_meter_point (mp);
628 GainMeterBase::set_route_group_meter_point (Route& route, MeterPoint mp)
630 RouteGroup* route_group;
632 if ((route_group = route.route_group ()) != 0) {
633 route_group->foreach_route (boost::bind (&Route::set_meter_point, _1, mp, false));
635 route.set_meter_point (mp);
640 GainMeterBase::meter_point_clicked ()
648 GainMeterBase::gain_slider_button_press (GdkEventButton* ev)
651 case GDK_BUTTON_PRESS:
652 _amp->gain_control()->start_touch (_amp->session().transport_frame());
662 GainMeterBase::gain_slider_button_release (GdkEventButton*)
664 _amp->gain_control()->stop_touch (false, _amp->session().transport_frame());
669 GainMeterBase::gain_automation_state_button_event (GdkEventButton *ev)
671 if (ev->type == GDK_BUTTON_RELEASE) {
675 switch (ev->button) {
677 gain_astate_menu.popup (1, ev->time);
687 GainMeterBase::gain_automation_style_button_event (GdkEventButton *ev)
689 if (ev->type == GDK_BUTTON_RELEASE) {
693 switch (ev->button) {
695 gain_astyle_menu.popup (1, ev->time);
704 GainMeterBase::astate_string (AutoState state)
706 return _astate_string (state, false);
710 GainMeterBase::short_astate_string (AutoState state)
712 return _astate_string (state, true);
716 GainMeterBase::_astate_string (AutoState state, bool shrt)
722 sstr = (shrt ? "M" : _("M"));
725 sstr = (shrt ? "P" : _("P"));
728 sstr = (shrt ? "T" : _("T"));
731 sstr = (shrt ? "W" : _("W"));
739 GainMeterBase::astyle_string (AutoStyle style)
741 return _astyle_string (style, false);
745 GainMeterBase::short_astyle_string (AutoStyle style)
747 return _astyle_string (style, true);
751 GainMeterBase::_astyle_string (AutoStyle style, bool shrt)
756 /* XXX it might different in different languages */
758 return (shrt ? _("Abs") : _("Abs"));
763 GainMeterBase::gain_automation_style_changed ()
767 gain_automation_style_button.set_text (astyle_string(_amp->gain_control()->alist()->automation_style()));
770 gain_automation_style_button.set_text (short_astyle_string(_amp->gain_control()->alist()->automation_style()));
776 GainMeterBase::gain_automation_state_changed ()
778 ENSURE_GUI_THREAD (*this, &GainMeterBase::gain_automation_state_changed)
784 gain_automation_state_button.set_text (astate_string(_amp->gain_control()->alist()->automation_state()));
787 gain_automation_state_button.set_text (short_astate_string(_amp->gain_control()->alist()->automation_state()));
791 x = (_amp->gain_control()->alist()->automation_state() != ARDOUR::Off);
793 if (gain_automation_state_button.get_active() != x) {
794 ignore_toggle = true;
795 gain_automation_state_button.set_active (x);
796 ignore_toggle = false;
799 update_gain_sensitive ();
801 /* start watching automation so that things move */
803 gain_watching.disconnect();
806 gain_watching = ARDOUR_UI::RapidScreenUpdate.connect (sigc::mem_fun (*this, &GainMeterBase::effective_gain_display));
811 GainMeterBase::update_meters()
814 float mpeak = level_meter->update_meters();
816 if (mpeak > max_peak) {
818 if (mpeak <= -200.0f) {
819 peak_display.set_label (_("-inf"));
821 snprintf (buf, sizeof(buf), "%.1f", mpeak);
822 peak_display.set_label (buf);
826 peak_display.set_name ("MixerStripPeakDisplayPeak");
831 void GainMeterBase::color_handler(bool dpi)
833 color_changed = true;
834 dpi_changed = (dpi) ? true : false;
839 GainMeterBase::set_width (Width w, int len)
842 level_meter->setup_meters (len);
847 GainMeterBase::on_theme_changed()
849 style_changed = true;
852 GainMeter::GainMeter (Session* s, int fader_length)
853 : GainMeterBase (s, false, fader_length, 24)
854 , gain_display_box(true, 0)
857 if (gain_display.get_parent()) {
858 gain_display.get_parent()->remove (gain_display);
860 gain_display_box.pack_start (gain_display, true, true);
862 meter_metric_area.set_name ("AudioTrackMetrics");
863 set_size_request_to_display_given_text (meter_metric_area, "-127", 0, 0);
865 gain_automation_style_button.set_name ("mixer strip button");
866 gain_automation_state_button.set_name ("mixer strip button");
868 ARDOUR_UI::instance()->set_tip (gain_automation_state_button, _("Fader automation mode"));
869 ARDOUR_UI::instance()->set_tip (gain_automation_style_button, _("Fader automation type"));
871 gain_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
872 gain_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
874 gain_automation_state_button.set_size_request(15, 15);
875 gain_automation_style_button.set_size_request(15, 15);
877 fader_vbox = manage (new Gtk::VBox());
878 fader_vbox->set_spacing (0);
879 fader_vbox->pack_start (*gain_slider, true, true);
881 fader_alignment.set (0.5, 0.5, 0.0, 1.0);
882 fader_alignment.add (*fader_vbox);
884 hbox.pack_start (fader_alignment, true, true);
888 pack_start (gain_display_box, Gtk::PACK_SHRINK);
889 pack_start (hbox, Gtk::PACK_SHRINK);
891 meter_alignment.set (0.5, 0.5, 0.0, 1.0);
892 meter_alignment.add (*level_meter);
894 meter_metric_area.signal_expose_event().connect (
895 sigc::mem_fun(*this, &GainMeter::meter_metrics_expose));
899 GainMeter::set_controls (boost::shared_ptr<Route> r,
900 boost::shared_ptr<PeakMeter> meter,
901 boost::shared_ptr<Amp> amp)
903 if (meter_alignment.get_parent()) {
904 hbox.remove (meter_alignment);
907 // if (gain_automation_state_button.get_parent()) {
908 // fader_vbox->remove (gain_automation_state_button);
911 GainMeterBase::set_controls (r, meter, amp);
914 _meter->ConfigurationChanged.connect (
915 model_connections, invalidator (*this), boost::bind (&GainMeter::meter_configuration_changed, this, _1), gui_context()
918 meter_configuration_changed (_meter->input_streams ());
923 if we have a non-hidden route (ie. we're not the click or the auditioner),
924 pack some route-dependent stuff.
927 hbox.pack_start (meter_alignment, true, true);
929 // if (r && !r->is_auditioner()) {
930 // fader_vbox->pack_start (gain_automation_state_button, false, false, 0);
938 GainMeter::get_gm_width ()
941 hbox.size_request (sz);
946 GainMeter::render_metrics (Gtk::Widget& w, vector<DataType> types)
948 Glib::RefPtr<Gdk::Window> win (w.get_window());
951 win->get_size (width, height);
953 cairo_surface_t* surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, height);
954 cairo_t* cr = cairo_create (surface);
955 PangoLayout* layout = gtk_widget_create_pango_layout (w.gobj(), "");
957 cairo_move_to (cr, 0, 0);
958 cairo_rectangle (cr, 0, 0, width, height);
960 Gdk::Color c = w.get_style()->get_bg (Gtk::STATE_NORMAL);
961 cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
965 for (vector<DataType>::const_iterator i = types.begin(); i != types.end(); ++i) {
969 if (types.size() > 1) {
970 /* we're overlaying more than 1 set of marks, so use different colours */
973 case DataType::AUDIO:
974 c = w.get_style()->get_fg (Gtk::STATE_NORMAL);
975 cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
978 c = w.get_style()->get_fg (Gtk::STATE_ACTIVE);
979 cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
983 c = w.get_style()->get_fg (Gtk::STATE_NORMAL);
984 cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
990 case DataType::AUDIO:
991 points.push_back (-50);
992 points.push_back (-40);
993 points.push_back (-30);
994 points.push_back (-20);
995 points.push_back (-10);
996 points.push_back (-3);
997 points.push_back (0);
998 points.push_back (4);
1001 case DataType::MIDI:
1002 points.push_back (0);
1003 if (types.size() == 1) {
1004 points.push_back (32);
1006 /* tweak so as not to overlay the -30dB mark */
1007 points.push_back (48);
1009 points.push_back (64);
1010 points.push_back (96);
1011 points.push_back (127);
1017 for (vector<int>::const_iterator j = points.begin(); j != points.end(); ++j) {
1021 case DataType::AUDIO:
1022 fraction = log_meter (*j);
1024 case DataType::MIDI:
1025 fraction = *j / 127.0;
1029 gint const pos = height - (gint) floor (height * fraction);
1031 cairo_set_line_width (cr, 1.0);
1032 cairo_move_to (cr, 0, pos);
1033 cairo_line_to (cr, 4, pos);
1036 snprintf (buf, sizeof (buf), "%d", abs (*j));
1037 pango_layout_set_text (layout, buf, strlen (buf));
1039 /* we want logical extents, not ink extents here */
1042 pango_layout_get_pixel_size (layout, &tw, &th);
1044 int p = pos - (th / 2);
1045 p = min (p, height - th);
1048 cairo_move_to (cr, 6, p);
1049 pango_cairo_show_layout (cr, layout);
1053 cairo_pattern_t* pattern = cairo_pattern_create_for_surface (surface);
1054 MetricPatterns::iterator p;
1056 if ((p = metric_patterns.find (w.get_name())) != metric_patterns.end()) {
1057 cairo_pattern_destroy (p->second);
1060 metric_patterns[w.get_name()] = pattern;
1063 cairo_surface_destroy (surface);
1064 g_object_unref (layout);
1070 GainMeter::meter_metrics_expose (GdkEventExpose *ev)
1072 Glib::RefPtr<Gdk::Window> win (meter_metric_area.get_window());
1075 cr = gdk_cairo_create (win->gobj());
1077 /* clip to expose area */
1079 gdk_cairo_rectangle (cr, &ev->area);
1082 cairo_pattern_t* pattern;
1083 MetricPatterns::iterator i = metric_patterns.find (meter_metric_area.get_name());
1085 if (i == metric_patterns.end() || style_changed || dpi_changed) {
1086 pattern = render_metrics (meter_metric_area, _types);
1088 pattern = i->second;
1091 cairo_move_to (cr, 0, 0);
1092 cairo_set_source (cr, pattern);
1095 win->get_size (width, height);
1097 cairo_rectangle (cr, 0, 0, width, height);
1100 style_changed = false;
1101 dpi_changed = false;
1108 boost::shared_ptr<PBD::Controllable>
1109 GainMeterBase::get_controllable()
1112 return _amp->gain_control();
1114 return boost::shared_ptr<PBD::Controllable>();
1119 GainMeterBase::level_meter_button_press (GdkEventButton* ev)
1121 return LevelMeterButtonPress (ev); /* EMIT SIGNAL */
1125 GainMeter::meter_configuration_changed (ChanCount c)
1129 for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) {
1130 if (c.get (*i) > 0) {
1131 _types.push_back (*i);
1135 style_changed = true;
1136 meter_metric_area.queue_draw ();