From d5afda9d953f423fb88100e0d496db87a0e3e47d Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Thu, 4 Sep 2025 22:38:23 +1000 Subject: plugin: add BeatTracker Replaces beat-detector.cpp --- plugin/src/Caelestia/beattracker.hpp | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 plugin/src/Caelestia/beattracker.hpp (limited to 'plugin/src/Caelestia/beattracker.hpp') diff --git a/plugin/src/Caelestia/beattracker.hpp b/plugin/src/Caelestia/beattracker.hpp new file mode 100644 index 0000000..a300c20 --- /dev/null +++ b/plugin/src/Caelestia/beattracker.hpp @@ -0,0 +1,47 @@ +#pragma once + +#include +#include +#include +#include +#include + +class BeatTracker : public QObject { + Q_OBJECT + QML_ELEMENT + QML_SINGLETON + + Q_PROPERTY(smpl_t bpm READ bpm NOTIFY bpmChanged) + Q_PROPERTY(int refCount READ refCount WRITE setRefCount NOTIFY refCountChanged) + +public: + explicit BeatTracker(uint_t sampleRate = 44100, uint_t hopSize = 512, QObject* parent = nullptr); + ~BeatTracker(); + + [[nodiscard]] smpl_t bpm() const; + + [[nodiscard]] int refCount() const; + void setRefCount(int refCount); + +signals: + void bpmChanged(); + void refCountChanged(); + void beat(smpl_t bpm); + +private: + QAudioSource* m_source; + QIODevice* m_device; + + aubio_tempo_t* m_tempo; + fvec_t* m_in; + fvec_t* m_out; + uint_t m_hopSize; + + smpl_t m_bpm; + int m_refCount; + + void start(); + void stop(); + void process(); + void handleStateChanged(QtAudio::State state) const; +}; -- cgit v1.2.3-freya