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 playlistLength;
00175
00176 long long playlist;
00177
00178 long long storedplaylist;
00179
00180 int state;
00181
00182 int crossfade;
00183
00184
00185
00186
00187 int song;
00188
00189 int songid;
00190
00191
00192
00193 int elapsedTime;
00194
00195 int totalTime;
00196
00197 int bitRate;
00198
00199 unsigned int sampleRate;
00200
00201 int bits;
00202
00203 int channels;
00204
00205 int updatingDb;
00206
00207 char * error;
00208 } mpd_Status;
00209
00210 void mpd_sendStatusCommand(mpd_Connection * connection);
00211
00212
00213
00214
00215
00216 mpd_Status * mpd_getStatus(mpd_Connection * connection);
00217
00218
00219
00220
00221 void mpd_freeStatus(mpd_Status * status);
00222
00223 typedef struct _mpd_Stats {
00224 int numberOfArtists;
00225 int numberOfAlbums;
00226 int numberOfSongs;
00227 unsigned long uptime;
00228 unsigned long dbUpdateTime;
00229 unsigned long playTime;
00230 unsigned long dbPlayTime;
00231 } mpd_Stats;
00232
00233 typedef struct _mpd_SearchStats {
00234 int numberOfSongs;
00235 unsigned long playTime;
00236 } mpd_SearchStats;
00237
00238 void mpd_sendStatsCommand(mpd_Connection * connection);
00239
00240 mpd_Stats * mpd_getStats(mpd_Connection * connection);
00241
00242 void mpd_freeStats(mpd_Stats * stats);
00243
00244 mpd_SearchStats * mpd_getSearchStats(mpd_Connection * connection);
00245
00246 void mpd_freeSearchStats(mpd_SearchStats * stats);
00247
00248
00249
00250 #define MPD_SONG_NO_TIME -1
00251 #define MPD_SONG_NO_NUM -1
00252 #define MPD_SONG_NO_ID -1
00253
00254
00255
00256
00257 typedef struct _mpd_Song {
00258
00259 char * file;
00260
00261 char * artist;
00262
00263 char * title;
00264
00265 char * album;
00266
00267 char * track;
00268
00269
00270 char * name;
00271
00272 char *date;
00273
00274
00275
00276 char *genre;
00277
00278 char *composer;
00279
00280 char *performer;
00281
00282 char *disc;
00283
00284 char *comment;
00285
00286
00287 char *albumartist;
00288
00289 int time;
00290
00291
00292 int pos;
00293
00294 int id;
00295 } mpd_Song;
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 mpd_Song * mpd_newSong(void);
00306
00307
00308
00309
00310
00311 void mpd_freeSong(mpd_Song * song);
00312
00313
00314
00315
00316 mpd_Song * mpd_songDup(const mpd_Song * song);
00317
00318
00319
00320
00321
00322
00323 typedef struct _mpd_Directory {
00324 char * path;
00325 } mpd_Directory;
00326
00327
00328
00329
00330
00331 mpd_Directory * mpd_newDirectory(void);
00332
00333
00334
00335
00336
00337 void mpd_freeDirectory(mpd_Directory * directory);
00338
00339
00340
00341
00342 mpd_Directory * mpd_directoryDup(mpd_Directory * directory);
00343
00344
00345
00346
00347
00348
00349 typedef struct _mpd_PlaylistFile {
00350 char * path;
00351 char * mtime;
00352 } mpd_PlaylistFile;
00353
00354
00355
00356
00357
00358 mpd_PlaylistFile * mpd_newPlaylistFile(void);
00359
00360
00361
00362
00363
00364 void mpd_freePlaylistFile(mpd_PlaylistFile * playlist);
00365
00366
00367
00368
00369 mpd_PlaylistFile * mpd_playlistFileDup(mpd_PlaylistFile * playlist);
00370
00371
00372
00373
00374
00375
00376 #define MPD_INFO_ENTITY_TYPE_DIRECTORY 0
00377 #define MPD_INFO_ENTITY_TYPE_SONG 1
00378 #define MPD_INFO_ENTITY_TYPE_PLAYLISTFILE 2
00379
00380
00381
00382
00383 typedef struct mpd_InfoEntity {
00384
00385
00386
00387 int type;
00388
00389 union {
00390 mpd_Directory * directory;
00391 mpd_Song * song;
00392 mpd_PlaylistFile * playlistFile;
00393 } info;
00394 } mpd_InfoEntity;
00395
00396 mpd_InfoEntity * mpd_newInfoEntity(void);
00397
00398 void mpd_freeInfoEntity(mpd_InfoEntity * entity);
00399
00400
00401
00402
00403 mpd_InfoEntity * mpd_getNextInfoEntity(mpd_Connection * connection);
00404
00405
00406
00407 void mpd_sendCurrentSongCommand(mpd_Connection * connection);
00408
00409
00410 void mpd_sendPlaylistInfoCommand(mpd_Connection * connection, int songNum);
00411
00412
00413 void mpd_sendPlaylistIdCommand(mpd_Connection * connection, int songId);
00414
00415
00416 void mpd_sendPlChangesCommand(mpd_Connection * connection, long long playlist);
00417
00424 void mpd_sendPlChangesPosIdCommand(mpd_Connection * connection, long long playlist);
00425
00426
00427
00428 void mpd_sendListallCommand(mpd_Connection * connection, const char * dir);
00429
00430
00431 void mpd_sendListallInfoCommand(mpd_Connection * connection, const char * dir);
00432
00433
00434 void mpd_sendLsInfoCommand(mpd_Connection * connection, const char * dir);
00435
00436 #define MPD_TABLE_ARTIST MPD_TAG_ITEM_ARTIST
00437 #define MPD_TABLE_ALBUM MPD_TAG_ITEM_ALBUM
00438 #define MPD_TABLE_TITLE MPD_TAG_ITEM_TITLE
00439 #define MPD_TABLE_FILENAME MPD_TAG_ITEM_FILENAME
00440
00441 void mpd_sendSearchCommand(mpd_Connection * connection, int table,
00442 const char * str);
00443
00444 void mpd_sendFindCommand(mpd_Connection * connection, int table,
00445 const char * str);
00446
00447
00448
00449
00450
00451
00452 char * mpd_getNextArtist(mpd_Connection * connection);
00453
00454 char * mpd_getNextAlbum(mpd_Connection * connection);
00455
00456 char * mpd_getNextTag(mpd_Connection *connection, int type);
00457
00458
00459
00460
00461 void mpd_sendListCommand(mpd_Connection * connection, int table,
00462 const char * arg1);
00463
00464
00465
00466 void mpd_sendAddCommand(mpd_Connection * connection, const char * file);
00467
00468 int mpd_sendAddIdCommand(mpd_Connection *connection, const char *file);
00469
00470 void mpd_sendDeleteCommand(mpd_Connection * connection, int songNum);
00471
00472 void mpd_sendDeleteIdCommand(mpd_Connection * connection, int songNum);
00473
00474 void mpd_sendSaveCommand(mpd_Connection * connection, const char * name);
00475
00476 void mpd_sendLoadCommand(mpd_Connection * connection, const char * name);
00477
00478 void mpd_sendRmCommand(mpd_Connection * connection, const char * name);
00479
00480 void mpd_sendRenameCommand(mpd_Connection *connection, const char *from,
00481 const char *to);
00482
00483 void mpd_sendShuffleCommand(mpd_Connection * connection);
00484
00485 void mpd_sendClearCommand(mpd_Connection * connection);
00486
00487
00488 #define MPD_PLAY_AT_BEGINNING -1
00489
00490 void mpd_sendPlayCommand(mpd_Connection * connection, int songNum);
00491
00492 void mpd_sendPlayIdCommand(mpd_Connection * connection, int songNum);
00493
00494 void mpd_sendStopCommand(mpd_Connection * connection);
00495
00496 void mpd_sendPauseCommand(mpd_Connection * connection, int pauseMode);
00497
00498 void mpd_sendNextCommand(mpd_Connection * connection);
00499
00500 void mpd_sendPrevCommand(mpd_Connection * connection);
00501
00502 void mpd_sendMoveCommand(mpd_Connection * connection, int from, int to);
00503
00504 void mpd_sendMoveIdCommand(mpd_Connection * connection, int from, int to);
00505
00506 void mpd_sendSwapCommand(mpd_Connection * connection, int song1, int song2);
00507
00508 void mpd_sendSwapIdCommand(mpd_Connection * connection, int song1, int song2);
00509
00510 void mpd_sendSeekCommand(mpd_Connection * connection, int song, int time);
00511
00512 void mpd_sendSeekIdCommand(mpd_Connection * connection, int song, int time);
00513
00514 void mpd_sendRepeatCommand(mpd_Connection * connection, int repeatMode);
00515
00516 void mpd_sendRandomCommand(mpd_Connection * connection, int randomMode);
00517
00518 void mpd_sendSetvolCommand(mpd_Connection * connection, int volumeChange);
00519
00520
00521 void mpd_sendVolumeCommand(mpd_Connection * connection, int volumeChange);
00522
00523 void mpd_sendCrossfadeCommand(mpd_Connection * connection, int seconds);
00524
00525 void mpd_sendUpdateCommand(mpd_Connection * connection,const char * path);
00526
00527
00528 int mpd_getUpdateId(mpd_Connection * connection);
00529
00530 void mpd_sendPasswordCommand(mpd_Connection * connection, const char * pass);
00531
00532
00533
00534
00535 void mpd_finishCommand(mpd_Connection * connection);
00536
00537
00538 void mpd_sendCommandListBegin(mpd_Connection * connection);
00539
00540 void mpd_sendCommandListOkBegin(mpd_Connection * connection);
00541
00542 void mpd_sendCommandListEnd(mpd_Connection * connection);
00543
00544
00545
00546
00547 int mpd_nextListOkCommand(mpd_Connection * connection);
00548
00549 typedef struct _mpd_OutputEntity {
00550 int id;
00551 char * name;
00552 int enabled;
00553 } mpd_OutputEntity;
00554
00555 void mpd_sendOutputsCommand(mpd_Connection * connection);
00556
00557 mpd_OutputEntity * mpd_getNextOutput(mpd_Connection * connection);
00558
00559 void mpd_sendEnableOutputCommand(mpd_Connection * connection, int outputId);
00560
00561 void mpd_sendDisableOutputCommand(mpd_Connection * connection, int outputId);
00562
00563 void mpd_freeOutputElement(mpd_OutputEntity * output);
00564
00570 void mpd_sendCommandsCommand(mpd_Connection * connection);
00571
00577 void mpd_sendNotCommandsCommand(mpd_Connection * connection);
00578
00586 char *mpd_getNextCommand(mpd_Connection *connection);
00587
00588 void mpd_sendUrlHandlersCommand(mpd_Connection * connection);
00589
00590 char *mpd_getNextHandler(mpd_Connection * connection);
00591
00592 void mpd_sendTagTypesCommand(mpd_Connection * connection);
00593
00594 char *mpd_getNextTagType(mpd_Connection * connection);
00595
00603 void mpd_sendListPlaylistInfoCommand(mpd_Connection *connection,const char *path);
00604
00612 void mpd_sendListPlaylistCommand(mpd_Connection *connection,const char *path);
00613
00621 void mpd_startSearch(mpd_Connection *connection, int exact);
00622
00628 void mpd_addConstraintSearch(mpd_Connection *connection, int type, const char *name);
00629
00633 void mpd_commitSearch(mpd_Connection *connection);
00634
00656 void mpd_startFieldSearch(mpd_Connection *connection, int type);
00657
00658 void mpd_startPlaylistSearch(mpd_Connection *connection, int exact);
00659
00660 void mpd_startStatsSearch(mpd_Connection *connection);
00661
00662 void mpd_sendPlaylistClearCommand(mpd_Connection *connection,const char *path);
00663
00664 void mpd_sendPlaylistAddCommand(mpd_Connection *connection,
00665 const char *playlist,const char *path);
00666
00667 void mpd_sendPlaylistMoveCommand(mpd_Connection *connection,
00668 const char *playlist, int from, int to);
00669
00670 void mpd_sendPlaylistDeleteCommand(mpd_Connection *connection,
00671 const char *playlist, int pos);
00672
00673 void mpd_sendClearErrorCommand(mpd_Connection * connection);
00674
00675 void mpd_sendGetEventsCommand(mpd_Connection *connection);
00676 char * mpd_getNextEvent(mpd_Connection *connection);
00677 void mpd_sendListPlaylistsCommand(mpd_Connection * connection);
00678
00679 char * mpd_getNextSticker (mpd_Connection * connection);
00680
00681 void mpd_sendSetSongSticker(mpd_Connection *connection, const char *song, const char *sticker, const char *value);
00682 void mpd_sendGetSongSticker(mpd_Connection *connection, const char *song, const char *sticker);
00683
00684 #ifdef __cplusplus
00685 }
00686 #endif
00687
00688 #endif