From 66bfac5a0ae1068908639dd0190433f5ab430473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gl=C3=B6ckner?= Date: Fri, 27 May 2016 09:25:32 +0200 Subject: Instrument holds AudioFile via unique_ptr --- src/drumkitloader.cc | 2 +- src/instrument.cc | 6 ------ src/instrument.h | 2 +- src/instrumentparser.cc | 8 ++++---- src/instrumentparser.h | 1 + 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/drumkitloader.cc b/src/drumkitloader.cc index f2ef61a..7eab562 100644 --- a/src/drumkitloader.cc +++ b/src/drumkitloader.cc @@ -143,7 +143,7 @@ void DrumKitLoader::loadKit(DrumKit *kit) { for(auto& audiofile: instr_ptr->audiofiles) { - load_queue.push_back(audiofile); + load_queue.push_back(audiofile.get()); } } diff --git a/src/instrument.cc b/src/instrument.cc index 9a4c0b7..8c78f40 100644 --- a/src/instrument.cc +++ b/src/instrument.cc @@ -47,12 +47,6 @@ Instrument::~Instrument() magic = nullptr; DEBUG(instrument, "delete %p\n", this); - std::vector::iterator i = audiofiles.begin(); - while(i != audiofiles.end()) - { - delete *i; - i++; - } } bool Instrument::isValid() const diff --git a/src/instrument.h b/src/instrument.h index ee67b3f..e61d446 100644 --- a/src/instrument.h +++ b/src/instrument.h @@ -56,7 +56,7 @@ public: // std::map channelmap; - std::vector audiofiles; + std::vector> audiofiles; bool isValid() const; diff --git a/src/instrumentparser.cc b/src/instrumentparser.cc index 1e42cc3..b42accd 100644 --- a/src/instrumentparser.cc +++ b/src/instrumentparser.cc @@ -31,6 +31,7 @@ #include +#include "cpp11fix.h" #include "path.h" #include "nolocale.h" @@ -141,18 +142,17 @@ void InstrumentParser::startTag(const std::string& name, const attr_t& attr) filechannel = filechannel - 1; // 1-based in file but zero-based internally. - AudioFile *audio_file = - new AudioFile(path + "/" + attr.at("file"), filechannel); + auto audio_file = std::make_unique(path + "/" + attr.at("file"), filechannel); // TODO: This is not deleted anywhere... InstrumentChannel *instrument_channel = new InstrumentChannel(attr.at("channel")); channellist.push_back(instrument_channel); - sample->addAudioFile(instrument_channel, audio_file); + sample->addAudioFile(instrument_channel, audio_file.get()); // Transfer audio_file ownership to the instrument. - instrument.audiofiles.push_back(audio_file); + instrument.audiofiles.push_back(std::move(audio_file)); } if(name == "velocities") diff --git a/src/instrumentparser.h b/src/instrumentparser.h index 6cbaf8a..793bfb6 100644 --- a/src/instrumentparser.h +++ b/src/instrumentparser.h @@ -29,6 +29,7 @@ #include "saxparser.h" #include "instrument.h" +#include #include class InstrumentParser -- cgit v1.2.3