compare hashes instead of filenames
This commit is contained in:
@@ -47,12 +47,6 @@ CPPFLAGS="$CPPFLAGS $libmpd_CFLAGS"
|
||||
LDFLAGS="$LDFLAGS $libmpd_LIBS"
|
||||
AC_CHECK_HEADERS([libmpd/libmpd.h], , AC_MSG_ERROR([missing libmpd.h header]))
|
||||
|
||||
dnl ========================
|
||||
dnl = checking for pthread =
|
||||
dnl ========================
|
||||
AC_CHECK_LIB(pthread, pthread_create, LDFLAGS="$LDFLAGS -pthread", AC_MSG_ERROR([missing pthread library]))
|
||||
AC_CHECK_HEADERS([pthread.h], , AC_MSG_ERROR([missing pthread.h header]))
|
||||
|
||||
dnl =======================
|
||||
dnl = checking for taglib =
|
||||
dnl =======================
|
||||
|
||||
@@ -37,6 +37,7 @@ extern Window *wFooter;
|
||||
extern vector<Song> vPlaylist;
|
||||
extern vector<MpdDataType> vFileType;
|
||||
extern vector<string> vNameList;
|
||||
extern vector<long long> vHashList;
|
||||
|
||||
extern CurrScreen current_screen;
|
||||
|
||||
@@ -63,33 +64,6 @@ extern string UNKNOWN_ARTIST;
|
||||
extern string UNKNOWN_TITLE;
|
||||
extern string UNKNOWN_ALBUM;
|
||||
|
||||
void * BoldSongsFromPlaylist(void *t)
|
||||
{
|
||||
if (!vNameList.empty())
|
||||
{
|
||||
bool bold = 0;
|
||||
for (int i = 0; i < vFileType.size(); i++)
|
||||
{
|
||||
if (vFileType[i] == MPD_DATA_TYPE_SONG)
|
||||
{
|
||||
for (vector<Song>::const_iterator it = vPlaylist.begin(); it != vPlaylist.end(); it++)
|
||||
{
|
||||
if (it->GetFile() == vNameList[i])
|
||||
{
|
||||
bold = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
mBrowser->BoldOption(i+1, bold);
|
||||
bold = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (current_screen == csBrowser)
|
||||
mBrowser->Refresh();
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
bool SortSongsByTrack(const Song &a, const Song &b)
|
||||
{
|
||||
return StrToInt(a.GetTrack()) < StrToInt(b.GetTrack());
|
||||
@@ -539,12 +513,14 @@ void GetDirectory(string dir)
|
||||
browsed_dir = dir;
|
||||
vFileType.clear();
|
||||
vNameList.clear();
|
||||
mBrowser->Clear(current_screen != csLibrary);
|
||||
vHashList.clear();
|
||||
mBrowser->Clear(0);
|
||||
if (dir != "/")
|
||||
{
|
||||
mBrowser->AddOption("[..]");
|
||||
vFileType.push_back(MPD_DATA_TYPE_DIRECTORY);
|
||||
vNameList.push_back("");
|
||||
vHashList.push_back(0);
|
||||
}
|
||||
browser = mpd_database_get_directory(conn, (char *)dir.c_str());
|
||||
FOR_EACH_MPD_DATA(browser)
|
||||
@@ -555,6 +531,7 @@ void GetDirectory(string dir)
|
||||
{
|
||||
vFileType.push_back(MPD_DATA_TYPE_PLAYLIST);
|
||||
vNameList.push_back(browser->playlist);
|
||||
vHashList.push_back(0);
|
||||
mBrowser->AddOption("[red](playlist)[/red] " + string(browser->playlist));
|
||||
break;
|
||||
}
|
||||
@@ -562,6 +539,7 @@ void GetDirectory(string dir)
|
||||
{
|
||||
string subdir = browser->directory;
|
||||
vFileType.push_back(MPD_DATA_TYPE_DIRECTORY);
|
||||
vHashList.push_back(0);
|
||||
if (dir == "/")
|
||||
vNameList.push_back(subdir.substr(browsed_dir.size()-1,subdir.size()-browsed_dir.size()+1));
|
||||
else
|
||||
@@ -577,15 +555,25 @@ void GetDirectory(string dir)
|
||||
vFileType.push_back(MPD_DATA_TYPE_SONG);
|
||||
Song s = browser->song;
|
||||
vNameList.push_back(s.GetFile());
|
||||
mBrowser->AddOption(DisplaySong(s));
|
||||
vHashList.push_back(s.GetHash());
|
||||
bool bold = 0;
|
||||
for (vector<Song>::const_iterator it = vPlaylist.begin(); it != vPlaylist.end(); it++)
|
||||
{
|
||||
if (it->GetHash() == s.GetHash())
|
||||
{
|
||||
bold = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
bold ? mBrowser->AddBoldOption(DisplaySong(s)) : mBrowser->AddOption(DisplaySong(s));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pthread_create(&bolder, NULL, BoldSongsFromPlaylist, NULL);
|
||||
|
||||
mpd_data_free(browser);
|
||||
browsed_subdir.clear();
|
||||
|
||||
if (current_screen != csLibrary && current_screen == csBrowser)
|
||||
mBrowser->Hide();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,15 +23,12 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include "ncmpcpp.h"
|
||||
#include "settings.h"
|
||||
#include "song.h"
|
||||
|
||||
extern ncmpcpp_config Config;
|
||||
|
||||
void * BoldSongsFromPlaylist(void *);
|
||||
bool SortSongsByTrack(const Song &, const Song &);
|
||||
bool CaseInsensitiveComparison(string, string);
|
||||
void WindowTitle(const string &);
|
||||
|
||||
@@ -59,6 +59,7 @@ vector<Song> vPlaylist;
|
||||
vector<Song> vSearched;
|
||||
vector<MpdDataType> vFileType;
|
||||
vector<string> vNameList;
|
||||
vector<long long> vHashList;
|
||||
|
||||
vector<string> vArtists;
|
||||
vector<Song> vSongs;
|
||||
@@ -397,7 +398,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
for (vector<Song>::const_iterator j = vPlaylist.begin(); j != vPlaylist.end(); j++)
|
||||
{
|
||||
if (it->GetFile() == j->GetFile())
|
||||
if (it->GetHash() == j->GetHash())
|
||||
{
|
||||
bold = 1;
|
||||
break;
|
||||
@@ -866,12 +867,14 @@ int main(int argc, char *argv[])
|
||||
for (vector<Song>::const_iterator it = vSearched.begin(); it != vSearched.end(); it++)
|
||||
{
|
||||
for (vector<Song>::const_iterator j = vPlaylist.begin(); j != vPlaylist.end(); j++)
|
||||
if (j->GetFile() == it->GetFile())
|
||||
{
|
||||
if (j->GetHash() == it->GetHash())
|
||||
{
|
||||
bold = 1;
|
||||
if (bold)
|
||||
mSearcher->AddBoldOption(DisplaySong(*it));
|
||||
else
|
||||
mSearcher->AddOption(DisplaySong(*it));
|
||||
break;
|
||||
}
|
||||
}
|
||||
bold ? mSearcher->AddBoldOption(DisplaySong(*it)) : mSearcher->AddOption(DisplaySong(*it));
|
||||
bold = 0;
|
||||
}
|
||||
|
||||
|
||||
11
src/song.cpp
11
src/song.cpp
@@ -36,7 +36,8 @@ void DefineEmptyTags()
|
||||
UNKNOWN_ALBUM = "[" + et_col + "]<no album>[/" + et_col + "]";
|
||||
}
|
||||
|
||||
Song::Song(mpd_Song *s) : itsMinutesLength(s->time/60),
|
||||
Song::Song(mpd_Song *s) : itsHash(0),
|
||||
itsMinutesLength(s->time/60),
|
||||
itsSecondsLength((s->time-itsMinutesLength*60)),
|
||||
itsPosition(s->pos),
|
||||
itsID(s->id),
|
||||
@@ -67,6 +68,14 @@ Song::Song(mpd_Song *s) : itsMinutesLength(s->time/60),
|
||||
itsDirectory = "/";
|
||||
itsShortName = itsFile;
|
||||
}
|
||||
// generate pseudo-hash
|
||||
i = 0;
|
||||
for (string::const_iterator it = itsFile.begin(); it != itsFile.end(); it++, i++)
|
||||
{
|
||||
itsHash += *it;
|
||||
if (i%2)
|
||||
itsHash *= *it;
|
||||
}
|
||||
}
|
||||
|
||||
string Song::GetLength() const
|
||||
|
||||
@@ -37,7 +37,7 @@ void DefineEmptyTags();
|
||||
class Song
|
||||
{
|
||||
public:
|
||||
Song() : itsMinutesLength(0), itsSecondsLength(0), itsPosition(0), itsID(0), itsGetEmptyFields(0) { }
|
||||
Song() : itsHash(0), itsMinutesLength(0), itsSecondsLength(0), itsPosition(0), itsID(0), itsGetEmptyFields(0) { }
|
||||
Song(mpd_Song *);
|
||||
~Song() {};
|
||||
|
||||
@@ -56,6 +56,7 @@ class Song
|
||||
//string GetDisc() const { return itsDisc; }
|
||||
string GetComment() const;
|
||||
string GetLength() const;
|
||||
long long GetHash() const { return itsHash; }
|
||||
int GetTotalLength() const { return itsMinutesLength*60+itsSecondsLength; }
|
||||
int GetMinutesLength() const { return itsMinutesLength; }
|
||||
int GetSecondsLength() const { return itsSecondsLength; }
|
||||
@@ -91,6 +92,7 @@ class Song
|
||||
//string itsPerformer;
|
||||
//string itsDisc;
|
||||
string itsComment;
|
||||
long long itsHash;
|
||||
int itsMinutesLength;
|
||||
int itsSecondsLength;
|
||||
int itsPosition;
|
||||
|
||||
@@ -43,6 +43,7 @@ extern vector<Song> vPlaylist;
|
||||
extern vector<Song> vSearched;
|
||||
extern vector<MpdDataType> vFileType;
|
||||
extern vector<string> vNameList;
|
||||
extern vector<long long> vHashList;
|
||||
|
||||
extern time_t block_delay;
|
||||
extern time_t timer;
|
||||
@@ -210,7 +211,7 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
|
||||
{
|
||||
for (vector<Song>::const_iterator it = vPlaylist.begin(); it != vPlaylist.end(); it++)
|
||||
{
|
||||
if (it->GetFile() == vNameList[i])
|
||||
if (it->GetHash() == vHashList[i])
|
||||
{
|
||||
bold = 1;
|
||||
break;
|
||||
@@ -229,7 +230,7 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
|
||||
{
|
||||
for (vector<Song>::const_iterator j = vPlaylist.begin(); j != vPlaylist.end(); j++)
|
||||
{
|
||||
if (j->GetFile() == it->GetFile())
|
||||
if (j->GetHash() == it->GetHash())
|
||||
{
|
||||
bold = 1;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user