Chris@17: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@17: Chris@17: /* Chris@17: Vamp feature extraction plugin for the BeatRoot beat tracker. Chris@17: Chris@17: Centre for Digital Music, Queen Mary, University of London. Chris@17: This file copyright 2011 Simon Dixon, Chris Cannam and QMUL. Chris@17: Chris@17: This program is free software; you can redistribute it and/or Chris@17: modify it under the terms of the GNU General Public License as Chris@17: published by the Free Software Foundation; either version 2 of the Chris@17: License, or (at your option) any later version. See the file Chris@17: COPYING included with this distribution for more information. Chris@17: */ Chris@17: Chris@17: #include "BeatTracker.h" Chris@17: Chris@23: EventList BeatTracker::beatTrack(AgentParameters params, Chris@36: EventList events, EventList beats, Chris@36: EventList *unfilledReturn) Chris@17: { Chris@17: AgentList agents; Chris@17: int count = 0; Chris@17: double beatTime = -1; Chris@17: if (!beats.empty()) { Chris@17: count = beats.size() - 1; Chris@17: EventList::iterator itr = beats.end(); Chris@17: --itr; Chris@17: beatTime = itr->time; Chris@17: } Chris@17: if (count > 0) { // tempo given by mean of initial beats Chris@17: double ioi = (beatTime - beats.begin()->time) / count; Chris@23: agents.push_back(new Agent(params, ioi)); Chris@17: } else // tempo not given; use tempo induction Chris@23: agents = Induction::beatInduction(params, events); Chris@17: if (!beats.empty()) Chris@17: for (AgentList::iterator itr = agents.begin(); itr != agents.end(); Chris@17: ++itr) { Chris@17: (*itr)->beatTime = beatTime; Chris@17: (*itr)->beatCount = count; Chris@17: (*itr)->events = beats; Chris@17: } Chris@23: agents.beatTrack(events, params, -1); Chris@17: Agent *best = agents.bestAgent(); Chris@17: EventList results; Chris@17: if (best) { Chris@36: if (unfilledReturn) *unfilledReturn = best->events; Chris@17: best->fillBeats(beatTime); Chris@17: results = best->events; Chris@17: } Chris@17: for (AgentList::iterator ai = agents.begin(); ai != agents.end(); ++ai) { Chris@17: delete *ai; Chris@17: } Chris@17: return results; Chris@17: } // beatTrack()/1 Chris@17: Chris@17: