From: Kaj-Michael Lang Date: Mon, 7 Apr 2008 14:05:49 +0000 (+0300) Subject: Use pretty time format for audio note X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a0f5ecf4ff82720fa11da723f7ac453b2141ac0;p=mapper Use pretty time format for audio note --- diff --git a/src/audio-note.c b/src/audio-note.c index ad6f52f..445b633 100644 --- a/src/audio-note.c +++ b/src/audio-note.c @@ -39,13 +39,35 @@ static GstBus *bus; static gboolean audio_note_stop(audio_note_ui *ui); +#define GST_TIME_TO_SECS(t) \ + (gdouble) (((gdouble)(t)) / (gdouble) GST_SECOND) /* GST_SECOND should be 1e9 */ + +static void +audio_note_set_length(audio_note_ui *ui, gdouble secs) +{ +gchar buffer[16]; +guint min=0; + +if (secs<0.0) { + gtk_label_set_text(GTK_LABEL(ui->lbl_time), "--:--"); + return; +} + +if (secs>=60.0) { + min=secs/60.0; + secs-=min*60.0; +} + +g_snprintf(buffer, sizeof(buffer), "%u:%05.2f", min, secs); +gtk_label_set_text(GTK_LABEL(ui->lbl_time), buffer); +} + static gboolean audio_note_position_cb(gpointer data) { GstFormat fmt=GST_FORMAT_TIME; GstElement *pipe; gint64 pos, len; -gchar buffer[128]; audio_note_ui *ui=(audio_note_ui *)data; if (ui->note_record->active) @@ -56,9 +78,8 @@ else else return TRUE; -if (gst_element_query_position (pipe, &fmt, &pos) && gst_element_query_duration (pipe, &fmt, &len)) { - g_snprintf(buffer, sizeof(buffer), "Time: %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT, GST_TIME_ARGS (pos), GST_TIME_ARGS (len)); - gtk_label_set_text(GTK_LABEL(ui->lbl_time), buffer); +if (gst_element_query_position(pipe, &fmt, &pos) && gst_element_query_duration(pipe, &fmt, &len)) { + audio_note_set_length(ui, GST_TIME_TO_SECS(pos)); } return TRUE;