summaryrefslogtreecommitdiff
path: root/src/sample.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2016-03-23 21:57:41 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2016-03-29 22:43:32 +0200
commit6ac5946767ba41d7eff9eb8521519007fdc58750 (patch)
tree3ea70169dfe7568fa97c54c19a6f2de5189ef249 /src/sample.cc
parentef1d7e4478649296ccb17900acc949a604097d66 (diff)
More cleanup.
Diffstat (limited to 'src/sample.cc')
-rw-r--r--src/sample.cc67
1 files changed, 22 insertions, 45 deletions
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 <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*/