To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / AgentFeeder.cpp @ 53:19c8c6ca4406
History | View | Annotate | Download (2.77 KB)
| 1 |
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
|---|---|
| 2 |
/*
|
| 3 |
This file is Copyright (c) 2012 Chris Cannam
|
| 4 |
|
| 5 |
Permission is hereby granted, free of charge, to any person
|
| 6 |
obtaining a copy of this software and associated documentation
|
| 7 |
files (the "Software"), to deal in the Software without
|
| 8 |
restriction, including without limitation the rights to use, copy,
|
| 9 |
modify, merge, publish, distribute, sublicense, and/or sell copies
|
| 10 |
of the Software, and to permit persons to whom the Software is
|
| 11 |
furnished to do so, subject to the following conditions:
|
| 12 |
|
| 13 |
The above copyright notice and this permission notice shall be
|
| 14 |
included in all copies or substantial portions of the Software.
|
| 15 |
|
| 16 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 17 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 18 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 19 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
| 20 |
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
| 21 |
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
| 22 |
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 23 |
*/
|
| 24 |
|
| 25 |
#include "AgentFeeder.h" |
| 26 |
|
| 27 |
void AgentFeeder::feed(NoteHypothesis::Estimate e)
|
| 28 |
{
|
| 29 |
if (!m_current.accept(e)) {
|
| 30 |
|
| 31 |
if (m_current.getState() == NoteHypothesis::Expired) {
|
| 32 |
m_accepted.push_back(m_current); |
| 33 |
} |
| 34 |
|
| 35 |
bool swallowed = false; |
| 36 |
|
| 37 |
Hypotheses newCandidates; |
| 38 |
|
| 39 |
for (typename Hypotheses::iterator i = m_candidates.begin(); |
| 40 |
i != m_candidates.end(); ++i) {
|
| 41 |
|
| 42 |
NoteHypothesis h = *i; |
| 43 |
|
| 44 |
if (swallowed) {
|
| 45 |
|
| 46 |
// don't offer: each observation can only belong to one
|
| 47 |
// satisfied hypothesis
|
| 48 |
newCandidates.push_back(h); |
| 49 |
|
| 50 |
} else {
|
| 51 |
|
| 52 |
if (h.accept(e)) {
|
| 53 |
|
| 54 |
if (h.getState() == NoteHypothesis::Satisfied) {
|
| 55 |
|
| 56 |
swallowed = true;
|
| 57 |
|
| 58 |
if (m_current.getState() == NoteHypothesis::Expired ||
|
| 59 |
m_current.getState() == NoteHypothesis::Rejected) {
|
| 60 |
m_current = h; |
| 61 |
} else {
|
| 62 |
newCandidates.push_back(h); |
| 63 |
} |
| 64 |
|
| 65 |
} else {
|
| 66 |
newCandidates.push_back(h); |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
if (!swallowed) {
|
| 73 |
NoteHypothesis h; |
| 74 |
h.accept(e); // must succeed, as h is new
|
| 75 |
newCandidates.push_back(h); |
| 76 |
} |
| 77 |
|
| 78 |
// reap rejected/expired hypotheses from candidates list,
|
| 79 |
// and assign back to m_candidates
|
| 80 |
|
| 81 |
m_candidates.clear(); |
| 82 |
|
| 83 |
for (typename Hypotheses::const_iterator i = newCandidates.begin(); |
| 84 |
i != newCandidates.end(); ++i) {
|
| 85 |
NoteHypothesis h = *i; |
| 86 |
if (h.getState() != NoteHypothesis::Rejected &&
|
| 87 |
h.getState() != NoteHypothesis::Expired) {
|
| 88 |
m_candidates.push_back(h); |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
void
|
| 95 |
AgentFeeder::finish() |
| 96 |
{
|
| 97 |
if (m_current.getState() == NoteHypothesis::Satisfied) {
|
| 98 |
m_accepted.push_back(m_current); |
| 99 |
} |
| 100 |
} |
| 101 |
|