Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
8bb5a565
Commit
8bb5a565
authored
Dec 18, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PlaylistError: add exception class wrapping enum PlaylistResult
parent
7562c575
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
124 additions
and
126 deletions
+124
-126
Partition.hxx
src/Partition.hxx
+24
-27
PlaylistError.hxx
src/PlaylistError.hxx
+24
-0
CommandError.cxx
src/command/CommandError.cxx
+2
-0
PlayerCommands.cxx
src/command/PlayerCommands.cxx
+4
-4
QueueCommands.cxx
src/command/QueueCommands.cxx
+17
-25
Playlist.hxx
src/queue/Playlist.hxx
+15
-21
PlaylistControl.cxx
src/queue/PlaylistControl.cxx
+10
-9
PlaylistEdit.cxx
src/queue/PlaylistEdit.cxx
+28
-40
No files found.
src/Partition.hxx
View file @
8bb5a565
...
@@ -63,12 +63,12 @@ struct Partition final : private PlayerListener, private MixerListener {
...
@@ -63,12 +63,12 @@ struct Partition final : private PlayerListener, private MixerListener {
return
playlist
.
AppendURI
(
pc
,
loader
,
uri_utf8
,
error
);
return
playlist
.
AppendURI
(
pc
,
loader
,
uri_utf8
,
error
);
}
}
PlaylistResult
DeletePosition
(
unsigned
position
)
{
void
DeletePosition
(
unsigned
position
)
{
return
playlist
.
DeletePosition
(
pc
,
position
);
playlist
.
DeletePosition
(
pc
,
position
);
}
}
PlaylistResult
DeleteId
(
unsigned
id
)
{
void
DeleteId
(
unsigned
id
)
{
return
playlist
.
DeleteId
(
pc
,
id
);
playlist
.
DeleteId
(
pc
,
id
);
}
}
/**
/**
...
@@ -77,8 +77,8 @@ struct Partition final : private PlayerListener, private MixerListener {
...
@@ -77,8 +77,8 @@ struct Partition final : private PlayerListener, private MixerListener {
* @param start the position of the first song to delete
* @param start the position of the first song to delete
* @param end the position after the last song to delete
* @param end the position after the last song to delete
*/
*/
PlaylistResult
DeleteRange
(
unsigned
start
,
unsigned
end
)
{
void
DeleteRange
(
unsigned
start
,
unsigned
end
)
{
return
playlist
.
DeleteRange
(
pc
,
start
,
end
);
playlist
.
DeleteRange
(
pc
,
start
,
end
);
}
}
#ifdef ENABLE_DATABASE
#ifdef ENABLE_DATABASE
...
@@ -93,53 +93,50 @@ struct Partition final : private PlayerListener, private MixerListener {
...
@@ -93,53 +93,50 @@ struct Partition final : private PlayerListener, private MixerListener {
playlist
.
Shuffle
(
pc
,
start
,
end
);
playlist
.
Shuffle
(
pc
,
start
,
end
);
}
}
PlaylistResult
MoveRange
(
unsigned
start
,
unsigned
end
,
int
to
)
{
void
MoveRange
(
unsigned
start
,
unsigned
end
,
int
to
)
{
return
playlist
.
MoveRange
(
pc
,
start
,
end
,
to
);
playlist
.
MoveRange
(
pc
,
start
,
end
,
to
);
}
}
PlaylistResult
MoveId
(
unsigned
id
,
int
to
)
{
void
MoveId
(
unsigned
id
,
int
to
)
{
return
playlist
.
MoveId
(
pc
,
id
,
to
);
playlist
.
MoveId
(
pc
,
id
,
to
);
}
}
PlaylistResult
SwapPositions
(
unsigned
song1
,
unsigned
song2
)
{
void
SwapPositions
(
unsigned
song1
,
unsigned
song2
)
{
return
playlist
.
SwapPositions
(
pc
,
song1
,
song2
);
playlist
.
SwapPositions
(
pc
,
song1
,
song2
);
}
}
PlaylistResult
SwapIds
(
unsigned
id1
,
unsigned
id2
)
{
void
SwapIds
(
unsigned
id1
,
unsigned
id2
)
{
return
playlist
.
SwapIds
(
pc
,
id1
,
id2
);
playlist
.
SwapIds
(
pc
,
id1
,
id2
);
}
}
PlaylistResult
SetPriorityRange
(
unsigned
start_position
,
void
SetPriorityRange
(
unsigned
start_position
,
unsigned
end_position
,
unsigned
end_position
,
uint8_t
priority
)
{
uint8_t
priority
)
{
return
playlist
.
SetPriorityRange
(
pc
,
playlist
.
SetPriorityRange
(
pc
,
start_position
,
end_position
,
start_position
,
end_position
,
priority
);
priority
);
}
}
PlaylistResult
SetPriorityId
(
unsigned
song_id
,
void
SetPriorityId
(
unsigned
song_id
,
uint8_t
priority
)
{
uint8_t
priority
)
{
playlist
.
SetPriorityId
(
pc
,
song_id
,
priority
);
return
playlist
.
SetPriorityId
(
pc
,
song_id
,
priority
);
}
}
void
Stop
()
{
void
Stop
()
{
playlist
.
Stop
(
pc
);
playlist
.
Stop
(
pc
);
}
}
PlaylistResult
PlayPosition
(
int
position
)
{
void
PlayPosition
(
int
position
)
{
return
playlist
.
PlayPosition
(
pc
,
position
);
playlist
.
PlayPosition
(
pc
,
position
);
}
}
PlaylistResult
PlayId
(
int
id
)
{
void
PlayId
(
int
id
)
{
return
playlist
.
PlayId
(
pc
,
id
);
playlist
.
PlayId
(
pc
,
id
);
}
}
void
PlayNext
()
{
void
PlayNext
()
{
return
playlist
.
PlayNext
(
pc
);
playlist
.
PlayNext
(
pc
);
}
}
void
PlayPrevious
()
{
void
PlayPrevious
()
{
return
playlist
.
PlayPrevious
(
pc
);
playlist
.
PlayPrevious
(
pc
);
}
}
bool
SeekSongPosition
(
unsigned
song_position
,
bool
SeekSongPosition
(
unsigned
song_position
,
...
...
src/PlaylistError.hxx
View file @
8bb5a565
...
@@ -20,6 +20,8 @@
...
@@ -20,6 +20,8 @@
#ifndef MPD_PLAYLIST_ERROR_HXX
#ifndef MPD_PLAYLIST_ERROR_HXX
#define MPD_PLAYLIST_ERROR_HXX
#define MPD_PLAYLIST_ERROR_HXX
#include <stdexcept>
class
Domain
;
class
Domain
;
enum
class
PlaylistResult
{
enum
class
PlaylistResult
{
...
@@ -37,4 +39,26 @@ enum class PlaylistResult {
...
@@ -37,4 +39,26 @@ enum class PlaylistResult {
extern
const
Domain
playlist_domain
;
extern
const
Domain
playlist_domain
;
class
PlaylistError
:
public
std
::
runtime_error
{
PlaylistResult
code
;
public
:
PlaylistError
(
PlaylistResult
_code
,
const
char
*
msg
)
:
std
::
runtime_error
(
msg
),
code
(
_code
)
{}
PlaylistResult
GetCode
()
const
{
return
code
;
}
static
PlaylistError
NoSuchSong
()
{
return
PlaylistError
(
PlaylistResult
::
BAD_RANGE
,
"No such song"
);
}
static
PlaylistError
BadRange
()
{
return
PlaylistError
(
PlaylistResult
::
BAD_RANGE
,
"Bad song index"
);
}
};
#endif
#endif
src/command/CommandError.cxx
View file @
8bb5a565
...
@@ -165,6 +165,8 @@ PrintError(Response &r, const std::exception &e)
...
@@ -165,6 +165,8 @@ PrintError(Response &r, const std::exception &e)
try
{
try
{
throw
e
;
throw
e
;
}
catch
(
const
PlaylistError
&
pe
)
{
r
.
Error
(
ToAck
(
pe
.
GetCode
()),
pe
.
what
());
}
catch
(
const
std
::
system_error
&
)
{
}
catch
(
const
std
::
system_error
&
)
{
r
.
Error
(
ACK_ERROR_SYSTEM
,
e
.
what
());
r
.
Error
(
ACK_ERROR_SYSTEM
,
e
.
what
());
}
catch
(...)
{
}
catch
(...)
{
...
...
src/command/PlayerCommands.cxx
View file @
8bb5a565
...
@@ -63,8 +63,8 @@ handle_play(Client &client, Request args, Response &r)
...
@@ -63,8 +63,8 @@ handle_play(Client &client, Request args, Response &r)
if
(
!
args
.
ParseOptional
(
0
,
song
,
r
))
if
(
!
args
.
ParseOptional
(
0
,
song
,
r
))
return
CommandResult
::
ERROR
;
return
CommandResult
::
ERROR
;
PlaylistResult
result
=
client
.
partition
.
PlayPosition
(
song
);
client
.
partition
.
PlayPosition
(
song
);
return
print_playlist_result
(
r
,
result
)
;
return
CommandResult
::
OK
;
}
}
CommandResult
CommandResult
...
@@ -74,8 +74,8 @@ handle_playid(Client &client, Request args, Response &r)
...
@@ -74,8 +74,8 @@ handle_playid(Client &client, Request args, Response &r)
if
(
!
args
.
ParseOptional
(
0
,
id
,
r
))
if
(
!
args
.
ParseOptional
(
0
,
id
,
r
))
return
CommandResult
::
ERROR
;
return
CommandResult
::
ERROR
;
PlaylistResult
result
=
client
.
partition
.
PlayId
(
id
);
client
.
partition
.
PlayId
(
id
);
return
print_playlist_result
(
r
,
result
)
;
return
CommandResult
::
OK
;
}
}
CommandResult
CommandResult
...
...
src/command/QueueCommands.cxx
View file @
8bb5a565
...
@@ -132,12 +132,13 @@ handle_addid(Client &client, Request args, Response &r)
...
@@ -132,12 +132,13 @@ handle_addid(Client &client, Request args, Response &r)
if
(
!
args
.
Parse
(
1
,
to
,
r
))
if
(
!
args
.
Parse
(
1
,
to
,
r
))
return
CommandResult
::
ERROR
;
return
CommandResult
::
ERROR
;
PlaylistResult
result
=
client
.
partition
.
MoveId
(
added_id
,
to
);
try
{
if
(
result
!=
PlaylistResult
::
SUCCESS
)
{
client
.
partition
.
MoveId
(
added_id
,
to
);
CommandResult
ret
=
return
CommandResult
::
OK
;
print_playlist_result
(
r
,
result
);
}
catch
(...)
{
/* rollback */
client
.
partition
.
DeleteId
(
added_id
);
client
.
partition
.
DeleteId
(
added_id
);
return
ret
;
throw
;
}
}
}
}
...
@@ -205,8 +206,8 @@ handle_delete(Client &client, Request args, Response &r)
...
@@ -205,8 +206,8 @@ handle_delete(Client &client, Request args, Response &r)
if
(
!
args
.
Parse
(
0
,
range
,
r
))
if
(
!
args
.
Parse
(
0
,
range
,
r
))
return
CommandResult
::
ERROR
;
return
CommandResult
::
ERROR
;
auto
result
=
client
.
partition
.
DeleteRange
(
range
.
start
,
range
.
end
);
client
.
partition
.
DeleteRange
(
range
.
start
,
range
.
end
);
return
print_playlist_result
(
r
,
result
)
;
return
CommandResult
::
OK
;
}
}
CommandResult
CommandResult
...
@@ -216,8 +217,8 @@ handle_deleteid(Client &client, Request args, Response &r)
...
@@ -216,8 +217,8 @@ handle_deleteid(Client &client, Request args, Response &r)
if
(
!
args
.
Parse
(
0
,
id
,
r
))
if
(
!
args
.
Parse
(
0
,
id
,
r
))
return
CommandResult
::
ERROR
;
return
CommandResult
::
ERROR
;
PlaylistResult
result
=
client
.
partition
.
DeleteId
(
id
);
client
.
partition
.
DeleteId
(
id
);
return
print_playlist_result
(
r
,
result
)
;
return
CommandResult
::
OK
;
}
}
CommandResult
CommandResult
...
@@ -351,12 +352,8 @@ handle_prio(Client &client, Request args, Response &r)
...
@@ -351,12 +352,8 @@ handle_prio(Client &client, Request args, Response &r)
if
(
!
ParseCommandArg
(
r
,
range
,
i
))
if
(
!
ParseCommandArg
(
r
,
range
,
i
))
return
CommandResult
::
ERROR
;
return
CommandResult
::
ERROR
;
PlaylistResult
result
=
client
.
partition
.
SetPriorityRange
(
range
.
start
,
range
.
end
,
client
.
partition
.
SetPriorityRange
(
range
.
start
,
range
.
end
,
priority
);
priority
);
if
(
result
!=
PlaylistResult
::
SUCCESS
)
return
print_playlist_result
(
r
,
result
);
}
}
return
CommandResult
::
OK
;
return
CommandResult
::
OK
;
...
@@ -374,10 +371,7 @@ handle_prioid(Client &client, Request args, Response &r)
...
@@ -374,10 +371,7 @@ handle_prioid(Client &client, Request args, Response &r)
if
(
!
ParseCommandArg
(
r
,
song_id
,
i
))
if
(
!
ParseCommandArg
(
r
,
song_id
,
i
))
return
CommandResult
::
ERROR
;
return
CommandResult
::
ERROR
;
PlaylistResult
result
=
client
.
partition
.
SetPriorityId
(
song_id
,
priority
);
client
.
partition
.
SetPriorityId
(
song_id
,
priority
);
if
(
result
!=
PlaylistResult
::
SUCCESS
)
return
print_playlist_result
(
r
,
result
);
}
}
return
CommandResult
::
OK
;
return
CommandResult
::
OK
;
...
@@ -392,9 +386,8 @@ handle_move(Client &client, Request args, Response &r)
...
@@ -392,9 +386,8 @@ handle_move(Client &client, Request args, Response &r)
if
(
!
args
.
Parse
(
0
,
range
,
r
)
||
!
args
.
Parse
(
1
,
to
,
r
))
if
(
!
args
.
Parse
(
0
,
range
,
r
)
||
!
args
.
Parse
(
1
,
to
,
r
))
return
CommandResult
::
ERROR
;
return
CommandResult
::
ERROR
;
PlaylistResult
result
=
client
.
partition
.
MoveRange
(
range
.
start
,
range
.
end
,
to
);
client
.
partition
.
MoveRange
(
range
.
start
,
range
.
end
,
to
);
return
print_playlist_result
(
r
,
result
)
;
return
CommandResult
::
OK
;
}
}
CommandResult
CommandResult
...
@@ -405,8 +398,8 @@ handle_moveid(Client &client, Request args, Response &r)
...
@@ -405,8 +398,8 @@ handle_moveid(Client &client, Request args, Response &r)
if
(
!
args
.
Parse
(
0
,
id
,
r
)
||
!
args
.
Parse
(
1
,
to
,
r
))
if
(
!
args
.
Parse
(
0
,
id
,
r
)
||
!
args
.
Parse
(
1
,
to
,
r
))
return
CommandResult
::
ERROR
;
return
CommandResult
::
ERROR
;
PlaylistResult
result
=
client
.
partition
.
MoveId
(
id
,
to
);
client
.
partition
.
MoveId
(
id
,
to
);
return
print_playlist_result
(
r
,
result
)
;
return
CommandResult
::
OK
;
}
}
CommandResult
CommandResult
...
@@ -416,9 +409,8 @@ handle_swap(Client &client, Request args, Response &r)
...
@@ -416,9 +409,8 @@ handle_swap(Client &client, Request args, Response &r)
if
(
!
args
.
Parse
(
0
,
song1
,
r
)
||
!
args
.
Parse
(
1
,
song2
,
r
))
if
(
!
args
.
Parse
(
0
,
song1
,
r
)
||
!
args
.
Parse
(
1
,
song2
,
r
))
return
CommandResult
::
ERROR
;
return
CommandResult
::
ERROR
;
PlaylistResult
result
=
client
.
partition
.
SwapPositions
(
song1
,
song2
);
client
.
partition
.
SwapPositions
(
song1
,
song2
);
return
print_playlist_result
(
r
,
result
)
;
return
CommandResult
::
OK
;
}
}
CommandResult
CommandResult
...
@@ -428,6 +420,6 @@ handle_swapid(Client &client, Request args, Response &r)
...
@@ -428,6 +420,6 @@ handle_swapid(Client &client, Request args, Response &r)
if
(
!
args
.
Parse
(
0
,
id1
,
r
)
||
!
args
.
Parse
(
1
,
id2
,
r
))
if
(
!
args
.
Parse
(
0
,
id1
,
r
)
||
!
args
.
Parse
(
1
,
id2
,
r
))
return
CommandResult
::
ERROR
;
return
CommandResult
::
ERROR
;
PlaylistResult
result
=
client
.
partition
.
SwapIds
(
id1
,
id2
);
client
.
partition
.
SwapIds
(
id1
,
id2
);
return
print_playlist_result
(
r
,
result
)
;
return
CommandResult
::
OK
;
}
}
src/queue/Playlist.hxx
View file @
8bb5a565
...
@@ -214,15 +214,13 @@ protected:
...
@@ -214,15 +214,13 @@ protected:
unsigned
song
,
const
DetachedSong
**
queued_p
);
unsigned
song
,
const
DetachedSong
**
queued_p
);
public
:
public
:
PlaylistResult
DeletePosition
(
PlayerControl
&
pc
,
void
DeletePosition
(
PlayerControl
&
pc
,
unsigned
position
);
unsigned
position
);
PlaylistResult
DeleteOrder
(
PlayerControl
&
pc
,
void
DeleteOrder
(
PlayerControl
&
pc
,
unsigned
order
)
{
unsigned
order
)
{
DeletePosition
(
pc
,
queue
.
OrderToPosition
(
order
));
return
DeletePosition
(
pc
,
queue
.
OrderToPosition
(
order
));
}
}
PlaylistResult
DeleteId
(
PlayerControl
&
pc
,
unsigned
id
);
void
DeleteId
(
PlayerControl
&
pc
,
unsigned
id
);
/**
/**
* Deletes a range of songs from the playlist.
* Deletes a range of songs from the playlist.
...
@@ -230,30 +228,26 @@ public:
...
@@ -230,30 +228,26 @@ public:
* @param start the position of the first song to delete
* @param start the position of the first song to delete
* @param end the position after the last song to delete
* @param end the position after the last song to delete
*/
*/
PlaylistResult
DeleteRange
(
PlayerControl
&
pc
,
void
DeleteRange
(
PlayerControl
&
pc
,
unsigned
start
,
unsigned
end
);
unsigned
start
,
unsigned
end
);
void
DeleteSong
(
PlayerControl
&
pc
,
const
char
*
uri
);
void
DeleteSong
(
PlayerControl
&
pc
,
const
char
*
uri
);
void
Shuffle
(
PlayerControl
&
pc
,
unsigned
start
,
unsigned
end
);
void
Shuffle
(
PlayerControl
&
pc
,
unsigned
start
,
unsigned
end
);
PlaylistResult
MoveRange
(
PlayerControl
&
pc
,
void
MoveRange
(
PlayerControl
&
pc
,
unsigned
start
,
unsigned
start
,
unsigned
end
,
int
to
);
unsigned
end
,
int
to
);
PlaylistResult
MoveId
(
PlayerControl
&
pc
,
unsigned
id
,
int
to
);
void
MoveId
(
PlayerControl
&
pc
,
unsigned
id
,
int
to
);
PlaylistResult
SwapPositions
(
PlayerControl
&
pc
,
void
SwapPositions
(
PlayerControl
&
pc
,
unsigned
song1
,
unsigned
song2
);
unsigned
song1
,
unsigned
song2
);
PlaylistResult
SwapIds
(
PlayerControl
&
pc
,
void
SwapIds
(
PlayerControl
&
pc
,
unsigned
id1
,
unsigned
id2
);
unsigned
id1
,
unsigned
id2
);
PlaylistResult
SetPriorityRange
(
PlayerControl
&
pc
,
void
SetPriorityRange
(
PlayerControl
&
pc
,
unsigned
start_position
,
unsigned
start_position
,
unsigned
end_position
,
unsigned
end_position
,
uint8_t
priority
);
uint8_t
priority
);
PlaylistResult
SetPriorityId
(
PlayerControl
&
pc
,
void
SetPriorityId
(
PlayerControl
&
pc
,
unsigned
song_id
,
uint8_t
priority
);
unsigned
song_id
,
uint8_t
priority
);
/**
/**
...
@@ -270,11 +264,11 @@ public:
...
@@ -270,11 +264,11 @@ public:
void
Stop
(
PlayerControl
&
pc
);
void
Stop
(
PlayerControl
&
pc
);
PlaylistResult
PlayPosition
(
PlayerControl
&
pc
,
int
position
);
void
PlayPosition
(
PlayerControl
&
pc
,
int
position
);
void
PlayOrder
(
PlayerControl
&
pc
,
int
order
);
void
PlayOrder
(
PlayerControl
&
pc
,
int
order
);
PlaylistResult
PlayId
(
PlayerControl
&
pc
,
int
id
);
void
PlayId
(
PlayerControl
&
pc
,
int
id
);
void
PlayNext
(
PlayerControl
&
pc
);
void
PlayNext
(
PlayerControl
&
pc
);
...
...
src/queue/PlaylistControl.cxx
View file @
8bb5a565
...
@@ -56,7 +56,7 @@ playlist::Stop(PlayerControl &pc)
...
@@ -56,7 +56,7 @@ playlist::Stop(PlayerControl &pc)
}
}
}
}
PlaylistResult
void
playlist
::
PlayPosition
(
PlayerControl
&
pc
,
int
song
)
playlist
::
PlayPosition
(
PlayerControl
&
pc
,
int
song
)
{
{
pc
.
LockClearError
();
pc
.
LockClearError
();
...
@@ -66,13 +66,13 @@ playlist::PlayPosition(PlayerControl &pc, int song)
...
@@ -66,13 +66,13 @@ playlist::PlayPosition(PlayerControl &pc, int song)
/* play any song ("current" song, or the first song */
/* play any song ("current" song, or the first song */
if
(
queue
.
IsEmpty
())
if
(
queue
.
IsEmpty
())
return
PlaylistResult
::
SUCCESS
;
return
;
if
(
playing
)
{
if
(
playing
)
{
/* already playing: unpause playback, just in
/* already playing: unpause playback, just in
case it was paused, and return */
case it was paused, and return */
pc
.
LockSetPause
(
false
);
pc
.
LockSetPause
(
false
);
return
PlaylistResult
::
SUCCESS
;
return
;
}
}
/* select a song: "current" song, or the first one */
/* select a song: "current" song, or the first one */
...
@@ -80,7 +80,7 @@ playlist::PlayPosition(PlayerControl &pc, int song)
...
@@ -80,7 +80,7 @@ playlist::PlayPosition(PlayerControl &pc, int song)
?
current
?
current
:
0
;
:
0
;
}
else
if
(
!
queue
.
IsValidPosition
(
song
))
}
else
if
(
!
queue
.
IsValidPosition
(
song
))
return
PlaylistResult
::
BAD_RANGE
;
throw
PlaylistError
::
BadRange
()
;
if
(
queue
.
random
)
{
if
(
queue
.
random
)
{
if
(
song
>=
0
)
if
(
song
>=
0
)
...
@@ -103,18 +103,19 @@ playlist::PlayPosition(PlayerControl &pc, int song)
...
@@ -103,18 +103,19 @@ playlist::PlayPosition(PlayerControl &pc, int song)
error_count
=
0
;
error_count
=
0
;
PlayOrder
(
pc
,
i
);
PlayOrder
(
pc
,
i
);
return
PlaylistResult
::
SUCCESS
;
}
}
PlaylistResult
void
playlist
::
PlayId
(
PlayerControl
&
pc
,
int
id
)
playlist
::
PlayId
(
PlayerControl
&
pc
,
int
id
)
{
{
if
(
id
==
-
1
)
if
(
id
==
-
1
)
{
return
PlayPosition
(
pc
,
id
);
PlayPosition
(
pc
,
id
);
return
;
}
int
song
=
queue
.
IdToPosition
(
id
);
int
song
=
queue
.
IdToPosition
(
id
);
if
(
song
<
0
)
if
(
song
<
0
)
return
PlaylistResult
::
NO_SUCH_SONG
;
throw
PlaylistError
::
NoSuchSong
()
;
return
PlayPosition
(
pc
,
song
);
return
PlayPosition
(
pc
,
song
);
}
}
...
...
src/queue/PlaylistEdit.cxx
View file @
8bb5a565
...
@@ -138,11 +138,11 @@ playlist::AppendURI(PlayerControl &pc, const SongLoader &loader,
...
@@ -138,11 +138,11 @@ playlist::AppendURI(PlayerControl &pc, const SongLoader &loader,
return
result
;
return
result
;
}
}
PlaylistResult
void
playlist
::
SwapPositions
(
PlayerControl
&
pc
,
unsigned
song1
,
unsigned
song2
)
playlist
::
SwapPositions
(
PlayerControl
&
pc
,
unsigned
song1
,
unsigned
song2
)
{
{
if
(
!
queue
.
IsValidPosition
(
song1
)
||
!
queue
.
IsValidPosition
(
song2
))
if
(
!
queue
.
IsValidPosition
(
song1
)
||
!
queue
.
IsValidPosition
(
song2
))
return
PlaylistResult
::
BAD_RANGE
;
throw
PlaylistError
::
BadRange
()
;
const
DetachedSong
*
const
queued_song
=
GetQueuedSong
();
const
DetachedSong
*
const
queued_song
=
GetQueuedSong
();
...
@@ -165,35 +165,33 @@ playlist::SwapPositions(PlayerControl &pc, unsigned song1, unsigned song2)
...
@@ -165,35 +165,33 @@ playlist::SwapPositions(PlayerControl &pc, unsigned song1, unsigned song2)
UpdateQueuedSong
(
pc
,
queued_song
);
UpdateQueuedSong
(
pc
,
queued_song
);
OnModified
();
OnModified
();
return
PlaylistResult
::
SUCCESS
;
}
}
PlaylistResult
void
playlist
::
SwapIds
(
PlayerControl
&
pc
,
unsigned
id1
,
unsigned
id2
)
playlist
::
SwapIds
(
PlayerControl
&
pc
,
unsigned
id1
,
unsigned
id2
)
{
{
int
song1
=
queue
.
IdToPosition
(
id1
);
int
song1
=
queue
.
IdToPosition
(
id1
);
int
song2
=
queue
.
IdToPosition
(
id2
);
int
song2
=
queue
.
IdToPosition
(
id2
);
if
(
song1
<
0
||
song2
<
0
)
if
(
song1
<
0
||
song2
<
0
)
return
PlaylistResult
::
NO_SUCH_SONG
;
throw
PlaylistError
::
NoSuchSong
()
;
return
SwapPositions
(
pc
,
song1
,
song2
);
SwapPositions
(
pc
,
song1
,
song2
);
}
}
PlaylistResult
void
playlist
::
SetPriorityRange
(
PlayerControl
&
pc
,
playlist
::
SetPriorityRange
(
PlayerControl
&
pc
,
unsigned
start
,
unsigned
end
,
unsigned
start
,
unsigned
end
,
uint8_t
priority
)
uint8_t
priority
)
{
{
if
(
start
>=
GetLength
())
if
(
start
>=
GetLength
())
return
PlaylistResult
::
BAD_RANGE
;
throw
PlaylistError
::
BadRange
()
;
if
(
end
>
GetLength
())
if
(
end
>
GetLength
())
end
=
GetLength
();
end
=
GetLength
();
if
(
start
>=
end
)
if
(
start
>=
end
)
return
PlaylistResult
::
SUCCESS
;
return
;
/* remember "current" and "queued" */
/* remember "current" and "queued" */
...
@@ -211,21 +209,17 @@ playlist::SetPriorityRange(PlayerControl &pc,
...
@@ -211,21 +209,17 @@ playlist::SetPriorityRange(PlayerControl &pc,
UpdateQueuedSong
(
pc
,
queued_song
);
UpdateQueuedSong
(
pc
,
queued_song
);
OnModified
();
OnModified
();
return
PlaylistResult
::
SUCCESS
;
}
}
PlaylistResult
void
playlist
::
SetPriorityId
(
PlayerControl
&
pc
,
playlist
::
SetPriorityId
(
PlayerControl
&
pc
,
unsigned
song_id
,
uint8_t
priority
)
unsigned
song_id
,
uint8_t
priority
)
{
{
int
song_position
=
queue
.
IdToPosition
(
song_id
);
int
song_position
=
queue
.
IdToPosition
(
song_id
);
if
(
song_position
<
0
)
if
(
song_position
<
0
)
return
PlaylistResult
::
NO_SUCH_SONG
;
throw
PlaylistError
::
NoSuchSong
();
return
SetPriorityRange
(
pc
,
song_position
,
song_position
+
1
,
priority
);
SetPriorityRange
(
pc
,
song_position
,
song_position
+
1
,
priority
);
}
}
void
void
...
@@ -272,11 +266,11 @@ playlist::DeleteInternal(PlayerControl &pc,
...
@@ -272,11 +266,11 @@ playlist::DeleteInternal(PlayerControl &pc,
current
--
;
current
--
;
}
}
PlaylistResult
void
playlist
::
DeletePosition
(
PlayerControl
&
pc
,
unsigned
song
)
playlist
::
DeletePosition
(
PlayerControl
&
pc
,
unsigned
song
)
{
{
if
(
song
>=
queue
.
GetLength
())
if
(
song
>=
queue
.
GetLength
())
return
PlaylistResult
::
BAD_RANGE
;
throw
PlaylistError
::
BadRange
()
;
const
DetachedSong
*
queued_song
=
GetQueuedSong
();
const
DetachedSong
*
queued_song
=
GetQueuedSong
();
...
@@ -284,21 +278,19 @@ playlist::DeletePosition(PlayerControl &pc, unsigned song)
...
@@ -284,21 +278,19 @@ playlist::DeletePosition(PlayerControl &pc, unsigned song)
UpdateQueuedSong
(
pc
,
queued_song
);
UpdateQueuedSong
(
pc
,
queued_song
);
OnModified
();
OnModified
();
return
PlaylistResult
::
SUCCESS
;
}
}
PlaylistResult
void
playlist
::
DeleteRange
(
PlayerControl
&
pc
,
unsigned
start
,
unsigned
end
)
playlist
::
DeleteRange
(
PlayerControl
&
pc
,
unsigned
start
,
unsigned
end
)
{
{
if
(
start
>=
queue
.
GetLength
())
if
(
start
>=
queue
.
GetLength
())
return
PlaylistResult
::
BAD_RANGE
;
throw
PlaylistError
::
BadRange
()
;
if
(
end
>
queue
.
GetLength
())
if
(
end
>
queue
.
GetLength
())
end
=
queue
.
GetLength
();
end
=
queue
.
GetLength
();
if
(
start
>=
end
)
if
(
start
>=
end
)
return
PlaylistResult
::
SUCCESS
;
return
;
const
DetachedSong
*
queued_song
=
GetQueuedSong
();
const
DetachedSong
*
queued_song
=
GetQueuedSong
();
...
@@ -308,18 +300,16 @@ playlist::DeleteRange(PlayerControl &pc, unsigned start, unsigned end)
...
@@ -308,18 +300,16 @@ playlist::DeleteRange(PlayerControl &pc, unsigned start, unsigned end)
UpdateQueuedSong
(
pc
,
queued_song
);
UpdateQueuedSong
(
pc
,
queued_song
);
OnModified
();
OnModified
();
return
PlaylistResult
::
SUCCESS
;
}
}
PlaylistResult
void
playlist
::
DeleteId
(
PlayerControl
&
pc
,
unsigned
id
)
playlist
::
DeleteId
(
PlayerControl
&
pc
,
unsigned
id
)
{
{
int
song
=
queue
.
IdToPosition
(
id
);
int
song
=
queue
.
IdToPosition
(
id
);
if
(
song
<
0
)
if
(
song
<
0
)
return
PlaylistResult
::
NO_SUCH_SONG
;
throw
PlaylistError
::
NoSuchSong
()
;
return
DeletePosition
(
pc
,
song
);
DeletePosition
(
pc
,
song
);
}
}
void
void
...
@@ -330,19 +320,19 @@ playlist::DeleteSong(PlayerControl &pc, const char *uri)
...
@@ -330,19 +320,19 @@ playlist::DeleteSong(PlayerControl &pc, const char *uri)
DeletePosition
(
pc
,
i
);
DeletePosition
(
pc
,
i
);
}
}
PlaylistResult
void
playlist
::
MoveRange
(
PlayerControl
&
pc
,
unsigned
start
,
unsigned
end
,
int
to
)
playlist
::
MoveRange
(
PlayerControl
&
pc
,
unsigned
start
,
unsigned
end
,
int
to
)
{
{
if
(
!
queue
.
IsValidPosition
(
start
)
||
!
queue
.
IsValidPosition
(
end
-
1
))
if
(
!
queue
.
IsValidPosition
(
start
)
||
!
queue
.
IsValidPosition
(
end
-
1
))
return
PlaylistResult
::
BAD_RANGE
;
throw
PlaylistError
::
BadRange
()
;
if
((
to
>=
0
&&
to
+
end
-
start
-
1
>=
GetLength
())
||
if
((
to
>=
0
&&
to
+
end
-
start
-
1
>=
GetLength
())
||
(
to
<
0
&&
unsigned
(
abs
(
to
))
>
GetLength
()))
(
to
<
0
&&
unsigned
(
abs
(
to
))
>
GetLength
()))
return
PlaylistResult
::
BAD_RANGE
;
throw
PlaylistError
::
BadRange
()
;
if
((
int
)
start
==
to
)
if
((
int
)
start
==
to
)
/* nothing happens */
/* nothing happens */
return
PlaylistResult
::
SUCCESS
;
return
;
const
DetachedSong
*
const
queued_song
=
GetQueuedSong
();
const
DetachedSong
*
const
queued_song
=
GetQueuedSong
();
...
@@ -355,11 +345,11 @@ playlist::MoveRange(PlayerControl &pc, unsigned start, unsigned end, int to)
...
@@ -355,11 +345,11 @@ playlist::MoveRange(PlayerControl &pc, unsigned start, unsigned end, int to)
if
(
currentSong
<
0
)
if
(
currentSong
<
0
)
/* can't move relative to current song,
/* can't move relative to current song,
because there is no current song */
because there is no current song */
return
PlaylistResult
::
BAD_RANGE
;
throw
PlaylistError
::
BadRange
()
;
if
(
start
<=
(
unsigned
)
currentSong
&&
(
unsigned
)
currentSong
<
end
)
if
(
start
<=
(
unsigned
)
currentSong
&&
(
unsigned
)
currentSong
<
end
)
/* no-op, can't be moved to offset of itself */
/* no-op, can't be moved to offset of itself */
return
PlaylistResult
::
SUCCESS
;
return
;
to
=
(
currentSong
+
abs
(
to
))
%
GetLength
();
to
=
(
currentSong
+
abs
(
to
))
%
GetLength
();
if
(
start
<
(
unsigned
)
to
)
if
(
start
<
(
unsigned
)
to
)
to
--
;
to
--
;
...
@@ -379,18 +369,16 @@ playlist::MoveRange(PlayerControl &pc, unsigned start, unsigned end, int to)
...
@@ -379,18 +369,16 @@ playlist::MoveRange(PlayerControl &pc, unsigned start, unsigned end, int to)
UpdateQueuedSong
(
pc
,
queued_song
);
UpdateQueuedSong
(
pc
,
queued_song
);
OnModified
();
OnModified
();
return
PlaylistResult
::
SUCCESS
;
}
}
PlaylistResult
void
playlist
::
MoveId
(
PlayerControl
&
pc
,
unsigned
id1
,
int
to
)
playlist
::
MoveId
(
PlayerControl
&
pc
,
unsigned
id1
,
int
to
)
{
{
int
song
=
queue
.
IdToPosition
(
id1
);
int
song
=
queue
.
IdToPosition
(
id1
);
if
(
song
<
0
)
if
(
song
<
0
)
return
PlaylistResult
::
NO_SUCH_SONG
;
throw
PlaylistError
::
NoSuchSong
()
;
return
MoveRange
(
pc
,
song
,
song
+
1
,
to
);
MoveRange
(
pc
,
song
,
song
+
1
,
to
);
}
}
void
void
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment