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 @ 23:633ec097fa56
History | View | Annotate | Download (4.45 KB)
| 1 |
/* -*- 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 |
#include <vector> |
| 23 |
#include <algorithm> |
| 24 |
|
| 25 |
#ifdef DEBUG_BEATROOT
|
| 26 |
#include <iostream> |
| 27 |
#endif
|
| 28 |
|
| 29 |
/** Class for maintaining the set of all Agents involved in beat tracking a piece of music.
|
| 30 |
*/
|
| 31 |
class AgentList |
| 32 |
{
|
| 33 |
public:
|
| 34 |
typedef std::vector<Agent *> Container;
|
| 35 |
typedef Container::iterator iterator;
|
| 36 |
|
| 37 |
protected:
|
| 38 |
Container list; |
| 39 |
|
| 40 |
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 |
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 |
size_t size() { return list.size(); }
|
| 55 |
void push_back(Agent *a) {
|
| 56 |
list.push_back(a); |
| 57 |
#ifdef DEBUG_BEATROOT
|
| 58 |
std::cerr << " Added Ag#" << a->idNumber << ", have " << list.size() << " agent(s)" << std::endl; |
| 59 |
#endif
|
| 60 |
} |
| 61 |
|
| 62 |
/** 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 |
|
| 66 |
/** For the purpose of removing duplicate agents, the default JND of IBI */
|
| 67 |
static const double DEFAULT_BI; |
| 68 |
|
| 69 |
/** For the purpose of removing duplicate agents, the default JND of phase */
|
| 70 |
static const double DEFAULT_BT; |
| 71 |
|
| 72 |
/** Inserts newAgent into the list in ascending order of beatInterval */
|
| 73 |
void add(Agent *a) {
|
| 74 |
add(a, true);
|
| 75 |
} // add()/1
|
| 76 |
|
| 77 |
/** 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 |
void add(Agent *newAgent, bool sort){ |
| 83 |
push_back(newAgent); |
| 84 |
if (sort) this->sort();
|
| 85 |
} // add()/2
|
| 86 |
|
| 87 |
/** Sorts the AgentList by increasing beatInterval. */
|
| 88 |
void sort() {
|
| 89 |
#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 |
} // sort()
|
| 105 |
|
| 106 |
/** 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 |
|
| 113 |
protected:
|
| 114 |
/** 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 |
void removeDuplicates();
|
| 119 |
|
| 120 |
public:
|
| 121 |
/** 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 |
void beatTrack(EventList el, AgentParameters params) {
|
| 125 |
beatTrack(el, params, -1.0); |
| 126 |
} // beatTrack()/1
|
| 127 |
|
| 128 |
/** 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 |
void beatTrack(EventList el, AgentParameters params, double stop); |
| 133 |
|
| 134 |
/** 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 |
Agent *bestAgent(); |
| 138 |
|
| 139 |
}; // class AgentList
|
| 140 |
|
| 141 |
#endif
|
| 142 |
|