KGameSound

Search for usage in LXR

#include <KGameSound>

Inheritance diagram for KGameSound:

Public Types

enum  PlaybackType { AmbientPlayback = 1 , AbsolutePlayback , RelativePlayback }
 

Properties

KGameSound::PlaybackType playbackType
 
QPointF pos
 
qreal volume
 
- Properties inherited from QObject
 objectName
 

Signals

void playbackTypeChanged (KGameSound::PlaybackType type)
 
void posChanged (QPointF pos)
 
void volumeChanged (qreal volume)
 

Public Slots

void start ()
 
void start (QPointF pos)
 
void stop ()
 

Public Member Functions

 KGameSound (const QString &file, QObject *parent=nullptr)
 
 ~KGameSound () override
 
bool hasError () const
 
bool isValid () const
 
KGameSound::PlaybackType playbackType () const
 
QPointF pos () const
 
void setPlaybackType (KGameSound::PlaybackType type)
 
void setPos (QPointF pos)
 
void setVolume (qreal volume)
 
qreal volume () const
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo ()
 
void dumpObjectInfo () const const
 
void dumpObjectTree ()
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
qobject_cast (const QObject *object)
 
qobject_cast (QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
QThreadthread () const const
 

Additional Inherited Members

- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
- Public Attributes inherited from QObject
typedef QObjectList
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Detailed Description

This class models a sound file.

Because it is implicitly added to this application's KGameAudioScene, it can be played at different positions (if positional playback is supported, see KGameAudioScene::capabilities()).

Compared to many other media playback classes, the notable difference of KGameSound is that one sound instance can be played multiple times at the same point in time, by calling start() multiple times (possibly with different playback positions). This behavior can be suppressed by calling stop() before start().

Note
WAV files and Ogg/Vorbis files are guaranteed to work. Other audio files may also work, depending on the KGameAudio backend and its configuration.

Definition at line 37 of file kgamesound.h.

Member Enumeration Documentation

◆ PlaybackType

This enumeration describes how a sound can be played back.

Enumerator
AmbientPlayback 

Positional playback disabled.

The sound will appear at the same volume from every listener position, and will not appear to be coming from any direction. The pos() of this sound is ignored.

AbsolutePlayback 

Positional playback enabled.

That means that the sound comes from a certain direction with a distance-depending volume. The pos() of this sound is given in absolute coordinates: Both direction and volume can change when the listener is moved.

RelativePlayback 

Positional playback enabled.

That means that the sound comes from a certain direction with a distance-depending volume. The pos() of this sound is given in relative coordinates: The direction and volume do not depend on the listener's position. (In these relative coordinates, the listener is at the point of origin.)

Definition at line 47 of file kgamesound.h.

Property Documentation

◆ playbackType

KGameSound::PlaybackType KGameSound::playbackType
readwrite

Definition at line 41 of file kgamesound.h.

◆ pos

QPointF KGameSound::pos
readwrite

Definition at line 42 of file kgamesound.h.

◆ volume

qreal KGameSound::volume
readwrite

Definition at line 43 of file kgamesound.h.

Constructor & Destructor Documentation

◆ KGameSound()

KGameSound::KGameSound ( const QString & file,
QObject * parent = nullptr )
explicit

Loads a new sound from the given file.

Note that this is an expensive operation which you might want to do during application startup. However, you can reuse the same Sound instance for multiple playback events.

Since version 7.2.0 this constructor supports reading files from Qt Resource System, file can be for example ":/sound.ogg".

Definition at line 32 of file kgamesound-openal.cpp.

◆ ~KGameSound()

KGameSound::~KGameSound ( )
override

Destroys this KGameSound instance.

Definition at line 95 of file kgamesound-openal.cpp.

Member Function Documentation

◆ hasError()

bool KGameSound::hasError ( ) const
Returns
whether loading or playing this sound failed

See KGameAudioScene::hasError() for why you typically do not need to use this method.

Definition at line 164 of file kgamesound-openal.cpp.

◆ isValid()

bool KGameSound::isValid ( ) const
Returns
whether the sound file could be loaded successfully

Definition at line 106 of file kgamesound-openal.cpp.

◆ playbackType()

KGameSound::PlaybackType KGameSound::playbackType ( ) const
Returns
the playback type for this sound

Definition at line 113 of file kgamesound-openal.cpp.

◆ pos()

QPointF KGameSound::pos ( ) const
Returns
the position of this sound

Definition at line 130 of file kgamesound-openal.cpp.

◆ setPlaybackType()

void KGameSound::setPlaybackType ( KGameSound::PlaybackType type)

Sets the playback type for this sound.

This affects how the sound will be perceived by the listener. The default is AmbientPlayback.

Note
Changes to this property will not be propagated to running playbacks of this sound.
Effective only if positional playback is supported.

Definition at line 120 of file kgamesound-openal.cpp.

◆ setPos()

void KGameSound::setPos ( QPointF pos)

Sets the position of this sound.

It depends on the playbackType() how this is position interpreted. See the KGameSound::PlaybackType enumeration documentation for details.

Note
Changes to this property will not be propagated to running playbacks of this sound.
Effective only if positional playback is supported.

Definition at line 137 of file kgamesound-openal.cpp.

◆ setVolume()

void KGameSound::setVolume ( qreal volume)

Sets the volume of this sound.

The default is 1.0, which means no volume change, compared to the original sound file. 0.0 means that the sound is inaudible.

If you think of the KGameSound as a loudspeaker, the volume which is controlled by this method is what you regulate at its volume control. If positional playback is enabled (see playbackType()), this will not be the actual volume which the listener will perceive, because the playback volume decreases with increasing playback-listener distances.

Note
Changes to this property will not be propagated to running playbacks of this sound.

Definition at line 154 of file kgamesound-openal.cpp.

◆ start [1/2]

void KGameSound::start ( )
slot

Starts a new playback instance of this sound.

This will not interrupt running playbacks of the same sound or any other sounds.

Definition at line 171 of file kgamesound-openal.cpp.

◆ start [2/2]

void KGameSound::start ( QPointF pos)
slot

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This overload takes an additional position argument which overrides the sound's pos() property.

Note
pos is respected only if positional playback is supported.

Definition at line 178 of file kgamesound-openal.cpp.

◆ stop

void KGameSound::stop ( )
slot

Stops any playbacks of this sounds.

Definition at line 194 of file kgamesound-openal.cpp.

◆ volume()

qreal KGameSound::volume ( ) const
Returns
the volume of this sound

Definition at line 147 of file kgamesound-openal.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:43:15 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.