diff --git a/README.org b/README.org index 4685a0e..8b06e46 100644 --- a/README.org +++ b/README.org @@ -48,13 +48,13 @@ SampleHive let's you manage your audio samples in a nice and simple way, just ad On Arch based distributions, #+begin_example -sudo pacman -S wxgtk3 wxsvg sqlite taglib yaml-cpp libsndfile +sudo pacman -S wxgtk3 wxsvg sqlite taglib yaml-cpp libsndfile spdlog #+end_example On Debian, Ubuntu and distributions based the on two, #+begin_example -sudo apt install libwxbase3.0-dev libwxgtk-media3.0-gtk3-dev libwxgtk3.0-gtk3-dev wx3.0-headers libsqlite3-dev libyaml-cpp-dev libtagc0-dev libtag1-dev libtagc0 libexif-dev libpango1.0-dev libsndfile1-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev +sudo apt install libwxbase3.0-dev libwxgtk-media3.0-gtk3-dev libwxgtk3.0-gtk3-dev wx3.0-headers libsqlite3-dev libyaml-cpp-dev libtagc0-dev libtag1-dev libtagc0 libexif-dev libpango1.0-dev libsndfile1-dev libspdlog-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev #+end_example You might also need to install =git=, =cmake=, =meson= and =g++= as well, if you don't already have them installed in order to build SampleHive. diff --git a/meson.build b/meson.build index c9707cb..800d740 100755 --- a/meson.build +++ b/meson.build @@ -126,6 +126,7 @@ src = [ 'src/Utility/Serialize.cpp', 'src/Utility/Tags.cpp', 'src/Utility/SH_Event.cpp', + 'src/Utility/Log.cpp', ] @@ -189,6 +190,17 @@ if not snd.found() snd = snd_subproject.dependency('sndfile') endif +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',]) + + 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,) @@ -204,14 +216,14 @@ if wx_found cpp_args: [wx_cxx_flags], link_args: [wx_libs], include_directories : include_dirs, - dependencies: [wx, taglib, sqlite3, yaml, snd], + 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], + dependencies: [wx, taglib, sqlite3, yaml, snd, spdlog], install: true, install_rpath: prefix / 'lib') endif diff --git a/src/App.cpp b/src/App.cpp index 80868fc..d8f5cdd 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -20,6 +20,7 @@ #include "App.hpp" #include "SampleHiveConfig.hpp" +#include "Utility/Log.hpp" #include #include @@ -93,5 +94,5 @@ bool App::OnCmdLineParsed(wxCmdLineParser& parser) void App::OnEventLoopEnter(wxEventLoopBase* event) { if (m_Frame->CreateWatcherIfNecessary()) - wxLogDebug("Filesystem watcher created sucessfully"); + SH_LOG_INFO("Filesystem watcher created sucessfully"); } diff --git a/src/Database/Database.cpp b/src/Database/Database.cpp index aa1141d..69f9241 100644 --- a/src/Database/Database.cpp +++ b/src/Database/Database.cpp @@ -19,6 +19,7 @@ */ #include "Database/Database.hpp" +#include "Utility/Log.hpp" #include #include @@ -26,7 +27,6 @@ #include #include -#include #include #include #include @@ -48,14 +48,15 @@ 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; const auto msg = ss.str(); - wxLogDebug(msg.c_str()); + SH_LOG_ERROR(msg.c_str()); wxMessageDialog msgDialog(NULL, _(msg), _(title), wxOK | wxICON_ERROR); msgDialog.ShowModal(); @@ -68,12 +69,12 @@ class Sqlite3Statement { throw_on_sqlite3_error(sqlite3_prepare_v2(database, query.c_str(), query.size(), &stmt, NULL)); } - ~Sqlite3Statement() + ~Sqlite3Statement() { throw_on_sqlite3_error(sqlite3_finalize(stmt)); } - sqlite3_stmt *stmt = nullptr; + sqlite3_stmt* stmt = nullptr; }; Database::Database(const std::string &dbPath) @@ -106,11 +107,11 @@ void Database::CreateTableSamples() try { throw_on_sqlite3_error(sqlite3_exec(m_Database, samples, NULL, 0, &m_ErrMsg)); - wxLogDebug(_("Samples table created successfully.")); + SH_LOG_INFO("SAMPLES table created successfully."); } catch (const std::exception &e) { - show_modal_dialog_and_log("Error! Cannot create table samples: ", "Error", e.what()); + show_modal_dialog_and_log("Error! Cannot create SAMPLES table", "Error", e.what()); } } @@ -122,11 +123,11 @@ void Database::CreateTableHives() try { throw_on_sqlite3_error(sqlite3_exec(m_Database, hives, NULL, 0, &m_ErrMsg)); - wxLogDebug("Hives table created successfully."); + SH_LOG_INFO("HIVES table created successfully."); } catch (const std::exception &e) { - show_modal_dialog_and_log("Error! Cannot create hives table", "Error", e.what()); + show_modal_dialog_and_log("Error! Cannot create HIVES table", "Error", e.what()); } } @@ -165,17 +166,23 @@ 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)); @@ -184,11 +191,11 @@ void Database::InsertIntoSamples(const std::vector &samples) throw_on_sqlite3_error(sqlite3_exec(m_Database, "END TRANSACTION", NULL, NULL, &m_ErrMsg)); - wxLogDebug("Data inserted successfully."); + SH_LOG_INFO("Data inserted successfully into SAMPLES."); } - catch (const std::exception &exception) + catch (const std::exception &e) { - wxLogDebug(exception.what()); + show_modal_dialog_and_log("Error! Cannot insert data into SAMPLES", "Error", e.what()); } } @@ -223,7 +230,8 @@ void Database::InsertIntoHives(const std::string &hiveName) // 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); @@ -232,11 +240,11 @@ void Database::InsertIntoHives(const std::string &hiveName) // rc = sqlite3_exec(m_Database, "END TRANSACTION", NULL, NULL, &m_ErrMsg); - wxLogDebug("Data inserted successfully."); + SH_LOG_INFO("Data inserted successfully into HIVES."); } - catch (const std::exception &exception) + catch (const std::exception &e) { - wxLogDebug(exception.what()); + show_modal_dialog_and_log("Error! Cannot insert data into HIVES", "Error", e.what()); } } @@ -248,21 +256,23 @@ void Database::UpdateHive(const std::string &hiveOldName, const std::string &hiv Sqlite3Statement statement(m_Database, 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) { - wxLogWarning("No data inserted."); + SH_LOG_INFO("Updating hive {} to {}", hiveOldName, hiveNewName); } else { - wxLogDebug("Hive updated successfully. %s", m_ErrMsg); + SH_LOG_INFO("Updated hive successfully."); } } - catch (const std::exception &exception) + catch (const std::exception& e) { - wxLogDebug(exception.what()); + show_modal_dialog_and_log("Error! Cannot update hive", "Error", e.what()); } } @@ -274,19 +284,21 @@ void Database::UpdateHiveName(const std::string &filename, const std::string &hi Sqlite3Statement statement(m_Database, 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) { - wxLogDebug("Record found, updating.."); + SH_LOG_INFO("Updating hive to {} for {}", hiveName, filename); } - wxLogDebug("Updated record successfully."); + SH_LOG_INFO("Updated hive name successfully."); } catch (const std::exception &e) { - show_modal_dialog_and_log("Error! Cannot update record: ", "Error", e.what()); + show_modal_dialog_and_log("Error! Cannot update hive name", "Error", e.what()); } } @@ -299,18 +311,19 @@ void Database::UpdateFavoriteColumn(const std::string &filename, int value) Sqlite3Statement statement(m_Database, 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) { - wxLogDebug("Record found, updating.."); + SH_LOG_INFO("Updating favorite value of {} to {}", filename, value); } - wxLogDebug("Updated record successfully."); + SH_LOG_INFO("Updated favorite column successfully."); } catch (const std::exception &e) { - show_modal_dialog_and_log("Error! Cannot update record: ", "Error", e.what()); + show_modal_dialog_and_log("Error! Cannot update favorite column", "Error", e.what()); } } @@ -322,19 +335,21 @@ void Database::UpdateSamplePack(const std::string &filename, const std::string & Sqlite3Statement statement(m_Database, 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) { - wxLogDebug("Record found, updating.."); + SH_LOG_INFO("Updating sample pack of {} to {}", filename, samplePack); } - wxLogDebug("Updated record successfully."); + SH_LOG_INFO("Updated sample pack successfully."); } catch (const std::exception &e) { - show_modal_dialog_and_log("Error! Cannot update record: ", "Error", e.what()); + show_modal_dialog_and_log("Error! Cannot update sample pack", "Error", e.what()); } } @@ -347,17 +362,19 @@ void Database::UpdateSampleType(const std::string &filename, const std::string & Sqlite3Statement statement(m_Database, 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) { - wxLogDebug("Record found, updating.."); + SH_LOG_INFO("Updating sample type of {} to {}", filename, type); } - wxLogDebug("Updated record successfully."); + + SH_LOG_INFO("Updated sample type successfully."); } catch (const std::exception &e) { - show_modal_dialog_and_log("Error! Cannot update record: ", "Error", e.what()); + show_modal_dialog_and_log("Error! Cannot update sample type", "Error", e.what()); } } @@ -371,20 +388,21 @@ std::string Database::GetSampleType(const std::string &filename) Sqlite3Statement statement(m_Database, 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) { - wxLogDebug("Record found, fetching.."); + SH_LOG_INFO("Record found, fetching sample type for {}", filename); type = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 0))); } - wxLogDebug("Selected data from table successfully."); + SH_LOG_INFO("Selected sample type from table successfully."); } catch (const std::exception &e) { - show_modal_dialog_and_log("Error! Cannot get sample type column value from table: ", "Error", e.what()); + show_modal_dialog_and_log("Error! Cannot get sample type from table", "Error", e.what()); } return type; @@ -400,19 +418,20 @@ int Database::GetFavoriteColumnValueByFilename(const std::string &filename) Sqlite3Statement statement(m_Database, 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) { - wxLogDebug("Record found, fetching.."); value = sqlite3_column_int(statement.stmt, 0); + SH_LOG_INFO("Record found, fetching favorite column value for {}", filename); } - wxLogDebug("Selected data from table successfully."); + SH_LOG_INFO("Selected favorite column from table successfully."); } catch (const std::exception &e) { - show_modal_dialog_and_log("Error! Cannot get favorite column value from table: ", "Error", e.what()); + show_modal_dialog_and_log("Error! Cannot get favorite column value from table", "Error", e.what()); } return value; @@ -428,19 +447,20 @@ std::string Database::GetHiveByFilename(const std::string &filename) Sqlite3Statement statement(m_Database, 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) { - wxLogDebug("Record found, fetching.."); hive = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 0))); + SH_LOG_INFO("Record found, fetching hive for {}", filename); } - wxLogDebug("Selected data from table successfully."); + SH_LOG_INFO("Selected hive from table successfully."); } catch (const std::exception &e) { - show_modal_dialog_and_log("Error! Cannot get hive value from table: ", "Error", e.what()); + show_modal_dialog_and_log("Error! Cannot get hive value from table", "Error", e.what()); } return hive; @@ -454,18 +474,19 @@ void Database::RemoveSampleFromDatabase(const std::string &filename) Sqlite3Statement statement(m_Database, 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) { - wxLogDebug("Record found, Deleting.."); + SH_LOG_INFO("Record found, Deleting {} from table", filename); } - wxLogDebug("Deleted data from table successfully."); + SH_LOG_INFO("Deleted sample from table successfully."); } catch (const std::exception &e) { - show_modal_dialog_and_log("Error! Cannot get hive value from table: ", "Error", e.what()); + show_modal_dialog_and_log("Error! Cannot delete sample from table", "Error", e.what()); } } @@ -477,18 +498,19 @@ void Database::RemoveHiveFromDatabase(const std::string &hiveName) Sqlite3Statement statement(m_Database, 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) { - wxLogDebug("Record found, Deleting.."); + SH_LOG_INFO("Record found, Deleting hive {} from table", hiveName); } - wxLogDebug("Deleted data from table successfully."); + SH_LOG_INFO("Deleted hive from table successfully."); } catch (const std::exception &e) { - show_modal_dialog_and_log("Error! Cannot get hive value from table: ", "Error", e.what()); + show_modal_dialog_and_log("Error! Cannot delete hive from table", "Error", e.what()); } } @@ -502,19 +524,20 @@ std::string Database::GetSamplePathByFilename(const std::string &filename) Sqlite3Statement statement(m_Database, 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) { - wxLogDebug("Record found, fetching.."); path = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 0))); + SH_LOG_INFO("Record found, fetching sample path for {}", filename); } - wxLogDebug("Selected data from table successfully."); + SH_LOG_INFO("Selected sample path from table successfully."); } catch (const std::exception &e) { - show_modal_dialog_and_log("Error! Cannot select sample path from table: ", "Error", e.what()); + show_modal_dialog_and_log("Error! Cannot select sample path from table", "Error", e.what()); } return path; @@ -530,19 +553,20 @@ std::string Database::GetSampleFileExtension(const std::string &filename) Sqlite3Statement statement(m_Database, 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) { - wxLogInfo("Record found, fetching.."); extension = std::string(reinterpret_cast(sqlite3_column_text(statement.stmt, 0))); + SH_LOG_INFO("Record found, fetching file extension for {}", filename); } - wxLogDebug("Selected data from table successfully."); + SH_LOG_INFO("Selected file extension from table successfully."); } catch (const std::exception &e) { - show_modal_dialog_and_log("Error! Cannot select sample extension from table: ", "Error", e.what()); + show_modal_dialog_and_log("Error! Cannot select sample extension from table", "Error", e.what()); } return extension; @@ -571,7 +595,7 @@ wxVector> Database::LoadSamplesDatabase(wxDataViewTreeCtrl & { num_rows = sqlite3_column_int(statement1.stmt, 0); - wxLogDebug("Loading %d samples..", num_rows); + SH_LOG_INFO("Loading {} samples..", num_rows); vecSet.reserve(num_rows); } @@ -585,17 +609,23 @@ 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()); @@ -615,7 +645,6 @@ wxVector> Database::LoadSamplesDatabase(wxDataViewTreeCtrl & { if (favorite == 1) { - // vec.push_back(true); vec.push_back(icon_filled); std::deque nodes; @@ -687,7 +716,7 @@ wxVector> Database::LoadSamplesDatabase(wxDataViewTreeCtrl & } catch (const std::exception &e) { - show_modal_dialog_and_log("Error! Cannot load data from table: ", "Error", e.what()); + show_modal_dialog_and_log("Error! Cannot load data from SAMPLES", "Error", e.what()); } return vecSet; @@ -709,22 +738,28 @@ Database::FilterDatabaseBySampleName(const std::string &sampleName, bool show_ex 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; while (SQLITE_ROW == sqlite3_step(statement.stmt)) { - wxLogDebug("Record found, fetching.."); + 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()); @@ -761,7 +796,7 @@ Database::FilterDatabaseBySampleName(const std::string &sampleName, bool show_ex } catch (const std::exception &e) { - show_modal_dialog_and_log("Error! Cannot filter data from table: ", "Error", e.what()); + show_modal_dialog_and_log("Error! Cannot filter data from table", "Error", e.what()); } return sampleVec; @@ -783,22 +818,28 @@ Database::FilterDatabaseByHiveName(const std::string &hiveName, bool show_extens 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; while (SQLITE_ROW == sqlite3_step(statement.stmt)) { - wxLogDebug("Record found, fetching.."); + 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()); @@ -811,21 +852,10 @@ Database::FilterDatabaseByHiveName(const std::string &hiveName, bool show_extens else vec.push_back(icon_empty); - // if (favorite == 1) - // vec.push_back(true); - // else - // vec.push_back(false); - - // vec.push_back(filename); - if (show_extension) - { vec.push_back(path.AfterLast('/')); - } else - { vec.push_back(path.AfterLast('/').BeforeLast('.')); - } vec.push_back(sample_pack); vec.push_back(sample_type); @@ -842,7 +872,7 @@ Database::FilterDatabaseByHiveName(const std::string &hiveName, bool show_extens } catch (const std::exception &e) { - show_modal_dialog_and_log("Error! Cannot filter data from table: ", "Error", e.what()); + show_modal_dialog_and_log("Error! Cannot filter data from table", "Error", e.what()); } return sampleVec; @@ -858,7 +888,7 @@ void Database::LoadHivesDatabase(wxDataViewTreeCtrl &treeCtrl) while (SQLITE_ROW == sqlite3_step(statement.stmt)) { - wxLogDebug("Loading hives.."); + SH_LOG_INFO("Loading hives.."); const auto hive = wxString(std::string(reinterpret_cast (sqlite3_column_text(statement.stmt, 0)))); @@ -868,7 +898,7 @@ void Database::LoadHivesDatabase(wxDataViewTreeCtrl &treeCtrl) } 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 hive from hives table", "Error", e.what()); } } @@ -895,15 +925,15 @@ wxArrayString Database::CheckDuplicates(const wxArrayString &files) if (sqlite3_step(statement.stmt) != SQLITE_ROW) sorted_files.push_back(files[i]); else - wxLogDebug("Already added: %s. Skipping..", files[i]); + SH_LOG_INFO("Already added: {}, skipping..", files[i]); rc = sqlite3_clear_bindings(statement.stmt); rc = sqlite3_reset(statement.stmt); } } - catch (const std::exception &exception) + catch (const std::exception &e) { - wxLogDebug(exception.what()); + show_modal_dialog_and_log("Error! Cannot check duplicates from table", "Error", e.what()); } return sorted_files; @@ -917,21 +947,22 @@ bool Database::IsTrashed(const std::string &filename) Sqlite3Statement statement(m_Database, 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) { - wxLogDebug("Record found, fetching.."); + SH_LOG_INFO("Record found, fetching {} trash status", filename); if (sqlite3_column_int(statement.stmt, 0) == 1) return true; } - wxLogDebug("Selected data from table successfully."); + SH_LOG_INFO("Selected trash status from table successfully."); } catch (const std::exception &e) { - show_modal_dialog_and_log("Error! Cannot select sample path from table: ", "Error", e.what()); + show_modal_dialog_and_log("Error! Cannot check for trash status from table", "Error", e.what()); } return false; @@ -946,18 +977,19 @@ void Database::UpdateTrashColumn(const std::string &filename, int value) Sqlite3Statement statement(m_Database, 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) { - wxLogDebug("Record found, updating.."); + SH_LOG_INFO("Record found, updating trash status for {}", filename); } - wxLogDebug("Updated record successfully."); + SH_LOG_INFO("Updated trash status successfully."); } catch (const std::exception &e) { - show_modal_dialog_and_log("Error! Cannot update record: ", "Error", e.what()); + show_modal_dialog_and_log("Error! Cannot update trash status", "Error", e.what()); } } @@ -978,22 +1010,29 @@ Database::RestoreFromTrashByFilename(const std::string &filename, Sqlite3Statement statement(m_Database, 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()); @@ -1027,7 +1066,7 @@ Database::RestoreFromTrashByFilename(const std::string &filename, } catch (const std::exception &e) { - show_modal_dialog_and_log("Error! Cannot load data from table: ", "Error", e.what()); + show_modal_dialog_and_log("Error! Cannot restore trash data from table", "Error", e.what()); } return vecSet; diff --git a/src/GUI/Dialogs/Settings.cpp b/src/GUI/Dialogs/Settings.cpp index a33d8b1..cc93c47 100644 --- a/src/GUI/Dialogs/Settings.cpp +++ b/src/GUI/Dialogs/Settings.cpp @@ -21,10 +21,10 @@ #include "GUI/Dialogs/Settings.hpp" #include "Utility/ControlID_Enums.hpp" #include "Utility/Serialize.hpp" +#include "Utility/Log.hpp" #include #include -#include #include Settings::Settings(const std::string& configFilepath, const std::string& databaseFilepath) @@ -358,8 +358,8 @@ void Settings::OnChangeFontSize(wxSpinEvent& event) m_Window->SetFont(m_Font); this->SetFont(m_Font); - wxLogDebug("Font size: %d", font_size); - wxLogDebug("Font size: %d", m_Font.GetPointSize()); + SH_LOG_DEBUG("Font size: {}", font_size); + SH_LOG_DEBUG("Font size: {}", m_Font.GetPointSize()); } void Settings::LoadDefaultConfig() @@ -422,11 +422,11 @@ void Settings::SetShowExtension(bool value) void Settings::PrintFont() { - wxLogDebug("Font face: %s", m_Font.GetFaceName()); - wxLogDebug("Font size: %d", m_Font.GetPointSize()); - wxLogDebug("Font family: %s", m_Font.GetFamilyString()); - wxLogDebug("Font style: %s", m_Font.GetStyleString()); - wxLogDebug("Font weight: %s", m_Font.GetWeightString()); + SH_LOG_DEBUG("Font face: {}", m_Font.GetFaceName()); + SH_LOG_DEBUG("Font size: {}", m_Font.GetPointSize()); + SH_LOG_DEBUG("Font family: {}", m_Font.GetFamilyString()); + SH_LOG_DEBUG("Font style: {}", m_Font.GetStyleString()); + SH_LOG_DEBUG("Font weight: {}", m_Font.GetWeightString()); } void Settings::SetCustomFont() @@ -475,14 +475,14 @@ void Settings::OnChangeWaveformColour(wxColourPickerEvent& event) if (colour != wave_colour) { - wxLogDebug("Waveform colour changed."); + SH_LOG_INFO("Waveform colour changed."); bWaveformColourChanged = true; serializer.SerializeWaveformColour(colour); } else { - wxLogDebug("Waveform colour not changed."); + SH_LOG_INFO("Waveform colour not changed."); bWaveformColourChanged = false; serializer.SerializeWaveformColour(colour); diff --git a/src/GUI/Dialogs/TagEditor.cpp b/src/GUI/Dialogs/TagEditor.cpp index a7eaac7..9eb1888 100644 --- a/src/GUI/Dialogs/TagEditor.cpp +++ b/src/GUI/Dialogs/TagEditor.cpp @@ -19,12 +19,12 @@ */ #include "Utility/ControlID_Enums.hpp" +#include "Utility/Log.hpp" #include "Database/Database.hpp" #include "GUI/Dialogs/TagEditor.hpp" #include #include -#include #include #include #include @@ -255,7 +255,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event) case wxID_YES: if (m_TitleCheck->GetValue() && m_TitleText->GetValue() != tags.GetAudioInfo().title) { - wxLogDebug("Changing title tag.."); + SH_LOG_INFO("Changing title tag.."); tags.SetTitle(title.ToStdString()); info_msg = wxString::Format("Successfully changed title tag to %s", title); @@ -263,19 +263,19 @@ void TagEditor::OnClickApply(wxCommandEvent& event) if (m_ArtistCheck->GetValue() && m_ArtistText->GetValue() != tags.GetAudioInfo().artist) { - wxLogDebug("Changing artist tag.."); + SH_LOG_INFO("Changing artist tag.."); tags.SetArtist(artist.ToStdString()); db.UpdateSamplePack(m_Filename, artist.ToStdString()); - wxLogDebug("SAMPLE FILENAME HERE: %s", m_Filename); + SH_LOG_DEBUG("SAMPLE FILENAME HERE: %s", m_Filename); info_msg = wxString::Format("Successfully changed artist tag to %s", artist); } if (m_AlbumCheck->GetValue() && m_AlbumText->GetValue() != tags.GetAudioInfo().album) { - wxLogDebug("Changing album tag.."); + SH_LOG_INFO("Changing album tag.."); tags.SetAlbum(album.ToStdString()); info_msg = wxString::Format("Successfully changed album tag to %s", album); @@ -283,7 +283,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event) if (m_GenreCheck->GetValue() && m_GenreText->GetValue() != tags.GetAudioInfo().genre) { - wxLogDebug("Changing genre tag.."); + SH_LOG_INFO("Changing genre tag.."); tags.SetGenre(genre.ToStdString()); info_msg = wxString::Format("Successfully changed genre tag to %s", genre); @@ -291,7 +291,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event) if (m_CommentCheck->GetValue() && m_CommentText->GetValue() != tags.GetAudioInfo().comment) { - wxLogDebug("Changing comment tag.."); + SH_LOG_INFO("Changing comment tag.."); tags.SetComment(comment.ToStdString()); info_msg = wxString::Format("Successfully changed comment tag to %s", comment); @@ -299,7 +299,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event) if (m_SampleTypeCheck->GetValue() && m_SampleTypeChoice->GetStringSelection() != sampleType) { - wxLogDebug("Changing type tag.."); + SH_LOG_INFO("Changing type tag.."); db.UpdateSampleType(filename, type.ToStdString()); info_msg = wxString::Format("Successfully changed type tag to %s", type); diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index ee1b211..3d70e63 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -25,6 +25,7 @@ #include "Utility/ControlID_Enums.hpp" #include "Utility/Tags.hpp" #include "Utility/Sample.hpp" +#include "Utility/Log.hpp" #include "SampleHiveConfig.hpp" #include @@ -56,7 +57,6 @@ #include #include #include -#include #include #include #include @@ -87,8 +87,9 @@ #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 APP_CONFIG_DIR wxGetHomeDir() + "/.config/SampleHive" -#define APP_DATA_DIR wxGetHomeDir() + "/.local/share/SampleHive" +#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" @@ -155,6 +156,9 @@ MainFrame::MainFrame() // Set the menu bar to use SetMenuBar(m_MenuBar); + // Initialize the logger + SampleHive::Log::InitLogger("SampleHive"); + // Load default yaml config file. LoadConfigFile(); @@ -209,8 +213,7 @@ MainFrame::MainFrame() _("All files|*|Ogg files (*.ogg)|*.ogg|Wav files (*.wav)|*.wav|" "Flac files (*.flac)|*.flac"), 0); - wxString path = wxGetHomeDir(); - m_DirCtrl->SetPath(path); + 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); @@ -702,7 +705,7 @@ void MainFrame::AddSamples(wxArrayString& files) data.push_back(wxString::Format("%d", sample.GetBitrate())); data.push_back(path); - wxLogDebug(_("Adding file: %s :: Extension: %s"), sample.GetFilename(), sample.GetFileExtension()); + SH_LOG_INFO("Adding file: {}, Extension: {}", sample.GetFilename(), sample.GetFileExtension()); m_Library->AppendItem(data); @@ -733,7 +736,7 @@ void MainFrame::OnClickDirCtrl(wxCommandEvent& event) void MainFrame::OnDragAndDropToLibrary(wxDropFilesEvent& event) { - wxLogDebug(_("Start Inserting Samples")); + SH_LOG_DEBUG("Start Inserting Samples"); if (event.GetNumberOfFiles() > 0) { @@ -776,8 +779,8 @@ void MainFrame::OnDragAndDropToLibrary(wxDropFilesEvent& event) progressDialog->Destroy(); AddSamples(filepath_array); - - wxLogDebug(_("Done Inserting Samples")); + + SH_LOG_DEBUG("Done Inserting Samples"); } } @@ -816,8 +819,7 @@ void MainFrame::OnDragAndDropToHives(wxDropFilesEvent& event) wxString file_name = serializer.DeserializeShowFileExtensionSetting() ? files[i].BeforeLast('.') : files[i]; - wxLogDebug(_("Dropping %d files %s on %s"), - rows - i, files[i], m_Hives->GetItemText(drop_target)); + 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) @@ -859,7 +861,7 @@ void MainFrame::OnDragAndDropToHives(wxDropFilesEvent& event) void MainFrame::OnAutoImportDir(const wxString& pathToDirectory) { - wxLogDebug(_("Start Importing Samples")); + SH_LOG_DEBUG("Start Importing Samples"); wxBusyCursor busy_cursor; wxWindowDisabler window_disabler; @@ -898,7 +900,7 @@ void MainFrame::OnAutoImportDir(const wxString& pathToDirectory) AddSamples(filepath_array); - wxLogDebug(_("Done Importing Samples")); + SH_LOG_DEBUG("Done Importing Samples"); } // Temporary function to check drag and drop result @@ -915,7 +917,7 @@ void LogDragResult(wxDragResult result) default: msg = "Huh?"; break; } - wxLogDebug(wxString("Drag result: ") + msg); + SH_LOG_DEBUG("Drag result: {}", msg); } void MainFrame::OnDragFromDirCtrl(wxTreeEvent& event) @@ -933,7 +935,8 @@ void MainFrame::OnDragFromLibrary(wxDataViewEvent& event) { int selected_row = m_Library->ItemToRow(event.GetItem()); - if (selected_row < 0) return; + if (selected_row < 0) + return; wxString selection = m_Library->GetTextValue(selected_row, 1); @@ -944,7 +947,7 @@ void MainFrame::OnDragFromLibrary(wxDataViewEvent& event) fileData->AddFile(sample_path); event.SetDataObject(fileData); - wxLogDebug(_("Started dragging '%s'."), sample_path); + SH_LOG_DEBUG("Started dragging '{}'.", sample_path); } void MainFrame::OnClickPlay(wxCommandEvent& event) @@ -968,18 +971,16 @@ void MainFrame::OnClickPlay(wxCommandEvent& event) void MainFrame::OnClickLoop(wxCommandEvent& event) { - if (m_LoopButton->GetValue()) - bLoop = true; - else - bLoop = false; + bLoop = m_LoopButton->GetValue(); } void MainFrame::OnClickStop(wxCommandEvent& event) { m_MediaCtrl->Stop(); + bStopped = true; - if (m_Timer->IsRunning()) + if (m_Timer->IsRunning()) m_Timer->Stop(); m_SamplePosition->SetLabel("--:--/--:--"); @@ -1018,7 +1019,7 @@ void MainFrame::OnMediaFinished(wxMediaEvent& event) if (m_Timer->IsRunning()) { m_Timer->Stop(); - wxLogDebug("TIMER STOPPED"); + SH_LOG_DEBUG("TIMER STOPPED"); } m_SamplePosition->SetLabel("--:--/--:--"); @@ -1029,7 +1030,7 @@ void MainFrame::OnMediaFinished(wxMediaEvent& event) void MainFrame::UpdateElapsedTime(wxTimerEvent& event) { - wxLogDebug("TIMER IS RUNNING.."); + SH_LOG_DEBUG("TIMER IS RUNNING.."); wxString duration, position; wxLongLong llLength, llTell; @@ -1104,7 +1105,6 @@ void MainFrame::OnClickLibrary(wxDataViewEvent& event) if (selected_row != current_row) { m_Library->SetCurrentItem(event.GetItem()); - wxLogDebug("Triggered"); return; } @@ -1116,7 +1116,7 @@ void MainFrame::OnClickLibrary(wxDataViewEvent& event) if (m_Timer->IsRunning()) { m_Timer->Stop(); - wxLogDebug("TIMER STOPPED"); + SH_LOG_DEBUG("TIMER STOPPED"); } wxString selection = m_Library->GetTextValue(selected_row, 1); @@ -1151,8 +1151,6 @@ void MainFrame::OnClickLibrary(wxDataViewEvent& event) } else { - wxLogDebug(_("Adding sample to favorite..")); - wxString msg; // Get hive name and location @@ -1265,17 +1263,16 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event) wxString msg; - wxTextEntryDialog* renameEntry; - renameEntry = new wxTextEntryDialog(this, _("Enter new name"), wxGetTextFromUserPromptStr, - wxEmptyString, wxTextEntryDialogStyle, wxDefaultPosition); + wxTextEntryDialog renameEntry(this, _("Enter new name"), wxGetTextFromUserPromptStr, + wxEmptyString, wxTextEntryDialogStyle, wxDefaultPosition); - renameEntry->SetTextValidator(wxFILTER_EMPTY); + renameEntry.SetTextValidator(wxFILTER_EMPTY); - switch (renameEntry->ShowModal()) + switch (renameEntry.ShowModal()) { case wxID_OK: { - wxString hive_name = renameEntry->GetValue(); + wxString hive_name = renameEntry.GetValue(); while(!nodes.empty()) { @@ -1285,15 +1282,12 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event) if (m_Hives->GetItemText(current_item) == hive_name) { found_item = current_item; - wxLogDebug(_("Found item: %s"), m_Hives->GetItemText(current_item)); + SH_LOG_DEBUG("Found item: {}", m_Hives->GetItemText(current_item)); break; } wxDataViewItem child = m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), 0); - wxLogDebug("Row: %d :: Hive count: %d :: Child: %s", - row, hive_count, m_Hives->GetItemText(child)); - while (row < (hive_count - 1)) { row ++; @@ -1320,8 +1314,6 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event) if (sample_count <= 0) { - wxLogDebug("Sample count: %d", sample_count); - m_Hives->SetItemText(selected_hive, hive_name); m_Database->UpdateHive(selected_hive_name.ToStdString(), hive_name.ToStdString()); @@ -1336,9 +1328,6 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event) m_Hives->GetItemText(sample_item).BeforeLast('.') : m_Hives->GetItemText(sample_item); - wxLogDebug("Sample count: %d :: Sample name: %s", - sample_count, sample_name); - m_Database->UpdateHiveName(sample_name.ToStdString(), hive_name.ToStdString()); m_Database->UpdateHive(selected_hive_name.ToStdString(), @@ -1450,7 +1439,7 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event) if (child_name == matched_sample) { - wxLogDebug(_("Found match")); + SH_LOG_DEBUG("Found match"); m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0); @@ -1462,7 +1451,7 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event) break; } else - wxLogDebug(_("No match found")); + SH_LOG_DEBUG("No match found"); } } @@ -1495,7 +1484,8 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event) { const auto dataset = m_Database->FilterDatabaseByHiveName(hive_name.ToStdString(), serializer.DeserializeShowFileExtensionSetting(), - ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px); + ICON_STAR_FILLED_16px, + ICON_STAR_EMPTY_16px); if (dataset.empty()) { @@ -1507,8 +1497,6 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event) { m_Library->DeleteAllItems(); - wxLogDebug("Hive name: %s", hive_name); - for (auto data : dataset) { m_Library->AppendItem(data); @@ -1576,7 +1564,7 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event) if(selected_sample_name == matched_sample) { - wxLogDebug(_("Found match")); + SH_LOG_DEBUG("Found match"); m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0); @@ -1608,7 +1596,7 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event) if(selected_sample_name == matched_sample) { - wxLogDebug(_("Found match")); + SH_LOG_DEBUG("Found match"); wxDataViewItem matched_item = m_Library->RowToItem(i); @@ -1776,23 +1764,21 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event) 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('/')), + 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), + 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 | @@ -1808,8 +1794,6 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event) { case wxID_YES: { - wxLogDebug("Selected row: %d :: Sample: %s", selected_row, filename); - m_Database->RemoveSampleFromDatabase(filename); m_Library->DeleteItem(selected_row); @@ -1903,7 +1887,7 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event) wxDataViewItem container, child; if (m_Database->IsTrashed(filename)) - wxLogDebug(_("Already trashed..")); + SH_LOG_INFO("{} already trashed", filename); else { wxDataViewItemArray items; @@ -1975,13 +1959,13 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event) switch (tagEditor->ShowModal()) { case wxID_OK: - wxLogDebug("tags dialog ok, Return code: %d", tagEditor->GetReturnCode()); + SH_LOG_DEBUG("tags dialog ok, Return code: {}", tagEditor->GetReturnCode()); break; case wxID_APPLY: - wxLogDebug("tags dialog apply, Return code: %d", tagEditor->GetReturnCode()); + SH_LOG_DEBUG("tags dialog apply, Return code: {}", tagEditor->GetReturnCode()); break; case wxID_CANCEL: - wxLogDebug("tags dialog cancel, Return code: %d", tagEditor->GetReturnCode()); + SH_LOG_DEBUG("tags dialog cancel, Return code: {}", tagEditor->GetReturnCode()); break; default: msg = _("Unexpected TagEditor return code!"); @@ -1996,6 +1980,7 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event) default: wxMessageBox(_("Unexpected wxMenu return code!"), _("Error!"), wxOK | wxICON_ERROR | wxCENTRE, this); + break; } if(!msg.IsEmpty()) @@ -2016,15 +2001,24 @@ void MainFrame::OnShowLibraryColumnHeaderContextMenu(wxDataViewEvent& event) 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()); + 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())) { @@ -2072,7 +2066,7 @@ void MainFrame::LoadDatabase() ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px); if (dataset.empty()) - wxLogInfo(_("Error! Database is empty.")); + SH_LOG_INFO("Error! Database is empty."); else { for (auto data : dataset) @@ -2104,8 +2098,6 @@ void MainFrame::OnShowTrashContextMenu(wxTreeEvent& event) { case MN_DeleteTrash: { - wxLogDebug(_("Delete permanently")); - wxString trashed_item_name = serializer.DeserializeShowFileExtensionSetting() ? m_Trash->GetItemText(selected_trashed_item).BeforeLast('.') : m_Trash->GetItemText(selected_trashed_item); @@ -2113,12 +2105,12 @@ void MainFrame::OnShowTrashContextMenu(wxTreeEvent& event) 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: { - wxLogDebug(_("Restore sample")); - wxArrayTreeItemIds selected_item_ids; m_Trash->GetSelections(selected_item_ids); @@ -2132,9 +2124,6 @@ void MainFrame::OnShowTrashContextMenu(wxTreeEvent& event) { selected_item_text = m_Trash->GetItemText(selected_item_ids[i]); - wxLogDebug("Count: %d :: Selected item text: %s", - static_cast(selected_item_ids.GetCount()), selected_item_text); - filename = GetFilenamePathAndExtension(selected_item_text).Filename; file_data.AddFile(filename); @@ -2148,10 +2137,12 @@ void MainFrame::OnShowTrashContextMenu(wxTreeEvent& event) wxVector> dataset; if (m_Database->RestoreFromTrashByFilename(files[i].ToStdString(), - dataset, serializer.DeserializeShowFileExtensionSetting(), - ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty()) + dataset, + serializer.DeserializeShowFileExtensionSetting(), + ICON_STAR_FILLED_16px, + ICON_STAR_EMPTY_16px).empty()) { - wxLogDebug(_("Error! Database is empty.")); + SH_LOG_INFO("Error! Database is empty."); } else { @@ -2167,6 +2158,8 @@ void MainFrame::OnShowTrashContextMenu(wxTreeEvent& event) } m_Trash->Delete(selected_item_ids[i]); + + SH_LOG_INFO("{} restored from trash", files[i]); } } break; @@ -2252,7 +2245,7 @@ void MainFrame::OnDragAndDropToTrash(wxDropFilesEvent& event) void MainFrame::OnClickAddHive(wxCommandEvent& event) { - std::deque nodes; + std::deque nodes; nodes.push_back(m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), 0)); wxDataViewItem current_item, found_item; @@ -2262,18 +2255,16 @@ void MainFrame::OnClickAddHive(wxCommandEvent& event) wxString msg; - wxTextEntryDialog* hiveEntry; - hiveEntry = new wxTextEntryDialog(this, _("Enter hive name"), - _("Create new hive"), wxEmptyString, - wxTextEntryDialogStyle, wxDefaultPosition); + wxTextEntryDialog hiveEntry(this, _("Enter hive name"), _("Create new hive"), wxEmptyString, + wxTextEntryDialogStyle, wxDefaultPosition); - hiveEntry->SetTextValidator(wxFILTER_EMPTY); + hiveEntry.SetTextValidator(wxFILTER_EMPTY); - switch (hiveEntry->ShowModal()) + switch (hiveEntry.ShowModal()) { case wxID_OK: { - wxString hive_name = hiveEntry->GetValue(); + wxString hive_name = hiveEntry.GetValue(); while(!nodes.empty()) { @@ -2283,15 +2274,12 @@ void MainFrame::OnClickAddHive(wxCommandEvent& event) if (m_Hives->GetItemText(current_item) == hive_name) { found_item = current_item; - wxLogDebug(_("Found item: %s"), m_Hives->GetItemText(current_item)); + SH_LOG_DEBUG("Found item: {}", m_Hives->GetItemText(current_item)); break; } wxDataViewItem child = m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), 0); - wxLogDebug("Row: %d :: Hive count: %d :: Child: %s", - row, hive_count, m_Hives->GetItemText(child)); - while (row < (hive_count - 1)) { row ++; @@ -2305,9 +2293,9 @@ void MainFrame::OnClickAddHive(wxCommandEvent& event) if (found_item.IsOk()) { - wxMessageBox(wxString::Format( - _("Another hive by the name %s already exist. Please try with a different name."), - hive_name), + wxMessageBox(wxString::Format(_("Another hive by the name %s already exist. " + "Please try with a different name."), + hive_name), _("Error!"), wxOK | wxCENTRE, this); } else @@ -2338,18 +2326,16 @@ void MainFrame::OnClickRemoveHive(wxCommandEvent& event) wxString msg; - wxMessageDialog deleteEmptyHiveDialog(this, wxString::Format( - _("Are you sure you want to delete " - "%s from hives?"), - hive_name), + 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), + 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); @@ -2418,7 +2404,7 @@ void MainFrame::OnClickRemoveHive(wxCommandEvent& event) if (child_name == matched_sample) { - wxLogDebug(_("Found match")); + SH_LOG_DEBUG("Found match"); m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0); @@ -2429,7 +2415,7 @@ void MainFrame::OnClickRemoveHive(wxCommandEvent& event) break; } else - wxLogDebug(_("No match found")); + SH_LOG_DEBUG("No match found"); } } @@ -2438,7 +2424,8 @@ void MainFrame::OnClickRemoveHive(wxCommandEvent& event) m_Database->RemoveHiveFromDatabase(hive_name.ToStdString()); - msg = wxString::Format(_("%s and all samples inside %s have been deleted from hives successfully."), + msg = wxString::Format(_("%s and all samples inside %s have been deleted " + "from hives successfully."), hive_name, hive_name); } break; @@ -2483,9 +2470,6 @@ void MainFrame::OnClickRestoreTrashItem(wxCommandEvent& event) { selected_item_text = m_Trash->GetItemText(selected_item_ids[i]); - wxLogDebug("Count: %d :: Selected item text: %s", - static_cast(selected_item_ids.GetCount()), selected_item_text); - filename = GetFilenamePathAndExtension(selected_item_text).Filename; file_data.AddFile(filename); @@ -2502,7 +2486,7 @@ void MainFrame::OnClickRestoreTrashItem(wxCommandEvent& event) serializer.DeserializeShowFileExtensionSetting(), ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty()) { - wxLogDebug(_("Error! Database is empty.")); + SH_LOG_INFO("Error! Database is empty."); } else { @@ -2529,12 +2513,14 @@ void MainFrame::OnDoSearch(wxCommandEvent& event) try { - const auto dataset = m_Database->FilterDatabaseBySampleName(search, serializer.DeserializeShowFileExtensionSetting(), - ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px); + const auto dataset = m_Database->FilterDatabaseBySampleName(search, + serializer.DeserializeShowFileExtensionSetting(), + ICON_STAR_FILLED_16px, + ICON_STAR_EMPTY_16px); if (dataset.empty()) { - wxLogDebug(_("Error! Database is empty.")); + SH_LOG_INFO("Error! Database is empty."); } else { @@ -2568,8 +2554,7 @@ void MainFrame::LoadConfigFile() wxPOSIX_GROUP_READ | wxPOSIX_GROUP_EXECUTE | wxPOSIX_OTHERS_READ | wxPOSIX_OTHERS_EXECUTE, wxPATH_MKDIR_FULL)) { - wxLogDebug(wxString::Format(_("Successfully created configuratin directory at %s"), - APP_CONFIG_DIR)); + SH_LOG_INFO("Successfully created configuratin directory at {}", APP_CONFIG_DIR); } else { @@ -2585,7 +2570,7 @@ void MainFrame::LoadConfigFile() wxPOSIX_GROUP_READ | wxPOSIX_GROUP_EXECUTE | wxPOSIX_OTHERS_READ | wxPOSIX_OTHERS_EXECUTE, wxPATH_MKDIR_FULL)) { - wxLogDebug(wxString::Format(_("Successfully created data directory at %s"), APP_DATA_DIR)); + SH_LOG_INFO("Successfully created data directory at {}", APP_DATA_DIR); } else { @@ -2596,7 +2581,7 @@ void MainFrame::LoadConfigFile() Serializer serialize(m_ConfigFilepath); - wxLogDebug(_("Reading from configuration file..")); + SH_LOG_INFO("Reading configuration file.."); int height = 600, width = 800; @@ -2631,8 +2616,6 @@ void MainFrame::RefreshDatabase() { m_Library->DeleteAllItems(); - wxLogDebug("Count: %d", m_Hives->GetChildCount(wxDataViewItem(wxNullPtr))); - if (m_Hives->GetChildCount(wxDataViewItem(wxNullPtr)) < 1 && m_Hives->GetItemText(wxDataViewItem(wxNullPtr)) == m_Hives->GetItemText(favorites_hive)) return; @@ -2659,7 +2642,7 @@ void MainFrame::CreateWatcher() { Serializer serializer(m_ConfigFilepath); - wxCHECK_RET(!m_FsWatcher, "Watcher already initialized"); + wxCHECK_RET(!m_FsWatcher, _("Watcher already initialized")); m_FsWatcher = new wxFileSystemWatcher(); m_FsWatcher->SetOwner(this); @@ -2668,7 +2651,7 @@ void MainFrame::CreateWatcher() if (serializer.DeserializeAutoImportSettings().first) { - wxLogDebug("Adding watch entry.."); + SH_LOG_INFO("Adding watch entry: {}", path); AddWatchEntry(wxFSWPath_Tree, path.ToStdString()); } } @@ -2679,21 +2662,18 @@ void MainFrame::AddWatchEntry(wxFSWPathType type, std::string path) if (path.empty()) { - path = wxDirSelector("Choose a directory to watch", "", wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST); + path = wxDirSelector(_("Choose a directory to watch"), "", wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST); if (path.empty()) return; } - wxCHECK_RET(m_FsWatcher, "Watcher not initialized"); + wxCHECK_RET(m_FsWatcher, _("Watcher not initialized")); - wxLogDebug("Adding %s: '%s'", path, type == wxFSWPath_Dir ? "directory" : "directory tree"); + SH_LOG_INFO("Adding {}: '{}'", path, type == wxFSWPath_Dir ? "directory" : "directory tree"); wxFileName filename = wxFileName::DirName(path); - if (filename.IsDir() && filename.IsDirReadable() && filename.IsOk()) - wxLogDebug("Path is ok, adding to watch list."); - if (!serializer.DeserializeFollowSymLink()) { filename.DontFollowLink(); @@ -2711,12 +2691,12 @@ void MainFrame::AddWatchEntry(wxFSWPathType type, std::string path) case wxFSWPath_File: break; case wxFSWPath_None: - wxFAIL_MSG("Unexpected path type."); + wxFAIL_MSG(_("Error! Unexpected path type.")); } if (!ok) { - wxLogError("Error! Cannot add '%s' to watched paths", filename.GetPath()); + SH_LOG_ERROR("Error! Cannot add '{}' to watched paths", filename.GetPath()); return; } } @@ -2732,31 +2712,31 @@ void MainFrame::OnFileSystemEvent(wxFileSystemWatcherEvent& event) wxArrayString files; files.push_back(path); - wxLogDebug("%s %s", path, event.ToString()); + SH_LOG_DEBUG("{} {}", path, event.ToString()); switch (type) { case wxFSW_EVENT_CREATE: - wxLogDebug("NEW FILES DETECTED, ADDING: %s", path); + SH_LOG_INFO("NEW FILES DETECTED, ADDING: {}", path); AddSamples(files); break; case wxFSW_EVENT_ACCESS: - wxLogDebug("ACCESSING DIRECTORY: %s", path); + SH_LOG_INFO("ACCESSING DIRECTORY: {}", path); break; case wxFSW_EVENT_DELETE: - wxLogDebug("FILES DELETED IN DIRECTORY: %s", path); + SH_LOG_INFO("FILES DELETED IN DIRECTORY: {}", path); break; case wxFSW_EVENT_MODIFY: - wxLogDebug("DIRECTORY MODIFIED: %s", path); + SH_LOG_INFO("DIRECTORY MODIFIED: {}", path); break; case wxFSW_EVENT_RENAME: - wxLogDebug("FILES RENAMED IN DIRECTORY: %s", event.GetNewPath().GetFullPath()); + SH_LOG_INFO("FILES RENAMED IN DIRECTORY: {}", event.GetNewPath().GetFullPath()); break; case wxFSW_EVENT_WARNING: - wxLogDebug("Filesystem watcher warning: %d", event.GetWarningType()); + SH_LOG_INFO("Filesystem watcher warning: {}", event.GetWarningType()); break; case wxFSW_EVENT_ERROR: - wxLogDebug("Error! Filesystem watcher: %s", event.GetErrorDescription()); + SH_LOG_INFO("Error! Filesystem watcher: {}", event.GetErrorDescription()); break; default: break; @@ -2792,13 +2772,13 @@ FileInfo MainFrame::GetFilenamePathAndExtension(const wxString& selected, void MainFrame::OnHiveStartEditing(wxDataViewEvent &event) { - wxLogDebug(_("Right click on a hive and select rename to rename it..")); + SH_LOG_INFO("Right click on a hive and select rename to rename it.."); event.Veto(); } void MainFrame::OnSelectAddFile(wxCommandEvent& event) { - wxFileDialog file_dialog(this, wxFileSelectorPromptStr, wxGetHomeDir(), + wxFileDialog file_dialog(this, wxFileSelectorPromptStr, USER_HOME_DIR, wxEmptyString, wxFileSelectorDefaultWildcardStr, wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE | wxFD_PREVIEW, wxDefaultPosition, wxDefaultSize); @@ -2821,8 +2801,8 @@ void MainFrame::OnSelectAddFile(wxCommandEvent& event) void MainFrame::OnSelectAddDirectory(wxCommandEvent& event) { - wxDirDialog dir_dialog(this, wxDirSelectorPromptStr, wxGetHomeDir(), - wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST, wxDefaultPosition, wxDefaultSize); + wxDirDialog dir_dialog(this, wxDirSelectorPromptStr, USER_HOME_DIR, + wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST, wxDefaultPosition, wxDefaultSize); switch (dir_dialog.ShowModal()) { @@ -2939,7 +2919,7 @@ void MainFrame::OnSelectResetAppData(wxCommandEvent& event) "\"%s\" and database file \"%s\" permanently, " "are you sure you want to delete these files?"), m_ConfigFilepath, m_DatabaseFilepath), - _("Clear app data"), + _("Clear app data?"), wxYES_NO | wxNO_DEFAULT | wxCENTRE, wxDefaultPosition); bool remove = false; @@ -2951,21 +2931,21 @@ void MainFrame::OnSelectResetAppData(wxCommandEvent& event) if (remove) { - bool configIsDeleted = wxRemoveFile(m_ConfigFilepath); + bool config_is_deleted = wxRemoveFile(m_ConfigFilepath); - if (configIsDeleted) - wxLogDebug("Deleted %s", m_ConfigFilepath); + if (config_is_deleted) + SH_LOG_INFO("Deleted {}", m_ConfigFilepath); else - wxLogDebug("Could not delete %s", m_ConfigFilepath); + SH_LOG_ERROR("Could not delete {}", m_ConfigFilepath); - bool dbIsDeleted = wxRemoveFile(m_DatabaseFilepath); + bool db_is_deleted = wxRemoveFile(m_DatabaseFilepath); - if (dbIsDeleted) - wxLogDebug("Deleted %s", m_DatabaseFilepath); + if (db_is_deleted) + SH_LOG_INFO("Deleted {}", m_DatabaseFilepath); else - wxLogDebug("Could not delete %s", m_DatabaseFilepath); + SH_LOG_ERROR("Could not delete {}", m_DatabaseFilepath); - if (configIsDeleted && dbIsDeleted) + if (config_is_deleted && db_is_deleted) m_InfoBar->ShowMessage(_("Successfully cleared app data"), wxICON_INFORMATION); else wxMessageBox(_("Error! Could not clear app data"), _("Error!"), @@ -3033,8 +3013,6 @@ void MainFrame::SetAfterFrameCreate() void MainFrame::OnRecieveLoopPoints(SampleHive::SH_LoopPointsEvent& event) { - wxLogDebug("%s called and recieved loop points", __FUNCTION__); - std::pair loop_points = event.GetLoopPoints(); m_LoopA = wxLongLong(loop_points.first); @@ -3045,14 +3023,12 @@ 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()); - wxLogDebug(wxString::Format("LoopA: %2i:%02i, LoopB: %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); bLoopPointsSet = true; - - wxLogDebug("%s Event processed successfully..", __FUNCTION__); } void MainFrame::OnRecieveStatusBarStatus(SampleHive::SH_StatusBarMessageEvent& event) @@ -3073,15 +3049,13 @@ void MainFrame::ClearLoopPoints() void MainFrame::PlaySample(const std::string& filepath, const std::string& sample, bool seek, wxFileOffset where, wxSeekMode mode) { - wxLogDebug("TIMER STARTING FROM %s", __FUNCTION__); - if (m_MediaCtrl->Load(filepath)) { if (seek) m_MediaCtrl->Seek(where, mode); if (!m_MediaCtrl->Play()) - wxLogDebug(_("Error! Cannot play sample.")); + SH_LOG_ERROR("Error! Cannot play sample."); PushStatusText(wxString::Format(_("Now playing: %s"), sample), 1); @@ -3089,7 +3063,7 @@ void MainFrame::PlaySample(const std::string& filepath, const std::string& sampl m_Timer->Start(20, wxTIMER_CONTINUOUS); } else - wxLogDebug(_("Error! Cannot load sample.")); + SH_LOG_ERROR("Error! Cannot load sample."); } MainFrame::~MainFrame() diff --git a/src/GUI/WaveformViewer.cpp b/src/GUI/WaveformViewer.cpp index b21bf0c..41199e8 100644 --- a/src/GUI/WaveformViewer.cpp +++ b/src/GUI/WaveformViewer.cpp @@ -22,6 +22,7 @@ #include "Utility/Serialize.hpp" #include "Utility/Tags.hpp" #include "Utility/SH_Event.hpp" +#include "Utility/Log.hpp" #include @@ -31,7 +32,6 @@ #include #include #include -#include #include #include @@ -70,7 +70,7 @@ void WaveformViewer::OnPaint(wxPaintEvent& event) || m_WaveformBitmap.GetHeight() != size.y || bBitmapDirty) { - wxLogDebug("Updating waveform bitmap.."); + SH_LOG_INFO("Updating waveform bitmap.."); m_WaveformBitmap = wxBitmap(wxImage(size.x, size.y), 32); @@ -121,15 +121,15 @@ void WaveformViewer::RenderPlayhead(wxDC& dc) Tags tags(path); int length = tags.GetAudioInfo().length; - wxLogDebug("Sample length: %d", length); + SH_LOG_DEBUG("Sample length: {}", length); double position = m_MediaCtrl.Tell(); - wxLogDebug("Current Sample Position: %f", position); + SH_LOG_DEBUG("Current Sample Position: {}", position); int panel_width = this->GetSize().GetWidth(); double line_pos = panel_width * (position / length); - wxLogDebug("Drawing playhead at: %f", line_pos); + SH_LOG_DEBUG("Drawing playhead at: {}", line_pos); m_PlayheadColour = wxColor(255, 0, 0, 255); @@ -185,7 +185,7 @@ void WaveformViewer::UpdateWaveformBitmap() float display_width = this->GetSize().GetWidth(); float display_height = this->GetSize().GetHeight(); - wxLogDebug("Calculating Waveform bars RMS.."); + SH_LOG_INFO("Calculating Waveform bars RMS.."); float chunk_size = (float)(frames) / (float)display_width; int number_of_chunks = static_cast(static_cast(frames) / chunk_size); @@ -235,7 +235,7 @@ void WaveformViewer::UpdateWaveformBitmap() mdc.SetPen(wxPen(wxColour(m_WaveformColour), 2, wxPENSTYLE_SOLID)); - wxLogDebug("Drawing bitmap.."); + SH_LOG_DEBUG("Drawing bitmap.."); for (int i = 0; i < waveform.size() - 1; i++) { @@ -249,7 +249,7 @@ void WaveformViewer::UpdateWaveformBitmap() mdc.DrawLine(X, half_display_height + Y, X, half_display_height - Y); } - wxLogDebug("Done drawing bitmap.."); + SH_LOG_DEBUG("Done drawing bitmap.."); } void WaveformViewer::OnControlKeyDown(wxKeyEvent &event) @@ -314,7 +314,7 @@ void WaveformViewer::OnMouseMotion(wxMouseEvent& event) if (abs(pos.x - line_pos) <= 5 && pos.y <= 5) { SetCursor(wxCursor(wxCURSOR_HAND)); - wxLogDebug("Cursor on playhead.."); + SH_LOG_DEBUG("Cursor on playhead.."); } else if (bSelectRange) { @@ -322,7 +322,7 @@ void WaveformViewer::OnMouseMotion(wxMouseEvent& event) Refresh(); - wxLogDebug("CTRL pressed, pressing LMB will draw selection range at %d, %d", pos.x, pos.y); + SH_LOG_INFO("CTRL pressed, pressing LMB will draw selection range at {}, {}", pos.x, pos.y); } else return; @@ -354,11 +354,11 @@ void WaveformViewer::OnMouseLeftButtonDown(wxMouseEvent& event) SetCursor(wxCURSOR_CLOSED_HAND); CaptureMouse(); - wxLogDebug("Mouse Captured playhead.."); + SH_LOG_DEBUG("Mouse Captured playhead.."); } else if (event.ControlDown()) { - wxLogDebug("LMB pressed"); + SH_LOG_DEBUG("LMB pressed"); SetCursor(wxCURSOR_CLOSED_HAND); CaptureMouse(); @@ -402,13 +402,13 @@ void WaveformViewer::OnMouseLeftButtonUp(wxMouseEvent& event) if (!wxWindow::HasCapture()) { - wxLogDebug("Window doesn't have capture skipping.."); + SH_LOG_INFO("Window doesn't have capture skipping.."); return; } if (bSelectRange) { - wxLogDebug("LMB released"); + SH_LOG_DEBUG("LMB released"); m_CurrentPoint = wxPoint(pos.x, pos.y); @@ -444,7 +444,7 @@ void WaveformViewer::ResetDC() void WaveformViewer::SendLoopPoints() { - wxLogDebug("%s Called", __FUNCTION__); + SH_LOG_DEBUG("{} Called", __FUNCTION__); SampleHive::SH_LoopPointsEvent event(SampleHive::SH_EVT_LOOP_POINTS_UPDATED, this->GetId()); event.SetEventObject(this); @@ -472,7 +472,7 @@ void WaveformViewer::SendLoopPoints() HandleWindowEvent(event); - wxLogDebug("%s processed event, sending loop points..", __FUNCTION__); + SH_LOG_DEBUG("{} processed event, sending loop points..", __FUNCTION__); } void WaveformViewer::SendStatusBarStatus(const wxString& msg, int section) diff --git a/src/Utility/Log.cpp b/src/Utility/Log.cpp new file mode 100644 index 0000000..3f7574f --- /dev/null +++ b/src/Utility/Log.cpp @@ -0,0 +1,26 @@ +#include "Log.hpp" + +#include + +#include "spdlog/sinks/stdout_color_sinks.h" + +namespace SampleHive { + + std::shared_ptr Log::s_Logger; + + void Log::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); + } + catch (const spdlog::spdlog_ex& ex) + { + std::cout << "Logger initialization failed: " << ex.what() << std::endl; + } + } + +} diff --git a/src/Utility/Log.hpp b/src/Utility/Log.hpp new file mode 100644 index 0000000..61395d0 --- /dev/null +++ b/src/Utility/Log.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include + +#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE + +#include + +namespace SampleHive { + + class Log + { + public: + static void InitLogger(const std::string& logger); + + public: + inline static std::shared_ptr& GetLogger() { return s_Logger; } + + private: + static std::shared_ptr s_Logger; + }; + +} + +// 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/Serialize.cpp b/src/Utility/Serialize.cpp index 06b95c7..0c49e6e 100644 --- a/src/Utility/Serialize.cpp +++ b/src/Utility/Serialize.cpp @@ -19,12 +19,12 @@ */ #include "Utility/Serialize.hpp" +#include "Utility/Log.hpp" #include #include #include -#include #include #include @@ -43,9 +43,12 @@ Serializer::Serializer(const std::string& filepath) std::string dir = wxGetHomeDir().ToStdString(); + // Initialize the logger + // SampleHive::Log::InitLogger("Serializer"); + if (!ifstrm) { - wxLogDebug("Genrating configuration file.."); + SH_LOG_INFO("Genrating configuration file.."); m_Emitter << YAML::Comment("This is the configuration file for SampleHive," "feel free to edit the file as needed"); @@ -94,7 +97,7 @@ Serializer::Serializer(const std::string& filepath) std::ofstream ofstrm(m_Filepath); ofstrm << m_Emitter.c_str(); - wxLogDebug("Generated %s successfully!", m_Filepath); + SH_LOG_INFO("Generated {} successfully!", m_Filepath); } } @@ -124,10 +127,10 @@ WindowSize Serializer::DeserializeWinSize() const } catch(const YAML::ParserException& ex) { - std::cout << ex.what() << std::endl; + SH_LOG_ERROR(ex.what()); } - wxLogDebug("Window size: %d, %d", width, height); + SH_LOG_INFO("Window size: {}, {}", width, height); return { width, height }; } @@ -154,11 +157,11 @@ void Serializer::SerializeShowMenuAndStatusBar(std::string key, bool value) ofstrm << out.c_str(); } else - wxLogDebug("Error! Cannot store show bar values."); + SH_LOG_ERROR("Error! Cannot store show bar values."); } catch(const YAML::ParserException& ex) { - std::cout << ex.what() << std::endl; + SH_LOG_ERROR(ex.what()); } } @@ -180,12 +183,12 @@ bool Serializer::DeserializeShowMenuAndStatusBar(std::string key) const } else { - wxLogDebug("Error! Cannot fetch show bar values."); + SH_LOG_ERROR("Error! Cannot fetch show bar values."); } } catch(const YAML::ParserException& ex) { - std::cout << ex.what() << std::endl; + SH_LOG_ERROR(ex.what()); } return show; @@ -216,11 +219,11 @@ void Serializer::SerializeBrowserControls(std::string key, bool value) ofstrm << out.c_str(); } else - wxLogDebug("Error! Cannot store media values."); + SH_LOG_ERROR("Error! Cannot store media values."); } catch(const YAML::ParserException& ex) { - std::cout << ex.what() << std::endl; + SH_LOG_ERROR(ex.what()); } } @@ -244,14 +247,14 @@ bool Serializer::DeserializeBrowserControls(std::string key) const control = media["Muted"].as(); } else - wxLogDebug("Error! Cannot fetch values."); + SH_LOG_ERROR("Error! Cannot fetch values."); } catch(const YAML::ParserException& ex) { - std::cout << ex.what() << std::endl; + SH_LOG_ERROR(ex.what()); } - wxLogDebug("%s: %s", key, control ? "enabled" : "disabled"); + SH_LOG_INFO("{}: {}", key, control ? "enabled" : "disabled"); return control; } @@ -281,12 +284,12 @@ void Serializer::SerializeDisplaySettings(wxFont& font) } else { - wxLogDebug("Error! Cannot store font values."); + SH_LOG_ERROR("Error! Cannot store font values."); } } catch(const YAML::ParserException& ex) { - std::cout << ex.what() << std::endl; + SH_LOG_ERROR(ex.what()); } } @@ -313,12 +316,12 @@ wxFont Serializer::DeserializeDisplaySettings() const } else { - wxLogDebug("Error! Cannot fetch font values."); + SH_LOG_ERROR("Error! Cannot fetch font values."); } } catch(const YAML::ParserException& ex) { - std::cout << ex.what() << std::endl; + SH_LOG_ERROR(ex.what()); } return font; @@ -347,12 +350,12 @@ void Serializer::SerializeWaveformColour(wxColour& colour) } else { - wxLogDebug("Error! Cannot store waveform colour."); + SH_LOG_ERROR("Error! Cannot store waveform colour."); } } catch(const YAML::ParserException& ex) { - std::cout << ex.what() << std::endl; + SH_LOG_ERROR(ex.what()); } } @@ -372,12 +375,12 @@ wxColour Serializer::DeserializeWaveformColour() const } else { - wxLogDebug("Error! Cannot fetch waveform colour."); + SH_LOG_ERROR("Error! Cannot fetch waveform colour."); } } catch(const YAML::ParserException& ex) { - std::cout << ex.what() << std::endl; + SH_LOG_ERROR(ex.what()); } return static_cast(colour); @@ -403,12 +406,12 @@ void Serializer::SerializeAutoImportSettings(bool autoImport, const std::string& } else { - wxLogDebug("Error! Cannot store import dir values."); + SH_LOG_ERROR("Error! Cannot store import dir values."); } } catch(const YAML::ParserException& ex) { - std::cout << ex.what() << std::endl; + SH_LOG_ERROR(ex.what()); } } @@ -428,12 +431,12 @@ ImportDirInfo Serializer::DeserializeAutoImportSettings() const } else { - wxLogDebug("Error! Cannot fetch import dir values."); + SH_LOG_ERROR("Error! Cannot fetch import dir values."); } } - catch (const YAML::ParserException& ex) + catch(const YAML::ParserException& ex) { - std::cout << ex.what() << std::endl; + SH_LOG_ERROR(ex.what()); } return { auto_import, dir }; @@ -458,12 +461,12 @@ void Serializer::SerializeFollowSymLink(bool followSymLinks) } else { - wxLogDebug("Error! Cannot store follow symbolic links value."); + SH_LOG_ERROR("Error! Cannot store follow symbolic links value."); } } catch(const YAML::ParserException& ex) { - std::cout << ex.what() << std::endl; + SH_LOG_ERROR(ex.what()); } } @@ -481,12 +484,12 @@ bool Serializer::DeserializeFollowSymLink() const } else { - wxLogDebug("Error! Cannot fetch follow symbolic links value."); + SH_LOG_ERROR("Error! Cannot fetch follow symbolic links value."); } } catch(const YAML::ParserException& ex) { - std::cout << ex.what() << std::endl; + SH_LOG_ERROR(ex.what()); } return follow_sym_links; @@ -511,14 +514,13 @@ void Serializer::SerializeShowFileExtensionSetting(bool showExtension) } else { - wxLogDebug("Error! Cannot store show file extension value."); + SH_LOG_ERROR("Error! Cannot store show file extension value."); } } catch(const YAML::ParserException& ex) { - std::cout << ex.what() << std::endl; + SH_LOG_ERROR(ex.what()); } - } bool Serializer::DeserializeShowFileExtensionSetting() const @@ -535,12 +537,12 @@ bool Serializer::DeserializeShowFileExtensionSetting() const } else { - wxLogDebug("Error! Cannot fetch show file extension value."); + SH_LOG_ERROR("Error! Cannot fetch show file extension value."); } } catch(const YAML::ParserException& ex) { - std::cout << ex.what() << std::endl; + SH_LOG_ERROR(ex.what()); } return show_extension; diff --git a/subprojects/spdlog.wrap b/subprojects/spdlog.wrap new file mode 100644 index 0000000..bfa4995 --- /dev/null +++ b/subprojects/spdlog.wrap @@ -0,0 +1,12 @@ +[wrap-file] +directory = spdlog-1.8.5 +source_url = https://github.com/gabime/spdlog/archive/v1.8.5.tar.gz +source_filename = v1.8.5.tar.gz +source_hash = 944d0bd7c763ac721398dca2bb0f3b5ed16f67cef36810ede5061f35a543b4b8 +patch_url = https://wrapdb.mesonbuild.com/v2/spdlog_1.8.5-1/get_patch +patch_filename = spdlog-1.8.5-1-wrap.zip +patch_hash = 3c38f275d5792b1286391102594329e98b17737924b344f98312ab09929b74be + +[provide] +spdlog = spdlog_dep +