LMMS
Loading...
Searching...
No Matches
TapTempo.h
Go to the documentation of this file.
1/*
2 * TapTempo.h - Plugin to count beats per minute
3 *
4 * Copyright (c) 2026 saker <sakertooth@gmail.com>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25#ifndef LMMS_TAP_TEMPO_H
26#define LMMS_TAP_TEMPO_H
27
28#include <chrono>
29
30#include "TapTempoView.h"
31#include "ToolPlugin.h"
32
33namespace lmms {
34
35class TapTempo : public ToolPlugin
36{
37 Q_OBJECT
38public:
39 TapTempo();
40 void tap(bool play);
41 void sync();
42 void reset();
43 double bpm() const;
44
45 QString nodeName() const override;
46 void saveSettings(QDomDocument&, QDomElement&) override {}
47 void loadSettings(const QDomElement&) override {}
48
49 gui::PluginView* instantiateView(QWidget*) override { return new gui::TapTempoView(this); }
50
51private:
52 static constexpr auto MaxIntervals = 3;
53 using clock = std::chrono::steady_clock;
54 std::chrono::time_point<clock> m_lastTap;
55 std::array<std::chrono::milliseconds, MaxIntervals> m_intervals;
56 int m_beat = 0;
57 int m_taps = 0;
58 double m_bpm = 0;
59};
60} // namespace lmms
61
62#endif // LMMS_TAP_TEMPO_H
int m_beat
Definition TapTempo.h:56
TapTempo()
Definition TapTempo.cpp:47
static constexpr auto MaxIntervals
Definition TapTempo.h:52
void saveSettings(QDomDocument &, QDomElement &) override
Definition TapTempo.h:46
gui::PluginView * instantiateView(QWidget *) override
Create a view for the model.
Definition TapTempo.h:49
std::chrono::time_point< clock > m_lastTap
Definition TapTempo.h:54
void loadSettings(const QDomElement &) override
Definition TapTempo.h:47
double m_bpm
Definition TapTempo.h:58
void tap(bool play)
Definition TapTempo.cpp:53
double bpm() const
Definition TapTempo.cpp:124
std::chrono::steady_clock clock
Definition TapTempo.h:53
QString nodeName() const override
Definition TapTempo.cpp:119
std::array< std::chrono::milliseconds, MaxIntervals > m_intervals
Definition TapTempo.h:55
void reset()
Definition TapTempo.cpp:111
void sync()
Definition TapTempo.cpp:106
int m_taps
Definition TapTempo.h:57
ToolPlugin(const Descriptor *_descriptor, Model *_parent)
Definition ToolPlugin.cpp:33
Definition PluginView.h:36
Definition TapTempoView.h:41
Definition AudioAlsa.cpp:35