Commit 6cfe421c authored by J. Alexander Treuman's avatar J. Alexander Treuman

Committing pat's rewrite of the stored playlist code. This also adds two

new commands: playlistmove and playlistdelete. git-svn-id: https://svn.musicpd.org/mpd/trunk@6116 09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent 6f68587a
......@@ -18,6 +18,8 @@ ver 0.13.0 (2007/??/??)
* Fix a bug where no ACK was returned if loading a playlist failed
* Fix a bug where db_update in stats would be 0 after initial database creation
* New count command for getting stats on found songs (similar to "find")
* New playlistmove command for moving songs in stored playlists
* New playlistdelete command for deleting songs from stored playlists
* Lots of bug fixes, cleaned up code, and performance improvements
ver 0.12.2 (2007/3/20)
......
......@@ -40,12 +40,8 @@
*) abstract out state code from playlist.c
*) put MPD Version in statefile
*) rewrite saved playlist code
*) abstract out saved playlists from playlist.c
*) new commands
*) replace <playlist> /* replace current playlist
with saved playlist and
keep playing */
*) add playlistreplace command (replace current playlist with saved playlist
and keep playing)
*) add command for inserting songs in a specific position
......
......@@ -74,7 +74,8 @@ mpd_headers = \
utils.h \
volume.h \
zeroconf.h \
locate.h
locate.h \
storedPlaylist.h
mpd_SOURCES = \
......@@ -125,7 +126,8 @@ mpd_SOURCES = \
volume.c \
utf8.c \
zeroconf.c \
locate.c
locate.c \
storedPlaylist.c
mpd_CFLAGS = $(MPD_CFLAGS)
......
......@@ -30,6 +30,7 @@
#include "log.h"
#include "tag.h"
#include "utils.h"
#include "storedPlaylist.h"
#include <assert.h>
#include <stdarg.h>
......@@ -95,6 +96,8 @@
#define COMMAND_PLAYLISTADD "playlistadd"
#define COMMAND_PLAYLISTFIND "playlistfind"
#define COMMAND_PLAYLISTSEARCH "playlistsearch"
#define COMMAND_PLAYLISTMOVE "playlistmove"
#define COMMAND_PLAYLISTDELETE "playlistdelete"
#define COMMAND_TAGTYPES "tagtypes"
#define COMMAND_COUNT "count"
......@@ -578,6 +581,43 @@ static int handlePlaylistSearch(int fd, int *permission, int argc, char *argv[])
return 0;
}
static int handlePlaylistDelete(int fd, int *permission, int argc, char *argv[]) {
char *playlist = argv[1];
int from;
char *test;
from = strtol(argv[2], &test, 10);
if (*test != '\0') {
commandError(fd, ACK_ERROR_ARG,
"\"%s\" is not a integer", argv[2]);
return -1;
}
return removeOneSongFromStoredPlaylistByPath(fd, playlist, from);
}
static int handlePlaylistMove(int fd, int *permission, int argc, char *argv[])
{
char *playlist = argv[1];
int from, to;
char *test;
from = strtol(argv[2], &test, 10);
if (*test != '\0') {
commandError(fd, ACK_ERROR_ARG,
"\"%s\" is not a integer", argv[2]);
return -1;
}
to = strtol(argv[3], &test, 10);
if (*test != '\0') {
commandError(fd, ACK_ERROR_ARG,
"\"%s\" is not a integer", argv[3]);
return -1;
}
return moveSongInStoredPlaylistByPath(fd, playlist, from, to);
}
static int listHandleUpdate(int fd,
int *permission,
int argc,
......@@ -1072,6 +1112,8 @@ void initCommands(void)
addCommand(COMMAND_PLAYLISTADD, PERMISSION_CONTROL, 2, 2, handlePlaylistAdd, NULL);
addCommand(COMMAND_PLAYLISTFIND, PERMISSION_READ, 2, -1, handlePlaylistFind, NULL);
addCommand(COMMAND_PLAYLISTSEARCH, PERMISSION_READ, 2, -1, handlePlaylistSearch, NULL);
addCommand(COMMAND_PLAYLISTMOVE, PERMISSION_CONTROL, 3, 3, handlePlaylistMove, NULL);
addCommand(COMMAND_PLAYLISTDELETE, PERMISSION_CONTROL, 2, 2, handlePlaylistDelete, NULL);
addCommand(COMMAND_TAGTYPES, PERMISSION_READ, 0, 0, handleTagTypes, NULL);
addCommand(COMMAND_COUNT, PERMISSION_READ, 2, -1, handleCount, NULL);
......
......@@ -26,6 +26,7 @@
#include "tag.h"
#include "tagTracker.h"
#include "log.h"
#include "storedPlaylist.h"
typedef struct _ListCommandItem {
mpd_sint8 tagType;
......@@ -177,7 +178,9 @@ static int directoryAddSongToPlaylist(int fd, Song * song, void *data)
static int directoryAddSongToStoredPlaylist(int fd, Song *song, void *data)
{
return addSongToStoredPlaylist(fd, song, (char *)data);
if (appendSongToStoredPlaylistByPath(fd, (char *)data, song) != 0)
return -1;
return 0;
}
int addAllIn(int fd, char *name)
......
......@@ -28,6 +28,24 @@
#include <time.h>
#define PLAYLIST_FILE_SUFFIX "m3u"
#define PLAYLIST_COMMENT '#'
typedef struct _Playlist {
Song **songs;
/* holds version a song was modified on */
mpd_uint32 *songMod;
int *order;
int *positionToId;
int *idToPosition;
int length;
int current;
int queued;
int repeat;
int random;
mpd_uint32 version;
} Playlist;
extern int playlist_saveAbsolutePaths;
void initPlaylist(void);
......@@ -47,8 +65,6 @@ int addToStoredPlaylist(int fd, char *file, char *utf8file);
int addSongToPlaylist(int fd, Song * song, int printId);
int addSongToStoredPlaylist(int fd, Song *song, char *utf8file);
int showPlaylist(int fd);
int deleteFromPlaylist(int fd, int song);
......
/* the Music Player Daemon (MPD)
* Copyright (C) 2007 by Warren Dukes (warren.dukes@gmail.com)
* This project's homepage is: http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef STORED_PLAYLIST_H
#define STORED_PLAYLIST_H
#include "song.h"
#include "list.h"
#include "playlist.h"
typedef struct _storedPlaylist {
List *list;
unsigned int length;
char *fspath;
int fd;
} StoredPlaylist;
StoredPlaylist *newStoredPlaylist(const char *filename, int fd, int ignoreExisting);
StoredPlaylist *loadStoredPlaylist(const char *utf8path, int fd);
void freeStoredPlaylist(StoredPlaylist *sp);
int moveSongInStoredPlaylistByPath(int fd, const char *utf8path, int src, int dest);
int removeAllFromStoredPlaylistByPath(int fd, const char *utf8path);
int removeOneSongFromStoredPlaylistByPath(int fd, const char *utf8path, int pos);
int writeStoredPlaylist(StoredPlaylist *sp);
int appendSongToStoredPlaylistByPath(int fd, const char *utf8path, Song *song);
void appendPlaylistToStoredPlaylist(StoredPlaylist *sp, Playlist *playlist);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment