summaryrefslogtreecommitdiff
path: root/src/instrument.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2019-01-27 17:02:40 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2019-01-27 17:02:40 +0100
commit2aae9799e1d96d827ad156aeafa549deabd51e5d (patch)
tree707fb2798cd3b9304fc4af690b557efc9d98a1a8 /src/instrument.cc
parent053b723adf3948d18f025efed9450d837359edd9 (diff)
Re-instate instrument v1.0 support.
Diffstat (limited to 'src/instrument.cc')
-rw-r--r--src/instrument.cc39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/instrument.cc b/src/instrument.cc
index 05ac17d..29619d8 100644
--- a/src/instrument.cc
+++ b/src/instrument.cc
@@ -54,21 +54,44 @@ bool Instrument::isValid() const
return this == magic;
}
-Sample* Instrument::sample(level_t level, size_t pos)
+const Sample* Instrument::sample(level_t level, size_t pos)
{
- return powerlist.get(level * mod);
+ if(version >= VersionStr("2.0"))
+ {
+ // Version 2.0
+ return powerlist.get(level * mod);
+ }
+ else
+ {
+ // Version 1.0
+ auto s = samples.get(level * mod);
+ if(s.size() == 0)
+ {
+ return nullptr;
+ }
+
+ return rand.choose(s);
+ }
+}
+
+void Instrument::addSample(level_t a, level_t b, const Sample* s)
+{
+ samples.insert(a, b, s);
}
void Instrument::finalise()
{
- std::vector<Sample*>::iterator s = samplelist.begin();
- while(s != samplelist.end())
+ if(version >= VersionStr("2.0"))
{
- powerlist.add(*s);
- s++;
+ std::vector<Sample*>::iterator s = samplelist.begin();
+ while(s != samplelist.end())
+ {
+ powerlist.add(*s);
+ s++;
+ }
+
+ powerlist.finalise();
}
-
- powerlist.finalise();
}
const std::string& Instrument::getName() const