Mercurial > audlegacy-plugins
comparison src/Input/amidi-plug/i_backend.c @ 0:13389e613d67 trunk
[svn] - initial import of audacious-plugins tree (lots to do)
author | nenolod |
---|---|
date | Mon, 18 Sep 2006 01:11:49 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13389e613d67 |
---|---|
1 /* | |
2 * | |
3 * Author: Giacomo Lozito <james@develia.org>, (C) 2005-2006 | |
4 * | |
5 * This program is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License as published by the | |
7 * Free Software Foundation; either version 2 of the License, or (at your | |
8 * option) any later version. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, but | |
11 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU General Public License along | |
16 * with this program; if not, write to the Free Software Foundation, Inc., | |
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
18 * | |
19 */ | |
20 | |
21 #include "i_backend.h" | |
22 | |
23 gboolean i_str_has_pref_and_suff( const gchar *str , gchar *pref , gchar *suff ) | |
24 { | |
25 if ( (g_str_has_prefix( str , pref )) && | |
26 (g_str_has_suffix( str , suff )) ) | |
27 return TRUE; | |
28 else | |
29 return FALSE; | |
30 } | |
31 | |
32 GSList * i_backend_list_lookup( void ) | |
33 { | |
34 GDir * backend_directory; | |
35 GSList * backend_list = NULL; | |
36 | |
37 backend_directory = g_dir_open( AMIDIPLUGBACKENDDIR , 0 , NULL ); | |
38 if ( backend_directory != NULL ) | |
39 { | |
40 const gchar * backend_directory_entry = g_dir_read_name( backend_directory ); | |
41 while ( backend_directory_entry != NULL ) | |
42 { | |
43 /* simple filename checking */ | |
44 if ( i_str_has_pref_and_suff( backend_directory_entry , "ap-" , ".so" ) == TRUE ) | |
45 { | |
46 GModule * module; | |
47 gchar * (*getapmoduleinfo)( gchar ** , gchar ** , gchar ** , gint * ); | |
48 gchar * module_pathfilename = g_strjoin( "" , AMIDIPLUGBACKENDDIR , "/" , | |
49 backend_directory_entry , NULL ); | |
50 /* seems to be a backend for amidi-plug , try to load it */ | |
51 module = g_module_open( module_pathfilename , 0 ); | |
52 if ( module == NULL ) | |
53 g_warning( "Error loading module %s - %s\n" , module_pathfilename , g_module_error() ); | |
54 else | |
55 { | |
56 /* try to get the module name */ | |
57 if ( g_module_symbol( module , "backend_info_get" , (gpointer*)&getapmoduleinfo ) ) | |
58 { | |
59 /* module name found, ok! add its name and filename to the list */ | |
60 amidiplug_sequencer_backend_name_t * mn = g_malloc(sizeof(amidiplug_sequencer_backend_name_t)); | |
61 /* name and desc dinamically allocated */ | |
62 getapmoduleinfo( &mn->name , &mn->longname , &mn->desc , &mn->ppos ); | |
63 mn->filename = g_strdup(module_pathfilename); /* dinamically allocated */ | |
64 DEBUGMSG( "Backend found and added in list, filename: %s and lname: %s\n" , | |
65 mn->filename, mn->longname ); | |
66 backend_list = g_slist_append( backend_list , mn ); | |
67 } | |
68 else | |
69 { | |
70 /* module name not found, this is not a backend for amidi-plug */ | |
71 g_warning( "File %s is not a backend for amidi-plug!\n" , module_pathfilename ); | |
72 } | |
73 g_module_close( module ); | |
74 } | |
75 } | |
76 backend_directory_entry = g_dir_read_name( backend_directory ); | |
77 } | |
78 g_dir_close( backend_directory ); | |
79 } | |
80 else | |
81 g_warning( "Unable to open the backend directory %s\n" , AMIDIPLUGBACKENDDIR ); | |
82 | |
83 return backend_list; | |
84 } | |
85 | |
86 | |
87 void i_backend_list_free( GSList * backend_list ) | |
88 { | |
89 while ( backend_list != NULL ) | |
90 { | |
91 amidiplug_sequencer_backend_name_t * mn = backend_list->data; | |
92 g_free( mn->desc ); | |
93 g_free( mn->name ); | |
94 g_free( mn->longname ); | |
95 g_free( mn->filename ); | |
96 g_free( mn ); | |
97 backend_list = backend_list->next; | |
98 } | |
99 return; | |
100 } | |
101 | |
102 | |
103 gint i_backend_load( gchar * module_name ) | |
104 { | |
105 gchar * module_pathfilename = g_strjoin( "" , AMIDIPLUGBACKENDDIR , "/ap-" , module_name , ".so" , NULL ); | |
106 DEBUGMSG( "loading backend '%s'\n" , module_pathfilename ); | |
107 backend.gmodule = g_module_open( module_pathfilename , 0 ); | |
108 | |
109 if ( backend.gmodule != NULL ) | |
110 { | |
111 gchar * (*getapmoduleinfo)( gchar ** , gchar ** , gchar ** , gint * ); | |
112 gboolean (*checkautonomousaudio)( void ); | |
113 g_module_symbol( backend.gmodule , "backend_init" , (gpointer *)&backend.init ); | |
114 g_module_symbol( backend.gmodule , "backend_cleanup" , (gpointer *)&backend.cleanup ); | |
115 g_module_symbol( backend.gmodule , "audio_info_get" , (gpointer*)&backend.audio_info_get ); | |
116 g_module_symbol( backend.gmodule , "audio_volume_get" , (gpointer *)&backend.audio_volume_get ); | |
117 g_module_symbol( backend.gmodule , "audio_volume_set" , (gpointer *)&backend.audio_volume_set ); | |
118 g_module_symbol( backend.gmodule , "sequencer_start" , (gpointer *)&backend.seq_start ); | |
119 g_module_symbol( backend.gmodule , "sequencer_stop" , (gpointer *)&backend.seq_stop ); | |
120 g_module_symbol( backend.gmodule , "sequencer_on" , (gpointer *)&backend.seq_on ); | |
121 g_module_symbol( backend.gmodule , "sequencer_off" , (gpointer *)&backend.seq_off ); | |
122 g_module_symbol( backend.gmodule , "sequencer_queue_tempo" , (gpointer *)&backend.seq_queue_tempo ); | |
123 g_module_symbol( backend.gmodule , "sequencer_queue_start" , (gpointer *)&backend.seq_queue_start ); | |
124 g_module_symbol( backend.gmodule , "sequencer_event_init" , (gpointer *)&backend.seq_event_init ); | |
125 g_module_symbol( backend.gmodule , "sequencer_event_noteon" , (gpointer *)&backend.seq_event_noteon ); | |
126 g_module_symbol( backend.gmodule , "sequencer_event_noteoff" , (gpointer *)&backend.seq_event_noteoff ); | |
127 g_module_symbol( backend.gmodule , "sequencer_event_keypress" , (gpointer *)&backend.seq_event_keypress ); | |
128 g_module_symbol( backend.gmodule , "sequencer_event_controller" , (gpointer *)&backend.seq_event_controller ); | |
129 g_module_symbol( backend.gmodule , "sequencer_event_pgmchange" , (gpointer *)&backend.seq_event_pgmchange ); | |
130 g_module_symbol( backend.gmodule , "sequencer_event_chanpress" , (gpointer *)&backend.seq_event_chanpress ); | |
131 g_module_symbol( backend.gmodule , "sequencer_event_pitchbend" , (gpointer *)&backend.seq_event_pitchbend ); | |
132 g_module_symbol( backend.gmodule , "sequencer_event_sysex" , (gpointer *)&backend.seq_event_sysex ); | |
133 g_module_symbol( backend.gmodule , "sequencer_event_tempo" , (gpointer *)&backend.seq_event_tempo ); | |
134 g_module_symbol( backend.gmodule , "sequencer_event_other" , (gpointer *)&backend.seq_event_other ); | |
135 g_module_symbol( backend.gmodule , "sequencer_output" , (gpointer *)&backend.seq_output ); | |
136 g_module_symbol( backend.gmodule , "sequencer_output_shut" , (gpointer *)&backend.seq_output_shut ); | |
137 g_module_symbol( backend.gmodule , "sequencer_get_port_count" , (gpointer *)&backend.seq_get_port_count ); | |
138 g_module_symbol( backend.gmodule , "backend_info_get" , (gpointer*)&getapmoduleinfo ); | |
139 g_module_symbol( backend.gmodule , "audio_check_autonomous" , (gpointer*)&checkautonomousaudio ); | |
140 getapmoduleinfo( &backend.name , NULL , NULL , NULL ); | |
141 backend.autonomous_audio = checkautonomousaudio(); | |
142 DEBUGMSG( "backend %s (name '%s') successfully loaded\n" , module_pathfilename , backend.name ); | |
143 backend.init(); | |
144 g_free( module_pathfilename ); | |
145 return 1; | |
146 } | |
147 else | |
148 { | |
149 backend.name = NULL; | |
150 g_warning( "unable to load backend '%s'\n" , module_pathfilename ); | |
151 g_free( module_pathfilename ); | |
152 return 0; | |
153 } | |
154 } | |
155 | |
156 | |
157 gint i_backend_unload( void ) | |
158 { | |
159 if ( backend.gmodule != NULL ) | |
160 { | |
161 DEBUGMSG( "unloading backend '%s'\n" , backend.name ); | |
162 backend.cleanup(); | |
163 g_module_close( backend.gmodule ); | |
164 DEBUGMSG( "backend '%s' unloaded\n" , backend.name ); | |
165 g_free( backend.name ); | |
166 backend.gmodule = NULL; | |
167 return 1; | |
168 } | |
169 else | |
170 { | |
171 g_warning( "attempting to unload backend, but no backend is loaded\n" ); | |
172 return 0; | |
173 } | |
174 } |