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
|
|
|
*/
|
2015-09-08 09:39:35 -04:00
|
|
|
extern "C" {
|
2015-12-17 10:32:01 -05:00
|
|
|
#include <core/audio.h>
|
2015-01-27 08:34:32 -05:00
|
|
|
#include <core/string.h>
|
2015-12-24 09:35:36 -05:00
|
|
|
#include <gui/builder.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
|
|
|
|
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-18 08:09:34 -05:00
|
|
|
static void on_load(struct track *track)
|
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-18 08:09:34 -05:00
|
|
|
}
|
2015-12-15 14:34:13 -05:00
|
|
|
|
2015-12-18 08:09:34 -05:00
|
|
|
static void on_change_state(GstState state)
|
|
|
|
{
|
|
|
|
if (state == GST_STATE_PLAYING) {
|
|
|
|
o_play->hide();
|
|
|
|
o_pause->show();
|
|
|
|
} else {
|
|
|
|
o_play->show();
|
|
|
|
o_pause->hide();
|
|
|
|
}
|
2015-12-15 10:23:15 -05:00
|
|
|
}
|
2015-01-14 20:16:01 -05:00
|
|
|
|
2015-12-16 12:50:14 -05:00
|
|
|
static void on_config_pause(int n)
|
|
|
|
{
|
|
|
|
if (n == -1)
|
|
|
|
o_enabled->set_active(false);
|
|
|
|
else {
|
|
|
|
o_count->set_value(n);
|
|
|
|
o_enabled->set_active(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-19 14:25:23 -05:00
|
|
|
|
2015-12-15 10:23:15 -05:00
|
|
|
struct audio_ops audio_ops = {
|
|
|
|
on_load,
|
2015-12-18 08:09:34 -05:00
|
|
|
on_change_state,
|
2015-12-16 12:50:14 -05:00
|
|
|
on_config_pause,
|
2015-12-15 10:23:15 -05:00
|
|
|
};
|
|
|
|
|
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-12-16 12:50:14 -05:00
|
|
|
audio_pause_after(o_count->get_value());
|
2015-01-15 09:34:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void on_pause_enabled()
|
|
|
|
{
|
2015-12-16 12:50:14 -05:00
|
|
|
if (!o_enabled->get_active())
|
|
|
|
audio_pause_after(-1);
|
|
|
|
else
|
|
|
|
audio_pause_after(o_count->get_value());
|
2015-01-15 09:34:17 -05:00
|
|
|
}
|
|
|
|
|
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-12-18 08:09:34 -05:00
|
|
|
void gst :: play() { audio_play(); }
|
|
|
|
void gst :: pause() { audio_pause(); }
|
|
|
|
void gst :: stop() { audio_stop(); }
|
2015-12-18 08:34:42 -05:00
|
|
|
void gst :: next() { audio_next(); }
|
|
|
|
void gst :: prev() { audio_prev(); }
|
2015-12-16 12:21:59 -05:00
|
|
|
|
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-12-24 09:35:36 -05:00
|
|
|
o_next = Glib :: wrap(GTK_BUTTON(gui_builder_widget("o_next")), false);
|
|
|
|
o_pause = Glib :: wrap(GTK_BUTTON(gui_builder_widget("o_pause")), false);
|
|
|
|
o_play = Glib :: wrap(GTK_BUTTON(gui_builder_widget("o_play")), false);
|
|
|
|
o_prev = Glib :: wrap(GTK_BUTTON(gui_builder_widget("o_prev")), false);
|
|
|
|
o_stop = Glib :: wrap(GTK_BUTTON(gui_builder_widget("o_stop")), false);
|
|
|
|
o_seek = Glib :: wrap(GTK_SCALE(gui_builder_widget("o_seek")), false);
|
|
|
|
|
|
|
|
o_count = Glib :: wrap(GTK_SPIN_BUTTON(gui_builder_widget("o_pause_count")), false);
|
|
|
|
o_enabled = Glib :: wrap(GTK_CHECK_BUTTON(gui_builder_widget("o_pause_enabled")), false);
|
|
|
|
|
|
|
|
o_album = Glib :: wrap(GTK_LABEL(gui_builder_widget("o_album")), false);
|
|
|
|
o_artist = Glib :: wrap(GTK_LABEL(gui_builder_widget("o_artist")), false);
|
|
|
|
o_duration = Glib :: wrap(GTK_LABEL(gui_builder_widget("o_duration")), false);
|
|
|
|
o_position = Glib :: wrap(GTK_LABEL(gui_builder_widget("o_position")), false);
|
|
|
|
o_title = Glib ::wrap(GTK_LABEL(gui_builder_widget("o_title")), false);
|
|
|
|
o_progress = Glib :: wrap(GTK_ADJUSTMENT(gui_builder_object("o_progress")), false);
|
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-12-16 12:21:59 -05:00
|
|
|
o_prev->signal_clicked().connect(sigc::ptr_fun(gst :: prev));
|
2015-01-14 08:21:07 -05:00
|
|
|
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()
|
|
|
|
{
|
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
|
|
|
}
|