/* * Copyright 2014 (c) Anna Schumaker. * * The gst_init() function parses command line options passed to Ocarina * through argv. Use the command `gst-inspect-1.0 --help-gst` to find * what options are supported. */ extern "C" { #include #include #include #include } #include static GtkScale *o_seek; static GtkSpinButton *o_count; static GtkToggleButton *o_enabled; static GtkAdjustment *o_progress; const gchar *TITLE_FMT = "%s"; const gchar *ARTIST_FMT = "By: %s"; const gchar *ALBUM_FMT = "From: %s"; static inline void __audio_set_label(const gchar *label, const gchar *fmt, const gchar *text) { gchar *markup = g_markup_printf_escaped(fmt, text); gtk_label_set_markup(GTK_LABEL(gui_builder_widget(label)), markup); g_free(markup); } static inline void __audio_set_time_label(const gchar *label, unsigned int time) { gchar *str = string_sec2str(time); __audio_set_label(label, "%s", str); g_free(str); } static void on_load(struct track *track) { Gtk::ToggleButton *toggle; __audio_set_label("o_title", TITLE_FMT, track->tr_title); __audio_set_label("o_artist", ARTIST_FMT, track->tr_artist->ar_name); __audio_set_label("o_album", ALBUM_FMT, track->tr_album->al_name); __audio_set_time_label("o_position", 0); __audio_set_time_label("o_duration", track->tr_length); toggle = Glib :: wrap(GTK_TOGGLE_BUTTON(gui_builder_widget("o_ban")), false); toggle->set_active(playlist_has(PL_HIDDEN, track)); toggle = Glib :: wrap(GTK_TOGGLE_BUTTON(gui_builder_widget("o_favorite")), false); toggle->set_active(playlist_has(PL_FAVORITED, track)); } static void on_change_state(GstState state) { if (state == GST_STATE_PLAYING) { gtk_widget_hide(gui_builder_widget("o_play")); gtk_widget_show(gui_builder_widget("o_pause")); } else { gtk_widget_show(gui_builder_widget("o_play")); gtk_widget_hide(gui_builder_widget("o_pause")); } } static void on_config_pause(int n) { if (n == -1) gtk_toggle_button_set_active(o_enabled, false); else { gtk_spin_button_set_value(o_count, n); gtk_toggle_button_set_active(o_enabled, true); } } struct audio_ops audio_ops = { on_load, on_change_state, on_config_pause, }; static bool on_seek(Gtk::ScrollType type, double value) { audio_seek(value); return true; } static void on_pause_count() { gtk_toggle_button_set_active(o_enabled, true); audio_pause_after(gtk_spin_button_get_value(o_count)); } static void on_pause_enabled() { if (!gtk_toggle_button_get_active(o_enabled)) audio_pause_after(-1); else audio_pause_after(gtk_spin_button_get_value(o_count)); } static bool on_timeout() { gtk_adjustment_set_upper(o_progress, audio_duration()); gtk_adjustment_set_value(o_progress, audio_position()); __audio_set_time_label("o_position", audio_position() / GST_SECOND); return true; } void gst :: toggle() { if (audio_cur_state() == GST_STATE_PLAYING) audio_pause(); else audio_play(); } void gst :: init_pre() { o_seek = GTK_SCALE(gui_builder_widget("o_seek")); o_count = GTK_SPIN_BUTTON(gui_builder_widget("o_pause_count")); o_enabled = GTK_TOGGLE_BUTTON(gui_builder_widget("o_pause_enabled")); o_progress = GTK_ADJUSTMENT(gui_builder_object("o_progress")); g_signal_connect(o_seek, "change-value", G_CALLBACK(on_seek), NULL); g_signal_connect(o_count, "changed", G_CALLBACK(on_pause_count), NULL); g_signal_connect(o_enabled, "toggled", G_CALLBACK(on_pause_enabled), NULL); } void gst :: init() { Glib :: signal_timeout().connect(sigc::ptr_fun(on_timeout), 500); }