diff --git a/src/actions.cpp b/src/actions.cpp index 0adee22e..43d000e2 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -494,11 +494,11 @@ void ScrollUpArtist::Run() size_t pos = mList->Choice(); if (MPD::Song *s = myScreen->GetSong(pos)) { - std::string artist = s->GetArtist(); + std::string artist = s->getArtist(); while (pos > 0) { s = myScreen->GetSong(--pos); - if (!s || s->GetArtist() != artist) + if (!s || s->getArtist() != artist) break; } mList->Highlight(pos); @@ -513,11 +513,11 @@ void ScrollUpAlbum::Run() size_t pos = mList->Choice(); if (MPD::Song *s = myScreen->GetSong(pos)) { - std::string album = s->GetAlbum(); + std::string album = s->getAlbum(); while (pos > 0) { s = myScreen->GetSong(--pos); - if (!s || s->GetAlbum() != album) + if (!s || s->getAlbum() != album) break; } mList->Highlight(pos); @@ -532,11 +532,11 @@ void ScrollDownArtist::Run() size_t pos = mList->Choice(); if (MPD::Song *s = myScreen->GetSong(pos)) { - std::string artist = s->GetArtist(); + std::string artist = s->getArtist(); while (pos < mList->Size() - 1) { s = myScreen->GetSong(++pos); - if (!s || s->GetArtist() != artist) + if (!s || s->getArtist() != artist) break; } mList->Highlight(pos); @@ -551,11 +551,11 @@ void ScrollDownAlbum::Run() size_t pos = mList->Choice(); if (MPD::Song *s = myScreen->GetSong(pos)) { - std::string album = s->GetAlbum(); + std::string album = s->getAlbum(); while (pos < mList->Size() - 1) { s = myScreen->GetSong(++pos); - if (!s || s->GetAlbum() != album) + if (!s || s->getAlbum() != album) break; } mList->Highlight(pos); @@ -745,7 +745,7 @@ void Delete::Run() myPlaylist->Items->GetSelected(list); Mpd.StartCommandsList(); for (std::vector::reverse_iterator it = list.rbegin(); it != list.rend(); ++it) - Mpd.DeleteID((*myPlaylist->Items)[*it].GetID()); + Mpd.DeleteID((*myPlaylist->Items)[*it].getID()); if (Mpd.CommitCommandsList()) { for (size_t i = 0; i < myPlaylist->Items->Size(); ++i) @@ -754,7 +754,7 @@ void Delete::Run() } } else - Mpd.DeleteID(myPlaylist->CurrentSong()->GetID()); + Mpd.DeleteID(myPlaylist->CurrentSong()->getID()); } else if ( (myScreen == myBrowser && !myBrowser->Main()->Empty() && myBrowser->CurrentDir() == "/" && myBrowser->Main()->Current().type == itPlaylist) @@ -803,7 +803,7 @@ void Delete::Run() if (item.type == itDirectory && item.song) // parent dir return; - std::string name = item.type == itSong ? item.song->GetName() : item.name; + std::string name = item.type == itSong ? item.song->getName() : item.name; std::string question; if (myBrowser->Main()->hasSelected()) question = "Delete selected items?"; @@ -826,7 +826,7 @@ void Delete::Run() for (size_t i = 0; i < list.size(); ++i) { const MPD::Item &it = (*myBrowser->Main())[list[i]]; - name = it.type == itSong ? it.song->GetName() : it.name; + name = it.type == itSong ? it.song->getName() : it.name; if (myBrowser->DeleteItem(it)) { const char msg[] = "\"%s\" deleted"; @@ -1422,12 +1422,12 @@ void EditLibraryTag::Run() { (*it)->Localize(); (*it)->SetTags(set, new_tag); - ShowMessage("Updating tags in \"%s\"...", (*it)->GetName().c_str()); - std::string path = Config.mpd_music_dir + (*it)->GetFile(); + ShowMessage("Updating tags in \"%s\"...", (*it)->getName().c_str()); + std::string path = Config.mpd_music_dir + (*it)->getURI(); if (!TagEditor::WriteTags(**it)) { const char msg[] = "Error while updating tags in \"%s\""; - ShowMessage(msg, Shorten(TO_WSTRING((*it)->GetFile()), COLS-static_strlen(msg)).c_str()); + ShowMessage(msg, Shorten(TO_WSTRING((*it)->getURI()), COLS-static_strlen(msg)).c_str()); success = 0; break; } @@ -1470,13 +1470,13 @@ void EditLibraryAlbum::Run() for (size_t i = 0; i < myLibrary->Songs->Size(); ++i) { (*myLibrary->Songs)[i].Localize(); - ShowMessage("Updating tags in \"%s\"...", (*myLibrary->Songs)[i].GetName().c_str()); - std::string path = Config.mpd_music_dir + (*myLibrary->Songs)[i].GetFile(); + ShowMessage("Updating tags in \"%s\"...", (*myLibrary->Songs)[i].getName().c_str()); + std::string path = Config.mpd_music_dir + (*myLibrary->Songs)[i].getURI(); TagLib::FileRef f(locale_to_utf_cpy(path).c_str()); if (f.isNull()) { const char msg[] = "Error while opening file \"%s\""; - ShowMessage(msg, Shorten(TO_WSTRING((*myLibrary->Songs)[i].GetFile()), COLS-static_strlen(msg)).c_str()); + ShowMessage(msg, Shorten(TO_WSTRING((*myLibrary->Songs)[i].getURI()), COLS-static_strlen(msg)).c_str()); success = 0; break; } @@ -1484,7 +1484,7 @@ void EditLibraryAlbum::Run() if (!f.save()) { const char msg[] = "Error while writing tags in \"%s\""; - ShowMessage(msg, Shorten(TO_WSTRING((*myLibrary->Songs)[i].GetFile()), COLS-static_strlen(msg)).c_str()); + ShowMessage(msg, Shorten(TO_WSTRING((*myLibrary->Songs)[i].getURI()), COLS-static_strlen(msg)).c_str()); success = 0; break; } @@ -1749,7 +1749,7 @@ void JumpToPositionInSong::Run() if (newpos >= 0 && newpos <= Mpd.GetTotalTime()) Mpd.Seek(newpos); else - ShowMessage("Out of bounds, 0:00-%s possible for mm:ss, %s given", s->GetLength().c_str(), MPD::Song::ShowTime(newpos).c_str()); + ShowMessage("Out of bounds, 0:00-%s possible for mm:ss, %s given", s->getLength().c_str(), MPD::Song::ShowTime(newpos).c_str()); } else if (position.find('s') != std::string::npos) // probably position in seconds { @@ -1757,7 +1757,7 @@ void JumpToPositionInSong::Run() if (newpos >= 0 && newpos <= Mpd.GetTotalTime()) Mpd.Seek(newpos); else - ShowMessage("Out of bounds, 0-%d possible for seconds, %d given", s->GetTotalLength(), newpos); + ShowMessage("Out of bounds, 0-%d possible for seconds, %d given", s->getDuration(), newpos); } else { @@ -1808,7 +1808,7 @@ void SelectAlbum::Run() size_t pos = mList->Choice(); if (MPD::Song *s = myScreen->GetSong(pos)) { - std::string album = s->GetAlbum(); + std::string album = s->getAlbum(); // select song under cursor mList->Select(pos, 1); @@ -1816,7 +1816,7 @@ void SelectAlbum::Run() while (pos > 0) { s = myScreen->GetSong(--pos); - if (!s || s->GetAlbum() != album) + if (!s || s->getAlbum() != album) break; else mList->Select(pos, 1); @@ -1826,7 +1826,7 @@ void SelectAlbum::Run() while (pos < mList->Size() - 1) { s = myScreen->GetSong(++pos); - if (!s || s->GetAlbum() != album) + if (!s || s->getAlbum() != album) break; else mList->Select(pos, 1); @@ -1864,7 +1864,7 @@ void CropMainPlaylist::Run() bool delete_np = (delete_all_but_current && current != myPlaylist->NowPlaying) || (!delete_all_but_current && !myPlaylist->Items->isSelected(myPlaylist->NowPlaying)); if (myPlaylist->isPlaying() && delete_np) - Mpd.DeleteID(myPlaylist->NowPlayingSong()->GetID()); + Mpd.DeleteID(myPlaylist->NowPlayingSong()->getID()); ShowMessage("Cropping playlist..."); if (Mpd.CommitCommandsList()) ShowMessage("Playlist cropped"); @@ -1918,7 +1918,7 @@ void ClearMainPlaylist::Run() ShowMessage("Deleting filtered items..."); Mpd.StartCommandsList(); for (int i = myPlaylist->Items->Size()-1; i >= 0; --i) - Mpd.Delete((*myPlaylist->Items)[i].GetPosition()); + Mpd.Delete((*myPlaylist->Items)[i].getPosition()); if (Mpd.CommitCommandsList()) ShowMessage("Filtered items deleted"); } @@ -2326,7 +2326,7 @@ void ShowArtistInfo::Run() MPD::Song *s = myScreen->CurrentSong(); if (s) - artist = s->GetArtist(); + artist = s->getArtist(); else if (myScreen == myLibrary && myLibrary->Main() == myLibrary->Artists && !myLibrary->Artists->Empty()) artist = myLibrary->Artists->Current(); diff --git a/src/browser.cpp b/src/browser.cpp index fbf12350..f9448718 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -320,19 +320,19 @@ bool Browser::hasSupportedExtension(const std::string &file) void Browser::LocateSong(const MPD::Song &s) { - if (s.GetDirectory().empty()) + if (s.getDirectory().empty()) return; - itsBrowseLocally = !s.isFromDB(); + itsBrowseLocally = !s.isFromDatabase(); if (myScreen != this) SwitchTo(); - if (itsBrowsedDir != s.GetDirectory()) - GetDirectory(s.GetDirectory()); + if (itsBrowsedDir != s.getDirectory()) + GetDirectory(s.getDirectory()); for (size_t i = 0; i < w->Size(); ++i) { - if ((*w)[i].type == itSong && s.GetHash() == (*w)[i].song->GetHash()) + if ((*w)[i].type == itSong && s.getHash() == (*w)[i].song->getHash()) { w->Highlight(i); break; @@ -402,7 +402,7 @@ void Browser::GetDirectory(std::string dir, std::string subdir) bool bold = 0; for (size_t i = 0; i < myPlaylist->Items->Size(); ++i) { - if (myPlaylist->Items->at(i).GetHash() == it->song->GetHash()) + if (myPlaylist->Items->at(i).getHash() == it->song->getHash()) { bold = 1; break; @@ -543,7 +543,7 @@ bool Browser::DeleteItem(const MPD::Item &item) std::string path; if (!isLocal()) path = Config.mpd_music_dir; - path += item.type == itSong ? item.song->GetFile() : item.name; + path += item.type == itSong ? item.song->getURI() : item.name; if (item.type == itDirectory) ClearDirectory(path); @@ -561,7 +561,7 @@ void Browser::UpdateItemList() { for (size_t j = 0; j < myPlaylist->Items->Size(); ++j) { - if (myPlaylist->Items->at(j).GetHash() == w->at(i).song->GetHash()) + if (myPlaylist->Items->at(j).getHash() == w->at(i).song->getHash()) { bold = 1; break; diff --git a/src/conv.cpp b/src/conv.cpp index b2bc05bb..8ea2ed5b 100644 --- a/src/conv.cpp +++ b/src/conv.cpp @@ -205,37 +205,37 @@ MPD::Song::GetFunction toGetFunction(char c) switch (c) { case 'l': - return &MPD::Song::GetLength; + return &MPD::Song::getLength; case 'D': - return &MPD::Song::GetDirectory; + return &MPD::Song::getDirectory; case 'f': - return &MPD::Song::GetName; + return &MPD::Song::getName; case 'a': - return &MPD::Song::GetArtist; + return &MPD::Song::getArtist; case 'A': - return &MPD::Song::GetAlbumArtist; + return &MPD::Song::getAlbumArtist; case 'b': - return &MPD::Song::GetAlbum; + return &MPD::Song::getAlbum; case 'y': - return &MPD::Song::GetDate; + return &MPD::Song::getDate; case 'n': - return &MPD::Song::GetTrackNumber; + return &MPD::Song::getTrackNumber; case 'N': - return &MPD::Song::GetTrack; + return &MPD::Song::getTrack; case 'g': - return &MPD::Song::GetGenre; + return &MPD::Song::getGenre; case 'c': - return &MPD::Song::GetComposer; + return &MPD::Song::getComposer; case 'p': - return &MPD::Song::GetPerformer; + return &MPD::Song::getPerformer; case 'd': - return &MPD::Song::GetDisc; + return &MPD::Song::getDisc; case 'C': - return &MPD::Song::GetComment; + return &MPD::Song::getComment; case 't': - return &MPD::Song::GetTitle; + return &MPD::Song::getTitle; case 'P': - return &MPD::Song::GetPriority; + return &MPD::Song::getPriority; default: return 0; } diff --git a/src/display.cpp b/src/display.cpp index 860eb7ff..a7974485 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -139,9 +139,6 @@ std::string Display::Columns(size_t list_width) void Display::SongsInColumns(const MPD::Song &s, void *data, Menu *menu) { - if (!s.Localized()) - const_cast(&s)->Localize(); - if (Config.columns.empty()) return; @@ -150,13 +147,13 @@ void Display::SongsInColumns(const MPD::Song &s, void *data, Menu *me if (Config.playlist_separate_albums && menu->CurrentlyDrawedPosition()+1 < menu->Size()) { MPD::Song *next = static_cast(data)->screen->GetSong(menu->CurrentlyDrawedPosition()+1); - if (next && next->GetAlbum() != s.GetAlbum()) + if (next && next->getAlbum() != s.getAlbum()) separate_albums = true; } if (separate_albums) *menu << fmtUnderline; - int song_pos = menu->isFiltered() ? s.GetPosition() : menu->CurrentlyDrawedPosition(); + int song_pos = menu->isFiltered() ? s.getPosition() : menu->CurrentlyDrawedPosition(); bool is_now_playing = menu == myPlaylist->Items && song_pos == myPlaylist->NowPlaying; bool is_selected = menu->isSelected(menu->CurrentlyDrawedPosition()); bool discard_colors = Config.discard_colors_if_item_is_selected && is_selected; @@ -218,7 +215,7 @@ void Display::SongsInColumns(const MPD::Song &s, void *data, Menu *me for (size_t i = 0; i < it->type.length(); ++i) { MPD::Song::GetFunction get = toGetFunction(it->type[i]); - tag = TO_WSTRING(get ? s.GetTags(get) : ""); + tag = TO_WSTRING(get ? s.getTags(get) : ""); if (!tag.empty()) break; } @@ -271,10 +268,7 @@ void Display::SongsInColumns(const MPD::Song &s, void *data, Menu *me void Display::Songs(const MPD::Song &s, void *data, Menu *menu) { - if (!s.Localized()) - const_cast(&s)->Localize(); - - bool is_now_playing = menu == myPlaylist->Items && (menu->isFiltered() ? s.GetPosition() : menu->CurrentlyDrawedPosition()) == size_t(myPlaylist->NowPlaying); + bool is_now_playing = menu == myPlaylist->Items && (menu->isFiltered() ? s.getPosition() : menu->CurrentlyDrawedPosition()) == size_t(myPlaylist->NowPlaying); if (is_now_playing) *menu << Config.now_playing_prefix; @@ -283,7 +277,7 @@ void Display::Songs(const MPD::Song &s, void *data, Menu *menu) if (Config.playlist_separate_albums && menu->CurrentlyDrawedPosition()+1 < menu->Size()) { MPD::Song *next = static_cast(data)->screen->GetSong(menu->CurrentlyDrawedPosition()+1); - if (next && next->GetAlbum() != s.GetAlbum()) + if (next && next->getAlbum() != s.getAlbum()) separate_albums = true; } if (separate_albums) @@ -347,14 +341,16 @@ void Display::Tags(const MPD::Song &s, void *data, Menu *menu) size_t i = static_cast *>(data)->Choice(); if (i < 11) { - ShowTag(*menu, s.GetTags(SongInfo::Tags[i].Get)); + ShowTag(*menu, s.getTags(SongInfo::Tags[i].Get)); } else if (i == 12) { - if (s.GetNewName().empty()) - *menu << s.GetName(); + // FIXME + /*if (s.GetNewName().empty()) + *menu << s.getName(); else - *menu << s.GetName() << Config.color2 << " -> " << clEnd << s.GetNewName(); + *menu << s.getName() << Config.color2 << " -> " << clEnd << s.GetNewName(); + */ } } diff --git a/src/helpers.cpp b/src/helpers.cpp index 23c10775..67ad080e 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -317,7 +317,7 @@ bool CaseInsensitiveSorting::operator()(const MPD::Item &a, const MPD::Item &b) result = operator()(a.song, b.song); break; case smMTime: - result = a.song->GetMTime() > b.song->GetMTime(); + result = a.song->getMTime() > b.song->getMTime(); break; case smCustomFormat: result = cmp(a.song->toString(Config.browser_sort_format), b.song->toString(Config.browser_sort_format)) < 0; @@ -352,7 +352,7 @@ void UpdateSongList(Menu *menu) { for (size_t j = 0; j < myPlaylist->Items->Size(); ++j) { - if (myPlaylist->Items->at(j).GetHash() == menu->at(i).GetHash()) + if (myPlaylist->Items->at(j).getHash() == menu->at(i).getHash()) { bold = 1; break; diff --git a/src/helpers.h b/src/helpers.h index d0a85954..dbf41a8d 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -57,7 +57,7 @@ class CaseInsensitiveSorting bool operator()(MPD::Song *a, MPD::Song *b) { - return cmp(a->GetName(), b->GetName()) < 0; + return cmp(a->getName(), b->getName()) < 0; } template bool operator()(const std::pair &a, const std::pair &b) diff --git a/src/lyrics.cpp b/src/lyrics.cpp index cfe89d4a..d5b993c7 100644 --- a/src/lyrics.cpp +++ b/src/lyrics.cpp @@ -76,7 +76,7 @@ void Lyrics::Update() if (ReloadNP) { const MPD::Song *s = myPlaylist->NowPlayingSong(); - if (s && !s->GetArtist().empty() && !s->GetTitle().empty()) + if (s && !s->getArtist().empty() && !s->getTitle().empty()) { Global::RedrawHeader = true; itsScrollBegin = 0; @@ -117,7 +117,7 @@ void Lyrics::SwitchTo() if (const MPD::Song *s = myScreen->CurrentSong()) { - if (!s->GetArtist().empty() && !s->GetTitle().empty()) + if (!s->getArtist().empty() && !s->getTitle().empty()) { myOldScreen = myScreen; myScreen = this; @@ -159,10 +159,8 @@ void Lyrics::SpacePressed() #ifdef HAVE_CURL_CURL_H void Lyrics::DownloadInBackground(const MPD::Song *s) { - if (!s || s->GetArtist().empty() || s->GetTitle().empty()) + if (!s || s->getArtist().empty() || s->getTitle().empty()) return; - if (!s->Localized()) - const_cast(s)->Localize(); std::string filename = GenerateFilename(*s); std::ifstream f(filename.c_str()); @@ -222,8 +220,8 @@ void *Lyrics::DownloadInBackgroundImpl(void *void_ptr) void Lyrics::DownloadInBackgroundImplHelper(MPD::Song *s) { - std::string artist = Curl::escape(locale_to_utf_cpy(s->GetArtist())); - std::string title = Curl::escape(locale_to_utf_cpy(s->GetTitle())); + std::string artist = Curl::escape(locale_to_utf_cpy(s->getArtist())); + std::string title = Curl::escape(locale_to_utf_cpy(s->getTitle())); LyricsFetcher::Result result; bool fetcher_defined = itsFetcher && *itsFetcher; @@ -241,8 +239,8 @@ void Lyrics::DownloadInBackgroundImplHelper(MPD::Song *s) void *Lyrics::Download() { - std::string artist = Curl::escape(locale_to_utf_cpy(itsSong.GetArtist())); - std::string title = Curl::escape(locale_to_utf_cpy(itsSong.GetTitle())); + std::string artist = Curl::escape(locale_to_utf_cpy(itsSong.getArtist())); + std::string title = Curl::escape(locale_to_utf_cpy(itsSong.getTitle())); LyricsFetcher::Result result; @@ -287,14 +285,14 @@ std::string Lyrics::GenerateFilename(const MPD::Song &s) std::string filename; if (Config.store_lyrics_in_song_dir) { - if (s.isFromDB()) + if (s.isFromDatabase()) { filename = Config.mpd_music_dir; filename += "/"; - filename += s.GetFile(); + filename += s.getURI(); } else - filename = s.GetFile(); + filename = s.getURI(); // replace song's extension with .txt size_t dot = filename.rfind('.'); assert(dot != std::string::npos); @@ -303,9 +301,9 @@ std::string Lyrics::GenerateFilename(const MPD::Song &s) } else { - std::string file = locale_to_utf_cpy(s.GetArtist()); + std::string file = locale_to_utf_cpy(s.getArtist()); file += " - "; - file += locale_to_utf_cpy(s.GetTitle()); + file += locale_to_utf_cpy(s.getTitle()); file += ".txt"; EscapeUnallowedChars(file); filename = Config.lyrics_directory; @@ -322,10 +320,9 @@ void Lyrics::Load() return; # endif // HAVE_CURL_CURL_H - assert(!itsSong.GetArtist().empty()); - assert(!itsSong.GetTitle().empty()); + assert(!itsSong.getArtist().empty()); + assert(!itsSong.getTitle().empty()); - itsSong.Localize(); itsFilename = GenerateFilename(itsSong); CreateDir(Config.lyrics_directory); diff --git a/src/media_library.cpp b/src/media_library.cpp index 2c369a6c..5f1a96d0 100644 --- a/src/media_library.cpp +++ b/src/media_library.cpp @@ -344,7 +344,7 @@ void MediaLibrary::Update() { for (size_t j = 0; j < myPlaylist->Items->Size(); ++j) { - if ((*it)->GetHash() == myPlaylist->Items->at(j).GetHash()) + if ((*it)->getHash() == myPlaylist->Items->at(j).getHash()) { bold = 1; break; @@ -627,19 +627,19 @@ void MediaLibrary::LocateSong(const MPD::Song &s) switch (Config.media_lib_primary_tag) { case MPD_TAG_ARTIST: - primary_tag = s.GetArtist(); + primary_tag = s.getArtist(); break; case MPD_TAG_DATE: - primary_tag = s.GetDate(); + primary_tag = s.getDate(); break; case MPD_TAG_GENRE: - primary_tag = s.GetGenre(); + primary_tag = s.getGenre(); break; case MPD_TAG_COMPOSER: - primary_tag = s.GetComposer(); + primary_tag = s.getComposer(); break; case MPD_TAG_PERFORMER: - primary_tag = s.GetPerformer(); + primary_tag = s.getPerformer(); break; default: // shouldn't happen assert(false); @@ -682,8 +682,8 @@ void MediaLibrary::LocateSong(const MPD::Song &s) if (Albums->Empty()) Update(); - std::string album = s.GetAlbum(); - std::string date = s.GetDate(); + std::string album = s.getAlbum(); + std::string date = s.getDate(); if ((hasTwoColumns && Albums->Current().PrimaryTag != primary_tag) || album != Albums->Current().Album || date != Albums->Current().Date) @@ -705,11 +705,11 @@ void MediaLibrary::LocateSong(const MPD::Song &s) if (Songs->Empty()) Update(); - if (s.GetHash() != Songs->Current().GetHash()) + if (s.getHash() != Songs->Current().getHash()) { for (size_t i = 0; i < Songs->Size(); ++i) { - if (s.GetHash() == (*Songs)[i].GetHash()) + if (s.getHash() == (*Songs)[i].getHash()) { Songs->Highlight(i); break; @@ -801,19 +801,19 @@ bool MediaLibrary::SearchConstraintsSorting::operator()(const SearchConstraints bool MediaLibrary::SortSongsByTrack(MPD::Song *a, MPD::Song *b) { - if (a->GetDisc() == b->GetDisc()) - return StrToInt(a->GetTrack()) < StrToInt(b->GetTrack()); + if (a->getDisc() == b->getDisc()) + return StrToInt(a->getTrack()) < StrToInt(b->getTrack()); else - return StrToInt(a->GetDisc()) < StrToInt(b->GetDisc()); + return StrToInt(a->getDisc()) < StrToInt(b->getDisc()); } bool MediaLibrary::SortAllTracks(MPD::Song *a, MPD::Song *b) { - static MPD::Song::GetFunction gets[] = { &MPD::Song::GetDate, &MPD::Song::GetAlbum, &MPD::Song::GetDisc, 0 }; + static MPD::Song::GetFunction gets[] = { &MPD::Song::getDate, &MPD::Song::getAlbum, &MPD::Song::getDisc, 0 }; CaseInsensitiveStringComparison cmp; for (MPD::Song::GetFunction *get = gets; *get; ++get) - if (int ret = cmp(a->GetTags(*get), b->GetTags(*get))) + if (int ret = cmp(a->getTags(*get), b->getTags(*get))) return ret < 0; - return a->GetTrack() < b->GetTrack(); + return a->getTrack() < b->getTrack(); } diff --git a/src/mpdpp.cpp b/src/mpdpp.cpp index 2fe98a8d..1cef3ec1 100644 --- a/src/mpdpp.cpp +++ b/src/mpdpp.cpp @@ -569,8 +569,7 @@ bool MPD::Connection::ClearPlaylist(const std::string &playlist) void MPD::Connection::AddToPlaylist(const std::string &path, const Song &s) { - if (!s.Empty()) - AddToPlaylist(path, s.GetFile()); + AddToPlaylist(path, s.getURI()); } void MPD::Connection::AddToPlaylist(const std::string &path, const std::string &file) @@ -632,7 +631,7 @@ void MPD::Connection::GetPlaylistChanges(unsigned version, SongList &v) GoBusy(); mpd_send_queue_changes_meta(itsConnection, version); while (mpd_song *s = mpd_recv_song(itsConnection)) - v.push_back(new Song(s, 1)); + v.push_back(new Song(s)); mpd_response_finish(itsConnection); GoIdle(); } @@ -664,7 +663,8 @@ MPD::Song MPD::Connection::GetCurrentlyPlayingSong() { assert(!isCommandsListEnabled); GoBusy(); - Song result = Song(itsConnection && isPlaying() ? mpd_run_current_song(itsConnection) : 0); + mpd_song *s = itsConnection && isPlaying() ? mpd_run_current_song(itsConnection) : 0; + Song result = s ? Song(s) : Song(); GoIdle(); return result; } @@ -846,12 +846,12 @@ bool MPD::Connection::SetPriority(const Song &s, int prio) if (!isCommandsListEnabled) { GoBusy(); - return mpd_run_prio_id(itsConnection, prio, s.GetID()); + return mpd_run_prio_id(itsConnection, prio, s.getID()); } else { assert(!isIdle); - return mpd_send_prio_id(itsConnection, prio, s.GetID()); + return mpd_send_prio_id(itsConnection, prio, s.getID()); } } @@ -880,7 +880,7 @@ int MPD::Connection::AddSong(const std::string &path, int pos) int MPD::Connection::AddSong(const Song &s, int pos) { - return !s.Empty() ? (AddSong((!s.isFromDB() ? "file://" : "") + (s.Localized() ? locale_to_utf_cpy(s.GetFile()) : s.GetFile()), pos)) : -1; + return AddSong((!s.isFromDatabase() ? "file://" : "") + s.getURI(), pos); } bool MPD::Connection::Add(const std::string &path) diff --git a/src/playlist.cpp b/src/playlist.cpp index 7d9185a5..f52fc2a9 100644 --- a/src/playlist.cpp +++ b/src/playlist.cpp @@ -66,16 +66,16 @@ void Playlist::Init() SortDialog->CenteredCursor(Config.centered_cursor); SortDialog->SetItemDisplayer(Display::Pairs); - SortDialog->AddOption(std::make_pair("Artist", &MPD::Song::GetArtist)); - SortDialog->AddOption(std::make_pair("Album", &MPD::Song::GetAlbum)); - SortDialog->AddOption(std::make_pair("Disc", &MPD::Song::GetDisc)); - SortDialog->AddOption(std::make_pair("Track", &MPD::Song::GetTrack)); - SortDialog->AddOption(std::make_pair("Genre", &MPD::Song::GetGenre)); - SortDialog->AddOption(std::make_pair("Date", &MPD::Song::GetDate)); - SortDialog->AddOption(std::make_pair("Composer", &MPD::Song::GetComposer)); - SortDialog->AddOption(std::make_pair("Performer", &MPD::Song::GetPerformer)); - SortDialog->AddOption(std::make_pair("Title", &MPD::Song::GetTitle)); - SortDialog->AddOption(std::make_pair("Filename", &MPD::Song::GetFile)); + SortDialog->AddOption(std::make_pair("Artist", &MPD::Song::getArtist)); + SortDialog->AddOption(std::make_pair("Album", &MPD::Song::getAlbum)); + SortDialog->AddOption(std::make_pair("Disc", &MPD::Song::getDisc)); + SortDialog->AddOption(std::make_pair("Track", &MPD::Song::getTrack)); + SortDialog->AddOption(std::make_pair("Genre", &MPD::Song::getGenre)); + SortDialog->AddOption(std::make_pair("Date", &MPD::Song::getDate)); + SortDialog->AddOption(std::make_pair("Composer", &MPD::Song::getComposer)); + SortDialog->AddOption(std::make_pair("Performer", &MPD::Song::getPerformer)); + SortDialog->AddOption(std::make_pair("Title", &MPD::Song::getTitle)); + SortDialog->AddOption(std::make_pair("Filename", &MPD::Song::getURI)); SortDialog->AddSeparator(); SortDialog->AddOption(std::make_pair("Sort", static_cast(0))); SortDialog->AddOption(std::make_pair("Cancel", static_cast(0))); @@ -152,7 +152,7 @@ void Playlist::EnterPressed() if (w == Items) { if (!Items->Empty()) - Mpd.PlayID(Items->Current().GetID()); + Mpd.PlayID(Items->Current().getID()); } else if (w == SortDialog) { @@ -191,9 +191,9 @@ void Playlist::EnterPressed() auto song_cmp = [](MPD::Song *a, MPD::Song *b) { CaseInsensitiveStringComparison cmp; for (size_t i = 0; i < SortOptions; ++i) - if (int ret = cmp(a->GetTags((*SortDialog)[i].second), b->GetTags((*SortDialog)[i].second))) + if (int ret = cmp(a->getTags((*SortDialog)[i].second), b->getTags((*SortDialog)[i].second))) return ret < 0; - return a->GetPosition() < b->GetPosition(); + return a->getPosition() < b->getPosition(); }; iter_swap = [&playlist](MPD::SongList::iterator a, MPD::SongList::iterator b) { std::iter_swap(a, b); @@ -452,14 +452,14 @@ std::string Playlist::TotalLength() { itsTotalLength = 0; for (size_t i = 0; i < Items->Size(); ++i) - itsTotalLength += (*Items)[i].GetTotalLength(); + itsTotalLength += (*Items)[i].getDuration(); ReloadTotalLength = 0; } if (Config.playlist_show_remaining_time && ReloadRemaining && !Items->isFiltered()) { itsRemainingTime = 0; for (size_t i = NowPlaying; i < Items->Size(); ++i) - itsRemainingTime += (*Items)[i].GetTotalLength(); + itsRemainingTime += (*Items)[i].getDuration(); ReloadRemaining = false; } @@ -512,12 +512,12 @@ bool Playlist::Add(const MPD::Song &s, bool in_playlist, bool play, int position { if (Config.ncmpc_like_songs_adding && in_playlist) { - unsigned hash = s.GetHash(); + unsigned hash = s.getHash(); if (play) { for (size_t i = 0; i < Items->Size(); ++i) { - if (Items->at(i).GetHash() == hash) + if (Items->at(i).getHash() == hash) { Mpd.Play(i); break; @@ -530,7 +530,7 @@ bool Playlist::Add(const MPD::Song &s, bool in_playlist, bool play, int position Mpd.StartCommandsList(); for (size_t i = 0; i < Items->Size(); ++i) { - if ((*Items)[i].GetHash() == hash) + if ((*Items)[i].getHash() == hash) { Mpd.Delete(i); Items->DeleteOption(i); diff --git a/src/playlist_editor.cpp b/src/playlist_editor.cpp index c181277c..39543344 100644 --- a/src/playlist_editor.cpp +++ b/src/playlist_editor.cpp @@ -161,7 +161,7 @@ void PlaylistEditor::Update() { for (size_t j = 0; j < myPlaylist->Items->Size(); ++j) { - if ((*it)->GetHash() == myPlaylist->Items->at(j).GetHash()) + if ((*it)->getHash() == myPlaylist->Items->at(j).getHash()) { bold = 1; break; diff --git a/src/search_engine.cpp b/src/search_engine.cpp index 5d403241..d56f8568 100644 --- a/src/search_engine.cpp +++ b/src/search_engine.cpp @@ -266,7 +266,7 @@ void SearchEngine::UpdateFoundList() { for (size_t j = 0; j < myPlaylist->Items->Size(); ++j) { - if (myPlaylist->Items->at(j).GetHash() == w->at(i).second->GetHash()) + if (myPlaylist->Items->at(j).getHash() == w->at(i).second->getHash()) { bold = 1; break; @@ -283,7 +283,7 @@ void SearchEngine::SelectAlbum() if (pos < StaticOptions) return; // not on a song - std::string album = w->at(pos).second->GetAlbum(); + std::string album = w->at(pos).second->getAlbum(); // select song under cursor w->Select(pos, 1); @@ -291,7 +291,7 @@ void SearchEngine::SelectAlbum() // go up while (pos > StaticOptions) { - if (w->at(--pos).second->GetAlbum() != album) + if (w->at(--pos).second->getAlbum() != album) break; else w->Select(pos, 1); @@ -300,7 +300,7 @@ void SearchEngine::SelectAlbum() // go down while (pos < w->Size() - 1) { - if (w->at(++pos).second->GetAlbum() != album) + if (w->at(++pos).second->getAlbum() != album) break; else w->Select(pos, 1); @@ -422,16 +422,16 @@ void SearchEngine::Search() if (regcomp(&rx, itsConstraints[0].c_str(), REG_ICASE | Config.regex_type) == 0) { any_found = - !regexec(&rx, (*it)->GetArtist().c_str(), 0, 0, 0) - || !regexec(&rx, (*it)->GetAlbumArtist().c_str(), 0, 0, 0) - || !regexec(&rx, (*it)->GetTitle().c_str(), 0, 0, 0) - || !regexec(&rx, (*it)->GetAlbum().c_str(), 0, 0, 0) - || !regexec(&rx, (*it)->GetName().c_str(), 0, 0, 0) - || !regexec(&rx, (*it)->GetComposer().c_str(), 0, 0, 0) - || !regexec(&rx, (*it)->GetPerformer().c_str(), 0, 0, 0) - || !regexec(&rx, (*it)->GetGenre().c_str(), 0, 0, 0) - || !regexec(&rx, (*it)->GetDate().c_str(), 0, 0, 0) - || !regexec(&rx, (*it)->GetComment().c_str(), 0, 0, 0); + !regexec(&rx, (*it)->getArtist().c_str(), 0, 0, 0) + || !regexec(&rx, (*it)->getAlbumArtist().c_str(), 0, 0, 0) + || !regexec(&rx, (*it)->getTitle().c_str(), 0, 0, 0) + || !regexec(&rx, (*it)->getAlbum().c_str(), 0, 0, 0) + || !regexec(&rx, (*it)->getName().c_str(), 0, 0, 0) + || !regexec(&rx, (*it)->getComposer().c_str(), 0, 0, 0) + || !regexec(&rx, (*it)->getPerformer().c_str(), 0, 0, 0) + || !regexec(&rx, (*it)->getGenre().c_str(), 0, 0, 0) + || !regexec(&rx, (*it)->getDate().c_str(), 0, 0, 0) + || !regexec(&rx, (*it)->getComment().c_str(), 0, 0, 0); } regfree(&rx); } @@ -439,61 +439,61 @@ void SearchEngine::Search() if (found && !itsConstraints[1].empty()) { if (!regcomp(&rx, itsConstraints[1].c_str(), REG_ICASE | Config.regex_type)) - found = !regexec(&rx, (*it)->GetArtist().c_str(), 0, 0, 0); + found = !regexec(&rx, (*it)->getArtist().c_str(), 0, 0, 0); regfree(&rx); } if (found && !itsConstraints[2].empty()) { if (!regcomp(&rx, itsConstraints[2].c_str(), REG_ICASE | Config.regex_type)) - found = !regexec(&rx, (*it)->GetAlbumArtist().c_str(), 0, 0, 0); + found = !regexec(&rx, (*it)->getAlbumArtist().c_str(), 0, 0, 0); regfree(&rx); } if (found && !itsConstraints[3].empty()) { if(!regcomp(&rx, itsConstraints[3].c_str(), REG_ICASE | Config.regex_type)) - found = !regexec(&rx, (*it)->GetTitle().c_str(), 0, 0, 0); + found = !regexec(&rx, (*it)->getTitle().c_str(), 0, 0, 0); regfree(&rx); } if (found && !itsConstraints[4].empty()) { if (!regcomp(&rx, itsConstraints[4].c_str(), REG_ICASE | Config.regex_type)) - found = !regexec(&rx, (*it)->GetAlbum().c_str(), 0, 0, 0); + found = !regexec(&rx, (*it)->getAlbum().c_str(), 0, 0, 0); regfree(&rx); } if (found && !itsConstraints[5].empty()) { if (!regcomp(&rx, itsConstraints[5].c_str(), REG_ICASE | Config.regex_type)) - found = !regexec(&rx, (*it)->GetName().c_str(), 0, 0, 0); + found = !regexec(&rx, (*it)->getName().c_str(), 0, 0, 0); regfree(&rx); } if (found && !itsConstraints[6].empty()) { if (!regcomp(&rx, itsConstraints[6].c_str(), REG_ICASE | Config.regex_type)) - found = !regexec(&rx, (*it)->GetComposer().c_str(), 0, 0, 0); + found = !regexec(&rx, (*it)->getComposer().c_str(), 0, 0, 0); regfree(&rx); } if (found && !itsConstraints[7].empty()) { if (!regcomp(&rx, itsConstraints[7].c_str(), REG_ICASE | Config.regex_type)) - found = !regexec(&rx, (*it)->GetPerformer().c_str(), 0, 0, 0); + found = !regexec(&rx, (*it)->getPerformer().c_str(), 0, 0, 0); regfree(&rx); } if (found && !itsConstraints[8].empty()) { if (!regcomp(&rx, itsConstraints[8].c_str(), REG_ICASE | Config.regex_type)) - found = !regexec(&rx, (*it)->GetGenre().c_str(), 0, 0, 0); + found = !regexec(&rx, (*it)->getGenre().c_str(), 0, 0, 0); regfree(&rx); } if (found && !itsConstraints[9].empty()) { if (!regcomp(&rx, itsConstraints[9].c_str(), REG_ICASE | Config.regex_type)) - found = !regexec(&rx, (*it)->GetDate().c_str(), 0, 0, 0); + found = !regexec(&rx, (*it)->getDate().c_str(), 0, 0, 0); regfree(&rx); } if (found && !itsConstraints[10].empty()) { if (!regcomp(&rx, itsConstraints[10].c_str(), REG_ICASE | Config.regex_type)) - found = !regexec(&rx, (*it)->GetComment().c_str(), 0, 0, 0); + found = !regexec(&rx, (*it)->getComment().c_str(), 0, 0, 0); regfree(&rx); } } @@ -503,37 +503,37 @@ void SearchEngine::Search() if (!itsConstraints[0].empty()) any_found = - !cmp((*it)->GetArtist(), itsConstraints[0]) - || !cmp((*it)->GetAlbumArtist(), itsConstraints[0]) - || !cmp((*it)->GetTitle(), itsConstraints[0]) - || !cmp((*it)->GetAlbum(), itsConstraints[0]) - || !cmp((*it)->GetName(), itsConstraints[0]) - || !cmp((*it)->GetComposer(), itsConstraints[0]) - || !cmp((*it)->GetPerformer(), itsConstraints[0]) - || !cmp((*it)->GetGenre(), itsConstraints[0]) - || !cmp((*it)->GetDate(), itsConstraints[0]) - || !cmp((*it)->GetComment(), itsConstraints[0]); + !cmp((*it)->getArtist(), itsConstraints[0]) + || !cmp((*it)->getAlbumArtist(), itsConstraints[0]) + || !cmp((*it)->getTitle(), itsConstraints[0]) + || !cmp((*it)->getAlbum(), itsConstraints[0]) + || !cmp((*it)->getName(), itsConstraints[0]) + || !cmp((*it)->getComposer(), itsConstraints[0]) + || !cmp((*it)->getPerformer(), itsConstraints[0]) + || !cmp((*it)->getGenre(), itsConstraints[0]) + || !cmp((*it)->getDate(), itsConstraints[0]) + || !cmp((*it)->getComment(), itsConstraints[0]); if (found && !itsConstraints[1].empty()) - found = !cmp((*it)->GetArtist(), itsConstraints[1]); + found = !cmp((*it)->getArtist(), itsConstraints[1]); if (found && !itsConstraints[2].empty()) - found = !cmp((*it)->GetAlbumArtist(), itsConstraints[2]); + found = !cmp((*it)->getAlbumArtist(), itsConstraints[2]); if (found && !itsConstraints[3].empty()) - found = !cmp((*it)->GetTitle(), itsConstraints[3]); + found = !cmp((*it)->getTitle(), itsConstraints[3]); if (found && !itsConstraints[4].empty()) - found = !cmp((*it)->GetAlbum(), itsConstraints[4]); + found = !cmp((*it)->getAlbum(), itsConstraints[4]); if (found && !itsConstraints[5].empty()) - found = !cmp((*it)->GetName(), itsConstraints[5]); + found = !cmp((*it)->getName(), itsConstraints[5]); if (found && !itsConstraints[6].empty()) - found = !cmp((*it)->GetComposer(), itsConstraints[6]); + found = !cmp((*it)->getComposer(), itsConstraints[6]); if (found && !itsConstraints[7].empty()) - found = !cmp((*it)->GetPerformer(), itsConstraints[7]); + found = !cmp((*it)->getPerformer(), itsConstraints[7]); if (found && !itsConstraints[8].empty()) - found = !cmp((*it)->GetGenre(), itsConstraints[8]); + found = !cmp((*it)->getGenre(), itsConstraints[8]); if (found && !itsConstraints[9].empty()) - found = !cmp((*it)->GetDate(), itsConstraints[9]); + found = !cmp((*it)->getDate(), itsConstraints[9]); if (found && !itsConstraints[10].empty()) - found = !cmp((*it)->GetComment(), itsConstraints[10]); + found = !cmp((*it)->getComment(), itsConstraints[10]); } if (found && any_found) diff --git a/src/sel_items_adder.cpp b/src/sel_items_adder.cpp index 0ef44bc5..0ed178d6 100644 --- a/src/sel_items_adder.cpp +++ b/src/sel_items_adder.cpp @@ -227,10 +227,10 @@ void SelectedItemsAdder::EnterPressed() } else if (pos == 3) // after currently playing album { - std::string album = myPlaylist->NowPlayingSong()->GetAlbum(); + std::string album = myPlaylist->NowPlayingSong()->getAlbum(); int i; for (i = Mpd.GetCurrentlyPlayingSongPos()+1; i < int(myPlaylist->Items->Size()); ++i) - if ((*myPlaylist->Items)[i].GetAlbum() != album) + if ((*myPlaylist->Items)[i].getAlbum() != album) break; successful_operation = myPlaylist->Add(list, 0, i); } diff --git a/src/song.cpp b/src/song.cpp index 766c0c5a..a2364a3e 100644 --- a/src/song.cpp +++ b/src/song.cpp @@ -18,337 +18,313 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include +#include #include -#include #include -#include -#include +#include -#include "charset.h" -#include "conv.h" -#include "error.h" #include "song.h" +#include "conv.h" -namespace +namespace {// + +unsigned calc_hash(const char* s, unsigned seed = 0) { - unsigned calc_hash(const char *p) - { - unsigned hash = 5381; - while (*p) - hash = (hash << 5) + hash + *p++; - return hash; - } + unsigned hash = seed; + while (*s) + hash = hash * 101 + *s++; + return hash; } -MPD::Song::Song(mpd_song *s, bool copy_ptr) : itsSong(s), - itsFile(0), - itsTags(0), - itsSlash(std::string::npos), - itsHash(0), - copyPtr(copy_ptr), - isLocalised(0) -{ - if (itsSong) - SetHashAndSlash(); } -MPD::Song::Song(const Song &s) : itsSong(s.copyPtr ? s.itsSong : mpd_song_dup(s.itsSong)), - itsFile(s.itsFile ? strdup(s.itsFile) : 0), - itsTags(s.itsTags ? new TagMap(*s.itsTags) : 0), - itsNewName(s.itsNewName), - itsSlash(s.itsSlash), - itsHash(s.itsHash), - copyPtr(s.copyPtr), - isLocalised(s.isLocalised) -{ -} +namespace MPD {// -MPD::Song::~Song() +struct SongImpl { - if (itsSong) - mpd_song_free(itsSong); - delete [] itsFile; - delete itsTags; -} - -std::string MPD::Song::GetLength(unsigned pos) const -{ - if (pos > 0) - return ""; - unsigned len = mpd_song_get_duration(itsSong); - return !len ? "-:--" : ShowTime(len); -} - -std::string MPD::Song::GetPriority(unsigned pos) const -{ - if (pos > 0) - return ""; - return IntoStr(GetPrio()); -} - -void MPD::Song::Localize() -{ -# ifdef HAVE_ICONV_H - if (isLocalised) - return; - const char *tag, *conv_tag; - conv_tag = tag = mpd_song_get_uri(itsSong); - utf_to_locale(conv_tag, 0); - if (tag != conv_tag) // file has been converted - { - itsFile = conv_tag; - SetHashAndSlash(); - } - for (unsigned t = MPD_TAG_ARTIST; t <= MPD_TAG_DISC; ++t) - { - unsigned pos = 0; - for (; (tag = mpd_song_get_tag(itsSong, mpd_tag_type(t), pos)); ++pos) - { - conv_tag = tag; - utf_to_locale(conv_tag, 0); - if (tag != conv_tag) // tag has been converted - { - SetTag(mpd_tag_type(t), pos, conv_tag); - delete [] conv_tag; - } - } - } - isLocalised = 1; -# endif // HAVE_ICONV_H -} - -void MPD::Song::Clear() -{ - if (itsSong) - mpd_song_free(itsSong); - itsSong = 0; + mpd_song *m_song; + unsigned m_hash; - delete [] itsFile; - itsFile = 0; + SongImpl(mpd_song *s, unsigned hash) : m_song(s), m_hash(hash) { } + ~SongImpl() { mpd_song_free(m_song); } - delete itsTags; - itsTags = 0; - - itsNewName.clear(); - itsSlash = std::string::npos; - itsHash = 0; - isLocalised = 0; - copyPtr = 0; + const char *getTag(mpd_tag_type type, unsigned idx) + { + const char *tag = mpd_song_get_tag(m_song, type, idx); + return tag ? tag : ""; + } +}; + +Song::Song(mpd_song *s) +{ + assert(s); + pimpl = std::shared_ptr(new SongImpl(s, calc_hash(mpd_song_get_uri(s)))); } -bool MPD::Song::Empty() const +std::string Song::getURI(unsigned idx) const { - return !itsSong; -} - -bool MPD::Song::isFromDB() const -{ - return (MyFilename()[0] != '/') || itsSlash == std::string::npos; -} - -bool MPD::Song::isStream() const -{ - return !strncmp(MyFilename(), "http://", 7); -} - -std::string MPD::Song::GetFile(unsigned pos) const -{ - return pos > 0 ? "" : MyFilename(); -} - -std::string MPD::Song::GetName(unsigned pos) const -{ - if (pos > 0) + assert(pimpl); + if (idx > 0) return ""; - std::string name = GetTag(MPD_TAG_NAME, 0); - if (!name.empty()) - return name; - else if (itsSlash != std::string::npos) - return MyFilename()+itsSlash+1; else - return MyFilename(); + return mpd_song_get_uri(pimpl->m_song); } -std::string MPD::Song::GetDirectory(unsigned pos) const +std::string Song::getName(unsigned idx) const { - if (pos > 0 || isStream()) + assert(pimpl); + mpd_song *s = pimpl->m_song; + const char *res = mpd_song_get_tag(s, MPD_TAG_NAME, idx); + if (!res && idx > 0) return ""; - else if (itsSlash == std::string::npos) + const char *uri = mpd_song_get_uri(s); + const char *name = strrchr(uri, '/'); + if (name) + return name+1; + else + return uri; +} + +std::string Song::getDirectory(unsigned idx) const +{ + assert(pimpl); + if (idx > 0 || isStream()) + return ""; + const char *uri = mpd_song_get_uri(pimpl->m_song); + const char *name = strrchr(uri, '/'); + if (name) + return std::string(uri, name-uri); + else return "/"; +} + +std::string Song::getArtist(unsigned idx) const +{ + assert(pimpl); + return pimpl->getTag(MPD_TAG_ARTIST, idx); +} + +std::string Song::getTitle(unsigned idx) const +{ + assert(pimpl); + return pimpl->getTag(MPD_TAG_TITLE, idx); +} + +std::string Song::getAlbum(unsigned idx) const +{ + assert(pimpl); + return pimpl->getTag(MPD_TAG_ALBUM, idx); +} + +std::string Song::getAlbumArtist(unsigned idx) const +{ + assert(pimpl); + return pimpl->getTag(MPD_TAG_ALBUM_ARTIST, idx); +} + +std::string Song::getTrack(unsigned idx) const +{ + assert(pimpl); + std::string track = pimpl->getTag(MPD_TAG_TRACK, idx); + if ((track.length() == 1 && track[0] != '0') + || (track.length() > 3 && track[1] == '/')) + return "0"+track; else - return std::string(MyFilename(), itsSlash); + return track; } -std::string MPD::Song::GetArtist(unsigned pos) const +std::string Song::getTrackNumber(unsigned idx) const { - return GetTag(MPD_TAG_ARTIST, pos); -} - -std::string MPD::Song::GetTitle(unsigned pos) const -{ - return GetTag(MPD_TAG_TITLE, pos); -} - -std::string MPD::Song::GetAlbum(unsigned pos) const -{ - return GetTag(MPD_TAG_ALBUM, pos); -} - -std::string MPD::Song::GetAlbumArtist(unsigned pos) const -{ - return GetTag(MPD_TAG_ALBUM_ARTIST, pos); -} - -std::string MPD::Song::GetTrack(unsigned pos) const -{ - std::string track = GetTag(MPD_TAG_TRACK, pos); - return (track.length() == 1 && track[0] != '0') || (track.length() > 3 && track[1] == '/') ? "0"+track : track; -} - -std::string MPD::Song::GetTrackNumber(unsigned pos) const -{ - std::string track = GetTag(MPD_TAG_TRACK, pos); + assert(pimpl); + std::string track = pimpl->getTag(MPD_TAG_TRACK, idx); size_t slash = track.find('/'); if (slash != std::string::npos) track.resize(slash); - return track.length() == 1 && track[0] != '0' ? "0"+track : track; + if (track.length() == 1 && track[0] != '0') + return "0"+track; + else + return track; } -std::string MPD::Song::GetDate(unsigned pos) const +std::string Song::getDate(unsigned idx) const { - return GetTag(MPD_TAG_DATE, pos); + assert(pimpl); + return pimpl->getTag(MPD_TAG_DATE, idx); } -std::string MPD::Song::GetGenre(unsigned pos) const +std::string Song::getGenre(unsigned idx) const { - return GetTag(MPD_TAG_GENRE, pos); + assert(pimpl); + return pimpl->getTag(MPD_TAG_GENRE, idx); } -std::string MPD::Song::GetComposer(unsigned pos) const +std::string Song::getComposer(unsigned idx) const { - return GetTag(MPD_TAG_COMPOSER, pos); + assert(pimpl); + return pimpl->getTag(MPD_TAG_COMPOSER, idx); } -std::string MPD::Song::GetPerformer(unsigned pos) const +std::string Song::getPerformer(unsigned idx) const { - return GetTag(MPD_TAG_PERFORMER, pos); + assert(pimpl); + return pimpl->getTag(MPD_TAG_PERFORMER, idx); } -std::string MPD::Song::GetDisc(unsigned pos) const +std::string Song::getDisc(unsigned idx) const { - return GetTag(MPD_TAG_DISC, pos); + assert(pimpl); + return pimpl->getTag(MPD_TAG_DISC, idx); } -std::string MPD::Song::GetComment(unsigned pos) const +std::string Song::getComment(unsigned idx) const { - return GetTag(MPD_TAG_COMMENT, pos); + assert(pimpl); + return pimpl->getTag(MPD_TAG_COMMENT, idx); } -std::string MPD::Song::GetTags(GetFunction f) const +std::string Song::getLength(unsigned idx) const { - unsigned pos = 0; + assert(pimpl); + if (idx > 0) + return ""; + unsigned len = mpd_song_get_duration(pimpl->m_song); + if (len > 0) + return ShowTime(len); + else + return "-:--"; +} + +std::string Song::getPriority(unsigned idx) const +{ + assert(pimpl); + if (idx > 0) + return ""; + char buf[10]; + snprintf(buf, sizeof(buf), "%d", getPrio()); + return buf; +} + +std::string MPD::Song::getTags(GetFunction f, const std::string tag_separator) const +{ + assert(pimpl); + unsigned idx = 0; std::string result; - for (std::string tag; !(tag = (this->*f)(pos)).empty(); ++pos) + for (std::string tag; !(tag = (this->*f)(idx)).empty(); ++idx) { if (!result.empty()) - result += ", "; + result += tag_separator; result += tag; } return result; } -void MPD::Song::SetArtist(const std::string &str, unsigned pos) +unsigned Song::getHash() const { - SetTag(MPD_TAG_ARTIST, pos, str); + assert(pimpl); + return pimpl->m_hash; } -void MPD::Song::SetTitle(const std::string &str, unsigned pos) +unsigned Song::getDuration() const { - SetTag(MPD_TAG_TITLE, pos, str); + assert(pimpl); + return mpd_song_get_duration(pimpl->m_song); } -void MPD::Song::SetAlbum(const std::string &str, unsigned pos) +unsigned Song::getPosition() const { - SetTag(MPD_TAG_ALBUM, pos, str); + assert(pimpl); + return mpd_song_get_pos(pimpl->m_song); } -void MPD::Song::SetAlbumArtist(const std::string &str, unsigned pos) +unsigned Song::getID() const { - SetTag(MPD_TAG_ALBUM_ARTIST, pos, str); + assert(pimpl); + return mpd_song_get_id(pimpl->m_song); } -void MPD::Song::SetTrack(const std::string &str, unsigned pos) +unsigned Song::getPrio() const { - SetTag(MPD_TAG_TRACK, pos, str); + assert(pimpl); + return mpd_song_get_prio(pimpl->m_song); } -void MPD::Song::SetTrack(unsigned track, unsigned pos) +time_t Song::getMTime() const { - SetTag(MPD_TAG_TRACK, pos, IntoStr(track)); + assert(pimpl); + return mpd_song_get_last_modified(pimpl->m_song); } -void MPD::Song::SetDate(const std::string &str, unsigned pos) +bool Song::isFromDatabase() const { - SetTag(MPD_TAG_DATE, pos, str); + assert(pimpl); + const char *uri = mpd_song_get_uri(pimpl->m_song); + return uri[0] != '/' || !strrchr(uri, '/'); } -void MPD::Song::SetGenre(const std::string &str, unsigned pos) +bool Song::isStream() const { - SetTag(MPD_TAG_GENRE, pos, str); + assert(pimpl); + return !strncmp(mpd_song_get_uri(pimpl->m_song), "http://", 7); } -void MPD::Song::SetComposer(const std::string &str, unsigned pos) +bool Song::empty() const { - SetTag(MPD_TAG_COMPOSER, pos, str); + return pimpl == 0; } -void MPD::Song::SetPerformer(const std::string &str, unsigned pos) +std::string Song::toString(const std::string &fmt, const std::string &tag_separator, const std::string &escape_chars) const { - SetTag(MPD_TAG_PERFORMER, pos, str); + assert(pimpl); + std::string::const_iterator it = fmt.begin(); + return ParseFormat(it, tag_separator, escape_chars); } -void MPD::Song::SetDisc(const std::string &str, unsigned pos) +std::string Song::ShowTime(unsigned length) { - SetTag(MPD_TAG_DISC, pos, str); + int hours = length/3600; + length -= hours*3600; + int minutes = length/60; + length -= minutes*60; + int seconds = length; + + char buf[10]; + if (hours > 0) + snprintf(buf, sizeof(buf), "%d:%02d:%02d", hours, minutes, seconds); + else + snprintf(buf, sizeof(buf), "%d:%02d", minutes, seconds); + return buf; } -void MPD::Song::SetComment(const std::string &str, unsigned pos) +bool MPD::Song::isFormatOk(const std::string &type, const std::string &fmt) { - SetTag(MPD_TAG_COMMENT, pos, str); -} - -void MPD::Song::SetTags(SetFunction f, const std::string &value) -{ - unsigned pos = 0; - // tag editor can save multiple instances of performer and composer - // tag, so we need to split them and allow it to read them separately. - if (f == &Song::SetComposer || f == &Song::SetPerformer) + int braces = 0; + for (std::string::const_iterator it = fmt.begin(); it != fmt.end(); ++it) { - for (size_t i = 0; i != std::string::npos; i = value.find(",", i)) + if (*it == '{') + ++braces; + else if (*it == '}') + --braces; + } + if (braces) + { + std::cerr << type << ": number of opening and closing braces does not equal!\n"; + return false; + } + + for (size_t i = fmt.find('%'); i != std::string::npos; i = fmt.find('%', i)) + { + if (isdigit(fmt[++i])) + while (isdigit(fmt[++i])) { } + if (!toGetFunction(fmt[i])) { - if (i) - ++i; - while (value[i] == ' ') - ++i; - size_t j = value.find(",", i); - (this->*f)(value.substr(i, j-i), pos++); + std::cerr << type << ": invalid character at position " << IntoStr(i+1) << ": '" << fmt[i] << "'\n"; + return false; } } - else - (this->*f)(value, pos++); - // there should be empty tag at the end since if we are - // reading them, original tag from mpd_song at the position - // after the last one locally set can be non-empty and in this - // case GetTags() would read it, which is undesirable. - (this->*f)("", pos); + return true; } -std::string MPD::Song::ParseFormat(std::string::const_iterator &it, const char *escape_chars) const +std::string Song::ParseFormat(std::string::const_iterator &it, const std::string &tag_separator, const std::string &escape_chars) const { std::string result; bool has_some_tags = 0; @@ -357,7 +333,7 @@ std::string MPD::Song::ParseFormat(std::string::const_iterator &it, const char * { while (*it == '{') { - std::string tags = ParseFormat(it, escape_chars); + std::string tags = ParseFormat(it, tag_separator, escape_chars); if (!tags.empty()) { has_some_tags = 1; @@ -386,12 +362,14 @@ std::string MPD::Song::ParseFormat(std::string::const_iterator &it, const char * if (get) { - std::string tag = GetTags(get); - if (escape_chars) // prepend format escape character to all given chars to escape - for (const char *ch = escape_chars; *ch; ++ch) - for (size_t i = 0; (i = tag.find(*ch, i)) != std::string::npos; i += 2) - tag.replace(i, 1, std::string(1, FormatEscapeCharacter) + *ch); - if (!tag.empty() && (get != &MPD::Song::GetLength || GetTotalLength())) + std::string tag = getTags(get, tag_separator); + if (!escape_chars.empty()) // prepend format escape character to all given chars to escape + { + for (size_t i = 0; i < escape_chars.length(); ++i) + for (size_t j = 0; (j = tag.find(escape_chars[i], j)) != std::string::npos; j += 2) + tag.replace(j, 1, std::string(1, FormatEscapeCharacter) + escape_chars[i]); + } + if (!tag.empty() && (get != &MPD::Song::getLength || getDuration() > 0)) { if (delimiter) { @@ -420,7 +398,7 @@ std::string MPD::Song::ParseFormat(std::string::const_iterator &it, const char * --brace_counter; } if (*++it == '|') - return ParseFormat(++it, escape_chars); + return ParseFormat(++it, tag_separator, escape_chars); else return ""; } @@ -441,117 +419,4 @@ std::string MPD::Song::ParseFormat(std::string::const_iterator &it, const char * } } -std::string MPD::Song::toString(const std::string &format, const char *escape_chars) const -{ - std::string::const_iterator it = format.begin(); - return ParseFormat(it, escape_chars); } - -MPD::Song &MPD::Song::operator=(const MPD::Song &s) -{ - if (this == &s) - return *this; - if (itsSong) - mpd_song_free(itsSong); - delete [] itsFile; - delete itsTags; - itsSong = s.copyPtr ? s.itsSong : (s.itsSong ? mpd_song_dup(s.itsSong) : 0); - itsFile = s.itsFile ? strdup(s.itsFile) : 0; - itsTags = s.itsTags ? new TagMap(*s.itsTags) : 0; - itsNewName = s.itsNewName; - itsSlash = s.itsSlash; - itsHash = s.itsHash; - copyPtr = s.copyPtr; - isLocalised = s.isLocalised; - return *this; -} - -std::string MPD::Song::ShowTime(int length) -{ - std::ostringstream ss; - - int hours = length/3600; - length -= hours*3600; - int minutes = length/60; - length -= minutes*60; - int seconds = length; - - if (hours > 0) - { - ss << hours << ":" - << std::setw(2) << std::setfill('0') << minutes << ":" - << std::setw(2) << std::setfill('0') << seconds; - } - else - { - ss << minutes << ":" - << std::setw(2) << std::setfill('0') << seconds; - } - return ss.str(); -} - -bool MPD::Song::isFormatOk(const std::string &type, const std::string &s) -{ - int braces = 0; - for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) - { - if (*it == '{') - ++braces; - else if (*it == '}') - --braces; - } - if (braces) - { - std::cerr << type << ": number of opening and closing braces does not equal!\n"; - return false; - } - - for (size_t i = s.find('%'); i != std::string::npos; i = s.find('%', i)) - { - if (isdigit(s[++i])) - while (isdigit(s[++i])) { } - if (!toGetFunction(s[i])) - { - std::cerr << type << ": invalid character at position " << IntoStr(i+1) << ": '" << s[i] << "'\n"; - return false; - } - } - return true; -} - -void MPD::Song::SetHashAndSlash() -{ - const char *filename = MyFilename(); - if (!isStream()) - { - const char *tmp = strrchr(filename, '/'); - itsSlash = tmp ? tmp-filename : std::string::npos; - } - if (!itsFile) - itsHash = calc_hash(filename); -} - -const char *MPD::Song::MyFilename() const -{ - return itsFile ? itsFile : mpd_song_get_uri(itsSong); -} - -void MPD::Song::SetTag(mpd_tag_type type, unsigned pos, const std::string &value) -{ - if (!itsTags) - itsTags = new TagMap; - (*itsTags)[std::make_pair(type, pos)] = value; -} - -std::string MPD::Song::GetTag(mpd_tag_type type, unsigned pos) const -{ - if (itsTags) - { - TagMap::const_iterator it = itsTags->find(std::make_pair(type, pos)); - if (it != itsTags->end()) - return it->second; - } - const char *tag = mpd_song_get_tag(itsSong, type, pos); - return tag ? tag : ""; -} - diff --git a/src/song.h b/src/song.h index a63cf4a8..dce19d1a 100644 --- a/src/song.h +++ b/src/song.h @@ -21,120 +21,66 @@ #ifndef _SONG_H #define _SONG_H -#include +#include +#include #include #include -namespace MPD +namespace MPD {// + +struct Song { - class Song - { - typedef std::map, std::string> TagMap; + typedef std::string (Song::*GetFunction)(unsigned) const; + + Song() { } + Song(mpd_song *s); + + std::string getURI(unsigned idx = 0) const; + std::string getName(unsigned idx = 0) const; + std::string getDirectory(unsigned idx = 0) const; + std::string getArtist(unsigned idx = 0) const; + std::string getTitle(unsigned idx = 0) const; + std::string getAlbum(unsigned idx = 0) const; + std::string getAlbumArtist(unsigned idx = 0) const; + std::string getTrack(unsigned idx = 0) const; + std::string getTrackNumber(unsigned idx = 0) const; + std::string getDate(unsigned idx = 0) const; + std::string getGenre(unsigned idx = 0) const; + std::string getComposer(unsigned idx = 0) const; + std::string getPerformer(unsigned idx = 0) const; + std::string getDisc(unsigned idx = 0) const; + std::string getComment(unsigned idx = 0) const; + std::string getLength(unsigned idx = 0) const; + std::string getPriority(unsigned idx = 0) const; + + std::string getTags(GetFunction f, const std::string tag_separator = ", ") const; + + unsigned getHash() const; + unsigned getDuration() const; + unsigned getPosition() const; + unsigned getID() const; + unsigned getPrio() const; + time_t getMTime() const; + + bool isFromDatabase() const; + bool isStream() const; + + bool empty() const; + + std::string toString(const std::string &fmt, const std::string &tag_separator = ", ", const std::string &escape_chars = "") const; + + static std::string ShowTime(unsigned length); + static bool isFormatOk(const std::string &type, const std::string &fmt); + + static const char FormatEscapeCharacter = 1; + + private: + std::string ParseFormat(std::string::const_iterator &it, const std::string &tag_separator, const std::string &escape_chars) const; - public: - - typedef void (Song::*SetFunction)(const std::string &, unsigned); - typedef std::string (Song::*GetFunction)(unsigned) const; - - Song(mpd_song * = 0, bool = 0); - Song(const Song &); - ~Song(); - - std::string GetFile(unsigned = 0) const; - std::string GetName(unsigned = 0) const; - std::string GetDirectory(unsigned = 0) const; - std::string GetArtist(unsigned = 0) const; - std::string GetTitle(unsigned = 0) const; - std::string GetAlbum(unsigned = 0) const; - std::string GetAlbumArtist(unsigned = 0) const; - std::string GetTrack(unsigned = 0) const; - std::string GetTrackNumber(unsigned = 0) const; - std::string GetDate(unsigned = 0) const; - std::string GetGenre(unsigned = 0) const; - std::string GetComposer(unsigned = 0) const; - std::string GetPerformer(unsigned = 0) const; - std::string GetDisc(unsigned = 0) const; - std::string GetComment(unsigned = 0) const; - std::string GetLength(unsigned = 0) const; - std::string GetPriority(unsigned = 0) const; - - std::string GetTags(GetFunction) const; - - unsigned GetHash() const { return itsHash; } - unsigned GetTotalLength() const { return mpd_song_get_duration(itsSong); } - unsigned GetPosition() const { return mpd_song_get_pos(itsSong); } - unsigned GetID() const { return mpd_song_get_id(itsSong); } - unsigned GetPrio() const { return mpd_song_get_prio(itsSong); } - - time_t GetMTime() const { return mpd_song_get_last_modified(itsSong); } - - void SetArtist(const std::string &, unsigned = 0); - void SetTitle(const std::string &, unsigned = 0); - void SetAlbum(const std::string &, unsigned = 0); - void SetAlbumArtist(const std::string &, unsigned = 0); - void SetTrack(const std::string &, unsigned = 0); - void SetTrack(unsigned, unsigned = 0); - void SetDate(const std::string &, unsigned = 0); - void SetGenre(const std::string &, unsigned = 0); - void SetComposer(const std::string &, unsigned = 0); - void SetPerformer(const std::string &, unsigned = 0); - void SetDisc(const std::string &, unsigned = 0); - void SetComment(const std::string &, unsigned = 0); - - void SetTags(SetFunction, const std::string &); - - void SetNewName(const std::string &name) { itsNewName = name == GetName() ? "" : name; } - std::string GetNewName() const { return itsNewName; } - - std::string toString(const std::string &, const char *escape_chars = 0) const; - static const char FormatEscapeCharacter = 1; - - void NullMe() { itsSong = 0; } - void CopyPtr(bool copy) { copyPtr = copy; } - - void Localize(); - void Clear(); - bool Empty() const; - bool isFromDB() const; - bool isStream() const; - bool Localized() const { return isLocalised; } - - Song &operator=(const Song &); - - static std::string ShowTime(int); - static bool isFormatOk(const std::string &type, const std::string &format); - - private: - void SetHashAndSlash(); - std::string ParseFormat(std::string::const_iterator &it, const char *escape_chars) const; - - void SetTag(mpd_tag_type, unsigned, const std::string &); - std::string GetTag(mpd_tag_type, unsigned) const; - - /// Used internally for handling filename, since we don't have - /// write access to file string in mpd_song, manage our own if - /// localization was done and there is localized filename that - /// is different than the original one. - /// - const char *MyFilename() const; - - /// internal mpd_song structure - mpd_song *itsSong; - - /// localized version of filename - const char *itsFile; - - /// map that contains localized tags or these set by tag editor - TagMap *itsTags; - - std::string itsNewName; - - size_t itsSlash; - unsigned itsHash; - bool copyPtr; - bool isLocalised; - }; + std::shared_ptr pimpl; +}; + } #endif diff --git a/src/song_info.cpp b/src/song_info.cpp index 8520a305..71c34ea8 100644 --- a/src/song_info.cpp +++ b/src/song_info.cpp @@ -29,18 +29,18 @@ SongInfo *mySongInfo = new SongInfo; const SongInfo::Metadata SongInfo::Tags[] = { - { "Title", &MPD::Song::GetTitle, &MPD::Song::SetTitle }, - { "Artist", &MPD::Song::GetArtist, &MPD::Song::SetArtist }, - { "Album Artist", &MPD::Song::GetAlbumArtist, &MPD::Song::SetAlbumArtist }, - { "Album", &MPD::Song::GetAlbum, &MPD::Song::SetAlbum }, - { "Date", &MPD::Song::GetDate, &MPD::Song::SetDate }, - { "Track", &MPD::Song::GetTrack, &MPD::Song::SetTrack }, - { "Genre", &MPD::Song::GetGenre, &MPD::Song::SetGenre }, - { "Composer", &MPD::Song::GetComposer, &MPD::Song::SetComposer }, - { "Performer", &MPD::Song::GetPerformer, &MPD::Song::SetPerformer }, - { "Disc", &MPD::Song::GetDisc, &MPD::Song::SetDisc }, - { "Comment", &MPD::Song::GetComment, &MPD::Song::SetComment }, - { 0, 0, 0 } + { "Title", &MPD::Song::getTitle, }, + { "Artist", &MPD::Song::getArtist, }, + { "Album Artist", &MPD::Song::getAlbumArtist, }, + { "Album", &MPD::Song::getAlbum, }, + { "Date", &MPD::Song::getDate, }, + { "Track", &MPD::Song::getTrack, }, + { "Genre", &MPD::Song::getGenre, }, + { "Composer", &MPD::Song::getComposer, }, + { "Performer", &MPD::Song::getPerformer, }, + { "Disc", &MPD::Song::getDisc, }, + { "Comment", &MPD::Song::getComment, }, + { 0, 0, } }; void SongInfo::Init() @@ -101,19 +101,19 @@ void SongInfo::PrepareSong(MPD::Song &s) { # ifdef HAVE_TAGLIB_H std::string path_to_file; - if (s.isFromDB()) + if (s.isFromDatabase()) path_to_file += Config.mpd_music_dir; - path_to_file += s.GetFile(); + path_to_file += s.getURI(); TagLib::FileRef f(path_to_file.c_str()); if (!f.isNull()) s.SetComment(f.tag()->comment().to8Bit(1)); # endif // HAVE_TAGLIB_H - *w << fmtBold << Config.color1 << "Filename: " << fmtBoldEnd << Config.color2 << s.GetName() << "\n" << clEnd; + *w << fmtBold << Config.color1 << "Filename: " << fmtBoldEnd << Config.color2 << s.getName() << "\n" << clEnd; *w << fmtBold << "Directory: " << fmtBoldEnd << Config.color2; - ShowTag(*w, s.GetDirectory()); + ShowTag(*w, s.getDirectory()); *w << "\n\n" << clEnd; - *w << fmtBold << "Length: " << fmtBoldEnd << Config.color2 << s.GetLength() << "\n" << clEnd; + *w << fmtBold << "Length: " << fmtBoldEnd << Config.color2 << s.getLength() << "\n" << clEnd; # ifdef HAVE_TAGLIB_H if (!f.isNull()) { @@ -127,7 +127,7 @@ void SongInfo::PrepareSong(MPD::Song &s) for (const Metadata *m = Tags; m->Name; ++m) { *w << fmtBold << "\n" << m->Name << ": " << fmtBoldEnd; - ShowTag(*w, s.GetTags(m->Get)); + ShowTag(*w, s.getTags(m->Get)); } } diff --git a/src/song_info.h b/src/song_info.h index a9ff2a33..09c1272f 100644 --- a/src/song_info.h +++ b/src/song_info.h @@ -31,7 +31,7 @@ class SongInfo : public Screen { const char *Name; MPD::Song::GetFunction Get; - MPD::Song::SetFunction Set; + //MPD::Song::SetFunction Set; }; virtual void SwitchTo(); diff --git a/src/status.cpp b/src/status.cpp index dbed4d0d..ee93b5be 100644 --- a/src/status.cpp +++ b/src/status.cpp @@ -222,9 +222,6 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) if (changed.Playlist) { - if (!(np = Mpd.GetCurrentlyPlayingSong()).Empty()) - WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format))); - bool was_filtered = myPlaylist->Items->isFiltered(); myPlaylist->Items->ShowAll(); MPD::SongList list; @@ -237,7 +234,7 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) myPlaylist->Items->Reserve(playlist_length); for (MPD::SongList::const_iterator it = list.begin(); it != list.end(); ++it) { - int pos = (*it)->GetPosition(); + int pos = (*it)->getPosition(); if (pos < int(myPlaylist->Items->Size())) { // if song's already in playlist, replace it with a new one @@ -248,8 +245,6 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) // otherwise just add it to playlist myPlaylist->Items->AddOption(**it); } - myPlaylist->Items->at(pos).CopyPtr(0); - (*it)->NullMe(); } if (was_filtered) { @@ -324,8 +319,7 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) } case MPD::psPlay: { - if (!np.Empty()) - WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format))); + //WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format))); player_state = Config.new_design ? "[playing]" : "Playing: "; Playlist::ReloadRemaining = true; if (Mpd.GetOldState() == MPD::psStop) // show track info in status immediately @@ -391,9 +385,6 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) Lyrics::DownloadInBackground(myPlaylist->NowPlayingSong()); # endif // HAVE_CURL_CURL_H - if (Mpd.isPlaying() && !(np = Mpd.GetCurrentlyPlayingSong()).Empty()) - WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format))); - if (Config.autocenter_mode && !myPlaylist->Items->isFiltered()) myPlaylist->Items->Highlight(myPlaylist->NowPlaying); @@ -407,9 +398,13 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) } if (changed.ElapsedTime || changed.SongID || Global::RedrawStatusbar) { - if (np.Empty() && !(np = Mpd.GetCurrentlyPlayingSong()).Empty()) - WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format))); - if (!np.Empty() && Mpd.isPlaying()) + if (np.empty()) + { + np = Mpd.GetCurrentlyPlayingSong(); + if (!np.empty()) + WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format))); + } + if (!np.empty() && Mpd.isPlaying()) { std::string tracklength; if (Config.new_design) @@ -487,7 +482,7 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) tracklength += "]"; } basic_buffer np_song; - String2Buffer(TO_WSTRING(utf_to_locale_cpy(np.toString(Config.song_status_format, "$"))), np_song); + //String2Buffer(TO_WSTRING(utf_to_locale_cpy(np.toString(Config.song_status_format, "$"))), np_song); *wFooter << XY(0, 1) << wclrtoeol << fmtBold << player_state << fmtBoldEnd; np_song.Write(*wFooter, playing_song_scroll_begin, wFooter->GetWidth()-player_state.length()-tracklength.length(), U(" ** ")); *wFooter << fmtBold << XY(wFooter->GetWidth()-tracklength.length(), 1) << tracklength << fmtBoldEnd; diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index e2ab7f9e..f07d7308 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -381,7 +381,7 @@ void TagEditor::EnterPressed() *FParserLegend << "%C - comment\n\n"; *FParserLegend << fmtBold << "Files:\n" << fmtBoldEnd; for (MPD::SongList::const_iterator it = EditedSongs.begin(); it != EditedSongs.end(); ++it) - *FParserLegend << Config.color2 << " * " << clEnd << (*it)->GetName() << "\n"; + *FParserLegend << Config.color2 << " * " << clEnd << (*it)->getName() << "\n"; FParserLegend->Flush(); if (!Patterns.empty()) @@ -442,7 +442,7 @@ void TagEditor::EnterPressed() { if (FParserUsePreview) { - *FParserPreview << fmtBold << s.GetName() << ":\n" << fmtBoldEnd; + *FParserPreview << fmtBold << s.getName() << ":\n" << fmtBoldEnd; *FParserPreview << ParseFilename(s, Config.pattern, FParserUsePreview) << "\n"; } else @@ -450,13 +450,13 @@ void TagEditor::EnterPressed() } else // rename files { - std::string file = s.GetName(); + std::string file = s.getName(); size_t last_dot = file.rfind("."); std::string extension = file.substr(last_dot); std::string new_file = GenerateFilename(s, "{" + Config.pattern + "}"); if (new_file.empty() && !FParserUsePreview) { - ShowMessage("File \"%s\" would have an empty name", s.GetName().c_str()); + ShowMessage("File \"%s\" would have an empty name", s.getName().c_str()); FParserUsePreview = 1; success = 0; } @@ -556,7 +556,7 @@ void TagEditor::EnterPressed() { LockStatusbar(); Statusbar() << fmtBold << TagTypes->Current() << fmtBoldEnd << ": "; - std::string new_tag = wFooter->GetString(Tags->Current().GetTags(get)); + std::string new_tag = wFooter->GetString(Tags->Current().getTags(get)); UnlockStatusbar(); for (MPD::SongList::iterator it = EditedSongs.begin(); it != EditedSongs.end(); ++it) (*it)->SetTags(set, new_tag); @@ -565,9 +565,9 @@ void TagEditor::EnterPressed() { LockStatusbar(); Statusbar() << fmtBold << TagTypes->Current() << fmtBoldEnd << ": "; - std::string new_tag = wFooter->GetString(Tags->Current().GetTags(get)); + std::string new_tag = wFooter->GetString(Tags->Current().getTags(get)); UnlockStatusbar(); - if (new_tag != Tags->Current().GetTags(get)) + if (new_tag != Tags->Current().getTags(get)) Tags->Current().SetTags(set, new_tag); Tags->Scroll(wDown); } @@ -589,7 +589,7 @@ void TagEditor::EnterPressed() else if (w == Tags) { MPD::Song &s = Tags->Current(); - std::string old_name = s.GetNewName().empty() ? s.GetName() : s.GetNewName(); + std::string old_name = s.GetNewName().empty() ? s.getName() : s.GetNewName(); size_t last_dot = old_name.rfind("."); std::string extension = old_name.substr(last_dot); old_name = old_name.substr(0, last_dot); @@ -627,11 +627,11 @@ void TagEditor::EnterPressed() ShowMessage("Writing changes..."); for (MPD::SongList::iterator it = EditedSongs.begin(); it != EditedSongs.end(); ++it) { - ShowMessage("Writing tags in \"%s\"...", (*it)->GetName().c_str()); + ShowMessage("Writing tags in \"%s\"...", (*it)->getName().c_str()); if (!WriteTags(**it)) { const char msg[] = "Error while writing tags in \"%s\""; - ShowMessage(msg, Shorten(TO_WSTRING((*it)->GetFile()), COLS-static_strlen(msg)).c_str()); + ShowMessage(msg, Shorten(TO_WSTRING((*it)->getURI()), COLS-static_strlen(msg)).c_str()); success = 0; break; } @@ -953,7 +953,7 @@ void TagEditor::LocateSong(const MPD::Song &s) // highlight our file for (size_t i = 0; i < Tags->Size(); ++i) { - if ((*Tags)[i].GetHash() == s.GetHash()) + if ((*Tags)[i].getHash() == s.getHash()) { Tags->Highlight(i); break; @@ -963,7 +963,7 @@ void TagEditor::LocateSong(const MPD::Song &s) void TagEditor::ReadTags(MPD::Song &s) { - TagLib::FileRef f(s.GetFile().c_str()); + TagLib::FileRef f(s.getURI().c_str()); if (f.isNull()) return; @@ -1001,20 +1001,20 @@ void TagEditor::WriteXiphComments(const MPD::Song &s, TagLib::Ogg::XiphComment * { TagLib::StringList list; - tag->addField("DISCNUMBER", ToWString(s.GetDisc())); // disc + tag->addField("DISCNUMBER", ToWString(s.getDisc())); // disc tag->removeField("ALBUM ARTIST"); // album artist - GetTagList(list, s, &MPD::Song::GetAlbumArtist); + GetTagList(list, s, &MPD::Song::getAlbumArtist); for (TagLib::StringList::ConstIterator it = list.begin(); it != list.end(); ++it) tag->addField("ALBUM ARTIST", *it, 0); tag->removeField("COMPOSER"); // composer - GetTagList(list, s, &MPD::Song::GetComposer); + GetTagList(list, s, &MPD::Song::getComposer); for (TagLib::StringList::ConstIterator it = list.begin(); it != list.end(); ++it) tag->addField("COMPOSER", *it, 0); tag->removeField("PERFORMER"); // performer - GetTagList(list, s, &MPD::Song::GetPerformer); + GetTagList(list, s, &MPD::Song::getPerformer); for (TagLib::StringList::ConstIterator it = list.begin(); it != list.end(); ++it) tag->addField("PERFORMER", *it, 0); } @@ -1022,40 +1022,40 @@ void TagEditor::WriteXiphComments(const MPD::Song &s, TagLib::Ogg::XiphComment * bool TagEditor::WriteTags(MPD::Song &s) { std::string path_to_file; - bool file_is_from_db = s.isFromDB(); + bool file_is_from_db = s.isFromDatabase(); if (file_is_from_db) path_to_file += Config.mpd_music_dir; - path_to_file += s.GetFile(); + path_to_file += s.getURI(); TagLib::FileRef f(path_to_file.c_str()); if (!f.isNull()) { - f.tag()->setTitle(ToWString(s.GetTitle())); - f.tag()->setArtist(ToWString(s.GetArtist())); - f.tag()->setAlbum(ToWString(s.GetAlbum())); - f.tag()->setYear(StrToInt(s.GetDate())); - f.tag()->setTrack(StrToInt(s.GetTrack())); - f.tag()->setGenre(ToWString(s.GetGenre())); - f.tag()->setComment(ToWString(s.GetComment())); + f.tag()->setTitle(ToWString(s.getTitle())); + f.tag()->setArtist(ToWString(s.getArtist())); + f.tag()->setAlbum(ToWString(s.getAlbum())); + f.tag()->setYear(StrToInt(s.getDate())); + f.tag()->setTrack(StrToInt(s.getTrack())); + f.tag()->setGenre(ToWString(s.getGenre())); + f.tag()->setComment(ToWString(s.getComment())); if (TagLib::MPEG::File *mp3_file = dynamic_cast(f.file())) { TagLib::ID3v2::Tag *tag = mp3_file->ID3v2Tag(1); TagLib::StringList list; - WriteID3v2("TIT2", tag, ToWString(s.GetTitle())); // title - WriteID3v2("TPE1", tag, ToWString(s.GetArtist())); // artist - WriteID3v2("TALB", tag, ToWString(s.GetAlbum())); // album - WriteID3v2("TDRC", tag, ToWString(s.GetDate())); // date - WriteID3v2("TRCK", tag, ToWString(s.GetTrack())); // track - WriteID3v2("TCON", tag, ToWString(s.GetGenre())); // genre - WriteID3v2("TPOS", tag, ToWString(s.GetDisc())); // disc + WriteID3v2("TIT2", tag, ToWString(s.getTitle())); // title + WriteID3v2("TPE1", tag, ToWString(s.getArtist())); // artist + WriteID3v2("TALB", tag, ToWString(s.getAlbum())); // album + WriteID3v2("TDRC", tag, ToWString(s.getDate())); // date + WriteID3v2("TRCK", tag, ToWString(s.getTrack())); // track + WriteID3v2("TCON", tag, ToWString(s.getGenre())); // genre + WriteID3v2("TPOS", tag, ToWString(s.getDisc())); // disc - GetTagList(list, s, &MPD::Song::GetAlbumArtist); + GetTagList(list, s, &MPD::Song::getAlbumArtist); WriteID3v2("TPE2", tag, list); // album artist - GetTagList(list, s, &MPD::Song::GetComposer); + GetTagList(list, s, &MPD::Song::getComposer); WriteID3v2("TCOM", tag, list); // composer - GetTagList(list, s, &MPD::Song::GetPerformer); + GetTagList(list, s, &MPD::Song::getPerformer); // in >=mpd-0.16 treating TOPE frame as performer tag // was dropped in favor of TPE3/TPE4 frames, so we have // to write frame accurate to used mpd version @@ -1092,7 +1092,7 @@ bool TagEditor::WriteTags(MPD::Song &s) if (id >= 0) { s = myPlaylist->Items->Back(); - Mpd.Move(s.GetPosition(), pos); + Mpd.Move(s.getPosition(), pos); } Mpd.CommitCommandsList(); } @@ -1159,7 +1159,7 @@ std::string TagEditor::TagToString(const MPD::Song &s, void *data) if (i < 11) result = (s.*SongInfo::Tags[i].Get)(0); else if (i == 12) - result = s.GetNewName().empty() ? s.GetName() : s.GetName() + " -> " + s.GetNewName(); + result = s.GetNewName().empty() ? s.getName() : s.getName() + " -> " + s.GetNewName(); return result.empty() ? Config.empty_tag : result; } @@ -1234,7 +1234,7 @@ std::string TagEditor::ParseFilename(MPD::Song &s, std::string mask, bool previe std::ostringstream result; std::vector separators; std::vector< std::pair > tags; - std::string file = s.GetName().substr(0, s.GetName().rfind(".")); + std::string file = s.getName().substr(0, s.getName().rfind(".")); for (size_t i = mask.find("%"); i != std::string::npos; i = mask.find("%")) { diff --git a/src/tiny_tag_editor.cpp b/src/tiny_tag_editor.cpp index f2d62dfd..353d6e29 100644 --- a/src/tiny_tag_editor.cpp +++ b/src/tiny_tag_editor.cpp @@ -70,7 +70,7 @@ void TinyTagEditor::SwitchTo() { ShowMessage("Streams can't be edited"); } - else if (GetTags()) + else if (getTags()) { if (myLockedScreen) UpdateInactiveScreen(this); @@ -85,9 +85,9 @@ void TinyTagEditor::SwitchTo() else { std::string full_path; - if (itsEdited.isFromDB()) + if (itsEdited.isFromDatabase()) full_path += Config.mpd_music_dir; - full_path += itsEdited.GetFile(); + full_path += itsEdited.getURI(); std::string message = "Couldn't read file \""; message += Shorten(TO_WSTRING(full_path), COLS-message.length()-3); @@ -111,22 +111,22 @@ void TinyTagEditor::EnterPressed() { size_t pos = option-8; Statusbar() << fmtBold << SongInfo::Tags[pos].Name << ": " << fmtBoldEnd; - s.SetTags(SongInfo::Tags[pos].Set, Global::wFooter->GetString(s.GetTags(SongInfo::Tags[pos].Get))); + s.SetTags(SongInfo::Tags[pos].Set, Global::wFooter->GetString(s.getTags(SongInfo::Tags[pos].Get))); w->at(option).Clear(); w->at(option) << fmtBold << SongInfo::Tags[pos].Name << ':' << fmtBoldEnd << ' '; - ShowTag(w->at(option), s.GetTags(SongInfo::Tags[pos].Get)); + ShowTag(w->at(option), s.getTags(SongInfo::Tags[pos].Get)); } else if (option == 20) { Statusbar() << fmtBold << "Filename: " << fmtBoldEnd; - std::string filename = s.GetNewName().empty() ? s.GetName() : s.GetNewName(); + std::string filename = s.GetNewName().empty() ? s.getName() : s.GetNewName(); size_t dot = filename.rfind("."); std::string extension = filename.substr(dot); filename = filename.substr(0, dot); std::string new_name = Global::wFooter->GetString(filename); s.SetNewName(new_name + extension); w->at(option).Clear(); - w->at(option) << fmtBold << "Filename:" << fmtBoldEnd << ' ' << (s.GetNewName().empty() ? s.GetName() : s.GetNewName()); + w->at(option) << fmtBold << "Filename:" << fmtBoldEnd << ' ' << (s.GetNewName().empty() ? s.getName() : s.GetNewName()); } UnlockStatusbar(); @@ -136,7 +136,7 @@ void TinyTagEditor::EnterPressed() if (TagEditor::WriteTags(s)) { ShowMessage("Tags updated"); - if (s.isFromDB()) + if (s.isFromDatabase()) { Mpd.UpdateDirectory(locale_to_utf_cpy(s.GetDirectory())); if (myOldScreen == mySearcher) // songs from search engine are not updated automatically @@ -180,21 +180,21 @@ void TinyTagEditor::SetEdited(const MPD::Song &s) itsEdited = s; } -bool TinyTagEditor::GetTags() +bool TinyTagEditor::getTags() { MPD::Song &s = itsEdited; std::string path_to_file; - if (s.isFromDB()) + if (s.isFromDatabase()) path_to_file += Config.mpd_music_dir; - path_to_file += s.GetFile(); + path_to_file += s.getURI(); TagLib::FileRef f(path_to_file.c_str()); if (f.isNull()) return false; s.SetComment(f.tag()->comment().to8Bit(1)); - std::string ext = s.GetFile(); + std::string ext = s.getURI(); ext = ext.substr(ext.rfind(".")+1); ToLower(ext); @@ -222,11 +222,11 @@ bool TinyTagEditor::GetTags() w->Highlight(8); - w->at(0) << fmtBold << Config.color1 << "Song name: " << fmtBoldEnd << Config.color2 << s.GetName() << clEnd; + w->at(0) << fmtBold << Config.color1 << "Song name: " << fmtBoldEnd << Config.color2 << s.getName() << clEnd; w->at(1) << fmtBold << Config.color1 << "Location in DB: " << fmtBoldEnd << Config.color2; ShowTag(w->at(1), s.GetDirectory()); w->at(1) << clEnd; - w->at(3) << fmtBold << Config.color1 << "Length: " << fmtBoldEnd << Config.color2 << s.GetLength() << clEnd; + w->at(3) << fmtBold << Config.color1 << "Length: " << fmtBoldEnd << Config.color2 << s.getLength() << clEnd; w->at(4) << fmtBold << Config.color1 << "Bitrate: " << fmtBoldEnd << Config.color2 << f.audioProperties()->bitrate() << " kbps" << clEnd; w->at(5) << fmtBold << Config.color1 << "Sample rate: " << fmtBoldEnd << Config.color2 << f.audioProperties()->sampleRate() << " Hz" << clEnd; w->at(6) << fmtBold << Config.color1 << "Channels: " << fmtBoldEnd << Config.color2 << (f.audioProperties()->channels() == 1 ? "Mono" : "Stereo") << clDefault; @@ -235,10 +235,10 @@ bool TinyTagEditor::GetTags() for (const SongInfo::Metadata *m = SongInfo::Tags; m->Name; ++m, ++pos) { w->at(pos) << fmtBold << m->Name << ":" << fmtBoldEnd << ' '; - ShowTag(w->at(pos), s.GetTags(m->Get)); + ShowTag(w->at(pos), s.getTags(m->Get)); } - w->at(20) << fmtBold << "Filename:" << fmtBoldEnd << ' ' << s.GetName(); + w->at(20) << fmtBold << "Filename:" << fmtBoldEnd << ' ' << s.getName(); w->at(22) << "Save"; w->at(23) << "Cancel"; diff --git a/src/tiny_tag_editor.h b/src/tiny_tag_editor.h index 70edc873..1bc35fed 100644 --- a/src/tiny_tag_editor.h +++ b/src/tiny_tag_editor.h @@ -57,7 +57,7 @@ class TinyTagEditor : public Screen< Menu > virtual bool isLockable() { return true; } private: - bool GetTags(); + bool getTags(); MPD::Song itsEdited; static bool extendedTagsSupported(TagLib::File *); diff --git a/src/window.cpp b/src/window.cpp index 8c6f6ae4..4f31b959 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -732,7 +732,7 @@ size_t Window::GetStartY() const return starty; } -const std::string &Window::GetTitle() const +const std::string &Window::getTitle() const { return itsTitle; } diff --git a/src/window.h b/src/window.h index e12bd806..aa6779fc 100644 --- a/src/window.h +++ b/src/window.h @@ -242,7 +242,7 @@ namespace NCurses /// @return window's title /// - const std::string &GetTitle() const; + const std::string &getTitle() const; /// @return current window's color ///