00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef LIBMPDCLIENT_H
00034 #define LIBMPDCLIENT_H
00035
00036 #ifdef WIN32
00037 # define __W32API_USE_DLLIMPORT__ 1
00038 #endif
00039
00040 #include <sys/time.h>
00041 #include <stdarg.h>
00042 #define MPD_BUFFER_MAX_LENGTH 50000
00043 #define MPD_ERRORSTR_MAX_LENGTH 1000
00044 #define MPD_WELCOME_MESSAGE "OK MPD "
00045
00046 #define MPD_ERROR_TIMEOUT 10
00047 #define MPD_ERROR_SYSTEM 11
00048 #define MPD_ERROR_UNKHOST 12
00049 #define MPD_ERROR_CONNPORT 13
00050 #define MPD_ERROR_NOTMPD 14
00051 #define MPD_ERROR_NORESPONSE 15
00052 #define MPD_ERROR_SENDING 16
00053 #define MPD_ERROR_CONNCLOSED 17
00054 #define MPD_ERROR_ACK 18
00055 #define MPD_ERROR_BUFFEROVERRUN 19
00056
00057 #define MPD_ACK_ERROR_UNK -1
00058 #define MPD_ERROR_AT_UNK -1
00059
00060 #define MPD_ACK_ERROR_NOT_LIST 1
00061 #define MPD_ACK_ERROR_ARG 2
00062 #define MPD_ACK_ERROR_PASSWORD 3
00063 #define MPD_ACK_ERROR_PERMISSION 4
00064 #define MPD_ACK_ERROR_UNKNOWN_CMD 5
00065
00066 #define MPD_ACK_ERROR_NO_EXIST 50
00067 #define MPD_ACK_ERROR_PLAYLIST_MAX 51
00068 #define MPD_ACK_ERROR_SYSTEM 52
00069 #define MPD_ACK_ERROR_PLAYLIST_LOAD 53
00070 #define MPD_ACK_ERROR_UPDATE_ALREADY 54
00071 #define MPD_ACK_ERROR_PLAYER_SYNC 55
00072 #define MPD_ACK_ERROR_EXIST 56
00073
00074 #ifdef __cplusplus
00075 extern "C" {
00076 #endif
00077
00078 typedef enum mpd_TagItems
00079 {
00080 MPD_TAG_ITEM_ARTIST,
00081 MPD_TAG_ITEM_ALBUM,
00082 MPD_TAG_ITEM_TITLE,
00083 MPD_TAG_ITEM_TRACK,
00084 MPD_TAG_ITEM_NAME,
00085 MPD_TAG_ITEM_GENRE,
00086 MPD_TAG_ITEM_DATE,
00087 MPD_TAG_ITEM_COMPOSER,
00088 MPD_TAG_ITEM_PERFORMER,
00089 MPD_TAG_ITEM_COMMENT,
00090 MPD_TAG_ITEM_DISC,
00091 MPD_TAG_ITEM_FILENAME,
00092 MPD_TAG_ITEM_ALBUM_ARTIST,
00093 MPD_TAG_ITEM_ANY,
00094 MPD_TAG_NUM_OF_ITEM_TYPES
00095 } mpd_TagItems;
00096
00097 extern char * mpdTagItemKeys[MPD_TAG_NUM_OF_ITEM_TYPES];
00098
00099
00100 typedef struct _mpd_ReturnElement {
00101 char * name;
00102 char * value;
00103 } mpd_ReturnElement;
00104
00105
00106
00107
00108
00109 typedef struct _mpd_Connection {
00110
00111 int version[3];
00112
00113 char errorStr[MPD_ERRORSTR_MAX_LENGTH+1];
00114 int errorCode;
00115 int errorAt;
00116
00117 int error;
00118
00119 int sock;
00120 char buffer[MPD_BUFFER_MAX_LENGTH+1];
00121 int buflen;
00122 int bufstart;
00123 int doneProcessing;
00124 int listOks;
00125 int doneListOk;
00126 int commandList;
00127 mpd_ReturnElement * returnElement;
00128 struct timeval timeout;
00129 char *request;
00130 } mpd_Connection;
00131
00132
00133
00134
00135
00136
00137
00138 mpd_Connection * mpd_newConnection(const char * host, int port, float timeout);
00139
00140 void mpd_setConnectionTimeout(mpd_Connection * connection, float timeout);
00141
00142
00143
00144
00145 void mpd_closeConnection(mpd_Connection * connection);
00146
00147
00148
00149
00150 void mpd_clearError(mpd_Connection * connection);
00151
00152
00153
00154
00155 #define MPD_STATUS_STATE_UNKNOWN 0
00156 #define MPD_STATUS_STATE_STOP 1
00157 #define MPD_STATUS_STATE_PLAY 2
00158 #define MPD_STATUS_STATE_PAUSE 3
00159
00160
00161 #define MPD_STATUS_NO_VOLUME -1
00162
00163
00164
00165
00166 typedef struct mpd_Status {
00167
00168 int volume;
00169
00170 int repeat;
00171
00172 int random;
00173
00174 int single;
00175
00176 int consume;
00177
00178 int playlistLength;
00179
00180 long long playlist;
00181
00182 long long storedplaylist;
00183
00184 int state;
00185
00186 int crossfade;
00187
00188
00189
00190
00191 int song;
00192
00193 int songid;
00194
00195
00196 int nextsong;
00197
00198 int nextsongid;
00199
00200
00201
00202
00203 int elapsedTime;
00204
00205 int totalTime;
00206
00207 int bitRate;
00208
00209 unsigned int sampleRate;
00210
00211 int bits;
00212
00213 int channels;
00214
00215 int updatingDb;
00216
00217 char * error;
00218 } mpd_Status;
00219
00220 void mpd_sendStatusCommand(mpd_Connection * connection);
00221
00222
00223
00224
00225
00226 mpd_Status * mpd_getStatus(mpd_Connection * connection);
00227
00228
00229
00230
00231 void mpd_freeStatus(mpd_Status * status);
00232
00233 typedef struct _mpd_Stats {
00234 int numberOfArtists;
00235 int numberOfAlbums;
00236 int numberOfSongs;
00237 unsigned long uptime;
00238 unsigned long dbUpdateTime;
00239 unsigned long playTime;
00240 unsigned long dbPlayTime;
00241 } mpd_Stats;
00242
00243 typedef struct _mpd_SearchStats {
00244 int numberOfSongs;
00245 unsigned long playTime;
00246 } mpd_SearchStats;
00247
00248 void mpd_sendStatsCommand(mpd_Connection * connection);
00249
00250 mpd_Stats * mpd_getStats(mpd_Connection * connection);
00251
00252 void mpd_freeStats(mpd_Stats * stats);
00253
00254 mpd_SearchStats * mpd_getSearchStats(mpd_Connection * connection);
00255
00256 void mpd_freeSearchStats(mpd_SearchStats * stats);
00257
00258
00259
00260 #define MPD_SONG_NO_TIME -1
00261 #define MPD_SONG_NO_NUM -1
00262 #define MPD_SONG_NO_ID -1
00263
00264
00265
00266
00267 typedef struct _mpd_Song {
00268
00269 char * file;
00270
00271 char * artist;
00272
00273 char * title;
00274
00275 char * album;
00276
00277 char * track;
00278
00279
00280 char * name;
00281
00282 char *date;
00283
00284
00285
00286 char *genre;
00287
00288 char *composer;
00289
00290 char *performer;
00291
00292 char *disc;
00293
00294 char *comment;
00295
00296
00297 char *albumartist;
00298
00299 int time;
00300
00301
00302 int pos;
00303
00304 int id;
00305 } mpd_Song;
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315 mpd_Song * mpd_newSong(void);
00316
00317
00318
00319
00320
00321 void mpd_freeSong(mpd_Song * song);
00322
00323
00324
00325
00326 mpd_Song * mpd_songDup(const mpd_Song * song);
00327
00328
00329
00330
00331
00332
00333 typedef struct _mpd_Directory {
00334 char * path;
00335 } mpd_Directory;
00336
00337
00338
00339
00340
00341 mpd_Directory * mpd_newDirectory(void);
00342
00343
00344
00345
00346
00347 void mpd_freeDirectory(mpd_Directory * directory);
00348
00349
00350
00351
00352 mpd_Directory * mpd_directoryDup(mpd_Directory * directory);
00353
00354
00355
00356
00357
00358
00359 typedef struct _mpd_PlaylistFile {
00360 char * path;
00361 char * mtime;
00362 } mpd_PlaylistFile;
00363
00364
00365
00366
00367
00368 mpd_PlaylistFile * mpd_newPlaylistFile(void);
00369
00370
00371
00372
00373
00374 void mpd_freePlaylistFile(mpd_PlaylistFile * playlist);
00375
00376
00377
00378
00379 mpd_PlaylistFile * mpd_playlistFileDup(mpd_PlaylistFile * playlist);
00380
00381
00382
00383
00384
00385
00386 #define MPD_INFO_ENTITY_TYPE_DIRECTORY 0
00387 #define MPD_INFO_ENTITY_TYPE_SONG 1
00388 #define MPD_INFO_ENTITY_TYPE_PLAYLISTFILE 2
00389
00390
00391
00392
00393 typedef struct mpd_InfoEntity {
00394
00395
00396
00397 int type;
00398
00399 union {
00400 mpd_Directory * directory;
00401 mpd_Song * song;
00402 mpd_PlaylistFile * playlistFile;
00403 } info;
00404 } mpd_InfoEntity;
00405
00406 mpd_InfoEntity * mpd_newInfoEntity(void);
00407
00408 void mpd_freeInfoEntity(mpd_InfoEntity * entity);
00409
00410
00411
00412
00413 mpd_InfoEntity * mpd_getNextInfoEntity(mpd_Connection * connection);
00414
00415
00416
00417 void mpd_sendCurrentSongCommand(mpd_Connection * connection);
00418
00419
00420 void mpd_sendPlaylistInfoCommand(mpd_Connection * connection, int songNum);
00421
00422
00423 void mpd_sendPlaylistIdCommand(mpd_Connection * connection, int songId);
00424
00425
00426 void mpd_sendPlChangesCommand(mpd_Connection * connection, long long playlist);
00427
00434 void mpd_sendPlChangesPosIdCommand(mpd_Connection * connection, long long playlist);
00435
00436
00437
00438 void mpd_sendListallCommand(mpd_Connection * connection, const char * dir);
00439
00440
00441 void mpd_sendListallInfoCommand(mpd_Connection * connection, const char * dir);
00442
00443
00444 void mpd_sendLsInfoCommand(mpd_Connection * connection, const char * dir);
00445
00446 #define MPD_TABLE_ARTIST MPD_TAG_ITEM_ARTIST
00447 #define MPD_TABLE_ALBUM MPD_TAG_ITEM_ALBUM
00448 #define MPD_TABLE_TITLE MPD_TAG_ITEM_TITLE
00449 #define MPD_TABLE_FILENAME MPD_TAG_ITEM_FILENAME
00450
00451 void mpd_sendSearchCommand(mpd_Connection * connection, int table,
00452 const char * str);
00453
00454 void mpd_sendFindCommand(mpd_Connection * connection, int table,
00455 const char * str);
00456
00457
00458
00459
00460
00461
00462 char * mpd_getNextArtist(mpd_Connection * connection);
00463
00464 char * mpd_getNextAlbum(mpd_Connection * connection);
00465
00466 char * mpd_getNextTag(mpd_Connection *connection, int type);
00467
00468
00469
00470
00471 void mpd_sendListCommand(mpd_Connection * connection, int table,
00472 const char * arg1);
00473
00474
00475
00476 void mpd_sendAddCommand(mpd_Connection * connection, const char * file);
00477
00478 int mpd_sendAddIdCommand(mpd_Connection *connection, const char *file);
00479
00480 void mpd_sendDeleteCommand(mpd_Connection * connection, int songNum);
00481
00482 void mpd_sendDeleteIdCommand(mpd_Connection * connection, int songNum);
00483
00484 void mpd_sendSaveCommand(mpd_Connection * connection, const char * name);
00485
00486 void mpd_sendLoadCommand(mpd_Connection * connection, const char * name);
00487
00488 void mpd_sendRmCommand(mpd_Connection * connection, const char * name);
00489
00490 void mpd_sendRenameCommand(mpd_Connection *connection, const char *from,
00491 const char *to);
00492
00493 void mpd_sendShuffleCommand(mpd_Connection * connection);
00494
00495 void mpd_sendClearCommand(mpd_Connection * connection);
00496
00497
00498 #define MPD_PLAY_AT_BEGINNING -1
00499
00500 void mpd_sendPlayCommand(mpd_Connection * connection, int songNum);
00501
00502 void mpd_sendPlayIdCommand(mpd_Connection * connection, int songNum);
00503
00504 void mpd_sendStopCommand(mpd_Connection * connection);
00505
00506 void mpd_sendPauseCommand(mpd_Connection * connection, int pauseMode);
00507
00508 void mpd_sendNextCommand(mpd_Connection * connection);
00509
00510 void mpd_sendPrevCommand(mpd_Connection * connection);
00511
00512 void mpd_sendMoveCommand(mpd_Connection * connection, int from, int to);
00513
00514 void mpd_sendMoveIdCommand(mpd_Connection * connection, int from, int to);
00515
00516 void mpd_sendSwapCommand(mpd_Connection * connection, int song1, int song2);
00517
00518 void mpd_sendSwapIdCommand(mpd_Connection * connection, int song1, int song2);
00519
00520 void mpd_sendSeekCommand(mpd_Connection * connection, int song, int seek_time);
00521
00522 void mpd_sendSeekIdCommand(mpd_Connection * connection, int song, int seek_time);
00523
00524 void mpd_sendRepeatCommand(mpd_Connection * connection, int repeatMode);
00525
00526 void mpd_sendSingleCommand(mpd_Connection * connection, int singleMode);
00527
00528 void mpd_sendConsumeCommand(mpd_Connection * connection, int consumeMode);
00529
00530 void mpd_sendRandomCommand(mpd_Connection * connection, int randomMode);
00531
00532 void mpd_sendSetvolCommand(mpd_Connection * connection, int volumeChange);
00533
00534 void mpd_sendCrossfadeCommand(mpd_Connection * connection, int seconds);
00535
00536 void mpd_sendUpdateCommand(mpd_Connection * connection,const char * path);
00537
00538
00539 int mpd_getUpdateId(mpd_Connection * connection);
00540
00541 void mpd_sendPasswordCommand(mpd_Connection * connection, const char * pass);
00542
00543
00544
00545
00546 void mpd_finishCommand(mpd_Connection * connection);
00547
00548
00549 void mpd_sendCommandListBegin(mpd_Connection * connection);
00550
00551 void mpd_sendCommandListOkBegin(mpd_Connection * connection);
00552
00553 void mpd_sendCommandListEnd(mpd_Connection * connection);
00554
00555
00556
00557
00558 int mpd_nextListOkCommand(mpd_Connection * connection);
00559
00560 typedef struct _mpd_OutputEntity {
00561 int id;
00562 char * name;
00563 int enabled;
00564 } mpd_OutputEntity;
00565
00566 void mpd_sendOutputsCommand(mpd_Connection * connection);
00567
00568 mpd_OutputEntity * mpd_getNextOutput(mpd_Connection * connection);
00569
00570 void mpd_sendEnableOutputCommand(mpd_Connection * connection, int outputId);
00571
00572 void mpd_sendDisableOutputCommand(mpd_Connection * connection, int outputId);
00573
00574 void mpd_freeOutputElement(mpd_OutputEntity * output);
00575
00581 void mpd_sendCommandsCommand(mpd_Connection * connection);
00582
00588 void mpd_sendNotCommandsCommand(mpd_Connection * connection);
00589
00597 char *mpd_getNextCommand(mpd_Connection *connection);
00598
00599 void mpd_sendUrlHandlersCommand(mpd_Connection * connection);
00600
00601 char *mpd_getNextHandler(mpd_Connection * connection);
00602
00603 void mpd_sendTagTypesCommand(mpd_Connection * connection);
00604
00605 char *mpd_getNextTagType(mpd_Connection * connection);
00606
00614 void mpd_sendListPlaylistInfoCommand(mpd_Connection *connection,const char *path);
00615
00623 void mpd_sendListPlaylistCommand(mpd_Connection *connection,const char *path);
00624
00632 void mpd_startSearch(mpd_Connection *connection, int exact);
00633
00639 void mpd_addConstraintSearch(mpd_Connection *connection, int type, const char *name);
00640
00644 void mpd_commitSearch(mpd_Connection *connection);
00645
00667 void mpd_startFieldSearch(mpd_Connection *connection, int type);
00668
00669 void mpd_startPlaylistSearch(mpd_Connection *connection, int exact);
00670
00671 void mpd_startStatsSearch(mpd_Connection *connection);
00672
00673 void mpd_sendPlaylistClearCommand(mpd_Connection *connection,const char *path);
00674
00675 void mpd_sendPlaylistAddCommand(mpd_Connection *connection,
00676 const char *playlist,const char *path);
00677
00678 void mpd_sendPlaylistMoveCommand(mpd_Connection *connection,
00679 const char *playlist, int from, int to);
00680
00681 void mpd_sendPlaylistDeleteCommand(mpd_Connection *connection,
00682 const char *playlist, int pos);
00683
00684 void mpd_sendClearErrorCommand(mpd_Connection * connection);
00685
00686 void mpd_sendGetEventsCommand(mpd_Connection *connection);
00687 char * mpd_getNextEvent(mpd_Connection *connection);
00688 void mpd_sendListPlaylistsCommand(mpd_Connection * connection);
00689
00690 char * mpd_getNextSticker (mpd_Connection * connection);
00691
00692 void mpd_sendSetSongSticker(mpd_Connection *connection, const char *song, const char *sticker, const char *value);
00693 void mpd_sendGetSongSticker(mpd_Connection *connection, const char *song, const char *sticker);
00694
00695 void mpd_sendSetReplayGainMode(mpd_Connection *connection, const char *mode);
00696
00697 void mpd_sendReplayGainModeCommand(mpd_Connection *connection);
00698 char *mpd_getReplayGainMode(mpd_Connection *connection);
00699 #ifdef __cplusplus
00700 }
00701 #endif
00702
00703 #endif