aboutsummaryrefslogtreecommitdiffstats
path: root/src/player_control.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/player_control.c111
1 files changed, 32 insertions, 79 deletions
diff --git a/src/player_control.c b/src/player_control.c
index 90f616d77..5a16520c2 100644
--- a/src/player_control.c
+++ b/src/player_control.c
@@ -26,7 +26,7 @@
#include "song.h"
#include "idle.h"
#include "pcm_volume.h"
-#include "main.h"
+#include "Main.hxx"
#include <assert.h>
#include <stdio.h>
@@ -47,7 +47,7 @@ pc_new(unsigned buffer_chunks, unsigned int buffered_before_play)
pc->cond = g_cond_new();
pc->command = PLAYER_COMMAND_NONE;
- pc->error = PLAYER_ERROR_NOERROR;
+ pc->error_type = PLAYER_ERROR_NONE;
pc->state = PLAYER_STATE_STOP;
pc->cross_fade_seconds = 0;
pc->mixramp_db = 0;
@@ -59,6 +59,9 @@ pc_new(unsigned buffer_chunks, unsigned int buffered_before_play)
void
pc_free(struct player_control *pc)
{
+ if (pc->next_song != NULL)
+ song_free(pc->next_song);
+
g_cond_free(pc->cond);
g_mutex_free(pc->mutex);
g_free(pc);
@@ -76,15 +79,6 @@ player_wait_decoder(struct player_control *pc, struct decoder_control *dc)
g_cond_wait(pc->cond, dc->mutex);
}
-void
-pc_song_deleted(struct player_control *pc, const struct song *song)
-{
- if (pc->errored_song == song) {
- pc->error = PLAYER_ERROR_NOERROR;
- pc->errored_song = NULL;
- }
-}
-
static void
player_command_wait_locked(struct player_control *pc)
{
@@ -236,70 +230,43 @@ pc_get_status(struct player_control *pc, struct player_status *status)
player_unlock(pc);
}
-enum player_state
-pc_get_state(struct player_control *pc)
+void
+pc_set_error(struct player_control *pc, enum player_error type,
+ GError *error)
{
- return pc->state;
+ assert(pc != NULL);
+ assert(type != PLAYER_ERROR_NONE);
+ assert(error != NULL);
+
+ if (pc->error_type != PLAYER_ERROR_NONE)
+ g_error_free(pc->error);
+
+ pc->error_type = type;
+ pc->error = error;
}
void
pc_clear_error(struct player_control *pc)
{
player_lock(pc);
- pc->error = PLAYER_ERROR_NOERROR;
- pc->errored_song = NULL;
- player_unlock(pc);
-}
-enum player_error
-pc_get_error(struct player_control *pc)
-{
- return pc->error;
-}
+ if (pc->error_type != PLAYER_ERROR_NONE) {
+ pc->error_type = PLAYER_ERROR_NONE;
+ g_error_free(pc->error);
+ }
-static char *
-pc_errored_song_uri(struct player_control *pc)
-{
- return song_get_uri(pc->errored_song);
+ player_unlock(pc);
}
char *
pc_get_error_message(struct player_control *pc)
{
- char *error;
- char *uri;
-
- switch (pc->error) {
- case PLAYER_ERROR_NOERROR:
- return NULL;
-
- case PLAYER_ERROR_FILENOTFOUND:
- uri = pc_errored_song_uri(pc);
- error = g_strdup_printf("file \"%s\" does not exist or is inaccessible", uri);
- g_free(uri);
- return error;
-
- case PLAYER_ERROR_FILE:
- uri = pc_errored_song_uri(pc);
- error = g_strdup_printf("problems decoding \"%s\"", uri);
- g_free(uri);
- return error;
-
- case PLAYER_ERROR_AUDIO:
- return g_strdup("problems opening audio device");
-
- case PLAYER_ERROR_SYSTEM:
- return g_strdup("system error occurred");
-
- case PLAYER_ERROR_UNKTYPE:
- uri = pc_errored_song_uri(pc);
- error = g_strdup_printf("file type of \"%s\" is unknown", uri);
- g_free(uri);
- return error;
- }
-
- assert(false);
- return NULL;
+ player_lock(pc);
+ char *message = pc->error_type != PLAYER_ERROR_NONE
+ ? g_strdup(pc->error->message)
+ : NULL;
+ player_unlock(pc);
+ return message;
}
static void
@@ -328,6 +295,10 @@ pc_seek(struct player_control *pc, struct song *song, float seek_time)
assert(song != NULL);
player_lock(pc);
+
+ if (pc->next_song != NULL)
+ song_free(pc->next_song);
+
pc->next_song = song;
pc->seek_where = seek_time;
player_command_locked(pc, PLAYER_COMMAND_SEEK);
@@ -356,12 +327,6 @@ pc_set_cross_fade(struct player_control *pc, float cross_fade_seconds)
idle_add(IDLE_OPTIONS);
}
-float
-pc_get_mixramp_db(const struct player_control *pc)
-{
- return pc->mixramp_db;
-}
-
void
pc_set_mixramp_db(struct player_control *pc, float mixramp_db)
{
@@ -370,12 +335,6 @@ pc_set_mixramp_db(struct player_control *pc, float mixramp_db)
idle_add(IDLE_OPTIONS);
}
-float
-pc_get_mixramp_delay(const struct player_control *pc)
-{
- return pc->mixramp_delay_seconds;
-}
-
void
pc_set_mixramp_delay(struct player_control *pc, float mixramp_delay_seconds)
{
@@ -383,9 +342,3 @@ pc_set_mixramp_delay(struct player_control *pc, float mixramp_delay_seconds)
idle_add(IDLE_OPTIONS);
}
-
-double
-pc_get_total_play_time(const struct player_control *pc)
-{
- return pc->total_play_time;
-}