From d68d5f2b40f1770d9f81269736149199e913cc06 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 8 Sep 2014 17:20:28 -0400 Subject: [PATCH] gui: Create o_play() for handling the play function This calls the audio :: play() function, rather than having the button call into the audio layer directly. With this patch, the on_play() callback is unused. Signed-off-by: Anna Schumaker --- gui/controls.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++ gui/gui.cpp | 36 +++----------------------------- include/gui/controls.h | 9 ++++++++ 3 files changed, 59 insertions(+), 33 deletions(-) create mode 100644 gui/controls.cpp create mode 100644 include/gui/controls.h diff --git a/gui/controls.cpp b/gui/controls.cpp new file mode 100644 index 00000000..ef72d5fd --- /dev/null +++ b/gui/controls.cpp @@ -0,0 +1,47 @@ +/* + * Copyright 2014 (c) Anna Schumaker. + */ +#include +#include +#include + + +static inline bool audio_playing() +{ + return driver :: get_driver()->is_playing(); +} + + +/* + * Timeout function is called every half-second. + */ +static bool on_timeout() +{ + Gtk::Label *position = lib :: get_widget("o_cur_position"); + Glib::RefPtr bar = lib :: get_object("o_progress"); + + position->set_text(audio :: position_str()); + bar->set_upper(audio :: duration()); + bar->set_value(audio :: position()); + + return audio_playing(); +} + +static void enable_timeout() +{ + Glib::signal_timeout().connect(sigc::ptr_fun(on_timeout), 500); +} + + +static void hide_show_buttons(const std::string &hide, const std::string &show) +{ + lib :: get_widget(hide)->hide(); + lib :: get_widget(show)->show(); +} + +void o_play() +{ + audio :: play(); + hide_show_buttons("o_play", "o_pause"); + enable_timeout(); +} diff --git a/gui/gui.cpp b/gui/gui.cpp index 8e621b49..e3e8d4d1 100644 --- a/gui/gui.cpp +++ b/gui/gui.cpp @@ -11,13 +11,13 @@ #include #include +#include #include #include static bool audio_playing = false; static sigc::connection fav_connection; static sigc::connection ban_connection; -void enable_timeout(); @@ -32,14 +32,6 @@ static void on_config_pause() audio :: pause_after(enabled->get_active(), count->get_value()); } -static void on_play() -{ - lib :: get_widget("o_play")->hide(); - lib :: get_widget("o_pause")->show(); - audio_playing = true; - enable_timeout(); -} - static void on_pause() { lib :: get_widget("o_play")->show(); @@ -174,7 +166,7 @@ static bool on_window_key_released(GdkEventKey *event) if (driver :: get_driver()->is_playing()) audio :: pause(); else - audio :: play(); + o_play(); } else return false; return true; @@ -208,27 +200,6 @@ void enable_idle() -/* - * Timeout function - */ -bool on_timeout() -{ - Gtk::Label *position = lib :: get_widget("o_cur_position"); - Glib::RefPtr bar = lib :: get_object("o_progress"); - - position->set_text(audio :: position_str()); - bar->set_upper(audio :: duration()); - bar->set_value(audio :: position()); - - return audio_playing; -} - -void enable_timeout() -{ - Glib::signal_timeout().connect(sigc::ptr_fun(on_timeout), 500); -} - - /* * Ocarina functions */ @@ -246,12 +217,11 @@ Gtk::Window *setup_gui() Gtk::CheckButton *enabled = lib :: get_widget("o_pause_enabled"); Gtk::Scale *position = lib :: get_widget("o_position_scale"); - cb->on_play = on_play; cb->on_pause = on_pause; cb->on_track_loaded = on_track_loaded; cb->on_pause_count_changed = on_pause_count_changed; - connect_button("o_play", audio::play); + connect_button("o_play", o_play); connect_button("o_pause", audio::pause); connect_button("o_stop", audio::stop); connect_button("o_prev", audio::prev); diff --git a/include/gui/controls.h b/include/gui/controls.h new file mode 100644 index 00000000..1565f679 --- /dev/null +++ b/include/gui/controls.h @@ -0,0 +1,9 @@ +/* + * Copyright 2014 (c) Anna Schumaker. + */ +#ifndef OCARINA_GUI_CONTROLS_H +#define OCARINA_GUI_CONTROLS_H + +void o_play(); + +#endif /* OCARINA_GUI_CONTROLS_H */