int cmd_playlist(mpd_unused int argc, mpd_unused char **argv, mpd_Connection *conn) { mpd_InfoEntity * entity; mpd_Status * status; int count = 0; mpd_sendStatusCommand(conn); printErrorAndExit(conn); status = mpd_getStatus(conn); printErrorAndExit(conn); mpd_finishCommand(conn); mpd_sendPlaylistInfoCommand(conn,-1); printErrorAndExit(conn); while((entity = mpd_getNextInfoEntity(conn))) { if(entity->type==MPD_INFO_ENTITY_TYPE_SONG) { struct mpd_song *song = entity->info.song; printf("%s%i) ", (status->song == count)?">":" ", 1+count); pretty_print_song(song); printf("\n"); count++; } mpd_freeInfoEntity(entity); } my_finishCommand(conn); mpd_freeStatus(status); return 0; }
/******************** Song ingo retrival ************************************/ static int getSong(void) { mpd_Status *status; mpd_InfoEntity *info; /* Get status */ mpd_sendStatusCommand(D.conn); if (error()) return 0; status = mpd_getStatus(D.conn); if (error()) return 0; pdie_on(!status, "get status"); mpd_nextListOkCommand(D.conn); if (error()) { mpd_freeStatus(status); return 0; } /* Copy status */ D.cur.state = status->state; D.cur.songid = status->songid; D.cur.pos = status->elapsedTime; D.cur.len = status->totalTime; mpd_freeStatus(status); /* Same song, return */ if (D.cur.songid == D.old.songid) { return 1; } if (D.info) { mpd_freeInfoEntity(D.info); D.info = 0; } /* Get song */ mpd_sendCurrentSongCommand(D.conn); if (error()) { return 0; } info = mpd_getNextInfoEntity(D.conn); if (error()) { return 0; } if (!info) { return D.cur.state == MPD_STATUS_STATE_PLAY || D.cur.state == MPD_STATUS_STATE_PAUSE; } if (info->type != MPD_INFO_ENTITY_TYPE_SONG) { mpd_freeInfoEntity(info); return 0; } D.info = info; return 1; }
/* ================= MPD_Status - show info about currently playing song ================= */ void MPD_Status(void) { mpd_Status *status; mpd_InfoEntity *entity = NULL; mpd_Song *song = 0; char title[MP3_MAXSONGTITLE]; if(!MP3_Status()) return; mpd_sendStatusCommand(conn); if( (status = mpd_getStatus(conn)) == NULL) { Com_Printf("MPD: %s\n", conn->errorStr); mpd_finishCommand(conn); return; } mpd_finishCommand(conn); if( status->state == MPD_STATUS_STATE_STOP) { /* Playback stopped */ Com_Printf("MPD: not playing\n"); mpd_freeStatus(status); return; } if( status->state == MPD_STATUS_STATE_PLAY || MPD_STATUS_STATE_PAUSE ) { mpd_sendCurrentSongCommand(conn); while((entity = mpd_getNextInfoEntity(conn))) { if(entity->type != MPD_INFO_ENTITY_TYPE_SONG) { mpd_freeInfoEntity(entity); continue; } song = entity->info.song; if(song->title == NULL || song->artist == NULL) Com_sprintf(title, sizeof(title), "%s [%i:%02i]", (song->title) ? song->title : song->file, status->totalTime / 60, status->totalTime % 60); else Com_sprintf(title, sizeof(title), "%s - %s [%i:%02i]", song->artist, song->title, status->totalTime / 60, status->totalTime % 60); COM_MakePrintable(title); Com_Printf("%s\n", title); mpd_freeInfoEntity(entity); break; } mpd_finishCommand(conn); } mpd_freeStatus(status); }
void mpdGetSongTitle() { mpd_InfoEntity * entity; mpd_sendCommandListOkBegin(conn); mpd_sendStatusCommand(conn); mpd_sendCurrentSongCommand(conn); mpd_sendCommandListEnd(conn); if((status = mpd_getStatus(conn))==NULL) { fprintf(stderr,"%s\n",conn->errorStr); mpd_closeConnection(conn); } songname = (char *)malloc(100); mpd_nextListOkCommand(conn); while((entity = mpd_getNextInfoEntity(conn))) { mpd_Song * song = entity->info.song; if(entity->type!=MPD_INFO_ENTITY_TYPE_SONG) { mpd_freeInfoEntity(entity); continue; } if(song->artist) { strcpy(songname, " ["); strcat(songname, song->artist); strcat(songname, " - "); } if(song->album) { strcat(songname, song->album); strcat(songname, " - "); } if(song->title) { songname = strcat(songname, song->title); songname = strcat(songname, "] "); } mpd_freeInfoEntity(entity); } if(conn->error) { fprintf(stderr,"%s\n",conn->errorStr); mpd_closeConnection(conn); } mpd_finishCommand(conn); if(conn->error) { fprintf(stderr,"%s\n",conn->errorStr); mpd_closeConnection(conn); } }
static int mpdclient_playlist_update(void *data) { mpd_Status * status; mpd_InfoEntity *entity; int i; mpd_sendCommandListOkBegin(conn); mpd_sendStatusCommand(conn); mpd_sendPlChangesCommand(conn, cur_playlist); mpd_sendCommandListEnd(conn); if((status = mpd_getStatus(conn))==NULL) { fprintf(stderr,"%s\n",conn->errorStr); mpd_closeConnection(conn); return 1; } cur_playlist = status->playlist; cur_song = status->songid; mpd_nextListOkCommand(conn); evas_event_freeze(evas); while((entity = mpd_getNextInfoEntity(conn))) { if(entity->type!=MPD_INFO_ENTITY_TYPE_SONG) { mpd_freeInfoEntity(entity); continue; } music_song_insert(entity->info.song); mpd_freeInfoEntity(entity); } for (i = status->playlistLength; i < music_song_count(); i++) { music_song_remove(i); } if (status->state == MPD_STATUS_STATE_PLAY || status->state == MPD_STATUS_STATE_PAUSE) { music_song_update(status->song, status->totalTime); } else { music_song_update(-1, 0); } layout_update(status->state == MPD_STATUS_STATE_PLAY, status->volume); evas_event_thaw(evas); mpd_finishCommand(conn); mpd_freeStatus(status); return 1; }
MPDStatus MPDConnection::status() { if (!isConnected()) return MPDStatus(); Q_ASSERT(d->connection); mpd_call(MPDConnection::status, Status); mpd_Status *status = mpd_getStatus(d->connection); if (!finishCommand() || !status) return MPDStatus(); MPDStatus ret(status); mpd_freeStatus(status); return ret; }
static mpd_Status * getStatus(mpd_Connection * conn) { mpd_Status * ret; mpd_sendStatusCommand(conn); printErrorAndExit(conn); ret = mpd_getStatus(conn); printErrorAndExit(conn); mpd_finishCommand(conn); printErrorAndExit(conn); return ret; }
static char *MPD_SongTitle ( void ) { mpd_Status *status; mpd_InfoEntity *entity = NULL; mpd_Song *song = 0; static char title[MP3_MAXSONGTITLE]; title[0] = 0; if(!MP3_Status()) return title; mpd_sendCommandListOkBegin(conn); mpd_sendStatusCommand(conn); mpd_sendCurrentSongCommand(conn); mpd_sendCommandListEnd(conn); if( (status = mpd_getStatus(conn)) == NULL) { return title; } mpd_nextListOkCommand(conn); while((entity = mpd_getNextInfoEntity(conn))) { if(entity->type != MPD_INFO_ENTITY_TYPE_SONG) { mpd_freeInfoEntity(entity); continue; } song = entity->info.song; if(song->title == NULL || song->artist == NULL) Com_sprintf(title, sizeof(title), "%s [%i:%02i]", song->file, status->totalTime / 60, status->totalTime % 60); else Com_sprintf(title, sizeof(title), "%s - %s [%i:%02i]", song->artist, song->title, status->totalTime / 60, status->totalTime % 60); COM_MakePrintable(title); mpd_freeInfoEntity(entity); break; } mpd_freeStatus(status); mpd_finishCommand(conn); return title; }
int cmd_current(mpd_unused int argc, mpd_unused char ** argv, mpd_Connection *conn) { mpd_Status * status; mpd_InfoEntity * entity; mpd_sendCommandListOkBegin(conn); printErrorAndExit(conn); mpd_sendStatusCommand(conn); printErrorAndExit(conn); mpd_sendCurrentSongCommand(conn); printErrorAndExit(conn); mpd_sendCommandListEnd(conn); printErrorAndExit(conn); status = mpd_getStatus(conn); printErrorAndExit(conn); if (status->state == MPD_STATUS_STATE_PLAY || status->state == MPD_STATUS_STATE_PAUSE) { mpd_nextListOkCommand(conn); printErrorAndExit(conn); while((entity = mpd_getNextInfoEntity(conn))) { struct mpd_song *song = entity->info.song; if(entity->type!=MPD_INFO_ENTITY_TYPE_SONG) { mpd_freeInfoEntity(entity); continue; } pretty_print_song(song); printf("\n"); mpd_freeInfoEntity(entity); break; } printErrorAndExit(conn); mpd_finishCommand(conn); printErrorAndExit(conn); } mpd_freeStatus(status); return 0; }
/* ================= MPD_SetVol - set volume ================= */ void MPD_SetVol(void) { mpd_Status *status; if(!MP3_Status()) return; if(Cmd_Argc() < 2) { mpd_sendStatusCommand(conn); if( (status = mpd_getStatus(conn)) == NULL) { Com_Printf("MPD: %s\n", conn->errorStr); } else { Com_Printf("MPD: volume %i\%\n", status->volume); mpd_freeStatus(status); } mpd_finishCommand(conn); } else {
void mpdclient_pause(int state) { mpd_Status *status; if (state == 1) { mpd_sendPauseCommand(conn, state); mpd_finishCommand(conn); return; } /* If we are stopped, start playing */ mpd_sendStatusCommand(conn); status = mpd_getStatus(conn); if (status->state == MPD_STATUS_STATE_STOP && status->playlistLength > 0) { mpd_sendPlayCommand(conn, 0); //music_song_active(0); //music_playlist_autoscroll(0, 1); } else mpd_sendPauseCommand(conn, 0); mpd_finishCommand(conn); }
void MpdClient::update() { mpd_Status *old = status; mpd_sendStatusCommand(conn); status = mpd_getStatus(conn); assert(status); mpd_finishCommand(conn); if (!(old && old->playlist == status->playlist)) { if (old) updatePlaylist(old->playlist); else updatePlaylist(-1); if (currentSong()) emit(playingSong(currentSong())); } else if (old->song == status->song && currentSong()) emit(playingSong(currentSong())); }
static void *update_mpd_thread(void *arg) { static mpd_Connection *conn = NULL; mpd_Status *status; mpd_InfoEntity *entity; timed_thread *me = *(timed_thread **)arg; const char *emptystr = ""; while (1) { if (!conn) conn = mpd_newConnection(mpd_host, mpd_port, 10); if (*mpd_password) { mpd_sendPasswordCommand(conn, mpd_password); mpd_finishCommand(conn); } timed_thread_lock(me); if (conn->error || conn == NULL) { NORM_ERR("MPD error: %s\n", conn->errorStr); mpd_closeConnection(conn); conn = 0; clear_mpd(); mpd_info.status = "MPD not responding"; timed_thread_unlock(me); if (timed_thread_test(me, 0)) { timed_thread_exit(me); } continue; } mpd_sendStatusCommand(conn); if ((status = mpd_getStatus(conn)) == NULL) { NORM_ERR("MPD error: %s\n", conn->errorStr); mpd_closeConnection(conn); conn = 0; clear_mpd(); mpd_info.status = "MPD not responding"; timed_thread_unlock(me); if (timed_thread_test(me, 0)) { timed_thread_exit(me); } continue; } mpd_finishCommand(conn); if (conn->error) { // fprintf(stderr, "%s\n", conn->errorStr); mpd_closeConnection(conn); conn = 0; timed_thread_unlock(me); if (timed_thread_test(me, 0)) { timed_thread_exit(me); } continue; } mpd_info.vol = status->volume; if (status->random == 0) { mpd_info.random = "Off"; } else if (status->random == 1) { mpd_info.random = "On"; } else { mpd_info.random = ""; } if (status->repeat == 0) { mpd_info.repeat = "Off"; } else if (status->repeat == 1) { mpd_info.repeat = "On"; } else { mpd_info.repeat = ""; } /* if (status->error) { printf("error: %s\n", status->error); } */ switch (status->state) { case MPD_STATUS_STATE_PLAY: mpd_info.status = "Playing"; break; case MPD_STATUS_STATE_STOP: mpd_info.status = "Stopped"; break; case MPD_STATUS_STATE_PAUSE: mpd_info.status = "Paused"; break; default: mpd_info.status = ""; clear_mpd(); break; } if (status->state == MPD_STATUS_STATE_PLAY || status->state == MPD_STATUS_STATE_PAUSE) { mpd_info.is_playing = 1; mpd_info.bitrate = status->bitRate; mpd_info.progress = (float) status->elapsedTime / status->totalTime; mpd_info.elapsed = status->elapsedTime; mpd_info.length = status->totalTime; } else { mpd_info.progress = 0; mpd_info.is_playing = 0; mpd_info.elapsed = 0; } if (conn->error) { // fprintf(stderr, "%s\n", conn->errorStr); mpd_closeConnection(conn); conn = 0; timed_thread_unlock(me); if (timed_thread_test(me, 0)) { timed_thread_exit(me); } continue; } mpd_sendCurrentSongCommand(conn); while ((entity = mpd_getNextInfoEntity(conn))) { mpd_Song *song = entity->info.song; if (entity->type != MPD_INFO_ENTITY_TYPE_SONG) { mpd_freeInfoEntity(entity); continue; } #define SONGSET(x) { \ free(mpd_info.x); \ if(song->x) \ mpd_info.x = strmdup(song->x); \ else \ mpd_info.x = strmdup(emptystr); \ } SONGSET(artist); SONGSET(albumartist); SONGSET(album); SONGSET(title); SONGSET(date); SONGSET(track); SONGSET(name); SONGSET(file); #undef SONGSET if (entity != NULL) { mpd_freeInfoEntity(entity); entity = NULL; } } mpd_finishCommand(conn); if (conn->error) { // fprintf(stderr, "%s\n", conn->errorStr); mpd_closeConnection(conn); conn = 0; timed_thread_unlock(me); if (timed_thread_test(me, 0)) { timed_thread_exit(me); } continue; } timed_thread_unlock(me); if (conn->error) { // fprintf(stderr, "%s\n", conn->errorStr); mpd_closeConnection(conn); conn = 0; if (timed_thread_test(me, 0)) { timed_thread_exit(me); } continue; } mpd_freeStatus(status); /* if (conn) { mpd_closeConnection(conn); conn = 0; } */ if (timed_thread_test(me, 0)) { timed_thread_exit(me); } continue; } /* never reached */ }
int mpd_status_update(MpdObj *mi) { ChangedStatusType what_changed=0; if(!mpd_check_connected(mi)) { debug_printf(DEBUG_INFO,"not connected\n"); return MPD_NOT_CONNECTED; } if(mpd_lock_conn(mi)) { debug_printf(DEBUG_ERROR,"lock failed\n"); return MPD_LOCK_FAILED; } if(mi->status != NULL) { mpd_freeStatus(mi->status); mi->status = NULL; } mpd_sendStatusCommand(mi->connection); mi->status = mpd_getStatus(mi->connection); if(mi->status == NULL) { debug_printf(DEBUG_ERROR,"Failed to grab status from mpd\n"); mpd_unlock_conn(mi); return MPD_STATUS_FAILED; } if(mpd_unlock_conn(mi)) { debug_printf(DEBUG_ERROR, "Failed to unlock"); return MPD_LOCK_FAILED; } /* * check for changes */ /* first save the old status */ memcpy(&(mi->OldState), &(mi->CurrentState), sizeof(MpdServerState)); /* playlist change */ if(mi->CurrentState.playlistid != mi->status->playlist) { /* print debug message */ debug_printf(DEBUG_INFO, "Playlist has changed!"); /* We can't trust the current song anymore. so we remove it */ /* tags might have been updated */ if(mi->CurrentSong != NULL) { mpd_freeSong(mi->CurrentSong); mi->CurrentSong = NULL; } /* set MPD_CST_PLAYLIST to be changed */ what_changed |= MPD_CST_PLAYLIST; if(mi->CurrentState.playlistLength == mi->status->playlistLength) { // what_changed |= MPD_CST_SONGID; } /* save new id */ mi->CurrentState.playlistid = mi->status->playlist; } if(mi->CurrentState.storedplaylistid != mi->status->storedplaylist) { /* set MPD_CST_QUEUE to be changed */ what_changed |= MPD_CST_STORED_PLAYLIST; /* save new id */ mi->CurrentState.storedplaylistid = mi->status->storedplaylist; } /* state change */ if(mi->CurrentState.state != mi->status->state) { what_changed |= MPD_CST_STATE; mi->CurrentState.state = mi->status->state; } if(mi->CurrentState.songid != mi->status->songid) { /* print debug message */ debug_printf(DEBUG_INFO, "Songid has changed %i %i!", mi->OldState.songid, mi->status->songid); what_changed |= MPD_CST_SONGID; /* save new songid */ mi->CurrentState.songid = mi->status->songid; } if(mi->CurrentState.songpos != mi->status->song) { /* print debug message */ debug_printf(DEBUG_INFO, "Songpos has changed %i %i!", mi->OldState.songpos, mi->status->song); what_changed |= MPD_CST_SONGPOS; /* save new songid */ mi->CurrentState.songpos = mi->status->song; } if(mi->CurrentState.nextsongid != mi->status->nextsongid || mi->CurrentState.nextsongpos != mi->status->nextsong) { what_changed |= MPD_CST_NEXTSONG; /* save new songid */ mi->CurrentState.nextsongpos = mi->status->nextsong; mi->CurrentState.nextsongid = mi->status->nextsongid; } if(mi->CurrentState.single != mi->status->single) { what_changed |= MPD_CST_SINGLE_MODE; mi->CurrentState.single = mi->status->single; } if(mi->CurrentState.consume != mi->status->consume) { what_changed |= MPD_CST_CONSUME_MODE; mi->CurrentState.consume = mi->status->consume; } if(mi->CurrentState.repeat != mi->status->repeat) { what_changed |= MPD_CST_REPEAT; mi->CurrentState.repeat = mi->status->repeat; } if(mi->CurrentState.random != mi->status->random) { what_changed |= MPD_CST_RANDOM; mi->CurrentState.random = mi->status->random; } if(mi->CurrentState.volume != mi->status->volume) { what_changed |= MPD_CST_VOLUME; mi->CurrentState.volume = mi->status->volume; } if(mi->CurrentState.xfade != mi->status->crossfade) { what_changed |= MPD_CST_CROSSFADE; mi->CurrentState.xfade = mi->status->crossfade; } if(mi->CurrentState.totaltime != mi->status->totalTime) { what_changed |= MPD_CST_TOTAL_TIME; mi->CurrentState.totaltime = mi->status->totalTime; } if(mi->CurrentState.elapsedtime != mi->status->elapsedTime) { what_changed |= MPD_CST_ELAPSED_TIME; mi->CurrentState.elapsedtime = mi->status->elapsedTime; } /* Check if bitrate changed, happens with vbr encodings. */ if(mi->CurrentState.bitrate != mi->status->bitRate) { what_changed |= MPD_CST_BITRATE; mi->CurrentState.bitrate = mi->status->bitRate; } /* The following 3 probly only happen on a song change, or is it possible in one song/stream? */ /* Check if the sample rate changed */ if(mi->CurrentState.samplerate != mi->status->sampleRate) { what_changed |= MPD_CST_AUDIOFORMAT; mi->CurrentState.samplerate = mi->status->sampleRate; } /* check if the sampling depth changed */ if(mi->CurrentState.bits != mi->status->bits) { what_changed |= MPD_CST_AUDIOFORMAT; mi->CurrentState.bits = mi->status->bits; } /* Check if the amount of audio channels changed */ if(mi->CurrentState.channels != mi->status->channels) { what_changed |= MPD_CST_AUDIOFORMAT; mi->CurrentState.channels = mi->status->channels; } if(mi->status->error) { what_changed |= MPD_CST_SERVER_ERROR; strcpy(mi->CurrentState.error,mi->status->error); mpd_sendClearErrorCommand(mi->connection); mpd_finishCommand(mi->connection); } else { mi->CurrentState.error[0] ='\0'; } /* Check if the updating changed, * If it stopped, also update the stats for the new db-time. */ if(mi->CurrentState.updatingDb != mi->status->updatingDb ) { what_changed |= MPD_CST_UPDATING; if(!mi->status->updatingDb) { mpd_stats_update_real(mi, &what_changed); } mi->CurrentState.updatingDb = mi->status->updatingDb; } mi->CurrentState.playlistLength = mi->status->playlistLength; /* Detect changed outputs */ if(!mi->has_idle) { if(mi->num_outputs >0 ) { mpd_OutputEntity *output = NULL; mpd_sendOutputsCommand(mi->connection); while (( output = mpd_getNextOutput(mi->connection)) != NULL) { if(mi->num_outputs < output->id) { mi->num_outputs++; mi->output_states = realloc(mi->output_states,mi->num_outputs*sizeof(int)); mi->output_states[mi->num_outputs] = output->enabled; what_changed |= MPD_CST_OUTPUT; } if(mi->output_states[output->id] != output->enabled) { mi->output_states[output->id] = output->enabled; what_changed |= MPD_CST_OUTPUT; } mpd_freeOutputElement(output); } mpd_finishCommand(mi->connection); } else { /* if no outputs, lets fetch them */ mpd_server_update_outputs(mi); if(mi->num_outputs == 0) { assert("No outputs defined? that cannot be\n"); } what_changed |= MPD_CST_OUTPUT; } }else { char *name; int update_stats = 0; mpd_sendGetEventsCommand(mi->connection); while((name = mpd_getNextEvent(mi->connection))){ if(strcmp(name, "output") == 0){ what_changed |= MPD_CST_OUTPUT; }else if (strcmp(name, "database") == 0) { if((what_changed&MPD_CST_DATABASE) == 0) { update_stats = 1; } what_changed |= MPD_CST_DATABASE; }else if (strcmp(name, "stored_playlist")==0) { what_changed |= MPD_CST_STORED_PLAYLIST; }else if (strcmp(name, "tag") == 0) { what_changed |= MPD_CST_PLAYLIST; }else if (strcmp (name, "sticker") == 0) { what_changed |= MPD_CST_STICKER; } free(name); } mpd_finishCommand(mi->connection); if(update_stats) { mpd_stats_update_real(mi, &what_changed); } } /* Run the callback */ if((mi->the_status_changed_callback != NULL) && what_changed) { mi->the_status_changed_callback( mi, what_changed, mi->the_status_changed_signal_userdata ); } /* We could have lost connection again during signal handling... so before we return check again if we are connected */ if(!mpd_check_connected(mi)) { return MPD_NOT_CONNECTED; } return MPD_OK; }
int mpd_status_update(MpdObj *mi) { ChangedStatusType what_changed=0; if(!mpd_check_connected(mi)) { debug_printf(DEBUG_INFO,"Where not connected\n"); return MPD_NOT_CONNECTED; } if(mpd_lock_conn(mi)) { debug_printf(DEBUG_ERROR,"lock failed\n"); return MPD_LOCK_FAILED; } if(mi->status != NULL) { mpd_freeStatus(mi->status); mi->status = NULL; } mpd_sendStatusCommand(mi->connection); mi->status = mpd_getStatus(mi->connection); if(mi->status == NULL) { debug_printf(DEBUG_ERROR,"Failed to grab status from mpd\n"); mpd_unlock_conn(mi); return MPD_STATUS_FAILED; } if(mpd_unlock_conn(mi)) { debug_printf(DEBUG_ERROR, "Failed to unlock"); return MPD_LOCK_FAILED; } /* * check for changes */ /* first save the old status */ memcpy(&(mi->OldState), &(mi->CurrentState), sizeof(MpdServerState)); /* playlist change */ if(mi->CurrentState.playlistid != mi->status->playlist) { /* print debug message */ debug_printf(DEBUG_INFO, "Playlist has changed!"); /* We can't trust the current song anymore. so we remove it */ /* tags might have been updated */ if(mi->CurrentSong != NULL) { mpd_freeSong(mi->CurrentSong); mi->CurrentSong = NULL; } /* set MPD_CST_PLAYLIST to be changed */ what_changed |= MPD_CST_PLAYLIST; /* save new id */ mi->CurrentState.playlistid = mi->status->playlist; } /* state change */ if(mi->CurrentState.state != mi->status->state) { what_changed |= MPD_CST_STATE; mi->CurrentState.state = mi->status->state; } if(mi->CurrentState.songid != mi->status->songid) { /* print debug message */ debug_printf(DEBUG_INFO, "Song has changed %i %i!", mi->OldState.songid, mi->status->songid); what_changed |= MPD_CST_SONGID; /* save new songid */ mi->CurrentState.songid = mi->status->songid; } if(mi->CurrentState.songpos != mi->status->song) { /* print debug message */ debug_printf(DEBUG_INFO, "Song has changed %i %i!", mi->OldState.songpos, mi->status->song); what_changed |= MPD_CST_SONGPOS; /* save new songid */ mi->CurrentState.songpos = mi->status->song; } if(mi->CurrentState.repeat != mi->status->repeat) { what_changed |= MPD_CST_REPEAT; mi->CurrentState.repeat = mi->status->repeat; } if(mi->CurrentState.random != mi->status->random) { what_changed |= MPD_CST_RANDOM; mi->CurrentState.random = mi->status->random; } if(mi->CurrentState.volume != mi->status->volume) { what_changed |= MPD_CST_VOLUME; mi->CurrentState.volume = mi->status->volume; } if(mi->CurrentState.xfade != mi->status->crossfade) { what_changed |= MPD_CST_CROSSFADE; mi->CurrentState.xfade = mi->status->crossfade; } if(mi->CurrentState.totaltime != mi->status->totalTime) { what_changed |= MPD_CST_TOTAL_TIME; mi->CurrentState.totaltime = mi->status->totalTime; } if(mi->CurrentState.elapsedtime != mi->status->elapsedTime) { what_changed |= MPD_CST_ELAPSED_TIME; mi->CurrentState.elapsedtime = mi->status->elapsedTime; } /* Check if bitrate changed, happens with vbr encodings. */ if(mi->CurrentState.bitrate != mi->status->bitRate) { what_changed |= MPD_CST_BITRATE; mi->CurrentState.bitrate = mi->status->bitRate; } /* The following 3 probly only happen on a song change, or is it possible in one song/stream? */ /* Check if the sample rate changed */ if(mi->CurrentState.samplerate != mi->status->sampleRate) { what_changed |= MPD_CST_AUDIOFORMAT; mi->CurrentState.samplerate = mi->status->sampleRate; } /* check if the sampling depth changed */ if(mi->CurrentState.bits != mi->status->bits) { what_changed |= MPD_CST_AUDIOFORMAT; mi->CurrentState.bits = mi->status->bits; } /* Check if the amount of audio channels changed */ if(mi->CurrentState.channels != mi->status->channels) { what_changed |= MPD_CST_AUDIOFORMAT; mi->CurrentState.channels = mi->status->channels; } /* Check if the updating changed, * If it stopped, also update the stats for the new db-time. */ if(mi->CurrentState.updatingDb != mi->status->updatingDb ) { what_changed |= MPD_CST_UPDATING; if(!mi->status->updatingDb) { mpd_stats_update_real(mi, &what_changed); } mi->CurrentState.updatingDb = mi->status->updatingDb; } /* Run the callback */ if((mi->the_status_changed_callback != NULL) && what_changed) { mi->the_status_changed_callback( mi, what_changed, mi->the_status_changed_signal_userdata ); } /* We could have lost connection again during signal handling... so before we return check again if we are connected */ if(!mpd_check_connected(mi)) { return MPD_NOT_CONNECTED; } return MPD_OK; }
static void _mpdule_update_song (Instance * inst) { mpd_Connection *mpd; Evas_Object *mpdule; Evas_Object *o_popup; if (!inst->mpd) return; mpd = inst->mpd; mpdule = inst->mpdule; o_popup = inst->o_popup; mpd_sendStatusCommand (mpd); if (mpd->error == 0) { mpd_Status *status = mpd_getStatus (mpd); if (status) { if (status->state == MPD_STATUS_STATE_UNKNOWN) { edje_object_part_text_set (mpdule, "mpdule.status", D_ ("Unknown")); edje_object_part_text_set (o_popup, "mpdule.status", D_ ("Unknown")); } else if (status->state == MPD_STATUS_STATE_STOP) { edje_object_part_text_set (mpdule, "mpdule.status", D_ ("Stopped")); edje_object_part_text_set (o_popup, "mpdule.status", D_ ("Stopped")); } else if (status->state == MPD_STATUS_STATE_PLAY) { edje_object_part_text_set (mpdule, "mpdule.status", D_ ("Playing")); edje_object_part_text_set (o_popup, "mpdule.status", D_ ("Playing")); } else if (status->state == MPD_STATUS_STATE_PAUSE) { edje_object_part_text_set (mpdule, "mpdule.status", D_ ("Paused")); edje_object_part_text_set (o_popup, "mpdule.status", D_ ("Paused")); } if (status->state > MPD_STATUS_STATE_STOP) { mpd_sendCurrentSongCommand (mpd); mpd_InfoEntity *entity = NULL; while ((entity = mpd_getNextInfoEntity (mpd))) { if (entity->type == MPD_INFO_ENTITY_TYPE_SONG && entity->info.song->id == status->songid) { mpd_Song *song = entity->info.song; if (song->artist) { edje_object_part_text_set (mpdule, "mpdule.artist", song->artist); edje_object_part_text_set (o_popup, "mpdule.artist", song->artist); } else { edje_object_part_text_set (mpdule, "mpdule.artist", ""); edje_object_part_text_set (o_popup, "mpdule.artist", ""); } if (song->title) { edje_object_part_text_set (mpdule, "mpdule.title", song->title); edje_object_part_text_set (o_popup, "mpdule.title", song->title); } else { edje_object_part_text_set (mpdule, "mpdule.title", ""); edje_object_part_text_set (o_popup, "mpdule.title", ""); } if (song->album) { edje_object_part_text_set (mpdule, "mpdule.album", song->album); edje_object_part_text_set (o_popup, "mpdule.album", song->album); } else { edje_object_part_text_set (mpdule, "mpdule.album", ""); edje_object_part_text_set (o_popup, "mpdule.album", ""); } if (song->track) { edje_object_part_text_set (mpdule, "mpdule.track", song->track); edje_object_part_text_set (o_popup, "mpdule.track", song->track); } else { edje_object_part_text_set (mpdule, "mpdule.track", ""); edje_object_part_text_set (o_popup, "mpdule.track", ""); } if (song->date) { edje_object_part_text_set (mpdule, "mpdule.date", song->date); edje_object_part_text_set (o_popup, "mpdule.date", song->date); } else { edje_object_part_text_set (mpdule, "mpdule.date", ""); edje_object_part_text_set (o_popup, "mpdule.date", ""); } if (song->genre) { edje_object_part_text_set (mpdule, "mpdule.genre", song->genre); edje_object_part_text_set (o_popup, "mpdule.genre", song->genre); } else { edje_object_part_text_set (mpdule, "mpdule.genre", ""); edje_object_part_text_set (o_popup, "mpdule.genre", ""); } if (song->composer) { edje_object_part_text_set (mpdule, "mpdule.composer", song->composer); edje_object_part_text_set (o_popup, "mpdule.composer", song->composer); } else { edje_object_part_text_set (mpdule, "mpdule.composer", ""); edje_object_part_text_set (o_popup, "mpdule.composer", ""); } if (song->time) { //char * songtime; //sprintf(songtime, "%i", song->time); //edje_object_part_text_set (mpdule, "mpdule.time", songtime); //edje_object_part_text_set (o_popup, "mpdule.time", songtime); } else { edje_object_part_text_set (mpdule, "mpdule.time", ""); edje_object_part_text_set (o_popup, "mpdule.time", ""); } if (song->file) { edje_object_part_text_set (mpdule, "mpdule.file", song->file); edje_object_part_text_set (o_popup, "mpdule.file", song->file); } else { edje_object_part_text_set (mpdule, "mpdule.file", ""); edje_object_part_text_set (o_popup, "mpdule.file", ""); } } mpd_freeInfoEntity (entity); } } mpd_freeStatus (status); } } else { _mpdule_disconnect (inst); _mpdule_connect (inst); } }