Mercurial > audlegacy-plugins
comparison src/amidi-plug/i_configure.c @ 12:3da1b8942b8b trunk
[svn] - remove src/Input src/Output src/Effect src/General src/Visualization src/Container
author | nenolod |
---|---|
date | Mon, 18 Sep 2006 03:14:20 -0700 |
parents | src/Input/amidi-plug/i_configure.c@088092a52fea |
children | 59d793da5395 |
comparison
equal
deleted
inserted
replaced
11:cff1d04026ae | 12:3da1b8942b8b |
---|---|
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 | |
22 #include "i_configure.h" | |
23 #include "i_configure_private.h" | |
24 #include "i_backend.h" | |
25 #include "i_configure-ap.h" | |
26 #include "i_configure-alsa.h" | |
27 #include "i_configure-fluidsynth.h" | |
28 #include "i_configure-dummy.h" | |
29 #include "i_utils.h" | |
30 #include "audacious/beepctrl.h" | |
31 | |
32 | |
33 amidiplug_cfg_backend_t * amidiplug_cfg_backend; | |
34 | |
35 | |
36 void i_configure_ev_bcancel( gpointer ); | |
37 void i_configure_ev_bapply( GtkWidget * , gpointer ); | |
38 void i_configure_ev_bokcheck( GtkWidget * , gpointer ); | |
39 void i_configure_ev_bok( GtkWidget * , gpointer ); | |
40 void i_configure_cfg_backend_alloc( void ); | |
41 void i_configure_cfg_backend_free( void ); | |
42 void i_configure_cfg_backend_save( void ); | |
43 void i_configure_cfg_backend_read( void ); | |
44 void i_configure_cfg_ap_save( void ); | |
45 void i_configure_cfg_ap_read( void ); | |
46 | |
47 | |
48 GtkWidget * i_configure_gui_draw_title( gchar * title_string ) | |
49 { | |
50 GtkWidget *title_label, *title_evbox, *title_frame; | |
51 GtkStyle * style = gtk_widget_get_default_style(); | |
52 GdkColor title_fgcol = style->fg[GTK_STATE_SELECTED]; | |
53 GdkColor title_bgcol = style->bg[GTK_STATE_SELECTED]; | |
54 title_label = gtk_label_new( title_string ); | |
55 title_evbox = gtk_event_box_new(); | |
56 title_frame = gtk_frame_new( NULL ); | |
57 gtk_frame_set_shadow_type( GTK_FRAME(title_frame) , GTK_SHADOW_OUT ); | |
58 gtk_container_add( GTK_CONTAINER(title_evbox) , title_label ); | |
59 gtk_container_set_border_width( GTK_CONTAINER(title_evbox) , 5 ); | |
60 gtk_container_add( GTK_CONTAINER(title_frame) , title_evbox ); | |
61 gtk_widget_modify_fg( GTK_WIDGET(title_label) , GTK_STATE_NORMAL , &title_fgcol ); | |
62 gtk_widget_modify_bg( GTK_WIDGET(title_evbox) , GTK_STATE_NORMAL , &title_bgcol ); | |
63 return title_frame; | |
64 } | |
65 | |
66 | |
67 void i_configure_ev_browse_for_entry( GtkWidget * target_entry ) | |
68 { | |
69 GtkWidget *parent_window = gtk_widget_get_toplevel( target_entry ); | |
70 GtkFileChooserAction act = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(target_entry),"fc-act")); | |
71 if ( GTK_WIDGET_TOPLEVEL(parent_window) ) | |
72 { | |
73 GtkWidget *browse_dialog = gtk_file_chooser_dialog_new( _("AMIDI-Plug - select file") , | |
74 GTK_WINDOW(parent_window) , act , | |
75 GTK_STOCK_CANCEL , GTK_RESPONSE_CANCEL , | |
76 GTK_STOCK_OPEN , GTK_RESPONSE_ACCEPT , NULL ); | |
77 if ( strcmp( gtk_entry_get_text(GTK_ENTRY(target_entry)) , "" ) ) | |
78 gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(browse_dialog) , | |
79 gtk_entry_get_text(GTK_ENTRY(target_entry)) ); | |
80 if ( gtk_dialog_run(GTK_DIALOG(browse_dialog)) == GTK_RESPONSE_ACCEPT ) | |
81 { | |
82 gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(browse_dialog) ); | |
83 gtk_entry_set_text( GTK_ENTRY(target_entry) , filename ); | |
84 DEBUGMSG( "selected file: %s\n" , filename ); | |
85 g_free( filename ); | |
86 } | |
87 gtk_widget_destroy( browse_dialog ); | |
88 } | |
89 } | |
90 | |
91 | |
92 void i_configure_gui( void ) | |
93 { | |
94 static GtkWidget *configwin = NULL; | |
95 GdkGeometry cw_hints; | |
96 GtkWidget *configwin_vbox; | |
97 GtkWidget *hseparator, *hbuttonbox, *button_ok, *button_cancel, *button_apply; | |
98 | |
99 GtkWidget *configwin_notebook; | |
100 | |
101 GtkWidget *ap_page_alignment, *ap_pagelabel_alignment; /* amidi-plug */ | |
102 GtkWidget *alsa_page_alignment, *alsa_pagelabel_alignment; /* alsa */ | |
103 GtkWidget *dumm_page_alignment, *dumm_pagelabel_alignment; /* dummy */ | |
104 GtkWidget *fsyn_page_alignment, *fsyn_pagelabel_alignment; /* fluidsynth */ | |
105 | |
106 GSList *backend_list = NULL, *backend_list_h = NULL; | |
107 | |
108 if ( configwin != NULL ) | |
109 { | |
110 DEBUGMSG( "config window is already open!\n" ); | |
111 return; | |
112 } | |
113 | |
114 /* get configuration information for backends */ | |
115 i_configure_cfg_backend_alloc(); | |
116 i_configure_cfg_backend_read(); | |
117 | |
118 configwin = gtk_window_new( GTK_WINDOW_TOPLEVEL ); | |
119 gtk_window_set_type_hint( GTK_WINDOW(configwin), GDK_WINDOW_TYPE_HINT_DIALOG ); | |
120 gtk_window_set_title( GTK_WINDOW(configwin), _("AMIDI-Plug - configuration") ); | |
121 gtk_container_set_border_width( GTK_CONTAINER(configwin), 10 ); | |
122 g_signal_connect( G_OBJECT(configwin) , "destroy" , | |
123 G_CALLBACK(gtk_widget_destroyed) , &configwin ); | |
124 button_ok = gtk_button_new_from_stock( GTK_STOCK_OK ); | |
125 if ( g_signal_lookup( "ap-commit" , GTK_WIDGET_TYPE(button_ok) ) == 0 ) | |
126 { | |
127 g_signal_new( "ap-commit" , GTK_WIDGET_TYPE(button_ok) , | |
128 G_SIGNAL_ACTION , 0 , NULL , NULL , | |
129 g_cclosure_marshal_VOID__VOID , G_TYPE_NONE , 0 ); | |
130 } | |
131 g_signal_connect( G_OBJECT(button_ok) , "clicked" , | |
132 G_CALLBACK(i_configure_ev_bokcheck) , configwin ); | |
133 cw_hints.min_width = 480; cw_hints.min_height = -1; | |
134 gtk_window_set_geometry_hints( GTK_WINDOW(configwin) , GTK_WIDGET(configwin) , | |
135 &cw_hints , GDK_HINT_MIN_SIZE ); | |
136 | |
137 configwin_vbox = gtk_vbox_new( FALSE , 0 ); | |
138 gtk_container_add( GTK_CONTAINER(configwin) , configwin_vbox ); | |
139 | |
140 configwin_notebook = gtk_notebook_new(); | |
141 gtk_notebook_set_tab_pos( GTK_NOTEBOOK(configwin_notebook) , GTK_POS_LEFT ); | |
142 gtk_box_pack_start( GTK_BOX(configwin_vbox) , configwin_notebook , TRUE , TRUE , 2 ); | |
143 | |
144 /* GET A LIST OF BACKENDS */ | |
145 backend_list = i_backend_list_lookup(); /* get a list of available backends */; | |
146 backend_list_h = backend_list; | |
147 | |
148 /* AMIDI-PLUG PREFERENCES TAB */ | |
149 ap_pagelabel_alignment = gtk_alignment_new( 0.5 , 0.5 , 1 , 1 ); | |
150 ap_page_alignment = gtk_alignment_new( 0.5 , 0.5 , 1 , 1 ); | |
151 gtk_alignment_set_padding( GTK_ALIGNMENT(ap_page_alignment) , 3 , 3 , 8 , 3 ); | |
152 i_configure_gui_tab_ap( ap_page_alignment , backend_list , button_ok ); | |
153 i_configure_gui_tablabel_ap( ap_pagelabel_alignment , backend_list , button_ok ); | |
154 gtk_notebook_append_page( GTK_NOTEBOOK(configwin_notebook) , | |
155 ap_page_alignment , ap_pagelabel_alignment ); | |
156 | |
157 /* ALSA BACKEND CONFIGURATION TAB */ | |
158 alsa_pagelabel_alignment = gtk_alignment_new( 0.5 , 0.5 , 1 , 1 ); | |
159 alsa_page_alignment = gtk_alignment_new( 0.5 , 0.5 , 1 , 1 ); | |
160 gtk_alignment_set_padding( GTK_ALIGNMENT(alsa_page_alignment) , 3 , 3 , 8 , 3 ); | |
161 i_configure_gui_tab_alsa( alsa_page_alignment , backend_list , button_ok ); | |
162 i_configure_gui_tablabel_alsa( alsa_pagelabel_alignment , backend_list , button_ok ); | |
163 gtk_notebook_append_page( GTK_NOTEBOOK(configwin_notebook) , | |
164 alsa_page_alignment , alsa_pagelabel_alignment ); | |
165 | |
166 /* FLUIDSYNTH BACKEND CONFIGURATION TAB */ | |
167 fsyn_pagelabel_alignment = gtk_alignment_new( 0.5 , 0.5 , 1 , 1 ); | |
168 fsyn_page_alignment = gtk_alignment_new( 0.5 , 0.5 , 1 , 1 ); | |
169 gtk_alignment_set_padding( GTK_ALIGNMENT(fsyn_page_alignment) , 3 , 3 , 8 , 3 ); | |
170 i_configure_gui_tab_fsyn( fsyn_page_alignment , backend_list , button_ok ); | |
171 i_configure_gui_tablabel_fsyn( fsyn_pagelabel_alignment , backend_list , button_ok ); | |
172 gtk_notebook_append_page( GTK_NOTEBOOK(configwin_notebook) , | |
173 fsyn_page_alignment , fsyn_pagelabel_alignment ); | |
174 | |
175 /* DUMMY BACKEND CONFIGURATION TAB */ | |
176 dumm_pagelabel_alignment = gtk_alignment_new( 0.5 , 0.5 , 1 , 1 ); | |
177 dumm_page_alignment = gtk_alignment_new( 0.5 , 0.5 , 1 , 1 ); | |
178 gtk_alignment_set_padding( GTK_ALIGNMENT(dumm_page_alignment) , 3 , 3 , 8 , 3 ); | |
179 i_configure_gui_tab_dumm( dumm_page_alignment , backend_list , button_ok ); | |
180 i_configure_gui_tablabel_dumm( dumm_pagelabel_alignment , backend_list , button_ok ); | |
181 gtk_notebook_append_page( GTK_NOTEBOOK(configwin_notebook) , | |
182 dumm_page_alignment , dumm_pagelabel_alignment ); | |
183 | |
184 i_backend_list_free( backend_list_h ); /* done, free the list of available backends */ | |
185 | |
186 /* horizontal separator and buttons */ | |
187 hseparator = gtk_hseparator_new(); | |
188 gtk_box_pack_start( GTK_BOX(configwin_vbox) , hseparator , FALSE , FALSE , 4 ); | |
189 hbuttonbox = gtk_hbutton_box_new(); | |
190 gtk_button_box_set_layout( GTK_BUTTON_BOX(hbuttonbox) , GTK_BUTTONBOX_END ); | |
191 button_apply = gtk_button_new_from_stock( GTK_STOCK_APPLY ); | |
192 gtk_container_add( GTK_CONTAINER(hbuttonbox) , button_apply ); | |
193 button_cancel = gtk_button_new_from_stock( GTK_STOCK_CANCEL ); | |
194 g_signal_connect_swapped( G_OBJECT(button_cancel) , "clicked" , | |
195 G_CALLBACK(i_configure_ev_bcancel) , configwin ); | |
196 gtk_container_add( GTK_CONTAINER(hbuttonbox) , button_cancel ); | |
197 /* button_ok = gtk_button_new_from_stock( GTK_STOCK_OK ); created above */ | |
198 g_object_set_data( G_OBJECT(button_ok) , "bapply_pressed" , GUINT_TO_POINTER(0) ); | |
199 g_object_set_data( G_OBJECT(button_apply) , "bok" , button_ok ); | |
200 g_signal_connect( G_OBJECT(button_ok) , "ap-commit" , | |
201 G_CALLBACK(i_configure_ev_bok) , configwin ); | |
202 g_signal_connect( G_OBJECT(button_apply) , "clicked" , | |
203 G_CALLBACK(i_configure_ev_bapply) , configwin ); | |
204 gtk_container_add( GTK_CONTAINER(hbuttonbox) , button_ok ); | |
205 gtk_box_pack_start( GTK_BOX(configwin_vbox) , hbuttonbox , FALSE , FALSE , 0 ); | |
206 | |
207 gtk_widget_show_all( configwin ); | |
208 } | |
209 | |
210 | |
211 void i_configure_ev_bcancel( gpointer configwin ) | |
212 { | |
213 i_configure_cfg_backend_free(); /* free backend settings */ | |
214 gtk_widget_destroy(GTK_WIDGET(configwin)); | |
215 } | |
216 | |
217 | |
218 void i_configure_ev_bapply( GtkWidget * button_apply , gpointer configwin ) | |
219 { | |
220 GtkWidget *button_ok = g_object_get_data( G_OBJECT(button_apply) , "bok" ); | |
221 g_object_set_data( G_OBJECT(button_ok) , "bapply_pressed" , GUINT_TO_POINTER(1) ); | |
222 i_configure_ev_bokcheck( button_ok , configwin ); | |
223 } | |
224 | |
225 | |
226 void i_configure_ev_bokcheck( GtkWidget * button_ok , gpointer configwin ) | |
227 { | |
228 if ( xmms_remote_is_playing(0) || xmms_remote_is_paused(0) ) | |
229 { | |
230 /* we can't change settings while a song is being played */ | |
231 static GtkWidget * configwin_warnmsg = NULL; | |
232 g_object_set_data( G_OBJECT(button_ok) , "bapply_pressed" , GUINT_TO_POINTER(0) ); | |
233 if ( configwin_warnmsg != NULL ) | |
234 { | |
235 gdk_window_raise( configwin_warnmsg->window ); | |
236 } | |
237 else | |
238 { | |
239 configwin_warnmsg = (GtkWidget*)i_message_gui( _("AMIDI-Plug message") , | |
240 _("Please stop the player before changing AMIDI-Plug settings.") , | |
241 AMIDIPLUG_MESSAGE_WARN , configwin , FALSE ); | |
242 g_signal_connect( G_OBJECT(configwin_warnmsg) , "destroy" , | |
243 G_CALLBACK(gtk_widget_destroyed) , &configwin_warnmsg ); | |
244 gtk_widget_show_all( configwin_warnmsg ); | |
245 } | |
246 } | |
247 else | |
248 { | |
249 g_signal_emit_by_name( G_OBJECT(button_ok) , "ap-commit" ); /* call commit actions */ | |
250 } | |
251 } | |
252 | |
253 | |
254 void i_configure_ev_bok( GtkWidget * button_ok , gpointer configwin ) | |
255 { | |
256 DEBUGMSG( "saving configuration...\n" ); | |
257 i_configure_cfg_ap_save(); /* save amidiplug settings */ | |
258 i_configure_cfg_backend_save(); /* save backend settings */ | |
259 DEBUGMSG( "configuration saved\n" ); | |
260 | |
261 /* check if a different backend has been selected */ | |
262 if (( backend.name == NULL ) || ( strcmp( amidiplug_cfg_ap.ap_seq_backend , backend.name ) )) | |
263 { | |
264 DEBUGMSG( "a new backend has been selected, unloading previous and loading the new one\n" ); | |
265 i_backend_unload(); /* unload previous backend */ | |
266 i_backend_load( amidiplug_cfg_ap.ap_seq_backend ); /* load new backend */ | |
267 } | |
268 else /* same backend, just reload updated configuration */ | |
269 { | |
270 if ( backend.gmodule != NULL ) | |
271 { | |
272 DEBUGMSG( "the selected backend is already loaded, so just perform backend cleanup and reinit\n" ); | |
273 backend.cleanup(); | |
274 backend.init(); | |
275 } | |
276 } | |
277 | |
278 if ( GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(button_ok),"bapply_pressed")) == 1 ) | |
279 { | |
280 g_object_set_data( G_OBJECT(button_ok) , "bapply_pressed" , GUINT_TO_POINTER(0) ); | |
281 } | |
282 else | |
283 { | |
284 i_configure_cfg_backend_free(); /* free backend settings */ | |
285 gtk_widget_destroy(GTK_WIDGET(configwin)); | |
286 } | |
287 } | |
288 | |
289 | |
290 void i_configure_cfg_backend_alloc( void ) | |
291 { | |
292 amidiplug_cfg_backend = g_malloc(sizeof(amidiplug_cfg_backend)); | |
293 | |
294 i_configure_cfg_alsa_alloc(); /* alloc alsa backend configuration */ | |
295 i_configure_cfg_fsyn_alloc(); /* alloc fluidsynth backend configuration */ | |
296 i_configure_cfg_dumm_alloc(); /* alloc dummy backend configuration */ | |
297 } | |
298 | |
299 | |
300 void i_configure_cfg_backend_free( void ) | |
301 { | |
302 i_configure_cfg_alsa_free(); /* free alsa backend configuration */ | |
303 i_configure_cfg_fsyn_free(); /* free fluidsynth backend configuration */ | |
304 i_configure_cfg_dumm_free(); /* free dummy backend configuration */ | |
305 | |
306 g_free( amidiplug_cfg_backend ); | |
307 } | |
308 | |
309 | |
310 void i_configure_cfg_backend_read( void ) | |
311 { | |
312 pcfg_t *cfgfile; | |
313 | |
314 gchar * config_pathfilename = g_strjoin( "" , g_get_home_dir() , "/" , | |
315 PLAYER_LOCALRCDIR , "/amidi-plug.conf" , NULL ); | |
316 cfgfile = i_pcfg_new_from_file( config_pathfilename ); | |
317 | |
318 i_configure_cfg_alsa_read( cfgfile ); /* get alsa backend configuration */ | |
319 i_configure_cfg_fsyn_read( cfgfile ); /* get fluidsynth backend configuration */ | |
320 i_configure_cfg_dumm_read( cfgfile ); /* get dummy backend configuration */ | |
321 | |
322 if ( cfgfile != NULL ) | |
323 i_pcfg_free(cfgfile); | |
324 | |
325 g_free( config_pathfilename ); | |
326 } | |
327 | |
328 | |
329 void i_configure_cfg_backend_save( void ) | |
330 { | |
331 pcfg_t *cfgfile; | |
332 gchar * config_pathfilename = g_strjoin( "" , g_get_home_dir() , "/" , | |
333 PLAYER_LOCALRCDIR , "/amidi-plug.conf" , NULL ); | |
334 cfgfile = i_pcfg_new_from_file( config_pathfilename ); | |
335 | |
336 if (!cfgfile) | |
337 cfgfile = i_pcfg_new(); | |
338 | |
339 i_configure_cfg_alsa_save( cfgfile ); /* save alsa backend configuration */ | |
340 i_configure_cfg_fsyn_save( cfgfile ); /* save fluidsynth backend configuration */ | |
341 i_configure_cfg_dumm_save( cfgfile ); /* save dummy backend configuration */ | |
342 | |
343 i_pcfg_write_to_file( cfgfile , config_pathfilename ); | |
344 i_pcfg_free( cfgfile ); | |
345 g_free( config_pathfilename ); | |
346 } | |
347 | |
348 | |
349 /* read only the amidi-plug part of configuration */ | |
350 void i_configure_cfg_ap_read( void ) | |
351 { | |
352 pcfg_t *cfgfile; | |
353 gchar * config_pathfilename = g_strjoin( "" , g_get_home_dir() , "/" , | |
354 PLAYER_LOCALRCDIR , "/amidi-plug.conf" , NULL ); | |
355 cfgfile = i_pcfg_new_from_file( config_pathfilename ); | |
356 | |
357 if (!cfgfile) | |
358 { | |
359 /* amidi-plug defaults */ | |
360 amidiplug_cfg_ap.ap_seq_backend = g_strdup( "alsa" ); | |
361 amidiplug_cfg_ap.ap_opts_length_precalc = 0; | |
362 amidiplug_cfg_ap.ap_opts_lyrics_extract = 0; | |
363 amidiplug_cfg_ap.ap_opts_comments_extract = 0; | |
364 } | |
365 else | |
366 { | |
367 i_pcfg_read_string( cfgfile , "general" , "ap_seq_backend" , | |
368 &amidiplug_cfg_ap.ap_seq_backend , "alsa" ); | |
369 i_pcfg_read_integer( cfgfile , "general" , "ap_opts_length_precalc" , | |
370 &amidiplug_cfg_ap.ap_opts_length_precalc , 0 ); | |
371 i_pcfg_read_integer( cfgfile , "general" , "ap_opts_lyrics_extract" , | |
372 &amidiplug_cfg_ap.ap_opts_lyrics_extract , 0 ); | |
373 i_pcfg_read_integer( cfgfile , "general" , "ap_opts_comments_extract" , | |
374 &amidiplug_cfg_ap.ap_opts_comments_extract , 0 ); | |
375 i_pcfg_free( cfgfile ); | |
376 } | |
377 | |
378 g_free( config_pathfilename ); | |
379 } | |
380 | |
381 | |
382 void i_configure_cfg_ap_save( void ) | |
383 { | |
384 pcfg_t *cfgfile; | |
385 gchar * config_pathfilename = g_strjoin( "" , g_get_home_dir() , "/" , | |
386 PLAYER_LOCALRCDIR , "/amidi-plug.conf" , NULL ); | |
387 cfgfile = i_pcfg_new_from_file( config_pathfilename ); | |
388 | |
389 if (!cfgfile) | |
390 cfgfile = i_pcfg_new(); | |
391 | |
392 /* save amidi-plug config information */ | |
393 i_pcfg_write_string( cfgfile , "general" , "ap_seq_backend" , | |
394 amidiplug_cfg_ap.ap_seq_backend ); | |
395 i_pcfg_write_integer( cfgfile , "general" , "ap_opts_length_precalc" , | |
396 amidiplug_cfg_ap.ap_opts_length_precalc ); | |
397 i_pcfg_write_integer( cfgfile , "general" , "ap_opts_lyrics_extract" , | |
398 amidiplug_cfg_ap.ap_opts_lyrics_extract ); | |
399 i_pcfg_write_integer( cfgfile , "general" , "ap_opts_comments_extract" , | |
400 amidiplug_cfg_ap.ap_opts_comments_extract ); | |
401 | |
402 i_pcfg_write_to_file( cfgfile , config_pathfilename ); | |
403 i_pcfg_free( cfgfile ); | |
404 g_free( config_pathfilename ); | |
405 } |