core/audio: Clean up loading tracks
This lets us call playlist_played() whenever we change tracks to send UI updates once, rather than using multiple updates to change playcount and now-playing status. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
ee8825745b
commit
ed095eb987
50
core/audio.c
50
core/audio.c
|
@ -29,39 +29,43 @@ static bool __audio_change_state(GstState state)
|
|||
return true;
|
||||
}
|
||||
|
||||
/* Load a track, but don't add it to the history. */
|
||||
static struct track *__audio_load_basic(struct track *track, GstState state)
|
||||
static void __audio_gst_load(struct track *track, GstState state)
|
||||
{
|
||||
struct track *prev = audio_track;
|
||||
gchar *path, *uri;
|
||||
gchar *path = track_path(track);
|
||||
gchar *uri = gst_filename_to_uri(path, NULL);
|
||||
|
||||
if (!track)
|
||||
return NULL;
|
||||
|
||||
path = track_path(track);
|
||||
uri = gst_filename_to_uri(path, NULL);
|
||||
audio_track = track;
|
||||
|
||||
gst_element_set_state(audio_player, GST_STATE_NULL);
|
||||
g_object_set(G_OBJECT(audio_player), "uri", uri, NULL);
|
||||
audio_ops->on_load(track);
|
||||
__audio_change_state(state);
|
||||
|
||||
queue_updated(&playlist_lookup(PL_SYSTEM, "Queued Tracks")->pl_queue, prev);
|
||||
queue_updated(&playlist_lookup(PL_SYSTEM, "Collection")->pl_queue, prev);
|
||||
queue_updated(&playlist_lookup(PL_SYSTEM, "Collection")->pl_queue, audio_track);
|
||||
audio_ops->on_load(track);
|
||||
|
||||
audio_save();
|
||||
g_free(uri);
|
||||
g_free(path);
|
||||
return track;
|
||||
}
|
||||
|
||||
/* Load a track, but don't add it to the history. */
|
||||
static struct track *__audio_do_load(struct track *track, GstState state)
|
||||
{
|
||||
struct track *prev = audio_track;
|
||||
|
||||
if (track) {
|
||||
__audio_gst_load(track, state);
|
||||
queue_updated(&playlist_lookup(PL_SYSTEM, "Collection")->pl_queue, track);
|
||||
}
|
||||
|
||||
playlist_played(prev);
|
||||
return audio_track;
|
||||
}
|
||||
|
||||
static struct track *__audio_load(struct track *track, GstState state)
|
||||
{
|
||||
if (__audio_load_basic(track, state))
|
||||
playlist_add(playlist_lookup(PL_SYSTEM, "History"), track);
|
||||
return track;
|
||||
struct track *ret = __audio_do_load(track, state);
|
||||
|
||||
if (ret == track)
|
||||
playlist_add(playlist_lookup(PL_SYSTEM, "History"), ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct track *__audio_next(GstState state)
|
||||
|
@ -144,7 +148,7 @@ bool audio_load(struct track *track)
|
|||
{
|
||||
if (track == audio_track)
|
||||
return false;
|
||||
return __audio_load(track, GST_STATE_PLAYING);
|
||||
return __audio_load(track, GST_STATE_PLAYING) == track;
|
||||
}
|
||||
|
||||
struct track *audio_cur_track()
|
||||
|
@ -234,16 +238,14 @@ struct track *audio_next()
|
|||
|
||||
struct track *audio_prev()
|
||||
{
|
||||
return __audio_load_basic(playlist_prev(), GST_STATE_PLAYING);
|
||||
return __audio_do_load(playlist_prev(), GST_STATE_PLAYING);
|
||||
}
|
||||
|
||||
struct track *audio_eos()
|
||||
{
|
||||
/* Mark current track as played */
|
||||
if (audio_track) {
|
||||
if (audio_track)
|
||||
track_played(audio_track);
|
||||
playlist_played(audio_track);
|
||||
}
|
||||
|
||||
/* Check pause count and pick the next track */
|
||||
if (audio_pause_count >= 0) {
|
||||
|
|
|
@ -64,8 +64,11 @@ void playlist_save()
|
|||
void playlist_played(struct track *track)
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0; i < PL_MAX_TYPE; i++)
|
||||
playlist_types[i]->pl_played(track);
|
||||
|
||||
if (track) {
|
||||
for (i = 0; i < PL_MAX_TYPE; i++)
|
||||
playlist_types[i]->pl_played(track);
|
||||
}
|
||||
}
|
||||
|
||||
struct playlist *playlist_new(enum playlist_type_t type, const gchar *name)
|
||||
|
|
Loading…
Reference in New Issue