libvisual  0.5.0
lv_actor_c.cpp
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 #include "config.h"
23 #include "lv_actor.h"
24 #include "lv_plugin_registry.h"
25 
26 namespace {
27 
28  LV::PluginList const&
29  get_actor_plugin_list ()
30  {
31  return LV::PluginRegistry::instance()->get_plugins_by_type (VISUAL_PLUGIN_TYPE_ACTOR);
32  }
33 
34 } // anonymous namespace
35 
36 const char *visual_actor_get_prev_by_name_gl (const char *name)
37 {
38  const char *prev = name;
39  bool have_gl;
40 
41  do {
42  prev = visual_actor_get_prev_by_name (prev);
43  if (!prev)
44  return nullptr;
45 
46  auto plugin = visual_plugin_load (VISUAL_PLUGIN_TYPE_ACTOR, prev);
47  auto actplugin = (VisActorPlugin *) visual_plugin_get_info (plugin)->plugin;
48 
49  have_gl = (actplugin->vidoptions.depth & VISUAL_VIDEO_DEPTH_GL) > 0;
50 
51  visual_plugin_unload (plugin);
52 
53  } while (!have_gl);
54 
55  return prev;
56 }
57 
58 const char *visual_actor_get_next_by_name_gl (const char *name)
59 {
60  const char *next = nullptr;
61  bool have_gl;
62 
63  do {
64  next = visual_actor_get_next_by_name (next);
65  if (!next)
66  return nullptr;
67 
68  VisPluginData* plugin = visual_plugin_load (VISUAL_PLUGIN_TYPE_ACTOR, next);
69  VisActorPlugin* actplugin = (VisActorPlugin *) visual_plugin_get_info (plugin)->plugin;
70 
71  have_gl = (actplugin->vidoptions.depth & VISUAL_VIDEO_DEPTH_GL) > 0;
72 
73  visual_plugin_unload (plugin);
74 
75  } while (!have_gl);
76 
77  return next;
78 }
79 
80 const char *visual_actor_get_prev_by_name_nogl (const char *name)
81 {
82  const char *prev = name;
83  bool have_gl;
84 
85  do {
86  prev = visual_actor_get_prev_by_name (prev);
87  if (!prev)
88  return nullptr;
89 
90  auto plugin = visual_plugin_load (VISUAL_PLUGIN_TYPE_ACTOR, prev);
91  auto actplugin = (VisActorPlugin *) visual_plugin_get_info (plugin)->plugin;
92 
93  have_gl = (actplugin->vidoptions.depth & VISUAL_VIDEO_DEPTH_GL) > 0;
94 
95  visual_plugin_unload (plugin);
96 
97  } while (have_gl);
98 
99  return prev;
100 }
101 
102 const char *visual_actor_get_next_by_name_nogl (const char *name)
103 {
104  const char *next = name;
105  bool have_gl;
106 
107  do {
108  next = visual_actor_get_next_by_name (next);
109  if (!next)
110  return nullptr;
111 
112  auto plugin = visual_plugin_load (VISUAL_PLUGIN_TYPE_ACTOR, next);
113  auto actplugin = (VisActorPlugin *) visual_plugin_get_info (plugin)->plugin;
114 
115  have_gl = (actplugin->vidoptions.depth & VISUAL_VIDEO_DEPTH_GL) > 0;
116 
117  visual_plugin_unload (plugin);
118 
119  } while (have_gl);
120 
121  return next;
122 }
123 
124 const char *visual_actor_get_prev_by_name (const char *name)
125 {
126  return LV::plugin_get_prev_by_name (get_actor_plugin_list (), name);
127 }
128 
129 const char *visual_actor_get_next_by_name (const char *name)
130 {
131  return LV::plugin_get_next_by_name (get_actor_plugin_list (), name);
132 }
133 
134 VisActor *visual_actor_new (const char *name)
135 {
136  auto self = LV::Actor::load (name);
137  if (self) {
138  LV::intrusive_ptr_add_ref (self.get ());
139  }
140 
141  return self.get ();
142 }
143 
144 void visual_actor_ref (VisActor *self)
145 {
146  visual_return_if_fail (self != nullptr);
147 
148  LV::intrusive_ptr_add_ref (self);
149 }
150 
151 void visual_actor_unref (VisActor *self)
152 {
153  visual_return_if_fail (self != nullptr);
154 
155  LV::intrusive_ptr_release (self);
156 }
157 
158 int visual_actor_realize (VisActor *self)
159 {
160  visual_return_val_if_fail (self != nullptr, FALSE);
161 
162  return self->realize ();
163 }
164 
165 void visual_actor_run (VisActor *self, VisAudio *audio)
166 {
167  visual_return_if_fail (self != nullptr);
168  visual_return_if_fail (audio != nullptr);
169 
170  self->run (*audio);
171 }
172 
173 VisPluginData *visual_actor_get_plugin (VisActor *self)
174 {
175  visual_return_val_if_fail (self != nullptr, nullptr);
176 
177  return self->get_plugin ();
178 }
179 
180 VisSongInfo *visual_actor_get_songinfo (VisActor *self)
181 {
182  visual_return_val_if_fail (self != nullptr, nullptr);
183 
184  return const_cast<VisSongInfo*> (self->get_songinfo ());
185 }
186 
187 VisPalette *visual_actor_get_palette (VisActor *self)
188 {
189  visual_return_val_if_fail (self != nullptr, nullptr);
190 
191  return const_cast<VisPalette*> (self->get_palette ());
192 }
193 
194 
195 VisVideoDepth visual_actor_get_supported_depths (VisActor *self)
196 {
197  visual_return_val_if_fail (self != nullptr, VISUAL_VIDEO_DEPTH_NONE);
198 
199  return self->get_supported_depths ();
200 }
201 
202 VisVideoAttrOptions *visual_actor_get_video_attribute_options (VisActor *self)
203 {
204  visual_return_val_if_fail (self != nullptr, nullptr);
205 
206  return const_cast<VisVideoAttrOptions*> (self->get_video_attribute_options ());
207 }
208 
209 void visual_actor_set_video (VisActor *self, VisVideo *video)
210 {
211  visual_return_if_fail (self != nullptr);
212 
213  self->set_video (video);
214 }
215 
216 VisVideo *visual_actor_get_video (VisActor *self)
217 {
218  visual_return_val_if_fail (self != nullptr, nullptr);
219 
220  return self->get_video ().get ();
221 }
222 
223 int visual_actor_video_negotiate (VisActor *self, VisVideoDepth run_depth, int noevent, int forced)
224 {
225  visual_return_val_if_fail (self != nullptr, FALSE);
226 
227  return self->video_negotiate (run_depth, noevent, forced);
228 }