changeset 437:e1c6b223431e trunk

[svn] - amidiplug: on midi backend init, pass a function that helps the backend to get the location of amidi-plug.conf
author giacomo
date Mon, 15 Jan 2007 13:25:41 -0800
parents a668576342e0
children 4fec4a3ca1a4
files ChangeLog src/amidi-plug/Makefile src/amidi-plug/backend-alsa/b-alsa.c src/amidi-plug/backend-alsa/b-alsa.h src/amidi-plug/backend-dummy/b-dummy.c src/amidi-plug/backend-dummy/b-dummy.h src/amidi-plug/backend-fluidsynth/b-fluidsynth.c src/amidi-plug/backend-fluidsynth/b-fluidsynth.h src/amidi-plug/i_backend.c src/amidi-plug/i_backend.h src/amidi-plug/i_configure.c src/amidi-plug/i_configure_file.h
diffstat 12 files changed, 74 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Jan 15 12:46:38 2007 -0800
+++ b/ChangeLog	Mon Jan 15 13:25:41 2007 -0800
@@ -1,3 +1,10 @@
+2007-01-15 20:46:38 +0000  Giacomo Lozito <james@develia.org>
+  revision [956]
+  - make amidi-plug use audacious_get_localdir()
+  trunk/src/amidi-plug/i_configure.c |   24 ++++++++++++++++--------
+  1 file changed, 16 insertions(+), 8 deletions(-)
+
+
 2007-01-15 20:38:45 +0000  Giacomo Lozito <james@develia.org>
   revision [954]
   - added audacious_get_localdir() in util.c/h, returns a string with the full path of audacious local datadir
--- a/src/amidi-plug/Makefile	Mon Jan 15 12:46:38 2007 -0800
+++ b/src/amidi-plug/Makefile	Mon Jan 15 13:25:41 2007 -0800
@@ -6,7 +6,7 @@
 
 noinst_HEADERS = amidi-plug.h i_backend.h i_midi.h i_midievent.h \
                  i_vfslayer.h i_configure.h i_configure_private.h \
-                 i_configure-ap.h i_configure-alsa.h \
+                 i_configure_file.h i_configure-ap.h i_configure-alsa.h \
                  i_configure-fluidsynth.h i_configure-dummy.h \
                  i_fileinfo.h i_utils.h i_common.h \
                  amidi-plug-icon.xpm amidi-plug.logo.xpm \
--- a/src/amidi-plug/backend-alsa/b-alsa.c	Mon Jan 15 12:46:38 2007 -0800
+++ b/src/amidi-plug/backend-alsa/b-alsa.c	Mon Jan 15 13:25:41 2007 -0800
@@ -49,10 +49,10 @@
 }
 
 
-gint backend_init( void )
+gint backend_init( i_cfg_get_file_cb callback )
 {
   /* read configuration options */
-  i_cfg_read();
+  i_cfg_read( callback );
 
   sc.seq = NULL;
   sc.client_port = 0;
@@ -833,11 +833,10 @@
 }
 
 
-void i_cfg_read( void )
+void i_cfg_read( i_cfg_get_file_cb callback )
 {
   pcfg_t *cfgfile;
-  gchar * config_pathfilename = g_strjoin( "" , g_get_home_dir() , "/" ,
-                                           PLAYER_LOCALRCDIR , "/amidi-plug.conf" , NULL );
+  gchar * config_pathfilename = callback();
   cfgfile = i_pcfg_new_from_file( config_pathfilename );
 
   if ( !cfgfile )
--- a/src/amidi-plug/backend-alsa/b-alsa.h	Mon Jan 15 12:46:38 2007 -0800
+++ b/src/amidi-plug/backend-alsa/b-alsa.h	Mon Jan 15 13:25:41 2007 -0800
@@ -23,6 +23,7 @@
 
 #include <alsa/asoundlib.h>
 #include "../i_common.h"
+#include "../i_configure_file.h"
 #include "../pcfg/i_pcfg.h"
 #include "../i_midievent.h"
 
@@ -56,7 +57,7 @@
 GSList * i_seq_mixctl_get_list( gint );
 void i_seq_mixctl_free_list( GSList * );
 gint i_seq_mixer_find_selem( snd_mixer_t * , gchar * , gchar * , gint , snd_mixer_elem_t ** );
-void i_cfg_read( void );
+void i_cfg_read( i_cfg_get_file_cb );
 void i_cfg_free( void );
 gint i_util_str_count( gchar * , gchar );
 
--- a/src/amidi-plug/backend-dummy/b-dummy.c	Mon Jan 15 12:46:38 2007 -0800
+++ b/src/amidi-plug/backend-dummy/b-dummy.c	Mon Jan 15 13:25:41 2007 -0800
@@ -44,9 +44,9 @@
 }
 
 
-gint backend_init( void )
+gint backend_init( i_cfg_get_file_cb callback )
 {
-  i_cfg_read(); /* read configuration options */
+  i_cfg_read( callback ); /* read configuration options */
 
   return 1;
 }
@@ -346,13 +346,12 @@
 }
 
 
-void i_cfg_read( void )
+void i_cfg_read( i_cfg_get_file_cb callback )
 {
   pcfg_t *cfgfile;
   gchar * def_logfile = g_strjoin( "" , g_get_home_dir() , "/amidi-plug.log" , NULL );
   gchar * def_logdir = (gchar*)g_get_home_dir();
-  gchar * config_pathfilename = g_strjoin( "" , g_get_home_dir() , "/" ,
-                                           PLAYER_LOCALRCDIR , "/amidi-plug.conf" , NULL );
+  gchar * config_pathfilename = callback();
   cfgfile = i_pcfg_new_from_file( config_pathfilename );
 
   if ( !cfgfile )
--- a/src/amidi-plug/backend-dummy/b-dummy.h	Mon Jan 15 12:46:38 2007 -0800
+++ b/src/amidi-plug/backend-dummy/b-dummy.h	Mon Jan 15 13:25:41 2007 -0800
@@ -23,6 +23,7 @@
 
 
 #include "../i_common.h"
+#include "../i_configure_file.h"
 #include <glib/gprintf.h>
 #include "../pcfg/i_pcfg.h"
 #include "../i_midievent.h"
@@ -43,7 +44,7 @@
 
 void i_sleep( guint );
 void i_printf( FILE * , const gchar * , ... );
-void i_cfg_read( void );
+void i_cfg_read( i_cfg_get_file_cb );
 void i_cfg_free( void );
 
 #endif /* !_B_DUMMY_H */
--- a/src/amidi-plug/backend-fluidsynth/b-fluidsynth.c	Mon Jan 15 12:46:38 2007 -0800
+++ b/src/amidi-plug/backend-fluidsynth/b-fluidsynth.c	Mon Jan 15 13:25:41 2007 -0800
@@ -46,10 +46,10 @@
 }
 
 
-gint backend_init( void )
+gint backend_init( i_cfg_get_file_cb callback )
 {
   /* read configuration options */
-  i_cfg_read();
+  i_cfg_read( callback );
 
   sc.soundfont_ids = g_array_new( FALSE , FALSE , sizeof(gint) );
   sc.sample_rate = amidiplug_cfg_fsyn.fsyn_synth_samplerate;
@@ -391,11 +391,10 @@
 }
 
 
-void i_cfg_read( void )
+void i_cfg_read( i_cfg_get_file_cb callback )
 {
   pcfg_t *cfgfile;
-  gchar * config_pathfilename = g_strjoin( "" , g_get_home_dir() , "/" ,
-                                           PLAYER_LOCALRCDIR , "/amidi-plug.conf" , NULL );
+  gchar * config_pathfilename = callback();
   cfgfile = i_pcfg_new_from_file( config_pathfilename );
 
   if ( !cfgfile )
--- a/src/amidi-plug/backend-fluidsynth/b-fluidsynth.h	Mon Jan 15 12:46:38 2007 -0800
+++ b/src/amidi-plug/backend-fluidsynth/b-fluidsynth.h	Mon Jan 15 13:25:41 2007 -0800
@@ -24,6 +24,7 @@
 #include <fluidsynth.h>
 #include <math.h>
 #include "../i_common.h"
+#include "../i_configure_file.h"
 #include "../pcfg/i_pcfg.h"
 #include "../i_midievent.h"
 
@@ -50,7 +51,7 @@
 
 void i_sleep( guint );
 void i_soundfont_load( void );
-void i_cfg_read( void );
+void i_cfg_read( i_cfg_get_file_cb );
 void i_cfg_free( void );
 
 #endif /* !_B_FLUIDSYNTH_H */
--- a/src/amidi-plug/i_backend.c	Mon Jan 15 12:46:38 2007 -0800
+++ b/src/amidi-plug/i_backend.c	Mon Jan 15 13:25:41 2007 -0800
@@ -49,7 +49,7 @@
         gchar * module_pathfilename = g_strjoin( "" , AMIDIPLUGBACKENDDIR , "/" ,
                                                  backend_directory_entry , NULL );
         /* seems to be a backend for amidi-plug , try to load it */
-        module = g_module_open( module_pathfilename , 0 );
+        module = g_module_open( module_pathfilename , G_MODULE_BIND_LOCAL );
         if ( module == NULL )
           g_warning( "Error loading module %s - %s\n" , module_pathfilename , g_module_error() );
         else
@@ -141,7 +141,7 @@
     getapmoduleinfo( &backend.name , NULL , NULL , NULL );
     backend.autonomous_audio = checkautonomousaudio();
     DEBUGMSG( "backend %s (name '%s') successfully loaded\n" , module_pathfilename , backend.name );
-    backend.init();
+    backend.init( i_configure_cfg_get_file );
     g_free( module_pathfilename );
     return 1;
   }
--- a/src/amidi-plug/i_backend.h	Mon Jan 15 12:46:38 2007 -0800
+++ b/src/amidi-plug/i_backend.h	Mon Jan 15 13:25:41 2007 -0800
@@ -23,6 +23,7 @@
 
 #include <gmodule.h>
 #include "i_midievent.h"
+#include "i_configure_file.h"
 #include "i_common.h"
 
 
@@ -42,7 +43,7 @@
   gint id;
   GModule * gmodule;
   gchar * name;
-  gint (*init)( void );
+  gint (*init)( i_cfg_get_file_cb );
   gint (*cleanup)( void );
   gint (*audio_info_get)( gint * , gint * , gint * );
   gint (*audio_volume_get)( gint * , gint * );
--- a/src/amidi-plug/i_configure.c	Mon Jan 15 12:46:38 2007 -0800
+++ b/src/amidi-plug/i_configure.c	Mon Jan 15 13:25:41 2007 -0800
@@ -21,6 +21,7 @@
 
 #include "i_configure.h"
 #include "i_configure_private.h"
+#include "i_configure_file.h"
 #include "i_backend.h"
 #include "i_configure-ap.h"
 #include "i_configure-alsa.h"
@@ -272,7 +273,7 @@
     {
       DEBUGMSG( "the selected backend is already loaded, so just perform backend cleanup and reinit\n" );
       backend.cleanup();
-      backend.init();
+      backend.init( i_configure_cfg_get_file );
     }
   }
 
@@ -311,10 +312,8 @@
 void i_configure_cfg_backend_read( void )
 {
   pcfg_t *cfgfile;
-  gchar * config_datadir = (gchar*)audacious_get_localdir();
-  gchar * config_pathfilename = g_build_filename( config_datadir , "amidi-plug.conf" , NULL );
+  gchar *config_pathfilename = i_configure_cfg_get_file();
 
-  g_free( config_datadir );
   cfgfile = i_pcfg_new_from_file( config_pathfilename );
 
   i_configure_cfg_alsa_read( cfgfile ); /* get alsa backend configuration */
@@ -331,10 +330,8 @@
 void i_configure_cfg_backend_save( void )
 {
   pcfg_t *cfgfile;
-  gchar * config_datadir = (gchar*)audacious_get_localdir();
-  gchar * config_pathfilename = g_build_filename( config_datadir , "amidi-plug.conf" , NULL );
+  gchar *config_pathfilename = i_configure_cfg_get_file();
 
-  g_free( config_datadir );
   cfgfile = i_pcfg_new_from_file( config_pathfilename );
 
   if (!cfgfile)
@@ -354,10 +351,8 @@
 void i_configure_cfg_ap_read( void )
 {
   pcfg_t *cfgfile;
-  gchar * config_datadir = (gchar*)audacious_get_localdir();
-  gchar * config_pathfilename = g_build_filename( config_datadir , "amidi-plug.conf" , NULL );
+  gchar *config_pathfilename = i_configure_cfg_get_file();
 
-  g_free( config_datadir );
   cfgfile = i_pcfg_new_from_file( config_pathfilename );
 
   if (!cfgfile)
@@ -394,10 +389,7 @@
 void i_configure_cfg_ap_save( void )
 {
   pcfg_t *cfgfile;
-  gchar * config_datadir = (gchar*)audacious_get_localdir();
-  gchar * config_pathfilename = g_build_filename( config_datadir , "amidi-plug.conf" , NULL );
-
-  g_free( config_datadir );
+  gchar *config_pathfilename = i_configure_cfg_get_file();
   cfgfile = i_pcfg_new_from_file( config_pathfilename );
 
   if (!cfgfile)
@@ -421,3 +413,12 @@
   i_pcfg_free( cfgfile );
   g_free( config_pathfilename );
 }
+
+
+gchar * i_configure_cfg_get_file( void )
+{
+  gchar * config_datadir = (gchar*)audacious_get_localdir();
+  gchar * config_pathfilename = g_build_filename( config_datadir , "amidi-plug.conf" , NULL );
+  g_free( config_datadir );
+  return config_pathfilename;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/amidi-plug/i_configure_file.h	Mon Jan 15 13:25:41 2007 -0800
@@ -0,0 +1,29 @@
+/*
+*
+* Author: Giacomo Lozito <james@develia.org>, (C) 2005-2006
+*
+* 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_CONFIGURE_FILE_H
+#define _I_CONFIGURE_FILE_H 1
+
+#include <glib.h>
+
+typedef gchar * (*i_cfg_get_file_cb)( void );
+gchar * i_configure_cfg_get_file( void );
+
+#endif /* !_I_CONFIGURE_FILE_H */