MCPcopy Create free account
hub / github.com/RobLoach/raylib-cpp / SoundUnmanaged

Class SoundUnmanaged

include/SoundUnmanaged.hpp:18–185  ·  view source on GitHub ↗

* A Sound that is not managed by C++ RAII. * * Make sure to Unload() this if needed, otherwise use raylib::Sound. * * @see raylib::Sound */

Source from the content-addressed store, hash-verified

16 * @see raylib::Sound
17 */
18class SoundUnmanaged : public ::Sound {
19public:
20 /**
21 * Default constructor, creates an empty Sound.
22 */
23 SoundUnmanaged() : ::Sound{{nullptr, nullptr, 0, 0, 0}, 0} {}
24
25 /**
26 * Creates a SoundUnmanaged from its components.
27 */
28 SoundUnmanaged(::AudioStream stream, unsigned int frameCount) : ::Sound{stream, frameCount} {}
29
30 /**
31 * Creates a SoundUnmanaged from an existing Sound struct.
32 */
33 SoundUnmanaged(const ::Sound& sound) : ::Sound(sound) {}
34
35 /**
36 * Loads a Sound from the given file.
37 *
38 * @throws raylib::RaylibException Throws if the Sound failed to load.
39 */
40 SoundUnmanaged(const std::string& fileName) { Load(fileName); }
41
42 /**
43 * Loads a Sound from the given Wave.
44 *
45 * @throws raylib::RaylibException Throws if the Sound failed to load.
46 */
47 SoundUnmanaged(const ::Wave& wave) { Load(wave); }
48
49 GETTER(unsigned int, FrameCount, frameCount)
50 GETTER(::AudioStream, Stream, stream)
51
52 SoundUnmanaged& operator=(const ::Sound& sound) {
53 set(sound);
54 return *this;
55 }
56
57 [[nodiscard]] std::string ToString() const { return TextFormat("Sound(frameCount=%u)", frameCount); }
58
59 operator std::string() const { return ToString(); }
60
61 /**
62 * Load a sound from the given file.
63 *
64 * @throws raylib::RaylibException Throws if the Sound failed to load.
65 */
66 void Load(const std::string& fileName) {
67 set(::LoadSound(fileName.c_str()));
68 if (!IsValid()) {
69 throw RaylibException("Failed to load Sound from file");
70 }
71 }
72
73 /**
74 * Load a sound from the given Wave.
75 *

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected