diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-03-23 21:57:41 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-03-23 21:57:41 +0100 |
commit | 91b3683ad0b6228bf85eefdb32e2ac3f717bd41c (patch) | |
tree | 8bdfae1492f2a658992d79faf85fab95a645c8bc /src/sample.cc | |
parent | 5c04b951ffe53e1a31182bb0814908af8d7f0a6f (diff) |
More cleanup.
Diffstat (limited to 'src/sample.cc')
-rw-r--r-- | src/sample.cc | 67 |
1 files changed, 22 insertions, 45 deletions
diff --git a/src/sample.cc b/src/sample.cc index 45dc415..10fa6b1 100644 --- a/src/sample.cc +++ b/src/sample.cc @@ -26,60 +26,37 @@ */ #include "sample.h" -#include <stdlib.h> -#include <unistd.h> - -#include <sndfile.h> - -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*/ |