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 <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-03-28 08:22:08 -04:00
parent 711eb67f44
commit 8034a64f17
1 changed files with 14 additions and 14 deletions

View File

@ -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()