From 5ad21d7e98e1f21e09de66c1e0275ea2ab5b74e4 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 21 Aug 2012 19:17:14 +0200 Subject: queue_save: save song priorities --- NEWS | 1 + src/playlist_edit.c | 2 +- src/queue.c | 4 ++-- src/queue.h | 4 +++- src/queue_save.c | 21 +++++++++++++++++++-- test/test_queue_priority.c | 2 +- 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 41a69d8e..7bdfa353 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,7 @@ ver 0.17.2 (2012/??/??) * mapper: fix potential crash in file permission check * playlist: fix use-after-free bug * playlist: fix memory leak +* state_file: save song priorities ver 0.17.1 (2012/07/31) diff --git a/src/playlist_edit.c b/src/playlist_edit.c index 7adbccd7..d10f4945 100644 --- a/src/playlist_edit.c +++ b/src/playlist_edit.c @@ -83,7 +83,7 @@ playlist_append_song(struct playlist *playlist, struct player_control *pc, queued = playlist_get_queued_song(playlist); - id = queue_append(&playlist->queue, song); + id = queue_append(&playlist->queue, song, 0); if (playlist->queue.random) { /* shuffle the new song into the list of remaining diff --git a/src/queue.c b/src/queue.c index cd932875..4fe564a3 100644 --- a/src/queue.c +++ b/src/queue.c @@ -96,7 +96,7 @@ queue_modify_all(struct queue *queue) } unsigned -queue_append(struct queue *queue, struct song *song) +queue_append(struct queue *queue, struct song *song, uint8_t priority) { unsigned id = queue_generate_id(queue); @@ -106,7 +106,7 @@ queue_append(struct queue *queue, struct song *song) .song = song, .id = id, .version = queue->version, - .priority = 0, + .priority = priority, }; queue->order[queue->length] = queue->length; diff --git a/src/queue.h b/src/queue.h index 5cb5c196..e4bfcdff 100644 --- a/src/queue.h +++ b/src/queue.h @@ -280,9 +280,11 @@ queue_modify_all(struct queue *queue); * * If a song is not in the database (determined by * song_in_database()), it is freed when removed from the queue. + * + * @param priority the priority of this new queue item */ unsigned -queue_append(struct queue *queue, struct song *song); +queue_append(struct queue *queue, struct song *song, uint8_t priority); /** * Swaps two songs, addressed by their position. diff --git a/src/queue_save.c b/src/queue_save.c index a7c511c0..16852d3c 100644 --- a/src/queue_save.c +++ b/src/queue_save.c @@ -24,9 +24,12 @@ #include "uri.h" #include "database.h" #include "song_save.h" +#include "text_file.h" #include +#define PRIO_LABEL "Prio: " + static void queue_save_database_song(FILE *fp, int idx, const struct song *song) { @@ -54,8 +57,13 @@ queue_save_song(FILE *fp, int idx, const struct song *song) void queue_save(FILE *fp, const struct queue *queue) { - for (unsigned i = 0; i < queue_length(queue); i++) + for (unsigned i = 0; i < queue_length(queue); i++) { + uint8_t prio = queue_get_priority_at_position(queue, i); + if (prio != 0) + fprintf(fp, PRIO_LABEL "%u\n", prio); + queue_save_song(fp, i, queue_get(queue, i)); + } } static struct song * @@ -75,6 +83,15 @@ queue_load_song(FILE *fp, GString *buffer, const char *line, if (queue_is_full(queue)) return; + uint8_t priority = 0; + if (g_str_has_prefix(line, PRIO_LABEL)) { + priority = strtoul(line + sizeof(PRIO_LABEL) - 1, NULL, 10); + + line = read_text_line(fp, buffer); + if (line == NULL) + return; + } + if (g_str_has_prefix(line, SONG_BEGIN)) { const char *uri = line + sizeof(SONG_BEGIN) - 1; if (!uri_has_scheme(uri) && !g_path_is_absolute(uri)) @@ -102,5 +119,5 @@ queue_load_song(FILE *fp, GString *buffer, const char *line, return; } - queue_append(queue, song); + queue_append(queue, song, priority); } diff --git a/test/test_queue_priority.c b/test/test_queue_priority.c index a7106a8e..5543edbb 100644 --- a/test/test_queue_priority.c +++ b/test/test_queue_priority.c @@ -41,7 +41,7 @@ main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) queue_init(&queue, 32); for (unsigned i = 0; i < G_N_ELEMENTS(songs); ++i) - queue_append(&queue, &songs[i]); + queue_append(&queue, &songs[i], 0); assert(queue_length(&queue) == G_N_ELEMENTS(songs)); -- cgit v1.2.3 From 66ecf39efe703185b1d54775e052d1c6a3f76903 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 21 Aug 2012 19:38:08 +0200 Subject: command: make "single" a bool --- src/command.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command.c b/src/command.c index 329b7d51..c405925f 100644 --- a/src/command.c +++ b/src/command.c @@ -1069,7 +1069,7 @@ handle_next(G_GNUC_UNUSED struct client *client, { /* single mode is not considered when this is user who * wants to change song. */ - int single = g_playlist.queue.single; + const bool single = g_playlist.queue.single; g_playlist.queue.single = false; playlist_next(&g_playlist, client->player_control); -- cgit v1.2.3 From f351550534939478d7ddc791dc76aafd5f2a3503 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 25 Aug 2012 08:44:31 +0200 Subject: player_thread: disable cross-fading in "single" mode This commit reimplements the core of the "single" mode. Instead of doing the detection in the playlist code from the outside, it is moved to the player thread, which gets a new option called "border_pause". It will now pause playback exactly at the beginning of the new song, making the feature more reliable. Now that the player thread knows what will happen, it can suppress cross-fading. Fixes mantis tickets 0003055 and 0003166. --- NEWS | 1 + src/player_control.c | 8 ++++++++ src/player_control.h | 15 +++++++++++++++ src/player_thread.c | 15 ++++++++++++++- src/playlist.c | 17 ++++++++++------- 5 files changed, 48 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index 7bdfa353..717151de 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,7 @@ ver 0.17.2 (2012/??/??) * playlist: fix use-after-free bug * playlist: fix memory leak * state_file: save song priorities +* player: disable cross-fading in "single" mode ver 0.17.1 (2012/07/31) diff --git a/src/player_control.c b/src/player_control.c index d8d54dfd..90f616d7 100644 --- a/src/player_control.c +++ b/src/player_control.c @@ -210,6 +210,14 @@ pc_set_pause(struct player_control *pc, bool pause_flag) player_unlock(pc); } +void +pc_set_border_pause(struct player_control *pc, bool border_pause) +{ + player_lock(pc); + pc->border_pause = border_pause; + player_unlock(pc); +} + void pc_get_status(struct player_control *pc, struct player_status *status) { diff --git a/src/player_control.h b/src/player_control.h index 5a04ab0f..a77d31ec 100644 --- a/src/player_control.h +++ b/src/player_control.h @@ -115,6 +115,15 @@ struct player_control { float mixramp_db; float mixramp_delay_seconds; double total_play_time; + + /** + * If this flag is set, then the player will be auto-paused at + * the end of the song, before the next song starts to play. + * + * This is a copy of the queue's "single" flag most of the + * time. + */ + bool border_pause; }; struct player_control * @@ -207,6 +216,12 @@ pc_set_pause(struct player_control *pc, bool pause_flag); void pc_pause(struct player_control *pc); +/** + * Set the player's #border_pause flag. + */ +void +pc_set_border_pause(struct player_control *pc, bool border_pause); + void pc_kill(struct player_control *pc); diff --git a/src/player_thread.c b/src/player_thread.c index eaf6df30..707fb27a 100644 --- a/src/player_thread.c +++ b/src/player_thread.c @@ -842,6 +842,16 @@ player_song_border(struct player *player) if (!player_wait_for_decoder(player)) return false; + struct player_control *const pc = player->pc; + player_lock(pc); + + if (pc->border_pause) { + player->paused = true; + pc->state = PLAYER_STATE_PAUSE; + } + + player_unlock(pc); + return true; } @@ -957,7 +967,10 @@ static void do_play(struct player_control *pc, struct decoder_control *dc) player_dc_start(&player, music_pipe_new()); } - if (player_dc_at_next_song(&player) && + if (/* no cross-fading if MPD is going to pause at the + end of the current song */ + !pc->border_pause && + player_dc_at_next_song(&player) && player.xfade == XFADE_UNKNOWN && !decoder_lock_is_starting(dc)) { /* enable cross fading in this song? if yes, diff --git a/src/playlist.c b/src/playlist.c index d62865dd..dc6d8c34 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -109,11 +109,6 @@ playlist_song_started(struct playlist *playlist, struct player_control *pc) playlist->current = playlist->queued; playlist->queued = -1; - /* Pause if we are in single mode. */ - if(playlist->queue.single && !playlist->queue.repeat) { - pc_set_pause(pc, true); - } - if(playlist->queue.consume) playlist_delete(playlist, pc, queue_order_to_position(&playlist->queue, @@ -310,7 +305,11 @@ playlist_set_repeat(struct playlist *playlist, struct player_control *pc, if (status == playlist->queue.repeat) return; - playlist->queue.repeat = status; + struct queue *queue = &playlist->queue; + + queue->repeat = status; + + pc_set_border_pause(pc, queue->single && !queue->repeat); /* if the last song is currently being played, the "next song" might change when repeat mode is toggled */ @@ -338,7 +337,11 @@ playlist_set_single(struct playlist *playlist, struct player_control *pc, if (status == playlist->queue.single) return; - playlist->queue.single = status; + struct queue *queue = &playlist->queue; + + queue->single = status; + + pc_set_border_pause(pc, queue->single && !queue->repeat); /* if the last song is currently being played, the "next song" might change when single mode is toggled */ -- cgit v1.2.3 From acaa725478ae5e6e4fff9e07cf8637d17d314c41 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 25 Aug 2012 09:56:14 +0200 Subject: playlist/cue: map "PERFORMER" to "artist" or "album artist" Implements Mantis ticket 0003549. --- NEWS | 2 ++ src/cue/cue_parser.c | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 717151de..c23739d7 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,8 @@ ver 0.17.2 (2012/??/??) * output: - httpd: use monotonic clock, avoid hiccups after system clock adjustment - httpd: fix throttling bug after resuming playback +* playlist: + - cue: map "PERFORMER" to "artist" or "album artist" * mapper: fix non-UTF8 music directory name * mapper: fix potential crash in file permission check * playlist: fix use-after-free bug diff --git a/src/cue/cue_parser.c b/src/cue/cue_parser.c index 868aed09..2b0733f0 100644 --- a/src/cue/cue_parser.c +++ b/src/cue/cue_parser.c @@ -216,9 +216,19 @@ cue_parser_feed2(struct cue_parser *parser, char *p) if (tag != NULL) cue_parse_rem(p, tag); } else if (strcmp(command, "PERFORMER") == 0) { + /* MPD knows a "performer" tag, but it is not a good + match for this CUE tag; from the Hydrogenaudio + Knowledgebase: "At top-level this will specify the + CD artist, while at track-level it specifies the + track artist." */ + + enum tag_type type = parser->state == TRACK + ? TAG_ARTIST + : TAG_ALBUM_ARTIST; + struct tag *tag = cue_current_tag(parser); if (tag != NULL) - cue_add_tag(tag, TAG_PERFORMER, p); + cue_add_tag(tag, type, p); } else if (strcmp(command, "TITLE") == 0) { if (parser->state == HEADER) cue_add_tag(parser->tag, TAG_ALBUM, p); -- cgit v1.2.3