JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
Channel.hpp
Go to the documentation of this file.
1// Copyright 2024-2026 Jan Niklas Hasse <jhasse@bixense.com>
2// For conditions of distribution and use, see copyright notice in LICENSE.txt
5
6#include "Finally.hpp"
7
8#include <memory>
9#include <string>
10
11namespace jngl {
12
13class Sound;
14class SoundFile;
15struct Stream;
16
30class Channel {
31public:
32 Channel();
33 Channel(Channel&&) noexcept;
34 Channel& operator=(Channel&&) noexcept;
35 ~Channel();
36
38 void play(const std::string& filename);
39
42
47
49 void stop(const std::string& filename);
50
53
57 void stopAll();
58
62 bool isPlaying(std::string_view filename) const;
63
99 [[nodiscard]] Finally pause();
100
102 void setVolume(float volume);
103
105 static Channel& main();
106
110 void remove(const Stream*);
111
112private:
113 struct Impl;
115};
116
117} // namespace jngl
Contains jngl::Finally class.
An audio channel, different channels could be for example: "Music", "Speech" and "Sound Effects".
Definition Channel.hpp:30
Finally pause()
Pauses the Channel; destroying the returned Finally object will resume again.
static Channel & main()
Returns the main Channel on which jngl::play, jngl::loop, jngl::stop operate.
void setVolume(float volume)
Set volume of this channel in [0, ∞]. Default is 1.0f.
void remove(const Stream *)
Internal function for now.
void stopAll()
Stops all audio playing on this channel.
void play(std::shared_ptr< Sound >)
Play a Sound on this channel.
void stop(const std::shared_ptr< Sound > &)
Stop a Sound if it's playing on this channel.
bool isPlaying(std::string_view filename) const
Returns true if the OGG file is currently playing on this channel.
void add(std::shared_ptr< Stream >)
Internal function for now.
void play(const std::string &filename)
Play OGG file on this channel.
std::shared_ptr< SoundFile > loop(const std::string &filename)
Play an OGG audio file on this channel in a loop.
void stop(const std::string &filename)
Stop OGG file playing on this channel.
Helper class which calls a function when being destroyed.
Definition Finally.hpp:22
JNGL's main namespace.