summaryrefslogtreecommitdiff
path: root/src/instrumentparser.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2017-09-02 10:30:02 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2017-09-02 10:30:02 +0200
commite37c5f5048bb440140dc56ce773d105fc2129385 (patch)
tree0dfe0ab9faec524fd1ee085c6cf763aa15484331 /src/instrumentparser.cc
parent6a96bcf1659d07cd3a7f7e65519007abfaeda2a0 (diff)
Implement master bleed control in the instrument parser and engine.
Diffstat (limited to 'src/instrumentparser.cc')
-rw-r--r--src/instrumentparser.cc58
1 files changed, 46 insertions, 12 deletions
diff --git a/src/instrumentparser.cc b/src/instrumentparser.cc
index 45e76d8..1f3948e 100644
--- a/src/instrumentparser.cc
+++ b/src/instrumentparser.cc
@@ -82,6 +82,28 @@ void InstrumentParser::startTag(const std::string& name, const attr_t& attr)
}
}
+ if(name == "channels")
+ {
+ }
+
+ if(name == "channel")
+ {
+ if(attr.find("name") == attr.end())
+ {
+ ERR(instrparser,"Missing channel required attribute 'name'.\n");
+ return;
+ }
+
+ bool main = false;
+ if(attr.find("main") != attr.end())
+ {
+ main = attr.at("main") == "true";
+ }
+
+ InstrumentChannel* channel = addOrGetChannel(attr.at("name"));
+ channel->main = main;
+ }
+
if(name == "samples")
{
}
@@ -142,19 +164,13 @@ void InstrumentParser::startTag(const std::string& name, const attr_t& attr)
filechannel = filechannel - 1; // 1-based in file but zero-based internally.
- auto audio_file = std::make_unique<AudioFile>(path + "/" + attr.at("file"), filechannel);
+ InstrumentChannel *instrument_channel = addOrGetChannel(attr.at("channel"));
- // note: memory leak! the channels are never released
- // once I replaced this using unique_ptr, the channels were
- // destroyed when the InstrumentParser went out of scope
- // (see drumkitparser.cc, where the InstrumentParser lives in
- // local scope).
- // so.. we cannot replace this using smart ptr until we decided
- // the ownership semantics for instances InstrumentChannel
- InstrumentChannel *instrument_channel =
- new InstrumentChannel(attr.at("channel"));
+ auto audio_file =
+ std::make_unique<AudioFile>(path + "/" + attr.at("file"),
+ filechannel,
+ instrument_channel->main);
- channellist.push_back(instrument_channel);
sample->addAudioFile(instrument_channel, audio_file.get());
// Transfer audio_file ownership to the instrument.
@@ -203,7 +219,7 @@ void InstrumentParser::startTag(const std::string& name, const attr_t& attr)
if(sample_ref == nullptr)
{
- ERR(instrparser,"Samplref pointed at non-existing sample.\n");
+ ERR(instrparser,"Sampleref pointed at non-existing sample.\n");
return;
}
@@ -234,3 +250,21 @@ void InstrumentParser::endTag(const std::string& name)
instrument.finalise();
}
}
+
+InstrumentChannel* InstrumentParser::addOrGetChannel(const std::string& name)
+{
+ for(auto& channel : instrument.instrument_channels)
+ {
+ if(channel.name == name)
+ {
+ return &channel;
+ }
+ }
+
+ instrument.instrument_channels.emplace_back(name);
+ InstrumentChannel& channel = instrument.instrument_channels.back();
+ channel.main = true; // Ad-hoc added channels are all main by default for
+ // backwards compatibility.
+
+ return &channel;
+}