00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <unistd.h>
00004 #include <fcntl.h>
00005 #include <string.h>
00006 #include <math.h>
00007 #include <sys/stat.h>
00008 #include <sys/types.h>
00009
00010 #include <libvisual/libvisual.h>
00011 #include "GizmodLibVisualCInterface.h"
00012
00013 #if HAVE_CONFIG_H
00014 #include <config.h>
00015 #endif
00016 #define CONFIG_FILE "/config"
00017 #define PRESETS_DIR "/presets"
00018 #define FONTS_DIR "/fonts"
00019
00020
00021 int lv_gizmod_init(VisPluginData *plugin);
00022 int lv_gizmod_cleanup(VisPluginData *plugin);
00023 int lv_gizmod_requisition(VisPluginData *plugin, int *width, int *height);
00024 int lv_gizmod_dimension(VisPluginData *plugin, VisVideo *video, int width, int height);
00025 int lv_gizmod_events(VisPluginData *plugin, VisEventQueue *events);
00026 VisPalette *lv_gizmod_palette(VisPluginData *plugin);
00027 int lv_gizmod_render(VisPluginData *plugin, VisVideo *video, VisAudio *audio);
00028
00029
00030 VISUAL_PLUGIN_API_VERSION_VALIDATOR
00031
00039 const VisPluginInfo * get_plugin_info(int *count) {
00040
00041
00042
00043
00044 static VisActorPlugin actor[] = {{
00045 .requisition = lv_gizmod_requisition,
00046 .palette = lv_gizmod_palette,
00047 .render = lv_gizmod_render,
00048
00049 }};
00050
00051
00052
00053
00054 static const VisPluginInfo info[] = {{
00055 .type = VISUAL_PLUGIN_TYPE_ACTOR,
00056
00057 .plugname = "gizmod",
00058 .name = "libVisual Gizmo Daemon Visualization Plugin",
00059 .author = "Tim Burrell",
00060 .version = "3.0",
00061 .about = "Gizmo Daemon",
00062 .help = "This plugin is for visualizing music on Gizmo Daemon supported Gizmos\n\t(such as LEDs on certain USB dials, etc)",
00063
00064 .init = lv_gizmod_init,
00065 .cleanup = lv_gizmod_cleanup,
00066 .events = lv_gizmod_events,
00067
00068 .plugin = (void *) &actor[0]
00069 }};
00070
00071 *count = sizeof (info) / sizeof (*info);
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 return info;
00084 }
00085
00091 int lv_gizmod_init(VisPluginData *plugin) {
00092 GizmodLibVisual_Init();
00093 return 0;
00094 }
00095
00099 int lv_gizmod_cleanup(VisPluginData *plugin) {
00100 GizmodLibVisual_CleanUp();
00101 return 0;
00102 }
00103
00111 int lv_gizmod_requisition(VisPluginData *plugin, int *width, int *height) {
00112 *width = 0;
00113 *height = 0;
00114 return 0;
00115 }
00116
00120 int lv_gizmod_dimension(VisPluginData *plugin, VisVideo *video, int width, int height) {
00121 return 0;
00122 }
00123
00131 int lv_gizmod_events(VisPluginData *plugin, VisEventQueue *events) {
00132 return 0;
00133 }
00134
00141 VisPalette *lv_gizmod_palette(VisPluginData *plugin) {
00142 return NULL;
00143 }
00144
00151 int lv_gizmod_render(VisPluginData *plugin, VisVideo *video, VisAudio *audio) {
00152
00153 int lp;
00154 VisBuffer pcmb;
00155 float pcm[2][512];
00156 visual_buffer_set_data_pair (&pcmb, pcm[0], sizeof (pcm[0]));
00157 visual_audio_get_sample (audio, &pcmb, VISUAL_AUDIO_CHANNEL_LEFT);
00158 visual_buffer_set_data_pair (&pcmb, pcm[1], sizeof (pcm[1]));
00159 visual_audio_get_sample (audio, &pcmb, VISUAL_AUDIO_CHANNEL_RIGHT);
00160
00161 float VULeft = 0.0f;
00162 float VURight = 0.0f;
00163 float VUCombined = 0.0f;
00164 for (lp = 0; lp < 512; lp ++) {
00165 float vall = fabs(pcm[0][lp]);
00166 float valr = fabs(pcm[1][lp]);
00167 float valc = (vall + valr) / 2.0f;
00168
00169 if (vall > VULeft)
00170 VULeft = vall;
00171 if (valr > VURight)
00172 VURight = valr;
00173 if (valc > VUCombined)
00174 VUCombined = valc;
00175 }
00176
00177
00178 GizmodLibVisual_Render(VULeft, VURight, VUCombined);
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 return 0;
00204 }