示例#1
0
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;
}
示例#2
0
MpdData * mpd_playlist_get_song_from_pos_range(MpdObj *mi, int start, int stop)
{
    MpdData *data = NULL;
    int i;
	mpd_InfoEntity *ent = NULL;
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_ERROR, "Not Connected\n");
		return NULL;
	}
	if(mpd_status_check(mi) != MPD_OK)
	{
		debug_printf(DEBUG_ERROR,"Failed grabbing status\n");
		return NULL;
	}

	if(mpd_lock_conn(mi))
	{
		return NULL;
	}
    /* Don't check outside playlist length */
    if(!(stop < mi->status->playlistLength)) {
        stop = mi->status->playlistLength -1;
    }
    mpd_sendCommandListBegin(mi->connection);
    for(i=start; i <= stop; i++){
        mpd_sendPlaylistInfoCommand(mi->connection, i);
    }
	mpd_sendCommandListEnd(mi->connection);
	while (( ent = mpd_getNextInfoEntity(mi->connection)) != NULL)
	{
		if(ent->type == MPD_INFO_ENTITY_TYPE_SONG)
		{
			data = mpd_new_data_struct_append(data);
			data->type = MPD_DATA_TYPE_SONG;
			data->song = ent->info.song;
			ent->info.song = NULL;
		}
		mpd_freeInfoEntity(ent);
	}
	mpd_finishCommand(mi->connection);

	if(mpd_unlock_conn(mi))
	{
		/*TODO free entity. for now this can never happen */
		return NULL;
	}
    return data;
}
示例#3
0
mpd_Song * mpd_playlist_get_song_from_pos(MpdObj *mi, int songpos)
{
	mpd_Song *song = NULL;
	mpd_InfoEntity *ent = NULL;
	if(songpos < 0){
		debug_printf(DEBUG_ERROR, "songpos < 0 Failed");
		return NULL;
	}
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_ERROR, "Not Connected\n");
		return NULL;
	}

	if(mpd_lock_conn(mi))
	{
		return NULL;
	}
	debug_printf(DEBUG_INFO, "Trying to grab song with id: %i\n", songpos);
	mpd_sendPlaylistInfoCommand(mi->connection, songpos);
	ent = mpd_getNextInfoEntity(mi->connection);
	mpd_finishCommand(mi->connection);

	if(mpd_unlock_conn(mi))
	{
		/*TODO free entity. for now this can never happen */
		return NULL;
	}

	if(ent == NULL)
	{
		debug_printf(DEBUG_ERROR, "Failed to grab song from mpd\n");
		return NULL;
	}

	if(ent->type != MPD_INFO_ENTITY_TYPE_SONG)
	{
		mpd_freeInfoEntity(ent);
		debug_printf(DEBUG_ERROR, "Failed to grab corect song type from mpd\n");
		return NULL;
	}
	song = ent->info.song;
	ent->info.song = NULL;

	mpd_freeInfoEntity(ent);

	return song;
}
示例#4
0
void MpdClient::updatePlaylist(long long version)
{
	if (version < 0)
		mpd_sendPlChangesCommand(conn, version);
	else
		mpd_sendPlaylistInfoCommand(conn, -1);

	mpd_InfoEntity *entity;
	while ((entity = mpd_getNextInfoEntity(conn))) {
		assert(entity->type == MPD_INFO_ENTITY_TYPE_SONG);

		mpd_Song *song = mpd_songDup(entity->info.song);
		mpd_freeInfoEntity(entity);

		assert(song->pos <= playlist.size());

		if (song->pos == playlist.size())
			playlist += song;
		else {
			mpd_freeSong(playlist[song->pos]);
			playlist[song->pos] = song;
		}

		emit(changedSong(song));
	}

	mpd_finishCommand(conn);

	/* remove extra songs if the playlist was shortened */
	for (int i = playlist.size() - 1; i >= status->playlistLength; i--) {
		mpd_freeSong(playlist[i]);
		playlist.removeAt(i);
		emit(changedSong(NULL));
	}

}