libsaria: Remove most audio code

It'll be re-added as I review it all.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-03-22 08:32:26 -04:00
parent a0d509cdff
commit 5163447638
17 changed files with 95 additions and 94 deletions

View File

@ -15,34 +15,34 @@ namespace libsaria
{
void init(int, char**);
void quit();
void swap();
string get_current_file();
/*void swap();
string get_current_file();*/
/* Alsa controls */
void use_alsa(bool);
/*void use_alsa(bool);
bool using_alsa();
list<string> *get_alsa_devices();
void set_device(string &);
void set_device(string &);*/
/* Playback control functions */
void load_file(string);
/*void load_file(string);
void load(string);
void play();
void pause();
void stop();
bool is_playing();
bool is_playing();*/
/* Position related functions */
bool seek(int);
/*bool seek(int);
void seek_to(double);
gint64 duration();
gint64 position();
string posstr();
string durstr();
string durstr();*/
/* Volume functions */
float get_volume();
void set_volume(float);
/*float get_volume();
void set_volume(float);*/
};
};

View File

@ -9,10 +9,10 @@
#include <list>
using namespace std;
static GstElement *alsa = NULL;
//static GstElement *alsa = NULL;
static list<string> devices;
gulong about_to_finish_id;
/*
static void about_to_finish(GstElement *playbin, gpointer data)
{
string file;
@ -61,15 +61,15 @@ static void remove_alsa()
{
println("Removing ALSA");
g_signal_handler_disconnect(player, about_to_finish_id);
set_alsa_device("default");
set_alsa_device("default");*/
/* Removing the sink will also deallocate it */
set_audio_sink(NULL);
}
/* set_audio_sink(NULL);
}*/
namespace libsaria
{
void audio::use_alsa(bool use)
/*void audio::use_alsa(bool use)
{
struct StoredAudioState state;
save_audio_state(&state);
@ -113,6 +113,6 @@ namespace libsaria
save_audio_state(&state);
g_object_set(G_OBJECT(alsa), "device", device.c_str(), NULL);
load_audio_state(&state);
}
}*/
}; /* Namespace: libsaria */

View File

@ -8,7 +8,7 @@
GstElement *player = NULL;
GstBus *bus = NULL;
static bool restoring_state = false;
//static bool restoring_state = false;
static void parse_error(GstMessage *error)
{
@ -21,7 +21,7 @@ static void parse_error(GstMessage *error)
g_free(debug);
}
static void notify_audio_changed()
/*static void notify_audio_changed()
{
println("Notify audio changed");
if (libsaria::get_pause_after()) {
@ -30,7 +30,7 @@ static void notify_audio_changed()
}
if (restoring_state == false)
trigger_callback(TRACK_LOADED);
}
}*/
static gboolean on_message(GstBus *bus, GstMessage *message, gpointer data)
{
@ -38,7 +38,7 @@ static gboolean on_message(GstBus *bus, GstMessage *message, gpointer data)
case GST_MESSAGE_ERROR:
parse_error(message);
case GST_MESSAGE_EOS:
libsaria::next();
/*libsaria::next();*/
default:
break;
}
@ -47,13 +47,13 @@ static gboolean on_message(GstBus *bus, GstMessage *message, gpointer data)
static void audio_changed(GstElement *playbin, gpointer data)
{
notify_audio_changed();
//notify_audio_changed();
}
/*
* Set sink to NULL to use the default sink
*/
void set_audio_sink(GstElement *sink)
/*void set_audio_sink(GstElement *sink)
{
g_object_set(G_OBJECT(player), "audio-sink", sink, NULL);
}
@ -73,39 +73,38 @@ void load_audio_state(struct StoredAudioState *state)
if (state->was_playing == true)
libsaria::audio::play();
else
libsaria::audio::pause();
libsaria::audio::pause();*/
/*
* Wait for async play() or pause() to finish, otherwise
* the seek won't succeed
*/
gst_element_get_state(GST_ELEMENT(player), NULL, NULL, GST_CLOCK_TIME_NONE);
/* gst_element_get_state(GST_ELEMENT(player), NULL, NULL, GST_CLOCK_TIME_NONE);
libsaria::audio::seek_to(state->position);
restoring_state = false;
}
}*/
namespace libsaria
{
void audio::init(int argc, char **argv)
{
println("Initializing audio driver");
println("Initializing libsaria audio");
gst_init(&argc, &argv);
player = gst_element_factory_make("playbin2", "player");
bus = gst_pipeline_get_bus(GST_PIPELINE(player));
gst_bus_add_watch(bus, on_message, NULL);
g_signal_connect(player, "audio-changed", G_CALLBACK(audio_changed), NULL);
init_volume();
init_alsa();
/*init_volume();
init_alsa();*/
}
void audio::quit()
{
quit_alsa();
/*quit_alsa();*/
gst_deinit();
}

View File

@ -6,9 +6,9 @@
#include "audio.h"
static string cur_file;
static GstState cur_state = GST_STATE_NULL;
//static GstState cur_state = GST_STATE_NULL;
static bool change_state(GstState new_state)
/*static bool change_state(GstState new_state)
{
GstStateChangeReturn ret;
ret = gst_element_set_state(GST_ELEMENT(player), new_state);
@ -27,7 +27,7 @@ static void reset()
{
cur_file = "";
change_state(GST_STATE_NULL);
}
}*/
void load_file(GstElement *playbin, string file)
{
@ -42,7 +42,7 @@ void load_file(GstElement *playbin, string file)
namespace libsaria
{
void audio::play()
/*void audio::play()
{
if (cur_file == "")
return;
@ -82,6 +82,6 @@ namespace libsaria
string audio::get_current_file()
{
return cur_file;
}
}*/
};

View File

@ -5,7 +5,7 @@ using namespace std;
#include <libsaria/audio.h>
#include "audio.h"
static bool get_duration(gint64 &duration)
/*static bool get_duration(gint64 &duration)
{
GstFormat fmt = GST_FORMAT_TIME;
return gst_element_query_duration(GST_ELEMENT(player),
@ -37,33 +37,33 @@ static string to_string(gint64 time)
stream << "0";
stream << seconds;
return stream.str();
}
}*/
namespace libsaria
{
/* Seek to this many seconds into the song */
void audio::seek_to(double pos)
/*void audio::seek_to(double pos)
{
gst_element_seek_simple(GST_ELEMENT(player),
GST_FORMAT_TIME,
GST_SEEK_FLAG_FLUSH,
pos);
}
}*/
/*
* Use to seek forward or backward in a song
* by dt seconds.
*/
bool audio::seek(int dt)
/*bool audio::seek(int dt)
{
bool ret;
gint64 pos;
ret = get_position(pos);
if (ret == true) {
if (ret == true) {*/
/* Convert seconds to nano-seconds */
pos += (dt * GST_SECOND);
/* pos += (dt * GST_SECOND);
if (pos < 0)
pos = 0;
seek_to(pos);
@ -97,6 +97,6 @@ namespace libsaria
string audio::posstr()
{
return to_string(position());
}
}*/
};

View File

@ -15,20 +15,20 @@ void configure_volume(float volume)
namespace libsaria
{
void audio::set_volume(float volume)
/*void audio::set_volume(float volume)
{
prefs::set("volume", volume);
}
}*/
void audio::init_volume()
{
//configure_volume(prefs::get_float("volume", 1.0));
}
float audio::get_volume()
/*float audio::get_volume()
{
//return prefs::get_float("volume", 1.0);
return 1.0;
}
}*/
};

View File

@ -5,9 +5,9 @@
#include <libsaria/library.h>
#include <libsaria/stack.h>
static bool pause_after_current = false;
//static bool pause_after_current = false;
namespace libsaria
/*namespace libsaria
{
void play_file(string &filepath)
@ -30,14 +30,14 @@ namespace libsaria
//play_file(filepath);
}
/*void play_id(sid_t &songid)
void play_id(sid_t &songid)
{
println("Playing id: %lu", songid);
Track *track = library::lookup(songid);
string filepath = track->get_filepath();
println(filepath);
play_file(filepath);
}*/
}
void set_pause_after(bool state)
{
@ -66,4 +66,4 @@ namespace libsaria
{
audio::seek(5);
}
}; /* Namespace: libsaria */
}; *//* Namespace: libsaria */

View File

@ -13,10 +13,10 @@ namespace libsaria
{
// sid_t songid;
//libsaria::Track *current;
string file = libsaria::audio::get_current_file();
//string file = libsaria::audio::get_current_file();
if (file == "")
return NULL;
//if (file == "")
// return NULL;
// songid = lookup_songid(file);
/*current = libsaria::library::lookup(songid);

View File

@ -3,8 +3,10 @@
#include <libsaria/libsaria.h>
#include <libsaria/library.h>
#include <libsaria/format.h>
#include <libsaria/prefs.h>
#include <libsaria/print.h>
#include <libsaria/audio.h>
#include <libsaria/idle.h>
#include <libsaria/fs.h>
/*#include <libsaria/audio.h>
@ -31,9 +33,9 @@ namespace libsaria
if (enable_idle)
idle::enable();
/*audio::init(argc, argv);
audio::init(argc, argv);
println("saria dir: %s", get_saria_dir().c_str());
/*println("saria dir: %s", get_saria_dir().c_str());
make_saria_dir();*/
//libsaria::library::init();
@ -42,10 +44,10 @@ namespace libsaria
void quit()
{
/*println("Quitting libsaria");
println("Quitting libsaria");
audio::quit();
print_format_stats();
index::print_stats();
/*index::print_stats();
close_pipes();*/
}

View File

@ -62,8 +62,8 @@ static void on_click_open_file(GtkWidget *b, GdkEvent *e, gpointer d)
string file = ocarina::choose_file();
if (file != "") {
println("Playing file: " + file);
libsaria::audio::load(file);
libsaria::audio::play();
//libsaria::audio::load(file);
//libsaria::audio::play();
}
}

View File

@ -37,7 +37,7 @@ void hide_button_list(button_list_t bttn_list)
static void on_click_play(GtkWidget *b, GdkEvent *e, gpointer d)
{
libsaria::audio::play();
//libsaria::audio::play();
}
static void destroyed(GtkWidget *button, list<GtkWidget *> *widget_list)
@ -57,7 +57,7 @@ GtkWidget *make_play_button()
static void on_click_pause(GtkWidget *b, GdkEvent *e, gpointer d)
{
libsaria::audio::pause();
//libsaria::audio::pause();
}
GtkWidget *make_pause_button()
@ -72,7 +72,7 @@ GtkWidget *make_pause_button()
static void on_click_stop(GtkWidget *b, GdkEvent *e, gpointer d)
{
libsaria::audio::stop();
//libsaria::audio::stop();
}
GtkWidget *make_stop_button()
@ -84,7 +84,7 @@ GtkWidget *make_stop_button()
static void on_click_rewind(GtkWidget *b, GdkEvent *e, gpointer d)
{
libsaria::audio::seek(-5);
//libsaria::audio::seek(-5);
}
GtkWidget *make_rewind_button()
@ -96,7 +96,7 @@ GtkWidget *make_rewind_button()
static void on_click_forward(GtkWidget *b, GdkEvent *e, gpointer d)
{
libsaria::audio::seek(5);
//libsaria::audio::seek(5);
}
GtkWidget *make_forward_button()
@ -108,7 +108,7 @@ GtkWidget *make_forward_button()
static void on_click_next(GtkWidget *b, GdkEvent *e, gpointer d)
{
libsaria::next();
//libsaria::next();
}
GtkWidget *make_next_button()

View File

@ -24,15 +24,15 @@ static void set_increment(GtkWidget *volume, double incr)
static void changed(GtkWidget *button, gdouble value, gpointer data)
{
libsaria::audio::set_volume(value);
//libsaria::audio::set_volume(value);
resize(button);
}
GtkWidget *make_volume_button()
{
GtkWidget *volume = gtk_volume_button_new();
gtk_scale_button_set_value(GTK_SCALE_BUTTON(volume),
libsaria::audio::get_volume());
/*gtk_scale_button_set_value(GTK_SCALE_BUTTON(volume),
libsaria::audio::get_volume());*/
gtk_widget_show(volume);
set_increment(volume, 0.05);
resize(volume);

View File

@ -21,10 +21,10 @@ static GtkWidget *make_buttons()
return buttons;
}
static void toggle_pause_after()
/*static void toggle_pause_after()
{
libsaria::set_pause_after(!libsaria::get_pause_after());
}
}*/
GtkWidget *get_controls()
{
@ -40,10 +40,10 @@ GtkWidget *get_controls()
void controls_init()
{
register_shortcut("Left", libsaria::rewind);
/*register_shortcut("Left", libsaria::rewind);
register_shortcut("Right", libsaria::forward);
register_shortcut("space", libsaria::toggle_play);
register_shortcut("n", libsaria::next);
register_shortcut("s", libsaria::audio::stop);
register_shortcut("p", toggle_pause_after);
register_shortcut("p", toggle_pause_after);*/
}

View File

@ -17,21 +17,21 @@ static list<ProgressWidgets> widget_list;
static gboolean update_progress(struct ProgressWidgets *widgets)
{
gint64 pos = libsaria::audio::position();
/*gint64 pos = libsaria::audio::position();
gint64 dur = libsaria::audio::duration() + 1;
gtk_label_set_text(GTK_LABEL(widgets->position), libsaria::audio::posstr().c_str());
gtk_label_set_text(GTK_LABEL(widgets->duration), libsaria::audio::durstr().c_str());
gtk_label_set_text(GTK_LABEL(widgets->duration), libsaria::audio::durstr().c_str());*/
/*
* This happens when gstreamer's "about-to-finish" signal
* is emitted and we queue up a shorter song before the
* pipeline finishes.
*/
if (pos > dur)
/*if (pos > dur)
pos = 0;
gtk_range_set_range(GTK_RANGE(widgets->progress), 0, dur);
gtk_range_set_value(GTK_RANGE(widgets->progress), pos);
gtk_range_set_value(GTK_RANGE(widgets->progress), pos);*/
return TRUE;
}
@ -51,7 +51,7 @@ void progress_init()
static void slider_changed(GtkWidget *slider, GtkScrollType scroll,
gdouble value, gpointer data)
{
libsaria::audio::seek_to(value);
//libsaria::audio::seek_to(value);
}
static GtkWidget *make_scale()

View File

@ -13,14 +13,14 @@ static GIOChannel *pipe_in;
void perform_action(string action)
{
if (action == "play")
/* if (action == "play")
libsaria::audio::play();
else if (action == "pause")
libsaria::audio::pause();
else if (action == "stop")
libsaria::audio::stop();
else if (action == "next")
libsaria::next();
libsaria::next();*/
}
string pipe_read_text(GIOChannel *source)

View File

@ -9,7 +9,7 @@ static unsigned int num_alsa_devices = 0;
static void set_alsa_devices(bool using_alsa)
{
list<string> *devices;
//list<string> *devices;
list<string>::iterator it;
for (unsigned int i = 0; i < num_alsa_devices; i++)
@ -17,10 +17,10 @@ static void set_alsa_devices(bool using_alsa)
num_alsa_devices = 0;
if (using_alsa == true) {
devices = libsaria::audio::get_alsa_devices();
/*devices = libsaria::audio::get_alsa_devices();
for (it = devices->begin(); it != devices->end(); it++)
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(alsa_devices), it->c_str());
num_alsa_devices = devices->size();
num_alsa_devices = devices->size();*/
}
}
@ -29,7 +29,7 @@ static void change_alsa_device(GtkComboBox *combo, gpointer data)
char *device = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(alsa_devices));
if (device != NULL) {
string dev = device;
libsaria::audio::set_device(dev);
//libsaria::audio::set_device(dev);
g_free(device);
}
}
@ -37,22 +37,22 @@ static void change_alsa_device(GtkComboBox *combo, gpointer data)
static void toggle_alsa(GtkWidget *button, gpointer data)
{
bool active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
libsaria::audio::use_alsa(active);
//libsaria::audio::use_alsa(active);
gtk_widget_set_sensitive(alsa_devices, active);
set_alsa_devices(active);
}
static void add_alsa_settings(GtkWidget *general)
{
bool using_alsa = libsaria::audio::using_alsa();
//bool using_alsa = libsaria::audio::using_alsa();
GtkWidget *alsa = gtk_hbox_new(FALSE, 0);
GtkWidget *button = gtk_check_button_new_with_label("Use ALSA");
alsa_devices = gtk_combo_box_text_new();
gtk_widget_set_sensitive(alsa_devices, using_alsa);
set_alsa_devices(using_alsa);
//gtk_widget_set_sensitive(alsa_devices, using_alsa);
//set_alsa_devices(using_alsa);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), using_alsa);
//gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), using_alsa);
GTK_CONNECT(button, "toggled", toggle_alsa, NULL);
GTK_CONNECT(alsa_devices, "changed", change_alsa_device, NULL);

View File

@ -23,14 +23,14 @@ GtkWidget *MenuItem::get_widget()
static void toggle_pause_after(GtkMenuItem *menu, gpointer data)
{
libsaria::set_pause_after(!libsaria::get_pause_after());
//libsaria::set_pause_after(!libsaria::get_pause_after());
}
static GtkWidget *make_pause_after_item()
{
GtkWidget *widget = gtk_check_menu_item_new_with_label("Pause After Current Song");
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget),
libsaria::get_pause_after());
/*gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget),
libsaria::get_pause_after());*/
GTK_CONNECT(widget, "activate", toggle_pause_after, NULL);
return widget;
}