annotate AgentList.h @ 16:33d0b18b2509

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