2014-12-19 14:19:18 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2014 (c) Anna Schumaker.
|
2014-12-20 11:49:22 -05:00
|
|
|
*
|
|
|
|
* The gst_init() function parses command line options passed to Ocarina
|
|
|
|
* through argv. Use the command `gst-inspect-1.0 --help-gst` to find
|
|
|
|
* what options are supported.
|
2014-12-19 14:19:18 -05:00
|
|
|
*/
|
2014-12-19 17:25:36 -05:00
|
|
|
#include <core/audio.h>
|
2015-09-08 09:39:35 -04:00
|
|
|
extern "C" {
|
2016-03-21 08:33:14 -04:00
|
|
|
#include <core/collection.h>
|
2015-01-27 08:34:32 -05:00
|
|
|
#include <core/string.h>
|
2015-09-08 09:39:35 -04:00
|
|
|
}
|
2014-12-20 12:05:22 -05:00
|
|
|
#include <gui/ocarina.h>
|
2014-12-19 14:25:23 -05:00
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2014-12-19 14:19:18 -05:00
|
|
|
|
2014-12-20 15:01:10 -05:00
|
|
|
static GstBus *gst_bus;
|
2015-01-14 08:21:07 -05:00
|
|
|
|
|
|
|
static Gtk::Button *o_next;
|
2014-12-20 15:01:10 -05:00
|
|
|
static Gtk::Button *o_pause;
|
2015-01-14 08:21:07 -05:00
|
|
|
static Gtk::Button *o_play;
|
|
|
|
static Gtk::Button *o_prev;
|
|
|
|
static Gtk::Scale *o_seek;
|
|
|
|
static Gtk::Button *o_stop;
|
2014-12-20 10:45:40 -05:00
|
|
|
|
2015-01-15 09:34:17 -05:00
|
|
|
static Gtk::SpinButton *o_count;
|
|
|
|
static Gtk::CheckButton *o_enabled;
|
|
|
|
|
2015-01-14 20:16:01 -05:00
|
|
|
static Gtk::Label *o_album;
|
|
|
|
static Gtk::Label *o_artist;
|
|
|
|
static Gtk::Label *o_duration;
|
|
|
|
static Gtk::Label *o_position;
|
|
|
|
static Gtk::Label *o_title;
|
2015-01-14 19:57:06 -05:00
|
|
|
static Glib::RefPtr<Gtk::Adjustment> o_progress;
|
2015-01-14 19:28:55 -05:00
|
|
|
|
2014-12-20 10:45:40 -05:00
|
|
|
|
2015-01-14 20:16:01 -05:00
|
|
|
static void set_markup(Gtk::Label *label, const std::string &size,
|
|
|
|
const std::string &text)
|
|
|
|
{
|
|
|
|
label->set_markup("<span size='" + size + "'>" +
|
|
|
|
Glib::Markup::escape_text(text) + "</span>");
|
|
|
|
}
|
|
|
|
|
2015-12-15 14:34:13 -05:00
|
|
|
static void on_pause()
|
|
|
|
{
|
|
|
|
o_play->show();
|
|
|
|
o_pause->hide();
|
|
|
|
}
|
|
|
|
|
2015-12-15 10:23:15 -05:00
|
|
|
static void on_load(struct track *track, GstState state)
|
2014-12-19 14:25:23 -05:00
|
|
|
{
|
2015-12-15 10:23:15 -05:00
|
|
|
gchar *str = g_strdup_printf("From: %s", track->tr_album->al_name);
|
|
|
|
set_markup(o_album, "x-large", str);
|
|
|
|
g_free(str);
|
2014-12-20 12:05:22 -05:00
|
|
|
|
2015-12-15 10:23:15 -05:00
|
|
|
str = g_strdup_printf("By: %s", track->tr_artist->ar_name);
|
|
|
|
set_markup(o_artist, "x-large", str);
|
|
|
|
g_free(str);
|
2015-11-11 10:42:17 -05:00
|
|
|
|
2015-12-15 10:23:15 -05:00
|
|
|
set_markup(o_title, "xx-large", track->tr_title);
|
2015-11-11 08:11:54 -05:00
|
|
|
|
2015-12-15 10:23:15 -05:00
|
|
|
str = string_sec2str(track->tr_length);
|
|
|
|
o_duration->set_text(str);
|
|
|
|
g_free(str);
|
2015-11-11 10:42:17 -05:00
|
|
|
|
2015-12-15 10:23:15 -05:00
|
|
|
plist :: track_loaded(track);
|
2015-12-15 14:34:13 -05:00
|
|
|
|
|
|
|
if (state != GST_STATE_PLAYING)
|
|
|
|
on_pause();
|
2015-12-15 10:23:15 -05:00
|
|
|
}
|
2015-01-14 20:16:01 -05:00
|
|
|
|
2014-12-19 14:25:23 -05:00
|
|
|
|
2015-12-16 09:18:01 -05:00
|
|
|
class GSTDriver : public AudioDriver {} gst_driver;
|
2014-12-19 14:25:23 -05:00
|
|
|
|
2015-12-15 10:23:15 -05:00
|
|
|
struct audio_ops audio_ops = {
|
|
|
|
on_load,
|
|
|
|
};
|
|
|
|
|
2014-12-19 14:25:23 -05:00
|
|
|
|
2016-03-23 09:58:17 -04:00
|
|
|
static int parse_gst_error(GstMessage *error)
|
2014-12-19 14:25:23 -05:00
|
|
|
{
|
|
|
|
GError *err;
|
2015-12-16 08:26:49 -05:00
|
|
|
struct track *track = audio_cur_track();
|
2015-11-12 09:38:35 -05:00
|
|
|
gchar *path;
|
2016-03-23 09:58:17 -04:00
|
|
|
int ret = 0;
|
2014-12-20 11:33:08 -05:00
|
|
|
|
|
|
|
gst_message_parse_error(error, &err, NULL);
|
2014-12-19 14:25:23 -05:00
|
|
|
|
2015-11-12 09:38:35 -05:00
|
|
|
if (track) {
|
|
|
|
path = track_path(track);
|
|
|
|
g_print("Error playing file: %s\n", path);
|
2016-03-23 09:58:17 -04:00
|
|
|
ret = collection_check_library(track->tr_library);
|
2015-11-12 09:38:35 -05:00
|
|
|
g_free(path);
|
|
|
|
}
|
2014-12-19 14:25:23 -05:00
|
|
|
g_print("Error: %s\n", err->message);
|
|
|
|
g_error_free(err);
|
2016-03-23 09:58:17 -04:00
|
|
|
|
|
|
|
return ret;
|
2014-12-19 14:25:23 -05:00
|
|
|
}
|
|
|
|
|
2014-12-20 11:33:08 -05:00
|
|
|
static gboolean on_gst_message(GstBus *bus, GstMessage *message, gpointer data)
|
2014-12-19 14:25:23 -05:00
|
|
|
{
|
|
|
|
switch (GST_MESSAGE_TYPE(message)) {
|
|
|
|
case GST_MESSAGE_ERROR:
|
2016-03-23 09:58:17 -04:00
|
|
|
if (parse_gst_error(message) < 0)
|
|
|
|
break;
|
2014-12-19 17:25:36 -05:00
|
|
|
audio :: next();
|
2015-12-15 14:17:17 -05:00
|
|
|
gst :: play();
|
2014-12-19 14:25:23 -05:00
|
|
|
break;
|
|
|
|
case GST_MESSAGE_EOS:
|
2015-12-16 09:18:01 -05:00
|
|
|
gst_driver.eos();
|
2015-01-15 09:34:17 -05:00
|
|
|
o_count->set_value(audio :: pause_count());
|
|
|
|
o_enabled->set_active(audio :: pause_enabled());
|
2014-12-19 14:25:23 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-12-20 11:33:08 -05:00
|
|
|
|
|
|
|
return TRUE;
|
2014-12-19 14:25:23 -05:00
|
|
|
}
|
|
|
|
|
2015-01-14 08:21:07 -05:00
|
|
|
static bool on_seek(Gtk::ScrollType type, double value)
|
|
|
|
{
|
2015-12-15 15:50:02 -05:00
|
|
|
audio_seek(value);
|
2015-01-14 08:21:07 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-15 09:34:17 -05:00
|
|
|
static void on_pause_count()
|
|
|
|
{
|
|
|
|
o_enabled->set_active(true);
|
2015-02-04 08:36:57 -05:00
|
|
|
audio :: pause_after(true, o_count->get_value());
|
2015-01-15 09:34:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void on_pause_enabled()
|
|
|
|
{
|
|
|
|
audio :: pause_after(o_enabled->get_active(), o_count->get_value());
|
|
|
|
}
|
|
|
|
|
2015-01-14 19:28:55 -05:00
|
|
|
static bool on_timeout()
|
|
|
|
{
|
2015-12-15 16:42:49 -05:00
|
|
|
gchar *pos = string_sec2str(audio_position() / GST_SECOND);
|
2015-09-02 08:02:41 -04:00
|
|
|
|
2015-12-16 08:00:19 -05:00
|
|
|
o_progress->set_upper(audio_duration());
|
2015-12-15 16:42:49 -05:00
|
|
|
o_progress->set_value(audio_position());
|
2015-09-02 08:02:41 -04:00
|
|
|
o_position->set_text(pos);
|
|
|
|
g_free(pos);
|
2015-01-14 19:28:55 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-17 09:59:25 -05:00
|
|
|
|
|
|
|
|
2015-12-15 14:17:17 -05:00
|
|
|
void gst :: play()
|
|
|
|
{
|
|
|
|
if (audio_play()) {
|
|
|
|
o_play->hide();
|
|
|
|
o_pause->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-15 14:34:13 -05:00
|
|
|
void gst :: pause()
|
|
|
|
{
|
|
|
|
if (audio_pause()) {
|
|
|
|
on_pause();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-16 08:16:46 -05:00
|
|
|
void gst :: stop() {
|
|
|
|
if (audio_stop())
|
|
|
|
on_pause();
|
|
|
|
}
|
|
|
|
|
2015-01-17 09:59:25 -05:00
|
|
|
void gst :: next()
|
|
|
|
{
|
|
|
|
audio :: next();
|
2015-12-15 14:17:17 -05:00
|
|
|
gst :: play();
|
2015-01-17 09:59:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void gst :: toggle()
|
2015-01-14 19:35:02 -05:00
|
|
|
{
|
2015-12-16 09:18:01 -05:00
|
|
|
if (audio_cur_state() == GST_STATE_PLAYING)
|
2015-12-15 14:34:13 -05:00
|
|
|
gst :: pause();
|
2015-01-14 19:35:02 -05:00
|
|
|
else
|
2015-12-15 14:17:17 -05:00
|
|
|
gst :: play();
|
2015-01-14 19:35:02 -05:00
|
|
|
}
|
|
|
|
|
2015-12-15 08:16:06 -05:00
|
|
|
void gst :: init_pre()
|
2014-12-19 14:19:18 -05:00
|
|
|
{
|
2015-01-21 08:29:46 -05:00
|
|
|
o_next = gui :: get_widget<Gtk::Button>("o_next");
|
|
|
|
o_pause = gui :: get_widget<Gtk::Button>("o_pause");
|
|
|
|
o_play = gui :: get_widget<Gtk::Button>("o_play");
|
|
|
|
o_prev = gui :: get_widget<Gtk::Button>("o_prev");
|
|
|
|
o_seek = gui :: get_widget<Gtk::Scale>("o_seek");
|
|
|
|
o_stop = gui :: get_widget<Gtk::Button>("o_stop");
|
|
|
|
|
|
|
|
o_count = gui :: get_widget<Gtk::SpinButton>("o_pause_count");
|
|
|
|
o_enabled = gui :: get_widget<Gtk::CheckButton>("o_pause_enabled");
|
|
|
|
|
|
|
|
o_album = gui :: get_widget<Gtk::Label>("o_album");
|
|
|
|
o_artist = gui :: get_widget<Gtk::Label>("o_artist");
|
|
|
|
o_duration = gui :: get_widget<Gtk::Label>("o_duration");
|
|
|
|
o_position = gui :: get_widget<Gtk::Label>("o_position");
|
|
|
|
o_title = gui :: get_widget<Gtk::Label>("o_title");
|
|
|
|
o_progress = gui :: get_object<Gtk::Adjustment>("o_progress");
|
2015-01-14 19:28:55 -05:00
|
|
|
|
2015-01-17 09:59:25 -05:00
|
|
|
o_next->signal_clicked().connect(sigc::ptr_fun(next));
|
2015-12-15 14:34:13 -05:00
|
|
|
o_pause->signal_clicked().connect(sigc::ptr_fun(gst :: pause));
|
2015-12-15 14:17:17 -05:00
|
|
|
o_play->signal_clicked().connect(sigc::ptr_fun(gst :: play));
|
2015-01-14 08:21:07 -05:00
|
|
|
o_prev->signal_clicked().connect(sigc::ptr_fun(audio :: prev));
|
|
|
|
o_seek->signal_change_value().connect(sigc::ptr_fun(on_seek));
|
2015-12-16 08:16:46 -05:00
|
|
|
o_stop->signal_clicked().connect(sigc::ptr_fun(gst :: stop));
|
2015-01-14 08:21:07 -05:00
|
|
|
|
2015-01-15 09:34:17 -05:00
|
|
|
o_count->signal_changed().connect(sigc::ptr_fun(on_pause_count));
|
|
|
|
o_enabled->signal_toggled().connect(sigc::ptr_fun(on_pause_enabled));
|
2015-12-15 08:16:06 -05:00
|
|
|
}
|
2015-01-15 09:34:17 -05:00
|
|
|
|
2015-12-15 08:16:06 -05:00
|
|
|
void gst :: init()
|
|
|
|
{
|
|
|
|
gst_bus = gst_pipeline_get_bus(GST_PIPELINE(audio_get_player()));
|
2015-01-14 08:21:07 -05:00
|
|
|
gst_bus_add_watch(gst_bus, on_gst_message, NULL);
|
2015-01-21 08:10:59 -05:00
|
|
|
Glib :: signal_timeout().connect(sigc::ptr_fun(on_timeout), 500);
|
2014-12-19 14:19:18 -05:00
|
|
|
}
|