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 <Anna@OcarinaProject.net>
This commit is contained in:
parent
6a117c762e
commit
cd8c76e1b2
|
@ -7,26 +7,8 @@
|
|||
#include <gui/ocarina.h>
|
||||
|
||||
static Gtk::Label *o_position;
|
||||
static Gtk::Button *o_play_button;
|
||||
static Gtk::Button *o_pause_button;
|
||||
static Glib::RefPtr<Gtk::Adjustment> 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<Gtk::Label>("o_cur_position");
|
||||
o_pos_bar = lib :: get_object<Gtk::Adjustment>("o_progress");
|
||||
|
||||
o_play_button = lib :: get_widget<Gtk::Button>("o_play");
|
||||
o_pause_button = lib :: get_widget<Gtk::Button>("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);
|
||||
}
|
||||
|
|
28
gui/gst.cpp
28
gui/gst.cpp
|
@ -11,8 +11,10 @@
|
|||
#include <gst/gst.h>
|
||||
|
||||
|
||||
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<Gtk::Button>("o_play");
|
||||
o_pause = lib :: get_widget<Gtk::Button>("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()
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright 2014 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/core.h>
|
||||
#include <core/playlist.h>
|
||||
#include <lib/lib.h>
|
||||
#include <gui/ocarina.h>
|
||||
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue