diff options
Diffstat (limited to 'src/sample.cc')
-rw-r--r-- | src/sample.cc | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/src/sample.cc b/src/sample.cc index 27382af..66fe3c5 100644 --- a/src/sample.cc +++ b/src/sample.cc @@ -31,42 +31,45 @@ #include <sndfile.h> -Sample::Sample(std::string name, float power) +Sample::Sample(const std::string& name, float power) + : name{name} + , power{power} + , audiofiles{} { - this->name = name; - this->power = power; } Sample::~Sample() { } -void Sample::addAudioFile(Channel *c, AudioFile *a) +void Sample::addAudioFile(Channel* c, AudioFile* a) { - audiofiles[c] = a; + audiofiles[c] = a; } -AudioFile *Sample::getAudioFile(Channel *c) +AudioFile* Sample::getAudioFile(Channel* c) { - /* - if(audiofiles.find(c) == audiofiles.end()) return NULL; - return audiofiles[c]; - */ + /* + if(audiofiles.find(c) == audiofiles.end()) return nullptr; + 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++; - } + // todo: std::find_if ?? + for (auto& pair: audiofiles) + { + if (pair.first->num == c->num) + { + return pair.second; + } + } - return NULL; + return nullptr; } #ifdef TEST_SAMPLE -//deps: channel.cc audiofile.cc -//cflags: $(SNDFILE_CFLAGS) -//libs: $(SNDFILE_LIBS) +// deps: channel.cc audiofile.cc +// cflags: $(SNDFILE_CFLAGS) +// libs: $(SNDFILE_LIBS) #include "test.h" TEST_BEGIN; @@ -78,8 +81,8 @@ AudioFile a("test"); s.addAudioFile(&c, &a); TEST_EQUAL(s.getAudioFile(&c), &a, "?"); -TEST_EQUAL(s.getAudioFile(&c2), NULL, "?"); +TEST_EQUAL(s.getAudioFile(&c2), nullptr, "?"); TEST_END; -#endif/*TEST_SAMPLE*/ +#endif /*TEST_SAMPLE*/ |