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 <Anna@OcarinaProject.net>
This commit is contained in:
parent
c9cabb78f1
commit
d68d5f2b40
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright 2014 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <lib/lib.h>
|
||||
#include <core/audio.h>
|
||||
#include <core/driver.h>
|
||||
|
||||
|
||||
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<Gtk::Label>("o_cur_position");
|
||||
Glib::RefPtr<Gtk::Adjustment> bar = lib :: get_object<Gtk::Adjustment>("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<Gtk::Button>(hide)->hide();
|
||||
lib :: get_widget<Gtk::Button>(show)->show();
|
||||
}
|
||||
|
||||
void o_play()
|
||||
{
|
||||
audio :: play();
|
||||
hide_show_buttons("o_play", "o_pause");
|
||||
enable_timeout();
|
||||
}
|
36
gui/gui.cpp
36
gui/gui.cpp
|
@ -11,13 +11,13 @@
|
|||
#include <lib/colmgr.h>
|
||||
#include <lib/lib.h>
|
||||
|
||||
#include <gui/controls.h>
|
||||
#include <gui/ocarina.h>
|
||||
#include <gui/tabs.h>
|
||||
|
||||
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<Gtk::Button>("o_play")->hide();
|
||||
lib :: get_widget<Gtk::Button>("o_pause")->show();
|
||||
audio_playing = true;
|
||||
enable_timeout();
|
||||
}
|
||||
|
||||
static void on_pause()
|
||||
{
|
||||
lib :: get_widget<Gtk::Button>("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<Gtk::Label>("o_cur_position");
|
||||
Glib::RefPtr<Gtk::Adjustment> bar = lib :: get_object<Gtk::Adjustment>("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<Gtk::CheckButton>("o_pause_enabled");
|
||||
Gtk::Scale *position = lib :: get_widget<Gtk::Scale>("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);
|
||||
|
|
|
@ -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 */
|
Loading…
Reference in New Issue