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