Code

don't use libncursesw if libncurses was selected
[ncmpc.git] / src / libmpdclient.h
index 1b5f02dfe4c2533b4cf1e54cf0a1ab1db91f42f5..fe1991edc28f1f63d03e991b1e5ba0be8001fb8b 100644 (file)
@@ -1,27 +1,44 @@
 /* libmpdclient
- * (c)2003-2004 by Warren Dukes (shank@mercury.chem.pitt.edu)
- * This project's homepage is: http://www.musicpd.org
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library 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 Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser 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
- */
+   (c)2003-2006 by Warren Dukes (warren.dukes@gmail.com)
+   This project's homepage is: http://www.musicpd.org
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+
+   - Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+
+   - Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+   - Neither the name of the Music Player Daemon nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
 
 #ifndef LIBMPDCLIENT_H
 #define LIBMPDCLIENT_H
 
-#include <sys/time.h>
+#ifdef WIN32
+#  define __W32API_USE_DLLIMPORT__ 1
+#endif
 
+#include <sys/time.h>
+#include <stdarg.h>
 #define MPD_BUFFER_MAX_LENGTH  50000
 #define MPD_WELCOME_MESSAGE    "OK MPD "
 
 #define MPD_ACK_ERROR_PASSWORD                 3
 #define MPD_ACK_ERROR_PERMISSION               4
 #define MPD_ACK_ERROR_UNKNOWN_CMD              5
-#define MPD_ACK_ERROR_NO_EXIST                 6
-#define MPD_ACK_ERROR_PLAYLIST_MAX             7
-#define MPD_ACK_ERROR_SYSTEM                   8
-#define MPD_ACK_ERROR_PLAYLIST_LOAD            9
-#define MPD_ACK_ERROR_UPDATE_ALREADY           10
-#define MPD_ACK_ERROR_PLAYER_SYNC              11
+
+#define MPD_ACK_ERROR_NO_EXIST                 50
+#define MPD_ACK_ERROR_PLAYLIST_MAX             51
+#define MPD_ACK_ERROR_SYSTEM                   52
+#define MPD_ACK_ERROR_PLAYLIST_LOAD            53
+#define MPD_ACK_ERROR_UPDATE_ALREADY           54
+#define MPD_ACK_ERROR_PLAYER_SYNC              55
+#define MPD_ACK_ERROR_EXIST                    56
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+typedef enum mpd_TagItems
+{
+       MPD_TAG_ITEM_ARTIST,
+       MPD_TAG_ITEM_ALBUM,
+       MPD_TAG_ITEM_TITLE,
+       MPD_TAG_ITEM_TRACK,
+       MPD_TAG_ITEM_NAME,
+       MPD_TAG_ITEM_GENRE,
+       MPD_TAG_ITEM_DATE,
+       MPD_TAG_ITEM_COMPOSER,
+       MPD_TAG_ITEM_PERFORMER,
+       MPD_TAG_ITEM_COMMENT,
+       MPD_TAG_ITEM_DISC,
+       MPD_TAG_ITEM_FILENAME,
+       MPD_TAG_NUM_OF_ITEM_TYPES
+}mpd_TagItems;
+
+extern const char *const mpdTagItemKeys[MPD_TAG_NUM_OF_ITEM_TYPES];
+
 /* internal stuff don't touch this struct */
 typedef struct _mpd_ReturnElement {
        char * name;
@@ -75,7 +113,7 @@ typedef struct _mpd_Connection {
        /* this will be set to MPD_ERROR_* if there is an error, 0 if not */
        int error;
        /* DON'T TOUCH any of the rest of this stuff */
-       int sock; 
+       int sock;
        char buffer[MPD_BUFFER_MAX_LENGTH+1];
        int buflen;
        int bufstart;
@@ -85,6 +123,7 @@ typedef struct _mpd_Connection {
        int commandList;
        mpd_ReturnElement * returnElement;
        struct timeval timeout;
+       char *request;
 } mpd_Connection;
 
 /* mpd_newConnection
@@ -136,10 +175,12 @@ typedef struct mpd_Status {
        int state;
        /* crossfade setting in seconds */
        int crossfade;
-       /* if in PLAY or PAUSE state, this is the position of the currently
+       /* if a song is currently selected (always the case when state is
+        * PLAY or PAUSE), this is the position of the currently
         * playing song in the playlist, beginning with 0
         */
        int song;
+       /* Song ID of the currently selected song */
        int songid;
        /* time in seconds that have elapsed in the currently playing/paused
         * song
@@ -165,6 +206,7 @@ void mpd_sendStatusCommand(mpd_Connection * connection);
 
 /* mpd_getStatus
  * returns status info, be sure to free it with mpd_freeStatus()
+ * call this after mpd_sendStatusCommand()
  */
 mpd_Status * mpd_getStatus(mpd_Connection * connection);
 
@@ -212,11 +254,25 @@ typedef struct _mpd_Song {
        /* name, maybe NULL if there is no tag; it's the name of the current
         * song, f.e. the icyName of the stream */
        char * name;
+       /* date */
+       char *date;
+
+       /* added by qball */
+       /* Genre */
+       char *genre;
+       /* Composer */
+       char *composer;
+       /* Disc */
+       char *disc;
+       /* Comment */
+       char *comment;
+
        /* length of song in seconds, check that it is not MPD_SONG_NO_TIME  */
        int time;
-       /* if plchanges or playlistinfo used, is the position of the song in
-        * the playlist */
+       /* if plchanges/playlistinfo/playlistid used, is the position of the
+        * song in the playlist */
        int pos;
+       /* song id for a song in the playlist */
        int id;
 } mpd_Song;
 
@@ -228,7 +284,7 @@ typedef struct _mpd_Song {
  * use mpd_freeSong to free the memory for the mpd_Song, it will also
  * free memory for file, artist, etc, so don't do it yourself
  */
-mpd_Song * mpd_newSong();
+mpd_Song * mpd_newSong(void);
 
 /* mpd_freeSong
  * use to free memory allocated by mpd_newSong
@@ -254,7 +310,7 @@ typedef struct _mpd_Directory {
  * allocates memory for a new directory
  * use mpd_freeDirectory to free this memory
  */
-mpd_Directory * mpd_newDirectory ();
+mpd_Directory * mpd_newDirectory(void);
 
 /* mpd_freeDirectory
  * used to free memory allocated with mpd_newDirectory, and it frees
@@ -280,7 +336,7 @@ typedef struct _mpd_PlaylistFile {
  * allocates memory for new mpd_PlaylistFile, path is set to NULL
  * free this memory with mpd_freePlaylistFile
  */
-mpd_PlaylistFile * mpd_newPlaylistFile();
+mpd_PlaylistFile * mpd_newPlaylistFile(void);
 
 /* mpd_freePlaylist
  * free memory allocated for freePlaylistFile, will also free
@@ -318,7 +374,7 @@ typedef struct mpd_InfoEntity {
        } info;
 } mpd_InfoEntity;
 
-mpd_InfoEntity * mpd_newInfoEntity();
+mpd_InfoEntity * mpd_newInfoEntity(void);
 
 void mpd_freeInfoEntity(mpd_InfoEntity * entity);
 
@@ -327,18 +383,35 @@ void mpd_freeInfoEntity(mpd_InfoEntity * entity);
 /* use this function to loop over after calling Info/Listall functions */
 mpd_InfoEntity * mpd_getNextInfoEntity(mpd_Connection * connection);
 
+/* fetches the currently seeletect song (the song referenced by status->song
+ * and status->songid*/
 void mpd_sendCurrentSongCommand(mpd_Connection * connection);
 
 /* songNum of -1, means to display the whole list */
 void mpd_sendPlaylistInfoCommand(mpd_Connection * connection, int songNum);
 
+/* songId of -1, means to display the whole list */
+void mpd_sendPlaylistIdCommand(mpd_Connection * connection, int songId);
+
 /* use this to get the changes in the playlist since version _playlist_ */
 void mpd_sendPlChangesCommand(mpd_Connection * connection, long long playlist);
 
+/**
+ * @param connection: A valid and connected mpd_Connection.
+ * @param playlist: The playlist version you want the diff with.
+ * A more bandwidth efficient version of the mpd_sendPlChangesCommand.
+ * It only returns the pos+id of the changes song.
+ */
+void mpd_sendPlChangesPosIdCommand(mpd_Connection * connection, long long playlist);
+
+/* recursivel fetches all songs/dir/playlists in "dir* (no metadata is
+ * returned) */
 void mpd_sendListallCommand(mpd_Connection * connection, const char * dir);
 
+/* same as sendListallCommand, but also metadata is returned */
 void mpd_sendListallInfoCommand(mpd_Connection * connection, const char * dir);
 
+/* non-recursive version of ListallInfo */
 void mpd_sendLsInfoCommand(mpd_Connection * connection, const char * dir);
 
 #define MPD_TABLE_ARTIST       0
@@ -346,25 +419,27 @@ void mpd_sendLsInfoCommand(mpd_Connection * connection, const char * dir);
 #define MPD_TABLE_TITLE                2
 #define MPD_TABLE_FILENAME     3
 
-void mpd_sendSearchCommand(mpd_Connection * connection, int table, 
+void mpd_sendSearchCommand(mpd_Connection * connection, int table,
                const char * str);
 
-void mpd_sendFindCommand(mpd_Connection * connection, int table, 
+void mpd_sendFindCommand(mpd_Connection * connection, int table,
                const char * str);
 
 /* LIST TAG COMMANDS */
 
-/* use this function fetch next artist entry, be sure to free the returned 
+/* use this function fetch next artist entry, be sure to free the returned
  * string.  NULL means there are no more.  Best used with sendListArtists
  */
 char * mpd_getNextArtist(mpd_Connection * connection);
 
 char * mpd_getNextAlbum(mpd_Connection * connection);
 
+char * mpd_getNextTag(mpd_Connection *connection, int table);
+
 /* list artist or albums by artist, arg1 should be set to the artist if
  * listing albums by a artist, otherwise NULL for listing all artists or albums
  */
-void mpd_sendListCommand(mpd_Connection * connection, int table, 
+void mpd_sendListCommand(mpd_Connection * connection, int table,
                const char * arg1);
 
 /* SIMPLE COMMANDS */
@@ -423,7 +498,7 @@ void mpd_sendVolumeCommand(mpd_Connection * connection, int volumeChange);
 
 void mpd_sendCrossfadeCommand(mpd_Connection * connection, int seconds);
 
-void mpd_sendUpdateCommand(mpd_Connection * connection);
+void mpd_sendUpdateCommand(mpd_Connection * connection, const char *path);
 
 /* returns the update job id, call this after a update command*/
 int mpd_getUpdateId(mpd_Connection * connection);
@@ -442,8 +517,107 @@ void mpd_sendCommandListOkBegin(mpd_Connection * connection);
 
 void mpd_sendCommandListEnd(mpd_Connection * connection);
 
+/* advance to the next listOk
+ * returns 0 if advanced to the next list_OK,
+ * returns -1 if it advanced to an OK or ACK */
 int mpd_nextListOkCommand(mpd_Connection * connection);
 
+typedef struct _mpd_OutputEntity {
+       int id;
+       char * name;
+       int enabled;
+} mpd_OutputEntity;
+
+void mpd_sendOutputsCommand(mpd_Connection * connection);
+
+mpd_OutputEntity * mpd_getNextOutput(mpd_Connection * connection);
+
+void mpd_sendEnableOutputCommand(mpd_Connection * connection, int outputId);
+
+void mpd_sendDisableOutputCommand(mpd_Connection * connection, int outputId);
+
+void mpd_freeOutputElement(mpd_OutputEntity * output);
+
+/**
+ * @param connection a #mpd_Connection
+ *
+ * Queries mpd for the allowed commands
+ */
+void mpd_sendCommandsCommand(mpd_Connection * connection);
+/**
+ * @param connection a #mpd_Connection
+ *
+ * Queries mpd for the not allowed commands
+ */
+void mpd_sendNotCommandsCommand(mpd_Connection * connection);
+
+/**
+ * @param connection a #mpd_Connection
+ *
+ * returns the next supported command.
+ *
+ * @returns a string, needs to be free'ed
+ */
+char *mpd_getNextCommand(mpd_Connection *connection);
+
+/**
+ * @param connection a MpdConnection
+ * @param path the path to the playlist.
+ *
+ * List the content, with full metadata, of a stored playlist.
+ *
+ */
+void mpd_sendListPlaylistInfoCommand(mpd_Connection *connection, char *path);
+/**
+ * @param connection a MpdConnection
+ * @param path the path to the playlist.
+ *
+ * List the content of a stored playlist.
+ *
+ */
+void mpd_sendListPlaylistCommand(mpd_Connection *connection, char *path);
+
+/**
+ * @param connection a #mpd_Connection
+ * @param exact if to match exact
+ *
+ * starts a search, use mpd_addConstraintSearch to add
+ * a constraint to the search, and mpd_commitSearch to do the actual search
+ */
+void mpd_startSearch(mpd_Connection * connection,int exact);
+/**
+ * @param connection a #mpd_Connection
+ * @param field
+ * @param name
+ *
+ */
+void mpd_addConstraintSearch(mpd_Connection *connection, int field, char *name);
+/**
+ * @param connection a #mpd_Connection
+ *
+ */
+void mpd_commitSearch(mpd_Connection *connection);
+
+/**
+ * @param connection a #mpd_Connection
+ * @param field The field to search
+ *
+ * starts a search for fields... f.e. get a list of artists would be:
+ * mpd_startFieldSearch(connection, MPD_TAG_ITEM_ARTIST);
+ * mpd_commitSearch(connection);
+ *
+ * or get a list of artist in genre "jazz" would be:
+ * @code
+ * mpd_startFieldSearch(connection, MPD_TAG_ITEM_ARTIST);
+ * mpd_addConstraintSearch(connection, MPD_TAG_ITEM_GENRE, "jazz")
+ * mpd_commitSearch(connection);
+ * @endcode
+ *
+ * mpd_startSearch will return  a list of songs (and you need mpd_getNextInfoEntity)
+ * this one will return a list of only one field (the field specified with field) and you need
+ * mpd_getNextTag to get the results
+ */
+void mpd_startFieldSearch(mpd_Connection * connection,int field);
 #ifdef __cplusplus
 }
 #endif