From 010a798fe53a5d80cdb320436d96f99a02f35d9c Mon Sep 17 00:00:00 2001 From: apoorv569 Date: Mon, 24 Jan 2022 02:39:57 +0530 Subject: [PATCH] More encapsulation, lots of reformatting and cleanup. --- meson.build | 3 +- src/App.cpp | 18 +- src/App.hpp | 12 +- src/Database/Database.cpp | 322 +-- src/Database/Database.hpp | 10 +- src/GUI/Dialogs/Settings.cpp | 425 ++-- src/GUI/Dialogs/Settings.hpp | 169 +- src/GUI/Dialogs/TagEditor.cpp | 242 +- src/GUI/Dialogs/TagEditor.hpp | 99 +- src/GUI/DirectoryBrowser.cpp | 52 +- src/GUI/DirectoryBrowser.hpp | 23 + src/GUI/Hives.cpp | 278 +-- src/GUI/Hives.hpp | 31 +- src/GUI/InfoBar.cpp | 20 + src/GUI/InfoBar.hpp | 20 + src/GUI/Library.cpp | 30 +- src/GUI/Library.hpp | 33 +- src/GUI/ListCtrl.cpp | 499 ++--- src/GUI/ListCtrl.hpp | 52 +- src/GUI/MainFrame.cpp | 2740 +++-------------------- src/GUI/MainFrame.hpp | 293 +-- src/GUI/Notebook.cpp | 24 +- src/GUI/Notebook.hpp | 24 +- src/GUI/SearchBar.cpp | 48 +- src/GUI/SearchBar.hpp | 24 +- src/GUI/TransportControls.cpp | 157 +- src/GUI/TransportControls.hpp | 28 +- src/GUI/Trash.cpp | 115 +- src/GUI/Trash.hpp | 26 +- src/GUI/WaveformViewer.cpp | 83 +- src/GUI/WaveformViewer.hpp | 14 +- src/Utility/ControlIDs.hpp | 178 +- src/Utility/{SH_Event.cpp => Event.cpp} | 57 +- src/Utility/{SH_Event.hpp => Event.hpp} | 100 +- src/Utility/HiveData.hpp | 115 + src/Utility/Log.cpp | 28 +- src/Utility/Log.hpp | 42 +- src/Utility/Paths.hpp | 76 +- src/Utility/Serialize.cpp | 1394 ++++++------ src/Utility/Serialize.hpp | 108 +- src/Utility/Signal.cpp | 82 +- src/Utility/Signal.hpp | 31 +- src/Utility/Tags.cpp | 190 +- src/Utility/Tags.hpp | 70 +- src/Utility/Utils.cpp | 221 ++ src/Utility/Utils.hpp | 59 + 46 files changed, 3488 insertions(+), 5177 deletions(-) rename src/Utility/{SH_Event.cpp => Event.cpp} (50%) rename src/Utility/{SH_Event.hpp => Event.hpp} (52%) create mode 100644 src/Utility/HiveData.hpp create mode 100644 src/Utility/Utils.cpp create mode 100644 src/Utility/Utils.hpp diff --git a/meson.build b/meson.build index 3f02b04..552b782 100755 --- a/meson.build +++ b/meson.build @@ -163,9 +163,10 @@ src = [ 'src/Utility/Sample.cpp', 'src/Utility/Serialize.cpp', 'src/Utility/Tags.cpp', - 'src/Utility/SH_Event.cpp', + 'src/Utility/Event.cpp', 'src/Utility/Signal.cpp', 'src/Utility/Log.cpp', + 'src/Utility/Utils.cpp', ] diff --git a/src/App.cpp b/src/App.cpp index f8a4485..44f42c5 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -29,20 +29,20 @@ #include #include -wxIMPLEMENT_APP(App); +wxIMPLEMENT_APP(cApp); -App::App() +cApp::cApp() { // Initialize the logger - SampleHive::Log::InitLogger("SampleHive"); + SampleHive::cLog::InitLogger("SampleHive"); } -App::~App() +cApp::~cApp() { } -bool App::OnInit() +bool cApp::OnInit() { if (!wxApp::OnInit()) return false; @@ -50,7 +50,7 @@ bool App::OnInit() wxLog::AddTraceMask("EventSource"); wxLog::AddTraceMask(wxTRACE_FSWATCHER); - m_Frame = new MainFrame(); + m_Frame = new cMainFrame(); wxBitmap bitmap; wxSplashScreen* splash; @@ -69,7 +69,7 @@ bool App::OnInit() return true; } -void App::OnInitCmdLine(wxCmdLineParser& parser) +void cApp::OnInitCmdLine(wxCmdLineParser& parser) { wxApp::OnInitCmdLine(parser); @@ -78,7 +78,7 @@ void App::OnInitCmdLine(wxCmdLineParser& parser) parser.Parse(true); } -bool App::OnCmdLineParsed(wxCmdLineParser& parser) +bool cApp::OnCmdLineParsed(wxCmdLineParser& parser) { if (!wxApp::OnCmdLineParsed(parser)) return false; @@ -142,7 +142,7 @@ bool App::OnCmdLineParsed(wxCmdLineParser& parser) return true; } -void App::OnEventLoopEnter(wxEventLoopBase* event) +void cApp::OnEventLoopEnter(wxEventLoopBase* event) { if (m_Frame->CreateWatcherIfNecessary()) SH_LOG_INFO("Filesystem watcher created sucessfully"); diff --git a/src/App.hpp b/src/App.hpp index 0b6ebf5..1cdee1e 100644 --- a/src/App.hpp +++ b/src/App.hpp @@ -25,18 +25,18 @@ #include #include -class App : public wxApp +class cApp : public wxApp { public: - App(); - ~App(); - - private: - MainFrame* m_Frame = nullptr; + cApp(); + ~cApp(); private: virtual bool OnInit(); virtual void OnEventLoopEnter(wxEventLoopBase* event); virtual void OnInitCmdLine(wxCmdLineParser& parser); virtual bool OnCmdLineParsed(wxCmdLineParser& parser); + + private: + cMainFrame* m_Frame = nullptr; }; diff --git a/src/Database/Database.cpp b/src/Database/Database.cpp index e06a106..0a139f6 100644 --- a/src/Database/Database.cpp +++ b/src/Database/Database.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -49,11 +50,10 @@ void debug_log_on_error(int rc) } } -void show_modal_dialog_and_log(const std::string &message, const std::string &title, - const std::string &error_msg) +void show_modal_dialog_and_log(const std::string &message, const std::string &title, const std::string &error_msg) { std::stringstream ss; - ss << message << ": " << error_msg; + ss << message << " : " << error_msg; const auto msg = ss.str(); @@ -78,17 +78,17 @@ class Sqlite3Statement sqlite3_stmt* stmt = nullptr; }; -Database::Database() +cDatabase::cDatabase() { OpenDatabase(); } -Database::~Database() +cDatabase::~cDatabase() { CloseDatabase(); } -void Database::CreateTableSamples() +void cDatabase::CreateTableSamples() { /* Create SQL statement */ const auto samples = "CREATE TABLE IF NOT EXISTS SAMPLES(" @@ -107,7 +107,7 @@ void Database::CreateTableSamples() try { - throw_on_sqlite3_error(sqlite3_exec(m_Database, samples, NULL, 0, &m_ErrMsg)); + throw_on_sqlite3_error(sqlite3_exec(m_pDatabase, samples, NULL, 0, &m_pErrMsg)); SH_LOG_INFO("SAMPLES table created successfully."); } catch (const std::exception &e) @@ -116,14 +116,14 @@ void Database::CreateTableSamples() } } -void Database::CreateTableHives() +void cDatabase::CreateTableHives() { /* Create SQL statement */ const auto hives = "CREATE TABLE IF NOT EXISTS HIVES(HIVE TEXT NOT NULL);"; try { - throw_on_sqlite3_error(sqlite3_exec(m_Database, hives, NULL, 0, &m_ErrMsg)); + throw_on_sqlite3_error(sqlite3_exec(m_pDatabase, hives, NULL, 0, &m_pErrMsg)); SH_LOG_INFO("HIVES table created successfully."); } catch (const std::exception &e) @@ -133,7 +133,7 @@ void Database::CreateTableHives() } //Loops through a Sample array and adds them to the database -void Database::InsertIntoSamples(const std::vector &samples) +void cDatabase::InsertIntoSamples(const std::vector &samples) { try { @@ -142,9 +142,9 @@ void Database::InsertIntoSamples(const std::vector &samples) SAMPLERATE, BITRATE, PATH, TRASHED, HIVE) \ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; - Sqlite3Statement statement(m_Database, sql); + Sqlite3Statement statement(m_pDatabase, sql); - throw_on_sqlite3_error(sqlite3_exec(m_Database, "BEGIN TRANSACTION", NULL, NULL, &m_ErrMsg)); + throw_on_sqlite3_error(sqlite3_exec(m_pDatabase, "BEGIN TRANSACTION", NULL, NULL, &m_pErrMsg)); Sample sample; @@ -167,30 +167,25 @@ void Database::InsertIntoSamples(const std::vector &samples) std::string hive = "Favorites"; throw_on_sqlite3_error(sqlite3_bind_int(statement.stmt, 1, sample.GetFavorite())); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), - filename.size(), SQLITE_STATIC)); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 3, file_extension.c_str(), - file_extension.size(), SQLITE_STATIC)); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 4, sample_pack.c_str(), - sample_pack.size(), SQLITE_STATIC)); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 5, type.c_str(), - type.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), filename.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 3, file_extension.c_str(), file_extension.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 4, sample_pack.c_str(), sample_pack.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 5, type.c_str(), type.size(), SQLITE_STATIC)); throw_on_sqlite3_error(sqlite3_bind_int(statement.stmt, 6, sample.GetChannels())); throw_on_sqlite3_error(sqlite3_bind_int(statement.stmt, 7, sample.GetLength())); throw_on_sqlite3_error(sqlite3_bind_int(statement.stmt, 8, sample.GetSampleRate())); throw_on_sqlite3_error(sqlite3_bind_int(statement.stmt, 9, sample.GetBitrate())); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 10, path.c_str(), - path.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 10, path.c_str(), path.size(), SQLITE_STATIC)); throw_on_sqlite3_error(sqlite3_bind_int(statement.stmt, 11, sample.GetTrashed())); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 12, hive.c_str(), - hive.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 12, hive.c_str(), hive.size(), SQLITE_STATIC)); sqlite3_step(statement.stmt); + throw_on_sqlite3_error(sqlite3_clear_bindings(statement.stmt)); throw_on_sqlite3_error(sqlite3_reset(statement.stmt)); } - throw_on_sqlite3_error(sqlite3_exec(m_Database, "END TRANSACTION", NULL, NULL, &m_ErrMsg)); + throw_on_sqlite3_error(sqlite3_exec(m_pDatabase, "END TRANSACTION", NULL, NULL, &m_pErrMsg)); SH_LOG_INFO("Data inserted successfully into SAMPLES."); } @@ -200,67 +195,36 @@ void Database::InsertIntoSamples(const std::vector &samples) } } -void Database::InsertIntoHives(const std::string &hiveName) +void cDatabase::InsertIntoHives(const std::string &hiveName) { try { const auto sql = "INSERT INTO HIVES(HIVE) VALUES(?);"; - Sqlite3Statement statement(m_Database, sql); + Sqlite3Statement statement(m_pDatabase, sql); - // rc = sqlite3_exec(m_Database, "BEGIN TRANSACTION", NULL, NULL, &m_ErrMsg); - - // Sample sample; - - // std::string filename; - // std::string file_extension; - // std::string sample_pack; - // std::string type; - // std::string path; - - // for(unsigned int i = 0; i < samples.size(); i++) - // { - // sample = samples[i]; - - // filename = sample.GetFilename(); - // file_extension = sample.GetFileExtension(); - // sample_pack = sample.GetSamplePack(); - // type = sample.GetType(); - // path = sample.GetPath(); - - // std::string hive = "Favourites"; - - // rc = sqlite3_bind_int(statement.stmt, 1, sample.GetFavorite()); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveName.c_str(), - hiveName.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveName.c_str(), hiveName.size(), SQLITE_STATIC)); throw_on_sqlite3_error(sqlite3_step(statement.stmt)); - // rc = sqlite3_clear_bindings(statement.stmt); - // rc = sqlite3_reset(statement.stmt); - // } - - // rc = sqlite3_exec(m_Database, "END TRANSACTION", NULL, NULL, &m_ErrMsg); SH_LOG_INFO("Data inserted successfully into HIVES."); } - catch (const std::exception &e) + catch (const std::exception& e) { show_modal_dialog_and_log("Error! Cannot insert data into HIVES", "Error", e.what()); } } -void Database::UpdateHive(const std::string &hiveOldName, const std::string &hiveNewName) +void cDatabase::UpdateHive(const std::string &hiveOldName, const std::string &hiveNewName) { try { const auto sql = "UPDATE HIVES SET HIVE = ? WHERE HIVE = ?;"; - Sqlite3Statement statement(m_Database, sql); + Sqlite3Statement statement(m_pDatabase, sql); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveNewName.c_str(), - hiveNewName.size(), SQLITE_STATIC)); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, hiveOldName.c_str(), - hiveOldName.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveNewName.c_str(), hiveNewName.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, hiveOldName.c_str(), hiveOldName.size(), SQLITE_STATIC)); if (sqlite3_step(statement.stmt) != SQLITE_DONE) { @@ -277,18 +241,16 @@ void Database::UpdateHive(const std::string &hiveOldName, const std::string &hiv } } -void Database::UpdateHiveName(const std::string &filename, const std::string &hiveName) +void cDatabase::UpdateHiveName(const std::string &filename, const std::string &hiveName) { try { const auto sql = "UPDATE SAMPLES SET HIVE = ? WHERE FILENAME = ?;"; - Sqlite3Statement statement(m_Database, sql); + Sqlite3Statement statement(m_pDatabase, sql); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveName.c_str(), - hiveName.size(), SQLITE_STATIC)); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), - filename.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveName.c_str(), hiveName.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), filename.size(), SQLITE_STATIC)); if (sqlite3_step(statement.stmt) == SQLITE_ROW) { @@ -303,17 +265,16 @@ void Database::UpdateHiveName(const std::string &filename, const std::string &hi } } -void Database::UpdateFavoriteColumn(const std::string &filename, int value) +void cDatabase::UpdateFavoriteColumn(const std::string &filename, int value) { try { const auto sql = "UPDATE SAMPLES SET FAVORITE = ? WHERE FILENAME = ?;"; - Sqlite3Statement statement(m_Database, sql); + Sqlite3Statement statement(m_pDatabase, sql); throw_on_sqlite3_error(sqlite3_bind_int(statement.stmt, 1, value)); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), - filename.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), filename.size(), SQLITE_STATIC)); if (sqlite3_step(statement.stmt) == SQLITE_ROW) { @@ -328,18 +289,16 @@ void Database::UpdateFavoriteColumn(const std::string &filename, int value) } } -void Database::UpdateSamplePack(const std::string &filename, const std::string &samplePack) +void cDatabase::UpdateSamplePack(const std::string &filename, const std::string &samplePack) { try { const auto sql = "UPDATE SAMPLES SET SAMPLEPACK = ? WHERE FILENAME = ?;"; - Sqlite3Statement statement(m_Database, sql); + Sqlite3Statement statement(m_pDatabase, sql); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, samplePack.c_str(), - samplePack.size(), SQLITE_STATIC)); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), - filename.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, samplePack.c_str(), samplePack.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), filename.size(), SQLITE_STATIC)); if (sqlite3_step(statement.stmt) == SQLITE_ROW) { @@ -354,17 +313,16 @@ void Database::UpdateSamplePack(const std::string &filename, const std::string & } } -void Database::UpdateSampleType(const std::string &filename, const std::string &type) +void cDatabase::UpdateSampleType(const std::string &filename, const std::string &type) { try { const auto sql = "UPDATE SAMPLES SET TYPE = ? WHERE FILENAME = ?;"; - Sqlite3Statement statement(m_Database, sql); + Sqlite3Statement statement(m_pDatabase, sql); throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, type.c_str(), type.size(), SQLITE_STATIC)); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), - filename.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), filename.size(), SQLITE_STATIC)); if (sqlite3_step(statement.stmt) == SQLITE_ROW) { @@ -379,7 +337,7 @@ void Database::UpdateSampleType(const std::string &filename, const std::string & } } -std::string Database::GetSampleType(const std::string &filename) +std::string cDatabase::GetSampleType(const std::string &filename) { std::string type; @@ -387,16 +345,15 @@ std::string Database::GetSampleType(const std::string &filename) { const auto sql = "SELECT TYPE FROM SAMPLES WHERE FILENAME = ?;"; - Sqlite3Statement statement(m_Database, sql); + Sqlite3Statement statement(m_pDatabase, sql); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), - filename.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC)); if (sqlite3_step(statement.stmt) == SQLITE_ROW) { SH_LOG_INFO("Record found, fetching sample type for {}", filename); - type = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 0))); + type = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 0))); } SH_LOG_INFO("Selected sample type from table successfully."); @@ -409,7 +366,7 @@ std::string Database::GetSampleType(const std::string &filename) return type; } -int Database::GetFavoriteColumnValueByFilename(const std::string &filename) +int cDatabase::GetFavoriteColumnValueByFilename(const std::string &filename) { int value = 0; @@ -417,10 +374,9 @@ int Database::GetFavoriteColumnValueByFilename(const std::string &filename) { const auto sql = "SELECT FAVORITE FROM SAMPLES WHERE FILENAME = ?;"; - Sqlite3Statement statement(m_Database, sql); + Sqlite3Statement statement(m_pDatabase, sql); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), - filename.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC)); if (sqlite3_step(statement.stmt) == SQLITE_ROW) { @@ -438,7 +394,7 @@ int Database::GetFavoriteColumnValueByFilename(const std::string &filename) return value; } -std::string Database::GetHiveByFilename(const std::string &filename) +std::string cDatabase::GetHiveByFilename(const std::string &filename) { std::string hive; @@ -446,14 +402,13 @@ std::string Database::GetHiveByFilename(const std::string &filename) { const auto sql = "SELECT HIVE FROM SAMPLES WHERE FILENAME = ?;"; - Sqlite3Statement statement(m_Database, sql); + Sqlite3Statement statement(m_pDatabase, sql); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), - filename.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC)); if (sqlite3_step(statement.stmt) == SQLITE_ROW) { - hive = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 0))); + hive = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 0))); SH_LOG_INFO("Record found, fetching hive for {}", filename); } @@ -467,16 +422,15 @@ std::string Database::GetHiveByFilename(const std::string &filename) return hive; } -void Database::RemoveSampleFromDatabase(const std::string &filename) +void cDatabase::RemoveSampleFromDatabase(const std::string &filename) { try { const auto sql = "DELETE FROM SAMPLES WHERE FILENAME = ?;"; - Sqlite3Statement statement(m_Database, sql); + Sqlite3Statement statement(m_pDatabase, sql); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), - filename.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC)); if (sqlite3_step(statement.stmt) == SQLITE_DONE) { @@ -491,16 +445,15 @@ void Database::RemoveSampleFromDatabase(const std::string &filename) } } -void Database::RemoveHiveFromDatabase(const std::string &hiveName) +void cDatabase::RemoveHiveFromDatabase(const std::string &hiveName) { try { const auto sql = "DELETE FROM HIVES WHERE HIVE = ?;"; - Sqlite3Statement statement(m_Database, sql); + Sqlite3Statement statement(m_pDatabase, sql); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveName.c_str(), - hiveName.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveName.c_str(), hiveName.size(), SQLITE_STATIC)); if (sqlite3_step(statement.stmt) == SQLITE_DONE) { @@ -515,7 +468,7 @@ void Database::RemoveHiveFromDatabase(const std::string &hiveName) } } -std::string Database::GetSamplePathByFilename(const std::string &filename) +std::string cDatabase::GetSamplePathByFilename(const std::string &filename) { std::string path; @@ -523,14 +476,13 @@ std::string Database::GetSamplePathByFilename(const std::string &filename) { const auto sql = "SELECT PATH FROM SAMPLES WHERE FILENAME = ?;"; - Sqlite3Statement statement(m_Database, sql); + Sqlite3Statement statement(m_pDatabase, sql); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), - filename.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC)); if (sqlite3_step(statement.stmt) == SQLITE_ROW) { - path = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 0))); + path = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 0))); SH_LOG_INFO("Record found, fetching sample path for {}", filename); } @@ -544,7 +496,7 @@ std::string Database::GetSamplePathByFilename(const std::string &filename) return path; } -std::string Database::GetSampleFileExtension(const std::string &filename) +std::string cDatabase::GetSampleFileExtension(const std::string &filename) { std::string extension; @@ -552,14 +504,13 @@ std::string Database::GetSampleFileExtension(const std::string &filename) { const auto sql = "SELECT EXTENSION FROM SAMPLES WHERE FILENAME = ?;"; - Sqlite3Statement statement(m_Database, sql); + Sqlite3Statement statement(m_pDatabase, sql); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), - filename.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC)); if (sqlite3_step(statement.stmt) == SQLITE_ROW) { - extension = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 0))); + extension = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 0))); SH_LOG_INFO("Record found, fetching file extension for {}", filename); } @@ -573,7 +524,7 @@ std::string Database::GetSampleFileExtension(const std::string &filename) return extension; } -wxVector> Database::LoadSamplesDatabase(wxDataViewTreeCtrl &favorite_tree, +wxVector> cDatabase::LoadSamplesDatabase(wxDataViewTreeCtrl &favorite_tree, wxDataViewItem &favorite_item, wxTreeCtrl &trash_tree, wxTreeItemId &trash_item, bool show_extension, @@ -590,7 +541,7 @@ wxVector> Database::LoadSamplesDatabase(wxDataViewTreeCtrl & { int num_rows = 0; - Sqlite3Statement statement1(m_Database, "SELECT Count(*) FROM SAMPLES;"); + Sqlite3Statement statement1(m_pDatabase, "SELECT Count(*) FROM SAMPLES;"); if (SQLITE_ROW == sqlite3_step(statement1.stmt)) { @@ -601,7 +552,7 @@ wxVector> Database::LoadSamplesDatabase(wxDataViewTreeCtrl & vecSet.reserve(num_rows); } - Sqlite3Statement statement(m_Database, "SELECT FAVORITE, FILENAME, EXTENSION, SAMPLEPACK, \ + Sqlite3Statement statement(m_pDatabase, "SELECT FAVORITE, FILENAME, EXTENSION, SAMPLEPACK, \ TYPE, CHANNELS, LENGTH, SAMPLERATE, BITRATE, PATH, \ TRASHED, HIVE FROM SAMPLES;"); @@ -610,23 +561,17 @@ wxVector> Database::LoadSamplesDatabase(wxDataViewTreeCtrl & while (SQLITE_ROW == sqlite3_step(statement.stmt)) { int favorite = sqlite3_column_int(statement.stmt, 0); - wxString filename = std::string(reinterpret_cast - (sqlite3_column_text(statement.stmt, 1))); - wxString file_extension = std::string(reinterpret_cast - (sqlite3_column_text(statement.stmt, 2))); - wxString sample_pack = std::string(reinterpret_cast - (sqlite3_column_text(statement.stmt, 3))); - wxString sample_type = std::string(reinterpret_cast - (sqlite3_column_text(statement.stmt, 4))); + wxString filename = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 1))); + wxString file_extension = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 2))); + wxString sample_pack = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 3))); + wxString sample_type = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 4))); int channels = sqlite3_column_int(statement.stmt, 5); int length = sqlite3_column_int(statement.stmt, 6); int sample_rate = sqlite3_column_int(statement.stmt, 7); int bitrate = sqlite3_column_int(statement.stmt, 8); - wxString path = std::string(reinterpret_cast - (sqlite3_column_text(statement.stmt, 9))); + wxString path = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 9))); int trashed = sqlite3_column_int(statement.stmt, 10); - wxString hive_name = std::string(reinterpret_cast - (sqlite3_column_text(statement.stmt, 11))); + wxString hive_name = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 11))); wxLongLong llLength = length; int total_min = static_cast((llLength / 60000).GetValue()); @@ -683,8 +628,7 @@ wxVector> Database::LoadSamplesDatabase(wxDataViewTreeCtrl & if (found_item.IsOk()) { if (show_extension) - favorite_tree.AppendItem(found_item, - wxString::Format("%s.%s", filename, file_extension)); + favorite_tree.AppendItem(found_item, wxString::Format("%s.%s", filename, file_extension)); else favorite_tree.AppendItem(found_item, filename); } @@ -723,9 +667,9 @@ wxVector> Database::LoadSamplesDatabase(wxDataViewTreeCtrl & return vecSet; } -wxVector> -Database::FilterDatabaseBySampleName(const std::string &sampleName, bool show_extension, - const std::string &icon_star_filled, const std::string &icon_star_empty) +wxVector>cDatabase::FilterDatabaseBySampleName(const std::string &sampleName, bool show_extension, + const std::string &icon_star_filled, + const std::string &icon_star_empty) { wxVector> sampleVec; @@ -735,12 +679,11 @@ Database::FilterDatabaseBySampleName(const std::string &sampleName, bool show_ex try { - Sqlite3Statement statement(m_Database, "SELECT FAVORITE, FILENAME, SAMPLEPACK, TYPE, \ + Sqlite3Statement statement(m_pDatabase, "SELECT FAVORITE, FILENAME, SAMPLEPACK, TYPE, \ CHANNELS, LENGTH, SAMPLERATE, BITRATE, PATH \ FROM SAMPLES WHERE FILENAME LIKE '%' || ? || '%' ;"); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, sampleName.c_str(), - sampleName.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, sampleName.c_str(), sampleName.size(), SQLITE_STATIC)); int row = 0; @@ -749,18 +692,14 @@ Database::FilterDatabaseBySampleName(const std::string &sampleName, bool show_ex SH_LOG_INFO("Record found, filtering db by {}", sampleName); int favorite = sqlite3_column_int(statement.stmt, 0); - wxString filename = wxString(std::string(reinterpret_cast - (sqlite3_column_text(statement.stmt, 1)))); - wxString sample_pack = wxString(std::string(reinterpret_cast - (sqlite3_column_text(statement.stmt, 2)))); - wxString sample_type = std::string(reinterpret_cast - (sqlite3_column_text(statement.stmt, 3))); + wxString filename = wxString(std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 1)))); + wxString sample_pack = wxString(std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 2)))); + wxString sample_type = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 3))); int channels = sqlite3_column_int(statement.stmt, 4); int length = sqlite3_column_int(statement.stmt, 5); int sample_rate = sqlite3_column_int(statement.stmt, 6); int bitrate = sqlite3_column_int(statement.stmt, 7); - wxString path = wxString(std::string(reinterpret_cast - (sqlite3_column_text(statement.stmt, 8)))); + wxString path = wxString(std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 8)))); wxLongLong llLength = length; int total_min = static_cast((llLength / 60000).GetValue()); @@ -803,9 +742,9 @@ Database::FilterDatabaseBySampleName(const std::string &sampleName, bool show_ex return sampleVec; } -wxVector> -Database::FilterDatabaseByHiveName(const std::string &hiveName, bool show_extension, - const std::string &icon_star_filled, const std::string &icon_star_empty) +wxVector>cDatabase::FilterDatabaseByHiveName(const std::string &hiveName, bool show_extension, + const std::string &icon_star_filled, + const std::string &icon_star_empty) { wxVector> sampleVec; @@ -815,12 +754,11 @@ Database::FilterDatabaseByHiveName(const std::string &hiveName, bool show_extens try { - Sqlite3Statement statement(m_Database, "SELECT FAVORITE, FILENAME, SAMPLEPACK, TYPE, \ + Sqlite3Statement statement(m_pDatabase, "SELECT FAVORITE, FILENAME, SAMPLEPACK, TYPE, \ CHANNELS, LENGTH, SAMPLERATE, BITRATE, PATH \ FROM SAMPLES WHERE HIVE = ? AND FAVORITE = 1;"); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveName.c_str(), - hiveName.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveName.c_str(), hiveName.size(), SQLITE_STATIC)); int row = 0; @@ -829,18 +767,14 @@ Database::FilterDatabaseByHiveName(const std::string &hiveName, bool show_extens SH_LOG_INFO("Record found, filtering db by {}", hiveName); int favorite = sqlite3_column_int(statement.stmt, 0); - wxString filename = wxString(std::string(reinterpret_cast - (sqlite3_column_text(statement.stmt, 1)))); - wxString sample_pack = wxString(std::string(reinterpret_cast - (sqlite3_column_text(statement.stmt, 2)))); - wxString sample_type = std::string(reinterpret_cast - (sqlite3_column_text(statement.stmt, 3))); + wxString filename = wxString(std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 1)))); + wxString sample_pack = wxString(std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 2)))); + wxString sample_type = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 3))); int channels = sqlite3_column_int(statement.stmt, 4); int length = sqlite3_column_int(statement.stmt, 5); int sample_rate = sqlite3_column_int(statement.stmt, 6); int bitrate = sqlite3_column_int(statement.stmt, 7); - wxString path = wxString(std::string(reinterpret_cast - (sqlite3_column_text(statement.stmt, 8)))); + wxString path = wxString(std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 8)))); wxLongLong llLength = length; int total_min = static_cast((llLength / 60000).GetValue()); @@ -879,20 +813,19 @@ Database::FilterDatabaseByHiveName(const std::string &hiveName, bool show_extens return sampleVec; } -void Database::LoadHivesDatabase(wxDataViewTreeCtrl &treeCtrl) +void cDatabase::LoadHivesDatabase(wxDataViewTreeCtrl &treeCtrl) { try { const auto sql = "SELECT HIVE FROM HIVES;"; - Sqlite3Statement statement(m_Database, sql); + Sqlite3Statement statement(m_pDatabase, sql); while (SQLITE_ROW == sqlite3_step(statement.stmt)) { SH_LOG_INFO("Loading hives.."); - const auto hive = wxString(std::string(reinterpret_cast - (sqlite3_column_text(statement.stmt, 0)))); + const auto hive = wxString(std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 0)))); treeCtrl.AppendContainer(wxDataViewItem(wxNullPtr), hive); } @@ -903,8 +836,8 @@ void Database::LoadHivesDatabase(wxDataViewTreeCtrl &treeCtrl) } } -//Compares the input array with the database and removes duplicates. -wxArrayString Database::CheckDuplicates(const wxArrayString &files) +// Compares the input array with the database and removes duplicates. +wxArrayString cDatabase::CheckDuplicates(const wxArrayString &files) { wxArrayString sorted_files; @@ -915,7 +848,7 @@ wxArrayString Database::CheckDuplicates(const wxArrayString &files) { const auto sql = "SELECT * FROM SAMPLES WHERE FILENAME = ?;"; - Sqlite3Statement statement(m_Database, sql); + Sqlite3Statement statement(m_pDatabase, sql); for (unsigned int i = 0; i < files.size(); i++) { @@ -940,16 +873,15 @@ wxArrayString Database::CheckDuplicates(const wxArrayString &files) return sorted_files; } -bool Database::IsTrashed(const std::string &filename) +bool cDatabase::IsTrashed(const std::string &filename) { try { const auto sql = "SELECT TRASHED FROM SAMPLES WHERE FILENAME = ?;"; - Sqlite3Statement statement(m_Database, sql); + Sqlite3Statement statement(m_pDatabase, sql); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), - filename.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC)); if (sqlite3_step(statement.stmt) == SQLITE_ROW) { @@ -969,17 +901,16 @@ bool Database::IsTrashed(const std::string &filename) return false; } -void Database::UpdateTrashColumn(const std::string &filename, int value) +void cDatabase::UpdateTrashColumn(const std::string &filename, int value) { try { const auto sql = "UPDATE SAMPLES SET TRASHED = ? WHERE FILENAME = ?;"; - Sqlite3Statement statement(m_Database, sql); + Sqlite3Statement statement(m_pDatabase, sql); throw_on_sqlite3_error(sqlite3_bind_int(statement.stmt, 1, value)); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), - filename.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), filename.size(), SQLITE_STATIC)); if (sqlite3_step(statement.stmt) == SQLITE_ROW) { @@ -994,10 +925,10 @@ void Database::UpdateTrashColumn(const std::string &filename, int value) } } -wxVector> -Database::RestoreFromTrashByFilename(const std::string &filename, - wxVector> &vecSet, bool show_extension, - const std::string &icon_star_filled, const std::string &icon_star_empty) +wxVector>cDatabase::RestoreFromTrashByFilename(const std::string &filename, + wxVector> &vecSet, bool show_extension, + const std::string &icon_star_filled, + const std::string &icon_star_empty) { wxVariant icon_filled, icon_empty; icon_filled = wxVariant(wxBitmap(icon_star_filled)); @@ -1009,31 +940,24 @@ Database::RestoreFromTrashByFilename(const std::string &filename, TYPE, CHANNELS, LENGTH, SAMPLERATE, BITRATE, PATH, \ TRASHED, HIVE FROM SAMPLES WHERE FILENAME = ?;"; - Sqlite3Statement statement(m_Database, sql); + Sqlite3Statement statement(m_pDatabase, sql); - throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), - filename.size(), SQLITE_STATIC)); + throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC)); while (SQLITE_ROW == sqlite3_step(statement.stmt)) { int favorite = sqlite3_column_int(statement.stmt, 0); - wxString filename = std::string(reinterpret_cast - (sqlite3_column_text(statement.stmt, 1))); - wxString file_extension = std::string(reinterpret_cast - (sqlite3_column_text(statement.stmt, 2))); - wxString sample_pack = std::string(reinterpret_cast - (sqlite3_column_text(statement.stmt, 3))); - wxString sample_type = std::string(reinterpret_cast - (sqlite3_column_text(statement.stmt, 4))); + wxString filename = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 1))); + wxString file_extension = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 2))); + wxString sample_pack = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 3))); + wxString sample_type = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 4))); int channels = sqlite3_column_int(statement.stmt, 5); int length = sqlite3_column_int(statement.stmt, 6); int sample_rate = sqlite3_column_int(statement.stmt, 7); int bitrate = sqlite3_column_int(statement.stmt, 8); - wxString path = std::string(reinterpret_cast - (sqlite3_column_text(statement.stmt, 9))); + wxString path = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 9))); int trashed = sqlite3_column_int(statement.stmt, 10); - wxString hive_name = std::string(reinterpret_cast - (sqlite3_column_text(statement.stmt, 11))); + wxString hive_name = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 11))); wxLongLong llLength = length; int total_min = static_cast((llLength / 60000).GetValue()); @@ -1073,12 +997,12 @@ Database::RestoreFromTrashByFilename(const std::string &filename, return vecSet; } -void Database::OpenDatabase() +void cDatabase::OpenDatabase() { - throw_on_sqlite3_error(sqlite3_open(static_cast(DATABASE_FILEPATH).c_str(), &m_Database)); + throw_on_sqlite3_error(sqlite3_open(static_cast(DATABASE_FILEPATH).c_str(), &m_pDatabase)); } -void Database::CloseDatabase() +void cDatabase::CloseDatabase() { - throw_on_sqlite3_error(sqlite3_close(m_Database)); + throw_on_sqlite3_error(sqlite3_close(m_pDatabase)); } diff --git a/src/Database/Database.hpp b/src/Database/Database.hpp index b157466..4020c2f 100644 --- a/src/Database/Database.hpp +++ b/src/Database/Database.hpp @@ -34,17 +34,17 @@ #include -class Database +class cDatabase { public: - Database(); - ~Database(); + cDatabase(); + ~cDatabase(); private: // ------------------------------------------------------------------- - sqlite3* m_Database; + sqlite3* m_pDatabase = nullptr; int rc; - char* m_ErrMsg; + char* m_pErrMsg = nullptr; private: // ------------------------------------------------------------------- diff --git a/src/GUI/Dialogs/Settings.cpp b/src/GUI/Dialogs/Settings.cpp index 0ebe625..4dde838 100644 --- a/src/GUI/Dialogs/Settings.cpp +++ b/src/GUI/Dialogs/Settings.cpp @@ -20,189 +20,187 @@ #include "GUI/Dialogs/Settings.hpp" #include "Utility/ControlIDs.hpp" -#include "Utility/Serialize.hpp" #include "Utility/Log.hpp" #include "Utility/Paths.hpp" +#include "Utility/Serialize.hpp" #include #include #include -Settings::Settings(wxWindow *window) - : wxDialog(window, wxID_ANY, "Settings", wxDefaultPosition, +cSettings::cSettings(wxWindow *window) + : wxDialog(window, wxID_ANY, "cSettings", wxDefaultPosition, wxSize(720, 270), wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP), - m_Window(window) + m_pWindow(window) { - m_Panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize); + m_pPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize); - m_MainSizer = new wxBoxSizer(wxVERTICAL); - m_NotebookSizer = new wxBoxSizer(wxVERTICAL); - m_ButtonSizer = new wxBoxSizer(wxHORIZONTAL); + m_pMainSizer = new wxBoxSizer(wxVERTICAL); + m_pNotebookSizer = new wxBoxSizer(wxVERTICAL); + m_pButtonSizer = new wxBoxSizer(wxHORIZONTAL); - m_Notebook = new wxNotebook(m_Panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, _T("NOTEBOOK")); + m_pNotebook = new wxNotebook(m_pPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, _T("NOTEBOOK")); - m_DisplaySettingPanel = new wxPanel(m_Notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize); + m_pDisplaySettingPanel = new wxPanel(m_pNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize); - m_DisplayTopSizer = new wxBoxSizer(wxVERTICAL); - m_DisplayFontSizer = new wxBoxSizer(wxHORIZONTAL); - m_WaveformColourSizer = new wxBoxSizer(wxHORIZONTAL); + m_pDisplayTopSizer = new wxBoxSizer(wxVERTICAL); + m_pDisplayFontSizer = new wxBoxSizer(wxHORIZONTAL); + m_pWaveformColourSizer = new wxBoxSizer(wxHORIZONTAL); - Serializer serializer; + SampleHive::cSerializer serializer; wxString fontChoices[] = { "System default" }; - m_FontTypeText = new wxStaticText(m_DisplaySettingPanel, wxID_ANY, "Font", - wxDefaultPosition, wxDefaultSize, 0); - m_FontType = new wxChoice(m_DisplaySettingPanel, SD_FontType, - wxDefaultPosition, wxDefaultSize, 1, fontChoices, 0); - m_FontType->SetSelection(0); - m_FontSize = new wxSpinCtrl(m_DisplaySettingPanel, SD_FontSize, "Default", - wxDefaultPosition, wxDefaultSize); - m_FontSize->SetValue(window->GetFont().GetPointSize()); - m_FontBrowseButton = new wxButton(m_DisplaySettingPanel, SD_FontBrowseButton, "Select font", - wxDefaultPosition, wxDefaultSize, 0); - m_WaveformColourLabel = new wxStaticText(m_DisplaySettingPanel, wxID_ANY, "Waveform colour", - wxDefaultPosition, wxDefaultSize, 0); - m_WaveformColourPickerCtrl = new wxColourPickerCtrl(m_DisplaySettingPanel, SD_WaveformColourPickerCtrl, - serializer.DeserializeWaveformColour(), - wxDefaultPosition, wxDefaultSize, - wxCLRP_DEFAULT_STYLE); + m_pFontTypeText = new wxStaticText(m_pDisplaySettingPanel, wxID_ANY, "Font", wxDefaultPosition, wxDefaultSize, 0); + m_pFontType = new wxChoice(m_pDisplaySettingPanel, SampleHive::ID::SD_FontType, + wxDefaultPosition, wxDefaultSize, 1, fontChoices, 0); + m_pFontType->SetSelection(0); + m_pFontSize = new wxSpinCtrl(m_pDisplaySettingPanel, SampleHive::ID::SD_FontSize, "Default", wxDefaultPosition, wxDefaultSize); + m_pFontSize->SetValue(window->GetFont().GetPointSize()); + m_pFontBrowseButton = new wxButton(m_pDisplaySettingPanel, SampleHive::ID::SD_FontBrowseButton, "Select font", + wxDefaultPosition, wxDefaultSize, 0); + m_pWaveformColourLabel = new wxStaticText(m_pDisplaySettingPanel, wxID_ANY, "Waveform colour", + wxDefaultPosition, wxDefaultSize, 0); + m_pWaveformColourPickerCtrl = new wxColourPickerCtrl(m_pDisplaySettingPanel, SampleHive::ID::SD_WaveformColourPickerCtrl, + serializer.DeserializeWaveformColour(), + wxDefaultPosition, wxDefaultSize, + wxCLRP_DEFAULT_STYLE); - m_CollectionSettingPanel = new wxPanel(m_Notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize); + m_pCollectionSettingPanel = new wxPanel(m_pNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize); - m_CollectionMainSizer = new wxBoxSizer(wxVERTICAL); - m_CollectionImportDirSizer = new wxBoxSizer(wxHORIZONTAL); - m_CollectionImportOptionsSizer = new wxBoxSizer(wxHORIZONTAL); - m_CollectionShowExtensionSizer = new wxBoxSizer(wxVERTICAL); + m_pCollectionMainSizer = new wxBoxSizer(wxVERTICAL); + m_pCollectionImportDirSizer = new wxBoxSizer(wxHORIZONTAL); + m_pCollectionImportOptionsSizer = new wxBoxSizer(wxHORIZONTAL); + m_pCollectionShowExtensionSizer = new wxBoxSizer(wxVERTICAL); wxString defaultDir = wxGetHomeDir(); - m_AutoImportCheck = new wxCheckBox(m_CollectionSettingPanel, SD_AutoImport, "Auto import", - wxDefaultPosition, wxDefaultSize, 0); - m_ImportDirLocation = new wxTextCtrl(m_CollectionSettingPanel, wxID_ANY, defaultDir, - wxDefaultPosition, wxDefaultSize, 0); - m_ImportDirLocation->Disable(); - m_BrowseAutoImportDirButton = new wxButton(m_CollectionSettingPanel, SD_BrowseAutoImportDir, "Browse", - wxDefaultPosition, wxDefaultSize, 0); - m_BrowseAutoImportDirButton->Disable(); - m_FollowSymLinksCheck = new wxCheckBox(m_CollectionSettingPanel, SD_FollowSymLinks, - "Follow symbolic links", wxDefaultPosition, wxDefaultSize, 0); - m_FollowSymLinksCheck->SetToolTip("Wheather to follow symbolic links"); - m_FollowSymLinksCheck->Disable(); - m_RecursiveImportCheck = new wxCheckBox(m_CollectionSettingPanel, SD_RecursiveImport, - "Recursive search", wxDefaultPosition, wxDefaultSize, 0); - m_RecursiveImportCheck->SetToolTip("Recursively search for samples in the directory"); - m_RecursiveImportCheck->Disable(); - m_ShowFileExtensionCheck = new wxCheckBox(m_CollectionSettingPanel, SD_ShowFileExtension, - "Show file extension", wxDefaultPosition, wxDefaultSize, 0); - m_ShowFileExtensionCheck->SetToolTip("Weather to show file extension"); + m_pAutoImportCheck = new wxCheckBox(m_pCollectionSettingPanel, SampleHive::ID::SD_AutoImport, "Auto import", + wxDefaultPosition, wxDefaultSize, 0); + m_pImportDirLocation = new wxTextCtrl(m_pCollectionSettingPanel, wxID_ANY, defaultDir, + wxDefaultPosition, wxDefaultSize, 0); + m_pImportDirLocation->Disable(); + m_pBrowseAutoImportDirButton = new wxButton(m_pCollectionSettingPanel, SampleHive::ID::SD_BrowseAutoImportDir, "Browse", + wxDefaultPosition, wxDefaultSize, 0); + m_pBrowseAutoImportDirButton->Disable(); + m_pFollowSymLinksCheck = new wxCheckBox(m_pCollectionSettingPanel, SampleHive::ID::SD_FollowSymLinks, + "Follow symbolic links", wxDefaultPosition, wxDefaultSize, 0); + m_pFollowSymLinksCheck->SetToolTip("Wheather to follow symbolic links"); + m_pFollowSymLinksCheck->Disable(); + m_pRecursiveImportCheck = new wxCheckBox(m_pCollectionSettingPanel, SampleHive::ID::SD_RecursiveImport, + "Recursive search", wxDefaultPosition, wxDefaultSize, 0); + m_pRecursiveImportCheck->SetToolTip("Recursively search for samples in the directory"); + m_pRecursiveImportCheck->Disable(); + m_pShowFileExtensionCheck = new wxCheckBox(m_pCollectionSettingPanel, SampleHive::ID::SD_ShowFileExtension, + "Show file extension", wxDefaultPosition, wxDefaultSize, 0); + m_pShowFileExtensionCheck->SetToolTip("Weather to show file extension"); - m_ConfigurationSettingPanel = new wxPanel(m_Notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize); + m_pConfigurationSettingPanel = new wxPanel(m_pNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize); - m_GeneralMainSizer = new wxFlexGridSizer(2, 3, 0, 0); - m_GeneralMainSizer->AddGrowableCol(1); - m_GeneralMainSizer->SetFlexibleDirection(wxBOTH); - m_GeneralMainSizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED); + m_pGeneralMainSizer = new wxFlexGridSizer(2, 3, 0, 0); + m_pGeneralMainSizer->AddGrowableCol(1); + m_pGeneralMainSizer->SetFlexibleDirection(wxBOTH); + m_pGeneralMainSizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED); - m_ConfigLabel = new wxStaticText(m_ConfigurationSettingPanel, wxID_ANY, - "Default configuration file location", wxDefaultPosition, wxDefaultSize); - m_ConfigText = new wxTextCtrl(m_ConfigurationSettingPanel, wxID_ANY, CONFIG_FILEPATH, - wxDefaultPosition, wxDefaultSize); - m_ConfigBrowse = new wxButton(m_ConfigurationSettingPanel, SD_BrowseConfigDir, "Browse", - wxDefaultPosition, wxDefaultSize, 0); - m_DatabaseLabel = new wxStaticText(m_ConfigurationSettingPanel, wxID_ANY, "Default database location", - wxDefaultPosition, wxDefaultSize); - m_DatabaseText = new wxTextCtrl(m_ConfigurationSettingPanel, wxID_ANY, DATABASE_FILEPATH, - wxDefaultPosition, wxDefaultSize); - m_DatabaseBrowse = new wxButton(m_ConfigurationSettingPanel, SD_BrowseDatabaseDir, "Browse", - wxDefaultPosition, wxDefaultSize, 0); + m_pConfigLabel = new wxStaticText(m_pConfigurationSettingPanel, wxID_ANY, + "Default configuration file location", wxDefaultPosition, wxDefaultSize); + m_pConfigText = new wxTextCtrl(m_pConfigurationSettingPanel, wxID_ANY, CONFIG_FILEPATH, + wxDefaultPosition, wxDefaultSize); + m_pConfigBrowse = new wxButton(m_pConfigurationSettingPanel, SampleHive::ID::SD_BrowseConfigDir, "Browse", + wxDefaultPosition, wxDefaultSize, 0); + m_pDatabaseLabel = new wxStaticText(m_pConfigurationSettingPanel, wxID_ANY, "Default database location", + wxDefaultPosition, wxDefaultSize); + m_pDatabaseText = new wxTextCtrl(m_pConfigurationSettingPanel, wxID_ANY, DATABASE_FILEPATH, + wxDefaultPosition, wxDefaultSize); + m_pDatabaseBrowse = new wxButton(m_pConfigurationSettingPanel, SampleHive::ID::SD_BrowseDatabaseDir, "Browse", + wxDefaultPosition, wxDefaultSize, 0); - m_Notebook->AddPage(m_DisplaySettingPanel, "Display"); - m_Notebook->AddPage(m_CollectionSettingPanel, "Collection"); - m_Notebook->AddPage(m_ConfigurationSettingPanel, "General"); + m_pNotebook->AddPage(m_pDisplaySettingPanel, "Display"); + m_pNotebook->AddPage(m_pCollectionSettingPanel, "Collection"); + m_pNotebook->AddPage(m_pConfigurationSettingPanel, "General"); - m_OkButton = new wxButton(m_Panel, wxID_OK, "OK", wxDefaultPosition, wxDefaultSize); - m_CancelButton = new wxButton(m_Panel, wxID_CANCEL, "Cancel", wxDefaultPosition, wxDefaultSize); + m_pOkButton = new wxButton(m_pPanel, wxID_OK, "OK", wxDefaultPosition, wxDefaultSize); + m_pCancelButton = new wxButton(m_pPanel, wxID_CANCEL, "Cancel", wxDefaultPosition, wxDefaultSize); LoadDefaultConfig(); // Bind events - Bind(wxEVT_CHECKBOX, &Settings::OnCheckAutoImport, this, SD_AutoImport); - Bind(wxEVT_CHECKBOX, &Settings::OnCheckFollowSymLinks, this, SD_FollowSymLinks); - Bind(wxEVT_CHECKBOX, &Settings::OnCheckRecursiveImport, this, SD_RecursiveImport); - Bind(wxEVT_CHECKBOX, &Settings::OnCheckShowFileExtension, this, SD_ShowFileExtension); - Bind(wxEVT_SPINCTRL, &Settings::OnChangeFontSize, this, SD_FontSize); - Bind(wxEVT_BUTTON, &Settings::OnSelectFont, this, SD_FontBrowseButton); - Bind(wxEVT_BUTTON, &Settings::OnClickBrowseAutoImportDir, this, SD_BrowseAutoImportDir); - Bind(wxEVT_BUTTON, &Settings::OnClickConfigBrowse, this, SD_BrowseConfigDir); - Bind(wxEVT_BUTTON, &Settings::OnClickDatabaseBrowse, this, SD_BrowseDatabaseDir); - Bind(wxEVT_COLOURPICKER_CHANGED, &Settings::OnChangeWaveformColour, this, SD_WaveformColourPickerCtrl); + Bind(wxEVT_CHECKBOX, &cSettings::OnCheckAutoImport, this, SampleHive::ID::SD_AutoImport); + Bind(wxEVT_CHECKBOX, &cSettings::OnCheckFollowSymLinks, this, SampleHive::ID::SD_FollowSymLinks); + Bind(wxEVT_CHECKBOX, &cSettings::OnCheckRecursiveImport, this, SampleHive::ID::SD_RecursiveImport); + Bind(wxEVT_CHECKBOX, &cSettings::OnCheckShowFileExtension, this, SampleHive::ID::SD_ShowFileExtension); + Bind(wxEVT_SPINCTRL, &cSettings::OnChangeFontSize, this, SampleHive::ID::SD_FontSize); + Bind(wxEVT_BUTTON, &cSettings::OnSelectFont, this, SampleHive::ID::SD_FontBrowseButton); + Bind(wxEVT_BUTTON, &cSettings::OnClickBrowseAutoImportDir, this, SampleHive::ID::SD_BrowseAutoImportDir); + Bind(wxEVT_BUTTON, &cSettings::OnClickConfigBrowse, this, SampleHive::ID::SD_BrowseConfigDir); + Bind(wxEVT_BUTTON, &cSettings::OnClickDatabaseBrowse, this, SampleHive::ID::SD_BrowseDatabaseDir); + Bind(wxEVT_COLOURPICKER_CHANGED, &cSettings::OnChangeWaveformColour, this, SampleHive::ID::SD_WaveformColourPickerCtrl); // Adding controls to sizers - m_NotebookSizer->Add(m_Notebook, 1, wxALL | wxEXPAND, 2); + m_pNotebookSizer->Add(m_pNotebook, 1, wxALL | wxEXPAND, 2); - m_GeneralMainSizer->Add(m_ConfigLabel, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); - m_GeneralMainSizer->Add(m_ConfigText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2); - m_GeneralMainSizer->Add(m_ConfigBrowse, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); + m_pGeneralMainSizer->Add(m_pConfigLabel, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); + m_pGeneralMainSizer->Add(m_pConfigText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2); + m_pGeneralMainSizer->Add(m_pConfigBrowse, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); - m_GeneralMainSizer->Add(m_DatabaseLabel, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); - m_GeneralMainSizer->Add(m_DatabaseText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2); - m_GeneralMainSizer->Add(m_DatabaseBrowse, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); + m_pGeneralMainSizer->Add(m_pDatabaseLabel, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); + m_pGeneralMainSizer->Add(m_pDatabaseText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2); + m_pGeneralMainSizer->Add(m_pDatabaseBrowse, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); - m_DisplayFontSizer->Add(m_FontTypeText, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); - m_DisplayFontSizer->Add(m_FontType, 1, wxALL | wxALIGN_CENTER_VERTICAL, 2); - m_DisplayFontSizer->Add(m_FontSize, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); - m_DisplayFontSizer->Add(m_FontBrowseButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); - m_WaveformColourSizer->Add(m_WaveformColourLabel, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); - m_WaveformColourSizer->Add(m_WaveformColourPickerCtrl, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); + m_pDisplayFontSizer->Add(m_pFontTypeText, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); + m_pDisplayFontSizer->Add(m_pFontType, 1, wxALL | wxALIGN_CENTER_VERTICAL, 2); + m_pDisplayFontSizer->Add(m_pFontSize, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); + m_pDisplayFontSizer->Add(m_pFontBrowseButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); + m_pWaveformColourSizer->Add(m_pWaveformColourLabel, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); + m_pWaveformColourSizer->Add(m_pWaveformColourPickerCtrl, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); - m_DisplayTopSizer->Add(m_DisplayFontSizer, 0, wxALL | wxEXPAND, 2); - m_DisplayTopSizer->Add(m_WaveformColourSizer, 0, wxALL | wxEXPAND, 2); + m_pDisplayTopSizer->Add(m_pDisplayFontSizer, 0, wxALL | wxEXPAND, 2); + m_pDisplayTopSizer->Add(m_pWaveformColourSizer, 0, wxALL | wxEXPAND, 2); - m_CollectionImportDirSizer->Add(m_AutoImportCheck, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); - m_CollectionImportDirSizer->Add(m_ImportDirLocation, 1, wxALL | wxALIGN_CENTER_VERTICAL, 2); - m_CollectionImportDirSizer->Add(m_BrowseAutoImportDirButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); + m_pCollectionImportDirSizer->Add(m_pAutoImportCheck, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); + m_pCollectionImportDirSizer->Add(m_pImportDirLocation, 1, wxALL | wxALIGN_CENTER_VERTICAL, 2); + m_pCollectionImportDirSizer->Add(m_pBrowseAutoImportDirButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); - m_CollectionImportOptionsSizer->Add(m_FollowSymLinksCheck, 0, wxALL, 2); - m_CollectionImportOptionsSizer->Add(m_RecursiveImportCheck, 0, wxALL, 2); - m_CollectionShowExtensionSizer->Add(m_ShowFileExtensionCheck, 0, wxALL, 2); + m_pCollectionImportOptionsSizer->Add(m_pFollowSymLinksCheck, 0, wxALL, 2); + m_pCollectionImportOptionsSizer->Add(m_pRecursiveImportCheck, 0, wxALL, 2); + m_pCollectionShowExtensionSizer->Add(m_pShowFileExtensionCheck, 0, wxALL, 2); - m_CollectionMainSizer->Add(m_CollectionImportDirSizer, 0, wxALL | wxEXPAND, 2); - m_CollectionMainSizer->Add(m_CollectionImportOptionsSizer, 0, wxALL | wxEXPAND, 2); - m_CollectionMainSizer->Add(m_CollectionShowExtensionSizer, 0, wxALL | wxEXPAND, 2); + m_pCollectionMainSizer->Add(m_pCollectionImportDirSizer, 0, wxALL | wxEXPAND, 2); + m_pCollectionMainSizer->Add(m_pCollectionImportOptionsSizer, 0, wxALL | wxEXPAND, 2); + m_pCollectionMainSizer->Add(m_pCollectionShowExtensionSizer, 0, wxALL | wxEXPAND, 2); - m_ButtonSizer->Add(m_OkButton, 0, wxALL | wxALIGN_BOTTOM, 2); - m_ButtonSizer->Add(m_CancelButton, 0, wxALL | wxALIGN_BOTTOM, 2); + m_pButtonSizer->Add(m_pOkButton, 0, wxALL | wxALIGN_BOTTOM, 2); + m_pButtonSizer->Add(m_pCancelButton, 0, wxALL | wxALIGN_BOTTOM, 2); - m_MainSizer->Add(m_NotebookSizer, 1, wxALL | wxEXPAND, 2); - m_MainSizer->Add(m_ButtonSizer, 0, wxALL | wxALIGN_RIGHT, 2); + m_pMainSizer->Add(m_pNotebookSizer, 1, wxALL | wxEXPAND, 2); + m_pMainSizer->Add(m_pButtonSizer, 0, wxALL | wxALIGN_RIGHT, 2); // Top panel layout - m_Panel->SetSizer(m_MainSizer); - m_MainSizer->Fit(m_Panel); - m_MainSizer->SetSizeHints(m_Panel); - m_MainSizer->Layout(); + m_pPanel->SetSizer(m_pMainSizer); + m_pMainSizer->Fit(m_pPanel); + m_pMainSizer->SetSizeHints(m_pPanel); + m_pMainSizer->Layout(); // Display panel layout - m_DisplaySettingPanel->SetSizer(m_DisplayTopSizer); - m_DisplayTopSizer->Fit(m_DisplaySettingPanel); - m_DisplayTopSizer->SetSizeHints(m_DisplaySettingPanel); - m_DisplayTopSizer->Layout(); + m_pDisplaySettingPanel->SetSizer(m_pDisplayTopSizer); + m_pDisplayTopSizer->Fit(m_pDisplaySettingPanel); + m_pDisplayTopSizer->SetSizeHints(m_pDisplaySettingPanel); + m_pDisplayTopSizer->Layout(); // Collection panel layout - m_CollectionSettingPanel->SetSizer(m_CollectionMainSizer); - m_CollectionMainSizer->Fit(m_CollectionSettingPanel); - m_CollectionMainSizer->SetSizeHints(m_CollectionSettingPanel); - m_CollectionMainSizer->Layout(); + m_pCollectionSettingPanel->SetSizer(m_pCollectionMainSizer); + m_pCollectionMainSizer->Fit(m_pCollectionSettingPanel); + m_pCollectionMainSizer->SetSizeHints(m_pCollectionSettingPanel); + m_pCollectionMainSizer->Layout(); // Configuration panel layout - m_ConfigurationSettingPanel->SetSizer(m_GeneralMainSizer); - m_GeneralMainSizer->Fit(m_ConfigurationSettingPanel); - m_GeneralMainSizer->SetSizeHints(m_ConfigurationSettingPanel); - m_GeneralMainSizer->Layout(); + m_pConfigurationSettingPanel->SetSizer(m_pGeneralMainSizer); + m_pGeneralMainSizer->Fit(m_pConfigurationSettingPanel); + m_pGeneralMainSizer->SetSizeHints(m_pConfigurationSettingPanel); + m_pGeneralMainSizer->Layout(); } -void Settings::OnClickConfigBrowse(wxCommandEvent& event) +void cSettings::OnClickConfigBrowse(wxCommandEvent& event) { wxString initial_dir = wxGetHomeDir(); @@ -217,7 +215,7 @@ void Settings::OnClickConfigBrowse(wxCommandEvent& event) case wxID_OK: { wxString path = dir_dialog.GetPath(); - m_ConfigText->SetValue(path + "/config.yaml"); + m_pConfigText->SetValue(path + "/config.yaml"); break; } default: @@ -225,7 +223,7 @@ void Settings::OnClickConfigBrowse(wxCommandEvent& event) } } -void Settings::OnClickDatabaseBrowse(wxCommandEvent& event) +void cSettings::OnClickDatabaseBrowse(wxCommandEvent& event) { wxString initial_dir = wxGetHomeDir(); @@ -240,7 +238,7 @@ void Settings::OnClickDatabaseBrowse(wxCommandEvent& event) case wxID_OK: { wxString path = dir_dialog.GetPath(); - m_DatabaseText->SetValue(path + "/config.yaml"); + m_pDatabaseText->SetValue(path + "/config.yaml"); break; } default: @@ -248,56 +246,56 @@ void Settings::OnClickDatabaseBrowse(wxCommandEvent& event) } } -void Settings::OnCheckAutoImport(wxCommandEvent& event) +void cSettings::OnCheckAutoImport(wxCommandEvent& event) { - Serializer serializer; + SampleHive::cSerializer serializer; - if (!m_AutoImportCheck->GetValue()) + if (!m_pAutoImportCheck->GetValue()) { - bAutoImport = false; - m_ImportDirLocation->Disable(); - m_BrowseAutoImportDirButton->Disable(); - m_FollowSymLinksCheck->Disable(); - m_RecursiveImportCheck->Disable(); + m_bAutoImport = false; + m_pImportDirLocation->Disable(); + m_pBrowseAutoImportDirButton->Disable(); + m_pFollowSymLinksCheck->Disable(); + m_pRecursiveImportCheck->Disable(); - serializer.SerializeAutoImport(bAutoImport, m_ImportDirLocation->GetValue().ToStdString()); + serializer.SerializeAutoImport(m_bAutoImport, m_pImportDirLocation->GetValue().ToStdString()); } else { - bAutoImport = true; - m_ImportDirLocation->Enable(); - m_BrowseAutoImportDirButton->Enable(); - m_FollowSymLinksCheck->Enable(); - m_RecursiveImportCheck->Enable(); + m_bAutoImport = true; + m_pImportDirLocation->Enable(); + m_pBrowseAutoImportDirButton->Enable(); + m_pFollowSymLinksCheck->Enable(); + m_pRecursiveImportCheck->Enable(); - serializer.SerializeAutoImport(bAutoImport, m_ImportDirLocation->GetValue().ToStdString()); + serializer.SerializeAutoImport(m_bAutoImport, m_pImportDirLocation->GetValue().ToStdString()); } } -void Settings::OnCheckFollowSymLinks(wxCommandEvent& event) +void cSettings::OnCheckFollowSymLinks(wxCommandEvent& event) { - Serializer serializer; + SampleHive::cSerializer serializer; - serializer.SerializeFollowSymLink(m_FollowSymLinksCheck->GetValue()); + serializer.SerializeFollowSymLink(m_pFollowSymLinksCheck->GetValue()); } -void Settings::OnCheckRecursiveImport(wxCommandEvent& event) +void cSettings::OnCheckRecursiveImport(wxCommandEvent& event) { - Serializer serializer; + SampleHive::cSerializer serializer; - serializer.SerializeRecursiveImport(m_RecursiveImportCheck->GetValue()); + serializer.SerializeRecursiveImport(m_pRecursiveImportCheck->GetValue()); } -void Settings::OnCheckShowFileExtension(wxCommandEvent& event) +void cSettings::OnCheckShowFileExtension(wxCommandEvent& event) { - Serializer serializer; + SampleHive::cSerializer serializer; - serializer.SerializeShowFileExtension(m_ShowFileExtensionCheck->GetValue()); + serializer.SerializeShowFileExtension(m_pShowFileExtensionCheck->GetValue()); } -void Settings::OnClickBrowseAutoImportDir(wxCommandEvent& event) +void cSettings::OnClickBrowseAutoImportDir(wxCommandEvent& event) { - Serializer serializer; + SampleHive::cSerializer serializer; wxString initial_dir = wxGetHomeDir(); @@ -312,9 +310,9 @@ void Settings::OnClickBrowseAutoImportDir(wxCommandEvent& event) case wxID_OK: { wxString path = dir_dialog.GetPath(); - m_ImportDirLocation->SetValue(path); + m_pImportDirLocation->SetValue(path); - serializer.SerializeAutoImport(bAutoImport, m_ImportDirLocation->GetValue().ToStdString()); + serializer.SerializeAutoImport(m_bAutoImport, m_pImportDirLocation->GetValue().ToStdString()); break; } default: @@ -322,7 +320,7 @@ void Settings::OnClickBrowseAutoImportDir(wxCommandEvent& event) } } -void Settings::OnSelectFont(wxCommandEvent& event) +void cSettings::OnSelectFont(wxCommandEvent& event) { wxFontDialog font_dialog(this); @@ -333,16 +331,16 @@ void Settings::OnSelectFont(wxCommandEvent& event) wxFontData fontData = font_dialog.GetFontData(); m_Font = fontData.GetChosenFont(); - if (m_FontType->GetCount() > 1) + if (m_pFontType->GetCount() > 1) { - m_FontType->Delete(1); - m_FontType->AppendString(m_Font.GetFaceName()); - m_FontType->SetSelection(1); + m_pFontType->Delete(1); + m_pFontType->AppendString(m_Font.GetFaceName()); + m_pFontType->SetSelection(1); } else { - m_FontType->AppendString(m_Font.GetFaceName()); - m_FontType->SetSelection(1); + m_pFontType->AppendString(m_Font.GetFaceName()); + m_pFontType->SetSelection(1); } SetCustomFont(); @@ -354,29 +352,29 @@ void Settings::OnSelectFont(wxCommandEvent& event) PrintFont(); } -void Settings::OnChangeFontSize(wxSpinEvent& event) +void cSettings::OnChangeFontSize(wxSpinEvent& event) { - Serializer serializer; + SampleHive::cSerializer serializer; - int font_size = m_FontSize->GetValue(); + int font_size = m_pFontSize->GetValue(); - if (m_FontType->GetStringSelection() == "System default") + if (m_pFontType->GetStringSelection() == "System default") m_Font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT); m_Font.SetPointSize(font_size); serializer.SerializeFontSettings(m_Font); - m_Window->SetFont(m_Font); + m_pWindow->SetFont(m_Font); this->SetFont(m_Font); SH_LOG_DEBUG("Font size: {}", font_size); SH_LOG_DEBUG("Font size: {}", m_Font.GetPointSize()); } -void Settings::LoadDefaultConfig() +void cSettings::LoadDefaultConfig() { - Serializer serializer; + SampleHive::cSerializer serializer; wxFont sys_font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT); wxString system_font = sys_font.GetFaceName(); @@ -387,54 +385,54 @@ void Settings::LoadDefaultConfig() if (system_font != font_face) { - if (m_FontType->GetCount() > 1) + if (m_pFontType->GetCount() > 1) { - m_FontType->Delete(1); - m_FontType->AppendString(font_face); - m_FontType->SetSelection(1); + m_pFontType->Delete(1); + m_pFontType->AppendString(font_face); + m_pFontType->SetSelection(1); m_Font.SetFaceName(font_face); m_Font.SetPointSize(font_size); } else { - m_FontType->AppendString(font_face); - m_FontType->SetSelection(1); + m_pFontType->AppendString(font_face); + m_pFontType->SetSelection(1); m_Font.SetFaceName(font_face); m_Font.SetPointSize(font_size); } } - m_FontSize->SetValue(font_size); + m_pFontSize->SetValue(font_size); SetCustomFont(); - bAutoImport = serializer.DeserializeAutoImport().first; + m_bAutoImport = serializer.DeserializeAutoImport().first; - m_AutoImportCheck->SetValue(bAutoImport); - m_ImportDirLocation->SetValue(serializer.DeserializeAutoImport().second); - m_ShowFileExtensionCheck->SetValue(serializer.DeserializeShowFileExtension()); - m_FollowSymLinksCheck->SetValue(serializer.DeserializeFollowSymLink()); - m_RecursiveImportCheck->SetValue(serializer.DeserializeRecursiveImport()); + m_pAutoImportCheck->SetValue(m_bAutoImport); + m_pImportDirLocation->SetValue(serializer.DeserializeAutoImport().second); + m_pShowFileExtensionCheck->SetValue(serializer.DeserializeShowFileExtension()); + m_pFollowSymLinksCheck->SetValue(serializer.DeserializeFollowSymLink()); + m_pRecursiveImportCheck->SetValue(serializer.DeserializeRecursiveImport()); - if (bAutoImport) + if (m_bAutoImport) { - m_ImportDirLocation->Enable(); - m_BrowseAutoImportDirButton->Enable(); - m_FollowSymLinksCheck->Enable(); - m_RecursiveImportCheck->Enable(); + m_pImportDirLocation->Enable(); + m_pBrowseAutoImportDirButton->Enable(); + m_pFollowSymLinksCheck->Enable(); + m_pRecursiveImportCheck->Enable(); } } -void Settings::SetShowExtension(bool value) +void cSettings::SetShowExtension(bool value) { - Serializer serializer; + SampleHive::cSerializer serializer; - m_ShowFileExtensionCheck->SetValue(value); + m_pShowFileExtensionCheck->SetValue(value); serializer.SerializeShowFileExtension(value); } -void Settings::PrintFont() +void cSettings::PrintFont() { SH_LOG_DEBUG("Font face: {}", m_Font.GetFaceName()); SH_LOG_DEBUG("Font size: {}", m_Font.GetPointSize()); @@ -443,9 +441,9 @@ void Settings::PrintFont() SH_LOG_DEBUG("Font weight: {}", m_Font.GetWeightString()); } -void Settings::SetCustomFont() +void cSettings::SetCustomFont() { - Serializer serializer; + SampleHive::cSerializer serializer; wxFont sys_font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT); std::string system_font = sys_font.GetFaceName().ToStdString(); @@ -454,53 +452,56 @@ void Settings::SetCustomFont() wxString font_face = serializer.DeserializeFontSettings().GetFaceName(); int font_size = serializer.DeserializeFontSettings().GetPointSize(); - if (m_FontType->GetStringSelection() == "System default") + if (m_pFontType->GetStringSelection() == "System default") { - m_Window->SetFont(sys_font); + m_pWindow->SetFont(sys_font); this->SetFont(sys_font); serializer.SerializeFontSettings(sys_font); } else { - m_Window->SetFont(m_Font); + m_pWindow->SetFont(m_Font); this->SetFont(m_Font); serializer.SerializeFontSettings(m_Font); } } -wxString Settings::GetImportDirPath() +wxString cSettings::GetImportDirPath() { wxString dir = wxEmptyString; - if (m_AutoImportCheck->GetValue()) - dir = m_ImportDirLocation->GetValue(); + if (m_pAutoImportCheck->GetValue()) + dir = m_pImportDirLocation->GetValue(); return dir; } -void Settings::OnChangeWaveformColour(wxColourPickerEvent& event) +void cSettings::OnChangeWaveformColour(wxColourPickerEvent& event) { - Serializer serializer; - wxColour colour = m_WaveformColourPickerCtrl->GetColour(); + SampleHive::cSerializer serializer; + wxColour colour = m_pWaveformColourPickerCtrl->GetColour(); wxColour wave_colour = serializer.DeserializeWaveformColour(); if (colour != wave_colour) { SH_LOG_INFO("Waveform colour changed."); - bWaveformColourChanged = true; + m_bWaveformColourChanged = true; serializer.SerializeWaveformColour(colour); } else { SH_LOG_INFO("Waveform colour not changed."); - bWaveformColourChanged = false; + m_bWaveformColourChanged = false; serializer.SerializeWaveformColour(colour); } } -Settings::~Settings(){} +cSettings::~cSettings() +{ + +} diff --git a/src/GUI/Dialogs/Settings.hpp b/src/GUI/Dialogs/Settings.hpp index 064744e..df24b58 100644 --- a/src/GUI/Dialogs/Settings.hpp +++ b/src/GUI/Dialogs/Settings.hpp @@ -40,89 +40,11 @@ #include #include -class Settings : public wxDialog +class cSettings : public wxDialog { public: - Settings(wxWindow* window); - ~Settings(); - - private: - // ------------------------------------------------------------------- - wxWindow* m_Window; - - private: - // ------------------------------------------------------------------- - // Top panel for wxDialog - wxPanel* m_Panel; - - // ------------------------------------------------------------------- - // Notebook page panels - wxPanel* m_DisplaySettingPanel; - wxPanel* m_CollectionSettingPanel; - wxPanel* m_ConfigurationSettingPanel; - - // ------------------------------------------------------------------- - // Top panel sizers - wxBoxSizer* m_MainSizer; - wxBoxSizer* m_NotebookSizer; - wxBoxSizer* m_ButtonSizer; - - // ------------------------------------------------------------------- - // Notebook - wxNotebook* m_Notebook; - - // ------------------------------------------------------------------- - // Display page - wxBoxSizer* m_DisplayTopSizer; - wxBoxSizer* m_DisplayFontSizer; - wxStaticText* m_RowHeightText; - wxStaticText* m_FontTypeText; - wxChoice* m_RowHeight; - wxChoice* m_FontType; - wxButton* m_FontBrowseButton; - wxSpinCtrl* m_FontSize; - wxBoxSizer* m_WaveformColourSizer; - wxStaticText* m_WaveformColourLabel; - wxColourPickerCtrl* m_WaveformColourPickerCtrl; - - // ------------------------------------------------------------------- - // Collection page - wxBoxSizer* m_CollectionMainSizer; - wxBoxSizer* m_CollectionImportDirSizer; - wxBoxSizer* m_CollectionImportOptionsSizer; - wxBoxSizer* m_CollectionShowExtensionSizer; - wxCheckBox* m_AutoImportCheck; - wxCheckBox* m_FollowSymLinksCheck; - wxCheckBox* m_RecursiveImportCheck; - wxCheckBox* m_ShowFileExtensionCheck; - wxTextCtrl* m_ImportDirLocation; - wxButton* m_BrowseAutoImportDirButton; - - // ------------------------------------------------------------------- - // General configuration page - wxFlexGridSizer* m_GeneralMainSizer; - wxStaticText* m_ConfigLabel; - wxStaticText* m_DatabaseLabel; - wxTextCtrl* m_ConfigText; - wxTextCtrl* m_DatabaseText; - wxButton* m_ConfigBrowse; - wxButton* m_DatabaseBrowse; - - // ------------------------------------------------------------------- - // Common buttons for wxDialog - wxButton* m_OkButton; - wxButton* m_CancelButton; - - private: - // ------------------------------------------------------------------- - wxFont m_Font; - - private: - // ------------------------------------------------------------------- - bool bAutoImport = false; - // bool bFollowSymLinks = false; - // bool bShowExtension = true; - bool bWaveformColourChanged = false; + cSettings(wxWindow* window); + ~cSettings(); private: // ------------------------------------------------------------------- @@ -150,13 +72,88 @@ class Settings : public wxDialog wxString GetImportDirPath(); // inline wxFont GetFontType() { return m_Font; }; - inline bool CanAutoImport() { return bAutoImport; }; - // inline bool ShouldFollowSymLinks() { return bFollowSymLinks; }; - // inline bool ShouldShowFileExtension() { return bShowExtension; }; - inline bool IsWaveformColourChanged() { return bWaveformColourChanged; } - // inline wxColour GetWaveformColour() { return m_WaveformColourPickerCtrl->GetColour(); } + inline bool CanAutoImport() { return m_bAutoImport; }; + inline bool IsWaveformColourChanged() { return m_bWaveformColourChanged; } // ------------------------------------------------------------------- // Setters void SetShowExtension(bool value); + + private: + // ------------------------------------------------------------------- + wxWindow* m_pWindow = nullptr; + + private: + // ------------------------------------------------------------------- + // Top panel for wxDialog + wxPanel* m_pPanel = nullptr; + + // ------------------------------------------------------------------- + // Notebook page panels + wxPanel* m_pDisplaySettingPanel = nullptr; + wxPanel* m_pCollectionSettingPanel = nullptr; + wxPanel* m_pConfigurationSettingPanel = nullptr; + + // ------------------------------------------------------------------- + // Top panel sizers + wxBoxSizer* m_pMainSizer = nullptr; + wxBoxSizer* m_pNotebookSizer = nullptr; + wxBoxSizer* m_pButtonSizer = nullptr; + + // ------------------------------------------------------------------- + // Notebook + wxNotebook* m_pNotebook = nullptr; + + // ------------------------------------------------------------------- + // Display page + wxBoxSizer* m_pDisplayTopSizer = nullptr; + wxBoxSizer* m_pDisplayFontSizer = nullptr; + wxStaticText* m_pRowHeightText = nullptr; + wxStaticText* m_pFontTypeText = nullptr; + wxChoice* m_pRowHeight = nullptr; + wxChoice* m_pFontType = nullptr; + wxButton* m_pFontBrowseButton = nullptr; + wxSpinCtrl* m_pFontSize = nullptr; + wxBoxSizer* m_pWaveformColourSizer = nullptr; + wxStaticText* m_pWaveformColourLabel = nullptr; + wxColourPickerCtrl* m_pWaveformColourPickerCtrl = nullptr; + + // ------------------------------------------------------------------- + // Collection page + wxBoxSizer* m_pCollectionMainSizer = nullptr; + wxBoxSizer* m_pCollectionImportDirSizer = nullptr; + wxBoxSizer* m_pCollectionImportOptionsSizer = nullptr; + wxBoxSizer* m_pCollectionShowExtensionSizer = nullptr; + wxCheckBox* m_pAutoImportCheck = nullptr; + wxCheckBox* m_pFollowSymLinksCheck = nullptr; + wxCheckBox* m_pRecursiveImportCheck = nullptr; + wxCheckBox* m_pShowFileExtensionCheck = nullptr; + wxTextCtrl* m_pImportDirLocation = nullptr; + wxButton* m_pBrowseAutoImportDirButton = nullptr; + + // ------------------------------------------------------------------- + // General configuration page + wxFlexGridSizer* m_pGeneralMainSizer = nullptr; + wxStaticText* m_pConfigLabel = nullptr; + wxStaticText* m_pDatabaseLabel = nullptr; + wxTextCtrl* m_pConfigText = nullptr; + wxTextCtrl* m_pDatabaseText = nullptr; + wxButton* m_pConfigBrowse = nullptr; + wxButton* m_pDatabaseBrowse = nullptr; + + // ------------------------------------------------------------------- + // Common buttons for wxDialog + wxButton* m_pOkButton = nullptr; + wxButton* m_pCancelButton = nullptr; + + private: + // ------------------------------------------------------------------- + wxFont m_Font; + + private: + // ------------------------------------------------------------------- + bool m_bAutoImport = false; + // bool bFollowSymLinks = false; + // bool bShowExtension = true; + bool m_bWaveformColourChanged = false; }; diff --git a/src/GUI/Dialogs/TagEditor.cpp b/src/GUI/Dialogs/TagEditor.cpp index fdfe52d..fe1717c 100644 --- a/src/GUI/Dialogs/TagEditor.cpp +++ b/src/GUI/Dialogs/TagEditor.cpp @@ -18,13 +18,13 @@ * along with this program. If not, see . */ +#include "GUI/Dialogs/TagEditor.hpp" +#include "Database/Database.hpp" #include "Utility/ControlIDs.hpp" -#include "Utility/SH_Event.hpp" -#include "Utility/Signal.hpp" #include "Utility/Log.hpp" #include "Utility/Paths.hpp" -#include "Database/Database.hpp" -#include "GUI/Dialogs/TagEditor.hpp" +#include "Utility/Event.hpp" +#include "Utility/Signal.hpp" #include #include @@ -32,179 +32,179 @@ #include #include -TagEditor::TagEditor(wxWindow* window, const std::string& filename) +cTagEditor::cTagEditor(wxWindow* window, const std::string& filename) : wxDialog(window, wxID_ANY, "Edit tags", wxDefaultPosition, wxSize(640, 360), wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP), - m_Window(window), m_Filename(filename), tags(filename) + m_pWindow(window), m_Filename(filename), tags(filename) { - m_Panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize); + m_pPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize); - m_MainSizer = new wxBoxSizer(wxVERTICAL); - m_ButtonSizer = new wxBoxSizer(wxHORIZONTAL); - m_EditTagSizer = new wxFlexGridSizer(6, 2, 0, 0); - m_EditTagSizer->AddGrowableCol(1); - m_EditTagSizer->SetFlexibleDirection(wxBOTH); - m_EditTagSizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED); - m_SampleTypeSizer = new wxFlexGridSizer(1, 3, 0, 0); - m_SampleTypeSizer->AddGrowableCol(1); - m_SampleTypeSizer->SetFlexibleDirection(wxBOTH); - m_SampleTypeSizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED); - m_StaticEditTagSizer = new wxStaticBoxSizer(wxVERTICAL, m_Panel, "Edit tags"); - m_StaticSampleTypeSizer = new wxStaticBoxSizer(wxVERTICAL, m_Panel, "Sample type"); + m_pMainSizer = new wxBoxSizer(wxVERTICAL); + m_pButtonSizer = new wxBoxSizer(wxHORIZONTAL); + m_pEditTagSizer = new wxFlexGridSizer(6, 2, 0, 0); + m_pEditTagSizer->AddGrowableCol(1); + m_pEditTagSizer->SetFlexibleDirection(wxBOTH); + m_pEditTagSizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED); + m_pSampleTypeSizer = new wxFlexGridSizer(1, 3, 0, 0); + m_pSampleTypeSizer->AddGrowableCol(1); + m_pSampleTypeSizer->SetFlexibleDirection(wxBOTH); + m_pSampleTypeSizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED); + m_pStaticEditTagSizer = new wxStaticBoxSizer(wxVERTICAL, m_pPanel, "Edit tags"); + m_pStaticSampleTypeSizer = new wxStaticBoxSizer(wxVERTICAL, m_pPanel, "Sample type"); wxString choices[] = {"Kick", "Snare", "Clap", "HiHat", "Cymbal", "Cowbell", "Ride", "Tom", "Shaker", "Percussion"}; - m_TitleCheck = new wxCheckBox(m_Panel, ET_TitleCheck, "Title", wxDefaultPosition, wxDefaultSize); - m_ArtistCheck = new wxCheckBox(m_Panel, ET_ArtistCheck, "Artist", wxDefaultPosition, wxDefaultSize); - m_AlbumCheck = new wxCheckBox(m_Panel, ET_AlbumCheck, "Album", wxDefaultPosition, wxDefaultSize); - m_GenreCheck = new wxCheckBox(m_Panel, ET_GenreCheck, "Genre", wxDefaultPosition, wxDefaultSize); - m_CommentCheck = new wxCheckBox(m_Panel, ET_CommentsCheck, "Comments", wxDefaultPosition, wxDefaultSize); - m_SampleTypeCheck = new wxCheckBox(m_Panel, ET_TypeCheck, "Type", wxDefaultPosition, wxDefaultSize); + m_pTitleCheck = new wxCheckBox(m_pPanel, SampleHive::ID::ET_TitleCheck, "Title", wxDefaultPosition, wxDefaultSize); + m_pArtistCheck = new wxCheckBox(m_pPanel, SampleHive::ID::ET_ArtistCheck, "Artist", wxDefaultPosition, wxDefaultSize); + m_pAlbumCheck = new wxCheckBox(m_pPanel, SampleHive::ID::ET_AlbumCheck, "Album", wxDefaultPosition, wxDefaultSize); + m_pGenreCheck = new wxCheckBox(m_pPanel, SampleHive::ID::ET_GenreCheck, "Genre", wxDefaultPosition, wxDefaultSize); + m_pCommentCheck = new wxCheckBox(m_pPanel, SampleHive::ID::ET_CommentsCheck, "Comments", wxDefaultPosition, wxDefaultSize); + m_pSampleTypeCheck = new wxCheckBox(m_pPanel, SampleHive::ID::ET_TypeCheck, "Type", wxDefaultPosition, wxDefaultSize); - m_TitleText = new wxTextCtrl(m_Panel, wxID_ANY, tags.GetAudioInfo().title, wxDefaultPosition, wxDefaultSize); - m_TitleText->Disable(); - m_ArtistText = new wxTextCtrl(m_Panel, wxID_ANY, tags.GetAudioInfo().artist, wxDefaultPosition, wxDefaultSize); - m_ArtistText->Disable(); - m_AlbumText = new wxTextCtrl(m_Panel, wxID_ANY, tags.GetAudioInfo().album, wxDefaultPosition, wxDefaultSize); - m_AlbumText->Disable(); - m_GenreText = new wxTextCtrl(m_Panel, wxID_ANY, tags.GetAudioInfo().genre, wxDefaultPosition, wxDefaultSize); - m_GenreText->Disable(); - m_CommentText = new wxTextCtrl(m_Panel, wxID_ANY, tags.GetAudioInfo().comment, wxDefaultPosition, wxDefaultSize); - m_CommentText->Disable(); - m_SampleTypeChoice = new wxChoice(m_Panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 10, choices, wxCB_SORT); - m_SampleTypeChoice->Disable(); + m_pTitleText = new wxTextCtrl(m_pPanel, wxID_ANY, tags.GetAudioInfo().title, wxDefaultPosition, wxDefaultSize); + m_pTitleText->Disable(); + m_pArtistText = new wxTextCtrl(m_pPanel, wxID_ANY, tags.GetAudioInfo().artist, wxDefaultPosition, wxDefaultSize); + m_pArtistText->Disable(); + m_pAlbumText = new wxTextCtrl(m_pPanel, wxID_ANY, tags.GetAudioInfo().album, wxDefaultPosition, wxDefaultSize); + m_pAlbumText->Disable(); + m_pGenreText = new wxTextCtrl(m_pPanel, wxID_ANY, tags.GetAudioInfo().genre, wxDefaultPosition, wxDefaultSize); + m_pGenreText->Disable(); + m_pCommentText = new wxTextCtrl(m_pPanel, wxID_ANY, tags.GetAudioInfo().comment, wxDefaultPosition, wxDefaultSize); + m_pCommentText->Disable(); + m_pSampleTypeChoice = new wxChoice(m_pPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 10, choices, wxCB_SORT); + m_pSampleTypeChoice->Disable(); - m_SampleTypeButton = new wxButton(m_Panel, ET_CustomTag, "Custom", wxDefaultPosition, wxDefaultSize); - m_SampleTypeButton->Disable(); + m_pSampleTypeButton = new wxButton(m_pPanel, SampleHive::ID::ET_CustomTag, "Custom", wxDefaultPosition, wxDefaultSize); + m_pSampleTypeButton->Disable(); - m_OkButton = new wxButton(m_Panel, wxID_OK, "OK", wxDefaultPosition, wxDefaultSize); - m_ApplyButton = new wxButton(m_Panel, wxID_APPLY, "Apply", wxDefaultPosition, wxDefaultSize); - m_CancelButton = new wxButton(m_Panel, wxID_CANCEL, "Cancel", wxDefaultPosition, wxDefaultSize); + m_pOkButton = new wxButton(m_pPanel, wxID_OK, "OK", wxDefaultPosition, wxDefaultSize); + m_pApplyButton = new wxButton(m_pPanel, wxID_APPLY, "Apply", wxDefaultPosition, wxDefaultSize); + m_pCancelButton = new wxButton(m_pPanel, wxID_CANCEL, "Cancel", wxDefaultPosition, wxDefaultSize); // Binding events - Bind(wxEVT_CHECKBOX, &TagEditor::OnCheckTitle, this, ET_TitleCheck); - Bind(wxEVT_CHECKBOX, &TagEditor::OnCheckArtist, this, ET_ArtistCheck); - Bind(wxEVT_CHECKBOX, &TagEditor::OnCheckAlbum, this, ET_AlbumCheck); - Bind(wxEVT_CHECKBOX, &TagEditor::OnCheckGenre, this, ET_GenreCheck); - Bind(wxEVT_CHECKBOX, &TagEditor::OnCheckComments, this, ET_CommentsCheck); - Bind(wxEVT_CHECKBOX, &TagEditor::OnCheckType, this, ET_TypeCheck); + Bind(wxEVT_CHECKBOX, &cTagEditor::OnCheckTitle, this, SampleHive::ID::ET_TitleCheck); + Bind(wxEVT_CHECKBOX, &cTagEditor::OnCheckArtist, this, SampleHive::ID::ET_ArtistCheck); + Bind(wxEVT_CHECKBOX, &cTagEditor::OnCheckAlbum, this, SampleHive::ID::ET_AlbumCheck); + Bind(wxEVT_CHECKBOX, &cTagEditor::OnCheckGenre, this, SampleHive::ID::ET_GenreCheck); + Bind(wxEVT_CHECKBOX, &cTagEditor::OnCheckComments, this, SampleHive::ID::ET_CommentsCheck); + Bind(wxEVT_CHECKBOX, &cTagEditor::OnCheckType, this, SampleHive::ID::ET_TypeCheck); - Bind(wxEVT_BUTTON, &TagEditor::OnClickCustomTagButton, this, ET_CustomTag); + Bind(wxEVT_BUTTON, &cTagEditor::OnClickCustomTagButton, this, SampleHive::ID::ET_CustomTag); - Bind(wxEVT_BUTTON, &TagEditor::OnClickApply, this, wxID_APPLY); + Bind(wxEVT_BUTTON, &cTagEditor::OnClickApply, this, wxID_APPLY); - m_EditTagSizer->Add(m_TitleCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2); - m_EditTagSizer->Add(m_TitleText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2); + m_pEditTagSizer->Add(m_pTitleCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2); + m_pEditTagSizer->Add(m_pTitleText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2); - m_EditTagSizer->Add(m_ArtistCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2); - m_EditTagSizer->Add(m_ArtistText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2); + m_pEditTagSizer->Add(m_pArtistCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2); + m_pEditTagSizer->Add(m_pArtistText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2); - m_EditTagSizer->Add(m_AlbumCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2); - m_EditTagSizer->Add(m_AlbumText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2); + m_pEditTagSizer->Add(m_pAlbumCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2); + m_pEditTagSizer->Add(m_pAlbumText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2); - m_EditTagSizer->Add(m_GenreCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2); - m_EditTagSizer->Add(m_GenreText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2); + m_pEditTagSizer->Add(m_pGenreCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2); + m_pEditTagSizer->Add(m_pGenreText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2); - m_EditTagSizer->Add(m_CommentCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2); - m_EditTagSizer->Add(m_CommentText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2); + m_pEditTagSizer->Add(m_pCommentCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2); + m_pEditTagSizer->Add(m_pCommentText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2); - m_SampleTypeSizer->Add(m_SampleTypeCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2); - m_SampleTypeSizer->Add(m_SampleTypeChoice, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2); - m_SampleTypeSizer->Add(m_SampleTypeButton, 0, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 2); + m_pSampleTypeSizer->Add(m_pSampleTypeCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2); + m_pSampleTypeSizer->Add(m_pSampleTypeChoice, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2); + m_pSampleTypeSizer->Add(m_pSampleTypeButton, 0, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 2); - m_StaticEditTagSizer->Add(m_EditTagSizer, 1, wxALL | wxEXPAND, 2); - m_StaticSampleTypeSizer->Add(m_SampleTypeSizer, 1, wxALL | wxEXPAND, 2); + m_pStaticEditTagSizer->Add(m_pEditTagSizer, 1, wxALL | wxEXPAND, 2); + m_pStaticSampleTypeSizer->Add(m_pSampleTypeSizer, 1, wxALL | wxEXPAND, 2); - m_ButtonSizer->Add(m_OkButton, 0, wxALL | wxALIGN_BOTTOM, 2); - m_ButtonSizer->Add(m_ApplyButton, 0, wxALL | wxALIGN_BOTTOM, 2); - m_ButtonSizer->Add(m_CancelButton, 0, wxALL | wxALIGN_BOTTOM, 2); + m_pButtonSizer->Add(m_pOkButton, 0, wxALL | wxALIGN_BOTTOM, 2); + m_pButtonSizer->Add(m_pApplyButton, 0, wxALL | wxALIGN_BOTTOM, 2); + m_pButtonSizer->Add(m_pCancelButton, 0, wxALL | wxALIGN_BOTTOM, 2); - m_MainSizer->Add(m_StaticEditTagSizer, 1, wxALL | wxEXPAND, 2); - m_MainSizer->Add(m_StaticSampleTypeSizer, 1, wxALL | wxEXPAND, 2); - m_MainSizer->Add(m_ButtonSizer, 0, wxALL | wxALIGN_RIGHT, 2); + m_pMainSizer->Add(m_pStaticEditTagSizer, 1, wxALL | wxEXPAND, 2); + m_pMainSizer->Add(m_pStaticSampleTypeSizer, 1, wxALL | wxEXPAND, 2); + m_pMainSizer->Add(m_pButtonSizer, 0, wxALL | wxALIGN_RIGHT, 2); // Top panel layout - m_Panel->SetSizer(m_MainSizer); - m_MainSizer->Fit(m_Panel); - m_MainSizer->SetSizeHints(m_Panel); - m_MainSizer->Layout(); + m_pPanel->SetSizer(m_pMainSizer); + m_pMainSizer->Fit(m_pPanel); + m_pMainSizer->SetSizeHints(m_pPanel); + m_pMainSizer->Layout(); } -void TagEditor::OnCheckTitle(wxCommandEvent &event) +void cTagEditor::OnCheckTitle(wxCommandEvent &event) { - if (m_TitleCheck->GetValue()) + if (m_pTitleCheck->GetValue()) { - m_TitleText->Enable(); + m_pTitleText->Enable(); } else { - m_TitleText->Disable(); + m_pTitleText->Disable(); } } -void TagEditor::OnCheckArtist(wxCommandEvent &event) +void cTagEditor::OnCheckArtist(wxCommandEvent &event) { - if (m_ArtistCheck->GetValue()) + if (m_pArtistCheck->GetValue()) { - m_ArtistText->Enable(); + m_pArtistText->Enable(); } else { - m_ArtistText->Disable(); + m_pArtistText->Disable(); } } -void TagEditor::OnCheckAlbum(wxCommandEvent &event) +void cTagEditor::OnCheckAlbum(wxCommandEvent &event) { - if (m_AlbumCheck->GetValue()) + if (m_pAlbumCheck->GetValue()) { - m_AlbumText->Enable(); + m_pAlbumText->Enable(); } else { - m_AlbumText->Disable(); + m_pAlbumText->Disable(); } } -void TagEditor::OnCheckGenre(wxCommandEvent &event) +void cTagEditor::OnCheckGenre(wxCommandEvent &event) { - if (m_GenreCheck->GetValue()) + if (m_pGenreCheck->GetValue()) { - m_GenreText->Enable(); + m_pGenreText->Enable(); } else { - m_GenreText->Disable(); + m_pGenreText->Disable(); } } -void TagEditor::OnCheckComments(wxCommandEvent &event) +void cTagEditor::OnCheckComments(wxCommandEvent &event) { - if (m_CommentCheck->GetValue()) + if (m_pCommentCheck->GetValue()) { - m_CommentText->Enable(); + m_pCommentText->Enable(); } else { - m_CommentText->Disable(); + m_pCommentText->Disable(); } } -void TagEditor::OnCheckType(wxCommandEvent &event) +void cTagEditor::OnCheckType(wxCommandEvent &event) { - if (m_SampleTypeCheck->GetValue()) + if (m_pSampleTypeCheck->GetValue()) { - m_SampleTypeChoice->Enable(); - m_SampleTypeButton->Enable(); + m_pSampleTypeChoice->Enable(); + m_pSampleTypeButton->Enable(); } else { - m_SampleTypeChoice->Disable(); - m_SampleTypeButton->Disable(); + m_pSampleTypeChoice->Disable(); + m_pSampleTypeButton->Disable(); } } -void TagEditor::OnClickCustomTagButton(wxCommandEvent& event) +void cTagEditor::OnClickCustomTagButton(wxCommandEvent& event) { wxTextEntryDialog* customTag; customTag = new wxTextEntryDialog(this, "Enter a custom tag", @@ -216,8 +216,8 @@ void TagEditor::OnClickCustomTagButton(wxCommandEvent& event) case wxID_OK: { wxString tag = customTag->GetValue(); - m_SampleTypeChoice->AppendString(tag); - m_SampleTypeChoice->SetStringSelection(tag); + m_pSampleTypeChoice->AppendString(tag); + m_pSampleTypeChoice->SetStringSelection(tag); break; } case wxID_CANCEL: @@ -227,16 +227,16 @@ void TagEditor::OnClickCustomTagButton(wxCommandEvent& event) } } -void TagEditor::OnClickApply(wxCommandEvent& event) +void cTagEditor::OnClickApply(wxCommandEvent& event) { - Database db; + cDatabase db; - wxString title = m_TitleText->GetValue(); - wxString artist = m_ArtistText->GetValue(); - wxString album = m_AlbumText->GetValue(); - wxString genre = m_GenreText->GetValue(); - wxString comment = m_CommentText->GetValue(); - wxString type = m_SampleTypeChoice->GetStringSelection(); + wxString title = m_pTitleText->GetValue(); + wxString artist = m_pArtistText->GetValue(); + wxString album = m_pAlbumText->GetValue(); + wxString genre = m_pGenreText->GetValue(); + wxString comment = m_pCommentText->GetValue(); + wxString type = m_pSampleTypeChoice->GetStringSelection(); std::string sampleType = db.GetSampleType(m_Filename); @@ -255,7 +255,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event) switch (msgDialog->ShowModal()) { case wxID_YES: - if (m_TitleCheck->GetValue() && m_TitleText->GetValue() != tags.GetAudioInfo().title) + if (m_pTitleCheck->GetValue() && m_pTitleText->GetValue() != tags.GetAudioInfo().title) { SH_LOG_INFO("Changing title tag.."); tags.SetTitle(title.ToStdString()); @@ -263,7 +263,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event) info_msg = wxString::Format("Successfully changed title tag to %s", title); } - if (m_ArtistCheck->GetValue() && m_ArtistText->GetValue() != tags.GetAudioInfo().artist) + if (m_pArtistCheck->GetValue() && m_pArtistText->GetValue() != tags.GetAudioInfo().artist) { SH_LOG_INFO("Changing artist tag.."); tags.SetArtist(artist.ToStdString()); @@ -275,7 +275,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event) info_msg = wxString::Format("Successfully changed artist tag to %s", artist); } - if (m_AlbumCheck->GetValue() && m_AlbumText->GetValue() != tags.GetAudioInfo().album) + if (m_pAlbumCheck->GetValue() && m_pAlbumText->GetValue() != tags.GetAudioInfo().album) { SH_LOG_INFO("Changing album tag.."); tags.SetAlbum(album.ToStdString()); @@ -283,7 +283,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event) info_msg = wxString::Format("Successfully changed album tag to %s", album); } - if (m_GenreCheck->GetValue() && m_GenreText->GetValue() != tags.GetAudioInfo().genre) + if (m_pGenreCheck->GetValue() && m_pGenreText->GetValue() != tags.GetAudioInfo().genre) { SH_LOG_INFO("Changing genre tag.."); tags.SetGenre(genre.ToStdString()); @@ -291,7 +291,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event) info_msg = wxString::Format("Successfully changed genre tag to %s", genre); } - if (m_CommentCheck->GetValue() && m_CommentText->GetValue() != tags.GetAudioInfo().comment) + if (m_pCommentCheck->GetValue() && m_pCommentText->GetValue() != tags.GetAudioInfo().comment) { SH_LOG_INFO("Changing comment tag.."); tags.SetComment(comment.ToStdString()); @@ -299,7 +299,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event) info_msg = wxString::Format("Successfully changed comment tag to %s", comment); } - if (m_SampleTypeCheck->GetValue() && m_SampleTypeChoice->GetStringSelection() != sampleType) + if (m_pSampleTypeCheck->GetValue() && m_pSampleTypeChoice->GetStringSelection() != sampleType) { SH_LOG_INFO("Changing type tag.."); db.UpdateSampleType(filename, type.ToStdString()); @@ -313,10 +313,10 @@ void TagEditor::OnClickApply(wxCommandEvent& event) info_msg = "Error, cannot change tag!"; } - SampleHive::Signal::SendInfoBarMessage(info_msg, wxICON_INFORMATION, *this, true); + SampleHive::cSignal::SendInfoBarMessage(info_msg, wxICON_INFORMATION, *this, true); } -// void TagEditor::SendInfoBarMessage(const wxString& msg, int mode) +// void cTagEditor::SendInfoBarMessage(const wxString& msg, int mode) // { // SH_LOG_INFO("{} called..", __FUNCTION__); @@ -328,7 +328,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event) // GetParent()->GetEventHandler()->ProcessEvent(event); // } -TagEditor::~TagEditor() +cTagEditor::~cTagEditor() { } diff --git a/src/GUI/Dialogs/TagEditor.hpp b/src/GUI/Dialogs/TagEditor.hpp index b2a62f1..4a8ddf8 100644 --- a/src/GUI/Dialogs/TagEditor.hpp +++ b/src/GUI/Dialogs/TagEditor.hpp @@ -36,58 +36,11 @@ #include #include -class TagEditor : public wxDialog +class cTagEditor : public wxDialog { public: - TagEditor(wxWindow* window, const std::string& filename); - ~TagEditor(); - - private: - // ------------------------------------------------------------------- - wxWindow* m_Window; - - // ------------------------------------------------------------------- - const std::string m_Filename; - - private: - // ------------------------------------------------------------------- - // Top panel for wxDialog - wxPanel* m_Panel; - - // ------------------------------------------------------------------- - // Top panel sizers - wxBoxSizer* m_MainSizer; - wxFlexGridSizer* m_EditTagSizer; - wxFlexGridSizer* m_SampleTypeSizer; - wxBoxSizer* m_ButtonSizer; - wxStaticBoxSizer* m_StaticEditTagSizer; - wxStaticBoxSizer* m_StaticSampleTypeSizer; - - // ------------------------------------------------------------------- - // Dialog controls - wxCheckBox* m_TitleCheck; - wxCheckBox* m_ArtistCheck; - wxCheckBox* m_AlbumCheck; - wxCheckBox* m_GenreCheck; - wxCheckBox* m_CommentCheck; - wxCheckBox* m_SampleTypeCheck; - wxTextCtrl* m_TitleText; - wxTextCtrl* m_ArtistText; - wxTextCtrl* m_AlbumText; - wxTextCtrl* m_GenreText; - wxTextCtrl* m_CommentText; - wxChoice* m_SampleTypeChoice; - wxButton* m_SampleTypeButton; - - // ------------------------------------------------------------------- - // Common buttons for wxDialog - wxButton* m_OkButton; - wxButton* m_ApplyButton; - wxButton* m_CancelButton; - - private: - // ------------------------------------------------------------------- - Tags tags; + cTagEditor(wxWindow* window, const std::string& filename); + ~cTagEditor(); private: // ------------------------------------------------------------------- @@ -105,6 +58,50 @@ class TagEditor : public wxDialog // ------------------------------------------------------------------- void OnClickApply(wxCommandEvent& event); + private: // ------------------------------------------------------------------- - // void SendInfoBarMessage(const wxString& msg, int mode); + wxWindow* m_pWindow = nullptr; + + // ------------------------------------------------------------------- + const std::string& m_Filename; + + private: + // ------------------------------------------------------------------- + // Top panel for wxDialog + wxPanel* m_pPanel = nullptr; + + // ------------------------------------------------------------------- + // Top panel sizers + wxBoxSizer* m_pMainSizer = nullptr; + wxFlexGridSizer* m_pEditTagSizer = nullptr; + wxFlexGridSizer* m_pSampleTypeSizer = nullptr; + wxBoxSizer* m_pButtonSizer = nullptr; + wxStaticBoxSizer* m_pStaticEditTagSizer = nullptr; + wxStaticBoxSizer* m_pStaticSampleTypeSizer = nullptr; + + // ------------------------------------------------------------------- + // Dialog controls + wxCheckBox* m_pTitleCheck = nullptr; + wxCheckBox* m_pArtistCheck = nullptr; + wxCheckBox* m_pAlbumCheck = nullptr; + wxCheckBox* m_pGenreCheck = nullptr; + wxCheckBox* m_pCommentCheck = nullptr; + wxCheckBox* m_pSampleTypeCheck = nullptr; + wxTextCtrl* m_pTitleText = nullptr; + wxTextCtrl* m_pArtistText = nullptr; + wxTextCtrl* m_pAlbumText = nullptr; + wxTextCtrl* m_pGenreText = nullptr; + wxTextCtrl* m_pCommentText = nullptr; + wxChoice* m_pSampleTypeChoice = nullptr; + wxButton* m_pSampleTypeButton = nullptr; + + // ------------------------------------------------------------------- + // Common buttons for wxDialog + wxButton* m_pOkButton = nullptr; + wxButton* m_pApplyButton = nullptr; + wxButton* m_pCancelButton = nullptr; + + private: + // ------------------------------------------------------------------- + SampleHive::cTags tags; }; diff --git a/src/GUI/DirectoryBrowser.cpp b/src/GUI/DirectoryBrowser.cpp index 3de7a15..1181570 100644 --- a/src/GUI/DirectoryBrowser.cpp +++ b/src/GUI/DirectoryBrowser.cpp @@ -1,20 +1,42 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "GUI/DirectoryBrowser.hpp" -#include "Utility/Paths.hpp" #include "Utility/ControlIDs.hpp" #include "Utility/Log.hpp" +#include "Utility/Paths.hpp" +#include "Utility/Utils.hpp" #include #include cDirectoryBrowser::cDirectoryBrowser(wxWindow* window) - : wxGenericDirCtrl(window, BC_DirCtrl, wxDirDialogDefaultFolderStr, wxDefaultPosition, + : wxGenericDirCtrl(window, SampleHive::ID::BC_DirCtrl, wxDirDialogDefaultFolderStr, wxDefaultPosition, wxDefaultSize, wxDIRCTRL_SHOW_FILTERS, _("All files|*|Ogg files (*.ogg)|*.ogg|Wav files (*.wav)|*.wav|" - "Flac files (*.flac)|*.flac"), 0) + "Flac files (*.flac)|*.flac"), 0), + m_pWindow(window) { SetPath(USER_HOME_DIR); - Bind(wxEVT_DIRCTRL_FILEACTIVATED, &cDirectoryBrowser::OnClickDirCtrl, this, BC_DirCtrl); + Bind(wxEVT_DIRCTRL_FILEACTIVATED, &cDirectoryBrowser::OnClickDirCtrl, this, SampleHive::ID::BC_DirCtrl); Bind(wxEVT_TREE_BEGIN_DRAG, &cDirectoryBrowser::OnDragFromDirCtrl, this, this->GetTreeCtrl()->GetId()); } @@ -23,8 +45,24 @@ void cDirectoryBrowser::OnClickDirCtrl(wxCommandEvent& event) wxArrayString path; path.push_back(this->GetFilePath()); - // TODO - // AddSamples(path); + SampleHive::cUtils::Get().AddSamples(path, m_pWindow); +} + +// Temporary function to check drag and drop result +void LogDragResult(wxDragResult result) +{ + wxString msg; + switch (result) + { + case wxDragError: msg = "Error!"; break; + case wxDragNone: msg = "Nothing"; break; + case wxDragCopy: msg = "Copied"; break; + case wxDragMove: msg = "Moved"; break; + case wxDragCancel: msg = "Cancelled"; break; + default: msg = "Huh?"; break; + } + + SH_LOG_DEBUG("Drag result: {}", msg); } void cDirectoryBrowser::OnDragFromDirCtrl(wxTreeEvent& event) @@ -35,7 +73,7 @@ void cDirectoryBrowser::OnDragFromDirCtrl(wxTreeEvent& event) wxDropSource drop_source(this); drop_source.SetData(file_data); - // LogDragResult(drop_source.DoDragDrop()); + LogDragResult(drop_source.DoDragDrop()); } cDirectoryBrowser::~cDirectoryBrowser() diff --git a/src/GUI/DirectoryBrowser.hpp b/src/GUI/DirectoryBrowser.hpp index 26d1dbc..626b010 100644 --- a/src/GUI/DirectoryBrowser.hpp +++ b/src/GUI/DirectoryBrowser.hpp @@ -1,3 +1,23 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #include @@ -15,4 +35,7 @@ class cDirectoryBrowser : public wxGenericDirCtrl // DirCtrl event handlers void OnClickDirCtrl(wxCommandEvent& event); void OnDragFromDirCtrl(wxTreeEvent& event); + + private: + wxWindow* m_pWindow = nullptr; }; diff --git a/src/GUI/Hives.cpp b/src/GUI/Hives.cpp index a1a6fce..d7f2c8a 100644 --- a/src/GUI/Hives.cpp +++ b/src/GUI/Hives.cpp @@ -1,11 +1,31 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "GUI/Hives.hpp" -#include "GUI/ListCtrl.hpp" #include "Database/Database.hpp" #include "Utility/ControlIDs.hpp" +#include "Utility/HiveData.hpp" +#include "Utility/Log.hpp" #include "Utility/Paths.hpp" #include "Utility/Signal.hpp" #include "Utility/Serialize.hpp" -#include "Utility/Log.hpp" #include @@ -13,27 +33,26 @@ #include #include -cHivesPanel::cHivesPanel(wxWindow* window, wxDataViewListCtrl& listCtrl) +cHivesPanel::cHivesPanel(wxWindow* window) : wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL), - m_ListCtrl(listCtrl), m_pWindow(window) + m_pWindow(window) { m_pMainSizer = new wxBoxSizer(wxVERTICAL); m_pHivesSizer = new wxBoxSizer(wxVERTICAL); m_pButtonSizer = new wxBoxSizer(wxHORIZONTAL); - m_pAddHiveButton = new wxButton(this, BC_HiveAdd, "+", wxDefaultPosition, wxDefaultSize, 0); + m_pAddHiveButton = new wxButton(this, SampleHive::ID::BC_HiveAdd, "+", wxDefaultPosition, wxDefaultSize, 0); m_pAddHiveButton->SetToolTip(_("Create new hive")); m_pButtonSizer->Add(m_pAddHiveButton, wxSizerFlags(1).Expand()); - m_pRemoveHiveButton = new wxButton(this, BC_HiveRemove, "-", wxDefaultPosition, wxDefaultSize, 0); + m_pRemoveHiveButton = new wxButton(this, SampleHive::ID::BC_HiveRemove, "-", wxDefaultPosition, wxDefaultSize, 0); m_pRemoveHiveButton->SetToolTip(_("Delete selected hive")); m_pButtonSizer->Add(m_pRemoveHiveButton, wxSizerFlags(1).Expand()); // Initializing wxDataViewTreeCtrl as another page of wxNotebook - m_pHives = new wxDataViewTreeCtrl(this, BC_Hives, wxDefaultPosition, wxDefaultSize, - wxDV_NO_HEADER | wxDV_SINGLE); + m_pHives = new wxDataViewTreeCtrl(this, SampleHive::ID::BC_Hives, wxDefaultPosition, wxDefaultSize, wxDV_NO_HEADER | wxDV_SINGLE); m_pHivesSizer->Add(m_pHives, wxSizerFlags(1).Expand()); @@ -44,10 +63,10 @@ cHivesPanel::cHivesPanel(wxWindow* window, wxDataViewListCtrl& listCtrl) m_pHives->DragAcceptFiles(true); m_pHives->Connect(wxEVT_DROP_FILES, wxDropFilesEventHandler(cHivesPanel::OnDragAndDropToHives), NULL, this); - Bind(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &cHivesPanel::OnShowHivesContextMenu, this, BC_Hives); - Bind(wxEVT_DATAVIEW_ITEM_START_EDITING, &cHivesPanel::OnHiveStartEditing, this, BC_Hives); - Bind(wxEVT_BUTTON, &cHivesPanel::OnClickAddHive, this, BC_HiveAdd); - Bind(wxEVT_BUTTON, &cHivesPanel::OnClickRemoveHive, this, BC_HiveRemove); + Bind(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &cHivesPanel::OnShowHivesContextMenu, this, SampleHive::ID::BC_Hives); + Bind(wxEVT_DATAVIEW_ITEM_START_EDITING, &cHivesPanel::OnHiveStartEditing, this, SampleHive::ID::BC_Hives); + Bind(wxEVT_BUTTON, &cHivesPanel::OnClickAddHive, this, SampleHive::ID::BC_HiveAdd); + Bind(wxEVT_BUTTON, &cHivesPanel::OnClickRemoveHive, this, SampleHive::ID::BC_HiveRemove); m_pMainSizer->Add(m_pHivesSizer, wxSizerFlags(1).Expand()); m_pMainSizer->Add(m_pButtonSizer, wxSizerFlags(0).Expand()); @@ -61,9 +80,8 @@ cHivesPanel::cHivesPanel(wxWindow* window, wxDataViewListCtrl& listCtrl) void cHivesPanel::OnDragAndDropToHives(wxDropFilesEvent& event) { - Serializer serializer; - Database db; - // cListCtrl m_ListCtrl.m_pWindow); + SampleHive::cSerializer serializer; + cDatabase db; if (event.GetNumberOfFiles() > 0) { @@ -71,8 +89,7 @@ void cHivesPanel::OnDragAndDropToHives(wxDropFilesEvent& event) wxArrayString files; wxDataViewItemArray items; - int rows = m_ListCtrl.GetSelections(items); - // int rows = 2; + int rows = SampleHive::cHiveData::Get().GetListCtrlSelections(items); wxDataViewItem drop_target;; wxDataViewColumn* column; @@ -86,9 +103,9 @@ void cHivesPanel::OnDragAndDropToHives(wxDropFilesEvent& event) for (int i = 0; i < rows; i++) { - int row = m_ListCtrl.ItemToRow(items[i]); + int row = SampleHive::cHiveData::Get().GetListCtrlRowFromItem(items, i); - wxString name = m_ListCtrl.GetTextValue(row, 1); + wxString name = SampleHive::cHiveData::Get().GetListCtrlTextValue(row, 1); file_data.AddFile(name); @@ -104,7 +121,7 @@ void cHivesPanel::OnDragAndDropToHives(wxDropFilesEvent& event) { m_pHives->AppendItem(drop_target, files[i]); - m_ListCtrl.SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), row, 0); + SampleHive::cHiveData::Get().ListCtrlSetVariant(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), row, 0); db.UpdateFavoriteColumn(file_name.ToStdString(), 1); db.UpdateHiveName(file_name.ToStdString(), hive_name.ToStdString()); @@ -132,17 +149,15 @@ void cHivesPanel::OnDragAndDropToHives(wxDropFilesEvent& event) } if (!msg.IsEmpty()) - SampleHive::Signal::SendInfoBarMessage(msg, wxICON_ERROR, *this); - // m_InfoBar->ShowMessage(msg, wxICON_ERROR); + SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_ERROR, *this); } } } void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event) { - Serializer serializer; - Database db; - // cListCtrl m_ListCtrl.m_pWindow); + SampleHive::cSerializer serializer; + cDatabase db; wxDataViewItem selected_hive = event.GetItem(); @@ -153,27 +168,26 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event) if (m_pHives->IsContainer(selected_hive)) { // Container menu items - menu.Append(MN_RenameHive, _("Rename hive"), _("Rename selected hive")); - menu.Append(MN_DeleteHive, _("Delete hive"), _("Delete selected hive")); + menu.Append(SampleHive::ID::MN_RenameHive, _("Rename hive"), _("Rename selected hive")); + menu.Append(SampleHive::ID::MN_DeleteHive, _("Delete hive"), _("Delete selected hive")); if (!m_bFiltered) - menu.Append(MN_FilterLibrary, _("Filter library"), - _("Show only samples from current hive in library")); + menu.Append(SampleHive::ID::MN_FilterLibrary, _("Filter library"), _("Show only samples from current hive in library")); else - menu.Append(MN_FilterLibrary, _("Clear filter"), _("Clear the filter")); + menu.Append(SampleHive::ID::MN_FilterLibrary, _("Clear filter"), _("Clear the filter")); } else { // Child menu items - menu.Append(MN_RemoveSample, _("Remove sample"), _("Remove the selected sample(s)")); - menu.Append(MN_ShowInLibrary, _("Show sample in library"), _("Show the selected in library")); + menu.Append(SampleHive::ID::MN_RemoveSample, _("Remove sample"), _("Remove the selected sample(s)")); + menu.Append(SampleHive::ID::MN_ShowInLibrary, _("Show sample in library"), _("Show the selected in library")); } if (selected_hive.IsOk() && m_pHives->IsContainer(selected_hive)) { switch (m_pHives->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) { - case MN_RenameHive: + case SampleHive::ID::MN_RenameHive: { std::deque nodes; nodes.push_back(m_pHives->GetNthChild(wxDataViewItem(wxNullPtr), 0)); @@ -224,8 +238,7 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event) if (found_item.IsOk()) { wxMessageBox(wxString::Format(_("Another hive by the name %s already exist. " - "Please try with a different name."), - hive_name), + "Please try with a different name."), hive_name), _("Error!"), wxOK | wxCENTRE, this); } else @@ -237,8 +250,7 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event) if (sample_count <= 0) { m_pHives->SetItemText(selected_hive, hive_name); - db.UpdateHive(selected_hive_name.ToStdString(), - hive_name.ToStdString()); + db.UpdateHive(selected_hive_name.ToStdString(), hive_name.ToStdString()); } else { @@ -250,10 +262,8 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event) m_pHives->GetItemText(sample_item).BeforeLast('.') : m_pHives->GetItemText(sample_item); - db.UpdateHiveName(sample_name.ToStdString(), - hive_name.ToStdString()); - db.UpdateHive(selected_hive_name.ToStdString(), - hive_name.ToStdString()); + db.UpdateHiveName(sample_name.ToStdString(), hive_name.ToStdString()); + db.UpdateHive(selected_hive_name.ToStdString(), hive_name.ToStdString()); m_pHives->SetItemText(selected_hive, hive_name); } @@ -270,28 +280,22 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event) } if (!msg.IsEmpty()) - SampleHive::Signal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); - // m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); + SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); } break; - case MN_DeleteHive: + case SampleHive::ID::MN_DeleteHive: { wxString msg; - wxMessageDialog deleteEmptyHiveDialog(this, wxString::Format(_("Are you sure you want to " - "delete %s from chives?"), + wxMessageDialog deleteEmptyHiveDialog(this, wxString::Format(_("Are you sure you want to delete %s from hives?"), hive_name), wxMessageBoxCaptionStr, - wxYES_NO | wxNO_DEFAULT | - wxICON_QUESTION | wxSTAY_ON_TOP); + wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION | wxSTAY_ON_TOP); - wxMessageDialog deleteFilledHiveDialog(this, wxString::Format(_("Are you sure you want to " - "delete %s and all samples " - "inside %s from chives?"), - hive_name, hive_name), + wxMessageDialog deleteFilledHiveDialog(this, wxString::Format(_("Are you sure you want to delete %s and all samples " + "inside %s from hives?"), hive_name, hive_name), wxMessageBoxCaptionStr, - wxYES_NO | wxNO_DEFAULT | - wxICON_QUESTION | wxSTAY_ON_TOP); + wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION | wxSTAY_ON_TOP); if (hive_name == m_pHives->GetItemText(m_FavoritesHive)) { @@ -307,8 +311,7 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event) } else if (selected_hive.IsOk() && !m_pHives->IsContainer(selected_hive)) { - wxMessageBox(wxString::Format(_("Error! %s is not a hive, cannot delete from chives."), - hive_name), + wxMessageBox(wxString::Format(_("Error! %s is not a hive, cannot delete from hives."), hive_name), _("Error!"), wxOK | wxCENTRE, this); return; } @@ -325,7 +328,7 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event) db.RemoveHiveFromDatabase(hive_name.ToStdString()); - msg = wxString::Format(_("%s deleted from chives successfully."), hive_name); + msg = wxString::Format(_("%s deleted from hives successfully."), hive_name); } break; case wxID_NO: @@ -344,13 +347,11 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event) { wxDataViewItem child_item; - for (int i = 0; i < m_ListCtrl.GetItemCount(); i++) - // for (int i = 0; i < 1; i++) + for (int i = 0; i < SampleHive::cHiveData::Get().GetListCtrlItemCount(); i++) { - wxString matched_sample = - serializer.DeserializeShowFileExtension() ? - m_ListCtrl.GetTextValue(i, 1).BeforeLast('.') : - m_ListCtrl.GetTextValue(i, 1); + wxString matched_sample = serializer.DeserializeShowFileExtension() ? + SampleHive::cHiveData::Get().GetListCtrlTextValue(i, 1).BeforeLast('.') : + SampleHive::cHiveData::Get().GetListCtrlTextValue(i, 1); for (int j = 0; j < m_pHives->GetChildCount(selected_hive); j++) { @@ -362,11 +363,11 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event) m_pHives->GetItemText(child_item); if (child_name == matched_sample) - // if (child_name == "") { SH_LOG_DEBUG("Found match"); - m_ListCtrl.SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0); + SampleHive::cHiveData::Get().ListCtrlSetVariant(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), + i, 0); db.UpdateFavoriteColumn(matched_sample.ToStdString(), 0); db.UpdateHiveName(matched_sample.ToStdString(), @@ -384,8 +385,7 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event) db.RemoveHiveFromDatabase(hive_name.ToStdString()); - msg = wxString::Format(_("%s and all samples inside %s " - "have been deleted from chives successfully."), + msg = wxString::Format(_("%s and all samples inside %s have been deleted from hives successfully."), hive_name, hive_name); } break; @@ -397,20 +397,19 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event) } if (!msg.IsEmpty()) - SampleHive::Signal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); - // m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); + SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); } break; - case MN_FilterLibrary: + case SampleHive::ID::MN_FilterLibrary: { if (!m_bFiltered) { try { const auto dataset = db.FilterDatabaseByHiveName(hive_name.ToStdString(), - serializer.DeserializeShowFileExtension(), - ICON_STAR_FILLED_16px, - ICON_STAR_EMPTY_16px); + serializer.DeserializeShowFileExtension(), + ICON_STAR_FILLED_16px, + ICON_STAR_EMPTY_16px); if (dataset.empty()) { @@ -420,18 +419,18 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event) } else { - m_ListCtrl.DeleteAllItems(); + SampleHive::cHiveData::Get().ListCtrlDeleteAllItems(); for (auto data : dataset) { - m_ListCtrl.AppendItem(data); + SampleHive::cHiveData::Get().ListCtrlAppendItem(data); } } } - catch (...) + catch (std::exception& e) { - wxMessageBox(_("Error loading data, cannot filter sample view"), _("Error!"), - wxOK | wxICON_ERROR | wxCENTRE, this); + wxMessageBox(wxString::Format(_("Error loading data, cannot filter sample view. Error: %s"), e.what()), + _("Error!"), wxOK | wxICON_ERROR | wxCENTRE, this); } m_bFiltered = true; @@ -441,27 +440,26 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event) try { const auto dataset = db.FilterDatabaseBySampleName("", serializer.DeserializeShowFileExtension(), - ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px); + ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px); if (dataset.empty()) { - wxMessageBox(_("Error! Database is empty."), _("Error!"), - wxOK | wxICON_ERROR | wxCENTRE, this); + wxMessageBox(_("Error! Database is empty."), _("Error!"), wxOK | wxICON_ERROR | wxCENTRE, this); } else { - m_ListCtrl.DeleteAllItems(); + SampleHive::cHiveData::Get().ListCtrlDeleteAllItems(); for (auto data : dataset) { - m_ListCtrl.AppendItem(data); + SampleHive::cHiveData::Get().ListCtrlAppendItem(data); } } } - catch (...) + catch (std::exception& e) { - wxMessageBox(_("Error loading data, cannot filter sample view"), _("Error!"), - wxOK | wxICON_ERROR | wxCENTRE, this); + wxMessageBox(wxString::Format(_("Error loading data, cannot filter sample view. Error: %s"), e.what()), + _("Error!"), wxOK | wxICON_ERROR | wxCENTRE, this); } m_bFiltered = false; @@ -476,68 +474,57 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event) { switch (m_pHives->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) { - case MN_RemoveSample: - for(int i = 0; i < m_ListCtrl.GetItemCount(); i++) - // for(int i = 0; i < 1; i++) + case SampleHive::ID::MN_RemoveSample: + for (int i = 0; i < SampleHive::cHiveData::Get().GetListCtrlItemCount(); i++) { wxString matched_sample = serializer.DeserializeShowFileExtension() ? - m_ListCtrl.GetTextValue(i, 1).BeforeLast('.') : - m_ListCtrl.GetTextValue(i, 1); + SampleHive::cHiveData::Get().GetListCtrlTextValue(i, 1).BeforeLast('.') : + SampleHive::cHiveData::Get().GetListCtrlTextValue(i, 1); wxString selected_sample_name = serializer.DeserializeShowFileExtension() ? m_pHives->GetItemText(event.GetItem()).BeforeLast('.') : m_pHives->GetItemText(event.GetItem()); - if(selected_sample_name == matched_sample) - // if(selected_sample_name == "") + if (selected_sample_name == matched_sample) { SH_LOG_DEBUG("Found match"); - m_ListCtrl.SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0); + SampleHive::cHiveData::Get().ListCtrlSetVariant(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0); db.UpdateFavoriteColumn(matched_sample.ToStdString(), 0); - db.UpdateHiveName(matched_sample.ToStdString(), - m_pHives->GetItemText(m_FavoritesHive).ToStdString()); + db.UpdateHiveName(matched_sample.ToStdString(), m_pHives->GetItemText(m_FavoritesHive).ToStdString()); m_pHives->DeleteItem(selected_hive); break; } - wxString msg = wxString::Format(_("Removed %s from %s"), - m_pHives->GetItemText(event.GetItem()), + wxString msg = wxString::Format(_("Removed %s from %s"), m_pHives->GetItemText(event.GetItem()), db.GetHiveByFilename(matched_sample.ToStdString())); - // m_InfoBar->ShowMessage(wxString::Format(_("Removed %s from %s"), - // m_Hives->GetItemText(event.GetItem()), - // db.GetHiveByFilename(matched_sample.ToStdString())), - // wxICON_INFORMATION); - - SampleHive::Signal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); + SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); } break; - case MN_ShowInLibrary: - for(int i = 0; i < m_ListCtrl.GetItemCount(); i++) - // for(int i = 0; i < 1; i++) + case SampleHive::ID::MN_ShowInLibrary: + for (int i = 0; i < SampleHive::cHiveData::Get().GetListCtrlItemCount(); i++) { wxString matched_sample = serializer.DeserializeShowFileExtension() ? - m_ListCtrl.GetTextValue(i, 1).BeforeLast('.') : - m_ListCtrl.GetTextValue(i, 1); + SampleHive::cHiveData::Get().GetListCtrlTextValue(i, 1).BeforeLast('.') : + SampleHive::cHiveData::Get().GetListCtrlTextValue(i, 1); wxString selected_sample_name = serializer.DeserializeShowFileExtension() ? m_pHives->GetItemText(event.GetItem()).BeforeLast('.') : m_pHives->GetItemText(event.GetItem()); - if(selected_sample_name == matched_sample) - // if(selected_sample_name == "") + if (selected_sample_name == matched_sample) { SH_LOG_DEBUG("Found match"); - wxDataViewItem matched_item = m_ListCtrl.RowToItem(i); + wxDataViewItem matched_item = SampleHive::cHiveData::Get().GetListCtrlItemFromRow(i); - m_ListCtrl.UnselectAll(); - m_ListCtrl.SelectRow(i); - m_ListCtrl.EnsureVisible(matched_item); + SampleHive::cHiveData::Get().ListCtrlUnselectAllItems(); + SampleHive::cHiveData::Get().ListCtrlSelectRow(i); + SampleHive::cHiveData::Get().ListCtrlEnsureVisible(matched_item); break; } @@ -557,7 +544,7 @@ void cHivesPanel::OnHiveStartEditing(wxDataViewEvent &event) void cHivesPanel::OnClickAddHive(wxCommandEvent& event) { - Database db; + cDatabase db; std::deque nodes; nodes.push_back(m_pHives->GetNthChild(wxDataViewItem(wxNullPtr), 0)); @@ -580,7 +567,7 @@ void cHivesPanel::OnClickAddHive(wxCommandEvent& event) { wxString hive_name = hiveEntry.GetValue(); - while(!nodes.empty()) + while (!nodes.empty()) { current_item = nodes.front(); nodes.pop_front(); @@ -607,17 +594,15 @@ void cHivesPanel::OnClickAddHive(wxCommandEvent& event) if (found_item.IsOk()) { - wxMessageBox(wxString::Format(_("Another hive by the name %s already exist. " - "Please try with a different name."), - hive_name), - _("Error!"), wxOK | wxCENTRE, this); + wxMessageBox(wxString::Format(_("Another hive by the name %s already exist. Please try with a different name."), + hive_name), _("Error!"), wxOK | wxCENTRE, this); } else { m_pHives->AppendContainer(wxDataViewItem(wxNullPtr), hive_name); db.InsertIntoHives(hive_name.ToStdString()); - msg = wxString::Format(_("%s added to cHivesPanel."), hive_name); + msg = wxString::Format(_("%s added to Hives."), hive_name); } break; } @@ -628,39 +613,29 @@ void cHivesPanel::OnClickAddHive(wxCommandEvent& event) } if (!msg.IsEmpty()) - SampleHive::Signal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); - // m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); + SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); } void cHivesPanel::OnClickRemoveHive(wxCommandEvent& event) { - Serializer serializer; - Database db; - // cListCtrl m_ListCtrl.m_pWindow); + SampleHive::cSerializer serializer; + cDatabase db; wxDataViewItem selected_item = m_pHives->GetSelection(); wxString hive_name = m_pHives->GetItemText(selected_item); wxString msg; - wxMessageDialog deleteEmptyHiveDialog(this, wxString::Format(_("Are you sure you want to delete " - "%s from chives?"), - hive_name), - wxMessageBoxCaptionStr, - wxYES_NO | wxNO_DEFAULT | - wxICON_QUESTION | wxSTAY_ON_TOP); + wxMessageDialog deleteEmptyHiveDialog(this, wxString::Format(_("Are you sure you want to delete %s from hives?"), hive_name), + wxMessageBoxCaptionStr, wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION | wxSTAY_ON_TOP); wxMessageDialog deleteFilledHiveDialog(this, wxString::Format(_("Are you sure you want to delete " - "%s and all sample inside %s from chives?"), - hive_name, hive_name), - wxMessageBoxCaptionStr, - wxYES_NO | wxNO_DEFAULT | - wxICON_QUESTION | wxSTAY_ON_TOP); + "%s and all sample inside %s from hives?"), hive_name, hive_name), + wxMessageBoxCaptionStr, wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION | wxSTAY_ON_TOP); if (hive_name == m_pHives->GetItemText(m_FavoritesHive)) { - wxMessageBox(wxString::Format(_("Error! Default hive %s cannot be deleted."), hive_name), - _("Error!"), wxOK | wxCENTRE, this); + wxMessageBox(wxString::Format(_("Error! Default hive %s cannot be deleted."), hive_name), _("Error!"), wxOK | wxCENTRE, this); return; } else if (!selected_item.IsOk()) @@ -670,7 +645,7 @@ void cHivesPanel::OnClickRemoveHive(wxCommandEvent& event) } else if (selected_item.IsOk() && !m_pHives->IsContainer(selected_item)) { - wxMessageBox(wxString::Format(_("Error! %s is not a hive, cannot delete from chives."), hive_name), + wxMessageBox(wxString::Format(_("Error! %s is not a hive, cannot delete from hives."), hive_name), _("Error!"), wxOK | wxCENTRE, this); return; } @@ -686,7 +661,7 @@ void cHivesPanel::OnClickRemoveHive(wxCommandEvent& event) m_pHives->DeleteItem(selected_item); db.RemoveHiveFromDatabase(hive_name.ToStdString()); - msg = wxString::Format(_("%s deleted from chives successfully."), hive_name); + msg = wxString::Format(_("%s deleted from hives successfully."), hive_name); } break; case wxID_NO: @@ -705,12 +680,11 @@ void cHivesPanel::OnClickRemoveHive(wxCommandEvent& event) { wxDataViewItem child_item; - for (int i = 0; i < m_ListCtrl.GetItemCount(); i++) - // for (int i = 0; i < 1; i++) + for (int i = 0; i < SampleHive::cHiveData::Get().GetListCtrlItemCount(); i++) { wxString matched_sample = serializer.DeserializeShowFileExtension() ? - m_ListCtrl.GetTextValue(i, 1).BeforeLast('.') : - m_ListCtrl.GetTextValue(i, 1); + SampleHive::cHiveData::Get().GetListCtrlTextValue(i, 1).BeforeLast('.') : + SampleHive::cHiveData::Get().GetListCtrlTextValue(i, 1); for (int j = 0; j < m_pHives->GetChildCount(selected_item); j++) { @@ -721,15 +695,13 @@ void cHivesPanel::OnClickRemoveHive(wxCommandEvent& event) m_pHives->GetItemText(child_item); if (child_name == matched_sample) - // if (child_name == "") { SH_LOG_DEBUG("Found match"); - m_ListCtrl.SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0); + SampleHive::cHiveData::Get().ListCtrlSetVariant(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0); db.UpdateFavoriteColumn(matched_sample.ToStdString(), 0); - db.UpdateHiveName(matched_sample.ToStdString(), - m_pHives->GetItemText(m_FavoritesHive).ToStdString()); + db.UpdateHiveName(matched_sample.ToStdString(), m_pHives->GetItemText(m_FavoritesHive).ToStdString()); break; } @@ -743,8 +715,7 @@ void cHivesPanel::OnClickRemoveHive(wxCommandEvent& event) db.RemoveHiveFromDatabase(hive_name.ToStdString()); - msg = wxString::Format(_("%s and all samples inside %s have been deleted " - "from chives successfully."), + msg = wxString::Format(_("%s and all samples inside %s have been deleted from hives successfully."), hive_name, hive_name); } break; @@ -756,8 +727,7 @@ void cHivesPanel::OnClickRemoveHive(wxCommandEvent& event) } if (!msg.IsEmpty()) - SampleHive::Signal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); - // m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); + SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); } cHivesPanel::~cHivesPanel() diff --git a/src/GUI/Hives.hpp b/src/GUI/Hives.hpp index fbbefba..7f26e31 100644 --- a/src/GUI/Hives.hpp +++ b/src/GUI/Hives.hpp @@ -1,6 +1,24 @@ -#pragma once +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ -#include "GUI/ListCtrl.hpp" +#pragma once #include #include @@ -12,13 +30,13 @@ class cHivesPanel : public wxPanel { public: // ------------------------------------------------------------------- - cHivesPanel(wxWindow* window, wxDataViewListCtrl& listCtrl); + cHivesPanel(wxWindow* window); ~cHivesPanel(); public: // ------------------------------------------------------------------- wxDataViewTreeCtrl* GetHivesObject() { return m_pHives; } - wxDataViewItem GetFavoritesHive() { return m_FavoritesHive; } + wxDataViewItem& GetFavoritesHive() { return m_FavoritesHive; } bool IsLibraryFiltered() { return m_bFiltered; } @@ -48,9 +66,4 @@ class cHivesPanel : public wxPanel // ------------------------------------------------------------------- wxWindow* m_pWindow = nullptr; - - wxDataViewListCtrl& m_ListCtrl; - - // ------------------------------------------------------------------- - // friend class cListCtrl; }; diff --git a/src/GUI/InfoBar.cpp b/src/GUI/InfoBar.cpp index 60a37f1..d4a502a 100644 --- a/src/GUI/InfoBar.cpp +++ b/src/GUI/InfoBar.cpp @@ -1,3 +1,23 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "InfoBar.hpp" cInfoBar::cInfoBar(wxWindow* window) diff --git a/src/GUI/InfoBar.hpp b/src/GUI/InfoBar.hpp index 7069dce..c43bc3b 100644 --- a/src/GUI/InfoBar.hpp +++ b/src/GUI/InfoBar.hpp @@ -1,3 +1,23 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #include diff --git a/src/GUI/Library.cpp b/src/GUI/Library.cpp index 0355b33..50388ae 100644 --- a/src/GUI/Library.cpp +++ b/src/GUI/Library.cpp @@ -1,16 +1,34 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "GUI/Library.hpp" #include "Utility/Log.hpp" -cLibrary::cLibrary(wxWindow* window, wxDataViewItem favHive, wxDataViewTreeCtrl& hives, - wxTreeItemId trashRoot, wxTreeCtrl& trash) - : wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL), - m_FavoritesHive(favHive), m_pHives(hives), m_pTrash(trash), m_TrashRoot(trashRoot) +cLibrary::cLibrary(wxWindow* window) + : wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL) { m_pSizer = new wxBoxSizer(wxVERTICAL); - m_pSearchBar = new cSearchBar(this, *m_pListCtrl); + m_pSearchBar = new cSearchBar(this); m_pInfoBar = new cInfoBar(this); - m_pListCtrl = new cListCtrl(this, m_FavoritesHive, hives, trashRoot, trash); + m_pListCtrl = new cListCtrl(this); m_pSizer->Add(m_pSearchBar, wxSizerFlags(1).Expand()); m_pSizer->Add(m_pInfoBar, wxSizerFlags(0).Expand()); diff --git a/src/GUI/Library.hpp b/src/GUI/Library.hpp index c957eca..ae0aa7c 100644 --- a/src/GUI/Library.hpp +++ b/src/GUI/Library.hpp @@ -1,3 +1,23 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #include "GUI/InfoBar.hpp" @@ -13,8 +33,7 @@ class cLibrary : public wxPanel { public: - cLibrary(wxWindow* window, wxDataViewItem favHive, wxDataViewTreeCtrl& hives, - wxTreeItemId trashRoot, wxTreeCtrl& trash); + cLibrary(wxWindow* window); ~cLibrary(); public: @@ -22,19 +41,9 @@ class cLibrary : public wxPanel wxInfoBar* GetInfoBarObject() const { return m_pInfoBar; } wxDataViewListCtrl* GetListCtrlObject() const { return m_pListCtrl; } - // void SetHivesObject(wxDataViewTreeCtrl& hives) { m_pHives = &hives;} - // void SetFavoritesHive(wxDataViewItem favHive) { m_FavoritesHive = favHive;} - // void SetTrashObject(wxTreeCtrl& trash) { m_pTrash = &trash;} - // void SetTrashRoot(wxTreeItemId trashRoot) { m_TrashRoot = trashRoot;} - private: cSearchBar* m_pSearchBar = nullptr; cInfoBar* m_pInfoBar = nullptr; cListCtrl* m_pListCtrl = nullptr; wxBoxSizer* m_pSizer = nullptr; - - wxDataViewItem m_FavoritesHive; - wxDataViewTreeCtrl& m_pHives; - wxTreeCtrl& m_pTrash; - wxTreeItemId m_TrashRoot; }; diff --git a/src/GUI/ListCtrl.cpp b/src/GUI/ListCtrl.cpp index 2579320..2c6f8cc 100644 --- a/src/GUI/ListCtrl.cpp +++ b/src/GUI/ListCtrl.cpp @@ -1,29 +1,44 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "GUI/ListCtrl.hpp" -// #include "GUI/Hives.hpp" -// #include "GUI/Trash.hpp" #include "GUI/Dialogs/TagEditor.hpp" #include "Database/Database.hpp" -#include "GUI/Hives.hpp" #include "Utility/ControlIDs.hpp" -#include "Utility/SH_Event.hpp" -#include "Utility/Signal.hpp" +#include "Utility/HiveData.hpp" #include "Utility/Serialize.hpp" +#include "Utility/Event.hpp" +#include "Utility/Signal.hpp" #include "Utility/Log.hpp" #include "Utility/Paths.hpp" +#include "Utility/Utils.hpp" #include #include -#include "wx/log.h" #include #include -// cListCtrl::cListCtrl(wxWindow* window) -cListCtrl::cListCtrl(wxWindow* window, wxDataViewItem favHive, wxDataViewTreeCtrl& hives, - wxTreeItemId trashRoot, wxTreeCtrl& trash) - : wxDataViewListCtrl(window, BC_Library, wxDefaultPosition, wxDefaultSize, +cListCtrl::cListCtrl(wxWindow* window) + : wxDataViewListCtrl(window, SampleHive::ID::BC_Library, wxDefaultPosition, wxDefaultSize, wxDV_MULTIPLE | wxDV_HORIZ_RULES | wxDV_VERT_RULES | wxDV_ROW_LINES), - // m_pWindow(window) - m_pWindow(window), m_Hives(hives), m_FavoritesHive(favHive), m_TrashRoot(trashRoot), m_Trash(trash) + m_pWindow(window) { // Adding columns to wxDataViewListCtrl. AppendBitmapColumn(wxBitmap(ICON_STAR_FILLED_16px), @@ -95,20 +110,16 @@ cListCtrl::cListCtrl(wxWindow* window, wxDataViewItem favHive, wxDataViewTreeCtr // Enable dragging a file from cListCtrl this->EnableDragSource(wxDF_FILENAME); - Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &cListCtrl::OnClickLibrary, this, BC_Library); + Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &cListCtrl::OnClickLibrary, this, SampleHive::ID::BC_Library); Bind(wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, &cListCtrl::OnDragFromLibrary, this); this->Connect(wxEVT_DROP_FILES, wxDropFilesEventHandler(cListCtrl::OnDragAndDropToLibrary), NULL, this); - Bind(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &cListCtrl::OnShowLibraryContextMenu, this, BC_Library); - Bind(wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, - &cListCtrl::OnShowLibraryColumnHeaderContextMenu, this, BC_Library); - - LoadDatabase(); + Bind(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &cListCtrl::OnShowLibraryContextMenu, this, SampleHive::ID::BC_Library); + Bind(wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, &cListCtrl::OnShowLibraryColumnHeaderContextMenu, this, SampleHive::ID::BC_Library); } void cListCtrl::OnClickLibrary(wxDataViewEvent& event) { - // cHivesPanel hives(m_pWindow); - Database db; + cDatabase db; int selected_row = this->ItemToRow(event.GetItem()); int current_row = this->ItemToRow(this->GetCurrentItem()); @@ -123,19 +134,13 @@ void cListCtrl::OnClickLibrary(wxDataViewEvent& event) } // Update the waveform bitmap - SampleHive::Signal::SendWaveformUpdateStatus(*this); - // m_TopWaveformPanel->ResetDC(); + SampleHive::cSignal::SendWaveformUpdateStatus(*this); - // TODO - // SampleHive::Signal::SendSetLoopABButton(*this); - // m_LoopABButton->SetValue(false); + // Update LoopAB button value + SampleHive::cSignal::SendLoopABButtonValueChange(*this); - SampleHive::Signal::SendTimerStopStatus(*this); - // if (m_Timer->IsRunning()) - // { - // m_Timer->Stop(); - // SH_LOG_DEBUG("TIMER STOPPED"); - // } + // Stop the timer + SampleHive::cSignal::SendTimerStopStatus(*this); wxString selection = this->GetTextValue(selected_row, 1); @@ -148,40 +153,30 @@ void cListCtrl::OnClickLibrary(wxDataViewEvent& event) if (!CurrentColumn) return; - wxString sample_path = GetFilenamePathAndExtension(selection).Path; - std::string filename = GetFilenamePathAndExtension(selection).Filename; - std::string extension = GetFilenamePathAndExtension(selection).Extension; + wxString sample_path = SampleHive::cUtils::Get().GetFilenamePathAndExtension(selection).Path; + std::string filename = SampleHive::cUtils::Get().GetFilenamePathAndExtension(selection).Filename; + std::string extension = SampleHive::cUtils::Get().GetFilenamePathAndExtension(selection).Extension; if (CurrentColumn != FavoriteColumn) { - SampleHive::Signal::SendCallFunctionPlay(selection, *this); - - // TODO // ClearLoopPoints(); + SampleHive::cSignal::SendClearLoopPointsStatus(*this); - // if (bAutoplay) - // { - // if (bLoopPointsSet && m_LoopABButton->GetValue()) - // PlaySample(sample_path.ToStdString(), selection.ToStdString(), - // true, m_LoopA.ToDouble(), wxFromStart); - // else - // PlaySample(sample_path.ToStdString(), selection.ToStdString()); - // } - // else - // m_MediaCtrl->Stop(); + // Play the sample + SampleHive::cSignal::SendCallFunctionPlay(selection, true, *this); } else { wxString msg; // Get hive name and location - std::string hive_name = m_Hives.GetItemText(m_FavoritesHive).ToStdString(); - wxDataViewItem hive_selection = m_Hives.GetSelection(); + std::string hive_name = SampleHive::cHiveData::Get().GetHiveItemText(true).ToStdString(); + wxDataViewItem hive_selection = SampleHive::cHiveData::Get().GetHiveItemSelection(); SH_LOG_DEBUG("HIVE NAME: {}", hive_name); - if (hive_selection.IsOk() && m_Hives.IsContainer(hive_selection)) - hive_name = m_Hives.GetItemText(hive_selection).ToStdString(); + if (hive_selection.IsOk() && SampleHive::cHiveData::Get().IsHiveItemContainer(hive_selection)) + hive_name = SampleHive::cHiveData::Get().GetHiveItemText(false, hive_selection); wxString name = this->GetTextValue(selected_row, 1); @@ -192,20 +187,18 @@ void cListCtrl::OnClickLibrary(wxDataViewEvent& event) if (db.GetFavoriteColumnValueByFilename(filename) == 0) { - SH_LOG_DEBUG("TRUE COND...."); - this->SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), selected_row, 0); db.UpdateFavoriteColumn(filename, 1); db.UpdateHiveName(filename, hive_name); - for (int i = 0; i < m_Hives.GetChildCount(root); i++) + for (int i = 0; i < SampleHive::cHiveData::Get().GetHiveChildCount(root); i++) { - container = m_Hives.GetNthChild(root, i); + container = SampleHive::cHiveData::Get().GetHiveNthChild(root, i); - if (m_Hives.GetItemText(container).ToStdString() == hive_name) + if (SampleHive::cHiveData::Get().GetHiveItemText(false, container) == hive_name) { - m_Hives.AppendItem(container, name); + SampleHive::cHiveData::Get().HiveAppendItem(container, name); break; } } @@ -217,19 +210,19 @@ void cListCtrl::OnClickLibrary(wxDataViewEvent& event) this->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), selected_row, 0); db.UpdateFavoriteColumn(filename, 0); - db.UpdateHiveName(filename, m_Hives.GetItemText(m_FavoritesHive).ToStdString()); + db.UpdateHiveName(filename, SampleHive::cHiveData::Get().GetHiveItemText(true).ToStdString()); - for (int i = 0; i < m_Hives.GetChildCount(root); i++) + for (int i = 0; i < SampleHive::cHiveData::Get().GetHiveChildCount(root); i++) { - container = m_Hives.GetNthChild(root, i); + container = SampleHive::cHiveData::Get().GetHiveNthChild(root, i); - for (int j = 0; j < m_Hives.GetChildCount(container); j++) + for (int j = 0; j < SampleHive::cHiveData::Get().GetHiveChildCount(container); j++) { - child = m_Hives.GetNthChild(container, j); + child = SampleHive::cHiveData::Get().GetHiveNthChild(container, j); - if (m_Hives.GetItemText(child) == name) + if (SampleHive::cHiveData::Get().GetHiveItemText(false, child) == name) { - m_Hives.DeleteItem(child); + SampleHive::cHiveData::Get().HiveDeleteItem(child); break; } } @@ -239,8 +232,7 @@ void cListCtrl::OnClickLibrary(wxDataViewEvent& event) } if (!msg.IsEmpty()) - SampleHive::Signal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); - // m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); + SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); } } @@ -288,7 +280,7 @@ void cListCtrl::OnDragAndDropToLibrary(wxDropFilesEvent& event) progressDialog->Destroy(); - AddSamples(filepath_array); + SampleHive::cUtils::Get().AddSamples(filepath_array, m_pWindow); SH_LOG_DEBUG("Done Inserting Samples"); } @@ -303,7 +295,7 @@ void cListCtrl::OnDragFromLibrary(wxDataViewEvent& event) wxString selection = this->GetTextValue(selected_row, 1); - wxString sample_path = GetFilenamePathAndExtension(selection).Path; + wxString sample_path = SampleHive::cUtils::Get().GetFilenamePathAndExtension(selection).Path; wxFileDataObject* fileData = new wxFileDataObject(); @@ -315,10 +307,9 @@ void cListCtrl::OnDragFromLibrary(wxDataViewEvent& event) void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event) { - TagEditor* tagEditor; - Serializer serializer; - Database db; - // cHivesPanel hives(m_pWindow); + cTagEditor* tagEditor; + cDatabase db; + SampleHive::cSerializer serializer; wxString msg; @@ -332,9 +323,9 @@ void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event) wxString selection = this->GetTextValue(selected_row, 1); - wxString sample_path = GetFilenamePathAndExtension(selection).Path; - std::string filename = GetFilenamePathAndExtension(selection).Filename; - std::string extension = GetFilenamePathAndExtension(selection).Extension; + wxString sample_path = SampleHive::cUtils::Get().GetFilenamePathAndExtension(selection).Path; + std::string filename = SampleHive::cUtils::Get().GetFilenamePathAndExtension(selection).Filename; + std::string extension = SampleHive::cUtils::Get().GetFilenamePathAndExtension(selection).Extension; wxMenu menu; @@ -342,41 +333,41 @@ void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event) bool favorite_add = false; if (db.GetFavoriteColumnValueByFilename(filename) == 1) - menu.Append(MN_FavoriteSample, _("Remove from hive"), _("Remove the selected sample(s) from hive")); + menu.Append(SampleHive::ID::MN_FavoriteSample, _("Remove from hive"), _("Remove the selected sample(s) from hive")); else { - menu.Append(MN_FavoriteSample, _("Add to hive"), _("Add selected sample(s) to hive")); + menu.Append(SampleHive::ID::MN_FavoriteSample, _("Add to hive"), _("Add selected sample(s) to hive")); favorite_add = true; } - menu.Append(MN_DeleteSample, _("Delete"), _("Delete the selected sample(s) from database")); - menu.Append(MN_TrashSample, _("Trash"), _("Send the selected sample(s) to trash")); + menu.Append(SampleHive::ID::MN_DeleteSample, _("Delete"), _("Delete the selected sample(s) from database")); + menu.Append(SampleHive::ID::MN_TrashSample, _("Trash"), _("Send the selected sample(s) to trash")); if (this->GetSelectedItemsCount() <= 1) { - menu.Append(MN_EditTagSample, _("Edit tags"), + menu.Append(SampleHive::ID::MN_EditTagSample, _("Edit tags"), _("Edit the tags for the selected sample"))->Enable(true); - menu.Append(MN_OpenFile, _("Open in file manager"), + menu.Append(SampleHive::ID::MN_OpenFile, _("Open in file manager"), _("Open the selected sample in system's file manager"))->Enable(true); } else { - menu.Append(MN_EditTagSample, _("Edit tags"), + menu.Append(SampleHive::ID::MN_EditTagSample, _("Edit tags"), _("Edit the tags for the selected sample"))->Enable(false); - menu.Append(MN_OpenFile, _("Open in file manager"), + menu.Append(SampleHive::ID::MN_OpenFile, _("Open in file manager"), _("Open the selected sample in system's file manager"))->Enable(false); } switch (this->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) { - case MN_FavoriteSample: + case SampleHive::ID::MN_FavoriteSample: { - std::string hive_name = m_Hives.GetItemText(m_FavoritesHive).ToStdString(); + std::string hive_name = SampleHive::cHiveData::Get().GetHiveItemText(true).ToStdString(); - wxDataViewItem hive_selection = m_Hives.GetSelection(); + wxDataViewItem hive_selection = SampleHive::cHiveData::Get().GetHiveItemSelection(); - if (hive_selection.IsOk() && m_Hives.IsContainer(hive_selection)) - hive_name = m_Hives.GetItemText(hive_selection).ToStdString(); + if (hive_selection.IsOk() && SampleHive::cHiveData::Get().IsHiveItemContainer(hive_selection)) + hive_name = SampleHive::cHiveData::Get().GetHiveItemText(false, hive_selection); wxDataViewItem root = wxDataViewItem(wxNullPtr); wxDataViewItem container; @@ -417,13 +408,13 @@ void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event) db.UpdateFavoriteColumn(filename, 1); db.UpdateHiveName(filename, hive_name); - for (int i = 0; i < m_Hives.GetChildCount(root); i++) + for (int i = 0; i < SampleHive::cHiveData::Get().GetHiveChildCount(root); i++) { - container = m_Hives.GetNthChild(root, i); + container = SampleHive::cHiveData::Get().GetHiveNthChild(root, i); - if (m_Hives.GetItemText(container).ToStdString() == hive_name) + if (SampleHive::cHiveData::Get().GetHiveItemText(false, container) == hive_name) { - m_Hives.AppendItem(container, name); + SampleHive::cHiveData::Get().HiveAppendItem(container, name); msg = wxString::Format(_("Added %s to %s"), name, hive_name); break; @@ -436,20 +427,19 @@ void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event) this->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), selected_row, 0); db.UpdateFavoriteColumn(filename, 0); - db.UpdateHiveName(filename, - m_Hives.GetItemText(m_FavoritesHive).ToStdString()); + db.UpdateHiveName(filename, SampleHive::cHiveData::Get().GetHiveItemText(true).ToStdString()); - for (int i = 0; i < m_Hives.GetChildCount(root); i++) + for (int i = 0; i < SampleHive::cHiveData::Get().GetHiveChildCount(root); i++) { - container = m_Hives.GetNthChild(root, i); + container = SampleHive::cHiveData::Get().GetHiveNthChild(root, i); - for (int j = 0; j < m_Hives.GetChildCount(container); j++) + for (int j = 0; j < SampleHive::cHiveData::Get().GetHiveChildCount(container); j++) { - child = m_Hives.GetNthChild(container, j); + child = SampleHive::cHiveData::Get().GetHiveNthChild(container, j); - if (m_Hives.GetItemText(child) == name) + if (SampleHive::cHiveData::Get().GetHiveItemText(false, child) == name) { - m_Hives.DeleteItem(child); + SampleHive::cHiveData::Get().HiveDeleteItem(child); msg = wxString::Format(_("Removed %s from %s"), name, hive_name); break; @@ -458,32 +448,25 @@ void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event) } } } + break; } - case MN_DeleteSample: + case SampleHive::ID::MN_DeleteSample: { wxDataViewItemArray items; int rows = this->GetSelections(items); - wxMessageDialog singleMsgDialog(this, wxString::Format(_("Are you sure you want to delete " - "%s from database? " - "Warning this change is " - "permanent, and cannot be undone."), + wxMessageDialog singleMsgDialog(this, wxString::Format(_("Are you sure you want to delete %s from database? " + "Warning this change is permanent, and cannot be undone."), sample_path.AfterLast('/')), wxMessageBoxCaptionStr, - wxYES_NO | wxNO_DEFAULT | - wxICON_QUESTION | wxSTAY_ON_TOP | - wxCENTER); + wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION | wxSTAY_ON_TOP | wxCENTER); wxMessageDialog multipleMsgDialog(this, wxString::Format(_("Are you sure you want to delete " - "%d selected samples from database? " - "Warning this change is " - "permanent, and cannot be " - "undone."), rows), + "%d selected samples from database? Warning this change is " + "permanent, and cannot be undone."), rows), wxMessageBoxCaptionStr, - wxYES_NO | wxNO_DEFAULT | - wxICON_QUESTION | wxSTAY_ON_TOP | - wxCENTER); + wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION | wxSTAY_ON_TOP | wxCENTER); wxDataViewItem root = wxDataViewItem(wxNullPtr); wxDataViewItem container; @@ -498,21 +481,21 @@ void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event) db.RemoveSampleFromDatabase(filename); this->DeleteItem(selected_row); - for (int j = 0; j < m_Hives.GetChildCount(root); j++) + for (int j = 0; j < SampleHive::cHiveData::Get().GetHiveChildCount(root); j++) { - container = m_Hives.GetNthChild(root, j); + container = SampleHive::cHiveData::Get().GetHiveNthChild(root, j); - for (int k = 0; k < m_Hives.GetChildCount(container); k++) + for (int k = 0; k < SampleHive::cHiveData::Get().GetHiveChildCount(container); k++) { - child = m_Hives.GetNthChild(container, k); + child = SampleHive::cHiveData::Get().GetHiveNthChild(container, k); wxString child_text = serializer.DeserializeShowFileExtension() ? - m_Hives.GetItemText(child).BeforeLast('.') : - m_Hives.GetItemText(child); + SampleHive::cHiveData::Get().GetHiveItemText(false, child).BeforeLast('.') : + SampleHive::cHiveData::Get().GetHiveItemText(false, child); if (child_text == filename) { - m_Hives.DeleteItem(child); + SampleHive::cHiveData::Get().HiveDeleteItem(child); break; } @@ -548,21 +531,21 @@ void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event) db.RemoveSampleFromDatabase(multi_selection); this->DeleteItem(row); - for (int j = 0; j < m_Hives.GetChildCount(root); j++) + for (int j = 0; j < SampleHive::cHiveData::Get().GetHiveChildCount(root); j++) { - container = m_Hives.GetNthChild(root, j); + container = SampleHive::cHiveData::Get().GetHiveNthChild(root, j); - for (int k = 0; k < m_Hives.GetChildCount(container); k++) + for (int k = 0; k < SampleHive::cHiveData::Get().GetHiveChildCount(container); k++) { - child = m_Hives.GetNthChild(container, k); + child = SampleHive::cHiveData::Get().GetHiveNthChild(container, k); wxString child_text = serializer.DeserializeShowFileExtension() ? - m_Hives.GetItemText(child).BeforeLast('.') : - m_Hives.GetItemText(child); + SampleHive::cHiveData::Get().GetHiveItemText(false, child).BeforeLast('.') : + SampleHive::cHiveData::Get().GetHiveItemText(false, child); if (child_text == multi_selection) { - m_Hives.DeleteItem(child); + SampleHive::cHiveData::Get().HiveDeleteItem(child); break; } } @@ -582,7 +565,7 @@ void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event) } } break; - case MN_TrashSample: + case SampleHive::ID::MN_TrashSample: { wxDataViewItem root = wxDataViewItem(wxNullPtr); wxDataViewItem container, child; @@ -618,43 +601,42 @@ void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event) db.UpdateFavoriteColumn(files[i].ToStdString(), 0); - for (int j = 0; j < m_Hives.GetChildCount(root); j++) + for (int j = 0; j < SampleHive::cHiveData::Get().GetHiveChildCount(root); j++) { - container = m_Hives.GetNthChild(root, j); + container = SampleHive::cHiveData::Get().GetHiveNthChild(root, j); - for (int k = 0; k < m_Hives.GetChildCount(container); k++) + for (int k = 0; k < SampleHive::cHiveData::Get().GetHiveChildCount(container); k++) { - child = m_Hives.GetNthChild(container, k); + child = SampleHive::cHiveData::Get().GetHiveNthChild(container, k); wxString child_text = serializer.DeserializeShowFileExtension() ? - m_Hives.GetItemText(child).BeforeLast('.') : - m_Hives.GetItemText(child); + SampleHive::cHiveData::Get().GetHiveItemText(false, child).BeforeLast('.') : + SampleHive::cHiveData::Get().GetHiveItemText(false, child); if (child_text == files[i]) { - m_Hives.DeleteItem(child); + SampleHive::cHiveData::Get().HiveDeleteItem(child); break; } } } } - m_Trash.AppendItem(m_TrashRoot, text_value); + SampleHive::cHiveData::Get().TrashAppendItem(SampleHive::cHiveData::Get().GetTrashRoot(), text_value); this->DeleteItem(item_row); db.UpdateTrashColumn(files[i].ToStdString(), 1); - db.UpdateHiveName(files[i].ToStdString(), - m_Hives.GetItemText(m_FavoritesHive).ToStdString()); + db.UpdateHiveName(files[i].ToStdString(), SampleHive::cHiveData::Get().GetHiveItemText(true).ToStdString()); msg = wxString::Format(_("%s sent to trash"), text_value); } } } break; - case MN_EditTagSample: + case SampleHive::ID::MN_EditTagSample: { - tagEditor = new TagEditor(this, static_cast(sample_path)); + tagEditor = new cTagEditor(this, static_cast(sample_path)); switch (tagEditor->ShowModal()) { @@ -672,7 +654,7 @@ void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event) } } break; - case MN_OpenFile: + case SampleHive::ID::MN_OpenFile: wxExecute(wxString::Format("xdg-open '%s'", sample_path.BeforeLast('/'))); break; case wxID_NONE: @@ -684,8 +666,7 @@ void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event) } if (!msg.IsEmpty()) - SampleHive::Signal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); - // m_InfoBar->ShowMessage(msg); + SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); } void cListCtrl::OnShowLibraryColumnHeaderContextMenu(wxDataViewEvent& event) @@ -702,233 +683,59 @@ void cListCtrl::OnShowLibraryColumnHeaderContextMenu(wxDataViewEvent& event) wxDataViewColumn* BitrateColumn = this->GetColumn(7); wxDataViewColumn* PathColumn = this->GetColumn(8); - menu.AppendCheckItem(MN_ColumnFavorite, _("Favorites"), + menu.AppendCheckItem(SampleHive::ID::MN_ColumnFavorite, _("Favorites"), _("Toggle favorites column"))->Check(FavoriteColumn->IsShown()); - menu.AppendCheckItem(MN_ColumnFilename, _("Filename"), + menu.AppendCheckItem(SampleHive::ID::MN_ColumnFilename, _("Filename"), _("Toggle filename column"))->Check(FilenameColumn->IsShown()); - menu.AppendCheckItem(MN_ColumnSamplePack, _("Sample Pack"), + menu.AppendCheckItem(SampleHive::ID::MN_ColumnSamplePack, _("Sample Pack"), _("Toggle sample pack column"))->Check(SamplePackColumn->IsShown()); - menu.AppendCheckItem(MN_ColumnType, _("Type"), + menu.AppendCheckItem(SampleHive::ID::MN_ColumnType, _("Type"), _("Toggle type column"))->Check(TypeColumn->IsShown()); - menu.AppendCheckItem(MN_ColumnChannels, _("Channels"), + menu.AppendCheckItem(SampleHive::ID::MN_ColumnChannels, _("Channels"), _("Toggle channels column"))->Check(ChannelsColumn->IsShown()); - menu.AppendCheckItem(MN_ColumnLength, _("Length"), + menu.AppendCheckItem(SampleHive::ID::MN_ColumnLength, _("Length"), _("Toggle length column"))->Check(LengthColumn->IsShown()); - menu.AppendCheckItem(MN_ColumnSampleRate, _("Sample Rate"), + menu.AppendCheckItem(SampleHive::ID::MN_ColumnSampleRate, _("Sample Rate"), _("Toggle sample rate column"))->Check(SampleRateColumn->IsShown()); - menu.AppendCheckItem(MN_ColumnBitrate, _("Bitrate"), + menu.AppendCheckItem(SampleHive::ID::MN_ColumnBitrate, _("Bitrate"), _("Toggle bitrate column"))->Check(BitrateColumn->IsShown()); - menu.AppendCheckItem(MN_ColumnPath, _("Path"), + menu.AppendCheckItem(SampleHive::ID::MN_ColumnPath, _("Path"), _("Toggle path column"))->Check(PathColumn->IsShown()); switch (this->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) { - case MN_ColumnFavorite: - FavoriteColumn->SetHidden(!menu.IsChecked(MN_ColumnFavorite)); + case SampleHive::ID::MN_ColumnFavorite: + FavoriteColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnFavorite)); break; - case MN_ColumnFilename: - FilenameColumn->SetHidden(!menu.IsChecked(MN_ColumnFilename)); + case SampleHive::ID::MN_ColumnFilename: + FilenameColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnFilename)); break; - case MN_ColumnSamplePack: - SamplePackColumn->SetHidden(!menu.IsChecked(MN_ColumnSamplePack)); + case SampleHive::ID::MN_ColumnSamplePack: + SamplePackColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnSamplePack)); break; - case MN_ColumnType: - TypeColumn->SetHidden(!menu.IsChecked(MN_ColumnType)); + case SampleHive::ID::MN_ColumnType: + TypeColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnType)); break; - case MN_ColumnChannels: - ChannelsColumn->SetHidden(!menu.IsChecked(MN_ColumnChannels)); + case SampleHive::ID::MN_ColumnChannels: + ChannelsColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnChannels)); break; - case MN_ColumnLength: - LengthColumn->SetHidden(!menu.IsChecked(MN_ColumnLength)); + case SampleHive::ID::MN_ColumnLength: + LengthColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnLength)); break; - case MN_ColumnSampleRate: - SampleRateColumn->SetHidden(!menu.IsChecked(MN_ColumnSampleRate)); + case SampleHive::ID::MN_ColumnSampleRate: + SampleRateColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnSampleRate)); break; - case MN_ColumnBitrate: - BitrateColumn->SetHidden(!menu.IsChecked(MN_ColumnBitrate)); + case SampleHive::ID::MN_ColumnBitrate: + BitrateColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnBitrate)); break; - case MN_ColumnPath: - PathColumn->SetHidden(!menu.IsChecked(MN_ColumnPath)); + case SampleHive::ID::MN_ColumnPath: + PathColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnPath)); break; default: break; } } -void cListCtrl::AddSamples(wxArrayString& files) -{ - Serializer serializer; - Database db; - - wxBusyCursor busy_cursor; - wxWindowDisabler window_disabler; - - wxProgressDialog* progressDialog = new wxProgressDialog(_("Adding files.."), - _("Adding files, please wait..."), - static_cast(files.size()), this, - wxPD_APP_MODAL | wxPD_SMOOTH | wxPD_CAN_ABORT | - wxPD_AUTO_HIDE); - progressDialog->CenterOnParent(wxBOTH); - - std::vector sample_array; - - std::string path; - std::string artist; - std::string filename_with_extension; - std::string filename_without_extension; - std::string extension; - std::string filename; - - //Check All Files At Once - wxArrayString sorted_files; - - sorted_files = db.CheckDuplicates(files); - files = sorted_files; - - if(files.size() < 1) - { - progressDialog->Destroy(); - return; - } - - progressDialog->SetRange(files.size()); - - for(unsigned int i = 0; i < files.size(); i++) - { - progressDialog->Update(i, wxString::Format(_("Getting Data For %s"), files[i].AfterLast('/'))); - - if(progressDialog->WasCancelled()) - { - progressDialog->Destroy(); - return; - } - - path = files[i].ToStdString(); - filename_with_extension = files[i].AfterLast('/').ToStdString(); - filename_without_extension = files[i].AfterLast('/').BeforeLast('.').ToStdString(); - extension = files[i].AfterLast('.').ToStdString(); - - filename = serializer.DeserializeShowFileExtension() ? - filename_with_extension : filename_without_extension; - - Sample sample; - - sample.SetPath(path); - sample.SetFilename(filename_without_extension); - sample.SetFileExtension(extension); - - Tags tags(path); - - artist = tags.GetAudioInfo().artist.ToStdString(); - - sample.SetSamplePack(artist); - sample.SetChannels(tags.GetAudioInfo().channels); - sample.SetLength(tags.GetAudioInfo().length); - sample.SetSampleRate(tags.GetAudioInfo().sample_rate); - sample.SetBitrate(tags.GetAudioInfo().bitrate); - - wxLongLong llLength = sample.GetLength(); - int total_min = static_cast((llLength / 60000).GetValue()); - int total_sec = static_cast(((llLength % 60000) / 1000).GetValue()); - - wxVector data; - - wxVariant icon = wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)); - - if (tags.IsFileValid()) - { - data.clear(); - data.push_back(icon); - data.push_back(filename); - data.push_back(sample.GetSamplePack()); - data.push_back(""); - data.push_back(wxString::Format("%d", sample.GetChannels())); - data.push_back(wxString::Format("%2i:%02i", total_min, total_sec)); - data.push_back(wxString::Format("%d", sample.GetSampleRate())); - data.push_back(wxString::Format("%d", sample.GetBitrate())); - data.push_back(path); - - SH_LOG_INFO("Adding file: {}, Extension: {}", sample.GetFilename(), sample.GetFileExtension()); - - this->AppendItem(data); - - sample_array.push_back(sample); - } - else - { - wxString msg = wxString::Format(_("Error! Cannot open %s, Invalid file type."), - filename_with_extension); - - SampleHive::Signal::SendInfoBarMessage(msg, wxICON_ERROR, *this); - // m_InfoBar->ShowMessage(msg, wxICON_ERROR); - } - } - - progressDialog->Pulse(_("Updating Database.."), NULL); - - db.InsertIntoSamples(sample_array); - - progressDialog->Destroy(); -} - -cListCtrl::FileInfo cListCtrl::GetFilenamePathAndExtension(const wxString& selected, - bool checkExtension, bool doGetFilename) const -{ - Serializer serializer; - Database db; - - wxString path; - std::string extension, filename; - - wxString filename_with_extension = db.GetSamplePathByFilename(selected.BeforeLast('.').ToStdString()); - wxString filename_without_extension = db.GetSamplePathByFilename(selected.ToStdString()); - - if (checkExtension) - { - extension = serializer.DeserializeShowFileExtension() ? - db.GetSampleFileExtension(selected.ToStdString()) : - db.GetSampleFileExtension(selected.BeforeLast('.').ToStdString()); - } - - path = selected.Contains(wxString::Format(".%s", extension)) ? - filename_with_extension : filename_without_extension; - - if (doGetFilename) - filename = path.AfterLast('/').BeforeLast('.').ToStdString(); - - return { path, extension, filename }; -} - -void cListCtrl::LoadDatabase() -{ - Serializer serializer; - Database db; - // cHivesPanel hives(m_pWindow); - // cTrashPanel trash(m_pWindow); - - try - { - const auto dataset = db.LoadSamplesDatabase(m_Hives, m_FavoritesHive, - m_Trash, m_TrashRoot, - serializer.DeserializeShowFileExtension(), - ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px); - - if (dataset.empty()) - SH_LOG_INFO("Error! Database is empty."); - else - { - for (auto data : dataset) - this->AppendItem(data); - } - - db.LoadHivesDatabase(m_Hives); - } - catch(...) - { - std::cerr << "Error loading data." << std::endl; - } -} - cListCtrl::~cListCtrl() { diff --git a/src/GUI/ListCtrl.hpp b/src/GUI/ListCtrl.hpp index 76adee5..1ef2ee8 100644 --- a/src/GUI/ListCtrl.hpp +++ b/src/GUI/ListCtrl.hpp @@ -1,3 +1,23 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #include @@ -6,19 +26,9 @@ class cListCtrl : public wxDataViewListCtrl { - - struct FileInfo - { - wxString Path; - std::string Extension; - std::string Filename; - }; - public: // ------------------------------------------------------------------- - // cListCtrl(wxWindow* window); - cListCtrl(wxWindow* window, wxDataViewItem favHive, wxDataViewTreeCtrl& hives, - wxTreeItemId trashRoot, wxTreeCtrl& trash); + cListCtrl(wxWindow* window); ~cListCtrl(); public: @@ -34,27 +44,7 @@ class cListCtrl : public wxDataViewListCtrl void OnShowLibraryContextMenu(wxDataViewEvent& event); void OnShowLibraryColumnHeaderContextMenu(wxDataViewEvent& event); - // ------------------------------------------------------------------- - void AddSamples(wxArrayString& files); - - // ------------------------------------------------------------------- - cListCtrl::FileInfo GetFilenamePathAndExtension(const wxString& selected, - bool checkExtension = true, - bool doGetFilename = true) const; - - // ------------------------------------------------------------------- - void LoadDatabase(); - private: // ------------------------------------------------------------------- wxWindow* m_pWindow = nullptr; - - wxDataViewTreeCtrl& m_Hives; - wxDataViewItem m_FavoritesHive; - wxTreeItemId m_TrashRoot; - wxTreeCtrl& m_Trash; - - // ------------------------------------------------------------------- - // friend class cHives; - // friend class cTrash; }; diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index fe9b728..c061058 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -20,2359 +20,303 @@ #include "GUI/MainFrame.hpp" #include "GUI/Dialogs/Settings.hpp" -#include "GUI/Dialogs/TagEditor.hpp" #include "Database/Database.hpp" #include "Utility/ControlIDs.hpp" -#include "Utility/Paths.hpp" -#include "Utility/SH_Event.hpp" -#include "Utility/Tags.hpp" -#include "Utility/Sample.hpp" +#include "Utility/HiveData.hpp" #include "Utility/Log.hpp" +#include "Utility/Paths.hpp" +#include "Utility/Utils.hpp" #include "SampleHiveConfig.hpp" -#include -#include -#include -#include #include -#include #include -#include -#include #include -#include -#include -#include #include -#include -#include -#include -#include #include -#include -#include #include #include -#include -#include -#include #include #include -#include -#include #include -#include -#include -#include -#include -#include -MainFrame::MainFrame() +cMainFrame::cMainFrame() : wxFrame(NULL, wxID_ANY, "SampleHive", wxDefaultPosition) { // Initialize statusbar with 4 sections - m_StatusBar = CreateStatusBar(4); + m_pStatusBar = CreateStatusBar(4); // Set width for each section of the statusbar int status_width[4] = { 300, -6, -1, -2 }; - m_StatusBar->SetStatusWidths(4, status_width); + m_pStatusBar->SetStatusWidths(4, status_width); - m_HiveBitmap = new wxStaticBitmap(m_StatusBar, wxID_ANY, wxBitmap(ICON_HIVE_24px)); + m_pHiveBitmap = new wxStaticBitmap(m_pStatusBar, wxID_ANY, wxBitmap(ICON_HIVE_24px)); // Initialize menubar and menus - m_MenuBar = new wxMenuBar(); - m_FileMenu = new wxMenu(); - m_EditMenu = new wxMenu(); - m_ViewMenu = new wxMenu(); - m_HelpMenu = new wxMenu(); + m_pMenuBar = new wxMenuBar(); + m_pFileMenu = new wxMenu(); + m_pEditMenu = new wxMenu(); + m_pViewMenu = new wxMenu(); + m_pHelpMenu = new wxMenu(); // File menu items - m_AddFile = new wxMenuItem(m_FileMenu, MN_AddFile, _("Add a file\tCtrl+F"), _("Add a file")); - m_AddFile->SetBitmap(wxArtProvider::GetBitmap(wxART_NORMAL_FILE)); - m_FileMenu->Append(m_AddFile); + m_pAddFile = new wxMenuItem(m_pFileMenu, SampleHive::ID::MN_AddFile, _("Add a file\tCtrl+F"), _("Add a file")); + m_pAddFile->SetBitmap(wxArtProvider::GetBitmap(wxART_NORMAL_FILE)); + m_pFileMenu->Append(m_pAddFile); - m_AddDirectory = new wxMenuItem(m_FileMenu, MN_AddDirectory, - _("Add a directory\tCtrl+D"), _("Add a directory")); - m_AddDirectory->SetBitmap(wxArtProvider::GetBitmap(wxART_FOLDER)); - m_FileMenu->Append(m_AddDirectory); + m_pAddDirectory = new wxMenuItem(m_pFileMenu, SampleHive::ID::MN_AddDirectory, _("Add a directory\tCtrl+D"), _("Add a directory")); + m_pAddDirectory->SetBitmap(wxArtProvider::GetBitmap(wxART_FOLDER)); + m_pFileMenu->Append(m_pAddDirectory); - m_FileMenu->AppendSeparator(); + m_pFileMenu->AppendSeparator(); - m_FileMenu->Append(wxID_EXIT, wxEmptyString, _("Exits the application")); + m_pFileMenu->Append(wxID_EXIT, wxEmptyString, _("Exits the application")); // Edit menu items - m_EditMenu->Append(wxID_PREFERENCES, _("Preferences\tCtrl+P"), _("Open preferences dialog")); + m_pEditMenu->Append(wxID_PREFERENCES, _("Preferences\tCtrl+P"), _("Open preferences dialog")); // View menu items - m_ToggleExtension = new wxMenuItem(m_ViewMenu, MN_ToggleExtension, - _("Toggle Extension\tCtrl+E"), _("Show/Hide Extension"), wxITEM_CHECK); - m_ToggleMenuBar = new wxMenuItem(m_ViewMenu, MN_ToggleMenuBar, - _("Toggle Menu Bar\tCtrl+M"), _("Show/Hide Menu Bar"), wxITEM_CHECK); - m_ToggleStatusBar = new wxMenuItem(m_ViewMenu, MN_ToggleStatusBar, - _("Toggle Status Bar\tCtrl+B"), _("Show/Hide Status Bar"), wxITEM_CHECK); + m_pToggleExtension = new wxMenuItem(m_pViewMenu, SampleHive::ID::MN_ToggleExtension, + _("Toggle Extension\tCtrl+E"), _("Show/Hide Extension"), wxITEM_CHECK); + m_pToggleMenuBar = new wxMenuItem(m_pViewMenu, SampleHive::ID::MN_ToggleMenuBar, + _("Toggle Menu Bar\tCtrl+M"), _("Show/Hide Menu Bar"), wxITEM_CHECK); + m_pToggleStatusBar = new wxMenuItem(m_pViewMenu, SampleHive::ID::MN_ToggleStatusBar, + _("Toggle Status Bar\tCtrl+B"), _("Show/Hide Status Bar"), wxITEM_CHECK); - m_ViewMenu->Append(m_ToggleExtension)->Check(true); - m_ViewMenu->Append(m_ToggleMenuBar)->Check(m_MenuBar->IsShown()); - m_ViewMenu->Append(m_ToggleStatusBar)->Check(m_StatusBar->IsShown()); + m_pViewMenu->Append(m_pToggleExtension)->Check(true); + m_pViewMenu->Append(m_pToggleMenuBar)->Check(m_pMenuBar->IsShown()); + m_pViewMenu->Append(m_pToggleStatusBar)->Check(m_pStatusBar->IsShown()); // Help menu items - m_HelpMenu->Append(wxID_REFRESH, _("Reset app data"), - _("Clear the application data revert to default configuration")); - m_HelpMenu->Append(wxID_ABOUT, wxEmptyString, _("Show about the application")); + m_pHelpMenu->Append(wxID_REFRESH, _("Reset app data"), _("Clear the application data revert to default configuration")); + m_pHelpMenu->Append(wxID_ABOUT, wxEmptyString, _("Show about the application")); // Append all menus to menubar - m_MenuBar->Append(m_FileMenu, _("&File")); - m_MenuBar->Append(m_EditMenu, _("&Edit")); - m_MenuBar->Append(m_ViewMenu, _("&View")); - m_MenuBar->Append(m_HelpMenu, _("&Help")); + m_pMenuBar->Append(m_pFileMenu, _("&File")); + m_pMenuBar->Append(m_pEditMenu, _("&Edit")); + m_pMenuBar->Append(m_pViewMenu, _("&View")); + m_pMenuBar->Append(m_pHelpMenu, _("&Help")); // Set the menu bar to use - SetMenuBar(m_MenuBar); + SetMenuBar(m_pMenuBar); // Load default yaml config file. LoadConfigFile(); + // Initialize the database InitDatabase(); // Initializing Sizers - m_MainSizer = new wxBoxSizer(wxVERTICAL); + m_pMainSizer = new wxBoxSizer(wxVERTICAL); - // m_TopSizer = new wxBoxSizer(wxVERTICAL); - - // m_BottomLeftPanelMainSizer = new wxBoxSizer(wxVERTICAL); - m_TopPanelMainSizer = new wxBoxSizer(wxVERTICAL); - // m_BottomRightPanelMainSizer = new wxBoxSizer(wxVERTICAL); - - // m_WaveformDisplaySizer = new wxBoxSizer(wxHORIZONTAL); - - // m_HivesMainSizer = new wxBoxSizer(wxVERTICAL); - // m_HivesFavoritesSizer = new wxBoxSizer(wxVERTICAL); - // m_HivesButtonSizer = new wxBoxSizer(wxHORIZONTAL); - - // m_TrashMainSizer = new wxBoxSizer(wxVERTICAL); - // m_TrashItemSizer = new wxBoxSizer(wxVERTICAL); - // m_TrashButtonSizer = new wxBoxSizer(wxHORIZONTAL); - - // Main panel of the app - // m_MainPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); + m_pTopPanelMainSizer = new wxBoxSizer(wxVERTICAL); // Creating top splitter window - m_TopSplitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, - wxSP_NOBORDER | wxSP_LIVE_UPDATE | wxSP_THIN_SASH); - m_TopSplitter->SetMinimumPaneSize(200); - m_TopSplitter->SetSashGravity(0); + m_pTopSplitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, + wxSP_NOBORDER | wxSP_LIVE_UPDATE | wxSP_THIN_SASH); + m_pTopSplitter->SetMinimumPaneSize(200); + m_pTopSplitter->SetSashGravity(0); // Top half of TopSplitter window - m_TopPanel = new wxPanel(m_TopSplitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); + m_pTopPanel = new wxPanel(m_pTopSplitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); // Bottom half of the TopSplitter window - m_BottomSplitter = new wxSplitterWindow(m_TopSplitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, - wxSP_NOBORDER | wxSP_LIVE_UPDATE | wxSP_THIN_SASH); - m_BottomSplitter->SetMinimumPaneSize(300); - m_BottomSplitter->SetSashGravity(0); + m_pBottomSplitter = new wxSplitterWindow(m_pTopSplitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, + wxSP_NOBORDER | wxSP_LIVE_UPDATE | wxSP_THIN_SASH); + m_pBottomSplitter->SetMinimumPaneSize(300); + m_pBottomSplitter->SetSashGravity(0); - // Left half of the BottomSplitter window - // m_BottomLeftPanel = new wxPanel(m_BottomSplitter, wxID_ANY, - // wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); + m_pNotebook = new cNotebook(m_pBottomSplitter); - // m_Notebook = new cNotebook(m_BottomSplitter, *m_Library->GetListCtrlObject()); + m_pLibrary = new cLibrary(m_pBottomSplitter); - // Initializing wxNotebook - // m_Notebook = new wxNotebook(m_BottomLeftPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_TOP); - - // Initializing wxGenericDirCtrl as one of the wxNotebook page. - // m_DirCtrl = new wxGenericDirCtrl(m_Notebook, BC_DirCtrl, wxDirDialogDefaultFolderStr, wxDefaultPosition, - // wxDefaultSize, wxDIRCTRL_SHOW_FILTERS, - // _("All files|*|Ogg files (*.ogg)|*.ogg|Wav files (*.wav)|*.wav|" - // "Flac files (*.flac)|*.flac"), 0); - - // m_DirCtrl->SetPath(USER_HOME_DIR); - - // // This panel will hold 2nd page of wxNotebook - // m_HivesPanel = new wxPanel(m_Notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); - - // m_AddHiveButton = new wxButton(m_HivesPanel, BC_HiveAdd, "+", wxDefaultPosition, wxDefaultSize, 0); - // m_AddHiveButton->SetToolTip(_("Create new hive")); - // m_RemoveHiveButton = new wxButton(m_HivesPanel, BC_HiveRemove, "-", wxDefaultPosition, wxDefaultSize, 0); - // m_RemoveHiveButton->SetToolTip(_("Delete selected hive")); - - // // Initializing wxTreeCtrl as another page of wxNotebook - // m_Hives = new wxDataViewTreeCtrl(m_HivesPanel, BC_Hives, wxDefaultPosition, wxDefaultSize, - // wxDV_NO_HEADER | wxDV_SINGLE); - - // // Adding default hive - // favorites_hive = m_Hives->AppendContainer(wxDataViewItem(wxNullPtr), _("Favorites")); - - // // Setting m_Hives to accept files to be dragged and dropped on it - // m_Hives->DragAcceptFiles(true); - - // m_TrashPanel = new wxPanel(m_Notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); - - // m_Trash = new wxTreeCtrl(m_TrashPanel, BC_Trash, wxDefaultPosition, wxDefaultSize, - // wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_MULTIPLE); - - // // Setting m_Trash to accept files to be dragged and dropped on it - // m_Trash->DragAcceptFiles(true); - - // m_RestoreTrashedItemButton = new wxButton(m_TrashPanel, BC_RestoreTrashedItem, _("Restore sample"), - // wxDefaultPosition, wxDefaultSize, 0); - // m_RestoreTrashedItemButton->SetToolTip(_("Restore selected sample")); - - // // Addubg root to TrashedItems - // trash_root = m_Trash->AddRoot("Trash"); - - // // Adding the pages to wxNotebook - // m_Notebook->AddPage(m_DirCtrl, _("Browse"), false); - // m_Notebook->AddPage(m_HivesPanel, _("Hives"), false); - // m_Notebook->AddPage(m_TrashPanel, _("Trash"), false); - - // Right half of BottomSlitter window - // m_BottomRightPanel = new wxPanel(m_BottomSplitter, wxID_ANY, - // wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); - - m_Notebook = new cNotebook(m_BottomSplitter); - - m_Library = new cLibrary(m_BottomSplitter, - m_Notebook->GetHivesPanel()->GetFavoritesHive(), - *m_Notebook->GetHivesPanel()->GetHivesObject(), - m_Notebook->GetTrashPanel()->GetTrashRoot(), - *m_Notebook->GetTrashPanel()->GetTrashObject()); - - m_Notebook->SetListCtrlObject(*m_Library->GetListCtrlObject()); + SampleHive::cHiveData::Get().InitHiveData(*m_pLibrary->GetListCtrlObject(), + *m_pNotebook->GetHivesPanel()->GetHivesObject(), + m_pNotebook->GetHivesPanel()->GetFavoritesHive(), + *m_pNotebook->GetTrashPanel()->GetTrashObject(), + m_pNotebook->GetTrashPanel()->GetTrashRoot()); // Set split direction - m_TopSplitter->SplitHorizontally(m_TopPanel, m_BottomSplitter); - m_BottomSplitter->SplitVertically(m_Notebook, m_Library); - - // Initializing wxSearchCtrl on bottom panel. - // m_SearchBox = new wxSearchCtrl(m_BottomRightPanel, BC_Search, _("Search for samples.."), - // wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER); - - // // Set minimum and maximum size of m_SearchBox - // // so it doesn't expand too wide when resizing the main frame. - // m_SearchBox->SetMinSize(wxSize(-1, 38)); - // m_SearchBox->SetMaxSize(wxSize(-1, 38)); - - // m_SearchBox->ShowSearchButton(true); - // m_SearchBox->ShowCancelButton(true); - - // // Initializing wxDataViewListCtrl on bottom panel. - // m_Library = new wxDataViewListCtrl(m_BottomRightPanel, BC_Library, wxDefaultPosition, wxDefaultSize, - // wxDV_MULTIPLE | wxDV_HORIZ_RULES | wxDV_VERT_RULES | wxDV_ROW_LINES); - - // // Adding columns to wxDataViewListCtrl. - // m_Library->AppendBitmapColumn(wxBitmap(ICON_STAR_FILLED_16px), - // 0, - // wxDATAVIEW_CELL_ACTIVATABLE, - // 30, - // wxALIGN_CENTER, - // !wxDATAVIEW_COL_RESIZABLE); - // m_Library->AppendTextColumn(_("Filename"), - // wxDATAVIEW_CELL_INERT, - // 250, - // wxALIGN_LEFT, - // wxDATAVIEW_COL_RESIZABLE | - // wxDATAVIEW_COL_SORTABLE | - // wxDATAVIEW_COL_REORDERABLE); - // m_Library->AppendTextColumn(_("Sample Pack"), - // wxDATAVIEW_CELL_INERT, - // 180, - // wxALIGN_LEFT, - // wxDATAVIEW_COL_RESIZABLE | - // wxDATAVIEW_COL_SORTABLE | - // wxDATAVIEW_COL_REORDERABLE); - // m_Library->AppendTextColumn(_("Type"), - // wxDATAVIEW_CELL_INERT, - // 120, - // wxALIGN_LEFT, - // wxDATAVIEW_COL_RESIZABLE | - // wxDATAVIEW_COL_SORTABLE | - // wxDATAVIEW_COL_REORDERABLE); - // m_Library->AppendTextColumn(_("Channels"), - // wxDATAVIEW_CELL_INERT, - // 90, - // wxALIGN_RIGHT, - // wxDATAVIEW_COL_RESIZABLE | - // wxDATAVIEW_COL_SORTABLE | - // wxDATAVIEW_COL_REORDERABLE); - // m_Library->AppendTextColumn(_("Length"), - // wxDATAVIEW_CELL_INERT, - // 80, - // wxALIGN_RIGHT, - // wxDATAVIEW_COL_RESIZABLE | - // wxDATAVIEW_COL_SORTABLE | - // wxDATAVIEW_COL_REORDERABLE); - // m_Library->AppendTextColumn(_("Sample Rate"), - // wxDATAVIEW_CELL_INERT, - // 120, - // wxALIGN_RIGHT, - // wxDATAVIEW_COL_RESIZABLE | - // wxDATAVIEW_COL_SORTABLE | - // wxDATAVIEW_COL_REORDERABLE); - // m_Library->AppendTextColumn(_("Bitrate"), - // wxDATAVIEW_CELL_INERT, - // 80, - // wxALIGN_RIGHT, - // wxDATAVIEW_COL_RESIZABLE | - // wxDATAVIEW_COL_SORTABLE | - // wxDATAVIEW_COL_REORDERABLE); - // m_Library->AppendTextColumn(_("Path"), - // wxDATAVIEW_CELL_INERT, - // 250, - // wxALIGN_LEFT, - // wxDATAVIEW_COL_RESIZABLE | - // wxDATAVIEW_COL_SORTABLE | - // wxDATAVIEW_COL_REORDERABLE); - - // // Enable Library to accept files to be dropped on it - // m_Library->DragAcceptFiles(true); - - // // Enable dragging a file from Library - // m_Library->EnableDragSource(wxDF_FILENAME); - - // Initialize wxInfoBar for showing information inside application - // m_InfoBar = new wxInfoBar(m_BottomRightPanel); + m_pTopSplitter->SplitHorizontally(m_pTopPanel, m_pBottomSplitter); + m_pBottomSplitter->SplitVertically(m_pNotebook, m_pLibrary); // Initializing wxMediaCtrl. - m_MediaCtrl = new wxMediaCtrl(this, BC_MediaCtrl, wxEmptyString, wxDefaultPosition, - wxDefaultSize, 0, wxEmptyString); + m_pMediaCtrl = new wxMediaCtrl(this, SampleHive::ID::BC_MediaCtrl, wxEmptyString, wxDefaultPosition, + wxDefaultSize, 0, wxEmptyString); // Intializing wxTimer - m_Timer = new wxTimer(this); + m_pTimer = new wxTimer(this); - m_TransportControls = new cTransportControls(m_TopPanel, *m_Library->GetListCtrlObject(), *m_MediaCtrl, *m_Timer); - m_WaveformViewer = new cWaveformViewer(m_TopPanel, *m_Library->GetListCtrlObject(), *m_MediaCtrl, *m_Database); + m_pTransportControls = new cTransportControls(m_pTopPanel, *m_pMediaCtrl); + m_pWaveformViewer = new cWaveformViewer(m_pTopPanel, *m_pMediaCtrl, *m_pDatabase); // Binding events. - Bind(wxEVT_MENU, &MainFrame::OnSelectAddFile, this, MN_AddFile); - Bind(wxEVT_MENU, &MainFrame::OnSelectAddDirectory, this, MN_AddDirectory); - Bind(wxEVT_MENU, &MainFrame::OnSelectToggleExtension, this, MN_ToggleExtension); - Bind(wxEVT_MENU, &MainFrame::OnSelectToggleMenuBar, this, MN_ToggleMenuBar); - Bind(wxEVT_MENU, &MainFrame::OnSelectToggleStatusBar, this, MN_ToggleStatusBar); - Bind(wxEVT_MENU, &MainFrame::OnSelectExit, this, wxID_EXIT); - Bind(wxEVT_MENU, &MainFrame::OnSelectPreferences, this, wxID_PREFERENCES); - Bind(wxEVT_MENU, &MainFrame::OnSelectResetAppData, this, wxID_REFRESH); - Bind(wxEVT_MENU, &MainFrame::OnSelectAbout, this, wxID_ABOUT); + Bind(wxEVT_MENU, &cMainFrame::OnSelectAddFile, this, SampleHive::ID::MN_AddFile); + Bind(wxEVT_MENU, &cMainFrame::OnSelectAddDirectory, this, SampleHive::ID::MN_AddDirectory); + Bind(wxEVT_MENU, &cMainFrame::OnSelectToggleExtension, this, SampleHive::ID::MN_ToggleExtension); + Bind(wxEVT_MENU, &cMainFrame::OnSelectToggleMenuBar, this, SampleHive::ID::MN_ToggleMenuBar); + Bind(wxEVT_MENU, &cMainFrame::OnSelectToggleStatusBar, this, SampleHive::ID::MN_ToggleStatusBar); + Bind(wxEVT_MENU, &cMainFrame::OnSelectExit, this, wxID_EXIT); + Bind(wxEVT_MENU, &cMainFrame::OnSelectPreferences, this, wxID_PREFERENCES); + Bind(wxEVT_MENU, &cMainFrame::OnSelectResetAppData, this, wxID_REFRESH); + Bind(wxEVT_MENU, &cMainFrame::OnSelectAbout, this, wxID_ABOUT); - Bind(wxEVT_SPLITTER_SASH_POS_CHANGING, &MainFrame::OnTopSplitterSashPosChanged, - this, m_TopSplitter->GetId()); - Bind(wxEVT_SPLITTER_SASH_POS_CHANGING, &MainFrame::OnBottomSplitterSashPosChanged, - this, m_BottomSplitter->GetId()); + Bind(wxEVT_SPLITTER_SASH_POS_CHANGING, &cMainFrame::OnTopSplitterSashPosChanged, this, m_pTopSplitter->GetId()); + Bind(wxEVT_SPLITTER_SASH_POS_CHANGING, &cMainFrame::OnBottomSplitterSashPosChanged, this, m_pBottomSplitter->GetId()); - this->Connect(wxEVT_SIZE, wxSizeEventHandler(MainFrame::OnResizeFrame), NULL, this); - m_StatusBar->Connect(wxEVT_SIZE, wxSizeEventHandler(MainFrame::OnResizeStatusBar), NULL, this); + this->Connect(wxEVT_SIZE, wxSizeEventHandler(cMainFrame::OnResizeFrame), NULL, this); + m_pStatusBar->Connect(wxEVT_SIZE, wxSizeEventHandler(cMainFrame::OnResizeStatusBar), NULL, this); - // Bind(wxEVT_DIRCTRL_FILEACTIVATED, &MainFrame::OnClickDirCtrl, this, BC_DirCtrl); - // Bind(wxEVT_TREE_BEGIN_DRAG, &MainFrame::OnDragFromDirCtrl, this, m_DirCtrl->GetTreeCtrl()->GetId()); + Bind(wxEVT_MEDIA_FINISHED, &cMainFrame::OnMediaFinished, this, SampleHive::ID::BC_MediaCtrl); - // Bind(SampleHive::SH_EVT_CALL_FUNC_PLAY, &MainFrame::OnRecieveCallFunctionPlay, this); + Bind(wxEVT_TIMER, &cMainFrame::UpdateElapsedTime, this); - // Bind(wxEVT_MEDIA_FINISHED, &MainFrame::OnMediaFinished, this, BC_MediaCtrl); - // Bind(wxEVT_BUTTON, &MainFrame::OnClickSettings, this, BC_Settings); - - // Bind(wxEVT_TIMER, &MainFrame::UpdateElapsedTime, this); - - // m_Trash->Connect(wxEVT_DROP_FILES, wxDropFilesEventHandler(MainFrame::OnDragAndDropToTrash), NULL, this); - // Bind(wxEVT_TREE_ITEM_RIGHT_CLICK, &MainFrame::OnShowTrashContextMenu, this, BC_Trash); - // Bind(wxEVT_BUTTON, &MainFrame::OnClickRestoreTrashItem, this, BC_RestoreTrashedItem); - - // Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &MainFrame::OnClickLibrary, this, BC_Library); - // Bind(wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, &MainFrame::OnDragFromLibrary, this); - // m_Library->Connect(wxEVT_DROP_FILES, - // wxDropFilesEventHandler(MainFrame::OnDragAndDropToLibrary), NULL, this); - // Bind(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &MainFrame::OnShowLibraryContextMenu, this, BC_Library); - // Bind(wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, - // &MainFrame::OnShowLibraryColumnHeaderContextMenu, this, BC_Library); - - // Bind(wxEVT_TEXT, &MainFrame::OnDoSearch, this, BC_Search); - // Bind(wxEVT_SEARCHCTRL_SEARCH_BTN, &MainFrame::OnDoSearch, this, BC_Search); - // Bind(wxEVT_SEARCHCTRL_CANCEL_BTN, &MainFrame::OnCancelSearch, this, BC_Search); - - // m_Hives->Connect(wxEVT_DROP_FILES, wxDropFilesEventHandler(MainFrame::OnDragAndDropToHives), NULL, this); - // Bind(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &MainFrame::OnShowHivesContextMenu, this, BC_Hives); - // Bind(wxEVT_DATAVIEW_ITEM_START_EDITING, &MainFrame::OnHiveStartEditing, this, BC_Hives); - // Bind(wxEVT_BUTTON, &MainFrame::OnClickAddHive, this, BC_HiveAdd); - // Bind(wxEVT_BUTTON, &MainFrame::OnClickRemoveHive, this, BC_HiveRemove); - - Bind(SampleHive::SH_EVT_LOOP_POINTS_UPDATED, &MainFrame::OnRecieveLoopPoints, this); - Bind(SampleHive::SH_EVT_STATUSBAR_STATUS_PUSH, &MainFrame::OnRecievePushStatusBarStatus, this); - Bind(SampleHive::SH_EVT_STATUSBAR_STATUS_POP, &MainFrame::OnRecievePopStatusBarStatus, this); - Bind(SampleHive::SH_EVT_STATUSBAR_STATUS_SET, &MainFrame::OnRecieveSetStatusBarStatus, this); - Bind(SampleHive::SH_EVT_INFOBAR_MESSAGE_SHOW, &MainFrame::OnRecieveInfoBarStatus, this); - Bind(SampleHive::SH_EVT_TIMER_STOP, &MainFrame::OnRecieveTimerStopStatus, this); - Bind(SampleHive::SH_EVT_UPDATE_WAVEFORM, &MainFrame::OnRecieveWaveformUpdateStatus, this); - Bind(SampleHive::SH_EVT_CALL_FUNC_PLAY, &MainFrame::OnRecieveCallFunctionPlay, this); + Bind(SampleHive::SH_EVT_LOOP_POINTS_UPDATED, &cMainFrame::OnRecieveLoopPoints, this); + Bind(SampleHive::SH_EVT_LOOP_POINTS_CLEAR, &cMainFrame::OnRecieveClearLoopPointsStatus, this); + Bind(SampleHive::SH_EVT_STATUSBAR_STATUS_PUSH, &cMainFrame::OnRecievePushStatusBarStatus, this); + Bind(SampleHive::SH_EVT_STATUSBAR_STATUS_POP, &cMainFrame::OnRecievePopStatusBarStatus, this); + Bind(SampleHive::SH_EVT_STATUSBAR_STATUS_SET, &cMainFrame::OnRecieveSetStatusBarStatus, this); + Bind(SampleHive::SH_EVT_INFOBAR_MESSAGE_SHOW, &cMainFrame::OnRecieveInfoBarStatus, this); + Bind(SampleHive::SH_EVT_TIMER_STOP, &cMainFrame::OnRecieveTimerStopStatus, this); + Bind(SampleHive::SH_EVT_UPDATE_WAVEFORM, &cMainFrame::OnRecieveWaveformUpdateStatus, this); + Bind(SampleHive::SH_EVT_CALL_FUNC_PLAY, &cMainFrame::OnRecieveCallFunctionPlay, this); + Bind(SampleHive::SH_EVT_LOOP_AB_BUTTON_VALUE_CHANGE, &cMainFrame::OnRecieveLoopABButtonValueChange, this); // Adding widgets to their sizers - m_MainSizer->Add(m_TopSplitter, 1, wxALL | wxEXPAND, 0); + m_pMainSizer->Add(m_pTopSplitter, 1, wxALL | wxEXPAND, 0); - // m_TopSizer->Add(m_TopSplitter, 1, wxALL | wxEXPAND, 0); - - m_TopPanelMainSizer->Add(m_WaveformViewer, 1, wxALL | wxEXPAND, 2); - m_TopPanelMainSizer->Add(m_TransportControls, 0, wxALL | wxEXPAND, 2); - - // m_BottomLeftPanelMainSizer->Add(m_Notebook, 1, wxALL | wxEXPAND, 0); - - // m_HivesFavoritesSizer->Add(m_Hives, 1, wxALL | wxEXPAND, 0); - - // m_HivesButtonSizer->Add(m_AddHiveButton, 1, wxALL | wxEXPAND, 0); - // m_HivesButtonSizer->Add(m_RemoveHiveButton, 1, wxALL | wxEXPAND, 0); - - // m_HivesMainSizer->Add(m_HivesFavoritesSizer, 1, wxALL | wxEXPAND, 0); - // m_HivesMainSizer->Add(m_HivesButtonSizer, 0, wxALL | wxEXPAND, 0); - - // m_TrashItemSizer->Add(m_Trash, 1, wxALL | wxEXPAND, 0); - // m_TrashButtonSizer->Add(m_RestoreTrashedItemButton, 1, wxALL | wxEXPAND, 0); - - // m_TrashMainSizer->Add(m_TrashItemSizer, 1, wxALL | wxEXPAND, 0); - // m_TrashMainSizer->Add(m_TrashButtonSizer, 0, wxALL | wxEXPAND, 0); - - // m_BottomRightPanelMainSizer->Add(m_SearchBox, 1, wxALL | wxEXPAND, 2); - // m_BottomRightPanelMainSizer->Add(m_InfoBar, 0, wxALL | wxEXPAND, 0); - // m_BottomRightPanelMainSizer->Add(m_Library, 1, wxALL | wxEXPAND, 0); + m_pTopPanelMainSizer->Add(m_pWaveformViewer, 1, wxALL | wxEXPAND, 2); + m_pTopPanelMainSizer->Add(m_pTransportControls, 0, wxALL | wxEXPAND, 2); // Sizer for the frame - this->SetSizer(m_MainSizer); + this->SetSizer(m_pMainSizer); this->Layout(); this->Center(wxBOTH); - // Sizer for the main panel - // m_MainPanel->SetSizer(m_TopSizer); - // m_TopSizer->Fit(m_MainPanel); - // m_TopSizer->SetSizeHints(m_MainPanel); - // m_TopSizer->Layout(); - - // m_WaveformViewer->SetSizer(m_WaveformDisplaySizer); - // m_WaveformDisplaySizer->Fit(m_WaveformViewer); - // m_WaveformDisplaySizer->SetSizeHints(m_WaveformViewer); - // m_WaveformDisplaySizer->Layout(); - // Sizer for TopPanel - m_TopPanel->SetSizer(m_TopPanelMainSizer); - m_TopPanelMainSizer->Fit(m_TopPanel); - m_TopPanelMainSizer->SetSizeHints(m_TopPanel); - m_TopPanelMainSizer->Layout(); - - // Sizer for bottom left panel - // m_Notebook->SetSizer(m_BottomLeftPanelMainSizer); - // m_BottomLeftPanelMainSizer->Fit(m_Notebook); - // m_BottomLeftPanelMainSizer->SetSizeHints(m_Notebook); - // m_BottomLeftPanelMainSizer->Layout(); - - // Sizer for Hives page for wxNotebook - // m_HivesPanel->SetSizer(m_HivesMainSizer); - // m_HivesMainSizer->Fit(m_HivesPanel); - // m_HivesMainSizer->SetSizeHints(m_HivesPanel); - // m_HivesMainSizer->Layout(); - - // Sizer for trash pane - // m_TrashPanel->SetSizer(m_TrashMainSizer); - // m_TrashMainSizer->Fit(m_TrashPanel); - // m_TrashMainSizer->SetSizeHints(m_TrashPanel); - // m_TrashMainSizer->Layout(); - - // Sizer for bottom right panel - // m_BottomRightPanel->SetSizer(m_BottomRightPanelMainSizer); - // m_BottomRightPanelMainSizer->Fit(m_BottomRightPanel); - // m_BottomRightPanelMainSizer->SetSizeHints(m_BottomRightPanel); - // m_BottomRightPanelMainSizer->Layout(); + m_pTopPanel->SetSizer(m_pTopPanelMainSizer); + m_pTopPanelMainSizer->Fit(m_pTopPanel); + m_pTopPanelMainSizer->SetSizeHints(m_pTopPanel); + m_pTopPanelMainSizer->Layout(); // Restore the data previously added to Library - // LoadDatabase(); + LoadDatabase(); // Set some properites after the frame has been created - CallAfter(&MainFrame::SetAfterFrameCreate); + CallAfter(&cMainFrame::SetAfterFrameCreate); } -// void MainFrame::OnClickSettings(wxCommandEvent& event) -// { -// Settings* settings = new Settings(this); - -// switch (settings->ShowModal()) -// { -// case wxID_OK: -// if (settings->CanAutoImport()) -// { -// OnAutoImportDir(settings->GetImportDirPath()); -// RefreshDatabase(); -// } -// if (settings->IsWaveformColourChanged()) -// { -// m_WaveformViewer->ResetDC(); -// } -// break; -// case wxID_CANCEL: -// break; -// default: -// return; -// } -// } - -// void MainFrame::AddSamples(wxArrayString& files) -// { -// Serializer serializer; - -// wxBusyCursor busy_cursor; -// wxWindowDisabler window_disabler; - -// wxProgressDialog* progressDialog = new wxProgressDialog(_("Adding files.."), -// _("Adding files, please wait..."), -// static_cast(files.size()), this, -// wxPD_APP_MODAL | wxPD_SMOOTH | wxPD_CAN_ABORT | -// wxPD_AUTO_HIDE); -// progressDialog->CenterOnParent(wxBOTH); - -// std::vector sample_array; - -// std::string path; -// std::string artist; -// std::string filename_with_extension; -// std::string filename_without_extension; -// std::string extension; -// std::string filename; - -// //Check All Files At Once -// wxArrayString sorted_files; - -// sorted_files = m_Database->CheckDuplicates(files); -// files = sorted_files; - -// if(files.size() < 1) -// { -// progressDialog->Destroy(); -// return; -// } - -// progressDialog->SetRange(files.size()); - -// for(unsigned int i = 0; i < files.size(); i++) -// { -// progressDialog->Update(i, wxString::Format(_("Getting Data For %s"), files[i].AfterLast('/'))); - -// if(progressDialog->WasCancelled()) -// { -// progressDialog->Destroy(); -// return; -// } - -// path = files[i].ToStdString(); -// filename_with_extension = files[i].AfterLast('/').ToStdString(); -// filename_without_extension = files[i].AfterLast('/').BeforeLast('.').ToStdString(); -// extension = files[i].AfterLast('.').ToStdString(); - -// filename = serializer.DeserializeShowFileExtension() ? -// filename_with_extension : filename_without_extension; - -// Sample sample; - -// sample.SetPath(path); -// sample.SetFilename(filename_without_extension); -// sample.SetFileExtension(extension); - -// Tags tags(path); - -// artist = tags.GetAudioInfo().artist.ToStdString(); - -// sample.SetSamplePack(artist); -// sample.SetChannels(tags.GetAudioInfo().channels); -// sample.SetLength(tags.GetAudioInfo().length); -// sample.SetSampleRate(tags.GetAudioInfo().sample_rate); -// sample.SetBitrate(tags.GetAudioInfo().bitrate); - -// wxLongLong llLength = sample.GetLength(); -// int total_min = static_cast((llLength / 60000).GetValue()); -// int total_sec = static_cast(((llLength % 60000) / 1000).GetValue()); - -// wxVector data; - -// wxVariant icon = wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)); - -// if (tags.IsFileValid()) -// { -// data.clear(); -// data.push_back(icon); -// data.push_back(filename); -// data.push_back(sample.GetSamplePack()); -// data.push_back(""); -// data.push_back(wxString::Format("%d", sample.GetChannels())); -// data.push_back(wxString::Format("%2i:%02i", total_min, total_sec)); -// data.push_back(wxString::Format("%d", sample.GetSampleRate())); -// data.push_back(wxString::Format("%d", sample.GetBitrate())); -// data.push_back(path); - -// SH_LOG_INFO("Adding file: {}, Extension: {}", sample.GetFilename(), sample.GetFileExtension()); - -// m_Library->AppendItem(data); - -// sample_array.push_back(sample); -// } -// else -// { -// wxString msg = wxString::Format(_("Error! Cannot open %s, Invalid file type."), -// filename_with_extension); -// m_InfoBar->ShowMessage(msg, wxICON_ERROR); -// } -// } - -// progressDialog->Pulse(_("Updating Database.."), NULL); - -// m_Database->InsertIntoSamples(sample_array); - -// progressDialog->Destroy(); -// } - -// void MainFrame::OnClickDirCtrl(wxCommandEvent& event) -// { -// wxArrayString path; -// path.push_back(m_DirCtrl->GetFilePath()); - -// AddSamples(path); -// } - -// void MainFrame::OnDragAndDropToLibrary(wxDropFilesEvent& event) -// { -// SH_LOG_DEBUG("Start Inserting Samples"); - -// if (event.GetNumberOfFiles() > 0) -// { -// wxString* dropped = event.GetFiles(); -// wxASSERT(dropped); - -// wxBusyCursor busy_cursor; -// wxWindowDisabler window_disabler; - -// wxString name; -// wxString filepath; -// wxArrayString filepath_array; - -// wxProgressDialog* progressDialog = new wxProgressDialog(_("Reading files.."), -// _("Reading files, please wait..."), -// event.GetNumberOfFiles(), this, -// wxPD_APP_MODAL | wxPD_SMOOTH | -// wxPD_CAN_ABORT | wxPD_AUTO_HIDE); - -// progressDialog->CenterOnParent(wxBOTH); - -// wxYield(); - -// for (int i = 0; i < event.GetNumberOfFiles(); i++) -// { -// filepath = dropped[i]; - -// if (wxFileExists(filepath)) -// { -// filepath_array.push_back(filepath); -// } -// else if (wxDirExists(filepath)) -// { -// wxDir::GetAllFiles(filepath, &filepath_array); -// } - -// progressDialog->Pulse(_("Reading Samples"), NULL); -// } - -// progressDialog->Destroy(); - -// AddSamples(filepath_array); - -// SH_LOG_DEBUG("Done Inserting Samples"); -// } -// } - -// void MainFrame::OnDragAndDropToHives(wxDropFilesEvent& event) -// { -// Serializer serializer; - -// if (event.GetNumberOfFiles() > 0) -// { -// wxFileDataObject file_data; -// wxArrayString files; - -// wxDataViewItemArray items; -// int rows = m_Library->GetSelections(items); - -// wxDataViewItem drop_target;; -// wxDataViewColumn* column; -// wxPoint position = event.GetPosition(); - -// m_Hives->HitTest(position, drop_target, column); - -// wxString hive_name = m_Hives->GetItemText(drop_target); - -// wxString msg; - -// for (int i = 0; i < rows; i++) -// { -// int row = m_Library->ItemToRow(items[i]); - -// wxString name = m_Library->GetTextValue(row, 1); - -// file_data.AddFile(name); - -// files = file_data.GetFilenames(); - -// wxString file_name = serializer.DeserializeShowFileExtension() ? -// files[i].BeforeLast('.') : files[i]; - -// SH_LOG_DEBUG("Dropping {} file(s) {} on {}", rows - i, files[i], m_Hives->GetItemText(drop_target)); - -// if (drop_target.IsOk() && m_Hives->IsContainer(drop_target) && -// m_Database->GetFavoriteColumnValueByFilename(file_name.ToStdString()) == 0) -// { -// m_Hives->AppendItem(drop_target, files[i]); - -// m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), row, 0); - -// m_Database->UpdateFavoriteColumn(file_name.ToStdString(), 1); -// m_Database->UpdateHiveName(file_name.ToStdString(), hive_name.ToStdString()); - -// msg = wxString::Format(_("%s added to %s."), files[i], hive_name); -// } -// else -// { -// if (m_Database->GetFavoriteColumnValueByFilename(file_name.ToStdString()) == 1) -// { -// wxMessageBox(wxString::Format(_("%s is already added to %s hive"), files[i], -// m_Database->GetHiveByFilename(file_name.ToStdString())), -// _("Error!"), wxOK | wxICON_ERROR | wxCENTRE, this); -// } -// else -// { -// if (m_Hives->GetItemText(drop_target) == "") -// wxMessageBox(_("Cannot drop item outside of a hive, try dropping on a hive."), -// _("Error!"), wxOK | wxICON_ERROR | wxCENTRE, this); -// else -// wxMessageBox(wxString::Format(_("%s is not a hive, try dropping on a hive."), -// m_Hives->GetItemText(drop_target)), _("Error!"), -// wxOK | wxICON_ERROR | wxCENTRE, this); -// } -// } - -// if (!msg.IsEmpty()) -// m_InfoBar->ShowMessage(msg, wxICON_ERROR); -// } -// } -// } - -// void MainFrame::OnAutoImportDir(const wxString& pathToDirectory) -// { -// SH_LOG_DEBUG("Start Importing Samples"); - -// wxBusyCursor busy_cursor; -// wxWindowDisabler window_disabler; - -// wxString filepath; -// wxArrayString filepath_array; - -// size_t number_of_files = wxDir::GetAllFiles(pathToDirectory, &filepath_array, -// wxEmptyString, wxDIR_DEFAULT); - -// wxProgressDialog* progressDialog = new wxProgressDialog(_("Adding files.."), -// _("Adding files, please wait..."), -// static_cast(number_of_files), this, -// wxPD_APP_MODAL | wxPD_SMOOTH | -// wxPD_CAN_ABORT | wxPD_AUTO_HIDE); - -// progressDialog->CenterOnParent(wxBOTH); - -// for (size_t i = 0; i < number_of_files; i++) -// { -// filepath = filepath_array[i]; - -// if (wxFileExists(filepath)) -// { -// filepath_array.push_back(filepath); -// } -// else if (wxDirExists(filepath)) -// { -// wxDir::GetAllFiles(filepath, &filepath_array); -// } - -// progressDialog->Pulse(_("Reading Samples"), NULL); -// } - -// progressDialog->Destroy(); - -// AddSamples(filepath_array); - -// SH_LOG_DEBUG("Done Importing Samples"); -// } - -// // Temporary function to check drag and drop result -// void LogDragResult(wxDragResult result) -// { -// wxString msg; -// switch (result) -// { -// case wxDragError: msg = "Error!"; break; -// case wxDragNone: msg = "Nothing"; break; -// case wxDragCopy: msg = "Copied"; break; -// case wxDragMove: msg = "Moved"; break; -// case wxDragCancel: msg = "Cancelled"; break; -// default: msg = "Huh?"; break; -// } - -// SH_LOG_DEBUG("Drag result: {}", msg); -// } - -// void MainFrame::OnDragFromDirCtrl(wxTreeEvent& event) -// { -// wxFileDataObject file_data; -// file_data.AddFile(m_DirCtrl->GetPath(event.GetItem())); - -// wxDropSource drop_source(this); -// drop_source.SetData(file_data); - -// LogDragResult(drop_source.DoDragDrop()); -// } - -// void MainFrame::OnDragFromLibrary(wxDataViewEvent& event) -// { -// int selected_row = m_Library->ItemToRow(event.GetItem()); - -// if (selected_row < 0) -// return; - -// wxString selection = m_Library->GetTextValue(selected_row, 1); - -// wxString sample_path = GetFilenamePathAndExtension(selection).Path; - -// wxFileDataObject* fileData = new wxFileDataObject(); - -// fileData->AddFile(sample_path); -// event.SetDataObject(fileData); - -// SH_LOG_DEBUG("Started dragging '{}'.", sample_path); -// } - -void MainFrame::OnMediaFinished(wxMediaEvent& event) +void cMainFrame::OnMediaFinished(wxMediaEvent& event) { - if (m_TransportControls->CanLoop()) + if (m_pTransportControls->CanLoop()) { - if (!m_MediaCtrl->Play()) + if (!m_pMediaCtrl->Play()) { wxMessageDialog msgDialog(NULL, _("Error! Cannot loop media."), _("Error"), wxOK | wxICON_ERROR); msgDialog.ShowModal(); } else - m_MediaCtrl->Play(); + m_pMediaCtrl->Play(); } else { - if (m_Timer->IsRunning()) + if (m_pTimer->IsRunning()) { - m_Timer->Stop(); + m_pTimer->Stop(); SH_LOG_DEBUG("TIMER STOPPED"); } - m_TransportControls->SetSamplePositionText("--:--/--:--"); + m_pTransportControls->SetSamplePositionText("--:--/--:--"); PopStatusText(1); this->SetStatusText(_("Stopped"), 1); } } -void MainFrame::UpdateElapsedTime(wxTimerEvent& event) +void cMainFrame::UpdateElapsedTime(wxTimerEvent& event) { SH_LOG_DEBUG("TIMER IS RUNNING.."); wxString duration, position; wxLongLong llLength, llTell; - llLength = m_MediaCtrl->Length(); + llLength = m_pMediaCtrl->Length(); int total_min = static_cast((llLength / 60000).GetValue()); int total_sec = static_cast(((llLength % 60000) / 1000).GetValue()); - llTell = m_MediaCtrl->Tell(); + llTell = m_pMediaCtrl->Tell(); int current_min = static_cast((llTell / 60000).GetValue()); int current_sec = static_cast(((llTell % 60000) / 1000).GetValue()); duration.Printf(wxT("%2i:%02i"), total_min, total_sec); position.Printf(wxT("%2i:%02i"), current_min, current_sec); - m_TransportControls->SetSamplePositionText(wxString::Format(wxT("%s/%s"), - position.c_str(), duration.c_str())); + m_pTransportControls->SetSamplePositionText(wxString::Format(wxT("%s/%s"), position.c_str(), duration.c_str())); this->Refresh(); - m_TransportControls->Refresh(); - m_WaveformViewer->Refresh(); + m_pTransportControls->Refresh(); + m_pWaveformViewer->Refresh(); - if (bLoopPointsSet && m_TransportControls->IsLoopABOn()) - if (static_cast(m_MediaCtrl->Tell()) >= m_LoopB.ToDouble()) - m_MediaCtrl->Seek(m_LoopA.ToDouble(), wxFromStart); + if (m_bLoopPointsSet && m_pTransportControls->IsLoopABOn()) + if (static_cast(m_pMediaCtrl->Tell()) >= m_LoopB.ToDouble()) + m_pMediaCtrl->Seek(m_LoopA.ToDouble(), wxFromStart); } -// void MainFrame::OnClickLibrary(wxDataViewEvent& event) -// { -// int selected_row = m_Library->ItemToRow(event.GetItem()); -// int current_row = m_Library->ItemToRow(m_Library->GetCurrentItem()); - -// if (selected_row < 0 || !event.GetItem().IsOk()) -// return; - -// if (selected_row != current_row) -// { -// m_Library->SetCurrentItem(event.GetItem()); -// return; -// } - -// // Update the waveform bitmap -// m_WaveformViewer->ResetDC(); - -// m_TransportControls->SetLoopABValue(false); - -// if (m_Timer->IsRunning()) -// { -// m_Timer->Stop(); -// SH_LOG_DEBUG("TIMER STOPPED"); -// } - -// wxString selection = m_Library->GetTextValue(selected_row, 1); - -// // Get curremt column -// wxDataViewColumn* CurrentColumn = m_Library->GetCurrentColumn(); - -// // Get favorite column -// wxDataViewColumn* FavoriteColumn = m_Library->GetColumn(0); - -// if (!CurrentColumn) -// return; - -// wxString sample_path = GetFilenamePathAndExtension(selection).Path; -// std::string filename = GetFilenamePathAndExtension(selection).Filename; -// std::string extension = GetFilenamePathAndExtension(selection).Extension; - -// if (CurrentColumn != FavoriteColumn) -// { -// ClearLoopPoints(); - -// if (m_TransportControls->CanAutoplay()) -// { -// if (bLoopPointsSet && m_TransportControls->IsLoopABOn()) -// PlaySample(sample_path.ToStdString(), selection.ToStdString(), -// true, m_LoopA.ToDouble(), wxFromStart); -// else -// PlaySample(sample_path.ToStdString(), selection.ToStdString()); -// } -// else -// m_MediaCtrl->Stop(); -// } -// else -// { -// wxString msg; - -// // Get hive name and location -// std::string hive_name = m_Hives->GetItemText(favorites_hive).ToStdString(); -// wxDataViewItem hive_selection = m_Hives->GetSelection(); - -// if (hive_selection.IsOk() && m_Hives->IsContainer(hive_selection)) -// hive_name = m_Hives->GetItemText(hive_selection).ToStdString(); - -// wxString name = m_Library->GetTextValue(selected_row, 1); - -// // Get root -// wxDataViewItem root = wxDataViewItem(wxNullPtr); -// wxDataViewItem container; -// wxDataViewItem child; - -// if (m_Database->GetFavoriteColumnValueByFilename(filename) == 0) -// { -// m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), selected_row, 0); - -// m_Database->UpdateFavoriteColumn(filename, 1); -// m_Database->UpdateHiveName(filename, hive_name); - -// for (int i = 0; i < m_Hives->GetChildCount(root); i++) -// { -// container = m_Hives->GetNthChild(root, i); - -// if (m_Hives->GetItemText(container).ToStdString() == hive_name) -// { -// m_Hives->AppendItem(container, name); -// break; -// } -// } - -// msg = wxString::Format(_("Added %s to %s"), name, hive_name); -// } -// else -// { -// m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), selected_row, 0); - -// m_Database->UpdateFavoriteColumn(filename, 0); -// m_Database->UpdateHiveName(filename, m_Hives->GetItemText(favorites_hive).ToStdString()); - -// for (int i = 0; i < m_Hives->GetChildCount(root); i++) -// { -// container = m_Hives->GetNthChild(root, i); - -// for (int j = 0; j < m_Hives->GetChildCount(container); j++) -// { -// child = m_Hives->GetNthChild(container, j); - -// if (m_Hives->GetItemText(child) == name) -// { -// m_Hives->DeleteItem(child); -// break; -// } -// } -// } - -// msg = wxString::Format(_("Removed %s from %s"), name, hive_name); -// } - -// if (!msg.IsEmpty()) -// m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); -// } -// } - -// void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event) -// { -// Serializer serializer; - -// wxDataViewItem selected_hive = event.GetItem(); - -// wxString hive_name = m_Hives->GetItemText(selected_hive); - -// wxMenu menu; - -// if (m_Hives->IsContainer(selected_hive)) -// { -// // Container menu items -// menu.Append(MN_RenameHive, _("Rename hive"), _("Rename selected hive")); -// menu.Append(MN_DeleteHive, _("Delete hive"), _("Delete selected hive")); - -// if (!bFiltered) -// menu.Append(MN_FilterLibrary, _("Filter library"), -// _("Show only samples from current hive in library")); -// else -// menu.Append(MN_FilterLibrary, _("Clear filter"), _("Clear the filter")); -// } -// else -// { -// // Child menu items -// menu.Append(MN_RemoveSample, _("Remove sample"), _("Remove the selected sample(s)")); -// menu.Append(MN_ShowInLibrary, _("Show sample in library"), _("Show the selected in library")); -// } - -// if (selected_hive.IsOk() && m_Hives->IsContainer(selected_hive)) -// { -// switch (m_Hives->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) -// { -// case MN_RenameHive: -// { -// std::deque nodes; -// nodes.push_back(m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), 0)); - -// wxDataViewItem current_item, found_item; - -// int row = 0; -// int hive_count = m_Hives->GetChildCount(wxDataViewItem(wxNullPtr)); - -// wxString msg; - -// wxTextEntryDialog renameEntry(this, _("Enter new name"), wxGetTextFromUserPromptStr, -// wxEmptyString, wxTextEntryDialogStyle, wxDefaultPosition); - -// renameEntry.SetTextValidator(wxFILTER_EMPTY); - -// switch (renameEntry.ShowModal()) -// { -// case wxID_OK: -// { -// wxString hive_name = renameEntry.GetValue(); - -// while(!nodes.empty()) -// { -// current_item = nodes.front(); -// nodes.pop_front(); - -// if (m_Hives->GetItemText(current_item) == hive_name) -// { -// found_item = current_item; -// SH_LOG_DEBUG("Found item: {}", m_Hives->GetItemText(current_item)); -// break; -// } - -// wxDataViewItem child = m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), 0); - -// while (row < (hive_count - 1)) -// { -// row ++; - -// child = m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), row); -// nodes.push_back(child); -// } -// } - -// nodes.clear(); - -// if (found_item.IsOk()) -// { -// wxMessageBox(wxString::Format(_("Another hive by the name %s already exist. " -// "Please try with a different name."), -// hive_name), -// _("Error!"), wxOK | wxCENTRE, this); -// } -// else -// { -// wxString selected_hive_name = m_Hives->GetItemText(selected_hive); - -// int sample_count = m_Hives->GetChildCount(selected_hive); - -// if (sample_count <= 0) -// { -// m_Hives->SetItemText(selected_hive, hive_name); -// m_Database->UpdateHive(selected_hive_name.ToStdString(), -// hive_name.ToStdString()); -// } -// else -// { -// for (int i = 0; i < sample_count; i++) -// { -// wxDataViewItem sample_item = m_Hives->GetNthChild(selected_hive, i); - -// wxString sample_name = serializer.DeserializeShowFileExtension() ? -// m_Hives->GetItemText(sample_item).BeforeLast('.') : -// m_Hives->GetItemText(sample_item); - -// m_Database->UpdateHiveName(sample_name.ToStdString(), -// hive_name.ToStdString()); -// m_Database->UpdateHive(selected_hive_name.ToStdString(), -// hive_name.ToStdString()); - -// m_Hives->SetItemText(selected_hive, hive_name); -// } -// } - -// msg = wxString::Format(_("Successfully changed hive name to %s."), hive_name); -// } -// } -// break; -// case wxID_CANCEL: -// break; -// default: -// return; -// } - -// if (!msg.IsEmpty()) -// m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); -// } -// break; -// case MN_DeleteHive: -// { -// wxString msg; - -// wxMessageDialog deleteEmptyHiveDialog(this, wxString::Format(_("Are you sure you want to " -// "delete %s from hives?"), -// hive_name), -// wxMessageBoxCaptionStr, -// wxYES_NO | wxNO_DEFAULT | -// wxICON_QUESTION | wxSTAY_ON_TOP); - -// wxMessageDialog deleteFilledHiveDialog(this, wxString::Format(_("Are you sure you want to " -// "delete %s and all samples " -// "inside %s from hives?"), -// hive_name, hive_name), -// wxMessageBoxCaptionStr, -// wxYES_NO | wxNO_DEFAULT | -// wxICON_QUESTION | wxSTAY_ON_TOP); - -// if (hive_name == m_Hives->GetItemText(favorites_hive)) -// { -// wxMessageBox(wxString::Format(_("Error! Default hive %s cannot be deleted."), hive_name), -// _("Error!"), wxOK | wxCENTRE, this); -// return; -// } -// else if (!selected_hive.IsOk()) -// { -// wxMessageBox(_("No hive selected, try selecting a hive first"), _("Error!"), -// wxOK | wxCENTRE, this); -// return; -// } -// else if (selected_hive.IsOk() && !m_Hives->IsContainer(selected_hive)) -// { -// wxMessageBox(wxString::Format(_("Error! %s is not a hive, cannot delete from hives."), -// hive_name), -// _("Error!"), wxOK | wxCENTRE, this); -// return; -// } - -// if(m_Hives->GetChildCount(selected_hive) <= 0) -// { -// switch (deleteEmptyHiveDialog.ShowModal()) -// { -// case wxID_YES: -// if (selected_hive.IsOk() && m_Hives->IsContainer(selected_hive) && -// hive_name != m_Hives->GetItemText(favorites_hive)) -// { -// m_Hives->DeleteItem(selected_hive); - -// m_Database->RemoveHiveFromDatabase(hive_name.ToStdString()); - -// msg = wxString::Format(_("%s deleted from hives successfully."), hive_name); -// } -// break; -// case wxID_NO: -// break; -// default: -// return; -// } -// } -// else -// { -// switch (deleteFilledHiveDialog.ShowModal()) -// { -// case wxID_YES: -// if (selected_hive.IsOk() && m_Hives->IsContainer(selected_hive) && -// hive_name != m_Hives->GetItemText(favorites_hive)) -// { -// wxDataViewItem child_item; - -// for (int i = 0; i < m_Library->GetItemCount(); i++) -// { -// wxString matched_sample = -// serializer.DeserializeShowFileExtension() ? -// m_Library->GetTextValue(i, 1).BeforeLast('.') : -// m_Library->GetTextValue(i, 1); - -// for (int j = 0; j < m_Hives->GetChildCount(selected_hive); j++) -// { -// child_item = m_Hives->GetNthChild(selected_hive, j); - -// wxString child_name = -// serializer.DeserializeShowFileExtension() ? -// m_Hives->GetItemText(child_item).BeforeLast('.') : -// m_Hives->GetItemText(child_item); - -// if (child_name == matched_sample) -// { -// SH_LOG_DEBUG("Found match"); - -// m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), -// i, 0); - -// m_Database->UpdateFavoriteColumn(matched_sample.ToStdString(), 0); -// m_Database->UpdateHiveName(matched_sample.ToStdString(), -// m_Hives->GetItemText(favorites_hive).ToStdString()); - -// break; -// } -// else -// SH_LOG_DEBUG("No match found"); -// } -// } - -// m_Hives->DeleteChildren(selected_hive); -// m_Hives->DeleteItem(selected_hive); - -// m_Database->RemoveHiveFromDatabase(hive_name.ToStdString()); - -// msg = wxString::Format(_("%s and all samples inside %s " -// "have been deleted from hives successfully."), -// hive_name, hive_name); -// } -// break; -// case wxID_NO: -// break; -// default: -// return; -// } -// } - -// if (!msg.IsEmpty()) -// m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); -// } -// break; -// case MN_FilterLibrary: -// { -// if (!bFiltered) -// { -// try -// { -// const auto dataset = m_Database->FilterDatabaseByHiveName(hive_name.ToStdString(), -// serializer.DeserializeShowFileExtension(), -// ICON_STAR_FILLED_16px, -// ICON_STAR_EMPTY_16px); - -// if (dataset.empty()) -// { -// wxMessageBox(_("Error! Database is empty."), _("Error!"), -// wxOK | wxICON_ERROR | wxCENTRE, this); -// return; -// } -// else -// { -// m_Library->DeleteAllItems(); - -// for (auto data : dataset) -// { -// m_Library->AppendItem(data); -// } -// } -// } -// catch (...) -// { -// wxMessageBox(_("Error loading data, cannot filter sample view"), _("Error!"), -// wxOK | wxICON_ERROR | wxCENTRE, this); -// } - -// bFiltered = true; -// } -// else -// { -// try -// { -// const auto dataset = m_Database->FilterDatabaseBySampleName("", serializer.DeserializeShowFileExtension(), -// ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px); - -// if (dataset.empty()) -// { -// wxMessageBox(_("Error! Database is empty."), _("Error!"), -// wxOK | wxICON_ERROR | wxCENTRE, this); -// } -// else -// { -// m_Library->DeleteAllItems(); - -// for (auto data : dataset) -// { -// m_Library->AppendItem(data); -// } -// } -// } -// catch (...) -// { -// wxMessageBox(_("Error loading data, cannot filter sample view"), _("Error!"), -// wxOK | wxICON_ERROR | wxCENTRE, this); -// } - -// bFiltered = false; -// } -// } -// break; -// default: -// return; -// } -// } -// else if (selected_hive.IsOk() && !m_Hives->IsContainer(selected_hive)) -// { -// switch (m_Hives->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) -// { -// case MN_RemoveSample: -// for(int i = 0; i < m_Library->GetItemCount(); i++) -// { -// wxString matched_sample = serializer.DeserializeShowFileExtension() ? -// m_Library->GetTextValue(i, 1).BeforeLast('.') : -// m_Library->GetTextValue(i, 1); - -// wxString selected_sample_name = serializer.DeserializeShowFileExtension() ? -// m_Hives->GetItemText(event.GetItem()).BeforeLast('.') : -// m_Hives->GetItemText(event.GetItem()); - -// if(selected_sample_name == matched_sample) -// { -// SH_LOG_DEBUG("Found match"); - -// m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0); - -// m_Database->UpdateFavoriteColumn(matched_sample.ToStdString(), 0); -// m_Database->UpdateHiveName(matched_sample.ToStdString(), -// m_Hives->GetItemText(favorites_hive).ToStdString()); - -// m_Hives->DeleteItem(selected_hive); - -// break; -// } - -// m_InfoBar->ShowMessage(wxString::Format(_("Removed %s from %s"), -// m_Hives->GetItemText(event.GetItem()), -// m_Database->GetHiveByFilename(matched_sample.ToStdString())), -// wxICON_INFORMATION); -// } -// break; -// case MN_ShowInLibrary: -// for(int i = 0; i < m_Library->GetItemCount(); i++) -// { -// wxString matched_sample = serializer.DeserializeShowFileExtension() ? -// m_Library->GetTextValue(i, 1).BeforeLast('.') : -// m_Library->GetTextValue(i, 1); - -// wxString selected_sample_name = serializer.DeserializeShowFileExtension() ? -// m_Hives->GetItemText(event.GetItem()).BeforeLast('.') : -// m_Hives->GetItemText(event.GetItem()); - -// if(selected_sample_name == matched_sample) -// { -// SH_LOG_DEBUG("Found match"); - -// wxDataViewItem matched_item = m_Library->RowToItem(i); - -// m_Library->UnselectAll(); -// m_Library->SelectRow(i); -// m_Library->EnsureVisible(matched_item); - -// break; -// } -// } -// break; -// default: -// return; -// } -// } -// } - -// void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event) -// { -// TagEditor* tagEditor; -// Serializer serializer; - -// wxString msg; - -// wxDataViewItem item = event.GetItem(); -// int selected_row; - -// if (item.IsOk()) -// selected_row = m_Library->ItemToRow(item); -// else -// return; - -// wxString selection = m_Library->GetTextValue(selected_row, 1); - -// wxString sample_path = GetFilenamePathAndExtension(selection).Path; -// std::string filename = GetFilenamePathAndExtension(selection).Filename; -// std::string extension = GetFilenamePathAndExtension(selection).Extension; - -// wxMenu menu; - -// //true = add false = remove -// bool favorite_add = false; - -// if (m_Database->GetFavoriteColumnValueByFilename(filename) == 1) -// menu.Append(MN_FavoriteSample, _("Remove from hive"), _("Remove the selected sample(s) from hive")); -// else -// { -// menu.Append(MN_FavoriteSample, _("Add to hive"), _("Add selected sample(s) to hive")); -// favorite_add = true; -// } - -// menu.Append(MN_DeleteSample, _("Delete"), _("Delete the selected sample(s) from database")); -// menu.Append(MN_TrashSample, _("Trash"), _("Send the selected sample(s) to trash")); - -// if (m_Library->GetSelectedItemsCount() <= 1) -// { -// menu.Append(MN_EditTagSample, _("Edit tags"), -// _("Edit the tags for the selected sample"))->Enable(true); -// menu.Append(MN_OpenFile, _("Open in file manager"), -// _("Open the selected sample in system's file manager"))->Enable(true); -// } -// else -// { -// menu.Append(MN_EditTagSample, _("Edit tags"), -// _("Edit the tags for the selected sample"))->Enable(false); -// menu.Append(MN_OpenFile, _("Open in file manager"), -// _("Open the selected sample in system's file manager"))->Enable(false); -// } - -// switch (m_Library->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) -// { -// case MN_FavoriteSample: -// { -// std::string hive_name = m_Hives->GetItemText(favorites_hive).ToStdString(); - -// wxDataViewItem hive_selection = m_Hives->GetSelection(); - -// if (hive_selection.IsOk() && m_Hives->IsContainer(hive_selection)) -// hive_name = m_Hives->GetItemText(hive_selection).ToStdString(); - -// wxDataViewItem root = wxDataViewItem(wxNullPtr); -// wxDataViewItem container; -// wxDataViewItem child; - -// wxDataViewItemArray samples; -// int sample_count = m_Library->GetSelections(samples); -// int selected_row = 0; -// int db_status = 0; - -// for (int k = 0; k < sample_count; k++) -// { -// selected_row = m_Library->ItemToRow(samples[k]); - -// if (selected_row < 0) -// continue; - -// wxString name = m_Library->GetTextValue(selected_row, 1); - -// filename = serializer.DeserializeShowFileExtension() ? -// name.BeforeLast('.').ToStdString() : name.ToStdString(); - -// db_status = m_Database->GetFavoriteColumnValueByFilename(filename); - -// // Aleady Added, Do Nothing -// if (favorite_add && db_status == 1) -// continue; - -// // Already Removed, Do Nothing -// if (!favorite_add && db_status == 0) -// continue; - -// // Add To Favorites -// if (favorite_add && db_status == 0) -// { -// m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), selected_row, 0); - -// m_Database->UpdateFavoriteColumn(filename, 1); -// m_Database->UpdateHiveName(filename, hive_name); - -// for (int i = 0; i < m_Hives->GetChildCount(root); i++) -// { -// container = m_Hives->GetNthChild(root, i); - -// if (m_Hives->GetItemText(container).ToStdString() == hive_name) -// { -// m_Hives->AppendItem(container, name); - -// msg = wxString::Format(_("Added %s to %s"), name, hive_name); -// break; -// } -// } -// } -// else -// { -// //Remove From Favorites -// m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), selected_row, 0); - -// m_Database->UpdateFavoriteColumn(filename, 0); -// m_Database->UpdateHiveName(filename, -// m_Hives->GetItemText(favorites_hive).ToStdString()); - -// for (int i = 0; i < m_Hives->GetChildCount(root); i++) -// { -// container = m_Hives->GetNthChild(root, i); - -// for (int j = 0; j < m_Hives->GetChildCount(container); j++) -// { -// child = m_Hives->GetNthChild(container, j); - -// if (m_Hives->GetItemText(child) == name) -// { -// m_Hives->DeleteItem(child); - -// msg = wxString::Format(_("Removed %s from %s"), name, hive_name); -// break; -// } -// } -// } -// } -// } -// break; -// } -// case MN_DeleteSample: -// { -// wxDataViewItemArray items; -// int rows = m_Library->GetSelections(items); - -// wxMessageDialog singleMsgDialog(this, wxString::Format(_("Are you sure you want to delete " -// "%s from database? " -// "Warning this change is " -// "permanent, and cannot be undone."), -// sample_path.AfterLast('/')), -// wxMessageBoxCaptionStr, -// wxYES_NO | wxNO_DEFAULT | -// wxICON_QUESTION | wxSTAY_ON_TOP | -// wxCENTER); - -// wxMessageDialog multipleMsgDialog(this, wxString::Format(_("Are you sure you want to delete " -// "%d selected samples from database? " -// "Warning this change is " -// "permanent, and cannot be " -// "undone."), rows), -// wxMessageBoxCaptionStr, -// wxYES_NO | wxNO_DEFAULT | -// wxICON_QUESTION | wxSTAY_ON_TOP | -// wxCENTER); - -// wxDataViewItem root = wxDataViewItem(wxNullPtr); -// wxDataViewItem container; -// wxDataViewItem child; - -// if (m_Library->GetSelectedItemsCount() <= 1) -// { -// switch (singleMsgDialog.ShowModal()) -// { -// case wxID_YES: -// { -// m_Database->RemoveSampleFromDatabase(filename); -// m_Library->DeleteItem(selected_row); - -// for (int j = 0; j < m_Hives->GetChildCount(root); j++) -// { -// container = m_Hives->GetNthChild(root, j); - -// for (int k = 0; k < m_Hives->GetChildCount(container); k++) -// { -// child = m_Hives->GetNthChild(container, k); - -// wxString child_text = serializer.DeserializeShowFileExtension() ? -// m_Hives->GetItemText(child).BeforeLast('.') : -// m_Hives->GetItemText(child); - -// if (child_text == filename) -// { -// m_Hives->DeleteItem(child); - -// break; -// } -// } -// } - -// msg = wxString::Format(_("Deleted %s from database successfully"), selection); -// } -// break; -// case wxID_NO: -// msg = _("Cancel delete"); -// break; -// default: -// wxMessageBox(_("Unexpected wxMessageDialog return code!"), _("Error!"), -// wxOK | wxICON_ERROR | wxCENTRE, this); -// } -// } -// else -// { -// switch (multipleMsgDialog.ShowModal()) -// { -// case wxID_YES: -// { -// for (int i = 0; i < rows; i++) -// { -// int row = m_Library->ItemToRow(items[i]); - -// wxString text_value = m_Library->GetTextValue(row, 1); - -// std::string multi_selection = serializer.DeserializeShowFileExtension() ? -// text_value.BeforeLast('.').ToStdString() : text_value.ToStdString() ; - -// m_Database->RemoveSampleFromDatabase(multi_selection); -// m_Library->DeleteItem(row); - -// for (int j = 0; j < m_Hives->GetChildCount(root); j++) -// { -// container = m_Hives->GetNthChild(root, j); - -// for (int k = 0; k < m_Hives->GetChildCount(container); k++) -// { -// child = m_Hives->GetNthChild(container, k); - -// wxString child_text = serializer.DeserializeShowFileExtension() ? -// m_Hives->GetItemText(child).BeforeLast('.') : -// m_Hives->GetItemText(child); - -// if (child_text == multi_selection) -// { -// m_Hives->DeleteItem(child); -// break; -// } -// } -// } - -// msg = wxString::Format(_("Deleted %s from database successfully"), text_value); -// } -// } -// break; -// case wxID_NO: -// msg = _("Cancel delete"); -// break; -// default: -// wxMessageBox(_("Unexpected wxMessageDialog return code!"), _("Error!"), -// wxOK | wxICON_ERROR | wxCENTRE, this); -// } -// } -// } -// break; -// case MN_TrashSample: -// { -// wxDataViewItem root = wxDataViewItem(wxNullPtr); -// wxDataViewItem container, child; - -// if (m_Database->IsTrashed(filename)) -// SH_LOG_INFO("{} already trashed", filename); -// else -// { -// wxDataViewItemArray items; -// int rows = m_Library->GetSelections(items); - -// wxString name; -// wxFileDataObject file_data; -// wxArrayString files; - -// for (int i = 0; i < rows; i++) -// { -// int item_row = m_Library->ItemToRow(items[i]); - -// wxString text_value = m_Library->GetTextValue(item_row, 1); - -// std::string multi_selection = serializer.DeserializeShowFileExtension() ? -// m_Library->GetTextValue(item_row, 1).BeforeLast('.').ToStdString() : -// m_Library->GetTextValue(item_row, 1).ToStdString() ; - -// file_data.AddFile(multi_selection); - -// files = file_data.GetFilenames(); - -// if (m_Database->GetFavoriteColumnValueByFilename(files[i].ToStdString())) -// { -// m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), item_row, 0); - -// m_Database->UpdateFavoriteColumn(files[i].ToStdString(), 0); - -// for (int j = 0; j < m_Hives->GetChildCount(root); j++) -// { -// container = m_Hives->GetNthChild(root, j); - -// for (int k = 0; k < m_Hives->GetChildCount(container); k++) -// { -// child = m_Hives->GetNthChild(container, k); - -// wxString child_text = serializer.DeserializeShowFileExtension() ? -// m_Hives->GetItemText(child).BeforeLast('.') : -// m_Hives->GetItemText(child); - -// if (child_text == files[i]) -// { -// m_Hives->DeleteItem(child); -// break; -// } -// } -// } -// } - -// m_Database->UpdateTrashColumn(files[i].ToStdString(), 1); -// m_Database->UpdateHiveName(files[i].ToStdString(), -// m_Hives->GetItemText(favorites_hive).ToStdString()); - -// m_Trash->AppendItem(trash_root, text_value); - -// m_Library->DeleteItem(item_row); - -// msg = wxString::Format(_("%s sent to trash"), text_value); -// } -// } -// } -// break; -// case MN_EditTagSample: -// { -// tagEditor = new TagEditor(this, static_cast(sample_path)); - -// switch (tagEditor->ShowModal()) -// { -// case wxID_OK: -// SH_LOG_DEBUG("tags dialog ok, Return code: {}", tagEditor->GetReturnCode()); -// break; -// case wxID_APPLY: -// SH_LOG_DEBUG("tags dialog apply, Return code: {}", tagEditor->GetReturnCode()); -// break; -// case wxID_CANCEL: -// SH_LOG_DEBUG("tags dialog cancel, Return code: {}", tagEditor->GetReturnCode()); -// break; -// default: -// msg = _("Unexpected TagEditor return code!"); -// } -// } -// break; -// case MN_OpenFile: -// wxExecute(wxString::Format("xdg-open '%s'", sample_path.BeforeLast('/'))); -// break; -// case wxID_NONE: -// return; -// default: -// wxMessageBox(_("Unexpected wxMenu return code!"), _("Error!"), -// wxOK | wxICON_ERROR | wxCENTRE, this); -// break; -// } - -// if(!msg.IsEmpty()) -// m_InfoBar->ShowMessage(msg); -// } - -// void MainFrame::OnShowLibraryColumnHeaderContextMenu(wxDataViewEvent& event) -// { -// wxMenu menu; - -// wxDataViewColumn* FavoriteColumn = m_Library->GetColumn(0); -// wxDataViewColumn* FilenameColumn = m_Library->GetColumn(1); -// wxDataViewColumn* SamplePackColumn = m_Library->GetColumn(2); -// wxDataViewColumn* TypeColumn = m_Library->GetColumn(3); -// wxDataViewColumn* ChannelsColumn = m_Library->GetColumn(4); -// wxDataViewColumn* LengthColumn = m_Library->GetColumn(5); -// wxDataViewColumn* SampleRateColumn = m_Library->GetColumn(6); -// wxDataViewColumn* BitrateColumn = m_Library->GetColumn(7); -// wxDataViewColumn* PathColumn = m_Library->GetColumn(8); - -// menu.AppendCheckItem(MN_ColumnFavorite, _("Favorites"), -// _("Toggle favorites column"))->Check(FavoriteColumn->IsShown()); -// menu.AppendCheckItem(MN_ColumnFilename, _("Filename"), -// _("Toggle filename column"))->Check(FilenameColumn->IsShown()); -// menu.AppendCheckItem(MN_ColumnSamplePack, _("Sample Pack"), -// _("Toggle sample pack column"))->Check(SamplePackColumn->IsShown()); -// menu.AppendCheckItem(MN_ColumnType, _("Type"), -// _("Toggle type column"))->Check(TypeColumn->IsShown()); -// menu.AppendCheckItem(MN_ColumnChannels, _("Channels"), -// _("Toggle channels column"))->Check(ChannelsColumn->IsShown()); -// menu.AppendCheckItem(MN_ColumnLength, _("Length"), -// _("Toggle length column"))->Check(LengthColumn->IsShown()); -// menu.AppendCheckItem(MN_ColumnSampleRate, _("Sample Rate"), -// _("Toggle sample rate column"))->Check(SampleRateColumn->IsShown()); -// menu.AppendCheckItem(MN_ColumnBitrate, _("Bitrate"), -// _("Toggle bitrate column"))->Check(BitrateColumn->IsShown()); -// menu.AppendCheckItem(MN_ColumnPath, _("Path"), -// _("Toggle path column"))->Check(PathColumn->IsShown()); - -// switch (m_Library->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) -// { -// case MN_ColumnFavorite: -// FavoriteColumn->SetHidden(!menu.IsChecked(MN_ColumnFavorite)); -// break; -// case MN_ColumnFilename: -// FilenameColumn->SetHidden(!menu.IsChecked(MN_ColumnFilename)); -// break; -// case MN_ColumnSamplePack: -// SamplePackColumn->SetHidden(!menu.IsChecked(MN_ColumnSamplePack)); -// break; -// case MN_ColumnType: -// TypeColumn->SetHidden(!menu.IsChecked(MN_ColumnType)); -// break; -// case MN_ColumnChannels: -// ChannelsColumn->SetHidden(!menu.IsChecked(MN_ColumnChannels)); -// break; -// case MN_ColumnLength: -// LengthColumn->SetHidden(!menu.IsChecked(MN_ColumnLength)); -// break; -// case MN_ColumnSampleRate: -// SampleRateColumn->SetHidden(!menu.IsChecked(MN_ColumnSampleRate)); -// break; -// case MN_ColumnBitrate: -// BitrateColumn->SetHidden(!menu.IsChecked(MN_ColumnBitrate)); -// break; -// case MN_ColumnPath: -// PathColumn->SetHidden(!menu.IsChecked(MN_ColumnPath)); -// break; -// default: -// break; -// } -// } - -// void MainFrame::LoadDatabase() -// { -// Serializer serializer; - -// try -// { -// const auto dataset = m_Database->LoadSamplesDatabase(*m_Hives, favorites_hive, -// *m_Trash, trash_root, -// serializer.DeserializeShowFileExtension(), -// ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px); - -// if (dataset.empty()) -// SH_LOG_INFO("Error! Database is empty."); -// else -// { -// for (auto data : dataset) -// m_Library->AppendItem(data); -// } - -// m_Database->LoadHivesDatabase(*m_Hives); -// } -// catch(...) -// { -// std::cerr << "Error loading data." << std::endl; -// } -// } - -// void MainFrame::OnShowTrashContextMenu(wxTreeEvent& event) -// { -// Serializer serializer; - -// wxTreeItemId selected_trashed_item = event.GetItem(); - -// wxMenu menu; - -// menu.Append(MN_DeleteTrash, _("Delete from database"), _("Delete the selected sample(s) from database")); -// menu.Append(MN_RestoreTrashedItem, _("Restore sample"), _("Restore the selected sample(s) back to library")); - -// if (selected_trashed_item.IsOk()) -// { -// switch (m_Trash->GetPopupMenuSelectionFromUser(menu, event.GetPoint())) -// { -// case MN_DeleteTrash: -// { -// wxString trashed_item_name = serializer.DeserializeShowFileExtension() ? -// m_Trash->GetItemText(selected_trashed_item).BeforeLast('.') : -// m_Trash->GetItemText(selected_trashed_item); - -// m_Database->RemoveSampleFromDatabase(trashed_item_name.ToStdString()); - -// m_Trash->Delete(selected_trashed_item); - -// SH_LOG_INFO("{} deleted from trash and databse", trashed_item_name); -// } -// break; -// case MN_RestoreTrashedItem: -// { -// wxArrayTreeItemIds selected_item_ids; -// m_Trash->GetSelections(selected_item_ids); - -// wxFileDataObject file_data; -// wxArrayString files; - -// wxString selected_item_text; -// std::string filename; - -// for (size_t i = 0; i < selected_item_ids.GetCount(); i++) -// { -// selected_item_text = m_Trash->GetItemText(selected_item_ids[i]); - -// filename = GetFilenamePathAndExtension(selected_item_text).Filename; - -// file_data.AddFile(filename); - -// files = file_data.GetFilenames(); - -// m_Database->UpdateTrashColumn(files[i].ToStdString(), 0); - -// try -// { -// wxVector> dataset; - -// if (m_Database->RestoreFromTrashByFilename(files[i].ToStdString(), -// dataset, -// serializer.DeserializeShowFileExtension(), -// ICON_STAR_FILLED_16px, -// ICON_STAR_EMPTY_16px).empty()) -// { -// SH_LOG_INFO("Error! Database is empty."); -// } -// else -// { -// for (auto data : dataset) -// { -// m_Library->AppendItem(data); -// } -// } -// } -// catch (...) -// { -// std::cerr << "Error loading data." << std::endl; -// } - -// m_Trash->Delete(selected_item_ids[i]); - -// SH_LOG_INFO("{} restored from trash", files[i]); -// } -// } -// break; -// default: -// break; -// } -// } -// } - -// void MainFrame::OnDragAndDropToTrash(wxDropFilesEvent& event) -// { -// Serializer serializer; - -// if (event.GetNumberOfFiles() > 0) -// { -// wxFileDataObject file_data; -// wxArrayString files; - -// wxDataViewItemArray items; -// int rows = m_Library->GetSelections(items); - -// wxString msg; - -// wxDataViewItem root = wxDataViewItem(wxNullPtr); -// wxDataViewItem container, child; - -// for (int i = 0; i < rows; i++) -// { -// int item_row = m_Library->ItemToRow(items[i]); - -// wxString text_value = m_Library->GetTextValue(item_row, 1); - -// std::string multi_selection = serializer.DeserializeShowFileExtension() ? -// m_Library->GetTextValue(item_row, 1).BeforeLast('.').ToStdString() : -// m_Library->GetTextValue(item_row, 1).ToStdString() ; - -// file_data.AddFile(multi_selection); - -// files = file_data.GetFilenames(); - -// if (m_Database->GetFavoriteColumnValueByFilename(files[i].ToStdString())) -// { -// m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), item_row, 0); - -// m_Database->UpdateFavoriteColumn(files[i].ToStdString(), 0); - -// for (int j = 0; j < m_Hives->GetChildCount(root); j++) -// { -// container = m_Hives->GetNthChild(root, j); - -// for (int k = 0; k < m_Hives->GetChildCount(container); k++) -// { -// child = m_Hives->GetNthChild(container, k); - -// wxString child_text = serializer.DeserializeShowFileExtension() ? -// m_Hives->GetItemText(child).BeforeLast('.') : -// m_Hives->GetItemText(child); - -// if (child_text == files[i]) -// { -// m_Hives->DeleteItem(child); -// break; -// } -// } -// } -// } - -// m_Database->UpdateTrashColumn(files[i].ToStdString(), 1); -// m_Database->UpdateHiveName(files[i].ToStdString(), -// m_Hives->GetItemText(favorites_hive).ToStdString()); - -// m_Trash->AppendItem(trash_root, text_value); - -// m_Library->DeleteItem(item_row); - -// msg = wxString::Format(_("%s sent to trash"), text_value); -// } - -// if (!msg.IsEmpty()) -// m_InfoBar->ShowMessage(msg, wxICON_ERROR); -// } -// } - -// void MainFrame::OnClickAddHive(wxCommandEvent& event) -// { -// std::deque nodes; -// nodes.push_back(m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), 0)); - -// wxDataViewItem current_item, found_item; - -// int row = 0; -// int hive_count = m_Hives->GetChildCount(wxDataViewItem(wxNullPtr)); - -// wxString msg; - -// wxTextEntryDialog hiveEntry(this, _("Enter hive name"), _("Create new hive"), wxEmptyString, -// wxTextEntryDialogStyle, wxDefaultPosition); - -// hiveEntry.SetTextValidator(wxFILTER_EMPTY); - -// switch (hiveEntry.ShowModal()) -// { -// case wxID_OK: -// { -// wxString hive_name = hiveEntry.GetValue(); - -// while(!nodes.empty()) -// { -// current_item = nodes.front(); -// nodes.pop_front(); - -// if (m_Hives->GetItemText(current_item) == hive_name) -// { -// found_item = current_item; -// SH_LOG_DEBUG("Found item: {}", m_Hives->GetItemText(current_item)); -// break; -// } - -// wxDataViewItem child = m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), 0); - -// while (row < (hive_count - 1)) -// { -// row ++; - -// child = m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), row); -// nodes.push_back(child); -// } -// } - -// nodes.clear(); - -// if (found_item.IsOk()) -// { -// wxMessageBox(wxString::Format(_("Another hive by the name %s already exist. " -// "Please try with a different name."), -// hive_name), -// _("Error!"), wxOK | wxCENTRE, this); -// } -// else -// { -// m_Hives->AppendContainer(wxDataViewItem(wxNullPtr), hive_name); -// m_Database->InsertIntoHives(hive_name.ToStdString()); - -// msg = wxString::Format(_("%s added to Hives."), hive_name); -// } -// break; -// } -// case wxID_CANCEL: -// break; -// default: -// return; -// } - -// if (!msg.IsEmpty()) -// m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); -// } - -// void MainFrame::OnClickRemoveHive(wxCommandEvent& event) -// { -// Serializer serializer; - -// wxDataViewItem selected_item = m_Hives->GetSelection(); -// wxString hive_name = m_Hives->GetItemText(selected_item); - -// wxString msg; - -// wxMessageDialog deleteEmptyHiveDialog(this, wxString::Format(_("Are you sure you want to delete " -// "%s from hives?"), -// hive_name), -// wxMessageBoxCaptionStr, -// wxYES_NO | wxNO_DEFAULT | -// wxICON_QUESTION | wxSTAY_ON_TOP); - -// wxMessageDialog deleteFilledHiveDialog(this, wxString::Format(_("Are you sure you want to delete " -// "%s and all sample inside %s from hives?"), -// hive_name, hive_name), -// wxMessageBoxCaptionStr, -// wxYES_NO | wxNO_DEFAULT | -// wxICON_QUESTION | wxSTAY_ON_TOP); - -// if (hive_name == m_Hives->GetItemText(favorites_hive)) -// { -// wxMessageBox(wxString::Format(_("Error! Default hive %s cannot be deleted."), hive_name), -// _("Error!"), wxOK | wxCENTRE, this); -// return; -// } -// else if (!selected_item.IsOk()) -// { -// wxMessageBox(_("No hive selected, try selecting a hive first"), _("Error!"), wxOK | wxCENTRE, this); -// return; -// } -// else if (selected_item.IsOk() && !m_Hives->IsContainer(selected_item)) -// { -// wxMessageBox(wxString::Format(_("Error! %s is not a hive, cannot delete from hives."), hive_name), -// _("Error!"), wxOK | wxCENTRE, this); -// return; -// } - -// if (m_Hives->GetChildCount(selected_item) <= 0) -// { -// switch (deleteEmptyHiveDialog.ShowModal()) -// { -// case wxID_YES: -// if (selected_item.IsOk() && m_Hives->IsContainer(selected_item) && -// hive_name != m_Hives->GetItemText(favorites_hive)) -// { -// m_Hives->DeleteItem(selected_item); - -// m_Database->RemoveHiveFromDatabase(hive_name.ToStdString()); -// msg = wxString::Format(_("%s deleted from hives successfully."), hive_name); -// } -// break; -// case wxID_NO: -// break; -// default: -// return; -// } -// } -// else -// { -// switch (deleteFilledHiveDialog.ShowModal()) -// { -// case wxID_YES: -// if (selected_item.IsOk() && m_Hives->IsContainer(selected_item) && -// hive_name != m_Hives->GetItemText(favorites_hive)) -// { -// wxDataViewItem child_item; - -// for (int i = 0; i < m_Library->GetItemCount(); i++) -// { -// wxString matched_sample = serializer.DeserializeShowFileExtension() ? -// m_Library->GetTextValue(i, 1).BeforeLast('.') : -// m_Library->GetTextValue(i, 1); - -// for (int j = 0; j < m_Hives->GetChildCount(selected_item); j++) -// { -// child_item = m_Hives->GetNthChild(selected_item, j); - -// wxString child_name = serializer.DeserializeShowFileExtension() ? -// m_Hives->GetItemText(child_item).BeforeLast('.') : -// m_Hives->GetItemText(child_item); - -// if (child_name == matched_sample) -// { -// SH_LOG_DEBUG("Found match"); - -// m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0); - -// m_Database->UpdateFavoriteColumn(matched_sample.ToStdString(), 0); -// m_Database->UpdateHiveName(matched_sample.ToStdString(), -// m_Hives->GetItemText(favorites_hive).ToStdString()); - -// break; -// } -// else -// SH_LOG_DEBUG("No match found"); -// } -// } - -// m_Hives->DeleteChildren(selected_item); -// m_Hives->DeleteItem(selected_item); - -// m_Database->RemoveHiveFromDatabase(hive_name.ToStdString()); - -// msg = wxString::Format(_("%s and all samples inside %s have been deleted " -// "from hives successfully."), -// hive_name, hive_name); -// } -// break; -// case wxID_NO: -// break; -// default: -// return; -// } -// } - -// if (!msg.IsEmpty()) -// m_InfoBar->ShowMessage(msg, wxICON_INFORMATION); -// } - -// void MainFrame::OnClickRestoreTrashItem(wxCommandEvent& event) -// { -// Serializer serializer; - -// wxArrayTreeItemIds selected_item_ids; -// m_Trash->GetSelections(selected_item_ids); - -// wxFileDataObject file_data; -// wxArrayString files; - -// wxString selected_item_text; -// std::string filename; - -// if (m_Trash->GetChildrenCount(trash_root) == 0) -// { -// wxMessageBox(_("Trash is empty, nothing to restore!"), wxMessageBoxCaptionStr, wxOK | wxCENTRE, this); -// return; -// } - -// if (selected_item_ids.IsEmpty()) -// { -// wxMessageBox(_("No item selected, try selected a item first."), wxMessageBoxCaptionStr, -// wxOK | wxCENTRE, this); -// return; -// } - -// for (size_t i = 0; i < selected_item_ids.GetCount(); i++) -// { -// selected_item_text = m_Trash->GetItemText(selected_item_ids[i]); - -// filename = GetFilenamePathAndExtension(selected_item_text).Filename; - -// file_data.AddFile(filename); - -// files = file_data.GetFilenames(); - -// m_Database->UpdateTrashColumn(files[i].ToStdString(), 0); - -// try -// { -// wxVector> dataset; - -// if (m_Database->RestoreFromTrashByFilename(files[i].ToStdString(), dataset, -// serializer.DeserializeShowFileExtension(), -// ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty()) -// { -// SH_LOG_INFO("Error! Database is empty."); -// } -// else -// { -// for (auto data : dataset) -// { -// m_Library->AppendItem(data); -// } -// } -// } -// catch (...) -// { -// std::cerr << "Error loading data." << std::endl; -// } - -// m_Trash->Delete(selected_item_ids[i]); -// } -// } - -// void MainFrame::OnDoSearch(wxCommandEvent& event) -// { -// Serializer serializer; - -// const auto search = m_SearchBox->GetValue().ToStdString(); - -// try -// { -// const auto dataset = m_Database->FilterDatabaseBySampleName(search, -// serializer.DeserializeShowFileExtension(), -// ICON_STAR_FILLED_16px, -// ICON_STAR_EMPTY_16px); - -// if (dataset.empty()) -// { -// SH_LOG_INFO("Error! Database is empty."); -// } -// else -// { -// m_Library->DeleteAllItems(); - -// std::cout << search << std::endl; - -// for (const auto& data : dataset) -// { -// m_Library->AppendItem(data); -// } -// } -// } -// catch (...) -// { -// std::cerr << "Error loading data." << std::endl; -// } -// } - -// void MainFrame::OnCancelSearch(wxCommandEvent& event) -// { -// m_SearchBox->Clear(); -// } - -void MainFrame::LoadConfigFile() +void cMainFrame::LoadDatabase() +{ + SampleHive::cSerializer serializer; + + try + { + const auto dataset = m_pDatabase->LoadSamplesDatabase(*m_pNotebook->GetHivesPanel()->GetHivesObject(), + m_pNotebook->GetHivesPanel()->GetFavoritesHive(), + *m_pNotebook->GetTrashPanel()->GetTrashObject(), + m_pNotebook->GetTrashPanel()->GetTrashRoot(), + serializer.DeserializeShowFileExtension(), + ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px); + + if (dataset.empty()) + SH_LOG_INFO("Error! Database is empty."); + else + { + for (auto data : dataset) + SampleHive::cHiveData::Get().ListCtrlAppendItem(data); + } + + m_pDatabase->LoadHivesDatabase(*m_pNotebook->GetHivesPanel()->GetHivesObject()); + } + catch (std::exception& e) + { + SH_LOG_ERROR("Error loading data. {}", e.what()); + } +} + +void cMainFrame::LoadConfigFile() { // Check if SampleHive configuration directory exist and create it if not if (!wxDirExists(APP_CONFIG_DIR)) { + SH_LOG_WARN("Configuration directory not found. Creating directory at {}", APP_CONFIG_DIR); + if (wxFileName::Mkdir(APP_CONFIG_DIR, wxPOSIX_USER_READ | wxPOSIX_USER_WRITE | wxPOSIX_USER_EXECUTE | wxPOSIX_GROUP_READ | wxPOSIX_GROUP_EXECUTE | wxPOSIX_OTHERS_READ | wxPOSIX_OTHERS_EXECUTE, wxPATH_MKDIR_FULL)) { - SH_LOG_INFO("Successfully created configuratin directory at {}", APP_CONFIG_DIR); + SH_LOG_INFO("Successfully created configuration directory at {}", APP_CONFIG_DIR); } else { - wxMessageBox(wxString::Format(_("Error! Could not create configuration directory %s"), - APP_CONFIG_DIR), _("Error!"), wxOK | wxCENTRE, this); + wxMessageBox(wxString::Format(_("Error! Could not create configuration directory %s"), APP_CONFIG_DIR), + _("Error!"), wxOK | wxCENTRE, this); } } + else + SH_LOG_INFO("Found {} directory.", APP_CONFIG_DIR); // Check if SampleHive data directory exist and create it if not if (!wxDirExists(APP_DATA_DIR)) { + SH_LOG_WARN("Data directory not found. Creating directory at {}", APP_DATA_DIR); + if (wxFileName::Mkdir(APP_DATA_DIR, wxPOSIX_USER_READ | wxPOSIX_USER_WRITE | wxPOSIX_USER_EXECUTE | wxPOSIX_GROUP_READ | wxPOSIX_GROUP_EXECUTE | wxPOSIX_OTHERS_READ | wxPOSIX_OTHERS_EXECUTE, wxPATH_MKDIR_FULL)) @@ -2385,8 +329,10 @@ void MainFrame::LoadConfigFile() _("Error!"), wxOK | wxCENTRE, this); } } + else + SH_LOG_INFO("Found {} directory.", APP_DATA_DIR); - Serializer serializer; + SampleHive::cSerializer serializer; SH_LOG_INFO("Reading configuration file.."); @@ -2397,15 +343,15 @@ void MainFrame::LoadConfigFile() int min_width = 960, min_height = 540; - bShowMenuBar = serializer.DeserializeShowMenuAndStatusBar("menubar"); - bShowStatusBar = serializer.DeserializeShowMenuAndStatusBar("statusbar"); + m_bShowMenuBar = serializer.DeserializeShowMenuAndStatusBar("menubar"); + m_bShowStatusBar = serializer.DeserializeShowMenuAndStatusBar("statusbar"); - m_ToggleMenuBar->Check(bShowMenuBar); - m_MenuBar->Show(bShowMenuBar); - m_ToggleStatusBar->Check(bShowStatusBar); - m_StatusBar->Show(bShowStatusBar); + m_pToggleMenuBar->Check(m_bShowMenuBar); + m_pMenuBar->Show(m_bShowMenuBar); + m_pToggleStatusBar->Check(m_bShowStatusBar); + m_pStatusBar->Show(m_bShowStatusBar); - m_ToggleExtension->Check(serializer.DeserializeShowFileExtension()); + m_pToggleExtension->Check(serializer.DeserializeShowFileExtension()); this->SetFont(serializer.DeserializeFontSettings()); this->SetSize(width, height); @@ -2417,40 +363,41 @@ void MainFrame::LoadConfigFile() this->SetStatusText(_("Stopped"), 1); } -// void MainFrame::RefreshDatabase() +// void cMainFrame::RefreshDatabase() // { -// m_Library->DeleteAllItems(); +// m_pLibrary->GetListCtrlObject()->DeleteAllItems(); -// if (m_Hives->GetChildCount(wxDataViewItem(wxNullPtr)) < 1 && -// m_Hives->GetItemText(wxDataViewItem(wxNullPtr)) == m_Hives->GetItemText(favorites_hive)) +// if (m_pNotebook->GetHivesPanel()->GetHivesObject()->GetChildCount(wxDataViewItem(wxNullPtr)) <= 1 && +// m_pNotebook->GetHivesPanel()->GetHivesObject()->GetItemText(wxDataViewItem(wxNullPtr)) == +// m_pNotebook->GetHivesPanel()->GetHivesObject()->GetItemText(m_pNotebook->GetHivesPanel()->GetFavoritesHive())) // return; // else -// m_Hives->DeleteAllItems(); +// m_pNotebook->GetHivesPanel()->GetHivesObject()->DeleteAllItems(); -// m_Trash->DeleteAllItems(); +// m_pNotebook->GetTrashPanel()->GetTrashObject()->DeleteAllItems(); // LoadDatabase(); // } -bool MainFrame::CreateWatcherIfNecessary() +bool cMainFrame::CreateWatcherIfNecessary() { - if (m_FsWatcher) + if (m_pFsWatcher) return false; CreateWatcher(); - Bind(wxEVT_FSWATCHER, &MainFrame::OnFileSystemEvent, this); + Bind(wxEVT_FSWATCHER, &cMainFrame::OnFileSystemEvent, this); return true; } -void MainFrame::CreateWatcher() +void cMainFrame::CreateWatcher() { - Serializer serializer; + SampleHive::cSerializer serializer; - wxCHECK_RET(!m_FsWatcher, _("Watcher already initialized")); + wxCHECK_RET(!m_pFsWatcher, _("Watcher already initialized")); - m_FsWatcher = new wxFileSystemWatcher(); - m_FsWatcher->SetOwner(this); + m_pFsWatcher = new wxFileSystemWatcher(); + m_pFsWatcher->SetOwner(this); wxString path = serializer.DeserializeAutoImport().second; @@ -2465,9 +412,9 @@ void MainFrame::CreateWatcher() } } -void MainFrame::AddWatchEntry(wxFSWPathType type, std::string path) +void cMainFrame::AddWatchEntry(wxFSWPathType type, std::string path) { - Serializer serializer; + SampleHive::cSerializer serializer; if (path.empty()) { @@ -2477,7 +424,7 @@ void MainFrame::AddWatchEntry(wxFSWPathType type, std::string path) return; } - wxCHECK_RET(m_FsWatcher, _("Watcher not initialized")); + wxCHECK_RET(m_pFsWatcher, _("Watcher not initialized")); SH_LOG_INFO("Adding {}: '{}'", path, type == wxFSWPath_Dir ? "directory" : "directory tree"); @@ -2499,10 +446,10 @@ void MainFrame::AddWatchEntry(wxFSWPathType type, std::string path) switch (type) { case wxFSWPath_Dir: - ok = m_FsWatcher->Add(filename); + ok = m_pFsWatcher->Add(filename); break; case wxFSWPath_Tree: - ok = m_FsWatcher->AddTree(filename); + ok = m_pFsWatcher->AddTree(filename); break; case wxFSWPath_File: break; @@ -2517,7 +464,7 @@ void MainFrame::AddWatchEntry(wxFSWPathType type, std::string path) } } -void MainFrame::OnFileSystemEvent(wxFileSystemWatcherEvent& event) +void cMainFrame::OnFileSystemEvent(wxFileSystemWatcherEvent& event) { wxLogTrace(wxTRACE_FSWATCHER, "*** %s ***", event.ToString()); @@ -2534,7 +481,7 @@ void MainFrame::OnFileSystemEvent(wxFileSystemWatcherEvent& event) { case wxFSW_EVENT_CREATE: SH_LOG_INFO("NEW FILES DETECTED, ADDING: {}", path); - // AddSamples(files); + SampleHive::cUtils::Get().AddSamples(files, this); break; case wxFSW_EVENT_ACCESS: SH_LOG_INFO("ACCESSING DIRECTORY: {}", path); @@ -2559,40 +506,7 @@ void MainFrame::OnFileSystemEvent(wxFileSystemWatcherEvent& event) } } -// FileInfo MainFrame::GetFilenamePathAndExtension(const wxString& selected, -// bool checkExtension, bool doGetFilename) const -// { -// Serializer serializer; - -// wxString path; -// std::string extension, filename; - -// wxString filename_with_extension = m_Database->GetSamplePathByFilename(selected.BeforeLast('.').ToStdString()); -// wxString filename_without_extension = m_Database->GetSamplePathByFilename(selected.ToStdString()); - -// if (checkExtension) -// { -// extension = serializer.DeserializeShowFileExtension() ? -// m_Database->GetSampleFileExtension(selected.ToStdString()) : -// m_Database->GetSampleFileExtension(selected.BeforeLast('.').ToStdString()); -// } - -// path = selected.Contains(wxString::Format(".%s", extension)) ? -// filename_with_extension : filename_without_extension; - -// if (doGetFilename) -// filename = path.AfterLast('/').BeforeLast('.').ToStdString(); - -// return { path, extension, filename }; -// } - -// void MainFrame::OnHiveStartEditing(wxDataViewEvent &event) -// { -// SH_LOG_INFO("Right click on a hive and select rename to rename it.."); -// event.Veto(); -// } - -void MainFrame::OnSelectAddFile(wxCommandEvent& event) +void cMainFrame::OnSelectAddFile(wxCommandEvent& event) { wxFileDialog file_dialog(this, wxFileSelectorPromptStr, USER_HOME_DIR, wxEmptyString, wxFileSelectorDefaultWildcardStr, @@ -2606,8 +520,8 @@ void MainFrame::OnSelectAddFile(wxCommandEvent& event) wxArrayString paths; file_dialog.GetPaths(paths); - // for (size_t i = 0; i < (size_t)paths.size(); i++) - // AddSamples(paths); + for (size_t i = 0; i < (size_t)paths.size(); i++) + SampleHive::cUtils::Get().AddSamples(paths, this); } break; default: @@ -2615,7 +529,7 @@ void MainFrame::OnSelectAddFile(wxCommandEvent& event) } } -void MainFrame::OnSelectAddDirectory(wxCommandEvent& event) +void cMainFrame::OnSelectAddDirectory(wxCommandEvent& event) { wxDirDialog dir_dialog(this, wxDirSelectorPromptStr, USER_HOME_DIR, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST, wxDefaultPosition, wxDefaultSize); @@ -2626,7 +540,7 @@ void MainFrame::OnSelectAddDirectory(wxCommandEvent& event) { wxString path = dir_dialog.GetPath(); - // OnAutoImportDir(path); + SampleHive::cUtils::Get().OnAutoImportDir(path, this); } break; default: @@ -2634,92 +548,92 @@ void MainFrame::OnSelectAddDirectory(wxCommandEvent& event) } } -void MainFrame::OnSelectToggleExtension(wxCommandEvent& event) +void cMainFrame::OnSelectToggleExtension(wxCommandEvent& event) { - Serializer serializer; + SampleHive::cSerializer serializer; - if (m_ToggleExtension->IsChecked()) + if (m_pToggleExtension->IsChecked()) { serializer.SerializeShowFileExtension(true); - // m_InfoBar->ShowMessage(_("Extension showing, restart the application to view changes " - // "or press CTRL+E to toggle show/hide."), wxICON_INFORMATION); + m_pLibrary->GetInfoBarObject()->ShowMessage(_("Extension showing, restart the application to view changes " + "or press CTRL+E to toggle show/hide."), wxICON_INFORMATION); } else { serializer.SerializeShowFileExtension(false); - // m_InfoBar->ShowMessage(_("Extension hidden, restart the application to view changes " - // "or press CTRL+E to toggle show/hide."), wxICON_INFORMATION); + m_pLibrary->GetInfoBarObject()->ShowMessage(_("Extension hidden, restart the application to view changes " + "or press CTRL+E to toggle show/hide."), wxICON_INFORMATION); } } -void MainFrame::OnSelectToggleMenuBar(wxCommandEvent& event) +void cMainFrame::OnSelectToggleMenuBar(wxCommandEvent& event) { - Serializer serializer; + SampleHive::cSerializer serializer; - if (m_ToggleMenuBar->IsChecked()) + if (m_pToggleMenuBar->IsChecked()) { - m_MenuBar->Show(); - // m_InfoBar->ShowMessage(_("MenuBar showing, press CTRL+M to toggle show/hide."), wxICON_INFORMATION); + m_pMenuBar->Show(); + m_pLibrary->GetInfoBarObject()->ShowMessage(_("MenuBar showing, press CTRL+M to toggle show/hide."), wxICON_INFORMATION); - bShowMenuBar = true; + m_bShowMenuBar = true; - serializer.SerializeShowMenuAndStatusBar("menubar", bShowMenuBar); + serializer.SerializeShowMenuAndStatusBar("menubar", m_bShowMenuBar); } else { - m_MenuBar->Hide(); - // m_InfoBar->ShowMessage(_("MenuBar hidden, press CTRL+M to toggle show/hide."), wxICON_INFORMATION); + m_pMenuBar->Hide(); + m_pLibrary->GetInfoBarObject()->ShowMessage(_("MenuBar hidden, press CTRL+M to toggle show/hide."), wxICON_INFORMATION); - bShowMenuBar = false; + m_bShowMenuBar = false; - serializer.SerializeShowMenuAndStatusBar("menubar", bShowMenuBar); + serializer.SerializeShowMenuAndStatusBar("menubar", m_bShowMenuBar); } } -void MainFrame::OnSelectToggleStatusBar(wxCommandEvent& event) +void cMainFrame::OnSelectToggleStatusBar(wxCommandEvent& event) { - Serializer serializer; + SampleHive::cSerializer serializer; - if (m_ToggleStatusBar->IsChecked()) + if (m_pToggleStatusBar->IsChecked()) { - m_StatusBar->Show(); - // m_InfoBar->ShowMessage(_("StatusBar showing, press CTRL+B to toggle show/hide."), wxICON_INFORMATION); + m_pStatusBar->Show(); + m_pLibrary->GetInfoBarObject()->ShowMessage(_("StatusBar showing, press CTRL+B to toggle show/hide."), wxICON_INFORMATION); - bShowStatusBar = true; + m_bShowStatusBar = true; - serializer.SerializeShowMenuAndStatusBar("statusbar", bShowStatusBar); + serializer.SerializeShowMenuAndStatusBar("statusbar", m_bShowStatusBar); } else { - m_StatusBar->Hide(); - // m_InfoBar->ShowMessage(_("StatusBar hidden, press CTRL+B to toggle show/hide."), wxICON_INFORMATION); + m_pStatusBar->Hide(); + m_pLibrary->GetInfoBarObject()->ShowMessage(_("StatusBar hidden, press CTRL+B to toggle show/hide."), wxICON_INFORMATION); - bShowStatusBar = false; + m_bShowStatusBar = false; - serializer.SerializeShowMenuAndStatusBar("statusbar", bShowStatusBar); + serializer.SerializeShowMenuAndStatusBar("statusbar", m_bShowStatusBar); } } -void MainFrame::OnSelectExit(wxCommandEvent& event) +void cMainFrame::OnSelectExit(wxCommandEvent& event) { Close(); } -void MainFrame::OnSelectPreferences(wxCommandEvent& event) +void cMainFrame::OnSelectPreferences(wxCommandEvent& event) { - Settings* settings = new Settings(this); + cSettings* settings = new cSettings(this); switch (settings->ShowModal()) { case wxID_OK: if (settings->CanAutoImport()) { - // OnAutoImportDir(settings->GetImportDirPath()); + SampleHive::cUtils::Get().OnAutoImportDir(settings->GetImportDirPath(), this); // RefreshDatabase(); } if (settings->IsWaveformColourChanged()) { - m_WaveformViewer->ResetDC(); + m_pWaveformViewer->ResetDC(); } break; case wxID_CANCEL: @@ -2729,14 +643,13 @@ void MainFrame::OnSelectPreferences(wxCommandEvent& event) } } -void MainFrame::OnSelectResetAppData(wxCommandEvent& event) +void cMainFrame::OnSelectResetAppData(wxCommandEvent& event) { wxMessageDialog clearDataDialog(this, wxString::Format(_("Warning! This will delete configuration file " "\"%s\" and database file \"%s\" permanently, " "are you sure you want to delete these files?"), CONFIG_FILEPATH, DATABASE_FILEPATH), - _("Clear app data?"), - wxYES_NO | wxNO_DEFAULT | wxCENTRE, wxDefaultPosition); + _("Clear app data?"), wxYES_NO | wxNO_DEFAULT | wxCENTRE, wxDefaultPosition); bool remove = false; @@ -2774,11 +687,12 @@ void MainFrame::OnSelectResetAppData(wxCommandEvent& event) SH_LOG_ERROR("Could not delete {}", DATABASE_FILEPATH); if (config_is_deleted && db_is_deleted) - // m_InfoBar->ShowMessage(_("Successfully cleared app data"), wxICON_INFORMATION); + { + m_pLibrary->GetInfoBarObject()->ShowMessage(_("Successfully cleared app data"), wxICON_INFORMATION); SH_LOG_INFO("Cleared app data successfully"); + } else - wxMessageBox(_("Error! Could not clear app data"), _("Error!"), - wxOK | wxCENTRE | wxICON_ERROR, this); + wxMessageBox(_("Error! Could not clear app data"), _("Error!"), wxOK | wxCENTRE | wxICON_ERROR, this); } break; case wxID_NO: @@ -2788,7 +702,7 @@ void MainFrame::OnSelectResetAppData(wxCommandEvent& event) } } -void MainFrame::OnSelectAbout(wxCommandEvent& event) +void cMainFrame::OnSelectAbout(wxCommandEvent& event) { wxAboutDialogInfo aboutInfo; @@ -2801,43 +715,42 @@ void MainFrame::OnSelectAbout(wxCommandEvent& event) aboutInfo.SetWebSite(PROJECT_WEBSITE); aboutInfo.AddDeveloper(PROJECT_AUTHOR); aboutInfo.SetLicence(wxString::Format(wxString::FromAscii( - "%s %s\n" - "Copyright (C) %s Apoorv Singh\n" - "\n" - "%s is free software: you can redistribute it and/or modify\n" - "it under the terms of the GNU General Public License as published by\n" - "the Free Software Foundation, either version 3 of the License, or\n" - "(at your option) any later version.\n" - "\n" - "%s is distributed in the hope that it will be useful,\n" - "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" - "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" - "GNU General Public License for more details.\n" - "\n" - "You should have received a copy of the GNU General Public License\n" - "along with this program. If not, see .\n" - ), PROJECT_NAME, PROJECT_VERSION, PROJECT_COPYRIGHT_YEARS, - PROJECT_NAME, PROJECT_NAME)); + "%s %s\n" + "Copyright (C) %s Apoorv Singh\n" + "\n" + "%s is free software: you can redistribute it and/or modify\n" + "it under the terms of the GNU General Public License as published by\n" + "the Free Software Foundation, either version 3 of the License, or\n" + "(at your option) any later version.\n" + "\n" + "%s is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "GNU General Public License for more details.\n" + "\n" + "You should have received a copy of the GNU General Public License\n" + "along with this program. If not, see .\n" + ), PROJECT_NAME, PROJECT_VERSION, PROJECT_COPYRIGHT_YEARS, PROJECT_NAME, PROJECT_NAME)); wxAboutBox(aboutInfo); } -void MainFrame::OnResizeStatusBar(wxSizeEvent& event) +void cMainFrame::OnResizeStatusBar(wxSizeEvent& event) { wxRect rect; - m_StatusBar->GetFieldRect(2, rect); + m_pStatusBar->GetFieldRect(2, rect); - wxSize bitmap_size = m_HiveBitmap->GetSize(); + wxSize bitmap_size = m_pHiveBitmap->GetSize(); - m_HiveBitmap->Move(rect.x + (rect.width - bitmap_size.x), - rect.y + (rect.height - bitmap_size.y)); + m_pHiveBitmap->Move(rect.x + (rect.width - bitmap_size.x), + rect.y + (rect.height - bitmap_size.y)); event.Skip(); } -void MainFrame::OnResizeFrame(wxSizeEvent& event) +void cMainFrame::OnResizeFrame(wxSizeEvent& event) { - Serializer serializer; + SampleHive::cSerializer serializer; SH_LOG_DEBUG("Frame resized to {}, {}", GetSize().GetWidth(), GetSize().GetHeight()); @@ -2846,40 +759,33 @@ void MainFrame::OnResizeFrame(wxSizeEvent& event) event.Skip(); } -void MainFrame::OnTopSplitterSashPosChanged(wxSplitterEvent& event) +void cMainFrame::OnTopSplitterSashPosChanged(wxSplitterEvent& event) { - Serializer serializer; + SampleHive::cSerializer serializer; - SH_LOG_DEBUG("TopSplitter at {}", m_TopSplitter->GetSashPosition()); + SH_LOG_DEBUG("TopSplitter at {}", m_pTopSplitter->GetSashPosition()); - serializer.SerializeSplitterSashPos("top", m_TopSplitter->GetSashPosition()); + serializer.SerializeSplitterSashPos("top", m_pTopSplitter->GetSashPosition()); } -void MainFrame::OnBottomSplitterSashPosChanged(wxSplitterEvent& event) +void cMainFrame::OnBottomSplitterSashPosChanged(wxSplitterEvent& event) { - Serializer serializer; + SampleHive::cSerializer serializer; - SH_LOG_DEBUG("BottomSplitter at {}", m_BottomSplitter->GetSashPosition()); + SH_LOG_DEBUG("BottomSplitter at {}", m_pBottomSplitter->GetSashPosition()); - serializer.SerializeSplitterSashPos("bottom", m_BottomSplitter->GetSashPosition()); + serializer.SerializeSplitterSashPos("bottom", m_pBottomSplitter->GetSashPosition()); } -void MainFrame::SetAfterFrameCreate() +void cMainFrame::SetAfterFrameCreate() { - Serializer serializer; + SampleHive::cSerializer serializer; - m_TopSplitter->SetSashPosition(serializer.DeserializeSplitterSashPos("top")); - m_BottomSplitter->SetSashPosition(serializer.DeserializeSplitterSashPos("bottom")); - - // m_Notebook->SetListCtrlObject(*m_Library->GetListCtrlObject()); - - // m_Library->SetHivesObject(*m_Notebook->GetHivesPanel()->GetHivesObject()); - // m_Library->SetFavoritesHive(m_Notebook->GetHivesPanel()->GetFavoritesHive()); - // m_Library->SetTrashObject(*m_Notebook->GetTrashPanel()->GetTrashObject()); - // m_Library->SetTrashRoot(m_Notebook->GetTrashPanel()->GetTrashRoot()); + m_pTopSplitter->SetSashPosition(serializer.DeserializeSplitterSashPos("top")); + m_pBottomSplitter->SetSashPosition(serializer.DeserializeSplitterSashPos("bottom")); } -void MainFrame::OnRecieveLoopPoints(SampleHive::LoopPointsEvent& event) +void cMainFrame::OnRecieveLoopPoints(SampleHive::cLoopPointsEvent& event) { std::pair loop_points = event.GetLoopPoints(); @@ -2891,108 +797,130 @@ void MainFrame::OnRecieveLoopPoints(SampleHive::LoopPointsEvent& event) int loopB_min = static_cast((m_LoopB / 60000).GetValue()); int loopB_sec = static_cast(((m_LoopB % 60000) / 1000).GetValue()); - SH_LOG_INFO(wxString::Format(_("Loop points set: A: %2i:%02i, B: %2i:%02i"), - loopA_min, loopA_sec, loopB_min, loopB_sec)); + SH_LOG_INFO(wxString::Format(_("Loop points set: A: %2i:%02i, B: %2i:%02i"), loopA_min, loopA_sec, loopB_min, loopB_sec)); - m_TransportControls->SetLoopABValue(true); + m_pTransportControls->SetLoopABValue(true); - bLoopPointsSet = true; + m_bLoopPointsSet = true; } -void MainFrame::OnRecievePushStatusBarStatus(SampleHive::StatusBarStatusEvent& event) +void cMainFrame::OnRecievePushStatusBarStatus(SampleHive::cStatusBarStatusEvent& event) { std::pair status = event.GetPushMessageAndSection(); - m_StatusBar->PushStatusText(status.first, status.second); + m_pStatusBar->PushStatusText(status.first, status.second); } -void MainFrame::OnRecievePopStatusBarStatus(SampleHive::StatusBarStatusEvent& event) +void cMainFrame::OnRecievePopStatusBarStatus(SampleHive::cStatusBarStatusEvent& event) { - m_StatusBar->PopStatusText(event.GetPopMessageSection()); + m_pStatusBar->PopStatusText(event.GetPopMessageSection()); } -void MainFrame::OnRecieveSetStatusBarStatus(SampleHive::StatusBarStatusEvent& event) +void cMainFrame::OnRecieveSetStatusBarStatus(SampleHive::cStatusBarStatusEvent& event) { std::pair status = event.GetStatusTextAndSection(); - m_StatusBar->SetStatusText(status.first, status.second); + m_pStatusBar->SetStatusText(status.first, status.second); } -void MainFrame::OnRecieveInfoBarStatus(SampleHive::InfoBarMessageEvent& event) +void cMainFrame::OnRecieveInfoBarStatus(SampleHive::cInfoBarMessageEvent& event) { - SH_LOG_INFO("{} called..", __FUNCTION__); - std::pair info = event.GetInfoBarMessage(); - // m_InfoBar->ShowMessage(info.first, info.second); - - SH_LOG_INFO("{} event processed", __FUNCTION__); + m_pLibrary->GetInfoBarObject()->ShowMessage(info.first, info.second); } -void MainFrame::OnRecieveTimerStopStatus(SampleHive::TimerEvent& event) +void cMainFrame::OnRecieveTimerStopStatus(SampleHive::cTimerEvent& event) { - if (m_Timer->IsRunning()) - m_Timer->Stop(); + if (m_pTimer->IsRunning()) + m_pTimer->Stop(); } -void MainFrame::OnRecieveCallFunctionPlay(SampleHive::CallFunctionEvent& event) +void cMainFrame::OnRecieveCallFunctionPlay(SampleHive::cCallFunctionEvent& event) { - Serializer serializer; + SampleHive::cSerializer serializer; wxString selection = event.GetSlection(); + bool checkAutoplay = event.GetAutoplayValue(); - // wxString sample_path = GetFilenamePathAndExtension(selection).Path; wxString sample_path = serializer.DeserializeShowFileExtension() ? - m_Database->GetSamplePathByFilename(selection.BeforeLast('.').ToStdString()) : - m_Database->GetSamplePathByFilename(selection.ToStdString()); + m_pDatabase->GetSamplePathByFilename(selection.BeforeLast('.').ToStdString()) : + m_pDatabase->GetSamplePathByFilename(selection.ToStdString()); - if (bLoopPointsSet && m_TransportControls->IsLoopABOn()) - PlaySample(sample_path.ToStdString(), selection.ToStdString(), true, m_LoopA.ToDouble(), wxFromStart); + if (checkAutoplay) + { + if (m_pTransportControls->CanAutoplay()) + { + if (m_bLoopPointsSet && m_pTransportControls->IsLoopABOn()) + PlaySample(sample_path.ToStdString(), selection.ToStdString(), true, m_LoopA.ToDouble(), wxFromStart); + else + PlaySample(sample_path.ToStdString(), selection.ToStdString()); + } + else + m_pMediaCtrl->Stop(); + } else - PlaySample(sample_path.ToStdString(), selection.ToStdString()); + { + if (m_bLoopPointsSet && m_pTransportControls->IsLoopABOn()) + PlaySample(sample_path.ToStdString(), selection.ToStdString(), true, m_LoopA.ToDouble(), wxFromStart); + else + PlaySample(sample_path.ToStdString(), selection.ToStdString()); + } } -void MainFrame::OnRecieveWaveformUpdateStatus(SampleHive::WaveformUpdateEvent& event) +void cMainFrame::OnRecieveWaveformUpdateStatus(SampleHive::cWaveformUpdateEvent& event) { - m_WaveformViewer->ResetDC(); + m_pWaveformViewer->ResetDC(); } -void MainFrame::ClearLoopPoints() +void cMainFrame::OnRecieveClearLoopPointsStatus(SampleHive::cLoopPointsEvent& event) +{ + ClearLoopPoints(); +} + +void cMainFrame::OnRecieveLoopABButtonValueChange(SampleHive::cLoopPointsEvent& event) +{ + m_pTransportControls->SetLoopABValue(false); +} + +void cMainFrame::ClearLoopPoints() { m_LoopA = 0; m_LoopB = 0; - bLoopPointsSet = false; + m_bLoopPointsSet = false; } -void MainFrame::PlaySample(const std::string& filepath, const std::string& sample, - bool seek, wxFileOffset where, wxSeekMode mode) +void cMainFrame::PlaySample(const std::string& filepath, const std::string& sample, bool seek, wxFileOffset where, wxSeekMode mode) { - if (m_MediaCtrl->Load(filepath)) + if (m_pMediaCtrl->Load(filepath)) { if (seek) - m_MediaCtrl->Seek(where, mode); + m_pMediaCtrl->Seek(where, mode); - if (!m_MediaCtrl->Play()) + if (!m_pMediaCtrl->Play()) SH_LOG_ERROR("Error! Cannot play sample."); PushStatusText(wxString::Format(_("Now playing: %s"), sample), 1); - if (!m_Timer->IsRunning()) - m_Timer->Start(20, wxTIMER_CONTINUOUS); + if (!m_pTimer->IsRunning()) + { + SH_LOG_INFO("Starting timer.."); + m_pTimer->Start(20, wxTIMER_CONTINUOUS); + } } else SH_LOG_ERROR("Error! Cannot load sample."); } -void MainFrame::InitDatabase() +void cMainFrame::InitDatabase() { // Initialize the database try { - m_Database = std::make_unique(); - m_Database->CreateTableSamples(); - m_Database->CreateTableHives(); + m_pDatabase = std::make_unique(); + m_pDatabase->CreateTableSamples(); + m_pDatabase->CreateTableHives(); } catch (std::exception& e) { @@ -3000,11 +928,11 @@ void MainFrame::InitDatabase() } } -MainFrame::~MainFrame() +cMainFrame::~cMainFrame() { // Delete wxTimer - delete m_Timer; + delete m_pTimer; // Delete wxFilesystemWatcher - delete m_FsWatcher; + delete m_pFsWatcher; } diff --git a/src/GUI/MainFrame.hpp b/src/GUI/MainFrame.hpp index fdf57a0..4f4a853 100644 --- a/src/GUI/MainFrame.hpp +++ b/src/GUI/MainFrame.hpp @@ -20,211 +20,40 @@ #pragma once -#include "Database/Database.hpp" #include "GUI/Library.hpp" +#include "GUI/Notebook.hpp" #include "GUI/TransportControls.hpp" #include "GUI/WaveformViewer.hpp" -#include "GUI/Notebook.hpp" +#include "Database/Database.hpp" #include "Utility/Serialize.hpp" -#include "Utility/SH_Event.hpp" +#include "Utility/Event.hpp" #include "SampleHiveConfig.hpp" #include #include -#include -#include -#include -#include -#include -#include #include #include #include -#include -#include #include -#include #include -#include -#include #include -#include #include -#include #include #include #include -#include #include -#include -#include -#include -#include -#include -#include - -#ifndef USE_SYSTEM_INCLUDE_PATH - #include -#else - #include -#endif - -struct FileInfo -{ - wxString Path; - std::string Extension; - std::string Filename; -}; - -class MainFrame : public wxFrame +class cMainFrame : public wxFrame { public: - MainFrame(); - ~MainFrame(); - - private: - // ------------------------------------------------------------------- - // Main Panel - // wxPanel* m_MainPanel; - wxBoxSizer* m_MainSizer; - - // ------------------------------------------------------------------- - // Hive bitmap icon for the statusbar - wxStaticBitmap* m_HiveBitmap; - - // ------------------------------------------------------------------- - // App statusbar - wxStatusBar* m_StatusBar; - - // ------------------------------------------------------------------- - // App menubar - wxMenuBar* m_MenuBar; - - // ------------------------------------------------------------------- - // Menu and menu items for the menubar - wxMenu* m_FileMenu; - wxMenu* m_EditMenu; - wxMenu* m_ViewMenu; - wxMenu* m_HelpMenu; - wxMenuItem* m_AddFile; - wxMenuItem* m_AddDirectory; - wxMenuItem* m_ToggleExtension; - wxMenuItem* m_ToggleMenuBar; - wxMenuItem* m_ToggleStatusBar; - - // ------------------------------------------------------------------- - // Splitter windows - wxSplitterWindow* m_TopSplitter; - wxSplitterWindow* m_BottomSplitter; - - // ------------------------------------------------------------------- - // Top panel controls - wxPanel* m_TopPanel; - cTransportControls* m_TransportControls; - cWaveformViewer* m_WaveformViewer; - // wxBoxSizer* m_TopSizer; - wxBoxSizer* m_TopPanelMainSizer; - // wxBoxSizer* m_WaveformDisplaySizer; - - // ------------------------------------------------------------------- - // Left panel controls - // wxPanel* m_BottomLeftPanel; - cNotebook* m_Notebook; - // wxPanel* m_HivesPanel; - // wxPanel* m_TrashPanel; - // wxNotebook* m_Notebook; - // wxBoxSizer* m_BottomLeftPanelMainSizer; - // wxBoxSizer* m_HivesMainSizer; - // wxBoxSizer* m_HivesFavoritesSizer; - // wxBoxSizer* m_HivesButtonSizer; - // wxBoxSizer* m_TrashMainSizer; - // wxBoxSizer* m_TrashItemSizer; - // wxBoxSizer* m_TrashButtonSizer; - // wxGenericDirCtrl* m_DirCtrl; - // wxDataViewTreeCtrl* m_Hives; - // wxDataViewItem favorites_hive; - // wxTreeItemId trash_root; - // wxTreeCtrl* m_Trash; - // wxButton* m_AddHiveButton; - // wxButton* m_RemoveHiveButton; - // wxButton* m_RestoreTrashedItemButton; - - // ------------------------------------------------------------------- - // Right panel controls - cLibrary* m_Library; - // wxPanel* m_BottomRightPanel; - // wxBoxSizer* m_BottomRightPanelMainSizer; - // wxSearchCtrl* m_SearchBox; - // wxInfoBar* m_InfoBar; - // wxDataViewListCtrl* m_Library; - - // ------------------------------------------------------------------- - // MediaCtrl - wxMediaCtrl* m_MediaCtrl; - - // ------------------------------------------------------------------- - // Timer - wxTimer* m_Timer; - - // ------------------------------------------------------------------- - std::unique_ptr m_Database; - - // ------------------------------------------------------------------- - // FileSystemWatcher - wxFileSystemWatcher* m_FsWatcher = nullptr; - - // ------------------------------------------------------------------- - wxLongLong m_LoopA, m_LoopB; - - // ------------------------------------------------------------------- - // wxSystemAppearance m_Theme = wxSystemSettings::GetAppearance(); - - private: - // ------------------------------------------------------------------- - bool bFiltered = false; - bool bShowMenuBar = false; - bool bShowStatusBar = false; - bool bLoopPointsSet = false; + cMainFrame(); + ~cMainFrame(); private: // ------------------------------------------------------------------- // Top panel control handlers void OnMediaFinished(wxMediaEvent& event); - // void OnClickSettings(wxCommandEvent& event); - - // ------------------------------------------------------------------- - // DirCtrl event handlers - // void OnClickDirCtrl(wxCommandEvent& event); - // void OnDragFromDirCtrl(wxTreeEvent& event); - - // ------------------------------------------------------------------- - // TrashPane event handlers - // void OnShowTrashContextMenu(wxTreeEvent& event); - // void OnClickRestoreTrashItem(wxCommandEvent& event); - // void OnDragAndDropToTrash(wxDropFilesEvent& event); - - // ------------------------------------------------------------------- - // Hives panel button event handlers - // void OnDragAndDropToHives(wxDropFilesEvent& event); - // void OnClickAddHive(wxCommandEvent& event); - // void OnClickRemoveHive(wxCommandEvent& event); - // void OnShowHivesContextMenu(wxDataViewEvent& event); - // void OnHiveStartEditing(wxDataViewEvent& event); - - // ------------------------------------------------------------------- - // SearchCtrl event handlers - // void OnDoSearch(wxCommandEvent& event); - // void OnCancelSearch(wxCommandEvent& event); - - // ------------------------------------------------------------------- - // Library event handlers - // void OnClickLibrary(wxDataViewEvent& event); - // void OnDragAndDropToLibrary(wxDropFilesEvent& event); - // void OnDragFromLibrary(wxDataViewEvent& event); - // void OnShowLibraryContextMenu(wxDataViewEvent& event); - // void OnShowLibraryColumnHeaderContextMenu(wxDataViewEvent& event); // ------------------------------------------------------------------- // App menu items event handlers @@ -254,34 +83,27 @@ class MainFrame : public wxFrame // Timer update event handler void UpdateElapsedTime(wxTimerEvent& event); - // ------------------------------------------------------------------- - // void AddSamples(wxArrayString& files); - // void OnAutoImportDir(const wxString& pathToDirectory); - // ------------------------------------------------------------------- void PlaySample(const std::string& filepath, const std::string& sample, bool seek = false, wxFileOffset where = NULL, wxSeekMode mode = wxFromStart); // Recieve custom events // ------------------------------------------------------------------- - void OnRecieveLoopPoints(SampleHive::LoopPointsEvent& event); - void OnRecievePushStatusBarStatus(SampleHive::StatusBarStatusEvent& event); - void OnRecievePopStatusBarStatus(SampleHive::StatusBarStatusEvent& event); - void OnRecieveSetStatusBarStatus(SampleHive::StatusBarStatusEvent& event); - void OnRecieveInfoBarStatus(SampleHive::InfoBarMessageEvent& event); - void OnRecieveTimerStopStatus(SampleHive::TimerEvent& event); - void OnRecieveCallFunctionPlay(SampleHive::CallFunctionEvent& event); - void OnRecieveWaveformUpdateStatus(SampleHive::WaveformUpdateEvent& event); + void OnRecieveLoopPoints(SampleHive::cLoopPointsEvent& event); + void OnRecieveClearLoopPointsStatus(SampleHive::cLoopPointsEvent& event); + void OnRecieveLoopABButtonValueChange(SampleHive::cLoopPointsEvent& event); + void OnRecievePushStatusBarStatus(SampleHive::cStatusBarStatusEvent& event); + void OnRecievePopStatusBarStatus(SampleHive::cStatusBarStatusEvent& event); + void OnRecieveSetStatusBarStatus(SampleHive::cStatusBarStatusEvent& event); + void OnRecieveInfoBarStatus(SampleHive::cInfoBarMessageEvent& event); + void OnRecieveTimerStopStatus(SampleHive::cTimerEvent& event); + void OnRecieveCallFunctionPlay(SampleHive::cCallFunctionEvent& event); + void OnRecieveWaveformUpdateStatus(SampleHive::cWaveformUpdateEvent& event); // ------------------------------------------------------------------- - // void LoadDatabase(); - // void RefreshDatabase(); + void LoadDatabase(); void LoadConfigFile(); - - // ------------------------------------------------------------------- - // Getters - // FileInfo GetFilenamePathAndExtension(const wxString& selected, - // bool checkExtension = true, bool doGetFilename = true) const; + // void RefreshDatabase(); // ------------------------------------------------------------------- // Directory watchers @@ -290,8 +112,6 @@ class MainFrame : public wxFrame void AddWatchEntry(wxFSWPathType type, std::string path); void OnFileSystemEvent(wxFileSystemWatcherEvent& event); - // wxString TagLibTowx(const TagLib::String& in); - // ------------------------------------------------------------------- // Call after frame creation void SetAfterFrameCreate(); @@ -299,8 +119,83 @@ class MainFrame : public wxFrame // ------------------------------------------------------------------- void ClearLoopPoints(); + // ------------------------------------------------------------------- void InitDatabase(); // ------------------------------------------------------------------- - friend class App; + friend class cApp; + + private: + // ------------------------------------------------------------------- + // Main Panel + wxBoxSizer* m_pMainSizer = nullptr; + + // ------------------------------------------------------------------- + // Hive bitmap icon for the statusbar + wxStaticBitmap* m_pHiveBitmap = nullptr; + + // ------------------------------------------------------------------- + // App statusbar + wxStatusBar* m_pStatusBar = nullptr; + + // ------------------------------------------------------------------- + // App menubar + wxMenuBar* m_pMenuBar = nullptr; + + // ------------------------------------------------------------------- + // Menu and menu items for the menubar + wxMenu* m_pFileMenu = nullptr; + wxMenu* m_pEditMenu = nullptr; + wxMenu* m_pViewMenu = nullptr; + wxMenu* m_pHelpMenu = nullptr; + wxMenuItem* m_pAddFile = nullptr; + wxMenuItem* m_pAddDirectory = nullptr; + wxMenuItem* m_pToggleExtension = nullptr; + wxMenuItem* m_pToggleMenuBar = nullptr; + wxMenuItem* m_pToggleStatusBar = nullptr; + + // ------------------------------------------------------------------- + // Splitter windows + wxSplitterWindow* m_pTopSplitter = nullptr; + wxSplitterWindow* m_pBottomSplitter = nullptr; + + // ------------------------------------------------------------------- + // Top panel controls + wxPanel* m_pTopPanel = nullptr; + cWaveformViewer* m_pWaveformViewer = nullptr; + cTransportControls* m_pTransportControls = nullptr; + wxBoxSizer* m_pTopPanelMainSizer = nullptr; + + // ------------------------------------------------------------------- + // Left panel controls + cNotebook* m_pNotebook = nullptr; + + // ------------------------------------------------------------------- + // Right panel controls + cLibrary* m_pLibrary = nullptr; + + // ------------------------------------------------------------------- + // MediaCtrl + wxMediaCtrl* m_pMediaCtrl = nullptr; + + // ------------------------------------------------------------------- + // Timer + wxTimer* m_pTimer = nullptr; + + // ------------------------------------------------------------------- + std::unique_ptr m_pDatabase = nullptr; + + // ------------------------------------------------------------------- + // FileSystemWatcher + wxFileSystemWatcher* m_pFsWatcher = nullptr; + + // ------------------------------------------------------------------- + wxLongLong m_LoopA, m_LoopB; + + private: + // ------------------------------------------------------------------- + bool m_bFiltered = false; + bool m_bShowMenuBar = false; + bool m_bShowStatusBar = false; + bool m_bLoopPointsSet = false; }; diff --git a/src/GUI/Notebook.cpp b/src/GUI/Notebook.cpp index d9a7983..8ac6958 100644 --- a/src/GUI/Notebook.cpp +++ b/src/GUI/Notebook.cpp @@ -1,3 +1,23 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "GUI/Notebook.hpp" #include "GUI/DirectoryBrowser.hpp" #include "GUI/Hives.hpp" @@ -9,8 +29,8 @@ cNotebook::cNotebook(wxWindow* window) m_pNotebook = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_TOP); m_DirectoryBrowser = new cDirectoryBrowser(m_pNotebook); - m_HivesPanel = new cHivesPanel(m_pNotebook, *m_pListCtrl); - m_TrashPanel = new cTrashPanel(m_pNotebook, *m_pListCtrl); + m_HivesPanel = new cHivesPanel(m_pNotebook); + m_TrashPanel = new cTrashPanel(m_pNotebook); // Adding the pages to wxNotebook m_pNotebook->AddPage(m_DirectoryBrowser, _("Browse"), false); diff --git a/src/GUI/Notebook.hpp b/src/GUI/Notebook.hpp index df5f57f..21fa98a 100644 --- a/src/GUI/Notebook.hpp +++ b/src/GUI/Notebook.hpp @@ -1,3 +1,23 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #include "GUI/DirectoryBrowser.hpp" @@ -21,8 +41,6 @@ class cNotebook : public wxPanel cHivesPanel* GetHivesPanel() const { return m_HivesPanel; } cTrashPanel* GetTrashPanel() const { return m_TrashPanel; } - void SetListCtrlObject(wxDataViewListCtrl& listCtrl) { m_pListCtrl = &listCtrl; } - private: // ------------------------------------------------------------------- wxNotebook* m_pNotebook = nullptr; @@ -32,6 +50,4 @@ class cNotebook : public wxPanel cDirectoryBrowser* m_DirectoryBrowser = nullptr; cHivesPanel* m_HivesPanel = nullptr; cTrashPanel* m_TrashPanel = nullptr; - - wxDataViewListCtrl* m_pListCtrl; }; diff --git a/src/GUI/SearchBar.cpp b/src/GUI/SearchBar.cpp index 2c9592d..3626e1f 100644 --- a/src/GUI/SearchBar.cpp +++ b/src/GUI/SearchBar.cpp @@ -1,15 +1,38 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "GUI/SearchBar.hpp" #include "GUI/ListCtrl.hpp" #include "Database/Database.hpp" #include "Utility/ControlIDs.hpp" +#include "Utility/HiveData.hpp" #include "Utility/Serialize.hpp" #include "Utility/Paths.hpp" #include "Utility/Log.hpp" -cSearchBar::cSearchBar(wxWindow* window, wxDataViewListCtrl& listCtrl) - : wxSearchCtrl(window, BC_Search, _("Search for samples.."), +#include + +cSearchBar::cSearchBar(wxWindow* window) + : wxSearchCtrl(window, SampleHive::ID::BC_Search, _("Search for samples.."), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER), - m_pWindow(window), m_ListCtrl(listCtrl) + m_pWindow(window) { // Set minimum and maximum size of m_SearchBox // so it doesn't expand too wide when resizing the main frame. @@ -19,16 +42,15 @@ cSearchBar::cSearchBar(wxWindow* window, wxDataViewListCtrl& listCtrl) ShowSearchButton(true); ShowCancelButton(true); - Bind(wxEVT_TEXT, &cSearchBar::OnDoSearch, this, BC_Search); - Bind(wxEVT_SEARCHCTRL_SEARCH_BTN, &cSearchBar::OnDoSearch, this, BC_Search); - Bind(wxEVT_SEARCHCTRL_CANCEL_BTN, &cSearchBar::OnCancelSearch, this, BC_Search); + Bind(wxEVT_TEXT, &cSearchBar::OnDoSearch, this, SampleHive::ID::BC_Search); + Bind(wxEVT_SEARCHCTRL_SEARCH_BTN, &cSearchBar::OnDoSearch, this, SampleHive::ID::BC_Search); + Bind(wxEVT_SEARCHCTRL_CANCEL_BTN, &cSearchBar::OnCancelSearch, this, SampleHive::ID::BC_Search); } void cSearchBar::OnDoSearch(wxCommandEvent& event) { - Serializer serializer; - Database db; - // cListCtrl m_ListCtrl(m_pWindow); + SampleHive::cSerializer serializer; + cDatabase db; const auto search = this->GetValue().ToStdString(); @@ -43,19 +65,19 @@ void cSearchBar::OnDoSearch(wxCommandEvent& event) } else { - m_ListCtrl.DeleteAllItems(); + SampleHive::cHiveData::Get().ListCtrlDeleteAllItems(); std::cout << search << std::endl; for (const auto& data : dataset) { - m_ListCtrl.AppendItem(data); + SampleHive::cHiveData::Get().ListCtrlAppendItem(data); } } } - catch (...) + catch (std::exception& e) { - std::cerr << "Error loading data." << std::endl; + SH_LOG_ERROR("Error loading data. {}", e.what()); } } diff --git a/src/GUI/SearchBar.hpp b/src/GUI/SearchBar.hpp index ec4e521..d6988c5 100644 --- a/src/GUI/SearchBar.hpp +++ b/src/GUI/SearchBar.hpp @@ -1,3 +1,23 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #include @@ -6,7 +26,7 @@ class cSearchBar : public wxSearchCtrl { public: - cSearchBar(wxWindow* window, wxDataViewListCtrl& listCtrl); + cSearchBar(wxWindow* window); ~cSearchBar(); public: @@ -21,6 +41,4 @@ class cSearchBar : public wxSearchCtrl private: // ------------------------------------------------------------------- wxWindow* m_pWindow = nullptr; - - wxDataViewListCtrl& m_ListCtrl; }; diff --git a/src/GUI/TransportControls.cpp b/src/GUI/TransportControls.cpp index dd49cd4..c25200e 100644 --- a/src/GUI/TransportControls.cpp +++ b/src/GUI/TransportControls.cpp @@ -1,79 +1,91 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "GUI/TransportControls.hpp" +#include "GUI/Dialogs/Settings.hpp" #include "Utility/ControlIDs.hpp" -#include "Utility/SH_Event.hpp" +#include "Utility/Event.hpp" +#include "Utility/HiveData.hpp" +#include "Utility/Sample.hpp" #include "Utility/Signal.hpp" #include "Utility/Serialize.hpp" #include "Utility/Log.hpp" #include "Utility/Paths.hpp" +#include "Utility/Utils.hpp" -cTransportControls::cTransportControls(wxWindow* window, wxDataViewListCtrl& library, - wxMediaCtrl& mediaCtrl, wxTimer& timer) +cTransportControls::cTransportControls(wxWindow* window, wxMediaCtrl& mediaCtrl) : wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxNO_BORDER), - m_Library(library), m_MediaCtrl(mediaCtrl), m_Timer(timer) + m_MediaCtrl(mediaCtrl) { m_pMainSizer = new wxBoxSizer(wxHORIZONTAL); // Looping region controls if (m_Theme.IsDark()) - m_pLoopABButton = new wxBitmapToggleButton(this, BC_LoopABButton, - static_cast(ICON_AB_LIGHT_16px), + m_pLoopABButton = new wxBitmapToggleButton(this, SampleHive::ID::BC_LoopABButton, static_cast(ICON_AB_LIGHT_16px), wxDefaultPosition, wxDefaultSize, 0); else - m_pLoopABButton = new wxBitmapToggleButton(this, BC_LoopABButton, - static_cast(ICON_AB_DARK_16px), + m_pLoopABButton = new wxBitmapToggleButton(this, SampleHive::ID::BC_LoopABButton, static_cast(ICON_AB_DARK_16px), wxDefaultPosition, wxDefaultSize, 0); m_pLoopABButton->SetToolTip(_("Loop selected region")); // Autoplay checkbox - m_pAutoPlayCheck = new wxCheckBox(this, BC_Autoplay, _("Autoplay"), + m_pAutoPlayCheck = new wxCheckBox(this, SampleHive::ID::BC_Autoplay, _("Autoplay"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); m_pAutoPlayCheck->SetToolTip(_("Autoplay")); // Volume slider - m_pVolumeSlider = new wxSlider(this, BC_Volume, 100, 0, 100, - wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL); + m_pVolumeSlider = new wxSlider(this, SampleHive::ID::BC_Volume, 100, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL); m_pVolumeSlider->SetToolTip(_("Volume")); m_pVolumeSlider->SetMinSize(wxSize(120, -1)); m_pVolumeSlider->SetMaxSize(wxSize(120, -1)); // Sample position static text - m_pSamplePosition = new wxStaticText(this, BC_SamplePosition, "--:--/--:--", + m_pSamplePosition = new wxStaticText(this, SampleHive::ID::BC_SamplePosition, "--:--/--:--", wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL); // Transport control buttons if (m_Theme.IsDark()) { - m_pPlayButton = new wxBitmapButton(this, BC_Play, - wxBitmapBundle::FromBitmap(static_cast - (ICON_PLAY_LIGHT_16px)), + m_pPlayButton = new wxBitmapButton(this, SampleHive::ID::BC_Play, + wxBitmapBundle::FromBitmap(static_cast(ICON_PLAY_LIGHT_16px)), wxDefaultPosition, wxDefaultSize, 0); - m_pLoopButton = new wxBitmapToggleButton(this, BC_Loop, - static_cast(ICON_LOOP_LIGHT_16px), + m_pLoopButton = new wxBitmapToggleButton(this, SampleHive::ID::BC_Loop, static_cast(ICON_LOOP_LIGHT_16px), wxDefaultPosition, wxDefaultSize, 0); - m_pStopButton = new wxBitmapButton(this, BC_Stop, - wxBitmapBundle::FromBitmap(static_cast - (ICON_STOP_LIGHT_16px)), + m_pStopButton = new wxBitmapButton(this, SampleHive::ID::BC_Stop, + wxBitmapBundle::FromBitmap(static_cast(ICON_STOP_LIGHT_16px)), wxDefaultPosition, wxDefaultSize, 0); - m_pMuteButton = new wxBitmapToggleButton(this, BC_Mute, - static_cast(ICON_MUTE_LIGHT_16px), + m_pMuteButton = new wxBitmapToggleButton(this, SampleHive::ID::BC_Mute, static_cast(ICON_MUTE_LIGHT_16px), wxDefaultPosition, wxDefaultSize, 0); } else { - m_pPlayButton = new wxBitmapButton(this, BC_Play, - wxBitmapBundle::FromBitmap(static_cast - (ICON_PLAY_DARK_16px)), + m_pPlayButton = new wxBitmapButton(this, SampleHive::ID::BC_Play, + wxBitmapBundle::FromBitmap(static_cast(ICON_PLAY_DARK_16px)), wxDefaultPosition, wxDefaultSize, 0); - m_pLoopButton = new wxBitmapToggleButton(this, BC_Loop, - static_cast(ICON_LOOP_DARK_16px), + m_pLoopButton = new wxBitmapToggleButton(this, SampleHive::ID::BC_Loop, static_cast(ICON_LOOP_DARK_16px), wxDefaultPosition, wxDefaultSize, 0); - m_pStopButton = new wxBitmapButton(this, BC_Stop, - wxBitmapBundle::FromBitmap(static_cast - (ICON_STOP_DARK_16px)), + m_pStopButton = new wxBitmapButton(this, SampleHive::ID::BC_Stop, + wxBitmapBundle::FromBitmap(static_cast(ICON_STOP_DARK_16px)), wxDefaultPosition, wxDefaultSize, 0); - m_pMuteButton = new wxBitmapToggleButton(this, BC_Mute, - static_cast(ICON_MUTE_DARK_16px), + m_pMuteButton = new wxBitmapToggleButton(this, SampleHive::ID::BC_Mute, static_cast(ICON_MUTE_DARK_16px), wxDefaultPosition, wxDefaultSize, 0); } @@ -82,15 +94,14 @@ cTransportControls::cTransportControls(wxWindow* window, wxDataViewListCtrl& lib m_pStopButton->SetToolTip(_("Stop")); m_pMuteButton->SetToolTip(_("Mute")); - // m_pSettingsButton = new wxButton(this, BC_Settings, _("Settings"), - // wxDefaultPosition, wxDefaultSize, 0); - // m_pSettingsButton->SetToolTip(_("Settings")); + m_pSettingsButton = new wxButton(this, SampleHive::ID::BC_Settings, _("Settings"), wxDefaultPosition, wxDefaultSize, 0); + m_pSettingsButton->SetToolTip(_("Settings")); m_pMainSizer->Add(m_pPlayButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); m_pMainSizer->Add(m_pStopButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); m_pMainSizer->Add(m_pLoopButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); m_pMainSizer->Add(m_pLoopABButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); - // m_pMainSizer->Add(m_pSettingsButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); + m_pMainSizer->Add(m_pSettingsButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); m_pMainSizer->Add(0,0,1, wxALL | wxEXPAND, 0); m_pMainSizer->Add(m_pSamplePosition, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); m_pMainSizer->Add(30,0,0, wxALL | wxEXPAND, 0); @@ -103,37 +114,61 @@ cTransportControls::cTransportControls(wxWindow* window, wxDataViewListCtrl& lib m_pMainSizer->SetSizeHints(this); m_pMainSizer->Layout(); - Bind(wxEVT_BUTTON, &cTransportControls::OnClickPlay, this, BC_Play); - Bind(wxEVT_TOGGLEBUTTON, &cTransportControls::OnClickLoop, this, BC_Loop); - Bind(wxEVT_BUTTON, &cTransportControls::OnClickStop, this, BC_Stop); - Bind(wxEVT_TOGGLEBUTTON, &cTransportControls::OnClickMute, this, BC_Mute); - // Bind(wxEVT_BUTTON, &Controls::OnClickSettings, this, BC_Settings); - Bind(wxEVT_CHECKBOX, &cTransportControls::OnCheckAutoplay, this, BC_Autoplay); - Bind(wxEVT_SCROLL_THUMBTRACK, &cTransportControls::OnSlideVolume, this, BC_Volume); - Bind(wxEVT_SCROLL_THUMBRELEASE, &cTransportControls::OnReleaseVolumeSlider, this, BC_Volume); + Bind(wxEVT_BUTTON, &cTransportControls::OnClickPlay, this, SampleHive::ID::BC_Play); + Bind(wxEVT_TOGGLEBUTTON, &cTransportControls::OnClickLoop, this, SampleHive::ID::BC_Loop); + Bind(wxEVT_BUTTON, &cTransportControls::OnClickStop, this, SampleHive::ID::BC_Stop); + Bind(wxEVT_TOGGLEBUTTON, &cTransportControls::OnClickMute, this, SampleHive::ID::BC_Mute); + Bind(wxEVT_BUTTON, &cTransportControls::OnClickSettings, this, SampleHive::ID::BC_Settings); + Bind(wxEVT_CHECKBOX, &cTransportControls::OnCheckAutoplay, this, SampleHive::ID::BC_Autoplay); + Bind(wxEVT_SCROLL_THUMBTRACK, &cTransportControls::OnSlideVolume, this, SampleHive::ID::BC_Volume); + Bind(wxEVT_SCROLL_THUMBRELEASE, &cTransportControls::OnReleaseVolumeSlider, this, SampleHive::ID::BC_Volume); // Load control values from config file LoadConfigFile(); } +void cTransportControls::OnClickSettings(wxCommandEvent& event) +{ + cSettings* settings = new cSettings(this); + + switch (settings->ShowModal()) + { + case wxID_OK: + if (settings->CanAutoImport()) + { + SampleHive::cUtils::Get().OnAutoImportDir(settings->GetImportDirPath(), this); + // RefreshDatabase(); + } + if (settings->IsWaveformColourChanged()) + { + SampleHive::cSignal::SendWaveformUpdateStatus(*this); + } + break; + case wxID_CANCEL: + break; + default: + return; + } +} + void cTransportControls::OnClickPlay(wxCommandEvent& event) { m_bStopped = false; - int selected_row = m_Library.GetSelectedRow(); + int selected_row = SampleHive::cHiveData::Get().GetListCtrlSelectedRow(); if (selected_row < 0) return; - wxString selection = m_Library.GetTextValue(selected_row, 1); + wxString selection = SampleHive::cHiveData::Get().GetListCtrlTextValue(selected_row, 1); // Send custom event to MainFrame to play the sample - SampleHive::Signal::SendCallFunctionPlay(selection, *this); + SampleHive::cSignal::SendCallFunctionPlay(selection, false, *this); } void cTransportControls::OnClickLoop(wxCommandEvent& event) { - Serializer serializer; + SampleHive::cSerializer serializer; m_bLoop = m_pLoopButton->GetValue(); @@ -148,17 +183,17 @@ void cTransportControls::OnClickStop(wxCommandEvent& event) m_bStopped = true; // Send custom event to MainFrame to stop the timer - SampleHive::Signal::SendTimerStopStatus(*this); + SampleHive::cSignal::SendTimerStopStatus(*this); m_pSamplePosition->SetLabel("--:--/--:--"); // Send custom event to MainFrame to set the statusbar status - SampleHive::Signal::SendSetStatusBarStatus(_("Stopped"), 1, *this); + SampleHive::cSignal::SendSetStatusBarStatus(_("Stopped"), 1, *this); } void cTransportControls::OnClickMute(wxCommandEvent& event) { - Serializer serializer; + SampleHive::cSerializer serializer; if (m_pMuteButton->GetValue()) { @@ -178,7 +213,7 @@ void cTransportControls::OnClickMute(wxCommandEvent& event) void cTransportControls::OnCheckAutoplay(wxCommandEvent& event) { - Serializer serializer; + SampleHive::cSerializer serializer; if (m_pAutoPlayCheck->GetValue()) { @@ -199,39 +234,37 @@ void cTransportControls::OnSlideVolume(wxScrollEvent& event) m_MediaCtrl.SetVolume(double(m_pVolumeSlider->GetValue()) / 100); // Send custom event to MainFrame to push status to statusbar - SampleHive::Signal::SendPushStatusBarStatus(wxString::Format(_("Volume: %d"), - m_pVolumeSlider->GetValue()), 1, *this); + SampleHive::cSignal::SendPushStatusBarStatus(wxString::Format(_("Volume: %d"), m_pVolumeSlider->GetValue()), 1, *this); } void cTransportControls::OnReleaseVolumeSlider(wxScrollEvent& event) { - Serializer serializer; + SampleHive::cSerializer serializer; serializer.SerializeMediaVolume(m_pVolumeSlider->GetValue()); - int selected_row = m_Library.GetSelectedRow(); + int selected_row = SampleHive::cHiveData::Get().GetListCtrlSelectedRow(); if (selected_row < 0) return; - wxString selection = m_Library.GetTextValue(selected_row, 1); + wxString selection = SampleHive::cHiveData::Get().GetListCtrlTextValue(selected_row, 1); // Wait a second then remove the status from statusbar wxSleep(1); // Send custom event to MainFrame to pop status from statusbar - SampleHive::Signal::SendPopStatusBarStatus(1, *this); + SampleHive::cSignal::SendPopStatusBarStatus(1, *this); if (m_MediaCtrl.GetState() == wxMEDIASTATE_STOPPED) - SampleHive::Signal::SendSetStatusBarStatus(_("Stopped"), 1, *this); + SampleHive::cSignal::SendSetStatusBarStatus(_("Stopped"), 1, *this); else - SampleHive::Signal::SendPushStatusBarStatus(wxString::Format(_("Now playing: %s"), selection), - 1, *this); + SampleHive::cSignal::SendPushStatusBarStatus(wxString::Format(_("Now playing: %s"), selection), 1, *this); } void cTransportControls::LoadConfigFile() { - Serializer serializer; + SampleHive::cSerializer serializer; SH_LOG_INFO("Reading transport control values.."); diff --git a/src/GUI/TransportControls.hpp b/src/GUI/TransportControls.hpp index ffee40b..5891dbe 100644 --- a/src/GUI/TransportControls.hpp +++ b/src/GUI/TransportControls.hpp @@ -1,9 +1,28 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #include #include #include -#include #include #include #include @@ -12,7 +31,6 @@ #include #include #include -#include #include #include @@ -20,7 +38,7 @@ class cTransportControls : public wxPanel { public: // ------------------------------------------------------------------- - cTransportControls(wxWindow* window, wxDataViewListCtrl& library, wxMediaCtrl& mediaCtrl, wxTimer& timer); + cTransportControls(wxWindow* window, wxMediaCtrl& mediaCtrl); ~cTransportControls(); public: @@ -65,11 +83,11 @@ class cTransportControls : public wxPanel // Load control values from config file void LoadConfigFile(); + void OnAutoImportDir(const wxString& pathToDirectory); + private: // ------------------------------------------------------------------- - wxDataViewListCtrl& m_Library; wxMediaCtrl& m_MediaCtrl; - wxTimer& m_Timer; private: // ------------------------------------------------------------------- diff --git a/src/GUI/Trash.cpp b/src/GUI/Trash.cpp index 47da61b..37a5598 100644 --- a/src/GUI/Trash.cpp +++ b/src/GUI/Trash.cpp @@ -1,25 +1,47 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "GUI/Trash.hpp" -#include "GUI/Hives.hpp" -#include "GUI/ListCtrl.hpp" #include "Database/Database.hpp" #include "Utility/ControlIDs.hpp" +#include "Utility/HiveData.hpp" #include "Utility/Log.hpp" #include "Utility/Paths.hpp" #include "Utility/Signal.hpp" #include "Utility/Serialize.hpp" +#include "Utility/Utils.hpp" + +#include #include #include -cTrashPanel::cTrashPanel(wxWindow* window, wxDataViewListCtrl& listCtrl) +cTrashPanel::cTrashPanel(wxWindow* window) : wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL), - m_pWindow(window), m_ListCtrl(listCtrl) + m_pWindow(window) { m_pMainSizer = new wxBoxSizer(wxVERTICAL); m_pTrashSizer = new wxBoxSizer(wxVERTICAL); m_pButtonSizer = new wxBoxSizer(wxHORIZONTAL); - m_pTrash = new wxTreeCtrl(this, BC_Trash, wxDefaultPosition, wxDefaultSize, + m_pTrash = new wxTreeCtrl(this, SampleHive::ID::BC_Trash, wxDefaultPosition, wxDefaultSize, wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_MULTIPLE); // Setting m_Trash to accept files to be dragged and dropped on it @@ -27,7 +49,7 @@ cTrashPanel::cTrashPanel(wxWindow* window, wxDataViewListCtrl& listCtrl) m_pTrashSizer->Add(m_pTrash, wxSizerFlags(1).Expand()); - m_pRestoreTrashedItemButton = new wxButton(this, BC_RestoreTrashedItem, _("Restore sample"), + m_pRestoreTrashedItemButton = new wxButton(this, SampleHive::ID::BC_RestoreTrashedItem, _("Restore sample"), wxDefaultPosition, wxDefaultSize, 0); m_pRestoreTrashedItemButton->SetToolTip(_("Restore selected sample")); @@ -37,8 +59,8 @@ cTrashPanel::cTrashPanel(wxWindow* window, wxDataViewListCtrl& listCtrl) m_TrashRoot = m_pTrash->AddRoot("Trash"); m_pTrash->Connect(wxEVT_DROP_FILES, wxDropFilesEventHandler(cTrashPanel::OnDragAndDropToTrash), NULL, this); - Bind(wxEVT_TREE_ITEM_RIGHT_CLICK, &cTrashPanel::OnShowTrashContextMenu, this, BC_Trash); - Bind(wxEVT_BUTTON, &cTrashPanel::OnClickRestoreTrashItem, this, BC_RestoreTrashedItem); + Bind(wxEVT_TREE_ITEM_RIGHT_CLICK, &cTrashPanel::OnShowTrashContextMenu, this, SampleHive::ID::BC_Trash); + Bind(wxEVT_BUTTON, &cTrashPanel::OnClickRestoreTrashItem, this, SampleHive::ID::BC_RestoreTrashedItem); m_pMainSizer->Add(m_pTrashSizer, wxSizerFlags(1).Expand()); m_pMainSizer->Add(m_pButtonSizer, wxSizerFlags(0).Expand()); @@ -52,10 +74,8 @@ cTrashPanel::cTrashPanel(wxWindow* window, wxDataViewListCtrl& listCtrl) void cTrashPanel::OnDragAndDropToTrash(wxDropFilesEvent& event) { - Serializer serializer; - Database db; - cHivesPanel hives(m_pWindow, m_ListCtrl); - // cListCtrl m_ListCtrl.m_pWindow); + SampleHive::cSerializer serializer; + cDatabase db; if (event.GetNumberOfFiles() > 0) { @@ -63,8 +83,7 @@ void cTrashPanel::OnDragAndDropToTrash(wxDropFilesEvent& event) wxArrayString files; wxDataViewItemArray items; - int rows = m_ListCtrl.GetSelections(items); - // int rows = 2; + int rows = SampleHive::cHiveData::Get().GetListCtrlSelections(items); wxString msg; @@ -73,13 +92,13 @@ void cTrashPanel::OnDragAndDropToTrash(wxDropFilesEvent& event) for (int i = 0; i < rows; i++) { - int item_row = m_ListCtrl.ItemToRow(items[i]); + int item_row = SampleHive::cHiveData::Get().GetListCtrlRowFromItem(items, i); - wxString text_value = m_ListCtrl.GetTextValue(item_row, 1); + wxString text_value = SampleHive::cHiveData::Get().GetListCtrlTextValue(item_row, 1); std::string multi_selection = serializer.DeserializeShowFileExtension() ? - m_ListCtrl.GetTextValue(item_row, 1).BeforeLast('.').ToStdString() : - m_ListCtrl.GetTextValue(item_row, 1).ToStdString() ; + SampleHive::cHiveData::Get().GetListCtrlTextValue(item_row, 1).BeforeLast('.').ToStdString() : + SampleHive::cHiveData::Get().GetListCtrlTextValue(item_row, 1).ToStdString() ; file_data.AddFile(multi_selection); @@ -87,25 +106,25 @@ void cTrashPanel::OnDragAndDropToTrash(wxDropFilesEvent& event) if (db.GetFavoriteColumnValueByFilename(files[i].ToStdString())) { - m_ListCtrl.SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), item_row, 0); + SampleHive::cHiveData::Get().ListCtrlSetVariant(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), item_row, 0); db.UpdateFavoriteColumn(files[i].ToStdString(), 0); - for (int j = 0; j < hives.GetHivesObject()->GetChildCount(root); j++) + for (int j = 0; j < SampleHive::cHiveData::Get().GetHiveChildCount(root); j++) { - container = hives.GetHivesObject()->GetNthChild(root, j); + container = SampleHive::cHiveData::Get().GetHiveNthChild(root, j); - for (int k = 0; k < hives.GetHivesObject()->GetChildCount(container); k++) + for (int k = 0; k < SampleHive::cHiveData::Get().GetHiveChildCount(container); k++) { - child = hives.GetHivesObject()->GetNthChild(container, k); + child = SampleHive::cHiveData::Get().GetHiveNthChild(container, k); wxString child_text = serializer.DeserializeShowFileExtension() ? - hives.GetHivesObject()->GetItemText(child).BeforeLast('.') : - hives.GetHivesObject()->GetItemText(child); + SampleHive::cHiveData::Get().GetHiveItemText(child).BeforeLast('.') : + SampleHive::cHiveData::Get().GetHiveItemText(child); if (child_text == files[i]) { - hives.GetHivesObject()->DeleteItem(child); + SampleHive::cHiveData::Get().HiveDeleteItem(child); break; } } @@ -114,39 +133,37 @@ void cTrashPanel::OnDragAndDropToTrash(wxDropFilesEvent& event) db.UpdateTrashColumn(files[i].ToStdString(), 1); db.UpdateHiveName(files[i].ToStdString(), - hives.GetHivesObject()->GetItemText(hives.GetFavoritesHive()).ToStdString()); + SampleHive::cHiveData::Get().GetHiveItemText(SampleHive::cHiveData::Get().GetFavoritesHive()).ToStdString()); m_pTrash->AppendItem(m_TrashRoot, text_value); - m_ListCtrl.DeleteItem(item_row); + SampleHive::cHiveData::Get().ListCtrlDeleteItem(item_row); msg = wxString::Format(_("%s sent to trash"), text_value); } if (!msg.IsEmpty()) - SampleHive::Signal::SendInfoBarMessage(msg, wxICON_ERROR, *this); - // m_InfoBar->ShowMessage(msg, wxICON_ERROR); + SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_ERROR, *this); } } void cTrashPanel::OnShowTrashContextMenu(wxTreeEvent& event) { - Serializer serializer; - Database db; - // cListCtrl m_ListCtrl.m_pWindow); + SampleHive::cSerializer serializer; + cDatabase db; wxTreeItemId selected_trashed_item = event.GetItem(); wxMenu menu; - menu.Append(MN_DeleteTrash, _("Delete from database"), _("Delete the selected sample(s) from database")); - menu.Append(MN_RestoreTrashedItem, _("Restore sample"), _("Restore the selected sample(s) back to library")); + menu.Append(SampleHive::ID::MN_DeleteTrash, _("Delete from database"), _("Delete the selected sample(s) from database")); + menu.Append(SampleHive::ID::MN_RestoreTrashedItem, _("Restore sample"), _("Restore the selected sample(s) back to library")); if (selected_trashed_item.IsOk()) { switch (m_pTrash->GetPopupMenuSelectionFromUser(menu, event.GetPoint())) { - case MN_DeleteTrash: + case SampleHive::ID::MN_DeleteTrash: { wxString trashed_item_name = serializer.DeserializeShowFileExtension() ? m_pTrash->GetItemText(selected_trashed_item).BeforeLast('.') : @@ -159,7 +176,7 @@ void cTrashPanel::OnShowTrashContextMenu(wxTreeEvent& event) SH_LOG_INFO("{} deleted from trash and databse", trashed_item_name); } break; - case MN_RestoreTrashedItem: + case SampleHive::ID::MN_RestoreTrashedItem: { wxArrayTreeItemIds selected_item_ids; m_pTrash->GetSelections(selected_item_ids); @@ -174,7 +191,7 @@ void cTrashPanel::OnShowTrashContextMenu(wxTreeEvent& event) { selected_item_text = m_pTrash->GetItemText(selected_item_ids[i]); - // filename = GetFilenamePathAndExtension(selected_item_text).Filename; + filename = SampleHive::cUtils::Get().GetFilenamePathAndExtension(selected_item_text).Filename; file_data.AddFile(filename); @@ -198,13 +215,13 @@ void cTrashPanel::OnShowTrashContextMenu(wxTreeEvent& event) { for (auto data : dataset) { - m_ListCtrl.AppendItem(data); + SampleHive::cHiveData::Get().ListCtrlAppendItem(data); } } } - catch (...) + catch (std::exception& e) { - std::cerr << "Error loading data." << std::endl; + SH_LOG_ERROR("Error loading data. {}", e.what()); } m_pTrash->Delete(selected_item_ids[i]); @@ -221,9 +238,8 @@ void cTrashPanel::OnShowTrashContextMenu(wxTreeEvent& event) void cTrashPanel::OnClickRestoreTrashItem(wxCommandEvent& event) { - Serializer serializer; - Database db; - // cListCtrl m_ListCtrl.m_pWindow); + SampleHive::cSerializer serializer; + cDatabase db; wxArrayTreeItemIds selected_item_ids; m_pTrash->GetSelections(selected_item_ids); @@ -242,8 +258,7 @@ void cTrashPanel::OnClickRestoreTrashItem(wxCommandEvent& event) if (selected_item_ids.IsEmpty()) { - wxMessageBox(_("No item selected, try selected a item first."), wxMessageBoxCaptionStr, - wxOK | wxCENTRE, this); + wxMessageBox(_("No item selected, try selected a item first."), wxMessageBoxCaptionStr, wxOK | wxCENTRE, this); return; } @@ -251,7 +266,7 @@ void cTrashPanel::OnClickRestoreTrashItem(wxCommandEvent& event) { selected_item_text = m_pTrash->GetItemText(selected_item_ids[i]); - // filename = GetFilenamePathAndExtension(selected_item_text).Filename; + filename = SampleHive::cUtils::Get().GetFilenamePathAndExtension(selected_item_text).Filename; file_data.AddFile(filename); @@ -273,13 +288,13 @@ void cTrashPanel::OnClickRestoreTrashItem(wxCommandEvent& event) { for (auto data : dataset) { - m_ListCtrl.AppendItem(data); + SampleHive::cHiveData::Get().ListCtrlAppendItem(data); } } } - catch (...) + catch (std::exception& e) { - std::cerr << "Error loading data." << std::endl; + SH_LOG_ERROR("Error loading data. {}", e.what()); } m_pTrash->Delete(selected_item_ids[i]); diff --git a/src/GUI/Trash.hpp b/src/GUI/Trash.hpp index 170b1da..ce53ddb 100644 --- a/src/GUI/Trash.hpp +++ b/src/GUI/Trash.hpp @@ -1,3 +1,23 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #include @@ -11,12 +31,12 @@ class cTrashPanel : public wxPanel { public: - cTrashPanel(wxWindow* window, wxDataViewListCtrl& listCtrl); + cTrashPanel(wxWindow* window); ~cTrashPanel(); public: wxTreeCtrl* GetTrashObject() { return m_pTrash; } - wxTreeItemId GetTrashRoot() { return m_TrashRoot; } + wxTreeItemId& GetTrashRoot() { return m_TrashRoot; } private: // ------------------------------------------------------------------- @@ -35,6 +55,4 @@ class cTrashPanel : public wxPanel private: wxWindow* m_pWindow = nullptr; - wxDataViewListCtrl& m_ListCtrl; - // friend class cListCtrl; }; diff --git a/src/GUI/WaveformViewer.cpp b/src/GUI/WaveformViewer.cpp index 8234bce..d2a846d 100644 --- a/src/GUI/WaveformViewer.cpp +++ b/src/GUI/WaveformViewer.cpp @@ -19,12 +19,13 @@ */ #include "GUI/WaveformViewer.hpp" -#include "Utility/Serialize.hpp" -#include "Utility/Signal.hpp" -#include "Utility/Tags.hpp" -#include "Utility/SH_Event.hpp" +#include "Utility/HiveData.hpp" #include "Utility/Log.hpp" #include "Utility/Paths.hpp" +#include "Utility/Serialize.hpp" +#include "Utility/Event.hpp" +#include "Utility/Signal.hpp" +#include "Utility/Tags.hpp" #include @@ -38,11 +39,9 @@ #include -cWaveformViewer::cWaveformViewer(wxWindow* window, wxDataViewListCtrl& library, - wxMediaCtrl& mediaCtrl, Database& database) - : wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, - wxTAB_TRAVERSAL | wxNO_BORDER | wxFULL_REPAINT_ON_RESIZE), - m_Window(window), m_Database(database), m_Library(library), m_MediaCtrl(mediaCtrl) +cWaveformViewer::cWaveformViewer(wxWindow* window, wxMediaCtrl& mediaCtrl, cDatabase& database) + : wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxNO_BORDER | wxFULL_REPAINT_ON_RESIZE), + m_Window(window), m_Database(database), m_MediaCtrl(mediaCtrl) { this->SetDoubleBuffered(true); @@ -110,7 +109,7 @@ void cWaveformViewer::OnPaint(wxPaintEvent& event) bAreaSelected = true; // SendLoopPoints(); - SampleHive::Signal::SendLoopPoints(CalculateLoopPoints(), *this); + SampleHive::cSignal::SendLoopPoints(CalculateLoopPoints(), *this); } else bAreaSelected = false; @@ -118,15 +117,15 @@ void cWaveformViewer::OnPaint(wxPaintEvent& event) void cWaveformViewer::RenderPlayhead(wxDC& dc) { - int selected_row = m_Library.GetSelectedRow(); + int selected_row = SampleHive::cHiveData::Get().GetListCtrlSelectedRow(); if (selected_row < 0) return; - wxString selected = m_Library.GetTextValue(selected_row, 1); + wxString selected = SampleHive::cHiveData::Get().GetListCtrlTextValue(selected_row, 1); std::string path = m_Database.GetSamplePathByFilename(selected.BeforeLast('.').ToStdString()); - Tags tags(path); + SampleHive::cTags tags(path); int length = tags.GetAudioInfo().length; SH_LOG_DEBUG("Sample length: {}", length); @@ -150,23 +149,21 @@ void cWaveformViewer::RenderPlayhead(wxDC& dc) // Draw the line dc.SetPen(wxPen(m_PlayheadColour, 2, wxPENSTYLE_SOLID)); - dc.DrawLine(line_pos, this->GetSize().GetHeight() - (this->GetSize().GetHeight() - 1), - line_pos, this->GetSize().GetHeight() - 1); + dc.DrawLine(line_pos, this->GetSize().GetHeight() - (this->GetSize().GetHeight() - 1), line_pos, this->GetSize().GetHeight() - 1); } void cWaveformViewer::UpdateWaveformBitmap() { - Serializer serializer; + SampleHive::cSerializer serializer; - int selected_row = m_Library.GetSelectedRow(); + int selected_row = SampleHive::cHiveData::Get().GetListCtrlSelectedRow(); if (selected_row < 0) return; - wxString selection = m_Library.GetTextValue(selected_row, 1); + wxString selection = SampleHive::cHiveData::Get().GetListCtrlTextValue(selected_row, 1); - wxString filepath_with_extension = - m_Database.GetSamplePathByFilename(selection.BeforeLast('.').ToStdString()); + wxString filepath_with_extension = m_Database.GetSamplePathByFilename(selection.BeforeLast('.').ToStdString()); wxString filepath_without_extension = m_Database.GetSamplePathByFilename(selection.ToStdString()); std::string extension = serializer.DeserializeShowFileExtension() ? @@ -218,8 +215,8 @@ void cWaveformViewer::UpdateWaveformBitmap() sum += mono * mono; // Square } - sum /= chunk_size; // Mean - sum = pow(sum, 0.5); // Root + sum /= chunk_size; // Mean + sum = pow(sum, 0.5); // Root // We might bleed a bit on the end and get some near infs, dunno // what is causing astronomically big numbers from sample[] @@ -283,9 +280,12 @@ void cWaveformViewer::OnControlKeyUp(wxKeyEvent &event) if (bSelectRange) { SetCursor(wxCURSOR_ARROW); + bSelectRange = false; bDrawSelectedArea = false; + ReleaseMouse(); + return; } break; @@ -298,15 +298,15 @@ void cWaveformViewer::OnControlKeyUp(wxKeyEvent &event) void cWaveformViewer::OnMouseMotion(wxMouseEvent& event) { - int selected_row = m_Library.GetSelectedRow(); + int selected_row = SampleHive::cHiveData::Get().GetListCtrlSelectedRow(); if (selected_row < 0) return; - wxString selected = m_Library.GetTextValue(selected_row, 1); + wxString selected = SampleHive::cHiveData::Get().GetListCtrlTextValue(selected_row, 1); std::string path = m_Database.GetSamplePathByFilename(selected.BeforeLast('.').ToStdString()); - Tags tags(path); + SampleHive::cTags tags(path); int length = tags.GetAudioInfo().length; @@ -338,15 +338,15 @@ void cWaveformViewer::OnMouseMotion(wxMouseEvent& event) void cWaveformViewer::OnMouseLeftButtonDown(wxMouseEvent& event) { - int selected_row = m_Library.GetSelectedRow(); + int selected_row = SampleHive::cHiveData::Get().GetListCtrlSelectedRow(); if (selected_row < 0) return; - wxString selected = m_Library.GetTextValue(selected_row, 1); + wxString selected = SampleHive::cHiveData::Get().GetListCtrlTextValue(selected_row, 1); std::string path = m_Database.GetSamplePathByFilename(selected.BeforeLast('.').ToStdString()); - Tags tags(path); + SampleHive::cTags tags(path); int length = tags.GetAudioInfo().length; @@ -387,15 +387,15 @@ void cWaveformViewer::OnMouseLeftButtonDown(wxMouseEvent& event) void cWaveformViewer::OnMouseLeftButtonUp(wxMouseEvent& event) { - int selected_row = m_Library.GetSelectedRow(); + int selected_row = SampleHive::cHiveData::Get().GetListCtrlSelectedRow(); if (selected_row < 0) return; - wxString selected = m_Library.GetTextValue(selected_row, 1); + wxString selected = SampleHive::cHiveData::Get().GetListCtrlTextValue(selected_row, 1); std::string path = m_Database.GetSamplePathByFilename(selected.BeforeLast('.').ToStdString()); - Tags tags(path); + SampleHive::cTags tags(path); int length = tags.GetAudioInfo().length; @@ -436,9 +436,8 @@ void cWaveformViewer::OnMouseLeftButtonUp(wxMouseEvent& event) SetCursor(wxCURSOR_ARROW); m_MediaCtrl.Seek(seek_to, wxFromStart); - // SendPushStatusBarStatus(wxString::Format(_("Now playing: %s"), selected), 1); - SampleHive::Signal::SendInfoBarMessage(wxString::Format(_("Now playing: %s"), selected), 1, *this); - m_MediaCtrl.Play(); + SampleHive::cSignal::SendPushStatusBarStatus(wxString::Format(_("Now playing: %s"), selected), 1, *this); + SampleHive::cSignal::SendCallFunctionPlay(selected, false, *this); } } @@ -453,15 +452,15 @@ void cWaveformViewer::ResetDC() std::pair cWaveformViewer::CalculateLoopPoints() { - int selected_row = m_Library.GetSelectedRow(); + int selected_row = SampleHive::cHiveData::Get().GetListCtrlSelectedRow(); if (selected_row < 0) return { 0.0, 0.0 }; - wxString selected = m_Library.GetTextValue(selected_row, 1); + wxString selected = SampleHive::cHiveData::Get().GetListCtrlTextValue(selected_row, 1); std::string path = m_Database.GetSamplePathByFilename(selected.BeforeLast('.').ToStdString()); - Tags tags(path); + SampleHive::cTags tags(path); int length = tags.GetAudioInfo().length; @@ -474,13 +473,3 @@ std::pair cWaveformViewer::CalculateLoopPoints() return { loopA, loopB }; } - -// void cWaveformViewer::SendPushStatusBarStatus(const wxString& msg, int section) -// { -// SampleHive::SH_StatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_PUSH, this->GetId()); -// event.SetEventObject(this); - -// event.SetPushMessageAndSection({ msg, section }); - -// HandleWindowEvent(event); -// } diff --git a/src/GUI/WaveformViewer.hpp b/src/GUI/WaveformViewer.hpp index 0a38a93..2d4556d 100644 --- a/src/GUI/WaveformViewer.hpp +++ b/src/GUI/WaveformViewer.hpp @@ -22,24 +22,20 @@ #include "Database/Database.hpp" -#include #include #include #include #include -#include #include #include #include #include -#include #include class cWaveformViewer : public wxPanel { public: - cWaveformViewer(wxWindow* window, wxDataViewListCtrl& library, - wxMediaCtrl& mediaCtrl, Database& database); + cWaveformViewer(wxWindow* window, wxMediaCtrl& mediaCtrl, cDatabase& database); ~cWaveformViewer(); private: @@ -49,8 +45,7 @@ class cWaveformViewer : public wxPanel wxBoxSizer* m_Sizer; // ------------------------------------------------------------------- - Database& m_Database; - wxDataViewListCtrl& m_Library; + cDatabase& m_Database; wxMediaCtrl& m_MediaCtrl; private: @@ -89,11 +84,6 @@ class cWaveformViewer : public wxPanel // ------------------------------------------------------------------- std::pair CalculateLoopPoints(); - // ------------------------------------------------------------------- - // Send custom events - // void SendLoopPoints(); - // void SendPushStatusBarStatus(const wxString& msg, int section); - public: // ------------------------------------------------------------------- void ResetDC(); diff --git a/src/Utility/ControlIDs.hpp b/src/Utility/ControlIDs.hpp index 14c8244..528ed3a 100644 --- a/src/Utility/ControlIDs.hpp +++ b/src/Utility/ControlIDs.hpp @@ -20,98 +20,102 @@ #include -enum ControlIDs -{ - /* - ** BC = Browser control - ** SD = Settings dialog - ** MN = Popup menu - ** ET = Edit tag dialog - */ +namespace SampleHive { namespace ID { - // ------------------------------------------------------------------- - // Browser controls - BC_Play = wxID_HIGHEST + 1, - BC_Settings, - BC_Loop, - BC_Stop, - BC_LoopABButton, - BC_Mute, - BC_Autoplay, - BC_Volume, - BC_SamplePosition, - BC_Hives, - BC_DirCtrl, - BC_Library, - BC_Search, - BC_MediaCtrl, - BC_Trash, - BC_RestoreTrashedItem, - BC_HiveAdd, - BC_HiveRemove, + enum ControlIDs + { + /* + ** BC = Browser control + ** SD = Settings dialog + ** MN = Popup menu + ** ET = Edit tag dialog + */ - // ------------------------------------------------------------------- - // Setting dialog controls - SD_BrowseConfigDir, - SD_BrowseDatabaseDir, - SD_AutoImport, - SD_FollowSymLinks, - SD_RecursiveImport, - SD_ShowFileExtension, - SD_BrowseAutoImportDir, - SD_FontType, - SD_FontSize, - SD_FontBrowseButton, - SD_WaveformColourPickerCtrl, + // ------------------------------------------------------------------- + // Browser controls + BC_Play = wxID_HIGHEST + 1, + BC_Settings, + BC_Loop, + BC_Stop, + BC_LoopABButton, + BC_Mute, + BC_Autoplay, + BC_Volume, + BC_SamplePosition, + BC_Hives, + BC_DirCtrl, + BC_Library, + BC_Search, + BC_MediaCtrl, + BC_Trash, + BC_RestoreTrashedItem, + BC_HiveAdd, + BC_HiveRemove, - // ------------------------------------------------------------------- - // App Menu items - MN_AddFile, - MN_AddDirectory, - MN_ToggleExtension, - MN_ToggleMenuBar, - MN_ToggleStatusBar, + // ------------------------------------------------------------------- + // Setting dialog controls + SD_BrowseConfigDir, + SD_BrowseDatabaseDir, + SD_AutoImport, + SD_FollowSymLinks, + SD_RecursiveImport, + SD_ShowFileExtension, + SD_BrowseAutoImportDir, + SD_FontType, + SD_FontSize, + SD_FontBrowseButton, + SD_WaveformColourPickerCtrl, - // ------------------------------------------------------------------- - // Library Menu items - MN_FavoriteSample, - MN_DeleteSample, - MN_TrashSample, - MN_EditTagSample, - MN_OpenFile, + // ------------------------------------------------------------------- + // App Menu items + MN_AddFile, + MN_AddDirectory, + MN_ToggleExtension, + MN_ToggleMenuBar, + MN_ToggleStatusBar, - // ------------------------------------------------------------------- - // Library Column Header Menu items - MN_ColumnFavorite, - MN_ColumnFilename, - MN_ColumnSamplePack, - MN_ColumnType, - MN_ColumnChannels, - MN_ColumnLength, - MN_ColumnSampleRate, - MN_ColumnBitrate, - MN_ColumnPath, + // ------------------------------------------------------------------- + // Library Menu items + MN_FavoriteSample, + MN_DeleteSample, + MN_TrashSample, + MN_EditTagSample, + MN_OpenFile, - // ------------------------------------------------------------------- - // Hives Menu items - MN_RenameHive, - MN_DeleteHive, - MN_RemoveSample, - MN_FilterLibrary, - MN_ShowInLibrary, + // ------------------------------------------------------------------- + // Library Column Header Menu items + MN_ColumnFavorite, + MN_ColumnFilename, + MN_ColumnSamplePack, + MN_ColumnType, + MN_ColumnChannels, + MN_ColumnLength, + MN_ColumnSampleRate, + MN_ColumnBitrate, + MN_ColumnPath, - // ------------------------------------------------------------------- - // Trash Menu items - MN_DeleteTrash, - MN_RestoreTrashedItem, + // ------------------------------------------------------------------- + // Hives Menu items + MN_RenameHive, + MN_DeleteHive, + MN_RemoveSample, + MN_FilterLibrary, + MN_ShowInLibrary, - // ------------------------------------------------------------------- - // Edit tags dialog controls - ET_TitleCheck, - ET_ArtistCheck, - ET_AlbumCheck, - ET_GenreCheck, - ET_CommentsCheck, - ET_TypeCheck, - ET_CustomTag, -}; + // ------------------------------------------------------------------- + // Trash Menu items + MN_DeleteTrash, + MN_RestoreTrashedItem, + + // ------------------------------------------------------------------- + // Edit tags dialog controls + ET_TitleCheck, + ET_ArtistCheck, + ET_AlbumCheck, + ET_GenreCheck, + ET_CommentsCheck, + ET_TypeCheck, + ET_CustomTag, + }; + +}} diff --git a/src/Utility/SH_Event.cpp b/src/Utility/Event.cpp similarity index 50% rename from src/Utility/SH_Event.cpp rename to src/Utility/Event.cpp index 3f6ba23..2ce222b 100644 --- a/src/Utility/SH_Event.cpp +++ b/src/Utility/Event.cpp @@ -18,35 +18,24 @@ * along with this program. If not, see . */ -#include "Utility/SH_Event.hpp" +#include "Utility/Event.hpp" namespace SampleHive { - LoopPointsEvent::LoopPointsEvent(wxEventType eventType, int winId) + cLoopPointsEvent::cLoopPointsEvent(wxEventType eventType, int winId) : wxCommandEvent(eventType, winId) { } - LoopPointsEvent::~LoopPointsEvent() + cLoopPointsEvent::~cLoopPointsEvent() { } - wxDEFINE_EVENT(SH_EVT_LOOP_POINTS_UPDATED, LoopPointsEvent); - - // AddSampleEvent::AddSampleEvent(wxEventType eventType, int winId) - // : wxCommandEvent(eventType, winId) - // { - - // } - - // AddSampleEvent::~AddSampleEvent() - // { - - // } - - // wxDEFINE_EVENT(SH_EVT_STATUS_ADD_SAMPLE, AddSampleEvent); + wxDEFINE_EVENT(SH_EVT_LOOP_POINTS_UPDATED, cLoopPointsEvent); + wxDEFINE_EVENT(SH_EVT_LOOP_POINTS_CLEAR, cLoopPointsEvent); + wxDEFINE_EVENT(SH_EVT_LOOP_AB_BUTTON_VALUE_CHANGE, cLoopPointsEvent); // MediaEvent::MediaEvent(wxEventType eventType, int winId) // : wxCommandEvent(eventType, winId) @@ -61,70 +50,70 @@ namespace SampleHive // wxDEFINE_EVENT(SH_EVT_MEDIA_STATUS_UPDATED, MediaEvent); - StatusBarStatusEvent::StatusBarStatusEvent(wxEventType eventType, int winId) + cStatusBarStatusEvent::cStatusBarStatusEvent(wxEventType eventType, int winId) : wxCommandEvent(eventType, winId) { } - StatusBarStatusEvent::~StatusBarStatusEvent() + cStatusBarStatusEvent::~cStatusBarStatusEvent() { } - wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_PUSH, StatusBarStatusEvent); - wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_POP, StatusBarStatusEvent); - wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_SET, StatusBarStatusEvent); + wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_PUSH, cStatusBarStatusEvent); + wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_POP, cStatusBarStatusEvent); + wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_SET, cStatusBarStatusEvent); - InfoBarMessageEvent::InfoBarMessageEvent(wxEventType eventType, int winId) + cInfoBarMessageEvent::cInfoBarMessageEvent(wxEventType eventType, int winId) : wxCommandEvent(eventType, winId) { } - InfoBarMessageEvent::~InfoBarMessageEvent() + cInfoBarMessageEvent::~cInfoBarMessageEvent() { } - wxDEFINE_EVENT(SH_EVT_INFOBAR_MESSAGE_SHOW, InfoBarMessageEvent); + wxDEFINE_EVENT(SH_EVT_INFOBAR_MESSAGE_SHOW, cInfoBarMessageEvent); - TimerEvent::TimerEvent(wxEventType eventType, int winId) + cTimerEvent::cTimerEvent(wxEventType eventType, int winId) : wxCommandEvent(eventType, winId) { } - TimerEvent::~TimerEvent() + cTimerEvent::~cTimerEvent() { } - wxDEFINE_EVENT(SH_EVT_TIMER_STOP, TimerEvent); + wxDEFINE_EVENT(SH_EVT_TIMER_STOP, cTimerEvent); - CallFunctionEvent::CallFunctionEvent(wxEventType eventType, int winId) + cCallFunctionEvent::cCallFunctionEvent(wxEventType eventType, int winId) : wxCommandEvent(eventType, winId) { } - CallFunctionEvent::~CallFunctionEvent() + cCallFunctionEvent::~cCallFunctionEvent() { } - wxDEFINE_EVENT(SH_EVT_CALL_FUNC_PLAY, CallFunctionEvent); + wxDEFINE_EVENT(SH_EVT_CALL_FUNC_PLAY, cCallFunctionEvent); - WaveformUpdateEvent::WaveformUpdateEvent(wxEventType eventType, int winId) + cWaveformUpdateEvent::cWaveformUpdateEvent(wxEventType eventType, int winId) : wxCommandEvent(eventType, winId) { } - WaveformUpdateEvent::~WaveformUpdateEvent() + cWaveformUpdateEvent::~cWaveformUpdateEvent() { } - wxDEFINE_EVENT(SH_EVT_UPDATE_WAVEFORM, WaveformUpdateEvent); + wxDEFINE_EVENT(SH_EVT_UPDATE_WAVEFORM, cWaveformUpdateEvent); } diff --git a/src/Utility/SH_Event.hpp b/src/Utility/Event.hpp similarity index 52% rename from src/Utility/SH_Event.hpp rename to src/Utility/Event.hpp index 207ccf7..c2c1b13 100644 --- a/src/Utility/SH_Event.hpp +++ b/src/Utility/Event.hpp @@ -26,14 +26,14 @@ namespace SampleHive { - class LoopPointsEvent : public wxCommandEvent + class cLoopPointsEvent : public wxCommandEvent { public: - LoopPointsEvent(wxEventType eventType, int winId); - ~LoopPointsEvent(); + cLoopPointsEvent(wxEventType eventType, int winId); + ~cLoopPointsEvent(); public: - virtual wxEvent* Clone() const { return new LoopPointsEvent(*this); } + virtual wxEvent* Clone() const { return new cLoopPointsEvent(*this); } public: std::pair GetLoopPoints() const { return { m_LoopA, m_LoopB }; }; @@ -44,35 +44,18 @@ namespace SampleHive double m_LoopA, m_LoopB; }; - wxDECLARE_EVENT(SH_EVT_LOOP_POINTS_UPDATED, LoopPointsEvent); + wxDECLARE_EVENT(SH_EVT_LOOP_POINTS_UPDATED, cLoopPointsEvent); + wxDECLARE_EVENT(SH_EVT_LOOP_POINTS_CLEAR, cLoopPointsEvent); + wxDECLARE_EVENT(SH_EVT_LOOP_AB_BUTTON_VALUE_CHANGE, cLoopPointsEvent); - // class AddSampleEvent : public wxCommandEvent + // class cMediaEvent : public wxCommandEvent // { // public: - // AddSampleEvent(wxEventType eventType, int winId); - // ~AddSampleEvent(); + // cMediaEvent(wxEventType eventType, int winId); + // ~cMediaEvent(); // public: - // virtual wxEvent* Clone() const { return new AddSampleEvent(*this); } - - // public: - // wxArrayString GetArrayString() const { return m_Files; }; - // void SetArrayString(const wxArrayString& files) { m_Files = files; }; - - // private: - // wxArrayString m_Files; - // }; - - // wxDECLARE_EVENT(SH_EVT_STATUS_ADD_SAMPLE, AddSampleEvent); - - // class MediaEvent : public wxCommandEvent - // { - // public: - // MediaEvent(wxEventType eventType, int winId); - // ~MediaEvent(); - - // public: - // virtual wxEvent* Clone() const { return new MediaEvent(*this); } + // virtual wxEvent* Clone() const { return new cMediaEvent(*this); } // public: // void SetPath(const wxString& path) { m_Path = path; } @@ -82,16 +65,16 @@ namespace SampleHive // wxString m_Path; // }; - // wxDECLARE_EVENT(SH_EVT_MEDIA_STATUS_UPDATED, MediaEvent); + // wxDECLARE_EVENT(SH_EVT_MEDIA_STATUS_UPDATED, cMediaEvent); - class StatusBarStatusEvent : public wxCommandEvent + class cStatusBarStatusEvent : public wxCommandEvent { public: - StatusBarStatusEvent(wxEventType eventType, int winId); - ~StatusBarStatusEvent(); + cStatusBarStatusEvent(wxEventType eventType, int winId); + ~cStatusBarStatusEvent(); public: - virtual wxEvent* Clone() const { return new StatusBarStatusEvent(*this); } + virtual wxEvent* Clone() const { return new cStatusBarStatusEvent(*this); } public: std::pair GetPushMessageAndSection() const { return { m_Msg, m_PushSection }; } @@ -110,18 +93,18 @@ namespace SampleHive int m_PushSection, m_PopSection, m_SetSection; }; - wxDECLARE_EVENT(SH_EVT_STATUSBAR_STATUS_PUSH, StatusBarStatusEvent); - wxDECLARE_EVENT(SH_EVT_STATUSBAR_STATUS_POP, StatusBarStatusEvent); - wxDECLARE_EVENT(SH_EVT_STATUSBAR_STATUS_SET, StatusBarStatusEvent); + wxDECLARE_EVENT(SH_EVT_STATUSBAR_STATUS_PUSH, cStatusBarStatusEvent); + wxDECLARE_EVENT(SH_EVT_STATUSBAR_STATUS_POP, cStatusBarStatusEvent); + wxDECLARE_EVENT(SH_EVT_STATUSBAR_STATUS_SET, cStatusBarStatusEvent); - class InfoBarMessageEvent : public wxCommandEvent + class cInfoBarMessageEvent : public wxCommandEvent { public: - InfoBarMessageEvent(wxEventType eventType, int winId); - ~InfoBarMessageEvent(); + cInfoBarMessageEvent(wxEventType eventType, int winId); + ~cInfoBarMessageEvent(); public: - virtual wxEvent* Clone() const { return new InfoBarMessageEvent(*this); } + virtual wxEvent* Clone() const { return new cInfoBarMessageEvent(*this); } public: std::pair GetInfoBarMessage() const { return { m_Msg, m_Mode }; } @@ -133,49 +116,52 @@ namespace SampleHive int m_Mode; }; - wxDECLARE_EVENT(SH_EVT_INFOBAR_MESSAGE_SHOW, InfoBarMessageEvent); + wxDECLARE_EVENT(SH_EVT_INFOBAR_MESSAGE_SHOW, cInfoBarMessageEvent); - class TimerEvent : public wxCommandEvent + class cTimerEvent : public wxCommandEvent { public: - TimerEvent(wxEventType eventType, int winId); - ~TimerEvent(); + cTimerEvent(wxEventType eventType, int winId); + ~cTimerEvent(); public: - virtual wxEvent* Clone() const { return new TimerEvent(*this); } + virtual wxEvent* Clone() const { return new cTimerEvent(*this); } }; - wxDECLARE_EVENT(SH_EVT_TIMER_STOP, TimerEvent); + wxDECLARE_EVENT(SH_EVT_TIMER_STOP, cTimerEvent); - class CallFunctionEvent : public wxCommandEvent + class cCallFunctionEvent : public wxCommandEvent { public: - CallFunctionEvent(wxEventType eventType, int winId); - ~CallFunctionEvent(); + cCallFunctionEvent(wxEventType eventType, int winId); + ~cCallFunctionEvent(); public: - virtual wxEvent* Clone() const { return new CallFunctionEvent(*this); } + virtual wxEvent* Clone() const { return new cCallFunctionEvent(*this); } public: - wxString GetSlection() { return m_Selection; } + wxString GetSlection() const { return m_Selection; } + bool GetAutoplayValue() const { return m_bCheckAutoplay; } void SetSelection(const wxString& selection) { m_Selection = selection; } + void SetAutoplayValue(bool autoplay) { m_bCheckAutoplay = autoplay; } private: wxString m_Selection; + bool m_bCheckAutoplay; }; - wxDECLARE_EVENT(SH_EVT_CALL_FUNC_PLAY, CallFunctionEvent); + wxDECLARE_EVENT(SH_EVT_CALL_FUNC_PLAY, cCallFunctionEvent); - class WaveformUpdateEvent : public wxCommandEvent + class cWaveformUpdateEvent : public wxCommandEvent { public: - WaveformUpdateEvent(wxEventType eventType, int winId); - ~WaveformUpdateEvent(); + cWaveformUpdateEvent(wxEventType eventType, int winId); + ~cWaveformUpdateEvent(); public: - virtual wxEvent* Clone() const { return new WaveformUpdateEvent(*this); } + virtual wxEvent* Clone() const { return new cWaveformUpdateEvent(*this); } }; - wxDECLARE_EVENT(SH_EVT_UPDATE_WAVEFORM, WaveformUpdateEvent); + wxDECLARE_EVENT(SH_EVT_UPDATE_WAVEFORM, cWaveformUpdateEvent); } diff --git a/src/Utility/HiveData.hpp b/src/Utility/HiveData.hpp new file mode 100644 index 0000000..86adf1d --- /dev/null +++ b/src/Utility/HiveData.hpp @@ -0,0 +1,115 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "wx/dataview.h" +#include "wx/string.h" +#include "wx/treectrl.h" +#include "wx/treebase.h" +#include "wx/variant.h" +#include "wx/vector.h" + +#include + +namespace SampleHive { + + class cHiveData + { + private: + cHiveData() = default; + + public: + cHiveData(const cHiveData&) = delete; + cHiveData& operator=(const cHiveData) = delete; + + public: + static cHiveData& Get() + { + static cHiveData s_HiveData; + return s_HiveData; + } + + public: + // =============================================================== + // HivesPanel functions + void InitHiveData(wxDataViewListCtrl& listCtrl, wxDataViewTreeCtrl& hives, wxDataViewItem favoriteHive, + wxTreeCtrl& trash, wxTreeItemId trashRoot) + { + m_pListCtrl = &listCtrl; + m_FavoriteHive = favoriteHive; + m_pHives = &hives; + m_TrashRoot = trashRoot; + m_pTrash = &trash; + } + + inline wxDataViewTreeCtrl& GetHivesObj() { return *m_pHives; } + inline wxDataViewItem& GetFavoritesHive() { return m_FavoriteHive; } + + wxString GetHiveItemText(bool ofFavHive = false, wxDataViewItem hive = wxDataViewItem(0)) + { + wxString item_text; + + if (ofFavHive) + item_text = m_pHives->GetItemText(m_FavoriteHive); + else + item_text = m_pHives->GetItemText(hive); + + return item_text; + } + + inline wxDataViewItem GetHiveItemSelection() { return m_pHives->GetSelection(); } + inline bool IsHiveItemContainer(wxDataViewItem& hiveItem) { return m_pHives->IsContainer(hiveItem); } + inline int GetHiveChildCount(wxDataViewItem& root) { return m_pHives->GetChildCount(root); } + inline wxDataViewItem GetHiveNthChild(wxDataViewItem& root, int pos) { return m_pHives->GetNthChild(root, pos); } + inline void HiveAppendItem(wxDataViewItem& hiveItem, wxString name) { m_pHives->AppendItem(hiveItem, name); } + inline void HiveDeleteItem(wxDataViewItem& hiveItem) { m_pHives->DeleteItem(hiveItem); } + + // =============================================================== + // TrashPanel functions + inline wxTreeCtrl& GetTrashObj() { return *m_pTrash; } + inline wxTreeItemId& GetTrashRoot() { return m_TrashRoot; } + inline void TrashAppendItem(const wxTreeItemId& parent, const wxString& text) { m_pTrash->AppendItem(parent, text); } + + // =============================================================== + // ListCtrl functions + inline wxDataViewListCtrl& GetListCtrlObj() { return *m_pListCtrl; } + inline int GetListCtrlSelections(wxDataViewItemArray& items) { return m_pListCtrl->GetSelections(items); } + inline int GetListCtrlRowFromItem(wxDataViewItemArray& items, int index) { return m_pListCtrl->ItemToRow(items[index]); } + inline int GetListCtrlSelectedRow() { return m_pListCtrl->GetSelectedRow(); } + inline wxDataViewItem GetListCtrlItemFromRow(int row) { return m_pListCtrl->RowToItem(row); } + inline wxString GetListCtrlTextValue(unsigned int row, unsigned int col) { return m_pListCtrl->GetTextValue(row, col); } + inline int GetListCtrlItemCount() { return m_pListCtrl->GetItemCount(); } + inline void ListCtrlAppendItem(const wxVector& values) { m_pListCtrl->AppendItem(values); } + inline void ListCtrlSetVariant(const wxVariant& variant, unsigned int row, unsigned int col) + { m_pListCtrl->SetValue(variant, row, col); } + inline void ListCtrlUnselectAllItems() { m_pListCtrl->UnselectAll(); } + inline void ListCtrlSelectRow(int row) { m_pListCtrl->SelectRow(row); } + inline void ListCtrlEnsureVisible(const wxDataViewItem& item) { m_pListCtrl->EnsureVisible(item); } + inline void ListCtrlDeleteItem(unsigned int row) { m_pListCtrl->DeleteItem(row); } + inline void ListCtrlDeleteAllItems() { m_pListCtrl->DeleteAllItems(); } + + private: + wxDataViewListCtrl* m_pListCtrl = nullptr; + wxDataViewItem m_FavoriteHive; + wxDataViewTreeCtrl* m_pHives = nullptr; + wxTreeCtrl* m_pTrash = nullptr; + wxTreeItemId m_TrashRoot; + }; + +} diff --git a/src/Utility/Log.cpp b/src/Utility/Log.cpp index 3f7574f..46a335c 100644 --- a/src/Utility/Log.cpp +++ b/src/Utility/Log.cpp @@ -1,3 +1,23 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "Log.hpp" #include @@ -6,16 +26,16 @@ namespace SampleHive { - std::shared_ptr Log::s_Logger; + std::shared_ptr cLog::s_pLogger; - void Log::InitLogger(const std::string& logger) + void cLog::InitLogger(const std::string& logger) { spdlog::set_pattern("%^[%-T] [%-n] [%l]: %v %@%$"); try { - s_Logger = spdlog::stdout_color_mt(logger); - s_Logger->set_level(spdlog::level::trace); + s_pLogger = spdlog::stdout_color_mt(logger); + s_pLogger->set_level(spdlog::level::trace); } catch (const spdlog::spdlog_ex& ex) { diff --git a/src/Utility/Log.hpp b/src/Utility/Log.hpp index 61395d0..31ed10c 100644 --- a/src/Utility/Log.hpp +++ b/src/Utility/Log.hpp @@ -1,3 +1,23 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #include @@ -8,24 +28,24 @@ namespace SampleHive { - class Log + class cLog { public: static void InitLogger(const std::string& logger); public: - inline static std::shared_ptr& GetLogger() { return s_Logger; } + inline static std::shared_ptr& GetLogger() { return s_pLogger; } private: - static std::shared_ptr s_Logger; + static std::shared_ptr s_pLogger; }; -} + // Log macros + #define SH_LOG_TRACE(...) SPDLOG_LOGGER_TRACE(::SampleHive::cLog::GetLogger(), __VA_ARGS__) + #define SH_LOG_INFO(...) SPDLOG_LOGGER_INFO(::SampleHive::cLog::GetLogger(), __VA_ARGS__) + #define SH_LOG_WARN(...) SPDLOG_LOGGER_WARN(::SampleHive::cLog::GetLogger(), __VA_ARGS__) + #define SH_LOG_DEBUG(...) SPDLOG_LOGGER_DEBUG(::SampleHive::cLog::GetLogger(), __VA_ARGS__) + #define SH_LOG_ERROR(...) SPDLOG_LOGGER_ERROR(::SampleHive::cLog::GetLogger(), __VA_ARGS__) + #define SH_LOG_CRITICAL(...) SPDLOG_LOGGER_CRITICAL(::SampleHive::cLog::GetLogger(), __VA_ARGS__) -// Log macros -#define SH_LOG_TRACE(...) SPDLOG_LOGGER_TRACE(::SampleHive::Log::GetLogger(), __VA_ARGS__) -#define SH_LOG_INFO(...) SPDLOG_LOGGER_INFO(::SampleHive::Log::GetLogger(), __VA_ARGS__) -#define SH_LOG_WARN(...) SPDLOG_LOGGER_WARN(::SampleHive::Log::GetLogger(), __VA_ARGS__) -#define SH_LOG_DEBUG(...) SPDLOG_LOGGER_DEBUG(::SampleHive::Log::GetLogger(), __VA_ARGS__) -#define SH_LOG_ERROR(...) SPDLOG_LOGGER_ERROR(::SampleHive::Log::GetLogger(), __VA_ARGS__) -#define SH_LOG_CRITICAL(...) SPDLOG_LOGGER_CRITICAL(::SampleHive::Log::GetLogger(), __VA_ARGS__) +} diff --git a/src/Utility/Paths.hpp b/src/Utility/Paths.hpp index 8bda7e2..2fa12ba 100644 --- a/src/Utility/Paths.hpp +++ b/src/Utility/Paths.hpp @@ -1,31 +1,55 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #include "SampleHiveConfig.hpp" -// Path to all the assets -#define ICON_HIVE_16px SAMPLEHIVE_DATADIR "/icons/icon-hive_16x16.png" -#define ICON_HIVE_24px SAMPLEHIVE_DATADIR "/icons/icon-hive_24x24.png" -#define ICON_HIVE_32px SAMPLEHIVE_DATADIR "/icons/icon-hive_32x32.png" -#define ICON_HIVE_64px SAMPLEHIVE_DATADIR "/icons/icon-hive_64x64.png" -#define ICON_HIVE_128px SAMPLEHIVE_DATADIR "/icons/icon-hive_128x128.png" -#define ICON_HIVE_256px SAMPLEHIVE_DATADIR "/icons/icon-hive_256x256.png" -#define ICON_STAR_FILLED_16px SAMPLEHIVE_DATADIR "/icons/icon-star_filled_16x16.png" -#define ICON_STAR_EMPTY_16px SAMPLEHIVE_DATADIR "/icons/icon-star_empty_16x16.png" -#define ICON_PLAY_DARK_16px SAMPLEHIVE_DATADIR "/icons/icon-play-dark_16x16.png" -#define ICON_STOP_DARK_16px SAMPLEHIVE_DATADIR "/icons/icon-stop-dark_16x16.png" -#define ICON_AB_DARK_16px SAMPLEHIVE_DATADIR "/icons/icon-ab-dark_16x16.png" -#define ICON_LOOP_DARK_16px SAMPLEHIVE_DATADIR "/icons/icon-loop-dark_16x16.png" -#define ICON_MUTE_DARK_16px SAMPLEHIVE_DATADIR "/icons/icon-mute-dark_16x16.png" -#define ICON_PLAY_LIGHT_16px SAMPLEHIVE_DATADIR "/icons/icon-play-light_16x16.png" -#define ICON_STOP_LIGHT_16px SAMPLEHIVE_DATADIR "/icons/icon-stop-light_16x16.png" -#define ICON_AB_LIGHT_16px SAMPLEHIVE_DATADIR "/icons/icon-ab-light_16x16.png" -#define ICON_LOOP_LIGHT_16px SAMPLEHIVE_DATADIR "/icons/icon-loop-light_16x16.png" -#define ICON_MUTE_LIGHT_16px SAMPLEHIVE_DATADIR "/icons/icon-mute-light_16x16.png" -#define SPLASH_LOGO SAMPLEHIVE_DATADIR "/logo/logo-samplehive_768x432.png" +namespace SampleHive { -// Path to useful directories and files -#define USER_HOME_DIR wxGetUserHome() -#define APP_CONFIG_DIR USER_HOME_DIR + "/.config/SampleHive" -#define APP_DATA_DIR USER_HOME_DIR + "/.local/share/SampleHive" -#define CONFIG_FILEPATH APP_CONFIG_DIR + "/config.yaml" -#define DATABASE_FILEPATH APP_DATA_DIR "/sample.hive" + // Path to all the assets + #define ICON_HIVE_16px SAMPLEHIVE_DATADIR "/icons/icon-hive_16x16.png" + #define ICON_HIVE_24px SAMPLEHIVE_DATADIR "/icons/icon-hive_24x24.png" + #define ICON_HIVE_32px SAMPLEHIVE_DATADIR "/icons/icon-hive_32x32.png" + #define ICON_HIVE_64px SAMPLEHIVE_DATADIR "/icons/icon-hive_64x64.png" + #define ICON_HIVE_128px SAMPLEHIVE_DATADIR "/icons/icon-hive_128x128.png" + #define ICON_HIVE_256px SAMPLEHIVE_DATADIR "/icons/icon-hive_256x256.png" + #define ICON_STAR_FILLED_16px SAMPLEHIVE_DATADIR "/icons/icon-star_filled_16x16.png" + #define ICON_STAR_EMPTY_16px SAMPLEHIVE_DATADIR "/icons/icon-star_empty_16x16.png" + #define ICON_PLAY_DARK_16px SAMPLEHIVE_DATADIR "/icons/icon-play-dark_16x16.png" + #define ICON_STOP_DARK_16px SAMPLEHIVE_DATADIR "/icons/icon-stop-dark_16x16.png" + #define ICON_AB_DARK_16px SAMPLEHIVE_DATADIR "/icons/icon-ab-dark_16x16.png" + #define ICON_LOOP_DARK_16px SAMPLEHIVE_DATADIR "/icons/icon-loop-dark_16x16.png" + #define ICON_MUTE_DARK_16px SAMPLEHIVE_DATADIR "/icons/icon-mute-dark_16x16.png" + #define ICON_PLAY_LIGHT_16px SAMPLEHIVE_DATADIR "/icons/icon-play-light_16x16.png" + #define ICON_STOP_LIGHT_16px SAMPLEHIVE_DATADIR "/icons/icon-stop-light_16x16.png" + #define ICON_AB_LIGHT_16px SAMPLEHIVE_DATADIR "/icons/icon-ab-light_16x16.png" + #define ICON_LOOP_LIGHT_16px SAMPLEHIVE_DATADIR "/icons/icon-loop-light_16x16.png" + #define ICON_MUTE_LIGHT_16px SAMPLEHIVE_DATADIR "/icons/icon-mute-light_16x16.png" + #define SPLASH_LOGO SAMPLEHIVE_DATADIR "/logo/logo-samplehive_768x432.png" + + // Path to useful directories and files + #define USER_HOME_DIR wxGetUserHome() + #define APP_CONFIG_DIR USER_HOME_DIR + "/.config/SampleHive" + #define APP_DATA_DIR USER_HOME_DIR + "/.local/share/SampleHive" + #define CONFIG_FILEPATH APP_CONFIG_DIR + "/config.yaml" + #define DATABASE_FILEPATH APP_DATA_DIR "/sample.hive" + +} diff --git a/src/Utility/Serialize.cpp b/src/Utility/Serialize.cpp index 4f83067..f1380e8 100644 --- a/src/Utility/Serialize.cpp +++ b/src/Utility/Serialize.cpp @@ -31,713 +31,717 @@ #include #include -Serializer::Serializer() -{ - std::ifstream ifstrm(static_cast(CONFIG_FILEPATH)); +namespace SampleHive { - wxFont font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT); - std::string system_font_face = font.GetFaceName().ToStdString(); - int system_font_size = font.GetPointSize(); - - wxColour colour = "#FE9647"; - - std::string dir = wxGetHomeDir().ToStdString(); - - // Initialize the logger - // SampleHive::Log::InitLogger("Serializer"); - - if (!ifstrm) + cSerializer::cSerializer() { - SH_LOG_INFO("Genrating configuration file.."); + std::ifstream ifstrm(static_cast(CONFIG_FILEPATH)); - m_Emitter << YAML::Comment("This is the configuration file for SampleHive," - "feel free to edit the file as needed"); - m_Emitter << YAML::Newline; + wxFont font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT); + std::string system_font_face = font.GetFaceName().ToStdString(); + int system_font_size = font.GetPointSize(); - m_Emitter << YAML::BeginMap; + wxColour colour = "#FE9647"; - m_Emitter << YAML::Newline << YAML::Key << "Window"; - m_Emitter << YAML::BeginMap; - m_Emitter << YAML::Key << "Width" << YAML::Value << 1280; - m_Emitter << YAML::Key << "Height" << YAML::Value << 720; - m_Emitter << YAML::Key << "TopSplitterSashPos" << YAML::Value << 200; - m_Emitter << YAML::Key << "BottomSplitterSashPos" << YAML::Value << 300; - m_Emitter << YAML::Key << "ShowMenuBar" << YAML::Value << true; - m_Emitter << YAML::Key << "ShowStatusBar" << YAML::Value << true; - m_Emitter << YAML::EndMap << YAML::Newline; + std::string dir = wxGetHomeDir().ToStdString(); - m_Emitter << YAML::Newline << YAML::Key << "Media"; - m_Emitter << YAML::BeginMap; - m_Emitter << YAML::Key << "Autoplay" << YAML::Value << false; - m_Emitter << YAML::Key << "Loop" << YAML::Value << false; - m_Emitter << YAML::Key << "Muted" << YAML::Value << false; - m_Emitter << YAML::Key << "Volume" << YAML::Value << 100; - m_Emitter << YAML::EndMap << YAML::Newline; + // Initialize the logger + // SampleHive::Log::InitLogger("Serializer"); - m_Emitter << YAML::Newline << YAML::Key << "Display"; - m_Emitter << YAML::BeginMap; - m_Emitter << YAML::Key << "Font"; - m_Emitter << YAML::BeginMap; - m_Emitter << YAML::Key << "Family" << YAML::Value << system_font_face; - m_Emitter << YAML::Key << "Size" << YAML::Value << system_font_size; - m_Emitter << YAML::EndMap; - m_Emitter << YAML::Key << "Waveform"; - m_Emitter << YAML::BeginMap; - m_Emitter << YAML::Key << "Colour" << YAML::Value << colour.GetAsString().ToStdString(); - m_Emitter << YAML::EndMap; - m_Emitter << YAML::EndMap << YAML::Newline; + if (!ifstrm) + { + SH_LOG_INFO("Genrating configuration file.."); - m_Emitter << YAML::Newline << YAML::Key << "Collection"; - m_Emitter << YAML::BeginMap; - m_Emitter << YAML::Key << "AutoImport" << YAML::Value << false; - m_Emitter << YAML::Key << "Directory" << YAML::Value << dir; - m_Emitter << YAML::Key << "FollowSymLink" << YAML::Value << false; - m_Emitter << YAML::Key << "RecursiveImport" << YAML::Value << false; - m_Emitter << YAML::Key << "ShowFileExtension" << YAML::Value << true; - m_Emitter << YAML::EndMap << YAML::Newline; + m_Emitter << YAML::Comment("This is the configuration file for SampleHive," + "feel free to edit the file as needed"); + m_Emitter << YAML::Newline; - m_Emitter << YAML::EndMap; + m_Emitter << YAML::BeginMap; - std::ofstream ofstrm(CONFIG_FILEPATH); - ofstrm << m_Emitter.c_str(); + m_Emitter << YAML::Newline << YAML::Key << "Window"; + m_Emitter << YAML::BeginMap; + m_Emitter << YAML::Key << "Width" << YAML::Value << 1280; + m_Emitter << YAML::Key << "Height" << YAML::Value << 720; + m_Emitter << YAML::Key << "TopSplitterSashPos" << YAML::Value << 200; + m_Emitter << YAML::Key << "BottomSplitterSashPos" << YAML::Value << 300; + m_Emitter << YAML::Key << "ShowMenuBar" << YAML::Value << true; + m_Emitter << YAML::Key << "ShowStatusBar" << YAML::Value << true; + m_Emitter << YAML::EndMap << YAML::Newline; - SH_LOG_INFO("Generated {} successfully!", CONFIG_FILEPATH); + m_Emitter << YAML::Newline << YAML::Key << "Media"; + m_Emitter << YAML::BeginMap; + m_Emitter << YAML::Key << "Autoplay" << YAML::Value << false; + m_Emitter << YAML::Key << "Loop" << YAML::Value << false; + m_Emitter << YAML::Key << "Muted" << YAML::Value << false; + m_Emitter << YAML::Key << "Volume" << YAML::Value << 100; + m_Emitter << YAML::EndMap << YAML::Newline; + + m_Emitter << YAML::Newline << YAML::Key << "Display"; + m_Emitter << YAML::BeginMap; + m_Emitter << YAML::Key << "Font"; + m_Emitter << YAML::BeginMap; + m_Emitter << YAML::Key << "Family" << YAML::Value << system_font_face; + m_Emitter << YAML::Key << "Size" << YAML::Value << system_font_size; + m_Emitter << YAML::EndMap; + m_Emitter << YAML::Key << "Waveform"; + m_Emitter << YAML::BeginMap; + m_Emitter << YAML::Key << "Colour" << YAML::Value << colour.GetAsString().ToStdString(); + m_Emitter << YAML::EndMap; + m_Emitter << YAML::EndMap << YAML::Newline; + + m_Emitter << YAML::Newline << YAML::Key << "Collection"; + m_Emitter << YAML::BeginMap; + m_Emitter << YAML::Key << "AutoImport" << YAML::Value << false; + m_Emitter << YAML::Key << "Directory" << YAML::Value << dir; + m_Emitter << YAML::Key << "FollowSymLink" << YAML::Value << false; + m_Emitter << YAML::Key << "RecursiveImport" << YAML::Value << false; + m_Emitter << YAML::Key << "ShowFileExtension" << YAML::Value << true; + m_Emitter << YAML::EndMap << YAML::Newline; + + m_Emitter << YAML::EndMap; + + std::ofstream ofstrm(CONFIG_FILEPATH); + ofstrm << m_Emitter.c_str(); + + SH_LOG_INFO("Generated {} successfully!", CONFIG_FILEPATH); + } } -} -Serializer::~Serializer() -{ + cSerializer::~cSerializer() + { + + } + + void cSerializer::SerializeWinSize(int w, int h) + { + YAML::Emitter out; + + try + { + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); + + if (auto win = config["Window"]) + { + win["Width"] = w; + win["Height"] = h; + + out << config; + + std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); + ofstrm << out.c_str(); + } + else + { + SH_LOG_ERROR("Error! Cannot store window size values."); + } + } + catch (const YAML::ParserException& ex) + { + SH_LOG_ERROR(ex.what()); + } + } + + WindowSize cSerializer::DeserializeWinSize() const + { + int width = 800, height = 600; + + try + { + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); + + if (!config["Window"]) + { + return { width, height }; + } + + if (auto win = config["Window"]) + { + height = win["Height"].as(); + width = win["Width"].as(); + } + } + catch (const YAML::ParserException& ex) + { + SH_LOG_ERROR(ex.what()); + } + + SH_LOG_INFO("Window size: {}, {}", width, height); + + return { width, height }; + } + + void cSerializer::SerializeShowMenuAndStatusBar(std::string key, bool value) + { + YAML::Emitter out; + + try + { + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); + + if (auto bar = config["Window"]) + { + if (key == "menubar") + bar["ShowMenuBar"] = value; + + if (key == "statusbar") + bar["ShowStatusBar"] = value; + + out << config; + + std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); + ofstrm << out.c_str(); + } + else + SH_LOG_ERROR("Error! Cannot store show bar values."); + } + catch (const YAML::ParserException& ex) + { + SH_LOG_ERROR(ex.what()); + } + } + + bool cSerializer::DeserializeShowMenuAndStatusBar(std::string key) const + { + bool show = false; + + try + { + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); + + if (auto bar = config["Window"]) + { + if (key == "menubar") + show = bar["ShowMenuBar"].as(); + + if (key == "statusbar") + show = bar["ShowStatusBar"].as(); + } + else + { + SH_LOG_ERROR("Error! Cannot fetch show bar values."); + } + } + catch (const YAML::ParserException& ex) + { + SH_LOG_ERROR(ex.what()); + } + + return show; + } + + void cSerializer::SerializeSplitterSashPos(std::string key, int pos) + { + YAML::Emitter out; + + try + { + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); + + if (auto sash = config["Window"]) + { + if (key == "top") + sash["TopSplitterSashPos"] = pos; + + if (key == "bottom") + sash["BottomSplitterSashPos"] = pos; + + out << config; + + std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); + ofstrm << out.c_str(); + } + else + SH_LOG_ERROR("Error! Cannot store sash pos values."); + } + catch (const YAML::ParserException& ex) + { + SH_LOG_ERROR(ex.what()); + } + } + + int cSerializer::DeserializeSplitterSashPos(std::string key) const + { + int pos = 0; + + try + { + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); + + if (auto bar = config["Window"]) + { + if (key == "top") + pos = bar["TopSplitterSashPos"].as(); + + if (key == "bottom") + pos = bar["BottomSplitterSashPos"].as(); + } + else + { + SH_LOG_ERROR("Error! Cannot fetch sash pos values."); + } + } + catch (const YAML::ParserException& ex) + { + SH_LOG_ERROR(ex.what()); + } + + return pos; + } + + void cSerializer::SerializeMediaOptions(std::string key, bool value) + { + YAML::Emitter out; + + try + { + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); + + if (auto media = config["Media"]) + { + if (key == "autoplay") + media["Autoplay"] = value; + + if (key == "loop") + media["Loop"] = value; + + if (key == "muted") + media["Muted"] = value; + + out << config; + + std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); + ofstrm << out.c_str(); + } + else + SH_LOG_ERROR("Error! Cannot store media values."); + } + catch (const YAML::ParserException& ex) + { + SH_LOG_ERROR(ex.what()); + } + } + + bool cSerializer::DeserializeMediaOptions(std::string key) const + { + bool control = false; + + try + { + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); + + if (auto media = config["Media"]) + { + if (key == "autoplay") + control = media["Autoplay"].as(); + + if (key == "loop") + control = media["Loop"].as(); + + if (key == "muted") + control = media["Muted"].as(); + } + else + SH_LOG_ERROR("Error! Cannot fetch media values."); + } + catch (const YAML::ParserException& ex) + { + SH_LOG_ERROR(ex.what()); + } + + SH_LOG_INFO("{}: {}", key, control ? "enabled" : "disabled"); + + return control; + } + + void cSerializer::SerializeMediaVolume(int volume) + { + YAML::Emitter out; + + try + { + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); + + if (auto media = config["Media"]) + { + media["Volume"] = volume; + + out << config; + + std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); + ofstrm << out.c_str(); + } + else + SH_LOG_ERROR("Error! Cannot store volume values."); + } + catch (const YAML::ParserException& ex) + { + SH_LOG_ERROR(ex.what()); + } + } + + int cSerializer::DeserializeMediaVolume() const + { + int volume = 0; + + try + { + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); + + if (auto media = config["Media"]) + volume = media["Volume"].as(); + else + SH_LOG_ERROR("Error! Cannot fetch volume values."); + } + catch (const YAML::ParserException& ex) + { + SH_LOG_ERROR(ex.what()); + } + + SH_LOG_INFO("Volume: {}", volume); + + return volume; + } + + void cSerializer::SerializeFontSettings(wxFont& font) + { + YAML::Emitter out; + + std::string font_face = font.GetFaceName().ToStdString(); + int font_size = font.GetPointSize(); + + try + { + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); + + auto display = config["Display"]; + + if (auto fontSetting = display["Font"]) + { + fontSetting["Family"] = font_face; + fontSetting["Size"] = font_size; + + out << config; + + std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); + ofstrm << out.c_str(); + } + else + { + SH_LOG_ERROR("Error! Cannot store font values."); + } + } + catch (const YAML::ParserException& ex) + { + SH_LOG_ERROR(ex.what()); + } + } + + wxFont cSerializer::DeserializeFontSettings() const + { + wxFont font; + + wxString face; + int size = 0 ; + + try + { + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); + + auto display = config["Display"]; + + if (auto font_setting = display["Font"]) + { + face = font_setting["Family"].as(); + size = font_setting["Size"].as(); + + font.SetFaceName(face); + font.SetPointSize(size); + } + else + { + SH_LOG_ERROR("Error! Cannot fetch font values."); + } + } + catch (const YAML::ParserException& ex) + { + SH_LOG_ERROR(ex.what()); + } + + return font; + } + + void cSerializer::SerializeWaveformColour(wxColour& colour) + { + YAML::Emitter out; + + std::string colour_string = colour.GetAsString(wxC2S_HTML_SYNTAX).ToStdString(); + + try + { + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); + + auto display = config["Display"]; + + if (auto waveform = display["Waveform"]) + { + waveform["Colour"] = colour_string; + + out << config; + + std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); + ofstrm << out.c_str(); + } + else + { + SH_LOG_ERROR("Error! Cannot store waveform colour."); + } + } + catch (const YAML::ParserException& ex) + { + SH_LOG_ERROR(ex.what()); + } + } + + wxColour cSerializer::DeserializeWaveformColour() const + { + std::string colour; + + try + { + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); + + auto display = config["Display"]; + + if (auto waveform = display["Waveform"]) + { + colour = waveform["Colour"].as(); + } + else + { + SH_LOG_ERROR("Error! Cannot fetch waveform colour."); + } + } + catch (const YAML::ParserException& ex) + { + SH_LOG_ERROR(ex.what()); + } + + return static_cast(colour); + } + + void cSerializer::SerializeAutoImport(bool autoImport, const std::string& importDir) + { + YAML::Emitter out; + + try + { + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); + + if (auto autoImportInfo = config["Collection"]) + { + autoImportInfo["AutoImport"] = autoImport; + autoImportInfo["Directory"] = importDir; + + out << config; + + std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); + ofstrm << out.c_str(); + } + else + { + SH_LOG_ERROR("Error! Cannot store import dir values."); + } + } + catch (const YAML::ParserException& ex) + { + SH_LOG_ERROR(ex.what()); + } + } + + ImportDirInfo cSerializer::DeserializeAutoImport() const + { + wxString dir; + bool auto_import = false; + + try + { + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); + + if (auto autoImportInfo = config["Collection"]) + { + auto_import = autoImportInfo["AutoImport"].as(); + dir = autoImportInfo["Directory"].as(); + } + else + { + SH_LOG_ERROR("Error! Cannot fetch import dir values."); + } + } + catch (const YAML::ParserException& ex) + { + SH_LOG_ERROR(ex.what()); + } + + return { auto_import, dir }; + } + + void cSerializer::SerializeFollowSymLink(bool followSymLinks) + { + YAML::Emitter out; + + try + { + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); + + if (auto followSymLinks = config["Collection"]) + { + followSymLinks["FollowSymLink"] = followSymLinks; + + out << config; + + std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); + ofstrm << out.c_str(); + } + else + { + SH_LOG_ERROR("Error! Cannot store follow symbolic links value."); + } + } + catch (const YAML::ParserException& ex) + { + SH_LOG_ERROR(ex.what()); + } + } + + bool cSerializer::DeserializeFollowSymLink() const + { + bool follow_sym_links = false; + + try + { + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); + + if (auto followSymLinks = config["Collection"]) + { + follow_sym_links = followSymLinks["FollowSymLink"].as(); + } + else + { + SH_LOG_ERROR("Error! Cannot fetch follow symbolic links value."); + } + } + catch (const YAML::ParserException& ex) + { + SH_LOG_ERROR(ex.what()); + } + + return follow_sym_links; + } + + void cSerializer::SerializeRecursiveImport(bool recursiveImport) + { + YAML::Emitter out; + + try + { + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); + + if (auto recursive = config["Collection"]) + { + recursive["RecursiveImport"] = recursiveImport; + + out << config; + + std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); + ofstrm << out.c_str(); + } + else + { + SH_LOG_ERROR("Error! Cannot store recursive import value."); + } + } + catch (const YAML::ParserException& ex) + { + SH_LOG_ERROR(ex.what()); + } + } + + bool cSerializer::DeserializeRecursiveImport() const + { + bool recursive_import = false; + + try + { + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); + + if (auto recursive = config["Collection"]) + { + recursive_import = recursive["RecursiveImport"].as(); + } + else + { + SH_LOG_ERROR("Error! Cannot fetch recursive import value."); + } + } + catch (const YAML::ParserException& ex) + { + SH_LOG_ERROR(ex.what()); + } + + return recursive_import; + } + + void cSerializer::SerializeShowFileExtension(bool showExtension) + { + YAML::Emitter out; + + try + { + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); + + if (auto fileExtensionInfo = config["Collection"]) + { + fileExtensionInfo["ShowFileExtension"] = showExtension; + + out << config; + + std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); + ofstrm << out.c_str(); + } + else + { + SH_LOG_ERROR("Error! Cannot store show file extension value."); + } + } + catch (const YAML::ParserException& ex) + { + SH_LOG_ERROR(ex.what()); + } + } + + bool cSerializer::DeserializeShowFileExtension() const + { + bool show_extension = false; + + try + { + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); + + if (auto fileExtensionInfo = config["Collection"]) + { + show_extension = fileExtensionInfo["ShowFileExtension"].as(); + } + else + { + SH_LOG_ERROR("Error! Cannot fetch show file extension value."); + } + } + catch (const YAML::ParserException& ex) + { + SH_LOG_ERROR(ex.what()); + } + + return show_extension; + } } - -void Serializer::SerializeWinSize(int w, int h) -{ - YAML::Emitter out; - - try - { - YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); - - if (auto win = config["Window"]) - { - win["Width"] = w; - win["Height"] = h; - - out << config; - - std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); - ofstrm << out.c_str(); - } - else - { - SH_LOG_ERROR("Error! Cannot store window size values."); - } - } - catch(const YAML::ParserException& ex) - { - SH_LOG_ERROR(ex.what()); - } -} - -WindowSize Serializer::DeserializeWinSize() const -{ - int width = 800, height = 600; - - try - { - YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); - - if (!config["Window"]) - { - return { width, height }; - } - - if (auto win = config["Window"]) - { - height = win["Height"].as(); - width = win["Width"].as(); - } - } - catch(const YAML::ParserException& ex) - { - SH_LOG_ERROR(ex.what()); - } - - SH_LOG_INFO("Window size: {}, {}", width, height); - - return { width, height }; -} - -void Serializer::SerializeShowMenuAndStatusBar(std::string key, bool value) -{ - YAML::Emitter out; - - try - { - YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); - - if (auto bar = config["Window"]) - { - if (key == "menubar") - bar["ShowMenuBar"] = value; - - if (key == "statusbar") - bar["ShowStatusBar"] = value; - - out << config; - - std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); - ofstrm << out.c_str(); - } - else - SH_LOG_ERROR("Error! Cannot store show bar values."); - } - catch(const YAML::ParserException& ex) - { - SH_LOG_ERROR(ex.what()); - } -} - -bool Serializer::DeserializeShowMenuAndStatusBar(std::string key) const -{ - bool show = false; - - try - { - YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); - - if (auto bar = config["Window"]) - { - if (key == "menubar") - show = bar["ShowMenuBar"].as(); - - if (key == "statusbar") - show = bar["ShowStatusBar"].as(); - } - else - { - SH_LOG_ERROR("Error! Cannot fetch show bar values."); - } - } - catch(const YAML::ParserException& ex) - { - SH_LOG_ERROR(ex.what()); - } - - return show; -} - -void Serializer::SerializeSplitterSashPos(std::string key, int pos) -{ - YAML::Emitter out; - - try - { - YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); - - if (auto sash = config["Window"]) - { - if (key == "top") - sash["TopSplitterSashPos"] = pos; - - if (key == "bottom") - sash["BottomSplitterSashPos"] = pos; - - out << config; - - std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); - ofstrm << out.c_str(); - } - else - SH_LOG_ERROR("Error! Cannot store sash pos values."); - } - catch(const YAML::ParserException& ex) - { - SH_LOG_ERROR(ex.what()); - } -} - -int Serializer::DeserializeSplitterSashPos(std::string key) const -{ - int pos = 0; - - try - { - YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); - - if (auto bar = config["Window"]) - { - if (key == "top") - pos = bar["TopSplitterSashPos"].as(); - - if (key == "bottom") - pos = bar["BottomSplitterSashPos"].as(); - } - else - { - SH_LOG_ERROR("Error! Cannot fetch sash pos values."); - } - } - catch(const YAML::ParserException& ex) - { - SH_LOG_ERROR(ex.what()); - } - - return pos; -} - -void Serializer::SerializeMediaOptions(std::string key, bool value) -{ - YAML::Emitter out; - - try - { - YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); - - if (auto media = config["Media"]) - { - if (key == "autoplay") - media["Autoplay"] = value; - - if (key == "loop") - media["Loop"] = value; - - if (key == "muted") - media["Muted"] = value; - - out << config; - - std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); - ofstrm << out.c_str(); - } - else - SH_LOG_ERROR("Error! Cannot store media values."); - } - catch(const YAML::ParserException& ex) - { - SH_LOG_ERROR(ex.what()); - } -} - -bool Serializer::DeserializeMediaOptions(std::string key) const -{ - bool control = false; - - try - { - YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); - - if (auto media = config["Media"]) - { - if (key == "autoplay") - control = media["Autoplay"].as(); - - if (key == "loop") - control = media["Loop"].as(); - - if (key == "muted") - control = media["Muted"].as(); - } - else - SH_LOG_ERROR("Error! Cannot fetch media values."); - } - catch(const YAML::ParserException& ex) - { - SH_LOG_ERROR(ex.what()); - } - - SH_LOG_INFO("{}: {}", key, control ? "enabled" : "disabled"); - - return control; -} - -void Serializer::SerializeMediaVolume(int volume) -{ - YAML::Emitter out; - - try - { - YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); - - if (auto media = config["Media"]) - { - media["Volume"] = volume; - - out << config; - - std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); - ofstrm << out.c_str(); - } - else - SH_LOG_ERROR("Error! Cannot store volume values."); - } - catch(const YAML::ParserException& ex) - { - SH_LOG_ERROR(ex.what()); - } -} - -int Serializer::DeserializeMediaVolume() const -{ - int volume = 0; - - try - { - YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); - - if (auto media = config["Media"]) - volume = media["Volume"].as(); - else - SH_LOG_ERROR("Error! Cannot fetch volume values."); - } - catch(const YAML::ParserException& ex) - { - SH_LOG_ERROR(ex.what()); - } - - SH_LOG_INFO("Volume: {}", volume); - - return volume; -} - -void Serializer::SerializeFontSettings(wxFont& font) -{ - YAML::Emitter out; - - std::string font_face = font.GetFaceName().ToStdString(); - int font_size = font.GetPointSize(); - - try - { - YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); - - auto display = config["Display"]; - - if (auto fontSetting = display["Font"]) - { - fontSetting["Family"] = font_face; - fontSetting["Size"] = font_size; - - out << config; - - std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); - ofstrm << out.c_str(); - } - else - { - SH_LOG_ERROR("Error! Cannot store font values."); - } - } - catch(const YAML::ParserException& ex) - { - SH_LOG_ERROR(ex.what()); - } -} - -wxFont Serializer::DeserializeFontSettings() const -{ - wxFont font; - - wxString face; - int size = 0 ; - - try - { - YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); - - auto display = config["Display"]; - - if (auto font_setting = display["Font"]) - { - face = font_setting["Family"].as(); - size = font_setting["Size"].as(); - - font.SetFaceName(face); - font.SetPointSize(size); - } - else - { - SH_LOG_ERROR("Error! Cannot fetch font values."); - } - } - catch(const YAML::ParserException& ex) - { - SH_LOG_ERROR(ex.what()); - } - - return font; -} - -void Serializer::SerializeWaveformColour(wxColour& colour) -{ - YAML::Emitter out; - - std::string colour_string = colour.GetAsString(wxC2S_HTML_SYNTAX).ToStdString(); - - try - { - YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); - - auto display = config["Display"]; - - if (auto waveform = display["Waveform"]) - { - waveform["Colour"] = colour_string; - - out << config; - - std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); - ofstrm << out.c_str(); - } - else - { - SH_LOG_ERROR("Error! Cannot store waveform colour."); - } - } - catch(const YAML::ParserException& ex) - { - SH_LOG_ERROR(ex.what()); - } -} - -wxColour Serializer::DeserializeWaveformColour() const -{ - std::string colour; - - try - { - YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); - - auto display = config["Display"]; - - if (auto waveform = display["Waveform"]) - { - colour = waveform["Colour"].as(); - } - else - { - SH_LOG_ERROR("Error! Cannot fetch waveform colour."); - } - } - catch(const YAML::ParserException& ex) - { - SH_LOG_ERROR(ex.what()); - } - - return static_cast(colour); -} - -void Serializer::SerializeAutoImport(bool autoImport, const std::string& importDir) -{ - YAML::Emitter out; - - try - { - YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); - - if (auto autoImportInfo = config["Collection"]) - { - autoImportInfo["AutoImport"] = autoImport; - autoImportInfo["Directory"] = importDir; - - out << config; - - std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); - ofstrm << out.c_str(); - } - else - { - SH_LOG_ERROR("Error! Cannot store import dir values."); - } - } - catch(const YAML::ParserException& ex) - { - SH_LOG_ERROR(ex.what()); - } -} - -ImportDirInfo Serializer::DeserializeAutoImport() const -{ - wxString dir; - bool auto_import = false; - - try - { - YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); - - if (auto autoImportInfo = config["Collection"]) - { - auto_import = autoImportInfo["AutoImport"].as(); - dir = autoImportInfo["Directory"].as(); - } - else - { - SH_LOG_ERROR("Error! Cannot fetch import dir values."); - } - } - catch(const YAML::ParserException& ex) - { - SH_LOG_ERROR(ex.what()); - } - - return { auto_import, dir }; -} - -void Serializer::SerializeFollowSymLink(bool followSymLinks) -{ - YAML::Emitter out; - - try - { - YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); - - if (auto followSymLinks = config["Collection"]) - { - followSymLinks["FollowSymLink"] = followSymLinks; - - out << config; - - std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); - ofstrm << out.c_str(); - } - else - { - SH_LOG_ERROR("Error! Cannot store follow symbolic links value."); - } - } - catch(const YAML::ParserException& ex) - { - SH_LOG_ERROR(ex.what()); - } -} - -bool Serializer::DeserializeFollowSymLink() const -{ - bool follow_sym_links = false; - - try - { - YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); - - if (auto followSymLinks = config["Collection"]) - { - follow_sym_links = followSymLinks["FollowSymLink"].as(); - } - else - { - SH_LOG_ERROR("Error! Cannot fetch follow symbolic links value."); - } - } - catch(const YAML::ParserException& ex) - { - SH_LOG_ERROR(ex.what()); - } - - return follow_sym_links; -} - -void Serializer::SerializeRecursiveImport(bool recursiveImport) -{ - YAML::Emitter out; - - try - { - YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); - - if (auto recursive = config["Collection"]) - { - recursive["RecursiveImport"] = recursiveImport; - - out << config; - - std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); - ofstrm << out.c_str(); - } - else - { - SH_LOG_ERROR("Error! Cannot store recursive import value."); - } - } - catch(const YAML::ParserException& ex) - { - SH_LOG_ERROR(ex.what()); - } -} - -bool Serializer::DeserializeRecursiveImport() const -{ - bool recursive_import = false; - - try - { - YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); - - if (auto recursive = config["Collection"]) - { - recursive_import = recursive["RecursiveImport"].as(); - } - else - { - SH_LOG_ERROR("Error! Cannot fetch recursive import value."); - } - } - catch(const YAML::ParserException& ex) - { - SH_LOG_ERROR(ex.what()); - } - - return recursive_import; -} - -void Serializer::SerializeShowFileExtension(bool showExtension) -{ - YAML::Emitter out; - - try - { - YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); - - if (auto fileExtensionInfo = config["Collection"]) - { - fileExtensionInfo["ShowFileExtension"] = showExtension; - - out << config; - - std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); - ofstrm << out.c_str(); - } - else - { - SH_LOG_ERROR("Error! Cannot store show file extension value."); - } - } - catch(const YAML::ParserException& ex) - { - SH_LOG_ERROR(ex.what()); - } -} - -bool Serializer::DeserializeShowFileExtension() const -{ - bool show_extension = false; - - try - { - YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); - - if (auto fileExtensionInfo = config["Collection"]) - { - show_extension = fileExtensionInfo["ShowFileExtension"].as(); - } - else - { - SH_LOG_ERROR("Error! Cannot fetch show file extension value."); - } - } - catch(const YAML::ParserException& ex) - { - SH_LOG_ERROR(ex.what()); - } - - return show_extension; -} diff --git a/src/Utility/Serialize.hpp b/src/Utility/Serialize.hpp index 84f5714..32f08d0 100644 --- a/src/Utility/Serialize.hpp +++ b/src/Utility/Serialize.hpp @@ -42,67 +42,71 @@ typedef std::pair WindowSize; // typedef std::pair FontType; typedef std::pair ImportDirInfo; -class Serializer -{ - public: - Serializer(); - ~Serializer(); +namespace SampleHive { - private: - // ------------------------------------------------------------------- - YAML::Emitter m_Emitter; + class cSerializer + { + public: + cSerializer(); + ~cSerializer(); - public: - // ------------------------------------------------------------------- - // Window size - void SerializeWinSize(int w, int h); - WindowSize DeserializeWinSize() const; + public: + // ------------------------------------------------------------------- + // Window size + void SerializeWinSize(int w, int h); + WindowSize DeserializeWinSize() const; - // ------------------------------------------------------------------- - // Menu and status bar - void SerializeShowMenuAndStatusBar(std::string key, bool value); - bool DeserializeShowMenuAndStatusBar(std::string key) const; + // ------------------------------------------------------------------- + // Menu and status bar + void SerializeShowMenuAndStatusBar(std::string key, bool value); + bool DeserializeShowMenuAndStatusBar(std::string key) const; - // ------------------------------------------------------------------- - // Splitter window sash pos - void SerializeSplitterSashPos(std::string key, int pos); - int DeserializeSplitterSashPos(std::string key) const; + // ------------------------------------------------------------------- + // Splitter window sash pos + void SerializeSplitterSashPos(std::string key, int pos); + int DeserializeSplitterSashPos(std::string key) const; - // ------------------------------------------------------------------- - // Browser controls - void SerializeMediaOptions(std::string key, bool value); - bool DeserializeMediaOptions(std::string key) const; + // ------------------------------------------------------------------- + // Browser controls + void SerializeMediaOptions(std::string key, bool value); + bool DeserializeMediaOptions(std::string key) const; - void SerializeMediaVolume(int volume); - int DeserializeMediaVolume() const; + void SerializeMediaVolume(int volume); + int DeserializeMediaVolume() const; - // ------------------------------------------------------------------- - // Display settings - void SerializeFontSettings(wxFont& font); - wxFont DeserializeFontSettings() const; + // ------------------------------------------------------------------- + // Display settings + void SerializeFontSettings(wxFont& font); + wxFont DeserializeFontSettings() const; - // ------------------------------------------------------------------- - // Waveform colour - void SerializeWaveformColour(wxColour& colour); - wxColour DeserializeWaveformColour() const; + // ------------------------------------------------------------------- + // Waveform colour + void SerializeWaveformColour(wxColour& colour); + wxColour DeserializeWaveformColour() const; - // ------------------------------------------------------------------- - // Auto import settings - void SerializeAutoImport(bool autoImport, const std::string& importDir); - ImportDirInfo DeserializeAutoImport() const; + // ------------------------------------------------------------------- + // Auto import settings + void SerializeAutoImport(bool autoImport, const std::string& importDir); + ImportDirInfo DeserializeAutoImport() const; - // ------------------------------------------------------------------- - // Follow symbolic links - void SerializeFollowSymLink(bool followSymLink); - bool DeserializeFollowSymLink() const; + // ------------------------------------------------------------------- + // Follow symbolic links + void SerializeFollowSymLink(bool followSymLink); + bool DeserializeFollowSymLink() const; - // ------------------------------------------------------------------- - // Recursive import - void SerializeRecursiveImport(bool recursiveImport); - bool DeserializeRecursiveImport() const; + // ------------------------------------------------------------------- + // Recursive import + void SerializeRecursiveImport(bool recursiveImport); + bool DeserializeRecursiveImport() const; - // ------------------------------------------------------------------- - // Show file extension - void SerializeShowFileExtension(bool showExtension); - bool DeserializeShowFileExtension() const; -}; + // ------------------------------------------------------------------- + // Show file extension + void SerializeShowFileExtension(bool showExtension); + bool DeserializeShowFileExtension() const; + + private: + // ------------------------------------------------------------------- + YAML::Emitter m_Emitter; + }; + +} diff --git a/src/Utility/Signal.cpp b/src/Utility/Signal.cpp index d0cdefa..614d282 100644 --- a/src/Utility/Signal.cpp +++ b/src/Utility/Signal.cpp @@ -1,12 +1,32 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "Utility/Signal.hpp" #include "Utility/Log.hpp" -#include "Utility/SH_Event.hpp" +#include "Utility/Event.hpp" namespace SampleHive { - void Signal::SendInfoBarMessage(const wxString& msg, int mode, wxWindow& window, bool isDialog) + void cSignal::SendInfoBarMessage(const wxString& msg, int mode, wxWindow& window, bool isDialog) { - SampleHive::InfoBarMessageEvent event(SampleHive::SH_EVT_INFOBAR_MESSAGE_SHOW, window.GetId()); + SampleHive::cInfoBarMessageEvent event(SampleHive::SH_EVT_INFOBAR_MESSAGE_SHOW, window.GetId()); event.SetEventObject(&window); event.SetInfoBarMessage({ msg, mode }); @@ -17,9 +37,9 @@ namespace SampleHive { window.HandleWindowEvent(event); } - void Signal::SendPushStatusBarStatus(const wxString& msg, int section, wxWindow& window, bool isDialog) + void cSignal::SendPushStatusBarStatus(const wxString& msg, int section, wxWindow& window, bool isDialog) { - SampleHive::StatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_PUSH, window.GetId()); + SampleHive::cStatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_PUSH, window.GetId()); event.SetEventObject(&window); event.SetPushMessageAndSection({ msg, section }); @@ -30,9 +50,9 @@ namespace SampleHive { window.HandleWindowEvent(event); } - void Signal::SendPopStatusBarStatus(int section, wxWindow& window, bool isDialog) + void cSignal::SendPopStatusBarStatus(int section, wxWindow& window, bool isDialog) { - SampleHive::StatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_POP, window.GetId()); + SampleHive::cStatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_POP, window.GetId()); event.SetEventObject(&window); event.SetPopMessageSection(section); @@ -43,9 +63,9 @@ namespace SampleHive { window.HandleWindowEvent(event); } - void Signal::SendSetStatusBarStatus(const wxString& text, int section, wxWindow& window, bool isDialog) + void cSignal::SendSetStatusBarStatus(const wxString& text, int section, wxWindow& window, bool isDialog) { - SampleHive::StatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_SET, window.GetId()); + SampleHive::cStatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_SET, window.GetId()); event.SetEventObject(&window); event.SetStatusTextAndSection({ text, section }); @@ -56,12 +76,13 @@ namespace SampleHive { window.HandleWindowEvent(event); } - void Signal::SendCallFunctionPlay(const wxString& selection, wxWindow& window, bool isDialog) + void cSignal::SendCallFunctionPlay(const wxString& selection, bool checkAutoplay, wxWindow& window, bool isDialog) { - SampleHive::CallFunctionEvent event(SampleHive::SH_EVT_CALL_FUNC_PLAY, window.GetId()); + SampleHive::cCallFunctionEvent event(SampleHive::SH_EVT_CALL_FUNC_PLAY, window.GetId()); event.SetEventObject(&window); event.SetSelection(selection); + event.SetAutoplayValue(checkAutoplay); if (isDialog) window.GetParent()->GetEventHandler()->ProcessEvent(event); @@ -69,9 +90,9 @@ namespace SampleHive { window.HandleWindowEvent(event); } - void Signal::SendTimerStopStatus(wxWindow& window, bool isDialog) + void cSignal::SendTimerStopStatus(wxWindow& window, bool isDialog) { - SampleHive::TimerEvent event(SampleHive::SH_EVT_TIMER_STOP, window.GetId()); + SampleHive::cTimerEvent event(SampleHive::SH_EVT_TIMER_STOP, window.GetId()); event.SetEventObject(&window); if (isDialog) @@ -80,19 +101,44 @@ namespace SampleHive { window.HandleWindowEvent(event); } - void Signal::SendLoopPoints(std::pair loopPoint, wxWindow& window, bool isDialog) + void cSignal::SendLoopPoints(std::pair loopPoint, wxWindow& window, bool isDialog) { - SampleHive::LoopPointsEvent event(SampleHive::SH_EVT_LOOP_POINTS_UPDATED, window.GetId()); + SampleHive::cLoopPointsEvent event(SampleHive::SH_EVT_LOOP_POINTS_UPDATED, window.GetId()); event.SetEventObject(&window); event.SetLoopPoints({loopPoint.first, loopPoint.second}); - window.HandleWindowEvent(event); + if (isDialog) + window.GetParent()->GetEventHandler()->ProcessEvent(event); + else + window.HandleWindowEvent(event); } - void Signal::SendWaveformUpdateStatus(wxWindow& window, bool isDialog) + void cSignal::SendClearLoopPointsStatus(wxWindow& window, bool isDialog) { - SampleHive::WaveformUpdateEvent event(SampleHive::SH_EVT_UPDATE_WAVEFORM, window.GetId()); + SampleHive::cLoopPointsEvent event(SampleHive::SH_EVT_LOOP_POINTS_CLEAR, window.GetId()); + event.SetEventObject(&window); + + if (isDialog) + window.GetParent()->GetEventHandler()->ProcessEvent(event); + else + window.HandleWindowEvent(event); + } + + void cSignal::SendLoopABButtonValueChange(wxWindow& window, bool isDialog) + { + SampleHive::cLoopPointsEvent event(SampleHive::SH_EVT_LOOP_AB_BUTTON_VALUE_CHANGE, window.GetId()); + event.SetEventObject(&window); + + if (isDialog) + window.GetParent()->GetEventHandler()->ProcessEvent(event); + else + window.HandleWindowEvent(event); + } + + void cSignal::SendWaveformUpdateStatus(wxWindow& window, bool isDialog) + { + SampleHive::cWaveformUpdateEvent event(SampleHive::SH_EVT_UPDATE_WAVEFORM, window.GetId()); event.SetEventObject(&window); if (isDialog) diff --git a/src/Utility/Signal.hpp b/src/Utility/Signal.hpp index c0563dc..941dbcb 100644 --- a/src/Utility/Signal.hpp +++ b/src/Utility/Signal.hpp @@ -1,3 +1,23 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #include @@ -5,22 +25,23 @@ namespace SampleHive { - class Signal + class cSignal { public: - Signal(); - ~Signal(); + cSignal(); + ~cSignal(); public: static void SendInfoBarMessage(const wxString& msg, int mode, wxWindow& window, bool isDialog = false); static void SendPushStatusBarStatus(const wxString& msg, int section, wxWindow& window, bool isDialog = false); static void SendSetStatusBarStatus(const wxString& msg, int section, wxWindow& window, bool isDialog = false); static void SendPopStatusBarStatus(int section, wxWindow& window, bool isDialog = false); - static void SendCallFunctionPlay(const wxString& selection, wxWindow& window, bool isDialog = false); + static void SendCallFunctionPlay(const wxString& selection, bool checkAutoplay, wxWindow& window, bool isDialog = false); static void SendTimerStopStatus(wxWindow& window, bool isDialog = false); static void SendLoopPoints(std::pair loopPoint, wxWindow& window, bool isDialog = false); + static void SendClearLoopPointsStatus(wxWindow& window, bool isDialog = false); + static void SendLoopABButtonValueChange(wxWindow& window, bool isDialog = false); static void SendWaveformUpdateStatus(wxWindow& window, bool isDialog = false); - }; } diff --git a/src/Utility/Tags.cpp b/src/Utility/Tags.cpp index bdf33ef..b3c6402 100644 --- a/src/Utility/Tags.cpp +++ b/src/Utility/Tags.cpp @@ -30,121 +30,125 @@ #include #endif -Tags::Tags(const std::string& filename) - : m_Filepath(filename) -{ +namespace SampleHive { -} - -Tags::~Tags() -{ - -} - -AudioInfo Tags::GetAudioInfo() -{ - wxString artist, album, genre, title, comment; - int channels = 0, length = 0, sample_rate = 0, bitrate = 0; - - TagLib::FileRef f (static_cast(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average); - - if (!f.isNull() && f.tag() && f.audioProperties()) + cTags::cTags(const std::string& filename) + : m_Filepath(filename) { - TagLib::Tag* tag = f.tag(); - TagLib::AudioProperties* properties = f.audioProperties(); - TagLib::String Title = tag->title(); - TagLib::String Artist = tag->artist(); - TagLib::String Album = tag->album(); - TagLib::String Genre = tag->genre(); - TagLib::String Comment = tag->comment(); - - int seconds = properties->length() % 60; - int minutes = (properties->length() - seconds) / 60; - - bitrate = properties->bitrate(); - channels = properties->channels(); - length = properties->lengthInMilliseconds(); - int length_sec = properties->lengthInSeconds(); - sample_rate = properties->sampleRate(); - - title = wxString::FromUTF8(Title.toCString(true)); - artist = wxString::FromUTF8(Artist.toCString(true)); - album = wxString::FromUTF8(Album.toCString(true)); - genre = wxString::FromUTF8(Genre.toCString(true)); - comment = wxString::FromUTF8(Comment.toCString(true)); - - bValid = true; - } - else - { - bValid = false; } - return { title, artist, album, genre, comment, channels, length, sample_rate, bitrate }; -} - -void Tags::SetTitle(std::string title) -{ - TagLib::FileRef f (static_cast(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average); - - if (!f.isNull() && f.tag() && f.audioProperties()) + cTags::~cTags() { - TagLib::Tag* tag = f.tag(); - tag->setTitle(title); - f.save(); } -} -void Tags::SetArtist(std::string artist) -{ - TagLib::FileRef f (static_cast(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average); - - if (!f.isNull() && f.tag() && f.audioProperties()) + cTags::AudioInfo cTags::GetAudioInfo() { - TagLib::Tag* tag = f.tag(); + wxString artist, album, genre, title, comment; + int channels = 0, length = 0, sample_rate = 0, bitrate = 0; - tag->setArtist(artist); - f.save(); + TagLib::FileRef f (static_cast(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average); + + if (!f.isNull() && f.tag() && f.audioProperties()) + { + TagLib::Tag* tag = f.tag(); + TagLib::AudioProperties* properties = f.audioProperties(); + + TagLib::String Title = tag->title(); + TagLib::String Artist = tag->artist(); + TagLib::String Album = tag->album(); + TagLib::String Genre = tag->genre(); + TagLib::String Comment = tag->comment(); + + int seconds = properties->length() % 60; + int minutes = (properties->length() - seconds) / 60; + + bitrate = properties->bitrate(); + channels = properties->channels(); + length = properties->lengthInMilliseconds(); + int length_sec = properties->lengthInSeconds(); + sample_rate = properties->sampleRate(); + + title = wxString::FromUTF8(Title.toCString(true)); + artist = wxString::FromUTF8(Artist.toCString(true)); + album = wxString::FromUTF8(Album.toCString(true)); + genre = wxString::FromUTF8(Genre.toCString(true)); + comment = wxString::FromUTF8(Comment.toCString(true)); + + m_bValid = true; + } + else + { + m_bValid = false; + } + + return { title, artist, album, genre, comment, channels, length, sample_rate, bitrate }; } -} -void Tags::SetAlbum(std::string album) -{ - TagLib::FileRef f (static_cast(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average); - - if (!f.isNull() && f.tag() && f.audioProperties()) + void cTags::SetTitle(std::string title) { - TagLib::Tag* tag = f.tag(); + TagLib::FileRef f (static_cast(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average); - tag->setAlbum(album); - f.save(); + if (!f.isNull() && f.tag() && f.audioProperties()) + { + TagLib::Tag* tag = f.tag(); + + tag->setTitle(title); + f.save(); + } } -} -void Tags::SetGenre(std::string genre) -{ - TagLib::FileRef f (static_cast(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average); - - if (!f.isNull() && f.tag() && f.audioProperties()) + void cTags::SetArtist(std::string artist) { - TagLib::Tag* tag = f.tag(); + TagLib::FileRef f (static_cast(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average); - tag->setGenre(genre); - f.save(); + if (!f.isNull() && f.tag() && f.audioProperties()) + { + TagLib::Tag* tag = f.tag(); + + tag->setArtist(artist); + f.save(); + } } -} -void Tags::SetComment(std::string comment) -{ - TagLib::FileRef f (static_cast(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average); - - if (!f.isNull() && f.tag() && f.audioProperties()) + void cTags::SetAlbum(std::string album) { - TagLib::Tag* tag = f.tag(); + TagLib::FileRef f (static_cast(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average); - tag->setComment(comment); - f.save(); + if (!f.isNull() && f.tag() && f.audioProperties()) + { + TagLib::Tag* tag = f.tag(); + + tag->setAlbum(album); + f.save(); + } } + + void cTags::SetGenre(std::string genre) + { + TagLib::FileRef f (static_cast(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average); + + if (!f.isNull() && f.tag() && f.audioProperties()) + { + TagLib::Tag* tag = f.tag(); + + tag->setGenre(genre); + f.save(); + } + } + + void cTags::SetComment(std::string comment) + { + TagLib::FileRef f (static_cast(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average); + + if (!f.isNull() && f.tag() && f.audioProperties()) + { + TagLib::Tag* tag = f.tag(); + + tag->setComment(comment); + f.save(); + } + } + } diff --git a/src/Utility/Tags.hpp b/src/Utility/Tags.hpp index 2c2f165..c0ba60b 100644 --- a/src/Utility/Tags.hpp +++ b/src/Utility/Tags.hpp @@ -24,42 +24,46 @@ #include -struct AudioInfo -{ - wxString title; - wxString artist; - wxString album; - wxString genre; - wxString comment; +namespace SampleHive { - int channels; - int length; - int sample_rate; - int bitrate; -}; + class cTags + { + struct AudioInfo + { + wxString title; + wxString artist; + wxString album; + wxString genre; + wxString comment; -class Tags -{ - public: - Tags(const std::string& filepath); - ~Tags(); + int channels; + int length; + int sample_rate; + int bitrate; + }; - private: - // ------------------------------------------------------------------- - const std::string& m_Filepath; + public: + cTags(const std::string& filepath); + ~cTags(); - bool bValid = false; + public: + // ------------------------------------------------------------------- + cTags::AudioInfo GetAudioInfo(); + void SetTitle(std::string artist); + void SetArtist(std::string artist); + void SetAlbum(std::string album); + void SetGenre(std::string genre); + void SetComment(std::string comment); - public: - // ------------------------------------------------------------------- - AudioInfo GetAudioInfo(); - void SetTitle(std::string artist); - void SetArtist(std::string artist); - void SetAlbum(std::string album); - void SetGenre(std::string genre); - void SetComment(std::string comment); + public: + // ------------------------------------------------------------------- + inline bool IsFileValid() { return m_bValid; } - public: - // ------------------------------------------------------------------- - inline bool IsFileValid() { return bValid; } -}; + private: + // ------------------------------------------------------------------- + const std::string& m_Filepath; + + bool m_bValid = false; + }; + +} diff --git a/src/Utility/Utils.cpp b/src/Utility/Utils.cpp new file mode 100644 index 0000000..3e000a2 --- /dev/null +++ b/src/Utility/Utils.cpp @@ -0,0 +1,221 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "Database/Database.hpp" +#include "Utility/HiveData.hpp" +#include "Utility/Log.hpp" +#include "Utility/Paths.hpp" +#include "Utility/Serialize.hpp" +#include "Utility/Signal.hpp" +#include "Utility/Tags.hpp" +#include "Utility/Utils.hpp" + +#include +#include + +namespace SampleHive { + + SampleHive::cUtils::FileInfo SampleHive::cUtils::GetFilenamePathAndExtension(const wxString& selected, + bool checkExtension, bool doGetFilename) const + { + SampleHive::cSerializer serializer; + cDatabase db; + + wxString path; + std::string extension, filename; + + wxString filename_with_extension = db.GetSamplePathByFilename(selected.BeforeLast('.').ToStdString()); + wxString filename_without_extension = db.GetSamplePathByFilename(selected.ToStdString()); + + if (checkExtension) + { + extension = serializer.DeserializeShowFileExtension() ? + db.GetSampleFileExtension(selected.ToStdString()) : + db.GetSampleFileExtension(selected.BeforeLast('.').ToStdString()); + } + + path = selected.Contains(wxString::Format(".%s", extension)) ? + filename_with_extension : filename_without_extension; + + if (doGetFilename) + filename = path.AfterLast('/').BeforeLast('.').ToStdString(); + + return { path, extension, filename }; + } + + void SampleHive::cUtils::AddSamples(wxArrayString& files, wxWindow* parent) + { + SampleHive::cSerializer serializer; + cDatabase db; + + wxBusyCursor busy_cursor; + wxWindowDisabler window_disabler; + + wxProgressDialog* progressDialog = new wxProgressDialog(_("Adding files.."), + _("Adding files, please wait..."), + static_cast(files.size()), parent, + wxPD_APP_MODAL | wxPD_SMOOTH | wxPD_CAN_ABORT | + wxPD_AUTO_HIDE); + progressDialog->CenterOnParent(wxBOTH); + + std::vector sample_array; + + std::string path; + std::string artist; + std::string filename_with_extension; + std::string filename_without_extension; + std::string extension; + std::string filename; + + //Check All Files At Once + wxArrayString sorted_files; + + sorted_files = db.CheckDuplicates(files); + files = sorted_files; + + if (files.size() < 1) + { + progressDialog->Destroy(); + return; + } + + progressDialog->SetRange(files.size()); + + for (unsigned int i = 0; i < files.size(); i++) + { + progressDialog->Update(i, wxString::Format(_("Getting Data For %s"), files[i].AfterLast('/'))); + + if (progressDialog->WasCancelled()) + { + progressDialog->Destroy(); + return; + } + + path = files[i].ToStdString(); + filename_with_extension = files[i].AfterLast('/').ToStdString(); + filename_without_extension = files[i].AfterLast('/').BeforeLast('.').ToStdString(); + extension = files[i].AfterLast('.').ToStdString(); + + filename = serializer.DeserializeShowFileExtension() ? + filename_with_extension : filename_without_extension; + + Sample sample; + + sample.SetPath(path); + sample.SetFilename(filename_without_extension); + sample.SetFileExtension(extension); + + cTags tags(path); + + artist = tags.GetAudioInfo().artist.ToStdString(); + + sample.SetSamplePack(artist); + sample.SetChannels(tags.GetAudioInfo().channels); + sample.SetLength(tags.GetAudioInfo().length); + sample.SetSampleRate(tags.GetAudioInfo().sample_rate); + sample.SetBitrate(tags.GetAudioInfo().bitrate); + + wxLongLong llLength = sample.GetLength(); + int total_min = static_cast((llLength / 60000).GetValue()); + int total_sec = static_cast(((llLength % 60000) / 1000).GetValue()); + + wxVector data; + + wxVariant icon = wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)); + + if (tags.IsFileValid()) + { + data.clear(); + data.push_back(icon); + data.push_back(filename); + data.push_back(sample.GetSamplePack()); + data.push_back(""); + data.push_back(wxString::Format("%d", sample.GetChannels())); + data.push_back(wxString::Format("%2i:%02i", total_min, total_sec)); + data.push_back(wxString::Format("%d", sample.GetSampleRate())); + data.push_back(wxString::Format("%d", sample.GetBitrate())); + data.push_back(path); + + SH_LOG_INFO("Adding file: {}, Extension: {}", sample.GetFilename(), sample.GetFileExtension()); + + SampleHive::cHiveData::Get().ListCtrlAppendItem(data); + + sample_array.push_back(sample); + } + else + { + wxString msg = wxString::Format(_("Error! Cannot open %s, Invalid file type."), + filename_with_extension); + + SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_ERROR, *parent); + } + } + + progressDialog->Pulse(_("Updating Database.."), NULL); + + db.InsertIntoSamples(sample_array); + + progressDialog->Destroy(); + } + + void cUtils::OnAutoImportDir(const wxString& pathToDirectory, wxWindow* parent) + { + SH_LOG_DEBUG("Start Importing Samples"); + + wxBusyCursor busy_cursor; + wxWindowDisabler window_disabler; + + wxString filepath; + wxArrayString filepath_array; + + size_t number_of_files = wxDir::GetAllFiles(pathToDirectory, &filepath_array, wxEmptyString, wxDIR_DEFAULT); + + wxProgressDialog* progressDialog = new wxProgressDialog(_("Adding files.."), + _("Adding files, please wait..."), + static_cast(number_of_files), parent, + wxPD_APP_MODAL | wxPD_SMOOTH | + wxPD_CAN_ABORT | wxPD_AUTO_HIDE); + + progressDialog->CenterOnParent(wxBOTH); + + for (size_t i = 0; i < number_of_files; i++) + { + filepath = filepath_array[i]; + + if (wxFileExists(filepath)) + { + filepath_array.push_back(filepath); + } + else if (wxDirExists(filepath)) + { + wxDir::GetAllFiles(filepath, &filepath_array); + } + + progressDialog->Pulse(_("Reading Samples"), NULL); + } + + progressDialog->Destroy(); + + AddSamples(filepath_array, parent); + + SH_LOG_DEBUG("Done Importing Samples"); + } + +} diff --git a/src/Utility/Utils.hpp b/src/Utility/Utils.hpp new file mode 100644 index 0000000..082894b --- /dev/null +++ b/src/Utility/Utils.hpp @@ -0,0 +1,59 @@ +/* SampleHive + * Copyright (C) 2021 Apoorv Singh + * A simple, modern audio sample browser/manager for GNU/Linux. + * + * This file is a part of SampleHive + * + * SampleHive is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SampleHive is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "wx/arrstr.h" +#include "wx/string.h" +#include "wx/window.h" + +namespace SampleHive { + + class cUtils + { + private: + cUtils() = default; + + public: + cUtils(const cUtils&) = delete; + cUtils& operator=(const cUtils) = delete; + + public: + static cUtils& Get() + { + static cUtils s_cUtils; + return s_cUtils; + } + + public: + struct FileInfo + { + wxString Path; + std::string Extension; + std::string Filename; + }; + + // ------------------------------------------------------------------- + cUtils::FileInfo GetFilenamePathAndExtension(const wxString& selected, + bool checkExtension = true, + bool doGetFilename = true) const; + void AddSamples(wxArrayString& files, wxWindow* parent); + void OnAutoImportDir(const wxString& pathToDirectory, wxWindow* parent); + }; + +}