From 697c2c1113d88ed9f9d1c4d0570bec02a54ff94c Mon Sep 17 00:00:00 2001 From: Martin Blanchard Date: Tue, 20 Dec 2011 00:43:28 +0100 Subject: [PATCH] Random work from the last mounth... --- data/main.ui | 46 ++++++++++++++++++++++--------- libdictix/dix-recorder.c | 71 ++++++++++++++++++++++++++++++++++++++++++++---- src/dix-main.vala | 14 +++++----- src/dix-ui.vala | 49 +++++++++------------------------ vapi/libdictix.vapi | 12 ++++++++ 5 files changed, 131 insertions(+), 61 deletions(-) diff --git a/data/main.ui b/data/main.ui index c187b38..d5f10ae 100644 --- a/data/main.ui +++ b/data/main.ui @@ -144,8 +144,37 @@ True play-pause-action False - play-image none + + + True + False + + + True + False + media-playback-start-symbolic + + + False + True + 0 + + + + + True + False + media-playback-pause-symbolic + + + False + True + 1 + + + + False @@ -278,6 +307,7 @@ audio-volume-medium Record 128 + 30 True True True @@ -289,7 +319,7 @@ audio-volume-medium False - True + False 16 end 2 @@ -379,16 +409,6 @@ audio-volume-medium - - True - False - media-playback-pause-symbolic - - - True - False - media-playback-start-symbolic - True False @@ -512,7 +532,7 @@ audio-volume-medium 0 - middle - 21 + 12 1 diff --git a/libdictix/dix-recorder.c b/libdictix/dix-recorder.c index 2a81330..e4ed9d1 100755 --- a/libdictix/dix-recorder.c +++ b/libdictix/dix-recorder.c @@ -34,6 +34,7 @@ enum { PROP_0, + PROP_BANDS, PROP_LAST_RECORD_TIMEVAL, PROP_RECORDS_PATH }; @@ -56,11 +57,15 @@ struct _DixRecorderPrivate GstElement *source; GstElement *converter; + GstElement *spectrum; GstElement *encoder; GstElement *sink; GDateTime *last_record_timeval; guint record_count; + + guint bands; + gfloat *magnitudes; }; static const gchar *id_characters = "0123456789abcdef"; @@ -95,6 +100,10 @@ static gchar *months[] = { #define DIX_RECORDER_ID_SIZE 32 #define DIX_RECORDER_ID_CHARACTERS_SIZE 16 +#define DIX_RECORDER_SPECTRUM_BANDS 8 +#define DIX_RECORDER_SPECTRUM_THRESHOLD -80 +#define DIX_RECORDER_SPECTRUM_THRESHOLD_F -80.0f + #define DIX_RECORDER_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE ((obj), DIX_TYPE_RECORDER, DixRecorderPrivate)) @@ -138,7 +147,11 @@ dix_recorder_get_property (GObject *object, guint prop_id, GValue *value, GParam DixRecorderPrivate *priv = recorder->priv; switch (prop_id) { - case PROP_RECORDS_PATH: { + case PROP_BANDS: { + g_value_set_uint (value, priv->bands); + + break; + } case PROP_RECORDS_PATH: { g_value_set_string (value, g_strdup (priv->path)); break; @@ -194,6 +207,14 @@ dix_recorder_class_init (DixRecorderClass* klass) gobject_class->finalize = dix_recorder_finalize; g_object_class_install_property (gobject_class, + PROP_BANDS, + g_param_spec_uint ("bands", + "Bands", + "Number of frequency bands.", + 6, 12, DIX_RECORDER_SPECTRUM_BANDS, + G_PARAM_READABLE)); + + g_object_class_install_property (gobject_class, PROP_LAST_RECORD_TIMEVAL, g_param_spec_uint64 ("last-record-timeval", "Last record timeval", @@ -207,7 +228,7 @@ dix_recorder_class_init (DixRecorderClass* klass) "Records directory", "A path to the directory where records are put", NULL, - G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE)); + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); signals[RECORDING_STARTED] = g_signal_new ("record-started", G_TYPE_FROM_CLASS (gobject_class), @@ -241,6 +262,7 @@ dix_recorder_init (DixRecorder* recorder) { DixRecorderPrivate *priv = DIX_RECORDER_GET_PRIVATE (recorder); recorder->priv = priv; + gint i; gst_object_set_name (GST_OBJECT(recorder), "DictixRecorder"); @@ -251,11 +273,18 @@ dix_recorder_init (DixRecorder* recorder) priv->source = NULL; priv->converter = NULL; + priv->spectrum = NULL; priv->encoder = NULL; priv->sink = NULL; priv->last_record_timeval = NULL; priv->record_count = 1; + + priv->bands = DIX_RECORDER_SPECTRUM_BANDS; + priv->magnitudes = g_malloc (priv->bands * sizeof (gfloat)); + for (i = 0; i < priv->bands; i++) { + priv->magnitudes[i] = DIX_RECORDER_SPECTRUM_THRESHOLD_F; + } } DixRecorder* @@ -280,10 +309,19 @@ dix_recorder_start_recording (DixRecorder *recorder, GError **error) if (G_UNLIKELY (priv->bus == NULL)) { priv->source = gst_element_factory_make ("pulsesrc", "DictixRecorderSource"); priv->converter = gst_element_factory_make ("audioconvert", "DictixRecorderConverter"); + priv->spectrum = gst_element_factory_make ("spectrum", "DictixRecorderSpectrum"); priv->encoder = gst_element_factory_make ("flacenc", "DictixRecorderEncoder"); priv->sink = gst_element_factory_make ("giosink", "DictixRecorderSink"); - if (priv->source == NULL || priv->converter == NULL + g_object_set (G_OBJECT (priv->spectrum), + "bands", priv->bands, + "threshold", DIX_RECORDER_SPECTRUM_THRESHOLD, + "post-messages", TRUE, + "message-magnitude", TRUE, + "message-phase", FALSE, + NULL); + + if (priv->source == NULL || priv->spectrum == NULL || priv->converter == NULL || priv->encoder == NULL || priv->sink == NULL) { /* *error = g_error_new (DIX_ERROR, DIX_ERROR_GST_MISSING_PLUGINS,*/ /* _("You need the \"good\" set of gstreamer's plugin."));*/ @@ -294,12 +332,14 @@ dix_recorder_start_recording (DixRecorder *recorder, GError **error) gst_bin_add_many (GST_BIN (recorder), priv->source, priv->converter, +/* priv->spectrum,*/ priv->encoder, priv->sink, NULL); gst_element_link_many (priv->source, priv->converter, +/* priv->spectrum,*/ priv->encoder, priv->sink, NULL); @@ -478,13 +518,18 @@ dix_recorder_element_cb (GstBus *bus, GstMessage *message, gpointer data) DixRecorder *recorder = (DixRecorder *) data; DixRecorderPrivate *priv = recorder->priv; const GstStructure *structure; + const GValue *magnitudes; + const GValue *magnitude; + gint i; - if (message->src != GST_OBJECT (priv->sink)) { + if (message->src != GST_OBJECT (priv->sink) /*|| + message->src != GST_OBJECT (priv->spectrum)*/) { return; } structure = gst_message_get_structure (message); - if (gst_structure_has_name (structure, "file-exists")) { + + if (G_UNLIKELY (gst_structure_has_name (structure, "file-exists"))) { /* File alredy exists, shoud not happened... */ gst_bus_set_flushing (priv->bus, TRUE); g_free (priv->id); @@ -493,7 +538,23 @@ dix_recorder_element_cb (GstBus *bus, GstMessage *message, gpointer data) gst_bus_set_flushing (priv->bus, FALSE); gst_element_set_state (GST_ELEMENT (recorder), GST_STATE_PLAYING); + + return; } + +/* if (gst_structure_has_name (structure, "spectrum")) { /* G_LIKELY () ?? */ +/* magnitudes = gst_structure_get_value (structure, "magnitude");*/ + +/* for (i = 0; i < priv->bands; i++) {*/ +/* magnitude = gst_value_list_get_value (magnitudes, i);*/ + +/* if (magnitude != NULL) {*/ +/* priv->magnitudes[i] = g_value_get_float (magnitude);*/ +/* }*/ +/* }*/ + +/* return;*/ +/* }*/ } static void diff --git a/src/dix-main.vala b/src/dix-main.vala index 79fc1e4..32561a6 100755 --- a/src/dix-main.vala +++ b/src/dix-main.vala @@ -51,7 +51,7 @@ namespace Global { /* Main objects: */ public Recorder recorder; public Player player; - public Transcoder transcoder; +// public Transcoder transcoder; /* Record list, iter atributes are thoses: - 0: uri (string), @@ -298,7 +298,7 @@ namespace Dictix { Environment.set_application_name (Config.PACKAGE_NAME); - Global.settings = new GLib.Settings (Config.PACKAGE_SCHEMA); + //Global.settings = new GLib.Settings (Config.PACKAGE_SCHEMA); Global.recorder = new Recorder (Global.data_dir); if (Global.recorder == null) { @@ -318,12 +318,12 @@ namespace Dictix { Global.player.playback_started.connect (on_playback_started_cb); Global.player.playback_stopped.connect (on_playback_stopped_cb); - Global.transcoder = new Transcoder (); - if (Global.transcoder == null) { - warning (_("Impossible to allocate core transcoder object !")); +// Global.transcoder = new Transcoder (); +// if (Global.transcoder == null) { +// warning (_("Impossible to allocate core transcoder object !")); - return; - } +// return; +// } builder = new Builder (); try { diff --git a/src/dix-ui.vala b/src/dix-ui.vala index c63e8c3..be22de7 100755 --- a/src/dix-ui.vala +++ b/src/dix-ui.vala @@ -66,7 +66,8 @@ public enum NotificationDelay { private Gtk.Action next_action; private Gtk.Action record_stop_action; - private Button play_pause_button; + private Image play_image; + private Image pause_image; private Adjustment scale_adjustment; private Scale seek_scale; private Label position_label; @@ -82,9 +83,6 @@ public enum NotificationDelay { private FileFilter file_filter; - private Image play_image; - private Image pause_image; - public Ui (Builder builder, UIManager manager) { AccelGroup accel_group = null; CellRenderer renderer = null; @@ -129,7 +127,8 @@ public enum NotificationDelay { next_action = builder.get_object ("next-action") as Gtk.Action; record_stop_action = builder.get_object ("record-stop-action") as Gtk.Action; - play_pause_button = builder.get_object ("play-pause-button") as Button; + play_image = builder.get_object ("play-image") as Image; + pause_image = builder.get_object ("pause-image") as Image; scale_adjustment = builder.get_object ("scale-adjustment") as Adjustment; seek_scale = builder.get_object ("seek-scale") as Scale; position_label = builder.get_object ("position-label") as Label; @@ -184,9 +183,6 @@ public enum NotificationDelay { selection = tree_view.get_selection (); selection.changed.connect (on_selection_changed_cb); - play_image = builder.get_object ("play-image") as Image; - pause_image = builder.get_object ("pause-image") as Image; - builder.connect_signals (this); Timeout.add (100, on_timeout_cb); this.show_all (); @@ -287,7 +283,6 @@ public enum NotificationDelay { } public bool on_timeout_cb () { - TreeSelection selection = null; Notification notification = null; double progress = 0.0; int64 position = 0; @@ -300,7 +295,7 @@ public enum NotificationDelay { last_state = Global.state; } - if (Global.state == State.WORKING) { + if (unlikely (Global.state == State.WORKING)) { return true; } @@ -317,31 +312,11 @@ public enum NotificationDelay { no_records_label.show (); tree_view.hide (); + } else { + no_records_label.hide (); + tree_view.show (); - return true; - } - - no_records_label.hide (); - tree_view.show (); - - play_pause_action.set_sensitive (true); - - selection = tree_view.get_selection (); - - if (likely (selection != null)) { - if (selection.count_selected_rows () != 0) { - save_as_action.set_sensitive (true); - delete_action.set_sensitive (true); - properties_action.set_sensitive (true); - - seek_scale.set_sensitive (true); - } else { - save_as_action.set_sensitive (false); - delete_action.set_sensitive (false); - properties_action.set_sensitive (false); - - seek_scale.set_sensitive (false); - } + play_pause_action.set_sensitive (true); } if (Global.now_recording != was_recording) { @@ -431,11 +406,13 @@ public enum NotificationDelay { was_playing = Global.now_playing; if (Global.now_playing == true) { - play_pause_button.set_image (pause_image); + play_image.hide (); + pause_image.show (); Global.records.set (now_playing_iter, Column.PIXBUF, Stock.MEDIA_PLAY); } else { - play_pause_button.set_image (play_image); + play_image.show (); + pause_image.hide (); if (Global.transport_is_paused == false) { scale_adjustment.set_value (0.0); diff --git a/vapi/libdictix.vapi b/vapi/libdictix.vapi index f198554..a58af81 100644 --- a/vapi/libdictix.vapi +++ b/vapi/libdictix.vapi @@ -71,6 +71,18 @@ namespace Dix { public signal void record_stopped (string uri); } + [CCode (prefix = "Dix", lower_case_cprefix = "dix_", cheader_filename = "dix-spectrograph.h")] + + [Compact] + [CCode (free_function = "gtk_widget_destroy")] + public class Spectrograph : Widget { + [CCode (cname = "dix_spectrograph_new")] + public Spectrograph (); + + [CCode (cname = "dix_spectrograph_set_magnitudes")] + public void set_magnitudes (uint bands, float[] magnitudes); + } + [CCode (prefix = "Dix", lower_case_cprefix = "dix_", cheader_filename = "dix-tag-reader.h")] [Compact] -- 2.11.4.GIT