Mercurial > audlegacy-plugins
comparison src/crossfade/cfgutil.c @ 3059:2e241e90494a
Import work in progress xmms-crossfade rewrite.
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Fri, 24 Apr 2009 05:57:35 -0500 |
parents | |
children | 43a336a7791b |
comparison
equal
deleted
inserted
replaced
3058:2e649bf16ebc | 3059:2e241e90494a |
---|---|
1 /* | |
2 * XMMS Crossfade Plugin | |
3 * Copyright (C) 2000-2007 Peter Eisenlohr <peter@eisenlohr.org> | |
4 * | |
5 * based on the original OSS Output Plugin | |
6 * Copyright (C) 1998-2000 Peter Alm, Mikael Alm, Olle Hallnas, Thomas Nilsson and 4Front Technologies | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
21 * USA. | |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 # include "config.h" | |
26 #endif | |
27 | |
28 #undef PRESET_SUPPORT | |
29 | |
30 #include "crossfade.h" | |
31 #include "configure.h" | |
32 | |
33 #include <stdio.h> | |
34 #include <string.h> | |
35 #include <stdlib.h> | |
36 #include <ctype.h> | |
37 | |
38 # define ConfigFile ConfigDb | |
39 # define xmms_cfg_read_int aud_cfg_db_get_int | |
40 # define xmms_cfg_read_string aud_cfg_db_get_string | |
41 # define xmms_cfg_read_boolean aud_cfg_db_get_bool | |
42 # define xmms_cfg_write_int aud_cfg_db_set_int | |
43 # define xmms_cfg_write_string aud_cfg_db_set_string | |
44 # define xmms_cfg_write_boolean aud_cfg_db_set_bool | |
45 # define xmms_cfg_remove_key aud_cfg_db_unset_key | |
46 # define xmms_cfg_open_default_file aud_cfg_db_open | |
47 # define xmms_cfg_write_default_file aud_cfg_db_close | |
48 void xmms_cfg_dummy(ConfigDb *dummy) { } | |
49 # define xmms_cfg_free xmms_cfg_dummy | |
50 | |
51 /* init with DEFAULT_CFG to make sure all string pointers are set to NULL */ | |
52 config_t _xfg = CONFIG_DEFAULT; /* also used in configure.c */ | |
53 static config_t *xfg = &_xfg; | |
54 | |
55 /*****************************************************************************/ | |
56 | |
57 static void | |
58 update_plugin_config(gchar **config_string, gchar *name, plugin_config_t *pc, gboolean save); | |
59 | |
60 static void | |
61 g_free_f(gpointer data, gpointer user_data) | |
62 { | |
63 g_free(data); | |
64 } | |
65 | |
66 /*****************************************************************************/ | |
67 | |
68 static gchar *strip(gchar *s) | |
69 { | |
70 gchar *p; | |
71 if (!s) | |
72 return NULL; | |
73 | |
74 for (; *s == ' '; s++); | |
75 if (!*s) | |
76 return s; | |
77 | |
78 for (p = s + strlen(s) - 1; *p == ' '; p--); | |
79 *++p = 0; | |
80 return s; | |
81 } | |
82 | |
83 static void | |
84 update_plugin_config(gchar **config_string, gchar *name, plugin_config_t *pc, gboolean save) | |
85 { | |
86 plugin_config_t default_pc = DEFAULT_OP_CONFIG; | |
87 | |
88 gchar *buffer = NULL; | |
89 gchar out[1024]; | |
90 | |
91 gboolean plugin_found = FALSE; | |
92 gchar *plugin, *next_plugin; | |
93 gchar *args; | |
94 | |
95 if (pc && !save) | |
96 *pc = default_pc; | |
97 | |
98 if (!config_string || !*config_string || !name || !pc) | |
99 { | |
100 DEBUG(("[crossfade] update_plugin_config: missing arg!\n")); | |
101 return; | |
102 } | |
103 | |
104 buffer = g_strdup(*config_string); | |
105 out[0] = 0; | |
106 | |
107 for (plugin = buffer; plugin; plugin = next_plugin) | |
108 { | |
109 if ((next_plugin = strchr(plugin, ';'))) | |
110 *next_plugin++ = 0; | |
111 | |
112 if ((args = strchr(plugin, '='))) | |
113 *args++ = 0; | |
114 | |
115 plugin = strip(plugin); | |
116 if (!*plugin || !args || !*args) | |
117 continue; | |
118 | |
119 if (save) | |
120 { | |
121 if (strcmp(plugin, name) == 0) | |
122 continue; | |
123 | |
124 if (*out) | |
125 strcat(out, "; "); | |
126 | |
127 strcat(out, plugin); | |
128 strcat(out, "="); | |
129 strcat(out, args); | |
130 continue; | |
131 } | |
132 else if (strcmp(plugin, name)) | |
133 continue; | |
134 | |
135 args = strip(args); | |
136 sscanf(args, "%d,%d,%d,%d", &pc->throttle_enable, &pc->max_write_enable, &pc->max_write_len, &pc->force_reopen); | |
137 pc->max_write_len &= -4; | |
138 plugin_found = TRUE; | |
139 } | |
140 | |
141 if (save) | |
142 { | |
143 /* only save if settings differ from defaults */ | |
144 if ((pc->throttle_enable != default_pc.throttle_enable) | |
145 || (pc->max_write_enable != default_pc.max_write_enable) | |
146 || (pc->max_write_len != default_pc.max_write_len) | |
147 || (pc->force_reopen != default_pc.force_reopen)) | |
148 { | |
149 if (*out) | |
150 strcat(out, "; "); | |
151 | |
152 sprintf(out + strlen(out), "%s=%d,%d,%d,%d", name, | |
153 pc->throttle_enable ? 1 : 0, pc->max_write_enable ? 1 : 0, pc->max_write_len, pc->force_reopen); | |
154 } | |
155 if (*config_string) | |
156 g_free(*config_string); | |
157 | |
158 *config_string = g_strdup(out); | |
159 } | |
160 | |
161 g_free(buffer); | |
162 } | |
163 | |
164 /*****************************************************************************/ | |
165 | |
166 #ifdef PRESET_SUPPORT | |
167 static void | |
168 scan_presets(gchar *filename) | |
169 { | |
170 struct stat stats; | |
171 FILE *fh; | |
172 gchar *data, **lines, *tmp, *name; | |
173 int i; | |
174 | |
175 if (lstat(filename, &stats)) | |
176 { | |
177 DEBUG(("[crossfade] scan_presets: \"%s\":\n", filename)); | |
178 PERROR("[crossfade] scan_presets: lstat"); | |
179 return; | |
180 } | |
181 if (stats.st_size <= 0) | |
182 return; | |
183 | |
184 if (!(data = g_malloc(stats.st_size + 1))) | |
185 { | |
186 DEBUG(("[crossfade] scan_presets: g_malloc(%ld) failed!\n", stats.st_size)); | |
187 return; | |
188 } | |
189 | |
190 if (!(fh = fopen(filename, "r"))) | |
191 { | |
192 PERROR("[crossfade] scan_presets: fopen"); | |
193 g_free(data); | |
194 return; | |
195 } | |
196 | |
197 if (fread(data, stats.st_size, 1, fh) != 1) | |
198 { | |
199 DEBUG(("[crossfade] scan_presets: fread() failed!\n")); | |
200 g_free(data); | |
201 fclose(fh); | |
202 return; | |
203 } | |
204 fclose(fh); | |
205 data[stats.st_size] = 0; | |
206 | |
207 lines = g_strsplit(data, "\n", 0); | |
208 g_free(data); | |
209 | |
210 if (!lines) | |
211 { | |
212 DEBUG(("[crossfade] scan_presets: g_strsplit() failed!\n")); | |
213 return; | |
214 } | |
215 | |
216 g_list_foreach(config->presets, g_free_f, NULL); | |
217 g_list_free(config->presets); | |
218 config->presets = NULL; | |
219 | |
220 for (i = 0; lines[i]; i++) | |
221 { | |
222 if (lines[i][0] == '[') | |
223 { | |
224 if ((tmp = strchr(lines[i], ']'))) | |
225 { | |
226 *tmp = 0; | |
227 if ((name = g_strdup(lines[i] + 1))) | |
228 config->presets = g_list_append(config->presets, name); | |
229 } | |
230 } | |
231 } | |
232 | |
233 g_strfreev(lines); | |
234 } | |
235 #endif | |
236 | |
237 static void | |
238 read_fade_config(ConfigFile *cfgfile, gchar *section, gchar *key, fade_config_t *fc) | |
239 { | |
240 gchar *s = NULL; | |
241 gint n; | |
242 | |
243 if (!cfgfile || !section || !key || !fc) | |
244 return; | |
245 | |
246 xmms_cfg_read_string(cfgfile, section, key, &s); | |
247 if (!s) | |
248 return; | |
249 | |
250 n = sscanf(s, | |
251 "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", | |
252 &fc->type, | |
253 &fc->pause_len_ms, | |
254 &fc->simple_len_ms, | |
255 &fc->out_enable, | |
256 &fc->out_len_ms, | |
257 &fc->out_volume, | |
258 &fc->ofs_type, | |
259 &fc->ofs_type_wanted, | |
260 &fc->ofs_custom_ms, | |
261 &fc->in_locked, | |
262 &fc->in_enable, | |
263 &fc->in_len_ms, | |
264 &fc->in_volume, | |
265 &fc->flush_pause_enable, | |
266 &fc->flush_pause_len_ms, &fc->flush_in_enable, &fc->flush_in_len_ms, &fc->flush_in_volume); | |
267 | |
268 g_free(s); | |
269 } | |
270 | |
271 static void | |
272 write_fade_config(ConfigFile *cfgfile, gchar *section, gchar *key, fade_config_t *fc) | |
273 { | |
274 gchar *s; | |
275 | |
276 if (!cfgfile || !section || !key || !fc) | |
277 return; | |
278 | |
279 s = g_strdup_printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", | |
280 fc->type, | |
281 fc->pause_len_ms, | |
282 fc->simple_len_ms, | |
283 fc->out_enable, | |
284 fc->out_len_ms, | |
285 fc->out_volume, | |
286 fc->ofs_type, | |
287 fc->ofs_type_wanted, | |
288 fc->ofs_custom_ms, | |
289 fc->in_locked, | |
290 fc->in_enable, | |
291 fc->in_len_ms, | |
292 fc->in_volume, | |
293 fc->flush_pause_enable, | |
294 fc->flush_pause_len_ms, fc->flush_in_enable, fc->flush_in_len_ms, fc->flush_in_volume); | |
295 | |
296 if (!s) | |
297 return; | |
298 | |
299 xmms_cfg_write_string(cfgfile, section, key, s); | |
300 g_free(s); | |
301 } | |
302 | |
303 void | |
304 xfade_load_config() | |
305 { | |
306 #ifdef PRESET_SUPPORT | |
307 gchar *filename; | |
308 #endif | |
309 gchar *section = "Crossfade"; | |
310 ConfigFile *cfgfile; | |
311 | |
312 if ((cfgfile = xmms_cfg_open_default_file())) | |
313 { | |
314 /* *INDENT-OFF* */ | |
315 /* config items used in v0.1 */ | |
316 xmms_cfg_read_int (cfgfile, section, "output_method", &config->output_method); | |
317 xmms_cfg_read_int (cfgfile, section, "audio_device", &config->oss_audio_device); | |
318 xmms_cfg_read_boolean(cfgfile, section, "use_alt_audio_device", &config->oss_use_alt_audio_device); | |
319 xmms_cfg_read_string (cfgfile, section, "alt_audio_device", &config->oss_alt_audio_device); | |
320 xmms_cfg_read_int (cfgfile, section, "mixer_device", &config->oss_mixer_device); | |
321 xmms_cfg_read_string (cfgfile, section, "output_plugin", &config->op_name); | |
322 xmms_cfg_read_string (cfgfile, section, "op_config_string", &config->op_config_string); | |
323 xmms_cfg_read_int (cfgfile, section, "buffer_size", &config->mix_size_ms); | |
324 xmms_cfg_read_int (cfgfile, section, "sync_size", &config->sync_size_ms); | |
325 xmms_cfg_read_int (cfgfile, section, "preload_size", &config->preload_size_ms); | |
326 xmms_cfg_read_int (cfgfile, section, "songchange_timeout", &config->songchange_timeout); | |
327 xmms_cfg_read_boolean(cfgfile, section, "enable_mixer", &config->enable_mixer); | |
328 xmms_cfg_read_boolean(cfgfile, section, "mixer_reverse", &config->mixer_reverse); | |
329 xmms_cfg_read_boolean(cfgfile, section, "enable_debug", &config->enable_debug); | |
330 xmms_cfg_read_boolean(cfgfile, section, "enable_monitor", &config->enable_monitor); | |
331 | |
332 /* config items introduced by v0.2 */ | |
333 xmms_cfg_read_int (cfgfile, section, "oss_buffer_size", &config->oss_buffer_size_ms); | |
334 xmms_cfg_read_int (cfgfile, section, "oss_preload_size", &config->oss_preload_size_ms); | |
335 xmms_cfg_read_boolean(cfgfile, section, "oss_mixer_use_master", &config->oss_mixer_use_master); | |
336 xmms_cfg_read_boolean(cfgfile, section, "gap_lead_enable", &config->gap_lead_enable); | |
337 xmms_cfg_read_int (cfgfile, section, "gap_lead_len_ms", &config->gap_lead_len_ms); | |
338 xmms_cfg_read_int (cfgfile, section, "gap_lead_level", &config->gap_lead_level); | |
339 xmms_cfg_read_boolean(cfgfile, section, "gap_trail_enable", &config->gap_trail_enable); | |
340 xmms_cfg_read_int (cfgfile, section, "gap_trail_len_ms", &config->gap_trail_len_ms); | |
341 xmms_cfg_read_int (cfgfile, section, "gap_trail_level", &config->gap_trail_level); | |
342 xmms_cfg_read_int (cfgfile, section, "gap_trail_locked", &config->gap_trail_locked); | |
343 | |
344 /* config items introduced by v0.2.1 */ | |
345 xmms_cfg_read_boolean(cfgfile, section, "buffer_size_auto", &config->mix_size_auto); | |
346 | |
347 /* config items introduced by v0.2.3 */ | |
348 xmms_cfg_read_boolean(cfgfile, section, "album_detection", &config->album_detection); | |
349 | |
350 /* config items introduced by v0.2.4 */ | |
351 xmms_cfg_read_boolean(cfgfile, section, "http_workaround", &config->enable_http_workaround); | |
352 xmms_cfg_read_boolean(cfgfile, section, "enable_op_max_used", &config->enable_op_max_used); | |
353 xmms_cfg_read_int (cfgfile, section, "op_max_used_ms", &config->op_max_used_ms); | |
354 | |
355 /* config items introduced by v0.2.6 */ | |
356 xmms_cfg_read_string (cfgfile, section, "effect_plugin", &config->ep_name); | |
357 xmms_cfg_read_boolean(cfgfile, section, "effect_enable", &config->ep_enable); | |
358 xmms_cfg_read_int (cfgfile, section, "output_rate", &config->output_rate); | |
359 | |
360 /* config items introduced by v0.2.7 */ | |
361 xmms_cfg_read_boolean(cfgfile, section, "oss_maxbuf_enable", &config->oss_maxbuf_enable); | |
362 | |
363 /* config items introduced by v0.3.0 */ | |
364 xmms_cfg_read_boolean(cfgfile, section, "use_alt_mixer_device", &config->oss_use_alt_mixer_device); | |
365 xmms_cfg_read_int (cfgfile, section, "oss_fragments", &config->oss_fragments); | |
366 xmms_cfg_read_int (cfgfile, section, "oss_fragment_size", &config->oss_fragment_size); | |
367 xmms_cfg_read_boolean(cfgfile, section, "volnorm_enable", &config->volnorm_enable); | |
368 xmms_cfg_read_boolean(cfgfile, section, "volnorm_use_qa", &config->volnorm_use_qa); | |
369 xmms_cfg_read_int (cfgfile, section, "volnorm_target", &config->volnorm_target); | |
370 xmms_cfg_read_boolean(cfgfile, section, "output_keep_opened", &config->output_keep_opened); | |
371 xmms_cfg_read_boolean(cfgfile, section, "mixer_software", &config->mixer_software); | |
372 xmms_cfg_read_int (cfgfile, section, "mixer_vol_left", &config->mixer_vol_left); | |
373 xmms_cfg_read_int (cfgfile, section, "mixer_vol_right", &config->mixer_vol_right); | |
374 | |
375 /* config items introduced by v0.3.2 */ | |
376 xmms_cfg_read_boolean(cfgfile, section, "no_xfade_if_same_file",&config->no_xfade_if_same_file); | |
377 | |
378 /* config items introduced by v0.3.3 */ | |
379 xmms_cfg_read_string (cfgfile, section, "alt_mixer_device", &config->oss_alt_mixer_device); | |
380 xmms_cfg_read_boolean(cfgfile, section, "gap_crossing", &config->gap_crossing); | |
381 | |
382 /* config items introduced by v0.3.6 */ | |
383 xmms_cfg_read_int (cfgfile, section, "output_quality", &config->output_quality); | |
384 | |
385 /* fade configs */ | |
386 read_fade_config(cfgfile, section, "fc_xfade", &config->fc[FADE_CONFIG_XFADE]); | |
387 read_fade_config(cfgfile, section, "fc_manual", &config->fc[FADE_CONFIG_MANUAL]); | |
388 read_fade_config(cfgfile, section, "fc_album", &config->fc[FADE_CONFIG_ALBUM]); | |
389 read_fade_config(cfgfile, section, "fc_start", &config->fc[FADE_CONFIG_START]); | |
390 read_fade_config(cfgfile, section, "fc_stop", &config->fc[FADE_CONFIG_STOP]); | |
391 read_fade_config(cfgfile, section, "fc_eop", &config->fc[FADE_CONFIG_EOP]); | |
392 read_fade_config(cfgfile, section, "fc_seek", &config->fc[FADE_CONFIG_SEEK]); | |
393 read_fade_config(cfgfile, section, "fc_pause", &config->fc[FADE_CONFIG_PAUSE]); | |
394 | |
395 xmms_cfg_free(cfgfile); | |
396 DEBUG(("[crossfade] load_config: configuration loaded\n")); | |
397 } | |
398 else | |
399 DEBUG(("[crossfade] load_config: error loading config, using defaults\n")); | |
400 | |
401 #ifdef PRESET_SUPPORT | |
402 #ifdef COMPILE_FOR_AUDACIOUS | |
403 filename = g_strconcat(g_get_home_dir(), "/.audacious/crossfade-presets", NULL); | |
404 #else | |
405 filename = g_strconcat(g_get_home_dir(), "/.xmms/crossfade-presets", NULL); | |
406 #endif | |
407 scan_presets(filename); | |
408 g_free(filename); | |
409 #endif | |
410 } | |
411 | |
412 void | |
413 xfade_save_config() | |
414 { | |
415 gchar *section = "Crossfade"; | |
416 ConfigFile *cfgfile; | |
417 | |
418 if ((cfgfile = xmms_cfg_open_default_file())) | |
419 { | |
420 /* obsolete config items */ | |
421 xmms_cfg_remove_key(cfgfile, section, "underrun_pct"); | |
422 xmms_cfg_remove_key(cfgfile, section, "enable_crossfade"); | |
423 xmms_cfg_remove_key(cfgfile, section, "enable_gapkiller"); | |
424 xmms_cfg_remove_key(cfgfile, section, "mixer_use_master"); | |
425 xmms_cfg_remove_key(cfgfile, section, "late_effect"); | |
426 xmms_cfg_remove_key(cfgfile, section, "gap_lead_length"); | |
427 | |
428 /* config items used in v0.1 */ | |
429 xmms_cfg_write_int (cfgfile, section, "output_method", config->output_method); | |
430 xmms_cfg_write_int (cfgfile, section, "audio_device", config->oss_audio_device); | |
431 xmms_cfg_write_boolean(cfgfile, section, "use_alt_audio_device", config->oss_use_alt_audio_device); | |
432 xmms_cfg_write_string (cfgfile, section, "alt_audio_device", config->oss_alt_audio_device ? config->oss_alt_audio_device : DEFAULT_OSS_ALT_AUDIO_DEVICE); | |
433 xmms_cfg_write_int (cfgfile, section, "mixer_device", config->oss_mixer_device); | |
434 xmms_cfg_write_string (cfgfile, section, "output_plugin", config->op_name ? config->op_name : DEFAULT_OP_NAME); | |
435 xmms_cfg_write_string (cfgfile, section, "op_config_string", config->op_config_string ? config->op_config_string : DEFAULT_OP_CONFIG_STRING); | |
436 xmms_cfg_write_int (cfgfile, section, "buffer_size", config->mix_size_ms); | |
437 xmms_cfg_write_int (cfgfile, section, "sync_size", config->sync_size_ms); | |
438 xmms_cfg_write_int (cfgfile, section, "preload_size", config->preload_size_ms); | |
439 xmms_cfg_write_int (cfgfile, section, "songchange_timeout", config->songchange_timeout); | |
440 xmms_cfg_write_boolean(cfgfile, section, "enable_mixer", config->enable_mixer); | |
441 xmms_cfg_write_boolean(cfgfile, section, "mixer_reverse", config->mixer_reverse); | |
442 xmms_cfg_write_boolean(cfgfile, section, "enable_debug", config->enable_debug); | |
443 xmms_cfg_write_boolean(cfgfile, section, "enable_monitor", config->enable_monitor); | |
444 | |
445 /* config items introduced by v0.2 */ | |
446 xmms_cfg_write_int (cfgfile, section, "oss_buffer_size", config->oss_buffer_size_ms); | |
447 xmms_cfg_write_int (cfgfile, section, "oss_preload_size", config->oss_preload_size_ms); | |
448 xmms_cfg_write_boolean(cfgfile, section, "oss_mixer_use_master", config->oss_mixer_use_master); | |
449 xmms_cfg_write_boolean(cfgfile, section, "gap_lead_enable", config->gap_lead_enable); | |
450 xmms_cfg_write_int (cfgfile, section, "gap_lead_len_ms", config->gap_lead_len_ms); | |
451 xmms_cfg_write_int (cfgfile, section, "gap_lead_level", config->gap_lead_level); | |
452 xmms_cfg_write_boolean(cfgfile, section, "gap_trail_enable", config->gap_trail_enable); | |
453 xmms_cfg_write_int (cfgfile, section, "gap_trail_len_ms", config->gap_trail_len_ms); | |
454 xmms_cfg_write_int (cfgfile, section, "gap_trail_level", config->gap_trail_level); | |
455 xmms_cfg_write_int (cfgfile, section, "gap_trail_locked", config->gap_trail_locked); | |
456 | |
457 /* config items introduced by v0.2.1 */ | |
458 xmms_cfg_write_boolean(cfgfile, section, "buffer_size_auto", config->mix_size_auto); | |
459 | |
460 /* config items introduced by v0.2.3 */ | |
461 xmms_cfg_write_boolean(cfgfile, section, "album_detection", config->album_detection); | |
462 | |
463 /* config items introduced by v0.2.4 */ | |
464 xmms_cfg_write_boolean(cfgfile, section, "http_workaround", config->enable_http_workaround); | |
465 xmms_cfg_write_boolean(cfgfile, section, "enable_op_max_used", config->enable_op_max_used); | |
466 xmms_cfg_write_int (cfgfile, section, "op_max_used_ms", config->op_max_used_ms); | |
467 | |
468 /* config items introduced by v0.2.6 */ | |
469 xmms_cfg_write_string (cfgfile, section, "effect_plugin", config->ep_name ? config->ep_name : DEFAULT_EP_NAME); | |
470 xmms_cfg_write_boolean(cfgfile, section, "effect_enable", config->ep_enable); | |
471 xmms_cfg_write_int (cfgfile, section, "output_rate", config->output_rate); | |
472 | |
473 /* config items introduced by v0.2.7 */ | |
474 xmms_cfg_write_boolean(cfgfile, section, "oss_maxbuf_enable", config->oss_maxbuf_enable); | |
475 | |
476 /* config items introduced by v0.3.0 */ | |
477 xmms_cfg_write_boolean(cfgfile, section, "use_alt_mixer_device", config->oss_use_alt_mixer_device); | |
478 xmms_cfg_write_int (cfgfile, section, "oss_fragments", config->oss_fragments); | |
479 xmms_cfg_write_int (cfgfile, section, "oss_fragment_size", config->oss_fragment_size); | |
480 #ifdef VOLUME_NORMALIZER | |
481 xmms_cfg_write_boolean(cfgfile, section, "volnorm_enable", config->volnorm_enable); | |
482 xmms_cfg_write_boolean(cfgfile, section, "volnorm_use_qa", config->volnorm_use_qa); | |
483 xmms_cfg_write_int (cfgfile, section, "volnorm_target", config->volnorm_target); | |
484 #endif | |
485 xmms_cfg_write_boolean(cfgfile, section, "output_keep_opened", config->output_keep_opened); | |
486 xmms_cfg_write_boolean(cfgfile, section, "mixer_software", config->mixer_software); | |
487 xmms_cfg_write_int (cfgfile, section, "mixer_vol_left", config->mixer_vol_left); | |
488 xmms_cfg_write_int (cfgfile, section, "mixer_vol_right", config->mixer_vol_right); | |
489 | |
490 /* config items introduced by v0.3.2 */ | |
491 xmms_cfg_write_boolean(cfgfile, section, "no_xfade_if_same_file",config->no_xfade_if_same_file); | |
492 | |
493 /* config items introduced by v0.3.2 */ | |
494 xmms_cfg_write_string (cfgfile, section, "alt_mixer_device", config->oss_alt_mixer_device ? config->oss_alt_mixer_device : DEFAULT_OSS_ALT_MIXER_DEVICE); | |
495 xmms_cfg_write_boolean(cfgfile, section, "gap_crossing", config->gap_crossing); | |
496 | |
497 /* config items introduced by v0.3.6 */ | |
498 xmms_cfg_write_int(cfgfile, section, "output_quality", config->output_quality); | |
499 | |
500 /* fade configs */ | |
501 write_fade_config(cfgfile, section, "fc_xfade", &config->fc[FADE_CONFIG_XFADE]); | |
502 write_fade_config(cfgfile, section, "fc_manual", &config->fc[FADE_CONFIG_MANUAL]); | |
503 write_fade_config(cfgfile, section, "fc_album", &config->fc[FADE_CONFIG_ALBUM]); | |
504 write_fade_config(cfgfile, section, "fc_start", &config->fc[FADE_CONFIG_START]); | |
505 write_fade_config(cfgfile, section, "fc_stop", &config->fc[FADE_CONFIG_STOP]); | |
506 write_fade_config(cfgfile, section, "fc_eop", &config->fc[FADE_CONFIG_EOP]); | |
507 write_fade_config(cfgfile, section, "fc_seek", &config->fc[FADE_CONFIG_SEEK]); | |
508 write_fade_config(cfgfile, section, "fc_pause", &config->fc[FADE_CONFIG_PAUSE]); | |
509 /* *INDENT-ON* */ | |
510 | |
511 xmms_cfg_write_default_file(cfgfile); | |
512 xmms_cfg_free(cfgfile); | |
513 DEBUG(("[crossfade] save_config: configuration saved\n")); | |
514 } | |
515 else | |
516 DEBUG(("[crossfade] save_config: error saving configuration!\n")); | |
517 } | |
518 | |
519 #define SAFE_FREE(x) if(x) { g_free(x); x = NULL; } | |
520 void | |
521 xfade_free_config() | |
522 { | |
523 SAFE_FREE(xfg->oss_alt_audio_device); | |
524 SAFE_FREE(xfg->oss_alt_mixer_device); | |
525 SAFE_FREE(xfg->op_config_string); | |
526 SAFE_FREE(xfg->op_name); | |
527 | |
528 g_list_foreach(config->presets, g_free_f, NULL); | |
529 g_list_free(config->presets); | |
530 config->presets = NULL; | |
531 } | |
532 | |
533 void | |
534 xfade_load_plugin_config(gchar *config_string, gchar *plugin_name, plugin_config_t *plugin_config) | |
535 { | |
536 update_plugin_config(&config_string, plugin_name, plugin_config, FALSE); | |
537 } | |
538 | |
539 void | |
540 xfade_save_plugin_config(gchar **config_string, gchar *plugin_name, plugin_config_t *plugin_config) | |
541 { | |
542 update_plugin_config(config_string, plugin_name, plugin_config, TRUE); | |
543 } | |
544 | |
545 /*** helpers *****************************************************************/ | |
546 | |
547 gint | |
548 xfade_cfg_out_skip(fade_config_t *fc) | |
549 { | |
550 if (!fc) | |
551 return 0; | |
552 | |
553 switch (fc->config) | |
554 { | |
555 case FADE_CONFIG_TIMING: | |
556 return fc->out_skip_ms; | |
557 } | |
558 return 0; | |
559 } | |
560 | |
561 gint | |
562 xfade_cfg_fadeout_len(fade_config_t *fc) | |
563 { | |
564 if (!fc) | |
565 return 0; | |
566 | |
567 switch (fc->type) | |
568 { | |
569 case FADE_TYPE_SIMPLE_XF: | |
570 return fc->simple_len_ms; | |
571 | |
572 case FADE_TYPE_ADVANCED_XF: | |
573 return fc->out_enable ? fc->out_len_ms : 0; | |
574 | |
575 case FADE_TYPE_FADEOUT: | |
576 case FADE_TYPE_PAUSE_ADV: | |
577 return fc->out_len_ms; | |
578 } | |
579 return 0; | |
580 } | |
581 | |
582 gint | |
583 xfade_cfg_fadeout_volume(fade_config_t *fc) | |
584 { | |
585 gint volume; | |
586 if (!fc) | |
587 return 0; | |
588 | |
589 switch (fc->type) | |
590 { | |
591 case FADE_TYPE_ADVANCED_XF: | |
592 case FADE_TYPE_FADEOUT: | |
593 volume = fc->out_volume; | |
594 if (volume < 0) volume = 0; | |
595 if (volume > 100) volume = 100; | |
596 return volume; | |
597 } | |
598 return 0; | |
599 } | |
600 | |
601 gint | |
602 xfade_cfg_offset(fade_config_t *fc) | |
603 { | |
604 if (!fc) | |
605 return 0; | |
606 | |
607 switch (fc->type) | |
608 { | |
609 case FADE_TYPE_FLUSH: | |
610 return fc->flush_pause_enable ? fc->flush_pause_len_ms : 0; | |
611 | |
612 case FADE_TYPE_PAUSE: | |
613 return fc->pause_len_ms; | |
614 | |
615 case FADE_TYPE_SIMPLE_XF: | |
616 return -fc->simple_len_ms; | |
617 | |
618 case FADE_TYPE_ADVANCED_XF: | |
619 switch (fc->ofs_type) | |
620 { | |
621 case FC_OFFSET_LOCK_OUT: return -fc->out_len_ms; | |
622 case FC_OFFSET_LOCK_IN: return -fc->in_len_ms; | |
623 case FC_OFFSET_CUSTOM: return fc->ofs_custom_ms; | |
624 } | |
625 return 0; | |
626 | |
627 case FADE_TYPE_FADEOUT: | |
628 case FADE_TYPE_PAUSE_ADV: | |
629 return fc->ofs_custom_ms; | |
630 } | |
631 return 0; | |
632 } | |
633 | |
634 gint | |
635 xfade_cfg_in_skip(fade_config_t *fc) | |
636 { | |
637 if (!fc) | |
638 return 0; | |
639 | |
640 switch (fc->config) | |
641 { | |
642 case FADE_CONFIG_TIMING: | |
643 return fc->in_skip_ms; | |
644 } | |
645 return 0; | |
646 } | |
647 | |
648 gint | |
649 xfade_cfg_fadein_len(fade_config_t *fc) | |
650 { | |
651 if (!fc) | |
652 return 0; | |
653 | |
654 switch (fc->type) | |
655 { | |
656 case FADE_TYPE_FLUSH: | |
657 return fc->flush_in_enable ? fc->flush_in_len_ms : 0; | |
658 | |
659 case FADE_TYPE_SIMPLE_XF: | |
660 return fc->simple_len_ms; | |
661 | |
662 case FADE_TYPE_ADVANCED_XF: | |
663 return fc->in_locked | |
664 ? (fc->out_enable ? fc->out_len_ms : 0) | |
665 : (fc->in_enable ? fc->in_len_ms : 0); | |
666 | |
667 case FADE_TYPE_FADEIN: | |
668 case FADE_TYPE_PAUSE_ADV: | |
669 return fc->in_len_ms; | |
670 } | |
671 return 0; | |
672 } | |
673 | |
674 gint | |
675 xfade_cfg_fadein_volume(fade_config_t *fc) | |
676 { | |
677 gint volume; | |
678 if (!fc) | |
679 return 0; | |
680 | |
681 switch (fc->type) | |
682 { | |
683 case FADE_TYPE_FLUSH: | |
684 volume = fc->flush_in_volume; | |
685 break; | |
686 | |
687 case FADE_TYPE_ADVANCED_XF: | |
688 volume = fc->in_locked ? fc->out_volume : fc->in_volume; | |
689 break; | |
690 | |
691 case FADE_TYPE_FADEIN: | |
692 volume = fc->in_volume; | |
693 break; | |
694 | |
695 default: | |
696 volume = 0; | |
697 } | |
698 | |
699 if (volume < 0) volume = 0; | |
700 if (volume > 100) volume = 100; | |
701 return volume; | |
702 } | |
703 | |
704 gboolean | |
705 xfade_cfg_gap_trail_enable(config_t *cfg) | |
706 { | |
707 return xfg->gap_trail_locked ? xfg->gap_lead_enable : xfg->gap_trail_enable; | |
708 } | |
709 | |
710 gint | |
711 xfade_cfg_gap_trail_len(config_t *cfg) | |
712 { | |
713 if (!xfade_cfg_gap_trail_enable(cfg)) | |
714 return 0; | |
715 | |
716 return xfg->gap_trail_locked ? xfg->gap_lead_len_ms : xfg->gap_trail_len_ms; | |
717 } | |
718 | |
719 gint | |
720 xfade_cfg_gap_trail_level(config_t *cfg) | |
721 { | |
722 return xfg->gap_trail_locked ? xfg->gap_lead_level : xfg->gap_trail_level; | |
723 } | |
724 | |
725 gint | |
726 xfade_mix_size_ms(config_t *cfg) | |
727 { | |
728 if (xfg->mix_size_auto) | |
729 { | |
730 gint i, min_size = 0; | |
731 | |
732 for (i = 0; i < MAX_FADE_CONFIGS; i++) | |
733 { | |
734 gint size = xfade_cfg_fadeout_len(&xfg->fc[i]); | |
735 gint offset = xfade_cfg_offset(&xfg->fc[i]); | |
736 | |
737 if (xfg->fc[i].type == FADE_TYPE_PAUSE_ADV) | |
738 size += xfade_cfg_fadein_len(&xfg->fc[i]); | |
739 | |
740 if (size < -offset) | |
741 size = -offset; | |
742 | |
743 if (size > min_size) | |
744 min_size = size; | |
745 } | |
746 return min_size += xfade_cfg_gap_trail_len(cfg) + xfg->songchange_timeout; | |
747 } | |
748 else | |
749 return xfg->mix_size_ms; | |
750 } | |
751 | |
752 /*****************************************************************************/ |