Chris@6
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@6
|
2
|
Chris@6
|
3 /*
|
Chris@6
|
4 Vamp feature extraction plugin for the BeatRoot beat tracker.
|
Chris@6
|
5
|
Chris@6
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@6
|
7 This file copyright 2011 Simon Dixon, Chris Cannam and QMUL.
|
Chris@6
|
8
|
Chris@6
|
9 This program is free software; you can redistribute it and/or
|
Chris@6
|
10 modify it under the terms of the GNU General Public License as
|
Chris@6
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@6
|
12 License, or (at your option) any later version. See the file
|
Chris@6
|
13 COPYING included with this distribution for more information.
|
Chris@6
|
14 */
|
Chris@6
|
15
|
Chris@6
|
16 #ifndef _BEAT_TRACKER_H_
|
Chris@6
|
17 #define _BEAT_TRACKER_H_
|
Chris@6
|
18
|
Chris@6
|
19 #include "Event.h"
|
Chris@6
|
20 #include "Agent.h"
|
Chris@8
|
21 #include "AgentList.h"
|
Chris@7
|
22 #include "Induction.h"
|
Chris@6
|
23
|
Chris@6
|
24 using std::vector;
|
Chris@6
|
25
|
Chris@6
|
26 class BeatTracker
|
Chris@6
|
27 {
|
Chris@6
|
28 protected:
|
Chris@6
|
29 /** beat data encoded as a list of Events */
|
Chris@6
|
30 EventList beats;
|
Chris@6
|
31
|
Chris@6
|
32 /** a list of onset events for passing to the tempo induction and beat tracking methods */
|
Chris@6
|
33 EventList onsetList;
|
Chris@6
|
34
|
Chris@6
|
35 /** the times of onsets (in seconds) */
|
Chris@6
|
36 vector<double> onsets;
|
Chris@6
|
37
|
Chris@6
|
38 public:
|
Chris@6
|
39 /** Constructor:
|
Chris@6
|
40 * @param b The list of beats
|
Chris@6
|
41 */
|
Chris@6
|
42 BeatTracker(EventList b) {
|
Chris@6
|
43 beats = b;
|
Chris@6
|
44 } // BeatTracker constructor
|
Chris@6
|
45
|
Chris@6
|
46 /** Creates a new Event object representing a beat.
|
Chris@6
|
47 * @param time The time of the beat in seconds
|
Chris@6
|
48 * @param beatNum The index of the beat
|
Chris@6
|
49 * @return The Event object representing the beat
|
Chris@6
|
50 */
|
Chris@6
|
51 static Event newBeat(double time, int beatNum) {
|
Chris@6
|
52 return Event(time, beatNum, 0);
|
Chris@6
|
53 } // newBeat()
|
Chris@6
|
54
|
Chris@6
|
55 /** Perform beat tracking.
|
Chris@6
|
56 * @param events The onsets or peaks in a feature list
|
Chris@6
|
57 * @return The list of beats, or an empty list if beat tracking fails
|
Chris@6
|
58 */
|
Chris@23
|
59 static EventList beatTrack(AgentParameters params, EventList events) {
|
Chris@23
|
60 return beatTrack(params, events, EventList());
|
Chris@6
|
61 }
|
Chris@6
|
62
|
Chris@6
|
63 /** Perform beat tracking.
|
Chris@6
|
64 * @param events The onsets or peaks in a feature list
|
Chris@6
|
65 * @param beats The initial beats which are given, if any
|
Chris@6
|
66 * @return The list of beats, or an empty list if beat tracking fails
|
Chris@6
|
67 */
|
Chris@23
|
68 static EventList beatTrack(AgentParameters params,
|
Chris@23
|
69 EventList events, EventList beats);
|
Chris@6
|
70
|
Chris@6
|
71
|
Chris@6
|
72 // Various get and set methods
|
Chris@6
|
73
|
Chris@6
|
74 /** @return the list of beats */
|
Chris@6
|
75 EventList getBeats() {
|
Chris@6
|
76 return beats;
|
Chris@6
|
77 } // getBeats()
|
Chris@6
|
78
|
Chris@6
|
79 /** @return the array of onset times */
|
Chris@6
|
80 vector<double> getOnsets() {
|
Chris@6
|
81 return onsets;
|
Chris@6
|
82 } // getOnsets()
|
Chris@6
|
83
|
Chris@6
|
84 /** Sets the onset times as a list of Events, for use by the beat tracking methods.
|
Chris@6
|
85 * @param on The times of onsets in seconds
|
Chris@6
|
86 */
|
Chris@6
|
87 void setOnsetList(EventList on) {
|
Chris@6
|
88 onsetList = on;
|
Chris@6
|
89 } // setOnsetList()
|
Chris@6
|
90
|
Chris@6
|
91 /** Sets the array of onset times, for displaying MIDI or audio input data.
|
Chris@6
|
92 * @param on The times of onsets in seconds
|
Chris@6
|
93 */
|
Chris@6
|
94 void setOnsets(vector<double> on) {
|
Chris@6
|
95 onsets = on;
|
Chris@6
|
96 } // setOnsets()
|
Chris@6
|
97
|
Chris@6
|
98 /** Sets the list of beats.
|
Chris@6
|
99 * @param b The list of beats
|
Chris@6
|
100 */
|
Chris@6
|
101 void setBeats(EventList b) {
|
Chris@6
|
102 beats = b;
|
Chris@6
|
103 } // setBeats()
|
Chris@6
|
104
|
Chris@6
|
105 }; // class BeatTrackDisplay
|
Chris@6
|
106
|
Chris@6
|
107
|
Chris@6
|
108 #endif
|
Chris@6
|
109
|