Skip to content

Commit 27b6b12

Browse files
authored
Add AutomationEventList (#267)
1 parent ff5bd5b commit 27b6b12

File tree

4 files changed

+139
-0
lines changed

4 files changed

+139
-0
lines changed

clib.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"src": [
2424
"include/AudioDevice.hpp",
2525
"include/AudioStream.hpp",
26+
"include/AutomationEventList.hpp",
2627
"include/BoundingBox.hpp",
2728
"include/Camera2D.hpp",
2829
"include/Camera3D.hpp",

include/AutomationEventList.hpp

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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+
8+
namespace raylib {
9+
/**
10+
* AutomationEventList management functions
11+
*/
12+
class AutomationEventList : public ::AutomationEventList {
13+
public:
14+
AutomationEventList(const ::AutomationEventList& automationEventList) {
15+
set(automationEventList);
16+
}
17+
18+
AutomationEventList(unsigned int capacity = 16384,
19+
unsigned int count = 0,
20+
AutomationEvent *events = nullptr) : ::AutomationEventList{capacity, count, events} {
21+
// Nothing.
22+
}
23+
24+
AutomationEventList(const char* fileName) {
25+
Load(fileName);
26+
}
27+
28+
AutomationEventList(const AutomationEventList&) = delete;
29+
30+
AutomationEventList(AutomationEventList&& other) {
31+
set(other);
32+
33+
other.capacity = 0;
34+
other.count = 0;
35+
other.events = nullptr;
36+
}
37+
38+
~AutomationEventList() {
39+
Unload();
40+
}
41+
42+
GETTERSETTER(unsigned int, Capacity, capacity)
43+
GETTERSETTER(unsigned int, Count, count)
44+
GETTERSETTER(AutomationEvent*, Events, events)
45+
46+
AutomationEventList& operator=(const ::AutomationEventList& other) {
47+
set(other);
48+
return *this;
49+
}
50+
51+
AutomationEventList& operator=(const AutomationEventList&) = delete;
52+
53+
AutomationEventList& operator=(AutomationEventList&& other) noexcept {
54+
if (this == &other) {
55+
return *this;
56+
}
57+
58+
Unload();
59+
set(other);
60+
61+
other.capacity = 0;
62+
other.count = 0;
63+
other.events = nullptr;
64+
65+
return *this;
66+
}
67+
68+
/**
69+
* Load audio stream (to stream raw audio pcm data)
70+
*
71+
* @throws raylib::RaylibException Throws if the AutomationEventList failed to load.
72+
*/
73+
void Load(const char* fileName) {
74+
Unload();
75+
set(::LoadAutomationEventList(fileName));
76+
if (!IsReady()) {
77+
throw RaylibException("Failed to load automation event list");
78+
}
79+
}
80+
81+
/**
82+
* Update audio stream buffers with data
83+
*/
84+
inline AutomationEventList& Unload() {
85+
::UnloadAutomationEventList(this);
86+
return *this;
87+
}
88+
89+
inline bool IsReady() {
90+
return events != nullptr;
91+
}
92+
93+
inline bool Export(const char* fileName) {
94+
return ::ExportAutomationEventList(*this, fileName);
95+
}
96+
97+
inline void Set() {
98+
::SetAutomationEventList(this);
99+
}
100+
101+
inline void SetBaseFrame(int frame) {
102+
Set();
103+
::SetAutomationEventBaseFrame(frame);
104+
}
105+
106+
inline void StartRecording() {
107+
Set();
108+
::StartAutomationEventRecording();
109+
}
110+
111+
inline void StopRecording() {
112+
Set();
113+
::StopAutomationEventRecording();
114+
}
115+
116+
inline void Play(int index) {
117+
if (index < 0 || index >= this->count) {
118+
return;
119+
}
120+
121+
Set();
122+
::PlayAutomationEvent(this->events[index]);
123+
}
124+
125+
protected:
126+
void set(const ::AutomationEventList& other) {
127+
capacity = other.capacity;
128+
count = other.count;
129+
events = other.events;
130+
}
131+
};
132+
} // namespace raylib
133+
134+
using RAutomationEventList = raylib::AutomationEventList;
135+
136+
#endif // RAYLIB_CPP_INCLUDE_AUTOMATIONEVENTLIST_HPP_

include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ target_include_directories(raylib_cpp INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/)
77
install(FILES
88
AudioDevice.hpp
99
AudioStream.hpp
10+
AutomationEventList.hpp
1011
BoundingBox.hpp
1112
Camera2D.hpp
1213
Camera3D.hpp

include/raylib-cpp.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include "./AudioDevice.hpp"
3535
#include "./AudioStream.hpp"
36+
#include "./AutomationEventList.hpp"
3637
#include "./BoundingBox.hpp"
3738
#include "./Camera2D.hpp"
3839
#include "./Camera3D.hpp"

0 commit comments

Comments
 (0)