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