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 "./RaylibException.hpp"
5#include <span>
6#include <string_view>
7
8namespace raylib {
12class AutomationEventList : public ::AutomationEventList {
13public:
14 AutomationEventList(const ::AutomationEventList& automationEventList)
15 : ::AutomationEventList(automationEventList) {
16 // Nothing.
17 }
18
22 AutomationEventList() { set(::LoadAutomationEventList(0)); }
23
24 AutomationEventList(unsigned int capacity = 16384,
25 std::span<AutomationEvent> events = {}) : ::AutomationEventList{capacity, static_cast<unsigned int>(events.size()), events.data()} {
26 // Nothing.
27 }
28
34 AutomationEventList(const char* fileName) {
35 Load(fileName);
36 }
37 AutomationEventList(const std::string_view fileName) {
38 Load(fileName.data());
39 }
40
42
44 set(other);
45
46 other.capacity = 0;
47 other.count = 0;
48 other.events = nullptr;
49 }
50
51 ~AutomationEventList() { Unload(); }
52
53 GETTER(unsigned int, Capacity, capacity)
54 GETTER(unsigned int, Count, count)
55 GETTER(AutomationEvent*, Events, events)
56
57 AutomationEventList& operator=(const ::AutomationEventList& other) {
58 set(other);
59 return *this;
60 }
61
62 AutomationEventList& operator=(const AutomationEventList&) = delete;
63
64 AutomationEventList& operator=(AutomationEventList&& other) noexcept {
65 if (this == &other) {
66 return *this;
67 }
68
69 Unload();
70 set(other);
71
72 other.capacity = 0;
73 other.count = 0;
74 other.events = nullptr;
75
76 return *this;
77 }
78
84 void Load(const char* fileName) {
85 Unload();
86 set(::LoadAutomationEventList(fileName));
87 if (!IsValid()) {
88 throw RaylibException("Failed to load automation event list");
89 }
90 }
91
97 void Load(const std::string_view fileName) {
98 Unload();
99 set(::LoadAutomationEventList(fileName.data()));
100 if (!IsValid()) {
101 throw RaylibException("Failed to load automation event list");
102 }
103 }
104
108 void Unload() {
109 if (!IsValid()) {
110 return;
111 }
112
113// The function signature of UnloadAutomationEventList() changes from raylib 5.0.
114#if RAYLIB_VERSION_MAJOR == 5
115#if RAYLIB_VERSION_MINOR == 0
116 ::UnloadAutomationEventList(this);
117#elif RAYLIB_VERSION_MINOR >= 1
118 ::UnloadAutomationEventList(*this);
119#endif
120#else
121 ::UnloadAutomationEventList(*this);
122#endif
123 }
124
125 bool IsValid() { return events != nullptr; }
126
127 bool Export(const char* fileName) { return ::ExportAutomationEventList(*this, fileName); }
128
129 bool Export(const std::string_view fileName) {
130 return ::ExportAutomationEventList(*this, fileName.data());
131 }
132
133 void Set() {
134 ::SetAutomationEventList(this);
135 }
136
137 void SetBaseFrame(int frame) {
138 Set();
139 ::SetAutomationEventBaseFrame(frame);
140 }
141
142 void StartRecording() {
143 Set();
144 ::StartAutomationEventRecording();
145 }
146
147 void StopRecording() {
148 Set();
149 ::StopAutomationEventRecording();
150 }
151
152 void Play(int index) {
153 if (index < 0 || static_cast<unsigned int>(index) >= this->count) {
154 return;
155 }
156
157 Set();
158 ::PlayAutomationEvent(this->events[index]);
159 }
160protected:
161 void set(const ::AutomationEventList& other) {
162 capacity = other.capacity;
163 count = other.count;
164 events = other.events;
165 }
166};
167} // namespace raylib
168
170
171#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.
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8