From 331f707aab4ca7b6851eece86cf32ed42938fe04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Tue, 10 May 2016 10:03:35 +0200 Subject: Bugfix in InputProcessor class and avoid multiple map access there. --- src/inputprocessor.cc | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/inputprocessor.cc b/src/inputprocessor.cc index 84e4076..a5d8213 100644 --- a/src/inputprocessor.cc +++ b/src/inputprocessor.cc @@ -67,28 +67,32 @@ bool InputProcessor::processOnset(const event_t& event, size_t pos, double resam return false; } - if(event.instrument >= kit.instruments.size() || - !kit.instruments[event.instrument] || - !kit.instruments[event.instrument]->isValid()) + size_t ev_instr = event.instrument; + Instrument* instr = nullptr; + + if(ev_instr < kit.instruments.size()) { - ERR(inputprocessor, "Missing Instrument %d.\n", (int)event.instrument); - return false; + instr = kit.instruments[ev_instr]; } - Instrument& instr(*kit.instruments[event.instrument]); + if(instr == nullptr || !instr->isValid()) + { + ERR(inputprocessor, "Missing Instrument %d.\n", (int)ev_instr); + return false; + } - if(instr.getGroup() != "") + if(instr->getGroup() != "") { // Add event to ramp down all existing events with the same groupname. - for(auto& ch: kit.channels) + for(Channel& ch: kit.channels) { for(Event* event: activeevents[ch.num]) { if(event->getType() == Event::sample) { - EventSample& event_sample = *(EventSample*)event; - if(event_sample.group == instr.getGroup() && - event_sample.instrument != &instr) + auto& event_sample = *static_cast(event); + if(event_sample.group == instr->getGroup() && + event_sample.instrument != instr) { event_sample.rampdown = 3000; // Ramp down 3000 samples // TODO: This must be configurable at some point... @@ -100,18 +104,18 @@ bool InputProcessor::processOnset(const event_t& event, size_t pos, double resam } } - if(!instr.sample(event.velocity, event.offset + pos)) + Sample* sample = instr->sample(event.velocity, event.offset + pos); + + if(sample == nullptr) { ERR(inputprocessor, "Missing Sample.\n"); return false; } - Sample& s(*instr.sample(event.velocity, event.offset + pos)); - - for(auto& ch: kit.channels) + for(Channel& ch: kit.channels) { - AudioFile* af = s.getAudioFile(&ch); - if(af) + AudioFile* af = sample->getAudioFile(&ch); + if(af != nullptr) { // LAZYLOAD: // DEBUG(inputprocessor, "Requesting preparing of audio file\n"); @@ -124,7 +128,7 @@ bool InputProcessor::processOnset(const event_t& event, size_t pos, double resam else { //DEBUG(inputprocessor, "Adding event %d.\n", event.offset); - Event* evt = new EventSample(ch.num, 1.0, af, instr.getGroup(), &instr); + Event* evt = new EventSample(ch.num, 1.0, af, instr->getGroup(), instr); evt->offset = (event.offset + pos) * resample_ratio; activeevents[ch.num].push_back(evt); } -- cgit v1.2.3