[vlc-devel] [PATCH 2/2] New ProjectM API (2/2 - projectm)
XilasZ
xilasz at gmail.com
Wed Dec 8 23:37:22 CET 2010
Hi,
So as the title says, 7 new API for projectm, to get info on presets, change
it or lock it.
diff --git a/modules/visualization/projectm.cpp
b/modules/visualization/projectm.cpp
index 13e85d8..d510c4f 100644
--- a/modules/visualization/projectm.cpp
+++ b/modules/visualization/projectm.cpp
@@ -104,6 +104,9 @@ struct filter_sys_t
vout_thread_t *p_vout;
vout_display_t *p_vd;
+ /* libprojectM objects */
+ projectM *p_projectm;
+
/* Window size */
int i_width;
int i_height;
@@ -117,6 +120,10 @@ struct filter_sys_t
float *p_buffer;
int i_buffer_size;
int i_nb_samples;
+
+ /* projectm interaction */
+ bool b_changed;
+ int i_preset_id;
};
@@ -163,6 +170,7 @@ static int Open( vlc_object_t * p_this )
p_sys->p_buffer = NULL;
p_sys->i_buffer_size = 0;
p_sys->i_nb_samples = 0;
+ p_sys->b_changed = false;
/* Create the thread */
if( vlc_clone( &p_sys->thread, Thread, p_filter,
VLC_THREAD_PRIORITY_LOW ) )
@@ -257,6 +265,51 @@ static int VoutCallback( vlc_object_t *p_vout, char
const *psz_name,
}
/**
+ * Variable callback for the preset change request
+ */
+static int ProjectMCallback( vlc_object_t *p_vout, char const *psz_name,
+ vlc_value_t oldv, vlc_value_t newv, void *p_data )
+{
+ filter_t *p_filter = (filter_t*)p_data;
+ filter_sys_t *p_sys = p_filter->p_sys;
+
+ if( !strcmp(psz_name, "projectm-preset-cmd") )
+ {
+ if ( newv.i_int == VLC_PROJECTM_CMD_GET_COUNT )
+ {
+ var_SetInteger( p_filter, "projectm-preset-id",
(int)p_sys->p_projectm->getPlaylistSize() );
+ return VLC_SUCCESS;
+ }
+ if ( newv.i_int == VLC_PROJECTM_CMD_GET_CURRENT )
+ {
+ unsigned int id;
+ p_sys->p_projectm->selectedPresetIndex( id );
+ var_SetInteger( p_filter, "projectm-preset-id", id );
+ return VLC_SUCCESS;
+ }
+ if ( newv.i_int == VLC_PROJECTM_CMD_GET_NAME )
+ {
+ int id = var_GetInteger( p_filter, "projectm-preset-id" );
+ if ( id >= (int)p_sys->p_projectm->getPlaylistSize() || id < 0
)
+ return VLC_EBADVAR;
+ var_SetString( p_filter, "projectm-preset-name",
p_sys->p_projectm->getPresetName( id ).c_str() );
+ return VLC_SUCCESS;
+ }
+ if ( newv.i_int == VLC_PROJECTM_CMD_IS_LOCKED )
+ {
+ var_SetInteger( p_filter, "projectm-preset-id",
(int)p_sys->p_projectm->isPresetLocked() );
+ return VLC_SUCCESS;
+ }
+ if ( newv.i_int >= (int)p_sys->p_projectm->getPlaylistSize() ||
newv.i_int < VLC_PROJECTM_CMD_IS_LOCKED )
+ return VLC_EBADVAR;
+ // set_preset, random or lock
+ p_sys->i_preset_id = newv.i_int;
+ p_sys->b_changed = true;
+ }
+ return VLC_SUCCESS;
+}
+
+/**
* ProjectM update thread which do the rendering
* @param p_this: the p_thread object
*/
@@ -272,7 +325,6 @@ static void *Thread( void *p_data )
locale_t loc;
locale_t oldloc;
- projectM *p_projectm;
#ifndef HAVE_PROJECTM2
char *psz_config;
#else
@@ -330,7 +382,7 @@ static void *Thread( void *p_data )
/* Create the projectM object */
#ifndef HAVE_PROJECTM2
psz_config = var_InheritString( p_filter, "projectm-config" );
- p_projectm new projectM( psz_config );
+ p_sys->p_projectm = new projectM( psz_config );
free( psz_config );
#else
psz_preset_path = var_InheritString( p_filter, "projectm-preset-path"
);
@@ -352,25 +404,51 @@ static void *Thread( void *p_data )
settings.aspectCorrection = 1;
settings.easterEgg = 1;
settings.shuffleEnabled = 1;
- p_projectm = new projectM( settings );
+ p_sys->p_projectm = new projectM( settings );
free( psz_menu_font );
free( psz_title_font );
free( psz_preset_path );
#endif
- p_sys->i_buffer_size = p_projectm->pcm()->maxsamples;
+ p_sys->i_buffer_size = p_sys->p_projectm->pcm()->maxsamples;
p_sys->p_buffer = (float*)calloc( p_sys->i_buffer_size,
sizeof( float ) );
vlc_sem_post( &p_sys->ready );
/* Choose a preset randomly or projectM will always show the first one
*/
- p_projectm->selectPreset( (unsigned)vlc_mrand48() %
p_projectm->getPlaylistSize() );
+ p_sys->p_projectm->selectPreset( (unsigned)vlc_mrand48() %
p_sys->p_projectm->getPlaylistSize() );
+
+ var_Create( p_filter, "projectm-preset-cmd", VLC_VAR_INTEGER );
+ var_Create( p_filter, "projectm-preset-id", VLC_VAR_INTEGER );
+ var_Create( p_filter, "projectm-preset-name", VLC_VAR_STRING );
+ var_AddCallback( p_filter, "projectm-preset-cmd", ProjectMCallback,
p_filter );
/* */
for( ;; )
{
const mtime_t i_deadline = mdate() + CLOCK_FREQ / 50; /* 50 fps max
*/
+
+ /* Preset change requested */
+ if ( p_sys->b_changed )
+ {
+ switch ( p_sys->i_preset_id )
+ {
+ case VLC_PROJECTM_CMD_RANDOM:
+ p_sys->p_projectm->key_handler( PROJECTM_KEYDOWN,
PROJECTM_K_r, PROJECTM_KMOD_LSHIFT );
+ break;
+ case VLC_PROJECTM_CMD_LOCK:
+ p_sys->p_projectm->setPresetLock(TRUE);
+ break;
+ case VLC_PROJECTM_CMD_UNLOCK:
+ p_sys->p_projectm->setPresetLock(FALSE);
+ break;
+ default: // set preset
+ p_sys->p_projectm->selectPreset( p_sys->i_preset_id );
+ }
+ p_sys->b_changed = false;
+ }
+
/* Manage the events */
vout_ManageDisplay( p_sys->p_vd, true );
if( p_sys->p_vd->cfg->display.width != i_last_width ||
@@ -379,7 +457,7 @@ static void *Thread( void *p_data )
/* FIXME it is not perfect as we will have black bands */
vout_display_place_t place;
vout_display_PlacePicture( &place, &p_sys->p_vd->source,
p_sys->p_vd->cfg, false );
- p_projectm->projectM_resetGL( place.width, place.height );
+ p_sys->p_projectm->projectM_resetGL( place.width, place.height
);
i_last_width = p_sys->p_vd->cfg->display.width;
i_last_height = p_sys->p_vd->cfg->display.height;
@@ -389,15 +467,15 @@ static void *Thread( void *p_data )
vlc_mutex_lock( &p_sys->lock );
if( p_sys->i_nb_samples > 0 )
{
- p_projectm->pcm()->addPCMfloat( p_sys->p_buffer,
- p_sys->i_nb_samples );
+ p_sys->p_projectm->pcm()->addPCMfloat( p_sys->p_buffer,
+ p_sys->i_nb_samples );
p_sys->i_nb_samples = 0;
}
if( p_sys->b_quit )
{
vlc_mutex_unlock( &p_sys->lock );
- delete p_projectm;
+ delete p_sys->p_projectm;
vout_DeleteDisplay( p_sys->p_vd, NULL );
vlc_object_release( p_sys->p_vout );
if (loc != (locale_t)0)
@@ -409,7 +487,7 @@ static void *Thread( void *p_data )
}
vlc_mutex_unlock( &p_sys->lock );
- p_projectm->renderFrame();
+ p_sys->p_projectm->renderFrame();
/* */
mwait( i_deadline );
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20101208/69cd7d1e/attachment.html>
More information about the vlc-devel
mailing list