Add command line option to reset app data, new Paths header, more code refactoring.

This commit is contained in:
apoorv569 2021-11-07 08:41:04 +05:30
parent 8bfb8c718a
commit 77fb65377b
16 changed files with 323 additions and 210 deletions

View File

@ -1,11 +1,6 @@
((nil . ((cmake-ide-project-dir . "~/repos/sample-hive") ((nil . ((cmake-ide-project-dir . "~/repos/sample-hive")
(cmake-ide-build-dir . "~/repos/sample-hive/build")
(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-name . "SampleHive")
(cmake-ide-cmake-opts . "-DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DPORTABLE=1 -DCMAKE_CXX_COMPILER='/usr/bin/g++'") (projectile-project-run-cmd . "~/repos/sample-hive/build/SampleHive")
(projectile-project-test-cmd . "./test.sh"))))
(projectile-project-name . "SampleHive")
(projectile-project-run-cmd . "~/repos/sample-hive/build/SampleHive")
(projectile-project-test-cmd . "./test.sh"))))

View File

@ -22,23 +22,47 @@ project('SampleHive',
version : 'v0.9.0_alpha.1', version : 'v0.9.0_alpha.1',
license : 'GPL v3', license : 'GPL v3',
meson_version: '>= 0.58.0', meson_version: '>= 0.58.0',
default_options : ['warning_level=1', default_options : ['warning_level=2',
'cpp_std=c++14']) 'buildtype=debugoptimized',
'b_lto=true',
meson_src_root = meson.current_source_dir() 'b_lto_threads=2',
meson_build_root = meson.current_build_dir() 'cpp_std=gnu++14'])
# Create configuration data # Create configuration data
config_data = configuration_data() config_data = configuration_data()
# Save project information # Save project information
meson_src_root = meson.current_source_dir()
meson_build_root = meson.current_build_dir()
project_name = meson.project_name() project_name = meson.project_name()
project_license = meson.project_license() project_license = meson.project_license()
project_version = meson.project_version() project_version = meson.project_version()
project_author = 'Apoorv'
project_copyright_years = '2020-2021'
project_description = 'A simple, modern audio sample browser/manager for GNU/Linux.'
project_website = 'http://samplehive.gitlab.io/website'
config_data.set_quoted('NAME', project_name) build_type = get_option('buildtype')
config_data.set_quoted('LICENSE', project_license)
config_data.set_quoted('VERSION', project_version) host_sys = host_machine.system()
cpp_compiler_id = meson.get_compiler('cpp').get_id()
cpp_compiler_version = meson.get_compiler('cpp').version()
config_data.set_quoted('PROJECT_NAME', project_name)
config_data.set_quoted('PROJECT_LICENSE', project_license)
config_data.set_quoted('PROJECT_VERSION', project_version)
config_data.set_quoted('PROJECT_AUTHOR', project_author)
config_data.set_quoted('PROJECT_COPYRIGHT_YEARS', project_copyright_years)
config_data.set_quoted('PROJECT_DESCRIPTION', project_description)
config_data.set_quoted('PROJECT_WEBSITE', project_website)
config_data.set_quoted('BUILD_TYPE', build_type)
config_data.set_quoted('HOST_MACHINE', host_sys)
config_data.set_quoted('MESON_SRC_ROOT', meson_src_root)
config_data.set_quoted('MESON_BUILD_ROOT', meson_build_root)
config_data.set_quoted('CPP_COMPILER', cpp_compiler_id)
config_data.set_quoted('CPP_COMPILER_VERSION', cpp_compiler_version)
# Save important directories # Save important directories
prefix = get_option('prefix') prefix = get_option('prefix')
@ -230,8 +254,11 @@ endif
summary( summary(
{ {
'Debug': get_option('debug'), 'Build type': build_type,
'Optimization': get_option('optimization'), 'Optimization': get_option('optimization'),
'Link time optimization': get_option('b_lto'),
'Warning level': get_option('warning_level'),
'Host system': host_sys,
}, },
section: 'General') section: 'General')
@ -244,3 +271,15 @@ summary(
'samplehive_datadir': samplehive_datadir, 'samplehive_datadir': samplehive_datadir,
}, },
section: 'Directories') section: 'Directories')
summary(
{
'Project name': project_name,
'Project license': project_license,
'Project version': project_version,
'Project author': project_author,
'Project copyright years': project_copyright_years,
'Project description': project_description,
'Project website': project_website,
},
section: 'Project')

View File

@ -20,21 +20,22 @@
#include "App.hpp" #include "App.hpp"
#include "SampleHiveConfig.hpp" #include "SampleHiveConfig.hpp"
#include "Utility/Paths.hpp"
#include "Utility/Log.hpp" #include "Utility/Log.hpp"
#include <wx/bitmap.h> #include <wx/bitmap.h>
#include <wx/defs.h> #include <wx/defs.h>
#include <wx/filefn.h>
#include <wx/fswatcher.h> #include <wx/fswatcher.h>
#include <wx/gdicmn.h> #include <wx/gdicmn.h>
#include <wx/splash.h> #include <wx/splash.h>
#define SPLASH_LOGO SAMPLEHIVE_DATADIR "/logo/logo-samplehive_768x432.png"
wxIMPLEMENT_APP(App); wxIMPLEMENT_APP(App);
App::App() App::App()
{ {
// Initialize the logger
SampleHive::Log::InitLogger("SampleHive");
} }
App::~App() App::~App()
@ -74,6 +75,7 @@ void App::OnInitCmdLine(wxCmdLineParser& parser)
wxApp::OnInitCmdLine(parser); wxApp::OnInitCmdLine(parser);
parser.AddSwitch("v", "version", "Shows the application version", 0); parser.AddSwitch("v", "version", "Shows the application version", 0);
parser.AddSwitch("r", "reset", "Reset app data", 0);
parser.Parse(true); parser.Parse(true);
} }
@ -84,9 +86,59 @@ bool App::OnCmdLineParsed(wxCmdLineParser& parser)
if (parser.Found("version")) if (parser.Found("version"))
{ {
std::cout << NAME << ' ' << VERSION << std::endl; std::cout << PROJECT_NAME << ' ' << PROJECT_VERSION << std::endl;
return false; return false;
} }
else if (parser.Found("reset"))
{
char ans;
std::cout << "Are you sure you want reset app data? [y/N] ";
std::cin >> ans;
if (ans == 'y' || ans == 'Y')
{
if (!wxFileExists(CONFIG_FILEPATH))
{
SH_LOG_ERROR("Error! File {} doesn't exist.", CONFIG_FILEPATH);
return false;
}
bool config_is_deleted = wxRemoveFile(CONFIG_FILEPATH);
if (config_is_deleted)
SH_LOG_INFO("Deleted {}", CONFIG_FILEPATH);
else
SH_LOG_ERROR("Could not delete {}", CONFIG_FILEPATH);
if (!wxFileExists(DATABASE_FILEPATH))
{
SH_LOG_ERROR("Error! File {} doesn't exist.", DATABASE_FILEPATH);
return false;
}
bool db_is_deleted = wxRemoveFile(DATABASE_FILEPATH);
if (db_is_deleted)
SH_LOG_INFO("Deleted {}", DATABASE_FILEPATH);
else
SH_LOG_ERROR("Could not delete {}", DATABASE_FILEPATH);
if (config_is_deleted && db_is_deleted)
SH_LOG_INFO("Successfully cleared app data");
else
SH_LOG_ERROR("Error! Could not clear app data");
return false;
}
else if (ans == 'n' || ans == 'N')
return false;
else
{
SH_LOG_ERROR("Unknown option '{}' please select a correct option", ans);
return false;
}
}
return true; return true;
} }

View File

@ -22,21 +22,16 @@
#include "Utility/ControlID_Enums.hpp" #include "Utility/ControlID_Enums.hpp"
#include "Utility/Serialize.hpp" #include "Utility/Serialize.hpp"
#include "Utility/Log.hpp" #include "Utility/Log.hpp"
#include "Utility/Paths.hpp"
#include <wx/defs.h> #include <wx/defs.h>
#include <wx/gdicmn.h> #include <wx/gdicmn.h>
#include <wx/stringimpl.h> #include <wx/stringimpl.h>
Settings::Settings(const std::string& configFilepath, const std::string& databaseFilepath) Settings::Settings(wxWindow *window)
: m_ConfigFilepath(configFilepath), m_DatabaseFilepath(databaseFilepath)
{
}
Settings::Settings(wxWindow* window, const std::string& configFilepath, const std::string& databaseFilepath)
: wxDialog(window, wxID_ANY, "Settings", wxDefaultPosition, : wxDialog(window, wxID_ANY, "Settings", wxDefaultPosition,
wxSize(720, 270), wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP), wxSize(720, 270), wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP),
m_Window(window), m_ConfigFilepath(configFilepath), m_DatabaseFilepath(databaseFilepath) m_Window(window)
{ {
m_Panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize); m_Panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
@ -52,7 +47,7 @@ Settings::Settings(wxWindow* window, const std::string& configFilepath, const st
m_DisplayFontSizer = new wxBoxSizer(wxHORIZONTAL); m_DisplayFontSizer = new wxBoxSizer(wxHORIZONTAL);
m_WaveformColourSizer = new wxBoxSizer(wxHORIZONTAL); m_WaveformColourSizer = new wxBoxSizer(wxHORIZONTAL);
Serializer serializer(m_ConfigFilepath); Serializer serializer;
wxString fontChoices[] = { "System default" }; wxString fontChoices[] = { "System default" };
@ -106,13 +101,13 @@ Settings::Settings(wxWindow* window, const std::string& configFilepath, const st
m_ConfigLabel = new wxStaticText(m_ConfigurationSettingPanel, wxID_ANY, m_ConfigLabel = new wxStaticText(m_ConfigurationSettingPanel, wxID_ANY,
"Default configuration file location", wxDefaultPosition, wxDefaultSize); "Default configuration file location", wxDefaultPosition, wxDefaultSize);
m_ConfigText = new wxTextCtrl(m_ConfigurationSettingPanel, wxID_ANY, configFilepath, m_ConfigText = new wxTextCtrl(m_ConfigurationSettingPanel, wxID_ANY, CONFIG_FILEPATH,
wxDefaultPosition, wxDefaultSize); wxDefaultPosition, wxDefaultSize);
m_ConfigBrowse = new wxButton(m_ConfigurationSettingPanel, SD_BrowseConfigDir, "Browse", m_ConfigBrowse = new wxButton(m_ConfigurationSettingPanel, SD_BrowseConfigDir, "Browse",
wxDefaultPosition, wxDefaultSize, 0); wxDefaultPosition, wxDefaultSize, 0);
m_DatabaseLabel = new wxStaticText(m_ConfigurationSettingPanel, wxID_ANY, "Default database location", m_DatabaseLabel = new wxStaticText(m_ConfigurationSettingPanel, wxID_ANY, "Default database location",
wxDefaultPosition, wxDefaultSize); wxDefaultPosition, wxDefaultSize);
m_DatabaseText = new wxTextCtrl(m_ConfigurationSettingPanel, wxID_ANY, databaseFilepath, m_DatabaseText = new wxTextCtrl(m_ConfigurationSettingPanel, wxID_ANY, DATABASE_FILEPATH,
wxDefaultPosition, wxDefaultSize); wxDefaultPosition, wxDefaultSize);
m_DatabaseBrowse = new wxButton(m_ConfigurationSettingPanel, SD_BrowseDatabaseDir, "Browse", m_DatabaseBrowse = new wxButton(m_ConfigurationSettingPanel, SD_BrowseDatabaseDir, "Browse",
wxDefaultPosition, wxDefaultSize, 0); wxDefaultPosition, wxDefaultSize, 0);
@ -247,7 +242,7 @@ void Settings::OnClickDatabaseBrowse(wxCommandEvent& event)
void Settings::OnCheckAutoImport(wxCommandEvent& event) void Settings::OnCheckAutoImport(wxCommandEvent& event)
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
if (!m_AutoImportCheck->GetValue()) if (!m_AutoImportCheck->GetValue())
{ {
@ -271,21 +266,21 @@ void Settings::OnCheckAutoImport(wxCommandEvent& event)
void Settings::OnCheckFollowSymLinks(wxCommandEvent& event) void Settings::OnCheckFollowSymLinks(wxCommandEvent& event)
{ {
Serializer serialize(m_ConfigFilepath); Serializer serializer;
serialize.SerializeFollowSymLink(m_FollowSymLinksCheck->GetValue()); serializer.SerializeFollowSymLink(m_FollowSymLinksCheck->GetValue());
} }
void Settings::OnCheckShowFileExtension(wxCommandEvent& event) void Settings::OnCheckShowFileExtension(wxCommandEvent& event)
{ {
Serializer serialize(m_ConfigFilepath); Serializer serializer;
serialize.SerializeShowFileExtensionSetting(m_ShowFileExtensionCheck->GetValue()); serializer.SerializeShowFileExtensionSetting(m_ShowFileExtensionCheck->GetValue());
} }
void Settings::OnClickBrowseAutoImportDir(wxCommandEvent& event) void Settings::OnClickBrowseAutoImportDir(wxCommandEvent& event)
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
wxString initial_dir = wxGetHomeDir(); wxString initial_dir = wxGetHomeDir();
@ -344,7 +339,7 @@ void Settings::OnSelectFont(wxCommandEvent& event)
void Settings::OnChangeFontSize(wxSpinEvent& event) void Settings::OnChangeFontSize(wxSpinEvent& event)
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
int font_size = m_FontSize->GetValue(); int font_size = m_FontSize->GetValue();
@ -364,7 +359,7 @@ void Settings::OnChangeFontSize(wxSpinEvent& event)
void Settings::LoadDefaultConfig() void Settings::LoadDefaultConfig()
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
wxFont sys_font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT); wxFont sys_font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT);
wxString system_font = sys_font.GetFaceName(); wxString system_font = sys_font.GetFaceName();
@ -414,7 +409,7 @@ void Settings::LoadDefaultConfig()
void Settings::SetShowExtension(bool value) void Settings::SetShowExtension(bool value)
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
m_ShowFileExtensionCheck->SetValue(value); m_ShowFileExtensionCheck->SetValue(value);
serializer.SerializeShowFileExtensionSetting(value); serializer.SerializeShowFileExtensionSetting(value);
@ -431,7 +426,7 @@ void Settings::PrintFont()
void Settings::SetCustomFont() void Settings::SetCustomFont()
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
wxFont sys_font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT); wxFont sys_font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT);
std::string system_font = sys_font.GetFaceName().ToStdString(); std::string system_font = sys_font.GetFaceName().ToStdString();
@ -468,7 +463,7 @@ wxString Settings::GetImportDirPath()
void Settings::OnChangeWaveformColour(wxColourPickerEvent& event) void Settings::OnChangeWaveformColour(wxColourPickerEvent& event)
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
wxColour colour = m_WaveformColourPickerCtrl->GetColour(); wxColour colour = m_WaveformColourPickerCtrl->GetColour();
wxColour wave_colour = serializer.DeserializeWaveformColour(); wxColour wave_colour = serializer.DeserializeWaveformColour();

View File

@ -43,17 +43,13 @@
class Settings : public wxDialog class Settings : public wxDialog
{ {
public: public:
Settings(const std::string& configFilepath, const std::string& databaseFilepath); Settings(wxWindow* window);
Settings(wxWindow* window, const std::string& configFilepath, const std::string& databaseFilepath);
~Settings(); ~Settings();
private: private:
// ------------------------------------------------------------------- // -------------------------------------------------------------------
wxWindow* m_Window; wxWindow* m_Window;
const std::string& m_ConfigFilepath;
const std::string& m_DatabaseFilepath;
private: private:
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Top panel for wxDialog // Top panel for wxDialog

View File

@ -19,7 +19,9 @@
*/ */
#include "Utility/ControlID_Enums.hpp" #include "Utility/ControlID_Enums.hpp"
#include "Utility/SH_Event.hpp"
#include "Utility/Log.hpp" #include "Utility/Log.hpp"
#include "Utility/Paths.hpp"
#include "Database/Database.hpp" #include "Database/Database.hpp"
#include "GUI/Dialogs/TagEditor.hpp" #include "GUI/Dialogs/TagEditor.hpp"
@ -29,10 +31,10 @@
#include <wx/stringimpl.h> #include <wx/stringimpl.h>
#include <wx/textdlg.h> #include <wx/textdlg.h>
TagEditor::TagEditor(wxWindow* window, const std::string& dbPath, const std::string& filename, wxInfoBar& info_bar) TagEditor::TagEditor(wxWindow* window, const std::string& filename)
: wxDialog(window, wxID_ANY, "Edit tags", wxDefaultPosition, : wxDialog(window, wxID_ANY, "Edit tags", wxDefaultPosition,
wxSize(640, 360), wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP), wxSize(640, 360), wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP),
m_Window(window), m_DatabaseFilepath(dbPath), m_Filename(filename), m_InfoBar(info_bar), tags(filename) m_Window(window), m_Filename(filename), tags(filename)
{ {
m_Panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize); m_Panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
@ -226,8 +228,7 @@ void TagEditor::OnClickCustomTagButton(wxCommandEvent& event)
void TagEditor::OnClickApply(wxCommandEvent& event) void TagEditor::OnClickApply(wxCommandEvent& event)
{ {
// Database db(m_InfoBar, m_DatabaseFilepath); Database db(static_cast<std::string>(DATABASE_FILEPATH));
Database db(m_DatabaseFilepath);
wxString title = m_TitleText->GetValue(); wxString title = m_TitleText->GetValue();
wxString artist = m_ArtistText->GetValue(); wxString artist = m_ArtistText->GetValue();
@ -311,7 +312,19 @@ void TagEditor::OnClickApply(wxCommandEvent& event)
info_msg = "Error, cannot change tag!"; info_msg = "Error, cannot change tag!";
} }
m_InfoBar.ShowMessage(info_msg, wxICON_INFORMATION); SendInfoBarMessage(info_msg, wxICON_INFORMATION);
}
void TagEditor::SendInfoBarMessage(const wxString& msg, int mode)
{
SH_LOG_INFO("{} called..", __FUNCTION__);
SampleHive::SH_InfoBarMessageEvent event(SampleHive::SH_EVT_INFOBAR_MESSAGE_UPDATED, this->GetId());
event.SetEventObject(this);
event.SetInfoBarMessage({ msg, mode });
GetParent()->GetEventHandler()->ProcessEvent(event);
} }
TagEditor::~TagEditor() TagEditor::~TagEditor()

View File

@ -39,16 +39,15 @@
class TagEditor : public wxDialog class TagEditor : public wxDialog
{ {
public: public:
TagEditor(wxWindow* window, const std::string& dbPath, const std::string& filename, wxInfoBar& info_bar); TagEditor(wxWindow* window, const std::string& filename);
~TagEditor(); ~TagEditor();
private: private:
// ------------------------------------------------------------------- // -------------------------------------------------------------------
wxWindow* m_Window; wxWindow* m_Window;
const std::string m_DatabaseFilepath;
const std::string m_Filename;
wxInfoBar& m_InfoBar; // -------------------------------------------------------------------
const std::string m_Filename;
private: private:
// ------------------------------------------------------------------- // -------------------------------------------------------------------
@ -105,4 +104,7 @@ class TagEditor : public wxDialog
// ------------------------------------------------------------------- // -------------------------------------------------------------------
void OnClickApply(wxCommandEvent& event); void OnClickApply(wxCommandEvent& event);
// -------------------------------------------------------------------
void SendInfoBarMessage(const wxString& msg, int mode);
}; };

View File

@ -23,6 +23,7 @@
#include "GUI/Dialogs/TagEditor.hpp" #include "GUI/Dialogs/TagEditor.hpp"
#include "Database/Database.hpp" #include "Database/Database.hpp"
#include "Utility/ControlID_Enums.hpp" #include "Utility/ControlID_Enums.hpp"
#include "Utility/Paths.hpp"
#include "Utility/Tags.hpp" #include "Utility/Tags.hpp"
#include "Utility/Sample.hpp" #include "Utility/Sample.hpp"
#include "Utility/Log.hpp" #include "Utility/Log.hpp"
@ -68,34 +69,8 @@
#include <wx/vector.h> #include <wx/vector.h>
#include <wx/utils.h> #include <wx/utils.h>
// 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 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"
MainFrame::MainFrame() MainFrame::MainFrame()
: wxFrame(NULL, wxID_ANY, "SampleHive", wxDefaultPosition), : wxFrame(NULL, wxID_ANY, "SampleHive", wxDefaultPosition)
m_ConfigFilepath(CONFIG_FILEPATH), m_DatabaseFilepath(DATABASE_FILEPATH)
{ {
// Initialize statusbar with 4 sections // Initialize statusbar with 4 sections
m_StatusBar = CreateStatusBar(4); m_StatusBar = CreateStatusBar(4);
@ -156,9 +131,6 @@ MainFrame::MainFrame()
// Set the menu bar to use // Set the menu bar to use
SetMenuBar(m_MenuBar); SetMenuBar(m_MenuBar);
// Initialize the logger
SampleHive::Log::InitLogger("SampleHive");
// Load default yaml config file. // Load default yaml config file.
LoadConfigFile(); LoadConfigFile();
@ -430,13 +402,11 @@ MainFrame::MainFrame()
m_Timer = new wxTimer(this); m_Timer = new wxTimer(this);
// Initialize the database // Initialize the database
// m_Database = std::make_unique<Database>(*m_InfoBar, m_DatabaseFilepath); m_Database = std::make_unique<Database>(static_cast<std::string>(DATABASE_FILEPATH));
m_Database = std::make_unique<Database>(m_DatabaseFilepath);
m_Database->CreateTableSamples(); m_Database->CreateTableSamples();
m_Database->CreateTableHives(); m_Database->CreateTableHives();
m_TopWaveformPanel = new WaveformViewer(m_TopPanel, *m_Library, *m_MediaCtrl, *m_Database, m_TopWaveformPanel = new WaveformViewer(m_TopPanel, *m_Library, *m_MediaCtrl, *m_Database);
m_ConfigFilepath, m_DatabaseFilepath);
// Binding events. // Binding events.
Bind(wxEVT_MENU, &MainFrame::OnSelectAddFile, this, MN_AddFile); Bind(wxEVT_MENU, &MainFrame::OnSelectAddFile, this, MN_AddFile);
@ -490,6 +460,7 @@ MainFrame::MainFrame()
Bind(SampleHive::SH_EVT_LOOP_POINTS_UPDATED, &MainFrame::OnRecieveLoopPoints, this); Bind(SampleHive::SH_EVT_LOOP_POINTS_UPDATED, &MainFrame::OnRecieveLoopPoints, this);
Bind(SampleHive::SH_EVT_STATUSBAR_MESSAGE_UPDATED, &MainFrame::OnRecieveStatusBarStatus, this); Bind(SampleHive::SH_EVT_STATUSBAR_MESSAGE_UPDATED, &MainFrame::OnRecieveStatusBarStatus, this);
Bind(SampleHive::SH_EVT_INFOBAR_MESSAGE_UPDATED, &MainFrame::OnRecieveInfoBarStatus, this);
// Adding widgets to their sizers // Adding widgets to their sizers
m_MainSizer->Add(m_MainPanel, 1, wxALL | wxEXPAND, 0); m_MainSizer->Add(m_MainPanel, 1, wxALL | wxEXPAND, 0);
@ -591,7 +562,7 @@ MainFrame::MainFrame()
void MainFrame::OnClickSettings(wxCommandEvent& event) void MainFrame::OnClickSettings(wxCommandEvent& event)
{ {
Settings* settings = new Settings(this, m_ConfigFilepath, m_DatabaseFilepath); Settings* settings = new Settings(this);
switch (settings->ShowModal()) switch (settings->ShowModal())
{ {
@ -615,7 +586,7 @@ void MainFrame::OnClickSettings(wxCommandEvent& event)
void MainFrame::AddSamples(wxArrayString& files) void MainFrame::AddSamples(wxArrayString& files)
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
wxBusyCursor busy_cursor; wxBusyCursor busy_cursor;
wxWindowDisabler window_disabler; wxWindowDisabler window_disabler;
@ -786,7 +757,7 @@ void MainFrame::OnDragAndDropToLibrary(wxDropFilesEvent& event)
void MainFrame::OnDragAndDropToHives(wxDropFilesEvent& event) void MainFrame::OnDragAndDropToHives(wxDropFilesEvent& event)
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
if (event.GetNumberOfFiles() > 0) if (event.GetNumberOfFiles() > 0)
{ {
@ -1220,7 +1191,7 @@ void MainFrame::OnClickLibrary(wxDataViewEvent& event)
void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event) void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event)
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
wxDataViewItem selected_hive = event.GetItem(); wxDataViewItem selected_hive = event.GetItem();
@ -1617,7 +1588,7 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event)
void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event) void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event)
{ {
TagEditor* tagEditor; TagEditor* tagEditor;
Serializer serializer(m_ConfigFilepath); Serializer serializer;
wxString msg; wxString msg;
@ -1953,8 +1924,7 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event)
break; break;
case MN_EditTagSample: case MN_EditTagSample:
{ {
tagEditor = new TagEditor(this, static_cast<std::string>(DATABASE_FILEPATH), tagEditor = new TagEditor(this, static_cast<std::string>(sample_path));
static_cast<std::string>(sample_path), *m_InfoBar);
switch (tagEditor->ShowModal()) switch (tagEditor->ShowModal())
{ {
@ -2056,7 +2026,7 @@ void MainFrame::OnShowLibraryColumnHeaderContextMenu(wxDataViewEvent& event)
void MainFrame::LoadDatabase() void MainFrame::LoadDatabase()
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
try try
{ {
@ -2083,7 +2053,7 @@ void MainFrame::LoadDatabase()
void MainFrame::OnShowTrashContextMenu(wxTreeEvent& event) void MainFrame::OnShowTrashContextMenu(wxTreeEvent& event)
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
wxTreeItemId selected_trashed_item = event.GetItem(); wxTreeItemId selected_trashed_item = event.GetItem();
@ -2171,7 +2141,7 @@ void MainFrame::OnShowTrashContextMenu(wxTreeEvent& event)
void MainFrame::OnDragAndDropToTrash(wxDropFilesEvent& event) void MainFrame::OnDragAndDropToTrash(wxDropFilesEvent& event)
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
if (event.GetNumberOfFiles() > 0) if (event.GetNumberOfFiles() > 0)
{ {
@ -2319,7 +2289,7 @@ void MainFrame::OnClickAddHive(wxCommandEvent& event)
void MainFrame::OnClickRemoveHive(wxCommandEvent& event) void MainFrame::OnClickRemoveHive(wxCommandEvent& event)
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
wxDataViewItem selected_item = m_Hives->GetSelection(); wxDataViewItem selected_item = m_Hives->GetSelection();
wxString hive_name = m_Hives->GetItemText(selected_item); wxString hive_name = m_Hives->GetItemText(selected_item);
@ -2442,7 +2412,7 @@ void MainFrame::OnClickRemoveHive(wxCommandEvent& event)
void MainFrame::OnClickRestoreTrashItem(wxCommandEvent& event) void MainFrame::OnClickRestoreTrashItem(wxCommandEvent& event)
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
wxArrayTreeItemIds selected_item_ids; wxArrayTreeItemIds selected_item_ids;
m_Trash->GetSelections(selected_item_ids); m_Trash->GetSelections(selected_item_ids);
@ -2507,7 +2477,7 @@ void MainFrame::OnClickRestoreTrashItem(wxCommandEvent& event)
void MainFrame::OnDoSearch(wxCommandEvent& event) void MainFrame::OnDoSearch(wxCommandEvent& event)
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
const auto search = m_SearchBox->GetValue().ToStdString(); const auto search = m_SearchBox->GetValue().ToStdString();
@ -2579,36 +2549,36 @@ void MainFrame::LoadConfigFile()
} }
} }
Serializer serialize(m_ConfigFilepath); Serializer serializer;
SH_LOG_INFO("Reading configuration file.."); SH_LOG_INFO("Reading configuration file..");
int height = 600, width = 800; int height = 600, width = 800;
bAutoplay = serialize.DeserializeBrowserControls("autoplay"); bAutoplay = serializer.DeserializeBrowserControls("autoplay");
bLoop = serialize.DeserializeBrowserControls("loop"); bLoop = serializer.DeserializeBrowserControls("loop");
bMuted = serialize.DeserializeBrowserControls("muted"); bMuted = serializer.DeserializeBrowserControls("muted");
width = serialize.DeserializeWinSize().first; width = serializer.DeserializeWinSize().first;
height = serialize.DeserializeWinSize().second; height = serializer.DeserializeWinSize().second;
bShowMenuBar = serialize.DeserializeShowMenuAndStatusBar("menubar"); bShowMenuBar = serializer.DeserializeShowMenuAndStatusBar("menubar");
bShowStatusBar = serialize.DeserializeShowMenuAndStatusBar("statusbar"); bShowStatusBar = serializer.DeserializeShowMenuAndStatusBar("statusbar");
m_ToggleMenuBar->Check(bShowMenuBar); m_ToggleMenuBar->Check(bShowMenuBar);
m_MenuBar->Show(bShowMenuBar); m_MenuBar->Show(bShowMenuBar);
m_ToggleStatusBar->Check(bShowStatusBar); m_ToggleStatusBar->Check(bShowStatusBar);
m_StatusBar->Show(bShowStatusBar); m_StatusBar->Show(bShowStatusBar);
m_ToggleExtension->Check(serialize.DeserializeShowFileExtensionSetting()); m_ToggleExtension->Check(serializer.DeserializeShowFileExtensionSetting());
this->SetFont(serialize.DeserializeDisplaySettings()); this->SetFont(serializer.DeserializeDisplaySettings());
this->SetSize(width, height); this->SetSize(width, height);
this->SetMinSize(wxSize(width, height)); this->SetMinSize(wxSize(width, height));
this->CenterOnScreen(wxBOTH); this->CenterOnScreen(wxBOTH);
this->SetIcon(wxIcon(ICON_HIVE_256px, wxICON_DEFAULT_TYPE, -1, -1)); this->SetIcon(wxIcon(ICON_HIVE_256px, wxICON_DEFAULT_TYPE, -1, -1));
this->SetTitle(NAME); this->SetTitle(PROJECT_NAME);
this->SetStatusText(wxString::Format("%s %s", NAME, VERSION), 3); this->SetStatusText(wxString::Format("%s %s", PROJECT_NAME, PROJECT_VERSION), 3);
this->SetStatusText(_("Stopped"), 1); this->SetStatusText(_("Stopped"), 1);
} }
@ -2640,7 +2610,7 @@ bool MainFrame::CreateWatcherIfNecessary()
void MainFrame::CreateWatcher() void MainFrame::CreateWatcher()
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
wxCHECK_RET(!m_FsWatcher, _("Watcher already initialized")); wxCHECK_RET(!m_FsWatcher, _("Watcher already initialized"));
@ -2658,7 +2628,7 @@ void MainFrame::CreateWatcher()
void MainFrame::AddWatchEntry(wxFSWPathType type, std::string path) void MainFrame::AddWatchEntry(wxFSWPathType type, std::string path)
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
if (path.empty()) if (path.empty())
{ {
@ -2674,6 +2644,12 @@ void MainFrame::AddWatchEntry(wxFSWPathType type, std::string path)
wxFileName filename = wxFileName::DirName(path); wxFileName filename = wxFileName::DirName(path);
if (!filename.IsOk() || !filename.IsDir() || !filename.IsDirReadable())
{
SH_LOG_ERROR("Error! Something wrong with {} path", filename.GetFullPath());
return;
}
if (!serializer.DeserializeFollowSymLink()) if (!serializer.DeserializeFollowSymLink())
{ {
filename.DontFollowLink(); filename.DontFollowLink();
@ -2746,7 +2722,7 @@ void MainFrame::OnFileSystemEvent(wxFileSystemWatcherEvent& event)
FileInfo MainFrame::GetFilenamePathAndExtension(const wxString& selected, FileInfo MainFrame::GetFilenamePathAndExtension(const wxString& selected,
bool checkExtension, bool doGetFilename) const bool checkExtension, bool doGetFilename) const
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
wxString path; wxString path;
std::string extension, filename; std::string extension, filename;
@ -2820,7 +2796,7 @@ void MainFrame::OnSelectAddDirectory(wxCommandEvent& event)
void MainFrame::OnSelectToggleExtension(wxCommandEvent& event) void MainFrame::OnSelectToggleExtension(wxCommandEvent& event)
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
if (m_ToggleExtension->IsChecked()) if (m_ToggleExtension->IsChecked())
{ {
@ -2838,7 +2814,7 @@ void MainFrame::OnSelectToggleExtension(wxCommandEvent& event)
void MainFrame::OnSelectToggleMenuBar(wxCommandEvent& event) void MainFrame::OnSelectToggleMenuBar(wxCommandEvent& event)
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
if (m_ToggleMenuBar->IsChecked()) if (m_ToggleMenuBar->IsChecked())
{ {
@ -2862,7 +2838,7 @@ void MainFrame::OnSelectToggleMenuBar(wxCommandEvent& event)
void MainFrame::OnSelectToggleStatusBar(wxCommandEvent& event) void MainFrame::OnSelectToggleStatusBar(wxCommandEvent& event)
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
if (m_ToggleStatusBar->IsChecked()) if (m_ToggleStatusBar->IsChecked())
{ {
@ -2891,7 +2867,7 @@ void MainFrame::OnSelectExit(wxCommandEvent& event)
void MainFrame::OnSelectPreferences(wxCommandEvent& event) void MainFrame::OnSelectPreferences(wxCommandEvent& event)
{ {
Settings* settings = new Settings(this, m_ConfigFilepath, m_DatabaseFilepath); Settings* settings = new Settings(this);
switch (settings->ShowModal()) switch (settings->ShowModal())
{ {
@ -2918,7 +2894,7 @@ void MainFrame::OnSelectResetAppData(wxCommandEvent& event)
wxMessageDialog clearDataDialog(this, wxString::Format(_("Warning! This will delete configuration file " wxMessageDialog clearDataDialog(this, wxString::Format(_("Warning! This will delete configuration file "
"\"%s\" and database file \"%s\" permanently, " "\"%s\" and database file \"%s\" permanently, "
"are you sure you want to delete these files?"), "are you sure you want to delete these files?"),
m_ConfigFilepath, m_DatabaseFilepath), CONFIG_FILEPATH, DATABASE_FILEPATH),
_("Clear app data?"), _("Clear app data?"),
wxYES_NO | wxNO_DEFAULT | wxCENTRE, wxDefaultPosition); wxYES_NO | wxNO_DEFAULT | wxCENTRE, wxDefaultPosition);
@ -2931,19 +2907,31 @@ void MainFrame::OnSelectResetAppData(wxCommandEvent& event)
if (remove) if (remove)
{ {
bool config_is_deleted = wxRemoveFile(m_ConfigFilepath); if (!wxFileExists(CONFIG_FILEPATH))
{
SH_LOG_ERROR("Error! File {} doesn't exist.", CONFIG_FILEPATH);
return;
}
bool config_is_deleted = wxRemoveFile(CONFIG_FILEPATH);
if (config_is_deleted) if (config_is_deleted)
SH_LOG_INFO("Deleted {}", m_ConfigFilepath); SH_LOG_INFO("Deleted {}", CONFIG_FILEPATH);
else else
SH_LOG_ERROR("Could not delete {}", m_ConfigFilepath); SH_LOG_ERROR("Could not delete {}", CONFIG_FILEPATH);
bool db_is_deleted = wxRemoveFile(m_DatabaseFilepath); if (!wxFileExists(DATABASE_FILEPATH))
{
SH_LOG_ERROR("Error! File {} doesn't exist.", DATABASE_FILEPATH);
return;
}
bool db_is_deleted = wxRemoveFile(DATABASE_FILEPATH);
if (db_is_deleted) if (db_is_deleted)
SH_LOG_INFO("Deleted {}", m_DatabaseFilepath); SH_LOG_INFO("Deleted {}", DATABASE_FILEPATH);
else else
SH_LOG_ERROR("Could not delete {}", m_DatabaseFilepath); SH_LOG_ERROR("Could not delete {}", DATABASE_FILEPATH);
if (config_is_deleted && db_is_deleted) if (config_is_deleted && db_is_deleted)
m_InfoBar->ShowMessage(_("Successfully cleared app data"), wxICON_INFORMATION); m_InfoBar->ShowMessage(_("Successfully cleared app data"), wxICON_INFORMATION);
@ -2963,17 +2951,17 @@ void MainFrame::OnSelectAbout(wxCommandEvent& event)
{ {
wxAboutDialogInfo aboutInfo; wxAboutDialogInfo aboutInfo;
aboutInfo.SetName(NAME); aboutInfo.SetName(PROJECT_NAME);
aboutInfo.SetIcon(wxIcon(ICON_HIVE_64px)); aboutInfo.SetIcon(wxIcon(ICON_HIVE_64px));
aboutInfo.AddArtist("Apoorv"); aboutInfo.AddArtist(PROJECT_AUTHOR);
aboutInfo.SetVersion(VERSION, _("Version 0.9.0_alpha.1")); aboutInfo.SetVersion(PROJECT_VERSION, _("Version 0.9.0_alpha.1"));
aboutInfo.SetDescription(_("A simple, modern audio sample browser/manager for GNU/Linux.")); aboutInfo.SetDescription(_(PROJECT_DESCRIPTION));
aboutInfo.SetCopyright("(C) 2020-2021"); aboutInfo.SetCopyright("(C)" PROJECT_COPYRIGHT_YEARS);
aboutInfo.SetWebSite("http://samplehive.gitlab.io"); aboutInfo.SetWebSite(PROJECT_WEBSITE);
aboutInfo.AddDeveloper("Apoorv"); aboutInfo.AddDeveloper(PROJECT_AUTHOR);
aboutInfo.SetLicence(wxString::Format(wxString::FromAscii( aboutInfo.SetLicence(wxString::Format(wxString::FromAscii(
"%s %s\n" "%s %s\n"
"Copyright (C) 2021 Apoorv Singh\n" "Copyright (C) %s Apoorv Singh\n"
"\n" "\n"
"%s is free software: you can redistribute it and/or modify\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" "it under the terms of the GNU General Public License as published by\n"
@ -2987,7 +2975,8 @@ void MainFrame::OnSelectAbout(wxCommandEvent& event)
"\n" "\n"
"You should have received a copy of the GNU General Public License\n" "You should have received a copy of the GNU General Public License\n"
"along with this program. If not, see <https://www.gnu.org/licenses/>.\n" "along with this program. If not, see <https://www.gnu.org/licenses/>.\n"
), NAME, VERSION, NAME, NAME)); ), PROJECT_NAME, PROJECT_VERSION, PROJECT_COPYRIGHT_YEARS,
PROJECT_NAME, PROJECT_NAME));
wxAboutBox(aboutInfo); wxAboutBox(aboutInfo);
} }
@ -3038,6 +3027,17 @@ void MainFrame::OnRecieveStatusBarStatus(SampleHive::SH_StatusBarMessageEvent& e
m_StatusBar->PushStatusText(status.first, status.second); m_StatusBar->PushStatusText(status.first, status.second);
} }
void MainFrame::OnRecieveInfoBarStatus(SampleHive::SH_InfoBarMessageEvent& event)
{
SH_LOG_INFO("{} called..", __FUNCTION__);
std::pair<wxString, int> info = event.GetInfoBarMessage();
m_InfoBar->ShowMessage(info.first, info.second);
SH_LOG_INFO("{} event processed", __FUNCTION__);
}
void MainFrame::ClearLoopPoints() void MainFrame::ClearLoopPoints()
{ {
m_LoopA = 0; m_LoopA = 0;

View File

@ -197,10 +197,6 @@ class MainFrame : public wxFrame
bool bShowStatusBar = false; bool bShowStatusBar = false;
bool bLoopPointsSet = false; bool bLoopPointsSet = false;
// -------------------------------------------------------------------
const std::string m_ConfigFilepath;
const std::string m_DatabaseFilepath;
private: private:
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Top panel control handlers // Top panel control handlers
@ -278,6 +274,7 @@ class MainFrame : public wxFrame
// ------------------------------------------------------------------- // -------------------------------------------------------------------
void OnRecieveLoopPoints(SampleHive::SH_LoopPointsEvent& event); void OnRecieveLoopPoints(SampleHive::SH_LoopPointsEvent& event);
void OnRecieveStatusBarStatus(SampleHive::SH_StatusBarMessageEvent& event); void OnRecieveStatusBarStatus(SampleHive::SH_StatusBarMessageEvent& event);
void OnRecieveInfoBarStatus(SampleHive::SH_InfoBarMessageEvent& event);
// ------------------------------------------------------------------- // -------------------------------------------------------------------
void LoadDatabase(); void LoadDatabase();

View File

@ -23,6 +23,7 @@
#include "Utility/Tags.hpp" #include "Utility/Tags.hpp"
#include "Utility/SH_Event.hpp" #include "Utility/SH_Event.hpp"
#include "Utility/Log.hpp" #include "Utility/Log.hpp"
#include "Utility/Paths.hpp"
#include <vector> #include <vector>
@ -37,12 +38,10 @@
#include <sndfile.hh> #include <sndfile.hh>
WaveformViewer::WaveformViewer(wxWindow* window, wxDataViewListCtrl& library, WaveformViewer::WaveformViewer(wxWindow* window, wxDataViewListCtrl& library,
wxMediaCtrl& mediaCtrl, Database& database, wxMediaCtrl& mediaCtrl, Database& database)
const std::string& configFilepath, const std::string& databaseFilepath)
: wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, : wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize,
wxTAB_TRAVERSAL | wxNO_BORDER | wxFULL_REPAINT_ON_RESIZE), wxTAB_TRAVERSAL | wxNO_BORDER | wxFULL_REPAINT_ON_RESIZE),
m_Window(window), m_Database(database), m_Library(library), m_MediaCtrl(mediaCtrl), m_Window(window), m_Database(database), m_Library(library), m_MediaCtrl(mediaCtrl)
m_ConfigFilepath(configFilepath), m_DatabaseFilepath(databaseFilepath)
{ {
this->SetDoubleBuffered(true); this->SetDoubleBuffered(true);
@ -148,7 +147,7 @@ void WaveformViewer::RenderPlayhead(wxDC& dc)
void WaveformViewer::UpdateWaveformBitmap() void WaveformViewer::UpdateWaveformBitmap()
{ {
Serializer serializer(m_ConfigFilepath); Serializer serializer;
int selected_row = m_Library.GetSelectedRow(); int selected_row = m_Library.GetSelectedRow();

View File

@ -39,21 +39,18 @@ class WaveformViewer : public wxPanel
{ {
public: public:
WaveformViewer(wxWindow* window, wxDataViewListCtrl& library, WaveformViewer(wxWindow* window, wxDataViewListCtrl& library,
wxMediaCtrl& mediaCtrl, Database& database, wxMediaCtrl& mediaCtrl, Database& database);
const std::string& configFilepath, const std::string& databaseFilepath);
~WaveformViewer(); ~WaveformViewer();
private: private:
// ------------------------------------------------------------------- // -------------------------------------------------------------------
wxWindow* m_Window; wxWindow* m_Window;
// -------------------------------------------------------------------
Database& m_Database; Database& m_Database;
wxDataViewListCtrl& m_Library; wxDataViewListCtrl& m_Library;
wxMediaCtrl& m_MediaCtrl; wxMediaCtrl& m_MediaCtrl;
const std::string& m_ConfigFilepath;
const std::string& m_DatabaseFilepath;
private: private:
// ------------------------------------------------------------------- // -------------------------------------------------------------------
wxBitmap m_WaveformBitmap; wxBitmap m_WaveformBitmap;

29
src/Utility/Paths.hpp Normal file
View File

@ -0,0 +1,29 @@
#pragma once
// 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"

View File

@ -74,18 +74,18 @@ namespace SampleHive
wxDEFINE_EVENT(SH_EVT_STATUSBAR_MESSAGE_UPDATED, SH_StatusBarMessageEvent); wxDEFINE_EVENT(SH_EVT_STATUSBAR_MESSAGE_UPDATED, SH_StatusBarMessageEvent);
// SH_InfoBarMessageEvent::SH_InfoBarMessageEvent(wxEventType eventType, int winId) SH_InfoBarMessageEvent::SH_InfoBarMessageEvent(wxEventType eventType, int winId)
// : wxCommandEvent(eventType, winId) : wxCommandEvent(eventType, winId)
// { {
// } }
// SH_InfoBarMessageEvent::~SH_InfoBarMessageEvent() SH_InfoBarMessageEvent::~SH_InfoBarMessageEvent()
// { {
// } }
// wxDEFINE_EVENT(SH_EVT_INFOBAR_MESSAGE_UPDATED, SH_InfoBarMessageEvent); wxDEFINE_EVENT(SH_EVT_INFOBAR_MESSAGE_UPDATED, SH_InfoBarMessageEvent);
// SH_TimerEvent::SH_TimerEvent(wxEventType eventType, int winId) // SH_TimerEvent::SH_TimerEvent(wxEventType eventType, int winId)
// : wxCommandEvent(eventType, winId) // : wxCommandEvent(eventType, winId)

View File

@ -95,7 +95,8 @@ namespace SampleHive
public: public:
std::pair<wxString, int> GetMessageAndSection() const { return { m_Msg, m_Section }; } std::pair<wxString, int> GetMessageAndSection() const { return { m_Msg, m_Section }; }
void SetMessageAndSection(std::pair<const wxString&, int> status) { m_Msg = status.first; m_Section = status.second; } void SetMessageAndSection(std::pair<const wxString&, int> status)
{ m_Msg = status.first; m_Section = status.second; }
private: private:
wxString m_Msg; wxString m_Msg;
@ -104,25 +105,26 @@ namespace SampleHive
wxDECLARE_EVENT(SH_EVT_STATUSBAR_MESSAGE_UPDATED, SH_StatusBarMessageEvent); wxDECLARE_EVENT(SH_EVT_STATUSBAR_MESSAGE_UPDATED, SH_StatusBarMessageEvent);
// class SH_InfoBarMessageEvent : public wxCommandEvent class SH_InfoBarMessageEvent : public wxCommandEvent
// { {
// public: public:
// SH_InfoBarMessageEvent(wxEventType eventType, int winId); SH_InfoBarMessageEvent(wxEventType eventType, int winId);
// ~SH_InfoBarMessageEvent(); ~SH_InfoBarMessageEvent();
// public: public:
// virtual wxEvent* Clone() const { return new SH_InfoBarMessageEvent(*this); } virtual wxEvent* Clone() const { return new SH_InfoBarMessageEvent(*this); }
// public: public:
// std::pair<wxString, int> GetInfoBarMessage() const { return { m_Msg, m_Mode }; } std::pair<wxString, int> GetInfoBarMessage() const { return { m_Msg, m_Mode }; }
// void SetInfoBarMessage(std::pair<wxString, int> infoBarMessageEvent) { m_Msg = infoBarMessageEvent.first; m_Mode = infoBarMessageEvent.second; } void SetInfoBarMessage(std::pair<const wxString&, int> info)
{ m_Msg = info.first; m_Mode = info.second; }
// private: private:
// wxString m_Msg; wxString m_Msg;
// int m_Mode; int m_Mode;
// }; };
// wxDECLARE_EVENT(SH_EVT_INFOBAR_MESSAGE_UPDATED, SH_InfoBarMessageEvent); wxDECLARE_EVENT(SH_EVT_INFOBAR_MESSAGE_UPDATED, SH_InfoBarMessageEvent);
// class SH_TimerEvent : public wxCommandEvent // class SH_TimerEvent : public wxCommandEvent
// { // {

View File

@ -20,6 +20,7 @@
#include "Utility/Serialize.hpp" #include "Utility/Serialize.hpp"
#include "Utility/Log.hpp" #include "Utility/Log.hpp"
#include "Utility/Paths.hpp"
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
@ -30,10 +31,9 @@
#include <yaml-cpp/emittermanip.h> #include <yaml-cpp/emittermanip.h>
#include <yaml-cpp/node/parse.h> #include <yaml-cpp/node/parse.h>
Serializer::Serializer(const std::string& filepath) Serializer::Serializer()
: m_Filepath(filepath)
{ {
std::ifstream ifstrm(m_Filepath); std::ifstream ifstrm(static_cast<std::string>(CONFIG_FILEPATH));
wxFont font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT); wxFont font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT);
std::string system_font_face = font.GetFaceName().ToStdString(); std::string system_font_face = font.GetFaceName().ToStdString();
@ -94,10 +94,10 @@ Serializer::Serializer(const std::string& filepath)
m_Emitter << YAML::EndMap; m_Emitter << YAML::EndMap;
std::ofstream ofstrm(m_Filepath); std::ofstream ofstrm(CONFIG_FILEPATH);
ofstrm << m_Emitter.c_str(); ofstrm << m_Emitter.c_str();
SH_LOG_INFO("Generated {} successfully!", m_Filepath); SH_LOG_INFO("Generated {} successfully!", CONFIG_FILEPATH);
} }
} }
@ -112,7 +112,7 @@ WindowSize Serializer::DeserializeWinSize() const
try try
{ {
YAML::Node config = YAML::LoadFile(m_Filepath); YAML::Node config = YAML::LoadFile(static_cast<std::string>(CONFIG_FILEPATH));
if (!config["Window"]) if (!config["Window"])
{ {
@ -141,7 +141,7 @@ void Serializer::SerializeShowMenuAndStatusBar(std::string key, bool value)
try try
{ {
YAML::Node config = YAML::LoadFile(m_Filepath); YAML::Node config = YAML::LoadFile(static_cast<std::string>(CONFIG_FILEPATH));
if (auto bar = config["Window"]) if (auto bar = config["Window"])
{ {
@ -153,7 +153,7 @@ void Serializer::SerializeShowMenuAndStatusBar(std::string key, bool value)
out << config; out << config;
std::ofstream ofstrm(m_Filepath); std::ofstream ofstrm(static_cast<std::string>(CONFIG_FILEPATH));
ofstrm << out.c_str(); ofstrm << out.c_str();
} }
else else
@ -171,7 +171,7 @@ bool Serializer::DeserializeShowMenuAndStatusBar(std::string key) const
try try
{ {
YAML::Node config = YAML::LoadFile(m_Filepath); YAML::Node config = YAML::LoadFile(static_cast<std::string>(CONFIG_FILEPATH));
if (auto bar = config["Window"]) if (auto bar = config["Window"])
{ {
@ -200,7 +200,7 @@ void Serializer::SerializeBrowserControls(std::string key, bool value)
try try
{ {
YAML::Node config = YAML::LoadFile(m_Filepath); YAML::Node config = YAML::LoadFile(static_cast<std::string>(CONFIG_FILEPATH));
if (auto media = config["Media"]) if (auto media = config["Media"])
{ {
@ -215,7 +215,7 @@ void Serializer::SerializeBrowserControls(std::string key, bool value)
out << config; out << config;
std::ofstream ofstrm(m_Filepath); std::ofstream ofstrm(static_cast<std::string>(CONFIG_FILEPATH));
ofstrm << out.c_str(); ofstrm << out.c_str();
} }
else else
@ -233,7 +233,7 @@ bool Serializer::DeserializeBrowserControls(std::string key) const
try try
{ {
YAML::Node config = YAML::LoadFile(m_Filepath); YAML::Node config = YAML::LoadFile(static_cast<std::string>(CONFIG_FILEPATH));
if (auto media = config["Media"]) if (auto media = config["Media"])
{ {
@ -268,7 +268,7 @@ void Serializer::SerializeDisplaySettings(wxFont& font)
try try
{ {
YAML::Node config = YAML::LoadFile(m_Filepath); YAML::Node config = YAML::LoadFile(static_cast<std::string>(CONFIG_FILEPATH));
auto display = config["Display"]; auto display = config["Display"];
@ -279,7 +279,7 @@ void Serializer::SerializeDisplaySettings(wxFont& font)
out << config; out << config;
std::ofstream ofstrm(m_Filepath); std::ofstream ofstrm(static_cast<std::string>(CONFIG_FILEPATH));
ofstrm << out.c_str(); ofstrm << out.c_str();
} }
else else
@ -302,7 +302,7 @@ wxFont Serializer::DeserializeDisplaySettings() const
try try
{ {
YAML::Node config = YAML::LoadFile(m_Filepath); YAML::Node config = YAML::LoadFile(static_cast<std::string>(CONFIG_FILEPATH));
auto display = config["Display"]; auto display = config["Display"];
@ -335,7 +335,7 @@ void Serializer::SerializeWaveformColour(wxColour& colour)
try try
{ {
YAML::Node config = YAML::LoadFile(m_Filepath); YAML::Node config = YAML::LoadFile(static_cast<std::string>(CONFIG_FILEPATH));
auto display = config["Display"]; auto display = config["Display"];
@ -345,7 +345,7 @@ void Serializer::SerializeWaveformColour(wxColour& colour)
out << config; out << config;
std::ofstream ofstrm(m_Filepath); std::ofstream ofstrm(static_cast<std::string>(CONFIG_FILEPATH));
ofstrm << out.c_str(); ofstrm << out.c_str();
} }
else else
@ -365,7 +365,7 @@ wxColour Serializer::DeserializeWaveformColour() const
try try
{ {
YAML::Node config = YAML::LoadFile(m_Filepath); YAML::Node config = YAML::LoadFile(static_cast<std::string>(CONFIG_FILEPATH));
auto display = config["Display"]; auto display = config["Display"];
@ -392,7 +392,7 @@ void Serializer::SerializeAutoImportSettings(bool autoImport, const std::string&
try try
{ {
YAML::Node config = YAML::LoadFile(m_Filepath); YAML::Node config = YAML::LoadFile(static_cast<std::string>(CONFIG_FILEPATH));
if (auto autoImportInfo = config["Collection"]) if (auto autoImportInfo = config["Collection"])
{ {
@ -401,7 +401,7 @@ void Serializer::SerializeAutoImportSettings(bool autoImport, const std::string&
out << config; out << config;
std::ofstream ofstrm(m_Filepath); std::ofstream ofstrm(static_cast<std::string>(CONFIG_FILEPATH));
ofstrm << out.c_str(); ofstrm << out.c_str();
} }
else else
@ -422,7 +422,7 @@ ImportDirInfo Serializer::DeserializeAutoImportSettings() const
try try
{ {
YAML::Node config = YAML::LoadFile(m_Filepath); YAML::Node config = YAML::LoadFile(static_cast<std::string>(CONFIG_FILEPATH));
if (auto autoImportInfo = config["Collection"]) if (auto autoImportInfo = config["Collection"])
{ {
@ -448,7 +448,7 @@ void Serializer::SerializeFollowSymLink(bool followSymLinks)
try try
{ {
YAML::Node config = YAML::LoadFile(m_Filepath); YAML::Node config = YAML::LoadFile(static_cast<std::string>(CONFIG_FILEPATH));
if (auto followSymLinks = config["Collection"]) if (auto followSymLinks = config["Collection"])
{ {
@ -456,7 +456,7 @@ void Serializer::SerializeFollowSymLink(bool followSymLinks)
out << config; out << config;
std::ofstream ofstrm(m_Filepath); std::ofstream ofstrm(static_cast<std::string>(CONFIG_FILEPATH));
ofstrm << out.c_str(); ofstrm << out.c_str();
} }
else else
@ -476,7 +476,7 @@ bool Serializer::DeserializeFollowSymLink() const
try try
{ {
YAML::Node config = YAML::LoadFile(m_Filepath); YAML::Node config = YAML::LoadFile(static_cast<std::string>(CONFIG_FILEPATH));
if (auto followSymLinks = config["Collection"]) if (auto followSymLinks = config["Collection"])
{ {
@ -501,7 +501,7 @@ void Serializer::SerializeShowFileExtensionSetting(bool showExtension)
try try
{ {
YAML::Node config = YAML::LoadFile(m_Filepath); YAML::Node config = YAML::LoadFile(static_cast<std::string>(CONFIG_FILEPATH));
if (auto fileExtensionInfo = config["Collection"]) if (auto fileExtensionInfo = config["Collection"])
{ {
@ -509,7 +509,7 @@ void Serializer::SerializeShowFileExtensionSetting(bool showExtension)
out << config; out << config;
std::ofstream ofstrm(m_Filepath); std::ofstream ofstrm(static_cast<std::string>(CONFIG_FILEPATH));
ofstrm << out.c_str(); ofstrm << out.c_str();
} }
else else
@ -529,7 +529,7 @@ bool Serializer::DeserializeShowFileExtensionSetting() const
try try
{ {
YAML::Node config = YAML::LoadFile(m_Filepath); YAML::Node config = YAML::LoadFile(static_cast<std::string>(CONFIG_FILEPATH));
if (auto fileExtensionInfo = config["Collection"]) if (auto fileExtensionInfo = config["Collection"])
{ {

View File

@ -45,13 +45,10 @@ typedef std::pair<bool, wxString> ImportDirInfo;
class Serializer class Serializer
{ {
public: public:
Serializer(const std::string& filepath); Serializer();
~Serializer(); ~Serializer();
private: private:
// -------------------------------------------------------------------
const std::string& m_Filepath;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
YAML::Emitter m_Emitter; YAML::Emitter m_Emitter;