More encapsulation, lots of reformatting and cleanup.

This commit is contained in:
apoorv569 2022-01-24 02:39:57 +05:30
parent 9e0be8f55a
commit 010a798fe5
46 changed files with 3488 additions and 5177 deletions

View File

@ -163,9 +163,10 @@ src = [
'src/Utility/Sample.cpp',
'src/Utility/Serialize.cpp',
'src/Utility/Tags.cpp',
'src/Utility/SH_Event.cpp',
'src/Utility/Event.cpp',
'src/Utility/Signal.cpp',
'src/Utility/Log.cpp',
'src/Utility/Utils.cpp',
]

View File

@ -29,20 +29,20 @@
#include <wx/gdicmn.h>
#include <wx/splash.h>
wxIMPLEMENT_APP(App);
wxIMPLEMENT_APP(cApp);
App::App()
cApp::cApp()
{
// Initialize the logger
SampleHive::Log::InitLogger("SampleHive");
SampleHive::cLog::InitLogger("SampleHive");
}
App::~App()
cApp::~cApp()
{
}
bool App::OnInit()
bool cApp::OnInit()
{
if (!wxApp::OnInit())
return false;
@ -50,7 +50,7 @@ bool App::OnInit()
wxLog::AddTraceMask("EventSource");
wxLog::AddTraceMask(wxTRACE_FSWATCHER);
m_Frame = new MainFrame();
m_Frame = new cMainFrame();
wxBitmap bitmap;
wxSplashScreen* splash;
@ -69,7 +69,7 @@ bool App::OnInit()
return true;
}
void App::OnInitCmdLine(wxCmdLineParser& parser)
void cApp::OnInitCmdLine(wxCmdLineParser& parser)
{
wxApp::OnInitCmdLine(parser);
@ -78,7 +78,7 @@ void App::OnInitCmdLine(wxCmdLineParser& parser)
parser.Parse(true);
}
bool App::OnCmdLineParsed(wxCmdLineParser& parser)
bool cApp::OnCmdLineParsed(wxCmdLineParser& parser)
{
if (!wxApp::OnCmdLineParsed(parser))
return false;
@ -142,7 +142,7 @@ bool App::OnCmdLineParsed(wxCmdLineParser& parser)
return true;
}
void App::OnEventLoopEnter(wxEventLoopBase* event)
void cApp::OnEventLoopEnter(wxEventLoopBase* event)
{
if (m_Frame->CreateWatcherIfNecessary())
SH_LOG_INFO("Filesystem watcher created sucessfully");

View File

@ -25,18 +25,18 @@
#include <wx/app.h>
#include <wx/cmdline.h>
class App : public wxApp
class cApp : public wxApp
{
public:
App();
~App();
private:
MainFrame* m_Frame = nullptr;
cApp();
~cApp();
private:
virtual bool OnInit();
virtual void OnEventLoopEnter(wxEventLoopBase* event);
virtual void OnInitCmdLine(wxCmdLineParser& parser);
virtual bool OnCmdLineParsed(wxCmdLineParser& parser);
private:
cMainFrame* m_Frame = nullptr;
};

View File

@ -26,6 +26,7 @@
#include <exception>
#include <sstream>
#include <stdexcept>
#include <wx/dataview.h>
#include <wx/dvrenderers.h>
#include <wx/msgdlg.h>
@ -49,8 +50,7 @@ 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;
@ -78,17 +78,17 @@ class Sqlite3Statement
sqlite3_stmt* stmt = nullptr;
};
Database::Database()
cDatabase::cDatabase()
{
OpenDatabase();
}
Database::~Database()
cDatabase::~cDatabase()
{
CloseDatabase();
}
void Database::CreateTableSamples()
void cDatabase::CreateTableSamples()
{
/* Create SQL statement */
const auto samples = "CREATE TABLE IF NOT EXISTS SAMPLES("
@ -107,7 +107,7 @@ void Database::CreateTableSamples()
try
{
throw_on_sqlite3_error(sqlite3_exec(m_Database, samples, NULL, 0, &m_ErrMsg));
throw_on_sqlite3_error(sqlite3_exec(m_pDatabase, samples, NULL, 0, &m_pErrMsg));
SH_LOG_INFO("SAMPLES table created successfully.");
}
catch (const std::exception &e)
@ -116,14 +116,14 @@ void Database::CreateTableSamples()
}
}
void Database::CreateTableHives()
void cDatabase::CreateTableHives()
{
/* Create SQL statement */
const auto hives = "CREATE TABLE IF NOT EXISTS HIVES(HIVE TEXT NOT NULL);";
try
{
throw_on_sqlite3_error(sqlite3_exec(m_Database, hives, NULL, 0, &m_ErrMsg));
throw_on_sqlite3_error(sqlite3_exec(m_pDatabase, hives, NULL, 0, &m_pErrMsg));
SH_LOG_INFO("HIVES table created successfully.");
}
catch (const std::exception &e)
@ -133,7 +133,7 @@ void Database::CreateTableHives()
}
//Loops through a Sample array and adds them to the database
void Database::InsertIntoSamples(const std::vector<Sample> &samples)
void cDatabase::InsertIntoSamples(const std::vector<Sample> &samples)
{
try
{
@ -142,9 +142,9 @@ void Database::InsertIntoSamples(const std::vector<Sample> &samples)
SAMPLERATE, BITRATE, PATH, TRASHED, HIVE) \
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
Sqlite3Statement statement(m_Database, sql);
Sqlite3Statement statement(m_pDatabase, sql);
throw_on_sqlite3_error(sqlite3_exec(m_Database, "BEGIN TRANSACTION", NULL, NULL, &m_ErrMsg));
throw_on_sqlite3_error(sqlite3_exec(m_pDatabase, "BEGIN TRANSACTION", NULL, NULL, &m_pErrMsg));
Sample sample;
@ -167,30 +167,25 @@ void Database::InsertIntoSamples(const std::vector<Sample> &samples)
std::string hive = "Favorites";
throw_on_sqlite3_error(sqlite3_bind_int(statement.stmt, 1, sample.GetFavorite()));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(),
filename.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 3, file_extension.c_str(),
file_extension.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 4, sample_pack.c_str(),
sample_pack.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 5, type.c_str(),
type.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), filename.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 3, file_extension.c_str(), file_extension.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 4, sample_pack.c_str(), sample_pack.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 5, type.c_str(), type.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_int(statement.stmt, 6, sample.GetChannels()));
throw_on_sqlite3_error(sqlite3_bind_int(statement.stmt, 7, sample.GetLength()));
throw_on_sqlite3_error(sqlite3_bind_int(statement.stmt, 8, sample.GetSampleRate()));
throw_on_sqlite3_error(sqlite3_bind_int(statement.stmt, 9, sample.GetBitrate()));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 10, path.c_str(),
path.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 10, path.c_str(), path.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_int(statement.stmt, 11, sample.GetTrashed()));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 12, hive.c_str(),
hive.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 12, hive.c_str(), hive.size(), SQLITE_STATIC));
sqlite3_step(statement.stmt);
throw_on_sqlite3_error(sqlite3_clear_bindings(statement.stmt));
throw_on_sqlite3_error(sqlite3_reset(statement.stmt));
}
throw_on_sqlite3_error(sqlite3_exec(m_Database, "END TRANSACTION", NULL, NULL, &m_ErrMsg));
throw_on_sqlite3_error(sqlite3_exec(m_pDatabase, "END TRANSACTION", NULL, NULL, &m_pErrMsg));
SH_LOG_INFO("Data inserted successfully into SAMPLES.");
}
@ -200,46 +195,17 @@ void Database::InsertIntoSamples(const std::vector<Sample> &samples)
}
}
void Database::InsertIntoHives(const std::string &hiveName)
void cDatabase::InsertIntoHives(const std::string &hiveName)
{
try
{
const auto sql = "INSERT INTO HIVES(HIVE) VALUES(?);";
Sqlite3Statement statement(m_Database, sql);
Sqlite3Statement statement(m_pDatabase, sql);
// rc = sqlite3_exec(m_Database, "BEGIN TRANSACTION", NULL, NULL, &m_ErrMsg);
// Sample sample;
// std::string filename;
// std::string file_extension;
// std::string sample_pack;
// std::string type;
// std::string path;
// for(unsigned int i = 0; i < samples.size(); i++)
// {
// sample = samples[i];
// filename = sample.GetFilename();
// file_extension = sample.GetFileExtension();
// sample_pack = sample.GetSamplePack();
// type = sample.GetType();
// path = sample.GetPath();
// std::string hive = "Favourites";
// rc = sqlite3_bind_int(statement.stmt, 1, sample.GetFavorite());
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveName.c_str(),
hiveName.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveName.c_str(), hiveName.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_step(statement.stmt));
// rc = sqlite3_clear_bindings(statement.stmt);
// rc = sqlite3_reset(statement.stmt);
// }
// rc = sqlite3_exec(m_Database, "END TRANSACTION", NULL, NULL, &m_ErrMsg);
SH_LOG_INFO("Data inserted successfully into HIVES.");
}
@ -249,18 +215,16 @@ void Database::InsertIntoHives(const std::string &hiveName)
}
}
void Database::UpdateHive(const std::string &hiveOldName, const std::string &hiveNewName)
void cDatabase::UpdateHive(const std::string &hiveOldName, const std::string &hiveNewName)
{
try
{
const auto sql = "UPDATE HIVES SET HIVE = ? WHERE HIVE = ?;";
Sqlite3Statement statement(m_Database, sql);
Sqlite3Statement statement(m_pDatabase, sql);
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveNewName.c_str(),
hiveNewName.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, hiveOldName.c_str(),
hiveOldName.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveNewName.c_str(), hiveNewName.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, hiveOldName.c_str(), hiveOldName.size(), SQLITE_STATIC));
if (sqlite3_step(statement.stmt) != SQLITE_DONE)
{
@ -277,18 +241,16 @@ void Database::UpdateHive(const std::string &hiveOldName, const std::string &hiv
}
}
void Database::UpdateHiveName(const std::string &filename, const std::string &hiveName)
void cDatabase::UpdateHiveName(const std::string &filename, const std::string &hiveName)
{
try
{
const auto sql = "UPDATE SAMPLES SET HIVE = ? WHERE FILENAME = ?;";
Sqlite3Statement statement(m_Database, sql);
Sqlite3Statement statement(m_pDatabase, sql);
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveName.c_str(),
hiveName.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(),
filename.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveName.c_str(), hiveName.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), filename.size(), SQLITE_STATIC));
if (sqlite3_step(statement.stmt) == SQLITE_ROW)
{
@ -303,17 +265,16 @@ void Database::UpdateHiveName(const std::string &filename, const std::string &hi
}
}
void Database::UpdateFavoriteColumn(const std::string &filename, int value)
void cDatabase::UpdateFavoriteColumn(const std::string &filename, int value)
{
try
{
const auto sql = "UPDATE SAMPLES SET FAVORITE = ? WHERE FILENAME = ?;";
Sqlite3Statement statement(m_Database, sql);
Sqlite3Statement statement(m_pDatabase, sql);
throw_on_sqlite3_error(sqlite3_bind_int(statement.stmt, 1, value));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(),
filename.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), filename.size(), SQLITE_STATIC));
if (sqlite3_step(statement.stmt) == SQLITE_ROW)
{
@ -328,18 +289,16 @@ void Database::UpdateFavoriteColumn(const std::string &filename, int value)
}
}
void Database::UpdateSamplePack(const std::string &filename, const std::string &samplePack)
void cDatabase::UpdateSamplePack(const std::string &filename, const std::string &samplePack)
{
try
{
const auto sql = "UPDATE SAMPLES SET SAMPLEPACK = ? WHERE FILENAME = ?;";
Sqlite3Statement statement(m_Database, sql);
Sqlite3Statement statement(m_pDatabase, sql);
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, samplePack.c_str(),
samplePack.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(),
filename.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, samplePack.c_str(), samplePack.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), filename.size(), SQLITE_STATIC));
if (sqlite3_step(statement.stmt) == SQLITE_ROW)
{
@ -354,17 +313,16 @@ void Database::UpdateSamplePack(const std::string &filename, const std::string &
}
}
void Database::UpdateSampleType(const std::string &filename, const std::string &type)
void cDatabase::UpdateSampleType(const std::string &filename, const std::string &type)
{
try
{
const auto sql = "UPDATE SAMPLES SET TYPE = ? WHERE FILENAME = ?;";
Sqlite3Statement statement(m_Database, sql);
Sqlite3Statement statement(m_pDatabase, sql);
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, type.c_str(), type.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(),
filename.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), filename.size(), SQLITE_STATIC));
if (sqlite3_step(statement.stmt) == SQLITE_ROW)
{
@ -379,7 +337,7 @@ void Database::UpdateSampleType(const std::string &filename, const std::string &
}
}
std::string Database::GetSampleType(const std::string &filename)
std::string cDatabase::GetSampleType(const std::string &filename)
{
std::string type;
@ -387,10 +345,9 @@ std::string Database::GetSampleType(const std::string &filename)
{
const auto sql = "SELECT TYPE FROM SAMPLES WHERE FILENAME = ?;";
Sqlite3Statement statement(m_Database, sql);
Sqlite3Statement statement(m_pDatabase, sql);
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(),
filename.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC));
if (sqlite3_step(statement.stmt) == SQLITE_ROW)
{
@ -409,7 +366,7 @@ std::string Database::GetSampleType(const std::string &filename)
return type;
}
int Database::GetFavoriteColumnValueByFilename(const std::string &filename)
int cDatabase::GetFavoriteColumnValueByFilename(const std::string &filename)
{
int value = 0;
@ -417,10 +374,9 @@ int Database::GetFavoriteColumnValueByFilename(const std::string &filename)
{
const auto sql = "SELECT FAVORITE FROM SAMPLES WHERE FILENAME = ?;";
Sqlite3Statement statement(m_Database, sql);
Sqlite3Statement statement(m_pDatabase, sql);
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(),
filename.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC));
if (sqlite3_step(statement.stmt) == SQLITE_ROW)
{
@ -438,7 +394,7 @@ int Database::GetFavoriteColumnValueByFilename(const std::string &filename)
return value;
}
std::string Database::GetHiveByFilename(const std::string &filename)
std::string cDatabase::GetHiveByFilename(const std::string &filename)
{
std::string hive;
@ -446,10 +402,9 @@ std::string Database::GetHiveByFilename(const std::string &filename)
{
const auto sql = "SELECT HIVE FROM SAMPLES WHERE FILENAME = ?;";
Sqlite3Statement statement(m_Database, sql);
Sqlite3Statement statement(m_pDatabase, sql);
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(),
filename.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC));
if (sqlite3_step(statement.stmt) == SQLITE_ROW)
{
@ -467,16 +422,15 @@ std::string Database::GetHiveByFilename(const std::string &filename)
return hive;
}
void Database::RemoveSampleFromDatabase(const std::string &filename)
void cDatabase::RemoveSampleFromDatabase(const std::string &filename)
{
try
{
const auto sql = "DELETE FROM SAMPLES WHERE FILENAME = ?;";
Sqlite3Statement statement(m_Database, sql);
Sqlite3Statement statement(m_pDatabase, sql);
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(),
filename.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC));
if (sqlite3_step(statement.stmt) == SQLITE_DONE)
{
@ -491,16 +445,15 @@ void Database::RemoveSampleFromDatabase(const std::string &filename)
}
}
void Database::RemoveHiveFromDatabase(const std::string &hiveName)
void cDatabase::RemoveHiveFromDatabase(const std::string &hiveName)
{
try
{
const auto sql = "DELETE FROM HIVES WHERE HIVE = ?;";
Sqlite3Statement statement(m_Database, sql);
Sqlite3Statement statement(m_pDatabase, sql);
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveName.c_str(),
hiveName.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveName.c_str(), hiveName.size(), SQLITE_STATIC));
if (sqlite3_step(statement.stmt) == SQLITE_DONE)
{
@ -515,7 +468,7 @@ void Database::RemoveHiveFromDatabase(const std::string &hiveName)
}
}
std::string Database::GetSamplePathByFilename(const std::string &filename)
std::string cDatabase::GetSamplePathByFilename(const std::string &filename)
{
std::string path;
@ -523,10 +476,9 @@ std::string Database::GetSamplePathByFilename(const std::string &filename)
{
const auto sql = "SELECT PATH FROM SAMPLES WHERE FILENAME = ?;";
Sqlite3Statement statement(m_Database, sql);
Sqlite3Statement statement(m_pDatabase, sql);
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(),
filename.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC));
if (sqlite3_step(statement.stmt) == SQLITE_ROW)
{
@ -544,7 +496,7 @@ std::string Database::GetSamplePathByFilename(const std::string &filename)
return path;
}
std::string Database::GetSampleFileExtension(const std::string &filename)
std::string cDatabase::GetSampleFileExtension(const std::string &filename)
{
std::string extension;
@ -552,10 +504,9 @@ std::string Database::GetSampleFileExtension(const std::string &filename)
{
const auto sql = "SELECT EXTENSION FROM SAMPLES WHERE FILENAME = ?;";
Sqlite3Statement statement(m_Database, sql);
Sqlite3Statement statement(m_pDatabase, sql);
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(),
filename.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC));
if (sqlite3_step(statement.stmt) == SQLITE_ROW)
{
@ -573,7 +524,7 @@ std::string Database::GetSampleFileExtension(const std::string &filename)
return extension;
}
wxVector<wxVector<wxVariant>> Database::LoadSamplesDatabase(wxDataViewTreeCtrl &favorite_tree,
wxVector<wxVector<wxVariant>> cDatabase::LoadSamplesDatabase(wxDataViewTreeCtrl &favorite_tree,
wxDataViewItem &favorite_item,
wxTreeCtrl &trash_tree, wxTreeItemId &trash_item,
bool show_extension,
@ -590,7 +541,7 @@ wxVector<wxVector<wxVariant>> Database::LoadSamplesDatabase(wxDataViewTreeCtrl &
{
int num_rows = 0;
Sqlite3Statement statement1(m_Database, "SELECT Count(*) FROM SAMPLES;");
Sqlite3Statement statement1(m_pDatabase, "SELECT Count(*) FROM SAMPLES;");
if (SQLITE_ROW == sqlite3_step(statement1.stmt))
{
@ -601,7 +552,7 @@ wxVector<wxVector<wxVariant>> Database::LoadSamplesDatabase(wxDataViewTreeCtrl &
vecSet.reserve(num_rows);
}
Sqlite3Statement statement(m_Database, "SELECT FAVORITE, FILENAME, EXTENSION, SAMPLEPACK, \
Sqlite3Statement statement(m_pDatabase, "SELECT FAVORITE, FILENAME, EXTENSION, SAMPLEPACK, \
TYPE, CHANNELS, LENGTH, SAMPLERATE, BITRATE, PATH, \
TRASHED, HIVE FROM SAMPLES;");
@ -610,23 +561,17 @@ wxVector<wxVector<wxVariant>> Database::LoadSamplesDatabase(wxDataViewTreeCtrl &
while (SQLITE_ROW == sqlite3_step(statement.stmt))
{
int favorite = sqlite3_column_int(statement.stmt, 0);
wxString filename = std::string(reinterpret_cast<const char *>
(sqlite3_column_text(statement.stmt, 1)));
wxString file_extension = std::string(reinterpret_cast<const char *>
(sqlite3_column_text(statement.stmt, 2)));
wxString sample_pack = std::string(reinterpret_cast<const char *>
(sqlite3_column_text(statement.stmt, 3)));
wxString sample_type = std::string(reinterpret_cast<const char *>
(sqlite3_column_text(statement.stmt, 4)));
wxString filename = std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 1)));
wxString file_extension = std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 2)));
wxString sample_pack = std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 3)));
wxString sample_type = std::string(reinterpret_cast<const char*>(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<const char *>
(sqlite3_column_text(statement.stmt, 9)));
wxString path = std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 9)));
int trashed = sqlite3_column_int(statement.stmt, 10);
wxString hive_name = std::string(reinterpret_cast<const char *>
(sqlite3_column_text(statement.stmt, 11)));
wxString hive_name = std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 11)));
wxLongLong llLength = length;
int total_min = static_cast<int>((llLength / 60000).GetValue());
@ -683,8 +628,7 @@ wxVector<wxVector<wxVariant>> Database::LoadSamplesDatabase(wxDataViewTreeCtrl &
if (found_item.IsOk())
{
if (show_extension)
favorite_tree.AppendItem(found_item,
wxString::Format("%s.%s", filename, file_extension));
favorite_tree.AppendItem(found_item, wxString::Format("%s.%s", filename, file_extension));
else
favorite_tree.AppendItem(found_item, filename);
}
@ -723,9 +667,9 @@ wxVector<wxVector<wxVariant>> Database::LoadSamplesDatabase(wxDataViewTreeCtrl &
return vecSet;
}
wxVector<wxVector<wxVariant>>
Database::FilterDatabaseBySampleName(const std::string &sampleName, bool show_extension,
const std::string &icon_star_filled, const std::string &icon_star_empty)
wxVector<wxVector<wxVariant>>cDatabase::FilterDatabaseBySampleName(const std::string &sampleName, bool show_extension,
const std::string &icon_star_filled,
const std::string &icon_star_empty)
{
wxVector<wxVector<wxVariant>> sampleVec;
@ -735,12 +679,11 @@ Database::FilterDatabaseBySampleName(const std::string &sampleName, bool show_ex
try
{
Sqlite3Statement statement(m_Database, "SELECT FAVORITE, FILENAME, SAMPLEPACK, TYPE, \
Sqlite3Statement statement(m_pDatabase, "SELECT FAVORITE, FILENAME, SAMPLEPACK, TYPE, \
CHANNELS, LENGTH, SAMPLERATE, BITRATE, PATH \
FROM SAMPLES WHERE FILENAME LIKE '%' || ? || '%' ;");
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, sampleName.c_str(),
sampleName.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, sampleName.c_str(), sampleName.size(), SQLITE_STATIC));
int row = 0;
@ -749,18 +692,14 @@ Database::FilterDatabaseBySampleName(const std::string &sampleName, bool show_ex
SH_LOG_INFO("Record found, filtering db by {}", sampleName);
int favorite = sqlite3_column_int(statement.stmt, 0);
wxString filename = wxString(std::string(reinterpret_cast<const char *>
(sqlite3_column_text(statement.stmt, 1))));
wxString sample_pack = wxString(std::string(reinterpret_cast<const char *>
(sqlite3_column_text(statement.stmt, 2))));
wxString sample_type = std::string(reinterpret_cast<const char *>
(sqlite3_column_text(statement.stmt, 3)));
wxString filename = wxString(std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 1))));
wxString sample_pack = wxString(std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 2))));
wxString sample_type = std::string(reinterpret_cast<const char*>(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<const char *>
(sqlite3_column_text(statement.stmt, 8))));
wxString path = wxString(std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 8))));
wxLongLong llLength = length;
int total_min = static_cast<int>((llLength / 60000).GetValue());
@ -803,9 +742,9 @@ Database::FilterDatabaseBySampleName(const std::string &sampleName, bool show_ex
return sampleVec;
}
wxVector<wxVector<wxVariant>>
Database::FilterDatabaseByHiveName(const std::string &hiveName, bool show_extension,
const std::string &icon_star_filled, const std::string &icon_star_empty)
wxVector<wxVector<wxVariant>>cDatabase::FilterDatabaseByHiveName(const std::string &hiveName, bool show_extension,
const std::string &icon_star_filled,
const std::string &icon_star_empty)
{
wxVector<wxVector<wxVariant>> sampleVec;
@ -815,12 +754,11 @@ Database::FilterDatabaseByHiveName(const std::string &hiveName, bool show_extens
try
{
Sqlite3Statement statement(m_Database, "SELECT FAVORITE, FILENAME, SAMPLEPACK, TYPE, \
Sqlite3Statement statement(m_pDatabase, "SELECT FAVORITE, FILENAME, SAMPLEPACK, TYPE, \
CHANNELS, LENGTH, SAMPLERATE, BITRATE, PATH \
FROM SAMPLES WHERE HIVE = ? AND FAVORITE = 1;");
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveName.c_str(),
hiveName.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveName.c_str(), hiveName.size(), SQLITE_STATIC));
int row = 0;
@ -829,18 +767,14 @@ Database::FilterDatabaseByHiveName(const std::string &hiveName, bool show_extens
SH_LOG_INFO("Record found, filtering db by {}", hiveName);
int favorite = sqlite3_column_int(statement.stmt, 0);
wxString filename = wxString(std::string(reinterpret_cast<const char *>
(sqlite3_column_text(statement.stmt, 1))));
wxString sample_pack = wxString(std::string(reinterpret_cast<const char *>
(sqlite3_column_text(statement.stmt, 2))));
wxString sample_type = std::string(reinterpret_cast<const char *>
(sqlite3_column_text(statement.stmt, 3)));
wxString filename = wxString(std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 1))));
wxString sample_pack = wxString(std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 2))));
wxString sample_type = std::string(reinterpret_cast<const char*>(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<const char *>
(sqlite3_column_text(statement.stmt, 8))));
wxString path = wxString(std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 8))));
wxLongLong llLength = length;
int total_min = static_cast<int>((llLength / 60000).GetValue());
@ -879,20 +813,19 @@ Database::FilterDatabaseByHiveName(const std::string &hiveName, bool show_extens
return sampleVec;
}
void Database::LoadHivesDatabase(wxDataViewTreeCtrl &treeCtrl)
void cDatabase::LoadHivesDatabase(wxDataViewTreeCtrl &treeCtrl)
{
try
{
const auto sql = "SELECT HIVE FROM HIVES;";
Sqlite3Statement statement(m_Database, sql);
Sqlite3Statement statement(m_pDatabase, sql);
while (SQLITE_ROW == sqlite3_step(statement.stmt))
{
SH_LOG_INFO("Loading hives..");
const auto hive = wxString(std::string(reinterpret_cast<const char *>
(sqlite3_column_text(statement.stmt, 0))));
const auto hive = wxString(std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 0))));
treeCtrl.AppendContainer(wxDataViewItem(wxNullPtr), hive);
}
@ -904,7 +837,7 @@ void Database::LoadHivesDatabase(wxDataViewTreeCtrl &treeCtrl)
}
// Compares the input array with the database and removes duplicates.
wxArrayString Database::CheckDuplicates(const wxArrayString &files)
wxArrayString cDatabase::CheckDuplicates(const wxArrayString &files)
{
wxArrayString sorted_files;
@ -915,7 +848,7 @@ wxArrayString Database::CheckDuplicates(const wxArrayString &files)
{
const auto sql = "SELECT * FROM SAMPLES WHERE FILENAME = ?;";
Sqlite3Statement statement(m_Database, sql);
Sqlite3Statement statement(m_pDatabase, sql);
for (unsigned int i = 0; i < files.size(); i++)
{
@ -940,16 +873,15 @@ wxArrayString Database::CheckDuplicates(const wxArrayString &files)
return sorted_files;
}
bool Database::IsTrashed(const std::string &filename)
bool cDatabase::IsTrashed(const std::string &filename)
{
try
{
const auto sql = "SELECT TRASHED FROM SAMPLES WHERE FILENAME = ?;";
Sqlite3Statement statement(m_Database, sql);
Sqlite3Statement statement(m_pDatabase, sql);
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(),
filename.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC));
if (sqlite3_step(statement.stmt) == SQLITE_ROW)
{
@ -969,17 +901,16 @@ bool Database::IsTrashed(const std::string &filename)
return false;
}
void Database::UpdateTrashColumn(const std::string &filename, int value)
void cDatabase::UpdateTrashColumn(const std::string &filename, int value)
{
try
{
const auto sql = "UPDATE SAMPLES SET TRASHED = ? WHERE FILENAME = ?;";
Sqlite3Statement statement(m_Database, sql);
Sqlite3Statement statement(m_pDatabase, sql);
throw_on_sqlite3_error(sqlite3_bind_int(statement.stmt, 1, value));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(),
filename.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), filename.size(), SQLITE_STATIC));
if (sqlite3_step(statement.stmt) == SQLITE_ROW)
{
@ -994,10 +925,10 @@ void Database::UpdateTrashColumn(const std::string &filename, int value)
}
}
wxVector<wxVector<wxVariant>>
Database::RestoreFromTrashByFilename(const std::string &filename,
wxVector<wxVector<wxVariant>>cDatabase::RestoreFromTrashByFilename(const std::string &filename,
wxVector<wxVector<wxVariant>> &vecSet, bool show_extension,
const std::string &icon_star_filled, const std::string &icon_star_empty)
const std::string &icon_star_filled,
const std::string &icon_star_empty)
{
wxVariant icon_filled, icon_empty;
icon_filled = wxVariant(wxBitmap(icon_star_filled));
@ -1009,31 +940,24 @@ Database::RestoreFromTrashByFilename(const std::string &filename,
TYPE, CHANNELS, LENGTH, SAMPLERATE, BITRATE, PATH, \
TRASHED, HIVE FROM SAMPLES WHERE FILENAME = ?;";
Sqlite3Statement statement(m_Database, sql);
Sqlite3Statement statement(m_pDatabase, sql);
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(),
filename.size(), SQLITE_STATIC));
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC));
while (SQLITE_ROW == sqlite3_step(statement.stmt))
{
int favorite = sqlite3_column_int(statement.stmt, 0);
wxString filename = std::string(reinterpret_cast<const char *>
(sqlite3_column_text(statement.stmt, 1)));
wxString file_extension = std::string(reinterpret_cast<const char *>
(sqlite3_column_text(statement.stmt, 2)));
wxString sample_pack = std::string(reinterpret_cast<const char *>
(sqlite3_column_text(statement.stmt, 3)));
wxString sample_type = std::string(reinterpret_cast<const char *>
(sqlite3_column_text(statement.stmt, 4)));
wxString filename = std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 1)));
wxString file_extension = std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 2)));
wxString sample_pack = std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 3)));
wxString sample_type = std::string(reinterpret_cast<const char*>(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<const char *>
(sqlite3_column_text(statement.stmt, 9)));
wxString path = std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 9)));
int trashed = sqlite3_column_int(statement.stmt, 10);
wxString hive_name = std::string(reinterpret_cast<const char *>
(sqlite3_column_text(statement.stmt, 11)));
wxString hive_name = std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 11)));
wxLongLong llLength = length;
int total_min = static_cast<int>((llLength / 60000).GetValue());
@ -1073,12 +997,12 @@ Database::RestoreFromTrashByFilename(const std::string &filename,
return vecSet;
}
void Database::OpenDatabase()
void cDatabase::OpenDatabase()
{
throw_on_sqlite3_error(sqlite3_open(static_cast<std::string>(DATABASE_FILEPATH).c_str(), &m_Database));
throw_on_sqlite3_error(sqlite3_open(static_cast<std::string>(DATABASE_FILEPATH).c_str(), &m_pDatabase));
}
void Database::CloseDatabase()
void cDatabase::CloseDatabase()
{
throw_on_sqlite3_error(sqlite3_close(m_Database));
throw_on_sqlite3_error(sqlite3_close(m_pDatabase));
}

View File

@ -34,17 +34,17 @@
#include <sqlite3.h>
class Database
class cDatabase
{
public:
Database();
~Database();
cDatabase();
~cDatabase();
private:
// -------------------------------------------------------------------
sqlite3* m_Database;
sqlite3* m_pDatabase = nullptr;
int rc;
char* m_ErrMsg;
char* m_pErrMsg = nullptr;
private:
// -------------------------------------------------------------------

View File

@ -20,189 +20,187 @@
#include "GUI/Dialogs/Settings.hpp"
#include "Utility/ControlIDs.hpp"
#include "Utility/Serialize.hpp"
#include "Utility/Log.hpp"
#include "Utility/Paths.hpp"
#include "Utility/Serialize.hpp"
#include <wx/defs.h>
#include <wx/gdicmn.h>
#include <wx/stringimpl.h>
Settings::Settings(wxWindow *window)
: wxDialog(window, wxID_ANY, "Settings", wxDefaultPosition,
cSettings::cSettings(wxWindow *window)
: wxDialog(window, wxID_ANY, "cSettings", wxDefaultPosition,
wxSize(720, 270), wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP),
m_Window(window)
m_pWindow(window)
{
m_Panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
m_pPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
m_MainSizer = new wxBoxSizer(wxVERTICAL);
m_NotebookSizer = new wxBoxSizer(wxVERTICAL);
m_ButtonSizer = new wxBoxSizer(wxHORIZONTAL);
m_pMainSizer = new wxBoxSizer(wxVERTICAL);
m_pNotebookSizer = new wxBoxSizer(wxVERTICAL);
m_pButtonSizer = new wxBoxSizer(wxHORIZONTAL);
m_Notebook = new wxNotebook(m_Panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, _T("NOTEBOOK"));
m_pNotebook = new wxNotebook(m_pPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, _T("NOTEBOOK"));
m_DisplaySettingPanel = new wxPanel(m_Notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize);
m_pDisplaySettingPanel = new wxPanel(m_pNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize);
m_DisplayTopSizer = new wxBoxSizer(wxVERTICAL);
m_DisplayFontSizer = new wxBoxSizer(wxHORIZONTAL);
m_WaveformColourSizer = new wxBoxSizer(wxHORIZONTAL);
m_pDisplayTopSizer = new wxBoxSizer(wxVERTICAL);
m_pDisplayFontSizer = new wxBoxSizer(wxHORIZONTAL);
m_pWaveformColourSizer = new wxBoxSizer(wxHORIZONTAL);
Serializer serializer;
SampleHive::cSerializer serializer;
wxString fontChoices[] = { "System default" };
m_FontTypeText = new wxStaticText(m_DisplaySettingPanel, wxID_ANY, "Font",
wxDefaultPosition, wxDefaultSize, 0);
m_FontType = new wxChoice(m_DisplaySettingPanel, SD_FontType,
m_pFontTypeText = new wxStaticText(m_pDisplaySettingPanel, wxID_ANY, "Font", wxDefaultPosition, wxDefaultSize, 0);
m_pFontType = new wxChoice(m_pDisplaySettingPanel, SampleHive::ID::SD_FontType,
wxDefaultPosition, wxDefaultSize, 1, fontChoices, 0);
m_FontType->SetSelection(0);
m_FontSize = new wxSpinCtrl(m_DisplaySettingPanel, SD_FontSize, "Default",
wxDefaultPosition, wxDefaultSize);
m_FontSize->SetValue(window->GetFont().GetPointSize());
m_FontBrowseButton = new wxButton(m_DisplaySettingPanel, SD_FontBrowseButton, "Select font",
m_pFontType->SetSelection(0);
m_pFontSize = new wxSpinCtrl(m_pDisplaySettingPanel, SampleHive::ID::SD_FontSize, "Default", wxDefaultPosition, wxDefaultSize);
m_pFontSize->SetValue(window->GetFont().GetPointSize());
m_pFontBrowseButton = new wxButton(m_pDisplaySettingPanel, SampleHive::ID::SD_FontBrowseButton, "Select font",
wxDefaultPosition, wxDefaultSize, 0);
m_WaveformColourLabel = new wxStaticText(m_DisplaySettingPanel, wxID_ANY, "Waveform colour",
m_pWaveformColourLabel = new wxStaticText(m_pDisplaySettingPanel, wxID_ANY, "Waveform colour",
wxDefaultPosition, wxDefaultSize, 0);
m_WaveformColourPickerCtrl = new wxColourPickerCtrl(m_DisplaySettingPanel, SD_WaveformColourPickerCtrl,
m_pWaveformColourPickerCtrl = new wxColourPickerCtrl(m_pDisplaySettingPanel, SampleHive::ID::SD_WaveformColourPickerCtrl,
serializer.DeserializeWaveformColour(),
wxDefaultPosition, wxDefaultSize,
wxCLRP_DEFAULT_STYLE);
m_CollectionSettingPanel = new wxPanel(m_Notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize);
m_pCollectionSettingPanel = new wxPanel(m_pNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize);
m_CollectionMainSizer = new wxBoxSizer(wxVERTICAL);
m_CollectionImportDirSizer = new wxBoxSizer(wxHORIZONTAL);
m_CollectionImportOptionsSizer = new wxBoxSizer(wxHORIZONTAL);
m_CollectionShowExtensionSizer = new wxBoxSizer(wxVERTICAL);
m_pCollectionMainSizer = new wxBoxSizer(wxVERTICAL);
m_pCollectionImportDirSizer = new wxBoxSizer(wxHORIZONTAL);
m_pCollectionImportOptionsSizer = new wxBoxSizer(wxHORIZONTAL);
m_pCollectionShowExtensionSizer = new wxBoxSizer(wxVERTICAL);
wxString defaultDir = wxGetHomeDir();
m_AutoImportCheck = new wxCheckBox(m_CollectionSettingPanel, SD_AutoImport, "Auto import",
m_pAutoImportCheck = new wxCheckBox(m_pCollectionSettingPanel, SampleHive::ID::SD_AutoImport, "Auto import",
wxDefaultPosition, wxDefaultSize, 0);
m_ImportDirLocation = new wxTextCtrl(m_CollectionSettingPanel, wxID_ANY, defaultDir,
m_pImportDirLocation = new wxTextCtrl(m_pCollectionSettingPanel, wxID_ANY, defaultDir,
wxDefaultPosition, wxDefaultSize, 0);
m_ImportDirLocation->Disable();
m_BrowseAutoImportDirButton = new wxButton(m_CollectionSettingPanel, SD_BrowseAutoImportDir, "Browse",
m_pImportDirLocation->Disable();
m_pBrowseAutoImportDirButton = new wxButton(m_pCollectionSettingPanel, SampleHive::ID::SD_BrowseAutoImportDir, "Browse",
wxDefaultPosition, wxDefaultSize, 0);
m_BrowseAutoImportDirButton->Disable();
m_FollowSymLinksCheck = new wxCheckBox(m_CollectionSettingPanel, SD_FollowSymLinks,
m_pBrowseAutoImportDirButton->Disable();
m_pFollowSymLinksCheck = new wxCheckBox(m_pCollectionSettingPanel, SampleHive::ID::SD_FollowSymLinks,
"Follow symbolic links", wxDefaultPosition, wxDefaultSize, 0);
m_FollowSymLinksCheck->SetToolTip("Wheather to follow symbolic links");
m_FollowSymLinksCheck->Disable();
m_RecursiveImportCheck = new wxCheckBox(m_CollectionSettingPanel, SD_RecursiveImport,
m_pFollowSymLinksCheck->SetToolTip("Wheather to follow symbolic links");
m_pFollowSymLinksCheck->Disable();
m_pRecursiveImportCheck = new wxCheckBox(m_pCollectionSettingPanel, SampleHive::ID::SD_RecursiveImport,
"Recursive search", wxDefaultPosition, wxDefaultSize, 0);
m_RecursiveImportCheck->SetToolTip("Recursively search for samples in the directory");
m_RecursiveImportCheck->Disable();
m_ShowFileExtensionCheck = new wxCheckBox(m_CollectionSettingPanel, SD_ShowFileExtension,
m_pRecursiveImportCheck->SetToolTip("Recursively search for samples in the directory");
m_pRecursiveImportCheck->Disable();
m_pShowFileExtensionCheck = new wxCheckBox(m_pCollectionSettingPanel, SampleHive::ID::SD_ShowFileExtension,
"Show file extension", wxDefaultPosition, wxDefaultSize, 0);
m_ShowFileExtensionCheck->SetToolTip("Weather to show file extension");
m_pShowFileExtensionCheck->SetToolTip("Weather to show file extension");
m_ConfigurationSettingPanel = new wxPanel(m_Notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize);
m_pConfigurationSettingPanel = new wxPanel(m_pNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize);
m_GeneralMainSizer = new wxFlexGridSizer(2, 3, 0, 0);
m_GeneralMainSizer->AddGrowableCol(1);
m_GeneralMainSizer->SetFlexibleDirection(wxBOTH);
m_GeneralMainSizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
m_pGeneralMainSizer = new wxFlexGridSizer(2, 3, 0, 0);
m_pGeneralMainSizer->AddGrowableCol(1);
m_pGeneralMainSizer->SetFlexibleDirection(wxBOTH);
m_pGeneralMainSizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
m_ConfigLabel = new wxStaticText(m_ConfigurationSettingPanel, wxID_ANY,
m_pConfigLabel = new wxStaticText(m_pConfigurationSettingPanel, wxID_ANY,
"Default configuration file location", wxDefaultPosition, wxDefaultSize);
m_ConfigText = new wxTextCtrl(m_ConfigurationSettingPanel, wxID_ANY, CONFIG_FILEPATH,
m_pConfigText = new wxTextCtrl(m_pConfigurationSettingPanel, wxID_ANY, CONFIG_FILEPATH,
wxDefaultPosition, wxDefaultSize);
m_ConfigBrowse = new wxButton(m_ConfigurationSettingPanel, SD_BrowseConfigDir, "Browse",
m_pConfigBrowse = new wxButton(m_pConfigurationSettingPanel, SampleHive::ID::SD_BrowseConfigDir, "Browse",
wxDefaultPosition, wxDefaultSize, 0);
m_DatabaseLabel = new wxStaticText(m_ConfigurationSettingPanel, wxID_ANY, "Default database location",
m_pDatabaseLabel = new wxStaticText(m_pConfigurationSettingPanel, wxID_ANY, "Default database location",
wxDefaultPosition, wxDefaultSize);
m_DatabaseText = new wxTextCtrl(m_ConfigurationSettingPanel, wxID_ANY, DATABASE_FILEPATH,
m_pDatabaseText = new wxTextCtrl(m_pConfigurationSettingPanel, wxID_ANY, DATABASE_FILEPATH,
wxDefaultPosition, wxDefaultSize);
m_DatabaseBrowse = new wxButton(m_ConfigurationSettingPanel, SD_BrowseDatabaseDir, "Browse",
m_pDatabaseBrowse = new wxButton(m_pConfigurationSettingPanel, SampleHive::ID::SD_BrowseDatabaseDir, "Browse",
wxDefaultPosition, wxDefaultSize, 0);
m_Notebook->AddPage(m_DisplaySettingPanel, "Display");
m_Notebook->AddPage(m_CollectionSettingPanel, "Collection");
m_Notebook->AddPage(m_ConfigurationSettingPanel, "General");
m_pNotebook->AddPage(m_pDisplaySettingPanel, "Display");
m_pNotebook->AddPage(m_pCollectionSettingPanel, "Collection");
m_pNotebook->AddPage(m_pConfigurationSettingPanel, "General");
m_OkButton = new wxButton(m_Panel, wxID_OK, "OK", wxDefaultPosition, wxDefaultSize);
m_CancelButton = new wxButton(m_Panel, wxID_CANCEL, "Cancel", wxDefaultPosition, wxDefaultSize);
m_pOkButton = new wxButton(m_pPanel, wxID_OK, "OK", wxDefaultPosition, wxDefaultSize);
m_pCancelButton = new wxButton(m_pPanel, wxID_CANCEL, "Cancel", wxDefaultPosition, wxDefaultSize);
LoadDefaultConfig();
// Bind events
Bind(wxEVT_CHECKBOX, &Settings::OnCheckAutoImport, this, SD_AutoImport);
Bind(wxEVT_CHECKBOX, &Settings::OnCheckFollowSymLinks, this, SD_FollowSymLinks);
Bind(wxEVT_CHECKBOX, &Settings::OnCheckRecursiveImport, this, SD_RecursiveImport);
Bind(wxEVT_CHECKBOX, &Settings::OnCheckShowFileExtension, this, SD_ShowFileExtension);
Bind(wxEVT_SPINCTRL, &Settings::OnChangeFontSize, this, SD_FontSize);
Bind(wxEVT_BUTTON, &Settings::OnSelectFont, this, SD_FontBrowseButton);
Bind(wxEVT_BUTTON, &Settings::OnClickBrowseAutoImportDir, this, SD_BrowseAutoImportDir);
Bind(wxEVT_BUTTON, &Settings::OnClickConfigBrowse, this, SD_BrowseConfigDir);
Bind(wxEVT_BUTTON, &Settings::OnClickDatabaseBrowse, this, SD_BrowseDatabaseDir);
Bind(wxEVT_COLOURPICKER_CHANGED, &Settings::OnChangeWaveformColour, this, SD_WaveformColourPickerCtrl);
Bind(wxEVT_CHECKBOX, &cSettings::OnCheckAutoImport, this, SampleHive::ID::SD_AutoImport);
Bind(wxEVT_CHECKBOX, &cSettings::OnCheckFollowSymLinks, this, SampleHive::ID::SD_FollowSymLinks);
Bind(wxEVT_CHECKBOX, &cSettings::OnCheckRecursiveImport, this, SampleHive::ID::SD_RecursiveImport);
Bind(wxEVT_CHECKBOX, &cSettings::OnCheckShowFileExtension, this, SampleHive::ID::SD_ShowFileExtension);
Bind(wxEVT_SPINCTRL, &cSettings::OnChangeFontSize, this, SampleHive::ID::SD_FontSize);
Bind(wxEVT_BUTTON, &cSettings::OnSelectFont, this, SampleHive::ID::SD_FontBrowseButton);
Bind(wxEVT_BUTTON, &cSettings::OnClickBrowseAutoImportDir, this, SampleHive::ID::SD_BrowseAutoImportDir);
Bind(wxEVT_BUTTON, &cSettings::OnClickConfigBrowse, this, SampleHive::ID::SD_BrowseConfigDir);
Bind(wxEVT_BUTTON, &cSettings::OnClickDatabaseBrowse, this, SampleHive::ID::SD_BrowseDatabaseDir);
Bind(wxEVT_COLOURPICKER_CHANGED, &cSettings::OnChangeWaveformColour, this, SampleHive::ID::SD_WaveformColourPickerCtrl);
// Adding controls to sizers
m_NotebookSizer->Add(m_Notebook, 1, wxALL | wxEXPAND, 2);
m_pNotebookSizer->Add(m_pNotebook, 1, wxALL | wxEXPAND, 2);
m_GeneralMainSizer->Add(m_ConfigLabel, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_GeneralMainSizer->Add(m_ConfigText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2);
m_GeneralMainSizer->Add(m_ConfigBrowse, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_pGeneralMainSizer->Add(m_pConfigLabel, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_pGeneralMainSizer->Add(m_pConfigText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2);
m_pGeneralMainSizer->Add(m_pConfigBrowse, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_GeneralMainSizer->Add(m_DatabaseLabel, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_GeneralMainSizer->Add(m_DatabaseText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2);
m_GeneralMainSizer->Add(m_DatabaseBrowse, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_pGeneralMainSizer->Add(m_pDatabaseLabel, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_pGeneralMainSizer->Add(m_pDatabaseText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2);
m_pGeneralMainSizer->Add(m_pDatabaseBrowse, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_DisplayFontSizer->Add(m_FontTypeText, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_DisplayFontSizer->Add(m_FontType, 1, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_DisplayFontSizer->Add(m_FontSize, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_DisplayFontSizer->Add(m_FontBrowseButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_WaveformColourSizer->Add(m_WaveformColourLabel, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_WaveformColourSizer->Add(m_WaveformColourPickerCtrl, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_pDisplayFontSizer->Add(m_pFontTypeText, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_pDisplayFontSizer->Add(m_pFontType, 1, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_pDisplayFontSizer->Add(m_pFontSize, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_pDisplayFontSizer->Add(m_pFontBrowseButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_pWaveformColourSizer->Add(m_pWaveformColourLabel, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_pWaveformColourSizer->Add(m_pWaveformColourPickerCtrl, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_DisplayTopSizer->Add(m_DisplayFontSizer, 0, wxALL | wxEXPAND, 2);
m_DisplayTopSizer->Add(m_WaveformColourSizer, 0, wxALL | wxEXPAND, 2);
m_pDisplayTopSizer->Add(m_pDisplayFontSizer, 0, wxALL | wxEXPAND, 2);
m_pDisplayTopSizer->Add(m_pWaveformColourSizer, 0, wxALL | wxEXPAND, 2);
m_CollectionImportDirSizer->Add(m_AutoImportCheck, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_CollectionImportDirSizer->Add(m_ImportDirLocation, 1, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_CollectionImportDirSizer->Add(m_BrowseAutoImportDirButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_pCollectionImportDirSizer->Add(m_pAutoImportCheck, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_pCollectionImportDirSizer->Add(m_pImportDirLocation, 1, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_pCollectionImportDirSizer->Add(m_pBrowseAutoImportDirButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_CollectionImportOptionsSizer->Add(m_FollowSymLinksCheck, 0, wxALL, 2);
m_CollectionImportOptionsSizer->Add(m_RecursiveImportCheck, 0, wxALL, 2);
m_CollectionShowExtensionSizer->Add(m_ShowFileExtensionCheck, 0, wxALL, 2);
m_pCollectionImportOptionsSizer->Add(m_pFollowSymLinksCheck, 0, wxALL, 2);
m_pCollectionImportOptionsSizer->Add(m_pRecursiveImportCheck, 0, wxALL, 2);
m_pCollectionShowExtensionSizer->Add(m_pShowFileExtensionCheck, 0, wxALL, 2);
m_CollectionMainSizer->Add(m_CollectionImportDirSizer, 0, wxALL | wxEXPAND, 2);
m_CollectionMainSizer->Add(m_CollectionImportOptionsSizer, 0, wxALL | wxEXPAND, 2);
m_CollectionMainSizer->Add(m_CollectionShowExtensionSizer, 0, wxALL | wxEXPAND, 2);
m_pCollectionMainSizer->Add(m_pCollectionImportDirSizer, 0, wxALL | wxEXPAND, 2);
m_pCollectionMainSizer->Add(m_pCollectionImportOptionsSizer, 0, wxALL | wxEXPAND, 2);
m_pCollectionMainSizer->Add(m_pCollectionShowExtensionSizer, 0, wxALL | wxEXPAND, 2);
m_ButtonSizer->Add(m_OkButton, 0, wxALL | wxALIGN_BOTTOM, 2);
m_ButtonSizer->Add(m_CancelButton, 0, wxALL | wxALIGN_BOTTOM, 2);
m_pButtonSizer->Add(m_pOkButton, 0, wxALL | wxALIGN_BOTTOM, 2);
m_pButtonSizer->Add(m_pCancelButton, 0, wxALL | wxALIGN_BOTTOM, 2);
m_MainSizer->Add(m_NotebookSizer, 1, wxALL | wxEXPAND, 2);
m_MainSizer->Add(m_ButtonSizer, 0, wxALL | wxALIGN_RIGHT, 2);
m_pMainSizer->Add(m_pNotebookSizer, 1, wxALL | wxEXPAND, 2);
m_pMainSizer->Add(m_pButtonSizer, 0, wxALL | wxALIGN_RIGHT, 2);
// Top panel layout
m_Panel->SetSizer(m_MainSizer);
m_MainSizer->Fit(m_Panel);
m_MainSizer->SetSizeHints(m_Panel);
m_MainSizer->Layout();
m_pPanel->SetSizer(m_pMainSizer);
m_pMainSizer->Fit(m_pPanel);
m_pMainSizer->SetSizeHints(m_pPanel);
m_pMainSizer->Layout();
// Display panel layout
m_DisplaySettingPanel->SetSizer(m_DisplayTopSizer);
m_DisplayTopSizer->Fit(m_DisplaySettingPanel);
m_DisplayTopSizer->SetSizeHints(m_DisplaySettingPanel);
m_DisplayTopSizer->Layout();
m_pDisplaySettingPanel->SetSizer(m_pDisplayTopSizer);
m_pDisplayTopSizer->Fit(m_pDisplaySettingPanel);
m_pDisplayTopSizer->SetSizeHints(m_pDisplaySettingPanel);
m_pDisplayTopSizer->Layout();
// Collection panel layout
m_CollectionSettingPanel->SetSizer(m_CollectionMainSizer);
m_CollectionMainSizer->Fit(m_CollectionSettingPanel);
m_CollectionMainSizer->SetSizeHints(m_CollectionSettingPanel);
m_CollectionMainSizer->Layout();
m_pCollectionSettingPanel->SetSizer(m_pCollectionMainSizer);
m_pCollectionMainSizer->Fit(m_pCollectionSettingPanel);
m_pCollectionMainSizer->SetSizeHints(m_pCollectionSettingPanel);
m_pCollectionMainSizer->Layout();
// Configuration panel layout
m_ConfigurationSettingPanel->SetSizer(m_GeneralMainSizer);
m_GeneralMainSizer->Fit(m_ConfigurationSettingPanel);
m_GeneralMainSizer->SetSizeHints(m_ConfigurationSettingPanel);
m_GeneralMainSizer->Layout();
m_pConfigurationSettingPanel->SetSizer(m_pGeneralMainSizer);
m_pGeneralMainSizer->Fit(m_pConfigurationSettingPanel);
m_pGeneralMainSizer->SetSizeHints(m_pConfigurationSettingPanel);
m_pGeneralMainSizer->Layout();
}
void Settings::OnClickConfigBrowse(wxCommandEvent& event)
void cSettings::OnClickConfigBrowse(wxCommandEvent& event)
{
wxString initial_dir = wxGetHomeDir();
@ -217,7 +215,7 @@ void Settings::OnClickConfigBrowse(wxCommandEvent& event)
case wxID_OK:
{
wxString path = dir_dialog.GetPath();
m_ConfigText->SetValue(path + "/config.yaml");
m_pConfigText->SetValue(path + "/config.yaml");
break;
}
default:
@ -225,7 +223,7 @@ void Settings::OnClickConfigBrowse(wxCommandEvent& event)
}
}
void Settings::OnClickDatabaseBrowse(wxCommandEvent& event)
void cSettings::OnClickDatabaseBrowse(wxCommandEvent& event)
{
wxString initial_dir = wxGetHomeDir();
@ -240,7 +238,7 @@ void Settings::OnClickDatabaseBrowse(wxCommandEvent& event)
case wxID_OK:
{
wxString path = dir_dialog.GetPath();
m_DatabaseText->SetValue(path + "/config.yaml");
m_pDatabaseText->SetValue(path + "/config.yaml");
break;
}
default:
@ -248,56 +246,56 @@ void Settings::OnClickDatabaseBrowse(wxCommandEvent& event)
}
}
void Settings::OnCheckAutoImport(wxCommandEvent& event)
void cSettings::OnCheckAutoImport(wxCommandEvent& event)
{
Serializer serializer;
SampleHive::cSerializer serializer;
if (!m_AutoImportCheck->GetValue())
if (!m_pAutoImportCheck->GetValue())
{
bAutoImport = false;
m_ImportDirLocation->Disable();
m_BrowseAutoImportDirButton->Disable();
m_FollowSymLinksCheck->Disable();
m_RecursiveImportCheck->Disable();
m_bAutoImport = false;
m_pImportDirLocation->Disable();
m_pBrowseAutoImportDirButton->Disable();
m_pFollowSymLinksCheck->Disable();
m_pRecursiveImportCheck->Disable();
serializer.SerializeAutoImport(bAutoImport, m_ImportDirLocation->GetValue().ToStdString());
serializer.SerializeAutoImport(m_bAutoImport, m_pImportDirLocation->GetValue().ToStdString());
}
else
{
bAutoImport = true;
m_ImportDirLocation->Enable();
m_BrowseAutoImportDirButton->Enable();
m_FollowSymLinksCheck->Enable();
m_RecursiveImportCheck->Enable();
m_bAutoImport = true;
m_pImportDirLocation->Enable();
m_pBrowseAutoImportDirButton->Enable();
m_pFollowSymLinksCheck->Enable();
m_pRecursiveImportCheck->Enable();
serializer.SerializeAutoImport(bAutoImport, m_ImportDirLocation->GetValue().ToStdString());
serializer.SerializeAutoImport(m_bAutoImport, m_pImportDirLocation->GetValue().ToStdString());
}
}
void Settings::OnCheckFollowSymLinks(wxCommandEvent& event)
void cSettings::OnCheckFollowSymLinks(wxCommandEvent& event)
{
Serializer serializer;
SampleHive::cSerializer serializer;
serializer.SerializeFollowSymLink(m_FollowSymLinksCheck->GetValue());
serializer.SerializeFollowSymLink(m_pFollowSymLinksCheck->GetValue());
}
void Settings::OnCheckRecursiveImport(wxCommandEvent& event)
void cSettings::OnCheckRecursiveImport(wxCommandEvent& event)
{
Serializer serializer;
SampleHive::cSerializer serializer;
serializer.SerializeRecursiveImport(m_RecursiveImportCheck->GetValue());
serializer.SerializeRecursiveImport(m_pRecursiveImportCheck->GetValue());
}
void Settings::OnCheckShowFileExtension(wxCommandEvent& event)
void cSettings::OnCheckShowFileExtension(wxCommandEvent& event)
{
Serializer serializer;
SampleHive::cSerializer serializer;
serializer.SerializeShowFileExtension(m_ShowFileExtensionCheck->GetValue());
serializer.SerializeShowFileExtension(m_pShowFileExtensionCheck->GetValue());
}
void Settings::OnClickBrowseAutoImportDir(wxCommandEvent& event)
void cSettings::OnClickBrowseAutoImportDir(wxCommandEvent& event)
{
Serializer serializer;
SampleHive::cSerializer serializer;
wxString initial_dir = wxGetHomeDir();
@ -312,9 +310,9 @@ void Settings::OnClickBrowseAutoImportDir(wxCommandEvent& event)
case wxID_OK:
{
wxString path = dir_dialog.GetPath();
m_ImportDirLocation->SetValue(path);
m_pImportDirLocation->SetValue(path);
serializer.SerializeAutoImport(bAutoImport, m_ImportDirLocation->GetValue().ToStdString());
serializer.SerializeAutoImport(m_bAutoImport, m_pImportDirLocation->GetValue().ToStdString());
break;
}
default:
@ -322,7 +320,7 @@ void Settings::OnClickBrowseAutoImportDir(wxCommandEvent& event)
}
}
void Settings::OnSelectFont(wxCommandEvent& event)
void cSettings::OnSelectFont(wxCommandEvent& event)
{
wxFontDialog font_dialog(this);
@ -333,16 +331,16 @@ void Settings::OnSelectFont(wxCommandEvent& event)
wxFontData fontData = font_dialog.GetFontData();
m_Font = fontData.GetChosenFont();
if (m_FontType->GetCount() > 1)
if (m_pFontType->GetCount() > 1)
{
m_FontType->Delete(1);
m_FontType->AppendString(m_Font.GetFaceName());
m_FontType->SetSelection(1);
m_pFontType->Delete(1);
m_pFontType->AppendString(m_Font.GetFaceName());
m_pFontType->SetSelection(1);
}
else
{
m_FontType->AppendString(m_Font.GetFaceName());
m_FontType->SetSelection(1);
m_pFontType->AppendString(m_Font.GetFaceName());
m_pFontType->SetSelection(1);
}
SetCustomFont();
@ -354,29 +352,29 @@ void Settings::OnSelectFont(wxCommandEvent& event)
PrintFont();
}
void Settings::OnChangeFontSize(wxSpinEvent& event)
void cSettings::OnChangeFontSize(wxSpinEvent& event)
{
Serializer serializer;
SampleHive::cSerializer serializer;
int font_size = m_FontSize->GetValue();
int font_size = m_pFontSize->GetValue();
if (m_FontType->GetStringSelection() == "System default")
if (m_pFontType->GetStringSelection() == "System default")
m_Font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT);
m_Font.SetPointSize(font_size);
serializer.SerializeFontSettings(m_Font);
m_Window->SetFont(m_Font);
m_pWindow->SetFont(m_Font);
this->SetFont(m_Font);
SH_LOG_DEBUG("Font size: {}", font_size);
SH_LOG_DEBUG("Font size: {}", m_Font.GetPointSize());
}
void Settings::LoadDefaultConfig()
void cSettings::LoadDefaultConfig()
{
Serializer serializer;
SampleHive::cSerializer serializer;
wxFont sys_font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT);
wxString system_font = sys_font.GetFaceName();
@ -387,54 +385,54 @@ void Settings::LoadDefaultConfig()
if (system_font != font_face)
{
if (m_FontType->GetCount() > 1)
if (m_pFontType->GetCount() > 1)
{
m_FontType->Delete(1);
m_FontType->AppendString(font_face);
m_FontType->SetSelection(1);
m_pFontType->Delete(1);
m_pFontType->AppendString(font_face);
m_pFontType->SetSelection(1);
m_Font.SetFaceName(font_face);
m_Font.SetPointSize(font_size);
}
else
{
m_FontType->AppendString(font_face);
m_FontType->SetSelection(1);
m_pFontType->AppendString(font_face);
m_pFontType->SetSelection(1);
m_Font.SetFaceName(font_face);
m_Font.SetPointSize(font_size);
}
}
m_FontSize->SetValue(font_size);
m_pFontSize->SetValue(font_size);
SetCustomFont();
bAutoImport = serializer.DeserializeAutoImport().first;
m_bAutoImport = serializer.DeserializeAutoImport().first;
m_AutoImportCheck->SetValue(bAutoImport);
m_ImportDirLocation->SetValue(serializer.DeserializeAutoImport().second);
m_ShowFileExtensionCheck->SetValue(serializer.DeserializeShowFileExtension());
m_FollowSymLinksCheck->SetValue(serializer.DeserializeFollowSymLink());
m_RecursiveImportCheck->SetValue(serializer.DeserializeRecursiveImport());
m_pAutoImportCheck->SetValue(m_bAutoImport);
m_pImportDirLocation->SetValue(serializer.DeserializeAutoImport().second);
m_pShowFileExtensionCheck->SetValue(serializer.DeserializeShowFileExtension());
m_pFollowSymLinksCheck->SetValue(serializer.DeserializeFollowSymLink());
m_pRecursiveImportCheck->SetValue(serializer.DeserializeRecursiveImport());
if (bAutoImport)
if (m_bAutoImport)
{
m_ImportDirLocation->Enable();
m_BrowseAutoImportDirButton->Enable();
m_FollowSymLinksCheck->Enable();
m_RecursiveImportCheck->Enable();
m_pImportDirLocation->Enable();
m_pBrowseAutoImportDirButton->Enable();
m_pFollowSymLinksCheck->Enable();
m_pRecursiveImportCheck->Enable();
}
}
void Settings::SetShowExtension(bool value)
void cSettings::SetShowExtension(bool value)
{
Serializer serializer;
SampleHive::cSerializer serializer;
m_ShowFileExtensionCheck->SetValue(value);
m_pShowFileExtensionCheck->SetValue(value);
serializer.SerializeShowFileExtension(value);
}
void Settings::PrintFont()
void cSettings::PrintFont()
{
SH_LOG_DEBUG("Font face: {}", m_Font.GetFaceName());
SH_LOG_DEBUG("Font size: {}", m_Font.GetPointSize());
@ -443,9 +441,9 @@ void Settings::PrintFont()
SH_LOG_DEBUG("Font weight: {}", m_Font.GetWeightString());
}
void Settings::SetCustomFont()
void cSettings::SetCustomFont()
{
Serializer serializer;
SampleHive::cSerializer serializer;
wxFont sys_font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT);
std::string system_font = sys_font.GetFaceName().ToStdString();
@ -454,53 +452,56 @@ void Settings::SetCustomFont()
wxString font_face = serializer.DeserializeFontSettings().GetFaceName();
int font_size = serializer.DeserializeFontSettings().GetPointSize();
if (m_FontType->GetStringSelection() == "System default")
if (m_pFontType->GetStringSelection() == "System default")
{
m_Window->SetFont(sys_font);
m_pWindow->SetFont(sys_font);
this->SetFont(sys_font);
serializer.SerializeFontSettings(sys_font);
}
else
{
m_Window->SetFont(m_Font);
m_pWindow->SetFont(m_Font);
this->SetFont(m_Font);
serializer.SerializeFontSettings(m_Font);
}
}
wxString Settings::GetImportDirPath()
wxString cSettings::GetImportDirPath()
{
wxString dir = wxEmptyString;
if (m_AutoImportCheck->GetValue())
dir = m_ImportDirLocation->GetValue();
if (m_pAutoImportCheck->GetValue())
dir = m_pImportDirLocation->GetValue();
return dir;
}
void Settings::OnChangeWaveformColour(wxColourPickerEvent& event)
void cSettings::OnChangeWaveformColour(wxColourPickerEvent& event)
{
Serializer serializer;
wxColour colour = m_WaveformColourPickerCtrl->GetColour();
SampleHive::cSerializer serializer;
wxColour colour = m_pWaveformColourPickerCtrl->GetColour();
wxColour wave_colour = serializer.DeserializeWaveformColour();
if (colour != wave_colour)
{
SH_LOG_INFO("Waveform colour changed.");
bWaveformColourChanged = true;
m_bWaveformColourChanged = true;
serializer.SerializeWaveformColour(colour);
}
else
{
SH_LOG_INFO("Waveform colour not changed.");
bWaveformColourChanged = false;
m_bWaveformColourChanged = false;
serializer.SerializeWaveformColour(colour);
}
}
Settings::~Settings(){}
cSettings::~cSettings()
{
}

View File

@ -40,89 +40,11 @@
#include <wx/toplevel.h>
#include <wx/window.h>
class Settings : public wxDialog
class cSettings : public wxDialog
{
public:
Settings(wxWindow* window);
~Settings();
private:
// -------------------------------------------------------------------
wxWindow* m_Window;
private:
// -------------------------------------------------------------------
// Top panel for wxDialog
wxPanel* m_Panel;
// -------------------------------------------------------------------
// Notebook page panels
wxPanel* m_DisplaySettingPanel;
wxPanel* m_CollectionSettingPanel;
wxPanel* m_ConfigurationSettingPanel;
// -------------------------------------------------------------------
// Top panel sizers
wxBoxSizer* m_MainSizer;
wxBoxSizer* m_NotebookSizer;
wxBoxSizer* m_ButtonSizer;
// -------------------------------------------------------------------
// Notebook
wxNotebook* m_Notebook;
// -------------------------------------------------------------------
// Display page
wxBoxSizer* m_DisplayTopSizer;
wxBoxSizer* m_DisplayFontSizer;
wxStaticText* m_RowHeightText;
wxStaticText* m_FontTypeText;
wxChoice* m_RowHeight;
wxChoice* m_FontType;
wxButton* m_FontBrowseButton;
wxSpinCtrl* m_FontSize;
wxBoxSizer* m_WaveformColourSizer;
wxStaticText* m_WaveformColourLabel;
wxColourPickerCtrl* m_WaveformColourPickerCtrl;
// -------------------------------------------------------------------
// Collection page
wxBoxSizer* m_CollectionMainSizer;
wxBoxSizer* m_CollectionImportDirSizer;
wxBoxSizer* m_CollectionImportOptionsSizer;
wxBoxSizer* m_CollectionShowExtensionSizer;
wxCheckBox* m_AutoImportCheck;
wxCheckBox* m_FollowSymLinksCheck;
wxCheckBox* m_RecursiveImportCheck;
wxCheckBox* m_ShowFileExtensionCheck;
wxTextCtrl* m_ImportDirLocation;
wxButton* m_BrowseAutoImportDirButton;
// -------------------------------------------------------------------
// General configuration page
wxFlexGridSizer* m_GeneralMainSizer;
wxStaticText* m_ConfigLabel;
wxStaticText* m_DatabaseLabel;
wxTextCtrl* m_ConfigText;
wxTextCtrl* m_DatabaseText;
wxButton* m_ConfigBrowse;
wxButton* m_DatabaseBrowse;
// -------------------------------------------------------------------
// Common buttons for wxDialog
wxButton* m_OkButton;
wxButton* m_CancelButton;
private:
// -------------------------------------------------------------------
wxFont m_Font;
private:
// -------------------------------------------------------------------
bool bAutoImport = false;
// bool bFollowSymLinks = false;
// bool bShowExtension = true;
bool bWaveformColourChanged = false;
cSettings(wxWindow* window);
~cSettings();
private:
// -------------------------------------------------------------------
@ -150,13 +72,88 @@ class Settings : public wxDialog
wxString GetImportDirPath();
// inline wxFont GetFontType() { return m_Font; };
inline bool CanAutoImport() { return bAutoImport; };
// inline bool ShouldFollowSymLinks() { return bFollowSymLinks; };
// inline bool ShouldShowFileExtension() { return bShowExtension; };
inline bool IsWaveformColourChanged() { return bWaveformColourChanged; }
// inline wxColour GetWaveformColour() { return m_WaveformColourPickerCtrl->GetColour(); }
inline bool CanAutoImport() { return m_bAutoImport; };
inline bool IsWaveformColourChanged() { return m_bWaveformColourChanged; }
// -------------------------------------------------------------------
// Setters
void SetShowExtension(bool value);
private:
// -------------------------------------------------------------------
wxWindow* m_pWindow = nullptr;
private:
// -------------------------------------------------------------------
// Top panel for wxDialog
wxPanel* m_pPanel = nullptr;
// -------------------------------------------------------------------
// Notebook page panels
wxPanel* m_pDisplaySettingPanel = nullptr;
wxPanel* m_pCollectionSettingPanel = nullptr;
wxPanel* m_pConfigurationSettingPanel = nullptr;
// -------------------------------------------------------------------
// Top panel sizers
wxBoxSizer* m_pMainSizer = nullptr;
wxBoxSizer* m_pNotebookSizer = nullptr;
wxBoxSizer* m_pButtonSizer = nullptr;
// -------------------------------------------------------------------
// Notebook
wxNotebook* m_pNotebook = nullptr;
// -------------------------------------------------------------------
// Display page
wxBoxSizer* m_pDisplayTopSizer = nullptr;
wxBoxSizer* m_pDisplayFontSizer = nullptr;
wxStaticText* m_pRowHeightText = nullptr;
wxStaticText* m_pFontTypeText = nullptr;
wxChoice* m_pRowHeight = nullptr;
wxChoice* m_pFontType = nullptr;
wxButton* m_pFontBrowseButton = nullptr;
wxSpinCtrl* m_pFontSize = nullptr;
wxBoxSizer* m_pWaveformColourSizer = nullptr;
wxStaticText* m_pWaveformColourLabel = nullptr;
wxColourPickerCtrl* m_pWaveformColourPickerCtrl = nullptr;
// -------------------------------------------------------------------
// Collection page
wxBoxSizer* m_pCollectionMainSizer = nullptr;
wxBoxSizer* m_pCollectionImportDirSizer = nullptr;
wxBoxSizer* m_pCollectionImportOptionsSizer = nullptr;
wxBoxSizer* m_pCollectionShowExtensionSizer = nullptr;
wxCheckBox* m_pAutoImportCheck = nullptr;
wxCheckBox* m_pFollowSymLinksCheck = nullptr;
wxCheckBox* m_pRecursiveImportCheck = nullptr;
wxCheckBox* m_pShowFileExtensionCheck = nullptr;
wxTextCtrl* m_pImportDirLocation = nullptr;
wxButton* m_pBrowseAutoImportDirButton = nullptr;
// -------------------------------------------------------------------
// General configuration page
wxFlexGridSizer* m_pGeneralMainSizer = nullptr;
wxStaticText* m_pConfigLabel = nullptr;
wxStaticText* m_pDatabaseLabel = nullptr;
wxTextCtrl* m_pConfigText = nullptr;
wxTextCtrl* m_pDatabaseText = nullptr;
wxButton* m_pConfigBrowse = nullptr;
wxButton* m_pDatabaseBrowse = nullptr;
// -------------------------------------------------------------------
// Common buttons for wxDialog
wxButton* m_pOkButton = nullptr;
wxButton* m_pCancelButton = nullptr;
private:
// -------------------------------------------------------------------
wxFont m_Font;
private:
// -------------------------------------------------------------------
bool m_bAutoImport = false;
// bool bFollowSymLinks = false;
// bool bShowExtension = true;
bool m_bWaveformColourChanged = false;
};

View File

@ -18,13 +18,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "GUI/Dialogs/TagEditor.hpp"
#include "Database/Database.hpp"
#include "Utility/ControlIDs.hpp"
#include "Utility/SH_Event.hpp"
#include "Utility/Signal.hpp"
#include "Utility/Log.hpp"
#include "Utility/Paths.hpp"
#include "Database/Database.hpp"
#include "GUI/Dialogs/TagEditor.hpp"
#include "Utility/Event.hpp"
#include "Utility/Signal.hpp"
#include <wx/defs.h>
#include <wx/gdicmn.h>
@ -32,179 +32,179 @@
#include <wx/stringimpl.h>
#include <wx/textdlg.h>
TagEditor::TagEditor(wxWindow* window, const std::string& filename)
cTagEditor::cTagEditor(wxWindow* window, const std::string& filename)
: wxDialog(window, wxID_ANY, "Edit tags", wxDefaultPosition,
wxSize(640, 360), wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP),
m_Window(window), m_Filename(filename), tags(filename)
m_pWindow(window), m_Filename(filename), tags(filename)
{
m_Panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
m_pPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
m_MainSizer = new wxBoxSizer(wxVERTICAL);
m_ButtonSizer = new wxBoxSizer(wxHORIZONTAL);
m_EditTagSizer = new wxFlexGridSizer(6, 2, 0, 0);
m_EditTagSizer->AddGrowableCol(1);
m_EditTagSizer->SetFlexibleDirection(wxBOTH);
m_EditTagSizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
m_SampleTypeSizer = new wxFlexGridSizer(1, 3, 0, 0);
m_SampleTypeSizer->AddGrowableCol(1);
m_SampleTypeSizer->SetFlexibleDirection(wxBOTH);
m_SampleTypeSizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
m_StaticEditTagSizer = new wxStaticBoxSizer(wxVERTICAL, m_Panel, "Edit tags");
m_StaticSampleTypeSizer = new wxStaticBoxSizer(wxVERTICAL, m_Panel, "Sample type");
m_pMainSizer = new wxBoxSizer(wxVERTICAL);
m_pButtonSizer = new wxBoxSizer(wxHORIZONTAL);
m_pEditTagSizer = new wxFlexGridSizer(6, 2, 0, 0);
m_pEditTagSizer->AddGrowableCol(1);
m_pEditTagSizer->SetFlexibleDirection(wxBOTH);
m_pEditTagSizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
m_pSampleTypeSizer = new wxFlexGridSizer(1, 3, 0, 0);
m_pSampleTypeSizer->AddGrowableCol(1);
m_pSampleTypeSizer->SetFlexibleDirection(wxBOTH);
m_pSampleTypeSizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
m_pStaticEditTagSizer = new wxStaticBoxSizer(wxVERTICAL, m_pPanel, "Edit tags");
m_pStaticSampleTypeSizer = new wxStaticBoxSizer(wxVERTICAL, m_pPanel, "Sample type");
wxString choices[] = {"Kick", "Snare", "Clap", "HiHat", "Cymbal", "Cowbell", "Ride", "Tom", "Shaker", "Percussion"};
m_TitleCheck = new wxCheckBox(m_Panel, ET_TitleCheck, "Title", wxDefaultPosition, wxDefaultSize);
m_ArtistCheck = new wxCheckBox(m_Panel, ET_ArtistCheck, "Artist", wxDefaultPosition, wxDefaultSize);
m_AlbumCheck = new wxCheckBox(m_Panel, ET_AlbumCheck, "Album", wxDefaultPosition, wxDefaultSize);
m_GenreCheck = new wxCheckBox(m_Panel, ET_GenreCheck, "Genre", wxDefaultPosition, wxDefaultSize);
m_CommentCheck = new wxCheckBox(m_Panel, ET_CommentsCheck, "Comments", wxDefaultPosition, wxDefaultSize);
m_SampleTypeCheck = new wxCheckBox(m_Panel, ET_TypeCheck, "Type", wxDefaultPosition, wxDefaultSize);
m_pTitleCheck = new wxCheckBox(m_pPanel, SampleHive::ID::ET_TitleCheck, "Title", wxDefaultPosition, wxDefaultSize);
m_pArtistCheck = new wxCheckBox(m_pPanel, SampleHive::ID::ET_ArtistCheck, "Artist", wxDefaultPosition, wxDefaultSize);
m_pAlbumCheck = new wxCheckBox(m_pPanel, SampleHive::ID::ET_AlbumCheck, "Album", wxDefaultPosition, wxDefaultSize);
m_pGenreCheck = new wxCheckBox(m_pPanel, SampleHive::ID::ET_GenreCheck, "Genre", wxDefaultPosition, wxDefaultSize);
m_pCommentCheck = new wxCheckBox(m_pPanel, SampleHive::ID::ET_CommentsCheck, "Comments", wxDefaultPosition, wxDefaultSize);
m_pSampleTypeCheck = new wxCheckBox(m_pPanel, SampleHive::ID::ET_TypeCheck, "Type", wxDefaultPosition, wxDefaultSize);
m_TitleText = new wxTextCtrl(m_Panel, wxID_ANY, tags.GetAudioInfo().title, wxDefaultPosition, wxDefaultSize);
m_TitleText->Disable();
m_ArtistText = new wxTextCtrl(m_Panel, wxID_ANY, tags.GetAudioInfo().artist, wxDefaultPosition, wxDefaultSize);
m_ArtistText->Disable();
m_AlbumText = new wxTextCtrl(m_Panel, wxID_ANY, tags.GetAudioInfo().album, wxDefaultPosition, wxDefaultSize);
m_AlbumText->Disable();
m_GenreText = new wxTextCtrl(m_Panel, wxID_ANY, tags.GetAudioInfo().genre, wxDefaultPosition, wxDefaultSize);
m_GenreText->Disable();
m_CommentText = new wxTextCtrl(m_Panel, wxID_ANY, tags.GetAudioInfo().comment, wxDefaultPosition, wxDefaultSize);
m_CommentText->Disable();
m_SampleTypeChoice = new wxChoice(m_Panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 10, choices, wxCB_SORT);
m_SampleTypeChoice->Disable();
m_pTitleText = new wxTextCtrl(m_pPanel, wxID_ANY, tags.GetAudioInfo().title, wxDefaultPosition, wxDefaultSize);
m_pTitleText->Disable();
m_pArtistText = new wxTextCtrl(m_pPanel, wxID_ANY, tags.GetAudioInfo().artist, wxDefaultPosition, wxDefaultSize);
m_pArtistText->Disable();
m_pAlbumText = new wxTextCtrl(m_pPanel, wxID_ANY, tags.GetAudioInfo().album, wxDefaultPosition, wxDefaultSize);
m_pAlbumText->Disable();
m_pGenreText = new wxTextCtrl(m_pPanel, wxID_ANY, tags.GetAudioInfo().genre, wxDefaultPosition, wxDefaultSize);
m_pGenreText->Disable();
m_pCommentText = new wxTextCtrl(m_pPanel, wxID_ANY, tags.GetAudioInfo().comment, wxDefaultPosition, wxDefaultSize);
m_pCommentText->Disable();
m_pSampleTypeChoice = new wxChoice(m_pPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 10, choices, wxCB_SORT);
m_pSampleTypeChoice->Disable();
m_SampleTypeButton = new wxButton(m_Panel, ET_CustomTag, "Custom", wxDefaultPosition, wxDefaultSize);
m_SampleTypeButton->Disable();
m_pSampleTypeButton = new wxButton(m_pPanel, SampleHive::ID::ET_CustomTag, "Custom", wxDefaultPosition, wxDefaultSize);
m_pSampleTypeButton->Disable();
m_OkButton = new wxButton(m_Panel, wxID_OK, "OK", wxDefaultPosition, wxDefaultSize);
m_ApplyButton = new wxButton(m_Panel, wxID_APPLY, "Apply", wxDefaultPosition, wxDefaultSize);
m_CancelButton = new wxButton(m_Panel, wxID_CANCEL, "Cancel", wxDefaultPosition, wxDefaultSize);
m_pOkButton = new wxButton(m_pPanel, wxID_OK, "OK", wxDefaultPosition, wxDefaultSize);
m_pApplyButton = new wxButton(m_pPanel, wxID_APPLY, "Apply", wxDefaultPosition, wxDefaultSize);
m_pCancelButton = new wxButton(m_pPanel, wxID_CANCEL, "Cancel", wxDefaultPosition, wxDefaultSize);
// Binding events
Bind(wxEVT_CHECKBOX, &TagEditor::OnCheckTitle, this, ET_TitleCheck);
Bind(wxEVT_CHECKBOX, &TagEditor::OnCheckArtist, this, ET_ArtistCheck);
Bind(wxEVT_CHECKBOX, &TagEditor::OnCheckAlbum, this, ET_AlbumCheck);
Bind(wxEVT_CHECKBOX, &TagEditor::OnCheckGenre, this, ET_GenreCheck);
Bind(wxEVT_CHECKBOX, &TagEditor::OnCheckComments, this, ET_CommentsCheck);
Bind(wxEVT_CHECKBOX, &TagEditor::OnCheckType, this, ET_TypeCheck);
Bind(wxEVT_CHECKBOX, &cTagEditor::OnCheckTitle, this, SampleHive::ID::ET_TitleCheck);
Bind(wxEVT_CHECKBOX, &cTagEditor::OnCheckArtist, this, SampleHive::ID::ET_ArtistCheck);
Bind(wxEVT_CHECKBOX, &cTagEditor::OnCheckAlbum, this, SampleHive::ID::ET_AlbumCheck);
Bind(wxEVT_CHECKBOX, &cTagEditor::OnCheckGenre, this, SampleHive::ID::ET_GenreCheck);
Bind(wxEVT_CHECKBOX, &cTagEditor::OnCheckComments, this, SampleHive::ID::ET_CommentsCheck);
Bind(wxEVT_CHECKBOX, &cTagEditor::OnCheckType, this, SampleHive::ID::ET_TypeCheck);
Bind(wxEVT_BUTTON, &TagEditor::OnClickCustomTagButton, this, ET_CustomTag);
Bind(wxEVT_BUTTON, &cTagEditor::OnClickCustomTagButton, this, SampleHive::ID::ET_CustomTag);
Bind(wxEVT_BUTTON, &TagEditor::OnClickApply, this, wxID_APPLY);
Bind(wxEVT_BUTTON, &cTagEditor::OnClickApply, this, wxID_APPLY);
m_EditTagSizer->Add(m_TitleCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2);
m_EditTagSizer->Add(m_TitleText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2);
m_pEditTagSizer->Add(m_pTitleCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2);
m_pEditTagSizer->Add(m_pTitleText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2);
m_EditTagSizer->Add(m_ArtistCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2);
m_EditTagSizer->Add(m_ArtistText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2);
m_pEditTagSizer->Add(m_pArtistCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2);
m_pEditTagSizer->Add(m_pArtistText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2);
m_EditTagSizer->Add(m_AlbumCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2);
m_EditTagSizer->Add(m_AlbumText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2);
m_pEditTagSizer->Add(m_pAlbumCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2);
m_pEditTagSizer->Add(m_pAlbumText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2);
m_EditTagSizer->Add(m_GenreCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2);
m_EditTagSizer->Add(m_GenreText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2);
m_pEditTagSizer->Add(m_pGenreCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2);
m_pEditTagSizer->Add(m_pGenreText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2);
m_EditTagSizer->Add(m_CommentCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2);
m_EditTagSizer->Add(m_CommentText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2);
m_pEditTagSizer->Add(m_pCommentCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2);
m_pEditTagSizer->Add(m_pCommentText, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2);
m_SampleTypeSizer->Add(m_SampleTypeCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2);
m_SampleTypeSizer->Add(m_SampleTypeChoice, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2);
m_SampleTypeSizer->Add(m_SampleTypeButton, 0, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 2);
m_pSampleTypeSizer->Add(m_pSampleTypeCheck, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 2);
m_pSampleTypeSizer->Add(m_pSampleTypeChoice, 1, wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2);
m_pSampleTypeSizer->Add(m_pSampleTypeButton, 0, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 2);
m_StaticEditTagSizer->Add(m_EditTagSizer, 1, wxALL | wxEXPAND, 2);
m_StaticSampleTypeSizer->Add(m_SampleTypeSizer, 1, wxALL | wxEXPAND, 2);
m_pStaticEditTagSizer->Add(m_pEditTagSizer, 1, wxALL | wxEXPAND, 2);
m_pStaticSampleTypeSizer->Add(m_pSampleTypeSizer, 1, wxALL | wxEXPAND, 2);
m_ButtonSizer->Add(m_OkButton, 0, wxALL | wxALIGN_BOTTOM, 2);
m_ButtonSizer->Add(m_ApplyButton, 0, wxALL | wxALIGN_BOTTOM, 2);
m_ButtonSizer->Add(m_CancelButton, 0, wxALL | wxALIGN_BOTTOM, 2);
m_pButtonSizer->Add(m_pOkButton, 0, wxALL | wxALIGN_BOTTOM, 2);
m_pButtonSizer->Add(m_pApplyButton, 0, wxALL | wxALIGN_BOTTOM, 2);
m_pButtonSizer->Add(m_pCancelButton, 0, wxALL | wxALIGN_BOTTOM, 2);
m_MainSizer->Add(m_StaticEditTagSizer, 1, wxALL | wxEXPAND, 2);
m_MainSizer->Add(m_StaticSampleTypeSizer, 1, wxALL | wxEXPAND, 2);
m_MainSizer->Add(m_ButtonSizer, 0, wxALL | wxALIGN_RIGHT, 2);
m_pMainSizer->Add(m_pStaticEditTagSizer, 1, wxALL | wxEXPAND, 2);
m_pMainSizer->Add(m_pStaticSampleTypeSizer, 1, wxALL | wxEXPAND, 2);
m_pMainSizer->Add(m_pButtonSizer, 0, wxALL | wxALIGN_RIGHT, 2);
// Top panel layout
m_Panel->SetSizer(m_MainSizer);
m_MainSizer->Fit(m_Panel);
m_MainSizer->SetSizeHints(m_Panel);
m_MainSizer->Layout();
m_pPanel->SetSizer(m_pMainSizer);
m_pMainSizer->Fit(m_pPanel);
m_pMainSizer->SetSizeHints(m_pPanel);
m_pMainSizer->Layout();
}
void TagEditor::OnCheckTitle(wxCommandEvent &event)
void cTagEditor::OnCheckTitle(wxCommandEvent &event)
{
if (m_TitleCheck->GetValue())
if (m_pTitleCheck->GetValue())
{
m_TitleText->Enable();
m_pTitleText->Enable();
}
else
{
m_TitleText->Disable();
m_pTitleText->Disable();
}
}
void TagEditor::OnCheckArtist(wxCommandEvent &event)
void cTagEditor::OnCheckArtist(wxCommandEvent &event)
{
if (m_ArtistCheck->GetValue())
if (m_pArtistCheck->GetValue())
{
m_ArtistText->Enable();
m_pArtistText->Enable();
}
else
{
m_ArtistText->Disable();
m_pArtistText->Disable();
}
}
void TagEditor::OnCheckAlbum(wxCommandEvent &event)
void cTagEditor::OnCheckAlbum(wxCommandEvent &event)
{
if (m_AlbumCheck->GetValue())
if (m_pAlbumCheck->GetValue())
{
m_AlbumText->Enable();
m_pAlbumText->Enable();
}
else
{
m_AlbumText->Disable();
m_pAlbumText->Disable();
}
}
void TagEditor::OnCheckGenre(wxCommandEvent &event)
void cTagEditor::OnCheckGenre(wxCommandEvent &event)
{
if (m_GenreCheck->GetValue())
if (m_pGenreCheck->GetValue())
{
m_GenreText->Enable();
m_pGenreText->Enable();
}
else
{
m_GenreText->Disable();
m_pGenreText->Disable();
}
}
void TagEditor::OnCheckComments(wxCommandEvent &event)
void cTagEditor::OnCheckComments(wxCommandEvent &event)
{
if (m_CommentCheck->GetValue())
if (m_pCommentCheck->GetValue())
{
m_CommentText->Enable();
m_pCommentText->Enable();
}
else
{
m_CommentText->Disable();
m_pCommentText->Disable();
}
}
void TagEditor::OnCheckType(wxCommandEvent &event)
void cTagEditor::OnCheckType(wxCommandEvent &event)
{
if (m_SampleTypeCheck->GetValue())
if (m_pSampleTypeCheck->GetValue())
{
m_SampleTypeChoice->Enable();
m_SampleTypeButton->Enable();
m_pSampleTypeChoice->Enable();
m_pSampleTypeButton->Enable();
}
else
{
m_SampleTypeChoice->Disable();
m_SampleTypeButton->Disable();
m_pSampleTypeChoice->Disable();
m_pSampleTypeButton->Disable();
}
}
void TagEditor::OnClickCustomTagButton(wxCommandEvent& event)
void cTagEditor::OnClickCustomTagButton(wxCommandEvent& event)
{
wxTextEntryDialog* customTag;
customTag = new wxTextEntryDialog(this, "Enter a custom tag",
@ -216,8 +216,8 @@ void TagEditor::OnClickCustomTagButton(wxCommandEvent& event)
case wxID_OK:
{
wxString tag = customTag->GetValue();
m_SampleTypeChoice->AppendString(tag);
m_SampleTypeChoice->SetStringSelection(tag);
m_pSampleTypeChoice->AppendString(tag);
m_pSampleTypeChoice->SetStringSelection(tag);
break;
}
case wxID_CANCEL:
@ -227,16 +227,16 @@ void TagEditor::OnClickCustomTagButton(wxCommandEvent& event)
}
}
void TagEditor::OnClickApply(wxCommandEvent& event)
void cTagEditor::OnClickApply(wxCommandEvent& event)
{
Database db;
cDatabase db;
wxString title = m_TitleText->GetValue();
wxString artist = m_ArtistText->GetValue();
wxString album = m_AlbumText->GetValue();
wxString genre = m_GenreText->GetValue();
wxString comment = m_CommentText->GetValue();
wxString type = m_SampleTypeChoice->GetStringSelection();
wxString title = m_pTitleText->GetValue();
wxString artist = m_pArtistText->GetValue();
wxString album = m_pAlbumText->GetValue();
wxString genre = m_pGenreText->GetValue();
wxString comment = m_pCommentText->GetValue();
wxString type = m_pSampleTypeChoice->GetStringSelection();
std::string sampleType = db.GetSampleType(m_Filename);
@ -255,7 +255,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event)
switch (msgDialog->ShowModal())
{
case wxID_YES:
if (m_TitleCheck->GetValue() && m_TitleText->GetValue() != tags.GetAudioInfo().title)
if (m_pTitleCheck->GetValue() && m_pTitleText->GetValue() != tags.GetAudioInfo().title)
{
SH_LOG_INFO("Changing title tag..");
tags.SetTitle(title.ToStdString());
@ -263,7 +263,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event)
info_msg = wxString::Format("Successfully changed title tag to %s", title);
}
if (m_ArtistCheck->GetValue() && m_ArtistText->GetValue() != tags.GetAudioInfo().artist)
if (m_pArtistCheck->GetValue() && m_pArtistText->GetValue() != tags.GetAudioInfo().artist)
{
SH_LOG_INFO("Changing artist tag..");
tags.SetArtist(artist.ToStdString());
@ -275,7 +275,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event)
info_msg = wxString::Format("Successfully changed artist tag to %s", artist);
}
if (m_AlbumCheck->GetValue() && m_AlbumText->GetValue() != tags.GetAudioInfo().album)
if (m_pAlbumCheck->GetValue() && m_pAlbumText->GetValue() != tags.GetAudioInfo().album)
{
SH_LOG_INFO("Changing album tag..");
tags.SetAlbum(album.ToStdString());
@ -283,7 +283,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event)
info_msg = wxString::Format("Successfully changed album tag to %s", album);
}
if (m_GenreCheck->GetValue() && m_GenreText->GetValue() != tags.GetAudioInfo().genre)
if (m_pGenreCheck->GetValue() && m_pGenreText->GetValue() != tags.GetAudioInfo().genre)
{
SH_LOG_INFO("Changing genre tag..");
tags.SetGenre(genre.ToStdString());
@ -291,7 +291,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event)
info_msg = wxString::Format("Successfully changed genre tag to %s", genre);
}
if (m_CommentCheck->GetValue() && m_CommentText->GetValue() != tags.GetAudioInfo().comment)
if (m_pCommentCheck->GetValue() && m_pCommentText->GetValue() != tags.GetAudioInfo().comment)
{
SH_LOG_INFO("Changing comment tag..");
tags.SetComment(comment.ToStdString());
@ -299,7 +299,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event)
info_msg = wxString::Format("Successfully changed comment tag to %s", comment);
}
if (m_SampleTypeCheck->GetValue() && m_SampleTypeChoice->GetStringSelection() != sampleType)
if (m_pSampleTypeCheck->GetValue() && m_pSampleTypeChoice->GetStringSelection() != sampleType)
{
SH_LOG_INFO("Changing type tag..");
db.UpdateSampleType(filename, type.ToStdString());
@ -313,10 +313,10 @@ void TagEditor::OnClickApply(wxCommandEvent& event)
info_msg = "Error, cannot change tag!";
}
SampleHive::Signal::SendInfoBarMessage(info_msg, wxICON_INFORMATION, *this, true);
SampleHive::cSignal::SendInfoBarMessage(info_msg, wxICON_INFORMATION, *this, true);
}
// void TagEditor::SendInfoBarMessage(const wxString& msg, int mode)
// void cTagEditor::SendInfoBarMessage(const wxString& msg, int mode)
// {
// SH_LOG_INFO("{} called..", __FUNCTION__);
@ -328,7 +328,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event)
// GetParent()->GetEventHandler()->ProcessEvent(event);
// }
TagEditor::~TagEditor()
cTagEditor::~cTagEditor()
{
}

View File

@ -36,58 +36,11 @@
#include <wx/toplevel.h>
#include <wx/window.h>
class TagEditor : public wxDialog
class cTagEditor : public wxDialog
{
public:
TagEditor(wxWindow* window, const std::string& filename);
~TagEditor();
private:
// -------------------------------------------------------------------
wxWindow* m_Window;
// -------------------------------------------------------------------
const std::string m_Filename;
private:
// -------------------------------------------------------------------
// Top panel for wxDialog
wxPanel* m_Panel;
// -------------------------------------------------------------------
// Top panel sizers
wxBoxSizer* m_MainSizer;
wxFlexGridSizer* m_EditTagSizer;
wxFlexGridSizer* m_SampleTypeSizer;
wxBoxSizer* m_ButtonSizer;
wxStaticBoxSizer* m_StaticEditTagSizer;
wxStaticBoxSizer* m_StaticSampleTypeSizer;
// -------------------------------------------------------------------
// Dialog controls
wxCheckBox* m_TitleCheck;
wxCheckBox* m_ArtistCheck;
wxCheckBox* m_AlbumCheck;
wxCheckBox* m_GenreCheck;
wxCheckBox* m_CommentCheck;
wxCheckBox* m_SampleTypeCheck;
wxTextCtrl* m_TitleText;
wxTextCtrl* m_ArtistText;
wxTextCtrl* m_AlbumText;
wxTextCtrl* m_GenreText;
wxTextCtrl* m_CommentText;
wxChoice* m_SampleTypeChoice;
wxButton* m_SampleTypeButton;
// -------------------------------------------------------------------
// Common buttons for wxDialog
wxButton* m_OkButton;
wxButton* m_ApplyButton;
wxButton* m_CancelButton;
private:
// -------------------------------------------------------------------
Tags tags;
cTagEditor(wxWindow* window, const std::string& filename);
~cTagEditor();
private:
// -------------------------------------------------------------------
@ -105,6 +58,50 @@ class TagEditor : public wxDialog
// -------------------------------------------------------------------
void OnClickApply(wxCommandEvent& event);
private:
// -------------------------------------------------------------------
// void SendInfoBarMessage(const wxString& msg, int mode);
wxWindow* m_pWindow = nullptr;
// -------------------------------------------------------------------
const std::string& m_Filename;
private:
// -------------------------------------------------------------------
// Top panel for wxDialog
wxPanel* m_pPanel = nullptr;
// -------------------------------------------------------------------
// Top panel sizers
wxBoxSizer* m_pMainSizer = nullptr;
wxFlexGridSizer* m_pEditTagSizer = nullptr;
wxFlexGridSizer* m_pSampleTypeSizer = nullptr;
wxBoxSizer* m_pButtonSizer = nullptr;
wxStaticBoxSizer* m_pStaticEditTagSizer = nullptr;
wxStaticBoxSizer* m_pStaticSampleTypeSizer = nullptr;
// -------------------------------------------------------------------
// Dialog controls
wxCheckBox* m_pTitleCheck = nullptr;
wxCheckBox* m_pArtistCheck = nullptr;
wxCheckBox* m_pAlbumCheck = nullptr;
wxCheckBox* m_pGenreCheck = nullptr;
wxCheckBox* m_pCommentCheck = nullptr;
wxCheckBox* m_pSampleTypeCheck = nullptr;
wxTextCtrl* m_pTitleText = nullptr;
wxTextCtrl* m_pArtistText = nullptr;
wxTextCtrl* m_pAlbumText = nullptr;
wxTextCtrl* m_pGenreText = nullptr;
wxTextCtrl* m_pCommentText = nullptr;
wxChoice* m_pSampleTypeChoice = nullptr;
wxButton* m_pSampleTypeButton = nullptr;
// -------------------------------------------------------------------
// Common buttons for wxDialog
wxButton* m_pOkButton = nullptr;
wxButton* m_pApplyButton = nullptr;
wxButton* m_pCancelButton = nullptr;
private:
// -------------------------------------------------------------------
SampleHive::cTags tags;
};

View File

@ -1,20 +1,42 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "GUI/DirectoryBrowser.hpp"
#include "Utility/Paths.hpp"
#include "Utility/ControlIDs.hpp"
#include "Utility/Log.hpp"
#include "Utility/Paths.hpp"
#include "Utility/Utils.hpp"
#include <wx/dataobj.h>
#include <wx/dnd.h>
cDirectoryBrowser::cDirectoryBrowser(wxWindow* window)
: wxGenericDirCtrl(window, BC_DirCtrl, wxDirDialogDefaultFolderStr, wxDefaultPosition,
: wxGenericDirCtrl(window, SampleHive::ID::BC_DirCtrl, wxDirDialogDefaultFolderStr, wxDefaultPosition,
wxDefaultSize, wxDIRCTRL_SHOW_FILTERS,
_("All files|*|Ogg files (*.ogg)|*.ogg|Wav files (*.wav)|*.wav|"
"Flac files (*.flac)|*.flac"), 0)
"Flac files (*.flac)|*.flac"), 0),
m_pWindow(window)
{
SetPath(USER_HOME_DIR);
Bind(wxEVT_DIRCTRL_FILEACTIVATED, &cDirectoryBrowser::OnClickDirCtrl, this, BC_DirCtrl);
Bind(wxEVT_DIRCTRL_FILEACTIVATED, &cDirectoryBrowser::OnClickDirCtrl, this, SampleHive::ID::BC_DirCtrl);
Bind(wxEVT_TREE_BEGIN_DRAG, &cDirectoryBrowser::OnDragFromDirCtrl, this, this->GetTreeCtrl()->GetId());
}
@ -23,8 +45,24 @@ void cDirectoryBrowser::OnClickDirCtrl(wxCommandEvent& event)
wxArrayString path;
path.push_back(this->GetFilePath());
// TODO
// AddSamples(path);
SampleHive::cUtils::Get().AddSamples(path, m_pWindow);
}
// Temporary function to check drag and drop result
void LogDragResult(wxDragResult result)
{
wxString msg;
switch (result)
{
case wxDragError: msg = "Error!"; break;
case wxDragNone: msg = "Nothing"; break;
case wxDragCopy: msg = "Copied"; break;
case wxDragMove: msg = "Moved"; break;
case wxDragCancel: msg = "Cancelled"; break;
default: msg = "Huh?"; break;
}
SH_LOG_DEBUG("Drag result: {}", msg);
}
void cDirectoryBrowser::OnDragFromDirCtrl(wxTreeEvent& event)
@ -35,7 +73,7 @@ void cDirectoryBrowser::OnDragFromDirCtrl(wxTreeEvent& event)
wxDropSource drop_source(this);
drop_source.SetData(file_data);
// LogDragResult(drop_source.DoDragDrop());
LogDragResult(drop_source.DoDragDrop());
}
cDirectoryBrowser::~cDirectoryBrowser()

View File

@ -1,3 +1,23 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <wx/control.h>
@ -15,4 +35,7 @@ class cDirectoryBrowser : public wxGenericDirCtrl
// DirCtrl event handlers
void OnClickDirCtrl(wxCommandEvent& event);
void OnDragFromDirCtrl(wxTreeEvent& event);
private:
wxWindow* m_pWindow = nullptr;
};

View File

@ -1,11 +1,31 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "GUI/Hives.hpp"
#include "GUI/ListCtrl.hpp"
#include "Database/Database.hpp"
#include "Utility/ControlIDs.hpp"
#include "Utility/HiveData.hpp"
#include "Utility/Log.hpp"
#include "Utility/Paths.hpp"
#include "Utility/Signal.hpp"
#include "Utility/Serialize.hpp"
#include "Utility/Log.hpp"
#include <deque>
@ -13,27 +33,26 @@
#include <wx/menu.h>
#include <wx/msgdlg.h>
cHivesPanel::cHivesPanel(wxWindow* window, wxDataViewListCtrl& listCtrl)
cHivesPanel::cHivesPanel(wxWindow* window)
: wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
m_ListCtrl(listCtrl), m_pWindow(window)
m_pWindow(window)
{
m_pMainSizer = new wxBoxSizer(wxVERTICAL);
m_pHivesSizer = new wxBoxSizer(wxVERTICAL);
m_pButtonSizer = new wxBoxSizer(wxHORIZONTAL);
m_pAddHiveButton = new wxButton(this, BC_HiveAdd, "+", wxDefaultPosition, wxDefaultSize, 0);
m_pAddHiveButton = new wxButton(this, SampleHive::ID::BC_HiveAdd, "+", wxDefaultPosition, wxDefaultSize, 0);
m_pAddHiveButton->SetToolTip(_("Create new hive"));
m_pButtonSizer->Add(m_pAddHiveButton, wxSizerFlags(1).Expand());
m_pRemoveHiveButton = new wxButton(this, BC_HiveRemove, "-", wxDefaultPosition, wxDefaultSize, 0);
m_pRemoveHiveButton = new wxButton(this, SampleHive::ID::BC_HiveRemove, "-", wxDefaultPosition, wxDefaultSize, 0);
m_pRemoveHiveButton->SetToolTip(_("Delete selected hive"));
m_pButtonSizer->Add(m_pRemoveHiveButton, wxSizerFlags(1).Expand());
// Initializing wxDataViewTreeCtrl as another page of wxNotebook
m_pHives = new wxDataViewTreeCtrl(this, BC_Hives, wxDefaultPosition, wxDefaultSize,
wxDV_NO_HEADER | wxDV_SINGLE);
m_pHives = new wxDataViewTreeCtrl(this, SampleHive::ID::BC_Hives, wxDefaultPosition, wxDefaultSize, wxDV_NO_HEADER | wxDV_SINGLE);
m_pHivesSizer->Add(m_pHives, wxSizerFlags(1).Expand());
@ -44,10 +63,10 @@ cHivesPanel::cHivesPanel(wxWindow* window, wxDataViewListCtrl& listCtrl)
m_pHives->DragAcceptFiles(true);
m_pHives->Connect(wxEVT_DROP_FILES, wxDropFilesEventHandler(cHivesPanel::OnDragAndDropToHives), NULL, this);
Bind(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &cHivesPanel::OnShowHivesContextMenu, this, BC_Hives);
Bind(wxEVT_DATAVIEW_ITEM_START_EDITING, &cHivesPanel::OnHiveStartEditing, this, BC_Hives);
Bind(wxEVT_BUTTON, &cHivesPanel::OnClickAddHive, this, BC_HiveAdd);
Bind(wxEVT_BUTTON, &cHivesPanel::OnClickRemoveHive, this, BC_HiveRemove);
Bind(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &cHivesPanel::OnShowHivesContextMenu, this, SampleHive::ID::BC_Hives);
Bind(wxEVT_DATAVIEW_ITEM_START_EDITING, &cHivesPanel::OnHiveStartEditing, this, SampleHive::ID::BC_Hives);
Bind(wxEVT_BUTTON, &cHivesPanel::OnClickAddHive, this, SampleHive::ID::BC_HiveAdd);
Bind(wxEVT_BUTTON, &cHivesPanel::OnClickRemoveHive, this, SampleHive::ID::BC_HiveRemove);
m_pMainSizer->Add(m_pHivesSizer, wxSizerFlags(1).Expand());
m_pMainSizer->Add(m_pButtonSizer, wxSizerFlags(0).Expand());
@ -61,9 +80,8 @@ cHivesPanel::cHivesPanel(wxWindow* window, wxDataViewListCtrl& listCtrl)
void cHivesPanel::OnDragAndDropToHives(wxDropFilesEvent& event)
{
Serializer serializer;
Database db;
// cListCtrl m_ListCtrl.m_pWindow);
SampleHive::cSerializer serializer;
cDatabase db;
if (event.GetNumberOfFiles() > 0)
{
@ -71,8 +89,7 @@ void cHivesPanel::OnDragAndDropToHives(wxDropFilesEvent& event)
wxArrayString files;
wxDataViewItemArray items;
int rows = m_ListCtrl.GetSelections(items);
// int rows = 2;
int rows = SampleHive::cHiveData::Get().GetListCtrlSelections(items);
wxDataViewItem drop_target;;
wxDataViewColumn* column;
@ -86,9 +103,9 @@ void cHivesPanel::OnDragAndDropToHives(wxDropFilesEvent& event)
for (int i = 0; i < rows; i++)
{
int row = m_ListCtrl.ItemToRow(items[i]);
int row = SampleHive::cHiveData::Get().GetListCtrlRowFromItem(items, i);
wxString name = m_ListCtrl.GetTextValue(row, 1);
wxString name = SampleHive::cHiveData::Get().GetListCtrlTextValue(row, 1);
file_data.AddFile(name);
@ -104,7 +121,7 @@ void cHivesPanel::OnDragAndDropToHives(wxDropFilesEvent& event)
{
m_pHives->AppendItem(drop_target, files[i]);
m_ListCtrl.SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), row, 0);
SampleHive::cHiveData::Get().ListCtrlSetVariant(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), row, 0);
db.UpdateFavoriteColumn(file_name.ToStdString(), 1);
db.UpdateHiveName(file_name.ToStdString(), hive_name.ToStdString());
@ -132,17 +149,15 @@ void cHivesPanel::OnDragAndDropToHives(wxDropFilesEvent& event)
}
if (!msg.IsEmpty())
SampleHive::Signal::SendInfoBarMessage(msg, wxICON_ERROR, *this);
// m_InfoBar->ShowMessage(msg, wxICON_ERROR);
SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_ERROR, *this);
}
}
}
void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event)
{
Serializer serializer;
Database db;
// cListCtrl m_ListCtrl.m_pWindow);
SampleHive::cSerializer serializer;
cDatabase db;
wxDataViewItem selected_hive = event.GetItem();
@ -153,27 +168,26 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event)
if (m_pHives->IsContainer(selected_hive))
{
// Container menu items
menu.Append(MN_RenameHive, _("Rename hive"), _("Rename selected hive"));
menu.Append(MN_DeleteHive, _("Delete hive"), _("Delete selected hive"));
menu.Append(SampleHive::ID::MN_RenameHive, _("Rename hive"), _("Rename selected hive"));
menu.Append(SampleHive::ID::MN_DeleteHive, _("Delete hive"), _("Delete selected hive"));
if (!m_bFiltered)
menu.Append(MN_FilterLibrary, _("Filter library"),
_("Show only samples from current hive in library"));
menu.Append(SampleHive::ID::MN_FilterLibrary, _("Filter library"), _("Show only samples from current hive in library"));
else
menu.Append(MN_FilterLibrary, _("Clear filter"), _("Clear the filter"));
menu.Append(SampleHive::ID::MN_FilterLibrary, _("Clear filter"), _("Clear the filter"));
}
else
{
// Child menu items
menu.Append(MN_RemoveSample, _("Remove sample"), _("Remove the selected sample(s)"));
menu.Append(MN_ShowInLibrary, _("Show sample in library"), _("Show the selected in library"));
menu.Append(SampleHive::ID::MN_RemoveSample, _("Remove sample"), _("Remove the selected sample(s)"));
menu.Append(SampleHive::ID::MN_ShowInLibrary, _("Show sample in library"), _("Show the selected in library"));
}
if (selected_hive.IsOk() && m_pHives->IsContainer(selected_hive))
{
switch (m_pHives->GetPopupMenuSelectionFromUser(menu, event.GetPosition()))
{
case MN_RenameHive:
case SampleHive::ID::MN_RenameHive:
{
std::deque<wxDataViewItem> nodes;
nodes.push_back(m_pHives->GetNthChild(wxDataViewItem(wxNullPtr), 0));
@ -224,8 +238,7 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event)
if (found_item.IsOk())
{
wxMessageBox(wxString::Format(_("Another hive by the name %s already exist. "
"Please try with a different name."),
hive_name),
"Please try with a different name."), hive_name),
_("Error!"), wxOK | wxCENTRE, this);
}
else
@ -237,8 +250,7 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event)
if (sample_count <= 0)
{
m_pHives->SetItemText(selected_hive, hive_name);
db.UpdateHive(selected_hive_name.ToStdString(),
hive_name.ToStdString());
db.UpdateHive(selected_hive_name.ToStdString(), hive_name.ToStdString());
}
else
{
@ -250,10 +262,8 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event)
m_pHives->GetItemText(sample_item).BeforeLast('.') :
m_pHives->GetItemText(sample_item);
db.UpdateHiveName(sample_name.ToStdString(),
hive_name.ToStdString());
db.UpdateHive(selected_hive_name.ToStdString(),
hive_name.ToStdString());
db.UpdateHiveName(sample_name.ToStdString(), hive_name.ToStdString());
db.UpdateHive(selected_hive_name.ToStdString(), hive_name.ToStdString());
m_pHives->SetItemText(selected_hive, hive_name);
}
@ -270,28 +280,22 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event)
}
if (!msg.IsEmpty())
SampleHive::Signal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this);
// m_InfoBar->ShowMessage(msg, wxICON_INFORMATION);
SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this);
}
break;
case MN_DeleteHive:
case SampleHive::ID::MN_DeleteHive:
{
wxString msg;
wxMessageDialog deleteEmptyHiveDialog(this, wxString::Format(_("Are you sure you want to "
"delete %s from chives?"),
wxMessageDialog deleteEmptyHiveDialog(this, wxString::Format(_("Are you sure you want to delete %s from hives?"),
hive_name),
wxMessageBoxCaptionStr,
wxYES_NO | wxNO_DEFAULT |
wxICON_QUESTION | wxSTAY_ON_TOP);
wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION | wxSTAY_ON_TOP);
wxMessageDialog deleteFilledHiveDialog(this, wxString::Format(_("Are you sure you want to "
"delete %s and all samples "
"inside %s from chives?"),
hive_name, hive_name),
wxMessageDialog deleteFilledHiveDialog(this, wxString::Format(_("Are you sure you want to delete %s and all samples "
"inside %s from hives?"), hive_name, hive_name),
wxMessageBoxCaptionStr,
wxYES_NO | wxNO_DEFAULT |
wxICON_QUESTION | wxSTAY_ON_TOP);
wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION | wxSTAY_ON_TOP);
if (hive_name == m_pHives->GetItemText(m_FavoritesHive))
{
@ -307,8 +311,7 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event)
}
else if (selected_hive.IsOk() && !m_pHives->IsContainer(selected_hive))
{
wxMessageBox(wxString::Format(_("Error! %s is not a hive, cannot delete from chives."),
hive_name),
wxMessageBox(wxString::Format(_("Error! %s is not a hive, cannot delete from hives."), hive_name),
_("Error!"), wxOK | wxCENTRE, this);
return;
}
@ -325,7 +328,7 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event)
db.RemoveHiveFromDatabase(hive_name.ToStdString());
msg = wxString::Format(_("%s deleted from chives successfully."), hive_name);
msg = wxString::Format(_("%s deleted from hives successfully."), hive_name);
}
break;
case wxID_NO:
@ -344,13 +347,11 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event)
{
wxDataViewItem child_item;
for (int i = 0; i < m_ListCtrl.GetItemCount(); i++)
// for (int i = 0; i < 1; i++)
for (int i = 0; i < SampleHive::cHiveData::Get().GetListCtrlItemCount(); i++)
{
wxString matched_sample =
serializer.DeserializeShowFileExtension() ?
m_ListCtrl.GetTextValue(i, 1).BeforeLast('.') :
m_ListCtrl.GetTextValue(i, 1);
wxString matched_sample = serializer.DeserializeShowFileExtension() ?
SampleHive::cHiveData::Get().GetListCtrlTextValue(i, 1).BeforeLast('.') :
SampleHive::cHiveData::Get().GetListCtrlTextValue(i, 1);
for (int j = 0; j < m_pHives->GetChildCount(selected_hive); j++)
{
@ -362,11 +363,11 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event)
m_pHives->GetItemText(child_item);
if (child_name == matched_sample)
// if (child_name == "")
{
SH_LOG_DEBUG("Found match");
m_ListCtrl.SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0);
SampleHive::cHiveData::Get().ListCtrlSetVariant(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)),
i, 0);
db.UpdateFavoriteColumn(matched_sample.ToStdString(), 0);
db.UpdateHiveName(matched_sample.ToStdString(),
@ -384,8 +385,7 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event)
db.RemoveHiveFromDatabase(hive_name.ToStdString());
msg = wxString::Format(_("%s and all samples inside %s "
"have been deleted from chives successfully."),
msg = wxString::Format(_("%s and all samples inside %s have been deleted from hives successfully."),
hive_name, hive_name);
}
break;
@ -397,11 +397,10 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event)
}
if (!msg.IsEmpty())
SampleHive::Signal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this);
// m_InfoBar->ShowMessage(msg, wxICON_INFORMATION);
SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this);
}
break;
case MN_FilterLibrary:
case SampleHive::ID::MN_FilterLibrary:
{
if (!m_bFiltered)
{
@ -420,18 +419,18 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event)
}
else
{
m_ListCtrl.DeleteAllItems();
SampleHive::cHiveData::Get().ListCtrlDeleteAllItems();
for (auto data : dataset)
{
m_ListCtrl.AppendItem(data);
SampleHive::cHiveData::Get().ListCtrlAppendItem(data);
}
}
}
catch (...)
catch (std::exception& e)
{
wxMessageBox(_("Error loading data, cannot filter sample view"), _("Error!"),
wxOK | wxICON_ERROR | wxCENTRE, this);
wxMessageBox(wxString::Format(_("Error loading data, cannot filter sample view. Error: %s"), e.what()),
_("Error!"), wxOK | wxICON_ERROR | wxCENTRE, this);
}
m_bFiltered = true;
@ -445,23 +444,22 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event)
if (dataset.empty())
{
wxMessageBox(_("Error! Database is empty."), _("Error!"),
wxOK | wxICON_ERROR | wxCENTRE, this);
wxMessageBox(_("Error! Database is empty."), _("Error!"), wxOK | wxICON_ERROR | wxCENTRE, this);
}
else
{
m_ListCtrl.DeleteAllItems();
SampleHive::cHiveData::Get().ListCtrlDeleteAllItems();
for (auto data : dataset)
{
m_ListCtrl.AppendItem(data);
SampleHive::cHiveData::Get().ListCtrlAppendItem(data);
}
}
}
catch (...)
catch (std::exception& e)
{
wxMessageBox(_("Error loading data, cannot filter sample view"), _("Error!"),
wxOK | wxICON_ERROR | wxCENTRE, this);
wxMessageBox(wxString::Format(_("Error loading data, cannot filter sample view. Error: %s"), e.what()),
_("Error!"), wxOK | wxICON_ERROR | wxCENTRE, this);
}
m_bFiltered = false;
@ -476,68 +474,57 @@ void cHivesPanel::OnShowHivesContextMenu(wxDataViewEvent& event)
{
switch (m_pHives->GetPopupMenuSelectionFromUser(menu, event.GetPosition()))
{
case MN_RemoveSample:
for(int i = 0; i < m_ListCtrl.GetItemCount(); i++)
// for(int i = 0; i < 1; i++)
case SampleHive::ID::MN_RemoveSample:
for (int i = 0; i < SampleHive::cHiveData::Get().GetListCtrlItemCount(); i++)
{
wxString matched_sample = serializer.DeserializeShowFileExtension() ?
m_ListCtrl.GetTextValue(i, 1).BeforeLast('.') :
m_ListCtrl.GetTextValue(i, 1);
SampleHive::cHiveData::Get().GetListCtrlTextValue(i, 1).BeforeLast('.') :
SampleHive::cHiveData::Get().GetListCtrlTextValue(i, 1);
wxString selected_sample_name = serializer.DeserializeShowFileExtension() ?
m_pHives->GetItemText(event.GetItem()).BeforeLast('.') :
m_pHives->GetItemText(event.GetItem());
if (selected_sample_name == matched_sample)
// if(selected_sample_name == "")
{
SH_LOG_DEBUG("Found match");
m_ListCtrl.SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0);
SampleHive::cHiveData::Get().ListCtrlSetVariant(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0);
db.UpdateFavoriteColumn(matched_sample.ToStdString(), 0);
db.UpdateHiveName(matched_sample.ToStdString(),
m_pHives->GetItemText(m_FavoritesHive).ToStdString());
db.UpdateHiveName(matched_sample.ToStdString(), m_pHives->GetItemText(m_FavoritesHive).ToStdString());
m_pHives->DeleteItem(selected_hive);
break;
}
wxString msg = wxString::Format(_("Removed %s from %s"),
m_pHives->GetItemText(event.GetItem()),
wxString msg = wxString::Format(_("Removed %s from %s"), m_pHives->GetItemText(event.GetItem()),
db.GetHiveByFilename(matched_sample.ToStdString()));
// m_InfoBar->ShowMessage(wxString::Format(_("Removed %s from %s"),
// m_Hives->GetItemText(event.GetItem()),
// db.GetHiveByFilename(matched_sample.ToStdString())),
// wxICON_INFORMATION);
SampleHive::Signal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this);
SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this);
}
break;
case MN_ShowInLibrary:
for(int i = 0; i < m_ListCtrl.GetItemCount(); i++)
// for(int i = 0; i < 1; i++)
case SampleHive::ID::MN_ShowInLibrary:
for (int i = 0; i < SampleHive::cHiveData::Get().GetListCtrlItemCount(); i++)
{
wxString matched_sample = serializer.DeserializeShowFileExtension() ?
m_ListCtrl.GetTextValue(i, 1).BeforeLast('.') :
m_ListCtrl.GetTextValue(i, 1);
SampleHive::cHiveData::Get().GetListCtrlTextValue(i, 1).BeforeLast('.') :
SampleHive::cHiveData::Get().GetListCtrlTextValue(i, 1);
wxString selected_sample_name = serializer.DeserializeShowFileExtension() ?
m_pHives->GetItemText(event.GetItem()).BeforeLast('.') :
m_pHives->GetItemText(event.GetItem());
if (selected_sample_name == matched_sample)
// if(selected_sample_name == "")
{
SH_LOG_DEBUG("Found match");
wxDataViewItem matched_item = m_ListCtrl.RowToItem(i);
wxDataViewItem matched_item = SampleHive::cHiveData::Get().GetListCtrlItemFromRow(i);
m_ListCtrl.UnselectAll();
m_ListCtrl.SelectRow(i);
m_ListCtrl.EnsureVisible(matched_item);
SampleHive::cHiveData::Get().ListCtrlUnselectAllItems();
SampleHive::cHiveData::Get().ListCtrlSelectRow(i);
SampleHive::cHiveData::Get().ListCtrlEnsureVisible(matched_item);
break;
}
@ -557,7 +544,7 @@ void cHivesPanel::OnHiveStartEditing(wxDataViewEvent &event)
void cHivesPanel::OnClickAddHive(wxCommandEvent& event)
{
Database db;
cDatabase db;
std::deque<wxDataViewItem> nodes;
nodes.push_back(m_pHives->GetNthChild(wxDataViewItem(wxNullPtr), 0));
@ -607,17 +594,15 @@ void cHivesPanel::OnClickAddHive(wxCommandEvent& event)
if (found_item.IsOk())
{
wxMessageBox(wxString::Format(_("Another hive by the name %s already exist. "
"Please try with a different name."),
hive_name),
_("Error!"), wxOK | wxCENTRE, this);
wxMessageBox(wxString::Format(_("Another hive by the name %s already exist. Please try with a different name."),
hive_name), _("Error!"), wxOK | wxCENTRE, this);
}
else
{
m_pHives->AppendContainer(wxDataViewItem(wxNullPtr), hive_name);
db.InsertIntoHives(hive_name.ToStdString());
msg = wxString::Format(_("%s added to cHivesPanel."), hive_name);
msg = wxString::Format(_("%s added to Hives."), hive_name);
}
break;
}
@ -628,39 +613,29 @@ void cHivesPanel::OnClickAddHive(wxCommandEvent& event)
}
if (!msg.IsEmpty())
SampleHive::Signal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this);
// m_InfoBar->ShowMessage(msg, wxICON_INFORMATION);
SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this);
}
void cHivesPanel::OnClickRemoveHive(wxCommandEvent& event)
{
Serializer serializer;
Database db;
// cListCtrl m_ListCtrl.m_pWindow);
SampleHive::cSerializer serializer;
cDatabase db;
wxDataViewItem selected_item = m_pHives->GetSelection();
wxString hive_name = m_pHives->GetItemText(selected_item);
wxString msg;
wxMessageDialog deleteEmptyHiveDialog(this, wxString::Format(_("Are you sure you want to delete "
"%s from chives?"),
hive_name),
wxMessageBoxCaptionStr,
wxYES_NO | wxNO_DEFAULT |
wxICON_QUESTION | wxSTAY_ON_TOP);
wxMessageDialog deleteEmptyHiveDialog(this, wxString::Format(_("Are you sure you want to delete %s from hives?"), hive_name),
wxMessageBoxCaptionStr, wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION | wxSTAY_ON_TOP);
wxMessageDialog deleteFilledHiveDialog(this, wxString::Format(_("Are you sure you want to delete "
"%s and all sample inside %s from chives?"),
hive_name, hive_name),
wxMessageBoxCaptionStr,
wxYES_NO | wxNO_DEFAULT |
wxICON_QUESTION | wxSTAY_ON_TOP);
"%s and all sample inside %s from hives?"), hive_name, hive_name),
wxMessageBoxCaptionStr, wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION | wxSTAY_ON_TOP);
if (hive_name == m_pHives->GetItemText(m_FavoritesHive))
{
wxMessageBox(wxString::Format(_("Error! Default hive %s cannot be deleted."), hive_name),
_("Error!"), wxOK | wxCENTRE, this);
wxMessageBox(wxString::Format(_("Error! Default hive %s cannot be deleted."), hive_name), _("Error!"), wxOK | wxCENTRE, this);
return;
}
else if (!selected_item.IsOk())
@ -670,7 +645,7 @@ void cHivesPanel::OnClickRemoveHive(wxCommandEvent& event)
}
else if (selected_item.IsOk() && !m_pHives->IsContainer(selected_item))
{
wxMessageBox(wxString::Format(_("Error! %s is not a hive, cannot delete from chives."), hive_name),
wxMessageBox(wxString::Format(_("Error! %s is not a hive, cannot delete from hives."), hive_name),
_("Error!"), wxOK | wxCENTRE, this);
return;
}
@ -686,7 +661,7 @@ void cHivesPanel::OnClickRemoveHive(wxCommandEvent& event)
m_pHives->DeleteItem(selected_item);
db.RemoveHiveFromDatabase(hive_name.ToStdString());
msg = wxString::Format(_("%s deleted from chives successfully."), hive_name);
msg = wxString::Format(_("%s deleted from hives successfully."), hive_name);
}
break;
case wxID_NO:
@ -705,12 +680,11 @@ void cHivesPanel::OnClickRemoveHive(wxCommandEvent& event)
{
wxDataViewItem child_item;
for (int i = 0; i < m_ListCtrl.GetItemCount(); i++)
// for (int i = 0; i < 1; i++)
for (int i = 0; i < SampleHive::cHiveData::Get().GetListCtrlItemCount(); i++)
{
wxString matched_sample = serializer.DeserializeShowFileExtension() ?
m_ListCtrl.GetTextValue(i, 1).BeforeLast('.') :
m_ListCtrl.GetTextValue(i, 1);
SampleHive::cHiveData::Get().GetListCtrlTextValue(i, 1).BeforeLast('.') :
SampleHive::cHiveData::Get().GetListCtrlTextValue(i, 1);
for (int j = 0; j < m_pHives->GetChildCount(selected_item); j++)
{
@ -721,15 +695,13 @@ void cHivesPanel::OnClickRemoveHive(wxCommandEvent& event)
m_pHives->GetItemText(child_item);
if (child_name == matched_sample)
// if (child_name == "")
{
SH_LOG_DEBUG("Found match");
m_ListCtrl.SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0);
SampleHive::cHiveData::Get().ListCtrlSetVariant(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0);
db.UpdateFavoriteColumn(matched_sample.ToStdString(), 0);
db.UpdateHiveName(matched_sample.ToStdString(),
m_pHives->GetItemText(m_FavoritesHive).ToStdString());
db.UpdateHiveName(matched_sample.ToStdString(), m_pHives->GetItemText(m_FavoritesHive).ToStdString());
break;
}
@ -743,8 +715,7 @@ void cHivesPanel::OnClickRemoveHive(wxCommandEvent& event)
db.RemoveHiveFromDatabase(hive_name.ToStdString());
msg = wxString::Format(_("%s and all samples inside %s have been deleted "
"from chives successfully."),
msg = wxString::Format(_("%s and all samples inside %s have been deleted from hives successfully."),
hive_name, hive_name);
}
break;
@ -756,8 +727,7 @@ void cHivesPanel::OnClickRemoveHive(wxCommandEvent& event)
}
if (!msg.IsEmpty())
SampleHive::Signal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this);
// m_InfoBar->ShowMessage(msg, wxICON_INFORMATION);
SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this);
}
cHivesPanel::~cHivesPanel()

View File

@ -1,6 +1,24 @@
#pragma once
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "GUI/ListCtrl.hpp"
#pragma once
#include <wx/button.h>
#include <wx/dataview.h>
@ -12,13 +30,13 @@ class cHivesPanel : public wxPanel
{
public:
// -------------------------------------------------------------------
cHivesPanel(wxWindow* window, wxDataViewListCtrl& listCtrl);
cHivesPanel(wxWindow* window);
~cHivesPanel();
public:
// -------------------------------------------------------------------
wxDataViewTreeCtrl* GetHivesObject() { return m_pHives; }
wxDataViewItem GetFavoritesHive() { return m_FavoritesHive; }
wxDataViewItem& GetFavoritesHive() { return m_FavoritesHive; }
bool IsLibraryFiltered() { return m_bFiltered; }
@ -48,9 +66,4 @@ class cHivesPanel : public wxPanel
// -------------------------------------------------------------------
wxWindow* m_pWindow = nullptr;
wxDataViewListCtrl& m_ListCtrl;
// -------------------------------------------------------------------
// friend class cListCtrl;
};

View File

@ -1,3 +1,23 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "InfoBar.hpp"
cInfoBar::cInfoBar(wxWindow* window)

View File

@ -1,3 +1,23 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <wx/infobar.h>

View File

@ -1,16 +1,34 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "GUI/Library.hpp"
#include "Utility/Log.hpp"
cLibrary::cLibrary(wxWindow* window, wxDataViewItem favHive, wxDataViewTreeCtrl& hives,
wxTreeItemId trashRoot, wxTreeCtrl& trash)
: wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
m_FavoritesHive(favHive), m_pHives(hives), m_pTrash(trash), m_TrashRoot(trashRoot)
cLibrary::cLibrary(wxWindow* window)
: wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
{
m_pSizer = new wxBoxSizer(wxVERTICAL);
m_pSearchBar = new cSearchBar(this, *m_pListCtrl);
m_pSearchBar = new cSearchBar(this);
m_pInfoBar = new cInfoBar(this);
m_pListCtrl = new cListCtrl(this, m_FavoritesHive, hives, trashRoot, trash);
m_pListCtrl = new cListCtrl(this);
m_pSizer->Add(m_pSearchBar, wxSizerFlags(1).Expand());
m_pSizer->Add(m_pInfoBar, wxSizerFlags(0).Expand());

View File

@ -1,3 +1,23 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "GUI/InfoBar.hpp"
@ -13,8 +33,7 @@
class cLibrary : public wxPanel
{
public:
cLibrary(wxWindow* window, wxDataViewItem favHive, wxDataViewTreeCtrl& hives,
wxTreeItemId trashRoot, wxTreeCtrl& trash);
cLibrary(wxWindow* window);
~cLibrary();
public:
@ -22,19 +41,9 @@ class cLibrary : public wxPanel
wxInfoBar* GetInfoBarObject() const { return m_pInfoBar; }
wxDataViewListCtrl* GetListCtrlObject() const { return m_pListCtrl; }
// void SetHivesObject(wxDataViewTreeCtrl& hives) { m_pHives = &hives;}
// void SetFavoritesHive(wxDataViewItem favHive) { m_FavoritesHive = favHive;}
// void SetTrashObject(wxTreeCtrl& trash) { m_pTrash = &trash;}
// void SetTrashRoot(wxTreeItemId trashRoot) { m_TrashRoot = trashRoot;}
private:
cSearchBar* m_pSearchBar = nullptr;
cInfoBar* m_pInfoBar = nullptr;
cListCtrl* m_pListCtrl = nullptr;
wxBoxSizer* m_pSizer = nullptr;
wxDataViewItem m_FavoritesHive;
wxDataViewTreeCtrl& m_pHives;
wxTreeCtrl& m_pTrash;
wxTreeItemId m_TrashRoot;
};

View File

@ -1,29 +1,44 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "GUI/ListCtrl.hpp"
// #include "GUI/Hives.hpp"
// #include "GUI/Trash.hpp"
#include "GUI/Dialogs/TagEditor.hpp"
#include "Database/Database.hpp"
#include "GUI/Hives.hpp"
#include "Utility/ControlIDs.hpp"
#include "Utility/SH_Event.hpp"
#include "Utility/Signal.hpp"
#include "Utility/HiveData.hpp"
#include "Utility/Serialize.hpp"
#include "Utility/Event.hpp"
#include "Utility/Signal.hpp"
#include "Utility/Log.hpp"
#include "Utility/Paths.hpp"
#include "Utility/Utils.hpp"
#include <wx/dir.h>
#include <wx/menu.h>
#include "wx/log.h"
#include <wx/progdlg.h>
#include <wx/msgdlg.h>
// cListCtrl::cListCtrl(wxWindow* window)
cListCtrl::cListCtrl(wxWindow* window, wxDataViewItem favHive, wxDataViewTreeCtrl& hives,
wxTreeItemId trashRoot, wxTreeCtrl& trash)
: wxDataViewListCtrl(window, BC_Library, wxDefaultPosition, wxDefaultSize,
cListCtrl::cListCtrl(wxWindow* window)
: wxDataViewListCtrl(window, SampleHive::ID::BC_Library, wxDefaultPosition, wxDefaultSize,
wxDV_MULTIPLE | wxDV_HORIZ_RULES | wxDV_VERT_RULES | wxDV_ROW_LINES),
// m_pWindow(window)
m_pWindow(window), m_Hives(hives), m_FavoritesHive(favHive), m_TrashRoot(trashRoot), m_Trash(trash)
m_pWindow(window)
{
// Adding columns to wxDataViewListCtrl.
AppendBitmapColumn(wxBitmap(ICON_STAR_FILLED_16px),
@ -95,20 +110,16 @@ cListCtrl::cListCtrl(wxWindow* window, wxDataViewItem favHive, wxDataViewTreeCtr
// Enable dragging a file from cListCtrl
this->EnableDragSource(wxDF_FILENAME);
Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &cListCtrl::OnClickLibrary, this, BC_Library);
Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &cListCtrl::OnClickLibrary, this, SampleHive::ID::BC_Library);
Bind(wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, &cListCtrl::OnDragFromLibrary, this);
this->Connect(wxEVT_DROP_FILES, wxDropFilesEventHandler(cListCtrl::OnDragAndDropToLibrary), NULL, this);
Bind(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &cListCtrl::OnShowLibraryContextMenu, this, BC_Library);
Bind(wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK,
&cListCtrl::OnShowLibraryColumnHeaderContextMenu, this, BC_Library);
LoadDatabase();
Bind(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &cListCtrl::OnShowLibraryContextMenu, this, SampleHive::ID::BC_Library);
Bind(wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, &cListCtrl::OnShowLibraryColumnHeaderContextMenu, this, SampleHive::ID::BC_Library);
}
void cListCtrl::OnClickLibrary(wxDataViewEvent& event)
{
// cHivesPanel hives(m_pWindow);
Database db;
cDatabase db;
int selected_row = this->ItemToRow(event.GetItem());
int current_row = this->ItemToRow(this->GetCurrentItem());
@ -123,19 +134,13 @@ void cListCtrl::OnClickLibrary(wxDataViewEvent& event)
}
// Update the waveform bitmap
SampleHive::Signal::SendWaveformUpdateStatus(*this);
// m_TopWaveformPanel->ResetDC();
SampleHive::cSignal::SendWaveformUpdateStatus(*this);
// TODO
// SampleHive::Signal::SendSetLoopABButton(*this);
// m_LoopABButton->SetValue(false);
// Update LoopAB button value
SampleHive::cSignal::SendLoopABButtonValueChange(*this);
SampleHive::Signal::SendTimerStopStatus(*this);
// if (m_Timer->IsRunning())
// {
// m_Timer->Stop();
// SH_LOG_DEBUG("TIMER STOPPED");
// }
// Stop the timer
SampleHive::cSignal::SendTimerStopStatus(*this);
wxString selection = this->GetTextValue(selected_row, 1);
@ -148,40 +153,30 @@ void cListCtrl::OnClickLibrary(wxDataViewEvent& event)
if (!CurrentColumn)
return;
wxString sample_path = GetFilenamePathAndExtension(selection).Path;
std::string filename = GetFilenamePathAndExtension(selection).Filename;
std::string extension = GetFilenamePathAndExtension(selection).Extension;
wxString sample_path = SampleHive::cUtils::Get().GetFilenamePathAndExtension(selection).Path;
std::string filename = SampleHive::cUtils::Get().GetFilenamePathAndExtension(selection).Filename;
std::string extension = SampleHive::cUtils::Get().GetFilenamePathAndExtension(selection).Extension;
if (CurrentColumn != FavoriteColumn)
{
SampleHive::Signal::SendCallFunctionPlay(selection, *this);
// TODO
// ClearLoopPoints();
SampleHive::cSignal::SendClearLoopPointsStatus(*this);
// if (bAutoplay)
// {
// if (bLoopPointsSet && m_LoopABButton->GetValue())
// PlaySample(sample_path.ToStdString(), selection.ToStdString(),
// true, m_LoopA.ToDouble(), wxFromStart);
// else
// PlaySample(sample_path.ToStdString(), selection.ToStdString());
// }
// else
// m_MediaCtrl->Stop();
// Play the sample
SampleHive::cSignal::SendCallFunctionPlay(selection, true, *this);
}
else
{
wxString msg;
// Get hive name and location
std::string hive_name = m_Hives.GetItemText(m_FavoritesHive).ToStdString();
wxDataViewItem hive_selection = m_Hives.GetSelection();
std::string hive_name = SampleHive::cHiveData::Get().GetHiveItemText(true).ToStdString();
wxDataViewItem hive_selection = SampleHive::cHiveData::Get().GetHiveItemSelection();
SH_LOG_DEBUG("HIVE NAME: {}", hive_name);
if (hive_selection.IsOk() && m_Hives.IsContainer(hive_selection))
hive_name = m_Hives.GetItemText(hive_selection).ToStdString();
if (hive_selection.IsOk() && SampleHive::cHiveData::Get().IsHiveItemContainer(hive_selection))
hive_name = SampleHive::cHiveData::Get().GetHiveItemText(false, hive_selection);
wxString name = this->GetTextValue(selected_row, 1);
@ -192,20 +187,18 @@ void cListCtrl::OnClickLibrary(wxDataViewEvent& event)
if (db.GetFavoriteColumnValueByFilename(filename) == 0)
{
SH_LOG_DEBUG("TRUE COND....");
this->SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), selected_row, 0);
db.UpdateFavoriteColumn(filename, 1);
db.UpdateHiveName(filename, hive_name);
for (int i = 0; i < m_Hives.GetChildCount(root); i++)
for (int i = 0; i < SampleHive::cHiveData::Get().GetHiveChildCount(root); i++)
{
container = m_Hives.GetNthChild(root, i);
container = SampleHive::cHiveData::Get().GetHiveNthChild(root, i);
if (m_Hives.GetItemText(container).ToStdString() == hive_name)
if (SampleHive::cHiveData::Get().GetHiveItemText(false, container) == hive_name)
{
m_Hives.AppendItem(container, name);
SampleHive::cHiveData::Get().HiveAppendItem(container, name);
break;
}
}
@ -217,19 +210,19 @@ void cListCtrl::OnClickLibrary(wxDataViewEvent& event)
this->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), selected_row, 0);
db.UpdateFavoriteColumn(filename, 0);
db.UpdateHiveName(filename, m_Hives.GetItemText(m_FavoritesHive).ToStdString());
db.UpdateHiveName(filename, SampleHive::cHiveData::Get().GetHiveItemText(true).ToStdString());
for (int i = 0; i < m_Hives.GetChildCount(root); i++)
for (int i = 0; i < SampleHive::cHiveData::Get().GetHiveChildCount(root); i++)
{
container = m_Hives.GetNthChild(root, i);
container = SampleHive::cHiveData::Get().GetHiveNthChild(root, i);
for (int j = 0; j < m_Hives.GetChildCount(container); j++)
for (int j = 0; j < SampleHive::cHiveData::Get().GetHiveChildCount(container); j++)
{
child = m_Hives.GetNthChild(container, j);
child = SampleHive::cHiveData::Get().GetHiveNthChild(container, j);
if (m_Hives.GetItemText(child) == name)
if (SampleHive::cHiveData::Get().GetHiveItemText(false, child) == name)
{
m_Hives.DeleteItem(child);
SampleHive::cHiveData::Get().HiveDeleteItem(child);
break;
}
}
@ -239,8 +232,7 @@ void cListCtrl::OnClickLibrary(wxDataViewEvent& event)
}
if (!msg.IsEmpty())
SampleHive::Signal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this);
// m_InfoBar->ShowMessage(msg, wxICON_INFORMATION);
SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this);
}
}
@ -288,7 +280,7 @@ void cListCtrl::OnDragAndDropToLibrary(wxDropFilesEvent& event)
progressDialog->Destroy();
AddSamples(filepath_array);
SampleHive::cUtils::Get().AddSamples(filepath_array, m_pWindow);
SH_LOG_DEBUG("Done Inserting Samples");
}
@ -303,7 +295,7 @@ void cListCtrl::OnDragFromLibrary(wxDataViewEvent& event)
wxString selection = this->GetTextValue(selected_row, 1);
wxString sample_path = GetFilenamePathAndExtension(selection).Path;
wxString sample_path = SampleHive::cUtils::Get().GetFilenamePathAndExtension(selection).Path;
wxFileDataObject* fileData = new wxFileDataObject();
@ -315,10 +307,9 @@ void cListCtrl::OnDragFromLibrary(wxDataViewEvent& event)
void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event)
{
TagEditor* tagEditor;
Serializer serializer;
Database db;
// cHivesPanel hives(m_pWindow);
cTagEditor* tagEditor;
cDatabase db;
SampleHive::cSerializer serializer;
wxString msg;
@ -332,9 +323,9 @@ void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event)
wxString selection = this->GetTextValue(selected_row, 1);
wxString sample_path = GetFilenamePathAndExtension(selection).Path;
std::string filename = GetFilenamePathAndExtension(selection).Filename;
std::string extension = GetFilenamePathAndExtension(selection).Extension;
wxString sample_path = SampleHive::cUtils::Get().GetFilenamePathAndExtension(selection).Path;
std::string filename = SampleHive::cUtils::Get().GetFilenamePathAndExtension(selection).Filename;
std::string extension = SampleHive::cUtils::Get().GetFilenamePathAndExtension(selection).Extension;
wxMenu menu;
@ -342,41 +333,41 @@ void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event)
bool favorite_add = false;
if (db.GetFavoriteColumnValueByFilename(filename) == 1)
menu.Append(MN_FavoriteSample, _("Remove from hive"), _("Remove the selected sample(s) from hive"));
menu.Append(SampleHive::ID::MN_FavoriteSample, _("Remove from hive"), _("Remove the selected sample(s) from hive"));
else
{
menu.Append(MN_FavoriteSample, _("Add to hive"), _("Add selected sample(s) to hive"));
menu.Append(SampleHive::ID::MN_FavoriteSample, _("Add to hive"), _("Add selected sample(s) to hive"));
favorite_add = true;
}
menu.Append(MN_DeleteSample, _("Delete"), _("Delete the selected sample(s) from database"));
menu.Append(MN_TrashSample, _("Trash"), _("Send the selected sample(s) to trash"));
menu.Append(SampleHive::ID::MN_DeleteSample, _("Delete"), _("Delete the selected sample(s) from database"));
menu.Append(SampleHive::ID::MN_TrashSample, _("Trash"), _("Send the selected sample(s) to trash"));
if (this->GetSelectedItemsCount() <= 1)
{
menu.Append(MN_EditTagSample, _("Edit tags"),
menu.Append(SampleHive::ID::MN_EditTagSample, _("Edit tags"),
_("Edit the tags for the selected sample"))->Enable(true);
menu.Append(MN_OpenFile, _("Open in file manager"),
menu.Append(SampleHive::ID::MN_OpenFile, _("Open in file manager"),
_("Open the selected sample in system's file manager"))->Enable(true);
}
else
{
menu.Append(MN_EditTagSample, _("Edit tags"),
menu.Append(SampleHive::ID::MN_EditTagSample, _("Edit tags"),
_("Edit the tags for the selected sample"))->Enable(false);
menu.Append(MN_OpenFile, _("Open in file manager"),
menu.Append(SampleHive::ID::MN_OpenFile, _("Open in file manager"),
_("Open the selected sample in system's file manager"))->Enable(false);
}
switch (this->GetPopupMenuSelectionFromUser(menu, event.GetPosition()))
{
case MN_FavoriteSample:
case SampleHive::ID::MN_FavoriteSample:
{
std::string hive_name = m_Hives.GetItemText(m_FavoritesHive).ToStdString();
std::string hive_name = SampleHive::cHiveData::Get().GetHiveItemText(true).ToStdString();
wxDataViewItem hive_selection = m_Hives.GetSelection();
wxDataViewItem hive_selection = SampleHive::cHiveData::Get().GetHiveItemSelection();
if (hive_selection.IsOk() && m_Hives.IsContainer(hive_selection))
hive_name = m_Hives.GetItemText(hive_selection).ToStdString();
if (hive_selection.IsOk() && SampleHive::cHiveData::Get().IsHiveItemContainer(hive_selection))
hive_name = SampleHive::cHiveData::Get().GetHiveItemText(false, hive_selection);
wxDataViewItem root = wxDataViewItem(wxNullPtr);
wxDataViewItem container;
@ -417,13 +408,13 @@ void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event)
db.UpdateFavoriteColumn(filename, 1);
db.UpdateHiveName(filename, hive_name);
for (int i = 0; i < m_Hives.GetChildCount(root); i++)
for (int i = 0; i < SampleHive::cHiveData::Get().GetHiveChildCount(root); i++)
{
container = m_Hives.GetNthChild(root, i);
container = SampleHive::cHiveData::Get().GetHiveNthChild(root, i);
if (m_Hives.GetItemText(container).ToStdString() == hive_name)
if (SampleHive::cHiveData::Get().GetHiveItemText(false, container) == hive_name)
{
m_Hives.AppendItem(container, name);
SampleHive::cHiveData::Get().HiveAppendItem(container, name);
msg = wxString::Format(_("Added %s to %s"), name, hive_name);
break;
@ -436,20 +427,19 @@ void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event)
this->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), selected_row, 0);
db.UpdateFavoriteColumn(filename, 0);
db.UpdateHiveName(filename,
m_Hives.GetItemText(m_FavoritesHive).ToStdString());
db.UpdateHiveName(filename, SampleHive::cHiveData::Get().GetHiveItemText(true).ToStdString());
for (int i = 0; i < m_Hives.GetChildCount(root); i++)
for (int i = 0; i < SampleHive::cHiveData::Get().GetHiveChildCount(root); i++)
{
container = m_Hives.GetNthChild(root, i);
container = SampleHive::cHiveData::Get().GetHiveNthChild(root, i);
for (int j = 0; j < m_Hives.GetChildCount(container); j++)
for (int j = 0; j < SampleHive::cHiveData::Get().GetHiveChildCount(container); j++)
{
child = m_Hives.GetNthChild(container, j);
child = SampleHive::cHiveData::Get().GetHiveNthChild(container, j);
if (m_Hives.GetItemText(child) == name)
if (SampleHive::cHiveData::Get().GetHiveItemText(false, child) == name)
{
m_Hives.DeleteItem(child);
SampleHive::cHiveData::Get().HiveDeleteItem(child);
msg = wxString::Format(_("Removed %s from %s"), name, hive_name);
break;
@ -458,32 +448,25 @@ void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event)
}
}
}
break;
}
case MN_DeleteSample:
case SampleHive::ID::MN_DeleteSample:
{
wxDataViewItemArray items;
int rows = this->GetSelections(items);
wxMessageDialog singleMsgDialog(this, wxString::Format(_("Are you sure you want to delete "
"%s from database? "
"Warning this change is "
"permanent, and cannot be undone."),
wxMessageDialog singleMsgDialog(this, wxString::Format(_("Are you sure you want to delete %s from database? "
"Warning this change is permanent, and cannot be undone."),
sample_path.AfterLast('/')),
wxMessageBoxCaptionStr,
wxYES_NO | wxNO_DEFAULT |
wxICON_QUESTION | wxSTAY_ON_TOP |
wxCENTER);
wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION | wxSTAY_ON_TOP | wxCENTER);
wxMessageDialog multipleMsgDialog(this, wxString::Format(_("Are you sure you want to delete "
"%d selected samples from database? "
"Warning this change is "
"permanent, and cannot be "
"undone."), rows),
"%d selected samples from database? Warning this change is "
"permanent, and cannot be undone."), rows),
wxMessageBoxCaptionStr,
wxYES_NO | wxNO_DEFAULT |
wxICON_QUESTION | wxSTAY_ON_TOP |
wxCENTER);
wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION | wxSTAY_ON_TOP | wxCENTER);
wxDataViewItem root = wxDataViewItem(wxNullPtr);
wxDataViewItem container;
@ -498,21 +481,21 @@ void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event)
db.RemoveSampleFromDatabase(filename);
this->DeleteItem(selected_row);
for (int j = 0; j < m_Hives.GetChildCount(root); j++)
for (int j = 0; j < SampleHive::cHiveData::Get().GetHiveChildCount(root); j++)
{
container = m_Hives.GetNthChild(root, j);
container = SampleHive::cHiveData::Get().GetHiveNthChild(root, j);
for (int k = 0; k < m_Hives.GetChildCount(container); k++)
for (int k = 0; k < SampleHive::cHiveData::Get().GetHiveChildCount(container); k++)
{
child = m_Hives.GetNthChild(container, k);
child = SampleHive::cHiveData::Get().GetHiveNthChild(container, k);
wxString child_text = serializer.DeserializeShowFileExtension() ?
m_Hives.GetItemText(child).BeforeLast('.') :
m_Hives.GetItemText(child);
SampleHive::cHiveData::Get().GetHiveItemText(false, child).BeforeLast('.') :
SampleHive::cHiveData::Get().GetHiveItemText(false, child);
if (child_text == filename)
{
m_Hives.DeleteItem(child);
SampleHive::cHiveData::Get().HiveDeleteItem(child);
break;
}
@ -548,21 +531,21 @@ void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event)
db.RemoveSampleFromDatabase(multi_selection);
this->DeleteItem(row);
for (int j = 0; j < m_Hives.GetChildCount(root); j++)
for (int j = 0; j < SampleHive::cHiveData::Get().GetHiveChildCount(root); j++)
{
container = m_Hives.GetNthChild(root, j);
container = SampleHive::cHiveData::Get().GetHiveNthChild(root, j);
for (int k = 0; k < m_Hives.GetChildCount(container); k++)
for (int k = 0; k < SampleHive::cHiveData::Get().GetHiveChildCount(container); k++)
{
child = m_Hives.GetNthChild(container, k);
child = SampleHive::cHiveData::Get().GetHiveNthChild(container, k);
wxString child_text = serializer.DeserializeShowFileExtension() ?
m_Hives.GetItemText(child).BeforeLast('.') :
m_Hives.GetItemText(child);
SampleHive::cHiveData::Get().GetHiveItemText(false, child).BeforeLast('.') :
SampleHive::cHiveData::Get().GetHiveItemText(false, child);
if (child_text == multi_selection)
{
m_Hives.DeleteItem(child);
SampleHive::cHiveData::Get().HiveDeleteItem(child);
break;
}
}
@ -582,7 +565,7 @@ void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event)
}
}
break;
case MN_TrashSample:
case SampleHive::ID::MN_TrashSample:
{
wxDataViewItem root = wxDataViewItem(wxNullPtr);
wxDataViewItem container, child;
@ -618,43 +601,42 @@ void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event)
db.UpdateFavoriteColumn(files[i].ToStdString(), 0);
for (int j = 0; j < m_Hives.GetChildCount(root); j++)
for (int j = 0; j < SampleHive::cHiveData::Get().GetHiveChildCount(root); j++)
{
container = m_Hives.GetNthChild(root, j);
container = SampleHive::cHiveData::Get().GetHiveNthChild(root, j);
for (int k = 0; k < m_Hives.GetChildCount(container); k++)
for (int k = 0; k < SampleHive::cHiveData::Get().GetHiveChildCount(container); k++)
{
child = m_Hives.GetNthChild(container, k);
child = SampleHive::cHiveData::Get().GetHiveNthChild(container, k);
wxString child_text = serializer.DeserializeShowFileExtension() ?
m_Hives.GetItemText(child).BeforeLast('.') :
m_Hives.GetItemText(child);
SampleHive::cHiveData::Get().GetHiveItemText(false, child).BeforeLast('.') :
SampleHive::cHiveData::Get().GetHiveItemText(false, child);
if (child_text == files[i])
{
m_Hives.DeleteItem(child);
SampleHive::cHiveData::Get().HiveDeleteItem(child);
break;
}
}
}
}
m_Trash.AppendItem(m_TrashRoot, text_value);
SampleHive::cHiveData::Get().TrashAppendItem(SampleHive::cHiveData::Get().GetTrashRoot(), text_value);
this->DeleteItem(item_row);
db.UpdateTrashColumn(files[i].ToStdString(), 1);
db.UpdateHiveName(files[i].ToStdString(),
m_Hives.GetItemText(m_FavoritesHive).ToStdString());
db.UpdateHiveName(files[i].ToStdString(), SampleHive::cHiveData::Get().GetHiveItemText(true).ToStdString());
msg = wxString::Format(_("%s sent to trash"), text_value);
}
}
}
break;
case MN_EditTagSample:
case SampleHive::ID::MN_EditTagSample:
{
tagEditor = new TagEditor(this, static_cast<std::string>(sample_path));
tagEditor = new cTagEditor(this, static_cast<std::string>(sample_path));
switch (tagEditor->ShowModal())
{
@ -672,7 +654,7 @@ void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event)
}
}
break;
case MN_OpenFile:
case SampleHive::ID::MN_OpenFile:
wxExecute(wxString::Format("xdg-open '%s'", sample_path.BeforeLast('/')));
break;
case wxID_NONE:
@ -684,8 +666,7 @@ void cListCtrl::OnShowLibraryContextMenu(wxDataViewEvent& event)
}
if (!msg.IsEmpty())
SampleHive::Signal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this);
// m_InfoBar->ShowMessage(msg);
SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_INFORMATION, *this);
}
void cListCtrl::OnShowLibraryColumnHeaderContextMenu(wxDataViewEvent& event)
@ -702,233 +683,59 @@ void cListCtrl::OnShowLibraryColumnHeaderContextMenu(wxDataViewEvent& event)
wxDataViewColumn* BitrateColumn = this->GetColumn(7);
wxDataViewColumn* PathColumn = this->GetColumn(8);
menu.AppendCheckItem(MN_ColumnFavorite, _("Favorites"),
menu.AppendCheckItem(SampleHive::ID::MN_ColumnFavorite, _("Favorites"),
_("Toggle favorites column"))->Check(FavoriteColumn->IsShown());
menu.AppendCheckItem(MN_ColumnFilename, _("Filename"),
menu.AppendCheckItem(SampleHive::ID::MN_ColumnFilename, _("Filename"),
_("Toggle filename column"))->Check(FilenameColumn->IsShown());
menu.AppendCheckItem(MN_ColumnSamplePack, _("Sample Pack"),
menu.AppendCheckItem(SampleHive::ID::MN_ColumnSamplePack, _("Sample Pack"),
_("Toggle sample pack column"))->Check(SamplePackColumn->IsShown());
menu.AppendCheckItem(MN_ColumnType, _("Type"),
menu.AppendCheckItem(SampleHive::ID::MN_ColumnType, _("Type"),
_("Toggle type column"))->Check(TypeColumn->IsShown());
menu.AppendCheckItem(MN_ColumnChannels, _("Channels"),
menu.AppendCheckItem(SampleHive::ID::MN_ColumnChannels, _("Channels"),
_("Toggle channels column"))->Check(ChannelsColumn->IsShown());
menu.AppendCheckItem(MN_ColumnLength, _("Length"),
menu.AppendCheckItem(SampleHive::ID::MN_ColumnLength, _("Length"),
_("Toggle length column"))->Check(LengthColumn->IsShown());
menu.AppendCheckItem(MN_ColumnSampleRate, _("Sample Rate"),
menu.AppendCheckItem(SampleHive::ID::MN_ColumnSampleRate, _("Sample Rate"),
_("Toggle sample rate column"))->Check(SampleRateColumn->IsShown());
menu.AppendCheckItem(MN_ColumnBitrate, _("Bitrate"),
menu.AppendCheckItem(SampleHive::ID::MN_ColumnBitrate, _("Bitrate"),
_("Toggle bitrate column"))->Check(BitrateColumn->IsShown());
menu.AppendCheckItem(MN_ColumnPath, _("Path"),
menu.AppendCheckItem(SampleHive::ID::MN_ColumnPath, _("Path"),
_("Toggle path column"))->Check(PathColumn->IsShown());
switch (this->GetPopupMenuSelectionFromUser(menu, event.GetPosition()))
{
case MN_ColumnFavorite:
FavoriteColumn->SetHidden(!menu.IsChecked(MN_ColumnFavorite));
case SampleHive::ID::MN_ColumnFavorite:
FavoriteColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnFavorite));
break;
case MN_ColumnFilename:
FilenameColumn->SetHidden(!menu.IsChecked(MN_ColumnFilename));
case SampleHive::ID::MN_ColumnFilename:
FilenameColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnFilename));
break;
case MN_ColumnSamplePack:
SamplePackColumn->SetHidden(!menu.IsChecked(MN_ColumnSamplePack));
case SampleHive::ID::MN_ColumnSamplePack:
SamplePackColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnSamplePack));
break;
case MN_ColumnType:
TypeColumn->SetHidden(!menu.IsChecked(MN_ColumnType));
case SampleHive::ID::MN_ColumnType:
TypeColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnType));
break;
case MN_ColumnChannels:
ChannelsColumn->SetHidden(!menu.IsChecked(MN_ColumnChannels));
case SampleHive::ID::MN_ColumnChannels:
ChannelsColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnChannels));
break;
case MN_ColumnLength:
LengthColumn->SetHidden(!menu.IsChecked(MN_ColumnLength));
case SampleHive::ID::MN_ColumnLength:
LengthColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnLength));
break;
case MN_ColumnSampleRate:
SampleRateColumn->SetHidden(!menu.IsChecked(MN_ColumnSampleRate));
case SampleHive::ID::MN_ColumnSampleRate:
SampleRateColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnSampleRate));
break;
case MN_ColumnBitrate:
BitrateColumn->SetHidden(!menu.IsChecked(MN_ColumnBitrate));
case SampleHive::ID::MN_ColumnBitrate:
BitrateColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnBitrate));
break;
case MN_ColumnPath:
PathColumn->SetHidden(!menu.IsChecked(MN_ColumnPath));
case SampleHive::ID::MN_ColumnPath:
PathColumn->SetHidden(!menu.IsChecked(SampleHive::ID::MN_ColumnPath));
break;
default:
break;
}
}
void cListCtrl::AddSamples(wxArrayString& files)
{
Serializer serializer;
Database db;
wxBusyCursor busy_cursor;
wxWindowDisabler window_disabler;
wxProgressDialog* progressDialog = new wxProgressDialog(_("Adding files.."),
_("Adding files, please wait..."),
static_cast<int>(files.size()), this,
wxPD_APP_MODAL | wxPD_SMOOTH | wxPD_CAN_ABORT |
wxPD_AUTO_HIDE);
progressDialog->CenterOnParent(wxBOTH);
std::vector<Sample> sample_array;
std::string path;
std::string artist;
std::string filename_with_extension;
std::string filename_without_extension;
std::string extension;
std::string filename;
//Check All Files At Once
wxArrayString sorted_files;
sorted_files = db.CheckDuplicates(files);
files = sorted_files;
if(files.size() < 1)
{
progressDialog->Destroy();
return;
}
progressDialog->SetRange(files.size());
for(unsigned int i = 0; i < files.size(); i++)
{
progressDialog->Update(i, wxString::Format(_("Getting Data For %s"), files[i].AfterLast('/')));
if(progressDialog->WasCancelled())
{
progressDialog->Destroy();
return;
}
path = files[i].ToStdString();
filename_with_extension = files[i].AfterLast('/').ToStdString();
filename_without_extension = files[i].AfterLast('/').BeforeLast('.').ToStdString();
extension = files[i].AfterLast('.').ToStdString();
filename = serializer.DeserializeShowFileExtension() ?
filename_with_extension : filename_without_extension;
Sample sample;
sample.SetPath(path);
sample.SetFilename(filename_without_extension);
sample.SetFileExtension(extension);
Tags tags(path);
artist = tags.GetAudioInfo().artist.ToStdString();
sample.SetSamplePack(artist);
sample.SetChannels(tags.GetAudioInfo().channels);
sample.SetLength(tags.GetAudioInfo().length);
sample.SetSampleRate(tags.GetAudioInfo().sample_rate);
sample.SetBitrate(tags.GetAudioInfo().bitrate);
wxLongLong llLength = sample.GetLength();
int total_min = static_cast<int>((llLength / 60000).GetValue());
int total_sec = static_cast<int>(((llLength % 60000) / 1000).GetValue());
wxVector<wxVariant> data;
wxVariant icon = wxVariant(wxBitmap(ICON_STAR_EMPTY_16px));
if (tags.IsFileValid())
{
data.clear();
data.push_back(icon);
data.push_back(filename);
data.push_back(sample.GetSamplePack());
data.push_back("");
data.push_back(wxString::Format("%d", sample.GetChannels()));
data.push_back(wxString::Format("%2i:%02i", total_min, total_sec));
data.push_back(wxString::Format("%d", sample.GetSampleRate()));
data.push_back(wxString::Format("%d", sample.GetBitrate()));
data.push_back(path);
SH_LOG_INFO("Adding file: {}, Extension: {}", sample.GetFilename(), sample.GetFileExtension());
this->AppendItem(data);
sample_array.push_back(sample);
}
else
{
wxString msg = wxString::Format(_("Error! Cannot open %s, Invalid file type."),
filename_with_extension);
SampleHive::Signal::SendInfoBarMessage(msg, wxICON_ERROR, *this);
// m_InfoBar->ShowMessage(msg, wxICON_ERROR);
}
}
progressDialog->Pulse(_("Updating Database.."), NULL);
db.InsertIntoSamples(sample_array);
progressDialog->Destroy();
}
cListCtrl::FileInfo cListCtrl::GetFilenamePathAndExtension(const wxString& selected,
bool checkExtension, bool doGetFilename) const
{
Serializer serializer;
Database db;
wxString path;
std::string extension, filename;
wxString filename_with_extension = db.GetSamplePathByFilename(selected.BeforeLast('.').ToStdString());
wxString filename_without_extension = db.GetSamplePathByFilename(selected.ToStdString());
if (checkExtension)
{
extension = serializer.DeserializeShowFileExtension() ?
db.GetSampleFileExtension(selected.ToStdString()) :
db.GetSampleFileExtension(selected.BeforeLast('.').ToStdString());
}
path = selected.Contains(wxString::Format(".%s", extension)) ?
filename_with_extension : filename_without_extension;
if (doGetFilename)
filename = path.AfterLast('/').BeforeLast('.').ToStdString();
return { path, extension, filename };
}
void cListCtrl::LoadDatabase()
{
Serializer serializer;
Database db;
// cHivesPanel hives(m_pWindow);
// cTrashPanel trash(m_pWindow);
try
{
const auto dataset = db.LoadSamplesDatabase(m_Hives, m_FavoritesHive,
m_Trash, m_TrashRoot,
serializer.DeserializeShowFileExtension(),
ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px);
if (dataset.empty())
SH_LOG_INFO("Error! Database is empty.");
else
{
for (auto data : dataset)
this->AppendItem(data);
}
db.LoadHivesDatabase(m_Hives);
}
catch(...)
{
std::cerr << "Error loading data." << std::endl;
}
}
cListCtrl::~cListCtrl()
{

View File

@ -1,3 +1,23 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <wx/dataview.h>
@ -6,19 +26,9 @@
class cListCtrl : public wxDataViewListCtrl
{
struct FileInfo
{
wxString Path;
std::string Extension;
std::string Filename;
};
public:
// -------------------------------------------------------------------
// cListCtrl(wxWindow* window);
cListCtrl(wxWindow* window, wxDataViewItem favHive, wxDataViewTreeCtrl& hives,
wxTreeItemId trashRoot, wxTreeCtrl& trash);
cListCtrl(wxWindow* window);
~cListCtrl();
public:
@ -34,27 +44,7 @@ class cListCtrl : public wxDataViewListCtrl
void OnShowLibraryContextMenu(wxDataViewEvent& event);
void OnShowLibraryColumnHeaderContextMenu(wxDataViewEvent& event);
// -------------------------------------------------------------------
void AddSamples(wxArrayString& files);
// -------------------------------------------------------------------
cListCtrl::FileInfo GetFilenamePathAndExtension(const wxString& selected,
bool checkExtension = true,
bool doGetFilename = true) const;
// -------------------------------------------------------------------
void LoadDatabase();
private:
// -------------------------------------------------------------------
wxWindow* m_pWindow = nullptr;
wxDataViewTreeCtrl& m_Hives;
wxDataViewItem m_FavoritesHive;
wxTreeItemId m_TrashRoot;
wxTreeCtrl& m_Trash;
// -------------------------------------------------------------------
// friend class cHives;
// friend class cTrash;
};

File diff suppressed because it is too large Load Diff

View File

@ -20,211 +20,40 @@
#pragma once
#include "Database/Database.hpp"
#include "GUI/Library.hpp"
#include "GUI/Notebook.hpp"
#include "GUI/TransportControls.hpp"
#include "GUI/WaveformViewer.hpp"
#include "GUI/Notebook.hpp"
#include "Database/Database.hpp"
#include "Utility/Serialize.hpp"
#include "Utility/SH_Event.hpp"
#include "Utility/Event.hpp"
#include "SampleHiveConfig.hpp"
#include <memory>
#include <string>
#include <wx/button.h>
#include <wx/bmpbuttn.h>
#include <wx/checkbox.h>
#include <wx/collpane.h>
#include <wx/dataview.h>
#include <wx/dirctrl.h>
#include <wx/event.h>
#include <wx/frame.h>
#include <wx/fswatcher.h>
#include <wx/infobar.h>
#include <wx/listctrl.h>
#include <wx/mediactrl.h>
#include <wx/notebook.h>
#include <wx/panel.h>
#include <wx/setup.h>
#include <wx/srchctrl.h>
#include <wx/sizer.h>
#include <wx/slider.h>
#include <wx/splitter.h>
#include <wx/settings.h>
#include <wx/statbmp.h>
#include <wx/statusbr.h>
#include <wx/string.h>
#include <wx/tglbtn.h>
#include <wx/timer.h>
#include <wx/toplevel.h>
#include <wx/treebase.h>
#include <wx/treectrl.h>
#include <wx/window.h>
#include <taglib/tag.h>
#include <taglib/fileref.h>
#ifndef USE_SYSTEM_INCLUDE_PATH
#include <taglib/toolkit/tstring.h>
#else
#include <taglib/tstring.h>
#endif
struct FileInfo
{
wxString Path;
std::string Extension;
std::string Filename;
};
class MainFrame : public wxFrame
class cMainFrame : public wxFrame
{
public:
MainFrame();
~MainFrame();
private:
// -------------------------------------------------------------------
// Main Panel
// wxPanel* m_MainPanel;
wxBoxSizer* m_MainSizer;
// -------------------------------------------------------------------
// Hive bitmap icon for the statusbar
wxStaticBitmap* m_HiveBitmap;
// -------------------------------------------------------------------
// App statusbar
wxStatusBar* m_StatusBar;
// -------------------------------------------------------------------
// App menubar
wxMenuBar* m_MenuBar;
// -------------------------------------------------------------------
// Menu and menu items for the menubar
wxMenu* m_FileMenu;
wxMenu* m_EditMenu;
wxMenu* m_ViewMenu;
wxMenu* m_HelpMenu;
wxMenuItem* m_AddFile;
wxMenuItem* m_AddDirectory;
wxMenuItem* m_ToggleExtension;
wxMenuItem* m_ToggleMenuBar;
wxMenuItem* m_ToggleStatusBar;
// -------------------------------------------------------------------
// Splitter windows
wxSplitterWindow* m_TopSplitter;
wxSplitterWindow* m_BottomSplitter;
// -------------------------------------------------------------------
// Top panel controls
wxPanel* m_TopPanel;
cTransportControls* m_TransportControls;
cWaveformViewer* m_WaveformViewer;
// wxBoxSizer* m_TopSizer;
wxBoxSizer* m_TopPanelMainSizer;
// wxBoxSizer* m_WaveformDisplaySizer;
// -------------------------------------------------------------------
// Left panel controls
// wxPanel* m_BottomLeftPanel;
cNotebook* m_Notebook;
// wxPanel* m_HivesPanel;
// wxPanel* m_TrashPanel;
// wxNotebook* m_Notebook;
// wxBoxSizer* m_BottomLeftPanelMainSizer;
// wxBoxSizer* m_HivesMainSizer;
// wxBoxSizer* m_HivesFavoritesSizer;
// wxBoxSizer* m_HivesButtonSizer;
// wxBoxSizer* m_TrashMainSizer;
// wxBoxSizer* m_TrashItemSizer;
// wxBoxSizer* m_TrashButtonSizer;
// wxGenericDirCtrl* m_DirCtrl;
// wxDataViewTreeCtrl* m_Hives;
// wxDataViewItem favorites_hive;
// wxTreeItemId trash_root;
// wxTreeCtrl* m_Trash;
// wxButton* m_AddHiveButton;
// wxButton* m_RemoveHiveButton;
// wxButton* m_RestoreTrashedItemButton;
// -------------------------------------------------------------------
// Right panel controls
cLibrary* m_Library;
// wxPanel* m_BottomRightPanel;
// wxBoxSizer* m_BottomRightPanelMainSizer;
// wxSearchCtrl* m_SearchBox;
// wxInfoBar* m_InfoBar;
// wxDataViewListCtrl* m_Library;
// -------------------------------------------------------------------
// MediaCtrl
wxMediaCtrl* m_MediaCtrl;
// -------------------------------------------------------------------
// Timer
wxTimer* m_Timer;
// -------------------------------------------------------------------
std::unique_ptr<Database> m_Database;
// -------------------------------------------------------------------
// FileSystemWatcher
wxFileSystemWatcher* m_FsWatcher = nullptr;
// -------------------------------------------------------------------
wxLongLong m_LoopA, m_LoopB;
// -------------------------------------------------------------------
// wxSystemAppearance m_Theme = wxSystemSettings::GetAppearance();
private:
// -------------------------------------------------------------------
bool bFiltered = false;
bool bShowMenuBar = false;
bool bShowStatusBar = false;
bool bLoopPointsSet = false;
cMainFrame();
~cMainFrame();
private:
// -------------------------------------------------------------------
// Top panel control handlers
void OnMediaFinished(wxMediaEvent& event);
// void OnClickSettings(wxCommandEvent& event);
// -------------------------------------------------------------------
// DirCtrl event handlers
// void OnClickDirCtrl(wxCommandEvent& event);
// void OnDragFromDirCtrl(wxTreeEvent& event);
// -------------------------------------------------------------------
// TrashPane event handlers
// void OnShowTrashContextMenu(wxTreeEvent& event);
// void OnClickRestoreTrashItem(wxCommandEvent& event);
// void OnDragAndDropToTrash(wxDropFilesEvent& event);
// -------------------------------------------------------------------
// Hives panel button event handlers
// void OnDragAndDropToHives(wxDropFilesEvent& event);
// void OnClickAddHive(wxCommandEvent& event);
// void OnClickRemoveHive(wxCommandEvent& event);
// void OnShowHivesContextMenu(wxDataViewEvent& event);
// void OnHiveStartEditing(wxDataViewEvent& event);
// -------------------------------------------------------------------
// SearchCtrl event handlers
// void OnDoSearch(wxCommandEvent& event);
// void OnCancelSearch(wxCommandEvent& event);
// -------------------------------------------------------------------
// Library event handlers
// void OnClickLibrary(wxDataViewEvent& event);
// void OnDragAndDropToLibrary(wxDropFilesEvent& event);
// void OnDragFromLibrary(wxDataViewEvent& event);
// void OnShowLibraryContextMenu(wxDataViewEvent& event);
// void OnShowLibraryColumnHeaderContextMenu(wxDataViewEvent& event);
// -------------------------------------------------------------------
// App menu items event handlers
@ -254,34 +83,27 @@ class MainFrame : public wxFrame
// Timer update event handler
void UpdateElapsedTime(wxTimerEvent& event);
// -------------------------------------------------------------------
// void AddSamples(wxArrayString& files);
// void OnAutoImportDir(const wxString& pathToDirectory);
// -------------------------------------------------------------------
void PlaySample(const std::string& filepath, const std::string& sample, bool seek = false,
wxFileOffset where = NULL, wxSeekMode mode = wxFromStart);
// Recieve custom events
// -------------------------------------------------------------------
void OnRecieveLoopPoints(SampleHive::LoopPointsEvent& event);
void OnRecievePushStatusBarStatus(SampleHive::StatusBarStatusEvent& event);
void OnRecievePopStatusBarStatus(SampleHive::StatusBarStatusEvent& event);
void OnRecieveSetStatusBarStatus(SampleHive::StatusBarStatusEvent& event);
void OnRecieveInfoBarStatus(SampleHive::InfoBarMessageEvent& event);
void OnRecieveTimerStopStatus(SampleHive::TimerEvent& event);
void OnRecieveCallFunctionPlay(SampleHive::CallFunctionEvent& event);
void OnRecieveWaveformUpdateStatus(SampleHive::WaveformUpdateEvent& event);
void OnRecieveLoopPoints(SampleHive::cLoopPointsEvent& event);
void OnRecieveClearLoopPointsStatus(SampleHive::cLoopPointsEvent& event);
void OnRecieveLoopABButtonValueChange(SampleHive::cLoopPointsEvent& event);
void OnRecievePushStatusBarStatus(SampleHive::cStatusBarStatusEvent& event);
void OnRecievePopStatusBarStatus(SampleHive::cStatusBarStatusEvent& event);
void OnRecieveSetStatusBarStatus(SampleHive::cStatusBarStatusEvent& event);
void OnRecieveInfoBarStatus(SampleHive::cInfoBarMessageEvent& event);
void OnRecieveTimerStopStatus(SampleHive::cTimerEvent& event);
void OnRecieveCallFunctionPlay(SampleHive::cCallFunctionEvent& event);
void OnRecieveWaveformUpdateStatus(SampleHive::cWaveformUpdateEvent& event);
// -------------------------------------------------------------------
// void LoadDatabase();
// void RefreshDatabase();
void LoadDatabase();
void LoadConfigFile();
// -------------------------------------------------------------------
// Getters
// FileInfo GetFilenamePathAndExtension(const wxString& selected,
// bool checkExtension = true, bool doGetFilename = true) const;
// void RefreshDatabase();
// -------------------------------------------------------------------
// Directory watchers
@ -290,8 +112,6 @@ class MainFrame : public wxFrame
void AddWatchEntry(wxFSWPathType type, std::string path);
void OnFileSystemEvent(wxFileSystemWatcherEvent& event);
// wxString TagLibTowx(const TagLib::String& in);
// -------------------------------------------------------------------
// Call after frame creation
void SetAfterFrameCreate();
@ -299,8 +119,83 @@ class MainFrame : public wxFrame
// -------------------------------------------------------------------
void ClearLoopPoints();
// -------------------------------------------------------------------
void InitDatabase();
// -------------------------------------------------------------------
friend class App;
friend class cApp;
private:
// -------------------------------------------------------------------
// Main Panel
wxBoxSizer* m_pMainSizer = nullptr;
// -------------------------------------------------------------------
// Hive bitmap icon for the statusbar
wxStaticBitmap* m_pHiveBitmap = nullptr;
// -------------------------------------------------------------------
// App statusbar
wxStatusBar* m_pStatusBar = nullptr;
// -------------------------------------------------------------------
// App menubar
wxMenuBar* m_pMenuBar = nullptr;
// -------------------------------------------------------------------
// Menu and menu items for the menubar
wxMenu* m_pFileMenu = nullptr;
wxMenu* m_pEditMenu = nullptr;
wxMenu* m_pViewMenu = nullptr;
wxMenu* m_pHelpMenu = nullptr;
wxMenuItem* m_pAddFile = nullptr;
wxMenuItem* m_pAddDirectory = nullptr;
wxMenuItem* m_pToggleExtension = nullptr;
wxMenuItem* m_pToggleMenuBar = nullptr;
wxMenuItem* m_pToggleStatusBar = nullptr;
// -------------------------------------------------------------------
// Splitter windows
wxSplitterWindow* m_pTopSplitter = nullptr;
wxSplitterWindow* m_pBottomSplitter = nullptr;
// -------------------------------------------------------------------
// Top panel controls
wxPanel* m_pTopPanel = nullptr;
cWaveformViewer* m_pWaveformViewer = nullptr;
cTransportControls* m_pTransportControls = nullptr;
wxBoxSizer* m_pTopPanelMainSizer = nullptr;
// -------------------------------------------------------------------
// Left panel controls
cNotebook* m_pNotebook = nullptr;
// -------------------------------------------------------------------
// Right panel controls
cLibrary* m_pLibrary = nullptr;
// -------------------------------------------------------------------
// MediaCtrl
wxMediaCtrl* m_pMediaCtrl = nullptr;
// -------------------------------------------------------------------
// Timer
wxTimer* m_pTimer = nullptr;
// -------------------------------------------------------------------
std::unique_ptr<cDatabase> m_pDatabase = nullptr;
// -------------------------------------------------------------------
// FileSystemWatcher
wxFileSystemWatcher* m_pFsWatcher = nullptr;
// -------------------------------------------------------------------
wxLongLong m_LoopA, m_LoopB;
private:
// -------------------------------------------------------------------
bool m_bFiltered = false;
bool m_bShowMenuBar = false;
bool m_bShowStatusBar = false;
bool m_bLoopPointsSet = false;
};

View File

@ -1,3 +1,23 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "GUI/Notebook.hpp"
#include "GUI/DirectoryBrowser.hpp"
#include "GUI/Hives.hpp"
@ -9,8 +29,8 @@ cNotebook::cNotebook(wxWindow* window)
m_pNotebook = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_TOP);
m_DirectoryBrowser = new cDirectoryBrowser(m_pNotebook);
m_HivesPanel = new cHivesPanel(m_pNotebook, *m_pListCtrl);
m_TrashPanel = new cTrashPanel(m_pNotebook, *m_pListCtrl);
m_HivesPanel = new cHivesPanel(m_pNotebook);
m_TrashPanel = new cTrashPanel(m_pNotebook);
// Adding the pages to wxNotebook
m_pNotebook->AddPage(m_DirectoryBrowser, _("Browse"), false);

View File

@ -1,3 +1,23 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "GUI/DirectoryBrowser.hpp"
@ -21,8 +41,6 @@ class cNotebook : public wxPanel
cHivesPanel* GetHivesPanel() const { return m_HivesPanel; }
cTrashPanel* GetTrashPanel() const { return m_TrashPanel; }
void SetListCtrlObject(wxDataViewListCtrl& listCtrl) { m_pListCtrl = &listCtrl; }
private:
// -------------------------------------------------------------------
wxNotebook* m_pNotebook = nullptr;
@ -32,6 +50,4 @@ class cNotebook : public wxPanel
cDirectoryBrowser* m_DirectoryBrowser = nullptr;
cHivesPanel* m_HivesPanel = nullptr;
cTrashPanel* m_TrashPanel = nullptr;
wxDataViewListCtrl* m_pListCtrl;
};

View File

@ -1,15 +1,38 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "GUI/SearchBar.hpp"
#include "GUI/ListCtrl.hpp"
#include "Database/Database.hpp"
#include "Utility/ControlIDs.hpp"
#include "Utility/HiveData.hpp"
#include "Utility/Serialize.hpp"
#include "Utility/Paths.hpp"
#include "Utility/Log.hpp"
cSearchBar::cSearchBar(wxWindow* window, wxDataViewListCtrl& listCtrl)
: wxSearchCtrl(window, BC_Search, _("Search for samples.."),
#include <exception>
cSearchBar::cSearchBar(wxWindow* window)
: wxSearchCtrl(window, SampleHive::ID::BC_Search, _("Search for samples.."),
wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER),
m_pWindow(window), m_ListCtrl(listCtrl)
m_pWindow(window)
{
// Set minimum and maximum size of m_SearchBox
// so it doesn't expand too wide when resizing the main frame.
@ -19,16 +42,15 @@ cSearchBar::cSearchBar(wxWindow* window, wxDataViewListCtrl& listCtrl)
ShowSearchButton(true);
ShowCancelButton(true);
Bind(wxEVT_TEXT, &cSearchBar::OnDoSearch, this, BC_Search);
Bind(wxEVT_SEARCHCTRL_SEARCH_BTN, &cSearchBar::OnDoSearch, this, BC_Search);
Bind(wxEVT_SEARCHCTRL_CANCEL_BTN, &cSearchBar::OnCancelSearch, this, BC_Search);
Bind(wxEVT_TEXT, &cSearchBar::OnDoSearch, this, SampleHive::ID::BC_Search);
Bind(wxEVT_SEARCHCTRL_SEARCH_BTN, &cSearchBar::OnDoSearch, this, SampleHive::ID::BC_Search);
Bind(wxEVT_SEARCHCTRL_CANCEL_BTN, &cSearchBar::OnCancelSearch, this, SampleHive::ID::BC_Search);
}
void cSearchBar::OnDoSearch(wxCommandEvent& event)
{
Serializer serializer;
Database db;
// cListCtrl m_ListCtrl(m_pWindow);
SampleHive::cSerializer serializer;
cDatabase db;
const auto search = this->GetValue().ToStdString();
@ -43,19 +65,19 @@ void cSearchBar::OnDoSearch(wxCommandEvent& event)
}
else
{
m_ListCtrl.DeleteAllItems();
SampleHive::cHiveData::Get().ListCtrlDeleteAllItems();
std::cout << search << std::endl;
for (const auto& data : dataset)
{
m_ListCtrl.AppendItem(data);
SampleHive::cHiveData::Get().ListCtrlAppendItem(data);
}
}
}
catch (...)
catch (std::exception& e)
{
std::cerr << "Error loading data." << std::endl;
SH_LOG_ERROR("Error loading data. {}", e.what());
}
}

View File

@ -1,3 +1,23 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <wx/dataview.h>
@ -6,7 +26,7 @@
class cSearchBar : public wxSearchCtrl
{
public:
cSearchBar(wxWindow* window, wxDataViewListCtrl& listCtrl);
cSearchBar(wxWindow* window);
~cSearchBar();
public:
@ -21,6 +41,4 @@ class cSearchBar : public wxSearchCtrl
private:
// -------------------------------------------------------------------
wxWindow* m_pWindow = nullptr;
wxDataViewListCtrl& m_ListCtrl;
};

View File

@ -1,79 +1,91 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "GUI/TransportControls.hpp"
#include "GUI/Dialogs/Settings.hpp"
#include "Utility/ControlIDs.hpp"
#include "Utility/SH_Event.hpp"
#include "Utility/Event.hpp"
#include "Utility/HiveData.hpp"
#include "Utility/Sample.hpp"
#include "Utility/Signal.hpp"
#include "Utility/Serialize.hpp"
#include "Utility/Log.hpp"
#include "Utility/Paths.hpp"
#include "Utility/Utils.hpp"
cTransportControls::cTransportControls(wxWindow* window, wxDataViewListCtrl& library,
wxMediaCtrl& mediaCtrl, wxTimer& timer)
cTransportControls::cTransportControls(wxWindow* window, wxMediaCtrl& mediaCtrl)
: wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxNO_BORDER),
m_Library(library), m_MediaCtrl(mediaCtrl), m_Timer(timer)
m_MediaCtrl(mediaCtrl)
{
m_pMainSizer = new wxBoxSizer(wxHORIZONTAL);
// Looping region controls
if (m_Theme.IsDark())
m_pLoopABButton = new wxBitmapToggleButton(this, BC_LoopABButton,
static_cast<wxString>(ICON_AB_LIGHT_16px),
m_pLoopABButton = new wxBitmapToggleButton(this, SampleHive::ID::BC_LoopABButton, static_cast<wxString>(ICON_AB_LIGHT_16px),
wxDefaultPosition, wxDefaultSize, 0);
else
m_pLoopABButton = new wxBitmapToggleButton(this, BC_LoopABButton,
static_cast<wxString>(ICON_AB_DARK_16px),
m_pLoopABButton = new wxBitmapToggleButton(this, SampleHive::ID::BC_LoopABButton, static_cast<wxString>(ICON_AB_DARK_16px),
wxDefaultPosition, wxDefaultSize, 0);
m_pLoopABButton->SetToolTip(_("Loop selected region"));
// Autoplay checkbox
m_pAutoPlayCheck = new wxCheckBox(this, BC_Autoplay, _("Autoplay"),
m_pAutoPlayCheck = new wxCheckBox(this, SampleHive::ID::BC_Autoplay, _("Autoplay"),
wxDefaultPosition, wxDefaultSize, wxCHK_2STATE);
m_pAutoPlayCheck->SetToolTip(_("Autoplay"));
// Volume slider
m_pVolumeSlider = new wxSlider(this, BC_Volume, 100, 0, 100,
wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL);
m_pVolumeSlider = new wxSlider(this, SampleHive::ID::BC_Volume, 100, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL);
m_pVolumeSlider->SetToolTip(_("Volume"));
m_pVolumeSlider->SetMinSize(wxSize(120, -1));
m_pVolumeSlider->SetMaxSize(wxSize(120, -1));
// Sample position static text
m_pSamplePosition = new wxStaticText(this, BC_SamplePosition, "--:--/--:--",
m_pSamplePosition = new wxStaticText(this, SampleHive::ID::BC_SamplePosition, "--:--/--:--",
wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL);
// Transport control buttons
if (m_Theme.IsDark())
{
m_pPlayButton = new wxBitmapButton(this, BC_Play,
wxBitmapBundle::FromBitmap(static_cast<wxString>
(ICON_PLAY_LIGHT_16px)),
m_pPlayButton = new wxBitmapButton(this, SampleHive::ID::BC_Play,
wxBitmapBundle::FromBitmap(static_cast<wxString>(ICON_PLAY_LIGHT_16px)),
wxDefaultPosition, wxDefaultSize, 0);
m_pLoopButton = new wxBitmapToggleButton(this, BC_Loop,
static_cast<wxString>(ICON_LOOP_LIGHT_16px),
m_pLoopButton = new wxBitmapToggleButton(this, SampleHive::ID::BC_Loop, static_cast<wxString>(ICON_LOOP_LIGHT_16px),
wxDefaultPosition, wxDefaultSize, 0);
m_pStopButton = new wxBitmapButton(this, BC_Stop,
wxBitmapBundle::FromBitmap(static_cast<wxString>
(ICON_STOP_LIGHT_16px)),
m_pStopButton = new wxBitmapButton(this, SampleHive::ID::BC_Stop,
wxBitmapBundle::FromBitmap(static_cast<wxString>(ICON_STOP_LIGHT_16px)),
wxDefaultPosition, wxDefaultSize, 0);
m_pMuteButton = new wxBitmapToggleButton(this, BC_Mute,
static_cast<wxString>(ICON_MUTE_LIGHT_16px),
m_pMuteButton = new wxBitmapToggleButton(this, SampleHive::ID::BC_Mute, static_cast<wxString>(ICON_MUTE_LIGHT_16px),
wxDefaultPosition, wxDefaultSize, 0);
}
else
{
m_pPlayButton = new wxBitmapButton(this, BC_Play,
wxBitmapBundle::FromBitmap(static_cast<wxString>
(ICON_PLAY_DARK_16px)),
m_pPlayButton = new wxBitmapButton(this, SampleHive::ID::BC_Play,
wxBitmapBundle::FromBitmap(static_cast<wxString>(ICON_PLAY_DARK_16px)),
wxDefaultPosition, wxDefaultSize, 0);
m_pLoopButton = new wxBitmapToggleButton(this, BC_Loop,
static_cast<wxString>(ICON_LOOP_DARK_16px),
m_pLoopButton = new wxBitmapToggleButton(this, SampleHive::ID::BC_Loop, static_cast<wxString>(ICON_LOOP_DARK_16px),
wxDefaultPosition, wxDefaultSize, 0);
m_pStopButton = new wxBitmapButton(this, BC_Stop,
wxBitmapBundle::FromBitmap(static_cast<wxString>
(ICON_STOP_DARK_16px)),
m_pStopButton = new wxBitmapButton(this, SampleHive::ID::BC_Stop,
wxBitmapBundle::FromBitmap(static_cast<wxString>(ICON_STOP_DARK_16px)),
wxDefaultPosition, wxDefaultSize, 0);
m_pMuteButton = new wxBitmapToggleButton(this, BC_Mute,
static_cast<wxString>(ICON_MUTE_DARK_16px),
m_pMuteButton = new wxBitmapToggleButton(this, SampleHive::ID::BC_Mute, static_cast<wxString>(ICON_MUTE_DARK_16px),
wxDefaultPosition, wxDefaultSize, 0);
}
@ -82,15 +94,14 @@ cTransportControls::cTransportControls(wxWindow* window, wxDataViewListCtrl& lib
m_pStopButton->SetToolTip(_("Stop"));
m_pMuteButton->SetToolTip(_("Mute"));
// m_pSettingsButton = new wxButton(this, BC_Settings, _("Settings"),
// wxDefaultPosition, wxDefaultSize, 0);
// m_pSettingsButton->SetToolTip(_("Settings"));
m_pSettingsButton = new wxButton(this, SampleHive::ID::BC_Settings, _("Settings"), wxDefaultPosition, wxDefaultSize, 0);
m_pSettingsButton->SetToolTip(_("Settings"));
m_pMainSizer->Add(m_pPlayButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_pMainSizer->Add(m_pStopButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_pMainSizer->Add(m_pLoopButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_pMainSizer->Add(m_pLoopABButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
// m_pMainSizer->Add(m_pSettingsButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_pMainSizer->Add(m_pSettingsButton, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_pMainSizer->Add(0,0,1, wxALL | wxEXPAND, 0);
m_pMainSizer->Add(m_pSamplePosition, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_pMainSizer->Add(30,0,0, wxALL | wxEXPAND, 0);
@ -103,37 +114,61 @@ cTransportControls::cTransportControls(wxWindow* window, wxDataViewListCtrl& lib
m_pMainSizer->SetSizeHints(this);
m_pMainSizer->Layout();
Bind(wxEVT_BUTTON, &cTransportControls::OnClickPlay, this, BC_Play);
Bind(wxEVT_TOGGLEBUTTON, &cTransportControls::OnClickLoop, this, BC_Loop);
Bind(wxEVT_BUTTON, &cTransportControls::OnClickStop, this, BC_Stop);
Bind(wxEVT_TOGGLEBUTTON, &cTransportControls::OnClickMute, this, BC_Mute);
// Bind(wxEVT_BUTTON, &Controls::OnClickSettings, this, BC_Settings);
Bind(wxEVT_CHECKBOX, &cTransportControls::OnCheckAutoplay, this, BC_Autoplay);
Bind(wxEVT_SCROLL_THUMBTRACK, &cTransportControls::OnSlideVolume, this, BC_Volume);
Bind(wxEVT_SCROLL_THUMBRELEASE, &cTransportControls::OnReleaseVolumeSlider, this, BC_Volume);
Bind(wxEVT_BUTTON, &cTransportControls::OnClickPlay, this, SampleHive::ID::BC_Play);
Bind(wxEVT_TOGGLEBUTTON, &cTransportControls::OnClickLoop, this, SampleHive::ID::BC_Loop);
Bind(wxEVT_BUTTON, &cTransportControls::OnClickStop, this, SampleHive::ID::BC_Stop);
Bind(wxEVT_TOGGLEBUTTON, &cTransportControls::OnClickMute, this, SampleHive::ID::BC_Mute);
Bind(wxEVT_BUTTON, &cTransportControls::OnClickSettings, this, SampleHive::ID::BC_Settings);
Bind(wxEVT_CHECKBOX, &cTransportControls::OnCheckAutoplay, this, SampleHive::ID::BC_Autoplay);
Bind(wxEVT_SCROLL_THUMBTRACK, &cTransportControls::OnSlideVolume, this, SampleHive::ID::BC_Volume);
Bind(wxEVT_SCROLL_THUMBRELEASE, &cTransportControls::OnReleaseVolumeSlider, this, SampleHive::ID::BC_Volume);
// Load control values from config file
LoadConfigFile();
}
void cTransportControls::OnClickSettings(wxCommandEvent& event)
{
cSettings* settings = new cSettings(this);
switch (settings->ShowModal())
{
case wxID_OK:
if (settings->CanAutoImport())
{
SampleHive::cUtils::Get().OnAutoImportDir(settings->GetImportDirPath(), this);
// RefreshDatabase();
}
if (settings->IsWaveformColourChanged())
{
SampleHive::cSignal::SendWaveformUpdateStatus(*this);
}
break;
case wxID_CANCEL:
break;
default:
return;
}
}
void cTransportControls::OnClickPlay(wxCommandEvent& event)
{
m_bStopped = false;
int selected_row = m_Library.GetSelectedRow();
int selected_row = SampleHive::cHiveData::Get().GetListCtrlSelectedRow();
if (selected_row < 0)
return;
wxString selection = m_Library.GetTextValue(selected_row, 1);
wxString selection = SampleHive::cHiveData::Get().GetListCtrlTextValue(selected_row, 1);
// Send custom event to MainFrame to play the sample
SampleHive::Signal::SendCallFunctionPlay(selection, *this);
SampleHive::cSignal::SendCallFunctionPlay(selection, false, *this);
}
void cTransportControls::OnClickLoop(wxCommandEvent& event)
{
Serializer serializer;
SampleHive::cSerializer serializer;
m_bLoop = m_pLoopButton->GetValue();
@ -148,17 +183,17 @@ void cTransportControls::OnClickStop(wxCommandEvent& event)
m_bStopped = true;
// Send custom event to MainFrame to stop the timer
SampleHive::Signal::SendTimerStopStatus(*this);
SampleHive::cSignal::SendTimerStopStatus(*this);
m_pSamplePosition->SetLabel("--:--/--:--");
// Send custom event to MainFrame to set the statusbar status
SampleHive::Signal::SendSetStatusBarStatus(_("Stopped"), 1, *this);
SampleHive::cSignal::SendSetStatusBarStatus(_("Stopped"), 1, *this);
}
void cTransportControls::OnClickMute(wxCommandEvent& event)
{
Serializer serializer;
SampleHive::cSerializer serializer;
if (m_pMuteButton->GetValue())
{
@ -178,7 +213,7 @@ void cTransportControls::OnClickMute(wxCommandEvent& event)
void cTransportControls::OnCheckAutoplay(wxCommandEvent& event)
{
Serializer serializer;
SampleHive::cSerializer serializer;
if (m_pAutoPlayCheck->GetValue())
{
@ -199,39 +234,37 @@ void cTransportControls::OnSlideVolume(wxScrollEvent& event)
m_MediaCtrl.SetVolume(double(m_pVolumeSlider->GetValue()) / 100);
// Send custom event to MainFrame to push status to statusbar
SampleHive::Signal::SendPushStatusBarStatus(wxString::Format(_("Volume: %d"),
m_pVolumeSlider->GetValue()), 1, *this);
SampleHive::cSignal::SendPushStatusBarStatus(wxString::Format(_("Volume: %d"), m_pVolumeSlider->GetValue()), 1, *this);
}
void cTransportControls::OnReleaseVolumeSlider(wxScrollEvent& event)
{
Serializer serializer;
SampleHive::cSerializer serializer;
serializer.SerializeMediaVolume(m_pVolumeSlider->GetValue());
int selected_row = m_Library.GetSelectedRow();
int selected_row = SampleHive::cHiveData::Get().GetListCtrlSelectedRow();
if (selected_row < 0)
return;
wxString selection = m_Library.GetTextValue(selected_row, 1);
wxString selection = SampleHive::cHiveData::Get().GetListCtrlTextValue(selected_row, 1);
// Wait a second then remove the status from statusbar
wxSleep(1);
// Send custom event to MainFrame to pop status from statusbar
SampleHive::Signal::SendPopStatusBarStatus(1, *this);
SampleHive::cSignal::SendPopStatusBarStatus(1, *this);
if (m_MediaCtrl.GetState() == wxMEDIASTATE_STOPPED)
SampleHive::Signal::SendSetStatusBarStatus(_("Stopped"), 1, *this);
SampleHive::cSignal::SendSetStatusBarStatus(_("Stopped"), 1, *this);
else
SampleHive::Signal::SendPushStatusBarStatus(wxString::Format(_("Now playing: %s"), selection),
1, *this);
SampleHive::cSignal::SendPushStatusBarStatus(wxString::Format(_("Now playing: %s"), selection), 1, *this);
}
void cTransportControls::LoadConfigFile()
{
Serializer serializer;
SampleHive::cSerializer serializer;
SH_LOG_INFO("Reading transport control values..");

View File

@ -1,9 +1,28 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <wx/bmpbuttn.h>
#include <wx/button.h>
#include <wx/checkbox.h>
#include <wx/dataview.h>
#include <wx/event.h>
#include <wx/mediactrl.h>
#include <wx/settings.h>
@ -12,7 +31,6 @@
#include <wx/stattext.h>
#include <wx/tglbtn.h>
#include <wx/panel.h>
#include <wx/timer.h>
#include <wx/version.h>
#include <wx/window.h>
@ -20,7 +38,7 @@ class cTransportControls : public wxPanel
{
public:
// -------------------------------------------------------------------
cTransportControls(wxWindow* window, wxDataViewListCtrl& library, wxMediaCtrl& mediaCtrl, wxTimer& timer);
cTransportControls(wxWindow* window, wxMediaCtrl& mediaCtrl);
~cTransportControls();
public:
@ -65,11 +83,11 @@ class cTransportControls : public wxPanel
// Load control values from config file
void LoadConfigFile();
void OnAutoImportDir(const wxString& pathToDirectory);
private:
// -------------------------------------------------------------------
wxDataViewListCtrl& m_Library;
wxMediaCtrl& m_MediaCtrl;
wxTimer& m_Timer;
private:
// -------------------------------------------------------------------

View File

@ -1,25 +1,47 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "GUI/Trash.hpp"
#include "GUI/Hives.hpp"
#include "GUI/ListCtrl.hpp"
#include "Database/Database.hpp"
#include "Utility/ControlIDs.hpp"
#include "Utility/HiveData.hpp"
#include "Utility/Log.hpp"
#include "Utility/Paths.hpp"
#include "Utility/Signal.hpp"
#include "Utility/Serialize.hpp"
#include "Utility/Utils.hpp"
#include <exception>
#include <wx/menu.h>
#include <wx/msgdlg.h>
cTrashPanel::cTrashPanel(wxWindow* window, wxDataViewListCtrl& listCtrl)
cTrashPanel::cTrashPanel(wxWindow* window)
: wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
m_pWindow(window), m_ListCtrl(listCtrl)
m_pWindow(window)
{
m_pMainSizer = new wxBoxSizer(wxVERTICAL);
m_pTrashSizer = new wxBoxSizer(wxVERTICAL);
m_pButtonSizer = new wxBoxSizer(wxHORIZONTAL);
m_pTrash = new wxTreeCtrl(this, BC_Trash, wxDefaultPosition, wxDefaultSize,
m_pTrash = new wxTreeCtrl(this, SampleHive::ID::BC_Trash, wxDefaultPosition, wxDefaultSize,
wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_MULTIPLE);
// Setting m_Trash to accept files to be dragged and dropped on it
@ -27,7 +49,7 @@ cTrashPanel::cTrashPanel(wxWindow* window, wxDataViewListCtrl& listCtrl)
m_pTrashSizer->Add(m_pTrash, wxSizerFlags(1).Expand());
m_pRestoreTrashedItemButton = new wxButton(this, BC_RestoreTrashedItem, _("Restore sample"),
m_pRestoreTrashedItemButton = new wxButton(this, SampleHive::ID::BC_RestoreTrashedItem, _("Restore sample"),
wxDefaultPosition, wxDefaultSize, 0);
m_pRestoreTrashedItemButton->SetToolTip(_("Restore selected sample"));
@ -37,8 +59,8 @@ cTrashPanel::cTrashPanel(wxWindow* window, wxDataViewListCtrl& listCtrl)
m_TrashRoot = m_pTrash->AddRoot("Trash");
m_pTrash->Connect(wxEVT_DROP_FILES, wxDropFilesEventHandler(cTrashPanel::OnDragAndDropToTrash), NULL, this);
Bind(wxEVT_TREE_ITEM_RIGHT_CLICK, &cTrashPanel::OnShowTrashContextMenu, this, BC_Trash);
Bind(wxEVT_BUTTON, &cTrashPanel::OnClickRestoreTrashItem, this, BC_RestoreTrashedItem);
Bind(wxEVT_TREE_ITEM_RIGHT_CLICK, &cTrashPanel::OnShowTrashContextMenu, this, SampleHive::ID::BC_Trash);
Bind(wxEVT_BUTTON, &cTrashPanel::OnClickRestoreTrashItem, this, SampleHive::ID::BC_RestoreTrashedItem);
m_pMainSizer->Add(m_pTrashSizer, wxSizerFlags(1).Expand());
m_pMainSizer->Add(m_pButtonSizer, wxSizerFlags(0).Expand());
@ -52,10 +74,8 @@ cTrashPanel::cTrashPanel(wxWindow* window, wxDataViewListCtrl& listCtrl)
void cTrashPanel::OnDragAndDropToTrash(wxDropFilesEvent& event)
{
Serializer serializer;
Database db;
cHivesPanel hives(m_pWindow, m_ListCtrl);
// cListCtrl m_ListCtrl.m_pWindow);
SampleHive::cSerializer serializer;
cDatabase db;
if (event.GetNumberOfFiles() > 0)
{
@ -63,8 +83,7 @@ void cTrashPanel::OnDragAndDropToTrash(wxDropFilesEvent& event)
wxArrayString files;
wxDataViewItemArray items;
int rows = m_ListCtrl.GetSelections(items);
// int rows = 2;
int rows = SampleHive::cHiveData::Get().GetListCtrlSelections(items);
wxString msg;
@ -73,13 +92,13 @@ void cTrashPanel::OnDragAndDropToTrash(wxDropFilesEvent& event)
for (int i = 0; i < rows; i++)
{
int item_row = m_ListCtrl.ItemToRow(items[i]);
int item_row = SampleHive::cHiveData::Get().GetListCtrlRowFromItem(items, i);
wxString text_value = m_ListCtrl.GetTextValue(item_row, 1);
wxString text_value = SampleHive::cHiveData::Get().GetListCtrlTextValue(item_row, 1);
std::string multi_selection = serializer.DeserializeShowFileExtension() ?
m_ListCtrl.GetTextValue(item_row, 1).BeforeLast('.').ToStdString() :
m_ListCtrl.GetTextValue(item_row, 1).ToStdString() ;
SampleHive::cHiveData::Get().GetListCtrlTextValue(item_row, 1).BeforeLast('.').ToStdString() :
SampleHive::cHiveData::Get().GetListCtrlTextValue(item_row, 1).ToStdString() ;
file_data.AddFile(multi_selection);
@ -87,25 +106,25 @@ void cTrashPanel::OnDragAndDropToTrash(wxDropFilesEvent& event)
if (db.GetFavoriteColumnValueByFilename(files[i].ToStdString()))
{
m_ListCtrl.SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), item_row, 0);
SampleHive::cHiveData::Get().ListCtrlSetVariant(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), item_row, 0);
db.UpdateFavoriteColumn(files[i].ToStdString(), 0);
for (int j = 0; j < hives.GetHivesObject()->GetChildCount(root); j++)
for (int j = 0; j < SampleHive::cHiveData::Get().GetHiveChildCount(root); j++)
{
container = hives.GetHivesObject()->GetNthChild(root, j);
container = SampleHive::cHiveData::Get().GetHiveNthChild(root, j);
for (int k = 0; k < hives.GetHivesObject()->GetChildCount(container); k++)
for (int k = 0; k < SampleHive::cHiveData::Get().GetHiveChildCount(container); k++)
{
child = hives.GetHivesObject()->GetNthChild(container, k);
child = SampleHive::cHiveData::Get().GetHiveNthChild(container, k);
wxString child_text = serializer.DeserializeShowFileExtension() ?
hives.GetHivesObject()->GetItemText(child).BeforeLast('.') :
hives.GetHivesObject()->GetItemText(child);
SampleHive::cHiveData::Get().GetHiveItemText(child).BeforeLast('.') :
SampleHive::cHiveData::Get().GetHiveItemText(child);
if (child_text == files[i])
{
hives.GetHivesObject()->DeleteItem(child);
SampleHive::cHiveData::Get().HiveDeleteItem(child);
break;
}
}
@ -114,39 +133,37 @@ void cTrashPanel::OnDragAndDropToTrash(wxDropFilesEvent& event)
db.UpdateTrashColumn(files[i].ToStdString(), 1);
db.UpdateHiveName(files[i].ToStdString(),
hives.GetHivesObject()->GetItemText(hives.GetFavoritesHive()).ToStdString());
SampleHive::cHiveData::Get().GetHiveItemText(SampleHive::cHiveData::Get().GetFavoritesHive()).ToStdString());
m_pTrash->AppendItem(m_TrashRoot, text_value);
m_ListCtrl.DeleteItem(item_row);
SampleHive::cHiveData::Get().ListCtrlDeleteItem(item_row);
msg = wxString::Format(_("%s sent to trash"), text_value);
}
if (!msg.IsEmpty())
SampleHive::Signal::SendInfoBarMessage(msg, wxICON_ERROR, *this);
// m_InfoBar->ShowMessage(msg, wxICON_ERROR);
SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_ERROR, *this);
}
}
void cTrashPanel::OnShowTrashContextMenu(wxTreeEvent& event)
{
Serializer serializer;
Database db;
// cListCtrl m_ListCtrl.m_pWindow);
SampleHive::cSerializer serializer;
cDatabase db;
wxTreeItemId selected_trashed_item = event.GetItem();
wxMenu menu;
menu.Append(MN_DeleteTrash, _("Delete from database"), _("Delete the selected sample(s) from database"));
menu.Append(MN_RestoreTrashedItem, _("Restore sample"), _("Restore the selected sample(s) back to library"));
menu.Append(SampleHive::ID::MN_DeleteTrash, _("Delete from database"), _("Delete the selected sample(s) from database"));
menu.Append(SampleHive::ID::MN_RestoreTrashedItem, _("Restore sample"), _("Restore the selected sample(s) back to library"));
if (selected_trashed_item.IsOk())
{
switch (m_pTrash->GetPopupMenuSelectionFromUser(menu, event.GetPoint()))
{
case MN_DeleteTrash:
case SampleHive::ID::MN_DeleteTrash:
{
wxString trashed_item_name = serializer.DeserializeShowFileExtension() ?
m_pTrash->GetItemText(selected_trashed_item).BeforeLast('.') :
@ -159,7 +176,7 @@ void cTrashPanel::OnShowTrashContextMenu(wxTreeEvent& event)
SH_LOG_INFO("{} deleted from trash and databse", trashed_item_name);
}
break;
case MN_RestoreTrashedItem:
case SampleHive::ID::MN_RestoreTrashedItem:
{
wxArrayTreeItemIds selected_item_ids;
m_pTrash->GetSelections(selected_item_ids);
@ -174,7 +191,7 @@ void cTrashPanel::OnShowTrashContextMenu(wxTreeEvent& event)
{
selected_item_text = m_pTrash->GetItemText(selected_item_ids[i]);
// filename = GetFilenamePathAndExtension(selected_item_text).Filename;
filename = SampleHive::cUtils::Get().GetFilenamePathAndExtension(selected_item_text).Filename;
file_data.AddFile(filename);
@ -198,13 +215,13 @@ void cTrashPanel::OnShowTrashContextMenu(wxTreeEvent& event)
{
for (auto data : dataset)
{
m_ListCtrl.AppendItem(data);
SampleHive::cHiveData::Get().ListCtrlAppendItem(data);
}
}
}
catch (...)
catch (std::exception& e)
{
std::cerr << "Error loading data." << std::endl;
SH_LOG_ERROR("Error loading data. {}", e.what());
}
m_pTrash->Delete(selected_item_ids[i]);
@ -221,9 +238,8 @@ void cTrashPanel::OnShowTrashContextMenu(wxTreeEvent& event)
void cTrashPanel::OnClickRestoreTrashItem(wxCommandEvent& event)
{
Serializer serializer;
Database db;
// cListCtrl m_ListCtrl.m_pWindow);
SampleHive::cSerializer serializer;
cDatabase db;
wxArrayTreeItemIds selected_item_ids;
m_pTrash->GetSelections(selected_item_ids);
@ -242,8 +258,7 @@ void cTrashPanel::OnClickRestoreTrashItem(wxCommandEvent& event)
if (selected_item_ids.IsEmpty())
{
wxMessageBox(_("No item selected, try selected a item first."), wxMessageBoxCaptionStr,
wxOK | wxCENTRE, this);
wxMessageBox(_("No item selected, try selected a item first."), wxMessageBoxCaptionStr, wxOK | wxCENTRE, this);
return;
}
@ -251,7 +266,7 @@ void cTrashPanel::OnClickRestoreTrashItem(wxCommandEvent& event)
{
selected_item_text = m_pTrash->GetItemText(selected_item_ids[i]);
// filename = GetFilenamePathAndExtension(selected_item_text).Filename;
filename = SampleHive::cUtils::Get().GetFilenamePathAndExtension(selected_item_text).Filename;
file_data.AddFile(filename);
@ -273,13 +288,13 @@ void cTrashPanel::OnClickRestoreTrashItem(wxCommandEvent& event)
{
for (auto data : dataset)
{
m_ListCtrl.AppendItem(data);
SampleHive::cHiveData::Get().ListCtrlAppendItem(data);
}
}
}
catch (...)
catch (std::exception& e)
{
std::cerr << "Error loading data." << std::endl;
SH_LOG_ERROR("Error loading data. {}", e.what());
}
m_pTrash->Delete(selected_item_ids[i]);

View File

@ -1,3 +1,23 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <wx/button.h>
@ -11,12 +31,12 @@
class cTrashPanel : public wxPanel
{
public:
cTrashPanel(wxWindow* window, wxDataViewListCtrl& listCtrl);
cTrashPanel(wxWindow* window);
~cTrashPanel();
public:
wxTreeCtrl* GetTrashObject() { return m_pTrash; }
wxTreeItemId GetTrashRoot() { return m_TrashRoot; }
wxTreeItemId& GetTrashRoot() { return m_TrashRoot; }
private:
// -------------------------------------------------------------------
@ -35,6 +55,4 @@ class cTrashPanel : public wxPanel
private:
wxWindow* m_pWindow = nullptr;
wxDataViewListCtrl& m_ListCtrl;
// friend class cListCtrl;
};

View File

@ -19,12 +19,13 @@
*/
#include "GUI/WaveformViewer.hpp"
#include "Utility/Serialize.hpp"
#include "Utility/Signal.hpp"
#include "Utility/Tags.hpp"
#include "Utility/SH_Event.hpp"
#include "Utility/HiveData.hpp"
#include "Utility/Log.hpp"
#include "Utility/Paths.hpp"
#include "Utility/Serialize.hpp"
#include "Utility/Event.hpp"
#include "Utility/Signal.hpp"
#include "Utility/Tags.hpp"
#include <vector>
@ -38,11 +39,9 @@
#include <sndfile.hh>
cWaveformViewer::cWaveformViewer(wxWindow* window, wxDataViewListCtrl& library,
wxMediaCtrl& mediaCtrl, Database& database)
: wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize,
wxTAB_TRAVERSAL | wxNO_BORDER | wxFULL_REPAINT_ON_RESIZE),
m_Window(window), m_Database(database), m_Library(library), m_MediaCtrl(mediaCtrl)
cWaveformViewer::cWaveformViewer(wxWindow* window, wxMediaCtrl& mediaCtrl, cDatabase& database)
: wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxNO_BORDER | wxFULL_REPAINT_ON_RESIZE),
m_Window(window), m_Database(database), m_MediaCtrl(mediaCtrl)
{
this->SetDoubleBuffered(true);
@ -110,7 +109,7 @@ void cWaveformViewer::OnPaint(wxPaintEvent& event)
bAreaSelected = true;
// SendLoopPoints();
SampleHive::Signal::SendLoopPoints(CalculateLoopPoints(), *this);
SampleHive::cSignal::SendLoopPoints(CalculateLoopPoints(), *this);
}
else
bAreaSelected = false;
@ -118,15 +117,15 @@ void cWaveformViewer::OnPaint(wxPaintEvent& event)
void cWaveformViewer::RenderPlayhead(wxDC& dc)
{
int selected_row = m_Library.GetSelectedRow();
int selected_row = SampleHive::cHiveData::Get().GetListCtrlSelectedRow();
if (selected_row < 0)
return;
wxString selected = m_Library.GetTextValue(selected_row, 1);
wxString selected = SampleHive::cHiveData::Get().GetListCtrlTextValue(selected_row, 1);
std::string path = m_Database.GetSamplePathByFilename(selected.BeforeLast('.').ToStdString());
Tags tags(path);
SampleHive::cTags tags(path);
int length = tags.GetAudioInfo().length;
SH_LOG_DEBUG("Sample length: {}", length);
@ -150,23 +149,21 @@ void cWaveformViewer::RenderPlayhead(wxDC& dc)
// Draw the line
dc.SetPen(wxPen(m_PlayheadColour, 2, wxPENSTYLE_SOLID));
dc.DrawLine(line_pos, this->GetSize().GetHeight() - (this->GetSize().GetHeight() - 1),
line_pos, this->GetSize().GetHeight() - 1);
dc.DrawLine(line_pos, this->GetSize().GetHeight() - (this->GetSize().GetHeight() - 1), line_pos, this->GetSize().GetHeight() - 1);
}
void cWaveformViewer::UpdateWaveformBitmap()
{
Serializer serializer;
SampleHive::cSerializer serializer;
int selected_row = m_Library.GetSelectedRow();
int selected_row = SampleHive::cHiveData::Get().GetListCtrlSelectedRow();
if (selected_row < 0)
return;
wxString selection = m_Library.GetTextValue(selected_row, 1);
wxString selection = SampleHive::cHiveData::Get().GetListCtrlTextValue(selected_row, 1);
wxString filepath_with_extension =
m_Database.GetSamplePathByFilename(selection.BeforeLast('.').ToStdString());
wxString filepath_with_extension = m_Database.GetSamplePathByFilename(selection.BeforeLast('.').ToStdString());
wxString filepath_without_extension = m_Database.GetSamplePathByFilename(selection.ToStdString());
std::string extension = serializer.DeserializeShowFileExtension() ?
@ -283,9 +280,12 @@ void cWaveformViewer::OnControlKeyUp(wxKeyEvent &event)
if (bSelectRange)
{
SetCursor(wxCURSOR_ARROW);
bSelectRange = false;
bDrawSelectedArea = false;
ReleaseMouse();
return;
}
break;
@ -298,15 +298,15 @@ void cWaveformViewer::OnControlKeyUp(wxKeyEvent &event)
void cWaveformViewer::OnMouseMotion(wxMouseEvent& event)
{
int selected_row = m_Library.GetSelectedRow();
int selected_row = SampleHive::cHiveData::Get().GetListCtrlSelectedRow();
if (selected_row < 0)
return;
wxString selected = m_Library.GetTextValue(selected_row, 1);
wxString selected = SampleHive::cHiveData::Get().GetListCtrlTextValue(selected_row, 1);
std::string path = m_Database.GetSamplePathByFilename(selected.BeforeLast('.').ToStdString());
Tags tags(path);
SampleHive::cTags tags(path);
int length = tags.GetAudioInfo().length;
@ -338,15 +338,15 @@ void cWaveformViewer::OnMouseMotion(wxMouseEvent& event)
void cWaveformViewer::OnMouseLeftButtonDown(wxMouseEvent& event)
{
int selected_row = m_Library.GetSelectedRow();
int selected_row = SampleHive::cHiveData::Get().GetListCtrlSelectedRow();
if (selected_row < 0)
return;
wxString selected = m_Library.GetTextValue(selected_row, 1);
wxString selected = SampleHive::cHiveData::Get().GetListCtrlTextValue(selected_row, 1);
std::string path = m_Database.GetSamplePathByFilename(selected.BeforeLast('.').ToStdString());
Tags tags(path);
SampleHive::cTags tags(path);
int length = tags.GetAudioInfo().length;
@ -387,15 +387,15 @@ void cWaveformViewer::OnMouseLeftButtonDown(wxMouseEvent& event)
void cWaveformViewer::OnMouseLeftButtonUp(wxMouseEvent& event)
{
int selected_row = m_Library.GetSelectedRow();
int selected_row = SampleHive::cHiveData::Get().GetListCtrlSelectedRow();
if (selected_row < 0)
return;
wxString selected = m_Library.GetTextValue(selected_row, 1);
wxString selected = SampleHive::cHiveData::Get().GetListCtrlTextValue(selected_row, 1);
std::string path = m_Database.GetSamplePathByFilename(selected.BeforeLast('.').ToStdString());
Tags tags(path);
SampleHive::cTags tags(path);
int length = tags.GetAudioInfo().length;
@ -436,9 +436,8 @@ void cWaveformViewer::OnMouseLeftButtonUp(wxMouseEvent& event)
SetCursor(wxCURSOR_ARROW);
m_MediaCtrl.Seek(seek_to, wxFromStart);
// SendPushStatusBarStatus(wxString::Format(_("Now playing: %s"), selected), 1);
SampleHive::Signal::SendInfoBarMessage(wxString::Format(_("Now playing: %s"), selected), 1, *this);
m_MediaCtrl.Play();
SampleHive::cSignal::SendPushStatusBarStatus(wxString::Format(_("Now playing: %s"), selected), 1, *this);
SampleHive::cSignal::SendCallFunctionPlay(selected, false, *this);
}
}
@ -453,15 +452,15 @@ void cWaveformViewer::ResetDC()
std::pair<double, double> cWaveformViewer::CalculateLoopPoints()
{
int selected_row = m_Library.GetSelectedRow();
int selected_row = SampleHive::cHiveData::Get().GetListCtrlSelectedRow();
if (selected_row < 0)
return { 0.0, 0.0 };
wxString selected = m_Library.GetTextValue(selected_row, 1);
wxString selected = SampleHive::cHiveData::Get().GetListCtrlTextValue(selected_row, 1);
std::string path = m_Database.GetSamplePathByFilename(selected.BeforeLast('.').ToStdString());
Tags tags(path);
SampleHive::cTags tags(path);
int length = tags.GetAudioInfo().length;
@ -474,13 +473,3 @@ std::pair<double, double> cWaveformViewer::CalculateLoopPoints()
return { loopA, loopB };
}
// void cWaveformViewer::SendPushStatusBarStatus(const wxString& msg, int section)
// {
// SampleHive::SH_StatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_PUSH, this->GetId());
// event.SetEventObject(this);
// event.SetPushMessageAndSection({ msg, section });
// HandleWindowEvent(event);
// }

View File

@ -22,24 +22,20 @@
#include "Database/Database.hpp"
#include <wx/dataview.h>
#include <wx/bitmap.h>
#include <wx/colour.h>
#include <wx/dc.h>
#include <wx/event.h>
#include <wx/infobar.h>
#include <wx/mediactrl.h>
#include <wx/panel.h>
#include <wx/sizer.h>
#include <wx/statusbr.h>
#include <wx/timer.h>
#include <wx/window.h>
class cWaveformViewer : public wxPanel
{
public:
cWaveformViewer(wxWindow* window, wxDataViewListCtrl& library,
wxMediaCtrl& mediaCtrl, Database& database);
cWaveformViewer(wxWindow* window, wxMediaCtrl& mediaCtrl, cDatabase& database);
~cWaveformViewer();
private:
@ -49,8 +45,7 @@ class cWaveformViewer : public wxPanel
wxBoxSizer* m_Sizer;
// -------------------------------------------------------------------
Database& m_Database;
wxDataViewListCtrl& m_Library;
cDatabase& m_Database;
wxMediaCtrl& m_MediaCtrl;
private:
@ -89,11 +84,6 @@ class cWaveformViewer : public wxPanel
// -------------------------------------------------------------------
std::pair<double, double> CalculateLoopPoints();
// -------------------------------------------------------------------
// Send custom events
// void SendLoopPoints();
// void SendPushStatusBarStatus(const wxString& msg, int section);
public:
// -------------------------------------------------------------------
void ResetDC();

View File

@ -20,6 +20,8 @@
#include <wx/defs.h>
namespace SampleHive { namespace ID {
enum ControlIDs
{
/*
@ -115,3 +117,5 @@ enum ControlIDs
ET_TypeCheck,
ET_CustomTag,
};
}}

View File

@ -18,35 +18,24 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Utility/SH_Event.hpp"
#include "Utility/Event.hpp"
namespace SampleHive
{
LoopPointsEvent::LoopPointsEvent(wxEventType eventType, int winId)
cLoopPointsEvent::cLoopPointsEvent(wxEventType eventType, int winId)
: wxCommandEvent(eventType, winId)
{
}
LoopPointsEvent::~LoopPointsEvent()
cLoopPointsEvent::~cLoopPointsEvent()
{
}
wxDEFINE_EVENT(SH_EVT_LOOP_POINTS_UPDATED, LoopPointsEvent);
// AddSampleEvent::AddSampleEvent(wxEventType eventType, int winId)
// : wxCommandEvent(eventType, winId)
// {
// }
// AddSampleEvent::~AddSampleEvent()
// {
// }
// wxDEFINE_EVENT(SH_EVT_STATUS_ADD_SAMPLE, AddSampleEvent);
wxDEFINE_EVENT(SH_EVT_LOOP_POINTS_UPDATED, cLoopPointsEvent);
wxDEFINE_EVENT(SH_EVT_LOOP_POINTS_CLEAR, cLoopPointsEvent);
wxDEFINE_EVENT(SH_EVT_LOOP_AB_BUTTON_VALUE_CHANGE, cLoopPointsEvent);
// MediaEvent::MediaEvent(wxEventType eventType, int winId)
// : wxCommandEvent(eventType, winId)
@ -61,70 +50,70 @@ namespace SampleHive
// wxDEFINE_EVENT(SH_EVT_MEDIA_STATUS_UPDATED, MediaEvent);
StatusBarStatusEvent::StatusBarStatusEvent(wxEventType eventType, int winId)
cStatusBarStatusEvent::cStatusBarStatusEvent(wxEventType eventType, int winId)
: wxCommandEvent(eventType, winId)
{
}
StatusBarStatusEvent::~StatusBarStatusEvent()
cStatusBarStatusEvent::~cStatusBarStatusEvent()
{
}
wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_PUSH, StatusBarStatusEvent);
wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_POP, StatusBarStatusEvent);
wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_SET, StatusBarStatusEvent);
wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_PUSH, cStatusBarStatusEvent);
wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_POP, cStatusBarStatusEvent);
wxDEFINE_EVENT(SH_EVT_STATUSBAR_STATUS_SET, cStatusBarStatusEvent);
InfoBarMessageEvent::InfoBarMessageEvent(wxEventType eventType, int winId)
cInfoBarMessageEvent::cInfoBarMessageEvent(wxEventType eventType, int winId)
: wxCommandEvent(eventType, winId)
{
}
InfoBarMessageEvent::~InfoBarMessageEvent()
cInfoBarMessageEvent::~cInfoBarMessageEvent()
{
}
wxDEFINE_EVENT(SH_EVT_INFOBAR_MESSAGE_SHOW, InfoBarMessageEvent);
wxDEFINE_EVENT(SH_EVT_INFOBAR_MESSAGE_SHOW, cInfoBarMessageEvent);
TimerEvent::TimerEvent(wxEventType eventType, int winId)
cTimerEvent::cTimerEvent(wxEventType eventType, int winId)
: wxCommandEvent(eventType, winId)
{
}
TimerEvent::~TimerEvent()
cTimerEvent::~cTimerEvent()
{
}
wxDEFINE_EVENT(SH_EVT_TIMER_STOP, TimerEvent);
wxDEFINE_EVENT(SH_EVT_TIMER_STOP, cTimerEvent);
CallFunctionEvent::CallFunctionEvent(wxEventType eventType, int winId)
cCallFunctionEvent::cCallFunctionEvent(wxEventType eventType, int winId)
: wxCommandEvent(eventType, winId)
{
}
CallFunctionEvent::~CallFunctionEvent()
cCallFunctionEvent::~cCallFunctionEvent()
{
}
wxDEFINE_EVENT(SH_EVT_CALL_FUNC_PLAY, CallFunctionEvent);
wxDEFINE_EVENT(SH_EVT_CALL_FUNC_PLAY, cCallFunctionEvent);
WaveformUpdateEvent::WaveformUpdateEvent(wxEventType eventType, int winId)
cWaveformUpdateEvent::cWaveformUpdateEvent(wxEventType eventType, int winId)
: wxCommandEvent(eventType, winId)
{
}
WaveformUpdateEvent::~WaveformUpdateEvent()
cWaveformUpdateEvent::~cWaveformUpdateEvent()
{
}
wxDEFINE_EVENT(SH_EVT_UPDATE_WAVEFORM, WaveformUpdateEvent);
wxDEFINE_EVENT(SH_EVT_UPDATE_WAVEFORM, cWaveformUpdateEvent);
}

View File

@ -26,14 +26,14 @@
namespace SampleHive
{
class LoopPointsEvent : public wxCommandEvent
class cLoopPointsEvent : public wxCommandEvent
{
public:
LoopPointsEvent(wxEventType eventType, int winId);
~LoopPointsEvent();
cLoopPointsEvent(wxEventType eventType, int winId);
~cLoopPointsEvent();
public:
virtual wxEvent* Clone() const { return new LoopPointsEvent(*this); }
virtual wxEvent* Clone() const { return new cLoopPointsEvent(*this); }
public:
std::pair<double, double> GetLoopPoints() const { return { m_LoopA, m_LoopB }; };
@ -44,35 +44,18 @@ namespace SampleHive
double m_LoopA, m_LoopB;
};
wxDECLARE_EVENT(SH_EVT_LOOP_POINTS_UPDATED, LoopPointsEvent);
wxDECLARE_EVENT(SH_EVT_LOOP_POINTS_UPDATED, cLoopPointsEvent);
wxDECLARE_EVENT(SH_EVT_LOOP_POINTS_CLEAR, cLoopPointsEvent);
wxDECLARE_EVENT(SH_EVT_LOOP_AB_BUTTON_VALUE_CHANGE, cLoopPointsEvent);
// class AddSampleEvent : public wxCommandEvent
// class cMediaEvent : public wxCommandEvent
// {
// public:
// AddSampleEvent(wxEventType eventType, int winId);
// ~AddSampleEvent();
// cMediaEvent(wxEventType eventType, int winId);
// ~cMediaEvent();
// public:
// virtual wxEvent* Clone() const { return new AddSampleEvent(*this); }
// public:
// wxArrayString GetArrayString() const { return m_Files; };
// void SetArrayString(const wxArrayString& files) { m_Files = files; };
// private:
// wxArrayString m_Files;
// };
// wxDECLARE_EVENT(SH_EVT_STATUS_ADD_SAMPLE, AddSampleEvent);
// class MediaEvent : public wxCommandEvent
// {
// public:
// MediaEvent(wxEventType eventType, int winId);
// ~MediaEvent();
// public:
// virtual wxEvent* Clone() const { return new MediaEvent(*this); }
// virtual wxEvent* Clone() const { return new cMediaEvent(*this); }
// public:
// void SetPath(const wxString& path) { m_Path = path; }
@ -82,16 +65,16 @@ namespace SampleHive
// wxString m_Path;
// };
// wxDECLARE_EVENT(SH_EVT_MEDIA_STATUS_UPDATED, MediaEvent);
// wxDECLARE_EVENT(SH_EVT_MEDIA_STATUS_UPDATED, cMediaEvent);
class StatusBarStatusEvent : public wxCommandEvent
class cStatusBarStatusEvent : public wxCommandEvent
{
public:
StatusBarStatusEvent(wxEventType eventType, int winId);
~StatusBarStatusEvent();
cStatusBarStatusEvent(wxEventType eventType, int winId);
~cStatusBarStatusEvent();
public:
virtual wxEvent* Clone() const { return new StatusBarStatusEvent(*this); }
virtual wxEvent* Clone() const { return new cStatusBarStatusEvent(*this); }
public:
std::pair<wxString, int> GetPushMessageAndSection() const { return { m_Msg, m_PushSection }; }
@ -110,18 +93,18 @@ namespace SampleHive
int m_PushSection, m_PopSection, m_SetSection;
};
wxDECLARE_EVENT(SH_EVT_STATUSBAR_STATUS_PUSH, StatusBarStatusEvent);
wxDECLARE_EVENT(SH_EVT_STATUSBAR_STATUS_POP, StatusBarStatusEvent);
wxDECLARE_EVENT(SH_EVT_STATUSBAR_STATUS_SET, StatusBarStatusEvent);
wxDECLARE_EVENT(SH_EVT_STATUSBAR_STATUS_PUSH, cStatusBarStatusEvent);
wxDECLARE_EVENT(SH_EVT_STATUSBAR_STATUS_POP, cStatusBarStatusEvent);
wxDECLARE_EVENT(SH_EVT_STATUSBAR_STATUS_SET, cStatusBarStatusEvent);
class InfoBarMessageEvent : public wxCommandEvent
class cInfoBarMessageEvent : public wxCommandEvent
{
public:
InfoBarMessageEvent(wxEventType eventType, int winId);
~InfoBarMessageEvent();
cInfoBarMessageEvent(wxEventType eventType, int winId);
~cInfoBarMessageEvent();
public:
virtual wxEvent* Clone() const { return new InfoBarMessageEvent(*this); }
virtual wxEvent* Clone() const { return new cInfoBarMessageEvent(*this); }
public:
std::pair<wxString, int> GetInfoBarMessage() const { return { m_Msg, m_Mode }; }
@ -133,49 +116,52 @@ namespace SampleHive
int m_Mode;
};
wxDECLARE_EVENT(SH_EVT_INFOBAR_MESSAGE_SHOW, InfoBarMessageEvent);
wxDECLARE_EVENT(SH_EVT_INFOBAR_MESSAGE_SHOW, cInfoBarMessageEvent);
class TimerEvent : public wxCommandEvent
class cTimerEvent : public wxCommandEvent
{
public:
TimerEvent(wxEventType eventType, int winId);
~TimerEvent();
cTimerEvent(wxEventType eventType, int winId);
~cTimerEvent();
public:
virtual wxEvent* Clone() const { return new TimerEvent(*this); }
virtual wxEvent* Clone() const { return new cTimerEvent(*this); }
};
wxDECLARE_EVENT(SH_EVT_TIMER_STOP, TimerEvent);
wxDECLARE_EVENT(SH_EVT_TIMER_STOP, cTimerEvent);
class CallFunctionEvent : public wxCommandEvent
class cCallFunctionEvent : public wxCommandEvent
{
public:
CallFunctionEvent(wxEventType eventType, int winId);
~CallFunctionEvent();
cCallFunctionEvent(wxEventType eventType, int winId);
~cCallFunctionEvent();
public:
virtual wxEvent* Clone() const { return new CallFunctionEvent(*this); }
virtual wxEvent* Clone() const { return new cCallFunctionEvent(*this); }
public:
wxString GetSlection() { return m_Selection; }
wxString GetSlection() const { return m_Selection; }
bool GetAutoplayValue() const { return m_bCheckAutoplay; }
void SetSelection(const wxString& selection) { m_Selection = selection; }
void SetAutoplayValue(bool autoplay) { m_bCheckAutoplay = autoplay; }
private:
wxString m_Selection;
bool m_bCheckAutoplay;
};
wxDECLARE_EVENT(SH_EVT_CALL_FUNC_PLAY, CallFunctionEvent);
wxDECLARE_EVENT(SH_EVT_CALL_FUNC_PLAY, cCallFunctionEvent);
class WaveformUpdateEvent : public wxCommandEvent
class cWaveformUpdateEvent : public wxCommandEvent
{
public:
WaveformUpdateEvent(wxEventType eventType, int winId);
~WaveformUpdateEvent();
cWaveformUpdateEvent(wxEventType eventType, int winId);
~cWaveformUpdateEvent();
public:
virtual wxEvent* Clone() const { return new WaveformUpdateEvent(*this); }
virtual wxEvent* Clone() const { return new cWaveformUpdateEvent(*this); }
};
wxDECLARE_EVENT(SH_EVT_UPDATE_WAVEFORM, WaveformUpdateEvent);
wxDECLARE_EVENT(SH_EVT_UPDATE_WAVEFORM, cWaveformUpdateEvent);
}

115
src/Utility/HiveData.hpp Normal file
View File

@ -0,0 +1,115 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "wx/dataview.h"
#include "wx/string.h"
#include "wx/treectrl.h"
#include "wx/treebase.h"
#include "wx/variant.h"
#include "wx/vector.h"
#include <string>
namespace SampleHive {
class cHiveData
{
private:
cHiveData() = default;
public:
cHiveData(const cHiveData&) = delete;
cHiveData& operator=(const cHiveData) = delete;
public:
static cHiveData& Get()
{
static cHiveData s_HiveData;
return s_HiveData;
}
public:
// ===============================================================
// HivesPanel functions
void InitHiveData(wxDataViewListCtrl& listCtrl, wxDataViewTreeCtrl& hives, wxDataViewItem favoriteHive,
wxTreeCtrl& trash, wxTreeItemId trashRoot)
{
m_pListCtrl = &listCtrl;
m_FavoriteHive = favoriteHive;
m_pHives = &hives;
m_TrashRoot = trashRoot;
m_pTrash = &trash;
}
inline wxDataViewTreeCtrl& GetHivesObj() { return *m_pHives; }
inline wxDataViewItem& GetFavoritesHive() { return m_FavoriteHive; }
wxString GetHiveItemText(bool ofFavHive = false, wxDataViewItem hive = wxDataViewItem(0))
{
wxString item_text;
if (ofFavHive)
item_text = m_pHives->GetItemText(m_FavoriteHive);
else
item_text = m_pHives->GetItemText(hive);
return item_text;
}
inline wxDataViewItem GetHiveItemSelection() { return m_pHives->GetSelection(); }
inline bool IsHiveItemContainer(wxDataViewItem& hiveItem) { return m_pHives->IsContainer(hiveItem); }
inline int GetHiveChildCount(wxDataViewItem& root) { return m_pHives->GetChildCount(root); }
inline wxDataViewItem GetHiveNthChild(wxDataViewItem& root, int pos) { return m_pHives->GetNthChild(root, pos); }
inline void HiveAppendItem(wxDataViewItem& hiveItem, wxString name) { m_pHives->AppendItem(hiveItem, name); }
inline void HiveDeleteItem(wxDataViewItem& hiveItem) { m_pHives->DeleteItem(hiveItem); }
// ===============================================================
// TrashPanel functions
inline wxTreeCtrl& GetTrashObj() { return *m_pTrash; }
inline wxTreeItemId& GetTrashRoot() { return m_TrashRoot; }
inline void TrashAppendItem(const wxTreeItemId& parent, const wxString& text) { m_pTrash->AppendItem(parent, text); }
// ===============================================================
// ListCtrl functions
inline wxDataViewListCtrl& GetListCtrlObj() { return *m_pListCtrl; }
inline int GetListCtrlSelections(wxDataViewItemArray& items) { return m_pListCtrl->GetSelections(items); }
inline int GetListCtrlRowFromItem(wxDataViewItemArray& items, int index) { return m_pListCtrl->ItemToRow(items[index]); }
inline int GetListCtrlSelectedRow() { return m_pListCtrl->GetSelectedRow(); }
inline wxDataViewItem GetListCtrlItemFromRow(int row) { return m_pListCtrl->RowToItem(row); }
inline wxString GetListCtrlTextValue(unsigned int row, unsigned int col) { return m_pListCtrl->GetTextValue(row, col); }
inline int GetListCtrlItemCount() { return m_pListCtrl->GetItemCount(); }
inline void ListCtrlAppendItem(const wxVector<wxVariant>& values) { m_pListCtrl->AppendItem(values); }
inline void ListCtrlSetVariant(const wxVariant& variant, unsigned int row, unsigned int col)
{ m_pListCtrl->SetValue(variant, row, col); }
inline void ListCtrlUnselectAllItems() { m_pListCtrl->UnselectAll(); }
inline void ListCtrlSelectRow(int row) { m_pListCtrl->SelectRow(row); }
inline void ListCtrlEnsureVisible(const wxDataViewItem& item) { m_pListCtrl->EnsureVisible(item); }
inline void ListCtrlDeleteItem(unsigned int row) { m_pListCtrl->DeleteItem(row); }
inline void ListCtrlDeleteAllItems() { m_pListCtrl->DeleteAllItems(); }
private:
wxDataViewListCtrl* m_pListCtrl = nullptr;
wxDataViewItem m_FavoriteHive;
wxDataViewTreeCtrl* m_pHives = nullptr;
wxTreeCtrl* m_pTrash = nullptr;
wxTreeItemId m_TrashRoot;
};
}

View File

@ -1,3 +1,23 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Log.hpp"
#include <iostream>
@ -6,16 +26,16 @@
namespace SampleHive {
std::shared_ptr<spdlog::logger> Log::s_Logger;
std::shared_ptr<spdlog::logger> cLog::s_pLogger;
void Log::InitLogger(const std::string& logger)
void cLog::InitLogger(const std::string& logger)
{
spdlog::set_pattern("%^[%-T] [%-n] [%l]: %v %@%$");
try
{
s_Logger = spdlog::stdout_color_mt(logger);
s_Logger->set_level(spdlog::level::trace);
s_pLogger = spdlog::stdout_color_mt(logger);
s_pLogger->set_level(spdlog::level::trace);
}
catch (const spdlog::spdlog_ex& ex)
{

View File

@ -1,3 +1,23 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <memory>
@ -8,24 +28,24 @@
namespace SampleHive {
class Log
class cLog
{
public:
static void InitLogger(const std::string& logger);
public:
inline static std::shared_ptr<spdlog::logger>& GetLogger() { return s_Logger; }
inline static std::shared_ptr<spdlog::logger>& GetLogger() { return s_pLogger; }
private:
static std::shared_ptr<spdlog::logger> s_Logger;
static std::shared_ptr<spdlog::logger> s_pLogger;
};
}
// 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__)
#define SH_LOG_TRACE(...) SPDLOG_LOGGER_TRACE(::SampleHive::cLog::GetLogger(), __VA_ARGS__)
#define SH_LOG_INFO(...) SPDLOG_LOGGER_INFO(::SampleHive::cLog::GetLogger(), __VA_ARGS__)
#define SH_LOG_WARN(...) SPDLOG_LOGGER_WARN(::SampleHive::cLog::GetLogger(), __VA_ARGS__)
#define SH_LOG_DEBUG(...) SPDLOG_LOGGER_DEBUG(::SampleHive::cLog::GetLogger(), __VA_ARGS__)
#define SH_LOG_ERROR(...) SPDLOG_LOGGER_ERROR(::SampleHive::cLog::GetLogger(), __VA_ARGS__)
#define SH_LOG_CRITICAL(...) SPDLOG_LOGGER_CRITICAL(::SampleHive::cLog::GetLogger(), __VA_ARGS__)
}

View File

@ -1,7 +1,29 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "SampleHiveConfig.hpp"
namespace SampleHive {
// 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"
@ -29,3 +51,5 @@
#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

@ -31,7 +31,9 @@
#include <yaml-cpp/emittermanip.h>
#include <yaml-cpp/node/parse.h>
Serializer::Serializer()
namespace SampleHive {
cSerializer::cSerializer()
{
std::ifstream ifstrm(static_cast<std::string>(CONFIG_FILEPATH));
@ -105,12 +107,12 @@ Serializer::Serializer()
}
}
Serializer::~Serializer()
cSerializer::~cSerializer()
{
}
void Serializer::SerializeWinSize(int w, int h)
void cSerializer::SerializeWinSize(int w, int h)
{
YAML::Emitter out;
@ -139,7 +141,7 @@ void Serializer::SerializeWinSize(int w, int h)
}
}
WindowSize Serializer::DeserializeWinSize() const
WindowSize cSerializer::DeserializeWinSize() const
{
int width = 800, height = 600;
@ -168,7 +170,7 @@ WindowSize Serializer::DeserializeWinSize() const
return { width, height };
}
void Serializer::SerializeShowMenuAndStatusBar(std::string key, bool value)
void cSerializer::SerializeShowMenuAndStatusBar(std::string key, bool value)
{
YAML::Emitter out;
@ -198,7 +200,7 @@ void Serializer::SerializeShowMenuAndStatusBar(std::string key, bool value)
}
}
bool Serializer::DeserializeShowMenuAndStatusBar(std::string key) const
bool cSerializer::DeserializeShowMenuAndStatusBar(std::string key) const
{
bool show = false;
@ -227,7 +229,7 @@ bool Serializer::DeserializeShowMenuAndStatusBar(std::string key) const
return show;
}
void Serializer::SerializeSplitterSashPos(std::string key, int pos)
void cSerializer::SerializeSplitterSashPos(std::string key, int pos)
{
YAML::Emitter out;
@ -257,7 +259,7 @@ void Serializer::SerializeSplitterSashPos(std::string key, int pos)
}
}
int Serializer::DeserializeSplitterSashPos(std::string key) const
int cSerializer::DeserializeSplitterSashPos(std::string key) const
{
int pos = 0;
@ -286,7 +288,7 @@ int Serializer::DeserializeSplitterSashPos(std::string key) const
return pos;
}
void Serializer::SerializeMediaOptions(std::string key, bool value)
void cSerializer::SerializeMediaOptions(std::string key, bool value)
{
YAML::Emitter out;
@ -319,7 +321,7 @@ void Serializer::SerializeMediaOptions(std::string key, bool value)
}
}
bool Serializer::DeserializeMediaOptions(std::string key) const
bool cSerializer::DeserializeMediaOptions(std::string key) const
{
bool control = false;
@ -351,7 +353,7 @@ bool Serializer::DeserializeMediaOptions(std::string key) const
return control;
}
void Serializer::SerializeMediaVolume(int volume)
void cSerializer::SerializeMediaVolume(int volume)
{
YAML::Emitter out;
@ -377,7 +379,7 @@ void Serializer::SerializeMediaVolume(int volume)
}
}
int Serializer::DeserializeMediaVolume() const
int cSerializer::DeserializeMediaVolume() const
{
int volume = 0;
@ -400,7 +402,7 @@ int Serializer::DeserializeMediaVolume() const
return volume;
}
void Serializer::SerializeFontSettings(wxFont& font)
void cSerializer::SerializeFontSettings(wxFont& font)
{
YAML::Emitter out;
@ -434,7 +436,7 @@ void Serializer::SerializeFontSettings(wxFont& font)
}
}
wxFont Serializer::DeserializeFontSettings() const
wxFont cSerializer::DeserializeFontSettings() const
{
wxFont font;
@ -468,7 +470,7 @@ wxFont Serializer::DeserializeFontSettings() const
return font;
}
void Serializer::SerializeWaveformColour(wxColour& colour)
void cSerializer::SerializeWaveformColour(wxColour& colour)
{
YAML::Emitter out;
@ -500,7 +502,7 @@ void Serializer::SerializeWaveformColour(wxColour& colour)
}
}
wxColour Serializer::DeserializeWaveformColour() const
wxColour cSerializer::DeserializeWaveformColour() const
{
std::string colour;
@ -527,7 +529,7 @@ wxColour Serializer::DeserializeWaveformColour() const
return static_cast<wxString>(colour);
}
void Serializer::SerializeAutoImport(bool autoImport, const std::string& importDir)
void cSerializer::SerializeAutoImport(bool autoImport, const std::string& importDir)
{
YAML::Emitter out;
@ -556,7 +558,7 @@ void Serializer::SerializeAutoImport(bool autoImport, const std::string& importD
}
}
ImportDirInfo Serializer::DeserializeAutoImport() const
ImportDirInfo cSerializer::DeserializeAutoImport() const
{
wxString dir;
bool auto_import = false;
@ -583,7 +585,7 @@ ImportDirInfo Serializer::DeserializeAutoImport() const
return { auto_import, dir };
}
void Serializer::SerializeFollowSymLink(bool followSymLinks)
void cSerializer::SerializeFollowSymLink(bool followSymLinks)
{
YAML::Emitter out;
@ -611,7 +613,7 @@ void Serializer::SerializeFollowSymLink(bool followSymLinks)
}
}
bool Serializer::DeserializeFollowSymLink() const
bool cSerializer::DeserializeFollowSymLink() const
{
bool follow_sym_links = false;
@ -636,7 +638,7 @@ bool Serializer::DeserializeFollowSymLink() const
return follow_sym_links;
}
void Serializer::SerializeRecursiveImport(bool recursiveImport)
void cSerializer::SerializeRecursiveImport(bool recursiveImport)
{
YAML::Emitter out;
@ -664,7 +666,7 @@ void Serializer::SerializeRecursiveImport(bool recursiveImport)
}
}
bool Serializer::DeserializeRecursiveImport() const
bool cSerializer::DeserializeRecursiveImport() const
{
bool recursive_import = false;
@ -689,7 +691,7 @@ bool Serializer::DeserializeRecursiveImport() const
return recursive_import;
}
void Serializer::SerializeShowFileExtension(bool showExtension)
void cSerializer::SerializeShowFileExtension(bool showExtension)
{
YAML::Emitter out;
@ -717,7 +719,7 @@ void Serializer::SerializeShowFileExtension(bool showExtension)
}
}
bool Serializer::DeserializeShowFileExtension() const
bool cSerializer::DeserializeShowFileExtension() const
{
bool show_extension = false;
@ -741,3 +743,5 @@ bool Serializer::DeserializeShowFileExtension() const
return show_extension;
}
}

View File

@ -42,15 +42,13 @@ typedef std::pair<int, int> WindowSize;
// typedef std::pair<wxString, int> FontType;
typedef std::pair<bool, wxString> ImportDirInfo;
class Serializer
namespace SampleHive {
class cSerializer
{
public:
Serializer();
~Serializer();
private:
// -------------------------------------------------------------------
YAML::Emitter m_Emitter;
cSerializer();
~cSerializer();
public:
// -------------------------------------------------------------------
@ -105,4 +103,10 @@ class Serializer
// Show file extension
void SerializeShowFileExtension(bool showExtension);
bool DeserializeShowFileExtension() const;
private:
// -------------------------------------------------------------------
YAML::Emitter m_Emitter;
};
}

View File

@ -1,12 +1,32 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Utility/Signal.hpp"
#include "Utility/Log.hpp"
#include "Utility/SH_Event.hpp"
#include "Utility/Event.hpp"
namespace SampleHive {
void Signal::SendInfoBarMessage(const wxString& msg, int mode, wxWindow& window, bool isDialog)
void cSignal::SendInfoBarMessage(const wxString& msg, int mode, wxWindow& window, bool isDialog)
{
SampleHive::InfoBarMessageEvent event(SampleHive::SH_EVT_INFOBAR_MESSAGE_SHOW, window.GetId());
SampleHive::cInfoBarMessageEvent event(SampleHive::SH_EVT_INFOBAR_MESSAGE_SHOW, window.GetId());
event.SetEventObject(&window);
event.SetInfoBarMessage({ msg, mode });
@ -17,9 +37,9 @@ namespace SampleHive {
window.HandleWindowEvent(event);
}
void Signal::SendPushStatusBarStatus(const wxString& msg, int section, wxWindow& window, bool isDialog)
void cSignal::SendPushStatusBarStatus(const wxString& msg, int section, wxWindow& window, bool isDialog)
{
SampleHive::StatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_PUSH, window.GetId());
SampleHive::cStatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_PUSH, window.GetId());
event.SetEventObject(&window);
event.SetPushMessageAndSection({ msg, section });
@ -30,9 +50,9 @@ namespace SampleHive {
window.HandleWindowEvent(event);
}
void Signal::SendPopStatusBarStatus(int section, wxWindow& window, bool isDialog)
void cSignal::SendPopStatusBarStatus(int section, wxWindow& window, bool isDialog)
{
SampleHive::StatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_POP, window.GetId());
SampleHive::cStatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_POP, window.GetId());
event.SetEventObject(&window);
event.SetPopMessageSection(section);
@ -43,9 +63,9 @@ namespace SampleHive {
window.HandleWindowEvent(event);
}
void Signal::SendSetStatusBarStatus(const wxString& text, int section, wxWindow& window, bool isDialog)
void cSignal::SendSetStatusBarStatus(const wxString& text, int section, wxWindow& window, bool isDialog)
{
SampleHive::StatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_SET, window.GetId());
SampleHive::cStatusBarStatusEvent event(SampleHive::SH_EVT_STATUSBAR_STATUS_SET, window.GetId());
event.SetEventObject(&window);
event.SetStatusTextAndSection({ text, section });
@ -56,12 +76,13 @@ namespace SampleHive {
window.HandleWindowEvent(event);
}
void Signal::SendCallFunctionPlay(const wxString& selection, wxWindow& window, bool isDialog)
void cSignal::SendCallFunctionPlay(const wxString& selection, bool checkAutoplay, wxWindow& window, bool isDialog)
{
SampleHive::CallFunctionEvent event(SampleHive::SH_EVT_CALL_FUNC_PLAY, window.GetId());
SampleHive::cCallFunctionEvent event(SampleHive::SH_EVT_CALL_FUNC_PLAY, window.GetId());
event.SetEventObject(&window);
event.SetSelection(selection);
event.SetAutoplayValue(checkAutoplay);
if (isDialog)
window.GetParent()->GetEventHandler()->ProcessEvent(event);
@ -69,9 +90,9 @@ namespace SampleHive {
window.HandleWindowEvent(event);
}
void Signal::SendTimerStopStatus(wxWindow& window, bool isDialog)
void cSignal::SendTimerStopStatus(wxWindow& window, bool isDialog)
{
SampleHive::TimerEvent event(SampleHive::SH_EVT_TIMER_STOP, window.GetId());
SampleHive::cTimerEvent event(SampleHive::SH_EVT_TIMER_STOP, window.GetId());
event.SetEventObject(&window);
if (isDialog)
@ -80,19 +101,44 @@ namespace SampleHive {
window.HandleWindowEvent(event);
}
void Signal::SendLoopPoints(std::pair<double, double> loopPoint, wxWindow& window, bool isDialog)
void cSignal::SendLoopPoints(std::pair<double, double> loopPoint, wxWindow& window, bool isDialog)
{
SampleHive::LoopPointsEvent event(SampleHive::SH_EVT_LOOP_POINTS_UPDATED, window.GetId());
SampleHive::cLoopPointsEvent event(SampleHive::SH_EVT_LOOP_POINTS_UPDATED, window.GetId());
event.SetEventObject(&window);
event.SetLoopPoints({loopPoint.first, loopPoint.second});
if (isDialog)
window.GetParent()->GetEventHandler()->ProcessEvent(event);
else
window.HandleWindowEvent(event);
}
void Signal::SendWaveformUpdateStatus(wxWindow& window, bool isDialog)
void cSignal::SendClearLoopPointsStatus(wxWindow& window, bool isDialog)
{
SampleHive::WaveformUpdateEvent event(SampleHive::SH_EVT_UPDATE_WAVEFORM, window.GetId());
SampleHive::cLoopPointsEvent event(SampleHive::SH_EVT_LOOP_POINTS_CLEAR, window.GetId());
event.SetEventObject(&window);
if (isDialog)
window.GetParent()->GetEventHandler()->ProcessEvent(event);
else
window.HandleWindowEvent(event);
}
void cSignal::SendLoopABButtonValueChange(wxWindow& window, bool isDialog)
{
SampleHive::cLoopPointsEvent event(SampleHive::SH_EVT_LOOP_AB_BUTTON_VALUE_CHANGE, window.GetId());
event.SetEventObject(&window);
if (isDialog)
window.GetParent()->GetEventHandler()->ProcessEvent(event);
else
window.HandleWindowEvent(event);
}
void cSignal::SendWaveformUpdateStatus(wxWindow& window, bool isDialog)
{
SampleHive::cWaveformUpdateEvent event(SampleHive::SH_EVT_UPDATE_WAVEFORM, window.GetId());
event.SetEventObject(&window);
if (isDialog)

View File

@ -1,3 +1,23 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <wx/string.h>
@ -5,22 +25,23 @@
namespace SampleHive {
class Signal
class cSignal
{
public:
Signal();
~Signal();
cSignal();
~cSignal();
public:
static void SendInfoBarMessage(const wxString& msg, int mode, wxWindow& window, bool isDialog = false);
static void SendPushStatusBarStatus(const wxString& msg, int section, wxWindow& window, bool isDialog = false);
static void SendSetStatusBarStatus(const wxString& msg, int section, wxWindow& window, bool isDialog = false);
static void SendPopStatusBarStatus(int section, wxWindow& window, bool isDialog = false);
static void SendCallFunctionPlay(const wxString& selection, wxWindow& window, bool isDialog = false);
static void SendCallFunctionPlay(const wxString& selection, bool checkAutoplay, wxWindow& window, bool isDialog = false);
static void SendTimerStopStatus(wxWindow& window, bool isDialog = false);
static void SendLoopPoints(std::pair<double, double> loopPoint, wxWindow& window, bool isDialog = false);
static void SendClearLoopPointsStatus(wxWindow& window, bool isDialog = false);
static void SendLoopABButtonValueChange(wxWindow& window, bool isDialog = false);
static void SendWaveformUpdateStatus(wxWindow& window, bool isDialog = false);
};
}

View File

@ -30,18 +30,20 @@
#include <taglib/tstring.h>
#endif
Tags::Tags(const std::string& filename)
namespace SampleHive {
cTags::cTags(const std::string& filename)
: m_Filepath(filename)
{
}
Tags::~Tags()
cTags::~cTags()
{
}
AudioInfo Tags::GetAudioInfo()
cTags::AudioInfo cTags::GetAudioInfo()
{
wxString artist, album, genre, title, comment;
int channels = 0, length = 0, sample_rate = 0, bitrate = 0;
@ -74,17 +76,17 @@ AudioInfo Tags::GetAudioInfo()
genre = wxString::FromUTF8(Genre.toCString(true));
comment = wxString::FromUTF8(Comment.toCString(true));
bValid = true;
m_bValid = true;
}
else
{
bValid = false;
m_bValid = false;
}
return { title, artist, album, genre, comment, channels, length, sample_rate, bitrate };
}
void Tags::SetTitle(std::string title)
void cTags::SetTitle(std::string title)
{
TagLib::FileRef f (static_cast<const char*>(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average);
@ -97,7 +99,7 @@ void Tags::SetTitle(std::string title)
}
}
void Tags::SetArtist(std::string artist)
void cTags::SetArtist(std::string artist)
{
TagLib::FileRef f (static_cast<const char*>(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average);
@ -110,7 +112,7 @@ void Tags::SetArtist(std::string artist)
}
}
void Tags::SetAlbum(std::string album)
void cTags::SetAlbum(std::string album)
{
TagLib::FileRef f (static_cast<const char*>(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average);
@ -123,7 +125,7 @@ void Tags::SetAlbum(std::string album)
}
}
void Tags::SetGenre(std::string genre)
void cTags::SetGenre(std::string genre)
{
TagLib::FileRef f (static_cast<const char*>(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average);
@ -136,7 +138,7 @@ void Tags::SetGenre(std::string genre)
}
}
void Tags::SetComment(std::string comment)
void cTags::SetComment(std::string comment)
{
TagLib::FileRef f (static_cast<const char*>(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average);
@ -148,3 +150,5 @@ void Tags::SetComment(std::string comment)
f.save();
}
}
}

View File

@ -24,6 +24,10 @@
#include <wx/string.h>
namespace SampleHive {
class cTags
{
struct AudioInfo
{
wxString title;
@ -38,21 +42,13 @@ struct AudioInfo
int bitrate;
};
class Tags
{
public:
Tags(const std::string& filepath);
~Tags();
private:
// -------------------------------------------------------------------
const std::string& m_Filepath;
bool bValid = false;
cTags(const std::string& filepath);
~cTags();
public:
// -------------------------------------------------------------------
AudioInfo GetAudioInfo();
cTags::AudioInfo GetAudioInfo();
void SetTitle(std::string artist);
void SetArtist(std::string artist);
void SetAlbum(std::string album);
@ -61,5 +57,13 @@ class Tags
public:
// -------------------------------------------------------------------
inline bool IsFileValid() { return bValid; }
inline bool IsFileValid() { return m_bValid; }
private:
// -------------------------------------------------------------------
const std::string& m_Filepath;
bool m_bValid = false;
};
}

221
src/Utility/Utils.cpp Normal file
View File

@ -0,0 +1,221 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Database/Database.hpp"
#include "Utility/HiveData.hpp"
#include "Utility/Log.hpp"
#include "Utility/Paths.hpp"
#include "Utility/Serialize.hpp"
#include "Utility/Signal.hpp"
#include "Utility/Tags.hpp"
#include "Utility/Utils.hpp"
#include <wx/dir.h>
#include <wx/progdlg.h>
namespace SampleHive {
SampleHive::cUtils::FileInfo SampleHive::cUtils::GetFilenamePathAndExtension(const wxString& selected,
bool checkExtension, bool doGetFilename) const
{
SampleHive::cSerializer serializer;
cDatabase db;
wxString path;
std::string extension, filename;
wxString filename_with_extension = db.GetSamplePathByFilename(selected.BeforeLast('.').ToStdString());
wxString filename_without_extension = db.GetSamplePathByFilename(selected.ToStdString());
if (checkExtension)
{
extension = serializer.DeserializeShowFileExtension() ?
db.GetSampleFileExtension(selected.ToStdString()) :
db.GetSampleFileExtension(selected.BeforeLast('.').ToStdString());
}
path = selected.Contains(wxString::Format(".%s", extension)) ?
filename_with_extension : filename_without_extension;
if (doGetFilename)
filename = path.AfterLast('/').BeforeLast('.').ToStdString();
return { path, extension, filename };
}
void SampleHive::cUtils::AddSamples(wxArrayString& files, wxWindow* parent)
{
SampleHive::cSerializer serializer;
cDatabase db;
wxBusyCursor busy_cursor;
wxWindowDisabler window_disabler;
wxProgressDialog* progressDialog = new wxProgressDialog(_("Adding files.."),
_("Adding files, please wait..."),
static_cast<int>(files.size()), parent,
wxPD_APP_MODAL | wxPD_SMOOTH | wxPD_CAN_ABORT |
wxPD_AUTO_HIDE);
progressDialog->CenterOnParent(wxBOTH);
std::vector<Sample> sample_array;
std::string path;
std::string artist;
std::string filename_with_extension;
std::string filename_without_extension;
std::string extension;
std::string filename;
//Check All Files At Once
wxArrayString sorted_files;
sorted_files = db.CheckDuplicates(files);
files = sorted_files;
if (files.size() < 1)
{
progressDialog->Destroy();
return;
}
progressDialog->SetRange(files.size());
for (unsigned int i = 0; i < files.size(); i++)
{
progressDialog->Update(i, wxString::Format(_("Getting Data For %s"), files[i].AfterLast('/')));
if (progressDialog->WasCancelled())
{
progressDialog->Destroy();
return;
}
path = files[i].ToStdString();
filename_with_extension = files[i].AfterLast('/').ToStdString();
filename_without_extension = files[i].AfterLast('/').BeforeLast('.').ToStdString();
extension = files[i].AfterLast('.').ToStdString();
filename = serializer.DeserializeShowFileExtension() ?
filename_with_extension : filename_without_extension;
Sample sample;
sample.SetPath(path);
sample.SetFilename(filename_without_extension);
sample.SetFileExtension(extension);
cTags tags(path);
artist = tags.GetAudioInfo().artist.ToStdString();
sample.SetSamplePack(artist);
sample.SetChannels(tags.GetAudioInfo().channels);
sample.SetLength(tags.GetAudioInfo().length);
sample.SetSampleRate(tags.GetAudioInfo().sample_rate);
sample.SetBitrate(tags.GetAudioInfo().bitrate);
wxLongLong llLength = sample.GetLength();
int total_min = static_cast<int>((llLength / 60000).GetValue());
int total_sec = static_cast<int>(((llLength % 60000) / 1000).GetValue());
wxVector<wxVariant> data;
wxVariant icon = wxVariant(wxBitmap(ICON_STAR_EMPTY_16px));
if (tags.IsFileValid())
{
data.clear();
data.push_back(icon);
data.push_back(filename);
data.push_back(sample.GetSamplePack());
data.push_back("");
data.push_back(wxString::Format("%d", sample.GetChannels()));
data.push_back(wxString::Format("%2i:%02i", total_min, total_sec));
data.push_back(wxString::Format("%d", sample.GetSampleRate()));
data.push_back(wxString::Format("%d", sample.GetBitrate()));
data.push_back(path);
SH_LOG_INFO("Adding file: {}, Extension: {}", sample.GetFilename(), sample.GetFileExtension());
SampleHive::cHiveData::Get().ListCtrlAppendItem(data);
sample_array.push_back(sample);
}
else
{
wxString msg = wxString::Format(_("Error! Cannot open %s, Invalid file type."),
filename_with_extension);
SampleHive::cSignal::SendInfoBarMessage(msg, wxICON_ERROR, *parent);
}
}
progressDialog->Pulse(_("Updating Database.."), NULL);
db.InsertIntoSamples(sample_array);
progressDialog->Destroy();
}
void cUtils::OnAutoImportDir(const wxString& pathToDirectory, wxWindow* parent)
{
SH_LOG_DEBUG("Start Importing Samples");
wxBusyCursor busy_cursor;
wxWindowDisabler window_disabler;
wxString filepath;
wxArrayString filepath_array;
size_t number_of_files = wxDir::GetAllFiles(pathToDirectory, &filepath_array, wxEmptyString, wxDIR_DEFAULT);
wxProgressDialog* progressDialog = new wxProgressDialog(_("Adding files.."),
_("Adding files, please wait..."),
static_cast<int>(number_of_files), parent,
wxPD_APP_MODAL | wxPD_SMOOTH |
wxPD_CAN_ABORT | wxPD_AUTO_HIDE);
progressDialog->CenterOnParent(wxBOTH);
for (size_t i = 0; i < number_of_files; i++)
{
filepath = filepath_array[i];
if (wxFileExists(filepath))
{
filepath_array.push_back(filepath);
}
else if (wxDirExists(filepath))
{
wxDir::GetAllFiles(filepath, &filepath_array);
}
progressDialog->Pulse(_("Reading Samples"), NULL);
}
progressDialog->Destroy();
AddSamples(filepath_array, parent);
SH_LOG_DEBUG("Done Importing Samples");
}
}

59
src/Utility/Utils.hpp Normal file
View File

@ -0,0 +1,59 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "wx/arrstr.h"
#include "wx/string.h"
#include "wx/window.h"
namespace SampleHive {
class cUtils
{
private:
cUtils() = default;
public:
cUtils(const cUtils&) = delete;
cUtils& operator=(const cUtils) = delete;
public:
static cUtils& Get()
{
static cUtils s_cUtils;
return s_cUtils;
}
public:
struct FileInfo
{
wxString Path;
std::string Extension;
std::string Filename;
};
// -------------------------------------------------------------------
cUtils::FileInfo GetFilenamePathAndExtension(const wxString& selected,
bool checkExtension = true,
bool doGetFilename = true) const;
void AddSamples(wxArrayString& files, wxWindow* parent);
void OnAutoImportDir(const wxString& pathToDirectory, wxWindow* parent);
};
}