LV2 Toolkit  1.2.0
event.hpp
1 
31 #ifndef LVTK_EVENT_HPP
32 #define LVTK_EVENT_HPP
33 
34 #include <lv2/lv2plug.in/ns/ext/event/event.h>
35 #include <lv2/lv2plug.in/ns/ext/event/event-helpers.h>
36 
37 #warning "this header uses the deprecated lv2 extension event. \
38  please use Atoms instead."
39 
40 #include "lvtk/private/types.hpp"
41 
42 namespace lvtk {
43 
53  template <bool Required = true>
54  struct EventRef
55  {
56  template <class Derived>
57  struct I : Extension<Required>
58  {
59  typedef I<Derived> Mixin;
60 
61  I() : m_callback_data(0), m_ref_func(0), m_unref_func(0) { }
62 
64  static void
65  map_feature_handlers(FeatureHandlerMap& hmap)
66  {
67  hmap[LV2_EVENT_URI] = &Mixin::handle_feature;
68  }
69 
71  static void
72  handle_feature(void* instance, void* data)
73  {
74  Derived* derived = reinterpret_cast<Derived*>(instance);
75  I<Derived>* mixin = static_cast<I<Derived>*>(derived);
76 
77  LV2_Event_Feature* edata =
78  reinterpret_cast<LV2_Event_Feature*>(data);
79 
80  mixin->m_callback_data = edata->callback_data;
81  mixin->m_ref_func = edata->lv2_event_ref;
82  mixin->m_unref_func = edata->lv2_event_unref;
83 
84  mixin->m_ok = true;
85  }
86 
87  bool
88  check_ok() {
89  if (LVTK_DEBUG) {
90  std::clog<<" [LV2::EventRef] Validation "
91  <<(this->m_ok ? "succeeded" : "failed")<<"."<<std::endl;
92  }
93  return this->m_ok;
94  }
95 
96  protected:
97 
107  uint32_t
108  event_ref(LV2_Event* event) {
109  return m_ref_func(m_callback_data, event);
110  }
111 
116  uint32_t
117  event_unref(LV2_Event* event) {
118  return m_unref_func(m_callback_data, event);
119  }
120 
121  LV2_Event_Callback_Data m_callback_data;
122  uint32_t (*m_ref_func)(LV2_Event_Callback_Data, LV2_Event*);
123  uint32_t (*m_unref_func)(LV2_Event_Callback_Data, LV2_Event*);
124 
125  };
126 
127  };
128 
129 } /* namespace lvtk */
130 
131 #endif /* LVTK_EVENT_HPP */
Definition: event.hpp:54
Definition: event.hpp:57
uint32_t event_unref(LV2_Event *event)
Definition: event.hpp:117
Definition: feature.hpp:34
uint32_t event_ref(LV2_Event *event)
Definition: event.hpp:108
map< string, FeatureHandler > FeatureHandlerMap
Definition: feature.hpp:57