+
+void GainMeterBase::color_handler(bool dpi)
+{
+ color_changed = true;
+ dpi_changed = (dpi) ? true : false;
+ setup_meters();
+}
+
+void
+GainMeterBase::set_width (Width w, int len)
+{
+ _width = w;
+ level_meter->setup_meters (len);
+}
+
+
+void
+GainMeterBase::on_theme_changed()
+{
+ style_changed = true;
+}
+
+GainMeter::GainMeter (Session* s, int fader_length)
+ : GainMeterBase (s, slider, false, fader_length)
+{
+ gain_display_box.set_homogeneous (true);
+ gain_display_box.set_spacing (2);
+ gain_display_box.pack_start (gain_display, true, true);
+
+ meter_metric_area.set_name ("AudioTrackMetrics");
+ set_size_request_to_display_given_text (meter_metric_area, "-50", 0, 0);
+
+ gain_automation_style_button.set_name ("MixerAutomationModeButton");
+ gain_automation_state_button.set_name ("MixerAutomationPlaybackButton");
+
+ ARDOUR_UI::instance()->set_tip (gain_automation_state_button, _("Fader automation mode"));
+ ARDOUR_UI::instance()->set_tip (gain_automation_style_button, _("Fader automation type"));
+
+ gain_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
+ gain_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
+
+ gain_automation_state_button.set_size_request(15, 15);
+ gain_automation_style_button.set_size_request(15, 15);
+
+ HBox* fader_centering_box = manage (new HBox);
+ fader_centering_box->pack_start (*gain_slider, true, false);
+
+ fader_vbox = manage (new Gtk::VBox());
+ fader_vbox->set_spacing (0);
+ fader_vbox->pack_start (*fader_centering_box, false, false, 0);
+
+ hbox.set_spacing (2);
+ hbox.pack_start (*fader_vbox, true, true);
+
+ set_spacing (2);
+
+ pack_start (gain_display_box, Gtk::PACK_SHRINK);
+ pack_start (hbox, Gtk::PACK_SHRINK);
+
+ meter_metric_area.signal_expose_event().connect (sigc::mem_fun(*this, &GainMeter::meter_metrics_expose));
+}
+
+void
+GainMeter::set_controls (boost::shared_ptr<Route> r,
+ boost::shared_ptr<PeakMeter> meter,
+ boost::shared_ptr<Amp> amp)
+{
+ if (level_meter->get_parent()) {
+ hbox.remove (*level_meter);
+ }
+
+ if (peak_display.get_parent()) {
+ gain_display_box.remove (peak_display);
+ }
+
+ if (gain_automation_state_button.get_parent()) {
+ fader_vbox->remove (gain_automation_state_button);
+ }
+
+ GainMeterBase::set_controls (r, meter, amp);
+
+ /*
+ if we have a non-hidden route (ie. we're not the click or the auditioner),
+ pack some route-dependent stuff.
+ */
+
+ gain_display_box.pack_end (peak_display, true, true);
+ hbox.pack_end (*level_meter, true, true);
+
+ if (r && !r->is_hidden()) {
+ fader_vbox->pack_start (gain_automation_state_button, false, false, 0);
+ }
+
+ setup_meters ();
+ hbox.show_all ();
+}
+
+int
+GainMeter::get_gm_width ()
+{
+ Gtk::Requisition sz;
+ hbox.size_request (sz);
+ return sz.width;
+}
+
+Glib::RefPtr<Gdk::Pixmap>
+GainMeter::render_metrics (Gtk::Widget& w)
+{
+ Glib::RefPtr<Gdk::Window> win (w.get_window());
+ Glib::RefPtr<Gdk::GC> fg_gc (w.get_style()->get_fg_gc (Gtk::STATE_NORMAL));
+ Glib::RefPtr<Gdk::GC> bg_gc (w.get_style()->get_bg_gc (Gtk::STATE_NORMAL));
+ gint width, height;
+ int db_points[] = { -50, -40, -20, -30, -10, -3, 0, 4 };
+ char buf[32];
+
+ win->get_size (width, height);
+
+ Glib::RefPtr<Gdk::Pixmap> pixmap = Gdk::Pixmap::create (win, width, height);
+
+ metric_pixmaps[w.get_name()] = pixmap;
+
+ pixmap->draw_rectangle (bg_gc, true, 0, 0, width, height);
+
+ Glib::RefPtr<Pango::Layout> layout = w.create_pango_layout("");
+
+ for (uint32_t i = 0; i < sizeof (db_points)/sizeof (db_points[0]); ++i) {
+
+ float fraction = log_meter (db_points[i]);
+ gint pos = height - (gint) floor (height * fraction);
+
+ snprintf (buf, sizeof (buf), "%d", abs (db_points[i]));
+
+ layout->set_text (buf);
+
+ /* we want logical extents, not ink extents here */
+
+ int width, height;
+ layout->get_pixel_size (width, height);
+
+ pixmap->draw_line (fg_gc, 0, pos, 4, pos);
+ pixmap->draw_layout (fg_gc, 6, pos - (height/2), layout);
+ }
+
+ return pixmap;
+}
+
+gint
+GainMeter::meter_metrics_expose (GdkEventExpose *ev)
+{
+ static Glib::RefPtr<Gtk::Style> meter_style;
+ if (style_changed) {
+ meter_style = meter_metric_area.get_style();
+ }
+ Glib::RefPtr<Gdk::Window> win (meter_metric_area.get_window());
+ Glib::RefPtr<Gdk::GC> bg_gc (meter_style->get_bg_gc (Gtk::STATE_INSENSITIVE));
+ GdkRectangle base_rect;
+ GdkRectangle draw_rect;
+ gint width, height;
+
+ win->get_size (width, height);
+
+ base_rect.width = width;
+ base_rect.height = height;
+ base_rect.x = 0;
+ base_rect.y = 0;
+
+ Glib::RefPtr<Gdk::Pixmap> pixmap;
+ std::map<string,Glib::RefPtr<Gdk::Pixmap> >::iterator i = metric_pixmaps.find (meter_metric_area.get_name());
+
+ if (i == metric_pixmaps.end() || style_changed || dpi_changed) {
+ pixmap = render_metrics (meter_metric_area);
+ } else {
+ pixmap = i->second;
+ }
+
+ gdk_rectangle_intersect (&ev->area, &base_rect, &draw_rect);
+ win->draw_drawable (bg_gc, pixmap, draw_rect.x, draw_rect.y, draw_rect.x, draw_rect.y, draw_rect.width, draw_rect.height);
+ style_changed = false;
+ return true;
+}
+
+boost::shared_ptr<PBD::Controllable>
+GainMeterBase::get_controllable()
+{
+ if (_amp) {
+ return _amp->gain_control();
+ } else {
+ return boost::shared_ptr<PBD::Controllable>();
+ }
+}
+
+