From 6509ebfaea12f690af459ddc85416786e475684b Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 5 Oct 2011 21:24:01 +0200 Subject: Make channel maps work. --- src/drumkitparser.cc | 65 ++++++++++++++++++++++++++-------------------------- src/drumkitparser.h | 4 ++++ 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/src/drumkitparser.cc b/src/drumkitparser.cc index 1c16574..53b0a6d 100644 --- a/src/drumkitparser.cc +++ b/src/drumkitparser.cc @@ -85,8 +85,31 @@ void DrumKitParser::startTag(std::string name, printf("Missing file in instrument tag.\n"); return; } + + instr_name = attr["name"]; + instr_file = attr["file"]; + } + + if(name == "channelmap") { + if(attr.find("in") == attr.end()) { + printf("Missing 'in' in channelmap tag.\n"); + return; + } + + if(attr.find("out") == attr.end()) { + printf("Missing 'out' in channelmap tag.\n"); + return; + } + + channelmap[attr["in"]] = attr["out"]; + } +} + +void DrumKitParser::endTag(std::string name) +{ + if(name == "instrument") { Instrument i; - InstrumentParser parser(path + "/" + attr["file"], i); + InstrumentParser parser(path + "/" + instr_file, i); parser.parse(); kit.instruments.push_back(i);//[attr["name"]] = i; @@ -95,49 +118,27 @@ void DrumKitParser::startTag(std::string name, while(ic != parser.channellist.end()) { InstrumentChannel *c = *ic; + std::string cname = c->name; + if(channelmap.find(cname) != channelmap.end()) cname = channelmap[cname]; + for(size_t cnt = 0; cnt < kit.channels.size(); cnt++) { - if(kit.channels[cnt].name == c->name) c->num = kit.channels[cnt].num; + if(kit.channels[cnt].name == cname) c->num = kit.channels[cnt].num; } if(c->num == NO_CHANNEL) { printf("Missing channel '%s' in instrument '%s'\n", c->name.c_str(), i.name().c_str()); } else { - printf("Assigned channel '%s' to number %d in instrument '%s'\n", - c->name.c_str(), c->num, i.name().c_str()); + /* + printf("Assigned channel '%s' to number %d in instrument '%s'\n", + c->name.c_str(), c->num, i.name().c_str()); + */ } ic++; } - //instr = &kit.instruments[attr["name"]]; - } - /* - if(name == "channelmap") { - if(instr == NULL) { - printf("Missing instrument.\n"); - return; - } - - if(attr.find("in") == attr.end()) { - printf("Missing 'in' in channelmap tag.\n"); - return; - } - - if(attr.find("out") == attr.end()) { - printf("Missing 'out' in channelmap tag.\n"); - return; - } - instr->channelmap[attr["in"]] = attr["out"]; - } - */ -} + channelmap.clear(); -void DrumKitParser::endTag(std::string name) -{ - /* - if(name == "instrument") { - instr = NULL; } - */ } int DrumKitParser::readData(char *data, size_t size) diff --git a/src/drumkitparser.h b/src/drumkitparser.h index f585043..f02eece 100644 --- a/src/drumkitparser.h +++ b/src/drumkitparser.h @@ -47,6 +47,10 @@ private: DrumKit &kit; // Instrument *instr; std::string path; + + std::map channelmap; + std::string instr_file; + std::string instr_name; }; #endif/*__DRUMGIZMO_DRUMKITPARSER_H__*/ -- cgit v1.2.3