Beispiel #1
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);
}
Beispiel #2
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;
}
Beispiel #3
0
int mpd_player_set_random(MpdObj * mi, int random)
{
	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_sendRandomCommand(mi->connection, random);
	mpd_finishCommand(mi->connection);

	mpd_unlock_conn(mi);
	mpd_status_queue_update(mi);
	return MPD_OK;
}
Beispiel #4
0
int mpd_status_set_crossfade(MpdObj *mi,int crossfade_time)
{
	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_sendCrossfadeCommand(mi->connection, crossfade_time);
	mpd_finishCommand(mi->connection);

	mpd_unlock_conn(mi);
	mpd_status_queue_update(mi);
	return MPD_OK;
}
Beispiel #5
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;
}