C++ API Reference RNBO: src/RNBO_PresetEvent.h Source File

RNBO: src/RNBO_PresetEvent.h Source File

1 //
2 // RNBO_PresetEvent.h
3 //
4 //
5 
6 #ifndef _RNBO_PresetEvent_H_
7 #define _RNBO_PresetEvent_H_
8 
9 #include <memory>
10 
11 #include "RNBO_Types.h"
12 #include "RNBO_List.h"
13 #include "RNBO_PlatformInterface.h"
14 #include "RNBO_Logger.h"
15 #include "RNBO_Debug.h"
16 #include "RNBO_Presets.h"
17 
18 namespace RNBO {
19 
20  class PatcherEventTarget;
21 
22 #ifdef RNBO_NOPRESETS
23 
24  class PresetEvent {
25  public:
26 
27  MillisecondTime getTime() const { return 0; }
28 
29  bool operator==(const PresetEvent& rhs) const
30  {
31  return false;
32  }
33 
34  PatcherEventTarget* getEventTarget() const { return nullptr; }
35 
36  void dumpEvent() const {}
37 
38  private:
39  friend class EventVariant;
40 
41  void setTime(MillisecondTime eventTime) { }
42  };
43 #else
44 
47  class PresetEvent {
48 
49  public:
50 
51  enum Type {
52  Invalid = -1,
53  Set = 0,
54  Touched,
55  Get,
56  SettingBegin,
57  SettingEnd,
58  Max_Type
59  };
60 
61 
62  PresetEvent()
63  : _eventTime(0)
64  , _type(Invalid)
65  {
66  }
67 
68  ~PresetEvent()
69  {
70  }
71 
72  PresetEvent(MillisecondTime eventTime, PresetEvent::Type type)
73  : _eventTime(eventTime)
74  , _type(type)
75  {}
76 
78  MillisecondTime eventTime,
79  PresetEvent::Type type,
80  PresetPtr preset,
81  PresetCallback callback
82  )
83  : _eventTime(eventTime)
84  , _type(type)
85  , _preset(preset)
86  , _callback(callback)
87  {
88  }
89 
90  PresetEvent(const PresetEvent& other)
91  : _eventTime(other._eventTime)
92  {
93  _preset = other._preset;
94  _type = other._type;
95  _callback = other._callback;
96  }
97 
98  PresetEvent(PresetEvent&& other)
99  : _eventTime(std::move(other._eventTime))
100  {
101  _preset = std::move(other._preset);
102  _callback = std::move(other._callback);
103 
104  _type = other._type;
105  other._type = Invalid;
106  }
107 
108  PresetEvent& operator = (const PresetEvent& other)
109  {
110  _eventTime = other._eventTime;
111  _preset = other._preset;
112  _type = other._type;
113  _callback = other._callback;
114 
115  return *this;
116  }
117 
118  PresetEvent& operator = (PresetEvent&& other)
119  {
120  _eventTime = std::move(other._eventTime);
121  _preset = std::move(other._preset);
122  _callback = std::move(other._callback);
123 
124  _type = other._type;
125  other._type = Invalid;
126 
127  return *this;
128  }
129 
130  bool operator==(const PresetEvent& rhs) const
131  {
132  return rhs.getTime() == getTime()
133  && rhs.getType() == getType()
134  && rhs.getPreset() == getPreset();
135  }
136 
137  PresetEvent::Type getType() const { return _type; }
138  MillisecondTime getTime() const { return _eventTime; }
139  PresetPtr getPreset() const { return _preset; }
140  PresetCallback getCallback() const { return _callback; }
141 
142  // we will always use the default event target (the top level patcher)
143  PatcherEventTarget* getEventTarget() const { return nullptr; }
144 
145  // debugging
146  void dumpEvent() const {
147  // disabling for now to avoid requiring fprintf support in generated code
148 // fprintf(stdout, "PresetEvent: time=%.3f type=%d", _eventTime, _type);
149  }
150 
151  protected:
152 
153  MillisecondTime _eventTime;
154  PresetEvent::Type _type = Invalid;
155 
156  PresetPtr _preset;
157  PresetCallback _callback = nullptr;
158 
159  friend class EventVariant;
160 
161  void setTime(MillisecondTime eventTime) { _eventTime = eventTime; }
162  };
163 
164 #endif // RNBO_NOPRESETS
165 
166 } // namespace RNBO
167 
168 
169 #endif // #ifndef _RNBO_PresetEvent_H_