-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
metronome.h
61 lines (46 loc) · 1.3 KB
/
metronome.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef METRONOME_H
#define METRONOME_H
#include <QObject>
#include <QTimer>
#include <QMediaPlayer>
#include "note.h"
class Metronome : public QObject
{
Q_OBJECT
Q_PROPERTY(int bpm READ bpm WRITE setBpm NOTIFY bpmChanged)
Q_PROPERTY(QVector<Note*> notes READ notes NOTIFY notesChanged)
Q_PROPERTY(int currentIndex READ currentIndex NOTIFY currentIndexChanged)
Q_PROPERTY(bool running READ running NOTIFY runningChanged)
public:
enum Sounds {
Click,
HighHead,
Snare
};
Q_ENUM(Sounds)
explicit Metronome(QObject *parent = nullptr);
Q_INVOKABLE void start();
Q_INVOKABLE void stop();
int bpm() const;
void setBpm(int bpm);
Q_SIGNAL void bpmChanged();
QVector<Note *> notes() const;
Q_SIGNAL void notesChanged();
Q_INVOKABLE void addNote(const Sounds sound);
Q_INVOKABLE void removeNote(const int index);
Q_SIGNAL void hit();
Q_SLOT void playHitSound();
int currentIndex() const;
void setCurrentIndex(int curentIndex);
Q_SIGNAL void currentIndexChanged();
bool running() const;
Q_SIGNAL void runningChanged();
private:
int m_bpm;
QTimer m_hitTimer;
QMediaPlayer m_mediaPlayer;
QVector<Note*> m_notes;
int m_hitCount = 0;
int m_currentIndex = 0;
};
#endif // METRONOME_H