diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-09-04 22:38:23 +1000 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-09-04 22:38:23 +1000 |
| commit | d5afda9d953f423fb88100e0d496db87a0e3e47d (patch) | |
| tree | e6125d7740820c654eeb85336f43aafaba47719a /plugin/src/Caelestia/beattracker.hpp | |
| parent | nix: remove unneeded deps (diff) | |
| download | caelestia-shell-d5afda9d953f423fb88100e0d496db87a0e3e47d.tar.gz caelestia-shell-d5afda9d953f423fb88100e0d496db87a0e3e47d.tar.bz2 caelestia-shell-d5afda9d953f423fb88100e0d496db87a0e3e47d.zip | |
plugin: add BeatTracker
Replaces beat-detector.cpp
Diffstat (limited to 'plugin/src/Caelestia/beattracker.hpp')
| -rw-r--r-- | plugin/src/Caelestia/beattracker.hpp | 47 |
1 files changed, 47 insertions, 0 deletions
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 <QAudioSource> +#include <QIODevice> +#include <QObject> +#include <aubio/aubio.h> +#include <qqmlintegration.h> + +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; +}; |