To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / AgentList.h
History | View | Annotate | Download (4.45 KB)
| 1 | 8:f04f87b5e643 | Chris | /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
|---|---|---|---|
| 2 | |||
| 3 | /*
|
||
| 4 | Vamp feature extraction plugin for the BeatRoot beat tracker.
|
||
| 5 | |||
| 6 | Centre for Digital Music, Queen Mary, University of London.
|
||
| 7 | This file copyright 2011 Simon Dixon, Chris Cannam and QMUL.
|
||
| 8 | |||
| 9 | This program is free software; you can redistribute it and/or
|
||
| 10 | modify it under the terms of the GNU General Public License as
|
||
| 11 | published by the Free Software Foundation; either version 2 of the
|
||
| 12 | License, or (at your option) any later version. See the file
|
||
| 13 | COPYING included with this distribution for more information.
|
||
| 14 | */
|
||
| 15 | |||
| 16 | #ifndef _AGENT_LIST_H_
|
||
| 17 | #define _AGENT_LIST_H_
|
||
| 18 | |||
| 19 | #include "Agent.h" |
||
| 20 | #include "Event.h" |
||
| 21 | |||
| 22 | 13:0d4048bfadbb | Chris | #include <vector> |
| 23 | 8:f04f87b5e643 | Chris | #include <algorithm> |
| 24 | |||
| 25 | 12:59520cd6abac | Chris | #ifdef DEBUG_BEATROOT
|
| 26 | #include <iostream> |
||
| 27 | #endif
|
||
| 28 | |||
| 29 | 8:f04f87b5e643 | Chris | /** Class for maintaining the set of all Agents involved in beat tracking a piece of music.
|
| 30 | */
|
||
| 31 | class AgentList |
||
| 32 | {
|
||
| 33 | public:
|
||
| 34 | 16:33d0b18b2509 | Chris | typedef std::vector<Agent *> Container;
|
| 35 | 8:f04f87b5e643 | Chris | typedef Container::iterator iterator;
|
| 36 | |||
| 37 | protected:
|
||
| 38 | Container list; |
||
| 39 | |||
| 40 | 20:03927f6acee2 | Chris | static bool agentComparator(const Agent *a, const Agent *b) { |
| 41 | if (a->beatInterval == b->beatInterval) {
|
||
| 42 | return a->idNumber < b->idNumber; // ensure stable ordering |
||
| 43 | } else {
|
||
| 44 | return a->beatInterval < b->beatInterval;
|
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | 8:f04f87b5e643 | Chris | public:
|
| 49 | // expose some vector methods
|
||
| 50 | //!!! can we remove these again once the rest of AgentList is implemented?
|
||
| 51 | bool empty() const { return list.empty(); } |
||
| 52 | Container::iterator begin() { return list.begin(); }
|
||
| 53 | Container::iterator end() { return list.end(); }
|
||
| 54 | 12:59520cd6abac | Chris | size_t size() { return list.size(); }
|
| 55 | 16:33d0b18b2509 | Chris | void push_back(Agent *a) {
|
| 56 | 12:59520cd6abac | Chris | list.push_back(a); |
| 57 | #ifdef DEBUG_BEATROOT
|
||
| 58 | 16:33d0b18b2509 | Chris | std::cerr << " Added Ag#" << a->idNumber << ", have " << list.size() << " agent(s)" << std::endl; |
| 59 | 12:59520cd6abac | Chris | #endif
|
| 60 | } |
||
| 61 | 8:f04f87b5e643 | Chris | |
| 62 | 11:7169eb47b1bc | Chris | /** Flag for choice between sum and average beat salience values for Agent scores.
|
| 63 | * The use of summed saliences favours faster tempi or lower metrical levels. */
|
||
| 64 | static bool useAverageSalience; |
||
| 65 | 8:f04f87b5e643 | Chris | |
| 66 | 11:7169eb47b1bc | Chris | /** For the purpose of removing duplicate agents, the default JND of IBI */
|
| 67 | static const double DEFAULT_BI; |
||
| 68 | 8:f04f87b5e643 | Chris | |
| 69 | 11:7169eb47b1bc | Chris | /** For the purpose of removing duplicate agents, the default JND of phase */
|
| 70 | static const double DEFAULT_BT; |
||
| 71 | 8:f04f87b5e643 | Chris | |
| 72 | 11:7169eb47b1bc | Chris | /** Inserts newAgent into the list in ascending order of beatInterval */
|
| 73 | 16:33d0b18b2509 | Chris | void add(Agent *a) {
|
| 74 | 11:7169eb47b1bc | Chris | add(a, true);
|
| 75 | } // add()/1
|
||
| 76 | 8:f04f87b5e643 | Chris | |
| 77 | 11:7169eb47b1bc | Chris | /** Appends newAgent to list (sort==false), or inserts newAgent into the list
|
| 78 | * in ascending order of beatInterval
|
||
| 79 | * @param newAgent The agent to be added to the list
|
||
| 80 | * @param sort Flag indicating whether the list is sorted or not
|
||
| 81 | */
|
||
| 82 | 16:33d0b18b2509 | Chris | void add(Agent *newAgent, bool sort){ |
| 83 | 12:59520cd6abac | Chris | push_back(newAgent); |
| 84 | 11:7169eb47b1bc | Chris | if (sort) this->sort();
|
| 85 | } // add()/2
|
||
| 86 | 8:f04f87b5e643 | Chris | |
| 87 | 11:7169eb47b1bc | Chris | /** Sorts the AgentList by increasing beatInterval. */
|
| 88 | void sort() {
|
||
| 89 | 20:03927f6acee2 | Chris | #ifdef DEBUG_BEATROOT
|
| 90 | std::cerr << "sort: before: ";
|
||
| 91 | for (iterator i = list.begin(); i != list.end(); ++i) {
|
||
| 92 | std::cerr << (*i)->idNumber << " ";
|
||
| 93 | } |
||
| 94 | std::cerr << std::endl; |
||
| 95 | #endif
|
||
| 96 | std::sort(list.begin(), list.end(), agentComparator); |
||
| 97 | #ifdef DEBUG_BEATROOT
|
||
| 98 | std::cerr << "sort: after: ";
|
||
| 99 | for (iterator i = list.begin(); i != list.end(); ++i) {
|
||
| 100 | std::cerr << (*i)->idNumber << " ";
|
||
| 101 | } |
||
| 102 | std::cerr << std::endl; |
||
| 103 | #endif
|
||
| 104 | 11:7169eb47b1bc | Chris | } // sort()
|
| 105 | 8:f04f87b5e643 | Chris | |
| 106 | 11:7169eb47b1bc | Chris | /** Removes the given item from the list.
|
| 107 | * @param ptr Points to the Agent which is removed from the list
|
||
| 108 | */
|
||
| 109 | void remove(iterator itr) {
|
||
| 110 | list.erase(itr); |
||
| 111 | } // remove()
|
||
| 112 | 8:f04f87b5e643 | Chris | |
| 113 | protected:
|
||
| 114 | 11:7169eb47b1bc | Chris | /** Removes Agents from the list which are duplicates of other Agents.
|
| 115 | * A duplicate is defined by the tempo and phase thresholds
|
||
| 116 | * thresholdBI and thresholdBT respectively.
|
||
| 117 | */
|
||
| 118 | 15:887c629502a9 | Chris | void removeDuplicates();
|
| 119 | 8:f04f87b5e643 | Chris | |
| 120 | public:
|
||
| 121 | 11:7169eb47b1bc | Chris | /** Perform beat tracking on a list of events (onsets).
|
| 122 | * @param el The list of onsets (or events or peaks) to beat track
|
||
| 123 | */
|
||
| 124 | 23:633ec097fa56 | Chris | void beatTrack(EventList el, AgentParameters params) {
|
| 125 | beatTrack(el, params, -1.0); |
||
| 126 | 11:7169eb47b1bc | Chris | } // beatTrack()/1
|
| 127 | 8:f04f87b5e643 | Chris | |
| 128 | 11:7169eb47b1bc | Chris | /** Perform beat tracking on a list of events (onsets).
|
| 129 | * @param el The list of onsets (or events or peaks) to beat track.
|
||
| 130 | * @param stop Do not find beats after <code>stop</code> seconds.
|
||
| 131 | */
|
||
| 132 | 23:633ec097fa56 | Chris | void beatTrack(EventList el, AgentParameters params, double stop); |
| 133 | 8:f04f87b5e643 | Chris | |
| 134 | 11:7169eb47b1bc | Chris | /** Finds the Agent with the highest score in the list, or NULL if beat tracking has failed.
|
| 135 | * @return The Agent with the highest score
|
||
| 136 | */
|
||
| 137 | 15:887c629502a9 | Chris | Agent *bestAgent(); |
| 138 | 8:f04f87b5e643 | Chris | |
| 139 | }; // class AgentList
|
||
| 140 | |||
| 141 | #endif
|