From 8034a64f17a1b8b267c2e7696c193fbcb11d4af7 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 28 Mar 2016 08:22:08 -0400 Subject: [PATCH] audio: Clean up audio loading It's better to have a single function loading tracks and adding them to the history queue. Fixes #2: Initial track not added to history Signed-off-by: Anna Schumaker --- core/audio.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/core/audio.c b/core/audio.c index 99210f1f..44ecfae6 100644 --- a/core/audio.c +++ b/core/audio.c @@ -34,12 +34,13 @@ static bool __audio_change_state(GstState state) return true; } -static bool __audio_load(struct track *track, GstState state) +/* Load a track, but don't add it to the history. */ +static struct track *__audio_load_basic(struct track *track, GstState state) { gchar *path, *uri; if (!track) - return false; + return NULL; path = track_path(track); uri = gst_filename_to_uri(path, NULL); @@ -53,7 +54,14 @@ static bool __audio_load(struct track *track, GstState state) __audio_save(); g_free(uri); g_free(path); - return true; + return track; +} + +static struct track *__audio_load(struct track *track, GstState state) +{ + if (__audio_load_basic(track, state)) + history_add(track); + return track; } static struct track *__audio_next(GstState state) @@ -61,9 +69,7 @@ static struct track *__audio_next(GstState state) struct track *track = tempq_next(); if (!track) track = queue_next(collection_get_queue()); - if (__audio_load(track, state)) - history_add(track); - return track; + return __audio_load(track, state); } static gboolean __audio_message(GstBus *bus, GstMessage *message, gpointer data) @@ -119,11 +125,7 @@ bool audio_load(struct track *track) { if (track == audio_track) return false; - if (__audio_load(track, GST_STATE_PLAYING)) { - history_add(audio_track); - return true; - } - return false; + return __audio_load(track, GST_STATE_PLAYING); } struct track *audio_cur_track() @@ -200,9 +202,7 @@ struct track *audio_next() struct track *audio_prev() { - struct track *track = history_prev(); - __audio_load(track, GST_STATE_PLAYING); - return track; + return __audio_load_basic(history_prev(), GST_STATE_PLAYING); } struct track *audio_eos()