2014-12-19 14:19:18 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
|
|
*/
|
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 12:55:31 -05:00
|
|
|
#include <gui/audio.h>
|
2015-12-24 13:05:20 -05:00
|
|
|
#include <gui/builder.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 GtkSpinButton *o_count;
|
|
|
|
static GtkToggleButton *o_enabled;
|
|
|
|
static GtkAdjustment *o_progress;
|
2015-01-14 19:28:55 -05:00
|
|
|
|
2015-12-24 12:40:01 -05:00
|
|
|
const gchar *TITLE_FMT = "<span size='xx-large'>%s</span>";
|
|
|
|
const gchar *ARTIST_FMT = "<span size='x-large'>By: %s</span>";
|
|
|
|
const gchar *ALBUM_FMT = "<span size='x-large'>From: %s</span>";
|
2014-12-20 10:45:40 -05:00
|
|
|
|
2015-12-24 12:40:01 -05:00
|
|
|
static inline void __audio_set_label(const gchar *label, const gchar *fmt,
|
|
|
|
const gchar *text)
|
2015-01-14 20:16:01 -05:00
|
|
|
{
|
2015-12-24 12:40:01 -05:00
|
|
|
gchar *markup = g_markup_printf_escaped(fmt, text);
|
|
|
|
gtk_label_set_markup(GTK_LABEL(gui_builder_widget(label)), markup);
|
2015-12-24 12:03:23 -05:00
|
|
|
g_free(markup);
|
2015-01-14 20:16:01 -05:00
|
|
|
}
|
|
|
|
|
2015-12-24 12:46:08 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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 12:40:01 -05:00
|
|
|
__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);
|
2015-11-11 08:11:54 -05:00
|
|
|
|
2015-12-24 12:46:08 -05:00
|
|
|
__audio_set_time_label("o_position", 0);
|
|
|
|
__audio_set_time_label("o_duration", track->tr_length);
|
2015-11-11 10:42:17 -05:00
|
|
|
|
2015-12-24 12:48:15 -05:00
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gui_builder_widget("o_ban")),
|
|
|
|
playlist_has(PL_HIDDEN, track));
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gui_builder_widget("o_favorite")),
|
|
|
|
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-12-24 13:07:54 -05:00
|
|
|
void __audio_seek(GtkScrollType type, double value)
|
2015-01-14 08:21:07 -05:00
|
|
|
{
|
2015-12-15 15:50:02 -05:00
|
|
|
audio_seek(value);
|
2015-01-14 08:21:07 -05:00
|
|
|
}
|
|
|
|
|
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-12-24 13:03:30 -05:00
|
|
|
static int on_timeout(gpointer data)
|
2015-01-14 19:28:55 -05: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());
|
2015-12-24 12:46:08 -05:00
|
|
|
__audio_set_time_label("o_position", audio_position() / GST_SECOND);
|
2015-01-14 19:28:55 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-24 12:55:31 -05:00
|
|
|
void gui_audio_init()
|
2014-12-19 14:19:18 -05:00
|
|
|
{
|
2015-12-24 12:03:23 -05:00
|
|
|
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_count, "changed", G_CALLBACK(on_pause_count), NULL);
|
|
|
|
g_signal_connect(o_enabled, "toggled", G_CALLBACK(on_pause_enabled), NULL);
|
2015-01-15 09:34:17 -05:00
|
|
|
|
2015-12-24 13:03:30 -05:00
|
|
|
g_timeout_add(500, on_timeout, NULL);
|
2014-12-19 14:19:18 -05:00
|
|
|
}
|