mirror of
https://gitlab.com/samplehive/sample-hive.git
synced 2026-10-24 13:45:00 +02:00
More encapsulation, lots of reformatting and cleanup.
This commit is contained in:
+123
-199
@@ -26,6 +26,7 @@
|
||||
#include <exception>
|
||||
#include <sstream>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <wx/dataview.h>
|
||||
#include <wx/dvrenderers.h>
|
||||
#include <wx/msgdlg.h>
|
||||
@@ -49,11 +50,10 @@ void debug_log_on_error(int rc)
|
||||
}
|
||||
}
|
||||
|
||||
void show_modal_dialog_and_log(const std::string &message, const std::string &title,
|
||||
const std::string &error_msg)
|
||||
void show_modal_dialog_and_log(const std::string &message, const std::string &title, const std::string &error_msg)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << message << ": " << error_msg;
|
||||
ss << message << " : " << error_msg;
|
||||
|
||||
const auto msg = ss.str();
|
||||
|
||||
@@ -78,17 +78,17 @@ class Sqlite3Statement
|
||||
sqlite3_stmt* stmt = nullptr;
|
||||
};
|
||||
|
||||
Database::Database()
|
||||
cDatabase::cDatabase()
|
||||
{
|
||||
OpenDatabase();
|
||||
}
|
||||
|
||||
Database::~Database()
|
||||
cDatabase::~cDatabase()
|
||||
{
|
||||
CloseDatabase();
|
||||
}
|
||||
|
||||
void Database::CreateTableSamples()
|
||||
void cDatabase::CreateTableSamples()
|
||||
{
|
||||
/* Create SQL statement */
|
||||
const auto samples = "CREATE TABLE IF NOT EXISTS SAMPLES("
|
||||
@@ -107,7 +107,7 @@ void Database::CreateTableSamples()
|
||||
|
||||
try
|
||||
{
|
||||
throw_on_sqlite3_error(sqlite3_exec(m_Database, samples, NULL, 0, &m_ErrMsg));
|
||||
throw_on_sqlite3_error(sqlite3_exec(m_pDatabase, samples, NULL, 0, &m_pErrMsg));
|
||||
SH_LOG_INFO("SAMPLES table created successfully.");
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
@@ -116,14 +116,14 @@ void Database::CreateTableSamples()
|
||||
}
|
||||
}
|
||||
|
||||
void Database::CreateTableHives()
|
||||
void cDatabase::CreateTableHives()
|
||||
{
|
||||
/* Create SQL statement */
|
||||
const auto hives = "CREATE TABLE IF NOT EXISTS HIVES(HIVE TEXT NOT NULL);";
|
||||
|
||||
try
|
||||
{
|
||||
throw_on_sqlite3_error(sqlite3_exec(m_Database, hives, NULL, 0, &m_ErrMsg));
|
||||
throw_on_sqlite3_error(sqlite3_exec(m_pDatabase, hives, NULL, 0, &m_pErrMsg));
|
||||
SH_LOG_INFO("HIVES table created successfully.");
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
@@ -133,7 +133,7 @@ void Database::CreateTableHives()
|
||||
}
|
||||
|
||||
//Loops through a Sample array and adds them to the database
|
||||
void Database::InsertIntoSamples(const std::vector<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,67 +195,36 @@ 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.");
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
show_modal_dialog_and_log("Error! Cannot insert data into HIVES", "Error", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void Database::UpdateHive(const std::string &hiveOldName, const std::string &hiveNewName)
|
||||
void cDatabase::UpdateHive(const std::string &hiveOldName, const std::string &hiveNewName)
|
||||
{
|
||||
try
|
||||
{
|
||||
const auto sql = "UPDATE HIVES SET HIVE = ? WHERE HIVE = ?;";
|
||||
|
||||
Sqlite3Statement statement(m_Database, sql);
|
||||
Sqlite3Statement statement(m_pDatabase, sql);
|
||||
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveNewName.c_str(),
|
||||
hiveNewName.size(), SQLITE_STATIC));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, hiveOldName.c_str(),
|
||||
hiveOldName.size(), SQLITE_STATIC));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveNewName.c_str(), hiveNewName.size(), SQLITE_STATIC));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, hiveOldName.c_str(), hiveOldName.size(), SQLITE_STATIC));
|
||||
|
||||
if (sqlite3_step(statement.stmt) != SQLITE_DONE)
|
||||
{
|
||||
@@ -277,18 +241,16 @@ void Database::UpdateHive(const std::string &hiveOldName, const std::string &hiv
|
||||
}
|
||||
}
|
||||
|
||||
void Database::UpdateHiveName(const std::string &filename, const std::string &hiveName)
|
||||
void cDatabase::UpdateHiveName(const std::string &filename, const std::string &hiveName)
|
||||
{
|
||||
try
|
||||
{
|
||||
const auto sql = "UPDATE SAMPLES SET HIVE = ? WHERE FILENAME = ?;";
|
||||
|
||||
Sqlite3Statement statement(m_Database, sql);
|
||||
Sqlite3Statement statement(m_pDatabase, sql);
|
||||
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveName.c_str(),
|
||||
hiveName.size(), SQLITE_STATIC));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(),
|
||||
filename.size(), SQLITE_STATIC));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveName.c_str(), hiveName.size(), SQLITE_STATIC));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), filename.size(), SQLITE_STATIC));
|
||||
|
||||
if (sqlite3_step(statement.stmt) == SQLITE_ROW)
|
||||
{
|
||||
@@ -303,17 +265,16 @@ void Database::UpdateHiveName(const std::string &filename, const std::string &hi
|
||||
}
|
||||
}
|
||||
|
||||
void Database::UpdateFavoriteColumn(const std::string &filename, int value)
|
||||
void cDatabase::UpdateFavoriteColumn(const std::string &filename, int value)
|
||||
{
|
||||
try
|
||||
{
|
||||
const auto sql = "UPDATE SAMPLES SET FAVORITE = ? WHERE FILENAME = ?;";
|
||||
|
||||
Sqlite3Statement statement(m_Database, sql);
|
||||
Sqlite3Statement statement(m_pDatabase, sql);
|
||||
|
||||
throw_on_sqlite3_error(sqlite3_bind_int(statement.stmt, 1, value));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(),
|
||||
filename.size(), SQLITE_STATIC));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), filename.size(), SQLITE_STATIC));
|
||||
|
||||
if (sqlite3_step(statement.stmt) == SQLITE_ROW)
|
||||
{
|
||||
@@ -328,18 +289,16 @@ void Database::UpdateFavoriteColumn(const std::string &filename, int value)
|
||||
}
|
||||
}
|
||||
|
||||
void Database::UpdateSamplePack(const std::string &filename, const std::string &samplePack)
|
||||
void cDatabase::UpdateSamplePack(const std::string &filename, const std::string &samplePack)
|
||||
{
|
||||
try
|
||||
{
|
||||
const auto sql = "UPDATE SAMPLES SET SAMPLEPACK = ? WHERE FILENAME = ?;";
|
||||
|
||||
Sqlite3Statement statement(m_Database, sql);
|
||||
Sqlite3Statement statement(m_pDatabase, sql);
|
||||
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, samplePack.c_str(),
|
||||
samplePack.size(), SQLITE_STATIC));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(),
|
||||
filename.size(), SQLITE_STATIC));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, samplePack.c_str(), samplePack.size(), SQLITE_STATIC));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), filename.size(), SQLITE_STATIC));
|
||||
|
||||
if (sqlite3_step(statement.stmt) == SQLITE_ROW)
|
||||
{
|
||||
@@ -354,17 +313,16 @@ void Database::UpdateSamplePack(const std::string &filename, const std::string &
|
||||
}
|
||||
}
|
||||
|
||||
void Database::UpdateSampleType(const std::string &filename, const std::string &type)
|
||||
void cDatabase::UpdateSampleType(const std::string &filename, const std::string &type)
|
||||
{
|
||||
try
|
||||
{
|
||||
const auto sql = "UPDATE SAMPLES SET TYPE = ? WHERE FILENAME = ?;";
|
||||
|
||||
Sqlite3Statement statement(m_Database, sql);
|
||||
Sqlite3Statement statement(m_pDatabase, sql);
|
||||
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, type.c_str(), type.size(), SQLITE_STATIC));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(),
|
||||
filename.size(), SQLITE_STATIC));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), filename.size(), SQLITE_STATIC));
|
||||
|
||||
if (sqlite3_step(statement.stmt) == SQLITE_ROW)
|
||||
{
|
||||
@@ -379,7 +337,7 @@ void Database::UpdateSampleType(const std::string &filename, const std::string &
|
||||
}
|
||||
}
|
||||
|
||||
std::string Database::GetSampleType(const std::string &filename)
|
||||
std::string cDatabase::GetSampleType(const std::string &filename)
|
||||
{
|
||||
std::string type;
|
||||
|
||||
@@ -387,16 +345,15 @@ std::string Database::GetSampleType(const std::string &filename)
|
||||
{
|
||||
const auto sql = "SELECT TYPE FROM SAMPLES WHERE FILENAME = ?;";
|
||||
|
||||
Sqlite3Statement statement(m_Database, sql);
|
||||
Sqlite3Statement statement(m_pDatabase, sql);
|
||||
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(),
|
||||
filename.size(), SQLITE_STATIC));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC));
|
||||
|
||||
if (sqlite3_step(statement.stmt) == SQLITE_ROW)
|
||||
{
|
||||
SH_LOG_INFO("Record found, fetching sample type for {}", filename);
|
||||
|
||||
type = std::string(reinterpret_cast<const char *>(sqlite3_column_text(statement.stmt, 0)));
|
||||
type = std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 0)));
|
||||
}
|
||||
|
||||
SH_LOG_INFO("Selected sample type from table successfully.");
|
||||
@@ -409,7 +366,7 @@ std::string Database::GetSampleType(const std::string &filename)
|
||||
return type;
|
||||
}
|
||||
|
||||
int Database::GetFavoriteColumnValueByFilename(const std::string &filename)
|
||||
int cDatabase::GetFavoriteColumnValueByFilename(const std::string &filename)
|
||||
{
|
||||
int value = 0;
|
||||
|
||||
@@ -417,10 +374,9 @@ int Database::GetFavoriteColumnValueByFilename(const std::string &filename)
|
||||
{
|
||||
const auto sql = "SELECT FAVORITE FROM SAMPLES WHERE FILENAME = ?;";
|
||||
|
||||
Sqlite3Statement statement(m_Database, sql);
|
||||
Sqlite3Statement statement(m_pDatabase, sql);
|
||||
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(),
|
||||
filename.size(), SQLITE_STATIC));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC));
|
||||
|
||||
if (sqlite3_step(statement.stmt) == SQLITE_ROW)
|
||||
{
|
||||
@@ -438,7 +394,7 @@ int Database::GetFavoriteColumnValueByFilename(const std::string &filename)
|
||||
return value;
|
||||
}
|
||||
|
||||
std::string Database::GetHiveByFilename(const std::string &filename)
|
||||
std::string cDatabase::GetHiveByFilename(const std::string &filename)
|
||||
{
|
||||
std::string hive;
|
||||
|
||||
@@ -446,14 +402,13 @@ std::string Database::GetHiveByFilename(const std::string &filename)
|
||||
{
|
||||
const auto sql = "SELECT HIVE FROM SAMPLES WHERE FILENAME = ?;";
|
||||
|
||||
Sqlite3Statement statement(m_Database, sql);
|
||||
Sqlite3Statement statement(m_pDatabase, sql);
|
||||
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(),
|
||||
filename.size(), SQLITE_STATIC));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC));
|
||||
|
||||
if (sqlite3_step(statement.stmt) == SQLITE_ROW)
|
||||
{
|
||||
hive = std::string(reinterpret_cast<const char *>(sqlite3_column_text(statement.stmt, 0)));
|
||||
hive = std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 0)));
|
||||
SH_LOG_INFO("Record found, fetching hive for {}", filename);
|
||||
}
|
||||
|
||||
@@ -467,16 +422,15 @@ std::string Database::GetHiveByFilename(const std::string &filename)
|
||||
return hive;
|
||||
}
|
||||
|
||||
void Database::RemoveSampleFromDatabase(const std::string &filename)
|
||||
void cDatabase::RemoveSampleFromDatabase(const std::string &filename)
|
||||
{
|
||||
try
|
||||
{
|
||||
const auto sql = "DELETE FROM SAMPLES WHERE FILENAME = ?;";
|
||||
|
||||
Sqlite3Statement statement(m_Database, sql);
|
||||
Sqlite3Statement statement(m_pDatabase, sql);
|
||||
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(),
|
||||
filename.size(), SQLITE_STATIC));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC));
|
||||
|
||||
if (sqlite3_step(statement.stmt) == SQLITE_DONE)
|
||||
{
|
||||
@@ -491,16 +445,15 @@ void Database::RemoveSampleFromDatabase(const std::string &filename)
|
||||
}
|
||||
}
|
||||
|
||||
void Database::RemoveHiveFromDatabase(const std::string &hiveName)
|
||||
void cDatabase::RemoveHiveFromDatabase(const std::string &hiveName)
|
||||
{
|
||||
try
|
||||
{
|
||||
const auto sql = "DELETE FROM HIVES WHERE HIVE = ?;";
|
||||
|
||||
Sqlite3Statement statement(m_Database, sql);
|
||||
Sqlite3Statement statement(m_pDatabase, sql);
|
||||
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveName.c_str(),
|
||||
hiveName.size(), SQLITE_STATIC));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, hiveName.c_str(), hiveName.size(), SQLITE_STATIC));
|
||||
|
||||
if (sqlite3_step(statement.stmt) == SQLITE_DONE)
|
||||
{
|
||||
@@ -515,7 +468,7 @@ void Database::RemoveHiveFromDatabase(const std::string &hiveName)
|
||||
}
|
||||
}
|
||||
|
||||
std::string Database::GetSamplePathByFilename(const std::string &filename)
|
||||
std::string cDatabase::GetSamplePathByFilename(const std::string &filename)
|
||||
{
|
||||
std::string path;
|
||||
|
||||
@@ -523,14 +476,13 @@ std::string Database::GetSamplePathByFilename(const std::string &filename)
|
||||
{
|
||||
const auto sql = "SELECT PATH FROM SAMPLES WHERE FILENAME = ?;";
|
||||
|
||||
Sqlite3Statement statement(m_Database, sql);
|
||||
Sqlite3Statement statement(m_pDatabase, sql);
|
||||
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(),
|
||||
filename.size(), SQLITE_STATIC));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC));
|
||||
|
||||
if (sqlite3_step(statement.stmt) == SQLITE_ROW)
|
||||
{
|
||||
path = std::string(reinterpret_cast<const char *>(sqlite3_column_text(statement.stmt, 0)));
|
||||
path = std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 0)));
|
||||
SH_LOG_INFO("Record found, fetching sample path for {}", filename);
|
||||
}
|
||||
|
||||
@@ -544,7 +496,7 @@ std::string Database::GetSamplePathByFilename(const std::string &filename)
|
||||
return path;
|
||||
}
|
||||
|
||||
std::string Database::GetSampleFileExtension(const std::string &filename)
|
||||
std::string cDatabase::GetSampleFileExtension(const std::string &filename)
|
||||
{
|
||||
std::string extension;
|
||||
|
||||
@@ -552,14 +504,13 @@ std::string Database::GetSampleFileExtension(const std::string &filename)
|
||||
{
|
||||
const auto sql = "SELECT EXTENSION FROM SAMPLES WHERE FILENAME = ?;";
|
||||
|
||||
Sqlite3Statement statement(m_Database, sql);
|
||||
Sqlite3Statement statement(m_pDatabase, sql);
|
||||
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(),
|
||||
filename.size(), SQLITE_STATIC));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC));
|
||||
|
||||
if (sqlite3_step(statement.stmt) == SQLITE_ROW)
|
||||
{
|
||||
extension = std::string(reinterpret_cast<const char *>(sqlite3_column_text(statement.stmt, 0)));
|
||||
extension = std::string(reinterpret_cast<const char*>(sqlite3_column_text(statement.stmt, 0)));
|
||||
SH_LOG_INFO("Record found, fetching file extension for {}", filename);
|
||||
}
|
||||
|
||||
@@ -573,7 +524,7 @@ std::string Database::GetSampleFileExtension(const std::string &filename)
|
||||
return extension;
|
||||
}
|
||||
|
||||
wxVector<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);
|
||||
}
|
||||
@@ -903,8 +836,8 @@ void Database::LoadHivesDatabase(wxDataViewTreeCtrl &treeCtrl)
|
||||
}
|
||||
}
|
||||
|
||||
//Compares the input array with the database and removes duplicates.
|
||||
wxArrayString Database::CheckDuplicates(const wxArrayString &files)
|
||||
// Compares the input array with the database and removes duplicates.
|
||||
wxArrayString cDatabase::CheckDuplicates(const wxArrayString &files)
|
||||
{
|
||||
wxArrayString sorted_files;
|
||||
|
||||
@@ -915,7 +848,7 @@ wxArrayString Database::CheckDuplicates(const wxArrayString &files)
|
||||
{
|
||||
const auto sql = "SELECT * FROM SAMPLES WHERE FILENAME = ?;";
|
||||
|
||||
Sqlite3Statement statement(m_Database, sql);
|
||||
Sqlite3Statement statement(m_pDatabase, sql);
|
||||
|
||||
for (unsigned int i = 0; i < files.size(); i++)
|
||||
{
|
||||
@@ -940,16 +873,15 @@ wxArrayString Database::CheckDuplicates(const wxArrayString &files)
|
||||
return sorted_files;
|
||||
}
|
||||
|
||||
bool Database::IsTrashed(const std::string &filename)
|
||||
bool cDatabase::IsTrashed(const std::string &filename)
|
||||
{
|
||||
try
|
||||
{
|
||||
const auto sql = "SELECT TRASHED FROM SAMPLES WHERE FILENAME = ?;";
|
||||
|
||||
Sqlite3Statement statement(m_Database, sql);
|
||||
Sqlite3Statement statement(m_pDatabase, sql);
|
||||
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(),
|
||||
filename.size(), SQLITE_STATIC));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC));
|
||||
|
||||
if (sqlite3_step(statement.stmt) == SQLITE_ROW)
|
||||
{
|
||||
@@ -969,17 +901,16 @@ bool Database::IsTrashed(const std::string &filename)
|
||||
return false;
|
||||
}
|
||||
|
||||
void Database::UpdateTrashColumn(const std::string &filename, int value)
|
||||
void cDatabase::UpdateTrashColumn(const std::string &filename, int value)
|
||||
{
|
||||
try
|
||||
{
|
||||
const auto sql = "UPDATE SAMPLES SET TRASHED = ? WHERE FILENAME = ?;";
|
||||
|
||||
Sqlite3Statement statement(m_Database, sql);
|
||||
Sqlite3Statement statement(m_pDatabase, sql);
|
||||
|
||||
throw_on_sqlite3_error(sqlite3_bind_int(statement.stmt, 1, value));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(),
|
||||
filename.size(), SQLITE_STATIC));
|
||||
throw_on_sqlite3_error(sqlite3_bind_text(statement.stmt, 2, filename.c_str(), filename.size(), SQLITE_STATIC));
|
||||
|
||||
if (sqlite3_step(statement.stmt) == SQLITE_ROW)
|
||||
{
|
||||
@@ -994,10 +925,10 @@ void Database::UpdateTrashColumn(const std::string &filename, int value)
|
||||
}
|
||||
}
|
||||
|
||||
wxVector<wxVector<wxVariant>>
|
||||
Database::RestoreFromTrashByFilename(const std::string &filename,
|
||||
wxVector<wxVector<wxVariant>> &vecSet, bool show_extension,
|
||||
const std::string &icon_star_filled, const std::string &icon_star_empty)
|
||||
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)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user