-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.h
70 lines (59 loc) · 1.65 KB
/
player.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
62
63
64
65
66
67
68
69
70
// Copyright (C) 2023 Michel de Boer
// License: GPLv3
#pragma once
#include "circle.h"
#include "music_generator.h"
#include "recorder.h"
#include <QTimer>
namespace SpiralFun {
using namespace std::chrono_literals;
class Player : public QObject
{
Q_OBJECT
public:
struct Stats
{
int mCycles = 0;
std::chrono::milliseconds mPlayTime = 0ms;
bool mRecordingFailed = false;
};
Player(const CircleList &circles, std::unique_ptr<MusicGenerator> musicGenerator);
~Player();
bool play(std::unique_ptr<Recorder> recorder = nullptr);
void playAll();
qreal getAngle() const { return mAngle; }
const QString& getFileName() const { return mRecorder->getFileName(); }
signals:
void done(Player::Stats stats);
void refreshScene();
void angleChanged();
private:
void startTimers();
void stopTimers();
void advance();
void advanceCircles(qreal angle);
void advanceCircle(unsigned index, qreal angle);
void forceDraw();
void recordingFailed();
void finishPlaying();
bool setupRecording();
void resetRecordingRect();
void updateRecordingRect();
bool record();
const CircleList& mCircles;
QTimer mPlayTimer;
QTimer mSceneRefreshTimer;
qreal mAngle = 0.0;
const qreal mStepAngle = qDegreesToRadians(0.05);
unsigned mStepsPerInterval = 1;
const qreal mRecordAngleThreshold = qDegreesToRadians(1);
qreal mRecordAngle = 0.0;
int mStartTime;
int mCycles;
QRect mFullFrameRect;
QRectF mRecordingRect;
std::unique_ptr<Recorder> mRecorder;
bool mRecording = false;
std::unique_ptr<MusicGenerator> mMusicGenerator;
};
}