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