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/barcontroller.h>
34 #include <gtkmm2ext/gtk_ui.h>
35 #include "midi++/manager.h"
36 #include "pbd/fastlog.h"
37 #include "pbd/stacktrace.h"
39 #include "ardour_ui.h"
40 #include "gain_meter.h"
41 #include "global_signals.h"
43 #include "gui_thread.h"
45 #include "public_editor.h"
48 #include "ardour/session.h"
49 #include "ardour/route.h"
50 #include "ardour/meter.h"
54 using namespace ARDOUR;
56 using namespace Gtkmm2ext;
59 using Gtkmm2ext::Keyboard;
61 sigc::signal<void> GainMeterBase::ResetAllPeakDisplays;
62 sigc::signal<void,RouteGroup*> GainMeterBase::ResetGroupPeakDisplays;
64 GainMeter::MetricPatterns GainMeter::metric_patterns;
66 GainMeterBase::GainMeterBase (Session* s, bool horizontal, int fader_length, int fader_girth)
67 : gain_adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain()), 0.0, 1.0, 0.01, 0.1)
68 , gain_automation_style_button ("")
69 , gain_automation_state_button ("")
70 , style_changed (false)
72 , _data_type (DataType::AUDIO)
75 using namespace Menu_Helpers;
79 ignore_toggle = false;
81 next_release_selects = false;
85 gain_slider = manage (new HSliderController (&gain_adjustment, fader_length, fader_girth, false));
87 gain_slider = manage (new VSliderController (&gain_adjustment, fader_length, fader_girth, false));
90 level_meter = new LevelMeter(_session);
92 level_meter->ButtonPress.connect_same_thread (_level_meter_connection, boost::bind (&GainMeterBase::level_meter_button_press, this, _1));
93 meter_metric_area.signal_button_press_event().connect (sigc::mem_fun (*this, &GainMeterBase::level_meter_button_press));
94 meter_metric_area.add_events (Gdk::BUTTON_PRESS_MASK);
96 gain_slider->signal_button_press_event().connect (sigc::mem_fun(*this, &GainMeter::gain_slider_button_press), false);
97 gain_slider->signal_button_release_event().connect (sigc::mem_fun(*this, &GainMeter::gain_slider_button_release), false);
98 gain_slider->set_name ("GainFader");
100 gain_display.set_name ("MixerStripGainDisplay");
101 set_size_request_to_display_given_text (gain_display, "-80.g", 2, 6); /* note the descender */
102 gain_display.signal_activate().connect (sigc::mem_fun (*this, &GainMeter::gain_activated));
103 gain_display.signal_focus_in_event().connect (sigc::mem_fun (*this, &GainMeter::gain_focused), false);
104 gain_display.signal_focus_out_event().connect (sigc::mem_fun (*this, &GainMeter::gain_focused), false);
106 peak_display.set_name ("MixerStripPeakDisplay");
107 set_size_request_to_display_given_text (peak_display, "-80.g", 2, 6); /* note the descender */
108 max_peak = minus_infinity();
109 peak_display.set_label (_("-inf"));
110 peak_display.unset_flags (Gtk::CAN_FOCUS);
112 gain_automation_style_button.set_name ("mixer strip button");
113 gain_automation_state_button.set_name ("mixer strip button");
115 ARDOUR_UI::instance()->set_tip (gain_automation_state_button, _("Fader automation mode"));
116 ARDOUR_UI::instance()->set_tip (gain_automation_style_button, _("Fader automation type"));
118 gain_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
119 gain_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
121 gain_automation_state_button.set_size_request(15, 15);
122 gain_automation_style_button.set_size_request(15, 15);
124 gain_astyle_menu.items().push_back (MenuElem (_("Trim")));
125 gain_astyle_menu.items().push_back (MenuElem (_("Abs")));
127 gain_astate_menu.set_name ("ArdourContextMenu");
128 gain_astyle_menu.set_name ("ArdourContextMenu");
130 gain_adjustment.signal_value_changed().connect (sigc::mem_fun(*this, &GainMeterBase::gain_adjusted));
131 peak_display.signal_button_release_event().connect (sigc::mem_fun(*this, &GainMeterBase::peak_button_release), false);
132 gain_display.signal_key_press_event().connect (sigc::mem_fun(*this, &GainMeterBase::gain_key_press), false);
134 ResetAllPeakDisplays.connect (sigc::mem_fun(*this, &GainMeterBase::reset_peak_display));
135 ResetGroupPeakDisplays.connect (sigc::mem_fun(*this, &GainMeterBase::reset_group_peak_display));
137 UI::instance()->theme_changed.connect (sigc::mem_fun(*this, &GainMeterBase::on_theme_changed));
138 ColorsChanged.connect (sigc::bind(sigc::mem_fun (*this, &GainMeterBase::color_handler), false));
139 DPIReset.connect (sigc::bind(sigc::mem_fun (*this, &GainMeterBase::color_handler), true));
141 // PBD::ScopedConnection _config_connection;
142 // Config->ParameterChanged.connect ( _config_connection, MISSING_INVALIDATOR, boost::bind(&GainMeterBase::set_flat_buttons, this, _1), gui_context() );
146 GainMeterBase::set_flat_buttons ()
148 printf("set_flat_butt\n");
149 // gain_slider->set_flat_buttons( ARDOUR_UI::config()->flat_buttons.get() );
152 GainMeterBase::~GainMeterBase ()
159 GainMeterBase::set_controls (boost::shared_ptr<Route> r,
160 boost::shared_ptr<PeakMeter> pm,
161 boost::shared_ptr<Amp> amp)
163 connections.clear ();
164 model_connections.drop_connections ();
167 level_meter->set_meter (0);
168 gain_slider->set_controllable (boost::shared_ptr<PBD::Controllable>());
179 level_meter->set_meter (pm.get());
180 gain_slider->set_controllable (amp->gain_control());
183 amp->ConfigurationChanged.connect (
184 model_connections, invalidator (*this), boost::bind (&GainMeterBase::setup_gain_adjustment, this), gui_context ()
188 setup_gain_adjustment ();
190 if (!_route || !_route->is_auditioner()) {
192 using namespace Menu_Helpers;
194 gain_astate_menu.items().clear ();
196 gain_astate_menu.items().push_back (MenuElem (S_("Automation|Manual"),
197 sigc::bind (sigc::mem_fun (*(amp.get()), &Automatable::set_parameter_automation_state),
198 Evoral::Parameter(GainAutomation), (AutoState) ARDOUR::Off)));
199 gain_astate_menu.items().push_back (MenuElem (_("Play"),
200 sigc::bind (sigc::mem_fun (*(amp.get()), &Automatable::set_parameter_automation_state),
201 Evoral::Parameter(GainAutomation), (AutoState) Play)));
202 gain_astate_menu.items().push_back (MenuElem (_("Write"),
203 sigc::bind (sigc::mem_fun (*(amp.get()), &Automatable::set_parameter_automation_state),
204 Evoral::Parameter(GainAutomation), (AutoState) Write)));
205 gain_astate_menu.items().push_back (MenuElem (_("Touch"),
206 sigc::bind (sigc::mem_fun (*(amp.get()), &Automatable::set_parameter_automation_state),
207 Evoral::Parameter(GainAutomation), (AutoState) Touch)));
209 connections.push_back (gain_automation_style_button.signal_button_press_event().connect (sigc::mem_fun(*this, &GainMeterBase::gain_automation_style_button_event), false));
210 connections.push_back (gain_automation_state_button.signal_button_press_event().connect (sigc::mem_fun(*this, &GainMeterBase::gain_automation_state_button_event), false));
212 boost::shared_ptr<AutomationControl> gc = amp->gain_control();
214 gc->alist()->automation_state_changed.connect (model_connections, invalidator (*this), boost::bind (&GainMeter::gain_automation_state_changed, this), gui_context());
215 gc->alist()->automation_style_changed.connect (model_connections, invalidator (*this), boost::bind (&GainMeter::gain_automation_style_changed, this), gui_context());
217 gain_automation_state_changed ();
220 amp->gain_control()->Changed.connect (model_connections, invalidator (*this), boost::bind (&GainMeterBase::gain_changed, this), gui_context());
224 update_gain_sensitive ();
228 GainMeterBase::setup_gain_adjustment ()
234 if (_previous_amp_output_streams == _amp->output_streams ()) {
238 ignore_toggle = true;
240 if (_amp->output_streams().n_midi() <= _amp->output_streams().n_audio()) {
241 _data_type = DataType::AUDIO;
242 gain_adjustment.set_lower (0.0);
243 gain_adjustment.set_upper (1.0);
244 gain_adjustment.set_step_increment (0.01);
245 gain_adjustment.set_page_increment (0.1);
246 gain_slider->set_default_value (gain_to_slider_position (1));
248 _data_type = DataType::MIDI;
249 gain_adjustment.set_lower (0.0);
250 gain_adjustment.set_upper (2.0);
251 gain_adjustment.set_step_increment (1.0/128.0);
252 gain_adjustment.set_page_increment (10.0/128.0);
253 gain_slider->set_default_value (1.0);
256 ignore_toggle = false;
258 effective_gain_display ();
260 _previous_amp_output_streams = _amp->output_streams ();
264 GainMeterBase::hide_all_meters ()
266 level_meter->hide_meters();
270 GainMeter::hide_all_meters ()
272 bool remove_metric_area = false;
274 GainMeterBase::hide_all_meters ();
276 if (remove_metric_area) {
277 if (meter_metric_area.get_parent()) {
278 level_meter->remove (meter_metric_area);
284 GainMeterBase::setup_meters (int len)
286 level_meter->setup_meters(len, 5);
290 GainMeter::setup_meters (int len)
292 if (!meter_metric_area.get_parent()) {
293 level_meter->pack_end (meter_metric_area, false, false);
294 meter_metric_area.show_all ();
296 GainMeterBase::setup_meters (len);
300 GainMeterBase::gain_key_press (GdkEventKey* ev)
302 if (key_is_legal_for_numeric_entry (ev->keyval)) {
303 /* drop through to normal handling */
306 /* illegal key for gain entry */
311 GainMeterBase::peak_button_release (GdkEventButton* ev)
313 /* reset peak label */
315 if (ev->button == 1 && Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier|Keyboard::TertiaryModifier)) {
316 ResetAllPeakDisplays ();
317 } else if (ev->button == 1 && Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
319 ResetGroupPeakDisplays (_route->route_group());
322 reset_peak_display ();
329 GainMeterBase::reset_peak_display ()
332 level_meter->clear_meters();
333 max_peak = -INFINITY;
334 peak_display.set_label (_("-Inf"));
335 peak_display.set_name ("MixerStripPeakDisplay");
339 GainMeterBase::reset_group_peak_display (RouteGroup* group)
341 if (_route && group == _route->route_group()) {
342 reset_peak_display ();
347 GainMeterBase::popup_meter_menu (GdkEventButton *ev)
349 using namespace Menu_Helpers;
351 if (meter_menu == 0) {
352 meter_menu = new Gtk::Menu;
353 MenuList& items = meter_menu->items();
355 items.push_back (MenuElem ("-inf .. +0dBFS"));
356 items.push_back (MenuElem ("-10dB .. +0dBFS"));
357 items.push_back (MenuElem ("-4 .. +0dBFS"));
358 items.push_back (SeparatorElem());
359 items.push_back (MenuElem ("-inf .. -2dBFS"));
360 items.push_back (MenuElem ("-10dB .. -2dBFS"));
361 items.push_back (MenuElem ("-4 .. -2dBFS"));
364 meter_menu->popup (1, ev->time);
368 GainMeterBase::gain_focused (GdkEventFocus* ev)
371 gain_display.select_region (0, -1);
373 gain_display.select_region (0, 0);
379 GainMeterBase::gain_activated ()
384 // Switch to user's preferred locale so that
385 // if they use different LC_NUMERIC conventions,
386 // we will honor them.
388 PBD::LocaleGuard lg ("");
389 if (sscanf (gain_display.get_text().c_str(), "%f", &f) != 1) {
394 /* clamp to displayable values */
395 if (_data_type == DataType::AUDIO) {
397 _amp->set_gain (dB_to_coefficient(f), this);
399 f = min (fabs (f), 2.0f);
400 _amp->set_gain (f, this);
403 if (gain_display.has_focus()) {
404 Gtk::Widget* w = gain_display.get_toplevel();
406 Gtk::Window* win = dynamic_cast<Gtk::Window*> (w);
408 /* sigh. gtkmm doesn't wrap get_default_widget() */
411 GtkWidget* f = gtk_window_get_default_widget (win->gobj());
413 gtk_widget_grab_focus (f);
422 GainMeterBase::show_gain ()
426 float v = gain_adjustment.get_value();
428 switch (_data_type) {
429 case DataType::AUDIO:
431 strcpy (buf, _("-inf"));
433 snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain_with_max (v, Config->get_max_gain())));
437 snprintf (buf, sizeof (buf), "%.1f", v);
441 gain_display.set_text (buf);
445 GainMeterBase::gain_adjusted ()
449 /* convert from adjustment range (0..1) to gain coefficient */
451 if (_data_type == DataType::AUDIO) {
452 value = slider_position_to_gain_with_max (gain_adjustment.get_value(), Config->get_max_gain());
454 value = gain_adjustment.get_value();
457 if (!ignore_toggle) {
458 if (_route && _route->amp() == _amp) {
459 _route->set_gain (value, this);
461 _amp->set_gain (value, this);
469 GainMeterBase::effective_gain_display ()
473 switch (_data_type) {
474 case DataType::AUDIO:
475 value = gain_to_slider_position_with_max (_amp->gain(), Config->get_max_gain());
478 value = _amp->gain ();
482 if (gain_adjustment.get_value() != value) {
483 ignore_toggle = true;
484 gain_adjustment.set_value (value);
485 ignore_toggle = false;
490 GainMeterBase::gain_changed ()
492 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&GainMeterBase::effective_gain_display, this));
496 GainMeterBase::set_meter_strip_name (const char * name)
498 meter_metric_area.set_name (name);
502 GainMeterBase::set_fader_name (const char * name)
504 gain_slider->set_name (name);
508 GainMeterBase::update_gain_sensitive ()
510 bool x = !(_amp->gain_control()->alist()->automation_state() & Play);
511 static_cast<Gtkmm2ext::SliderController*>(gain_slider)->set_sensitive (x);
515 next_meter_point (MeterPoint mp)
519 return MeterPreFader;
523 return MeterPostFader;
544 GainMeterBase::meter_press(GdkEventButton* ev)
546 wait_for_release = false;
552 if (!ignore_toggle) {
554 if (Keyboard::is_context_menu_event (ev)) {
556 // no menu at this time.
560 if (Keyboard::is_button2_event(ev)) {
562 // Primary-button2 click is the midi binding click
563 // button2-click is "momentary"
565 if (!Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier))) {
566 wait_for_release = true;
567 old_meter_point = _route->meter_point ();
571 if (_route && (ev->button == 1 || Keyboard::is_button2_event (ev))) {
573 if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
575 /* Primary+Tertiary-click applies change to all routes */
577 _session->foreach_route (this, &GainMeterBase::set_meter_point, next_meter_point (_route->meter_point()));
580 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
582 /* Primary-click: solo mix group.
583 NOTE: Primary-button2 is MIDI learn.
586 if (ev->button == 1) {
587 set_route_group_meter_point (*_route, next_meter_point (_route->meter_point()));
592 /* click: change just this route */
596 _route->set_meter_point (next_meter_point (_route->meter_point()));
607 GainMeterBase::meter_release(GdkEventButton*)
609 if (!ignore_toggle) {
610 if (wait_for_release) {
611 wait_for_release = false;
614 set_meter_point (*_route, old_meter_point);
623 GainMeterBase::set_meter_point (Route& route, MeterPoint mp)
625 route.set_meter_point (mp);
629 GainMeterBase::set_route_group_meter_point (Route& route, MeterPoint mp)
631 RouteGroup* route_group;
633 if ((route_group = route.route_group ()) != 0) {
634 route_group->foreach_route (boost::bind (&Route::set_meter_point, _1, mp, false));
636 route.set_meter_point (mp);
641 GainMeterBase::meter_point_clicked ()
649 GainMeterBase::gain_slider_button_press (GdkEventButton* ev)
652 case GDK_BUTTON_PRESS:
653 _amp->gain_control()->start_touch (_amp->session().transport_frame());
663 GainMeterBase::gain_slider_button_release (GdkEventButton*)
665 _amp->gain_control()->stop_touch (false, _amp->session().transport_frame());
670 GainMeterBase::gain_automation_state_button_event (GdkEventButton *ev)
672 if (ev->type == GDK_BUTTON_RELEASE) {
676 switch (ev->button) {
678 gain_astate_menu.popup (1, ev->time);
688 GainMeterBase::gain_automation_style_button_event (GdkEventButton *ev)
690 if (ev->type == GDK_BUTTON_RELEASE) {
694 switch (ev->button) {
696 gain_astyle_menu.popup (1, ev->time);
705 GainMeterBase::astate_string (AutoState state)
707 return _astate_string (state, false);
711 GainMeterBase::short_astate_string (AutoState state)
713 return _astate_string (state, true);
717 GainMeterBase::_astate_string (AutoState state, bool shrt)
723 sstr = (shrt ? "M" : _("M"));
726 sstr = (shrt ? "P" : _("P"));
729 sstr = (shrt ? "T" : _("T"));
732 sstr = (shrt ? "W" : _("W"));
740 GainMeterBase::astyle_string (AutoStyle style)
742 return _astyle_string (style, false);
746 GainMeterBase::short_astyle_string (AutoStyle style)
748 return _astyle_string (style, true);
752 GainMeterBase::_astyle_string (AutoStyle style, bool shrt)
757 /* XXX it might different in different languages */
759 return (shrt ? _("Abs") : _("Abs"));
764 GainMeterBase::gain_automation_style_changed ()
768 gain_automation_style_button.set_text (astyle_string(_amp->gain_control()->alist()->automation_style()));
771 gain_automation_style_button.set_text (short_astyle_string(_amp->gain_control()->alist()->automation_style()));
777 GainMeterBase::gain_automation_state_changed ()
779 ENSURE_GUI_THREAD (*this, &GainMeterBase::gain_automation_state_changed)
785 gain_automation_state_button.set_text (astate_string(_amp->gain_control()->alist()->automation_state()));
788 gain_automation_state_button.set_text (short_astate_string(_amp->gain_control()->alist()->automation_state()));
792 x = (_amp->gain_control()->alist()->automation_state() != ARDOUR::Off);
794 if (gain_automation_state_button.get_active() != x) {
795 ignore_toggle = true;
796 gain_automation_state_button.set_active (x);
797 ignore_toggle = false;
800 update_gain_sensitive ();
802 /* start watching automation so that things move */
804 gain_watching.disconnect();
807 gain_watching = ARDOUR_UI::RapidScreenUpdate.connect (sigc::mem_fun (*this, &GainMeterBase::effective_gain_display));
812 GainMeterBase::update_meters()
815 float mpeak = level_meter->update_meters();
817 if (mpeak > max_peak) {
819 if (mpeak <= -200.0f) {
820 peak_display.set_label (_("-inf"));
822 snprintf (buf, sizeof(buf), "%.1f", mpeak);
823 peak_display.set_label (buf);
827 peak_display.set_name ("MixerStripPeakDisplayPeak");
832 void GainMeterBase::color_handler(bool dpi)
834 color_changed = true;
835 dpi_changed = (dpi) ? true : false;
840 GainMeterBase::set_width (Width w, int len)
843 level_meter->setup_meters (len);
848 GainMeterBase::on_theme_changed()
850 style_changed = true;
853 GainMeter::GainMeter (Session* s, int fader_length)
854 : GainMeterBase (s, false, fader_length, 24)
855 , gain_display_box(true, 0)
858 if (gain_display.get_parent()) {
859 gain_display.get_parent()->remove (gain_display);
861 gain_display_box.pack_start (gain_display, true, true);
863 meter_metric_area.set_name ("AudioTrackMetrics");
864 set_size_request_to_display_given_text (meter_metric_area, "-127", 1, 0);
866 gain_automation_style_button.set_name ("mixer strip button");
867 gain_automation_state_button.set_name ("mixer strip button");
869 ARDOUR_UI::instance()->set_tip (gain_automation_state_button, _("Fader automation mode"));
870 ARDOUR_UI::instance()->set_tip (gain_automation_style_button, _("Fader automation type"));
872 gain_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
873 gain_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
875 gain_automation_state_button.set_size_request(15, 15);
876 gain_automation_style_button.set_size_request(15, 15);
878 fader_vbox = manage (new Gtk::VBox());
879 fader_vbox->set_spacing (0);
880 fader_vbox->pack_start (*gain_slider, true, true);
882 fader_alignment.set (0.5, 0.5, 0.0, 1.0);
883 fader_alignment.add (*fader_vbox);
885 hbox.pack_start (fader_alignment, true, true);
889 pack_start (gain_display_box, Gtk::PACK_SHRINK);
890 pack_start (hbox, Gtk::PACK_SHRINK);
892 meter_alignment.set (0.5, 0.5, 0.0, 1.0);
893 meter_alignment.add (*level_meter);
895 meter_metric_area.signal_expose_event().connect (
896 sigc::mem_fun(*this, &GainMeter::meter_metrics_expose));
900 GainMeter::set_controls (boost::shared_ptr<Route> r,
901 boost::shared_ptr<PeakMeter> meter,
902 boost::shared_ptr<Amp> amp)
904 if (meter_alignment.get_parent()) {
905 hbox.remove (meter_alignment);
908 // if (gain_automation_state_button.get_parent()) {
909 // fader_vbox->remove (gain_automation_state_button);
912 GainMeterBase::set_controls (r, meter, amp);
915 _meter->ConfigurationChanged.connect (
916 model_connections, invalidator (*this), boost::bind (&GainMeter::meter_configuration_changed, this, _1), gui_context()
919 meter_configuration_changed (_meter->input_streams ());
924 if we have a non-hidden route (ie. we're not the click or the auditioner),
925 pack some route-dependent stuff.
928 hbox.pack_start (meter_alignment, true, true);
930 // if (r && !r->is_auditioner()) {
931 // fader_vbox->pack_start (gain_automation_state_button, false, false, 0);
939 GainMeter::get_gm_width ()
942 hbox.size_request (sz);
947 GainMeter::render_metrics (Gtk::Widget& w, vector<DataType> types)
949 Glib::RefPtr<Gdk::Window> win (w.get_window());
952 win->get_size (width, height);
954 cairo_surface_t* surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, height);
955 cairo_t* cr = cairo_create (surface);
956 Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(w.get_pango_context());
959 Pango::AttrList audio_font_attributes;
960 Pango::AttrList midi_font_attributes;
962 Pango::AttrFontDesc* font_attr;
963 Pango::FontDescription font;
965 font = Pango::FontDescription (""); // use defaults
966 //font = get_font_for_style("gain-fader");
967 //font = w.get_style()->get_font();
969 font.set_weight (Pango::WEIGHT_NORMAL);
970 font.set_size (10.0 * PANGO_SCALE);
971 font_attr = new Pango::AttrFontDesc (Pango::Attribute::create_attr_font_desc (font));
972 audio_font_attributes.change (*font_attr);
975 font.set_weight (Pango::WEIGHT_ULTRALIGHT);
976 font.set_stretch (Pango::STRETCH_ULTRA_CONDENSED);
977 font.set_size (7.5 * PANGO_SCALE);
978 font_attr = new Pango::AttrFontDesc (Pango::Attribute::create_attr_font_desc (font));
979 midi_font_attributes.change (*font_attr);
983 cairo_move_to (cr, 0, 0);
984 cairo_rectangle (cr, 0, 0, width, height);
986 Gdk::Color c = w.get_style()->get_bg (Gtk::STATE_NORMAL);
987 cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
991 for (vector<DataType>::const_iterator i = types.begin(); i != types.end(); ++i) {
995 if (types.size() > 1) {
996 /* we're overlaying more than 1 set of marks, so use different colours */
999 case DataType::AUDIO:
1000 c = w.get_style()->get_fg (Gtk::STATE_NORMAL);
1001 cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
1003 case DataType::MIDI:
1004 c = w.get_style()->get_fg (Gtk::STATE_ACTIVE);
1005 cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
1009 c = w.get_style()->get_fg (Gtk::STATE_NORMAL);
1010 cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
1016 case DataType::AUDIO:
1017 layout->set_attributes (audio_font_attributes);
1018 points.push_back (-50);
1019 points.push_back (-40);
1020 points.push_back (-30);
1021 points.push_back (-20);
1022 points.push_back (-10);
1023 points.push_back (-3);
1024 points.push_back (0);
1025 points.push_back (4);
1028 case DataType::MIDI:
1029 layout->set_attributes (midi_font_attributes);
1030 points.push_back (0);
1031 if (types.size() == 1) {
1032 points.push_back (32);
1034 /* tweak so as not to overlay the -30dB mark */
1035 points.push_back (48);
1037 points.push_back (64);
1038 points.push_back (96);
1039 points.push_back (127);
1045 for (vector<int>::const_iterator j = points.begin(); j != points.end(); ++j) {
1049 case DataType::AUDIO:
1050 fraction = log_meter (*j);
1052 case DataType::MIDI:
1053 fraction = *j / 127.0;
1057 gint const pos = height - (gint) floor (height * fraction);
1059 cairo_set_line_width (cr, 1.0);
1060 cairo_move_to (cr, 0, pos);
1061 cairo_line_to (cr, 3.5, pos);
1064 snprintf (buf, sizeof (buf), "%2d", abs (*j));
1065 layout->set_text(buf);
1067 /* we want logical extents, not ink extents here */
1070 layout->get_pixel_size(tw, th);
1072 int p = pos - (th / 2);
1073 p = min (p, height - th);
1076 cairo_move_to (cr, 5, p);
1077 pango_cairo_show_layout (cr, layout->gobj());
1081 cairo_pattern_t* pattern = cairo_pattern_create_for_surface (surface);
1082 MetricPatterns::iterator p;
1084 if ((p = metric_patterns.find (w.get_name())) != metric_patterns.end()) {
1085 cairo_pattern_destroy (p->second);
1088 metric_patterns[w.get_name()] = pattern;
1091 cairo_surface_destroy (surface);
1097 GainMeter::meter_metrics_expose (GdkEventExpose *ev)
1099 Glib::RefPtr<Gdk::Window> win (meter_metric_area.get_window());
1102 cr = gdk_cairo_create (win->gobj());
1104 /* clip to expose area */
1106 gdk_cairo_rectangle (cr, &ev->area);
1109 cairo_pattern_t* pattern;
1110 MetricPatterns::iterator i = metric_patterns.find (meter_metric_area.get_name());
1112 if (i == metric_patterns.end() || style_changed || dpi_changed) {
1113 pattern = render_metrics (meter_metric_area, _types);
1115 pattern = i->second;
1118 cairo_move_to (cr, 0, 0);
1119 cairo_set_source (cr, pattern);
1122 win->get_size (width, height);
1124 cairo_rectangle (cr, 0, 0, width, height);
1127 style_changed = false;
1128 dpi_changed = false;
1135 boost::shared_ptr<PBD::Controllable>
1136 GainMeterBase::get_controllable()
1139 return _amp->gain_control();
1141 return boost::shared_ptr<PBD::Controllable>();
1146 GainMeterBase::level_meter_button_press (GdkEventButton* ev)
1148 return LevelMeterButtonPress (ev); /* EMIT SIGNAL */
1152 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);
1162 style_changed = true;
1163 meter_metric_area.queue_draw ();