Remove unnecessary logging statements and database queries.

This commit is contained in:
apoorv569
2022-03-18 17:39:52 +05:30
parent 22f45fbd66
commit 293c12a7e0
5 changed files with 52 additions and 47 deletions
+24 -14
View File
@@ -34,26 +34,15 @@
namespace SampleHive {
SampleHive::cUtils::FileInfo SampleHive::cUtils::GetFilenamePathAndExtension(const wxString& selected,
bool checkExtension, bool doGetFilename) const
bool checkExtension, bool doGetFilename)
{
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());
path = GetSamplePath(selected);
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;
extension = path.AfterLast('/').AfterLast('.').ToStdString();
if (doGetFilename)
filename = path.AfterLast('/').BeforeLast('.').ToStdString();
@@ -222,4 +211,25 @@ namespace SampleHive {
SH_LOG_DEBUG("Done Importing Samples");
}
std::string cUtils::GetSamplePath(const wxString& name)
{
SampleHive::cSerializer serializer;
cDatabase db;
wxString sample_path;
if (m_PathCache.find(name.ToStdString()) != m_PathCache.end())
return m_PathCache[name.ToStdString()];
else
{
sample_path = serializer.DeserializeShowFileExtension() ?
db.GetSamplePathByFilename(name.BeforeLast('.').ToStdString()) :
db.GetSamplePathByFilename(name.ToStdString());
m_PathCache[name.ToStdString()] = sample_path;
}
return sample_path.ToStdString();
}
}
+14 -1
View File
@@ -22,6 +22,8 @@
#include "wx/string.h"
#include "wx/window.h"
#include <unordered_map>
namespace SampleHive {
class cUtils
@@ -30,10 +32,12 @@ namespace SampleHive {
cUtils() = default;
public:
// -------------------------------------------------------------------
cUtils(const cUtils&) = delete;
cUtils& operator=(const cUtils) = delete;
public:
// -------------------------------------------------------------------
static cUtils& Get()
{
static cUtils s_cUtils;
@@ -41,6 +45,7 @@ namespace SampleHive {
}
public:
// -------------------------------------------------------------------
struct FileInfo
{
wxString Path;
@@ -51,9 +56,17 @@ namespace SampleHive {
// -------------------------------------------------------------------
cUtils::FileInfo GetFilenamePathAndExtension(const wxString& selected,
bool checkExtension = true,
bool doGetFilename = true) const;
bool doGetFilename = true);
void AddSamples(wxArrayString& files, wxWindow* parent);
void OnAutoImportDir(const wxString& pathToDirectory, wxWindow* parent);
private:
// -------------------------------------------------------------------
std::string GetSamplePath(const wxString& name);
private:
// -------------------------------------------------------------------
std::unordered_map<std::string, std::string> m_PathCache;
};
}