summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/drumkit.cc5
-rw-r--r--src/drumkitloader.cc8
-rw-r--r--src/drumkitparser.cc13
-rw-r--r--src/instrument.h3
-rw-r--r--src/memchecker.cc6
5 files changed, 16 insertions, 19 deletions
diff --git a/src/drumkit.cc b/src/drumkit.cc
index f25a6ea..1dadf04 100644
--- a/src/drumkit.cc
+++ b/src/drumkit.cc
@@ -39,11 +39,6 @@ DrumKit::~DrumKit()
void DrumKit::clear()
{
- for(auto& instrument : instruments)
- {
- delete instrument;
- }
-
instruments.clear();
channels.clear();
diff --git a/src/drumkitloader.cc b/src/drumkitloader.cc
index 94daf79..f2ef61a 100644
--- a/src/drumkitloader.cc
+++ b/src/drumkitloader.cc
@@ -133,15 +133,15 @@ void DrumKitLoader::loadKit(DrumKit *kit)
// Count total number of files that need loading:
settings.number_of_files.store(0);
- for(auto instr : kit->instruments)
+ for(auto& instr_ptr: kit->instruments)
{
- settings.number_of_files.fetch_add(instr->audiofiles.size());
+ settings.number_of_files.fetch_add(instr_ptr->audiofiles.size());
}
// Now actually queue them for loading:
- for(auto instr : kit->instruments)
+ for(auto& instr_ptr: kit->instruments)
{
- for(auto audiofile : instr->audiofiles)
+ for(auto& audiofile: instr_ptr->audiofiles)
{
load_queue.push_back(audiofile);
}
diff --git a/src/drumkitparser.cc b/src/drumkitparser.cc
index 073d240..cd1c32d 100644
--- a/src/drumkitparser.cc
+++ b/src/drumkitparser.cc
@@ -30,6 +30,7 @@
#include <stdio.h>
#include <hugin.hpp>
+#include "cpp11fix.h"
#include "instrumentparser.h"
#include "path.h"
#include "drumgizmo.h"
@@ -184,14 +185,14 @@ void DrumKitParser::endTag(const std::string& name)
{
if(name == "instrument")
{
- Instrument* instrument = new Instrument(settings, rand);
- instrument->setGroup(instr_group);
-
- InstrumentParser parser(*instrument);
+ auto ptr = std::make_unique<Instrument>(settings, rand);
+ ptr->setGroup(instr_group);
+
+ InstrumentParser parser(*ptr);
parser.parseFile(path + "/" + instr_file);
// Transfer ownership to the DrumKit object.
- kit.instruments.push_back(instrument);
+ kit.instruments.push_back(std::move(ptr));
// Assign kit channel numbers to instruments channels.
std::vector<InstrumentChannel*>::iterator ic = parser.channellist.begin();
@@ -216,7 +217,7 @@ void DrumKitParser::endTag(const std::string& name)
if(c->num == NO_CHANNEL)
{
ERR(kitparser, "Missing channel '%s' in instrument '%s'\n",
- c->name.c_str(), instrument->getName().c_str());
+ c->name.c_str(), ptr->getName().c_str());
}
else
{
diff --git a/src/instrument.h b/src/instrument.h
index 621dddb..ee67b3f 100644
--- a/src/instrument.h
+++ b/src/instrument.h
@@ -28,6 +28,7 @@
#include <string>
#include <vector>
+#include <memory>
#include "rangemap.h"
#include "powerlist.h"
@@ -83,4 +84,4 @@ private:
};
// typedef std::map< std::string, Instrument > Instruments;
-typedef std::vector<Instrument*> Instruments;
+using Instruments = std::vector<std::unique_ptr<Instrument>>;
diff --git a/src/memchecker.cc b/src/memchecker.cc
index 81c9da7..6d66965 100644
--- a/src/memchecker.cc
+++ b/src/memchecker.cc
@@ -73,12 +73,12 @@ uint64_t MemChecker::calcNeededMemory(const DrumKit& drumkit) const
uint64_t needed_memory = 0;
// Calculate memory usage of all instruments of drumkit.
- for(auto instrument : drumkit.instruments)
+ for(auto& instr_ptr: drumkit.instruments)
{
- const auto& audiofiles = instrument->audiofiles;
+ const auto& audiofiles = instr_ptr->audiofiles;
// Calculate memory usage of all audiofiles.
- for(auto audiofile : audiofiles)
+ for(auto& audiofile: audiofiles)
{
needed_memory += calcBytesPerChannel(audiofile->filename);
}