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: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-24 13:12:42 -05:00
|
|
|
static void __audio_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-24 13:12:42 -05:00
|
|
|
static void __audio_change_state(GstState state)
|
2015-12-18 08:09:34 -05:00
|
|
|
{
|
|
|
|
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-24 13:12:42 -05:00
|
|
|
static void __audio_config_pause(int n)
|
2015-12-16 12:50:14 -05:00
|
|
|
{
|
2015-12-24 13:59:30 -05:00
|
|
|
GtkToggleButton *enabled = GTK_TOGGLE_BUTTON(gui_builder_widget("o_pause_enabled"));
|
|
|
|
|
|
|
|
if (n >= 0)
|
|
|
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(gui_builder_widget("o_pause_count")), n);
|
|
|
|
gtk_toggle_button_set_active(enabled, n >= 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __audio_pause_count(GtkSpinButton *count)
|
|
|
|
{
|
|
|
|
audio_pause_after(gtk_spin_button_get_value(count));
|
|
|
|
}
|
|
|
|
|
|
|
|
void __audio_pause_enabled(GtkToggleButton *enabled, GtkSpinButton *count)
|
|
|
|
{
|
|
|
|
int val = -1;
|
|
|
|
|
|
|
|
if (gtk_toggle_button_get_active(enabled))
|
|
|
|
val = gtk_spin_button_get_value(count);
|
|
|
|
audio_pause_after(val);
|
2015-12-16 12:50:14 -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-12-24 13:27:18 -05:00
|
|
|
static int __audio_timeout(gpointer data)
|
|
|
|
{
|
|
|
|
GtkAdjustment *progress = data;
|
|
|
|
|
|
|
|
gtk_adjustment_set_upper(progress, audio_duration());
|
|
|
|
gtk_adjustment_set_value(progress, audio_position());
|
|
|
|
__audio_set_time_label("o_position", audio_position() / GST_SECOND);
|
|
|
|
|
|
|
|
return G_SOURCE_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2015-12-24 13:12:42 -05:00
|
|
|
|
2015-12-24 13:59:30 -05:00
|
|
|
|
2015-12-24 13:12:42 -05:00
|
|
|
struct audio_ops audio_ops = {
|
|
|
|
__audio_load,
|
|
|
|
__audio_change_state,
|
|
|
|
__audio_config_pause,
|
|
|
|
};
|
|
|
|
|
2015-12-24 12:55:31 -05:00
|
|
|
void gui_audio_init()
|
2014-12-19 14:19:18 -05:00
|
|
|
{
|
2015-12-24 13:27:18 -05:00
|
|
|
g_timeout_add(500, __audio_timeout, gui_builder_object("o_progress"));
|
2014-12-19 14:19:18 -05:00
|
|
|
}
|