spek

Acoustic spectrum analyser
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

commit 6387760b7b7481796af7a4151a1e016846a2d299
parent 55a39fae102ff06ef43c028b4d2d56232bf65721
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date:   Mon, 28 Mar 2011 17:46:05 +0800

Fix the density ruler ticks

Diffstat:
Msrc/spek-ruler.vala | 19+++++++++++--------
Msrc/spek-spectrogram.vala | 5++++-
2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/spek-ruler.vala b/src/spek-ruler.vala @@ -33,22 +33,25 @@ namespace Spek { private int[] factors; private int units; private double spacing; - private UnitToPixel unit_to_pixel; + private Measure measure; + private Place place; private FormatTick format_tick; - public delegate double UnitToPixel (int unit); + public delegate double Measure (int unit); + public delegate double Place (double p); public delegate string FormatTick (int unit); public Ruler ( Position pos, string sample_label, int[] factors, int units, double spacing, - UnitToPixel unit_to_pixel, FormatTick format_tick) { + Measure measure, Place place, FormatTick format_tick) { this.pos = pos; this.sample_label = sample_label; this.factors = factors; this.units = units; this.spacing = spacing; - this.unit_to_pixel = unit_to_pixel; + this.measure = measure; + this.place = place; this.format_tick = format_tick; } @@ -62,7 +65,7 @@ namespace Spek { // Select the factor to use, we want some space between the labels. int factor = 0; foreach (var f in factors) { - if (unit_to_pixel (f) >= spacing * size) { + if (measure (f) >= spacing * size) { factor = f; break; } @@ -72,7 +75,7 @@ namespace Spek { int[] ticks = { 0, units }; if (factor > 0) { for (var tick = factor; tick < units; tick += factor) { - if (unit_to_pixel (units - tick) < size * 1.2) { + if (measure (units - tick) < size * 1.2) { break; } ticks += tick; @@ -85,9 +88,9 @@ namespace Spek { double TICK_LEN = 4; foreach (var tick in ticks) { var label = format_tick (tick); - var p = unit_to_pixel ( + var p = place (measure ( pos == Position.TOP || pos == Position.BOTTOM - ? tick : units - tick); + ? tick : units - tick)); layout.set_text (label, -1); layout.get_pixel_size (out w, out h); if (pos == Position.TOP) { diff --git a/src/spek-spectrogram.vala b/src/spek-spectrogram.vala @@ -190,6 +190,7 @@ namespace Spek { duration_seconds, 1.5, unit => (w - LPAD - RPAD) * unit / duration_seconds, + p => p, // TODO: i18n unit => "%d:%02d".printf (unit / 60, unit % 60)); cr.translate (LPAD, h - BPAD); @@ -205,6 +206,7 @@ namespace Spek { freq, 3.0, unit => (h - TPAD - BPAD) * unit / freq, + p => p, unit => _("%d kHz").printf (unit / 1000)); cr.translate (LPAD, TPAD); rate_ruler.draw (cr, layout); @@ -260,7 +262,8 @@ namespace Spek { -THRESHOLD, 3.0, unit => -(h - TPAD - BPAD) * unit / THRESHOLD, - unit => _("%d dB").printf (unit + THRESHOLD)); + p => h - TPAD - BPAD - p, + unit => _("%d dB").printf (-unit)); cr.translate (w - RPAD + GAP + RULER, TPAD); density_ruler.draw (cr, layout); cr.identity_matrix ();