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>
|
2016-07-20 12:02:47 -04:00
|
|
|
#include <gui/artwork.h>
|
2015-12-24 12:55:31 -05:00
|
|
|
#include <gui/audio.h>
|
2016-02-05 15:31:17 -05:00
|
|
|
#include <gui/idle.h>
|
2016-08-24 09:06:43 -04:00
|
|
|
#include <gui/treeview.h>
|
2016-01-22 14:16:51 -05:00
|
|
|
#include <gui/view.h>
|
2016-08-19 08:06:16 -04:00
|
|
|
#include <gui/window.h>
|
2014-12-19 14:19:18 -05:00
|
|
|
|
2017-03-30 09:50:03 -04:00
|
|
|
static guint audio_timeout = 0;
|
|
|
|
|
2015-12-24 14:29:57 -05:00
|
|
|
static inline void __audio_set_label(const gchar *label, const gchar *size,
|
2016-04-25 11:38:20 -04:00
|
|
|
const gchar *text)
|
2015-01-14 20:16:01 -05:00
|
|
|
{
|
2016-04-25 11:38:20 -04:00
|
|
|
gchar *markup = g_markup_printf_escaped("<span size='%s'>%s</span>",
|
|
|
|
size, text);
|
2015-12-24 12:40:01 -05:00
|
|
|
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);
|
2016-04-25 11:38:20 -04:00
|
|
|
__audio_set_label(label, "large", str);
|
2015-12-24 12:46:08 -05:00
|
|
|
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
|
|
|
{
|
2016-04-25 11:38:20 -04:00
|
|
|
__audio_set_label("o_title", "xx-large", track->tr_title);
|
2016-08-29 11:19:58 -04:00
|
|
|
__audio_set_label("o_artist", "x-large", track->tr_album->al_artist->ar_name);
|
2016-04-25 11:38:20 -04:00
|
|
|
__audio_set_label("o_album", "x-large", track->tr_album->al_name);
|
2015-12-24 12:46:08 -05:00
|
|
|
__audio_set_time_label("o_duration", track->tr_length);
|
2015-11-11 10:42:17 -05:00
|
|
|
|
2015-12-24 14:29:57 -05:00
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gui_builder_widget("o_hide")),
|
2016-05-06 08:05:21 -04:00
|
|
|
playlist_has(PL_SYSTEM, "Hidden", track));
|
2015-12-24 12:48:15 -05:00
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gui_builder_widget("o_favorite")),
|
2016-05-06 08:05:21 -04:00
|
|
|
playlist_has(PL_SYSTEM, "Favorites", track));
|
2016-02-05 15:31:17 -05:00
|
|
|
|
2016-08-24 09:06:43 -04:00
|
|
|
gui_treeview_scroll();
|
2016-07-20 12:02:47 -04:00
|
|
|
gui_artwork_set_cover();
|
2016-09-19 14:39:31 -04:00
|
|
|
gui_idle_enable();
|
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
|
|
|
{
|
2016-05-14 08:48:08 -04:00
|
|
|
GtkComboBox *combo = GTK_COMBO_BOX(gui_builder_widget("o_pause_after"));
|
|
|
|
gtk_combo_box_set_active(combo, n + 1);
|
2015-12-24 13:59:30 -05:00
|
|
|
}
|
|
|
|
|
2016-05-14 08:48:08 -04:00
|
|
|
void __audio_pause_changed(GtkComboBox *combo, gpointer data)
|
|
|
|
{
|
|
|
|
int val = gtk_combo_box_get_active(combo) - 1;
|
|
|
|
audio_pause_after(val);
|
|
|
|
}
|
|
|
|
|
2015-12-25 17:11:58 -05:00
|
|
|
void __audio_seek(GtkRange *range, GtkScrollType type, double value, gpointer data)
|
2015-01-14 08:21:07 -05:00
|
|
|
{
|
2015-12-25 17:57:58 -05:00
|
|
|
audio_seek(value * GST_SECOND);
|
2015-01-14 08:21:07 -05:00
|
|
|
}
|
|
|
|
|
2016-08-18 09:31:53 -04:00
|
|
|
void __audio_volume_changed(GtkScaleButton *button, gdouble value, gpointer data)
|
|
|
|
{
|
|
|
|
audio_set_volume((unsigned int)value);
|
|
|
|
}
|
|
|
|
|
2016-01-21 09:56:13 -05:00
|
|
|
void __audio_favorite(GtkToggleButton *toggle, gpointer data)
|
|
|
|
{
|
|
|
|
if (gtk_toggle_button_get_active(toggle))
|
2016-05-06 08:05:21 -04:00
|
|
|
playlist_add(PL_SYSTEM, "Favorites", audio_cur_track());
|
2016-01-21 09:56:13 -05:00
|
|
|
else
|
2016-05-06 08:05:21 -04:00
|
|
|
playlist_remove(PL_SYSTEM, "Favorites", audio_cur_track());
|
2016-01-21 09:56:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void __audio_hide(GtkToggleButton *toggle, gpointer data)
|
|
|
|
{
|
|
|
|
if (gtk_toggle_button_get_active(toggle)) {
|
2016-05-06 08:05:21 -04:00
|
|
|
if (playlist_add(PL_SYSTEM, "Hidden", audio_cur_track()))
|
2016-01-21 09:56:13 -05:00
|
|
|
audio_next();
|
|
|
|
} else
|
2016-05-06 08:05:21 -04:00
|
|
|
playlist_remove(PL_SYSTEM, "Hidden", audio_cur_track());
|
2016-01-21 09:56:13 -05:00
|
|
|
}
|
|
|
|
|
2015-12-24 13:27:18 -05:00
|
|
|
static int __audio_timeout(gpointer data)
|
|
|
|
{
|
|
|
|
GtkAdjustment *progress = data;
|
|
|
|
|
2015-12-25 17:57:58 -05:00
|
|
|
gtk_adjustment_set_upper(progress, audio_duration() / GST_SECOND);
|
|
|
|
gtk_adjustment_set_value(progress, audio_position() / GST_SECOND);
|
2015-12-24 13:27:18 -05:00
|
|
|
__audio_set_time_label("o_position", audio_position() / GST_SECOND);
|
|
|
|
return G_SOURCE_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2016-04-12 11:25:29 -04:00
|
|
|
gboolean __audio_can_accel(GtkWidget *widget, guint signal_id)
|
|
|
|
{
|
|
|
|
g_signal_stop_emission_by_name(widget, "can-activate-accel");
|
2016-08-19 08:06:16 -04:00
|
|
|
return !GTK_IS_ENTRY(gtk_window_get_focus(gui_window())) &&
|
2016-04-12 11:25:29 -04:00
|
|
|
gtk_widget_is_visible(widget) &&
|
|
|
|
gtk_widget_is_sensitive(widget);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2016-08-18 09:31:53 -04:00
|
|
|
GtkScaleButton *volume = GTK_SCALE_BUTTON(gui_builder_widget("o_volume"));
|
2017-03-30 09:50:03 -04:00
|
|
|
audio_timeout = g_timeout_add(500, __audio_timeout,
|
|
|
|
gui_builder_object("o_progress"));
|
2016-08-18 09:31:53 -04:00
|
|
|
gtk_scale_button_set_value(volume, audio_get_volume());
|
|
|
|
gtk_button_set_relief(GTK_BUTTON(volume), GTK_RELIEF_NORMAL);
|
2014-12-19 14:19:18 -05:00
|
|
|
}
|
2015-12-25 17:11:58 -05:00
|
|
|
|
2017-03-30 09:50:03 -04:00
|
|
|
void gui_audio_deinit()
|
|
|
|
{
|
|
|
|
g_source_remove(audio_timeout);
|
|
|
|
}
|
|
|
|
|
2015-12-25 17:11:58 -05:00
|
|
|
#ifdef CONFIG_TESTING
|
|
|
|
void test_gui_audio_timeout()
|
|
|
|
{
|
|
|
|
__audio_timeout(gui_builder_object("o_progress"));
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_TESTING */
|