2014-12-19 14:19:18 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2014 (c) Anna Schumaker.
|
2014-12-20 11:49:22 -05:00
|
|
|
*
|
|
|
|
* 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.
|
2014-12-19 14:19:18 -05:00
|
|
|
*/
|
2015-09-08 09:39:35 -04:00
|
|
|
extern "C" {
|
2015-12-17 10:32:01 -05:00
|
|
|
#include <core/audio.h>
|
2015-12-24 11:17:24 -05:00
|
|
|
#include <core/playlist.h>
|
2015-01-27 08:34:32 -05:00
|
|
|
#include <core/string.h>
|
2015-12-24 09:35:36 -05:00
|
|
|
#include <gui/builder.h>
|
2015-09-08 09:39:35 -04:00
|
|
|
}
|
2014-12-20 12:05:22 -05:00
|
|
|
#include <gui/ocarina.h>
|
2014-12-19 14:25:23 -05:00
|
|
|
|
2014-12-19 14:19:18 -05:00
|
|
|
|
2015-12-24 12:03:23 -05:00
|
|
|
static GtkScale *o_seek;
|
2014-12-20 10:45:40 -05:00
|
|
|
|
2015-12-24 12:03:23 -05:00
|
|
|
static GtkSpinButton *o_count;
|
|
|
|
static GtkToggleButton *o_enabled;
|
2015-01-15 09:34:17 -05:00
|
|
|
|
2015-12-24 12:03:23 -05:00
|
|
|
static GtkLabel *o_album;
|
|
|
|
static GtkLabel *o_artist;
|
|
|
|
static GtkLabel *o_duration;
|
|
|
|
static GtkLabel *o_position;
|
|
|
|
static GtkLabel *o_title;
|
|
|
|
static GtkAdjustment *o_progress;
|
2015-01-14 19:28:55 -05:00
|
|
|
|
2014-12-20 10:45:40 -05:00
|
|
|
|
2015-12-24 12:03:23 -05:00
|
|
|
static void set_markup(GtkLabel *label, const std::string &size,
|
2015-01-14 20:16:01 -05:00
|
|
|
const std::string &text)
|
|
|
|
{
|
2015-12-24 12:03:23 -05:00
|
|
|
gchar *markup = g_markup_printf_escaped("<span size='%s'>%s</span>",
|
|
|
|
size.c_str(), text.c_str());
|
|
|
|
gtk_label_set_markup(label, markup);
|
|
|
|
g_free(markup);
|
2015-01-14 20:16:01 -05:00
|
|
|
}
|
|
|
|
|
2015-12-18 08:09:34 -05:00
|
|
|
static void on_load(struct track *track)
|
2014-12-19 14:25:23 -05:00
|
|
|
{
|
2015-12-24 11:17:24 -05:00
|
|
|
Gtk::ToggleButton *toggle;
|
|
|
|
|
2015-12-15 10:23:15 -05:00
|
|
|
gchar *str = g_strdup_printf("From: %s", track->tr_album->al_name);
|
|
|
|
set_markup(o_album, "x-large", str);
|
|
|
|
g_free(str);
|
2014-12-20 12:05:22 -05:00
|
|
|
|
2015-12-15 10:23:15 -05:00
|
|
|
str = g_strdup_printf("By: %s", track->tr_artist->ar_name);
|
|
|
|
set_markup(o_artist, "x-large", str);
|
|
|
|
g_free(str);
|
2015-11-11 10:42:17 -05:00
|
|
|
|
2015-12-15 10:23:15 -05:00
|
|
|
set_markup(o_title, "xx-large", track->tr_title);
|
2015-11-11 08:11:54 -05:00
|
|
|
|
2015-12-15 10:23:15 -05:00
|
|
|
str = string_sec2str(track->tr_length);
|
2015-12-24 12:03:23 -05:00
|
|
|
gtk_label_set_text(o_duration, str);
|
2015-12-15 10:23:15 -05:00
|
|
|
g_free(str);
|
2015-11-11 10:42:17 -05:00
|
|
|
|
2015-12-24 11:17:24 -05:00
|
|
|
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));
|
2015-12-18 08:09:34 -05:00
|
|
|
}
|
2015-12-15 14:34:13 -05:00
|
|
|
|
2015-12-18 08:09:34 -05:00
|
|
|
static void on_change_state(GstState state)
|
|
|
|
{
|
|
|
|
if (state == GST_STATE_PLAYING) {
|
2015-12-24 12:23:10 -05:00
|
|
|
gtk_widget_hide(gui_builder_widget("o_play"));
|
2015-12-24 12:19:33 -05:00
|
|
|
gtk_widget_show(gui_builder_widget("o_pause"));
|
2015-12-18 08:09:34 -05:00
|
|
|
} else {
|
2015-12-24 12:23:10 -05:00
|
|
|
gtk_widget_show(gui_builder_widget("o_play"));
|
2015-12-24 12:19:33 -05:00
|
|
|
gtk_widget_hide(gui_builder_widget("o_pause"));
|
2015-12-18 08:09:34 -05:00
|
|
|
}
|
2015-12-15 10:23:15 -05:00
|
|
|
}
|
2015-01-14 20:16:01 -05:00
|
|
|
|
2015-12-16 12:50:14 -05:00
|
|
|
static void on_config_pause(int n)
|
|
|
|
{
|
|
|
|
if (n == -1)
|
2015-12-24 12:03:23 -05:00
|
|
|
gtk_toggle_button_set_active(o_enabled, false);
|
2015-12-16 12:50:14 -05:00
|
|
|
else {
|
2015-12-24 12:03:23 -05:00
|
|
|
gtk_spin_button_set_value(o_count, n);
|
|
|
|
gtk_toggle_button_set_active(o_enabled, true);
|
2015-12-16 12:50:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-19 14:25:23 -05:00
|
|
|
|
2015-12-15 10:23:15 -05:00
|
|
|
struct audio_ops audio_ops = {
|
|
|
|
on_load,
|
2015-12-18 08:09:34 -05:00
|
|
|
on_change_state,
|
2015-12-16 12:50:14 -05:00
|
|
|
on_config_pause,
|
2015-12-15 10:23:15 -05:00
|
|
|
};
|
|
|
|
|
2014-12-19 14:25:23 -05:00
|
|
|
|
2015-01-14 08:21:07 -05:00
|
|
|
static bool on_seek(Gtk::ScrollType type, double value)
|
|
|
|
{
|
2015-12-15 15:50:02 -05:00
|
|
|
audio_seek(value);
|
2015-01-14 08:21:07 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-15 09:34:17 -05:00
|
|
|
static void on_pause_count()
|
|
|
|
{
|
2015-12-24 12:03:23 -05:00
|
|
|
gtk_toggle_button_set_active(o_enabled, true);
|
|
|
|
audio_pause_after(gtk_spin_button_get_value(o_count));
|
2015-01-15 09:34:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void on_pause_enabled()
|
|
|
|
{
|
2015-12-24 12:03:23 -05:00
|
|
|
if (!gtk_toggle_button_get_active(o_enabled))
|
2015-12-16 12:50:14 -05:00
|
|
|
audio_pause_after(-1);
|
|
|
|
else
|
2015-12-24 12:03:23 -05:00
|
|
|
audio_pause_after(gtk_spin_button_get_value(o_count));
|
2015-01-15 09:34:17 -05:00
|
|
|
}
|
|
|
|
|
2015-01-14 19:28:55 -05:00
|
|
|
static bool on_timeout()
|
|
|
|
{
|
2015-12-15 16:42:49 -05:00
|
|
|
gchar *pos = string_sec2str(audio_position() / GST_SECOND);
|
2015-09-02 08:02:41 -04:00
|
|
|
|
2015-12-24 12:03:23 -05:00
|
|
|
gtk_adjustment_set_upper(o_progress, audio_duration());
|
|
|
|
gtk_adjustment_set_value(o_progress, audio_position());
|
|
|
|
gtk_label_set_text(o_position, pos);
|
2015-09-02 08:02:41 -04:00
|
|
|
g_free(pos);
|
2015-01-14 19:28:55 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-17 09:59:25 -05:00
|
|
|
void gst :: toggle()
|
2015-01-14 19:35:02 -05:00
|
|
|
{
|
2015-12-16 09:18:01 -05:00
|
|
|
if (audio_cur_state() == GST_STATE_PLAYING)
|
2015-12-24 12:19:33 -05:00
|
|
|
audio_pause();
|
2015-01-14 19:35:02 -05:00
|
|
|
else
|
2015-12-24 12:23:10 -05:00
|
|
|
audio_play();
|
2015-01-14 19:35:02 -05:00
|
|
|
}
|
|
|
|
|
2015-12-15 08:16:06 -05:00
|
|
|
void gst :: init_pre()
|
2014-12-19 14:19:18 -05:00
|
|
|
{
|
2015-12-24 12:03:23 -05:00
|
|
|
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_album = GTK_LABEL(gui_builder_widget("o_album"));
|
|
|
|
o_artist = GTK_LABEL(gui_builder_widget("o_artist"));
|
|
|
|
o_duration = GTK_LABEL(gui_builder_widget("o_duration"));
|
|
|
|
o_position = GTK_LABEL(gui_builder_widget("o_position"));
|
|
|
|
o_title = GTK_LABEL(gui_builder_widget("o_title"));
|
|
|
|
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);
|
2015-12-15 08:16:06 -05:00
|
|
|
}
|
2015-01-15 09:34:17 -05:00
|
|
|
|
2015-12-15 08:16:06 -05:00
|
|
|
void gst :: init()
|
|
|
|
{
|
2015-01-21 08:10:59 -05:00
|
|
|
Glib :: signal_timeout().connect(sigc::ptr_fun(on_timeout), 500);
|
2014-12-19 14:19:18 -05:00
|
|
|
}
|