To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / AgentFeeder.cpp @ 66:7ad142c710c6

History | View | Annotate | Download (3.4 KB)

1 53:19c8c6ca4406 Chris
/* -*- 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 54:751b43d119cf Chris
    if (m_haveCurrent) {
30
        if (m_current.accept(e)) {
31
            return;
32
        }
33
        if (m_current.getState() == NoteHypothesis::Expired) {
34
            m_accepted.push_back(m_current);
35
            m_haveCurrent = false;
36
        }
37
    }
38 53:19c8c6ca4406 Chris
39 54:751b43d119cf Chris
    bool swallowed = false;
40 53:19c8c6ca4406 Chris
41 54:751b43d119cf Chris
    Hypotheses newCandidates;
42 53:19c8c6ca4406 Chris
43 54:751b43d119cf Chris
    for (Hypotheses::iterator i = m_candidates.begin();
44
         i != m_candidates.end(); ++i) {
45
46
        NoteHypothesis h = *i;
47
48
        if (swallowed) {
49
50
            // don't offer: each observation can only belong to one
51
            // satisfied hypothesis
52
            newCandidates.push_back(h);
53
54
        } else {
55
56
            if (h.accept(e)) {
57 53:19c8c6ca4406 Chris
58 54:751b43d119cf Chris
                if (h.getState() == NoteHypothesis::Satisfied) {
59
60
                    swallowed = true;
61
62
                    if (!m_haveCurrent ||
63
                        m_current.getState() == NoteHypothesis::Expired ||
64
                        m_current.getState() == NoteHypothesis::Rejected) {
65
                        m_current = h;
66
                        m_haveCurrent = true;
67
                    } else {
68
                        newCandidates.push_back(h);
69
                    }
70
71
                } else {
72
                    newCandidates.push_back(h);
73
                }
74
            }
75
        }
76
    }
77
78
    if (!swallowed) {
79 66:7ad142c710c6 Chris
        NoteHypothesis h(m_slack);
80 54:751b43d119cf Chris
        if (h.accept(e)) {
81
            newCandidates.push_back(h);
82
        }
83
    }
84
85
    m_candidates = reap(newCandidates);
86 53:19c8c6ca4406 Chris
}
87
88 54:751b43d119cf Chris
AgentFeeder::Hypotheses
89
AgentFeeder::reap(Hypotheses candidates)
90
{
91
    // reap rejected/expired hypotheses from list of candidates
92
93
    Hypotheses survived;
94
    for (Hypotheses::const_iterator i = candidates.begin();
95
         i != candidates.end(); ++i) {
96
        NoteHypothesis h = *i;
97
        if (h.getState() != NoteHypothesis::Rejected &&
98
            h.getState() != NoteHypothesis::Expired) {
99
            survived.push_back(h);
100
        }
101
    }
102
103
    return survived;
104
}
105
106 53:19c8c6ca4406 Chris
void
107
AgentFeeder::finish()
108
{
109
    if (m_current.getState() == NoteHypothesis::Satisfied) {
110
        m_accepted.push_back(m_current);
111
    }
112
}