Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions include/AutomationEventList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AutomationEventList : public ::AutomationEventList {
*
* @param fileName The file path to load the automation events list from.
*/
AutomationEventList(const char* fileName) { Load(fileName); }
AutomationEventList(const char* fileName) : ::AutomationEventList{} { Load(fileName); }

AutomationEventList(const AutomationEventList&) = delete;

Expand All @@ -44,6 +44,7 @@ class AutomationEventList : public ::AutomationEventList {
GETTER(AutomationEvent*, Events, events)

AutomationEventList& operator=(const ::AutomationEventList& other) {
Unload();
set(other);
return *this;
}
Expand All @@ -66,7 +67,7 @@ class AutomationEventList : public ::AutomationEventList {
}

/**
* Load audio stream (to stream raw audio pcm data)
* Load automation events list from file, unloading any existing events.
*
* @throws raylib::RaylibException Throws if the AutomationEventList failed to load.
*/
Expand All @@ -79,26 +80,23 @@ class AutomationEventList : public ::AutomationEventList {
}

/**
* Update audio stream buffers with data
* Unload automation events list from memory.
*/
void Unload() {
if (!IsValid()) {
return;
}

// The function signature of UnloadAutomationEventList() changes from raylib 5.0.
#if RAYLIB_VERSION_MAJOR == 5
#if RAYLIB_VERSION_MINOR == 0
::UnloadAutomationEventList(this);
#elif RAYLIB_VERSION_MINOR >= 1
::UnloadAutomationEventList(*this);
#endif
#else
::UnloadAutomationEventList(*this);
#endif
capacity = 0;
count = 0;
events = nullptr;
}

bool IsValid() { return events != nullptr; }
/**
* Check if the automation events list has been loaded.
*/
bool IsValid() const { return events != nullptr; }

bool Export(const char* fileName) { return ::ExportAutomationEventList(*this, fileName); }

Expand Down
29 changes: 29 additions & 0 deletions tests/raylib_cpp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "raylib-assert.h"
// clang-format on
#include <string>
#include <utility>
#include <vector>

int main(int argc, char* argv[]) {
Expand Down Expand Up @@ -174,6 +175,34 @@ int main(int argc, char* argv[]) {
Assert(passed, "Expected to have a RaylibException to be thrown");
}

// AutomationEventList
{
raylib::AutomationEventList list;
Assert(list.IsValid(), "Expected empty automation event list to be valid");
AssertEqual(list.GetCount(), 0);
Assert(list.GetCapacity() > 0, "Expected automation event list to have capacity");

raylib::AutomationEventList moved;
moved = std::move(list);
Assert(moved.IsValid(), "Expected moved automation event list to be valid");
AssertNot(list.IsValid(), "Expected moved-from automation event list to be invalid");

// raylib returns an empty list when the file is missing.
bool threw = false;
try {
raylib::AutomationEventList missing("notfound.rae");
Assert(missing.IsValid(), "Expected missing file to give an empty list");
AssertEqual(missing.GetCount(), 0);
} catch (raylib::RaylibException& error) {
error.TraceLog(LOG_INFO);
threw = true;
}
AssertNot(threw, "Expected no RaylibException for a missing automation file");

moved.Unload();
AssertNot(moved.IsValid(), "Expected unloaded automation event list to be invalid");
}

// Load FileData
{
raylib::FileData file(path + "/resources/weird.wav");
Expand Down
Loading