Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qquick3dambientsound.cpp
Go to the documentation of this file.
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
4
#
include
"qquick3dambientsound_p.h"
5
6
#
include
<
QtMultimediaQuick
/
private
/
qqmlcontext_source_resolver_p
.
h
>
7
#
include
<
QtQuick3DSpatialAudio
/
private
/
qquick3daudioengine_p
.
h
>
8
#
include
<
QtSpatialAudio
/
qambientsound
.
h
>
9
#
include
<
QtSpatialAudio
/
private
/
qspatialaudiosound_p
.
h
>
10
11
QT_BEGIN_NAMESPACE
12
13
/*!
14
\qmltype AmbientSound
15
\nativetype QQuick3DAmbientSound
16
\inqmlmodule QtQuick3D.SpatialAudio
17
\ingroup quick3d_spatialaudio
18
\ingroup multimedia_audio_qml
19
20
\brief A stereo overlay sound.
21
22
A AmbientSound represents a position and orientation independent sound.
23
It's commonly used for background sounds (e.g. music) that is supposed to be independent
24
of the listeners position and orientation.
25
*/
26
27
QQuick3DAmbientSound::QQuick3DAmbientSound()
28
{
29
m_sound =
new
QAmbientSound(QQuick3DAudioEngine::getEngine());
30
31
connect(m_sound, &QAmbientSound::sourceChanged,
this
, &QQuick3DAmbientSound::sourceChanged);
32
connect(m_sound, &QAmbientSound::volumeChanged,
this
, &QQuick3DAmbientSound::volumeChanged);
33
connect(m_sound, &QAmbientSound::loopsChanged,
this
, &QQuick3DAmbientSound::loopsChanged);
34
connect(m_sound, &QAmbientSound::autoPlayChanged,
this
, &QQuick3DAmbientSound::autoPlayChanged);
35
36
auto
*soundPrivate =
static_cast
<QSpatialAudioSoundPrivate *>(QObjectPrivate::get(m_sound));
37
soundPrivate->m_sourceResolver =
38
std::make_unique<QMultimediaPrivate::QQmlContextSourceResolver>(
this
);
39
}
40
41
QQuick3DAmbientSound
::~
QQuick3DAmbientSound
()
42
{
43
delete
m_sound;
44
}
45
46
/*!
47
\qmlproperty url AmbientSound::source
48
49
The source file for the sound to be played.
50
*/
51
QUrl
QQuick3DAmbientSound
::
source
()
const
52
{
53
return
m_sound->source();
54
}
55
56
void
QQuick3DAmbientSound
::
setSource
(
const
QUrl& source)
57
{
58
m_sound->setSource(source);
59
}
60
61
/*!
62
\qmlproperty real AmbientSound::volume
63
64
Defines an overall volume for this sound source.
65
*/
66
void
QQuick3DAmbientSound
::
setVolume
(
float
volume)
67
{
68
m_sound->setVolume(volume);
69
}
70
71
float
QQuick3DAmbientSound
::
volume
()
const
72
{
73
return
m_sound->volume();
74
}
75
76
/*!
77
\qmlproperty int AmbientSound::loops
78
79
Determines how often the sound is played before the player stops.
80
Set to QAmbienSound::Infinite to loop the current sound forever.
81
82
The default value is \c 1.
83
*/
84
int
QQuick3DAmbientSound
::
loops
()
const
85
{
86
return
m_sound->loops();
87
}
88
89
void
QQuick3DAmbientSound
::
setLoops
(
int
loops)
90
{
91
m_sound->setLoops(loops);
92
}
93
94
/*!
95
\qmlproperty bool AmbientSound::autoPlay
96
97
Determines whether the sound should automatically start playing when a source
98
gets specified.
99
100
The default value is \c true.
101
*/
102
bool
QQuick3DAmbientSound
::
autoPlay
()
const
103
{
104
return
m_sound->autoPlay();
105
}
106
107
void
QQuick3DAmbientSound
::
setAutoPlay
(
bool
autoPlay)
108
{
109
m_sound->setAutoPlay(autoPlay);
110
}
111
112
/*!
113
\qmlmethod void AmbientSound::play()
114
115
Starts playing back the sound. Does nothing if the sound is already playing.
116
*/
117
void
QQuick3DAmbientSound
::play()
118
{
119
m_sound->play();
120
}
121
122
/*!
123
\qmlmethod void AmbientSound::pause()
124
125
Pauses sound playback at the current position. Calling play() will continue playback.
126
*/
127
void
QQuick3DAmbientSound
::
pause
()
128
{
129
m_sound->pause();
130
}
131
132
/*!
133
\qmlmethod void AmbientSound::stop()
134
135
Stops sound playback and resets the current position and loop count to 0. Calling play() will
136
begin playback at the beginning of the sound file.
137
*/
138
void
QQuick3DAmbientSound
::
stop
()
139
{
140
m_sound->stop();
141
}
142
143
QT_END_NAMESPACE
QQuick3DAmbientSound
Definition
qquick3dambientsound_p.h:26
QQuick3DAmbientSound::setAutoPlay
void setAutoPlay(bool autoPlay)
Definition
qquick3dambientsound.cpp:107
QQuick3DAmbientSound::setLoops
void setLoops(int loops)
Definition
qquick3dambientsound.cpp:89
QQuick3DAmbientSound::setSource
void setSource(const QUrl &source)
Definition
qquick3dambientsound.cpp:56
QQuick3DAmbientSound::pause
void pause()
\qmlmethod void AmbientSound::pause()
Definition
qquick3dambientsound.cpp:127
QQuick3DAmbientSound::loops
int loops() const
\qmlproperty int AmbientSound::loops
Definition
qquick3dambientsound.cpp:84
QQuick3DAmbientSound::stop
void stop()
\qmlmethod void AmbientSound::stop()
Definition
qquick3dambientsound.cpp:138
QQuick3DAmbientSound::~QQuick3DAmbientSound
~QQuick3DAmbientSound() override
Definition
qquick3dambientsound.cpp:41
QQuick3DAmbientSound::autoPlay
bool autoPlay() const
\qmlproperty bool AmbientSound::autoPlay
Definition
qquick3dambientsound.cpp:102
QQuick3DAmbientSound::source
QUrl source() const
\qmlproperty url AmbientSound::source
Definition
qquick3dambientsound.cpp:51
QQuick3DAmbientSound::setVolume
void setVolume(float volume)
\qmlproperty real AmbientSound::volume
Definition
qquick3dambientsound.cpp:66
QQuick3DAmbientSound::volume
float volume() const
Definition
qquick3dambientsound.cpp:71
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtmultimedia
src
spatialaudioquick3d
qquick3dambientsound.cpp
Generated on
for Qt by
1.18.0