File indexing completed on 2024-05-12 04:06:03

0001 /*
0002     SPDX-FileCopyrightText: 2010 Stefan Majewsky <majewsky@gmx.net>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-only
0005 */
0006 
0007 #ifndef KGAMEAUDIOSCENE_H
0008 #define KGAMEAUDIOSCENE_H
0009 
0010 // own
0011 #include "kdegames_export.h"
0012 // Qt
0013 #include <QPointF>
0014 
0015 /**
0016  * @namespace KGameAudioScene
0017  *
0018  * This class exposes general properties of the audio playback context. Actual
0019  * sounds are represented in this context by KGameSound instances.
0020  *
0021  * The audio scene basically consists of a listener. The position of this
0022  * listener is relevant when sounds are played at certain positions: The audio
0023  * channels will then be balanced to make the sound appear to come from that
0024  * direction.
0025  *
0026  * Because there can ogly be one listener, all methods in this class are static.
0027  *
0028  * @warning Not all functionally exposed by the API of this class is guaranteed
0029  *          to be available on the compiled KGameAudio backend. Check
0030  *          KGameAudioScene::capabilities() if in doubt.
0031  */
0032 namespace KGameAudioScene
0033 {
0034 /// This enumeration represents capabilities which may not be provided by
0035 /// every KGameAudio backend.
0036 enum Capability {
0037     /// Playback starts as soon as KGameSound::start is called.
0038     SupportsLowLatencyPlayback = 1 << 0,
0039     SupportsPositionalPlayback = 1 << 1,
0040 };
0041 /**
0042  * Stores a combination of #Capability values.
0043  */
0044 Q_DECLARE_FLAGS(Capabilities, Capability)
0045 
0046 /// @return which capabilities are supported by the compiled KGameAudio backend
0047 KDEGAMES_EXPORT Capabilities capabilities();
0048 
0049 /// @return the position of the listener
0050 KDEGAMES_EXPORT QPointF listenerPos();
0051 /// Sets the position of the listener. The default is (0.0, 0.0), the
0052 /// point of origin.
0053 /// @note Effective only if positional playback is supported.
0054 KDEGAMES_EXPORT void setListenerPos(QPointF pos);
0055 /// @return the master volume for sounds outputted by TagaroAudio
0056 KDEGAMES_EXPORT qreal volume();
0057 /// Sets the master volume for sounds outputted by TagaroAudio. The
0058 /// default is 1.0, which means no volume change, compared to the
0059 /// original sounds. 0.0 means that all sounds are muted.
0060 KDEGAMES_EXPORT void setVolume(qreal volume);
0061 
0062 /// @returns whether an error was detected in the audio backend
0063 ///
0064 /// Since KGameAudio is typically used by games where audio is not an absolutely
0065 /// vital part of the gameplay, we do not need to fail if sound does not work,
0066 /// over even make some sort of deep analysis why something did not work. The
0067 /// user will notice missing sound, and advanced users may investigate
0068 /// the kWarning() messages. That is usually enough. If not, use this method.
0069 ///
0070 /// The state of hasError() may theoretically change while the application
0071 /// runs, but in practice, this is very unlikely. (The only tricky part is
0072 /// typically the initial allocation of resources.)
0073 ///
0074 /// @sa KGameSound::hasError()
0075 KDEGAMES_EXPORT bool hasError();
0076 };
0077 
0078 Q_DECLARE_OPERATORS_FOR_FLAGS(KGameAudioScene::Capabilities)
0079 
0080 #endif // KGAMEAUDIOSCENE_H