LV2 Toolkit  1.2.0
resize_port.hpp
1 /*
2  resize_port.hpp - support file for writing LV2 plugins in C++
3  Copyright (C) 2012 Michael Fisher <mfisher31@gmail.com>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 01222-1307 USA
18  */
19 
24 #ifndef LVTK_RESIZE_PORT_HPP
25 #define LVTK_RESIZE_PORT_HPP
26 
27 #include <lv2/lv2plug.in/ns/ext/resize-port/resize-port.h>
28 
29 #include <lvtk/private/types.hpp>
30 
31 namespace lvtk
32 {
34  typedef enum
35  {
36  RESIZE_PORT_SUCCESS = LV2_RESIZE_PORT_SUCCESS,
37  RESIZE_PORT_ERR_UNKNOWN = LV2_RESIZE_PORT_ERR_UNKNOWN,
38  RESIZE_PORT_ERR_NO_SPACE = LV2_RESIZE_PORT_ERR_NO_SPACE
40 
46  template<bool Required = true>
47  struct ResizePort
48  {
49  template<class Derived>
50  struct I : Extension<Required>
51  {
52  I() : p_resize_port_resize(NULL) { }
53 
55  static void
56  map_feature_handlers(FeatureHandlerMap& hmap)
57  {
58  hmap[LV2_RESIZE_PORT__resize] =
60  }
61 
63  static void
64  handle_feature(LV2_Handle instance, FeatureData data)
65  {
66  Derived* derived = reinterpret_cast<Derived*>(instance);
67  I<Derived>* mixin = static_cast<I<Derived>*>(derived);
68 
69  mixin->p_resize_port_resize =
70  reinterpret_cast<LV2_Resize_Port_Resize*>(data);
71 
72  mixin->m_ok = true;
73  }
74 
76  bool
77  check_ok()
78  {
79  if (LVTK_DEBUG)
80  {
81  std::clog << " [LV2::ResizePort] Validation "
82  << (this->m_ok ? "succeeded" : "failed")
83  << "." << std::endl;
84  }
85  return this->m_ok;
86  }
87 
88  protected:
89 
103  ResizePortStatus
104  resize (uint32_t index, size_t size)
105  {
106  if (0 == p_resize_port_resize)
108 
109  LV2_Resize_Port_Feature_Data data = p_resize_port_resize->data;
110  return (ResizePortStatus) p_resize_port_resize->resize (data, index, size);
111  }
112 
113  private:
114  LV2_Resize_Port_Resize * p_resize_port_resize;
115  };
116  };
117 
118 } /* namespace lvtk */
119 
120 #endif /* LVTK_RESIZE_PORT_HPP */
ResizePortStatus resize(uint32_t index, size_t size)
Definition: resize_port.hpp:104
Definition: resize_port.hpp:37
void * FeatureData
Definition: feature.hpp:47
Definition: resize_port.hpp:36
Definition: feature.hpp:34
Definition: resize_port.hpp:50
Definition: resize_port.hpp:38
ResizePortStatus
Definition: resize_port.hpp:34
Definition: resize_port.hpp:47
map< string, FeatureHandler > FeatureHandlerMap
Definition: feature.hpp:57