-/* XXX code-copy from gain_meter.cc -- TODO consolidate
- *
- * slightly different:
- * - ticks & label positions are swapped
- * - more ticks for audio (longer meter by default)
- * - right-aligned lables, unit-legend
- * - height limitation of FastMeter::max_pattern_metric_size is included here
- */
-cairo_pattern_t*
-MeterStrip::render_metrics (Gtk::Widget& w, vector<DataType> types)
-{
- Glib::RefPtr<Gdk::Window> win (w.get_window());
-
- gint width, height;
- win->get_size (width, height);
-
- cairo_surface_t* surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, height);
- cairo_t* cr = cairo_create (surface);
- Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(w.get_pango_context());
-
- Pango::AttrList audio_font_attributes;
- Pango::AttrList midi_font_attributes;
- Pango::AttrList unit_font_attributes;
-
- Pango::AttrFontDesc* font_attr;
- Pango::FontDescription font;
-
- font = Pango::FontDescription (""); // use defaults
- //font = get_font_for_style("gain-fader");
- //font = w.get_style()->get_font();
-
- font.set_weight (Pango::WEIGHT_NORMAL);
- font.set_size (9.0 * PANGO_SCALE);
- font_attr = new Pango::AttrFontDesc (Pango::Attribute::create_attr_font_desc (font));
- audio_font_attributes.change (*font_attr);
- delete font_attr;
-
- font.set_weight (Pango::WEIGHT_ULTRALIGHT);
- font.set_stretch (Pango::STRETCH_ULTRA_CONDENSED);
- font.set_size (7.5 * PANGO_SCALE);
- font_attr = new Pango::AttrFontDesc (Pango::Attribute::create_attr_font_desc (font));
- midi_font_attributes.change (*font_attr);
- delete font_attr;
-
- font.set_size (7.0 * PANGO_SCALE);
- font_attr = new Pango::AttrFontDesc (Pango::Attribute::create_attr_font_desc (font));
- unit_font_attributes.change (*font_attr);
- delete font_attr;
-
- cairo_move_to (cr, 0, 0);
- cairo_rectangle (cr, 0, 0, width, height);
- {
- Gdk::Color c = w.get_style()->get_bg (Gtk::STATE_ACTIVE);
- cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
- }
- cairo_fill (cr);
-
- if (height > max_pattern_metric_size) {
- cairo_move_to (cr, 0, max_pattern_metric_size + 1);
- cairo_rectangle (cr, 0, max_pattern_metric_size, width, height - max_pattern_metric_size);
- Gdk::Color c = w.get_style()->get_bg (Gtk::STATE_ACTIVE);
- cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
- cairo_fill (cr);
- }
-
- height = min(max_pattern_metric_size, height);
- uint32_t peakcolor = ARDOUR_UI::config()->color_by_name ("meterbridge peaklabel");
-
- for (vector<DataType>::const_iterator i = types.begin(); i != types.end(); ++i) {
-
- Gdk::Color c;
-
- if (types.size() > 1) {
- /* we're overlaying more than 1 set of marks, so use different colours */
- Gdk::Color c;
- switch (*i) {
- case DataType::AUDIO:
- c = w.get_style()->get_fg (Gtk::STATE_NORMAL);
- cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
- break;
- case DataType::MIDI:
- c = w.get_style()->get_fg (Gtk::STATE_ACTIVE);
- cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
- break;
- }
- } else {
- c = w.get_style()->get_fg (Gtk::STATE_NORMAL);
- cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
- }
-
- std::map<int,float> points;
-
- switch (*i) {
- case DataType::AUDIO:
- layout->set_attributes (audio_font_attributes);
- points.insert (std::pair<int,float>(-50, 0.5));
- points.insert (std::pair<int,float>(-40, 0.5));
- points.insert (std::pair<int,float>(-30, 0.5));
- points.insert (std::pair<int,float>(-25, 0.5));
- points.insert (std::pair<int,float>(-20, 1.0));
- points.insert (std::pair<int,float>(-18, 1.0));
- points.insert (std::pair<int,float>(-15, 1.0));
- points.insert (std::pair<int,float>(-10, 1.0));
- points.insert (std::pair<int,float>( -5, 1.0));
- points.insert (std::pair<int,float>( -3, 0.5));
- points.insert (std::pair<int,float>( 0, 1.0));
- points.insert (std::pair<int,float>( 3, 0.5));
- break;
-
- case DataType::MIDI:
- layout->set_attributes (midi_font_attributes);
- points.insert (std::pair<int,float>( 0, 1.0));
- if (types.size() == 1) {
- points.insert (std::pair<int,float>( 16, 0.5));
- points.insert (std::pair<int,float>( 32, 0.5));
- points.insert (std::pair<int,float>( 48, 0.5));
- points.insert (std::pair<int,float>( 64, 1.0));
- points.insert (std::pair<int,float>( 80, 0.5));
- points.insert (std::pair<int,float>( 96, 0.5));
- points.insert (std::pair<int,float>(100, 0.5));
- points.insert (std::pair<int,float>(112, 0.5));
- } else {
- /* labels that don't overlay with dB */
- points.insert (std::pair<int,float>( 48, 0.5));
- points.insert (std::pair<int,float>( 72, 0.5));
- points.insert (std::pair<int,float>( 88, 0.5));
- }
- points.insert (std::pair<int,float>(127, 1.0));
- break;
- }
-
- char buf[32];
- gint pos;
-
- for (std::map<int,float>::const_iterator j = points.begin(); j != points.end(); ++j) {
-
- float fraction = 0;
- switch (*i) {
- case DataType::AUDIO:
- cairo_set_line_width (cr, (j->second));
- if (j->first >= 0) {
- cairo_set_source_rgb (cr,
- UINT_RGBA_R_FLT(peakcolor),
- UINT_RGBA_G_FLT(peakcolor),
- UINT_RGBA_B_FLT(peakcolor));
- }
- fraction = log_meter (j->first);
- snprintf (buf, sizeof (buf), "%+2d", j->first);
- pos = height - (gint) floor (height * fraction);
- cairo_move_to(cr, width-2.5, pos + .5);
- cairo_line_to(cr, width, pos + .5);
- cairo_stroke (cr);
- break;
- case DataType::MIDI:
- cairo_set_line_width (cr, 1.0);
- fraction = (j->first) / 127.0;
- snprintf (buf, sizeof (buf), "%3d", j->first);
- pos = 1 + height - (gint) rintf (height * fraction);
- pos = min (pos, height);
- cairo_arc(cr, 3, pos + .5, 1.0, 0, 2 * M_PI);
- cairo_fill(cr);
- break;
- }
-
- layout->set_text(buf);
-
- /* we want logical extents, not ink extents here */
-
- int tw, th;
- layout->get_pixel_size(tw, th);
-
- int p = pos - (th / 2);
- p = min (p, height - th);
- p = max (p, 0);
-
- cairo_move_to (cr, width-4-tw, p);
- pango_cairo_show_layout (cr, layout->gobj());
- }
- }
-
- if (types.size() == 1) {
- int tw, th;
- layout->set_attributes (unit_font_attributes);
- switch (types.at(0)) {
- case DataType::AUDIO:
- layout->set_text("dBFS");
- layout->get_pixel_size(tw, th);
- break;
- case DataType::MIDI:
- layout->set_text("vel");
- layout->get_pixel_size(tw, th);
- break;
- }
- Gdk::Color c = w.get_style()->get_fg (Gtk::STATE_ACTIVE);
- cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
- cairo_move_to (cr, 1, height - th - 1.5);
- pango_cairo_show_layout (cr, layout->gobj());
- }
-
- cairo_pattern_t* pattern = cairo_pattern_create_for_surface (surface);
- MetricPatterns::iterator p;
-
- if ((p = metric_patterns.find (w.get_name())) != metric_patterns.end()) {
- cairo_pattern_destroy (p->second);
- }
-
- metric_patterns[w.get_name()] = pattern;
-
- cairo_destroy (cr);
- cairo_surface_destroy (surface);
-
- return pattern;
-}
-
-/* XXX code-copy from gain_meter.cc -- TODO consolidate */