libvisual  0.5.0
lv_param.h
1 /* Libvisual - The audio visualisation framework.
2  *
3  * Copyright (C) 2012-2013 Libvisual team
4  *
5  * Authors: Chong Kai Xiong <kaixiong@codeleft.sg>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */
21 
22 #ifndef _LV_PARAM_H
23 #define _LV_PARAM_H
24 
25 #include <libvisual/lvconfig.h>
26 #include <libvisual/lv_defines.h>
27 #include <libvisual/lv_color.h>
28 #include <libvisual/lv_palette.h>
29 #include <libvisual/lv_event.h>
30 #include <libvisual/lv_param_value.h>
31 #include <libvisual/lv_param_validators.h>
32 
38 #ifdef __cplusplus
39 
40 #include <initializer_list>
41 #include <memory>
42 
43 namespace LV {
44 
45  class Param;
46 
47  class LV_API ParamList
48  {
49  public:
50 
54  ParamList ();
55 
59  ParamList (std::initializer_list<Param*> params);
60 
64  ParamList (ParamList&& list);
65 
67  ~ParamList ();
68 
74  void add (Param&& param);
75 
83  void add (Param* param);
84 
90  template <class Container>
91  void add (Container const& params)
92  {
93  for (auto const& param : params) {
94  add (param);
95  }
96  }
97 
105  bool remove (std::string const& name);
106 
115  Param* get (std::string const& name) const;
116 
122  void set_event_queue (EventQueue& event_queue);
123 
131  EventQueue* get_event_queue () const;
132 
133  private:
134 
135  class Impl;
136  std::unique_ptr<Impl> m_impl;
137  };
138 
139 } // LV namespace
140 
141 typedef LV::Param VisParam;
143 
144 #else
145 
146 typedef struct _VisParam VisParam;
147 typedef struct _VisParamList VisParamList;
148 
149 #endif
150 
151 #define VISUAL_PARAM(obj) ((VisParam *) (obj))
152 #define VISUAL_PARAM_LIST(obj) ((VisParamList *) (obj))
153 
154 typedef int (*VisParamValidateFunc) (VisParamValue *value, void *priv);
155 typedef void (*VisParamChangedFunc) (VisParam *param, void *priv);
156 typedef void (*VisDestroyFunc) (void *data);
157 
158 LV_BEGIN_DECLS
159 
160 /* VisClosure API */
161 
162 LV_API VisClosure *visual_closure_new (void *func, void *data, VisDestroyFunc destroy_func);
163 LV_API void visual_closure_free (VisClosure *self);
164 
165 /* VisParamList API */
166 
167 LV_API VisParamList *visual_param_list_new (void);
168 LV_API void visual_param_list_free (VisParamList *self);
169 
170 LV_API void visual_param_list_add (VisParamList *list, VisParam *param);
171 LV_API void visual_param_list_add_array (VisParamList *list, VisParam **params, unsigned int nparams);
172 LV_API void visual_param_list_add_many (VisParamList *list, ...);
173 LV_API VisParam ** visual_param_list_get_entries (VisParamList *list);
174 LV_API int visual_param_list_remove (VisParamList *list, const char *name);
175 LV_API VisParam * visual_param_list_get (VisParamList *list, const char *name);
176 
177 LV_API void visual_param_list_set_event_queue (VisParamList *list, VisEventQueue *eventqueue);
178 LV_API VisEventQueue *visual_param_list_get_event_queue (VisParamList *list);
179 
180 /* VisParam API */
181 
193 LV_API VisParam *visual_param_new (const char * name,
194  const char * description,
195  VisParamType type,
196  void * default_value,
197  VisClosure * validator);
198 
204 LV_API void visual_param_free (VisParam *param);
205 
214 LV_API VisClosure *visual_param_add_callback (VisParam * param,
215  VisParamChangedFunc func,
216  void * data,
217  VisDestroyFunc destroy_func);
218 
227 LV_API int visual_param_remove_callback (VisParam *param, VisClosure *closure);
228 
234 LV_API void visual_param_notify_callbacks (VisParam *param);
235 
241 LV_API void visual_param_changed (VisParam *param);
242 
251 LV_API int visual_param_has_name (VisParam *param, const char *name);
252 
253 LV_API const char * visual_param_get_name (VisParam *param);
254 LV_API VisParamType visual_param_get_type (VisParam *param);
255 LV_API const char * visual_param_get_description (VisParam *param);
256 
257 LV_API void visual_param_set_value (VisParam *param, VisParamValue *value);
258 LV_API void visual_param_set_value_bool (VisParam *param, int boolean);
259 LV_API void visual_param_set_value_integer (VisParam *param, int integer);
260 LV_API void visual_param_set_value_float (VisParam *param, float flt);
261 LV_API void visual_param_set_value_double (VisParam *param, double dbl);
262 LV_API void visual_param_set_value_string (VisParam *param, const char *string);
263 LV_API void visual_param_set_value_color (VisParam *param, VisColor *color);
264 LV_API void visual_param_set_value_palette (VisParam *param, VisPalette *pal);
265 
266 LV_API int visual_param_get_value_bool (VisParam *param);
267 LV_API int visual_param_get_value_integer (VisParam *param);
268 LV_API float visual_param_get_value_float (VisParam *param);
269 LV_API double visual_param_get_value_double (VisParam *param);
270 LV_API const char *visual_param_get_value_string (VisParam *param);
271 LV_API VisColor * visual_param_get_value_color (VisParam *param);
272 LV_API VisPalette *visual_param_get_value_palette (VisParam *param);
273 
274 /* Type-safe variants of visual_param_new() */
275 
276 #define _LV_DEFINE_PARAM_NEW(func,ctype,type,marshal) \
277  static inline VisParam *visual_param_new_##func (const char *name, \
278  const char *description, \
279  ctype default_value, \
280  VisClosure *validator) \
281  { return visual_param_new (name, description, VISUAL_PARAM_TYPE_##type, _LV_PARAM_MARSHAL_##marshal (default_value), validator); }
282 
283 _LV_DEFINE_PARAM_NEW (bool , int , BOOL , INTEGER)
284 _LV_DEFINE_PARAM_NEW (integer, int , INTEGER, INTEGER)
285 _LV_DEFINE_PARAM_NEW (float , float , FLOAT , FLOAT)
286 _LV_DEFINE_PARAM_NEW (double , double , DOUBLE , DOUBLE)
287 _LV_DEFINE_PARAM_NEW (string , const char * , STRING , POINTER)
288 _LV_DEFINE_PARAM_NEW (color , const VisColor * , COLOR , POINTER)
289 _LV_DEFINE_PARAM_NEW (palette, const VisPalette *, PALETTE, POINTER)
290 
291 static inline VisParam *visual_param_new_color_rgb (const char *name,
292  const char *description,
293  uint8_t red,
294  uint8_t green,
295  uint8_t blue,
296  VisClosure *validator)
297 {
298  VisColor color = { red, green, blue, 255 };
299  return visual_param_new_color (name, description, &color, validator);
300 }
301 
302 LV_END_DECLS
303 
308 #endif /* _LV_PARAM_H */