|
| 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_ |
0 commit comments