Esempio n. 1
0
int mpd_player_pause(MpdObj * mi)
{
	if (!mpd_check_connected(mi)) {
		debug_printf(DEBUG_WARNING, "not connected\n");
		return MPD_NOT_CONNECTED;
	}
	if (mpd_lock_conn(mi)) {
		debug_printf(DEBUG_WARNING, "lock failed\n");
		return MPD_LOCK_FAILED;
	}

	if (mpd_player_get_state(mi) == MPD_PLAYER_PAUSE) {
		mpd_sendPauseCommand(mi->connection, 0);
		mpd_finishCommand(mi->connection);
	} else if (mpd_player_get_state(mi) == MPD_PLAYER_PLAY) {
		mpd_sendPauseCommand(mi->connection, 1);
		mpd_finishCommand(mi->connection);
	}


	mpd_unlock_conn(mi);
	if (mpd_status_update(mi)) {
		return MPD_STATUS_FAILED;
	}
	return MPD_OK;
}
Esempio n. 2
0
static void queue_song(ttk_menu_item *item)
{
	mpd_InfoEntity entity;

	if (mpdc_tickle() < 0)
		return;
	mpd_sendSearchCommand(mpdz, (long)item->data, item->name);

	if (mpdz->error) {
		mpdc_tickle();
		return;
	}

	while ((mpd_getNextInfoEntity_st(&entity, mpdz))) {
		int found = 1;
		mpd_Song *song = entity.info.song;
		if (entity.type != MPD_INFO_ENTITY_TYPE_SONG) {
				continue;
		}
		found &= (!current_song.artist || (song->artist &&
				strcmp(current_song.artist,song->artist)==0));
		found &= (!current_song.album || (song->album &&
				strcmp(current_song.album, song->album) == 0));
		found &= ((song->title ? (strcmp(item->name, song->title)==0) :
				0) || strcmp(item->name, song->file)==0);
		if (found && song->file) {
			mpd_finishCommand(mpdz);
			mpd_sendAddCommand(mpdz, song->file);
			break;
		}
	}
	mpd_finishCommand(mpdz);
}
Esempio n. 3
0
File: mpd.c Progetto: mattx86/aprq2
/*
=================
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);
}
Esempio n. 4
0
int mpd_server_get_allowed_commands(MpdObj *mi)
{
	char *temp = NULL;
	int num_commands = 0;
	if(!mi){
		debug_printf(DEBUG_ERROR, "mi != NULL failed\n");
	       	return MPD_ARGS_ERROR;
	}
	if(!mpd_check_connected(mi)) {
		debug_printf(DEBUG_WARNING, "Not Connected");
		return MPD_NOT_CONNECTED;
	}
	if(!mpd_server_check_version(mi,0,12,0)){
		debug_printf(DEBUG_INFO, "Not supported by mpd");
	       	return MPD_SERVER_NOT_SUPPORTED;
	}

	mpd_server_free_commands(mi);

	if(mpd_lock_conn(mi))
	{
		debug_printf(DEBUG_ERROR, "lock failed");
		return MPD_LOCK_FAILED;
	}
	mpd_sendCommandsCommand(mi->connection);
	while((temp = mpd_getNextCommand(mi->connection)))
	{
		num_commands++;
		mi->commands = realloc(mi->commands, (num_commands+1)*sizeof(MpdCommand));
		mi->commands[num_commands-1].command_name = temp;
		mi->commands[num_commands-1].enabled = TRUE;
		mi->commands[num_commands].command_name = NULL;
		mi->commands[num_commands].enabled = FALSE;
	}
	mpd_finishCommand(mi->connection);
	mpd_sendNotCommandsCommand(mi->connection);
	while((temp = mpd_getNextCommand(mi->connection)))
	{
		num_commands++;
		mi->commands = realloc(mi->commands, (num_commands+1)*sizeof(MpdCommand));
		mi->commands[num_commands-1].command_name = temp;
		mi->commands[num_commands-1].enabled = FALSE;
		mi->commands[num_commands].command_name = NULL;
		mi->commands[num_commands].enabled = FALSE;
	}
	mpd_finishCommand(mi->connection);

	if(mpd_unlock_conn(mi))
    {
        return MPD_LOCK_FAILED;
    }
	return MPD_OK;
}
Esempio n. 5
0
int mpdc_status(mpd_Connection *con_fd)
{
	mpd_Status status;
	status.error = NULL;
	if (mpdz == NULL)
		return -2;
	mpd_sendStatusCommand(con_fd);
	if (mpd_getStatus_st(&status, con_fd)) {
		mpd_finishCommand(con_fd);
		return status.state;
	}
	mpd_finishCommand(con_fd);
	return -1;
}
Esempio n. 6
0
int mpd_send_password(MpdObj *mi)
{
	if(!mi) return MPD_ARGS_ERROR;
	if(mi->password && mpd_check_connected(mi) && strlen(mi->password))
	{
		if(mpd_lock_conn(mi))
		{
			debug_printf(DEBUG_WARNING, "failed to lock connection");
			return MPD_LOCK_FAILED;
		}
		mpd_sendPasswordCommand(mi->connection, mi->password);
		mpd_finishCommand(mi->connection);
		if(mpd_unlock_conn(mi))
		{
			debug_printf(DEBUG_ERROR, "Failed to unlock connection\n");
			return MPD_LOCK_FAILED;
		}
		mpd_server_get_allowed_commands(mi);
		/*TODO: should I do it here, or in the
		 * mpd_server_get_allowed_command, so it also get's executed on
		 * connect
		 */
		if((mi->the_status_changed_callback != NULL))
		{
			mi->the_status_changed_callback( mi,
					MPD_CST_PERMISSION, mi->the_status_changed_signal_userdata );
		}
	}
	return MPD_OK;
}
Esempio n. 7
0
int mpd_server_set_output_device(MpdObj *mi,int device_id,int state)
{
    if(!mpd_check_connected(mi))
    {
        debug_printf(DEBUG_WARNING,"not connected\n");	
        return MPD_NOT_CONNECTED;
    }
    if(mpd_lock_conn(mi))
    {
        debug_printf(DEBUG_ERROR,"lock failed\n");
        return MPD_LOCK_FAILED;
    }
    if(state)
    {
        mpd_sendEnableOutputCommand(mi->connection, device_id);
    }
    else
    {
        mpd_sendDisableOutputCommand(mi->connection, device_id);
    }	
    mpd_finishCommand(mi->connection);

    mpd_unlock_conn(mi);
    mpd_status_queue_update(mi);
    return FALSE;
}
Esempio n. 8
0
MpdData * mpd_database_get_artists(MpdObj *mi)
{
	char *string = NULL;
	MpdData *data = NULL;
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_WARNING,"not connected\n");
		return NULL;
	}
	if(mpd_lock_conn(mi))
	{
		debug_printf(DEBUG_ERROR,"lock failed\n");
		return NULL;
	}

	mpd_sendListCommand(mi->connection,MPD_TABLE_ARTIST,NULL);
	while (( string = mpd_getNextArtist(mi->connection)) != NULL)
	{
		data = mpd_new_data_struct_append(data);
		data->type = MPD_DATA_TYPE_TAG;
		data->tag_type = MPD_TAG_ITEM_ARTIST;
		data->tag = string;
	}
	mpd_finishCommand(mi->connection);

	/* unlock */
	mpd_unlock_conn(mi);
	if(data == NULL)
	{
		return NULL;
	}
	data = mpd_misc_sort_tag_list(data);
	return mpd_data_get_first(data);
}
Esempio n. 9
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;
}
Esempio n. 10
0
int mpd_database_save_playlist(MpdObj *mi, char *name)
{
	if(name == NULL || !strlen(name))
	{
		debug_printf(DEBUG_WARNING, "mpd_playlist_save: name != NULL  and strlen(name) > 0 failed");
		return MPD_ARGS_ERROR;
	}
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_WARNING,"mpd_playlist_save: not connected\n");
		return MPD_NOT_CONNECTED;
	}
	if(mpd_lock_conn(mi))
	{
		debug_printf(DEBUG_ERROR,"mpd_playlist_save: lock failed\n");
		return MPD_LOCK_FAILED;
	}

	mpd_sendSaveCommand(mi->connection,name);
	mpd_finishCommand(mi->connection);
	if(mi->connection->error == MPD_ERROR_ACK && mi->connection->errorCode == MPD_ACK_ERROR_EXIST)
	{
		mpd_clearError(mi->connection);
		mpd_unlock_conn(mi);
		return MPD_DATABASE_PLAYLIST_EXIST;

	}
	/* unlock */
	mpd_unlock_conn(mi);
	return MPD_OK;
}
Esempio n. 11
0
int mpd_database_delete_playlist(MpdObj *mi,char *path)
{
	if(path == NULL)
	{
		debug_printf(DEBUG_WARNING, "path == NULL");
		return MPD_ARGS_ERROR;
	}
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_WARNING,"not connected\n");
		return MPD_NOT_CONNECTED;
	}
	if(mpd_lock_conn(mi))
	{
		debug_printf(DEBUG_ERROR,"lock failed\n");
		return MPD_LOCK_FAILED;
	}

	mpd_sendRmCommand(mi->connection,path);
	mpd_finishCommand(mi->connection);

	/* unlock */
	mpd_unlock_conn(mi);
	return MPD_OK;
}
Esempio n. 12
0
static TWidget *populate_playlists()
{
	mpd_InfoEntity entity;
	TWidget *ret;
	
	if (mpdc_tickle() < 0)
		return NULL;

	ret = ttk_new_menu_widget(NULL, ttk_menufont,
			ttk_screen->w - ttk_screen->wx,
			ttk_screen->h - ttk_screen->wy);

	mpd_sendLsInfoCommand(mpdz, "");

	while ((mpd_getNextInfoEntity_st(&entity, mpdz))) {
		mpd_PlaylistFile *playlist;
		ttk_menu_item *item;
		if (entity.type != MPD_INFO_ENTITY_TYPE_PLAYLISTFILE) {
			continue;
		}
		playlist = entity.info.playlistFile;
		item = (ttk_menu_item *)calloc(1, sizeof(ttk_menu_item));
		item->name = (char *)strdup(playlist->path);
		item->free_name = 1;
		item->makesub = open_playlist;

		ttk_menu_append(ret, item);
	}
	ttk_menu_set_i18nable(ret, 0);

	mpd_finishCommand(mpdz);
	return ret;
}
Esempio n. 13
0
int mpd_playlist_queue_commit(MpdObj *mi)
{
	if(mi->queue == NULL)
	{
		debug_printf(DEBUG_WARNING,"mi->queue is empty");
		return MPD_PLAYLIST_QUEUE_EMPTY;
	}
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_WARNING,"not connected\n");
		return MPD_NOT_CONNECTED;
	}
	if(mpd_lock_conn(mi))
	{
		debug_printf(DEBUG_WARNING,"lock failed\n");
		return  MPD_LOCK_FAILED;
	}
	mpd_sendCommandListBegin(mi->connection);
	/* get first item */
	mi->queue = mi->queue->first;
	while(mi->queue != NULL)
	{
		if(mi->queue->type == MPD_QUEUE_ADD)
		{
			if(mi->queue->path != NULL)
			{
				mpd_sendAddCommand(mi->connection, mi->queue->path);
			}
		}
		else if(mi->queue->type == MPD_QUEUE_LOAD)
		{
			if(mi->queue->path != NULL)
			{
				mpd_sendLoadCommand(mi->connection, mi->queue->path);
			}
		}
		else if (mi->queue->type == MPD_QUEUE_DELETE_ID)
		{
			if(mi->queue->id >= 0)
			{
				mpd_sendDeleteIdCommand(mi->connection, mi->queue->id);
			}
		}
		else if (mi->queue->type == MPD_QUEUE_DELETE_POS)
		{                                                                      		
			if(mi->queue->id >= 0)
			{
				mpd_sendDeleteCommand(mi->connection, mi->queue->id);
			}
		}


		mpd_queue_get_next(mi);
	}
	mpd_sendCommandListEnd(mi->connection);
	mpd_finishCommand(mi->connection);
	mpd_unlock_conn(mi);
	mpd_status_update(mi);
	return MPD_OK;
}
Esempio n. 14
0
int mpd_playlist_load(MpdObj *mi, const char *path)
{
    int retv = MPD_OK;
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_WARNING,"mpd_playlist_load: not connected\n");
		return MPD_NOT_CONNECTED;
	}
	if(mpd_lock_conn(mi))
	{
		debug_printf(DEBUG_ERROR,"lock failed\n");
		return MPD_LOCK_FAILED;
	}
    mpd_sendLoadCommand(mi->connection,path);
	mpd_finishCommand(mi->connection);
    if(mi->connection->errorCode == MPD_ACK_ERROR_NO_EXIST) 
    {
        debug_printf(DEBUG_WARNING, "mpd_playlist_load: failed to load playlist\n");
		mpd_clearError(mi->connection);
        retv = MPD_PLAYLIST_LOAD_FAILED;
    }

	if(mpd_unlock_conn(mi))
	{
		debug_printf(DEBUG_ERROR, "Failed to unlock connection");
		return MPD_LOCK_FAILED;
	}
    return retv;
}
Esempio n. 15
0
int mpd_player_seek(MpdObj * mi, int sec)
{
	int cur_song = mpd_player_get_current_song_pos(mi);
	if (cur_song < 0) {
		debug_printf(DEBUG_ERROR, "mpd_player_get_current_song_pos returned error\n");
		return cur_song;
	}
	if (!mpd_check_connected(mi)) {
		debug_printf(DEBUG_WARNING, "not connected\n");
		return MPD_NOT_CONNECTED;
	}
	if (mpd_lock_conn(mi)) {
		debug_printf(DEBUG_WARNING, "lock failed\n");
		return MPD_LOCK_FAILED;
	}

	debug_printf(DEBUG_INFO, "seeking in song %i to %i sec\n", cur_song, sec);

	mpd_sendSeekCommand(mi->connection, cur_song, sec);
	mpd_finishCommand(mi->connection);


	mpd_unlock_conn(mi);
	if (mpd_status_update(mi)) {
		return MPD_STATUS_FAILED;
	}
	return MPD_OK;
}
Esempio n. 16
0
int
cmd_outputs(mpd_unused int argc, mpd_unused char **argv, mpd_Connection *conn)
{
	mpd_OutputEntity * output;

	mpd_sendOutputsCommand( conn );
	while(( output = mpd_getNextOutput( conn ))) {
		/* We increment by 1 to make it natural to the user  */
		output->id++;

		/* If it's a negative number a password is needed  */
		if( output->id > 0 )
		{
			if( output->enabled ) {
				printf( "Output %i (%s) is enabled\n", output->id, output->name );
			} else {
				printf( "Output %i (%s) is disabled\n", output->id, output->name );
			}
		}
		else
		{
			DIE( "cannot receive the current outputs\n" );
		}
		mpd_freeOutputElement( output );
	}
	mpd_finishCommand( conn );
	return( 0 );
}
Esempio n. 17
0
int mpd_database_update_dir(MpdObj *mi, char *path)
{
/*	if(path == NULL || !strlen(path))
	{
		debug_printf(DEBUG_ERROR, "path != NULL  and strlen(path) > 0 failed");
		return MPD_ARGS_ERROR;
	}
*/
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_WARNING,"not connected\n");
		return MPD_NOT_CONNECTED;
	}
	if(mpd_lock_conn(mi))
	{
		debug_printf(DEBUG_ERROR,"lock failed\n");
		return MPD_LOCK_FAILED;
	}

	mpd_sendUpdateCommand(mi->connection,path);
	mpd_finishCommand(mi->connection);
	/* I have no idea why do this ?? it even makes gmpc very very unhappy.
	 * Because it doesnt trigger an signal anymore when updating starts
	 * mi->CurrentState.updatingDb = mpd_getUpdateId(mi->connection);
	*/

	/* unlock */
	mpd_unlock_conn(mi);
	/* What I think you should do is to force a direct status updated
	 */
	mpd_status_update(mi);
	return MPD_OK;
}
Esempio n. 18
0
bool MPDConnection::finishCommand() {
	if (d->connection->error)
	 {
		QString errormsg = QString::fromUtf8(d->connection->errorStr).replace("\n", "");
		switch (d->connection->error) {
			case MPD_ERROR_TIMEOUT:
			case MPD_ERROR_SYSTEM:
			case MPD_ERROR_UNKHOST:
			case MPD_ERROR_CONNPORT:
			case MPD_ERROR_NOTMPD:
			case MPD_ERROR_NORESPONSE:
			case MPD_ERROR_SENDING:
			case MPD_ERROR_CONNCLOSED:
				// These are the serious errors. Set errormsg.
				qWarning("Error: `%s (error code %d). Disconnecting.", qPrintable(errormsg), d->connection->error);
				disconnectFromMPD(errormsg);
				return false;
			default:
				// Just warnings. We ignore them.
				qWarning("Warning: `%s (error code %d). Ignoring.", qPrintable(errormsg), d->connection->error);
		}
		qWarning("Problem occured while executing command: %s, called from: %s", qPrintable(d->command), qPrintable(d->caller));
		d->caller = d->command = QString();
		mpd_clearError(d->connection);
		return false;
	} else
		mpd_finishCommand(d->connection);
	// Clear error code, just in case.
	mpd_clearError(d->connection);
	return true;
}
Esempio n. 19
0
MpdData * mpd_server_get_output_devices(MpdObj *mi)
{
    mpd_OutputEntity *output = NULL;
    MpdData *data = NULL;
    if(!mpd_check_connected(mi))
    {
        debug_printf(DEBUG_WARNING,"not connected\n");
        return NULL;
    }
    /* TODO: Check version */
    if(mpd_lock_conn(mi))
    {
        debug_printf(DEBUG_ERROR,"lock failed\n");
        return NULL;
    }

    mpd_sendOutputsCommand(mi->connection);
    while (( output = mpd_getNextOutput(mi->connection)) != NULL)
    {	
        data = mpd_new_data_struct_append(data);
        data->type = MPD_DATA_TYPE_OUTPUT_DEV; 
        data->output_dev = output;
    }
    mpd_finishCommand(mi->connection);

    /* unlock */
    mpd_unlock_conn(mi);
    if(data == NULL) 
    {
        return NULL;
    }
    return mpd_data_get_first(data);
}
Esempio n. 20
0
int mpd_status_set_volume(MpdObj *mi,int volume)
{
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_WARNING,"not connected\n");
		return MPD_NOT_CONNECTED;
	}
	/* making sure volume is between 0 and 100 */
	volume = (volume < 0)? 0:(volume>100)? 100:volume;

	if(mpd_lock_conn(mi))
	{
		debug_printf(DEBUG_ERROR,"lock failed\n");
		return MPD_LOCK_FAILED;
	}

	/* send the command */
	mpd_sendSetvolCommand(mi->connection , volume);
	mpd_finishCommand(mi->connection);
	/* check for errors */

	mpd_unlock_conn(mi);
	/* update status, because we changed it */
	mpd_status_queue_update(mi);
	/* return current volume */
	return mpd_status_get_volume(mi);
}
Esempio n. 21
0
int mpd_sticker_song_set(MpdObj *mi, const char *path, const char *tag, const char *value)
{
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_INFO,"not connected\n");
		return MPD_NOT_CONNECTED;
	}
    if(mpd_server_check_command_allowed(mi, "sticker") != MPD_SERVER_COMMAND_ALLOWED) {
        debug_printf(DEBUG_WARNING, "Command not allowed\n");
        return MPD_SERVER_NOT_SUPPORTED;
    }
	if(mpd_lock_conn(mi))
	{
		debug_printf(DEBUG_ERROR,"lock failed\n");
		return MPD_LOCK_FAILED;
	}

    mpd_sendSetSongSticker(mi->connection,path, tag,value); 
    mpd_finishCommand(mi->connection);
    if(mpd_unlock_conn(mi))
    {
		debug_printf(DEBUG_ERROR, "Failed to unlock");
		return MPD_LOCK_FAILED;
	}
    return MPD_OK;
}
Esempio n. 22
0
void mpdc_next()
{
	if (mpdc_tickle() < 0)
		return;
	mpd_sendNextCommand(mpdz);
	mpd_finishCommand(mpdz);
}
Esempio n. 23
0
void mpdc_prev()
{
	if (mpdc_tickle() < 0)
		return;
	mpd_sendPrevCommand(mpdz);
	mpd_finishCommand(mpdz);
}
Esempio n. 24
0
void mpdc_change_volume(mpd_Connection *con_fd, int volume)
{
	if (mpdc_tickle() < 0)
		return;
	mpd_sendSetvolCommand(con_fd, volume);
	mpd_finishCommand(con_fd);
}
Esempio n. 25
0
MpdData *mpd_database_get_playlist_content(MpdObj *mi,char *playlist)
{
	MpdData *data = NULL;
	mpd_InfoEntity *ent = NULL;
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_WARNING,"not connected\n");
		return NULL;
	}
	if(!mpd_server_check_version(mi, 0,12,0))
	{
		debug_printf(DEBUG_WARNING, "only works with mpd higher then 0.12.0");
		return NULL;
	}
	if(mpd_server_check_command_allowed(mi, "listplaylistinfo") != MPD_SERVER_COMMAND_ALLOWED)
	{
		debug_printf(DEBUG_WARNING, "Listing playlist content not supported or allowed");
		return NULL;
	}
	if(mpd_lock_conn(mi))
	{
		debug_printf(DEBUG_WARNING,"lock failed\n");
		return NULL;
	}
	mpd_sendListPlaylistInfoCommand(mi->connection, playlist);
	while (( ent = mpd_getNextInfoEntity(mi->connection)) != NULL)
	{
		data = mpd_new_data_struct_append( data );
		if(ent->type == MPD_INFO_ENTITY_TYPE_DIRECTORY)
		{
			data->type = MPD_DATA_TYPE_DIRECTORY;
			data->directory = ent->info.directory->path;
			ent->info.directory->path = NULL;
		}
		else if (ent->type == MPD_INFO_ENTITY_TYPE_SONG)
		{
			data->type = MPD_DATA_TYPE_SONG;
			data->song = ent->info.song;
			ent->info.song = NULL;
		}
		else if (ent->type == MPD_INFO_ENTITY_TYPE_PLAYLISTFILE)
		{
			data->type = MPD_DATA_TYPE_PLAYLIST;
			data->playlist = ent->info.playlistFile->path;
			ent->info.playlistFile->path = NULL;
		}

		mpd_freeInfoEntity(ent);
	}
	mpd_finishCommand(mi->connection);

	/* unlock */
	mpd_unlock_conn(mi);
	if(data == NULL)
	{
		return NULL;
	}
	return mpd_data_get_first(data);
}
Esempio n. 26
0
/**
 * @param mi A #MpdObj
 * @param path an Path to a file
 *
 * Grabs the song info for a single file. Make sure you pass an url to a song
 * and not a directory, that might result in strange behauviour.
 *
 * @returns a #mpd_Song
 */
mpd_Song * mpd_database_get_fileinfo(MpdObj *mi,const char *path)
{
	mpd_Song *song = NULL;
	mpd_InfoEntity *ent = NULL;
	/*
	 * Check path for availibility and length
	 */
	if(path == NULL || path[0] == '\0')
	{
		debug_printf(DEBUG_ERROR, "path == NULL || strlen(path) == 0");
		return NULL;
	}
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_ERROR, "Not Connected\n");
		return NULL;
	}
	/* lock, so we can work on mi->connection */
	if(mpd_lock_conn(mi) != MPD_OK)
	{
		debug_printf(DEBUG_ERROR, "Failed to lock connection");
		return NULL;
	}
	/* send the request */
	mpd_sendListallInfoCommand(mi->connection, path);
	/* get the first (and only) result */
	ent = mpd_getNextInfoEntity(mi->connection);
	/* finish and clean up libmpdclient */
	mpd_finishCommand(mi->connection);
	/* unlock again */
	if(mpd_unlock_conn(mi))
	{
		if(ent) mpd_freeInfoEntity(ent);
		debug_printf(DEBUG_ERROR, "Failed to unlock");
		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 correct song type from mpd, path might not be a file\n");
		return NULL;
	}
	/* get the song */
	song = ent->info.song;
	/* remove reference to song from the entity */
	ent->info.song = NULL;
	/* free the entity */
	mpd_freeInfoEntity(ent);

	return song;
}
Esempio n. 27
0
static TWindow *open_playlist(ttk_menu_item *item)
{
	if (mpdc_tickle() < 0)
		return TTK_MENU_DONOTHING;
	mpd_sendClearCommand(mpdz);
	mpd_finishCommand(mpdz);

	mpd_sendLoadCommand(mpdz, (char *)item->name);
	mpd_finishCommand(mpdz);
	if (mpdz->error) {
		mpdc_tickle();
		return TTK_MENU_DONOTHING;
	}
	mpd_sendPlayCommand(mpdz, -1);
	mpd_finishCommand(mpdz);

	return mpd_currently_playing();
}
Esempio n. 28
0
File: mpd.c Progetto: mattx86/aprq2
/*
=================
MPD_Prev - play previous song
=================
*/
void MPD_Prev(void)
{
	if(!MP3_Status())
		return;

	mpd_sendPrevCommand(conn);
	mpd_finishCommand(conn);

	MPD_Status();
}
Esempio n. 29
0
File: mpd.c Progetto: mattx86/aprq2
/*
=================
MPD_Next - play next song
=================
*/
void MPD_Next(void)
{
	if(!MP3_Status())
		return;

	mpd_sendNextCommand(conn);
	mpd_finishCommand(conn);

	MPD_Status();
}
Esempio n. 30
0
File: mpd.c Progetto: mattx86/aprq2
/*
=================
MPD_Pause - pause playback
=================
*/
void MPD_Pause(void)
{
	if(!MP3_Status())
		return;

	mpd_sendPauseCommand(conn, 1);
	mpd_finishCommand(conn);

	MPD_Status();
}