static note_pipeline note_play;
static note_pipeline note_record;
static GstBus *bus;
-static gchar *cfile=NULL;
+
+static gboolean audio_note_stop(audio_note_ui *ui);
static gboolean
audio_note_position_cb(gpointer data)
gchar buffer[128];
audio_note_ui *ui=(audio_note_ui *)data;
-pipe=ui->note_record->pipeline;
+if (ui->note_record->active)
+ pipe=ui->note_record->pipeline;
+else
+ if (ui->note_play->active)
+ pipe=ui->note_play->pipeline;
+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(ui->lbl_time, buffer);
+ gtk_label_set_text(GTK_LABEL(ui->lbl_time), buffer);
}
return TRUE;
}
+static void
+audio_note_position_display(audio_note_ui *ui, gboolean ena)
+{
+if (ui->pos_sid!=0) {
+ g_source_remove(ui->pos_sid);
+ ui->pos_sid=0;
+}
+if (ena)
+ ui->pos_sid=g_timeout_add(250, (GSourceFunc)audio_note_position_cb, ui);
+}
+
static gboolean
audio_note_record_cb(GtkWidget *widget, gpointer data)
{
const gchar *basedir;
gchar buffer[128];
audio_note_ui *ui=(audio_note_ui *)data;
-GDate *gd;
time_t t;
struct tm *tmp;
}
strftime(buffer, sizeof(buffer), "%Y-%m-%d-%H:%M:%S", tmp);
-if (cfile)
- g_free(cfile);
-
-cfile=g_strdup_printf("%s/an-%s.wav", basedir, buffer);
+if (ui->cfile)
+ g_free(ui->cfile);
-audio_note_record(cfile);
-ui->pos_sid=g_timeout_add (250, (GSourceFunc)audio_note_position_cb, ui);
+ui->cfile=g_strdup_printf("%s/an-%s.wav", basedir, buffer);
-MACRO_BANNER_SHOW_INFO(_window, _("Recording..."));
+if (audio_note_record(ui->cfile)==TRUE) {
+ audio_note_position_display(ui, TRUE);
+ MACRO_BANNER_SHOW_INFO(_window, _("Recording..."));
+ gtk_widget_set_sensitive(ui->btn_play, FALSE);
+ gtk_widget_set_sensitive(ui->btn_record, FALSE);
+ gtk_widget_set_sensitive(ui->btn_stop, TRUE);
+}
return TRUE;
}
{
audio_note_ui *ui=(audio_note_ui *)data;
-audio_note_play(cfile);
-MACRO_BANNER_SHOW_INFO(_window, _("Playing..."));
+if (!ui->cfile) {
+ MACRO_BANNER_SHOW_INFO(_window, _("No active audio note."));
+ return TRUE;
+}
+
+if (audio_note_play(ui->cfile)==TRUE) {
+ audio_note_position_display(ui, TRUE);
+ MACRO_BANNER_SHOW_INFO(_window, _("Playing..."));
+ gtk_widget_set_sensitive(ui->btn_play, FALSE);
+ gtk_widget_set_sensitive(ui->btn_record, FALSE);
+ gtk_widget_set_sensitive(ui->btn_stop, TRUE);
+}
return TRUE;
}
static gboolean
audio_note_stop_cb(GtkWidget *widget, gpointer data)
{
-if (audio_note_stop()==TRUE)
+audio_note_ui *ui=(audio_note_ui *)data;
+
+if (audio_note_stop(ui)==TRUE)
MACRO_BANNER_SHOW_INFO(_window, _("Stopped..."));
+
+audio_note_position_display(ui, FALSE);
+gtk_widget_set_sensitive(ui->btn_record, TRUE);
+gtk_widget_set_sensitive(ui->btn_play, TRUE);
+gtk_widget_set_sensitive(ui->btn_stop, FALSE);
+
return TRUE;
}
audio_note_ui *ui;
ui=g_slice_new(audio_note_ui);
ui->pos_sid=0;
+ui->cfile=NULL;
ui->vbox=gtk_vbox_new(FALSE, 0);
ui->lbl_time=gtk_label_new("");
ui->btn_record=gtk_button_new_from_stock(GTK_STOCK_MEDIA_RECORD);
ui->btn_play=gtk_button_new_from_stock(GTK_STOCK_MEDIA_PLAY);
ui->btn_stop=gtk_button_new_from_stock(GTK_STOCK_MEDIA_STOP);
+gtk_widget_set_sensitive(ui->btn_play, FALSE);
+gtk_widget_set_sensitive(ui->btn_stop, FALSE);
+
gtk_box_pack_start(GTK_BOX(ui->vbox), ui->lbl_time, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(ui->vbox), ui->btn_record, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(ui->vbox), ui->btn_play, TRUE, TRUE, 0);
return TRUE;
}
+static gboolean
+audio_new_pad_cb(GstElement *wavparse, GstPad *new_pad, gpointer data)
+{
+GstElement *sink=(GstElement *)data;
+
+if (!gst_element_link(wavparse, sink))
+ g_printerr("Failed to link wavparse to sink\n");
+
+gst_element_sync_state_with_parent(sink);
+
+return FALSE;
+}
+
static gboolean
audio_create_pipeline(note_pipeline *np, gboolean rec)
{
if (!gst_element_link(np->src, np->filter))
g_printerr("Failed to link source to filter\n");
- if (!gst_element_link(np->filter, np->sink))
- g_printerr("Failed to link filter to source\n");
+
+ g_signal_connect(np->filter, "pad_added", G_CALLBACK(audio_new_pad_cb), np->sink);
}
bus=gst_pipeline_get_bus(GST_PIPELINE(np->pipeline));
gst_bus_add_watch(bus, audio_note_bus_cb, np);
return TRUE;
}
-gboolean
-audio_note_stop()
+static gboolean
+audio_note_stop(audio_note_ui *ui)
{
GstState current;
GstState pending;
+audio_note_position_display(ui, FALSE);
+
gst_element_get_state(note_record.pipeline, ¤t, &pending, GST_CLOCK_TIME_NONE);
if (current==GST_STATE_PLAYING) {
+ g_debug("Stop: recording");
gst_element_set_state(note_record.pipeline, GST_STATE_NULL);
note_record.active=FALSE;
return TRUE;
gst_element_get_state(note_play.pipeline, ¤t, &pending, GST_CLOCK_TIME_NONE);
if (current==GST_STATE_PLAYING) {
- gst_element_set_state(note_play.pipeline, GST_STATE_READY);
+ g_debug("Stop: playing");
+ gst_element_set_state(note_play.pipeline, GST_STATE_NULL);
note_play.active=FALSE;
return TRUE;
}