Mercurial > hg > xmms-sid
comparison src/xs_config.c @ 228:a9a5924eb10c
Have and use a mutex for xs_cfg configuration structure.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 19 Dec 2004 16:54:04 +0000 |
parents | df4cb5115322 |
children | 608f31f6c095 |
comparison
equal
deleted
inserted
replaced
227:92bad4c7b998 | 228:a9a5924eb10c |
---|---|
38 | 38 |
39 | 39 |
40 /* | 40 /* |
41 * Configuration specific stuff | 41 * Configuration specific stuff |
42 */ | 42 */ |
43 XS_MUTEX(xs_cfg); | |
44 struct t_xs_cfg xs_cfg; | |
45 | |
43 t_xs_cfg_item xs_cfgtable[] = { | 46 t_xs_cfg_item xs_cfgtable[] = { |
44 {CTYPE_INT, &xs_cfg.audioBitsPerSample, "audioBitsPerSample"}, | 47 {CTYPE_INT, &xs_cfg.audioBitsPerSample, "audioBitsPerSample"}, |
45 {CTYPE_INT, &xs_cfg.audioChannels, "audioChannels"}, | 48 {CTYPE_INT, &xs_cfg.audioChannels, "audioChannels"}, |
46 {CTYPE_INT, &xs_cfg.audioFrequency, "audioFrequency"}, | 49 {CTYPE_INT, &xs_cfg.audioFrequency, "audioFrequency"}, |
47 | 50 |
79 | 82 |
80 {CTYPE_BOOL, &xs_cfg.titleOverride, "titleOverride"}, | 83 {CTYPE_BOOL, &xs_cfg.titleOverride, "titleOverride"}, |
81 {CTYPE_STR, &xs_cfg.titleFormat, "titleFormat"}, | 84 {CTYPE_STR, &xs_cfg.titleFormat, "titleFormat"}, |
82 }; | 85 }; |
83 | 86 |
84 const gint xs_cfgtable_max = (sizeof(xs_cfgtable) / sizeof(t_xs_cfg_item)); | 87 static const gint xs_cfgtable_max = (sizeof(xs_cfgtable) / sizeof(t_xs_cfg_item)); |
85 | 88 |
86 | 89 |
87 t_xs_wid_item xs_widtable[] = { | 90 t_xs_wid_item xs_widtable[] = { |
88 { WTYPE_BGROUP, CTYPE_INT, "cfg_res_16bit", &xs_cfg.audioBitsPerSample, XS_RES_16BIT }, | 91 { WTYPE_BGROUP, CTYPE_INT, "cfg_res_16bit", &xs_cfg.audioBitsPerSample, XS_RES_16BIT }, |
89 { WTYPE_BGROUP, CTYPE_INT, "cfg_res_8bit", &xs_cfg.audioBitsPerSample, XS_RES_8BIT }, | 92 { WTYPE_BGROUP, CTYPE_INT, "cfg_res_8bit", &xs_cfg.audioBitsPerSample, XS_RES_8BIT }, |
137 { WTYPE_BUTTON, CTYPE_BOOL, "cfg_ftitle_override", &xs_cfg.titleOverride, 0 }, | 140 { WTYPE_BUTTON, CTYPE_BOOL, "cfg_ftitle_override", &xs_cfg.titleOverride, 0 }, |
138 { WTYPE_TEXT, CTYPE_STR, "cfg_ftitle_format", &xs_cfg.titleFormat, 0 }, | 141 { WTYPE_TEXT, CTYPE_STR, "cfg_ftitle_format", &xs_cfg.titleFormat, 0 }, |
139 | 142 |
140 }; | 143 }; |
141 | 144 |
142 const gint xs_widtable_max = (sizeof(xs_widtable) / sizeof(t_xs_wid_item)); | 145 static const gint xs_widtable_max = (sizeof(xs_widtable) / sizeof(t_xs_wid_item)); |
143 | 146 |
144 | 147 |
145 /* | 148 /* |
146 * Reset the filter settings | 149 * Reset the filter settings |
147 */ | 150 */ |
148 void xs_reset_filters(void) | 151 void xs_reset_filters(void) |
149 { | 152 { |
150 /* Reset filter values (copied from libsidplay1's headers) */ | 153 /* Reset filter values (copied from libsidplay1's headers) */ |
154 XS_MUTEX_LOCK(xs_cfg); | |
155 | |
151 xs_cfg.filterFs = 400.0f; | 156 xs_cfg.filterFs = 400.0f; |
152 xs_cfg.filterFm = 60.0f; | 157 xs_cfg.filterFm = 60.0f; |
153 xs_cfg.filterFt = 0.05f; | 158 xs_cfg.filterFt = 0.05f; |
159 | |
160 XS_MUTEX_UNLOCK(xs_cfg); | |
154 } | 161 } |
155 | 162 |
156 | 163 |
157 /* | 164 /* |
158 * Get the configuration (from file or default) | 165 * Get the configuration (from file or default) |
162 gchar *cfgFilename, *tmpStr; | 169 gchar *cfgFilename, *tmpStr; |
163 ConfigFile *cfgFile; | 170 ConfigFile *cfgFile; |
164 gint i; | 171 gint i; |
165 | 172 |
166 XSDEBUG("initializing configuration ...\n"); | 173 XSDEBUG("initializing configuration ...\n"); |
174 XS_MUTEX_LOCK(xs_cfg); | |
167 | 175 |
168 /* Pre-initialize configuration structure */ | 176 /* Pre-initialize configuration structure */ |
169 xs_cfg.audioBitsPerSample = XS_RES_16BIT; | 177 xs_cfg.audioBitsPerSample = XS_RES_16BIT; |
170 xs_cfg.audioChannels = XS_CHN_MONO; | 178 xs_cfg.audioChannels = XS_CHN_MONO; |
171 xs_cfg.audioFrequency = 44100; | 179 xs_cfg.audioFrequency = 44100; |
285 | 293 |
286 | 294 |
287 /* Free the config file */ | 295 /* Free the config file */ |
288 xmms_cfg_free(cfgFile); | 296 xmms_cfg_free(cfgFile); |
289 | 297 |
298 XS_MUTEX_UNLOCK(xs_cfg); | |
290 XSDEBUG("OK\n"); | 299 XSDEBUG("OK\n"); |
291 } | 300 } |
292 | 301 |
293 | 302 |
294 | 303 |
300 gchar *cfgFilename; | 309 gchar *cfgFilename; |
301 ConfigFile *cfgFile; | 310 ConfigFile *cfgFile; |
302 gint i; | 311 gint i; |
303 | 312 |
304 XSDEBUG("writing configuration ...\n"); | 313 XSDEBUG("writing configuration ...\n"); |
314 XS_MUTEX_LOCK(xs_cfg); | |
305 | 315 |
306 /* | 316 /* |
307 * Try to open the XMMS configuration file | 317 * Try to open the XMMS configuration file |
308 */ | 318 */ |
309 #ifdef HAVE_NODEFAULTCFG | 319 #ifdef HAVE_NODEFAULTCFG |
314 #endif | 324 #endif |
315 | 325 |
316 if (!cfgFile) | 326 if (!cfgFile) |
317 cfgFile = xmms_cfg_new(); | 327 cfgFile = xmms_cfg_new(); |
318 | 328 |
319 | |
320 /* Write the new settings to XMMS configuration file */ | 329 /* Write the new settings to XMMS configuration file */ |
321 for (i = 0; i < xs_cfgtable_max; i++) | 330 for (i = 0; i < xs_cfgtable_max; i++) |
322 { | 331 { |
323 switch (xs_cfgtable[i].itemType) { | 332 switch (xs_cfgtable[i].itemType) { |
324 case CTYPE_INT: | 333 case CTYPE_INT: |
352 #endif | 361 #endif |
353 | 362 |
354 /* Free the memory areas */ | 363 /* Free the memory areas */ |
355 xmms_cfg_free(cfgFile); | 364 xmms_cfg_free(cfgFile); |
356 | 365 |
366 XS_MUTEX_UNLOCK(xs_cfg); | |
367 | |
357 return 0; | 368 return 0; |
358 } | 369 } |
359 | 370 |
360 | 371 |
361 /* | 372 /* |
450 /* | 461 /* |
451 * Reset filter settings to defaults | 462 * Reset filter settings to defaults |
452 */ | 463 */ |
453 void xs_cfg_filter_reset(void) | 464 void xs_cfg_filter_reset(void) |
454 { | 465 { |
466 XS_MUTEX_LOCK(xs_cfg); | |
467 | |
455 xs_reset_filters(); | 468 xs_reset_filters(); |
456 | 469 |
457 gtk_adjustment_set_value(gtk_range_get_adjustment(GTK_RANGE(LUW("cfg_emu_filt_fs"))), xs_cfg.filterFs); | 470 gtk_adjustment_set_value(gtk_range_get_adjustment(GTK_RANGE(LUW("cfg_emu_filt_fs"))), xs_cfg.filterFs); |
458 gtk_adjustment_set_value(gtk_range_get_adjustment(GTK_RANGE(LUW("cfg_emu_filt_fm"))), xs_cfg.filterFm); | 471 gtk_adjustment_set_value(gtk_range_get_adjustment(GTK_RANGE(LUW("cfg_emu_filt_fm"))), xs_cfg.filterFm); |
459 gtk_adjustment_set_value(gtk_range_get_adjustment(GTK_RANGE(LUW("cfg_emu_filt_ft"))), xs_cfg.filterFt); | 472 gtk_adjustment_set_value(gtk_range_get_adjustment(GTK_RANGE(LUW("cfg_emu_filt_ft"))), xs_cfg.filterFt); |
473 | |
474 XS_MUTEX_UNLOCK(xs_cfg); | |
460 } | 475 } |
461 | 476 |
462 | 477 |
463 /* | 478 /* |
464 * HVSC songlength-database file selector response-functions | 479 * HVSC songlength-database file selector response-functions |
735 } | 750 } |
736 | 751 |
737 /* Create the window */ | 752 /* Create the window */ |
738 xs_configwin = create_xs_configwin(); | 753 xs_configwin = create_xs_configwin(); |
739 | 754 |
755 /* Get lock on configuration */ | |
756 XS_MUTEX_LOCK(xs_cfg); | |
740 | 757 |
741 /* Based on available optional parts, gray out options */ | 758 /* Based on available optional parts, gray out options */ |
742 #ifndef HAVE_SIDPLAY1 | 759 #ifndef HAVE_SIDPLAY1 |
743 gtk_widget_set_sensitive(LUW("cfg_emu_sidplay1"), FALSE); | 760 gtk_widget_set_sensitive(LUW("cfg_emu_sidplay1"), FALSE); |
744 #endif | 761 #endif |
830 *(gchar **) xs_widtable[i].itemData); | 847 *(gchar **) xs_widtable[i].itemData); |
831 } | 848 } |
832 break; | 849 break; |
833 } | 850 } |
834 } | 851 } |
835 | 852 |
853 /* Release the configuration */ | |
854 XS_MUTEX_UNLOCK(xs_cfg); | |
855 | |
856 /* Show the widget */ | |
836 gtk_widget_show(xs_configwin); | 857 gtk_widget_show(xs_configwin); |
837 } | 858 } |
838 | 859 |