aboutsummaryrefslogtreecommitdiffstats
path: root/libmpdclient.c
diff options
context:
space:
mode:
authorKalle Wallin <kaw@linux.se>2004-03-19 14:18:06 +0000
committerKalle Wallin <kaw@linux.se>2004-03-19 14:18:06 +0000
commit430d6194668da5c3e312de1ff368e0a1a9a8b7dc (patch)
tree046f62bc5c1bd45afe8d2b8e54ed36a612deb162 /libmpdclient.c
parentd9ca9697327e2f134901a27f4aa5e2cc454b6caf (diff)
downloadmpd-430d6194668da5c3e312de1ff368e0a1a9a8b7dc.tar.gz
mpd-430d6194668da5c3e312de1ff368e0a1a9a8b7dc.tar.xz
mpd-430d6194668da5c3e312de1ff368e0a1a9a8b7dc.zip
Updated to 0.10.x
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@294 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--libmpdclient.c104
1 files changed, 100 insertions, 4 deletions
diff --git a/libmpdclient.c b/libmpdclient.c
index e3f3b9501..a58ca06e0 100644
--- a/libmpdclient.c
+++ b/libmpdclient.c
@@ -1,5 +1,5 @@
/* libmpdclient
- * (c)2002 by Warren Dukes (shank@mercury.chem.pitt.edu)
+ * (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
@@ -96,8 +96,8 @@ void mpd_freeReturnElement(mpd_ReturnElement * re) {
void mpd_setConnectionTimeout(mpd_Connection * connection, float timeout) {
connection->timeout.tv_sec = (int)timeout;
- connection->timeout.tv_usec = (int)((timeout -
- connection->timeout.tv_sec)/1e+6+0.5);
+ connection->timeout.tv_usec = (int)(timeout*1e6 -
+ connection->timeout.tv_sec*1000000+0.5);
}
mpd_Connection * mpd_newConnection(const char * host, int port, float timeout) {
@@ -243,7 +243,8 @@ mpd_Connection * mpd_newConnection(const char * host, int port, float timeout) {
if(readed<=0) {
snprintf(connection->errorStr,MPD_BUFFER_MAX_LENGTH,
"problems getting a response from"
- " \"%s\" on port %i",host,port);
+ " \"%s\" on port %i",host,
+ port);
connection->error = MPD_ERROR_NORESPONSE;
return connection;
}
@@ -509,6 +510,10 @@ mpd_Status * mpd_getStatus(mpd_Connection * connection) {
status->elapsedTime = 0;
status->totalTime = 0;
status->bitRate = 0;
+ status->sampleRate = 0;
+ status->bits = 0;
+ status->channels = 0;
+ status->crossfade = -1;
status->error = NULL;
mpd_getNextReturnElement(connection);
@@ -564,6 +569,18 @@ mpd_Status * mpd_getStatus(mpd_Connection * connection) {
else if(strcmp(re->name,"error")==0) {
status->error = strdup(re->value);
}
+ else if(strcmp(re->name,"xfade")==0) {
+ status->crossfade = atoi(re->value);
+ }
+ else if(strcmp(re->name,"audio")==0) {
+ char * tok;
+ char * copy;
+ copy = strdup(re->value);
+ status->sampleRate = atoi(strtok_r(copy,":",&tok));
+ status->bits = atoi(strtok_r(NULL,":",&tok));
+ status->channels = atoi(strtok_r(NULL,"",&tok));
+ free(copy);
+ }
mpd_getNextReturnElement(connection);
if(connection->error) {
@@ -591,6 +608,62 @@ void mpd_freeStatus(mpd_Status * status) {
free(status);
}
+mpd_Stats * mpd_getStats(mpd_Connection * connection) {
+ mpd_Stats * stats;
+
+ mpd_executeCommand(connection,"stats\n");
+
+ if(connection->error) return NULL;
+
+ stats = malloc(sizeof(mpd_Stats));
+ stats->numberOfArtists = 0;
+ stats->numberOfAlbums = 0;
+ stats->numberOfSongs = 0;
+ stats->uptime = 0;
+ stats->dbUpdateTime = 0;
+
+ mpd_getNextReturnElement(connection);
+ if(connection->error) {
+ free(stats);
+ return NULL;
+ }
+ while(connection->returnElement) {
+ mpd_ReturnElement * re = connection->returnElement;
+ if(strcmp(re->name,"artists")==0) {
+ stats->numberOfArtists = atoi(re->value);
+ }
+ else if(strcmp(re->name,"albums")==0) {
+ stats->numberOfAlbums = atoi(re->value);
+ }
+ else if(strcmp(re->name,"songs")==0) {
+ stats->numberOfSongs = atoi(re->value);
+ }
+ else if(strcmp(re->name,"uptime")==0) {
+ stats->uptime = strtol(re->value,NULL,10);
+ }
+ else if(strcmp(re->name,"db_update")==0) {
+ stats->dbUpdateTime = strtol(re->value,NULL,10);
+ }
+
+ mpd_getNextReturnElement(connection);
+ if(connection->error) {
+ free(stats);
+ return NULL;
+ }
+ }
+
+ if(connection->error) {
+ free(stats);
+ return NULL;
+ }
+
+ return stats;
+}
+
+void mpd_freeStats(mpd_Stats * stats) {
+ free(stats);
+}
+
void mpd_initSong(mpd_Song * song) {
song->file = NULL;
song->artist = NULL;
@@ -1048,6 +1121,13 @@ void mpd_sendRandomCommand(mpd_Connection * connection, int randomMode) {
free(string);
}
+void mpd_sendSetvolCommand(mpd_Connection * connection, int volumeChange) {
+ char * string = malloc(strlen("setvol")+25);
+ sprintf(string,"setvol \"%i\"\n",volumeChange);
+ mpd_executeCommand(connection,string);
+ free(string);
+}
+
void mpd_sendVolumeCommand(mpd_Connection * connection, int volumeChange) {
char * string = malloc(strlen("volume")+25);
sprintf(string,"volume \"%i\"\n",volumeChange);
@@ -1055,6 +1135,22 @@ void mpd_sendVolumeCommand(mpd_Connection * connection, int volumeChange) {
free(string);
}
+void mpd_sendCrossfadeCommand(mpd_Connection * connection, int seconds) {
+ char * string = malloc(strlen("crossfade")+25);
+ sprintf(string,"crossfade \"%i\"\n",seconds);
+ mpd_executeCommand(connection,string);
+ free(string);
+}
+
+void mpd_sendPasswordCommand(mpd_Connection * connection, const char * pass) {
+ char * sPass = mpd_sanitizeArg(pass);
+ char * string = malloc(strlen("password")+strlen(sPass)+5);
+ sprintf(string,"password \"%s\"\n",sPass);
+ mpd_executeCommand(connection,string);
+ free(string);
+ free(sPass);
+}
+
void mpd_sendCommandListBegin(mpd_Connection * connection) {
if(connection->commandList) {
strcpy(connection->errorStr,"already in command list mode");