int mpd_put_state(char *buffer, int *current_song_id, unsigned *queue_version) { struct mpd_status *status; int len; status = mpd_run_status(mpd.conn); if (!status) { fprintf(stderr, "MPD mpd_run_status: %s\n", mpd_connection_get_error_message(mpd.conn)); mpd.conn_state = MPD_FAILURE; return 0; } len = snprintf(buffer, MAX_SIZE, "{\"type\":\"state\", \"data\":{" " \"state\":%d, \"volume\":%d, \"repeat\":%d," " \"single\":%d, \"consume\":%d, \"random\":%d, " " \"songpos\": %d, \"elapsedTime\": %d, \"totalTime\":%d, " " \"currentsongid\": %d" "}}", mpd_status_get_state(status), mpd_status_get_volume(status), mpd_status_get_repeat(status), mpd_status_get_single(status), mpd_status_get_consume(status), mpd_status_get_random(status), mpd_status_get_song_pos(status), mpd_status_get_elapsed_time(status), mpd_status_get_total_time(status), mpd_status_get_song_id(status)); *current_song_id = mpd_status_get_song_id(status); *queue_version = mpd_status_get_queue_version(status); mpd_status_free(status); return len; }
void mpd_put_state(void) { struct mpd_status *status; int len; unsigned queue_len; int song_pos, next_song_pos; status = mpd_run_status(mpd.conn); if (!status) { syslog(LOG_ERR, "%s mpd_run_status: %s\n", __func__, mpd_connection_get_error_message(mpd.conn)); mpd.conn_state = MPD_FAILURE; return; } mpd.song_pos = mpd_status_get_song_pos(status); mpd.next_song_pos = song_pos+1; //TODO: mpd_status_get_next_song_pos(status); mpd.queue_len = mpd_status_get_queue_length(status); mpd.volume = mpd_status_get_volume(status); mpd.state = mpd_status_get_state(status); mpd.repeat = mpd_status_get_repeat(status); mpd.single = mpd_status_get_single(status); mpd.consume = mpd_status_get_consume(status); mpd.random = mpd_status_get_random(status); mpd.elapsed_time = mpd_status_get_elapsed_time(status); mpd.total_time = mpd_status_get_total_time(status); mpd.song_id = mpd_status_get_song_id(status); // printf("%d\n", mpd.song_id); mpd_status_free(status); }
/* * pgmpc_single * Switch single mode. */ Datum pgmpc_single(PG_FUNCTION_ARGS) { bool is_single; pgmpc_init(); /* Get first status of server to determine next action */ mpd_status = mpd_run_status(mpd_conn); if (mpd_status == NULL) pgmpc_print_error(); /* Reverse single mode */ is_single = mpd_status_get_single(mpd_status); if (!mpd_run_single(mpd_conn, !is_single)) pgmpc_print_error(); pgmpc_reset(); PG_RETURN_BOOL(!is_single); }
void Mpd_status::assign_status(struct mpd_status * status) { const struct mpd_audio_format *format; uint32_t ms; volume = mpd_status_get_volume(status); repeat = mpd_status_get_repeat(status); single = mpd_status_get_single(status); random = mpd_status_get_random(status); consume = mpd_status_get_consume(status); playlist_length = mpd_status_get_queue_length(status); playlist = mpd_status_get_queue_version(status); state = mpd_status_get_state(status); crossfade = mpd_status_get_crossfade(status); song = mpd_status_get_song_pos(status); songid = mpd_status_get_song_id(status); time_total = mpd_status_get_total_time(status); db_updating = mpd_status_get_update_id(status); /* Time elapsed */ #if LIBMPDCLIENT_CHECK_VERSION(2, 1, 0) ms = mpd_status_get_elapsed_ms(status); #else ms = mpd_status_get_elapsed(status) * 1000; #endif set_time_elapsed_ms(ms); /* Audio format */ bitrate = mpd_status_get_kbit_rate(status); format = mpd_status_get_audio_format(status); if (!format) { return; } samplerate = format->sample_rate; bits = format->bits; channels = format->channels; }
void updatempdstatus(void) { char statustext[STEXTSIZE]; struct mpd_status *s = NULL; struct mpd_song *so = NULL; int s_volume, s_flagmask, s_queuelength, s_songpos, s_state, s_songlen, s_songtime; int s_time_r, s_time_min, s_time_sec; const char *artist, *title; if(mpdcmd_connect() != 0) return; s = mpd_run_status(mpdc); if(s == NULL) return; // retrieve status information if((s_state = mpd_status_get_state(s)) == MPD_STATE_STOP || (so = mpd_run_current_song(mpdc)) == NULL) goto EXIT; s_volume = mpd_status_get_volume(s); s_queuelength = mpd_status_get_queue_length(s); s_songpos = mpd_status_get_song_pos(s); s_songlen = mpd_status_get_total_time(s); s_songtime = mpd_status_get_elapsed_time(s); s_time_r = s_songlen - s_songtime; s_time_sec = s_time_r % 60; s_time_min = (s_time_r - s_time_sec) / 60; if(mpd_status_get_consume(s) == 1) s_flagmask |= MpdFlag_Consume; if(mpd_status_get_single(s) == 1) s_flagmask |= MpdFlag_Single; if(mpd_status_get_random(s) == 1) s_flagmask |= MpdFlag_Random; if(mpd_status_get_repeat(s) == 1) s_flagmask |= MpdFlag_Repeat; artist = mpd_song_get_tag(so, MPD_TAG_ARTIST, 0); title = mpd_song_get_tag(so, MPD_TAG_TITLE, 0); //%artist - %title (-%total-%elapsed) [$flags] [#%pos/%queuelength] snprintf(statustext, STEXTSIZE, "%s - %s (-%d:%02d)", artist != NULL ? artist : "名無し", title != NULL ? title : "曲名無し", s_time_min, s_time_sec); strncpy(stext, statustext, STEXTSIZE); EXIT:; mpd_song_free(so); mpd_status_free(s); return; }
bool handle_player_command(struct mpdclient *c, command_t cmd) { struct mpd_connection *connection; if (!mpdclient_is_connected(c) || c->status == NULL) return false; cancel_seek_timer(); switch(cmd) { /* case CMD_PLAY: mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING); break; */ case CMD_PAUSE: connection = mpdclient_get_connection(c); if (connection == NULL) break; if (!mpd_run_pause(connection, mpd_status_get_state(c->status) != MPD_STATE_PAUSE)) mpdclient_handle_error(c); break; case CMD_STOP: connection = mpdclient_get_connection(c); if (connection == NULL) break; if (!mpd_run_stop(connection)) mpdclient_handle_error(c); break; case CMD_CROP: mpdclient_cmd_crop(c); break; case CMD_SEEK_FORWARD: if (!setup_seek(c)) break; seek_target_time += options.seek_time; if (seek_target_time > (int)mpd_status_get_total_time(c->status)) seek_target_time = mpd_status_get_total_time(c->status); break; case CMD_TRACK_NEXT: connection = mpdclient_get_connection(c); if (connection == NULL) break; if (!mpd_run_next(connection)) mpdclient_handle_error(c); break; case CMD_SEEK_BACKWARD: if (!setup_seek(c)) break; seek_target_time -= options.seek_time; if (seek_target_time < 0) seek_target_time = 0; break; case CMD_TRACK_PREVIOUS: connection = mpdclient_get_connection(c); if (connection == NULL) break; if (!mpd_run_previous(connection)) mpdclient_handle_error(c); break; case CMD_SHUFFLE: connection = mpdclient_get_connection(c); if (connection == NULL) break; if (mpd_run_shuffle(connection)) screen_status_message(_("Shuffled playlist")); else mpdclient_handle_error(c); break; case CMD_CLEAR: connection = mpdclient_get_connection(c); if (connection == NULL) break; if (mpdclient_cmd_clear(c)) screen_status_message(_("Cleared playlist")); break; case CMD_REPEAT: connection = mpdclient_get_connection(c); if (connection == NULL) break; if (!mpd_run_repeat(connection, !mpd_status_get_repeat(c->status))) mpdclient_handle_error(c); break; case CMD_RANDOM: connection = mpdclient_get_connection(c); if (connection == NULL) break; if (!mpd_run_random(connection, !mpd_status_get_random(c->status))) mpdclient_handle_error(c); break; case CMD_SINGLE: connection = mpdclient_get_connection(c); if (connection == NULL) break; if (!mpd_run_single(connection, !mpd_status_get_single(c->status))) mpdclient_handle_error(c); break; case CMD_CONSUME: connection = mpdclient_get_connection(c); if (connection == NULL) break; if (!mpd_run_consume(connection, !mpd_status_get_consume(c->status))) mpdclient_handle_error(c); break; case CMD_CROSSFADE: connection = mpdclient_get_connection(c); if (connection == NULL) break; if (!mpd_run_crossfade(connection, mpd_status_get_crossfade(c->status) > 0 ? 0 : options.crossfade_time)) mpdclient_handle_error(c); break; case CMD_DB_UPDATE: screen_database_update(c, NULL); break; case CMD_VOLUME_UP: mpdclient_cmd_volume_up(c); break; case CMD_VOLUME_DOWN: mpdclient_cmd_volume_down(c); break; default: return false; } return true; }
static void env_export_status(struct mpd_status *status) { char *envstr; const struct mpd_audio_format *fmt; envstr = g_strdup_printf("%d", mpd_status_get_volume(status)); g_setenv("MPD_STATUS_VOLUME", envstr, 1); g_free(envstr); envstr = g_strdup_printf("%d", mpd_status_get_repeat(status)); g_setenv("MPD_STATUS_REPEAT", envstr, 1); g_free(envstr); envstr = g_strdup_printf("%d", mpd_status_get_random(status)); g_setenv("MPD_STATUS_RANDOM", envstr, 1); g_free(envstr); envstr = g_strdup_printf("%d", mpd_status_get_single(status)); g_setenv("MPD_STATUS_SINGLE", envstr, 1); g_free(envstr); envstr = g_strdup_printf("%d", mpd_status_get_consume(status)); g_setenv("MPD_STATUS_CONSUME", envstr, 1); g_free(envstr); envstr = g_strdup_printf("%d", mpd_status_get_queue_length(status)); g_setenv("MPD_STATUS_QUEUE_LENGTH", envstr, 1); g_free(envstr); envstr = g_strdup_printf("%d", mpd_status_get_queue_version(status)); g_setenv("MPD_STATUS_QUEUE_VERSION", envstr, 1); g_free(envstr); envstr = g_strdup_printf("%d", mpd_status_get_crossfade(status)); g_setenv("MPD_STATUS_CROSSFADE", envstr, 1); g_free(envstr); envstr = g_strdup_printf("%d", mpd_status_get_song_pos(status)); g_setenv("MPD_STATUS_SONG_POS", envstr, 1); g_free(envstr); envstr = g_strdup_printf("%d", mpd_status_get_song_id(status)); g_setenv("MPD_STATUS_SONG_ID", envstr, 1); g_free(envstr); envstr = g_strdup_printf("%u", mpd_status_get_elapsed_time(status)); g_setenv("MPD_STATUS_ELAPSED_TIME", envstr, 1); g_free(envstr); envstr = g_strdup_printf("%u", mpd_status_get_elapsed_ms(status)); g_setenv("MPD_STATUS_ELAPSED_MS", envstr, 1); g_free(envstr); envstr = g_strdup_printf("%u", mpd_status_get_total_time(status)); g_setenv("MPD_STATUS_TOTAL_TIME", envstr, 1); g_free(envstr); envstr = g_strdup_printf("%u", mpd_status_get_kbit_rate(status)); g_setenv("MPD_STATUS_KBIT_RATE", envstr, 1); g_free(envstr); envstr = g_strdup_printf("%u", mpd_status_get_update_id(status)); g_setenv("MPD_STATUS_UPDATE_ID", envstr, 1); g_free(envstr); g_setenv("MPD_STATUS_STATE", env_strstate(mpd_status_get_state(status)), 1); if ((fmt = mpd_status_get_audio_format(status)) == NULL) g_setenv("MPD_STATUS_AUDIO_FORMAT", "0", 1); else { g_setenv("MPD_STATUS_AUDIO_FORMAT", "1", 1); envstr = g_strdup_printf("%u", fmt->sample_rate); g_setenv("MPD_STATUS_AUDIO_FORMAT_SAMPLE_RATE", envstr, 1); g_free(envstr); envstr = g_strdup_printf("%u", fmt->bits); g_setenv("MPD_STATUS_AUDIO_FORMAT_BITS", envstr, 1); g_free(envstr); envstr = g_strdup_printf("%u", fmt->channels); g_setenv("MPD_STATUS_AUDIO_FORMAT_CHANNELS", envstr, 1); g_free(envstr); } }
void screen_update(struct mpdclient *c) { #ifndef NCMPC_MINI static bool was_connected; static bool initialized = false; static bool repeat; static bool random_enabled; static bool single; static bool consume; static unsigned crossfade; /* print a message if mpd status has changed */ if ((c->events & MPD_IDLE_OPTIONS) && c->status != NULL) { if (!initialized) { repeat = mpd_status_get_repeat(c->status); random_enabled = mpd_status_get_random(c->status); single = mpd_status_get_single(c->status); consume = mpd_status_get_consume(c->status); crossfade = mpd_status_get_crossfade(c->status); initialized = true; } if (repeat != mpd_status_get_repeat(c->status)) screen_status_printf(mpd_status_get_repeat(c->status) ? _("Repeat mode is on") : _("Repeat mode is off")); if (random_enabled != mpd_status_get_random(c->status)) screen_status_printf(mpd_status_get_random(c->status) ? _("Random mode is on") : _("Random mode is off")); if (single != mpd_status_get_single(c->status)) screen_status_printf(mpd_status_get_single(c->status) ? /* "single" mode means that MPD will automatically stop after playing one single song */ _("Single mode is on") : _("Single mode is off")); if (consume != mpd_status_get_consume(c->status)) screen_status_printf(mpd_status_get_consume(c->status) ? /* "consume" mode means that MPD removes each song which has finished playing */ _("Consume mode is on") : _("Consume mode is off")); if (crossfade != mpd_status_get_crossfade(c->status)) screen_status_printf(_("Crossfade %d seconds"), mpd_status_get_crossfade(c->status)); repeat = mpd_status_get_repeat(c->status); random_enabled = mpd_status_get_random(c->status); single = mpd_status_get_single(c->status); consume = mpd_status_get_consume(c->status); crossfade = mpd_status_get_crossfade(c->status); } if ((c->events & MPD_IDLE_DATABASE) != 0 && was_connected && mpdclient_is_connected(c)) screen_status_printf(_("Database updated")); was_connected = mpdclient_is_connected(c); /* update title/header window */ if (screen.welcome_source_id != 0) paint_top_window("", c); else #endif if (mode_fn->get_title != NULL) { paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c); } else paint_top_window("", c); /* update progress window */ update_progress_window(c, false); /* update status window */ status_bar_paint(&screen.status_bar, c->status, c->song); /* update the main window */ if (mode_fn->update != NULL) mode_fn->update(c); /* move the cursor to the origin */ if (!options.hardware_cursor) wmove(screen.main_window.w, 0, 0); wnoutrefresh(screen.main_window.w); /* tell curses to update */ doupdate(); }
static int lmpdstatus_index(lua_State *L) { const char *key; const struct mpd_audio_format *audio_format; struct mpd_status **status; status = luaL_checkudata(L, 1, MPD_STATUS_T); key = luaL_checkstring(L, 2); assert(*status != NULL); if (strncmp(key, "volume", 7) == 0) { lua_pushinteger(L, mpd_status_get_volume(*status)); return 1; } else if (strncmp(key, "repeat", 7) == 0) { lua_pushinteger(L, mpd_status_get_repeat(*status)); return 1; } else if (strncmp(key, "random", 7) == 0) { lua_pushinteger(L, mpd_status_get_random(*status)); return 1; } else if (strncmp(key, "single", 7) == 0) { lua_pushinteger(L, mpd_status_get_single(*status)); return 1; } else if (strncmp(key, "consume", 8) == 0) { lua_pushinteger(L, mpd_status_get_consume(*status)); return 1; } else if (strncmp(key, "queue_length", 16) == 0) { lua_pushnumber(L, mpd_status_get_queue_length(*status)); return 1; } else if (strncmp(key, "queue_version", 17) == 0) { lua_pushnumber(L, mpd_status_get_queue_version(*status)); return 1; } else if (strncmp(key, "state", 6) == 0) { lua_pushinteger(L, mpd_status_get_state(*status)); return 1; } else if (strncmp(key, "crossfade", 10) == 0) { lua_pushinteger(L, mpd_status_get_crossfade(*status)); return 1; } else if (strncmp(key, "song_pos", 5) == 0) { lua_pushinteger(L, mpd_status_get_song_pos(*status)); return 1; } else if (strncmp(key, "song_id", 7) == 0) { lua_pushinteger(L, mpd_status_get_song_id(*status)); return 1; } else if (strncmp(key, "elapsed_time", 13) == 0) { lua_pushinteger(L, mpd_status_get_elapsed_time(*status)); return 1; } else if (strncmp(key, "total_time", 11) == 0) { lua_pushinteger(L, mpd_status_get_total_time(*status)); return 1; } else if (strncmp(key, "kbit_rate", 10) == 0) { lua_pushinteger(L, mpd_status_get_kbit_rate(*status)); return 1; } else if (strncmp(key, "audio_format", 13) == 0) { audio_format = mpd_status_get_audio_format(*status); lua_newtable(L); lua_pushinteger(L, audio_format->sample_rate); lua_setfield(L, -2, "sample_rate"); lua_pushinteger(L, audio_format->bits); lua_setfield(L, -2, "bits"); lua_pushinteger(L, audio_format->channels); lua_setfield(L, -2, "channels"); return 1; } else if (strncmp(key, "update_id", 11) == 0) { lua_pushinteger(L, mpd_status_get_update_id(*status)); return 1; } else if (strncmp(key, "error", 6) == 0) { lua_pushstring(L, mpd_status_get_error(*status)); return 1; } else return luaL_error(L, "Invalid key `%s'", key); }
void basic_state_checking(void) { int rep, ran, sgl, len, crt, vol, ply, btr; struct mpd_status *status; status = getStatus(conn); rep = mpd_status_get_repeat(status); ran = mpd_status_get_random(status); sgl = mpd_status_get_single(status); len = mpd_status_get_queue_length(status); crt = mpd_status_get_song_id(status); vol = mpd_status_get_volume(status); ply = mpd_status_get_state(status); btr = mpd_status_get_kbit_rate(status); basic_info->crt_time = mpd_status_get_elapsed_time(status); basic_info->total_time = mpd_status_get_total_time(status); mpd_status_free(status); if(rep != basic_info->repeat || ran != basic_info->random || sgl != basic_info->single || len != basic_info->total || crt != basic_info->current || vol != basic_info->volume || ply != basic_info->state) { basic_info->repeat = rep; basic_info->random = ran; basic_info->single = sgl; basic_info->total = len; basic_info->current = crt; basic_info->volume = vol; basic_info->state = ply; signal_all_wins(); } /* as many songs's bit rate varies while playing we refresh the bit rate display only when the relevant change greater than 0.2 */ if(abs(basic_info->bit_rate - btr) / (float)(btr + 1) > 0.2) { basic_info->bit_rate = btr; signal_win(BASIC_INFO); } /* get current song's name */ status = init_mpd_status(conn); strncpy(basic_info->format, "null", 16); *basic_info->crt_name = '\0'; if (basic_info->state == MPD_STATE_PLAY || basic_info->state == MPD_STATE_PAUSE) { struct mpd_song *song; if (!mpd_response_next(conn)) printErrorAndExit(conn); song = mpd_recv_song(conn); if (song != NULL) { strncpy(basic_info->crt_name, get_song_tag(song, MPD_TAG_TITLE), 512); strncpy(basic_info->format, get_song_format(song), 16); } mpd_song_free(song); } mpd_status_free(status); my_finishCommand(conn); }
void mpd_query_status(struct mpd_connection *conn) { struct mpd_status *status; struct mpd_song *song; const struct mpd_audio_format *audio; if (!conn) return; if (!mpd_command_list_begin(conn, true) || !mpd_send_status(conn) || !mpd_send_current_song(conn) || !mpd_command_list_end(conn)) { mpd_printerror("queue_commands"); return; } status = mpd_recv_status(conn); if (status == NULL) { mpd_printerror("recv_status"); return; } if (currentSong != NULL) { mpd_song_free(currentSong); currentSong = NULL; } if (!mpd_response_next(conn)) { mpd_printerror("response_next"); return; } song = mpd_recv_song(conn); if (song != NULL) { currentSong = mpd_song_dup(song); mpd_song_free(song); l_elapsedTimeSec = mpd_status_get_elapsed_time(status); l_totalTimeSec = mpd_status_get_total_time(status); l_bitRate = mpd_status_get_kbit_rate(status); } else { l_elapsedTimeSec = 0; l_totalTimeSec = 0; l_bitRate = 0; } l_state = mpd_status_get_state(status); l_repeatEnabled = mpd_status_get_repeat(status); l_randomEnabled = mpd_status_get_random(status); l_singleEnabled = mpd_status_get_single(status); l_consumeEnabled = mpd_status_get_consume(status); l_volume = mpd_status_get_volume(status); l_currentSongPos = mpd_status_get_song_pos(status) + 1; l_playlistLength = mpd_status_get_queue_length(status); audio = mpd_status_get_audio_format(status); if (audio) { l_sampleRate = audio->sample_rate; l_channels = audio->channels; } else { l_sampleRate = 0; l_channels = 0; } if (mpd_status_get_error(status) != NULL) error("[MPD] query status : %s", charset_from_utf8(mpd_status_get_error(status))); mpd_status_free(status); if (!mpd_response_finish(conn)) { mpd_printerror("response_finish"); return; } }
void print_status(struct mpd_connection *conn) { if (!mpd_command_list_begin(conn, true) || !mpd_send_status(conn) || !mpd_send_current_song(conn) || !mpd_command_list_end(conn)) printErrorAndExit(conn); struct mpd_status *status = mpd_recv_status(conn); if (status == NULL) printErrorAndExit(conn); if (mpd_status_get_state(status) == MPD_STATE_PLAY || mpd_status_get_state(status) == MPD_STATE_PAUSE) { if (!mpd_response_next(conn)) printErrorAndExit(conn); struct mpd_song *song = mpd_recv_song(conn); if (song != NULL) { pretty_print_song(song); printf("\n"); mpd_song_free(song); } if (mpd_status_get_state(status) == MPD_STATE_PLAY) printf("[playing]"); else printf("[paused] "); printf(" #%i/%u %3i:%02i/%i:%02i (%u%%)\n", mpd_status_get_song_pos(status) + 1, mpd_status_get_queue_length(status), mpd_status_get_elapsed_time(status) / 60, mpd_status_get_elapsed_time(status) % 60, mpd_status_get_total_time(status) / 60, mpd_status_get_total_time(status) % 60, elapsed_percent(status)); } if (mpd_status_get_update_id(status) > 0) printf("Updating DB (#%u) ...\n", mpd_status_get_update_id(status)); if (mpd_status_get_volume(status) >= 0) printf("volume:%3i%c ", mpd_status_get_volume(status), '%'); else { printf("volume: n/a "); } printf("repeat: "); if (mpd_status_get_repeat(status)) printf("on "); else printf("off "); printf("random: "); if (mpd_status_get_random(status)) printf("on "); else printf("off "); printf("single: "); if (mpd_status_get_single(status)) printf("on "); else printf("off "); printf("consume: "); if (mpd_status_get_consume(status)) printf("on \n"); else printf("off\n"); if (mpd_status_get_error(status) != NULL) printf("ERROR: %s\n", charset_from_utf8(mpd_status_get_error(status))); mpd_status_free(status); if (!mpd_response_finish(conn)) printErrorAndExit(conn); }