diff options
author | Andrzej Rybczak <electricityispower@gmail.com> | 2014-09-03 19:07:55 +0200 |
---|---|---|
committer | Andrzej Rybczak <electricityispower@gmail.com> | 2014-09-03 20:08:00 +0200 |
commit | 06a07b0d334e1898b033bbe7c4a596324d57a6a1 (patch) | |
tree | 197a2d344e374c8977b41a5ea62f1c09ba45f8b6 | |
parent | 18de4c1e7720c24551f3891d2227209bb2a1ab27 (diff) |
status: fix toggling flags
-rw-r--r-- | src/actions.cpp | 62 | ||||
-rw-r--r-- | src/display.cpp | 4 | ||||
-rw-r--r-- | src/ncmpcpp.cpp | 2 | ||||
-rw-r--r-- | src/playlist.cpp | 28 | ||||
-rw-r--r-- | src/playlist.h | 8 | ||||
-rw-r--r-- | src/sel_items_adder.cpp | 8 | ||||
-rw-r--r-- | src/status.cpp | 84 | ||||
-rw-r--r-- | src/status.h | 15 | ||||
-rw-r--r-- | src/statusbar.cpp | 8 | ||||
-rw-r--r-- | src/visualizer.cpp | 2 |
10 files changed, 72 insertions, 149 deletions
diff --git a/src/actions.cpp b/src/actions.cpp index e7e5e710..80ee9b8e 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -331,14 +331,14 @@ void MouseEvent::run() && m_mouse_event.y == LINES-(Config.statusbar_visibility ? 2 : 1) ) // progressbar { - if (Status::State::player() == MPD::psStop) + if (Status::get().playerState() == MPD::psStop) return; - Mpd.Seek(myPlaylist->currentSongPosition(), - myPlaylist->currentSongLength()*m_mouse_event.x/double(COLS)); + Mpd.Seek(Status::get().currentSongPosition(), + Status::get().totalTime()*m_mouse_event.x/double(COLS)); } else if (m_mouse_event.bstate & BUTTON1_PRESSED && (Config.statusbar_visibility || Config.design == Design::Alternative) - && Status::State::player() != MPD::psStop + && Status::get().playerState() != MPD::psStop && m_mouse_event.y == (Config.design == Design::Alternative ? 1 : LINES-1) && m_mouse_event.x < 9 ) // playing/paused @@ -616,13 +616,13 @@ void SlaveScreen::run() void VolumeUp::run() { - int volume = std::min(Status::State::volume()+Config.volume_change_step, 100u); + int volume = std::min(Status::get().volume()+Config.volume_change_step, 100u); Mpd.SetVolume(volume); } void VolumeDown::run() { - int volume = std::max(int(Status::State::volume()-Config.volume_change_step), 0); + int volume = std::max(int(Status::get().volume()-Config.volume_change_step), 0); Mpd.SetVolume(volume); } @@ -744,8 +744,8 @@ void DeleteStoredPlaylist::run() void ReplaySong::run() { - if (Status::State::player() != MPD::psStop) - Mpd.Seek(myPlaylist->currentSongPosition(), 0); + if (Status::get().playerState() != MPD::psStop) + Mpd.Seek(Status::get().currentSongPosition(), 0); } void PreviousSong::run() @@ -979,7 +979,7 @@ void Add::run() bool SeekForward::canBeRun() const { - return Status::State::player() != MPD::psStop && myPlaylist->currentSongLength() > 0; + return Status::get().playerState() != MPD::psStop && Status::get().totalTime() > 0; } void SeekForward::run() @@ -989,7 +989,7 @@ void SeekForward::run() bool SeekBackward::canBeRun() const { - return Status::State::player() != MPD::psStop && myPlaylist->currentSongLength() > 0; + return Status::get().playerState() != MPD::psStop && Status::get().totalTime() > 0; } void SeekBackward::run() @@ -1140,9 +1140,9 @@ void TogglePlayingSongCentering::run() Config.autocenter_mode ? "on" : "off" ); if (Config.autocenter_mode - && Status::State::player() != MPD::psStop + && Status::get().playerState() != MPD::psStop && !myPlaylist->main().isFiltered()) - myPlaylist->main().highlight(myPlaylist->currentSongPosition()); + myPlaylist->main().highlight(Status::get().currentSongPosition()); } void UpdateDatabase::run() @@ -1162,13 +1162,13 @@ bool JumpToPlayingSong::canBeRun() const return ((myScreen == myPlaylist && !myPlaylist->isFiltered()) || myScreen == myBrowser || myScreen == myLibrary) - && Status::State::player() != MPD::psStop; + && Status::get().playerState() != MPD::psStop; } void JumpToPlayingSong::run() { if (myScreen == myPlaylist) - myPlaylist->main().highlight(myPlaylist->currentSongPosition()); + myPlaylist->main().highlight(Status::get().currentSongPosition()); else if (myScreen == myBrowser) { myBrowser->LocateSong(myPlaylist->nowPlayingSong()); @@ -1182,7 +1182,7 @@ void JumpToPlayingSong::run() void ToggleRepeat::run() { - Mpd.SetRepeat(!Status::State::repeat()); + Mpd.SetRepeat(!Status::get().repeat()); } void Shuffle::run() @@ -1192,7 +1192,7 @@ void Shuffle::run() void ToggleRandom::run() { - Mpd.SetRandom(!Status::State::random()); + Mpd.SetRandom(!Status::get().random()); } bool StartSearching::canBeRun() const @@ -1237,17 +1237,17 @@ void SaveTagChanges::run() void ToggleSingle::run() { - Mpd.SetSingle(!Status::State::single()); + Mpd.SetSingle(!Status::get().single()); } void ToggleConsume::run() { - Mpd.SetConsume(!Status::State::consume()); + Mpd.SetConsume(!Status::get().consume()); } void ToggleCrossfade::run() { - Mpd.SetCrossfade(Status::State::crossfade() ? 0 : Config.crossfade_time); + Mpd.SetCrossfade(Status::get().crossfade() ? 0 : Config.crossfade_time); } void SetCrossfade::run() @@ -1612,7 +1612,7 @@ void JumpToTagEditor::run() bool JumpToPositionInSong::canBeRun() const { - return Status::State::player() != MPD::psStop && myPlaylist->currentSongLength() > 0; + return Status::get().playerState() != MPD::psStop && Status::get().totalTime() > 0; } void JumpToPositionInSong::run() @@ -2668,7 +2668,7 @@ void seek() using Global::Timer; using Global::SeekingInProgress; - if (!myPlaylist->currentSongLength()) + if (!Status::get().totalTime()) { Statusbar::print("Unknown item length"); return; @@ -2676,8 +2676,8 @@ void seek() Progressbar::lock(); Statusbar::lock(); - - unsigned songpos = Status::State::elapsedTime(); + + unsigned songpos = Status::elapsedTime(); auto t = Timer; int old_timeout = wFooter->getTimeout(); @@ -2702,8 +2702,8 @@ void seek() auto a = k.first->action(); if (a == seekForward) { - if (songpos < myPlaylist->currentSongLength()) - songpos = std::min(songpos + howmuch, myPlaylist->currentSongLength()); + if (songpos < Status::get().totalTime()) + songpos = std::min(songpos + howmuch, Status::get().totalTime()); } else if (a == seekBackward) { @@ -2727,12 +2727,12 @@ void seek() if (Config.display_remaining_time) { tracklength += "-"; - tracklength += MPD::Song::ShowTime(myPlaylist->currentSongLength()-songpos); + tracklength += MPD::Song::ShowTime(Status::get().totalTime()-songpos); } else tracklength += MPD::Song::ShowTime(songpos); tracklength += "/"; - tracklength += MPD::Song::ShowTime(myPlaylist->currentSongLength()); + tracklength += MPD::Song::ShowTime(Status::get().totalTime()); tracklength += "]"; *wFooter << NC::XY(wFooter->getWidth()-tracklength.length(), 1) << tracklength; break; @@ -2740,22 +2740,22 @@ void seek() if (Config.display_remaining_time) { tracklength = "-"; - tracklength += MPD::Song::ShowTime(myPlaylist->currentSongLength()-songpos); + tracklength += MPD::Song::ShowTime(Status::get().totalTime()-songpos); } else tracklength = MPD::Song::ShowTime(songpos); tracklength += "/"; - tracklength += MPD::Song::ShowTime(myPlaylist->currentSongLength()); + tracklength += MPD::Song::ShowTime(Status::get().totalTime()); *wHeader << NC::XY(0, 0) << tracklength << " "; wHeader->refresh(); break; } *wFooter << NC::Format::NoBold; - Progressbar::draw(songpos, myPlaylist->currentSongLength()); + Progressbar::draw(songpos, Status::get().totalTime()); wFooter->refresh(); } SeekingInProgress = false; - Mpd.Seek(myPlaylist->currentSongPosition(), songpos); + Mpd.Seek(Status::get().currentSongPosition(), songpos); wFooter->setTimeout(old_timeout); diff --git a/src/display.cpp b/src/display.cpp index ec9010ed..64b10ef6 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -97,8 +97,8 @@ void setProperties(NC::Menu<T> &menu, const MPD::Song &s, const ProxySongList &p discard_colors = Config.discard_colors_if_item_is_selected && is_selected; int song_pos = menu.isFiltered() ? s.getPosition() : drawn_pos; - is_now_playing = Status::State::player() != MPD::psStop && myPlaylist->isActiveWindow(menu) - && song_pos == myPlaylist->currentSongPosition(); + is_now_playing = Status::get().playerState() != MPD::psStop && myPlaylist->isActiveWindow(menu) + && song_pos == Status::get().currentSongPosition(); if (is_now_playing) menu << Config.now_playing_prefix; } diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 5d89ad5b..f821b022 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -174,7 +174,7 @@ int main(int argc, char **argv) if (Config.jump_to_now_playing_song_at_start) { - int curr_pos = myPlaylist->currentSongPosition(); + int curr_pos = Status::get().currentSongPosition(); if (curr_pos >= 0) myPlaylist->main().highlight(curr_pos); } diff --git a/src/playlist.cpp b/src/playlist.cpp index 1a603729..f6828ce4 100644 --- a/src/playlist.cpp +++ b/src/playlist.cpp @@ -48,7 +48,7 @@ bool playlistEntryMatcher(const boost::regex &rx, const MPD::Song &s); } Playlist::Playlist() -: m_total_length(0), m_remaining_time(0), m_scroll_begin(0), m_old_playlist_version(0) +: m_total_length(0), m_remaining_time(0), m_scroll_begin(0) , m_reload_total_length(false), m_reload_remaining(false) { w = NC::Menu<MPD::Song>(0, MainStartY, COLS, MainHeight, Config.playlist_display_mode == DisplayMode::Columns && Config.titles_visibility ? Display::Columns(COLS) : "", Config.main_color, NC::Border::None); @@ -249,9 +249,9 @@ MPD::SongList Playlist::getSelectedSongs() MPD::Song Playlist::nowPlayingSong() { MPD::Song s; - if (Status::State::player() != MPD::psStop) + if (Status::get().playerState() != MPD::psStop) withUnfilteredMenu(w, [this, &s]() { - s = w.at(currentSongPosition()).value(); + s = w.at(Status::get().currentSongPosition()).value(); }); return s; } @@ -298,7 +298,7 @@ std::string Playlist::getTotalLength() if (Config.playlist_show_remaining_time && m_reload_remaining && !w.isFiltered()) { m_remaining_time = 0; - for (size_t i = currentSongPosition(); i < w.size(); ++i) + for (size_t i = Status::get().currentSongPosition(); i < w.size(); ++i) m_remaining_time += w[i].value().getDuration(); m_reload_remaining = false; } @@ -338,26 +338,6 @@ void Playlist::SetSelectedItemsPriority(int prio) Statusbar::print("Priority set"); } -void Playlist::setStatus(MPD::Status status) -{ - m_status = status; -} - -unsigned Playlist::oldVersion() const -{ - return m_old_playlist_version; -} - -int Playlist::currentSongPosition() const -{ - return m_status.empty() ? -1 : m_status.currentSongPosition(); -} - -unsigned Playlist::currentSongLength() const -{ - return m_status.empty() ? 0 : m_status.totalTime(); -} - bool Playlist::checkForSong(const MPD::Song &s) { return m_song_refs.find(s) != m_song_refs.end(); diff --git a/src/playlist.h b/src/playlist.h index 33f3733a..2df8f881 100644 --- a/src/playlist.h +++ b/src/playlist.h @@ -75,11 +75,6 @@ struct Playlist: Screen<NC::Menu<MPD::Song>>, Filterable, HasSongs, Searchable, void SetSelectedItemsPriority(int prio); - void setStatus(MPD::Status status); - unsigned oldVersion() const; - int currentSongPosition() const; - unsigned currentSongLength() const; - bool checkForSong(const MPD::Song &s); void registerSong(const MPD::Song &s); void unregisterSong(const MPD::Song &s); @@ -102,9 +97,6 @@ private: size_t m_scroll_begin; boost::posix_time::ptime m_timer; - - MPD::Status m_status; - unsigned m_old_playlist_version; bool m_reload_total_length; bool m_reload_remaining; diff --git a/src/sel_items_adder.cpp b/src/sel_items_adder.cpp index c9fb955e..97d44a69 100644 --- a/src/sel_items_adder.cpp +++ b/src/sel_items_adder.cpp @@ -255,9 +255,9 @@ void SelectedItemsAdder::addAtTheBeginningOfPlaylist() const void SelectedItemsAdder::addAfterCurrentSong() const { - if (Status::State::player() == MPD::psStop) + if (Status::get().playerState() == MPD::psStop) return; - size_t pos = myPlaylist->currentSongPosition(); + size_t pos = Status::get().currentSongPosition(); ++pos; bool success = addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, pos); exitSuccessfully(success); @@ -265,10 +265,10 @@ void SelectedItemsAdder::addAfterCurrentSong() const void SelectedItemsAdder::addAfterCurrentAlbum() const { - if (Status::State::player() == MPD::psStop) + if (Status::get().playerState() == MPD::psStop) return; auto &pl = myPlaylist->main(); - size_t pos = myPlaylist->currentSongPosition(); + size_t pos = Status::get().currentSongPosition(); withUnfilteredMenu(pl, [&pos, &pl]() { std::string album = pl[pos].value().getAlbum(); while (pos < pl.size() && pl[pos].value().getAlbum() == album) diff --git a/src/status.cpp b/src/status.cpp index 41925693..9caa5fea 100644 --- a/src/status.cpp +++ b/src/status.cpp @@ -61,8 +61,6 @@ char m_crossfade = 0; char m_db_updating = 0; MPD::Status m_status; -MPD::PlayerState m_player_state = MPD::psUnknown; -int m_volume = -1; unsigned m_elapsed_time = 0; void drawTitle(const MPD::Song &np) @@ -137,7 +135,7 @@ void Status::trace(bool update_timer, bool update_window_timeout) Timer = boost::posix_time::microsec_clock::local_time(); if (Mpd.Connected()) { - if (State::player() == MPD::psPlay + if (m_status.playerState() == MPD::psPlay && Global::Timer - past > boost::posix_time::seconds(1)) { // update elapsed time/bitrate of the current song @@ -167,16 +165,14 @@ void Status::update(int event) { MPD::Status old_status = m_status; m_status = Mpd.getStatus(); - m_player_state = m_status.playerState(); - m_volume = m_status.volume(); - myPlaylist->setStatus(m_status); + m_elapsed_time = m_status.elapsedTime(); if (event & MPD_IDLE_DATABASE) Changes::database(); if (event & MPD_IDLE_STORED_PLAYLIST) Changes::storedPlaylists(); if (event & MPD_IDLE_PLAYLIST) - Changes::playlist(); + Changes::playlist(old_status.empty() ? 0 : old_status.playlistVersion()); if (event & MPD_IDLE_PLAYER) { Changes::playerState(); @@ -216,52 +212,22 @@ void Status::update(int event) /*************************************************************************/ -bool Status::State::repeat() +const MPD::Status &Status::get() { - return m_repeat; + return m_status; } -bool Status::State::random() -{ - return m_random; -} - -bool Status::State::single() -{ - return m_single; -} - -bool Status::State::consume() -{ - return m_consume; -} - -bool Status::State::crossfade() -{ - return m_crossfade; -} - -MPD::PlayerState Status::State::player() -{ - return m_player_state; -} - -int Status::State::volume() -{ - return m_volume; -} - -unsigned int Status::State::elapsedTime() +unsigned Status::elapsedTime() { return m_elapsed_time; } /*************************************************************************/ -void Status::Changes::playlist() +void Status::Changes::playlist(unsigned previous_version) { myPlaylist->main().clearSearchResults(); - withUnfilteredMenuReapplyFilter(myPlaylist->main(), []() { + withUnfilteredMenuReapplyFilter(myPlaylist->main(), [previous_version]() { size_t playlist_length = m_status.playlistLength(); if (playlist_length < myPlaylist->main().size()) { @@ -272,7 +238,7 @@ void Status::Changes::playlist() myPlaylist->main().resizeList(playlist_length); } - Mpd.GetPlaylistChanges(myPlaylist->oldVersion(), [](MPD::Song s) { + Mpd.GetPlaylistChanges(previous_version, [](MPD::Song s) { size_t pos = s.getPosition(); if (pos < myPlaylist->main().size()) { @@ -287,7 +253,7 @@ void Status::Changes::playlist() }); }); - if (State::player() != MPD::psStop) + if (m_status.playerState() != MPD::psStop) drawTitle(myPlaylist->nowPlayingSong()); myPlaylist->reloadTotalLength(); @@ -337,7 +303,7 @@ void Status::Changes::database() void Status::Changes::playerState() { - switch (State::player()) + switch (m_status.playerState()) { case MPD::psPlay: drawTitle(myPlaylist->nowPlayingSong()); @@ -363,7 +329,7 @@ void Status::Changes::playerState() break; } - std::string state = playerStateToString(State::player()); + std::string state = playerStateToString(m_status.playerState()); if (Config.design == Design::Alternative) { *wHeader << NC::XY(0, 1) << NC::Format::Bold << state << NC::Format::NoBold; @@ -386,12 +352,11 @@ void Status::Changes::playerState() void Status::Changes::songID() { // update information about current song - myPlaylist->setStatus(m_status); myPlaylist->reloadRemaining(); playing_song_scroll_begin = 0; first_line_scroll_begin = 0; second_line_scroll_begin = 0; - if (State::player() != MPD::psStop) + if (m_status.playerState() != MPD::psStop) { GNUC_UNUSED int res; if (!Config.execute_on_song_change.empty()) @@ -405,7 +370,7 @@ void Status::Changes::songID() drawTitle(myPlaylist->nowPlayingSong()); if (Config.autocenter_mode && !myPlaylist->main().isFiltered()) - myPlaylist->main().highlight(myPlaylist->currentSongPosition()); + myPlaylist->main().highlight(Status::get().currentSongPosition()); if (Config.now_playing_lyrics && isVisible(myLyrics) && myLyrics->previousScreen() == myPlaylist) myLyrics->ReloadNP = 1; @@ -416,10 +381,7 @@ void Status::Changes::songID() void Status::Changes::elapsedTime(bool update_elapsed) { if (update_elapsed) - { - m_status = Mpd.getStatus(); - m_elapsed_time = m_status.elapsedTime(); - } + m_elapsed_time = Mpd.getStatus().elapsedTime(); const auto &st = m_status; if (st.playerState() == MPD::psStop) @@ -451,17 +413,17 @@ void Status::Changes::elapsedTime(bool update_elapsed) if (Config.display_remaining_time) { tracklength += "-"; - tracklength += MPD::Song::ShowTime(st.totalTime()-st.elapsedTime()); + tracklength += MPD::Song::ShowTime(st.totalTime()-m_elapsed_time); } else - tracklength += MPD::Song::ShowTime(st.elapsedTime()); + tracklength += MPD::Song::ShowTime(m_elapsed_time); tracklength += "/"; tracklength += MPD::Song::ShowTime(st.totalTime()); tracklength += "]"; } else { - tracklength += MPD::Song::ShowTime(st.elapsedTime()); + tracklength += MPD::Song::ShowTime(m_elapsed_time); tracklength += "]"; } NC::WBuffer np_song; @@ -475,10 +437,10 @@ void Status::Changes::elapsedTime(bool update_elapsed) if (Config.display_remaining_time) { tracklength = "-"; - tracklength += MPD::Song::ShowTime(st.totalTime()-st.elapsedTime()); + tracklength += MPD::Song::ShowTime(st.totalTime()-m_elapsed_time); } else - tracklength = MPD::Song::ShowTime(st.elapsedTime()); + tracklength = MPD::Song::ShowTime(m_elapsed_time); if (st.totalTime()) { tracklength += "/"; @@ -518,7 +480,7 @@ void Status::Changes::elapsedTime(bool update_elapsed) flags(); } if (Progressbar::isUnlocked()) - Progressbar::draw(st.elapsedTime(), st.totalTime()); + Progressbar::draw(m_elapsed_time, st.totalTime()); } void Status::Changes::repeat(bool show_msg) @@ -638,11 +600,11 @@ void Status::Changes::mixer() VolumeState = " " "Vol" ": "; break; } - if (State::volume() < 0) + if (m_status.volume() < 0) VolumeState += "n/a"; else { - VolumeState += boost::lexical_cast<std::string>(State::volume()); + VolumeState += boost::lexical_cast<std::string>(m_status.volume()); VolumeState += "%"; } *wHeader << Config.volume_color; diff --git a/src/status.h b/src/status.h index 7a0d4471..c9a3ecba 100644 --- a/src/status.h +++ b/src/status.h @@ -33,23 +33,12 @@ void trace(bool update_timer, bool update_window_timeout); inline void trace() { trace(true, false); } void update(int event); -namespace State {// - -bool repeat(); -bool random(); -bool single(); -bool consume(); -bool crossfade(); - -MPD::PlayerState player(); -int volume(); +const MPD::Status &get(); unsigned elapsedTime(); -} - namespace Changes {// -void playlist(); +void playlist(unsigned previous_version); void storedPlaylists(); void database(); void playerState(); diff --git a/src/statusbar.cpp b/src/statusbar.cpp index 6f4198c4..a7c99c83 100644 --- a/src/statusbar.cpp +++ b/src/statusbar.cpp @@ -104,7 +104,7 @@ void Statusbar::unlock() else progressbarBlockUpdate = false; } - if (Status::State::player() == MPD::psStop) + if (Status::get().playerState() == MPD::psStop) { switch (Config.design) { @@ -112,7 +112,7 @@ void Statusbar::unlock() put() << wclrtoeol; break; case Design::Alternative: - Progressbar::draw(Status::State::elapsedTime(), myPlaylist->currentSongLength()); + Progressbar::draw(Status::elapsedTime(), Status::get().totalTime()); break; } wFooter->refresh(); @@ -137,7 +137,7 @@ void Statusbar::tryRedraw() else progressbarBlockUpdate = !statusbarAllowUnlock; - if (Status::State::player() != MPD::psStop && !statusbarBlockUpdate && !progressbarBlockUpdate) + if (Status::get().playerState() != MPD::psStop && !statusbarBlockUpdate && !progressbarBlockUpdate) { switch (Config.design) { @@ -145,7 +145,7 @@ void Statusbar::tryRedraw() Status::Changes::elapsedTime(false); break; case Design::Alternative: - Progressbar::draw(Status::State::elapsedTime(), myPlaylist->currentSongLength()); + Progressbar::draw(Status::elapsedTime(), Status::get().totalTime()); break; } wFooter->refresh(); diff --git a/src/visualizer.cpp b/src/visualizer.cpp index 906be47e..58e88695 100644 --- a/src/visualizer.cpp +++ b/src/visualizer.cpp @@ -145,7 +145,7 @@ void Visualizer::update() int Visualizer::windowTimeout() { - if (m_fifo >= 0 && Status::State::player() == MPD::psPlay) + if (m_fifo >= 0 && Status::get().playerState() == MPD::psPlay) return 1000/fps; else return Screen<WindowType>::windowTimeout(); |