Chris@53: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@53: /* Chris@53: This file is Copyright (c) 2012 Chris Cannam Chris@53: Chris@53: Permission is hereby granted, free of charge, to any person Chris@53: obtaining a copy of this software and associated documentation Chris@53: files (the "Software"), to deal in the Software without Chris@53: restriction, including without limitation the rights to use, copy, Chris@53: modify, merge, publish, distribute, sublicense, and/or sell copies Chris@53: of the Software, and to permit persons to whom the Software is Chris@53: furnished to do so, subject to the following conditions: Chris@53: Chris@53: The above copyright notice and this permission notice shall be Chris@53: included in all copies or substantial portions of the Software. Chris@53: Chris@53: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, Chris@53: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF Chris@53: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND Chris@53: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR Chris@53: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF Chris@53: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION Chris@53: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Chris@53: */ Chris@53: Chris@53: #include "AgentFeeder.h" Chris@53: Chris@53: void AgentFeeder::feed(NoteHypothesis::Estimate e) Chris@53: { Chris@53: if (!m_current.accept(e)) { Chris@53: Chris@53: if (m_current.getState() == NoteHypothesis::Expired) { Chris@53: m_accepted.push_back(m_current); Chris@53: } Chris@53: Chris@53: bool swallowed = false; Chris@53: Chris@53: Hypotheses newCandidates; Chris@53: Chris@53: for (typename Hypotheses::iterator i = m_candidates.begin(); Chris@53: i != m_candidates.end(); ++i) { Chris@53: Chris@53: NoteHypothesis h = *i; Chris@53: Chris@53: if (swallowed) { Chris@53: Chris@53: // don't offer: each observation can only belong to one Chris@53: // satisfied hypothesis Chris@53: newCandidates.push_back(h); Chris@53: Chris@53: } else { Chris@53: Chris@53: if (h.accept(e)) { Chris@53: Chris@53: if (h.getState() == NoteHypothesis::Satisfied) { Chris@53: Chris@53: swallowed = true; Chris@53: Chris@53: if (m_current.getState() == NoteHypothesis::Expired || Chris@53: m_current.getState() == NoteHypothesis::Rejected) { Chris@53: m_current = h; Chris@53: } else { Chris@53: newCandidates.push_back(h); Chris@53: } Chris@53: Chris@53: } else { Chris@53: newCandidates.push_back(h); Chris@53: } Chris@53: } Chris@53: } Chris@53: } Chris@53: Chris@53: if (!swallowed) { Chris@53: NoteHypothesis h; Chris@53: h.accept(e); // must succeed, as h is new Chris@53: newCandidates.push_back(h); Chris@53: } Chris@53: Chris@53: // reap rejected/expired hypotheses from candidates list, Chris@53: // and assign back to m_candidates Chris@53: Chris@53: m_candidates.clear(); Chris@53: Chris@53: for (typename Hypotheses::const_iterator i = newCandidates.begin(); Chris@53: i != newCandidates.end(); ++i) { Chris@53: NoteHypothesis h = *i; Chris@53: if (h.getState() != NoteHypothesis::Rejected && Chris@53: h.getState() != NoteHypothesis::Expired) { Chris@53: m_candidates.push_back(h); Chris@53: } Chris@53: } Chris@53: } Chris@53: } Chris@53: Chris@53: void Chris@53: AgentFeeder::finish() Chris@53: { Chris@53: if (m_current.getState() == NoteHypothesis::Satisfied) { Chris@53: m_accepted.push_back(m_current); Chris@53: } Chris@53: } Chris@53: