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