LV2 Toolkit  1.2.0
bufsize.hpp
1 /*
2  bufsize.hpp - Support file for writing LV2 plugins in C++
3 
4  Copyright (C) 2013 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 */
20 
23 #ifndef LVTK_BUFSIZE_HPP
24 #define LVTK_BUFSIZE_HPP
25 
26 
27 #include <lv2/lv2plug.in/ns/ext/buf-size/buf-size.h>
28 
29 #include <lvtk/ext/options.hpp>
30 #include <lvtk/ext/urid.hpp>
31 
32 namespace lvtk {
33 
34  struct BufferInfo {
35  uint32_t min;
36  uint32_t max;
37  uint32_t sequence_size;
38  bool bounded;
39  bool fixed;
40  bool power_of_two;
41  };
42 
52  template <bool Required = false>
53  struct BufSize
54  {
55  template <class Derived>
56  struct I : Extension<Required>
57  {
59  I() : m_checked (false)
60  {
61  this->m_ok = true;
62  memset (&m_info, 0, sizeof (BufferInfo));
63  }
64 
66  static void
68  {
69  hmap[LV2_BUF_SIZE__boundedBlockLength] = &I<Derived>::handle_bounded;
70  hmap[LV2_BUF_SIZE__powerOf2BlockLength] = &I<Derived>::handle_poweroftwo;
71  hmap[LV2_BUF_SIZE__fixedBlockLength] = &I<Derived>::handle_fixed;
72  }
73 
75  static void
76  handle_bounded (void* instance, FeatureData data)
77  {
78  Derived* plugin (reinterpret_cast<Derived*> (instance));
79  I<Derived>* mixin (static_cast<I<Derived>*> (plugin));
80  mixin->m_info.bounded = true;
81  }
82 
84  static void
85  handle_poweroftwo (void* instance, FeatureData data)
86  {
87  Derived* plugin (reinterpret_cast<Derived*> (instance));
88  I<Derived>* mixin (static_cast<I<Derived>*> (plugin));
89  mixin->m_info.power_of_two = true;
90  }
91 
93  static void
94  handle_fixed (void* instance, FeatureData data)
95  {
96  Derived* plugin (reinterpret_cast<Derived*> (instance));
97  I<Derived>* mixin (static_cast<I<Derived>*> (plugin));
98  mixin->m_info.fixed = true;
99  }
101  bool
102  check_ok()
103  {
104  if (LVTK_DEBUG) {
105  std::clog <<" [BufSize] validation "
106  <<(this->m_ok ? "succeeded" : "failed")<<"."<<std::endl;
107  }
108  return this->m_ok;
109  }
110 
111  protected:
112 
114  const BufferInfo&
116  {
117  if (! m_checked)
118  {
119  Derived* plugin (static_cast<Derived*> (this));
120  LV2_URID min (plugin->map (LV2_BUF_SIZE__minBlockLength));
121  LV2_URID max (plugin->map (LV2_BUF_SIZE__maxBlockLength));
122  LV2_URID seq_size (plugin->map (LV2_BUF_SIZE__sequenceSize));
123 
124  OptionsIter iter (plugin->get_supplied_options());
125  while (const Option* opt = iter.next())
126  {
127  if (min == opt->key)
128  m_info.min = *(uint32_t*) opt->value;
129  if (max == opt->key)
130  m_info.max = *(uint32_t*) opt->value;
131  if (seq_size == opt->key)
132  m_info.sequence_size = *(uint32_t*) opt->value;
133  }
134 
135  m_checked = true;
136  }
137 
138  return m_info;
139  }
140 
141  private:
142 
143  bool m_checked;
144  BufferInfo m_info;
145 
146  };
147  };
148 
149 }
150 
151 
152 #endif /* LVTK_BUFSIZE_HPP */
void * FeatureData
Definition: feature.hpp:47
Definition: bufsize.hpp:53
Definition: options.hpp:81
Definition: bufsize.hpp:56
Definition: feature.hpp:34
static void map_feature_handlers(FeatureHandlerMap &hmap)
Definition: bufsize.hpp:67
LV2_Options_Option Option
Definition: options.hpp:39
const BufferInfo & get_buffer_info()
Definition: bufsize.hpp:115
I()
Definition: bufsize.hpp:59
Definition: bufsize.hpp:34
map< string, FeatureHandler > FeatureHandlerMap
Definition: feature.hpp:57