KgSound

Search for usage in LXR

Inheritance diagram for KgSound:

Public Types

enum  PlaybackType { AmbientPlayback = 1, AbsolutePlayback, RelativePlayback }
 

Properties

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

Signals

void playbackTypeChanged (KgSound::PlaybackType type)
 
void posChanged (const QPointF &pos)
 
void volumeChanged (qreal volume)
 

Public Slots

void start ()
 
void start (const QPointF &pos)
 
void stop ()
 

Public Member Functions

 KgSound (const QString &file, QObject *parent=nullptr)
 
virtual ~KgSound ()
 
bool hasError () const
 
bool isValid () const
 
KgSound::PlaybackType playbackType () const
 
QPointF pos () const
 
void setPlaybackType (KgSound::PlaybackType type)
 
void setPos (const 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 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
 
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 (QObject *object)
 
qobject_cast (const 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 *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
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, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &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 KgAudioScene, it can be played at different positions (if positional playback is supported, see KgAudioScene::capabilities()).

Compared to many other media playback classes, the notable difference of KgSound 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 KgAudio backend and its configuration.

Definition at line 37 of file audio/kgsound.h.

Member Enumeration Documentation

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 46 of file audio/kgsound.h.

Constructor & Destructor Documentation

KgSound::KgSound ( 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 kgsound-openal.cpp.

KgSound::~KgSound ( )
virtual

Destroys this KgSound instance.

Definition at line 97 of file kgsound-openal.cpp.

Member Function Documentation

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

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

Definition at line 151 of file kgsound-openal.cpp.

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

Definition at line 107 of file kgsound-openal.cpp.

KgSound::PlaybackType KgSound::playbackType ( ) const
Returns
the playback type for this sound
QPointF KgSound::pos ( ) const
Returns
the position of this sound
void KgSound::setPlaybackType ( KgSound::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 117 of file kgsound-openal.cpp.

void KgSound::setPos ( const QPointF pos)

Sets the position of this sound.

It depends on the playbackType() how this is position interpreted. See the KgSound::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 130 of file kgsound-openal.cpp.

void KgSound::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 KgSound 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 143 of file kgsound-openal.cpp.

void KgSound::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 156 of file kgsound-openal.cpp.

void KgSound::start ( const 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 161 of file kgsound-openal.cpp.

void KgSound::stop ( )
slot

Stops any playbacks of this sounds.

Definition at line 180 of file kgsound-openal.cpp.

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

The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Jun 18 2021 22:37:26 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.