Beispiel #1
0
mpd_Song * mpd_playlist_get_current_song(MpdObj *mi)
{
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_WARNING, "Not Connected\n");
		return NULL;
	}

	if(mpd_status_check(mi) != MPD_OK)
	{
		debug_printf(DEBUG_ERROR, "Failed to check status\n");
		return NULL;
	}

	if(mi->CurrentSong != NULL && mi->CurrentSong->id != mi->status->songid)
	{
		debug_printf(DEBUG_WARNING, "Current song not up2date, updating\n");
		mpd_freeSong(mi->CurrentSong);
		mi->CurrentSong = NULL;
	}
	/* only update song when playing/pasing */
	if(mi->CurrentSong == NULL && 
			(mpd_player_get_state(mi) != MPD_PLAYER_STOP && mpd_player_get_state(mi) != MPD_PLAYER_UNKNOWN))
	{
		/* TODO: this to use the geT_current_song_id function */
		mi->CurrentSong = mpd_playlist_get_song(mi, mpd_player_get_current_song_id(mi));
		if(mi->CurrentSong == NULL)
		{
			debug_printf(DEBUG_ERROR, "Failed to grab song\n");
			return NULL;
		}
	}
	return mi->CurrentSong;
}
Beispiel #2
0
int mpd_player_get_random(MpdObj * mi)
{
	if (!mpd_check_connected(mi)) {
		debug_printf(DEBUG_WARNING, "not connected\n");
		return MPD_NOT_CONNECTED;
	}
	if (mpd_status_check(mi) != MPD_OK) {
		debug_printf(DEBUG_WARNING, "Failed grabbing status\n");
		return MPD_NOT_CONNECTED;
	}
	return mi->status->random;
}
Beispiel #3
0
int mpd_player_get_state(MpdObj * mi)
{
	if (!mpd_check_connected(mi)) {
		debug_printf(DEBUG_WARNING, "not connected\n");
		return MPD_NOT_CONNECTED;
	}
	if (mpd_status_check(mi) != MPD_OK) {
		debug_printf(DEBUG_WARNING, "Failed to get status\n");
		return MPD_STATUS_FAILED;
	}
	return mi->status->state;
}
Beispiel #4
0
long long mpd_playlist_get_playlist_id(MpdObj *mi)
{
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_WARNING,"not connected\n");
		return MPD_NOT_CONNECTED;
	}
	if(mpd_status_check(mi) != MPD_OK)
	{
		debug_printf(DEBUG_WARNING,"Failed grabbing status\n");
		return MPD_STATUS_FAILED;
	}
	return mi->status->playlist;
}
Beispiel #5
0
int mpd_status_get_elapsed_song_time(MpdObj *mi)
{
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_WARNING,"failed to check mi == NULL\n");
		return MPD_NOT_CONNECTED;
	}
	if(mpd_status_check(mi) != MPD_OK)
	{
		debug_printf(DEBUG_WARNING,"Failed to get status\n");
		return MPD_STATUS_FAILED;
	}
	return mi->status->elapsedTime;
}
Beispiel #6
0
int mpd_status_get_total_song_time(MpdObj *mi)
{
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_ERROR, "failed to check mi == NULL\n");
		return MPD_ARGS_ERROR;
	}
	if(mpd_status_check(mi) != MPD_OK)
	{
		debug_printf(DEBUG_WARNING, "Failed to get status\n");
		return MPD_STATUS_FAILED;
	}
	return mi->status->totalTime;
}
Beispiel #7
0
int mpd_status_get_bits(MpdObj *mi)
{
	if(mi == NULL)
	{
		debug_printf(DEBUG_WARNING,"failed to check mi == NULL\n");
		return MPD_ARGS_ERROR;
	}
	if(mpd_status_check(mi) != MPD_OK)
	{
		debug_printf(DEBUG_WARNING, "Failed to get status\n");
		return MPD_STATUS_FAILED;
	}
	return mi->CurrentState.bits;
}
Beispiel #8
0
int mpd_status_get_volume(MpdObj *mi)
{
	if(mi == NULL)
	{
		debug_printf(DEBUG_ERROR, "failed to check mi == NULL\n");
		return MPD_ARGS_ERROR;
	}
	if(mpd_status_check(mi) != MPD_OK)
	{
		debug_printf(DEBUG_WARNING, "Failed to get status\n");
		return MPD_STATUS_FAILED;
	}
	return mi->status->volume;
}
Beispiel #9
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;
}
Beispiel #10
0
int mpd_player_get_current_song_id(MpdObj * mi)
{
	if (!mpd_check_connected(mi)) {
		debug_printf(DEBUG_WARNING, "not connected\n");
		return MPD_NOT_CONNECTED;
	}
	if (mpd_status_check(mi) != MPD_OK) {
		debug_printf(DEBUG_ERROR, "Failed to get status\n");
		return MPD_STATUS_FAILED;
	}
	/* check if in valid state */
	if (mpd_player_get_state(mi) != MPD_PLAYER_PLAY &&
			mpd_player_get_state(mi) != MPD_PLAYER_PAUSE) {
		return MPD_PLAYER_NOT_PLAYING;
	}
	/* just to be sure check */
	if (!mi->status->playlistLength) {
		return MPD_PLAYLIST_EMPTY;
	}
	return mi->status->songid;
}
Beispiel #11
0
void mpd_database_playlist_clear(MpdObj *mi, const char *path)
{
	if(!path )
		return;
	if (!mpd_check_connected(mi)) {
		debug_printf(DEBUG_WARNING, "not connected\n");
		return;
	}
	if (mpd_status_check(mi) != MPD_OK) {
		debug_printf(DEBUG_WARNING, "Failed to get status\n");
		return;
	}
	if(mpd_lock_conn(mi))
	{
		return ;
	}

	mpd_sendPlaylistClearCommand(mi->connection, (char *)path);
	mpd_finishCommand(mi->connection);

	mpd_unlock_conn(mi);
}
Beispiel #12
0
/* -------------------------------------------------------------------------- */
void *mpd_run(void *cookie)
{
    time_t next_update, current;
    gboolean result;
    int retry_count = RETRY_INTERVAL;
    struct lcd_stuff_mpd mpd;

    /* default values */
    mpd.lcd = (struct lcd_stuff *)cookie;
    mpd.mpd = NULL;
    mpd.error = 0;
    mpd.current_state = 0;
    mpd.song_displayed = false;
    mpd.current_song = NULL;
    mpd.stop_time = UINT_MAX;
    mpd.current_list = NULL;
    mpd.connection = NULL;
    mpd.timeout = 0;

    result = key_file_has_group(MODULE_NAME);
    if (!result) {
        report(RPT_INFO, "mpd disabled");
        conf_dec_count();
        return NULL;
    }

    if (!mpd_init(&mpd))
        goto out;

    if (!mpd_init_connection(&mpd))
        goto out_screen;
    if (!mpd_start_connection(&mpd))
        goto out_screen;

    /* do first update instantly */
    next_update = time(NULL);

    conf_dec_count();

    /* dispatcher */
    while (!g_exit) {

        /* if we are in error state, try to retrieve a connection first */
        if (mpd.error) {
            if (retry_count-- <= 0) { /* each minute */
                if (mpd_start_connection(&mpd)) {
                    mpd.error = false;
                } else {
                    retry_count = RETRY_INTERVAL;
                }
            }

            if (mpd.error) {
                g_usleep(1000000);
                continue;
            }
        }

        current = time(NULL);

        g_usleep(1000000);
        mpd_status_queue_update(mpd.mpd);
        mpd_status_check(mpd.mpd);
        mpd_update_status_time(&mpd);

        /* check playlists ? */
        if (current > next_update) {
            mpd_update_playlist_menu(&mpd);
            next_update = time(NULL) + 60;
        } if (current > mpd.stop_time) {
            mpd_player_stop(mpd.mpd);
            mpd.stop_time = UINT_MAX;
            service_thread_command(mpd.lcd->service_thread,
                                   "menu_set_item \"\" mpd_standby -value 0\n");
        }
    }

out_screen:
    mpd_deinit(&mpd);

out:
    if (mpd.mpd)
        mpd_free(mpd.mpd);
    if (mpd.current_list)
        mpd_free_playlist(mpd.current_list);
    service_thread_unregister_client(mpd.lcd->service_thread, MODULE_NAME);
    mpd_song_delete(mpd.current_song);
    connection_delete(mpd.connection);

    return NULL;
}