diff --git a/include/Containers.h b/include/Containers.h index 171d5bf..b273cb7 100644 --- a/include/Containers.h +++ b/include/Containers.h @@ -53,8 +53,8 @@ class HashTable { HashTable ( HashTable && ) noexcept = default; HashTable &operator= ( HashTable && ) noexcept = default; - void ht_insert ( const std::string &key, trackPtr track ); - trackPtr ht_lookup ( const std::string &key ) const; + void ht_insert ( const std::string &key, Track* t ); + Track* ht_lookup ( const std::string &key ) const; bool ht_delete ( const std::string &key ); std::vector listAll () const; @@ -72,7 +72,7 @@ class HashTable { struct Entry { std::string key; uint64_t hash = 0; - trackPtr track; + Track* track; }; // helpers diff --git a/include/File.h b/include/File.h index f597280..22aaf6d 100644 --- a/include/File.h +++ b/include/File.h @@ -12,11 +12,9 @@ class File { public: Track importFile( const std::string& filePath ); void scanFolder( const std::string& folderPath, std::vector& tracks ); + void updateLibrary(); void readFileTag( Track& t ); TagLib::VariantMap importArtwork( Track& t ); - std::string parseFiletype( const std::string& path ); - void updateLibrary(); - uint64_t hashString( Track t ); private: std::string path_; diff --git a/include/PlayerLocal.h b/include/PlayerLocal.h index e375954..bbfd47d 100644 --- a/include/PlayerLocal.h +++ b/include/PlayerLocal.h @@ -9,6 +9,7 @@ class PlayerLocal : public Player { public: // Library Controls void loadFile ( Track track ) override; + void loadLibrary(); void scanLibrary() override; void updateLibrary() override; void editMetadata() override; @@ -30,4 +31,8 @@ class PlayerLocal : public Player { unsigned int currentTrack_; db db_; std::string musicFolder_ = "data/"; + + ht tracks_; + ht artists_; + ht albums_; }; diff --git a/src/Database.cpp b/src/Database.cpp index 16be66c..ac9c321 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -97,7 +97,7 @@ void db::fetchAll( std::vector& entries ) const { t.trackNr = sqlite3_column_int( stmt, 3 ) ? sqlite3_column_int( stmt, 3 ) : 0; t.filePath = sqlite3_column_text( stmt, 4 ) ? reinterpret_cast ( sqlite3_column_text( stmt, 4 )) : ""; t.length = sqlite3_column_int( stmt, 5 ) ? sqlite3_column_int ( stmt, 5 ) : 0; - t.artwork = sqlite3_column_text( stmt, 6 ) ? reinterpret_cast ( sqlite3_column_text( stmt, 6 )) : ""; + //t.artwork = ; t.genre = sqlite3_column_text( stmt, 7 ) ? reinterpret_cast ( sqlite3_column_text( stmt, 7 )) : ""; t.format = sqlite3_column_text( stmt, 8 ) ? reinterpret_cast ( sqlite3_column_text( stmt, 8 )) : ""; @@ -125,7 +125,7 @@ void db::fetchAll( std::map& dbEntries ) const { t.trackNr = sqlite3_column_int( stmt, 3 ) ? sqlite3_column_int( stmt, 3 ) : 0; t.filePath = sqlite3_column_text( stmt, 4 ) ? reinterpret_cast ( sqlite3_column_text( stmt, 4 )) : ""; t.length = sqlite3_column_int( stmt, 5 ) ? sqlite3_column_int ( stmt, 5 ) : 0; - t.artwork = sqlite3_column_text( stmt, 6 ) ? reinterpret_cast ( sqlite3_column_text( stmt, 6 )) : ""; + //t.artwork = sqlite3_column_text( stmt, 6 ) ? reinterpret_cast ( sqlite3_column_text( stmt, 6 )) : ""; t.genre = sqlite3_column_text( stmt, 7 ) ? reinterpret_cast ( sqlite3_column_text( stmt, 7 )) : ""; t.format = sqlite3_column_text( stmt, 8 ) ? reinterpret_cast ( sqlite3_column_text( stmt, 8 )) : ""; @@ -200,11 +200,11 @@ void db::addTrack( Track t) { sqlite3_bind_text( stmt, 1,t.artist.toCString(), -1, SQLITE_STATIC ); sqlite3_bind_text( stmt, 2,t.title.toCString(), -1, SQLITE_STATIC ); - sqlite3_bind_int( stmt, 3, )); + //sqlite3_bind_int( stmt, 3, )); sqlite3_bind_int( stmt, 4, t.trackNr ); sqlite3_bind_int( stmt, 5, t.length ); sqlite3_bind_text( stmt, 6,t.filePath.c_str(), -1, SQLITE_STATIC ); - sqlite3_bind_text( stmt, 7,t.artwork.c_str(), -1, SQLITE_STATIC ); + //sqlite3_bind_text( stmt, 7,t.artwork.c_str(), -1, SQLITE_STATIC ); sqlite3_bind_text( stmt, 8,t.genre.toCString(), -1, SQLITE_STATIC ); sqlite3_bind_text( stmt, 9, t.format.c_str(), -1, SQLITE_STATIC ); sqlite3_bind_int( stmt, 10, t.hash ); @@ -224,7 +224,7 @@ void db::addAlbum( Track t ) { int rc = sqlite3_prepare_v2( db_, sql, -1, &stmt, nullptr ); sqlite3_bind_text( stmt, 0, t.album.toCString(), -1, SQLITE_TRANSIENT ); - sqlite3_bind_int( stmt, 1, artistId, -1, SQLITE_TRANSIENT ); + //sqlite3_bind_int( stmt, 1, getArtistId( t.artist.toCString()), -1, SQLITE_TRANSIENT ); if ( rc != SQLITE_OK ) throw std::runtime_error( sqlite3_errmsg( db_ )); } diff --git a/src/HashTable.cpp b/src/HashTable.cpp index 167a58b..63471c0 100644 --- a/src/HashTable.cpp +++ b/src/HashTable.cpp @@ -108,7 +108,7 @@ std::ptrdiff_t ht::probe ( const std::string &key, uint64_t hash, bool insert ) #endif } // probe -void ht::ht_insert( const std::string& key, trackPtr track ) { +void ht::ht_insert( const std::string& key, Track* t ) { //double loadFactor = static_cast ( size_ ) / static_cast ( ctrl_.size()); if ( loadFactor_ > MAX_LOAD ) rehash( ctrl_.size() * 2 ); @@ -120,16 +120,16 @@ void ht::ht_insert( const std::string& key, trackPtr track ) { Entry tmp; tmp.key = key; tmp.hash = hash; - tmp.track = track; + tmp.track = t; entries_.at( idx ) = std::move( tmp ); ++size_; } else { - entries_.at( idx ).track = track; + entries_.at( idx ).track = t; } ctrl_.at( idx ) = fingerprint( hash ); } -trackPtr ht::ht_lookup( const std::string& key ) const { +Track* ht::ht_lookup( const std::string& key ) const { uint64_t hash = hashString( key ); auto idx = probe( key, hash, false ); if ( idx != -1 ) return entries_.at( static_cast ( idx )).track; diff --git a/src/PlayerLocal.cpp b/src/PlayerLocal.cpp index b5ae263..e96b7ba 100644 --- a/src/PlayerLocal.cpp +++ b/src/PlayerLocal.cpp @@ -4,6 +4,8 @@ #include "../include/Database.h" #include "../include/Containers.h" +#include + using db = Database; void Player::play () { PE_.startPlayback(); } @@ -55,3 +57,12 @@ void PlayerLocal::scanLibrary(){ db_.addTrack( t ); } } + +void PlayerLocal::loadLibrary() { + db_.fetchAll( library ); + for ( auto t : library ) { + tracks_.ht_insert(t.title.toCString(), &t ); + artists_.ht_insert( t.artist.toCString(), &t ); + albums_.ht_insert( t.album.toCString(), &t ); + } +}