From 0f254b164e0eb814093aa2c84df3ea2536c5715a Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Tue, 4 Nov 2014 11:01:58 +0100 Subject: [PATCH 1/6] tags: mp3: write IDv2.4 tags only --- NEWS | 1 + src/tags.cpp | 26 ++++++++++---------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/NEWS b/NEWS index a747842a..79a15928 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ ncmpcpp-0.6.1 (????-??-??) * Comment tag is now properly written to mp3 files. +* Only ID3v2.4 tags are now saved to mp3 files. ncmpcpp-0.6 (2014-10-25) diff --git a/src/tags.cpp b/src/tags.cpp index 03a8330e..832351e4 100644 --- a/src/tags.cpp +++ b/src/tags.cpp @@ -117,17 +117,6 @@ void readXiphComments(MPD::MutableSong &s, TagLib::Ogg::XiphComment *tag) readField(fields["COMMENT"], &MPD::MutableSong::setComment); } -void clearID3v1Tags(TagLib::ID3v1::Tag *tag) -{ - tag->setTitle(TagLib::String::null); - tag->setArtist(TagLib::String::null); - tag->setAlbum(TagLib::String::null); - tag->setYear(0); - tag->setTrack(0); - tag->setGenre(TagLib::String::null); - tag->setComment(TagLib::String::null); -} - void writeCommonTags(const MPD::MutableSong &s, TagLib::Tag *tag) { tag->setTitle(ToWString(s.getTitle())); @@ -293,10 +282,15 @@ bool write(MPD::MutableSong &s) if (f.isNull()) return false; - if (auto mp3_file = dynamic_cast(f.file())) + bool saved = false; + if (auto mpeg_file = dynamic_cast(f.file())) { - clearID3v1Tags(mp3_file->ID3v1Tag()); - writeID3v2Tags(s, mp3_file->ID3v2Tag(true)); + writeID3v2Tags(s, mpeg_file->ID3v2Tag(true)); + // write id3v2.4 tags only + if (!mpeg_file->save(TagLib::MPEG::File::ID3v2, true, 4, false)) + return false; + // do not call generic save() as it will duplicate tags + saved = true; } else if (auto ogg_file = dynamic_cast(f.file())) { @@ -309,9 +303,9 @@ bool write(MPD::MutableSong &s) else writeCommonTags(s, f.tag()); - if (!f.save()) + if (!saved && !f.save()) return false; - + if (!s.getNewName().empty()) { std::string new_name; From 60749ea4bd83f991c1c967f25b8410ac9aeacf71 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Wed, 5 Nov 2014 21:07:39 +0100 Subject: [PATCH 2/6] window: fix wheel scrolling if NCURSES_MOUSE_VERSION > 1 --- NEWS | 1 + src/actions.cpp | 16 ++++++++++------ src/actions.h | 6 +++++- src/screen.cpp | 4 ++-- src/window.h | 13 ++++++------- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/NEWS b/NEWS index 79a15928..fe5e9af2 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ ncmpcpp-0.6.1 (????-??-??) * Comment tag is now properly written to mp3 files. * Only ID3v2.4 tags are now saved to mp3 files. +* Mouse scrolling with newer ncurses API now works properly. ncmpcpp-0.6 (2014-10-25) diff --git a/src/actions.cpp b/src/actions.cpp index 270d52f7..a1c9c678 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -318,15 +318,19 @@ void MouseEvent::run() m_old_mouse_event = m_mouse_event; getmouse(&m_mouse_event); + +# if NCURSES_MOUSE_VERSION == 1 // workaround shitty ncurses behavior introduced in >=5.8, when we mysteriously get // a few times after ncmpcpp startup 2^27 code instead of BUTTON{1,3}_RELEASED. since that // 2^27 thing shows constantly instead of BUTTON2_PRESSED, it was redefined to be recognized - // as BUTTON2_PRESSED. but clearly we don't want to trigger behavior bound to BUTTON2 + // as BUTTON5_PRESSED. but clearly we don't want to trigger behavior bound to BUTTON5 // after BUTTON{1,3} was pressed. so, here is the workaround: if last event was BUTTON{1,3}_PRESSED, - // we MUST get BUTTON{1,3}_RELEASED afterwards. if we get BUTTON2_PRESSED, erroneus behavior + // we MUST get BUTTON{1,3}_RELEASED afterwards. if we get BUTTON5_PRESSED, erroneus behavior // is about to occur and we need to prevent that. - if (m_old_mouse_event.bstate & (BUTTON1_PRESSED | BUTTON3_PRESSED) && m_mouse_event.bstate & BUTTON2_PRESSED) + if (m_old_mouse_event.bstate & (BUTTON1_PRESSED | BUTTON3_PRESSED) && m_mouse_event.bstate & BUTTON5_PRESSED) return; +# endif // NCURSES_MOUSE_VERSION == 1 + if (m_mouse_event.bstate & BUTTON1_PRESSED && m_mouse_event.y == LINES-(Config.statusbar_visibility ? 2 : 1) ) // progressbar @@ -345,17 +349,17 @@ void MouseEvent::run() { Mpd.Toggle(); } - else if ((m_mouse_event.bstate & BUTTON2_PRESSED || m_mouse_event.bstate & BUTTON4_PRESSED) + else if ((m_mouse_event.bstate & BUTTON5_PRESSED || m_mouse_event.bstate & BUTTON4_PRESSED) && (Config.header_visibility || Config.design == Design::Alternative) && m_mouse_event.y == 0 && size_t(m_mouse_event.x) > COLS-VolumeState.length() ) // volume { - if (m_mouse_event.bstate & BUTTON2_PRESSED) + if (m_mouse_event.bstate & BUTTON5_PRESSED) get(Type::VolumeDown).execute(); else get(Type::VolumeUp).execute(); } - else if (m_mouse_event.bstate & (BUTTON1_PRESSED | BUTTON2_PRESSED | BUTTON3_PRESSED | BUTTON4_PRESSED)) + else if (m_mouse_event.bstate & (BUTTON1_PRESSED | BUTTON3_PRESSED | BUTTON4_PRESSED | BUTTON5_PRESSED)) myScreen->mouseButtonPressed(m_mouse_event); } diff --git a/src/actions.h b/src/actions.h index d828c2eb..b6437a43 100644 --- a/src/actions.h +++ b/src/actions.h @@ -122,7 +122,11 @@ protected: struct MouseEvent : public BaseAction { - MouseEvent() : BaseAction(Type::MouseEvent, "mouse_event") { } + MouseEvent() : BaseAction(Type::MouseEvent, "mouse_event") + { + m_old_mouse_event.bstate = 0; + m_mouse_event.bstate = 0; + } protected: virtual bool canBeRun() const; diff --git a/src/screen.cpp b/src/screen.cpp index 36c82930..f370d9e8 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -38,7 +38,7 @@ void drawSeparator(int x) void genericMouseButtonPressed(NC::Window &w, MEVENT me) { - if (me.bstate & BUTTON2_PRESSED) + if (me.bstate & BUTTON5_PRESSED) { if (Config.mouse_list_scroll_whole_page) w.scroll(NC::Scroll::PageDown); @@ -58,7 +58,7 @@ void genericMouseButtonPressed(NC::Window &w, MEVENT me) void scrollpadMouseButtonPressed(NC::Scrollpad &w, MEVENT me) { - if (me.bstate & BUTTON2_PRESSED) + if (me.bstate & BUTTON5_PRESSED) { for (size_t i = 0; i < Config.lines_scrolled; ++i) w.scroll(NC::Scroll::Down); diff --git a/src/window.h b/src/window.h index b769e16f..7f751056 100644 --- a/src/window.h +++ b/src/window.h @@ -95,13 +95,12 @@ // undefine scroll macro as it collides with Window::scroll #undef scroll -#ifndef USE_PDCURSES -// NOTICE: redefine BUTTON2_PRESSED as it doesn't always work, I noticed -// that it sometimes returns 134217728 (2^27) instead of expected mask, so the -// modified define does it right but is rather experimental. -# undef BUTTON2_PRESSED -# define BUTTON2_PRESSED (NCURSES_MOUSE_MASK(2, NCURSES_BUTTON_PRESSED) | (1U << 27)) -#endif // USE_PDCURSES +#if !defined(USE_PDCURSES) && NCURSES_MOUSE_VERSION == 1 +// NOTICE: define BUTTON5_PRESSED to be BUTTON2_PRESSED with additional mask +// (I noticed that it sometimes returns 134217728 (2^27) instead of expected +// mask, so the modified define does it right. +# define BUTTON5_PRESSED (BUTTON2_PRESSED | (1U << 27)) +#endif // !defined(USE_PDCURSES) && NCURSES_MOUSE_VERSION == 1 // workaraund for win32 #ifdef WIN32 From 08d17f9d0e8a6cc9b3b96008163d299e487b9c0f Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Thu, 6 Nov 2014 18:53:31 +0100 Subject: [PATCH 3/6] media library: fix adding songs with fetch delay enabled --- NEWS | 1 + src/media_library.cpp | 26 +++++++++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index fe5e9af2..d87d6df6 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ ncmpcpp-0.6.1 (????-??-??) * Comment tag is now properly written to mp3 files. * Only ID3v2.4 tags are now saved to mp3 files. * Mouse scrolling with newer ncurses API now works properly. +* Adding songs from an album in media library now works properly with fetch delay. ncmpcpp-0.6 (2014-10-25) diff --git a/src/media_library.cpp b/src/media_library.cpp index 496cc3a6..c8944db1 100644 --- a/src/media_library.cpp +++ b/src/media_library.cpp @@ -58,6 +58,19 @@ size_t itsRightColStartX; typedef MediaLibrary::AlbumEntry AlbumEntry; +template +void withSongsFromAlbum(const AlbumEntry &album, FunT &&f) +{ + Mpd.StartSearch(true); + Mpd.AddSearch(Config.media_lib_primary_tag, album.entry().tag()); + if (!album.isAllTracksEntry()) + { + Mpd.AddSearch(MPD_TAG_ALBUM, album.entry().album()); + Mpd.AddSearch(MPD_TAG_DATE, album.entry().date()); + } + Mpd.CommitSearchSongs(std::forward(f)); +} + std::string AlbumToString(const AlbumEntry &ae); std::string SongToString(const MPD::Song &s); @@ -778,9 +791,9 @@ MPD::SongList MediaLibrary::getSelectedSongs() // if no item is selected, add songs from right column if (!any_selected && !Albums.empty()) { - withUnfilteredMenu(Songs, [this, &result]() { - result.insert(result.end(), Songs.beginV(), Songs.endV()); - }); + size_t begin = result.size(); + withSongsFromAlbum(Albums.current().value().entry(), vectorMoveInserter(result)); + std::sort(result.begin()+begin, result.end(), SortSongs(false)); } } else if (isActiveWindow(Songs)) @@ -1059,10 +1072,9 @@ void MediaLibrary::AddToPlaylist(bool add_n_play) } else if (isActiveWindow(Albums)) { - bool success; - withUnfilteredMenu(Songs, [&]() { - success = addSongsToPlaylist(Songs.beginV(), Songs.endV(), add_n_play, -1); - }); + MPD::SongList list; + withSongsFromAlbum(Albums.current().value(), vectorMoveInserter(list)); + bool success = addSongsToPlaylist(list.begin(), list.end(), add_n_play, -1); Statusbar::printf("Songs from album \"%1%\" added%2%", Albums.current().value().entry().album(), withErrors(success) ); From 3e9d25ccea428f1f46a5590f6999ab3108398feb Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Thu, 6 Nov 2014 18:54:16 +0100 Subject: [PATCH 4/6] playlist editor: fix adding songs with fetch delay enabled --- NEWS | 1 + src/playlist_editor.cpp | 17 +++++------------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/NEWS b/NEWS index d87d6df6..b89d5aab 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ ncmpcpp-0.6.1 (????-??-??) * Only ID3v2.4 tags are now saved to mp3 files. * Mouse scrolling with newer ncurses API now works properly. * Adding songs from an album in media library now works properly with fetch delay. +* Adding songs from a playlist in playlist editor now works properly with fetch delay. ncmpcpp-0.6 (2014-10-25) diff --git a/src/playlist_editor.cpp b/src/playlist_editor.cpp index dcc118f0..cf3689bb 100644 --- a/src/playlist_editor.cpp +++ b/src/playlist_editor.cpp @@ -239,14 +239,11 @@ ProxySongList PlaylistEditor::contentProxyList() void PlaylistEditor::AddToPlaylist(bool add_n_play) { - MPD::SongList list; - if (isActiveWindow(Playlists) && !Playlists.empty()) { - bool success; - withUnfilteredMenu(Content, [&]() { - success = addSongsToPlaylist(Content.beginV(), Content.endV(), add_n_play, -1); - }); + MPD::SongList list; + Mpd.GetPlaylistContent(Playlists.current().value(), vectorMoveInserter(list)); + bool success = addSongsToPlaylist(list.begin(), list.end(), add_n_play, -1); Statusbar::printf("Playlist \"%1%\" loaded%2%", Playlists.current().value(), withErrors(success) ); @@ -488,12 +485,8 @@ MPD::SongList PlaylistEditor::getSelectedSongs() } } // if no item is selected, add songs from right column - if (!any_selected && !Content.empty()) - { - withUnfilteredMenu(Content, [this, &result]() { - result.insert(result.end(), Content.beginV(), Content.endV()); - }); - } + if (!any_selected && !Playlists.empty()) + Mpd.GetPlaylistContent(Playlists.current().value(), vectorMoveInserter(result)); } else if (isActiveWindow(Content)) { From d958e94d752a4ae1f4e32dcd0ea8ecd417e889ba Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Thu, 6 Nov 2014 19:00:24 +0100 Subject: [PATCH 5/6] lyrics: check if the song exists --- src/helpers.h | 2 +- src/lyrics.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/helpers.h b/src/helpers.h index ff8abd22..e993bc18 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -52,7 +52,7 @@ inline MPD::Song *currentSong(BaseScreen *screen) { MPD::Song *ptr = 0; auto pl = proxySongList(screen); - if (pl) + if (pl && !pl.empty()) ptr = pl.currentSong(); return ptr; } diff --git a/src/lyrics.cpp b/src/lyrics.cpp index f4514a03..000c3c45 100644 --- a/src/lyrics.cpp +++ b/src/lyrics.cpp @@ -107,6 +107,9 @@ void Lyrics::switchTo() # endif // HAVE_CURL_CURL_H auto s = currentSong(myScreen); + if (!s) + return; + if (SetSong(*s)) { SwitchTo::execute(this); From a32a4262b8e458297838b111a5708a36ad970ef5 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Thu, 6 Nov 2014 19:21:21 +0100 Subject: [PATCH 6/6] change version to 0.6.1 --- NEWS | 3 ++- configure.ac | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index b89d5aab..a987ddf4 100644 --- a/NEWS +++ b/NEWS @@ -1,10 +1,11 @@ -ncmpcpp-0.6.1 (????-??-??) +ncmpcpp-0.6.1 (2014-11-06) * Comment tag is now properly written to mp3 files. * Only ID3v2.4 tags are now saved to mp3 files. * Mouse scrolling with newer ncurses API now works properly. * Adding songs from an album in media library now works properly with fetch delay. * Adding songs from a playlist in playlist editor now works properly with fetch delay. +* Trying to fetch lyrics from an empty list doesn't crash the application anymore. ncmpcpp-0.6 (2014-10-25) diff --git a/configure.ac b/configure.ac index 878d6b9f..8cd32ca6 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ AC_INIT(configure.ac) AC_CONFIG_HEADERS(config.h) -AM_INIT_AUTOMAKE(ncmpcpp, 0.6.1_pre) +AM_INIT_AUTOMAKE(ncmpcpp, 0.6.1) AC_PREREQ(2.59)