summaryrefslogtreecommitdiff
path: root/src/drumkitparser.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2017-09-03 14:08:41 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2017-09-03 14:08:41 +0200
commit1c25d3a69ac27dc1f93bca3a71996e757b452c4b (patch)
treea67541f62bd35577003f812b35ab6a35098e36ae /src/drumkitparser.cc
parenta359d234ff53bcdab671faa169f45c4f14f5575d (diff)
Add bleed controls for the drumkit with priority over those set in the instrument files.
Diffstat (limited to 'src/drumkitparser.cc')
-rw-r--r--src/drumkitparser.cc77
1 files changed, 52 insertions, 25 deletions
diff --git a/src/drumkitparser.cc b/src/drumkitparser.cc
index f517ef7..2a49e47 100644
--- a/src/drumkitparser.cc
+++ b/src/drumkitparser.cc
@@ -177,7 +177,14 @@ void DrumKitParser::startTag(const std::string& name, const attr_t& attr)
return;
}
- channelmap[attr.at("in")] = attr.at("out");
+ channel_attribute_t cattr{attr.at("out"), main_state_t::unset};
+ if(attr.find("main") != attr.end())
+ {
+ cattr.main_state = (attr.at("main") == "true") ?
+ main_state_t::is_main : main_state_t::is_not_main;
+ }
+
+ channelmap[attr.at("in")] = cattr;
}
}
@@ -185,43 +192,63 @@ void DrumKitParser::endTag(const std::string& name)
{
if(name == "instrument")
{
- auto ptr = std::make_unique<Instrument>(settings, rand);
- ptr->setGroup(instr_group);
+ {
+ // Scope the std::unique_ptr 'ptr' so we don't accidentally use it after
+ // it is std::move'd to the instruments list.
+ auto ptr = std::make_unique<Instrument>(settings, rand);
+ ptr->setGroup(instr_group);
+
+ InstrumentParser parser(*ptr);
+ parser.parseFile(path + "/" + instr_file);
+
+ // Transfer ownership to the DrumKit object.
+ kit.instruments.emplace_back(std::move(ptr));
+ }
+
+ auto& instrument = *kit.instruments.back();
+
+ // Only use main attribute from drumkit file if at least one exists.
+ main_state_t default_main_state = main_state_t::unset;
+ for(const auto& channel: channelmap)
+ {
+ if(channel.second.main_state != main_state_t::unset)
+ {
+ default_main_state = main_state_t::is_not_main;
+ }
+ }
- InstrumentParser parser(*ptr);
- parser.parseFile(path + "/" + instr_file);
+ // Assign kit channel numbers to instruments channels and reset
+ // main_state attribute as needed.
+ for(auto& instrument_channel: instrument.instrument_channels)
+ {
+ channel_attribute_t cattr{instrument_channel.name, main_state_t::unset};
+ if(channelmap.find(instrument_channel.name) != channelmap.end())
+ {
+ cattr = channelmap[instrument_channel.name];
+ }
- // Transfer ownership to the DrumKit object.
- kit.instruments.emplace_back(std::move(ptr));
- Instrument& instrument = *kit.instruments.back();
+ if(cattr.main_state == main_state_t::unset)
+ {
+ cattr.main_state = default_main_state;
+ }
- // Assign kit channel numbers to instruments channels.
- for (auto& c: instrument.instrument_channels) {
- std::string cname = c.name;
- if(channelmap.find(cname) != channelmap.end())
+ if(cattr.main_state != main_state_t::unset)
{
- cname = channelmap[cname];
+ instrument_channel.main = cattr.main_state;
}
- for(std::size_t cnt = 0; cnt < kit.channels.size(); cnt++)
+ for(auto cnt = 0u; cnt < kit.channels.size(); ++cnt)
{
- if(kit.channels[cnt].name == cname)
+ if(kit.channels[cnt].name == cattr.cname)
{
- c.num = kit.channels[cnt].num;
+ instrument_channel.num = kit.channels[cnt].num;
}
}
- if(c.num == NO_CHANNEL)
+ if(instrument_channel.num == NO_CHANNEL)
{
ERR(kitparser, "Missing channel '%s' in instrument '%s'\n",
- c.name.c_str(), instrument.getName().c_str());
- }
- else
- {
- /*
- DEBUG(kitparser, "Assigned channel '%s' to number %d in instrument '%s'\n",
- c->name.c_str(), c->num, i.name().c_str());
- */
+ instrument_channel.name.c_str(), instrument.getName().c_str());
}
}