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
10824204
Commit
10824204
authored
Jan 06, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
queue: convert all functions to methods
parent
70652abf
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
277 additions
and
347 deletions
+277
-347
Playlist.cxx
src/Playlist.cxx
+27
-36
PlaylistControl.cxx
src/PlaylistControl.cxx
+19
-23
PlaylistEdit.cxx
src/PlaylistEdit.cxx
+46
-54
PlaylistPrint.cxx
src/PlaylistPrint.cxx
+4
-4
PlaylistSave.cxx
src/PlaylistSave.cxx
+2
-2
PlaylistState.cxx
src/PlaylistState.cxx
+6
-9
Queue.cxx
src/Queue.cxx
+0
-0
Queue.hxx
src/Queue.hxx
+110
-155
QueueCommands.cxx
src/QueueCommands.cxx
+1
-1
QueuePrint.cxx
src/QueuePrint.cxx
+13
-13
QueueSave.cxx
src/QueueSave.cxx
+5
-5
TestQueuePriority.cxx
test/TestQueuePriority.cxx
+44
-45
No files found.
src/Playlist.cxx
View file @
10824204
...
...
@@ -36,7 +36,7 @@ extern "C" {
void
playlist_increment_version_all
(
struct
playlist
*
playlist
)
{
queue_modify_all
(
&
playlist
->
queue
);
playlist
->
queue
.
ModifyAll
(
);
idle_add
(
IDLE_PLAYLIST
);
}
...
...
@@ -48,7 +48,7 @@ playlist_tag_changed(struct playlist *playlist)
assert
(
playlist
->
current
>=
0
);
queue_modify
(
&
playlist
->
queue
,
playlist
->
current
);
playlist
->
queue
.
ModifyAtOrder
(
playlist
->
current
);
idle_add
(
IDLE_PLAYLIST
);
}
...
...
@@ -61,12 +61,12 @@ playlist_queue_song_order(struct playlist *playlist, struct player_control *pc,
{
char
*
uri
;
assert
(
queue_valid_order
(
&
playlist
->
queue
,
order
));
assert
(
playlist
->
queue
.
IsValidOrder
(
order
));
playlist
->
queued
=
order
;
struct
song
*
song
=
song_dup_detached
(
queue_get_order
(
&
playlist
->
queue
,
order
));
song_dup_detached
(
playlist
->
queue
.
GetOrder
(
order
));
uri
=
song_get_uri
(
song
);
g_debug
(
"queue song %i:
\"
%s
\"
"
,
playlist
->
queued
,
uri
);
...
...
@@ -93,8 +93,7 @@ playlist_song_started(struct playlist *playlist, struct player_control *pc)
if
(
playlist
->
queue
.
consume
)
playlist_delete
(
playlist
,
pc
,
queue_order_to_position
(
&
playlist
->
queue
,
current
));
playlist
->
queue
.
OrderToPosition
(
current
));
idle_add
(
IDLE_PLAYER
);
}
...
...
@@ -105,7 +104,7 @@ playlist_get_queued_song(struct playlist *playlist)
if
(
!
playlist
->
playing
||
playlist
->
queued
<
0
)
return
NULL
;
return
queue_get_order
(
&
playlist
->
queue
,
playlist
->
queued
);
return
playlist
->
queue
.
GetOrder
(
playlist
->
queued
);
}
void
...
...
@@ -119,11 +118,11 @@ playlist_update_queued_song(struct playlist *playlist,
if
(
!
playlist
->
playing
)
return
;
assert
(
!
queue_is_empty
(
&
playlist
->
queue
));
assert
(
!
playlist
->
queue
.
IsEmpty
(
));
assert
((
playlist
->
queued
<
0
)
==
(
prev
==
NULL
));
next_order
=
playlist
->
current
>=
0
?
queue_next_order
(
&
playlist
->
queue
,
playlist
->
current
)
?
playlist
->
queue
.
GetNextOrder
(
playlist
->
current
)
:
0
;
if
(
next_order
==
0
&&
playlist
->
queue
.
random
&&
...
...
@@ -132,21 +131,19 @@ playlist_update_queued_song(struct playlist *playlist,
order each time the playlist is played
completely */
unsigned
current_position
=
queue_order_to_position
(
&
playlist
->
queue
,
playlist
->
current
);
playlist
->
queue
.
OrderToPosition
(
playlist
->
current
);
queue_shuffle_order
(
&
playlist
->
queue
);
playlist
->
queue
.
ShuffleOrder
(
);
/* make sure that the playlist->current still points to
the current song, after the song order has been
shuffled */
playlist
->
current
=
queue_position_to_order
(
&
playlist
->
queue
,
current_position
);
playlist
->
queue
.
PositionToOrder
(
current_position
);
}
if
(
next_order
>=
0
)
next_song
=
queue_get_order
(
&
playlist
->
queue
,
next_order
);
next_song
=
playlist
->
queue
.
GetOrder
(
next_order
);
else
next_song
=
NULL
;
...
...
@@ -174,7 +171,7 @@ playlist_play_order(struct playlist *playlist, struct player_control *pc,
playlist
->
queued
=
-
1
;
struct
song
*
song
=
song_dup_detached
(
queue_get_order
(
&
playlist
->
queue
,
orderNum
));
song_dup_detached
(
playlist
->
queue
.
GetOrder
(
orderNum
));
uri
=
song_get_uri
(
song
);
g_debug
(
"play %i:
\"
%s
\"
"
,
orderNum
,
uri
);
...
...
@@ -247,7 +244,7 @@ playlist_resume_playback(struct playlist *playlist, struct player_control *pc)
if
((
playlist
->
stop_on_error
&&
error
!=
PLAYER_ERROR_NONE
)
||
error
==
PLAYER_ERROR_OUTPUT
||
playlist
->
error_count
>=
queue_length
(
&
playlist
->
queue
))
playlist
->
error_count
>=
playlist
->
queue
.
GetLength
(
))
/* too many errors, or critical error: stop
playback */
playlist_stop
(
playlist
,
pc
);
...
...
@@ -306,10 +303,9 @@ playlist_order(struct playlist *playlist)
{
if
(
playlist
->
current
>=
0
)
/* update playlist.current, order==position now */
playlist
->
current
=
queue_order_to_position
(
&
playlist
->
queue
,
playlist
->
current
);
playlist
->
current
=
playlist
->
queue
.
OrderToPosition
(
playlist
->
current
);
queue_restore_order
(
&
playlist
->
queue
);
playlist
->
queue
.
RestoreOrder
(
);
}
void
...
...
@@ -362,20 +358,18 @@ playlist_set_random(struct playlist *playlist, struct player_control *pc,
int
current_position
=
playlist
->
playing
&&
playlist
->
current
>=
0
?
(
int
)
queue_order_to_position
(
&
playlist
->
queue
,
playlist
->
current
)
?
(
int
)
playlist
->
queue
.
OrderToPosition
(
playlist
->
current
)
:
-
1
;
queue_shuffle_order
(
&
playlist
->
queue
);
playlist
->
queue
.
ShuffleOrder
(
);
if
(
current_position
>=
0
)
{
/* make sure the current song is the first in
the order list, so the whole rest of the
playlist is played after that */
unsigned
current_order
=
queue_position_to_order
(
&
playlist
->
queue
,
current_position
);
queue_swap_order
(
&
playlist
->
queue
,
0
,
current_order
);
playlist
->
queue
.
PositionToOrder
(
current_position
);
playlist
->
queue
.
SwapOrders
(
0
,
current_order
);
playlist
->
current
=
0
;
}
else
playlist
->
current
=
-
1
;
...
...
@@ -391,8 +385,7 @@ int
playlist_get_current_song
(
const
struct
playlist
*
playlist
)
{
if
(
playlist
->
current
>=
0
)
return
queue_order_to_position
(
&
playlist
->
queue
,
playlist
->
current
);
return
playlist
->
queue
.
OrderToPosition
(
playlist
->
current
);
return
-
1
;
}
...
...
@@ -403,13 +396,11 @@ playlist_get_next_song(const struct playlist *playlist)
if
(
playlist
->
current
>=
0
)
{
if
(
playlist
->
queue
.
single
==
1
&&
playlist
->
queue
.
repeat
==
1
)
return
queue_order_to_position
(
&
playlist
->
queue
,
playlist
->
current
);
else
if
(
playlist
->
current
+
1
<
(
int
)
queue_length
(
&
playlist
->
queue
))
return
queue_order_to_position
(
&
playlist
->
queue
,
playlist
->
current
+
1
);
return
playlist
->
queue
.
OrderToPosition
(
playlist
->
current
);
else
if
(
playlist
->
current
+
1
<
(
int
)
playlist
->
queue
.
GetLength
())
return
playlist
->
queue
.
OrderToPosition
(
playlist
->
current
+
1
);
else
if
(
playlist
->
queue
.
repeat
==
1
)
return
queue_order_to_position
(
&
playlist
->
queue
,
0
);
return
playlist
->
queue
.
OrderToPosition
(
0
);
}
return
-
1
;
...
...
@@ -424,11 +415,11 @@ playlist_get_version(const struct playlist *playlist)
int
playlist_get_length
(
const
struct
playlist
*
playlist
)
{
return
queue_length
(
&
playlist
->
queue
);
return
playlist
->
queue
.
GetLength
(
);
}
unsigned
playlist_get_song_id
(
const
struct
playlist
*
playlist
,
unsigned
song
)
{
return
queue_position_to_id
(
&
playlist
->
queue
,
song
);
return
playlist
->
queue
.
PositionToId
(
song
);
}
src/PlaylistControl.cxx
View file @
10824204
...
...
@@ -50,16 +50,14 @@ playlist_stop(struct playlist *playlist, struct player_control *pc)
result in a new random order */
unsigned
current_position
=
queue_order_to_position
(
&
playlist
->
queue
,
playlist
->
current
);
playlist
->
queue
.
OrderToPosition
(
playlist
->
current
);
queue_shuffle_order
(
&
playlist
->
queue
);
playlist
->
queue
.
ShuffleOrder
(
);
/* make sure that "current" stays valid, and the next
"play" command plays the same song again */
playlist
->
current
=
queue_position_to_order
(
&
playlist
->
queue
,
current_position
);
playlist
->
queue
.
PositionToOrder
(
current_position
);
}
}
...
...
@@ -74,7 +72,7 @@ playlist_play(struct playlist *playlist, struct player_control *pc,
if
(
song
==
-
1
)
{
/* play any song ("current" song, or the first song */
if
(
queue_is_empty
(
&
playlist
->
queue
))
if
(
playlist
->
queue
.
IsEmpty
(
))
return
PLAYLIST_RESULT_SUCCESS
;
if
(
playlist
->
playing
)
{
...
...
@@ -88,7 +86,7 @@ playlist_play(struct playlist *playlist, struct player_control *pc,
i
=
playlist
->
current
>=
0
?
playlist
->
current
:
0
;
}
else
if
(
!
queue_valid_position
(
&
playlist
->
queue
,
song
))
}
else
if
(
!
playlist
->
queue
.
IsValidPosition
(
song
))
return
PLAYLIST_RESULT_BAD_RANGE
;
if
(
playlist
->
queue
.
random
)
{
...
...
@@ -97,15 +95,14 @@ playlist_play(struct playlist *playlist, struct player_control *pc,
would be equal to the order number in
no-random mode); convert it to a order
number, because random mode is enabled */
i
=
queue_position_to_order
(
&
playlist
->
queue
,
song
);
i
=
playlist
->
queue
.
PositionToOrder
(
song
);
if
(
!
playlist
->
playing
)
playlist
->
current
=
0
;
/* swap the new song with the previous "current" one,
so playback continues as planned */
queue_swap_order
(
&
playlist
->
queue
,
i
,
playlist
->
current
);
playlist
->
queue
.
SwapOrders
(
i
,
playlist
->
current
);
i
=
playlist
->
current
;
}
...
...
@@ -126,7 +123,7 @@ playlist_play_id(struct playlist *playlist, struct player_control *pc,
return
playlist_play
(
playlist
,
pc
,
id
);
}
song
=
queue_id_to_position
(
&
playlist
->
queue
,
id
);
song
=
playlist
->
queue
.
IdToPosition
(
id
);
if
(
song
<
0
)
return
PLAYLIST_RESULT_NO_SUCH_SONG
;
...
...
@@ -142,15 +139,15 @@ playlist_next(struct playlist *playlist, struct player_control *pc)
if
(
!
playlist
->
playing
)
return
;
assert
(
!
queue_is_empty
(
&
playlist
->
queue
));
assert
(
queue_valid_order
(
&
playlist
->
queue
,
playlist
->
current
));
assert
(
!
playlist
->
queue
.
IsEmpty
(
));
assert
(
playlist
->
queue
.
IsValidOrder
(
playlist
->
current
));
current
=
playlist
->
current
;
playlist
->
stop_on_error
=
false
;
/* determine the next song from the queue's order list */
next_order
=
queue_next_order
(
&
playlist
->
queue
,
playlist
->
current
);
next_order
=
playlist
->
queue
.
GetNextOrder
(
playlist
->
current
);
if
(
next_order
<
0
)
{
/* no song after this one: stop playback */
playlist_stop
(
playlist
,
pc
);
...
...
@@ -167,7 +164,7 @@ playlist_next(struct playlist *playlist, struct player_control *pc)
songs in a different than before */
assert
(
playlist
->
queue
.
repeat
);
queue_shuffle_order
(
&
playlist
->
queue
);
playlist
->
queue
.
ShuffleOrder
(
);
/* note that playlist->current and playlist->queued are
now invalid, but playlist_play_order() will
...
...
@@ -180,8 +177,7 @@ playlist_next(struct playlist *playlist, struct player_control *pc)
/* Consume mode removes each played songs. */
if
(
playlist
->
queue
.
consume
)
playlist_delete
(
playlist
,
pc
,
queue_order_to_position
(
&
playlist
->
queue
,
current
));
playlist
->
queue
.
OrderToPosition
(
current
));
}
void
...
...
@@ -190,7 +186,7 @@ playlist_previous(struct playlist *playlist, struct player_control *pc)
if
(
!
playlist
->
playing
)
return
;
assert
(
queue_length
(
&
playlist
->
queue
)
>
0
);
assert
(
playlist
->
queue
.
GetLength
(
)
>
0
);
if
(
playlist
->
current
>
0
)
{
/* play the preceding song */
...
...
@@ -199,7 +195,7 @@ playlist_previous(struct playlist *playlist, struct player_control *pc)
}
else
if
(
playlist
->
queue
.
repeat
)
{
/* play the last song in "repeat" mode */
playlist_play_order
(
playlist
,
pc
,
queue_length
(
&
playlist
->
queue
)
-
1
);
playlist
->
queue
.
GetLength
(
)
-
1
);
}
else
{
/* re-start playing the current song if it's
the first one */
...
...
@@ -215,13 +211,13 @@ playlist_seek_song(struct playlist *playlist, struct player_control *pc,
unsigned
i
;
bool
success
;
if
(
!
queue_valid_position
(
&
playlist
->
queue
,
song
))
if
(
!
playlist
->
queue
.
IsValidPosition
(
song
))
return
PLAYLIST_RESULT_BAD_RANGE
;
queued
=
playlist_get_queued_song
(
playlist
);
if
(
playlist
->
queue
.
random
)
i
=
queue_position_to_order
(
&
playlist
->
queue
,
song
);
i
=
playlist
->
queue
.
PositionToOrder
(
song
);
else
i
=
song
;
...
...
@@ -240,7 +236,7 @@ playlist_seek_song(struct playlist *playlist, struct player_control *pc,
}
struct
song
*
the_song
=
song_dup_detached
(
queue_get_order
(
&
playlist
->
queue
,
i
));
song_dup_detached
(
playlist
->
queue
.
GetOrder
(
i
));
success
=
pc_seek
(
pc
,
the_song
,
seek_time
);
if
(
!
success
)
{
playlist_update_queued_song
(
playlist
,
pc
,
queued
);
...
...
@@ -258,7 +254,7 @@ enum playlist_result
playlist_seek_song_id
(
struct
playlist
*
playlist
,
struct
player_control
*
pc
,
unsigned
id
,
float
seek_time
)
{
int
song
=
queue_id_to_position
(
&
playlist
->
queue
,
id
);
int
song
=
playlist
->
queue
.
IdToPosition
(
id
);
if
(
song
<
0
)
return
PLAYLIST_RESULT_NO_SUCH_SONG
;
...
...
src/PlaylistEdit.cxx
View file @
10824204
This diff is collapsed.
Click to expand it.
src/PlaylistPrint.cxx
View file @
10824204
...
...
@@ -41,7 +41,7 @@ playlist_print_uris(Client *client, const struct playlist *playlist)
{
const
struct
queue
*
queue
=
&
playlist
->
queue
;
queue_print_uris
(
client
,
queue
,
0
,
queue
_length
(
queue
));
queue_print_uris
(
client
,
queue
,
0
,
queue
->
GetLength
(
));
}
bool
...
...
@@ -50,9 +50,9 @@ playlist_print_info(Client *client, const struct playlist *playlist,
{
const
struct
queue
*
queue
=
&
playlist
->
queue
;
if
(
end
>
queue
_length
(
queue
))
if
(
end
>
queue
->
GetLength
(
))
/* correct the "end" offset */
end
=
queue
_length
(
queue
);
end
=
queue
->
GetLength
(
);
if
(
start
>
end
)
/* an invalid "start" offset is fatal */
...
...
@@ -69,7 +69,7 @@ playlist_print_id(Client *client, const struct playlist *playlist,
const
struct
queue
*
queue
=
&
playlist
->
queue
;
int
position
;
position
=
queue
_id_to_position
(
queue
,
id
);
position
=
queue
->
IdToPosition
(
id
);
if
(
position
<
0
)
/* no such song */
return
false
;
...
...
src/PlaylistSave.cxx
View file @
10824204
...
...
@@ -98,8 +98,8 @@ spl_save_queue(const char *name_utf8, const struct queue *queue)
if
(
file
==
NULL
)
return
PLAYLIST_RESULT_ERRNO
;
for
(
unsigned
i
=
0
;
i
<
queue
_length
(
queue
);
i
++
)
playlist_print_song
(
file
,
queue
_get
(
queue
,
i
));
for
(
unsigned
i
=
0
;
i
<
queue
->
GetLength
(
);
i
++
)
playlist_print_song
(
file
,
queue
->
Get
(
i
));
fclose
(
file
);
...
...
src/PlaylistState.cxx
View file @
10824204
...
...
@@ -74,8 +74,7 @@ playlist_state_save(FILE *fp, const struct playlist *playlist,
fputs
(
PLAYLIST_STATE_FILE_STATE_PLAY
"
\n
"
,
fp
);
}
fprintf
(
fp
,
PLAYLIST_STATE_FILE_CURRENT
"%i
\n
"
,
queue_order_to_position
(
&
playlist
->
queue
,
playlist
->
current
));
playlist
->
queue
.
OrderToPosition
(
playlist
->
current
));
fprintf
(
fp
,
PLAYLIST_STATE_FILE_TIME
"%i
\n
"
,
(
int
)
player_status
.
elapsed_time
);
}
else
{
...
...
@@ -83,8 +82,7 @@ playlist_state_save(FILE *fp, const struct playlist *playlist,
if
(
playlist
->
current
>=
0
)
fprintf
(
fp
,
PLAYLIST_STATE_FILE_CURRENT
"%i
\n
"
,
queue_order_to_position
(
&
playlist
->
queue
,
playlist
->
current
));
playlist
->
queue
.
OrderToPosition
(
playlist
->
current
));
}
fprintf
(
fp
,
PLAYLIST_STATE_FILE_RANDOM
"%i
\n
"
,
playlist
->
queue
.
random
);
...
...
@@ -123,7 +121,7 @@ playlist_state_load(TextFile &file, struct playlist *playlist)
}
}
queue_increment_version
(
&
playlist
->
queue
);
playlist
->
queue
.
IncrementVersion
(
);
}
bool
...
...
@@ -195,8 +193,8 @@ playlist_state_restore(const char *line, TextFile &file,
playlist_set_random
(
playlist
,
pc
,
random_mode
);
if
(
!
queue_is_empty
(
&
playlist
->
queue
))
{
if
(
!
queue_valid_position
(
&
playlist
->
queue
,
current
))
if
(
!
playlist
->
queue
.
IsEmpty
(
))
{
if
(
!
playlist
->
queue
.
IsValidPosition
(
current
))
current
=
0
;
if
(
state
==
PLAYER_STATE_PLAY
&&
...
...
@@ -239,8 +237,7 @@ playlist_state_get_hash(const struct playlist *playlist,
?
((
int
)
player_status
.
elapsed_time
<<
8
)
:
0
)
^
(
playlist
->
current
>=
0
?
(
queue_order_to_position
(
&
playlist
->
queue
,
playlist
->
current
)
<<
16
)
?
(
playlist
->
queue
.
OrderToPosition
(
playlist
->
current
)
<<
16
)
:
0
)
^
((
int
)
pc_get_cross_fade
(
pc
)
<<
20
)
^
(
player_status
.
state
<<
24
)
^
...
...
src/Queue.cxx
View file @
10824204
This diff is collapsed.
Click to expand it.
src/Queue.hxx
View file @
10824204
...
...
@@ -20,10 +20,11 @@
#ifndef MPD_QUEUE_HXX
#define MPD_QUEUE_HXX
#include "gcc.h"
#include <glib.h>
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
enum
{
...
...
@@ -110,169 +111,141 @@ struct queue {
queue
(
const
queue
&
other
)
=
delete
;
queue
&
operator
=
(
const
queue
&
other
)
=
delete
;
};
static
inline
unsigned
queue_length
(
const
struct
queue
*
queue
)
{
assert
(
queue
->
length
<=
queue
->
max_length
);
unsigned
GetLength
()
const
{
assert
(
length
<=
max_length
);
return
queue
->
length
;
}
return
length
;
}
/**
/**
* Determine if the queue is empty, i.e. there are no songs.
*/
static
inline
bool
queue_is_empty
(
const
struct
queue
*
queue
)
{
return
queue
->
length
==
0
;
}
bool
IsEmpty
()
const
{
return
length
==
0
;
}
/**
/**
* Determine if the maximum number of songs has been reached.
*/
static
inline
bool
queue_is_full
(
const
struct
queue
*
queue
)
{
assert
(
queue
->
length
<=
queue
->
max_length
);
bool
IsFull
()
const
{
assert
(
length
<=
max_length
);
return
queue
->
length
>=
queue
->
max_length
;
}
return
length
>=
max_length
;
}
/**
/**
* Is that a valid position number?
*/
static
inline
bool
queue_valid_position
(
const
struct
queue
*
queue
,
unsigned
position
)
{
return
position
<
queue
->
length
;
}
bool
IsValidPosition
(
unsigned
position
)
const
{
return
position
<
length
;
}
/**
/**
* Is that a valid order number?
*/
static
inline
bool
queue_valid_order
(
const
struct
queue
*
queue
,
unsigned
order
)
{
return
order
<
queue
->
length
;
}
static
inline
int
queue_id_to_position
(
const
struct
queue
*
queue
,
unsigned
id
)
{
if
(
id
>=
queue
->
max_length
*
QUEUE_HASH_MULT
)
bool
IsValidOrder
(
unsigned
_order
)
const
{
return
_order
<
length
;
}
int
IdToPosition
(
unsigned
id
)
const
{
if
(
id
>=
max_length
*
QUEUE_HASH_MULT
)
return
-
1
;
assert
(
queue
->
id_to_position
[
id
]
>=
-
1
);
assert
(
queue
->
id_to_position
[
id
]
<
(
int
)
queue
->
length
);
assert
(
id_to_position
[
id
]
>=
-
1
);
assert
(
id_to_position
[
id
]
<
(
int
)
length
);
return
queue
->
id_to_position
[
id
];
}
return
id_to_position
[
id
];
}
static
inline
int
queue_position_to_id
(
const
struct
queue
*
queue
,
unsigned
position
)
{
assert
(
position
<
queue
->
length
);
int
PositionToId
(
unsigned
position
)
const
{
assert
(
position
<
length
);
return
queue
->
items
[
position
].
id
;
}
return
items
[
position
].
id
;
}
static
inline
unsigned
queue_order_to_position
(
const
struct
queue
*
queue
,
unsigned
order
)
{
assert
(
order
<
queue
->
length
);
gcc_pure
unsigned
OrderToPosition
(
unsigned
_order
)
const
{
assert
(
_order
<
length
);
return
queue
->
order
[
order
];
}
return
order
[
_
order
];
}
static
inline
unsigned
queue_position_to_order
(
const
struct
queue
*
queue
,
unsigned
position
)
{
assert
(
position
<
queue
->
length
);
gcc_pure
unsigned
PositionToOrder
(
unsigned
position
)
const
{
assert
(
position
<
length
);
for
(
unsigned
i
=
0
;;
++
i
)
{
assert
(
i
<
queue
->
length
);
assert
(
i
<
length
);
if
(
queue
->
order
[
i
]
==
position
)
if
(
order
[
i
]
==
position
)
return
i
;
}
}
}
G_GNUC_PURE
static
inline
uint8_t
queue_get_priority_at_position
(
const
struct
queue
*
queue
,
unsigned
position
)
{
assert
(
position
<
queue
->
length
);
G_GNUC_PURE
uint8_t
GetPriorityAtPosition
(
unsigned
position
)
const
{
assert
(
position
<
length
);
return
queue
->
items
[
position
].
priority
;
}
return
items
[
position
].
priority
;
}
/**
/**
* Returns the song at the specified position.
*/
static
inline
struct
song
*
queue_get
(
const
struct
queue
*
queue
,
unsigned
position
)
{
assert
(
position
<
queue
->
length
);
struct
song
*
Get
(
unsigned
position
)
const
{
assert
(
position
<
length
);
return
queue
->
items
[
position
].
song
;
}
return
items
[
position
].
song
;
}
/**
/**
* Returns the song at the specified order number.
*/
static
inline
struct
song
*
queue_get_order
(
const
struct
queue
*
queue
,
unsigned
order
)
{
return
queue_get
(
queue
,
queue_order_to_position
(
queue
,
order
));
}
struct
song
*
GetOrder
(
unsigned
_order
)
const
{
return
Get
(
OrderToPosition
(
_order
));
}
/**
/**
* Is the song at the specified position newer than the specified
* version?
*/
static
inline
bool
queue_song_newer
(
const
struct
queue
*
queue
,
unsigned
position
,
uint32_t
version
)
{
assert
(
position
<
queue
->
length
);
bool
IsNewerAtPosition
(
unsigned
position
,
uint32_t
_version
)
const
{
assert
(
position
<
length
);
return
version
>
queue
->
version
||
queue
->
items
[
position
].
version
>=
version
||
queue
->
items
[
position
].
version
==
0
;
}
return
_version
>
version
||
items
[
position
].
version
>=
_
version
||
items
[
position
].
version
==
0
;
}
/**
/**
* Returns the order number following the specified one. This takes
* end of queue and "repeat" mode into account.
*
* @return the next order number, or -1 to stop playback
*/
int
queue_next_order
(
const
struct
queue
*
queue
,
unsigned
order
)
;
gcc_pure
int
GetNextOrder
(
unsigned
order
)
const
;
/**
/**
* Increments the queue's version number. This handles integer
* overflow well.
*/
void
queue_increment_version
(
struct
queue
*
queue
);
void
IncrementVersion
();
/**
/**
* Marks the specified song as "modified" and increments the version
* number.
*/
void
queue_modify
(
struct
queue
*
queue
,
unsigned
order
);
void
ModifyAtOrder
(
unsigned
order
);
/**
/**
* Marks all songs as "modified" and increments the version number.
*/
void
queue_modify_all
(
struct
queue
*
queue
);
void
ModifyAll
();
/**
/**
* Appends a song to the queue and returns its position. Prior to
* that, the caller must check if the queue is already full.
*
...
...
@@ -281,97 +254,79 @@ queue_modify_all(struct queue *queue);
*
* @param priority the priority of this new queue item
*/
unsigned
queue_append
(
struct
queue
*
queue
,
struct
song
*
song
,
uint8_t
priority
);
unsigned
Append
(
struct
song
*
song
,
uint8_t
priority
);
/**
/**
* Swaps two songs, addressed by their position.
*/
void
queue_swap
(
struct
queue
*
queue
,
unsigned
position1
,
unsigned
position2
);
void
SwapPositions
(
unsigned
position1
,
unsigned
position2
);
/**
/**
* Swaps two songs, addressed by their order number.
*/
static
inline
void
queue_swap_order
(
struct
queue
*
queue
,
unsigned
order1
,
unsigned
order2
)
{
unsigned
tmp
=
queue
->
order
[
order1
];
queue
->
order
[
order1
]
=
queue
->
order
[
order2
];
queue
->
order
[
order2
]
=
tmp
;
}
void
SwapOrders
(
unsigned
order1
,
unsigned
order2
)
{
unsigned
tmp
=
order
[
order1
];
order
[
order1
]
=
order
[
order2
];
order
[
order2
]
=
tmp
;
}
/**
/**
* Moves a song to a new position.
*/
void
queue_move
(
struct
queue
*
queue
,
unsigned
from
,
unsigned
to
);
void
MovePostion
(
unsigned
from
,
unsigned
to
);
/**
/**
* Moves a range of songs to a new position.
*/
void
queue_move_range
(
struct
queue
*
queue
,
unsigned
start
,
unsigned
end
,
unsigned
to
);
void
MoveRange
(
unsigned
start
,
unsigned
end
,
unsigned
to
);
/**
/**
* Removes a song from the playlist.
*/
void
queue_delete
(
struct
queue
*
queue
,
unsigned
position
);
void
DeletePosition
(
unsigned
position
);
/**
/**
* Removes all songs from the playlist.
*/
void
queue_clear
(
struct
queue
*
queue
);
void
Clear
();
/**
/**
* Initializes the "order" array, and restores "normal" order.
*/
static
inline
void
queue_restore_order
(
struct
queue
*
queue
)
{
for
(
unsigned
i
=
0
;
i
<
queue
->
length
;
++
i
)
queue
->
order
[
i
]
=
i
;
}
void
RestoreOrder
()
{
for
(
unsigned
i
=
0
;
i
<
length
;
++
i
)
order
[
i
]
=
i
;
}
/**
/**
* Shuffle the order of items in the specified range, taking their
* priorities into account.
*/
void
queue_shuffle_order_range_with_priority
(
struct
queue
*
queue
,
unsigned
start
,
unsigned
end
);
void
ShuffleOrderRangeWithPriority
(
unsigned
start
,
unsigned
end
);
/**
/**
* Shuffles the virtual order of songs, but does not move them
* physically. This is used in random mode.
*/
void
queue_shuffle_order
(
struct
queue
*
queue
);
void
ShuffleOrder
();
/**
/**
* Shuffles the virtual order of the last song in the specified
* (order) range. This is used in random mode after a song has been
* appended by queue_append().
*/
void
queue_shuffle_order_last
(
struct
queue
*
queue
,
unsigned
start
,
unsigned
end
);
void
ShuffleOrderLast
(
unsigned
start
,
unsigned
end
);
/**
/**
* Shuffles a (position) range in the queue. The songs are physically
* shuffled, not by using the "order" mapping.
*/
void
queue_shuffle_range
(
struct
queue
*
queue
,
unsigned
start
,
unsigned
end
);
void
ShuffleRange
(
unsigned
start
,
unsigned
end
);
bool
queue_set_priority
(
struct
queue
*
queue
,
unsigned
position
,
uint8_t
priority
,
int
after_order
);
bool
SetPriority
(
unsigned
position
,
uint8_t
priority
,
int
after_order
);
bool
queue_set_priority_range
(
struct
queue
*
queue
,
unsigned
start_position
,
unsigned
end_position
,
bool
SetPriorityRange
(
unsigned
start_position
,
unsigned
end_position
,
uint8_t
priority
,
int
after_order
);
};
#endif
src/QueueCommands.cxx
View file @
10824204
...
...
@@ -171,7 +171,7 @@ enum command_return
handle_shuffle
(
G_GNUC_UNUSED
Client
*
client
,
G_GNUC_UNUSED
int
argc
,
G_GNUC_UNUSED
char
*
argv
[])
{
unsigned
start
=
0
,
end
=
queue_length
(
&
client
->
playlist
.
queue
);
unsigned
start
=
0
,
end
=
client
->
playlist
.
queue
.
GetLength
(
);
if
(
argc
==
2
&&
!
check_range
(
client
,
&
start
,
&
end
,
argv
[
1
]))
return
COMMAND_RETURN_ERROR
;
...
...
src/QueuePrint.cxx
View file @
10824204
...
...
@@ -41,11 +41,11 @@ static void
queue_print_song_info
(
Client
*
client
,
const
struct
queue
*
queue
,
unsigned
position
)
{
song_print_info
(
client
,
queue
_get
(
queue
,
position
));
song_print_info
(
client
,
queue
->
Get
(
position
));
client_printf
(
client
,
"Pos: %u
\n
Id: %u
\n
"
,
position
,
queue
_position_to_id
(
queue
,
position
));
position
,
queue
->
PositionToId
(
position
));
uint8_t
priority
=
queue
_get_priority_at_position
(
queue
,
position
);
uint8_t
priority
=
queue
->
GetPriorityAtPosition
(
position
);
if
(
priority
!=
0
)
client_printf
(
client
,
"Prio: %u
\n
"
,
priority
);
}
...
...
@@ -55,7 +55,7 @@ queue_print_info(Client *client, const struct queue *queue,
unsigned
start
,
unsigned
end
)
{
assert
(
start
<=
end
);
assert
(
end
<=
queue
_length
(
queue
));
assert
(
end
<=
queue
->
GetLength
(
));
for
(
unsigned
i
=
start
;
i
<
end
;
++
i
)
queue_print_song_info
(
client
,
queue
,
i
);
...
...
@@ -66,11 +66,11 @@ queue_print_uris(Client *client, const struct queue *queue,
unsigned
start
,
unsigned
end
)
{
assert
(
start
<=
end
);
assert
(
end
<=
queue
_length
(
queue
));
assert
(
end
<=
queue
->
GetLength
(
));
for
(
unsigned
i
=
start
;
i
<
end
;
++
i
)
{
client_printf
(
client
,
"%i:"
,
i
);
song_print_uri
(
client
,
queue
_get
(
queue
,
i
));
song_print_uri
(
client
,
queue
->
Get
(
i
));
}
}
...
...
@@ -78,8 +78,8 @@ void
queue_print_changes_info
(
Client
*
client
,
const
struct
queue
*
queue
,
uint32_t
version
)
{
for
(
unsigned
i
=
0
;
i
<
queue
_length
(
queue
);
i
++
)
{
if
(
queue
_song_newer
(
queue
,
i
,
version
))
for
(
unsigned
i
=
0
;
i
<
queue
->
GetLength
(
);
i
++
)
{
if
(
queue
->
IsNewerAtPosition
(
i
,
version
))
queue_print_song_info
(
client
,
queue
,
i
);
}
}
...
...
@@ -88,18 +88,18 @@ void
queue_print_changes_position
(
Client
*
client
,
const
struct
queue
*
queue
,
uint32_t
version
)
{
for
(
unsigned
i
=
0
;
i
<
queue
_length
(
queue
);
i
++
)
if
(
queue
_song_newer
(
queue
,
i
,
version
))
for
(
unsigned
i
=
0
;
i
<
queue
->
GetLength
(
);
i
++
)
if
(
queue
->
IsNewerAtPosition
(
i
,
version
))
client_printf
(
client
,
"cpos: %i
\n
Id: %i
\n
"
,
i
,
queue
_position_to_id
(
queue
,
i
));
i
,
queue
->
PositionToId
(
i
));
}
void
queue_find
(
Client
*
client
,
const
struct
queue
*
queue
,
const
SongFilter
&
filter
)
{
for
(
unsigned
i
=
0
;
i
<
queue
_length
(
queue
);
i
++
)
{
const
struct
song
*
song
=
queue
_get
(
queue
,
i
);
for
(
unsigned
i
=
0
;
i
<
queue
->
GetLength
(
);
i
++
)
{
const
struct
song
*
song
=
queue
->
Get
(
i
);
if
(
filter
.
Match
(
*
song
))
queue_print_song_info
(
client
,
queue
,
i
);
...
...
src/QueueSave.cxx
View file @
10824204
...
...
@@ -61,19 +61,19 @@ 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
++
)
{
uint8_t
prio
=
queue
_get_priority_at_position
(
queue
,
i
);
for
(
unsigned
i
=
0
;
i
<
queue
->
GetLength
(
);
i
++
)
{
uint8_t
prio
=
queue
->
GetPriorityAtPosition
(
i
);
if
(
prio
!=
0
)
fprintf
(
fp
,
PRIO_LABEL
"%u
\n
"
,
prio
);
queue_save_song
(
fp
,
i
,
queue
_get
(
queue
,
i
));
queue_save_song
(
fp
,
i
,
queue
->
Get
(
i
));
}
}
void
queue_load_song
(
TextFile
&
file
,
const
char
*
line
,
queue
*
queue
)
{
if
(
queue
_is_full
(
queue
))
if
(
queue
->
IsFull
(
))
return
;
uint8_t
priority
=
0
;
...
...
@@ -123,7 +123,7 @@ queue_load_song(TextFile &file, const char *line, queue *queue)
}
}
queue
_append
(
queue
,
song
,
priority
);
queue
->
Append
(
song
,
priority
);
if
(
db
!=
nullptr
)
db
->
ReturnSong
(
song
);
...
...
test/TestQueuePriority.cxx
View file @
10824204
...
...
@@ -23,21 +23,21 @@ G_GNUC_UNUSED
static
void
dump_order
(
const
struct
queue
*
queue
)
{
g_printerr
(
"queue length=%u, order:
\n
"
,
queue
_length
(
queue
));
for
(
unsigned
i
=
0
;
i
<
queue
_length
(
queue
);
++
i
)
g_printerr
(
"queue length=%u, order:
\n
"
,
queue
->
GetLength
(
));
for
(
unsigned
i
=
0
;
i
<
queue
->
GetLength
(
);
++
i
)
g_printerr
(
" [%u] -> %u (prio=%u)
\n
"
,
i
,
queue
->
order
[
i
],
queue
->
items
[
queue
->
order
[
i
]].
priority
);
}
static
void
check_descending_priority
(
G_GNUC_UNUSED
const
struct
queue
*
queue
,
check_descending_priority
(
const
struct
queue
*
queue
,
unsigned
start_order
)
{
assert
(
start_order
<
queue
_length
(
queue
));
assert
(
start_order
<
queue
->
GetLength
(
));
uint8_t
last_priority
=
0xff
;
for
(
unsigned
order
=
start_order
;
order
<
queue
_length
(
queue
);
++
order
)
{
unsigned
position
=
queue
_order_to_position
(
queue
,
order
);
for
(
unsigned
order
=
start_order
;
order
<
queue
->
GetLength
(
);
++
order
)
{
unsigned
position
=
queue
->
OrderToPosition
(
order
);
uint8_t
priority
=
queue
->
items
[
position
].
priority
;
assert
(
priority
<=
last_priority
);
(
void
)
last_priority
;
...
...
@@ -48,74 +48,74 @@ check_descending_priority(G_GNUC_UNUSED const struct queue *queue,
int
main
(
G_GNUC_UNUSED
int
argc
,
G_GNUC_UNUSED
char
**
argv
)
{
struct
song
songs
[
16
];
st
atic
st
ruct
song
songs
[
16
];
struct
queue
queue
(
32
);
for
(
unsigned
i
=
0
;
i
<
G_N_ELEMENTS
(
songs
);
++
i
)
queue
_append
(
&
queue
,
&
songs
[
i
],
0
);
queue
.
Append
(
&
songs
[
i
],
0
);
assert
(
queue
_length
(
&
queue
)
==
G_N_ELEMENTS
(
songs
));
assert
(
queue
.
GetLength
(
)
==
G_N_ELEMENTS
(
songs
));
/* priority=10 for 4 items */
queue
_set_priority_range
(
&
queue
,
4
,
8
,
10
,
-
1
);
queue
.
SetPriorityRange
(
4
,
8
,
10
,
-
1
);
queue
.
random
=
true
;
queue
_shuffle_order
(
&
queue
);
queue
.
ShuffleOrder
(
);
check_descending_priority
(
&
queue
,
0
);
for
(
unsigned
i
=
0
;
i
<
4
;
++
i
)
{
assert
(
queue
_position_to_order
(
&
queue
,
i
)
>=
4
);
assert
(
queue
.
PositionToOrder
(
i
)
>=
4
);
}
for
(
unsigned
i
=
4
;
i
<
8
;
++
i
)
{
assert
(
queue
_position_to_order
(
&
queue
,
i
)
<
4
);
assert
(
queue
.
PositionToOrder
(
i
)
<
4
);
}
for
(
unsigned
i
=
8
;
i
<
G_N_ELEMENTS
(
songs
);
++
i
)
{
assert
(
queue
_position_to_order
(
&
queue
,
i
)
>=
4
);
assert
(
queue
.
PositionToOrder
(
i
)
>=
4
);
}
/* priority=50 one more item */
queue
_set_priority_range
(
&
queue
,
15
,
16
,
50
,
-
1
);
queue
.
SetPriorityRange
(
15
,
16
,
50
,
-
1
);
check_descending_priority
(
&
queue
,
0
);
assert
(
queue
_position_to_order
(
&
queue
,
15
)
==
0
);
assert
(
queue
.
PositionToOrder
(
15
)
==
0
);
for
(
unsigned
i
=
0
;
i
<
4
;
++
i
)
{
assert
(
queue
_position_to_order
(
&
queue
,
i
)
>=
4
);
assert
(
queue
.
PositionToOrder
(
i
)
>=
4
);
}
for
(
unsigned
i
=
4
;
i
<
8
;
++
i
)
{
assert
(
queue
_position_to_order
(
&
queue
,
i
)
>=
1
&&
queue
_position_to_order
(
&
queue
,
i
)
<
5
);
assert
(
queue
.
PositionToOrder
(
i
)
>=
1
&&
queue
.
PositionToOrder
(
i
)
<
5
);
}
for
(
unsigned
i
=
8
;
i
<
15
;
++
i
)
{
assert
(
queue
_position_to_order
(
&
queue
,
i
)
>=
5
);
assert
(
queue
.
PositionToOrder
(
i
)
>=
5
);
}
/* priority=20 for one of the 4 priority=10 items */
queue
_set_priority_range
(
&
queue
,
3
,
4
,
20
,
-
1
);
queue
.
SetPriorityRange
(
3
,
4
,
20
,
-
1
);
check_descending_priority
(
&
queue
,
0
);
assert
(
queue
_position_to_order
(
&
queue
,
3
)
==
1
);
assert
(
queue
_position_to_order
(
&
queue
,
15
)
==
0
);
assert
(
queue
.
PositionToOrder
(
3
)
==
1
);
assert
(
queue
.
PositionToOrder
(
15
)
==
0
);
for
(
unsigned
i
=
0
;
i
<
3
;
++
i
)
{
assert
(
queue
_position_to_order
(
&
queue
,
i
)
>=
5
);
assert
(
queue
.
PositionToOrder
(
i
)
>=
5
);
}
for
(
unsigned
i
=
4
;
i
<
8
;
++
i
)
{
assert
(
queue
_position_to_order
(
&
queue
,
i
)
>=
2
&&
queue
_position_to_order
(
&
queue
,
i
)
<
6
);
assert
(
queue
.
PositionToOrder
(
i
)
>=
2
&&
queue
.
PositionToOrder
(
i
)
<
6
);
}
for
(
unsigned
i
=
8
;
i
<
15
;
++
i
)
{
assert
(
queue
_position_to_order
(
&
queue
,
i
)
>=
6
);
assert
(
queue
.
PositionToOrder
(
i
)
>=
6
);
}
/* priority=20 for another one of the 4 priority=10 items;
...
...
@@ -124,17 +124,17 @@ main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv)
unsigned
current_order
=
4
;
unsigned
current_position
=
queue
_order_to_position
(
&
queue
,
current_order
);
queue
.
OrderToPosition
(
current_order
);
unsigned
a_order
=
3
;
unsigned
a_position
=
queue
_order_to_position
(
&
queue
,
a_order
);
unsigned
a_position
=
queue
.
OrderToPosition
(
a_order
);
assert
(
queue
.
items
[
a_position
].
priority
==
10
);
queue
_set_priority
(
&
queue
,
a_position
,
20
,
current_order
);
queue
.
SetPriority
(
a_position
,
20
,
current_order
);
current_order
=
queue
_position_to_order
(
&
queue
,
current_position
);
current_order
=
queue
.
PositionToOrder
(
current_position
);
assert
(
current_order
==
3
);
a_order
=
queue
_position_to_order
(
&
queue
,
a_position
);
a_order
=
queue
.
PositionToOrder
(
a_position
);
assert
(
a_order
==
4
);
check_descending_priority
(
&
queue
,
current_order
+
1
);
...
...
@@ -144,14 +144,14 @@ main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv)
just created */
unsigned
b_order
=
10
;
unsigned
b_position
=
queue
_order_to_position
(
&
queue
,
b_order
);
unsigned
b_position
=
queue
.
OrderToPosition
(
b_order
);
assert
(
queue
.
items
[
b_position
].
priority
==
0
);
queue
_set_priority
(
&
queue
,
b_position
,
70
,
current_order
);
queue
.
SetPriority
(
b_position
,
70
,
current_order
);
current_order
=
queue
_position_to_order
(
&
queue
,
current_position
);
current_order
=
queue
.
PositionToOrder
(
current_position
);
assert
(
current_order
==
3
);
b_order
=
queue
_position_to_order
(
&
queue
,
b_position
);
b_order
=
queue
.
PositionToOrder
(
b_position
);
assert
(
b_order
==
4
);
check_descending_priority
(
&
queue
,
current_order
+
1
);
...
...
@@ -161,27 +161,26 @@ main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv)
hasn't changed (it was already higher before) */
unsigned
c_order
=
0
;
unsigned
c_position
=
queue
_order_to_position
(
&
queue
,
c_order
);
unsigned
c_position
=
queue
.
OrderToPosition
(
c_order
);
assert
(
queue
.
items
[
c_position
].
priority
==
50
);
queue
_set_priority
(
&
queue
,
c_position
,
60
,
current_order
);
queue
.
SetPriority
(
c_position
,
60
,
current_order
);
current_order
=
queue
_position_to_order
(
&
queue
,
current_position
);
current_order
=
queue
.
PositionToOrder
(
current_position
);
assert
(
current_order
==
3
);
c_order
=
queue
_position_to_order
(
&
queue
,
c_position
);
c_order
=
queue
.
PositionToOrder
(
c_position
);
assert
(
c_order
==
0
);
/* move the prio=20 item back */
a_order
=
queue
_position_to_order
(
&
queue
,
a_position
);
a_order
=
queue
.
PositionToOrder
(
a_position
);
assert
(
a_order
==
5
);
assert
(
queue
.
items
[
a_position
].
priority
==
20
);
queue
_set_priority
(
&
queue
,
a_position
,
5
,
current_order
);
queue
.
SetPriority
(
a_position
,
5
,
current_order
);
current_order
=
queue_position_to_order
(
&
queue
,
current_position
);
current_order
=
queue
.
PositionToOrder
(
current_position
);
assert
(
current_order
==
3
);
a_order
=
queue
_position_to_order
(
&
queue
,
a_position
);
a_order
=
queue
.
PositionToOrder
(
a_position
);
assert
(
a_order
==
6
);
}
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