spek

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

commit f625d32a6e5393de4757ed930caf5ff802fb2008
parent 64d19bd837fa375ae3f526e2f8f62ac496277057
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date:   Sun, 16 May 2010 18:11:14 +1000

Duration ruler (start and end only)

Diffstat:
Msrc/spek-source.vala | 2++
Msrc/spek-spectrogram.vala | 24+++++++++++++++++++++++-
2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/spek-source.vala b/src/spek-source.vala @@ -27,6 +27,7 @@ namespace Spek { public int threshold { get; construct; } // TODO: file a bug, cannot s/set/construct/ public Callback callback {get; set; } + public int64 duration { get; private set; } public delegate void Callback (int sample, float[] values); @@ -84,6 +85,7 @@ namespace Spek { Format format; int64 duration; query.parse_duration (out format, out duration); + this.duration = duration; spectrum.set ("interval", duration / (samples + 1)); pipeline.set_state (State.PLAYING); diff --git a/src/spek-spectrogram.vala b/src/spek-spectrogram.vala @@ -108,13 +108,35 @@ namespace Spek { cr.set_source_rgb (0, 0, 0); cr.paint (); - // Draw the spectrogram. if (image != null) { + // Draw the spectrogram. cr.translate (PADDING, h - PADDING); cr.scale (1, -(h - 2 * PADDING) / image.get_height ()); cr.set_source_surface (image, 0, 0); cr.paint (); cr.identity_matrix (); + + // Time ruler. + int64[] time_points = {0, source.duration}; + cr.set_source_rgb (1, 1, 1); + cr.set_line_width (1); + cr.set_antialias (Antialias.NONE); + cr.select_font_face ("sans-serif", FontSlant.NORMAL, FontWeight.NORMAL); + cr.set_font_size (10.0); + TextExtents ext; + cr.text_extents ("00:00", out ext); + double tick_width = ext.width; + foreach (var pt in time_points) { + var seconds = (int) (pt / 1000000000); + var label = "%d:%02d".printf (seconds / 60, seconds % 60); + var pos = PADDING + (w - 2 * PADDING) * pt / source.duration; + cr.text_extents (label, out ext); + cr.move_to (pos - ext.width / 2, h - PADDING + GAP + ext.height); + cr.show_text (label); + cr.move_to (pos, h - PADDING); + cr.rel_line_to (0, 4); + cr.stroke (); + } } // Border around the spectrogram.