From e190d38057892b69246391841b234a368bc2b4ad Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 1 Mar 2011 19:19:02 +0000 Subject: MAJOR rewrite of the internals. New input/output 'plugin' system. Still a lot missing. --- src/instrument.cc | 59 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 11 deletions(-) (limited to 'src/instrument.cc') diff --git a/src/instrument.cc b/src/instrument.cc index 0aa38ac..b710757 100644 --- a/src/instrument.cc +++ b/src/instrument.cc @@ -26,23 +26,60 @@ */ #include "instrument.h" -Instrument::Instrument(std::string name, unsigned int midimap) +#include + +Instrument::Instrument(std::string name) { this->name = name; - this->midimap = midimap; } -void Instrument::addVelocity(Velocity *velocity) +Sample *Instrument::sample(level_t level) { - velocities.push_back(velocity); + std::vector s = samples.get(level); + if(s.size() == 0) return NULL; + size_t idx = rand()%(s.size()); + return s[idx]; } -Velocity *Instrument::getVelocity(unsigned int v) +void Instrument::addSample(level_t a, level_t b, Sample *s) { - Velocities::iterator i = velocities.begin(); - while(i != velocities.end()) { - if(v >= (*i)->lower && v <= (*i)->upper) return *i; - i++; - } - return NULL; + samples.insert(a, b, s); } + +#ifdef TEST_INSTRUMENT +//deps: channel.cc sample.cc audiofile.cc +//cflags: $(SNDFILE_CFLAGS) +//libs: $(SNDFILE_LIBS) +#include "test.h" + +TEST_BEGIN; + +Instrument i("test"); + +Sample *a = new Sample(); +i.addSample(0.0, 1.0, a); + +Sample *b = new Sample(); +i.addSample(0.0, 1.0, b); + +Sample *c = new Sample(); +i.addSample(1.5, 1.7, c); + +TEST_EQUAL(i.sample(0.0), b, "?"); +TEST_EQUAL(i.sample(0.0), a, "?"); +TEST_EQUAL(i.sample(0.0), b, "?"); +TEST_EQUAL(i.sample(0.0), b, "?"); +TEST_EQUAL(i.sample(0.0), b, "?"); +TEST_EQUAL(i.sample(0.0), b, "?"); +TEST_EQUAL(i.sample(0.0), a, "?"); +TEST_EQUAL(i.sample(0.0), a, "?"); + +TEST_EQUAL(i.sample(2.0), NULL, "?"); + +TEST_EQUAL(i.sample(1.6), c, "?"); +TEST_EQUAL(i.sample(1.6), c, "?"); +TEST_EQUAL(i.sample(1.6), c, "?"); + +TEST_END; + +#endif/*TEST_INSTRUMENT*/ -- cgit v1.2.3