From cd8c76e1b2e2c1190c393193f97998c5fb09e85a Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 20 Dec 2014 15:01:10 -0500 Subject: [PATCH] gst: Move play and pause button handling into gst code I can handle these widgets directly from within the gst driver. I think this is easier (and more straightforward) than handling this in a separate file. Signed-off-by: Anna Schumaker --- gui/controls.cpp | 50 +++++++----------------------------------------- gui/gst.cpp | 28 +++++++++++++++++++++++---- gui/main.cpp | 4 +++- lib/lib.cpp | 2 -- 4 files changed, 34 insertions(+), 50 deletions(-) diff --git a/gui/controls.cpp b/gui/controls.cpp index 323b94e4..d007d3eb 100644 --- a/gui/controls.cpp +++ b/gui/controls.cpp @@ -7,26 +7,8 @@ #include static Gtk::Label *o_position; -static Gtk::Button *o_play_button; -static Gtk::Button *o_pause_button; static Glib::RefPtr o_pos_bar; -static inline bool audio_playing() -{ - return audio :: get_driver()->is_playing(); -} - -void o_fix_buttons() -{ - if (audio_playing()) { - o_play_button->hide(); - o_pause_button->show(); - } else { - o_play_button->show(); - o_pause_button->hide(); - } -} - /* * Timeout function is called every half-second. */ @@ -35,37 +17,22 @@ static bool on_timeout() o_position->set_text(audio :: position_str()); o_pos_bar->set_upper(audio :: duration()); o_pos_bar->set_value(audio :: position()); - - o_fix_buttons(); - return audio_playing(); + return true; } -static void o_play() -{ - audio :: play(); - o_fix_buttons(); - lib :: schedule(on_timeout, 500); -} - -static void o_pause() -{ - audio :: pause(); - o_fix_buttons(); -} - void o_toggle() { - if (audio_playing()) - o_pause(); + if (audio :: get_driver()->is_playing()) + audio :: pause(); else - o_play(); + audio :: play(); } void o_next() { audio :: next(); - o_play(); + audio :: play(); } bool o_seek(Gtk::ScrollType type, double value) @@ -82,13 +49,10 @@ void controls_init() o_position = lib :: get_widget("o_cur_position"); o_pos_bar = lib :: get_object("o_progress"); - o_play_button = lib :: get_widget("o_play"); - o_pause_button = lib :: get_widget("o_pause"); - pos_scale->signal_change_value().connect(sigc::ptr_fun(o_seek)); - connect_button("o_play", o_play); - connect_button("o_pause", o_pause); connect_button("o_stop", audio::stop); connect_button("o_prev", audio::prev); connect_button("o_next", o_next); + + lib :: schedule(on_timeout, 500); } diff --git a/gui/gst.cpp b/gui/gst.cpp index 86732dc2..dbab72b0 100644 --- a/gui/gst.cpp +++ b/gui/gst.cpp @@ -11,8 +11,10 @@ #include -static GstBus *gst_bus; -static GstElement *gst_player; +static GstBus *gst_bus; +static GstElement *gst_player; +static Gtk::Button *o_play; +static Gtk::Button *o_pause; static bool gst_change_state(GstState state) @@ -42,8 +44,21 @@ public: on_track_loaded(track); } - void play() { gst_change_state(GST_STATE_PLAYING); } - void pause() { gst_change_state(GST_STATE_PAUSED); } + void play() + { + if (gst_change_state(GST_STATE_PLAYING)) { + o_play->hide(); + o_pause->show(); + } + } + + void pause() + { + if (gst_change_state(GST_STATE_PAUSED)) { + o_play->show(); + o_pause->hide(); + } + } bool is_playing() { @@ -126,7 +141,12 @@ void init_gst(int *argc, char ***argv) gst_bus = gst_pipeline_get_bus(GST_PIPELINE(gst_player)); gst_driver = new GSTDriver(); + o_play = lib :: get_widget("o_play"); + o_pause = lib :: get_widget("o_pause"); + gst_bus_add_watch(gst_bus, on_gst_message, NULL); + o_play->signal_clicked().connect(sigc::ptr_fun(audio :: play)); + o_pause->signal_clicked().connect(sigc::ptr_fun(audio :: pause)); } void quit_gst() diff --git a/gui/main.cpp b/gui/main.cpp index 5135b40c..0e0f629a 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -1,6 +1,7 @@ /* * Copyright 2014 (c) Anna Schumaker. */ +#include #include #include #include @@ -8,8 +9,9 @@ Gtk::Window *ocarina_init(int *argc, char ***argv) { - init_gst(argc, argv); lib :: init(argc, argv, "ocarina6.glade"); + init_gst(argc, argv); + core :: init(); Gtk::Window *window = setup_gui(); post_init_tabs(); diff --git a/lib/lib.cpp b/lib/lib.cpp index bc150bfc..82a13f0b 100644 --- a/lib/lib.cpp +++ b/lib/lib.cpp @@ -29,8 +29,6 @@ void lib :: init(int *argc, char ***argv, const std::string >k_xml) builder = Gtk::Builder::create(); if (!builder->add_from_file(lib :: share_file(gtk_xml))) exit(1); - - core :: init(); } const std::string lib :: share_file(const std::string &f)