RhythmGame 1.4.3
Loading...
Searching...
No Matches
AudioPlayer.h
Go to the documentation of this file.
1//
2// Created by PC on 10/09/2025.
3//
4
5#ifndef RHYTHMGAME_AUDIOPLAYER_H
6#define RHYTHMGAME_AUDIOPLAYER_H
7#include "Sound.h"
8
9#include <QByteArray>
10#include <QObject>
11#include <QTimer>
12#include <qqmlintegration.h>
13
14#include <atomic>
15#include <memory>
16#include <vector>
17
18namespace sounds {
19class AudioEngine;
20}
21namespace resource_managers {
22class SongAssetStore;
23}
24namespace sounds {
25
26class AudioPlayer : public QObject
27{
28 Q_OBJECT
29 QML_ELEMENT
30
34 Q_PROPERTY(QString source READ getSource WRITE setSource RESET resetSource
35 NOTIFY sourceChanged)
36 Q_PROPERTY(float volume READ getVolume WRITE setVolume NOTIFY volumeChanged)
37 Q_PROPERTY(
38 bool looping READ isLooping WRITE setLooping NOTIFY loopingChanged)
39 Q_PROPERTY(double fadeInMillis READ getFadeInMillis WRITE setFadeInMillis
41 Q_PROPERTY(
42 bool playing READ isPlaying WRITE setPlaying NOTIFY playingChanged)
43 Q_PROPERTY(bool loaded READ isLoaded NOTIFY loadedChanged)
45 Q_PROPERTY(float length READ getLength NOTIFY lengthChanged)
46
47 struct OverlappingSound
48 {
49 std::unique_ptr<ma_decoder> memoryDecoder;
50 std::unique_ptr<ma_sound> sound;
51 };
52
53 QString source;
54 QString resolvedSource;
55 QByteArray encodedSource;
56 std::unique_ptr<ma_decoder> memoryDecoder;
57 std::unique_ptr<ma_sound> sound;
58 std::vector<OverlappingSound> overlappingSounds;
59 double volume = 1.0;
60 bool looping = false;
61 bool playing = false;
62 bool loaded = false;
63 uint64_t fadeInMillis = 0;
64 float length = 0.0f;
65 QTimer playingFinishedTimer;
66 QTimer overlappingCleanupTimer;
67 quint64 sourceGeneration = 0;
68 std::shared_ptr<std::atomic_bool> sourceCancellation;
69 void onPlayingFinishedTimerTriggered();
70 void cleanupOverlappingSounds();
71 void stopOverlappingSounds();
72 void loadResolvedSource(QString value);
73 void loadEncodedSource(QByteArray value);
74 [[nodiscard]] bool initializeMemorySound(
75 std::unique_ptr<ma_decoder>& decoder,
76 std::unique_ptr<ma_sound>& targetSound);
77 void clearMemoryDecoder();
78 void finishLoadingSound(float previousLength);
79 void failLoadingSound(float previousLength);
80 void setLoaded(bool value);
81
82 public:
83 explicit AudioPlayer(QObject* parent = nullptr);
84 ~AudioPlayer() override;
85 auto getSource() const -> QString;
86 void setSource(const QString& value);
87 void resetSource();
88 void setPlaying(bool value);
89 Q_INVOKABLE void play();
90 Q_INVOKABLE bool playOverlapping();
91 Q_INVOKABLE void stop();
92 auto isPlaying() const -> bool;
93 auto isLoaded() const -> bool;
94
95 auto getVolume() const -> float;
96 void setVolume(float value);
97 auto isLooping() const -> bool;
98 void setLooping(bool value);
99 auto getFadeInMillis() const -> uint64_t;
100 void setFadeInMillis(uint64_t value);
101 auto getLength() const -> float;
102 inline static AudioEngine* engine = nullptr;
103 inline static resource_managers::SongAssetStore* assetStore = nullptr;
104 signals:
113};
114
115} // namespace sounds
116
117#endif // RHYTHMGAME_AUDIOPLAYER_H
double value
Definition BmsNotesData.cpp:35
Definition AudioEngine.h:16
Definition AudioPlayer.h:27
Q_INVOKABLE bool playOverlapping()
Definition AudioPlayer.cpp:352
Q_INVOKABLE void play()
Definition AudioPlayer.cpp:332
void setVolume(float value)
Definition AudioPlayer.cpp:416
void setSource(const QString &value)
Definition AudioPlayer.cpp:68
static AudioEngine * engine
Definition AudioPlayer.h:102
float length
Definition AudioPlayer.h:45
void setLooping(bool value)
Definition AudioPlayer.cpp:433
Q_INVOKABLE void stop()
Definition AudioPlayer.cpp:396
bool playing
Definition AudioPlayer.h:42
auto isLoaded() const -> bool
Definition AudioPlayer.cpp:288
auto getSource() const -> QString
Definition AudioPlayer.cpp:63
~AudioPlayer() override
Definition AudioPlayer.cpp:51
void resetSource()
Definition AudioPlayer.cpp:278
auto isLooping() const -> bool
Definition AudioPlayer.cpp:428
auto getLength() const -> float
Definition AudioPlayer.cpp:468
double fadeInMillis
Definition AudioPlayer.h:40
static resource_managers::SongAssetStore * assetStore
Definition AudioPlayer.h:103
bool looping
Definition AudioPlayer.h:38
bool loaded
Definition AudioPlayer.h:43
auto getVolume() const -> float
Definition AudioPlayer.cpp:411
float volume
Definition AudioPlayer.h:36
auto isPlaying() const -> bool
Definition AudioPlayer.cpp:283
void setPlaying(bool value)
Definition AudioPlayer.cpp:38
QML_ELEMENTQString source
Definition AudioPlayer.h:35
void setFadeInMillis(uint64_t value)
Definition AudioPlayer.cpp:459
auto getFadeInMillis() const -> uint64_t
Definition AudioPlayer.cpp:454
Classes and functions related to loading and managing resources such as charts, sounds,...
Definition ProfileArenaIdentityProvider.h:12
The namespace for all sound related classes.
Definition HitRules.h:16