summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/drumgizmo.cc4
-rw-r--r--src/drumgizmo.h2
-rw-r--r--src/memchecker.cc30
-rw-r--r--src/memchecker.h18
4 files changed, 29 insertions, 25 deletions
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc
index 44cd73c..e47cab7 100644
--- a/src/drumgizmo.cc
+++ b/src/drumgizmo.cc
@@ -87,8 +87,8 @@ bool DrumGizmo::loadkit(std::string file)
// Check if there is enough free RAM to load the drumkit.
if(!memchecker.enoughFreeMemory(kit))
{
- ERR(drumgizmo, "Not enough free RAM to load the drumkit.");
- return false;
+ printf("WARNING: There doesn't seem to be enough RAM available to load the kit.\n"
+ "Trying to load it anyway...\n");
}
loader.loadKit(&kit);
diff --git a/src/drumgizmo.h b/src/drumgizmo.h
index 3f84fdd..f1f570a 100644
--- a/src/drumgizmo.h
+++ b/src/drumgizmo.h
@@ -102,7 +102,7 @@ protected:
AudioCache audioCache;
DrumKit kit;
- Memchecker memchecker;
+ MemChecker memchecker;
size_t framesize;
bool freewheel;
diff --git a/src/memchecker.cc b/src/memchecker.cc
index b26603a..8c8c183 100644
--- a/src/memchecker.cc
+++ b/src/memchecker.cc
@@ -27,25 +27,25 @@
#include "memchecker.h"
#ifdef WIN32
- #define WIN32_LEAN_AND_MEAN
- #include <windows.h>
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
#else
- #include <sys/sysinfo.h>
+#include <sys/sysinfo.h>
#endif
#include <sndfile.h>
#include <hugin.hpp>
-bool Memchecker::enoughFreeMemory(const DrumKit& drumkit) const
+bool MemChecker::enoughFreeMemory(const DrumKit& drumkit) const
{
- size_t freeMemory = calcFreeMemory();
- size_t neededMemory = calcNeededMemory(drumkit);
+ uint64_t free_memory = calcFreeMemory();
+ uint64_t needed_memory = calcNeededMemory(drumkit);
- return freeMemory >= neededMemory;
+ return free_memory >= needed_memory;
}
-size_t Memchecker::calcFreeMemory() const
+uint64_t MemChecker::calcFreeMemory() const
{
- size_t free_memory(0);
+ uint64_t free_memory = 0;
// Platform specific calculation of the amount of free memory.
#ifdef WIN32
@@ -55,18 +55,18 @@ size_t Memchecker::calcFreeMemory() const
free_memory = status.ullAvailPhys;
#else
struct sysinfo sys_info;
- sysinfo (&sys_info);
+ sysinfo(&sys_info);
free_memory = sys_info.freeram * sys_info.mem_unit;
#endif
- DEBUG(memchecker, "Calculated %llu free memory.\n", (long long unsigned int)free_memory);
+ DEBUG(memchecker, "Calculated %" PRIu64 " free memory.\n", free_memory);
return free_memory;
}
-size_t Memchecker::calcNeededMemory(const DrumKit& drumkit) const
+uint64_t MemChecker::calcNeededMemory(const DrumKit& drumkit) const
{
- size_t needed_memory(0);
+ uint64_t needed_memory = 0;
// Calculate memory usage of all instruments of drumkit.
for(auto instrument : drumkit.instruments)
@@ -80,12 +80,12 @@ size_t Memchecker::calcNeededMemory(const DrumKit& drumkit) const
}
}
- DEBUG(memchecker, "Calculated %llu needed memory.\n", (long long unsigned int)needed_memory);
+ DEBUG(memchecker, "Calculated %" PRIu64 " needed memory.\n", needed_memory);
return needed_memory;
}
-size_t Memchecker::calcBytesPerChannel(const std::string& filename) const
+uint64_t MemChecker::calcBytesPerChannel(const std::string& filename) const
{
SF_INFO sf_info;
diff --git a/src/memchecker.h b/src/memchecker.h
index c3e13c2..f12c3d2 100644
--- a/src/memchecker.h
+++ b/src/memchecker.h
@@ -29,20 +29,24 @@
#include "drumkit.h"
#include <string>
+// includes cstdint automatically and is needed for the PRIu64 macro
+#include <cinttypes>
-class Memchecker
+class MemChecker
{
public:
- //! Checks if there is enough memory left to load drumkit into RAM.
- //! \param drumkit The drumkit for which it is checked if there's enough memory left.
- //! \return True iff there is enough memory left.
+ //! Checks if there is enough memory left to load drumkit into RAM.
+ //! \param drumkit The drumkit for which it is checked if there's enough memory left.
+ //! \return True iff there is enough memory left.
bool enoughFreeMemory(const DrumKit& drumkit) const;
protected:
// Computes how much RAM (in bytes) is left.
- size_t calcFreeMemory() const;
+ uint64_t calcFreeMemory() const;
+
// Computes how much memory the drumkit takes when loaded into RAM (in bytes).
- size_t calcNeededMemory(const DrumKit& drumkit) const;
+ uint64_t calcNeededMemory(const DrumKit& drumkit) const;
+
// Computes the number of bytes per channel of <filename> using libsnd.
- size_t calcBytesPerChannel(const std::string& filename) const;
+ uint64_t calcBytesPerChannel(const std::string& filename) const;
};