1 | // Copyright (C) 2022 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only |
3 | #ifndef QQUICK3DSPATIALSOUND_H |
4 | #define QQUICK3DSPATIALSOUND_H |
5 | |
6 | // |
7 | // W A R N I N G |
8 | // ------------- |
9 | // |
10 | // This file is not part of the Qt API. It exists purely as an |
11 | // implementation detail. This header file may change from version to |
12 | // version without notice, or even be removed. |
13 | // |
14 | // We mean it. |
15 | // |
16 | |
17 | #include <private/qquick3dnode_p.h> |
18 | #include <QUrl> |
19 | #include <qvector3d.h> |
20 | #include <qspatialsound.h> |
21 | |
22 | QT_BEGIN_NAMESPACE |
23 | |
24 | class QQuick3DSpatialSound : public QQuick3DNode |
25 | { |
26 | Q_OBJECT |
27 | Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) |
28 | Q_PROPERTY(float volume READ volume WRITE setVolume NOTIFY volumeChanged) |
29 | Q_PROPERTY(DistanceModel distanceModel READ distanceModel WRITE setDistanceModel NOTIFY distanceModelChanged) |
30 | Q_PROPERTY(float size READ size WRITE setSize NOTIFY sizeChanged) |
31 | Q_PROPERTY(float distanceCutoff READ distanceCutoff WRITE setDistanceCutoff NOTIFY distanceCutoffChanged) |
32 | Q_PROPERTY(float manualAttenuation READ manualAttenuation WRITE setManualAttenuation NOTIFY manualAttenuationChanged) |
33 | Q_PROPERTY(float occlusionIntensity READ occlusionIntensity WRITE setOcclusionIntensity NOTIFY occlusionIntensityChanged) |
34 | Q_PROPERTY(float directivity READ directivity WRITE setDirectivity NOTIFY directivityChanged) |
35 | Q_PROPERTY(float directivityOrder READ directivityOrder WRITE setDirectivityOrder NOTIFY directivityOrderChanged) |
36 | Q_PROPERTY(float nearFieldGain READ nearFieldGain WRITE setNearFieldGain NOTIFY nearFieldGainChanged) |
37 | Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopsChanged) |
38 | Q_PROPERTY(bool autoPlay READ autoPlay WRITE setAutoPlay NOTIFY autoPlayChanged) |
39 | QML_NAMED_ELEMENT(SpatialSound) |
40 | |
41 | public: |
42 | QQuick3DSpatialSound(); |
43 | ~QQuick3DSpatialSound(); |
44 | |
45 | void setSource(QUrl source); |
46 | QUrl source() const; |
47 | |
48 | void setVolume(float volume); |
49 | float volume() const; |
50 | |
51 | enum DistanceModel { |
52 | Logarithmic, |
53 | Linear, |
54 | ManualAttenuation |
55 | }; |
56 | Q_ENUM(DistanceModel); |
57 | |
58 | void setDistanceModel(DistanceModel model); |
59 | DistanceModel distanceModel() const; |
60 | |
61 | void setSize(float min); |
62 | float size() const; |
63 | |
64 | void setDistanceCutoff(float max); |
65 | float distanceCutoff() const; |
66 | |
67 | void setManualAttenuation(float attenuation); |
68 | float manualAttenuation() const; |
69 | |
70 | void setOcclusionIntensity(float occlusion); |
71 | float occlusionIntensity() const; |
72 | |
73 | void setDirectivity(float alpha); |
74 | float directivity() const; |
75 | |
76 | void setDirectivityOrder(float alpha); |
77 | float directivityOrder() const; |
78 | |
79 | void setNearFieldGain(float gain); |
80 | float nearFieldGain() const; |
81 | |
82 | enum Loops |
83 | { |
84 | Infinite = -1, |
85 | Once = 1 |
86 | }; |
87 | Q_ENUM(Loops) |
88 | |
89 | int loops() const; |
90 | void setLoops(int loops); |
91 | |
92 | bool autoPlay() const; |
93 | void setAutoPlay(bool autoPlay); |
94 | |
95 | public Q_SLOTS: |
96 | void play(); |
97 | void pause(); |
98 | void stop(); |
99 | |
100 | Q_SIGNALS: |
101 | void sourceChanged(); |
102 | void volumeChanged(); |
103 | void distanceModelChanged(); |
104 | void sizeChanged(); |
105 | void distanceCutoffChanged(); |
106 | void manualAttenuationChanged(); |
107 | void occlusionIntensityChanged(); |
108 | void directivityChanged(); |
109 | void directivityOrderChanged(); |
110 | void nearFieldGainChanged(); |
111 | void loopsChanged(); |
112 | void autoPlayChanged(); |
113 | |
114 | private Q_SLOTS: |
115 | void updatePosition(); |
116 | void updateRotation(); |
117 | |
118 | protected: |
119 | QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *) override { return nullptr; } |
120 | |
121 | private: |
122 | QSpatialSound *m_sound = nullptr; |
123 | }; |
124 | |
125 | QT_END_NAMESPACE |
126 | |
127 | #endif |
128 | |