compare hashes instead of filenames

This commit is contained in:
unknown
2008-08-09 03:31:25 +02:00
parent f7abc08c16
commit 828ec8e2f6
7 changed files with 45 additions and 51 deletions

View File

@@ -47,12 +47,6 @@ CPPFLAGS="$CPPFLAGS $libmpd_CFLAGS"
LDFLAGS="$LDFLAGS $libmpd_LIBS" LDFLAGS="$LDFLAGS $libmpd_LIBS"
AC_CHECK_HEADERS([libmpd/libmpd.h], , AC_MSG_ERROR([missing libmpd.h header])) 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 =======================
dnl = checking for taglib = dnl = checking for taglib =
dnl ======================= dnl =======================

View File

@@ -37,6 +37,7 @@ extern Window *wFooter;
extern vector<Song> vPlaylist; extern vector<Song> vPlaylist;
extern vector<MpdDataType> vFileType; extern vector<MpdDataType> vFileType;
extern vector<string> vNameList; extern vector<string> vNameList;
extern vector<long long> vHashList;
extern CurrScreen current_screen; extern CurrScreen current_screen;
@@ -63,33 +64,6 @@ extern string UNKNOWN_ARTIST;
extern string UNKNOWN_TITLE; extern string UNKNOWN_TITLE;
extern string UNKNOWN_ALBUM; 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) bool SortSongsByTrack(const Song &a, const Song &b)
{ {
return StrToInt(a.GetTrack()) < StrToInt(b.GetTrack()); return StrToInt(a.GetTrack()) < StrToInt(b.GetTrack());
@@ -539,12 +513,14 @@ void GetDirectory(string dir)
browsed_dir = dir; browsed_dir = dir;
vFileType.clear(); vFileType.clear();
vNameList.clear(); vNameList.clear();
mBrowser->Clear(current_screen != csLibrary); vHashList.clear();
mBrowser->Clear(0);
if (dir != "/") if (dir != "/")
{ {
mBrowser->AddOption("[..]"); mBrowser->AddOption("[..]");
vFileType.push_back(MPD_DATA_TYPE_DIRECTORY); vFileType.push_back(MPD_DATA_TYPE_DIRECTORY);
vNameList.push_back(""); vNameList.push_back("");
vHashList.push_back(0);
} }
browser = mpd_database_get_directory(conn, (char *)dir.c_str()); browser = mpd_database_get_directory(conn, (char *)dir.c_str());
FOR_EACH_MPD_DATA(browser) FOR_EACH_MPD_DATA(browser)
@@ -555,6 +531,7 @@ void GetDirectory(string dir)
{ {
vFileType.push_back(MPD_DATA_TYPE_PLAYLIST); vFileType.push_back(MPD_DATA_TYPE_PLAYLIST);
vNameList.push_back(browser->playlist); vNameList.push_back(browser->playlist);
vHashList.push_back(0);
mBrowser->AddOption("[red](playlist)[/red] " + string(browser->playlist)); mBrowser->AddOption("[red](playlist)[/red] " + string(browser->playlist));
break; break;
} }
@@ -562,6 +539,7 @@ void GetDirectory(string dir)
{ {
string subdir = browser->directory; string subdir = browser->directory;
vFileType.push_back(MPD_DATA_TYPE_DIRECTORY); vFileType.push_back(MPD_DATA_TYPE_DIRECTORY);
vHashList.push_back(0);
if (dir == "/") if (dir == "/")
vNameList.push_back(subdir.substr(browsed_dir.size()-1,subdir.size()-browsed_dir.size()+1)); vNameList.push_back(subdir.substr(browsed_dir.size()-1,subdir.size()-browsed_dir.size()+1));
else else
@@ -577,15 +555,25 @@ void GetDirectory(string dir)
vFileType.push_back(MPD_DATA_TYPE_SONG); vFileType.push_back(MPD_DATA_TYPE_SONG);
Song s = browser->song; Song s = browser->song;
vNameList.push_back(s.GetFile()); 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; break;
} }
} }
} }
pthread_create(&bolder, NULL, BoldSongsFromPlaylist, NULL);
mpd_data_free(browser); mpd_data_free(browser);
browsed_subdir.clear(); browsed_subdir.clear();
if (current_screen != csLibrary && current_screen == csBrowser)
mBrowser->Hide();
} }

View File

@@ -23,15 +23,12 @@
#include <algorithm> #include <algorithm>
#include <pthread.h>
#include "ncmpcpp.h" #include "ncmpcpp.h"
#include "settings.h" #include "settings.h"
#include "song.h" #include "song.h"
extern ncmpcpp_config Config; extern ncmpcpp_config Config;
void * BoldSongsFromPlaylist(void *);
bool SortSongsByTrack(const Song &, const Song &); bool SortSongsByTrack(const Song &, const Song &);
bool CaseInsensitiveComparison(string, string); bool CaseInsensitiveComparison(string, string);
void WindowTitle(const string &); void WindowTitle(const string &);

View File

@@ -59,6 +59,7 @@ vector<Song> vPlaylist;
vector<Song> vSearched; vector<Song> vSearched;
vector<MpdDataType> vFileType; vector<MpdDataType> vFileType;
vector<string> vNameList; vector<string> vNameList;
vector<long long> vHashList;
vector<string> vArtists; vector<string> vArtists;
vector<Song> vSongs; 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++) for (vector<Song>::const_iterator j = vPlaylist.begin(); j != vPlaylist.end(); j++)
{ {
if (it->GetFile() == j->GetFile()) if (it->GetHash() == j->GetHash())
{ {
bold = 1; bold = 1;
break; 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 it = vSearched.begin(); it != vSearched.end(); it++)
{ {
for (vector<Song>::const_iterator j = vPlaylist.begin(); j != vPlaylist.end(); j++) for (vector<Song>::const_iterator j = vPlaylist.begin(); j != vPlaylist.end(); j++)
if (j->GetFile() == it->GetFile()) {
if (j->GetHash() == it->GetHash())
{
bold = 1; bold = 1;
if (bold) break;
mSearcher->AddBoldOption(DisplaySong(*it)); }
else }
mSearcher->AddOption(DisplaySong(*it)); bold ? mSearcher->AddBoldOption(DisplaySong(*it)) : mSearcher->AddOption(DisplaySong(*it));
bold = 0; bold = 0;
} }

View File

@@ -36,7 +36,8 @@ void DefineEmptyTags()
UNKNOWN_ALBUM = "[" + et_col + "]<no album>[/" + et_col + "]"; 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)), itsSecondsLength((s->time-itsMinutesLength*60)),
itsPosition(s->pos), itsPosition(s->pos),
itsID(s->id), itsID(s->id),
@@ -67,6 +68,14 @@ Song::Song(mpd_Song *s) : itsMinutesLength(s->time/60),
itsDirectory = "/"; itsDirectory = "/";
itsShortName = itsFile; 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 string Song::GetLength() const

View File

@@ -37,7 +37,7 @@ void DefineEmptyTags();
class Song class Song
{ {
public: 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(mpd_Song *);
~Song() {}; ~Song() {};
@@ -56,6 +56,7 @@ class Song
//string GetDisc() const { return itsDisc; } //string GetDisc() const { return itsDisc; }
string GetComment() const; string GetComment() const;
string GetLength() const; string GetLength() const;
long long GetHash() const { return itsHash; }
int GetTotalLength() const { return itsMinutesLength*60+itsSecondsLength; } int GetTotalLength() const { return itsMinutesLength*60+itsSecondsLength; }
int GetMinutesLength() const { return itsMinutesLength; } int GetMinutesLength() const { return itsMinutesLength; }
int GetSecondsLength() const { return itsSecondsLength; } int GetSecondsLength() const { return itsSecondsLength; }
@@ -91,6 +92,7 @@ class Song
//string itsPerformer; //string itsPerformer;
//string itsDisc; //string itsDisc;
string itsComment; string itsComment;
long long itsHash;
int itsMinutesLength; int itsMinutesLength;
int itsSecondsLength; int itsSecondsLength;
int itsPosition; int itsPosition;

View File

@@ -43,6 +43,7 @@ extern vector<Song> vPlaylist;
extern vector<Song> vSearched; extern vector<Song> vSearched;
extern vector<MpdDataType> vFileType; extern vector<MpdDataType> vFileType;
extern vector<string> vNameList; extern vector<string> vNameList;
extern vector<long long> vHashList;
extern time_t block_delay; extern time_t block_delay;
extern time_t timer; 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++) for (vector<Song>::const_iterator it = vPlaylist.begin(); it != vPlaylist.end(); it++)
{ {
if (it->GetFile() == vNameList[i]) if (it->GetHash() == vHashList[i])
{ {
bold = 1; bold = 1;
break; break;
@@ -229,7 +230,7 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
{ {
for (vector<Song>::const_iterator j = vPlaylist.begin(); j != vPlaylist.end(); j++) for (vector<Song>::const_iterator j = vPlaylist.begin(); j != vPlaylist.end(); j++)
{ {
if (j->GetFile() == it->GetFile()) if (j->GetHash() == it->GetHash())
{ {
bold = 1; bold = 1;
break; break;