aboutsummaryrefslogtreecommitdiffstats
path: root/src/queue
diff options
context:
space:
mode:
Diffstat (limited to 'src/queue')
-rw-r--r--src/queue/IdTable.hxx2
-rw-r--r--src/queue/Playlist.cxx86
-rw-r--r--src/queue/Playlist.hxx33
-rw-r--r--src/queue/PlaylistControl.cxx4
-rw-r--r--src/queue/PlaylistEdit.cxx4
-rw-r--r--src/queue/PlaylistState.cxx9
-rw-r--r--src/queue/PlaylistState.hxx2
-rw-r--r--src/queue/PlaylistTag.cxx2
-rw-r--r--src/queue/PlaylistUpdate.cxx2
-rw-r--r--src/queue/Queue.cxx7
-rw-r--r--src/queue/Queue.hxx5
-rw-r--r--src/queue/QueuePrint.cxx38
-rw-r--r--src/queue/QueuePrint.hxx15
-rw-r--r--src/queue/QueueSave.cxx2
-rw-r--r--src/queue/QueueSave.hxx2
15 files changed, 122 insertions, 91 deletions
diff --git a/src/queue/IdTable.hxx b/src/queue/IdTable.hxx
index 8e445243d..d1a0008fb 100644
--- a/src/queue/IdTable.hxx
+++ b/src/queue/IdTable.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/queue/Playlist.cxx b/src/queue/Playlist.cxx
index b2fd673b4..841684272 100644
--- a/src/queue/Playlist.cxx
+++ b/src/queue/Playlist.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -20,7 +20,7 @@
#include "config.h"
#include "Playlist.hxx"
#include "PlaylistError.hxx"
-#include "PlayerControl.hxx"
+#include "player/Control.hxx"
#include "DetachedSong.hxx"
#include "Idle.hxx"
#include "Log.hxx"
@@ -44,45 +44,52 @@ playlist::TagModified(DetachedSong &&song)
idle_add(IDLE_PLAYLIST);
}
-/**
- * Queue a song, addressed by its order number.
- */
-static void
-playlist_queue_song_order(playlist &playlist, PlayerControl &pc,
- unsigned order)
+inline void
+playlist::QueueSongOrder(PlayerControl &pc, unsigned order)
+
{
- assert(playlist.queue.IsValidOrder(order));
+ assert(queue.IsValidOrder(order));
- playlist.queued = order;
+ queued = order;
- const DetachedSong &song = playlist.queue.GetOrder(order);
+ const DetachedSong &song = queue.GetOrder(order);
FormatDebug(playlist_domain, "queue song %i:\"%s\"",
- playlist.queued, song.GetURI());
+ queued, song.GetURI());
pc.EnqueueSong(new DetachedSong(song));
}
-/**
- * Called if the player thread has started playing the "queued" song.
- */
-static void
-playlist_song_started(playlist &playlist, PlayerControl &pc)
+void
+playlist::SongStarted()
+{
+ assert(current >= 0);
+
+ /* reset a song's "priority" when playback starts */
+ if (queue.SetPriority(queue.OrderToPosition(current), 0, -1, false))
+ OnModified();
+}
+
+inline void
+playlist::QueuedSongStarted(PlayerControl &pc)
{
assert(pc.next_song == nullptr);
- assert(playlist.queued >= -1);
+ assert(queued >= -1);
+ assert(current >= 0);
/* queued song has started: copy queued to current,
and notify the clients */
- int current = playlist.current;
- playlist.current = playlist.queued;
- playlist.queued = -1;
+ const int old_current = current;
+ current = queued;
+ queued = -1;
- if(playlist.queue.consume)
- playlist.DeleteOrder(pc, current);
+ if (queue.consume)
+ DeleteOrder(pc, old_current);
idle_add(IDLE_PLAYER);
+
+ SongStarted();
}
const DetachedSong *
@@ -139,7 +146,7 @@ playlist::UpdateQueuedSong(PlayerControl &pc, const DetachedSong *prev)
if (next_order >= 0) {
if (next_song != prev)
- playlist_queue_song_order(*this, pc, next_order);
+ QueueSongOrder(pc, next_order);
else
queued = next_order;
}
@@ -157,10 +164,9 @@ playlist::PlayOrder(PlayerControl &pc, int order)
pc.Play(new DetachedSong(song));
current = order;
-}
-static void
-playlist_resume_playback(playlist &playlist, PlayerControl &pc);
+ SongStarted();
+}
void
playlist::SyncWithPlayer(PlayerControl &pc)
@@ -180,12 +186,12 @@ playlist::SyncWithPlayer(PlayerControl &pc)
should be restarted with the next song. That can
happen if the playlist isn't filling the queue fast
enough */
- playlist_resume_playback(*this, pc);
+ ResumePlayback(pc);
else {
/* check if the player thread has already started
playing the queued song */
if (pc_next_song == nullptr && queued != -1)
- playlist_song_started(*this, pc);
+ QueuedSongStarted(pc);
pc.Lock();
pc_next_song = pc.next_song;
@@ -198,31 +204,27 @@ playlist::SyncWithPlayer(PlayerControl &pc)
}
}
-/**
- * The player has stopped for some reason. Check the error, and
- * decide whether to re-start playback
- */
-static void
-playlist_resume_playback(playlist &playlist, PlayerControl &pc)
+inline void
+playlist::ResumePlayback(PlayerControl &pc)
{
- assert(playlist.playing);
+ assert(playing);
assert(pc.GetState() == PlayerState::STOP);
const auto error = pc.GetErrorType();
if (error == PlayerError::NONE)
- playlist.error_count = 0;
+ error_count = 0;
else
- ++playlist.error_count;
+ ++error_count;
- if ((playlist.stop_on_error && error != PlayerError::NONE) ||
+ if ((stop_on_error && error != PlayerError::NONE) ||
error == PlayerError::OUTPUT ||
- playlist.error_count >= playlist.queue.GetLength())
+ error_count >= queue.GetLength())
/* too many errors, or critical error: stop
playback */
- playlist.Stop(pc);
+ Stop(pc);
else
/* continue playback at the next song */
- playlist.PlayNext(pc);
+ PlayNext(pc);
}
void
diff --git a/src/queue/Playlist.hxx b/src/queue/Playlist.hxx
index ea19d9bba..a185a79c8 100644
--- a/src/queue/Playlist.hxx
+++ b/src/queue/Playlist.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -135,6 +135,17 @@ protected:
void OnModified();
/**
+ * Called when playback of a new song starts. Unlike
+ * QueuedSongStarted(), this also gets called when the user
+ * manually switches to another song. It may be used for
+ * playlist fixups.
+ *
+ * The song being started is specified by the #current
+ * attribute.
+ */
+ void SongStarted();
+
+ /**
* Updates the "queued song". Calculates the next song
* according to the current one (if MPD isn't playing, it
* takes the first song), and queues this song. Clears the
@@ -145,6 +156,24 @@ protected:
*/
void UpdateQueuedSong(PlayerControl &pc, const DetachedSong *prev);
+ /**
+ * Queue a song, addressed by its order number.
+ */
+ void QueueSongOrder(PlayerControl &pc, unsigned order);
+
+ /**
+ * Called when the player thread has started playing the
+ * "queued" song, i.e. it has switched from one song to the
+ * next automatically.
+ */
+ void QueuedSongStarted(PlayerControl &pc);
+
+ /**
+ * The player has stopped for some reason. Check the error,
+ * and decide whether to re-start playback.
+ */
+ void ResumePlayback(PlayerControl &pc);
+
public:
void BeginBulk();
void CommitBulk(PlayerControl &pc);
@@ -266,7 +295,7 @@ public:
* Seek within the current song. Fails if MPD is not currently
* playing.
*
- * @param time the time in seconds
+ * @param seek_time the time
* @param relative if true, then the specified time is relative to the
* current position
*/
diff --git a/src/queue/PlaylistControl.cxx b/src/queue/PlaylistControl.cxx
index f7e80dc46..f7f0a4225 100644
--- a/src/queue/PlaylistControl.cxx
+++ b/src/queue/PlaylistControl.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -25,7 +25,7 @@
#include "config.h"
#include "Playlist.hxx"
#include "PlaylistError.hxx"
-#include "PlayerControl.hxx"
+#include "player/Control.hxx"
#include "DetachedSong.hxx"
#include "Log.hxx"
diff --git a/src/queue/PlaylistEdit.cxx b/src/queue/PlaylistEdit.cxx
index 22a88dc46..0d15f6a04 100644
--- a/src/queue/PlaylistEdit.cxx
+++ b/src/queue/PlaylistEdit.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -26,7 +26,7 @@
#include "config.h"
#include "Playlist.hxx"
#include "PlaylistError.hxx"
-#include "PlayerControl.hxx"
+#include "player/Control.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
#include "DetachedSong.hxx"
diff --git a/src/queue/PlaylistState.cxx b/src/queue/PlaylistState.cxx
index 6ea86166e..fa51b1519 100644
--- a/src/queue/PlaylistState.cxx
+++ b/src/queue/PlaylistState.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -29,10 +29,9 @@
#include "queue/QueueSave.hxx"
#include "fs/io/TextFile.hxx"
#include "fs/io/BufferedOutputStream.hxx"
-#include "PlayerControl.hxx"
+#include "player/Control.hxx"
#include "config/ConfigGlobal.hxx"
#include "config/ConfigOption.hxx"
-#include "fs/Limits.hxx"
#include "util/CharUtil.hxx"
#include "util/StringUtil.hxx"
#include "Log.hxx"
@@ -57,8 +56,6 @@
#define PLAYLIST_STATE_FILE_STATE_PAUSE "pause"
#define PLAYLIST_STATE_FILE_STATE_STOP "stop"
-#define PLAYLIST_BUFFER_SIZE 2*MPD_PATH_MAX
-
void
playlist_state_save(BufferedOutputStream &os, const struct playlist &playlist,
PlayerControl &pc)
@@ -195,7 +192,7 @@ playlist_state_restore(const char *line, TextFile &file,
current = 0;
if (state == PlayerState::PLAY &&
- config_get_bool(CONF_RESTORE_PAUSED, false))
+ config_get_bool(ConfigOption::RESTORE_PAUSED, false))
/* the user doesn't want MPD to auto-start
playback after startup; fall back to
"pause" */
diff --git a/src/queue/PlaylistState.hxx b/src/queue/PlaylistState.hxx
index 3211b1178..9af9ff1f9 100644
--- a/src/queue/PlaylistState.hxx
+++ b/src/queue/PlaylistState.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/queue/PlaylistTag.cxx b/src/queue/PlaylistTag.cxx
index 556e7f4e9..69b6abae8 100644
--- a/src/queue/PlaylistTag.cxx
+++ b/src/queue/PlaylistTag.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/queue/PlaylistUpdate.cxx b/src/queue/PlaylistUpdate.cxx
index 8876711ef..9fcd2f911 100644
--- a/src/queue/PlaylistUpdate.cxx
+++ b/src/queue/PlaylistUpdate.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/queue/Queue.cxx b/src/queue/Queue.cxx
index 99b545ab1..72837e3f4 100644
--- a/src/queue/Queue.cxx
+++ b/src/queue/Queue.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -402,7 +402,8 @@ Queue::CountSamePriority(unsigned start_order, uint8_t priority) const
}
bool
-Queue::SetPriority(unsigned position, uint8_t priority, int after_order)
+Queue::SetPriority(unsigned position, uint8_t priority, int after_order,
+ bool reorder)
{
assert(position < length);
@@ -414,7 +415,7 @@ Queue::SetPriority(unsigned position, uint8_t priority, int after_order)
item->version = version;
item->priority = priority;
- if (!random)
+ if (!random || !reorder)
/* don't reorder if not in random mode */
return true;
diff --git a/src/queue/Queue.hxx b/src/queue/Queue.hxx
index 016619e65..770357e3a 100644
--- a/src/queue/Queue.hxx
+++ b/src/queue/Queue.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -343,7 +343,8 @@ struct Queue {
*/
void ShuffleRange(unsigned start, unsigned end);
- bool SetPriority(unsigned position, uint8_t priority, int after_order);
+ bool SetPriority(unsigned position, uint8_t priority, int after_order,
+ bool reorder=true);
bool SetPriorityRange(unsigned start_position, unsigned end_position,
uint8_t priority, int after_order);
diff --git a/src/queue/QueuePrint.cxx b/src/queue/QueuePrint.cxx
index 831ecafb9..5ae1a3036 100644
--- a/src/queue/QueuePrint.cxx
+++ b/src/queue/QueuePrint.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -22,7 +22,7 @@
#include "Queue.hxx"
#include "SongFilter.hxx"
#include "SongPrint.hxx"
-#include "client/Client.hxx"
+#include "client/Response.hxx"
/**
* Send detailed information about a range of songs in the queue to a
@@ -33,70 +33,70 @@
* @param end the index of the last song (excluding)
*/
static void
-queue_print_song_info(Client &client, const Queue &queue,
+queue_print_song_info(Response &r, Partition &partition, const Queue &queue,
unsigned position)
{
- song_print_info(client, queue.Get(position));
- client_printf(client, "Pos: %u\nId: %u\n",
- position, queue.PositionToId(position));
+ song_print_info(r, partition, queue.Get(position));
+ r.Format("Pos: %u\nId: %u\n",
+ position, queue.PositionToId(position));
uint8_t priority = queue.GetPriorityAtPosition(position);
if (priority != 0)
- client_printf(client, "Prio: %u\n", priority);
+ r.Format("Prio: %u\n", priority);
}
void
-queue_print_info(Client &client, const Queue &queue,
+queue_print_info(Response &r, Partition &partition, const Queue &queue,
unsigned start, unsigned end)
{
assert(start <= end);
assert(end <= queue.GetLength());
for (unsigned i = start; i < end; ++i)
- queue_print_song_info(client, queue, i);
+ queue_print_song_info(r, partition, queue, i);
}
void
-queue_print_uris(Client &client, const Queue &queue,
+queue_print_uris(Response &r, Partition &partition, const Queue &queue,
unsigned start, unsigned end)
{
assert(start <= end);
assert(end <= queue.GetLength());
for (unsigned i = start; i < end; ++i) {
- client_printf(client, "%i:", i);
- song_print_uri(client, queue.Get(i));
+ r.Format("%i:", i);
+ song_print_uri(r, partition, queue.Get(i));
}
}
void
-queue_print_changes_info(Client &client, const Queue &queue,
+queue_print_changes_info(Response &r, Partition &partition, const Queue &queue,
uint32_t version)
{
for (unsigned i = 0; i < queue.GetLength(); i++) {
if (queue.IsNewerAtPosition(i, version))
- queue_print_song_info(client, queue, i);
+ queue_print_song_info(r, partition, queue, i);
}
}
void
-queue_print_changes_position(Client &client, const Queue &queue,
+queue_print_changes_position(Response &r, const Queue &queue,
uint32_t version)
{
for (unsigned i = 0; i < queue.GetLength(); i++)
if (queue.IsNewerAtPosition(i, version))
- client_printf(client, "cpos: %i\nId: %i\n",
- i, queue.PositionToId(i));
+ r.Format("cpos: %i\nId: %i\n",
+ i, queue.PositionToId(i));
}
void
-queue_find(Client &client, const Queue &queue,
+queue_find(Response &r, Partition &partition, const Queue &queue,
const SongFilter &filter)
{
for (unsigned i = 0; i < queue.GetLength(); i++) {
const DetachedSong &song = queue.Get(i);
if (filter.Match(song))
- queue_print_song_info(client, queue, i);
+ queue_print_song_info(r, partition, queue, i);
}
}
diff --git a/src/queue/QueuePrint.hxx b/src/queue/QueuePrint.hxx
index 1aa876219..88d28e8ca 100644
--- a/src/queue/QueuePrint.hxx
+++ b/src/queue/QueuePrint.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -28,27 +28,28 @@
#include <stdint.h>
struct Queue;
+struct Partition;
class SongFilter;
-class Client;
+class Response;
void
-queue_print_info(Client &client, const Queue &queue,
+queue_print_info(Response &r, Partition &partition, const Queue &queue,
unsigned start, unsigned end);
void
-queue_print_uris(Client &client, const Queue &queue,
+queue_print_uris(Response &r, Partition &partition, const Queue &queue,
unsigned start, unsigned end);
void
-queue_print_changes_info(Client &client, const Queue &queue,
+queue_print_changes_info(Response &r, Partition &partition, const Queue &queue,
uint32_t version);
void
-queue_print_changes_position(Client &client, const Queue &queue,
+queue_print_changes_position(Response &r, const Queue &queue,
uint32_t version);
void
-queue_find(Client &client, const Queue &queue,
+queue_find(Response &response, Partition &partition, const Queue &queue,
const SongFilter &filter);
#endif
diff --git a/src/queue/QueueSave.cxx b/src/queue/QueueSave.cxx
index bc2702572..f5c49549e 100644
--- a/src/queue/QueueSave.cxx
+++ b/src/queue/QueueSave.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/queue/QueueSave.hxx b/src/queue/QueueSave.hxx
index 3fb4dc1a6..3eeacb418 100644
--- a/src/queue/QueueSave.hxx
+++ b/src/queue/QueueSave.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify