diff options
author | haslersn <sebastian.hasler@gmx.net> | 2019-07-06 15:58:22 +0200 |
---|---|---|
committer | haslersn <sebastian.hasler@gmx.net> | 2019-07-08 00:39:02 +0200 |
commit | 2777ca1413361bbc78f22b16ec1e62e30a119a7c (patch) | |
tree | ae455034ec6031d3549959efa06d24aa7bd4b521 | |
parent | 4cbbd95eff4488d0f509ac40ae6568ff85b3e120 (diff) |
database: Outsource {music, perfdata}_db_path() to namespace djinterop::enginelibrary
-rw-r--r-- | include/djinterop/database.hpp | 6 | ||||
-rw-r--r-- | include/djinterop/enginelibrary.hpp | 14 | ||||
-rw-r--r-- | src/djinterop/database.cpp | 10 | ||||
-rw-r--r-- | src/djinterop/enginelibrary.cpp | 16 | ||||
-rw-r--r-- | src/djinterop/enginelibrary/el_database_impl.cpp | 10 | ||||
-rw-r--r-- | src/djinterop/enginelibrary/el_database_impl.hpp | 2 | ||||
-rw-r--r-- | src/djinterop/enginelibrary/el_storage.hpp | 8 | ||||
-rw-r--r-- | src/djinterop/impl/database_impl.hpp | 2 | ||||
-rw-r--r-- | test/enginelibrary/crate_test.cpp | 4 | ||||
-rw-r--r-- | test/enginelibrary/database_test.cpp | 12 |
10 files changed, 37 insertions, 47 deletions
diff --git a/include/djinterop/database.hpp b/include/djinterop/database.hpp index f6b321d..3a93762 100644 --- a/include/djinterop/database.hpp +++ b/include/djinterop/database.hpp @@ -90,12 +90,6 @@ public: /// `libdjinterop` or not bool is_supported() const; - /// Returns the path to the music database, i.e. m.db - std::string music_db_path() const; - - /// Returns the path to the performance data database, i.e. p.db - std::string perfdata_db_path() const; - /// Returns the UUID of the database std::string uuid() const; diff --git a/include/djinterop/enginelibrary.hpp b/include/djinterop/enginelibrary.hpp index 0549560..5a957cf 100644 --- a/include/djinterop/enginelibrary.hpp +++ b/include/djinterop/enginelibrary.hpp @@ -27,6 +27,13 @@ database make_database( std::string directory, const semantic_version& default_version = version_latest); +/// Given an enginelibrary database, returns the path to its m.db sqlite +/// database file +/// +/// If the given database is not an enginelibrary, then the behaviour of this +/// function is undefined. +std::string music_db_path(const database& db); + /// Normalizes a beat-grid, so that the beat indexes are in the form normally /// expected by Engine Prime. /// @@ -38,5 +45,12 @@ database make_database( std::vector<beatgrid_marker> normalize_beatgrid( std::vector<beatgrid_marker> beatgrid, int64_t sample_count); +/// Given an enginelibrary database, returns the path to its p.db sqlite +/// database file +/// +/// If the given database is not an enginelibrary, then the behaviour of this +/// function is undefined. +std::string perfdata_db_path(const database& db); + } // namespace enginelibrary } // namespace djinterop diff --git a/src/djinterop/database.cpp b/src/djinterop/database.cpp index 4643293..9c072f1 100644 --- a/src/djinterop/database.cpp +++ b/src/djinterop/database.cpp @@ -71,16 +71,6 @@ void database::verify() const pimpl_->verify(); } -std::string database::music_db_path() const -{ - return pimpl_->music_db_path(); -} - -std::string database::perfdata_db_path() const -{ - return pimpl_->perfdata_db_path(); -} - void database::remove_crate(crate cr) const { pimpl_->remove_crate(cr); diff --git a/src/djinterop/enginelibrary.cpp b/src/djinterop/enginelibrary.cpp index 41a6b91..373344d 100644 --- a/src/djinterop/enginelibrary.cpp +++ b/src/djinterop/enginelibrary.cpp @@ -19,7 +19,7 @@ database load_database(std::string directory) } database make_database( - std::string directory, const semantic_version &default_version) + std::string directory, const semantic_version& default_version) { if (!is_supported(default_version)) { @@ -70,6 +70,11 @@ database make_database( return load_database(std::move(directory)); } +std::string music_db_path(const database& db) +{ + return db.directory() + "/m.db"; +} + std::vector<beatgrid_marker> normalize_beatgrid( std::vector<beatgrid_marker> beatgrid, int64_t sample_count) { @@ -81,7 +86,7 @@ std::vector<beatgrid_marker> normalize_beatgrid( { auto last_marker_iter = std::find_if( beatgrid.begin(), beatgrid.end(), - [sample_count](const beatgrid_marker &marker) { + [sample_count](const beatgrid_marker& marker) { return marker.sample_offset > sample_count; }); if (last_marker_iter != beatgrid.end()) @@ -93,7 +98,7 @@ std::vector<beatgrid_marker> normalize_beatgrid( { auto after_first_marker_iter = std::find_if( beatgrid.begin(), beatgrid.end(), - [](const beatgrid_marker &marker) { + [](const beatgrid_marker& marker) { return marker.sample_offset > 0; }); if (after_first_marker_iter != beatgrid.begin()) @@ -130,5 +135,10 @@ std::vector<beatgrid_marker> normalize_beatgrid( return beatgrid; // Named RVO } +std::string perfdata_db_path(const database& db) +{ + return db.directory() + "/p.db"; +} + } // namespace enginelibrary } // namespace djinterop diff --git a/src/djinterop/enginelibrary/el_database_impl.cpp b/src/djinterop/enginelibrary/el_database_impl.cpp index 50e7690..8dfb6d7 100644 --- a/src/djinterop/enginelibrary/el_database_impl.cpp +++ b/src/djinterop/enginelibrary/el_database_impl.cpp @@ -187,16 +187,6 @@ void el_database_impl::verify() verify_performance_schema(storage_->perfdata_db); } -std::string el_database_impl::music_db_path() -{ - return storage_->music_db_path; -} - -std::string el_database_impl::perfdata_db_path() -{ - return storage_->perfdata_db_path; -} - void el_database_impl::remove_crate(crate cr) { storage_->music_db << "DELETE FROM Crate WHERE id = ?" << cr.id(); diff --git a/src/djinterop/enginelibrary/el_database_impl.hpp b/src/djinterop/enginelibrary/el_database_impl.hpp index 0ab4f71..fa6ca7a 100644 --- a/src/djinterop/enginelibrary/el_database_impl.hpp +++ b/src/djinterop/enginelibrary/el_database_impl.hpp @@ -46,8 +46,6 @@ public: std::string directory() override; bool is_supported() override; void verify() override; - std::string music_db_path() override; - std::string perfdata_db_path() override; void remove_crate(djinterop::crate cr) override; void remove_track(djinterop::track tr) override; std::vector<djinterop::crate> root_crates() override; diff --git a/src/djinterop/enginelibrary/el_storage.hpp b/src/djinterop/enginelibrary/el_storage.hpp index 14667ec..ca828ed 100644 --- a/src/djinterop/enginelibrary/el_storage.hpp +++ b/src/djinterop/enginelibrary/el_storage.hpp @@ -13,17 +13,13 @@ class el_storage public: el_storage(std::string directory) : directory{directory}, - music_db_path{directory + "/m.db"}, - perfdata_db_path{directory + "/p.db"}, - music_db{music_db_path}, - perfdata_db{perfdata_db_path} + music_db{directory + "/m.db"}, + perfdata_db{directory + "/p.db"} { // TODO (haslersn): Should we check that directory is an absolute path? } std::string directory; - std::string music_db_path; - std::string perfdata_db_path; sqlite::database music_db; sqlite::database perfdata_db; }; diff --git a/src/djinterop/impl/database_impl.hpp b/src/djinterop/impl/database_impl.hpp index e7c197c..79faac6 100644 --- a/src/djinterop/impl/database_impl.hpp +++ b/src/djinterop/impl/database_impl.hpp @@ -24,8 +24,6 @@ public: virtual std::string directory() = 0; virtual bool is_supported() = 0; virtual void verify() = 0; - virtual std::string music_db_path() = 0; - virtual std::string perfdata_db_path() = 0; virtual void remove_crate(crate cr) = 0; virtual void remove_track(track tr) = 0; virtual std::vector<crate> root_crates() = 0; diff --git a/test/enginelibrary/crate_test.cpp b/test/enginelibrary/crate_test.cpp index c4076d9..fc58b37 100644 --- a/test/enginelibrary/crate_test.cpp +++ b/test/enginelibrary/crate_test.cpp @@ -59,8 +59,8 @@ static void remove_temp_dir(const fs::path &temp_dir) static void copy_test_db_to_temp_dir(const fs::path &temp_dir) { auto db = el::load_database(sample_path); - fs::path music_db_path{db.music_db_path()}; - fs::path perfdata_db_path{db.perfdata_db_path()}; + fs::path music_db_path{el::music_db_path(db)}; + fs::path perfdata_db_path{el::perfdata_db_path(db)}; fs::copy_file(music_db_path, temp_dir / music_db_path.filename()); fs::copy_file(perfdata_db_path, temp_dir / perfdata_db_path.filename()); } diff --git a/test/enginelibrary/database_test.cpp b/test/enginelibrary/database_test.cpp index e563b8c..b4bcc64 100644 --- a/test/enginelibrary/database_test.cpp +++ b/test/enginelibrary/database_test.cpp @@ -93,8 +93,8 @@ BOOST_AUTO_TEST_CASE(information__valid_db__expected) // Assert BOOST_CHECK_EQUAL(db.directory(), sample_path); - BOOST_CHECK_EQUAL(db.music_db_path(), sample_path + "/m.db"); - BOOST_CHECK_EQUAL(db.perfdata_db_path(), sample_path + "/p.db"); + BOOST_CHECK_EQUAL(el::music_db_path(db), sample_path + "/m.db"); + BOOST_CHECK_EQUAL(el::perfdata_db_path(db), sample_path + "/p.db"); BOOST_CHECK_EQUAL(db.uuid(), "e535b170-26ef-4f30-8cb2-5b9fa4c2a27f"); BOOST_CHECK_EQUAL(db.version(), el::version_1_6_0); @@ -112,8 +112,8 @@ BOOST_AUTO_TEST_CASE(make_database__version_1_6_0__creates_verified) BOOST_CHECK_NO_THROW(db.verify()); BOOST_CHECK_EQUAL(db.is_supported(), true); BOOST_CHECK_EQUAL(db.directory(), temp_dir.string()); - BOOST_CHECK_EQUAL(db.music_db_path(), (temp_dir / "m.db").string()); - BOOST_CHECK_EQUAL(db.perfdata_db_path(), (temp_dir / "p.db").string()); + BOOST_CHECK_EQUAL(el::music_db_path(db), (temp_dir / "m.db").string()); + BOOST_CHECK_EQUAL(el::perfdata_db_path(db), (temp_dir / "p.db").string()); BOOST_CHECK_EQUAL(db.version(), el::version_1_6_0); db.verify(); fs::remove_all(temp_dir); @@ -131,8 +131,8 @@ BOOST_AUTO_TEST_CASE(make_database__version_1_7_1__creates_verified) BOOST_CHECK_NO_THROW(db.verify()); BOOST_CHECK_EQUAL(db.is_supported(), true); BOOST_CHECK_EQUAL(db.directory(), temp_dir.string()); - BOOST_CHECK_EQUAL(db.music_db_path(), (temp_dir / "m.db").string()); - BOOST_CHECK_EQUAL(db.perfdata_db_path(), (temp_dir / "p.db").string()); + BOOST_CHECK_EQUAL(el::music_db_path(db), (temp_dir / "m.db").string()); + BOOST_CHECK_EQUAL(el::perfdata_db_path(db), (temp_dir / "p.db").string()); BOOST_CHECK_EQUAL(db.version(), el::version_1_7_1); db.verify(); fs::remove_all(temp_dir); |