Code

screen: don't set list_window->repaint
[ncmpc.git] / src / libmpdclient.h
index 04b70fd948b3e6a85ad04482e5fc045d3b95b871..7928944763a8eda7886a67bc9f4479181eb3f1e0 100644 (file)
@@ -1,22 +1,22 @@
 /* libmpdclient
-   (c)2003-2004 by Warren Dukes (shank@mercury.chem.pitt.edu)
+   (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
    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 "song.h"
+
+#ifdef WIN32
+#  define __W32API_USE_DLLIMPORT__ 1
+#endif
+
 #include <sys/time.h>
+#include <stddef.h>
 
-#define MPD_BUFFER_MAX_LENGTH  50000
 #define MPD_WELCOME_MESSAGE    "OK MPD "
 
 #define MPD_ERROR_TIMEOUT      10 /* timeout trying to talk to mpd */
 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;
@@ -85,22 +109,23 @@ typedef struct _mpd_Connection {
        /* use this to check the version of mpd */
        int version[3];
        /* IMPORTANT, you want to get the error messages from here */
-       char errorStr[MPD_BUFFER_MAX_LENGTH+1];
+       char errorStr[512];
        int errorCode;
        int errorAt;
        /* 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; 
-       char buffer[MPD_BUFFER_MAX_LENGTH+1];
-       int buflen;
-       int bufstart;
+       int sock;
+       char buffer[16384];
+       size_t buflen;
+       size_t bufstart;
        int doneProcessing;
        int listOks;
        int doneListOk;
        int commandList;
        mpd_ReturnElement * returnElement;
        struct timeval timeout;
+       char *request;
 } mpd_Connection;
 
 /* mpd_newConnection
@@ -208,59 +233,6 @@ mpd_Stats * mpd_getStats(mpd_Connection * connection);
 
 void mpd_freeStats(mpd_Stats * stats);
 
-/* SONG STUFF */
-
-#define MPD_SONG_NO_TIME       -1
-#define MPD_SONG_NO_NUM                -1
-#define MPD_SONG_NO_ID         -1
-
-/* mpd_Song
- * for storing song info returned by mpd
- */
-typedef struct _mpd_Song {
-       /* filename of song */
-       char * file;
-       /* artist, maybe NULL if there is no tag */
-       char * artist;
-       /* title, maybe NULL if there is no tag */
-       char * title;
-       /* album, maybe NULL if there is no tag */
-       char * album;
-       /* track, maybe NULL if there is no tag */
-       char * track;
-       /* 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;
-       /* length of song in seconds, check that it is not MPD_SONG_NO_TIME  */
-       int time;
-       /* 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;
-
-/* mpd_newSong
- * use to allocate memory for a new mpd_Song
- * file, artist, etc all initialized to NULL
- * if your going to assign values to file, artist, etc
- * be sure to malloc or strdup the memory
- * 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_freeSong
- * use to free memory allocated by mpd_newSong
- * also it will free memory pointed to by file, artist, etc, so be careful
- */
-void mpd_freeSong(mpd_Song * song);
-
-/* mpd_songDup
- * works like strDup, but for a mpd_Song
- */
-mpd_Song * mpd_songDup(mpd_Song * song);
-
 /* DIRECTORY STUFF */
 
 /* mpd_Directory
@@ -274,7 +246,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
@@ -300,7 +272,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
@@ -338,7 +310,7 @@ typedef struct mpd_InfoEntity {
        } info;
 } mpd_InfoEntity;
 
-mpd_InfoEntity * mpd_newInfoEntity();
+mpd_InfoEntity * mpd_newInfoEntity(void);
 
 void mpd_freeInfoEntity(mpd_InfoEntity * entity);
 
@@ -354,10 +326,21 @@ 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);
 
-/* recursivel fetches all songs/dir/playlists in "dir* (no metadata is 
+/**
+ * @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);
 
@@ -372,25 +355,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 */
@@ -449,7 +434,7 @@ void mpd_sendVolumeCommand(mpd_Connection * connection, int volumeChange);
 
 void mpd_sendCrossfadeCommand(mpd_Connection * connection, int seconds);
 
-void mpd_sendUpdateCommand(mpd_Connection * connection, char * path);
+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);
@@ -468,11 +453,107 @@ void mpd_sendCommandListOkBegin(mpd_Connection * connection);
 
 void mpd_sendCommandListEnd(mpd_Connection * connection);
 
-/* advance to the next listOk 
+/* 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