changeset 597:05bc0456fabb trunk

[svn] - aosd: add missing aosd_trigger* sources
author giacomo
date Thu, 01 Feb 2007 16:46:20 -0800
parents 1708b03e116c
children e83e6fb3ebfa
files ChangeLog src/aosd/aosd_trigger.c src/aosd/aosd_trigger.h src/aosd/aosd_trigger_private.h
diffstat 4 files changed, 326 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Feb 01 16:45:47 2007 -0800
+++ b/ChangeLog	Thu Feb 01 16:46:20 2007 -0800
@@ -1,3 +1,14 @@
+2007-02-02 00:45:47 +0000  Giacomo Lozito <james@develia.org>
+  revision [1278]
+  - aosd: replaced polling with hooks; added trigger options as well, working triggers are playback start and title changes
+  trunk/src/aosd/Makefile   |    4 -
+  trunk/src/aosd/aosd.c     |   57 +------------------------
+  trunk/src/aosd/aosd_cfg.c |   41 ++++++++++++++++++
+  trunk/src/aosd/aosd_cfg.h |    9 ++++
+  trunk/src/aosd/aosd_ui.c  |  102 ++++++++++++++++++++++++++++++++++++++++------
+  5 files changed, 145 insertions(+), 68 deletions(-)
+
+
 2007-02-01 19:12:38 +0000  Michael Farber <01mf02@gmail.com>
   revision [1276]
   - Uncommented some (obviously unneeded?) stuff -> fixed crash
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/aosd/aosd_trigger.c	Thu Feb 01 16:46:20 2007 -0800
@@ -0,0 +1,233 @@
+/*
+*
+* Author: Giacomo Lozito <james@develia.org>, (C) 2005-2007
+*
+* This program is free software; you can redistribute it and/or modify it
+* under the terms of the GNU General Public License as published by the
+* Free Software Foundation; either version 2 of the License, or (at your
+* option) any later version.
+*
+* This program is distributed in the hope that it will be useful, but
+* WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+* General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License along
+* with this program; if not, write to the Free Software Foundation, Inc.,
+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+*
+*/
+
+#include "aosd_trigger.h"
+#include "aosd_trigger_private.h"
+#include "aosd_cfg.h"
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <audacious/playlist.h>
+#include <audacious/strings.h>
+#include <audacious/hook.h>
+
+
+extern aosd_cfg_t * global_config;
+
+
+/* trigger codes ( the code values do not need to be sequential ) */
+enum
+{
+  AOSD_TRIGGER_PB_START = 0,
+  AOSD_TRIGGER_PB_TITLECHANGE = 1
+};
+
+/* trigger codes array size */
+#define AOSD_TRIGGER_CODES_ARRAY_SIZE 2
+
+/* trigger codes array */
+gint aosd_trigger_codes[] =
+{
+  AOSD_TRIGGER_PB_START,
+  AOSD_TRIGGER_PB_TITLECHANGE
+};
+
+/* prototypes of trigger functions */
+static void aosd_trigger_func_pb_start_onoff ( gboolean );
+static void aosd_trigger_func_pb_start_cb ( gpointer , gpointer );
+static void aosd_trigger_func_pb_titlechange_onff ( gboolean );
+static void aosd_trigger_func_pb_titlechange_cb ( gpointer , gpointer );
+
+/* map trigger codes to trigger objects */
+aosd_trigger_t aosd_triggers[] =
+{
+  [AOSD_TRIGGER_PB_START] = { N_("Playback Start") ,
+                              N_("Triggers OSD when a playlist entry is played.") ,
+                              aosd_trigger_func_pb_start_onoff ,
+                              aosd_trigger_func_pb_start_cb },
+
+  [AOSD_TRIGGER_PB_TITLECHANGE] = { N_("Title Change") ,
+                                    N_("Trigger OSD when, during playback, the song title changes "
+                                       "but the filename is the same. This is mostly useful to display "
+                                       "title changes in internet streams.") ,
+                                    aosd_trigger_func_pb_titlechange_onff ,
+                                    aosd_trigger_func_pb_titlechange_cb }
+};
+
+
+
+/* TRIGGER API */
+
+void
+aosd_trigger_get_codes_array ( gint ** array , gint * array_size )
+{
+  *array = aosd_trigger_codes;
+  *array_size = AOSD_TRIGGER_CODES_ARRAY_SIZE;
+  return;
+}
+
+
+const gchar *
+aosd_trigger_get_name ( gint trig_code )
+{
+  return aosd_triggers[trig_code].name;
+}
+
+
+const gchar *
+aosd_trigger_get_desc ( gint trig_code )
+{
+  return aosd_triggers[trig_code].desc;
+}
+
+
+void
+aosd_trigger_start ( aosd_cfg_osd_trigger_t * cfg_trigger )
+{
+  gint i = 0;
+  for ( i = 0 ; i < cfg_trigger->active->len ; i++ )
+  {
+    gint trig_code = g_array_index( cfg_trigger->active , gint , i );
+    aosd_triggers[trig_code].onoff_func( TRUE );
+  }
+  return;
+}
+
+
+void
+aosd_trigger_stop ( aosd_cfg_osd_trigger_t * cfg_trigger )
+{
+  gint i = 0;
+  for ( i = 0 ; i < cfg_trigger->active->len ; i++ )
+  {
+    gint trig_code = g_array_index( cfg_trigger->active , gint , i );
+    aosd_triggers[trig_code].onoff_func( FALSE );
+  }
+  return;
+}
+
+
+/* TRIGGER FUNCTIONS */
+
+static void
+aosd_trigger_func_pb_start_onoff ( gboolean turn_on )
+{
+  if ( turn_on == TRUE )
+    hook_associate( "playback begin" , aosd_trigger_func_pb_start_cb , NULL );
+  else
+    hook_dissociate( "playback begin" , aosd_trigger_func_pb_start_cb );
+  return;
+}
+
+static void
+aosd_trigger_func_pb_start_cb ( gpointer plentry_gp , gpointer unused )
+{
+  PlaylistEntry *pl_entry = plentry_gp;
+  if (( plentry_gp != NULL ) && ( pl_entry->title != NULL ))
+  {
+    gchar *utf8_title = str_to_utf8( pl_entry->title );
+    gchar *utf8_title_markup = g_markup_printf_escaped(
+      "<span font_desc='%s'>%s</span>" , global_config->osd->text.fonts_name[0] , utf8_title );
+    aosd_display( utf8_title_markup , global_config->osd , FALSE );
+    g_free( utf8_title_markup );
+    g_free( utf8_title );
+  }
+  return;
+}
+
+
+
+typedef struct
+{
+  gchar *title;
+  gchar *filename;
+}
+aosd_pb_titlechange_prevs_t;
+
+
+static void
+aosd_trigger_func_pb_titlechange_onff ( gboolean turn_on )
+{
+  static aosd_pb_titlechange_prevs_t *prevs = NULL;
+
+  if ( turn_on == TRUE )
+  {
+    prevs = g_malloc0(sizeof(aosd_pb_titlechange_prevs_t));
+    prevs->title = NULL;
+    prevs->filename = NULL;
+    hook_associate( "playlist set info" , aosd_trigger_func_pb_titlechange_cb , prevs );
+  }
+  else
+  {
+    hook_dissociate( "playlist set info" , aosd_trigger_func_pb_titlechange_cb );
+    if ( prevs != NULL )
+    {
+      if ( prevs->title != NULL ) g_free( prevs->title );
+      if ( prevs->filename != NULL ) g_free( prevs->filename );
+      g_free( prevs );
+      prevs = NULL;
+    }
+  }
+  return;
+}
+
+static void
+aosd_trigger_func_pb_titlechange_cb ( gpointer plentry_gp , gpointer prevs_gp )
+{
+  if ( ip_data.playing )
+  {
+    aosd_pb_titlechange_prevs_t *prevs = prevs_gp;
+    PlaylistEntry *pl_entry = plentry_gp;
+
+    /* same filename but title changed, useful to detect http stream song changes */
+
+    if ( ( prevs->title != NULL ) && ( prevs->filename != NULL ) )
+    {
+      if ( !strcmp(pl_entry->filename,prevs->filename) )
+      {
+        if ( strcmp(pl_entry->title,prevs->title) )
+        {
+          /* string formatting is done here a.t.m. - TODO - improve this area */
+          gchar *utf8_title = str_to_utf8( pl_entry->title );
+          gchar *utf8_title_markup = g_markup_printf_escaped(
+            "<span font_desc='%s'>%s</span>" , global_config->osd->text.fonts_name[0] , utf8_title );
+          aosd_display( utf8_title_markup , global_config->osd , FALSE );
+          g_free( utf8_title_markup );
+          g_free( utf8_title );
+          g_free( prevs->title );
+          prevs->title = g_strdup(pl_entry->title);
+        }
+      }
+      else
+      {
+        g_free(prevs->filename);
+        prevs->filename = g_strdup(pl_entry->filename);
+      }
+    }
+    else
+    {
+      if ( prevs->title != NULL )
+        g_free(prevs->title);
+      prevs->title = g_strdup(pl_entry->title);
+      if ( prevs->filename != NULL )
+        g_free(prevs->filename);
+      prevs->filename = g_strdup(pl_entry->filename);
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/aosd/aosd_trigger.h	Thu Feb 01 16:46:20 2007 -0800
@@ -0,0 +1,37 @@
+/*
+*
+* Author: Giacomo Lozito <james@develia.org>, (C) 2005-2007
+*
+* This program is free software; you can redistribute it and/or modify it
+* under the terms of the GNU General Public License as published by the
+* Free Software Foundation; either version 2 of the License, or (at your
+* option) any later version.
+*
+* This program is distributed in the hope that it will be useful, but
+* WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+* General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License along
+* with this program; if not, write to the Free Software Foundation, Inc.,
+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+*
+*/
+
+#ifndef _I_AOSD_TRIGGER_H
+#define _I_AOSD_TRIGGER_H 1
+
+#include "aosd_common.h"
+#include "aosd_cfg.h"
+#include <glib.h>
+
+
+/* trigger public API */
+void aosd_trigger_get_codes_array ( gint ** , gint * );
+const gchar * aosd_trigger_get_name ( gint );
+const gchar * aosd_trigger_get_desc ( gint );
+void aosd_trigger_start ( aosd_cfg_osd_trigger_t * cfg_trigger );
+void aosd_trigger_stop ( aosd_cfg_osd_trigger_t * cfg_trigger );
+
+
+#endif /* !_I_AOSD_TRIGGER_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/aosd/aosd_trigger_private.h	Thu Feb 01 16:46:20 2007 -0800
@@ -0,0 +1,45 @@
+/*
+*
+* Author: Giacomo Lozito <james@develia.org>, (C) 2005-2007
+*
+* This program is free software; you can redistribute it and/or modify it
+* under the terms of the GNU General Public License as published by the
+* Free Software Foundation; either version 2 of the License, or (at your
+* option) any later version.
+*
+* This program is distributed in the hope that it will be useful, but
+* WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+* General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License along
+* with this program; if not, write to the Free Software Foundation, Inc.,
+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+*
+*/
+
+#ifndef _I_AOSD_TRIGGER_PRIVATE_H
+#define _I_AOSD_TRIGGER_PRIVATE_H 1
+
+#include "aosd_common.h"
+#include <glib.h>
+
+
+/* trigger object
+   ----------------------------------------------------------
+   name           name
+   desc           description
+   onoff_func     function used to enable/disable the trigger
+   callback_func  function called by triggering event
+*/
+typedef struct
+{
+  const gchar * name;
+  const gchar * desc;
+  void (*onoff_func)( gboolean );
+  void (*callback_func)( gpointer , gpointer );
+}
+aosd_trigger_t;
+
+
+#endif /* !_I_AOSD_TRIGGER_PRIVATE_H */