* A Music stream that is not managed by C++ RAII. * * Make sure to Unload() this if needed, otherwise use raylib::Music. * * @see raylib::Music */
| 16 | * @see raylib::Music |
| 17 | */ |
| 18 | class MusicUnmanaged : public ::Music { |
| 19 | public: |
| 20 | /** |
| 21 | * Creates a MusicUnmanaged with the given components. |
| 22 | */ |
| 23 | MusicUnmanaged( |
| 24 | ::AudioStream stream = {nullptr, nullptr, 0, 0, 0}, |
| 25 | unsigned int frameCount = 0, |
| 26 | bool looping = false, |
| 27 | int ctxType = 0, |
| 28 | void* ctxData = nullptr) |
| 29 | : ::Music{stream, frameCount, looping, ctxType, ctxData} {} |
| 30 | |
| 31 | /** |
| 32 | * Creates a MusicUnmanaged from an existing Music struct. |
| 33 | */ |
| 34 | MusicUnmanaged(const ::Music& music) : ::Music(music) {} |
| 35 | |
| 36 | /** |
| 37 | * Load music stream from file. |
| 38 | * |
| 39 | * @throws raylib::RaylibException Throws if the music failed to load. |
| 40 | */ |
| 41 | MusicUnmanaged(const std::string& fileName) { Load(fileName); } |
| 42 | |
| 43 | /** |
| 44 | * Load music stream from memory. |
| 45 | * |
| 46 | * @throws raylib::RaylibException Throws if the music failed to load. |
| 47 | */ |
| 48 | MusicUnmanaged(const std::string& fileType, unsigned char* data, int dataSize) { |
| 49 | Load(fileType, data, dataSize); |
| 50 | } |
| 51 | |
| 52 | GETTER(::AudioStream, Stream, stream) |
| 53 | GETTER(unsigned int, FrameCount, frameCount) |
| 54 | GETTERSETTER(bool, Looping, looping) |
| 55 | GETTER(int, CtxType, ctxType) |
| 56 | GETTER(void*, CtxData, ctxData) |
| 57 | |
| 58 | MusicUnmanaged& operator=(const ::Music& music) { |
| 59 | set(music); |
| 60 | return *this; |
| 61 | } |
| 62 | |
| 63 | [[nodiscard]] std::string ToString() const { return TextFormat("Music(frameCount=%u, looping=%s)", frameCount, looping ? "true" : "false"); } |
| 64 | |
| 65 | operator std::string() const { return ToString(); } |
| 66 | |
| 67 | /** |
| 68 | * Load music stream from file. |
| 69 | * |
| 70 | * @throws raylib::RaylibException Throws if the music failed to load. |
| 71 | */ |
| 72 | void Load(const std::string& fileName) { |
| 73 | set(::LoadMusicStream(fileName.c_str())); |
| 74 | if (!IsValid()) { |
| 75 | throw RaylibException(TextFormat("Failed to load Music from file: %s", fileName.c_str())); |
nothing calls this directly
no outgoing calls
no test coverage detected