- metric_patterns.clear();
- ticks_patterns.clear();
- VBox::on_size_allocate(a);
-}
-
-/* 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_NORMAL);
- cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
- }
- cairo_fill (cr);
-
- height = min(1024, height); // XXX see FastMeter::max_pattern_metric_size
-
- 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());
- }
-
- vector<int> points;
-
- switch (*i) {
- case DataType::AUDIO:
- layout->set_attributes (audio_font_attributes);
- points.push_back (-50);
- points.push_back (-40);
- points.push_back (-30);
- points.push_back (-25);
- points.push_back (-20);
- points.push_back (-18);
- points.push_back (-15);
- points.push_back (-10);
- points.push_back (-5);
- points.push_back (-3);
- points.push_back (0);
- points.push_back (3);
- break;
-
- case DataType::MIDI:
- layout->set_attributes (midi_font_attributes);
- points.push_back (0);
- if (types.size() == 1) {
- points.push_back (32);
- } else {
- /* tweak so as not to overlay the -30dB mark */
- points.push_back (48);
- }
- if (types.size() == 1) {
- points.push_back (64); // very close to -18dB
- points.push_back (96); // overlays with -6dB mark
- } else {
- points.push_back (72);
- points.push_back (88);
- }
- points.push_back (127);
- break;
- }
-
- char buf[32];
-
- for (vector<int>::const_iterator j = points.begin(); j != points.end(); ++j) {
-
- float fraction = 0;
- switch (*i) {
- case DataType::AUDIO:
- fraction = log_meter (*j);
- snprintf (buf, sizeof (buf), "%+2d", *j);
- break;
- case DataType::MIDI:
- fraction = *j / 127.0;
- snprintf (buf, sizeof (buf), "%3d", *j);
- break;
- }
-
- gint const pos = height - (gint) floor (height * fraction);
- 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-1-tw, p + .5);
- pango_cairo_show_layout (cr, layout->gobj());
- }