From 6ac5946767ba41d7eff9eb8521519007fdc58750 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 23 Mar 2016 21:57:41 +0100 Subject: More cleanup. --- src/sample.cc | 67 ++++++++++++++++++++--------------------------------------- 1 file changed, 22 insertions(+), 45 deletions(-) (limited to 'src/sample.cc') diff --git a/src/sample.cc b/src/sample.cc index 27382af..22bee14 100644 --- a/src/sample.cc +++ b/src/sample.cc @@ -26,60 +26,37 @@ */ #include "sample.h" -#include -#include - -#include - -Sample::Sample(std::string name, float power) +Sample::Sample(const std::string& name, float power) + : name(name) + , power(power) { - this->name = name; - this->power = power; } Sample::~Sample() { } -void Sample::addAudioFile(Channel *c, AudioFile *a) +void Sample::addAudioFile(InstrumentChannel* instrument_channel, + AudioFile* audio_file) { - audiofiles[c] = a; + audiofiles[instrument_channel] = audio_file; } -AudioFile *Sample::getAudioFile(Channel *c) +AudioFile *Sample::getAudioFile(InstrumentChannel* instrument_channel) { - /* - if(audiofiles.find(c) == audiofiles.end()) return NULL; - return audiofiles[c]; - */ - - AudioFiles::iterator i = audiofiles.begin(); - while(i != audiofiles.end()) { - Channel *ch = i->first; - if(c->num == ch->num) return i->second; - i++; - } - - return NULL; + /* + if(audiofiles.find(c) == audiofiles.end()) return NULL; + return audiofiles[c]; + */ + + for(auto& audio_file : audiofiles) + { + InstrumentChannel *ch = audio_file.first; + if(instrument_channel->num == ch->num) + { + return audio_file.second; + } + } + + return nullptr; } - -#ifdef TEST_SAMPLE -//deps: channel.cc audiofile.cc -//cflags: $(SNDFILE_CFLAGS) -//libs: $(SNDFILE_LIBS) -#include "test.h" - -TEST_BEGIN; - -Sample s; -InstrumentChannel c; -InstrumentChannel c2; -AudioFile a("test"); - -s.addAudioFile(&c, &a); -TEST_EQUAL(s.getAudioFile(&c), &a, "?"); -TEST_EQUAL(s.getAudioFile(&c2), NULL, "?"); - -TEST_END; - -#endif/*TEST_SAMPLE*/ -- cgit v1.2.3