int cmd_crossfade ( int argc, char ** argv, struct mpd_connection *conn ) { if(argc==1) { int seconds; if(!parse_int(argv[0], &seconds) || seconds<0) DIE("\"%s\" is not 0 or positive integer\n",argv[0]); if (!mpd_run_crossfade(conn, seconds)) printErrorAndExit(conn); } else { struct mpd_status *status; status = getStatus(conn); printf("crossfade: %i\n", mpd_status_get_crossfade(status)); mpd_status_free(status); } return 0; }
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; }
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, \"crossfade\":%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_crossfade(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; }
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 status_changed(MpdObj *mi, ChangedStatusType what, thread_data *my_data) { if(what&MPD_CST_SONGID) { mpd_Song *song = mpd_playlist_get_current_song(mi); if(song) { printf( "Song:"" %s - %s\n", song->artist, song->title); } } if(what&MPD_CST_REPEAT){ printf("Repeat:"" %s\n", mpd_player_get_repeat(mi)? "On":"Off"); } if(what&MPD_CST_RANDOM){ printf("Random:"" %s\n", mpd_player_get_random(mi)? "On":"Off"); } if(what&MPD_CST_VOLUME){ printf("Volume:"" %03i%%\n", mpd_status_get_volume(mi)); my_data->mainLCD->printVolume(mpd_status_get_volume(mi)); try { my_data->ptr_MPD_info->volume= mpd_status_get_volume(mi); } catch (...) { log_file_mutex.mutex_lock(); log_file_cout << ERROR << "problem z wpisaniem volume "<< std::endl; log_file_mutex.mutex_unlock(); } } if(what&MPD_CST_CROSSFADE){ printf("X-Fade:"" %i sec.\n", mpd_status_get_crossfade(mi)); } if(what&MPD_CST_UPDATING) { if(mpd_status_db_is_updating(mi)) { printf("Started updating DB""\n"); } else { printf("Updating DB finished""\n"); } } if(what&MPD_CST_DATABASE) { printf("Databased changed""\n"); } if(what&MPD_CST_PLAYLIST) { printf("Playlist changed2""\n"); if (check_title_song_to==true) { mpd_Song *song = mpd_playlist_get_current_song(mi); // std::cout <<" SONG: " << song->artist<<" "<< song->title << std::endl; printf("aktualnie gramy:"" %s - %s\n", song->artist, song->title); try { my_data->ptr_MPD_info->title = std::string( song->title); } catch (...) { my_data->myEventHandler.run("mpd")->addEvent("wrong title"); my_data->ptr_MPD_info->title = "no data"; } try { my_data->ptr_MPD_info->artist = std::string( song->artist); } catch (...) { my_data->myEventHandler.run("mpd")->addEvent("wrong artist"); my_data->ptr_MPD_info->artist = "no data"; } if (song->name != NULL){ _msg = song->name; try { my_data->ptr_MPD_info->radio = _msg; } catch (...) { my_data->myEventHandler.run("mpd")->addEvent("wrong radio station name"); } my_data->mainLCD->printRadioName(true,0,0,_msg); my_data->mainLCD->set_lcd_STATE(5); std::string temp_str=""; temp_str = send_to_arduino(my_data,"temperature:2;"); temp_str.erase(temp_str.size()-2,temp_str.size()); my_data->mainLCD->printString(false,0,1,"temp:"+temp_str+" c"); updatePlayList(mi,my_data); } if (song->title != NULL ){ _msg = song->title; if (_msg.size() < 7 ) { _msg = song->name; _msg += " - brak nazwy "; } } else if (song->artist != NULL){ _msg = song->artist; } else { _msg += " - brak nazwy "; } // my_data->ptr_MPD_info->title = _msg; my_data->mainLCD->printSongName(_msg); } } if(what&MPD_CST_STATE) { printf("State:"); switch(mpd_player_get_state(mi)) { case MPD_PLAYER_PLAY: printf("Playing\n"); check_title_song_to=true; my_data->mainLCD->play_Y_N=true; my_data->ptr_MPD_info->isPlay=true; digitalWrite(GPIO_SPIK, LOW); my_data->mainLCD->set_lcd_STATE(1); my_data->mainLCD->song_printstr(); updatePlayList(mi,my_data); my_data->myEventHandler.run("mpd")->addEvent("MPD playing"); break; case MPD_PLAYER_PAUSE: printf("Paused\n"); my_data->mainLCD->set_lcd_STATE( -1); my_data->mainLCD->printString(true ,0,1," PAUSE"); my_data->myEventHandler.run("mpd")->addEvent("MPD pause"); break; case MPD_PLAYER_STOP: printf("Stopped\n"); if (my_data->ptr_MPD_info->isPlay ==true){ send_to_arduino(my_data,"LED_CLEAR:44;"); } check_title_song_to=false; my_data->mainLCD->play_Y_N=false; my_data->ptr_MPD_info->isPlay=false; my_data->ptr_MPD_info->title="* * * *"; digitalWrite(GPIO_SPIK,HIGH); my_data->mainLCD->noBacklight(); sleep(1); my_data->myEventHandler.run("mpd")->addEvent("MPD stopped"); break; default: break; } } /* not yet implemented signals */ if(what&MPD_CST_AUDIO){ printf("Audio Changed""\n"); } if(what&MPD_CST_TOTAL_TIME){ printf("Total song time changed:"" %02i:%02i\n", mpd_status_get_total_song_time(mi)/60, mpd_status_get_total_song_time(mi)%60); } if(what&MPD_CST_ELAPSED_TIME){ /* printf(GREEN"Time elapsed changed:"RESET" %02i:%02i\n", mpd_status_get_elapsed_song_time(mi)/60, mpd_status_get_elapsed_song_time(mi)%60); */ } if(what&MPD_CST_PERMISSION){ printf( "Permission:"" Changed\n"); } }