From ae5b3a358e0cee29032978ce88dc30d4b2928cd9 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Sat, 20 Aug 2011 12:12:53 -0400 Subject: [PATCH] Play and pause buttons work They play and pause music... --- gui/button.cpp | 21 +++++++++++++++++++-- include/libsaria/audio.h | 2 ++ libsaria/audio/init.cpp | 11 +++++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/gui/button.cpp b/gui/button.cpp index b6c3dd32..f66fd916 100644 --- a/gui/button.cpp +++ b/gui/button.cpp @@ -1,5 +1,16 @@ #include +#include +#include + +#define reg_on_click(func) \ +static void on_click_##func(GtkWidget *button, GdkEvent *event, gpointer data)\ +{ \ + func(); \ +} + +#define on_click(func) \ + on_click_##func GtkWidget *make_button(const gchar *stockid, GtkIconSize size) { @@ -12,12 +23,18 @@ GtkWidget *make_button(const gchar *stockid, GtkIconSize size) return button; } +reg_on_click(gst_play); GtkWidget *make_play_button(GtkIconSize size) { - return make_button(GTK_STOCK_MEDIA_PLAY, size); + GtkWidget *button = make_button(GTK_STOCK_MEDIA_PLAY, size); + GTK_CONNECT(button, "clicked", on_click(gst_play), NULL); + return button; } +reg_on_click(gst_pause); GtkWidget *make_pause_button(GtkIconSize size) { - return make_button(GTK_STOCK_MEDIA_PAUSE, size); + GtkWidget *button = make_button(GTK_STOCK_MEDIA_PAUSE, size); + GTK_CONNECT(button, "clicked", on_click(gst_pause), NULL); + return button; } diff --git a/include/libsaria/audio.h b/include/libsaria/audio.h index d8affd42..710b50ef 100644 --- a/include/libsaria/audio.h +++ b/include/libsaria/audio.h @@ -6,5 +6,7 @@ extern "C" { } void audio_init(int, char **); +void gst_play(); +void gst_pause(); #endif /* LIBSARIA_AUDIO_H */ diff --git a/libsaria/audio/init.cpp b/libsaria/audio/init.cpp index 68f81e76..f09247f9 100644 --- a/libsaria/audio/init.cpp +++ b/libsaria/audio/init.cpp @@ -23,11 +23,18 @@ void load_file(string file) g_object_set(G_OBJECT(player), "uri", uri.c_str(), NULL); } -void play() +void gst_play() { + print("Playing!"); change_state(GST_STATE_PLAYING); } +void gst_pause() +{ + print("Paused!"); + change_state(GST_STATE_PAUSED); +} + void audio_init(int argc, char **argv) { print("Initializing audio..."); @@ -36,5 +43,5 @@ void audio_init(int argc, char **argv) player = gst_element_factory_make("playbin2", "player"); if (argc > 1) load_file(argv[1]); - play(); + gst_play(); }