raylib-cpp
C++ object-oriented wrapper library for raylib.
Loading...
Searching...
No Matches
AutomationEventList.hpp
1#ifndef RAYLIB_CPP_INCLUDE_AUTOMATIONEVENTLIST_HPP_
2#define RAYLIB_CPP_INCLUDE_AUTOMATIONEVENTLIST_HPP_
3
4#include "./raylib.hpp"
5#include "./raylib-cpp-utils.hpp"
6#include "./RaylibException.hpp"
7#include <span>
8#include <string_view>
9
10namespace raylib {
14class AutomationEventList : public ::AutomationEventList {
15 public:
16 AutomationEventList(const ::AutomationEventList& automationEventList) {
17 set(automationEventList);
18 }
19
24 set(::LoadAutomationEventList(0));
25 }
26
27 AutomationEventList(unsigned int capacity = 16384,
28 std::span<AutomationEvent> events = {}) : ::AutomationEventList{capacity, static_cast<unsigned int>(events.size()), events.data()} {
29 // Nothing.
30 }
31
37 AutomationEventList(const char* fileName) {
38 Load(fileName);
39 }
40 AutomationEventList(const std::string_view fileName) {
41 Load(fileName.data());
42 }
43
45
47 set(other);
48
49 other.capacity = 0;
50 other.count = 0;
51 other.events = nullptr;
52 }
53
54 ~AutomationEventList() {
55 Unload();
56 }
57
58 GETTER(unsigned int, Capacity, capacity)
59 GETTER(unsigned int, Count, count)
60 GETTER(AutomationEvent*, Events, events)
61
62 AutomationEventList& operator=(const ::AutomationEventList& other) {
63 set(other);
64 return *this;
65 }
66
67 AutomationEventList& operator=(const AutomationEventList&) = delete;
68
69 AutomationEventList& operator=(AutomationEventList&& other) noexcept {
70 if (this == &other) {
71 return *this;
72 }
73
74 Unload();
75 set(other);
76
77 other.capacity = 0;
78 other.count = 0;
79 other.events = nullptr;
80
81 return *this;
82 }
83
89 void Load(const char* fileName) {
90 Unload();
91 set(::LoadAutomationEventList(fileName));
92 if (!IsReady()) {
93 throw RaylibException("Failed to load automation event list");
94 }
95 }
96
102 void Load(const std::string_view fileName) {
103 Unload();
104 set(::LoadAutomationEventList(fileName.data()));
105 if (!IsReady()) {
106 throw RaylibException("Failed to load automation event list");
107 }
108 }
109
113 void Unload() {
114 if (!IsReady()) {
115 return;
116 }
117
118 // The function signature of UnloadAutomationEventList() changes from raylib 5.0.
119 #if RAYLIB_VERSION_MAJOR == 5
120 #if RAYLIB_VERSION_MINOR == 0
121 ::UnloadAutomationEventList(this);
122 #elif RAYLIB_VERSION_MINOR >= 1
123 ::UnloadAutomationEventList(*this);
124 #endif
125 #else
126 ::UnloadAutomationEventList(*this);
127 #endif
128 }
129
130 bool IsReady() {
131 return events != nullptr;
132 }
133
134 bool Export(const char* fileName) {
135 return ::ExportAutomationEventList(*this, fileName);
136 }
137
138 bool Export(const std::string_view fileName) {
139 return ::ExportAutomationEventList(*this, fileName.data());
140 }
141
142 void Set() {
143 ::SetAutomationEventList(this);
144 }
145
146 void SetBaseFrame(int frame) {
147 Set();
148 ::SetAutomationEventBaseFrame(frame);
149 }
150
151 void StartRecording() {
152 Set();
153 ::StartAutomationEventRecording();
154 }
155
156 void StopRecording() {
157 Set();
158 ::StopAutomationEventRecording();
159 }
160
161 void Play(int index) {
162 if (index < 0 || static_cast<unsigned int>(index) >= this->count) {
163 return;
164 }
165
166 Set();
167 ::PlayAutomationEvent(this->events[index]);
168 }
169
170 protected:
171 void set(const ::AutomationEventList& other) {
172 capacity = other.capacity;
173 count = other.count;
174 events = other.events;
175 }
176};
177} // namespace raylib
178
180
181#endif // RAYLIB_CPP_INCLUDE_AUTOMATIONEVENTLIST_HPP_
AutomationEventList management functions.
void Load(const char *fileName)
Load audio stream (to stream raw audio pcm data)
AutomationEventList(const char *fileName)
Load automation events list from file.
AutomationEventList()
Load an empty automation events list.
void Unload()
Update audio stream buffers with data.
void Load(const std::string_view fileName)
Load audio stream (to stream raw audio pcm data)
Exception used for most raylib-related exceptions.