Debian Codegraph @

include/frei0r.hpp

raw symbols SCIP
1 extern "C"
2 {
3 #include "frei0r.h"
4 }
5
6 #include <list>
7 #include <vector>
8 #include <string>
9 #include <iostream>
10
11
12 namespace frei0r
13 {
14 class fx;
15
16 // remember me
17 static std::string s_name;
18 static std::string s_author;
19 static std::string s_explanation;
20 static std::pair<int,int> s_version;
21 static unsigned int s_effect_type;
22 static unsigned int s_color_model;
23
24 static fx* (*s_build) (unsigned int, unsigned int);
25
26 struct param_info
27 {
28 param_info(const std::string& name, const std::string& desc, int type)
29 : m_name(name), m_desc(desc), m_type(type) {}
30
31 std::string m_name;
32 std::string m_desc;
33 int m_type;
34 };
35
36 static std::vector<param_info> s_params;
37
38
39 class fx
40 {
41 public:
42
43 unsigned int width;
44 unsigned int height;
45 unsigned int size; // = width * height
46 std::vector<void*> param_ptrs;
47
48 fx()
49 {
50 s_params.clear(); // reinit static params
51 }
52
53 virtual unsigned int effect_type()=0;
54
55 void register_param(f0r_param_color& p_loc,
56 const std::string& name,
57 const std::string& desc)
58 {
59 param_ptrs.push_back(&p_loc);
60 s_params.push_back(param_info(name,desc,F0R_PARAM_COLOR));
61 }
62
63 void register_param(double& p_loc,
64 const std::string& name,
65 const std::string& desc)
66 {
67 param_ptrs.push_back(&p_loc);
68 s_params.push_back(param_info(name,desc,F0R_PARAM_DOUBLE));
69 }
70
71 void register_param(bool& p_loc,
72 const std::string& name,
73 const std::string& desc)
74 {
75 param_ptrs.push_back(&p_loc);
76 s_params.push_back(param_info(name,desc,F0R_PARAM_BOOL));
77 }
78
79 void register_param(f0r_param_position& p_loc,
80 const std::string& name,
81 const std::string& desc)
82 {
83 param_ptrs.push_back(&p_loc);
84 s_params.push_back(param_info(name,desc,F0R_PARAM_POSITION));
85 }
86
87 void register_param(std::string& p_loc,
88 const std::string& name,
89 const std::string& desc)
90 {
91 param_ptrs.push_back(&p_loc);
92 s_params.push_back(param_info(name,desc,F0R_PARAM_STRING));
93 }
94
95
96 void get_param_value(f0r_param_t param, int param_index)
97 {
98 if (!param || param_index < 0 || param_index >= (int)param_ptrs.size())
99 return;
100
101 void* ptr = param_ptrs[param_index];
102
103 switch (s_params[param_index].m_type)
104 {
105 case F0R_PARAM_BOOL :
106 *static_cast<f0r_param_bool*>(param)
107 = *static_cast<bool*>(ptr) ? 1.0 : 0.0;
108 break;
109 case F0R_PARAM_DOUBLE:
110 *static_cast<f0r_param_double*>(param)
111 = *static_cast<f0r_param_double*>(ptr);
112 break;
113 case F0R_PARAM_COLOR:
114 *static_cast<f0r_param_color*>(param)
115 = *static_cast<f0r_param_color*>(ptr);
116 break;
117 case F0R_PARAM_POSITION:
118 *static_cast<f0r_param_position*>(param)
119 = *static_cast<f0r_param_position*>(ptr);
120 break;
121 case F0R_PARAM_STRING:
122 *static_cast<f0r_param_string*>(param)
123 = const_cast<f0r_param_string>(static_cast<std::string*>(ptr)->c_str());
124 break;
125 }
126 }
127
128
129 void set_param_value(f0r_param_t param, int param_index)
130 {
131 if (!param || param_index < 0 || param_index >= (int)param_ptrs.size())
132 return;
133
134 void* ptr = param_ptrs[param_index];
135
136 switch (s_params[param_index].m_type)
137 {
138 case F0R_PARAM_BOOL :
139 *static_cast<bool*>(ptr)
140 = (*static_cast<f0r_param_bool*>(param) > 0.5) ;
141 break;
142 case F0R_PARAM_DOUBLE:
143 *static_cast<f0r_param_double*>(ptr)
144 = *static_cast<f0r_param_double*>(param);
145 break;
146 case F0R_PARAM_COLOR:
147 *static_cast<f0r_param_color*>(ptr)
148 = *static_cast<f0r_param_color*>(param);
149 break;
150 case F0R_PARAM_POSITION:
151 *static_cast<f0r_param_position*>(ptr)
152 = *static_cast<f0r_param_position*>(param);
153 break;
154 case F0R_PARAM_STRING:
155 {
156 f0r_param_string str = *static_cast<f0r_param_string*>(param);
157 if (str)
158 *static_cast<std::string*>(ptr) = str;
159 break;
160 }
161 }
162
163 }
164
165 virtual void update(double time,
166 uint32_t* out,
167 const uint32_t* in1,
168 const uint32_t* in2,
169 const uint32_t* in3) = 0;
170
171 virtual ~fx()
172 {
173 }
174 };
175
176 class source : public fx
177 {
178 protected:
179 source() {}
180
181 public:
182 virtual unsigned int effect_type(){ return F0R_PLUGIN_TYPE_SOURCE; }
183 virtual void update(double time, uint32_t* out) = 0;
184
185 private:
186 virtual void update(double time,
187 uint32_t* out,
188 const uint32_t* in1,
189 const uint32_t* in2,
190 const uint32_t* in3) {
191 (void)in1; // unused
192 (void)in2; // unused
193 (void)in3; // unused
194 update(time, out);
195 }
196 };
197
198 class filter : public fx
199 {
200 protected:
201 filter() {}
202
203 public:
204 virtual unsigned int effect_type(){ return F0R_PLUGIN_TYPE_FILTER; }
205 virtual void update(double time, uint32_t* out, const uint32_t* in1) = 0;
206
207 private:
208 virtual void update(double time,
209 uint32_t* out,
210 const uint32_t* in1,
211 const uint32_t* in2,
212 const uint32_t* in3) {
213 (void)in2; // unused
214 (void)in3; // unused
215 update(time, out, in1);
216 }
217 };
218
219 class mixer2 : public fx
220 {
221 protected:
222 mixer2() {}
223
224 public:
225 virtual unsigned int effect_type(){ return F0R_PLUGIN_TYPE_MIXER2; }
226 virtual void update(double time, uint32_t* out, const uint32_t* in1, const uint32_t* in2) = 0;
227
228 private:
229 virtual void update(double time,
230 uint32_t* out,
231 const uint32_t* in1,
232 const uint32_t* in2,
233 const uint32_t* in3) {
234 (void)in3; // unused
235 update(time, out, in1, in2);
236 }
237 };
238
239
240 class mixer3 : public fx
241 {
242 protected:
243 mixer3() {}
244
245 public:
246 virtual unsigned int effect_type(){ return F0R_PLUGIN_TYPE_MIXER3; }
247 };
248
249
250 // register stuff
251 template<class T>
252 class construct
253 {
254 public:
255 construct(const std::string& name,
256 const std::string& explanation,
257 const std::string& author,
258 const int& major_version,
259 const int& minor_version,
260 unsigned int color_model = F0R_COLOR_MODEL_BGRA8888)
261 {
262 T a(0,0);
263
264 s_name=name;
265 s_explanation=explanation;
266 s_author=author;
267 s_version=std::make_pair(major_version,minor_version);
268 s_build=build;
269
270 s_effect_type=a.effect_type();
271 s_color_model=color_model;
272 }
273
274 private:
275 static fx* build(unsigned int width, unsigned int height)
276 {
277 return new T(width,height);
278 }
279 };
280 }
281
282
283 // the exported frei0r functions
284
285 int f0r_init()
286 {
287 return 1;
288 }
289
290 void f0r_deinit()
291 {
292 }
293
294 void f0r_get_plugin_info(f0r_plugin_info_t* info)
295 {
296 info->name = frei0r::s_name.c_str();
297 info->author = frei0r::s_author.c_str();
298 info->plugin_type = frei0r::s_effect_type;
299 info->color_model = frei0r::s_color_model;
300 info->frei0r_version = FREI0R_MAJOR_VERSION;
301 info->major_version = frei0r::s_version.first;
302 info->minor_version = frei0r::s_version.second;
303 info->explanation = frei0r::s_explanation.c_str();
304 info->num_params = static_cast<int>(frei0r::s_params.size());
305 }
306
307 void f0r_get_param_info(f0r_param_info_t* info, int param_index)
308 {
309 if (!info || param_index < 0 || param_index >= (int)frei0r::s_params.size())
310 return;
311
312 info->name=frei0r::s_params[param_index].m_name.c_str();
313 info->type=frei0r::s_params[param_index].m_type;
314 info->explanation=frei0r::s_params[param_index].m_desc.c_str();
315 }
316
317 f0r_instance_t f0r_construct(unsigned int width, unsigned int height)
318 {
319 frei0r::fx* nfx = frei0r::s_build(width, height);
320 nfx->width=width;
321 nfx->height=height;
322 nfx->size=width*height;
323 return nfx;
324 }
325
326 void f0r_destruct(f0r_instance_t instance)
327 {
328 delete static_cast<frei0r::fx*>(instance);
329 }
330
331 void f0r_set_param_value(f0r_instance_t instance,
332 f0r_param_t param, int param_index)
333 {
334 if (instance)
335 static_cast<frei0r::fx*>(instance)->set_param_value(param, param_index);
336 }
337
338 void f0r_get_param_value(f0r_instance_t instance,
339 f0r_param_t param, int param_index)
340 {
341 if (instance)
342 static_cast<frei0r::fx*>(instance)->get_param_value(param, param_index);
343 }
344
345 void f0r_update2(f0r_instance_t instance, double time,
346 const uint32_t* inframe1,
347 const uint32_t* inframe2,
348 const uint32_t* inframe3,
349 uint32_t* outframe)
350 {
351 static_cast<frei0r::fx*>(instance)->update(time,
352 outframe,
353 inframe1,
354 inframe2,
355 inframe3);
356 }
357
358 // compatibility for frei0r 1.0
359 void f0r_update(f0r_instance_t instance,
360 double time, const uint32_t* inframe, uint32_t* outframe)
361 {
362 f0r_update2(instance, time, inframe, 0, 0, outframe);
363 }