diff --git a/.dir-locals.el b/.dir-locals.el index 71e329e..40fedb5 100755 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -1,6 +1,35 @@ +;;; Directory Local Variables +;;; For more information see (info "(emacs) Directory Variables") + +;; (concat (cdr (project-current)) + ((nil . ((cmake-ide-project-dir . "~/repos/sample-hive") (cmake-ide-build-dir . "~/repos/sample-hive/build") (cmake-ide-cmake-opts . "-DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DPORTABLE=1 -DCMAKE_CXX_COMPILER='/usr/bin/g++'") + ;; (projectile-project-root . "~/repos/sample-hive") (projectile-project-name . "SampleHive") (projectile-project-run-cmd . "~/repos/sample-hive/build/SampleHive") - (projectile-project-test-cmd . "./test.sh")))) + ;; (projectile-project-run-cmd . "/tmp/SampleHive/bin/SampleHive") + (compile-command . "cd .. && ninja -C build install") + (fill-column . 110) + ;; Setup dap debugging template for the project + (setq dap-debug-template-configurations + '(("SampleHive::Core::Debug" + :type "gdb" + :request "launch" + :name "SampleHive::Core::Debug" + :target "${workspaceFolder}/build/SampleHive" + ;; :target "/tmp/SampleHive/bin/SampleHive" + :cwd "${workspaceFolder}" + :symbolLoadInfo "loadAll" + :additionalSOLibSearchPath "/tmp/SampleHive/bin/")))))) + +;; ((c++-mode . ((dap-debug-template-configurations . '(("SampleHive::Core::Debug" +;; :type "gdb" +;; :request "launch" +;; :name "SampleHive::Core::Debug" +;; :target "${workspaceFolder}/build/SampleHive" +;; ;; :target "/tmp/SampleHive/bin/SampleHive" +;; :cwd "${workspaceFolder}" +;; :symbolLoadInfo "loadAll" +;; :additionalSOLibSearchPath "/tmp/SampleHive/bin/")))))) diff --git a/meson.build b/meson.build index eb433d3..785c3ba 100755 --- a/meson.build +++ b/meson.build @@ -80,6 +80,15 @@ config_data.set_quoted('SAMPLEHIVE_DATADIR', samplehive_datadir) # Import CMake cmake = import('cmake') +# Check which platform the build is for and set the appropriate GUI toolkit +wx_toolkit = '' + +if host_sys == 'linux' + wx_toolkit = 'gtk3' +elif host_sys == 'windows' + wx_toolkit = 'msw' +endif + wx_opts = cmake.subproject_options() wx_opts.add_cmake_defines({'CMAKE_POSITION_INDEPENDENT_CODE': 'ON', 'CMAKE_INSTALL_PREFIX': prefix, @@ -93,7 +102,7 @@ wx_opts.add_cmake_defines({'CMAKE_POSITION_INDEPENDENT_CODE': 'ON', 'wxBUILD_SAMPLES': 'OFF', 'wxBUILD_DEMOS': 'OFF', 'wxBUILD_COMPATIBILITY': '3.0', - 'wxBUILD_TOOLKIT': 'gtk3', + 'wxBUILD_TOOLKIT': wx_toolkit, 'wxUSE_UNICODE': 'ON', 'wxUSE_AUI': 'OFF', 'wxUSE_XML': 'OFF', @@ -144,7 +153,16 @@ src = [ 'src/App.cpp', 'src/GUI/MainFrame.cpp', + 'src/GUI/TransportControls.cpp', 'src/GUI/WaveformViewer.cpp', + 'src/GUI/Notebook.cpp', + 'src/GUI/DirectoryBrowser.cpp', + 'src/GUI/Hives.cpp', + 'src/GUI/Trash.cpp', + 'src/GUI/ListCtrl.cpp', + 'src/GUI/SearchBar.cpp', + 'src/GUI/InfoBar.cpp', + 'src/GUI/Library.cpp', 'src/GUI/Dialogs/Settings.cpp', 'src/GUI/Dialogs/TagEditor.cpp', @@ -154,8 +172,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', ] @@ -164,23 +184,18 @@ include_dirs = include_directories('src') # Dependencies wx = dependency('wxwidgets', version: '>=3.1.5', required: false) -wx_found = false +wx_cxx_flags = [] +wx_libs = [] if not wx.found() - wx_found = false - wx_subproject = cmake.subproject('wxwidgets', options: wx_opts) wx_base = wx_subproject.dependency('wxbase') wx_core = wx_subproject.dependency('wxcore') wx_media = wx_subproject.dependency('wxmedia') wx = [wx_core, wx_base, wx_media] else - wx_found = true - - wxconfig = find_program(['wx-config-gtk3', 'wx-config']) + wxconfig = find_program(['wx-config', 'wx-config-gtk3']) wx_modules = ['media', 'std'] - wx_cxx_flags = [] - wx_libs = [] foreach module : wx_modules wx_cxx_flags += run_command(wxconfig, '--cxxflags', module).stdout().strip().split() @@ -212,50 +227,37 @@ if not yaml.found() yaml = yaml_subproject.dependency('yaml-cpp') endif -snd = dependency('sndfile', version: '>=1.0.28', required: false) - -if not snd.found() - snd_subproject = cmake.subproject('libsndfile', options: snd_opts) - snd = snd_subproject.dependency('sndfile') -endif +snd_subproject = cmake.subproject('libsndfile', options: snd_opts) +snd = snd_subproject.dependency('sndfile') spdlog = dependency('spdlog', version: '>=1.8.5', required: false) if not spdlog.found() spdlog_subproject = subproject('spdlog', - default_options: [ - 'default_library=static', - 'compile_library=true',]) + default_options: [ + 'default_library=static', + 'compile_library=true',]) spdlog = spdlog_subproject.get_variable('spdlog_dep') endif -# Create samplehive-config.h based on configuration -config_h = configure_file(output: 'SampleHiveConfig.hpp', - configuration: config_data,) +# Create SampleHiveConfig.hpp based on configuration +config = configure_file(output: 'SampleHiveConfig.hpp', + configuration: config_data,) install_subdir('assets', install_dir: samplehive_datadir, exclude_directories: 'screenshots', strip_directory: true) -if wx_found - executable('SampleHive', - sources: src, - cpp_args: [wx_cxx_flags], - link_args: [wx_libs], - include_directories : include_dirs, - dependencies: [wx, taglib, sqlite3, yaml, snd, spdlog], - install: true, - install_rpath: prefix / 'lib') -else - executable('SampleHive', - sources: src, - include_directories : include_dirs, - dependencies: [wx, taglib, sqlite3, yaml, snd, spdlog], - install: true, - install_rpath: prefix / 'lib') -endif +executable('SampleHive', + sources: src, + cpp_args: [wx_cxx_flags], + link_args: [wx_libs], + include_directories : include_dirs, + dependencies: [wx, taglib, sqlite3, yaml, snd, spdlog], + install: true, + install_rpath: prefix / 'lib') summary( { 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 4167ea2..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,32 +813,31 @@ 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); } } catch (const std::exception &e) { - show_modal_dialog_and_log("Error! Cannot load hive from hives table", "Error", e.what()); + show_modal_dialog_and_log("Error! Cannot load data from HIVES", "Error", e.what()); } } -//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 81792e6..4dde838 100644 --- a/src/GUI/Dialogs/Settings.cpp +++ b/src/GUI/Dialogs/Settings.cpp @@ -19,190 +19,188 @@ */ #include "GUI/Dialogs/Settings.hpp" -#include "Utility/ControlID_Enums.hpp" -#include "Utility/Serialize.hpp" +#include "Utility/ControlIDs.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 d09338f..fe1717c 100644 --- a/src/GUI/Dialogs/TagEditor.cpp +++ b/src/GUI/Dialogs/TagEditor.cpp @@ -18,12 +18,13 @@ * along with this program. If not, see . */ -#include "Utility/ControlID_Enums.hpp" -#include "Utility/SH_Event.hpp" +#include "GUI/Dialogs/TagEditor.hpp" +#include "Database/Database.hpp" +#include "Utility/ControlIDs.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 @@ -31,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", @@ -215,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: @@ -226,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); @@ -254,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()); @@ -262,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()); @@ -274,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()); @@ -282,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()); @@ -290,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()); @@ -298,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()); @@ -312,22 +313,22 @@ void TagEditor::OnClickApply(wxCommandEvent& event) info_msg = "Error, cannot change tag!"; } - SendInfoBarMessage(info_msg, wxICON_INFORMATION); + SampleHive::cSignal::SendInfoBarMessage(info_msg, wxICON_INFORMATION, *this, true); } -void TagEditor::SendInfoBarMessage(const wxString& msg, int mode) -{ - SH_LOG_INFO("{} called..", __FUNCTION__); +// void cTagEditor::SendInfoBarMessage(const wxString& msg, int mode) +// { +// SH_LOG_INFO("{} called..", __FUNCTION__); - SampleHive::SH_InfoBarMessageEvent event(SampleHive::SH_EVT_INFOBAR_MESSAGE_SHOW, this->GetId()); - event.SetEventObject(this); +// SampleHive::SH_InfoBarMessageEvent event(SampleHive::SH_EVT_INFOBAR_MESSAGE_SHOW, this->GetId()); +// event.SetEventObject(this); - event.SetInfoBarMessage({ msg, mode }); +// event.SetInfoBarMessage({ msg, mode }); - GetParent()->GetEventHandler()->ProcessEvent(event); -} +// GetParent()->GetEventHandler()->ProcessEvent(event); +// } -TagEditor::~TagEditor() +cTagEditor::~cTagEditor() { } diff --git a/src/GUI/Dialogs/TagEditor.hpp b/src/GUI/Dialogs/TagEditor.hpp index 32a8d3d..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 new file mode 100644 index 0000000..1181570 --- /dev/null +++ b/src/GUI/DirectoryBrowser.cpp @@ -0,0 +1,82 @@ +/* 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/ControlIDs.hpp" +#include "Utility/Log.hpp" +#include "Utility/Paths.hpp" +#include "Utility/Utils.hpp" + +#include +#include + +cDirectoryBrowser::cDirectoryBrowser(wxWindow* window) + : 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), + m_pWindow(window) +{ + SetPath(USER_HOME_DIR); + + Bind(wxEVT_DIRCTRL_FILEACTIVATED, &cDirectoryBrowser::OnClickDirCtrl, this, SampleHive::ID::BC_DirCtrl); + Bind(wxEVT_TREE_BEGIN_DRAG, &cDirectoryBrowser::OnDragFromDirCtrl, this, this->GetTreeCtrl()->GetId()); +} + +void cDirectoryBrowser::OnClickDirCtrl(wxCommandEvent& event) +{ + wxArrayString path; + path.push_back(this->GetFilePath()); + + 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) +{ + wxFileDataObject file_data; + file_data.AddFile(this->GetPath(event.GetItem())); + + wxDropSource drop_source(this); + drop_source.SetData(file_data); + + LogDragResult(drop_source.DoDragDrop()); +} + +cDirectoryBrowser::~cDirectoryBrowser() +{ + +} diff --git a/src/GUI/DirectoryBrowser.hpp b/src/GUI/DirectoryBrowser.hpp new file mode 100644 index 0000000..626b010 --- /dev/null +++ b/src/GUI/DirectoryBrowser.hpp @@ -0,0 +1,41 @@ +/* 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 + +class cDirectoryBrowser : public wxGenericDirCtrl +{ + public: + cDirectoryBrowser(wxWindow* window); + ~cDirectoryBrowser(); + + private: + // ------------------------------------------------------------------- + // 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 new file mode 100644 index 0000000..d7f2c8a --- /dev/null +++ b/src/GUI/Hives.cpp @@ -0,0 +1,736 @@ +/* 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 "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 + +#include +#include +#include + +cHivesPanel::cHivesPanel(wxWindow* window) + : wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL), + m_pWindow(window) +{ + m_pMainSizer = new wxBoxSizer(wxVERTICAL); + m_pHivesSizer = new wxBoxSizer(wxVERTICAL); + m_pButtonSizer = new wxBoxSizer(wxHORIZONTAL); + + 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, 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, SampleHive::ID::BC_Hives, wxDefaultPosition, wxDefaultSize, wxDV_NO_HEADER | wxDV_SINGLE); + + m_pHivesSizer->Add(m_pHives, wxSizerFlags(1).Expand()); + + // Adding default hive + m_FavoritesHive = m_pHives->AppendContainer(wxDataViewItem(wxNullPtr), _("Favorites")); + + // Setting m_Hives to accept files to be dragged and dropped on it + 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, 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()); + + // Sizer for Hives page for wxNotebook + this->SetSizer(m_pMainSizer); + m_pMainSizer->Fit(this); + m_pMainSizer->SetSizeHints(this); + m_pMainSizer->Layout(); +} + +void cHivesPanel::OnDragAndDropToHives(wxDropFilesEvent& event) +{ + SampleHive::cSerializer serializer; + cDatabase db; + + if (event.GetNumberOfFiles() > 0) + { + wxFileDataObject file_data; + wxArrayString files; + + wxDataViewItemArray items; + int rows = SampleHive::cHiveData::Get().GetListCtrlSelections(items); + + wxDataViewItem drop_target;; + wxDataViewColumn* column; + wxPoint position = event.GetPosition(); + + m_pHives->HitTest(position, drop_target, column); + + wxString hive_name = m_pHives->GetItemText(drop_target); + + wxString msg; + + for (int i = 0; i < rows; i++) + { + int row = SampleHive::cHiveData::Get().GetListCtrlRowFromItem(items, i); + + wxString name = SampleHive::cHiveData::Get().GetListCtrlTextValue(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_pHives->GetItemText(drop_target)); + + if (drop_target.IsOk() && m_pHives->IsContainer(drop_target) && + db.GetFavoriteColumnValueByFilename(file_name.ToStdString()) == 0) + { + m_pHives->AppendItem(drop_target, files[i]); + + 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()); + + msg = wxString::Format(_("%s added to %s."), files[i], hive_name); + } + else + { + if (db.GetFavoriteColumnValueByFilename(file_name.ToStdString()) == 1) + { + wxMessageBox(wxString::Format(_("%s is already added to %s hive"), files[i], + db.GetHiveByFilename(file_name.ToStdString())), + _("Error!"), wxOK | wxICON_ERROR | wxCENTRE, this); + } + else + { + if (m_pHives->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_pHives->GetItemText(drop_target)), _("Error!"), + wxOK | wxICON_ERROR | wxCENTRE, this); + } + } + + if (!msg.IsEmpty()) + SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_ERROR, *this); + } + } +} + +void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event) +{ + SampleHive::cSerializer serializer; + cDatabase db; + + wxDataViewItem selected_hive = event.GetItem(); + + wxString hive_name = m_pHives->GetItemText(selected_hive); + + wxMenu menu; + + if (m_pHives->IsContainer(selected_hive)) + { + // Container menu items + 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(SampleHive::ID::MN_FilterLibrary, _("Filter library"), _("Show only samples from current hive in library")); + else + menu.Append(SampleHive::ID::MN_FilterLibrary, _("Clear filter"), _("Clear the filter")); + } + else + { + // Child menu items + 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 SampleHive::ID::MN_RenameHive: + { + std::deque nodes; + nodes.push_back(m_pHives->GetNthChild(wxDataViewItem(wxNullPtr), 0)); + + wxDataViewItem current_item, found_item; + + int row = 0; + int hive_count = m_pHives->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_pHives->GetItemText(current_item) == hive_name) + { + found_item = current_item; + SH_LOG_DEBUG("Found item: {}", m_pHives->GetItemText(current_item)); + break; + } + + wxDataViewItem child = m_pHives->GetNthChild(wxDataViewItem(wxNullPtr), 0); + + while (row < (hive_count - 1)) + { + row ++; + + child = m_pHives->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_pHives->GetItemText(selected_hive); + + int sample_count = m_pHives->GetChildCount(selected_hive); + + if (sample_count <= 0) + { + m_pHives->SetItemText(selected_hive, hive_name); + db.UpdateHive(selected_hive_name.ToStdString(), hive_name.ToStdString()); + } + else + { + for (int i = 0; i < sample_count; i++) + { + wxDataViewItem sample_item = m_pHives->GetNthChild(selected_hive, i); + + wxString sample_name = serializer.DeserializeShowFileExtension() ? + 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()); + + m_pHives->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()) + SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); + } + break; + case SampleHive::ID::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_pHives->GetItemText(m_FavoritesHive)) + { + 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_pHives->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_pHives->GetChildCount(selected_hive) <= 0) + { + switch (deleteEmptyHiveDialog.ShowModal()) + { + case wxID_YES: + if (selected_hive.IsOk() && m_pHives->IsContainer(selected_hive) && + hive_name != m_pHives->GetItemText(m_FavoritesHive)) + { + m_pHives->DeleteItem(selected_hive); + + db.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_pHives->IsContainer(selected_hive) && + hive_name != m_pHives->GetItemText(m_FavoritesHive)) + { + wxDataViewItem child_item; + + for (int i = 0; i < SampleHive::cHiveData::Get().GetListCtrlItemCount(); i++) + { + 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++) + { + child_item = m_pHives->GetNthChild(selected_hive, j); + + wxString child_name = + serializer.DeserializeShowFileExtension() ? + m_pHives->GetItemText(child_item).BeforeLast('.') : + m_pHives->GetItemText(child_item); + + if (child_name == matched_sample) + { + SH_LOG_DEBUG("Found match"); + + 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()); + + break; + } + else + SH_LOG_DEBUG("No match found"); + } + } + + m_pHives->DeleteChildren(selected_hive); + m_pHives->DeleteItem(selected_hive); + + db.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()) + SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); + } + break; + 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); + + if (dataset.empty()) + { + wxMessageBox(_("Error! Database is empty."), _("Error!"), + wxOK | wxICON_ERROR | wxCENTRE, this); + return; + } + else + { + SampleHive::cHiveData::Get().ListCtrlDeleteAllItems(); + + for (auto data : dataset) + { + SampleHive::cHiveData::Get().ListCtrlAppendItem(data); + } + } + } + catch (std::exception& e) + { + wxMessageBox(wxString::Format(_("Error loading data, cannot filter sample view. Error: %s"), e.what()), + _("Error!"), wxOK | wxICON_ERROR | wxCENTRE, this); + } + + m_bFiltered = true; + } + else + { + try + { + const auto dataset = db.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 + { + SampleHive::cHiveData::Get().ListCtrlDeleteAllItems(); + + for (auto data : dataset) + { + SampleHive::cHiveData::Get().ListCtrlAppendItem(data); + } + } + } + catch (std::exception& e) + { + wxMessageBox(wxString::Format(_("Error loading data, cannot filter sample view. Error: %s"), e.what()), + _("Error!"), wxOK | wxICON_ERROR | wxCENTRE, this); + } + + m_bFiltered = false; + } + } + break; + default: + return; + } + } + else if (selected_hive.IsOk() && !m_pHives->IsContainer(selected_hive)) + { + switch (m_pHives->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) + { + case SampleHive::ID::MN_RemoveSample: + for (int i = 0; i < SampleHive::cHiveData::Get().GetListCtrlItemCount(); i++) + { + wxString matched_sample = serializer.DeserializeShowFileExtension() ? + 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) + { + SH_LOG_DEBUG("Found match"); + + 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()); + + m_pHives->DeleteItem(selected_hive); + + break; + } + + wxString msg = wxString::Format(_("Removed %s from %s"), m_pHives->GetItemText(event.GetItem()), + db.GetHiveByFilename(matched_sample.ToStdString())); + + SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); + } + break; + case SampleHive::ID::MN_ShowInLibrary: + for (int i = 0; i < SampleHive::cHiveData::Get().GetListCtrlItemCount(); i++) + { + wxString matched_sample = serializer.DeserializeShowFileExtension() ? + 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) + { + SH_LOG_DEBUG("Found match"); + + wxDataViewItem matched_item = SampleHive::cHiveData::Get().GetListCtrlItemFromRow(i); + + SampleHive::cHiveData::Get().ListCtrlUnselectAllItems(); + SampleHive::cHiveData::Get().ListCtrlSelectRow(i); + SampleHive::cHiveData::Get().ListCtrlEnsureVisible(matched_item); + + break; + } + } + break; + default: + return; + } + } +} + +void cHivesPanel::OnHiveStartEditing(wxDataViewEvent &event) +{ + SH_LOG_INFO("Right click on a hive and select rename to rename it.."); + event.Veto(); +} + +void cHivesPanel::OnClickAddHive(wxCommandEvent& event) +{ + cDatabase db; + + std::deque nodes; + nodes.push_back(m_pHives->GetNthChild(wxDataViewItem(wxNullPtr), 0)); + + wxDataViewItem current_item, found_item; + + int row = 0; + int hive_count = m_pHives->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_pHives->GetItemText(current_item) == hive_name) + { + found_item = current_item; + SH_LOG_DEBUG("Found item: {}", m_pHives->GetItemText(current_item)); + break; + } + + wxDataViewItem child = m_pHives->GetNthChild(wxDataViewItem(wxNullPtr), 0); + + while (row < (hive_count - 1)) + { + row ++; + + child = m_pHives->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_pHives->AppendContainer(wxDataViewItem(wxNullPtr), hive_name); + db.InsertIntoHives(hive_name.ToStdString()); + + msg = wxString::Format(_("%s added to Hives."), hive_name); + } + break; + } + case wxID_CANCEL: + break; + default: + return; + } + + if (!msg.IsEmpty()) + SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); +} + +void cHivesPanel::OnClickRemoveHive(wxCommandEvent& event) +{ + 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 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_pHives->GetItemText(m_FavoritesHive)) + { + 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_pHives->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_pHives->GetChildCount(selected_item) <= 0) + { + switch (deleteEmptyHiveDialog.ShowModal()) + { + case wxID_YES: + if (selected_item.IsOk() && m_pHives->IsContainer(selected_item) && + hive_name != m_pHives->GetItemText(m_FavoritesHive)) + { + m_pHives->DeleteItem(selected_item); + + db.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_pHives->IsContainer(selected_item) && + hive_name != m_pHives->GetItemText(m_FavoritesHive)) + { + wxDataViewItem child_item; + + for (int i = 0; i < SampleHive::cHiveData::Get().GetListCtrlItemCount(); i++) + { + 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_item); j++) + { + child_item = m_pHives->GetNthChild(selected_item, j); + + wxString child_name = serializer.DeserializeShowFileExtension() ? + m_pHives->GetItemText(child_item).BeforeLast('.') : + m_pHives->GetItemText(child_item); + + if (child_name == matched_sample) + { + SH_LOG_DEBUG("Found match"); + + 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()); + + break; + } + else + SH_LOG_DEBUG("No match found"); + } + } + + m_pHives->DeleteChildren(selected_item); + m_pHives->DeleteItem(selected_item); + + db.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()) + SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); +} + +cHivesPanel::~cHivesPanel() +{ + +} diff --git a/src/GUI/Hives.hpp b/src/GUI/Hives.hpp new file mode 100644 index 0000000..7f26e31 --- /dev/null +++ b/src/GUI/Hives.hpp @@ -0,0 +1,69 @@ +/* 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 + +class cHivesPanel : public wxPanel +{ + public: + // ------------------------------------------------------------------- + cHivesPanel(wxWindow* window); + ~cHivesPanel(); + + public: + // ------------------------------------------------------------------- + wxDataViewTreeCtrl* GetHivesObject() { return m_pHives; } + wxDataViewItem& GetFavoritesHive() { return m_FavoritesHive; } + + bool IsLibraryFiltered() { return m_bFiltered; } + + private: + // ------------------------------------------------------------------- + // 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); + + private: + // ------------------------------------------------------------------- + wxDataViewItem m_FavoritesHive; + + wxDataViewTreeCtrl* m_pHives = nullptr; + wxButton* m_pAddHiveButton = nullptr; + wxButton* m_pRemoveHiveButton = nullptr; + wxBoxSizer* m_pMainSizer = nullptr; + wxBoxSizer* m_pHivesSizer = nullptr; + wxBoxSizer* m_pButtonSizer = nullptr; + + private: + // ------------------------------------------------------------------- + bool m_bFiltered = false; + + // ------------------------------------------------------------------- + wxWindow* m_pWindow = nullptr; +}; diff --git a/src/GUI/InfoBar.cpp b/src/GUI/InfoBar.cpp new file mode 100644 index 0000000..d4a502a --- /dev/null +++ b/src/GUI/InfoBar.cpp @@ -0,0 +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 "InfoBar.hpp" + +cInfoBar::cInfoBar(wxWindow* window) + : wxInfoBar(window) +{ + +} + +cInfoBar::~cInfoBar() +{ + +} diff --git a/src/GUI/InfoBar.hpp b/src/GUI/InfoBar.hpp new file mode 100644 index 0000000..c43bc3b --- /dev/null +++ b/src/GUI/InfoBar.hpp @@ -0,0 +1,37 @@ +/* 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 + +class cInfoBar : public wxInfoBar +{ + public: + cInfoBar(wxWindow* window); + ~cInfoBar(); + + public: + wxInfoBar* GetInfoBarObject() { return this; } + + private: + wxWindow* m_pWindow; +}; diff --git a/src/GUI/Library.cpp b/src/GUI/Library.cpp new file mode 100644 index 0000000..50388ae --- /dev/null +++ b/src/GUI/Library.cpp @@ -0,0 +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/Library.hpp" +#include "Utility/Log.hpp" + +cLibrary::cLibrary(wxWindow* window) + : wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL) +{ + m_pSizer = new wxBoxSizer(wxVERTICAL); + + m_pSearchBar = new cSearchBar(this); + m_pInfoBar = new cInfoBar(this); + m_pListCtrl = new cListCtrl(this); + + m_pSizer->Add(m_pSearchBar, wxSizerFlags(1).Expand()); + m_pSizer->Add(m_pInfoBar, wxSizerFlags(0).Expand()); + m_pSizer->Add(m_pListCtrl, wxSizerFlags(1).Expand()); + + // Sizer for bottom right panel + this->SetSizer(m_pSizer); + m_pSizer->Fit(this); + m_pSizer->SetSizeHints(this); + m_pSizer->Layout(); +} + +cLibrary::~cLibrary() +{ + +} diff --git a/src/GUI/Library.hpp b/src/GUI/Library.hpp new file mode 100644 index 0000000..ae0aa7c --- /dev/null +++ b/src/GUI/Library.hpp @@ -0,0 +1,49 @@ +/* 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" +#include "GUI/ListCtrl.hpp" +#include "GUI/SearchBar.hpp" + +#include +#include +#include +#include +#include + +class cLibrary : public wxPanel +{ + public: + cLibrary(wxWindow* window); + ~cLibrary(); + + public: + wxSearchCtrl* GetSearchCtrlObject() const { return m_pSearchBar; } + wxInfoBar* GetInfoBarObject() const { return m_pInfoBar; } + wxDataViewListCtrl* GetListCtrlObject() const { return m_pListCtrl; } + + private: + cSearchBar* m_pSearchBar = nullptr; + cInfoBar* m_pInfoBar = nullptr; + cListCtrl* m_pListCtrl = nullptr; + wxBoxSizer* m_pSizer = nullptr; +}; diff --git a/src/GUI/ListCtrl.cpp b/src/GUI/ListCtrl.cpp new file mode 100644 index 0000000..2c6f8cc --- /dev/null +++ b/src/GUI/ListCtrl.cpp @@ -0,0 +1,742 @@ +/* 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/Dialogs/TagEditor.hpp" +#include "Database/Database.hpp" +#include "Utility/ControlIDs.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 +#include + +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) +{ + // Adding columns to wxDataViewListCtrl. + AppendBitmapColumn(wxBitmap(ICON_STAR_FILLED_16px), + 0, + wxDATAVIEW_CELL_ACTIVATABLE, + 30, + wxALIGN_CENTER, + !wxDATAVIEW_COL_RESIZABLE); + AppendTextColumn(_("Filename"), + wxDATAVIEW_CELL_INERT, + 250, + wxALIGN_LEFT, + wxDATAVIEW_COL_RESIZABLE | + wxDATAVIEW_COL_SORTABLE | + wxDATAVIEW_COL_REORDERABLE); + AppendTextColumn(_("Sample Pack"), + wxDATAVIEW_CELL_INERT, + 180, + wxALIGN_LEFT, + wxDATAVIEW_COL_RESIZABLE | + wxDATAVIEW_COL_SORTABLE | + wxDATAVIEW_COL_REORDERABLE); + AppendTextColumn(_("Type"), + wxDATAVIEW_CELL_INERT, + 120, + wxALIGN_LEFT, + wxDATAVIEW_COL_RESIZABLE | + wxDATAVIEW_COL_SORTABLE | + wxDATAVIEW_COL_REORDERABLE); + AppendTextColumn(_("Channels"), + wxDATAVIEW_CELL_INERT, + 90, + wxALIGN_RIGHT, + wxDATAVIEW_COL_RESIZABLE | + wxDATAVIEW_COL_SORTABLE | + wxDATAVIEW_COL_REORDERABLE); + AppendTextColumn(_("Length"), + wxDATAVIEW_CELL_INERT, + 80, + wxALIGN_RIGHT, + wxDATAVIEW_COL_RESIZABLE | + wxDATAVIEW_COL_SORTABLE | + wxDATAVIEW_COL_REORDERABLE); + AppendTextColumn(_("Sample Rate"), + wxDATAVIEW_CELL_INERT, + 120, + wxALIGN_RIGHT, + wxDATAVIEW_COL_RESIZABLE | + wxDATAVIEW_COL_SORTABLE | + wxDATAVIEW_COL_REORDERABLE); + AppendTextColumn(_("Bitrate"), + wxDATAVIEW_CELL_INERT, + 80, + wxALIGN_RIGHT, + wxDATAVIEW_COL_RESIZABLE | + wxDATAVIEW_COL_SORTABLE | + wxDATAVIEW_COL_REORDERABLE); + AppendTextColumn(_("Path"), + wxDATAVIEW_CELL_INERT, + 250, + wxALIGN_LEFT, + wxDATAVIEW_COL_RESIZABLE | + wxDATAVIEW_COL_SORTABLE | + wxDATAVIEW_COL_REORDERABLE); + + // Enable cListCtrl to accept files to be dropped on it + this->DragAcceptFiles(true); + + // Enable dragging a file from cListCtrl + this->EnableDragSource(wxDF_FILENAME); + + 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, SampleHive::ID::BC_Library); + Bind(wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, &cListCtrl::OnShowLibraryColumnHeaderContextMenu, this, SampleHive::ID::BC_Library); +} + +void cListCtrl::OnClickLibrary(wxDataViewEvent& event) +{ + cDatabase db; + + int selected_row = this->ItemToRow(event.GetItem()); + int current_row = this->ItemToRow(this->GetCurrentItem()); + + if (selected_row < 0 || !event.GetItem().IsOk()) + return; + + if (selected_row != current_row) + { + this->SetCurrentItem(event.GetItem()); + return; + } + + // Update the waveform bitmap + SampleHive::cSignal::SendWaveformUpdateStatus(*this); + + // Update LoopAB button value + SampleHive::cSignal::SendLoopABButtonValueChange(*this); + + // Stop the timer + SampleHive::cSignal::SendTimerStopStatus(*this); + + wxString selection = this->GetTextValue(selected_row, 1); + + // Get curremt column + wxDataViewColumn* CurrentColumn = this->GetCurrentColumn(); + + // Get favorite column + wxDataViewColumn* FavoriteColumn = this->GetColumn(0); + + if (!CurrentColumn) + return; + + 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) + { + // ClearLoopPoints(); + SampleHive::cSignal::SendClearLoopPointsStatus(*this); + + // Play the sample + SampleHive::cSignal::SendCallFunctionPlay(selection, true, *this); + } + else + { + wxString msg; + + // Get hive name and location + 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() && SampleHive::cHiveData::Get().IsHiveItemContainer(hive_selection)) + hive_name = SampleHive::cHiveData::Get().GetHiveItemText(false, hive_selection); + + wxString name = this->GetTextValue(selected_row, 1); + + // Get root + wxDataViewItem root = wxDataViewItem(wxNullPtr); + wxDataViewItem container; + wxDataViewItem child; + + if (db.GetFavoriteColumnValueByFilename(filename) == 0) + { + 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 < SampleHive::cHiveData::Get().GetHiveChildCount(root); i++) + { + container = SampleHive::cHiveData::Get().GetHiveNthChild(root, i); + + if (SampleHive::cHiveData::Get().GetHiveItemText(false, container) == hive_name) + { + SampleHive::cHiveData::Get().HiveAppendItem(container, name); + break; + } + } + + msg = wxString::Format(_("Added %s to %s"), name, hive_name); + } + else + { + this->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), selected_row, 0); + + db.UpdateFavoriteColumn(filename, 0); + db.UpdateHiveName(filename, SampleHive::cHiveData::Get().GetHiveItemText(true).ToStdString()); + + for (int i = 0; i < SampleHive::cHiveData::Get().GetHiveChildCount(root); i++) + { + container = SampleHive::cHiveData::Get().GetHiveNthChild(root, i); + + for (int j = 0; j < SampleHive::cHiveData::Get().GetHiveChildCount(container); j++) + { + child = SampleHive::cHiveData::Get().GetHiveNthChild(container, j); + + if (SampleHive::cHiveData::Get().GetHiveItemText(false, child) == name) + { + SampleHive::cHiveData::Get().HiveDeleteItem(child); + break; + } + } + } + + msg = wxString::Format(_("Removed %s from %s"), name, hive_name); + } + + if (!msg.IsEmpty()) + SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); + } +} + +void cListCtrl::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(); + + SampleHive::cUtils::Get().AddSamples(filepath_array, m_pWindow); + + SH_LOG_DEBUG("Done Inserting Samples"); + } +} + +void cListCtrl::OnDragFromLibrary(wxDataViewEvent& event) +{ + int selected_row = this->ItemToRow(event.GetItem()); + + if (selected_row < 0) + return; + + wxString selection = this->GetTextValue(selected_row, 1); + + wxString sample_path = SampleHive::cUtils::Get().GetFilenamePathAndExtension(selection).Path; + + wxFileDataObject* fileData = new wxFileDataObject(); + + fileData->AddFile(sample_path); + event.SetDataObject(fileData); + + SH_LOG_DEBUG("Started dragging '{}'.", sample_path); +} + +void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event) +{ + cTagEditor* tagEditor; + cDatabase db; + SampleHive::cSerializer serializer; + + wxString msg; + + wxDataViewItem item = event.GetItem(); + int selected_row; + + if (item.IsOk()) + selected_row = this->ItemToRow(item); + else + return; + + wxString selection = this->GetTextValue(selected_row, 1); + + 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; + + //true = add false = remove + bool favorite_add = false; + + if (db.GetFavoriteColumnValueByFilename(filename) == 1) + menu.Append(SampleHive::ID::MN_FavoriteSample, _("Remove from hive"), _("Remove the selected sample(s) from hive")); + else + { + menu.Append(SampleHive::ID::MN_FavoriteSample, _("Add to hive"), _("Add selected sample(s) to hive")); + favorite_add = true; + } + + 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(SampleHive::ID::MN_EditTagSample, _("Edit tags"), + _("Edit the tags for the selected sample"))->Enable(true); + menu.Append(SampleHive::ID::MN_OpenFile, _("Open in file manager"), + _("Open the selected sample in system's file manager"))->Enable(true); + } + else + { + menu.Append(SampleHive::ID::MN_EditTagSample, _("Edit tags"), + _("Edit the tags for the selected sample"))->Enable(false); + 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 SampleHive::ID::MN_FavoriteSample: + { + std::string hive_name = SampleHive::cHiveData::Get().GetHiveItemText(true).ToStdString(); + + wxDataViewItem hive_selection = SampleHive::cHiveData::Get().GetHiveItemSelection(); + + 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; + wxDataViewItem child; + + wxDataViewItemArray samples; + int sample_count = this->GetSelections(samples); + int selected_row = 0; + int db_status = 0; + + for (int k = 0; k < sample_count; k++) + { + selected_row = this->ItemToRow(samples[k]); + + if (selected_row < 0) + continue; + + wxString name = this->GetTextValue(selected_row, 1); + + filename = serializer.DeserializeShowFileExtension() ? + name.BeforeLast('.').ToStdString() : name.ToStdString(); + + db_status = db.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) + { + 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 < SampleHive::cHiveData::Get().GetHiveChildCount(root); i++) + { + container = SampleHive::cHiveData::Get().GetHiveNthChild(root, i); + + if (SampleHive::cHiveData::Get().GetHiveItemText(false, container) == hive_name) + { + SampleHive::cHiveData::Get().HiveAppendItem(container, name); + + msg = wxString::Format(_("Added %s to %s"), name, hive_name); + break; + } + } + } + else + { + //Remove From Favorites + this->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), selected_row, 0); + + db.UpdateFavoriteColumn(filename, 0); + db.UpdateHiveName(filename, SampleHive::cHiveData::Get().GetHiveItemText(true).ToStdString()); + + for (int i = 0; i < SampleHive::cHiveData::Get().GetHiveChildCount(root); i++) + { + container = SampleHive::cHiveData::Get().GetHiveNthChild(root, i); + + for (int j = 0; j < SampleHive::cHiveData::Get().GetHiveChildCount(container); j++) + { + child = SampleHive::cHiveData::Get().GetHiveNthChild(container, j); + + if (SampleHive::cHiveData::Get().GetHiveItemText(false, child) == name) + { + SampleHive::cHiveData::Get().HiveDeleteItem(child); + + msg = wxString::Format(_("Removed %s from %s"), name, hive_name); + break; + } + } + } + } + } + + break; + } + 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."), + 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 (this->GetSelectedItemsCount() <= 1) + { + switch (singleMsgDialog.ShowModal()) + { + case wxID_YES: + { + db.RemoveSampleFromDatabase(filename); + this->DeleteItem(selected_row); + + for (int j = 0; j < SampleHive::cHiveData::Get().GetHiveChildCount(root); j++) + { + container = SampleHive::cHiveData::Get().GetHiveNthChild(root, j); + + for (int k = 0; k < SampleHive::cHiveData::Get().GetHiveChildCount(container); k++) + { + child = SampleHive::cHiveData::Get().GetHiveNthChild(container, k); + + wxString child_text = serializer.DeserializeShowFileExtension() ? + SampleHive::cHiveData::Get().GetHiveItemText(false, child).BeforeLast('.') : + SampleHive::cHiveData::Get().GetHiveItemText(false, child); + + if (child_text == filename) + { + SampleHive::cHiveData::Get().HiveDeleteItem(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 = this->ItemToRow(items[i]); + + wxString text_value = this->GetTextValue(row, 1); + + std::string multi_selection = serializer.DeserializeShowFileExtension() ? + text_value.BeforeLast('.').ToStdString() : text_value.ToStdString() ; + + db.RemoveSampleFromDatabase(multi_selection); + this->DeleteItem(row); + + for (int j = 0; j < SampleHive::cHiveData::Get().GetHiveChildCount(root); j++) + { + container = SampleHive::cHiveData::Get().GetHiveNthChild(root, j); + + for (int k = 0; k < SampleHive::cHiveData::Get().GetHiveChildCount(container); k++) + { + child = SampleHive::cHiveData::Get().GetHiveNthChild(container, k); + + wxString child_text = serializer.DeserializeShowFileExtension() ? + SampleHive::cHiveData::Get().GetHiveItemText(false, child).BeforeLast('.') : + SampleHive::cHiveData::Get().GetHiveItemText(false, child); + + if (child_text == multi_selection) + { + SampleHive::cHiveData::Get().HiveDeleteItem(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 SampleHive::ID::MN_TrashSample: + { + wxDataViewItem root = wxDataViewItem(wxNullPtr); + wxDataViewItem container, child; + + if (db.IsTrashed(filename)) + SH_LOG_INFO("{} already trashed", filename); + else + { + wxDataViewItemArray items; + int rows = this->GetSelections(items); + + wxString name; + wxFileDataObject file_data; + wxArrayString files; + + for (int i = 0; i < rows; i++) + { + int item_row = this->ItemToRow(items[i]); + + wxString text_value = this->GetTextValue(item_row, 1); + + std::string multi_selection = serializer.DeserializeShowFileExtension() ? + this->GetTextValue(item_row, 1).BeforeLast('.').ToStdString() : + this->GetTextValue(item_row, 1).ToStdString() ; + + file_data.AddFile(multi_selection); + + files = file_data.GetFilenames(); + + if (db.GetFavoriteColumnValueByFilename(files[i].ToStdString())) + { + this->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), item_row, 0); + + db.UpdateFavoriteColumn(files[i].ToStdString(), 0); + + for (int j = 0; j < SampleHive::cHiveData::Get().GetHiveChildCount(root); j++) + { + container = SampleHive::cHiveData::Get().GetHiveNthChild(root, j); + + for (int k = 0; k < SampleHive::cHiveData::Get().GetHiveChildCount(container); k++) + { + child = SampleHive::cHiveData::Get().GetHiveNthChild(container, k); + + wxString child_text = serializer.DeserializeShowFileExtension() ? + SampleHive::cHiveData::Get().GetHiveItemText(false, child).BeforeLast('.') : + SampleHive::cHiveData::Get().GetHiveItemText(false, child); + + if (child_text == files[i]) + { + SampleHive::cHiveData::Get().HiveDeleteItem(child); + break; + } + } + } + } + + 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(), SampleHive::cHiveData::Get().GetHiveItemText(true).ToStdString()); + + msg = wxString::Format(_("%s sent to trash"), text_value); + } + } + } + break; + case SampleHive::ID::MN_EditTagSample: + { + tagEditor = new cTagEditor(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 SampleHive::ID::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()) + SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this); +} + +void cListCtrl::OnShowLibraryColumnHeaderContextMenu(wxDataViewEvent& event) +{ + wxMenu menu; + + wxDataViewColumn* FavoriteColumn = this->GetColumn(0); + wxDataViewColumn* FilenameColumn = this->GetColumn(1); + wxDataViewColumn* SamplePackColumn = this->GetColumn(2); + wxDataViewColumn* TypeColumn = this->GetColumn(3); + wxDataViewColumn* ChannelsColumn = this->GetColumn(4); + wxDataViewColumn* LengthColumn = this->GetColumn(5); + wxDataViewColumn* SampleRateColumn = this->GetColumn(6); + wxDataViewColumn* BitrateColumn = this->GetColumn(7); + wxDataViewColumn* PathColumn = this->GetColumn(8); + + menu.AppendCheckItem(SampleHive::ID::MN_ColumnFavorite, _("Favorites"), + _("Toggle favorites column"))->Check(FavoriteColumn->IsShown()); + menu.AppendCheckItem(SampleHive::ID::MN_ColumnFilename, _("Filename"), + _("Toggle filename column"))->Check(FilenameColumn->IsShown()); + menu.AppendCheckItem(SampleHive::ID::MN_ColumnSamplePack, _("Sample Pack"), + _("Toggle sample pack column"))->Check(SamplePackColumn->IsShown()); + menu.AppendCheckItem(SampleHive::ID::MN_ColumnType, _("Type"), + _("Toggle type column"))->Check(TypeColumn->IsShown()); + menu.AppendCheckItem(SampleHive::ID::MN_ColumnChannels, _("Channels"), + _("Toggle channels column"))->Check(ChannelsColumn->IsShown()); + menu.AppendCheckItem(SampleHive::ID::MN_ColumnLength, _("Length"), + _("Toggle length column"))->Check(LengthColumn->IsShown()); + menu.AppendCheckItem(SampleHive::ID::MN_ColumnSampleRate, _("Sample Rate"), + _("Toggle sample rate column"))->Check(SampleRateColumn->IsShown()); + menu.AppendCheckItem(SampleHive::ID::MN_ColumnBitrate, _("Bitrate"), + _("Toggle bitrate column"))->Check(BitrateColumn->IsShown()); + menu.AppendCheckItem(SampleHive::ID::MN_ColumnPath, _("Path"), + _("Toggle path column"))->Check(PathColumn->IsShown()); + + switch (this->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) + { + case SampleHive::ID::MN_ColumnFavorite: + FavoriteColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnFavorite)); + break; + case SampleHive::ID::MN_ColumnFilename: + FilenameColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnFilename)); + break; + case SampleHive::ID::MN_ColumnSamplePack: + SamplePackColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnSamplePack)); + break; + case SampleHive::ID::MN_ColumnType: + TypeColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnType)); + break; + case SampleHive::ID::MN_ColumnChannels: + ChannelsColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnChannels)); + break; + case SampleHive::ID::MN_ColumnLength: + LengthColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnLength)); + break; + case SampleHive::ID::MN_ColumnSampleRate: + SampleRateColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnSampleRate)); + break; + case SampleHive::ID::MN_ColumnBitrate: + BitrateColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnBitrate)); + break; + case SampleHive::ID::MN_ColumnPath: + PathColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnPath)); + break; + default: + break; + } +} + +cListCtrl::~cListCtrl() +{ + +} diff --git a/src/GUI/ListCtrl.hpp b/src/GUI/ListCtrl.hpp new file mode 100644 index 0000000..1ef2ee8 --- /dev/null +++ b/src/GUI/ListCtrl.hpp @@ -0,0 +1,50 @@ +/* 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 + +class cListCtrl : public wxDataViewListCtrl +{ + public: + // ------------------------------------------------------------------- + cListCtrl(wxWindow* window); + ~cListCtrl(); + + public: + // ------------------------------------------------------------------- + wxDataViewListCtrl* GetListCtrlObject() { return this; } + + private: + // ------------------------------------------------------------------- + // Library event handlers + void OnClickLibrary(wxDataViewEvent& event); + void OnDragAndDropToLibrary(wxDropFilesEvent& event); + void OnDragFromLibrary(wxDataViewEvent& event); + void OnShowLibraryContextMenu(wxDataViewEvent& event); + void OnShowLibraryColumnHeaderContextMenu(wxDataViewEvent& event); + + private: + // ------------------------------------------------------------------- + wxWindow* m_pWindow = nullptr; +}; diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index ffe1b6e..c061058 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -20,2054 +20,257 @@ #include "GUI/MainFrame.hpp" #include "GUI/Dialogs/Settings.hpp" -#include "GUI/Dialogs/TagEditor.hpp" #include "Database/Database.hpp" -#include "Utility/ControlID_Enums.hpp" -#include "Utility/Paths.hpp" -#include "Utility/Tags.hpp" -#include "Utility/Sample.hpp" +#include "Utility/ControlIDs.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 -#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); - - // Initializing Sizers - m_MainSizer = new wxBoxSizer(wxVERTICAL); - - m_TopSizer = new wxBoxSizer(wxVERTICAL); - - m_BottomLeftPanelMainSizer = new wxBoxSizer(wxVERTICAL); - m_TopPanelMainSizer = new wxBoxSizer(wxVERTICAL); - m_BottomRightPanelMainSizer = new wxBoxSizer(wxVERTICAL); - - m_BrowserControlSizer = new wxBoxSizer(wxHORIZONTAL); - 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); - - // Creating top splitter window - m_TopSplitter = new wxSplitterWindow(m_MainPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, - wxSP_NOBORDER | wxSP_LIVE_UPDATE | wxSP_THIN_SASH); - m_TopSplitter->SetMinimumPaneSize(200); - m_TopSplitter->SetSashGravity(0); - - // Top half of TopSplitter window - m_TopPanel = new wxPanel(m_TopSplitter, 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); - - // Left half of the BottomSplitter window - m_BottomLeftPanel = new wxPanel(m_BottomSplitter, wxID_ANY, - wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); - - // 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); - - // Set split direction - m_TopSplitter->SplitHorizontally(m_TopPanel, m_BottomSplitter); - m_BottomSplitter->SplitVertically(m_BottomLeftPanel, m_BottomRightPanel); - - m_TopControlsPanel = new wxPanel(m_TopPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, - wxTAB_TRAVERSAL | wxNO_BORDER); - - // Looping region controls - if (m_Theme.IsDark()) - m_LoopABButton = new wxBitmapToggleButton(m_TopControlsPanel, BC_LoopABButton, - static_cast(ICON_AB_LIGHT_16px), - wxDefaultPosition, wxDefaultSize, 0); - else - m_LoopABButton = new wxBitmapToggleButton(m_TopControlsPanel, BC_LoopABButton, - static_cast(ICON_AB_DARK_16px), - wxDefaultPosition, wxDefaultSize, 0); - - m_LoopABButton->SetToolTip(_("Loop selected region")); - - // Initializing browser controls on top panel. - m_AutoPlayCheck = new wxCheckBox(m_TopControlsPanel, BC_Autoplay, _("Autoplay"), - wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); - m_AutoPlayCheck->SetToolTip(_("Autoplay")); - m_VolumeSlider = new wxSlider(m_TopControlsPanel, BC_Volume, 100, 0, 100, - wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL); - m_VolumeSlider->SetToolTip(_("Volume")); - m_VolumeSlider->SetMinSize(wxSize(120, -1)); - m_VolumeSlider->SetMaxSize(wxSize(120, -1)); - m_SamplePosition = new wxStaticText(m_TopControlsPanel, BC_SamplePosition, "--:--/--:--", - wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL); - - // Initialize browser control buttons - if (m_Theme.IsDark()) - { - m_PlayButton = new wxBitmapButton(m_TopControlsPanel, BC_Play, - wxBitmapBundle::FromBitmap(static_cast - (ICON_PLAY_LIGHT_16px)), - wxDefaultPosition, wxDefaultSize, 0); - m_LoopButton = new wxBitmapToggleButton(m_TopControlsPanel, BC_Loop, - static_cast(ICON_LOOP_LIGHT_16px), - wxDefaultPosition, wxDefaultSize, 0); - m_StopButton = new wxBitmapButton(m_TopControlsPanel, BC_Stop, - wxBitmapBundle::FromBitmap(static_cast - (ICON_STOP_LIGHT_16px)), - wxDefaultPosition, wxDefaultSize, 0); - m_MuteButton = new wxBitmapToggleButton(m_TopControlsPanel, BC_Mute, - static_cast(ICON_MUTE_LIGHT_16px), - wxDefaultPosition, wxDefaultSize, 0); - } - else - { - m_PlayButton = new wxBitmapButton(m_TopControlsPanel, BC_Play, - wxBitmapBundle::FromBitmap(static_cast - (ICON_PLAY_DARK_16px)), - wxDefaultPosition, wxDefaultSize, 0); - m_LoopButton = new wxBitmapToggleButton(m_TopControlsPanel, BC_Loop, - static_cast(ICON_LOOP_DARK_16px), - wxDefaultPosition, wxDefaultSize, 0); - m_StopButton = new wxBitmapButton(m_TopControlsPanel, BC_Stop, - wxBitmapBundle::FromBitmap(static_cast - (ICON_STOP_DARK_16px)), - wxDefaultPosition, wxDefaultSize, 0); - m_MuteButton = new wxBitmapToggleButton(m_TopControlsPanel, BC_Mute, - static_cast(ICON_MUTE_DARK_16px), - wxDefaultPosition, wxDefaultSize, 0); - } - - m_PlayButton->SetToolTip(_("Play")); - m_LoopButton->SetToolTip(_("Loop")); - m_StopButton->SetToolTip(_("Stop")); - m_MuteButton->SetToolTip(_("Mute")); - - m_SettingsButton = new wxButton(m_TopControlsPanel, BC_Settings, _("Settings"), - wxDefaultPosition, wxDefaultSize, 0); - m_SettingsButton->SetToolTip(_("Settings")); - - // 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); - - // Initializing wxMediaCtrl. - m_MediaCtrl = new wxMediaCtrl(this, BC_MediaCtrl, wxEmptyString, wxDefaultPosition, - wxDefaultSize, 0, wxEmptyString); - - // Intializing wxTimer - m_Timer = new wxTimer(this); + SetMenuBar(m_pMenuBar); // Load default yaml config file. LoadConfigFile(); // Initialize the database - try - { - m_Database = std::make_unique(); - m_Database->CreateTableSamples(); - m_Database->CreateTableHives(); - } - catch (std::exception& e) - { - SH_LOG_ERROR("Error! Cannot initialize database {}", e.what()); - } + InitDatabase(); - m_TopWaveformPanel = new WaveformViewer(m_TopPanel, *m_Library, *m_MediaCtrl, *m_Database); + // Initializing Sizers + m_pMainSizer = new wxBoxSizer(wxVERTICAL); + + m_pTopPanelMainSizer = new wxBoxSizer(wxVERTICAL); + + // Creating top splitter window + 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_pTopPanel = new wxPanel(m_pTopSplitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); + + // Bottom half of the TopSplitter window + 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); + + m_pNotebook = new cNotebook(m_pBottomSplitter); + + m_pLibrary = new cLibrary(m_pBottomSplitter); + + 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_pTopSplitter->SplitHorizontally(m_pTopPanel, m_pBottomSplitter); + m_pBottomSplitter->SplitVertically(m_pNotebook, m_pLibrary); + + // Initializing wxMediaCtrl. + m_pMediaCtrl = new wxMediaCtrl(this, SampleHive::ID::BC_MediaCtrl, wxEmptyString, wxDefaultPosition, + wxDefaultSize, 0, wxEmptyString); + + // Intializing wxTimer + m_pTimer = new wxTimer(this); + + 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(wxEVT_BUTTON, &MainFrame::OnClickPlay, this, BC_Play); - Bind(wxEVT_TOGGLEBUTTON, &MainFrame::OnClickLoop, this, BC_Loop); - Bind(wxEVT_BUTTON, &MainFrame::OnClickStop, this, BC_Stop); - Bind(wxEVT_TOGGLEBUTTON, &MainFrame::OnClickMute, this, BC_Mute); - Bind(wxEVT_MEDIA_FINISHED, &MainFrame::OnMediaFinished, this, BC_MediaCtrl); - Bind(wxEVT_BUTTON, &MainFrame::OnClickSettings, this, BC_Settings); - Bind(wxEVT_CHECKBOX, &MainFrame::OnCheckAutoplay, this, BC_Autoplay); - Bind(wxEVT_SCROLL_THUMBTRACK, &MainFrame::OnSlideVolume, this, BC_Volume); - Bind(wxEVT_SCROLL_THUMBRELEASE, &MainFrame::OnReleaseVolumeSlider, this, BC_Volume); + Bind(wxEVT_TIMER, &cMainFrame::UpdateElapsedTime, this); - 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_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_MainPanel, 1, wxALL | wxEXPAND, 0); + m_pMainSizer->Add(m_pTopSplitter, 1, wxALL | wxEXPAND, 0); - m_TopSizer->Add(m_TopSplitter, 1, wxALL | wxEXPAND, 0); - - m_BrowserControlSizer->Add(m_PlayButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); - m_BrowserControlSizer->Add(m_StopButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); - m_BrowserControlSizer->Add(m_LoopButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); - m_BrowserControlSizer->Add(m_LoopABButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); - m_BrowserControlSizer->Add(m_SettingsButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); - m_BrowserControlSizer->Add(0,0,1, wxALL | wxEXPAND, 0); - m_BrowserControlSizer->Add(m_SamplePosition, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); - m_BrowserControlSizer->Add(30,0,0, wxALL | wxEXPAND, 0); - m_BrowserControlSizer->Add(m_MuteButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); - m_BrowserControlSizer->Add(m_VolumeSlider, 1, wxALL | wxALIGN_CENTER_VERTICAL, 2); - m_BrowserControlSizer->Add(m_AutoPlayCheck, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); - - m_TopPanelMainSizer->Add(m_TopWaveformPanel, 1, wxALL | wxEXPAND, 2); - m_TopPanelMainSizer->Add(m_TopControlsPanel, 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_TopControlsPanel->SetSizer(m_BrowserControlSizer); - m_BrowserControlSizer->Fit(m_TopControlsPanel); - m_BrowserControlSizer->SetSizeHints(m_TopControlsPanel); - m_BrowserControlSizer->Layout(); - - m_TopWaveformPanel->SetSizer(m_WaveformDisplaySizer); - m_WaveformDisplaySizer->Fit(m_TopWaveformPanel); - m_WaveformDisplaySizer->SetSizeHints(m_TopWaveformPanel); - 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_BottomLeftPanel->SetSizer(m_BottomLeftPanelMainSizer); - m_BottomLeftPanelMainSizer->Fit(m_BottomLeftPanel); - m_BottomLeftPanelMainSizer->SetSizeHints(m_BottomLeftPanel); - 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(); // Set some properites after the frame has been created - CallAfter(&MainFrame::SetAfterFrameCreate); + CallAfter(&cMainFrame::SetAfterFrameCreate); } -void MainFrame::OnClickSettings(wxCommandEvent& event) +void cMainFrame::OnMediaFinished(wxMediaEvent& event) { - Settings* settings = new Settings(this); - - switch (settings->ShowModal()) + if (m_pTransportControls->CanLoop()) { - case wxID_OK: - if (settings->CanAutoImport()) - { - OnAutoImportDir(settings->GetImportDirPath()); - RefreshDatabase(); - } - if (settings->IsWaveformColourChanged()) - { - m_TopWaveformPanel->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::OnClickPlay(wxCommandEvent& event) -{ - bStopped = false; - - int selected_row = m_Library->GetSelectedRow(); - - if (selected_row < 0) - return; - - wxString selection = m_Library->GetTextValue(selected_row, 1); - - wxString sample_path = GetFilenamePathAndExtension(selection).Path; - - if (bLoopPointsSet && m_LoopABButton->GetValue()) - PlaySample(sample_path.ToStdString(), selection.ToStdString(), true, m_LoopA.ToDouble(), wxFromStart); - else - PlaySample(sample_path.ToStdString(), selection.ToStdString()); -} - -void MainFrame::OnClickLoop(wxCommandEvent& event) -{ - Serializer serializer; - - bLoop = m_LoopButton->GetValue(); - - serializer.SerializeMediaOptions("loop", bLoop); -} - -void MainFrame::OnClickStop(wxCommandEvent& event) -{ - m_MediaCtrl->Stop(); - - bStopped = true; - - if (m_Timer->IsRunning()) - m_Timer->Stop(); - - m_SamplePosition->SetLabel("--:--/--:--"); - - this->SetStatusText(_("Stopped"), 1); -} - -void MainFrame::OnClickMute(wxCommandEvent& event) -{ - Serializer serializer; - - if (m_MuteButton->GetValue()) - { - m_MediaCtrl->SetVolume(0.0); - bMuted = true; - - serializer.SerializeMediaOptions("muted", bMuted); - } - else - { - m_MediaCtrl->SetVolume(double(m_VolumeSlider->GetValue()) / 100); - bMuted = false; - - serializer.SerializeMediaOptions("muted", bMuted); - } -} - -void MainFrame::OnMediaFinished(wxMediaEvent& event) -{ - if (bLoop) - { - 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_SamplePosition->SetLabel("--:--/--:--"); + 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_SamplePosition->SetLabel(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())); - m_TopControlsPanel->Refresh(); - m_TopWaveformPanel->Refresh(); + this->Refresh(); + m_pTransportControls->Refresh(); + m_pWaveformViewer->Refresh(); - if (bLoopPointsSet && m_LoopABButton->GetValue()) - 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::OnCheckAutoplay(wxCommandEvent& event) +void cMainFrame::LoadDatabase() { - Serializer serializer; - - if (m_AutoPlayCheck->GetValue()) - { - bAutoplay = true; - - serializer.SerializeMediaOptions("autoplay", bAutoplay); - } - else - { - bAutoplay = false; - - serializer.SerializeMediaOptions("autoplay", bAutoplay); - } -} - -void MainFrame::OnSlideVolume(wxScrollEvent& event) -{ - m_MediaCtrl->SetVolume(double(m_VolumeSlider->GetValue()) / 100); - - PushStatusText(wxString::Format(_("Volume: %d"), m_VolumeSlider->GetValue()), 1); -} - -void MainFrame::OnReleaseVolumeSlider(wxScrollEvent& event) -{ - Serializer serializer; - - serializer.SerializeMediaVolume(m_VolumeSlider->GetValue()); - - int selected_row = m_Library->GetSelectedRow(); - - if (selected_row < 0) - return; - - wxString selection = m_Library->GetTextValue(selected_row, 1); - - // Wait a second then remove the status from statusbar - wxSleep(1); - PopStatusText(1); - - if (m_MediaCtrl->GetState() == wxMEDIASTATE_STOPPED) - this->SetStatusText(_("Stopped"), 1); - else - PushStatusText(wxString::Format(_("Now playing: %s"), selection), 1); -} - -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_TopWaveformPanel->ResetDC(); - - m_LoopABButton->SetValue(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 (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(); - } - 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; + SampleHive::cSerializer serializer; try { - const auto dataset = m_Database->LoadSamplesDatabase(*m_Hives, favorites_hive, - *m_Trash, trash_root, + 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); @@ -2076,502 +279,44 @@ void MainFrame::LoadDatabase() else { for (auto data : dataset) - m_Library->AppendItem(data); + SampleHive::cHiveData::Get().ListCtrlAppendItem(data); } - m_Database->LoadHivesDatabase(*m_Hives); + m_pDatabase->LoadHivesDatabase(*m_pNotebook->GetHivesPanel()->GetHivesObject()); } - catch(...) + catch (std::exception& e) { - std::cerr << "Error loading data." << std::endl; + SH_LOG_ERROR("Error loading data. {}", e.what()); } } -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::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)) @@ -2584,42 +329,29 @@ 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.."); int height = 600, width = 800; - bAutoplay = serializer.DeserializeMediaOptions("autoplay"); - bLoop = serializer.DeserializeMediaOptions("loop"); - bMuted = serializer.DeserializeMediaOptions("muted"); - - m_AutoPlayCheck->SetValue(bAutoplay); - m_LoopButton->SetValue(bLoop); - m_MuteButton->SetValue(bMuted); - - m_VolumeSlider->SetValue(serializer.DeserializeMediaVolume()); - - if (!bMuted) - m_MediaCtrl->SetVolume(double(m_VolumeSlider->GetValue()) / 100); - else - m_MediaCtrl->SetVolume(0.0); - width = serializer.DeserializeWinSize().first; height = serializer.DeserializeWinSize().second; 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); @@ -2631,40 +363,41 @@ void MainFrame::LoadConfigFile() this->SetStatusText(_("Stopped"), 1); } -void MainFrame::RefreshDatabase() +// void cMainFrame::RefreshDatabase() +// { +// m_pLibrary->GetListCtrlObject()->DeleteAllItems(); + +// 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_pNotebook->GetHivesPanel()->GetHivesObject()->DeleteAllItems(); + +// m_pNotebook->GetTrashPanel()->GetTrashObject()->DeleteAllItems(); + +// LoadDatabase(); +// } + +bool cMainFrame::CreateWatcherIfNecessary() { - m_Library->DeleteAllItems(); - - if (m_Hives->GetChildCount(wxDataViewItem(wxNullPtr)) < 1 && - m_Hives->GetItemText(wxDataViewItem(wxNullPtr)) == m_Hives->GetItemText(favorites_hive)) - return; - else - m_Hives->DeleteAllItems(); - - m_Trash->DeleteAllItems(); - - LoadDatabase(); -} - -bool MainFrame::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; @@ -2679,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()) { @@ -2691,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"); @@ -2713,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; @@ -2731,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()); @@ -2748,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); @@ -2773,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, @@ -2821,7 +521,7 @@ void MainFrame::OnSelectAddFile(wxCommandEvent& event) file_dialog.GetPaths(paths); for (size_t i = 0; i < (size_t)paths.size(); i++) - AddSamples(paths); + SampleHive::cUtils::Get().AddSamples(paths, this); } break; default: @@ -2829,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); @@ -2840,7 +540,7 @@ void MainFrame::OnSelectAddDirectory(wxCommandEvent& event) { wxString path = dir_dialog.GetPath(); - OnAutoImportDir(path); + SampleHive::cUtils::Get().OnAutoImportDir(path, this); } break; default: @@ -2848,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()); - RefreshDatabase(); + SampleHive::cUtils::Get().OnAutoImportDir(settings->GetImportDirPath(), this); + // RefreshDatabase(); } if (settings->IsWaveformColourChanged()) { - m_TopWaveformPanel->ResetDC(); + m_pWaveformViewer->ResetDC(); } break; case wxID_CANCEL: @@ -2943,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; @@ -2988,10 +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: @@ -3001,7 +702,7 @@ void MainFrame::OnSelectResetAppData(wxCommandEvent& event) } } -void MainFrame::OnSelectAbout(wxCommandEvent& event) +void cMainFrame::OnSelectAbout(wxCommandEvent& event) { wxAboutDialogInfo aboutInfo; @@ -3014,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()); @@ -3059,33 +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_pTopSplitter->SetSashPosition(serializer.DeserializeSplitterSashPos("top")); + m_pBottomSplitter->SetSashPosition(serializer.DeserializeSplitterSashPos("bottom")); } -void MainFrame::OnRecieveLoopPoints(SampleHive::SH_LoopPointsEvent& event) +void cMainFrame::OnRecieveLoopPoints(SampleHive::cLoopPointsEvent& event) { std::pair loop_points = event.GetLoopPoints(); @@ -3097,83 +797,142 @@ void MainFrame::OnRecieveLoopPoints(SampleHive::SH_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_LoopABButton->SetValue(true); + m_pTransportControls->SetLoopABValue(true); - bLoopPointsSet = true; + m_bLoopPointsSet = true; } -void MainFrame::OnRecievePushStatusBarStatus(SampleHive::SH_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::SH_StatusBarStatusEvent& event) +void cMainFrame::OnRecievePopStatusBarStatus(SampleHive::cStatusBarStatusEvent& event) { - m_StatusBar->PopStatusText(event.GetPopMessageSection()); + m_pStatusBar->PopStatusText(event.GetPopMessageSection()); } -void MainFrame::OnRecieveSetStatusBarStatus(SampleHive::SH_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::SH_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::SH_TimerEvent& event) +void cMainFrame::OnRecieveTimerStopStatus(SampleHive::cTimerEvent& event) { - if (m_Timer->IsRunning()) - m_Timer->Stop(); + if (m_pTimer->IsRunning()) + m_pTimer->Stop(); } -void MainFrame::ClearLoopPoints() +void cMainFrame::OnRecieveCallFunctionPlay(SampleHive::cCallFunctionEvent& event) +{ + SampleHive::cSerializer serializer; + + wxString selection = event.GetSlection(); + bool checkAutoplay = event.GetAutoplayValue(); + + wxString sample_path = serializer.DeserializeShowFileExtension() ? + m_pDatabase->GetSamplePathByFilename(selection.BeforeLast('.').ToStdString()) : + m_pDatabase->GetSamplePathByFilename(selection.ToStdString()); + + 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 + { + 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 cMainFrame::OnRecieveWaveformUpdateStatus(SampleHive::cWaveformUpdateEvent& event) +{ + m_pWaveformViewer->ResetDC(); +} + +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."); } -MainFrame::~MainFrame() +void cMainFrame::InitDatabase() +{ + // Initialize the database + try + { + m_pDatabase = std::make_unique(); + m_pDatabase->CreateTableSamples(); + m_pDatabase->CreateTableHives(); + } + catch (std::exception& e) + { + SH_LOG_ERROR("Error! Cannot initialize database {}", e.what()); + } +} + +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 eb53aa2..4f4a853 100644 --- a/src/GUI/MainFrame.hpp +++ b/src/GUI/MainFrame.hpp @@ -20,227 +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 "SampleHiveConfig.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; - WaveformViewer* m_TopWaveformPanel; - wxPanel* m_TopControlsPanel; - wxBoxSizer* m_TopSizer; - wxBoxSizer* m_TopPanelMainSizer; - wxBoxSizer* m_WaveformDisplaySizer; - wxBoxSizer* m_BrowserControlSizer; - wxBitmapButton* m_PlayButton; - wxBitmapToggleButton* m_LoopButton; - wxBitmapButton* m_StopButton; - wxButton* m_SettingsButton; - wxBitmapToggleButton* m_MuteButton; - wxBitmapToggleButton* m_LoopABButton; - wxStaticText* m_SamplePosition; - wxSlider* m_VolumeSlider; - wxCheckBox* m_AutoPlayCheck; - - // ------------------------------------------------------------------- - // Left panel controls - wxPanel* m_BottomLeftPanel; - 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 - 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 bAutoplay = false; - bool bLoop = false; - bool bMuted = false; - bool bStopped = false; - bool bFiltered = false; - bool bShowMenuBar = false; - bool bShowStatusBar = false; - bool bLoopPointsSet = false; + cMainFrame(); + ~cMainFrame(); private: // ------------------------------------------------------------------- // Top panel control handlers - void OnClickPlay(wxCommandEvent& event); - void OnClickLoop(wxCommandEvent& event); - void OnClickStop(wxCommandEvent& event); - void OnClickMute(wxCommandEvent& event); void OnMediaFinished(wxMediaEvent& event); - void OnCheckAutoplay(wxCommandEvent& event); - void OnSlideVolume(wxScrollEvent& event); - void OnReleaseVolumeSlider(wxScrollEvent& 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 @@ -270,32 +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::SH_LoopPointsEvent& event); - void OnRecievePushStatusBarStatus(SampleHive::SH_StatusBarStatusEvent& event); - void OnRecievePopStatusBarStatus(SampleHive::SH_StatusBarStatusEvent& event); - void OnRecieveSetStatusBarStatus(SampleHive::SH_StatusBarStatusEvent& event); - void OnRecieveInfoBarStatus(SampleHive::SH_InfoBarMessageEvent& event); - void OnRecieveTimerStopStatus(SampleHive::SH_TimerEvent& 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 LoadConfigFile(); - - // ------------------------------------------------------------------- - // Getters - FileInfo GetFilenamePathAndExtension(const wxString& selected, - bool checkExtension = true, bool doGetFilename = true) const; + // void RefreshDatabase(); // ------------------------------------------------------------------- // Directory watchers @@ -304,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(); @@ -314,5 +120,82 @@ class MainFrame : public wxFrame void ClearLoopPoints(); // ------------------------------------------------------------------- - friend class App; + void InitDatabase(); + + // ------------------------------------------------------------------- + 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 new file mode 100644 index 0000000..8ac6958 --- /dev/null +++ b/src/GUI/Notebook.cpp @@ -0,0 +1,53 @@ +/* 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" +#include "GUI/Trash.hpp" + +cNotebook::cNotebook(wxWindow* window) + : wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL) +{ + m_pNotebook = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_TOP); + + m_DirectoryBrowser = new cDirectoryBrowser(m_pNotebook); + m_HivesPanel = new cHivesPanel(m_pNotebook); + m_TrashPanel = new cTrashPanel(m_pNotebook); + + // Adding the pages to wxNotebook + m_pNotebook->AddPage(m_DirectoryBrowser, _("Browse"), false); + m_pNotebook->AddPage(m_HivesPanel, _("Hives"), false); + m_pNotebook->AddPage(m_TrashPanel, _("Trash"), false); + + m_pSizer = new wxBoxSizer(wxVERTICAL); + + m_pSizer->Add(m_pNotebook, wxSizerFlags(1).Expand()); + + this->SetSizer(m_pSizer); + m_pSizer->Fit(this); + m_pSizer->SetSizeHints(this); + m_pSizer->Layout(); +} + +cNotebook::~cNotebook() +{ + +} diff --git a/src/GUI/Notebook.hpp b/src/GUI/Notebook.hpp new file mode 100644 index 0000000..21fa98a --- /dev/null +++ b/src/GUI/Notebook.hpp @@ -0,0 +1,53 @@ +/* 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" +#include "GUI/Hives.hpp" +#include "GUI/Trash.hpp" + +#include +#include +#include +#include + +class cNotebook : public wxPanel +{ + public: + // ------------------------------------------------------------------- + cNotebook(wxWindow* window); + ~cNotebook(); + + // ------------------------------------------------------------------- + cDirectoryBrowser* GetDirectoryBrowser() const { return m_DirectoryBrowser; } + cHivesPanel* GetHivesPanel() const { return m_HivesPanel; } + cTrashPanel* GetTrashPanel() const { return m_TrashPanel; } + + private: + // ------------------------------------------------------------------- + wxNotebook* m_pNotebook = nullptr; + wxBoxSizer* m_pSizer = nullptr; + + // ------------------------------------------------------------------- + cDirectoryBrowser* m_DirectoryBrowser = nullptr; + cHivesPanel* m_HivesPanel = nullptr; + cTrashPanel* m_TrashPanel = nullptr; +}; diff --git a/src/GUI/SearchBar.cpp b/src/GUI/SearchBar.cpp new file mode 100644 index 0000000..3626e1f --- /dev/null +++ b/src/GUI/SearchBar.cpp @@ -0,0 +1,92 @@ +/* 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" + +#include + +cSearchBar::cSearchBar(wxWindow* window) + : wxSearchCtrl(window, SampleHive::ID::BC_Search, _("Search for samples.."), + wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER), + m_pWindow(window) +{ + // Set minimum and maximum size of m_SearchBox + // so it doesn't expand too wide when resizing the main frame. + SetMinSize(wxSize(-1, 38)); + SetMaxSize(wxSize(-1, 38)); + + ShowSearchButton(true); + ShowCancelButton(true); + + 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) +{ + SampleHive::cSerializer serializer; + cDatabase db; + + const auto search = this->GetValue().ToStdString(); + + try + { + const auto dataset = db.FilterDatabaseBySampleName(search, serializer.DeserializeShowFileExtension(), + ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px); + + if (dataset.empty()) + { + SH_LOG_INFO("Error! Database is empty."); + } + else + { + SampleHive::cHiveData::Get().ListCtrlDeleteAllItems(); + + std::cout << search << std::endl; + + for (const auto& data : dataset) + { + SampleHive::cHiveData::Get().ListCtrlAppendItem(data); + } + } + } + catch (std::exception& e) + { + SH_LOG_ERROR("Error loading data. {}", e.what()); + } +} + +void cSearchBar::OnCancelSearch(wxCommandEvent& event) +{ + this->Clear(); +} + +cSearchBar::~cSearchBar() +{ + +} diff --git a/src/GUI/SearchBar.hpp b/src/GUI/SearchBar.hpp new file mode 100644 index 0000000..d6988c5 --- /dev/null +++ b/src/GUI/SearchBar.hpp @@ -0,0 +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 . + */ + +#pragma once + +#include +#include + +class cSearchBar : public wxSearchCtrl +{ + public: + cSearchBar(wxWindow* window); + ~cSearchBar(); + + public: + wxSearchCtrl* GetSearchCtrlObject() { return this; } + + private: + // ------------------------------------------------------------------- + // SearchCtrl event handlers + void OnDoSearch(wxCommandEvent& event); + void OnCancelSearch(wxCommandEvent& event); + + private: + // ------------------------------------------------------------------- + wxWindow* m_pWindow = nullptr; +}; diff --git a/src/GUI/TransportControls.cpp b/src/GUI/TransportControls.cpp new file mode 100644 index 0000000..84ee5b3 --- /dev/null +++ b/src/GUI/TransportControls.cpp @@ -0,0 +1,298 @@ +/* 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/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" + +#include + +cTransportControls::cTransportControls(wxWindow* window, wxMediaCtrl& mediaCtrl) + : wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxNO_BORDER), + m_MediaCtrl(mediaCtrl) +{ + m_pMainSizer = new wxBoxSizer(wxHORIZONTAL); + + // Looping region controls + if (m_Theme.IsDark()) + m_pLoopABButton = new wxBitmapToggleButton(this, SampleHive::ID::BC_LoopABButton, + wxBitmapBundle::FromBitmap(static_cast(ICON_AB_LIGHT_16px)), + wxDefaultPosition, wxDefaultSize, 0); + else + m_pLoopABButton = new wxBitmapToggleButton(this, SampleHive::ID::BC_LoopABButton, + wxBitmapBundle::FromBitmap(static_cast(ICON_AB_DARK_16px)), + wxDefaultPosition, wxDefaultSize, 0); + + m_pLoopABButton->SetToolTip(_("Loop selected region")); + + // Autoplay checkbox + 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, 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, SampleHive::ID::BC_SamplePosition, "--:--/--:--", + wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL); + + // Transport control buttons + if (m_Theme.IsDark()) + { + 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, SampleHive::ID::BC_Loop, + wxBitmapBundle::FromBitmap(static_cast(ICON_LOOP_LIGHT_16px)), + wxDefaultPosition, wxDefaultSize, 0); + 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, SampleHive::ID::BC_Mute, + wxBitmapBundle::FromBitmap(static_cast(ICON_MUTE_LIGHT_16px)), + wxDefaultPosition, wxDefaultSize, 0); + } + else + { + 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, SampleHive::ID::BC_Loop, + wxBitmapBundle::FromBitmap(static_cast(ICON_LOOP_DARK_16px)), + wxDefaultPosition, wxDefaultSize, 0); + 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, SampleHive::ID::BC_Mute, + wxBitmapBundle::FromBitmap(static_cast(ICON_MUTE_DARK_16px)), + wxDefaultPosition, wxDefaultSize, 0); + } + + m_pPlayButton->SetToolTip(_("Play")); + m_pLoopButton->SetToolTip(_("Loop")); + m_pStopButton->SetToolTip(_("Stop")); + m_pMuteButton->SetToolTip(_("Mute")); + + 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(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); + m_pMainSizer->Add(m_pMuteButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); + m_pMainSizer->Add(m_pVolumeSlider, 1, wxALL | wxALIGN_CENTER_VERTICAL, 2); + m_pMainSizer->Add(m_pAutoPlayCheck, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); + + this->SetSizer(m_pMainSizer); + m_pMainSizer->Fit(this); + m_pMainSizer->SetSizeHints(this); + m_pMainSizer->Layout(); + + 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 = SampleHive::cHiveData::Get().GetListCtrlSelectedRow(); + + if (selected_row < 0) + return; + + wxString selection = SampleHive::cHiveData::Get().GetListCtrlTextValue(selected_row, 1); + + // Send custom event to MainFrame to play the sample + SampleHive::cSignal::SendCallFunctionPlay(selection, false, *this); +} + +void cTransportControls::OnClickLoop(wxCommandEvent& event) +{ + SampleHive::cSerializer serializer; + + m_bLoop = m_pLoopButton->GetValue(); + + serializer.SerializeMediaOptions("loop", m_bLoop); +} + +void cTransportControls::OnClickStop(wxCommandEvent& event) +{ + if (!m_MediaCtrl.Stop()) + SH_LOG_ERROR("Error! Unable to stop media."); + + m_bStopped = true; + + // Send custom event to MainFrame to stop the timer + SampleHive::cSignal::SendTimerStopStatus(*this); + + m_pSamplePosition->SetLabel("--:--/--:--"); + + // Send custom event to MainFrame to set the statusbar status + SampleHive::cSignal::SendSetStatusBarStatus(_("Stopped"), 1, *this); +} + +void cTransportControls::OnClickMute(wxCommandEvent& event) +{ + SampleHive::cSerializer serializer; + + if (m_pMuteButton->GetValue()) + { + m_MediaCtrl.SetVolume(0.0); + m_bMuted = true; + + serializer.SerializeMediaOptions("muted", m_bMuted); + } + else + { + m_MediaCtrl.SetVolume(double(m_pVolumeSlider->GetValue()) / 100); + m_bMuted = false; + + serializer.SerializeMediaOptions("muted", m_bMuted); + } +} + +void cTransportControls::OnCheckAutoplay(wxCommandEvent& event) +{ + SampleHive::cSerializer serializer; + + if (m_pAutoPlayCheck->GetValue()) + { + m_bAutoplay = true; + + serializer.SerializeMediaOptions("autoplay", m_bAutoplay); + } + else + { + m_bAutoplay = false; + + serializer.SerializeMediaOptions("autoplay", m_bAutoplay); + } +} + +void cTransportControls::OnSlideVolume(wxScrollEvent& event) +{ + m_MediaCtrl.SetVolume(double(m_pVolumeSlider->GetValue()) / 100); + + // Send custom event to MainFrame to push status to statusbar + SampleHive::cSignal::SendPushStatusBarStatus(wxString::Format(_("Volume: %d"), m_pVolumeSlider->GetValue()), 1, *this); +} + +void cTransportControls::OnReleaseVolumeSlider(wxScrollEvent& event) +{ + SampleHive::cSerializer serializer; + + serializer.SerializeMediaVolume(m_pVolumeSlider->GetValue()); + + int selected_row = SampleHive::cHiveData::Get().GetListCtrlSelectedRow(); + + if (selected_row < 0) + return; + + 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::cSignal::SendPopStatusBarStatus(1, *this); + + if (m_MediaCtrl.GetState() == wxMEDIASTATE_STOPPED) + SampleHive::cSignal::SendSetStatusBarStatus(_("Stopped"), 1, *this); + else + SampleHive::cSignal::SendPushStatusBarStatus(wxString::Format(_("Now playing: %s"), selection), 1, *this); +} + +void cTransportControls::LoadConfigFile() +{ + SampleHive::cSerializer serializer; + + SH_LOG_INFO("Reading transport control values.."); + + m_bAutoplay = serializer.DeserializeMediaOptions("autoplay"); + m_bLoop = serializer.DeserializeMediaOptions("loop"); + m_bMuted = serializer.DeserializeMediaOptions("muted"); + + m_pAutoPlayCheck->SetValue(m_bAutoplay); + m_pLoopButton->SetValue(m_bLoop); + m_pMuteButton->SetValue(m_bMuted); + + m_pVolumeSlider->SetValue(serializer.DeserializeMediaVolume()); + + if (!m_bMuted) + m_MediaCtrl.SetVolume(double(m_pVolumeSlider->GetValue()) / 100); + else + m_MediaCtrl.SetVolume(0.0); +} + +cTransportControls::~cTransportControls() +{ + +} diff --git a/src/GUI/TransportControls.hpp b/src/GUI/TransportControls.hpp new file mode 100644 index 0000000..5891dbe --- /dev/null +++ b/src/GUI/TransportControls.hpp @@ -0,0 +1,117 @@ +/* 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 +#include +#include +#include +#include +#include +#include + +class cTransportControls : public wxPanel +{ + public: + // ------------------------------------------------------------------- + cTransportControls(wxWindow* window, wxMediaCtrl& mediaCtrl); + ~cTransportControls(); + + public: + // ------------------------------------------------------------------- + bool IsLoopABOn() const { return m_pLoopABButton->GetValue(); } + + // ------------------------------------------------------------------- + inline bool CanAutoplay() const { return m_bAutoplay; }; + inline bool CanLoop() const { return m_bLoop; }; + inline bool IsMuted() const { return m_bMuted; }; + inline bool IsStopped() const { return m_bStopped; }; + + // ------------------------------------------------------------------- + void SetLoopABValue(bool value) { m_pLoopABButton->SetValue(value); } + + // ------------------------------------------------------------------- + void SetCanAutoplay(bool autoplay) { m_bAutoplay = autoplay; } + void SetCanLoop(bool loop) { m_bLoop = loop; } + void SetIsMuted(bool muted) { m_bMuted = muted; } + void SetIsStopped(bool stopped) { m_bStopped = stopped; } + + // ------------------------------------------------------------------- + inline wxString GetSamplePositionText() const { return m_pSamplePosition->GetLabelText(); } + + // ------------------------------------------------------------------- + void SetSamplePositionText(const wxString& text) { m_pSamplePosition->SetLabel(text); } + + private: + // ------------------------------------------------------------------- + // Event handlers + void OnClickPlay(wxCommandEvent& event); + void OnClickLoop(wxCommandEvent& event); + void OnClickStop(wxCommandEvent& event); + void OnClickMute(wxCommandEvent& event); + void OnClickSettings(wxCommandEvent& event); + void OnCheckAutoplay(wxCommandEvent& event); + void OnSlideVolume(wxScrollEvent& event); + void OnReleaseVolumeSlider(wxScrollEvent& event); + + private: + // ------------------------------------------------------------------- + // Load control values from config file + void LoadConfigFile(); + + void OnAutoImportDir(const wxString& pathToDirectory); + + private: + // ------------------------------------------------------------------- + wxMediaCtrl& m_MediaCtrl; + + private: + // ------------------------------------------------------------------- + bool m_bAutoplay = false; + bool m_bLoop = false; + bool m_bMuted = false; + bool m_bStopped = false; + + private: + // ------------------------------------------------------------------- + wxBitmapButton* m_pPlayButton = nullptr; + wxBitmapToggleButton* m_pLoopButton = nullptr; + wxBitmapButton* m_pStopButton = nullptr; + wxButton* m_pSettingsButton = nullptr; + wxBitmapToggleButton* m_pMuteButton = nullptr; + wxBitmapToggleButton* m_pLoopABButton = nullptr; + wxStaticText* m_pSamplePosition = nullptr; + wxSlider* m_pVolumeSlider = nullptr; + wxCheckBox* m_pAutoPlayCheck = nullptr; + + // ------------------------------------------------------------------- + wxBoxSizer* m_pMainSizer = nullptr; + + private: + // ------------------------------------------------------------------- + wxSystemAppearance m_Theme = wxSystemSettings::GetAppearance(); +}; diff --git a/src/GUI/Trash.cpp b/src/GUI/Trash.cpp new file mode 100644 index 0000000..37a5598 --- /dev/null +++ b/src/GUI/Trash.cpp @@ -0,0 +1,307 @@ +/* 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 "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) + : wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL), + m_pWindow(window) +{ + m_pMainSizer = new wxBoxSizer(wxVERTICAL); + m_pTrashSizer = new wxBoxSizer(wxVERTICAL); + m_pButtonSizer = new wxBoxSizer(wxHORIZONTAL); + + 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 + m_pTrash->DragAcceptFiles(true); + + m_pTrashSizer->Add(m_pTrash, wxSizerFlags(1).Expand()); + + m_pRestoreTrashedItemButton = new wxButton(this, SampleHive::ID::BC_RestoreTrashedItem, _("Restore sample"), + wxDefaultPosition, wxDefaultSize, 0); + m_pRestoreTrashedItemButton->SetToolTip(_("Restore selected sample")); + + m_pButtonSizer->Add(m_pRestoreTrashedItemButton, wxSizerFlags(1).Expand()); + + // Addubg root to TrashedItems + 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, 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()); + + // Sizer for trash pane + this->SetSizer(m_pMainSizer); + m_pMainSizer->Fit(this); + m_pMainSizer->SetSizeHints(this); + m_pMainSizer->Layout(); +} + +void cTrashPanel::OnDragAndDropToTrash(wxDropFilesEvent& event) +{ + SampleHive::cSerializer serializer; + cDatabase db; + + if (event.GetNumberOfFiles() > 0) + { + wxFileDataObject file_data; + wxArrayString files; + + wxDataViewItemArray items; + int rows = SampleHive::cHiveData::Get().GetListCtrlSelections(items); + + wxString msg; + + wxDataViewItem root = wxDataViewItem(wxNullPtr); + wxDataViewItem container, child; + + for (int i = 0; i < rows; i++) + { + int item_row = SampleHive::cHiveData::Get().GetListCtrlRowFromItem(items, i); + + wxString text_value = SampleHive::cHiveData::Get().GetListCtrlTextValue(item_row, 1); + + std::string multi_selection = serializer.DeserializeShowFileExtension() ? + SampleHive::cHiveData::Get().GetListCtrlTextValue(item_row, 1).BeforeLast('.').ToStdString() : + SampleHive::cHiveData::Get().GetListCtrlTextValue(item_row, 1).ToStdString() ; + + file_data.AddFile(multi_selection); + + files = file_data.GetFilenames(); + + if (db.GetFavoriteColumnValueByFilename(files[i].ToStdString())) + { + SampleHive::cHiveData::Get().ListCtrlSetVariant(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), item_row, 0); + + db.UpdateFavoriteColumn(files[i].ToStdString(), 0); + + for (int j = 0; j < SampleHive::cHiveData::Get().GetHiveChildCount(root); j++) + { + container = SampleHive::cHiveData::Get().GetHiveNthChild(root, j); + + for (int k = 0; k < SampleHive::cHiveData::Get().GetHiveChildCount(container); k++) + { + child = SampleHive::cHiveData::Get().GetHiveNthChild(container, k); + + wxString child_text = serializer.DeserializeShowFileExtension() ? + SampleHive::cHiveData::Get().GetHiveItemText(child).BeforeLast('.') : + SampleHive::cHiveData::Get().GetHiveItemText(child); + + if (child_text == files[i]) + { + SampleHive::cHiveData::Get().HiveDeleteItem(child); + break; + } + } + } + } + + db.UpdateTrashColumn(files[i].ToStdString(), 1); + db.UpdateHiveName(files[i].ToStdString(), + SampleHive::cHiveData::Get().GetHiveItemText(SampleHive::cHiveData::Get().GetFavoritesHive()).ToStdString()); + + m_pTrash->AppendItem(m_TrashRoot, text_value); + + SampleHive::cHiveData::Get().ListCtrlDeleteItem(item_row); + + msg = wxString::Format(_("%s sent to trash"), text_value); + } + + if (!msg.IsEmpty()) + SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_ERROR, *this); + } +} + +void cTrashPanel::OnShowTrashContextMenu(wxTreeEvent& event) +{ + SampleHive::cSerializer serializer; + cDatabase db; + + wxTreeItemId selected_trashed_item = event.GetItem(); + + wxMenu menu; + + 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 SampleHive::ID::MN_DeleteTrash: + { + wxString trashed_item_name = serializer.DeserializeShowFileExtension() ? + m_pTrash->GetItemText(selected_trashed_item).BeforeLast('.') : + m_pTrash->GetItemText(selected_trashed_item); + + db.RemoveSampleFromDatabase(trashed_item_name.ToStdString()); + + m_pTrash->Delete(selected_trashed_item); + + SH_LOG_INFO("{} deleted from trash and databse", trashed_item_name); + } + break; + case SampleHive::ID::MN_RestoreTrashedItem: + { + wxArrayTreeItemIds selected_item_ids; + m_pTrash->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_pTrash->GetItemText(selected_item_ids[i]); + + filename = SampleHive::cUtils::Get().GetFilenamePathAndExtension(selected_item_text).Filename; + + file_data.AddFile(filename); + + files = file_data.GetFilenames(); + + db.UpdateTrashColumn(files[i].ToStdString(), 0); + + try + { + wxVector> dataset; + + if (db.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) + { + SampleHive::cHiveData::Get().ListCtrlAppendItem(data); + } + } + } + catch (std::exception& e) + { + SH_LOG_ERROR("Error loading data. {}", e.what()); + } + + m_pTrash->Delete(selected_item_ids[i]); + + SH_LOG_INFO("{} restored from trash", files[i]); + } + } + break; + default: + break; + } + } +} + +void cTrashPanel::OnClickRestoreTrashItem(wxCommandEvent& event) +{ + SampleHive::cSerializer serializer; + cDatabase db; + + wxArrayTreeItemIds selected_item_ids; + m_pTrash->GetSelections(selected_item_ids); + + wxFileDataObject file_data; + wxArrayString files; + + wxString selected_item_text; + std::string filename; + + if (m_pTrash->GetChildrenCount(m_TrashRoot) == 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_pTrash->GetItemText(selected_item_ids[i]); + + filename = SampleHive::cUtils::Get().GetFilenamePathAndExtension(selected_item_text).Filename; + + file_data.AddFile(filename); + + files = file_data.GetFilenames(); + + db.UpdateTrashColumn(files[i].ToStdString(), 0); + + try + { + wxVector> dataset; + + if (db.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) + { + SampleHive::cHiveData::Get().ListCtrlAppendItem(data); + } + } + } + catch (std::exception& e) + { + SH_LOG_ERROR("Error loading data. {}", e.what()); + } + + m_pTrash->Delete(selected_item_ids[i]); + } +} + +cTrashPanel::~cTrashPanel() +{ + +} diff --git a/src/GUI/Trash.hpp b/src/GUI/Trash.hpp new file mode 100644 index 0000000..ce53ddb --- /dev/null +++ b/src/GUI/Trash.hpp @@ -0,0 +1,58 @@ +/* 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 + +class cTrashPanel : public wxPanel +{ + public: + cTrashPanel(wxWindow* window); + ~cTrashPanel(); + + public: + wxTreeCtrl* GetTrashObject() { return m_pTrash; } + wxTreeItemId& GetTrashRoot() { return m_TrashRoot; } + + private: + // ------------------------------------------------------------------- + // TrashPane event handlers + void OnShowTrashContextMenu(wxTreeEvent& event); + void OnClickRestoreTrashItem(wxCommandEvent& event); + void OnDragAndDropToTrash(wxDropFilesEvent& event); + + private: + wxTreeItemId m_TrashRoot; + wxTreeCtrl* m_pTrash = nullptr; + wxButton* m_pRestoreTrashedItemButton = nullptr; + wxBoxSizer* m_pMainSizer = nullptr; + wxBoxSizer* m_pTrashSizer = nullptr; + wxBoxSizer* m_pButtonSizer = nullptr; + + private: + wxWindow* m_pWindow = nullptr; +}; diff --git a/src/GUI/WaveformViewer.cpp b/src/GUI/WaveformViewer.cpp index 5174c4e..92296e3 100644 --- a/src/GUI/WaveformViewer.cpp +++ b/src/GUI/WaveformViewer.cpp @@ -19,11 +19,13 @@ */ #include "GUI/WaveformViewer.hpp" -#include "Utility/Serialize.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 #include @@ -39,28 +41,33 @@ #include #include -WaveformViewer::WaveformViewer(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); - Bind(wxEVT_PAINT, &WaveformViewer::OnPaint, this); - Bind(wxEVT_MOTION, &WaveformViewer::OnMouseMotion, this); - Bind(wxEVT_LEFT_DOWN, &WaveformViewer::OnMouseLeftButtonDown, this); - Bind(wxEVT_LEFT_UP, &WaveformViewer::OnMouseLeftButtonUp, this); - // Bind(wxEVT_KEY_DOWN, &WaveformViewer::OnControlKeyDown, this); - Bind(wxEVT_KEY_UP, &WaveformViewer::OnControlKeyUp, this); + Bind(wxEVT_PAINT, &cWaveformViewer::OnPaint, this); + Bind(wxEVT_MOTION, &cWaveformViewer::OnMouseMotion, this); + Bind(wxEVT_LEFT_DOWN, &cWaveformViewer::OnMouseLeftButtonDown, this); + Bind(wxEVT_LEFT_UP, &cWaveformViewer::OnMouseLeftButtonUp, this); + // Bind(wxEVT_KEY_DOWN, &cWaveformViewer::OnControlKeyDown, this); + Bind(wxEVT_KEY_UP, &cWaveformViewer::OnControlKeyUp, this); + + m_Sizer = new wxBoxSizer(wxVERTICAL); + + this->SetSizer(m_Sizer); + m_Sizer->Fit(this); + m_Sizer->SetSizeHints(this); + m_Sizer->Layout(); } -WaveformViewer::~WaveformViewer() +cWaveformViewer::~cWaveformViewer() { } -void WaveformViewer::OnPaint(wxPaintEvent& event) +void cWaveformViewer::OnPaint(wxPaintEvent& event) { wxPaintDC dc(this); @@ -103,23 +110,24 @@ void WaveformViewer::OnPaint(wxPaintEvent& event) this->GetSize().GetHeight() + 5)); bAreaSelected = true; - SendLoopPoints(); + // SendLoopPoints(); + SampleHive::cSignal::SendLoopPoints(CalculateLoopPoints(), *this); } else bAreaSelected = false; } -void WaveformViewer::RenderPlayhead(wxDC& dc) +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); @@ -143,23 +151,21 @@ void WaveformViewer::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 WaveformViewer::UpdateWaveformBitmap() +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() ? @@ -261,7 +267,7 @@ void WaveformViewer::UpdateWaveformBitmap() } } -void WaveformViewer::OnControlKeyDown(wxKeyEvent &event) +void cWaveformViewer::OnControlKeyDown(wxKeyEvent &event) { switch (event.GetKeyCode()) { @@ -276,7 +282,7 @@ void WaveformViewer::OnControlKeyDown(wxKeyEvent &event) event.Skip(); } -void WaveformViewer::OnControlKeyUp(wxKeyEvent &event) +void cWaveformViewer::OnControlKeyUp(wxKeyEvent &event) { switch (event.GetKeyCode()) { @@ -284,9 +290,12 @@ void WaveformViewer::OnControlKeyUp(wxKeyEvent &event) if (bSelectRange) { SetCursor(wxCURSOR_ARROW); + bSelectRange = false; bDrawSelectedArea = false; + ReleaseMouse(); + return; } break; @@ -297,17 +306,17 @@ void WaveformViewer::OnControlKeyUp(wxKeyEvent &event) event.Skip(); } -void WaveformViewer::OnMouseMotion(wxMouseEvent& 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; @@ -337,17 +346,17 @@ void WaveformViewer::OnMouseMotion(wxMouseEvent& event) return; } -void WaveformViewer::OnMouseLeftButtonDown(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; @@ -386,17 +395,17 @@ void WaveformViewer::OnMouseLeftButtonDown(wxMouseEvent& event) event.Skip(); } -void WaveformViewer::OnMouseLeftButtonUp(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; @@ -437,12 +446,12 @@ void WaveformViewer::OnMouseLeftButtonUp(wxMouseEvent& event) SetCursor(wxCURSOR_ARROW); m_MediaCtrl.Seek(seek_to, wxFromStart); - SendPushStatusBarStatus(wxString::Format(_("Now playing: %s"), selected), 1); - m_MediaCtrl.Play(); + SampleHive::cSignal::SendPushStatusBarStatus(wxString::Format(_("Now playing: %s"), selected), 1, *this); + SampleHive::cSignal::SendCallFunctionPlay(selected, false, *this); } } -void WaveformViewer::ResetDC() +void cWaveformViewer::ResetDC() { bBitmapDirty = true; bSelectRange = false; @@ -451,22 +460,17 @@ void WaveformViewer::ResetDC() Refresh(); } -void WaveformViewer::SendLoopPoints() +std::pair cWaveformViewer::CalculateLoopPoints() { - SH_LOG_DEBUG("{} Called", __FUNCTION__); - - SampleHive::SH_LoopPointsEvent event(SampleHive::SH_EVT_LOOP_POINTS_UPDATED, this->GetId()); - event.SetEventObject(this); - - int selected_row = m_Library.GetSelectedRow(); + int selected_row = SampleHive::cHiveData::Get().GetListCtrlSelectedRow(); if (selected_row < 0) - return; + 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; @@ -477,19 +481,5 @@ void WaveformViewer::SendLoopPoints() double loopA = ((double)a / panel_width) * length; double loopB = ((double)b / panel_width) * length; - event.SetLoopPoints({ loopA, loopB }); - - HandleWindowEvent(event); - - SH_LOG_DEBUG("{} processed event, sending loop points..", __FUNCTION__); -} - -void WaveformViewer::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); + return { loopA, loopB }; } diff --git a/src/GUI/WaveformViewer.hpp b/src/GUI/WaveformViewer.hpp index cd6276d..2d4556d 100644 --- a/src/GUI/WaveformViewer.hpp +++ b/src/GUI/WaveformViewer.hpp @@ -22,33 +22,30 @@ #include "Database/Database.hpp" -#include #include #include #include #include -#include #include #include #include #include -#include #include -class WaveformViewer : public wxPanel +class cWaveformViewer : public wxPanel { public: - WaveformViewer(wxWindow* window, wxDataViewListCtrl& library, - wxMediaCtrl& mediaCtrl, Database& database); - ~WaveformViewer(); + cWaveformViewer(wxWindow* window, wxMediaCtrl& mediaCtrl, cDatabase& database); + ~cWaveformViewer(); private: // ------------------------------------------------------------------- wxWindow* m_Window; + wxBoxSizer* m_Sizer; + // ------------------------------------------------------------------- - Database& m_Database; - wxDataViewListCtrl& m_Library; + cDatabase& m_Database; wxMediaCtrl& m_MediaCtrl; private: @@ -85,9 +82,7 @@ class WaveformViewer : public wxPanel void OnControlKeyDown(wxKeyEvent& event); // ------------------------------------------------------------------- - // Send custom events - void SendLoopPoints(); - void SendPushStatusBarStatus(const wxString& msg, int section); + std::pair CalculateLoopPoints(); public: // ------------------------------------------------------------------- diff --git a/src/Utility/ControlID_Enums.hpp b/src/Utility/ControlID_Enums.hpp deleted file mode 100644 index 14c8244..0000000 --- a/src/Utility/ControlID_Enums.hpp +++ /dev/null @@ -1,117 +0,0 @@ -/* 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 - -enum ControlIDs -{ - /* - ** BC = Browser control - ** SD = Settings dialog - ** MN = Popup menu - ** ET = Edit tag dialog - */ - - // ------------------------------------------------------------------- - // 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, - - // ------------------------------------------------------------------- - // 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, - - // ------------------------------------------------------------------- - // App Menu items - MN_AddFile, - MN_AddDirectory, - MN_ToggleExtension, - MN_ToggleMenuBar, - MN_ToggleStatusBar, - - // ------------------------------------------------------------------- - // Library Menu items - MN_FavoriteSample, - MN_DeleteSample, - MN_TrashSample, - MN_EditTagSample, - MN_OpenFile, - - // ------------------------------------------------------------------- - // Library Column Header Menu items - MN_ColumnFavorite, - MN_ColumnFilename, - MN_ColumnSamplePack, - MN_ColumnType, - MN_ColumnChannels, - MN_ColumnLength, - MN_ColumnSampleRate, - MN_ColumnBitrate, - MN_ColumnPath, - - // ------------------------------------------------------------------- - // Hives Menu items - MN_RenameHive, - MN_DeleteHive, - MN_RemoveSample, - MN_FilterLibrary, - MN_ShowInLibrary, - - // ------------------------------------------------------------------- - // 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/ControlIDs.hpp b/src/Utility/ControlIDs.hpp new file mode 100644 index 0000000..528ed3a --- /dev/null +++ b/src/Utility/ControlIDs.hpp @@ -0,0 +1,121 @@ +/* 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 + +namespace SampleHive { namespace ID { + + enum ControlIDs + { + /* + ** BC = Browser control + ** SD = Settings dialog + ** MN = Popup menu + ** ET = Edit tag dialog + */ + + // ------------------------------------------------------------------- + // 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, + + // ------------------------------------------------------------------- + // 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, + + // ------------------------------------------------------------------- + // App Menu items + MN_AddFile, + MN_AddDirectory, + MN_ToggleExtension, + MN_ToggleMenuBar, + MN_ToggleStatusBar, + + // ------------------------------------------------------------------- + // Library Menu items + MN_FavoriteSample, + MN_DeleteSample, + MN_TrashSample, + MN_EditTagSample, + MN_OpenFile, + + // ------------------------------------------------------------------- + // Library Column Header Menu items + MN_ColumnFavorite, + MN_ColumnFilename, + MN_ColumnSamplePack, + MN_ColumnType, + MN_ColumnChannels, + MN_ColumnLength, + MN_ColumnSampleRate, + MN_ColumnBitrate, + MN_ColumnPath, + + // ------------------------------------------------------------------- + // Hives Menu items + MN_RenameHive, + MN_DeleteHive, + MN_RemoveSample, + MN_FilterLibrary, + MN_ShowInLibrary, + + // ------------------------------------------------------------------- + // 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/Event.cpp b/src/Utility/Event.cpp new file mode 100644 index 0000000..2ce222b --- /dev/null +++ b/src/Utility/Event.cpp @@ -0,0 +1,119 @@ +/* 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/Event.hpp" + +namespace SampleHive +{ + cLoopPointsEvent::cLoopPointsEvent(wxEventType eventType, int winId) + : wxCommandEvent(eventType, winId) + { + + } + + cLoopPointsEvent::~cLoopPointsEvent() + { + + } + + 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) + // { + + // } + + // MediaEvent::~MediaEvent() + // { + + // } + + // wxDEFINE_EVENT(SH_EVT_MEDIA_STATUS_UPDATED, MediaEvent); + + cStatusBarStatusEvent::cStatusBarStatusEvent(wxEventType eventType, int winId) + : wxCommandEvent(eventType, winId) + { + + } + + cStatusBarStatusEvent::~cStatusBarStatusEvent() + { + + } + + wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_PUSH, cStatusBarStatusEvent); + wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_POP, cStatusBarStatusEvent); + wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_SET, cStatusBarStatusEvent); + + cInfoBarMessageEvent::cInfoBarMessageEvent(wxEventType eventType, int winId) + : wxCommandEvent(eventType, winId) + { + + } + + cInfoBarMessageEvent::~cInfoBarMessageEvent() + { + + } + + wxDEFINE_EVENT(SH_EVT_INFOBAR_MESSAGE_SHOW, cInfoBarMessageEvent); + + cTimerEvent::cTimerEvent(wxEventType eventType, int winId) + : wxCommandEvent(eventType, winId) + { + + } + + cTimerEvent::~cTimerEvent() + { + + } + + wxDEFINE_EVENT(SH_EVT_TIMER_STOP, cTimerEvent); + + cCallFunctionEvent::cCallFunctionEvent(wxEventType eventType, int winId) + : wxCommandEvent(eventType, winId) + { + + } + + cCallFunctionEvent::~cCallFunctionEvent() + { + + } + + wxDEFINE_EVENT(SH_EVT_CALL_FUNC_PLAY, cCallFunctionEvent); + + cWaveformUpdateEvent::cWaveformUpdateEvent(wxEventType eventType, int winId) + : wxCommandEvent(eventType, winId) + { + + } + + cWaveformUpdateEvent::~cWaveformUpdateEvent() + { + + } + + wxDEFINE_EVENT(SH_EVT_UPDATE_WAVEFORM, cWaveformUpdateEvent); +} diff --git a/src/Utility/Event.hpp b/src/Utility/Event.hpp new file mode 100644 index 0000000..c2c1b13 --- /dev/null +++ b/src/Utility/Event.hpp @@ -0,0 +1,167 @@ +/* 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 + +namespace SampleHive +{ + class cLoopPointsEvent : public wxCommandEvent + { + public: + cLoopPointsEvent(wxEventType eventType, int winId); + ~cLoopPointsEvent(); + + public: + virtual wxEvent* Clone() const { return new cLoopPointsEvent(*this); } + + public: + std::pair GetLoopPoints() const { return { m_LoopA, m_LoopB }; }; + void SetLoopPoints(std::pair loopPoints) + { m_LoopA = loopPoints.first; m_LoopB = loopPoints.second; }; + + private: + double m_LoopA, m_LoopB; + }; + + 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 cMediaEvent : public wxCommandEvent + // { + // public: + // cMediaEvent(wxEventType eventType, int winId); + // ~cMediaEvent(); + + // public: + // virtual wxEvent* Clone() const { return new cMediaEvent(*this); } + + // public: + // void SetPath(const wxString& path) { m_Path = path; } + // wxString GetPath() const { return m_Path; } + + // private: + // wxString m_Path; + // }; + + // wxDECLARE_EVENT(SH_EVT_MEDIA_STATUS_UPDATED, cMediaEvent); + + class cStatusBarStatusEvent : public wxCommandEvent + { + public: + cStatusBarStatusEvent(wxEventType eventType, int winId); + ~cStatusBarStatusEvent(); + + public: + virtual wxEvent* Clone() const { return new cStatusBarStatusEvent(*this); } + + public: + std::pair GetPushMessageAndSection() const { return { m_Msg, m_PushSection }; } + void SetPushMessageAndSection(std::pair status) + { m_Msg = status.first; m_PushSection = status.second; } + + std::pair GetStatusTextAndSection() const { return { m_Text, m_SetSection }; } + void SetStatusTextAndSection(std::pair status) + { m_Text = status.first, m_SetSection = status.second; } + + int GetPopMessageSection() const { return m_PopSection; } + void SetPopMessageSection(int section) { m_PopSection = section; } + + private: + wxString m_Msg, m_Text; + int m_PushSection, m_PopSection, m_SetSection; + }; + + 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 cInfoBarMessageEvent : public wxCommandEvent + { + public: + cInfoBarMessageEvent(wxEventType eventType, int winId); + ~cInfoBarMessageEvent(); + + public: + virtual wxEvent* Clone() const { return new cInfoBarMessageEvent(*this); } + + public: + std::pair GetInfoBarMessage() const { return { m_Msg, m_Mode }; } + void SetInfoBarMessage(std::pair info) + { m_Msg = info.first; m_Mode = info.second; } + + private: + wxString m_Msg; + int m_Mode; + }; + + wxDECLARE_EVENT(SH_EVT_INFOBAR_MESSAGE_SHOW, cInfoBarMessageEvent); + + class cTimerEvent : public wxCommandEvent + { + public: + cTimerEvent(wxEventType eventType, int winId); + ~cTimerEvent(); + + public: + virtual wxEvent* Clone() const { return new cTimerEvent(*this); } + }; + + wxDECLARE_EVENT(SH_EVT_TIMER_STOP, cTimerEvent); + + class cCallFunctionEvent : public wxCommandEvent + { + public: + cCallFunctionEvent(wxEventType eventType, int winId); + ~cCallFunctionEvent(); + + public: + virtual wxEvent* Clone() const { return new cCallFunctionEvent(*this); } + + public: + 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, cCallFunctionEvent); + + class cWaveformUpdateEvent : public wxCommandEvent + { + public: + cWaveformUpdateEvent(wxEventType eventType, int winId); + ~cWaveformUpdateEvent(); + + public: + virtual wxEvent* Clone() const { return new cWaveformUpdateEvent(*this); } + }; + + 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/SH_Event.cpp b/src/Utility/SH_Event.cpp deleted file mode 100644 index 6c62342..0000000 --- a/src/Utility/SH_Event.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* 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/SH_Event.hpp" - -namespace SampleHive -{ - SH_LoopPointsEvent::SH_LoopPointsEvent(wxEventType eventType, int winId) - : wxCommandEvent(eventType, winId) - { - - } - - SH_LoopPointsEvent::~SH_LoopPointsEvent() - { - - } - - wxDEFINE_EVENT(SH_EVT_LOOP_POINTS_UPDATED, SH_LoopPointsEvent); - - // SH_AddSampleEvent::SH_AddSampleEvent(wxEventType eventType, int winId) - // : wxCommandEvent(eventType, winId) - // { - - // } - - // SH_AddSampleEvent::~SH_AddSampleEvent() - // { - - // } - - // wxDEFINE_EVENT(SH_EVT_STATUS_ADD_SAMPLE, SH_AddSampleEvent); - - // SH_MediaEvent::SH_MediaEvent(wxEventType eventType, int winId) - // : wxCommandEvent(eventType, winId) - // { - - // } - - // SH_MediaEvent::~SH_MediaEvent() - // { - - // } - - // wxDEFINE_EVENT(SH_EVT_MEDIA_STATUS_UPDATED, SH_MediaEvent); - - SH_StatusBarStatusEvent::SH_StatusBarStatusEvent(wxEventType eventType, int winId) - : wxCommandEvent(eventType, winId) - { - - } - - SH_StatusBarStatusEvent::~SH_StatusBarStatusEvent() - { - - } - - wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_PUSH, SH_StatusBarStatusEvent); - wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_POP, SH_StatusBarStatusEvent); - wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_SET, SH_StatusBarStatusEvent); - - SH_InfoBarMessageEvent::SH_InfoBarMessageEvent(wxEventType eventType, int winId) - : wxCommandEvent(eventType, winId) - { - - } - - SH_InfoBarMessageEvent::~SH_InfoBarMessageEvent() - { - - } - - wxDEFINE_EVENT(SH_EVT_INFOBAR_MESSAGE_SHOW, SH_InfoBarMessageEvent); - - SH_TimerEvent::SH_TimerEvent(wxEventType eventType, int winId) - : wxCommandEvent(eventType, winId) - { - - } - - SH_TimerEvent::~SH_TimerEvent() - { - - } - - wxDEFINE_EVENT(SH_EVT_TIMER_STOP, SH_TimerEvent); -} diff --git a/src/Utility/SH_Event.hpp b/src/Utility/SH_Event.hpp deleted file mode 100644 index d2baf58..0000000 --- a/src/Utility/SH_Event.hpp +++ /dev/null @@ -1,149 +0,0 @@ -/* 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 - -namespace SampleHive -{ - class SH_LoopPointsEvent : public wxCommandEvent - { - public: - SH_LoopPointsEvent(wxEventType eventType, int winId); - ~SH_LoopPointsEvent(); - - public: - virtual wxEvent* Clone() const { return new SH_LoopPointsEvent(*this); } - - public: - std::pair GetLoopPoints() const { return { m_LoopA, m_LoopB }; }; - void SetLoopPoints(std::pair loopPoints) - { m_LoopA = loopPoints.first; m_LoopB = loopPoints.second; }; - - private: - double m_LoopA, m_LoopB; - }; - - wxDECLARE_EVENT(SH_EVT_LOOP_POINTS_UPDATED, SH_LoopPointsEvent); - - // class SH_AddSampleEvent : public wxCommandEvent - // { - // public: - // SH_AddSampleEvent(wxEventType eventType, int winId); - // ~SH_AddSampleEvent(); - - // public: - // virtual wxEvent* Clone() const { return new SH_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, SH_AddSampleEvent); - - // class SH_MediaEvent : public wxCommandEvent - // { - // public: - // SH_MediaEvent(wxEventType eventType, int winId); - // ~SH_MediaEvent(); - - // public: - // virtual wxEvent* Clone() const { return new SH_MediaEvent(*this); } - - // public: - // void SetPath(const wxString& path) { m_Path = path; } - // wxString GetPath() const { return m_Path; } - - // private: - // wxString m_Path; - // }; - - // wxDECLARE_EVENT(SH_EVT_MEDIA_STATUS_UPDATED, SH_MediaEvent); - - class SH_StatusBarStatusEvent : public wxCommandEvent - { - public: - SH_StatusBarStatusEvent(wxEventType eventType, int winId); - ~SH_StatusBarStatusEvent(); - - public: - virtual wxEvent* Clone() const { return new SH_StatusBarStatusEvent(*this); } - - public: - std::pair GetPushMessageAndSection() const { return { m_Msg, m_PushSection }; } - void SetPushMessageAndSection(std::pair status) - { m_Msg = status.first; m_PushSection = status.second; } - - std::pair GetStatusTextAndSection() const { return { m_Text, m_SetSection }; } - void SetStatusTextAndSection(std::pair status) - { m_Text = status.first, m_SetSection = status.second; } - - int GetPopMessageSection() const { return m_PopSection; } - void SetPopMessageSection(int section) { m_PopSection = section; } - - private: - wxString m_Msg, m_Text; - int m_PushSection, m_PopSection, m_SetSection; - }; - - wxDECLARE_EVENT(SH_EVT_STATUSBAR_STATUS_PUSH, SH_StatusBarStatusEvent); - wxDECLARE_EVENT(SH_EVT_STATUSBAR_STATUS_POP, SH_StatusBarStatusEvent); - wxDECLARE_EVENT(SH_EVT_STATUSBAR_STATUS_SET, SH_StatusBarStatusEvent); - - class SH_InfoBarMessageEvent : public wxCommandEvent - { - public: - SH_InfoBarMessageEvent(wxEventType eventType, int winId); - ~SH_InfoBarMessageEvent(); - - public: - virtual wxEvent* Clone() const { return new SH_InfoBarMessageEvent(*this); } - - public: - std::pair GetInfoBarMessage() const { return { m_Msg, m_Mode }; } - void SetInfoBarMessage(std::pair info) - { m_Msg = info.first; m_Mode = info.second; } - - private: - wxString m_Msg; - int m_Mode; - }; - - wxDECLARE_EVENT(SH_EVT_INFOBAR_MESSAGE_SHOW, SH_InfoBarMessageEvent); - - class SH_TimerEvent : public wxCommandEvent - { - public: - SH_TimerEvent(wxEventType eventType, int winId); - ~SH_TimerEvent(); - - public: - virtual wxEvent* Clone() const { return new SH_TimerEvent(*this); } - }; - - wxDECLARE_EVENT(SH_EVT_TIMER_STOP, SH_TimerEvent); -} 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 new file mode 100644 index 0000000..614d282 --- /dev/null +++ b/src/Utility/Signal.cpp @@ -0,0 +1,150 @@ +/* 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/Event.hpp" + +namespace SampleHive { + + void cSignal::SendInfoBarMessage(const wxString& msg, int mode, wxWindow& window, bool isDialog) + { + SampleHive::cInfoBarMessageEvent event(SampleHive::SH_EVT_INFOBAR_MESSAGE_SHOW, window.GetId()); + event.SetEventObject(&window); + + event.SetInfoBarMessage({ msg, mode }); + + if (isDialog) + window.GetParent()->GetEventHandler()->ProcessEvent(event); + else + window.HandleWindowEvent(event); + } + + void cSignal::SendPushStatusBarStatus(const wxString& msg, int section, wxWindow& window, bool isDialog) + { + SampleHive::cStatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_PUSH, window.GetId()); + event.SetEventObject(&window); + + event.SetPushMessageAndSection({ msg, section }); + + if (isDialog) + window.GetParent()->GetEventHandler()->ProcessEvent(event); + else + window.HandleWindowEvent(event); + } + + void cSignal::SendPopStatusBarStatus(int section, wxWindow& window, bool isDialog) + { + SampleHive::cStatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_POP, window.GetId()); + event.SetEventObject(&window); + + event.SetPopMessageSection(section); + + if (isDialog) + window.GetParent()->GetEventHandler()->ProcessEvent(event); + else + window.HandleWindowEvent(event); + } + + void cSignal::SendSetStatusBarStatus(const wxString& text, int section, wxWindow& window, bool isDialog) + { + SampleHive::cStatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_SET, window.GetId()); + event.SetEventObject(&window); + + event.SetStatusTextAndSection({ text, section }); + + if (isDialog) + window.GetParent()->GetEventHandler()->ProcessEvent(event); + else + window.HandleWindowEvent(event); + } + + void cSignal::SendCallFunctionPlay(const wxString& selection, bool checkAutoplay, wxWindow& window, bool isDialog) + { + 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); + else + window.HandleWindowEvent(event); + } + + void cSignal::SendTimerStopStatus(wxWindow& window, bool isDialog) + { + SampleHive::cTimerEvent event(SampleHive::SH_EVT_TIMER_STOP, window.GetId()); + event.SetEventObject(&window); + + if (isDialog) + window.GetParent()->GetEventHandler()->ProcessEvent(event); + else + window.HandleWindowEvent(event); + } + + void cSignal::SendLoopPoints(std::pair loopPoint, wxWindow& window, bool isDialog) + { + SampleHive::cLoopPointsEvent event(SampleHive::SH_EVT_LOOP_POINTS_UPDATED, window.GetId()); + event.SetEventObject(&window); + + event.SetLoopPoints({loopPoint.first, loopPoint.second}); + + if (isDialog) + window.GetParent()->GetEventHandler()->ProcessEvent(event); + else + window.HandleWindowEvent(event); + } + + void cSignal::SendClearLoopPointsStatus(wxWindow& window, bool isDialog) + { + 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) + window.GetParent()->GetEventHandler()->ProcessEvent(event); + else + window.HandleWindowEvent(event); + } + +} diff --git a/src/Utility/Signal.hpp b/src/Utility/Signal.hpp new file mode 100644 index 0000000..941dbcb --- /dev/null +++ b/src/Utility/Signal.hpp @@ -0,0 +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 . + */ + +#pragma once + +#include +#include + +namespace SampleHive { + + class cSignal + { + public: + 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, 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 acb5a99..9cda359 100644 --- a/src/Utility/Tags.cpp +++ b/src/Utility/Tags.cpp @@ -33,142 +33,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_ms = 0, length_s = 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::PropertyMap property_map = f.file()->properties(); - 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_ms = properties->lengthInMilliseconds(); - length_s = 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; - - // unsigned int longest = 0; - - // for(TagLib::PropertyMap::ConstIterator i = property_map.begin(); i != property_map.end(); ++i) - // { - // if (i->first.size() > longest) - // { - // longest = i->first.size(); - // } - // } - - // std::cout << "-- TAG (properties) --" << std::endl; - - // for(TagLib::PropertyMap::ConstIterator i = property_map.begin(); i != property_map.end(); ++i) - // { - // for(TagLib::StringList::ConstIterator j = i->second.begin(); j != i->second.end(); ++j) - // { - // std::cout << std::left << std::setw(longest) << i->first << " - " << '"' << *j << '"' << std::endl; - // } - // } - } - else - { - bValid = false; } - return { title, artist, album, genre, comment, channels, length_ms, 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); + }; + +}