diff options
author | André Nusser <andre.nusser@googlemail.com> | 2016-04-24 13:26:00 +0200 |
---|---|---|
committer | André Nusser <andre.nusser@googlemail.com> | 2016-04-24 23:20:44 +0200 |
commit | 103401bab34dd8d9e01a07b7a4a02f0bf577eaa7 (patch) | |
tree | 0d00a572da400387b467742966319eea9b898957 /src | |
parent | 2ff860a7f2c8fe5cf027d1d792f539ab8bb27fe6 (diff) |
Split process in InputProcessor into process_onset and process_stop.
Diffstat (limited to 'src')
-rw-r--r-- | src/inputprocessor.cc | 195 | ||||
-rw-r--r-- | src/inputprocessor.h | 3 |
2 files changed, 106 insertions, 92 deletions
diff --git a/src/inputprocessor.cc b/src/inputprocessor.cc index a232e35..3f8cf65 100644 --- a/src/inputprocessor.cc +++ b/src/inputprocessor.cc @@ -46,120 +46,131 @@ bool InputProcessor::process(const std::vector<event_t>& events, size_t pos, dou { if(event.type == TYPE_ONSET) { - Instrument *i = nullptr; - int d = event.instrument; - /* - Instruments::iterator it = kit.instruments.begin(); - while(d-- && it != kit.instruments.end()) - { - i = &(it->second); - ++it; - } - */ - - // TODO can this be removed? - if(!kit.isValid()) + if(!process_onset(event, pos, resample_ratio)) { continue; } + } - if(d < (int)kit.instruments.size()) - { - i = kit.instruments[d]; - } + if(!process_stop(event)) + { + return false; + } + } - if(i == nullptr || !i->isValid()) - { - ERR(inputprocessor, "Missing Instrument %d.\n", (int)event.instrument); - continue; - } + return true; +} + +bool InputProcessor::process_onset(const event_t& event, size_t pos, double resample_ratio) +{ + Instrument* i = nullptr; + int d = event.instrument; + + // TODO can this be removed? + if(!kit.isValid()) + { + return false; + } + + if(d < (int)kit.instruments.size()) + { + i = kit.instruments[d]; + } - if(i->getGroup() != "") + if(i == nullptr || !i->isValid()) + { + ERR(inputprocessor, "Missing Instrument %d.\n", (int)event.instrument); + return false; + } + + if(i->getGroup() != "") + { + // Add event to ramp down all existing events with the same groupname. + Channels::iterator j = kit.channels.begin(); + while(j != kit.channels.end()) + { + Channel &ch = *j; + std::list< Event* >::iterator evs = activeevents[ch.num].begin(); + while(evs != activeevents[ch.num].end()) { - // Add event to ramp down all existing events with the same groupname. - Channels::iterator j = kit.channels.begin(); - while(j != kit.channels.end()) + Event *ev = *evs; + if(ev->getType() == Event::sample) { - Channel &ch = *j; - std::list< Event* >::iterator evs = activeevents[ch.num].begin(); - while(evs != activeevents[ch.num].end()) + EventSample *sev = (EventSample*)ev; + if(sev->group == i->getGroup() && sev->instrument != i) { - Event *ev = *evs; - if(ev->getType() == Event::sample) - { - EventSample *sev = (EventSample*)ev; - if(sev->group == i->getGroup() && sev->instrument != i) - { - sev->rampdown = 3000; // Ramp down 3000 samples - // TODO: This must be configurable at some point... - // ... perhaps even by instrument (ie. in the xml file) - sev->ramp_start = sev->rampdown; - } - } - ++evs; + sev->rampdown = 3000; // Ramp down 3000 samples + // TODO: This must be configurable at some point... + // ... perhaps even by instrument (ie. in the xml file) + sev->ramp_start = sev->rampdown; } - ++j; } + ++evs; } + ++j; + } + } - Sample *s = i->sample(event.velocity, event.offset + pos); + Sample *s = i->sample(event.velocity, event.offset + pos); - if(s == nullptr) - { - ERR(drumgizmo, "Missing Sample.\n"); - continue; - } + if(s == nullptr) + { + ERR(inputprocessor, "Missing Sample.\n"); + return false; + } - Channels::iterator j = kit.channels.begin(); - while(j != kit.channels.end()) - { - Channel &ch = *j; - AudioFile *af = s->getAudioFile(&ch); - if(af) - { - // LAZYLOAD: - // DEBUG(drumgizmo,"Requesting preparing of audio file\n"); - // loader.prepare(af); - } - if(af == nullptr || !af->isValid()) - { - //DEBUG(drumgizmo,"Missing AudioFile.\n"); - } - else - { - //DEBUG(drumgizmo, "Adding event %d.\n", event.offset); - Event *evt = new EventSample(ch.num, 1.0, af, i->getGroup(), i); - evt->offset = (event.offset + pos) * resample_ratio; - activeevents[ch.num].push_back(evt); - } - ++j; - } + Channels::iterator j = kit.channels.begin(); + while(j != kit.channels.end()) + { + Channel &ch = *j; + AudioFile *af = s->getAudioFile(&ch); + if(af) + { + // LAZYLOAD: + // DEBUG(inputprocessor, "Requesting preparing of audio file\n"); + // loader.prepare(af); } - - if(event.type == TYPE_STOP) + if(af == nullptr || !af->isValid()) { - is_stopping = true; + //DEBUG(inputprocessor, "Missing AudioFile.\n"); } - - if(is_stopping) + else { - // Count the number of active events. - int num_active_events = 0; - Channels::iterator j = kit.channels.begin(); - while(j != kit.channels.end()) - { - Channel &ch = *j; - num_active_events += activeevents[ch.num].size(); - ++j; - } + //DEBUG(inputprocessor, "Adding event %d.\n", event.offset); + Event *evt = new EventSample(ch.num, 1.0, af, i->getGroup(), i); + evt->offset = (event.offset + pos) * resample_ratio; + activeevents[ch.num].push_back(evt); + } + ++j; + } - if(num_active_events == 0) - { - // No more active events - now we can stop the engine. - return false; - } + return true; +} + +bool InputProcessor::process_stop(const event_t& event) +{ + if(event.type == TYPE_STOP) + { + is_stopping = true; + } + + if(is_stopping) + { + // Count the number of active events. + int num_active_events = 0; + Channels::iterator j = kit.channels.begin(); + while(j != kit.channels.end()) + { + Channel &ch = *j; + num_active_events += activeevents[ch.num].size(); + ++j; } + if(num_active_events == 0) + { + // No more active events - now we can stop the engine. + return false; + } } return true; diff --git a/src/inputprocessor.h b/src/inputprocessor.h index fb12555..7e03737 100644 --- a/src/inputprocessor.h +++ b/src/inputprocessor.h @@ -42,4 +42,7 @@ private: DrumKit& kit; std::list<Event*>* activeevents; bool is_stopping; ///< Is set to true when a TYPE_STOP event has been seen. + + bool process_onset(const event_t& event, size_t pos, double resample_ratio); + bool process_stop(const event_t& event); }; |