Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
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
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
27QQuick3DAmbientSound::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
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 */
52{
53 return m_sound->source();
54}
55
56void 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 */
67{
68 m_sound->setVolume(volume);
69}
70
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 */
85{
86 return m_sound->loops();
87}
88
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 */
103{
104 return m_sound->autoPlay();
105}
106
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 */
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 */
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 */
139{
140 m_sound->stop();
141}
142
143QT_END_NAMESPACE
void setAutoPlay(bool autoPlay)
void setSource(const QUrl &source)
void pause()
\qmlmethod void AmbientSound::pause()
int loops() const
\qmlproperty int AmbientSound::loops
void stop()
\qmlmethod void AmbientSound::stop()
bool autoPlay() const
\qmlproperty bool AmbientSound::autoPlay
QUrl source() const
\qmlproperty url AmbientSound::source
void setVolume(float volume)
\qmlproperty real AmbientSound::volume
Combined button and popup list for selecting options.