File indexing completed on 2024-04-28 16:08:28

0001 // SPDX-FileCopyrightText: 2023 Mathis BrĂ¼chert <mbb@kaidan.im>
0002 //
0003 // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 
0005 #ifndef METRONOME_H
0006 #define METRONOME_H
0007 
0008 #include <QObject>
0009 #include <QTimer>
0010 #include <QMediaPlayer>
0011 
0012 #include "note.h"
0013 
0014 class Metronome : public QObject
0015 {
0016     Q_OBJECT
0017     Q_PROPERTY(int bpm READ bpm WRITE setBpm NOTIFY bpmChanged)
0018     Q_PROPERTY(QVector<Note*> notes READ notes NOTIFY notesChanged)
0019     Q_PROPERTY(int currentIndex READ currentIndex NOTIFY currentIndexChanged)
0020     Q_PROPERTY(bool running READ running NOTIFY runningChanged)
0021 
0022 public:
0023     enum Sounds {
0024         D,
0025         E,
0026         F
0027     };
0028 
0029     Q_ENUM(Sounds)
0030 
0031     explicit Metronome(QObject *parent = nullptr);
0032 
0033     Q_INVOKABLE void start();
0034     Q_INVOKABLE void stop();
0035 
0036     int bpm() const;
0037     void setBpm(int bpm);
0038     Q_SIGNAL void bpmChanged();
0039 
0040     QVector<Note *> notes() const;
0041     Q_SIGNAL void notesChanged();
0042 
0043     Q_INVOKABLE void addNote(const Sounds sound);
0044     Q_INVOKABLE void removeNote(const int index);
0045 
0046     Q_SIGNAL void hit();
0047     Q_SLOT void playHitSound();
0048 
0049     int currentIndex() const;
0050     void setCurrentIndex(int curentIndex);
0051     Q_SIGNAL void currentIndexChanged();
0052 
0053     bool running() const;
0054     Q_SIGNAL void runningChanged();
0055 
0056 private:
0057     int m_bpm;
0058     QTimer m_hitTimer;
0059     QMediaPlayer m_mediaPlayer;
0060     QVector<Note*> m_notes;
0061     int m_hitCount = 0;
0062     int m_currentIndex = 0;
0063 };
0064 
0065 #endif // METRONOME_H