libvisual  0.5.0
lv_input.h
1 /* Libvisual - The audio visualisation framework.
2  *
3  * Copyright (C) 2012 Libvisual team
4  * 2004-2006 Dennis Smit
5  *
6  * Authors: Dennis Smit <ds@nerds-incorporated.org>
7  * Chong Kai Xiong <kaixiong@codeleft.sg>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public License as
11  * published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */
23 
24 #ifndef _LV_INPUT_H
25 #define _LV_INPUT_H
26 
27 #include <libvisual/lv_audio.h>
28 #include <libvisual/lv_plugin.h>
29 
35 #ifdef __cplusplus
36 
37 #include <libvisual/lv_intrusive_ptr.hpp>
38 #include <memory>
39 
40 namespace LV {
41 
42  class Input;
43 
44  typedef LV::IntrusivePtr<Input> InputPtr;
45 
46  class LV_API Input
47  {
48  public:
49 
57  static InputPtr load (std::string const& name);
58 
59  ~Input ();
60 
66  VisPluginData* get_plugin ();
67 
73  bool realize ();
74 
84  void set_callback (std::function<bool (Audio&)> const& callback);
85 
86  Audio const& get_audio ();
87 
97  bool run ();
98 
99  private:
100 
101  friend void intrusive_ptr_add_ref (Input const* input);
102  friend void intrusive_ptr_release (Input const* input);
103 
104  class Impl;
105  const std::unique_ptr<Impl> m_impl;
106 
107  mutable unsigned int m_ref_count;
108 
109  explicit Input (std::string const& name);
110  };
111 
112  inline void intrusive_ptr_add_ref (Input const* input)
113  {
114  input->m_ref_count++;
115  }
116 
117  inline void intrusive_ptr_release (Input const* input)
118  {
119  if (--input->m_ref_count == 0) {
120  delete input;
121  }
122  }
123 
124 } // LV namespace
125 
126 typedef LV::Input VisInput;
127 
128 #else
129 
130 typedef struct _VisInput VisInput;
131 struct _VisInput;
132 
133 #endif /* __cplusplus */
134 
138 typedef struct _VisInputPlugin VisInputPlugin;
139 
149 typedef int (*VisInputUploadCallbackFunc)(VisInput *input, VisAudio *audio, void *user_data);
150 
161 typedef int (*VisPluginInputUploadFunc)(VisPluginData *plugin, VisAudio *audio);
162 
168 };
169 
170 LV_BEGIN_DECLS
171 
172 LV_API VisInput *visual_input_new (const char *name);
173 LV_API void visual_input_ref (VisInput *input);
174 LV_API void visual_input_unref (VisInput *input);
175 LV_API int visual_input_realize (VisInput *input);
176 LV_API int visual_input_run (VisInput *input);
177 
178 LV_API VisPluginData *visual_input_get_plugin (VisInput *input);
179 LV_API VisAudio *visual_input_get_audio (VisInput *audio);
180 LV_API void visual_input_set_callback (VisInput *input, VisInputUploadCallbackFunc callback, void *user_data);
181 
191 LV_API const char *visual_input_get_next_by_name (const char *name);
192 
202 LV_API const char *visual_input_get_prev_by_name (const char *name);
203 
204 LV_END_DECLS
205 
210 #endif /* _LV_INPUT_H */