Пример #1
0
int mpd_put_outputs(char *buffer, int names)
{
    struct mpd_output *out;
    int nout;
    char *str, *strend;

    str = buffer;
    strend = buffer+MAX_SIZE;
    str += snprintf(str, strend-str, "{\"type\":\"%s\", \"data\":{",
            names ? "outputnames" : "outputs");

    mpd_send_outputs(mpd.conn);
    nout = 0;
    while ((out = mpd_recv_output(mpd.conn)) != NULL) {
        if (nout++)
            *str++ = ',';
        if (names)
            str += snprintf(str, strend - str, " \"%d\":\"%s\"",
                    mpd_output_get_id(out), mpd_output_get_name(out));
        else
            str += snprintf(str, strend-str, " \"%d\":%d",
                    mpd_output_get_id(out), mpd_output_get_enabled(out));
        mpd_output_free(out);
    }
    if (!mpd_response_finish(mpd.conn)) {
        fprintf(stderr, "MPD outputs: %s\n", mpd_connection_get_error_message(mpd.conn));
        mpd_connection_clear_error(mpd.conn);
        return 0;
    }
    str += snprintf(str, strend-str, " }}");
    return str-buffer;
}
Пример #2
0
static unsigned
match_outputs(struct mpd_connection *conn,
	      char **names, char **names_end, unsigned **ids_end)
{
	unsigned max = 0, *id = *ids_end;

	mpd_send_outputs(conn);

	struct mpd_output *output;
	while ((output = mpd_recv_output(conn)) != NULL) {
		const char *name = mpd_output_get_name(output);
		max = mpd_output_get_id(output);

		for (char **n = names; n != names_end; ++n) {
			if (!strcmp(*n, name)) {
				*id = max;
				++id;
				*n = *names;
				++names;
				break;
			}
		}

		mpd_output_free(output);
	}

	my_finishCommand(conn);

	for (char **n = names; n != names_end; ++n) {
		fprintf(stderr, "%s: no such output\n", *n);
	}

	*ids_end = id;
	return max;
}
Пример #3
0
/* This function get the sound card list from the MPD server
 * This list never changed but the filed "enable" could change
 */
void Player::retrieveSndCardList()
{
    mpd_malloc struct mpd_output *output;

    /* Request all outputs */
    mpd_send_outputs(conn);

    QVector<EMSSndCard> sndCards;

    while ((output = mpd_recv_output(conn)) != NULL)
    {
        EMSSndCard sndCard;
        sndCard.id_mpd = mpd_output_get_id(output)+1;
        sndCard.name = mpd_output_get_name(output);
        sndCard.enabled = mpd_output_get_enabled(output);
        mpd_output_free(output);
        qDebug() << "Find mpd output" << QString("(%1) : %2").arg(sndCard.id_mpd).arg(sndCard.name);
        sndCards.append(sndCard);
    }

    mutex.lock();
    outputs = sndCards;
    mutex.unlock();

    emit outputsChanged(sndCards);

    if (!mpd_response_finish(conn))
    {
        qCritical() << "Error while trying to get MPD outputs" ;
        qCritical() << "Reconnecting...";
        connectToMpd();
        return;
    }

}
Пример #4
0
int
cmd_outputs(gcc_unused int argc, gcc_unused char **argv, struct mpd_connection *conn)
{
	mpd_send_outputs(conn);

	struct mpd_output *output;
	while ((output = mpd_recv_output(conn)) != NULL) {
		/* We increment by 1 to make it natural to the user  */
		int id = mpd_output_get_id(output) + 1;
		const char *name = mpd_output_get_name(output);

		if (mpd_output_get_enabled(output)) {
			printf("Output %i (%s) is enabled\n", id, name);
		} else {
			printf("Output %i (%s) is disabled\n", id, name);
		}

		mpd_output_free(output);
	}
	mpd_response_finish(conn);
	return( 0 );
}