libvisual  0.5.0
lv_input_c.cpp
1 /* Libvisual - The audio visualisation framework.
2  *
3  * Copyright (C) 2012-2013 Libvisual team
4  * 2004-2006 Dennis Smit
5  *
6  * Authors: Chong Kai Xiong <kaixiong@codeleft.sg>
7  * Dennis Smit <ds@nerds-incorporated.org>
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 #include "config.h"
25 #include "lv_input.h"
26 #include "lv_plugin_registry.h"
27 
28 
29 namespace {
30 
31  LV::PluginList const&
32  get_input_plugin_list ()
33  {
34  return LV::PluginRegistry::instance()->get_plugins_by_type (VISUAL_PLUGIN_TYPE_INPUT);
35  }
36 
37 } // anonymous namespace
38 
39 VisInput *visual_input_new (const char *name)
40 {
41  auto self = LV::Input::load (name);
42  if (self) {
43  LV::intrusive_ptr_add_ref (self.get ());
44  }
45 
46  return self.get ();
47 }
48 
49 void visual_input_ref (VisInput *self)
50 {
51  visual_return_if_fail (self != nullptr);
52 
53  LV::intrusive_ptr_add_ref (self);
54 }
55 
56 void visual_input_unref (VisInput *self)
57 {
58  visual_return_if_fail (self != nullptr);
59 
60  LV::intrusive_ptr_release (self);
61 }
62 
63 int visual_input_realize (VisInput *self)
64 {
65  visual_return_val_if_fail (self != nullptr, FALSE);
66 
67  return self->realize ();
68 }
69 
70 int visual_input_run (VisInput *self)
71 {
72  visual_return_val_if_fail (self != nullptr, FALSE);
73 
74  return self->run ();
75 }
76 
77 VisPluginData *visual_input_get_plugin (VisInput *self)
78 {
79  visual_return_val_if_fail (self != nullptr, nullptr);
80 
81  return self->get_plugin ();
82 }
83 
84 VisAudio *visual_input_get_audio (VisInput *self)
85 {
86  visual_return_val_if_fail (self != nullptr, nullptr);
87 
88  return const_cast<VisAudio *> (&self->get_audio ());
89 }
90 
91 void visual_input_set_callback (VisInput *self, VisInputUploadCallbackFunc callback, void *user_data)
92 {
93  using namespace std::placeholders;
94 
95  visual_return_if_fail (self != nullptr);
96  visual_return_if_fail (callback);
97 
98  auto get_audio_ptr = [=] (LV::Audio& audio) { return &audio; };
99 
100  self->set_callback (std::bind (callback, self, std::bind (get_audio_ptr, _1), user_data));
101 }
102 
103 const char *visual_input_get_next_by_name (const char *name)
104 {
105  return LV::plugin_get_next_by_name (get_input_plugin_list (), name);
106 }
107 
108 const char *visual_input_get_prev_by_name (const char *name)
109 {
110  return LV::plugin_get_prev_by_name (get_input_plugin_list (), name);
111 }