Exemplo n.º 1
0
bool
mpd_run_send_message(struct mpd_connection *connection,
		     const char *channel, const char *text)
{
	return mpd_run_check(connection) &&
		mpd_send_send_message(connection, channel, text) &&
		mpd_response_finish(connection);
}
Exemplo n.º 2
0
bool
mpd_run_prio_range(struct mpd_connection *connection, int priority,
		   unsigned start, unsigned end)
{
	return mpd_run_check(connection) &&
		mpd_send_prio_range(connection, priority, start, end) &&
		mpd_response_finish(connection);
}
Exemplo n.º 3
0
bool
mpd_run_delete_range(struct mpd_connection *connection,
		     unsigned start, unsigned end)
{
	return mpd_run_check(connection) &&
		mpd_send_delete_range(connection, start, end) &&
		mpd_response_finish(connection);
}
Exemplo n.º 4
0
bool
mpd_run_seek_id(struct mpd_connection *connection,
	       unsigned song_id, unsigned t)
{
	return mpd_run_check(connection) &&
		mpd_send_seek_id(connection, song_id, t) &&
		mpd_response_finish(connection);
}
Exemplo n.º 5
0
bool
mpd_run_prio_id(struct mpd_connection *connection, int priority,
		unsigned id)
{
	return mpd_run_check(connection) &&
		mpd_send_prio_id(connection, priority, id) &&
		mpd_response_finish(connection);
}
Exemplo n.º 6
0
Song Connection::GetCurrentSong()
{
	prechecksNoCommandsList();
	mpd_send_current_song(m_connection.get());
	mpd_song *s = mpd_recv_song(m_connection.get());
	mpd_response_finish(m_connection.get());
	checkErrors();
	return Song(s);
}
Exemplo n.º 7
0
Song Connection::GetSong(const std::string &path)
{
	prechecksNoCommandsList();
	mpd_send_list_all_meta(m_connection.get(), path.c_str());
	mpd_song *s = mpd_recv_song(m_connection.get());
	mpd_response_finish(m_connection.get());
	checkErrors();
	return Song(s);
}
Exemplo n.º 8
0
void Connection::CommitCommandsList()
{
	prechecks();
	assert(m_command_list_active);
	mpd_command_list_end(m_connection.get());
	mpd_response_finish(m_connection.get());
	m_command_list_active = false;
	checkErrors();
}
Exemplo n.º 9
0
char *
getmpdstat() {
    struct mpd_song * song = NULL;
	const char * title = NULL;
	const char * artist = NULL;
	const char * uri = NULL;
	const char * titletag = NULL;
	const char * artisttag = NULL;
	char * retstr = NULL;
	int elapsed = 0, total = 0;
    struct mpd_connection * conn ;
    if (!(conn = mpd_connection_new("localhost", 0, 30000)) ||
        mpd_connection_get_error(conn)){
            return smprintf("");
    }

    mpd_command_list_begin(conn, true);
    mpd_send_status(conn);
    mpd_send_current_song(conn);
    mpd_command_list_end(conn);

    struct mpd_status* theStatus = mpd_recv_status(conn);
        if ((theStatus) && (mpd_status_get_state(theStatus) == MPD_STATE_PLAY)) {
                mpd_response_next(conn);
                song = mpd_recv_song(conn);
		titletag = mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
		artisttag = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);
                title = smprintf("%s",titletag);
                artist = smprintf("%s",artisttag);
		uri = smprintf("%s",mpd_song_get_uri(song));

                elapsed = mpd_status_get_elapsed_time(theStatus);
                total = mpd_status_get_total_time(theStatus);
                mpd_song_free(song);

		/* If the song isn't tagged, then just use the filename */
		if(artisttag == NULL && titletag == NULL) {
			retstr = smprintf("%s[%s%s%s | %s%.2d:%.2d%s/%.2d:%.2d%s]",
					colcyan, colyellow, uri, colcyan,
					colbyellow, elapsed/60, elapsed%60,
					colyellow, total/60,   total%60, colcyan);
		} else {
			retstr = smprintf("%s[%s%s%s | %s%s%s | %s%.2d:%.2d%s/%.2d:%.2d%s]",
					colcyan, colyellow, artist, colcyan, colred, title, colcyan,
					colbyellow, elapsed/60, elapsed%60,
					colyellow, total/60,   total%60, colcyan);
		}
                free((char*)title);
                free((char*)artist);
		free((char*)uri);
        }
        else retstr = smprintf("");
		mpd_response_finish(conn);
		mpd_connection_free(conn);
		return retstr;
}
Exemplo n.º 10
0
static void stopSong()
{
    mpd_update();
    if (currentSong != NULL) {
	if ((!mpd_run_stop(conn))
	    || (!mpd_response_finish(conn))) {
	    mpd_printerror("run_stop");
	}
    }
}
Exemplo n.º 11
0
void Connection::Delete(unsigned pos)
{
	prechecks();
	mpd_send_delete(m_connection.get(), pos);
	if (!m_command_list_active)
	{
		mpd_response_finish(m_connection.get());
		checkErrors();
	}
}
Exemplo n.º 12
0
void Connection::PlaylistDelete(const std::string &playlist, unsigned pos)
{
	prechecks();
	mpd_send_playlist_delete(m_connection.get(), playlist.c_str(), pos);
	if (!m_command_list_active)
	{
		mpd_response_finish(m_connection.get());
		checkErrors();
	}
}
Exemplo n.º 13
0
static void pauseSong()
{
    mpd_update();
    if (currentSong != NULL) {
	if ((!mpd_send_pause(conn, l_state == MPD_STATE_PAUSE ? 0 : 1))
	    || (!mpd_response_finish(conn))) {
	    mpd_printerror("send_pause");
	}
    }
}
Exemplo n.º 14
0
static void prevSong()
{
    mpd_update();
    if (currentSong != NULL) {
	if ((!mpd_run_previous(conn))
	    || (!mpd_response_finish(conn))) {
	    mpd_printerror("run_previous");
	}
    }
}
Exemplo n.º 15
0
static gboolean
lmc_idle(G_GNUC_UNUSED GIOChannel *source,
	 G_GNUC_UNUSED GIOCondition condition,
	 G_GNUC_UNUSED gpointer data)
{
	bool success;
	enum mpd_idle idle;

	assert(idle_source_id != 0);
	assert(g_mpd != NULL);
	assert(mpd_connection_get_error(g_mpd) == MPD_ERROR_SUCCESS);

	idle_source_id = 0;

	idle = mpd_recv_idle(g_mpd, false);
	success = mpd_response_finish(g_mpd);

	if (!success && mpd_connection_get_error(g_mpd) == MPD_ERROR_SERVER &&
	    mpd_connection_get_server_error(g_mpd) == MPD_SERVER_ERROR_UNKNOWN_CMD &&
	    mpd_connection_clear_error(g_mpd)) {
		/* MPD does not recognize the "idle" command - disable
		   it for this connection */

		g_message("MPD does not support the 'idle' command - "
			  "falling back to polling\n");

		idle_supported = false;
		lmc_schedule_update();
		return false;
	}

	if (!success) {
		lmc_failure();
		lmc_schedule_reconnect();
		return false;
	}

#if LIBMPDCLIENT_CHECK_VERSION(2,5,0)
	if (subscribed && (idle & MPD_IDLE_MESSAGE) != 0 &&
	    !lmc_read_messages()) {
		lmc_failure();
		lmc_schedule_reconnect();
		return false;
	}
#endif

	if (idle & MPD_IDLE_PLAYER)
		/* there was a change: query MPD */
		lmc_schedule_update();
	else
		/* nothing interesting: re-enter idle */
		lmc_schedule_idle();

	return false;
}
Exemplo n.º 16
0
Arquivo: mpd.c Projeto: cmende/mpd2irc
void mpd_say_status(void)
{
	gchar *state;
	gchar *artist, *title;

	if (!mpd.conn) {
		irc_say("Not connected to MPD");
		return;
	}

	if (mpd.status)
		mpd_status_free(mpd.status);

	mpd_run_noidle(mpd.conn);
	mpd.status = mpd_run_status(mpd.conn);
	if (!mpd_response_finish(mpd.conn)) {
		mpd_report_error();
		return;
	}
	mpd_send_idle_mask(mpd.conn, MPD_IDLE_PLAYER);

	switch (mpd_status_get_state(mpd.status)) {
		case MPD_STATE_STOP:
			state = g_strdup("stopped"); break;
		case MPD_STATE_PLAY:
			state = g_strdup("playing"); break;
		case MPD_STATE_PAUSE:
			state = g_strdup("paused"); break;
		default:
			state = g_strdup("unknown"); break;
	}

	if (mpd.song) {
		artist = g_strdup(mpd_song_get_tag(mpd.song, MPD_TAG_ARTIST,
					0));
		title = g_strdup(mpd_song_get_tag(mpd.song, MPD_TAG_TITLE, 0));
	} else {
		artist = g_strdup("");
		title = g_strdup("");
	}

	irc_say("[%s] %s - %s (%i:%02i/%i:%02i) | repeat: %sabled | "
			"random: %sabled | announce: %sabled",
			state, artist, title,
			mpd_status_get_elapsed_time(mpd.status) / 60,
			mpd_status_get_elapsed_time(mpd.status) % 60,
			mpd_status_get_total_time(mpd.status) / 60,
			mpd_status_get_total_time(mpd.status) % 60,
			(mpd_status_get_repeat(mpd.status) ? "en" : "dis"),
			(mpd_status_get_random(mpd.status) ? "en" : "dis"),
			(prefs.announce ? "en" : "dis"));
	g_free(state);
	g_free(artist);
	g_free(title);
}
Exemplo n.º 17
0
unsigned mpd_get_queue_length()
{
    unsigned length = 0;
    struct mpd_status *status = mpd_run_status(mpd.conn);
    if (status != NULL) {
        length = mpd_status_get_queue_length(status);
        mpd_status_free(status);
    }
    mpd_response_finish(mpd.conn);
    return length;
}
Exemplo n.º 18
0
static void toggleRandom()
{
    mpd_update();
    if (currentSong != NULL) {
	l_randomEnabled = !l_randomEnabled;
	if ((!mpd_run_random(conn, l_randomEnabled))
	    || (!mpd_response_finish(conn))) {
	    mpd_printerror("run_random");
	}
    }
}
Exemplo n.º 19
0
static void toggleConsume()
{
    mpd_update();
    if (currentSong != NULL) {
	l_consumeEnabled = !l_consumeEnabled;
	if ((!mpd_run_consume(conn, l_consumeEnabled))
	    || (!mpd_response_finish(conn))) {
	    mpd_printerror("run_consume");
	}
    }
}
Exemplo n.º 20
0
int main() {
	char fullpath[100], text[100];
	char *buf = NULL, *sub = NULL, *state = NULL;
	
	conn = mpd_connection_new(NULL, 0, 10000);
	notify = notify_notification_new(NULL, NULL, NULL);
	notify_init("mpdnotify");

	while(mpd_run_idle_mask(conn, MPD_IDLE_PLAYER)) {
		mpd_command_list_begin(conn, true);
		mpd_send_status(conn);
		mpd_send_current_song(conn);
		mpd_command_list_end(conn);

		status = mpd_recv_status(conn);
		if(mpd_status_get_state(status) == MPD_STATE_PLAY)
			state = "Playing:";
		else if(mpd_status_get_state(status) == MPD_STATE_PAUSE)
			state = "Paused:";
		else
			state = "Stopped:";
		mpd_response_next(conn);
		song = mpd_recv_song(conn);

		if(song) {
			artist = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);
			title = mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
			path = mpd_song_get_uri(song);

			sprintf(text, "%s - %s", artist, title);

			buf = fullpath;
			sub = strrchr(path, '/');
			buf = strcpy(buf, mpdroot);
			buf = strncat(buf, path, strlen(path) - strlen(sub) + 1);
			buf = strcat(buf, albumart);
			icon = gdk_pixbuf_new_from_file(fullpath, NULL);

			if(icon)
				notify_notification_update(notify, state, text, NULL);
			else
				notify_notification_update(notify, state, text, "sound");
			notify_notification_set_icon_from_pixbuf(notify, icon);
			notify_notification_show(notify, &gerror);

			mpd_song_free(song);
		}
		mpd_response_finish(conn);
	}
	mpd_connection_free(conn);
	notify_uninit();
	return 0;
}
Exemplo n.º 21
0
char *
get_mpd(void) {
	struct mpd_connection *con;
	struct mpd_status *status;
	struct mpd_song *song;
	int status_type;
	char *res;
	const char *artist = NULL, *title = NULL;

	con = mpd_connection_new(NULL, 0, 30000);
	if(mpd_connection_get_error(con)) {
		mpd_connection_free(con);
		return NO_MPD;
	}

	mpd_command_list_begin(con, true);
	mpd_send_status(con);
	mpd_send_current_song(con);
	mpd_command_list_end(con);

	status = mpd_recv_status(con);
	if(!status) {
		mpd_connection_free(con);
		return NO_MPD;
	}
	mpd_response_next(con);
	song = mpd_recv_song(con);
	title = mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
	if(!title)
		title = mpd_song_get_uri(song);
	artist = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);

	status_type = mpd_status_get_state(status);
	switch(status_type) {
		case(MPD_STATE_PLAY):
			res = smprintf(MPD, "Playing", artist, title);
			break;
		case(MPD_STATE_PAUSE):
			res = smprintf(MPD, "Paused", artist, title);
			break;
		case(MPD_STATE_STOP):
			res = smprintf(MPD, "Stopped", artist, title);
			break;
		default:
			res = NO_MPD;
			break;
	}
	mpd_song_free(song);
	mpd_response_finish(con);
	mpd_status_free(status);
	mpd_connection_free(con);
	return res;
}
Exemplo n.º 22
0
void Connection::PlaylistMove(const std::string &path, int from, int to)
{
	prechecks();
	if (m_command_list_active)
		mpd_send_playlist_move(m_connection.get(), path.c_str(), from, to);
	else
	{
		mpd_send_playlist_move(m_connection.get(), path.c_str(), from, to);
		mpd_response_finish(m_connection.get());
		checkErrors();
	}
}
Exemplo n.º 23
0
unsigned
mpd_run_rescan(struct mpd_connection *connection, const char *path)
{
	unsigned id;

	if (!mpd_run_check(connection) || !mpd_send_rescan(connection, path))
		return 0;

	id = mpd_recv_update_id(connection);
	return id != 0 && mpd_response_finish(connection)
		? id : 0;
}
Exemplo n.º 24
0
int Connection::noidle()
{
	checkConnection();
	int flags = 0;
	if (m_idle && mpd_send_noidle(m_connection.get()))
	{
		m_idle = false;
		flags = mpd_recv_idle(m_connection.get(), true);
		mpd_response_finish(m_connection.get());
		checkErrors();
	}
	return flags;
}
Exemplo n.º 25
0
static void volUp()
{
    mpd_update();
    if (currentSong != NULL) {
	l_volume += 5;
	if (l_volume > 100)
	    l_volume = 100;

	if ((!mpd_run_set_volume(conn, l_volume))
	    || (!mpd_response_finish(conn))) {
	    mpd_printerror("set_volume");
	}
    }
}
Exemplo n.º 26
0
std::string Connection::GetReplayGainMode()
{
	prechecksNoCommandsList();
	mpd_send_command(m_connection.get(), "replay_gain_status", NULL);
	std::string result;
	if (mpd_pair *pair = mpd_recv_pair_named(m_connection.get(), "replay_gain_mode"))
	{
		result = pair->value;
		mpd_return_pair(m_connection.get(), pair);
	}
	mpd_response_finish(m_connection.get());
	checkErrors();
	return result;
}
Exemplo n.º 27
0
int cmd_add (int argc, char ** argv, struct mpd_connection *conn )
{
	if (contains_absolute_path(argc, argv) && !path_prepare(conn))
		printErrorAndExit(conn);

	int i;

	if (!mpd_command_list_begin(conn, false))
		printErrorAndExit(conn);

	for(i=0;i<argc;i++) {
		strip_trailing_slash(argv[i]);

		const char *path = argv[i];
		const char *relative_path = to_relative_path(path);
		if (relative_path != NULL)
			path = relative_path;

		if (options.verbosity >= V_VERBOSE)
			printf("adding: %s\n", path);
		mpd_send_add(conn, charset_to_utf8(path));
	}

	if (!mpd_command_list_end(conn))
		printErrorAndExit(conn);

	if (!mpd_response_finish(conn)) {
#if LIBMPDCLIENT_CHECK_VERSION(2,4,0)
		if (mpd_connection_get_error(conn) == MPD_ERROR_SERVER) {
			/* check which of the arguments has failed */
			unsigned location =
				mpd_connection_get_server_error_location(conn);
			if (location < (unsigned)argc) {
				/* we've got a valid location from the
				   server */
				const char *message =
					mpd_connection_get_error_message(conn);
				message = charset_from_utf8(message);
				fprintf(stderr, "error adding %s: %s\n",
					argv[location], message);
				exit(EXIT_FAILURE);
			}
		}
#endif

		printErrorAndExit(conn);
	}

	return 0;
}
Exemplo n.º 28
0
static int fetch_items(MENU_SEARCH *menu,char *str,CLIENT_OBJECT *cli,DB_OBJECT *db)
{
    if (!(str && strlen(str)))
        return 1;

    /* send query */
    if (!mpd_search_db_songs(cli->conn,false))
        clear_or_exit_on_error(cli->conn);
    if (!mpd_search_add_tag_constraint(cli->conn,MPD_OPERATOR_DEFAULT,MPD_TAG_TITLE,str))
        clear_or_exit_on_error(cli->conn);
    if (!mpd_search_commit(cli->conn))
        clear_or_exit_on_error(cli->conn);

    /* process response */
    int block = 1024;
    menu->items = (MENU_SEARCH_ITEM*)calloc(block,sizeof(MENU_SEARCH_ITEM));

    struct mpd_song *song;
    int i = 0;
	while ((song = mpd_recv_song(cli->conn))) {

        /* realloc if memory not enough */
        if (i >= block) {
            block *= 2;
            menu->items = (MENU_SEARCH_ITEM*)realloc(menu->items,block*sizeof(MENU_SEARCH_ITEM));
        }

        unsigned id = mpd_song_get_id(song);
        const char *uri = mpd_song_get_uri(song);
        const char *title = mpd_song_get_tag(song,MPD_TAG_TITLE,0);

        menu->items[i].id = id;
        menu->items[i].title = (char *)malloc((strlen(title)+1)*sizeof(char));
        strcpy(menu->items[i].title,title);
        menu->items[i++].node = get_node_by_uri(db,uri);

		mpd_song_free(song);

	}

    if (mpd_connection_get_error(cli->conn) == MPD_ERROR_SUCCESS)
        mpd_response_finish(cli->conn);
    else
        clear_or_exit_on_error(cli->conn);

    menu->num = i;

    return 0;
}
Exemplo n.º 29
0
Arquivo: mpd.c Projeto: cmende/mpd2irc
void mpd_stop(void)
{
	if (!mpd.conn) {
		irc_say("Not connected to MPD");
		return;
	}

	mpd_run_noidle(mpd.conn);
	mpd_run_stop(mpd.conn);
	if (!mpd_response_finish(mpd.conn)) {
		mpd_report_error();
		return;
	}
	mpd_send_idle_mask(mpd.conn, MPD_IDLE_PLAYER);
}
Exemplo n.º 30
0
static void volDown()
{
    mpd_update();
    if (currentSong != NULL) {
	if (l_volume > 5)
	    l_volume -= 5;
	else
	    l_volume = 0;

	if ((!mpd_run_set_volume(conn, l_volume))
	    || (!mpd_response_finish(conn))) {
	    mpd_printerror("set_volume");
	}
    }
}