Commit Graph

235 Commits

Author SHA1 Message Date
Max Kellermann
00541f8ce9 playlist: replaced playlist_state with flag playlist.playing
There were only two possible states: STOP and PLAY.  The code looks a
lot easier if we use a bool instead.  Move the variable into the
playlist struct.
2009-01-23 00:09:26 +01:00
Max Kellermann
3a1de741bb queue: added queue_shuffle_order()
The function shuffles the virtual order of songs, but does not move
them physically.  This is used in random mode.

The new function replaces playlist.c's randomizeOrder() function,
which was aware of playlist.current and playlist.queued.  The latter
is always -1 anyway, and the former as preserved by the caller, by
converting playlist.current to a position, and then back to an order
number.
2009-01-23 00:08:40 +01:00
Max Kellermann
fb2ef107d1 playlist: check if repeat mode changes
Add a "changed" check to setPlaylistRepeatStatus(): when the new
repeat mode is the same as the old one, don't do anything at all.  No
more checks, no "idle" event.
2009-01-23 00:07:20 +01:00
Max Kellermann
9cad342056 playlist: recalculate the queued song after random is toggled
When the random mode is toggled, MPD did not clear the queue.  Because
of this, MPD continued with the next (random or non-random) song
according to the previous mode.  Clear the queued song to fix that.
2009-01-23 00:07:10 +01:00
Max Kellermann
144a91cace playlist: moved code to playlist_queue_song_order()
Merged duplicate code from queueNextSongInPlaylist().
2009-01-23 00:06:54 +01:00
Max Kellermann
f78cddb407 playlist: moved code to queue.c
Attempt to untie the playlist.c knot: moved the playlist storage code
to queue.c, struct queue.
2009-01-22 23:40:11 +01:00
Max Kellermann
d5dcd0ed66 playlist: corrected shuffle underflow test
Check for current>=0, not queued>=0.
2009-01-22 20:10:17 +01:00
Max Kellermann
1f8a1cbc08 playlist: fix buffer underflow when getting current song
The function moveSongInPlaylist() attempted to read the position of
the current song, even if it was -1.  Check that first.  The same bug
was in shufflePlaylist().
2009-01-22 16:14:34 +01:00
Max Kellermann
8484c3708b playlist: convert assertion to check in TAG event handler
It is possible that playlist.current is reset before the TAG event
handler playlist_tag_event() is called.  Convert the assertion into a
run-time check.
2009-01-21 17:11:41 +01:00
Max Kellermann
5541015ac6 command: don't restart player in the "status" command
Don't attempt to restart the player if it was stopped, but there were
still songs left on the playlist.  This looks like it has been a
workaround for a bug which has been fixed long time ago.
2009-01-21 16:17:57 +01:00
Max Kellermann
699b31178d playlist: use the "enum player_error" type
Don't assign the result of getPlayerError() to an integer.
2009-01-21 16:17:57 +01:00
Max Kellermann
6fd8c28d2e playlist: free memory with g_free()
Use g_free() consistently with g_malloc().  Don't clear the pointers
after freeing them.
2009-01-21 16:17:57 +01:00
Max Kellermann
2362ee4a48 use config_get_positive() instead of manual parsing
Simplify some code by using config_get_positive(), instead of doing
manual parsing and validation each time.
2009-01-21 08:48:02 +01:00
Max Kellermann
06bd9ad88f event_pipe: added "TAG" event
The "TAG" event is emitted by the player thread when the current
song's tag has changed.  Split this event from "PLAYLIST" and make it
a separate callback, which is more efficient.
2009-01-20 22:49:19 +01:00
Max Kellermann
9933144de7 mapper: make the playlist directory optional 2009-01-18 16:15:45 +01:00
Max Kellermann
a1a97cc048 conf: use config_get_bool() instead of getBoolConfigParam() 2009-01-17 20:23:33 +01:00
Max Kellermann
4d472c265e conf: no CamelCase, part I
Renamed functions, types, variables.
2009-01-17 20:23:27 +01:00
Max Kellermann
285a741b27 playlist: don't store getBoolConfigParam() in a bool
getBoolConfigParam() returns an int.  It is not possible to check for
CONF_BOOL_UNSET after it has been assigned to a bool; use a temporary
int value for that.
2009-01-16 17:11:18 +01:00
Max Kellermann
2c540ee8a4 playlist: safely search the playlist for deleted song
When a song file is deleted during database update, all pointers to it
must be removed from the playlist.  The "for" loop in
deleteASongFromPlaylist() did not deal with multiple copies of the
deleted song properly, and left instances of the (to-be-invalidated)
pointer in.  Fix this by reversing the loop.
2009-01-14 11:42:45 +01:00
Max Kellermann
d8fc8ca7ba playlist: implement Fisher-Yates shuffle properly
MPD's shuffling algorithm was not implemented well: it considers songs
which were already swapped, making it somewhat non-random.

Fix the Fisher-Yates shuffle algorithm by passing the proper bounds to
the PRNG.
2009-01-13 21:25:19 +01:00
Max Kellermann
8ebe7bfb25 playlist: pass unsigned integers to playlistInfo()
A song index cannot be negative.  Also require the second parameter to
be valid.
2009-01-10 17:39:49 +01:00
Max Kellermann
b7c4b78846 playlist: exclude end of range
In a range "start:end", "end" itself should not be included.  Use the
same semantics as other languages implementing ranges, e.g. Python.
2009-01-10 17:05:03 +01:00
Thomas Jansen
6f0781f039 command: playlistinfo now uses a range argument rather than just a song id
Loosely based on a patch provided by lesion in bug #1766. The playlistinfo
command can now retrieve ranges of the playlist. The new argument indicates
which entry is the last one that will be displayed. The number of displayed
entries may be smaller than expected if the end of the playlist is reached.

Previous usage:
playlistinfo [start]

New usage:
playlistinfo [start[:end]]
2009-01-10 16:50:34 +01:00
Max Kellermann
fed719197c song: allocate the result of song_get_url() 2009-01-04 19:09:34 +01:00
Max Kellermann
8c5470a3db playlist: log errors during loadPlaylist()
Don't call command_error() if loading a song from the playlist fails.
This may result in assertion failures, since command_error() may be
called more than once.
2009-01-04 18:59:32 +01:00
Max Kellermann
49ac6fa996 playlist: use GLib logging 2009-01-04 18:17:37 +01:00
Max Kellermann
17d8bdb427 playlist: use uri_has_scheme() instead of isRemoteUrl()
For internal checks (i.e. not in command.c), we need to check whether
an URI is in the databse, in the local file system or a remote URI
with a scheme.
2009-01-04 16:23:33 +01:00
Max Kellermann
dcff29e5aa state_file: errors are non-fatal in read_state_file()
If the state file cannot be read, for whatever reason, don't abort
MPD.  The state file isn't _that_ important.
2009-01-03 14:53:23 +01:00
Max Kellermann
7a8ef820a4 list: removed linked list library
It's been superseded by GLib's GSList.
2009-01-02 18:41:35 +01:00
Max Kellermann
9e46c32004 playlist: use GLib instead of utils.h 2009-01-02 17:22:47 +01:00
Max Kellermann
0c422838a8 playlist: use g_file_test() instead of stat()
To find out whether a file exists, use g_file_test() instead of
stat(), because it is more portable and easier to use.
2009-01-01 19:22:07 +01:00
Max Kellermann
80fa9183e4 mapper: allocate playlist path from heap
Don't pass a static buffer to map_spl_utf8_to_fs().
2009-01-01 19:17:44 +01:00
Max Kellermann
bb55ec6b4e command: don't allow adding local files on WIN32
There are no unix sockets on WIN32, and therefore no authentication.
WIN32 might have similar capabilities, but until we implement them,
disable that MPD feature.
2008-12-30 19:14:13 +01:00
Max Kellermann
e9a3c4ce32 playlist: use GLib's random number generator
srandom() and random() are not portable.  Use GLib's implementation.
2008-12-30 16:34:32 +01:00
Max Kellermann
95b3430f52 removed os_compat.h
Only include headers which are really needed.  os_compat.h aimed to
make MPD easily portable, but was never actually made portable.
2008-12-29 17:28:32 +01:00
Max Kellermann
859aac7242 utils: removed myFgets()
Replaced myFgets() with fgets() + g_strchomp().
2008-12-28 19:54:49 +01:00
Max Kellermann
13192546a8 playlist: clear pc.errored_song on delete
When a (remote) song is deleted from the playlist, there may still be
a reference to it in pc.errored_song.  Clear this reference.
2008-12-17 16:45:49 +01:00
Max Kellermann
3287726736 ls: removed isValidRemoteUtf8Url()
The function didn't do anything useful, it was just several lines
obfuscating that it was only forwarding isRemoteUrl()'s return value.
2008-12-16 21:15:20 +01:00
Max Kellermann
ae9bb92952 playlist: call clearPlayerQueue() only if song is queued II
This patch extends commit 35a16b99, and amends several 2 missing
checks.  It simplifies 2 more checks by merging "if" conditions.
2008-11-12 21:55:13 +01:00
Max Kellermann
acf0d141be playlist: track song metadata changes
When the tag of the current song changes (e.g. a new tag was sent in
the stream), update the playlist, so clients pick up the new tag.
2008-11-11 20:46:55 +01:00
Max Kellermann
d8e877e335 path: moved playlist_dir to mapper.c
Added the function map_spl_utf8_to_fs() which replaces
utf8_to_fs_playlist_path().
2008-10-31 16:47:14 +01:00
Max Kellermann
016d996131 utils: use g_str_has_prefix() instead of prefixcmp()
Remove duplicated code from MPD.
2008-10-28 20:33:56 +01:00
Max Kellermann
93598e28f4 stored_playlist: renamed and moved spl_delete() to stored_playlist.c
The function deletePlaylist() shouldn't be in playlist.c.
2008-10-23 09:54:32 +02:00
Max Kellermann
39f0c41fbf stored_playlist: spl_load() returns GPtrArray
Don't use our deprecated linked list library, use GLib's GPtrArray
instead.
2008-10-23 09:54:28 +02:00
Max Kellermann
bc938603f6 playlist: unsigned integers
There are some integers which have a "magic" -1 value which means
"undefined" or "nothing".  All others can be converted to unsigned,
since they must not contain a negative number.
2008-10-23 07:19:46 +02:00
Max Kellermann
1da921f03c stored_playlist: moved functions from playlist.c
The two functions clearStoredPlaylist() and addToStoredPlaylist()
don't belong into playlist.c.  clearStoredPlaylist() was a wrapper for
spl_clear(), and is converted into a CPP macro for now.
2008-10-22 17:23:11 +02:00
Max Kellermann
ac853b6165 stored_playlist: no CamelCase
Renamed all public functions, prefix is "spl_".
2008-10-22 17:21:59 +02:00
Max Kellermann
a4def81313 renamed storedPlaylist.c to stored_playlist.c
No CamelCase in file names.
2008-10-22 17:21:57 +02:00
Max Kellermann
f9222fdabe playlist: also allow world-readable local files
Allow a local user to not only add his own files, but also all
world-readable files (mode 0444).
2008-10-15 23:10:05 +02:00
Max Kellermann
8c0060fae4 playlist: added support for adding songs not in the music database
Clients which have authenticated via unix socket may add local files
to the MPD playlist, provided that they own the file.
2008-10-15 22:35:13 +02:00