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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load a track, but don't add it to the history. */
|
static void __audio_gst_load(struct track *track, GstState state)
|
||||||
static struct track *__audio_load_basic(struct track *track, GstState state)
|
|
||||||
{
|
{
|
||||||
struct track *prev = audio_track;
|
gchar *path = track_path(track);
|
||||||
gchar *path, *uri;
|
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;
|
audio_track = track;
|
||||||
|
|
||||||
gst_element_set_state(audio_player, GST_STATE_NULL);
|
gst_element_set_state(audio_player, GST_STATE_NULL);
|
||||||
g_object_set(G_OBJECT(audio_player), "uri", uri, NULL);
|
g_object_set(G_OBJECT(audio_player), "uri", uri, NULL);
|
||||||
audio_ops->on_load(track);
|
|
||||||
__audio_change_state(state);
|
__audio_change_state(state);
|
||||||
|
audio_ops->on_load(track);
|
||||||
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_save();
|
audio_save();
|
||||||
g_free(uri);
|
g_free(uri);
|
||||||
g_free(path);
|
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)
|
static struct track *__audio_load(struct track *track, GstState state)
|
||||||
{
|
{
|
||||||
if (__audio_load_basic(track, state))
|
struct track *ret = __audio_do_load(track, state);
|
||||||
playlist_add(playlist_lookup(PL_SYSTEM, "History"), track);
|
|
||||||
return track;
|
if (ret == track)
|
||||||
|
playlist_add(playlist_lookup(PL_SYSTEM, "History"), ret);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct track *__audio_next(GstState state)
|
static struct track *__audio_next(GstState state)
|
||||||
|
@ -144,7 +148,7 @@ bool audio_load(struct track *track)
|
||||||
{
|
{
|
||||||
if (track == audio_track)
|
if (track == audio_track)
|
||||||
return false;
|
return false;
|
||||||
return __audio_load(track, GST_STATE_PLAYING);
|
return __audio_load(track, GST_STATE_PLAYING) == track;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct track *audio_cur_track()
|
struct track *audio_cur_track()
|
||||||
|
@ -234,16 +238,14 @@ struct track *audio_next()
|
||||||
|
|
||||||
struct track *audio_prev()
|
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()
|
struct track *audio_eos()
|
||||||
{
|
{
|
||||||
/* Mark current track as played */
|
/* Mark current track as played */
|
||||||
if (audio_track) {
|
if (audio_track)
|
||||||
track_played(audio_track);
|
track_played(audio_track);
|
||||||
playlist_played(audio_track);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check pause count and pick the next track */
|
/* Check pause count and pick the next track */
|
||||||
if (audio_pause_count >= 0) {
|
if (audio_pause_count >= 0) {
|
||||||
|
|
|
@ -64,8 +64,11 @@ void playlist_save()
|
||||||
void playlist_played(struct track *track)
|
void playlist_played(struct track *track)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
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)
|
struct playlist *playlist_new(enum playlist_type_t type, const gchar *name)
|
||||||
|
|
Loading…
Reference in New Issue