[vlc-devel] [PATCH 1/2] New ProjectM API (libvlc)

XilasZ xilasz at gmail.com
Wed Dec 8 23:37:15 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/include/vlc/libvlc_media_player.h
b/include/vlc/libvlc_media_player.h
index 8ac784a..c592028 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -1391,6 +1391,69 @@ VLC_PUBLIC_API int64_t libvlc_audio_get_delay(
libvlc_media_player_t *p_mi );
  */
 VLC_PUBLIC_API int libvlc_audio_set_delay( libvlc_media_player_t *p_mi,
int64_t i_delay );

+/**
+ * Set a random projectm preset
+ *
+ * \param p_mi media player
+ * \version LibVLC 1.1.6 or later
+ */
+VLC_PUBLIC_API void libvlc_projectm_random( libvlc_media_player_t *p_mi );
+
+/**
+ * Set a projectm preset
+ *
+ * \param p_mi media player
+ * \param i_id preset id
+ * \version LibVLC 1.1.6 or later
+ */
+VLC_PUBLIC_API void libvlc_projectm_set_preset( libvlc_media_player_t
*p_mi, int i_id );
+
+/**
+ * Get projectm preset count
+ *
+ * \param p_mi media player
+ * \return number of presets loaded by projectm
+ * \version LibVLC 1.1.6 or later
+ */
+VLC_PUBLIC_API  int libvlc_projectm_get_preset_count( libvlc_media_player_t
*p_mi );
+
+/**
+ * Get the current preset id
+ *
+ * \param p_mi media player
+ * \return current preset id
+ * \version LibVLC 1.1.6 or later
+ */
+VLC_PUBLIC_API  int libvlc_projectm_get_preset_current_id(
libvlc_media_player_t *p_mi );
+
+/**
+ * Get the name of a preset
+ *
+ * \param p_mi media player
+ * \param i_id preset id
+ * \return name of the preset
+ * \version LibVLC 1.1.6 or later
+ */
+VLC_PUBLIC_API char *libvlc_projectm_get_preset_name( libvlc_media_player_t
*p_mi, int i_id );
+
+/**
+ * Get whether projectm is locked or not
+ *
+ * \param p_mi media player
+ * \return the lock status (boolean)
+ * \version LibVLC 1.1.6 or later
+ */
+VLC_PUBLIC_API  int libvlc_projectm_is_locked( libvlc_media_player_t *p_mi
);
+
+/**
+ * Lock/Unlock projectm on the current preset
+ *
+ * \param p_mi media player
+ * \param b_locked boolean for the lock status
+ * \version LibVLC 1.1.6 or later
+ */
+VLC_PUBLIC_API void libvlc_projectm_lock( libvlc_media_player_t *p_mi, int
b_locked );
+
 /** @} audio */

 /** @} media_player */
diff --git a/include/vlc_common.h b/include/vlc_common.h
index 3e9de44..909e82e 100644
--- a/include/vlc_common.h
+++ b/include/vlc_common.h
@@ -882,4 +882,15 @@ VLC_EXPORT( const char *, VLC_Compiler, ( void )
LIBVLC_USED );
     "Public License;\nsee the file named COPYING for details.\n" \
     "Written by the VideoLAN team; see the AUTHORS file.\n")

+/*****************************************************************************
+ * ProjectM stuff
+
*****************************************************************************/
+#define VLC_PROJECTM_CMD_RANDOM      -1
+#define VLC_PROJECTM_CMD_LOCK        -2
+#define VLC_PROJECTM_CMD_UNLOCK      -3
+#define VLC_PROJECTM_CMD_IS_LOCKED   -4
+#define VLC_PROJECTM_CMD_GET_COUNT   -5
+#define VLC_PROJECTM_CMD_GET_CURRENT -6
+#define VLC_PROJECTM_CMD_GET_NAME    -7
+
 #endif /* !VLC_COMMON_H */
diff --git a/src/control/audio.c b/src/control/audio.c
index a6e7888..9099083 100644
--- a/src/control/audio.c
+++ b/src/control/audio.c
@@ -515,3 +515,136 @@ int libvlc_audio_set_delay( libvlc_media_player_t
*p_mi, int64_t i_delay )
     }
     return ret;
 }
+
+/*****************************************************************************
+ * get_projectm : Find and return projectm object
+
*****************************************************************************/
+static vlc_object_t *get_projectm( libvlc_media_player_t *p_mi )
+{
+    aout_instance_t *p_aout = GetAOut( p_mi );
+    vlc_object_t *p_projectm = NULL;
+    if( !p_aout )
+        return NULL;
+
+    p_projectm = vlc_object_find_name( p_aout, "projectm", FIND_CHILD );
+    vlc_object_release( p_aout );
+    if (!p_projectm)
+    {
+        libvlc_printerr( "projectm not enabled" );
+    }
+    return p_projectm;
+}
+
+/*****************************************************************************
+ * send_projectm_cmd : Find projectm, send a command, and return the object
+
*****************************************************************************/
+static vlc_object_t *send_projectm_cmd( libvlc_media_player_t *p_mi, int
i_cmd )
+{
+    vlc_object_t *p_projectm = get_projectm( p_mi );
+    if ( !p_projectm )
+        return NULL;
+
+    if( var_SetInteger( p_projectm, "projectm-preset-cmd", i_cmd ) < 0 )
+    {
+        libvlc_printerr( "projectm-preset-cmd out of range" );
+    }
+    return p_projectm;
+}
+
+/*****************************************************************************
+ * libvlc_projectm_random : Set a random projectm preset
+
*****************************************************************************/
+void libvlc_projectm_random( libvlc_media_player_t *p_mi )
+{
+    vlc_object_t *p_projectm = send_projectm_cmd( p_mi,
VLC_PROJECTM_CMD_RANDOM );
+    if ( p_projectm )
+        vlc_object_release( p_projectm );
+}
+
+/*****************************************************************************
+ * libvlc_projectm_set_preset : Set a projectm preset
+
*****************************************************************************/
+void libvlc_projectm_set_preset( libvlc_media_player_t *p_mi, int i_id )
+{
+    vlc_object_t *p_projectm = send_projectm_cmd( p_mi, i_id );
+    if ( p_projectm )
+        vlc_object_release( p_projectm );
+}
+
+/*****************************************************************************
+ * libvlc_projectm_get_preset_count : Get projectm preset count
+
*****************************************************************************/
+int libvlc_projectm_get_preset_count( libvlc_media_player_t *p_mi )
+{
+    int count = 0;
+    vlc_object_t *p_projectm = send_projectm_cmd( p_mi,
VLC_PROJECTM_CMD_GET_COUNT );
+    if ( !p_projectm )
+        return count;
+
+    count = var_GetInteger( p_projectm, "projectm-preset-id" );
+    vlc_object_release( p_projectm );
+    return count;
+}
+
+/*****************************************************************************
+ * libvlc_projectm_get_preset_current_id : Get the current preset id
+
*****************************************************************************/
+int libvlc_projectm_get_preset_current_id( libvlc_media_player_t *p_mi )
+{
+    int id = 0;
+    vlc_object_t *p_projectm = send_projectm_cmd( p_mi,
VLC_PROJECTM_CMD_GET_CURRENT );
+    if ( !p_projectm )
+        return id;
+
+    id = var_GetInteger( p_projectm, "projectm-preset-id" );
+    vlc_object_release( p_projectm );
+    return id;
+}
+
+/*****************************************************************************
+ * libvlc_projectm_get_preset_name : Get the name of a preset
+
*****************************************************************************/
+char *libvlc_projectm_get_preset_name( libvlc_media_player_t *p_mi, int
i_id )
+{
+    char *name = NULL;
+    vlc_object_t *p_projectm = get_projectm( p_mi );
+    if ( !p_projectm )
+        return name;
+
+    if( var_SetInteger( p_projectm, "projectm-preset-id", i_id ) < 0 )
+    {
+        libvlc_printerr( "projectm-preset-id out of range" );
+    }
+    else
+    {
+        var_SetInteger( p_projectm, "projectm-preset-cmd",
VLC_PROJECTM_CMD_GET_NAME );
+        name = var_GetString( p_projectm, "projectm-preset-name" );
+    }
+    vlc_object_release( p_projectm );
+    return strdup(name);
+}
+
+/*****************************************************************************
+ * libvlc_projectm_is_locked : Get whether projectm is locked or not
+
*****************************************************************************/
+int libvlc_projectm_is_locked( libvlc_media_player_t *p_mi )
+{
+    int id = 0;
+    vlc_object_t *p_projectm = send_projectm_cmd( p_mi,
VLC_PROJECTM_CMD_IS_LOCKED );
+    if ( !p_projectm )
+        return id;
+
+    id = var_GetInteger( p_projectm, "projectm-preset-id" );
+    vlc_object_release( p_projectm );
+    return id;
+}
+
+/*****************************************************************************
+ * libvlc_projectm_lock : Lock/Unlock projectm on the current preset
+
*****************************************************************************/
+void libvlc_projectm_lock( libvlc_media_player_t *p_mi, int b_locked )
+{
+    vlc_object_t *p_projectm = send_projectm_cmd( p_mi, b_locked ?
VLC_PROJECTM_CMD_LOCK : VLC_PROJECTM_CMD_UNLOCK );
+    if ( p_projectm )
+        vlc_object_release( p_projectm );
+}
diff --git a/src/libvlc.sym b/src/libvlc.sym
index 1a401d1..5ce0a46 100644
--- a/src/libvlc.sym
+++ b/src/libvlc.sym
@@ -162,6 +162,13 @@ libvlc_media_subitems
 libvlc_new
 libvlc_new_with_builtins
 libvlc_playlist_play
+libvlc_projectm_get_preset_count
+libvlc_projectm_get_preset_current_id
+libvlc_projectm_get_preset_name
+libvlc_projectm_set_preset
+libvlc_projectm_random
+libvlc_projectm_is_locked
+libvlc_projectm_lock
 libvlc_release
 libvlc_retain
 libvlc_set_fullscreen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20101208/c263557d/attachment.html>


More information about the vlc-devel mailing list