Mercurial > audlegacy-plugins
annotate src/flacng/tools.c @ 3027:3b200cf6d1b7
Support comment tag in FLAC files. By Brent Towe, resolves bug #4.
author | Tony Vroon <chainsaw@gentoo.org> |
---|---|
date | Fri, 10 Apr 2009 00:30:15 +0100 |
parents | 2cdf6400594c |
children |
rev | line source |
---|---|
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
1 /* |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
2 * A FLAC decoder plugin for the Audacious Media Player |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
3 * Copyright (C) 2005 Ralf Ertzinger |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
4 * |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
5 * This program is free software; you can redistribute it and/or modify |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
6 * it under the terms of the GNU General Public License as published by |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
7 * the Free Software Foundation; either version 2 of the License, or |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
8 * (at your option) any later version. |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
9 * |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
10 * This program is distributed in the hope that it will be useful, |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
13 * GNU General Public License for more details. |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
14 * |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
16 * along with this program; if not, write to the Free Software |
2835 | 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
18 */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
19 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
20 #include <string.h> |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
21 #include <strings.h> |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
22 #include "tools.h" |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
23 #include "debug.h" |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
24 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
25 /* === */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
26 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
27 callback_info* init_callback_info(gchar* name) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
28 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
29 callback_info* info; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
30 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
31 _ENTER; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
32 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
33 if (NULL == name) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
34 _ERROR("Can not allocate callback structure without a name"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
35 _LEAVE NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
36 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
37 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
38 if (NULL == (info = malloc(sizeof(callback_info)))) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
39 _ERROR("Could not allocate memory for callback structure!"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
40 _LEAVE NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
41 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
42 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
43 if (NULL == (info->output_buffer = malloc(BUFFER_SIZE_BYTE))) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
44 _ERROR("Could not allocate memory for output buffer!"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
45 _LEAVE NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
46 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
47 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
48 /* |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
49 * We need to set this manually to NULL because |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
50 * reset_info will try to close the file pointed to |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
51 * by input_stream if it is non-NULL. |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
52 * Same for info->comment.x |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
53 */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
54 info->name = name; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
55 info->input_stream = NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
56 info->comment.artist = NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
57 info->comment.album = NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
58 info->comment.title = NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
59 info->comment.tracknumber = NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
60 info->comment.genre = NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
61 info->comment.date = NULL; |
3027
3b200cf6d1b7
Support comment tag in FLAC files. By Brent Towe, resolves bug #4.
Tony Vroon <chainsaw@gentoo.org>
parents:
2991
diff
changeset
|
62 info->comment.comment = NULL; |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
63 info->replaygain.ref_loud = NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
64 info->replaygain.track_gain = NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
65 info->replaygain.track_peak = NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
66 info->replaygain.album_gain = NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
67 info->replaygain.album_peak = NULL; |
1272
47559538ce3d
- stop read_metadata from stomping on the wrong file descriptors
Ralf Ertzinger <ralf@skytale.net>
parents:
1255
diff
changeset
|
68 reset_info(info, FALSE); |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
69 |
1401
263d72004333
- Introduce a mutex for test_info and lock appropriately
Ralf Ertzinger <ralf@skytale.net>
parents:
1272
diff
changeset
|
70 info->mutex = g_mutex_new(); |
263d72004333
- Introduce a mutex for test_info and lock appropriately
Ralf Ertzinger <ralf@skytale.net>
parents:
1272
diff
changeset
|
71 |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
72 _DEBUG("Playback buffer allocated for %d samples, %d bytes", BUFFER_SIZE_SAMP, BUFFER_SIZE_BYTE); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
73 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
74 _LEAVE info; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
75 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
76 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
77 /* --- */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
78 |
2266
5395c85a8724
Make flacng plugin to clean up after itself (Bugzilla #19)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
2140
diff
changeset
|
79 void clean_callback_info(callback_info* info) |
5395c85a8724
Make flacng plugin to clean up after itself (Bugzilla #19)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
2140
diff
changeset
|
80 { |
5395c85a8724
Make flacng plugin to clean up after itself (Bugzilla #19)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
2140
diff
changeset
|
81 g_mutex_free(info->mutex); |
5395c85a8724
Make flacng plugin to clean up after itself (Bugzilla #19)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
2140
diff
changeset
|
82 free(info->output_buffer); |
5395c85a8724
Make flacng plugin to clean up after itself (Bugzilla #19)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
2140
diff
changeset
|
83 free(info); |
5395c85a8724
Make flacng plugin to clean up after itself (Bugzilla #19)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
2140
diff
changeset
|
84 } |
5395c85a8724
Make flacng plugin to clean up after itself (Bugzilla #19)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
2140
diff
changeset
|
85 |
5395c85a8724
Make flacng plugin to clean up after itself (Bugzilla #19)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
2140
diff
changeset
|
86 /* --- */ |
5395c85a8724
Make flacng plugin to clean up after itself (Bugzilla #19)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
2140
diff
changeset
|
87 |
1272
47559538ce3d
- stop read_metadata from stomping on the wrong file descriptors
Ralf Ertzinger <ralf@skytale.net>
parents:
1255
diff
changeset
|
88 void reset_info(callback_info* info, gboolean close_fd) { |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
89 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
90 _ENTER; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
91 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
92 _DEBUG("Using callback_info %s", info->name); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
93 |
1272
47559538ce3d
- stop read_metadata from stomping on the wrong file descriptors
Ralf Ertzinger <ralf@skytale.net>
parents:
1255
diff
changeset
|
94 if (close_fd && (NULL != info->input_stream)) { |
47559538ce3d
- stop read_metadata from stomping on the wrong file descriptors
Ralf Ertzinger <ralf@skytale.net>
parents:
1255
diff
changeset
|
95 _DEBUG("Closing fd"); |
1978 | 96 aud_vfs_fclose(info->input_stream); |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
97 } |
1272
47559538ce3d
- stop read_metadata from stomping on the wrong file descriptors
Ralf Ertzinger <ralf@skytale.net>
parents:
1255
diff
changeset
|
98 info->input_stream = NULL; |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
99 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
100 // memset(info->output_buffer, 0, BUFFER_SIZE * sizeof(int16_t)); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
101 info->stream.samplerate = 0; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
102 info->stream.bits_per_sample = 0; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
103 info->stream.channels = 0; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
104 info->stream.samples = 0; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
105 info->stream.has_seektable = FALSE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
106 info->buffer_free = BUFFER_SIZE_SAMP; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
107 info->buffer_used = 0; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
108 info->write_pointer = info->output_buffer; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
109 info->read_max = -1; |
1041 | 110 info->testing = FALSE; |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
111 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
112 /* |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
113 * Clear the stream and frame information |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
114 */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
115 info->stream.bits_per_sample = 0; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
116 info->stream.samplerate = 0; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
117 info->stream.channels = 0; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
118 info->stream.samples = 0; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
119 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
120 if (NULL != info->comment.artist) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
121 free(info->comment.artist); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
122 info->comment.artist = NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
123 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
124 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
125 if (NULL != info->comment.album) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
126 free(info->comment.album); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
127 info->comment.album = NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
128 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
129 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
130 if (NULL != info->comment.title) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
131 free(info->comment.title); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
132 info->comment.title = NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
133 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
134 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
135 if (NULL != info->comment.tracknumber) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
136 free(info->comment.tracknumber); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
137 info->comment.tracknumber = NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
138 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
139 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
140 if (NULL != info->comment.genre) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
141 free(info->comment.genre); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
142 info->comment.genre = NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
143 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
144 |
3027
3b200cf6d1b7
Support comment tag in FLAC files. By Brent Towe, resolves bug #4.
Tony Vroon <chainsaw@gentoo.org>
parents:
2991
diff
changeset
|
145 if (NULL != info->comment.comment) { |
3b200cf6d1b7
Support comment tag in FLAC files. By Brent Towe, resolves bug #4.
Tony Vroon <chainsaw@gentoo.org>
parents:
2991
diff
changeset
|
146 free(info->comment.comment); |
3b200cf6d1b7
Support comment tag in FLAC files. By Brent Towe, resolves bug #4.
Tony Vroon <chainsaw@gentoo.org>
parents:
2991
diff
changeset
|
147 info->comment.comment = NULL; |
3b200cf6d1b7
Support comment tag in FLAC files. By Brent Towe, resolves bug #4.
Tony Vroon <chainsaw@gentoo.org>
parents:
2991
diff
changeset
|
148 } |
3b200cf6d1b7
Support comment tag in FLAC files. By Brent Towe, resolves bug #4.
Tony Vroon <chainsaw@gentoo.org>
parents:
2991
diff
changeset
|
149 |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
150 if (NULL != info->replaygain.ref_loud) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
151 free(info->replaygain.ref_loud); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
152 info->replaygain.ref_loud = NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
153 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
154 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
155 if (NULL != info->replaygain.track_gain) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
156 free(info->replaygain.track_gain); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
157 info->replaygain.track_gain = NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
158 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
159 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
160 if (NULL != info->replaygain.track_peak) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
161 free(info->replaygain.track_peak); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
162 info->replaygain.track_peak = NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
163 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
164 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
165 if (NULL != info->replaygain.album_gain) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
166 free(info->replaygain.album_gain); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
167 info->replaygain.album_gain = NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
168 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
169 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
170 if (NULL != info->replaygain.album_peak) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
171 free(info->replaygain.album_peak); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
172 info->replaygain.album_peak = NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
173 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
174 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
175 info->replaygain.has_rg = FALSE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
176 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
177 if (NULL != info->comment.date) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
178 free(info->comment.date); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
179 info->comment.date = NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
180 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
181 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
182 info->frame.bits_per_sample = 0; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
183 info->frame.samplerate = 0; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
184 info->frame.channels = 0; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
185 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
186 info->metadata_changed = FALSE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
187 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
188 _LEAVE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
189 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
190 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
191 /* --- */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
192 |
1255 | 193 gboolean read_metadata(VFSFile* fd, FLAC__StreamDecoder* decoder, callback_info* info) { |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
194 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
195 FLAC__StreamDecoderState ret; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
196 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
197 _ENTER; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
198 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
199 _DEBUG("Using callback_info %s", info->name); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
200 |
1272
47559538ce3d
- stop read_metadata from stomping on the wrong file descriptors
Ralf Ertzinger <ralf@skytale.net>
parents:
1255
diff
changeset
|
201 reset_info(info, FALSE); |
47559538ce3d
- stop read_metadata from stomping on the wrong file descriptors
Ralf Ertzinger <ralf@skytale.net>
parents:
1255
diff
changeset
|
202 |
47559538ce3d
- stop read_metadata from stomping on the wrong file descriptors
Ralf Ertzinger <ralf@skytale.net>
parents:
1255
diff
changeset
|
203 info->input_stream = fd; |
47559538ce3d
- stop read_metadata from stomping on the wrong file descriptors
Ralf Ertzinger <ralf@skytale.net>
parents:
1255
diff
changeset
|
204 |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
205 /* |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
206 * Reset the decoder |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
207 */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
208 if (false == FLAC__stream_decoder_reset(decoder)) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
209 _ERROR("Could not reset the decoder!"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
210 _LEAVE FALSE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
211 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
212 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
213 /* |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
214 * Just scan the first 8k for the start of metadata |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
215 */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
216 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
217 info->read_max = 8192; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
218 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
219 /* |
1041 | 220 * We are not sure if this is an actual flac file, so do not |
221 * complain too much about errors in the stream | |
222 */ | |
223 info->testing = TRUE; | |
224 | |
225 /* | |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
226 * Try to decode the metadata |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
227 */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
228 if (false == FLAC__stream_decoder_process_until_end_of_metadata(decoder)) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
229 ret = FLAC__stream_decoder_get_state(decoder); |
1246 | 230 _DEBUG("Could not read the metadata: %s(%d)!", |
231 FLAC__StreamDecoderStateString[ret], ret); | |
1255 | 232 /* Do not close the filehandle, it was passed to us */ |
1272
47559538ce3d
- stop read_metadata from stomping on the wrong file descriptors
Ralf Ertzinger <ralf@skytale.net>
parents:
1255
diff
changeset
|
233 reset_info(info, FALSE); |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
234 _LEAVE FALSE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
235 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
236 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
237 /* |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
238 * Seems to be a FLAC stream. Allow further reading |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
239 */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
240 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
241 info->read_max = -1; |
1041 | 242 info->testing = FALSE; |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
243 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
244 _LEAVE TRUE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
245 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
246 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
247 /* --- */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
248 |
1435
654aa79e43ef
flacng: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents:
1401
diff
changeset
|
249 Tuple* get_tuple(const gchar* filename, callback_info* info) { |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
250 |
1435
654aa79e43ef
flacng: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents:
1401
diff
changeset
|
251 Tuple *out; |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
252 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
253 _ENTER; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
254 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
255 _DEBUG("Using callback_info %s", info->name); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
256 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
257 out = aud_tuple_new_from_filename(filename); |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
258 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
259 aud_tuple_associate_string(out, FIELD_CODEC, NULL, "Free Lossless Audio Codec (FLAC)"); |
2140
1ebc33b0a608
flacng: tuple builder: fix codec/quality assignment
William Pitcock <nenolod@atheme.org>
parents:
2055
diff
changeset
|
260 aud_tuple_associate_string(out, FIELD_QUALITY, NULL, "lossless"); |
1459
4afd6954159d
hook up ${codec} and ${quality}
William Pitcock <nenolod@atheme-project.org>
parents:
1435
diff
changeset
|
261 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
262 aud_tuple_associate_string(out, FIELD_ARTIST, NULL, info->comment.artist); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
263 aud_tuple_associate_string(out, FIELD_TITLE, NULL, info->comment.title); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
264 aud_tuple_associate_string(out, FIELD_ALBUM, NULL, info->comment.album); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
265 aud_tuple_associate_string(out, FIELD_GENRE, NULL, info->comment.genre); |
3027
3b200cf6d1b7
Support comment tag in FLAC files. By Brent Towe, resolves bug #4.
Tony Vroon <chainsaw@gentoo.org>
parents:
2991
diff
changeset
|
266 aud_tuple_associate_string(out, FIELD_COMMENT, NULL, info->comment.comment); |
1435
654aa79e43ef
flacng: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents:
1401
diff
changeset
|
267 |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
268 if (info->comment.tracknumber != NULL) |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
269 aud_tuple_associate_int(out, FIELD_TRACK_NUMBER, NULL, atoi(info->comment.tracknumber)); |
1435
654aa79e43ef
flacng: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents:
1401
diff
changeset
|
270 |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
271 if (info->comment.date != NULL) |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
272 aud_tuple_associate_int(out, FIELD_YEAR, NULL, atoi(info->comment.date)); |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
273 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
274 /* |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
275 * Calculate the stream length (milliseconds) |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
276 */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
277 if (0 == info->stream.samplerate) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
278 _ERROR("Invalid sample rate for stream!"); |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
279 aud_tuple_associate_int(out, FIELD_LENGTH, NULL, -1); |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
280 } else { |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
281 aud_tuple_associate_int(out, FIELD_LENGTH, NULL, (info->stream.samples / info->stream.samplerate) * 1000); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
282 _DEBUG("Stream length: %d seconds", aud_tuple_get_int(out, FIELD_LENGTH, NULL)); |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
283 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
284 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
285 _DEBUG("Tuple created: [%p]", out); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
286 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
287 _LEAVE out; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
288 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
289 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
290 /* --- */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
291 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
292 gchar* get_title(const gchar* filename, callback_info* info) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
293 |
1435
654aa79e43ef
flacng: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents:
1401
diff
changeset
|
294 Tuple *input; |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
295 gchar *title; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
296 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
297 _ENTER; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
298 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
299 _DEBUG("Using callback_info %s", info->name); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
300 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
301 input = get_tuple(filename, info); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
302 |
2055 | 303 title = aud_tuple_formatter_make_title_string(input, aud_get_gentitle_format()); |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
304 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
305 aud_tuple_free(input); |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
306 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
307 _DEBUG("Title created: <%s>", title); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
308 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
309 _LEAVE title; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
310 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
311 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
312 /* --- */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
313 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
314 void add_comment(callback_info* info, gchar* key, gchar* value) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
315 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
316 /* |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
317 * We are currently interested in comments of type |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
318 * - ARTIST |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
319 * - ALBUM |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
320 * - TITLE |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
321 * - TRACKNUMBER |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
322 * |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
323 * We have to create copies of the value string. |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
324 */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
325 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
326 gchar** destination = NULL; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
327 gboolean rg = FALSE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
328 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
329 _ENTER; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
330 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
331 _DEBUG("Using callback_info %s", info->name); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
332 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
333 if (0 == strcasecmp(key, "ARTIST")) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
334 _DEBUG("Found key ARTIST"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
335 destination = &(info->comment.artist); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
336 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
337 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
338 if (0 == strcasecmp(key, "ALBUM")) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
339 _DEBUG("Found key ALBUM"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
340 destination = &(info->comment.album); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
341 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
342 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
343 if (0 == strcasecmp(key, "TITLE")) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
344 _DEBUG("Found key TITLE"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
345 destination = &(info->comment.title); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
346 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
347 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
348 if (0 == strcasecmp(key, "TRACKNUMBER")) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
349 _DEBUG("Found key TRACKNUMBER"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
350 destination = &(info->comment.tracknumber); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
351 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
352 |
3027
3b200cf6d1b7
Support comment tag in FLAC files. By Brent Towe, resolves bug #4.
Tony Vroon <chainsaw@gentoo.org>
parents:
2991
diff
changeset
|
353 if (0 == strcasecmp(key, "DESCRIPTION")) { |
3b200cf6d1b7
Support comment tag in FLAC files. By Brent Towe, resolves bug #4.
Tony Vroon <chainsaw@gentoo.org>
parents:
2991
diff
changeset
|
354 _DEBUG("Found key DESCRIPTION"); |
3b200cf6d1b7
Support comment tag in FLAC files. By Brent Towe, resolves bug #4.
Tony Vroon <chainsaw@gentoo.org>
parents:
2991
diff
changeset
|
355 destination = &(info->comment.comment); |
3b200cf6d1b7
Support comment tag in FLAC files. By Brent Towe, resolves bug #4.
Tony Vroon <chainsaw@gentoo.org>
parents:
2991
diff
changeset
|
356 } |
3b200cf6d1b7
Support comment tag in FLAC files. By Brent Towe, resolves bug #4.
Tony Vroon <chainsaw@gentoo.org>
parents:
2991
diff
changeset
|
357 |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
358 if (0 == strcasecmp(key, "REPLAYGAIN_REFERENCE_LOUDNESS")) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
359 _DEBUG("Found key REPLAYGAIN_REFERENCE_LOUDNESS"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
360 destination = &(info->replaygain.ref_loud); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
361 rg = TRUE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
362 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
363 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
364 if (0 == strcasecmp(key, "REPLAYGAIN_TRACK_GAIN")) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
365 _DEBUG("Found key REPLAYGAIN_TRACK_GAIN"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
366 destination = &(info->replaygain.track_gain); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
367 rg = TRUE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
368 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
369 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
370 if (0 == strcasecmp(key, "REPLAYGAIN_TRACK_PEAK")) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
371 _DEBUG("Found key REPLAYGAIN_TRACK_PEAK"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
372 destination = &(info->replaygain.track_peak); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
373 rg = TRUE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
374 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
375 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
376 if (0 == strcasecmp(key, "REPLAYGAIN_ALBUM_GAIN")) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
377 _DEBUG("Found key REPLAYGAIN_ALBUM_GAIN"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
378 destination = &(info->replaygain.album_gain); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
379 rg = TRUE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
380 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
381 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
382 if (0 == strcasecmp(key, "REPLAYGAIN_ALBUM_PEAK")) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
383 _DEBUG("Found key REPLAYGAIN_ALBUM_PEAK"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
384 destination = &(info->replaygain.album_peak); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
385 rg = TRUE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
386 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
387 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
388 if (0 == strcasecmp(key, "DATE")) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
389 _DEBUG("Found key DATE"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
390 destination = &(info->comment.date); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
391 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
392 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
393 if (0 == strcasecmp(key, "GENRE")) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
394 _DEBUG("Found key GENRE"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
395 destination = &(info->comment.genre); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
396 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
397 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
398 if (NULL != destination) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
399 if (NULL != *destination) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
400 g_free(*destination); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
401 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
402 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
403 if (NULL == (*destination = g_strdup(value))) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
404 _ERROR("Could not allocate memory for comment!"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
405 _LEAVE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
406 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
407 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
408 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
409 if (rg) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
410 info->replaygain.has_rg = TRUE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
411 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
412 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
413 _LEAVE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
414 } |
2991 | 415 |
416 /* --- */ | |
417 | |
418 ReplayGainInfo get_replay_gain(callback_info *info) { | |
419 | |
420 ReplayGainInfo rg; | |
421 | |
422 if (info->replaygain.has_rg) { | |
423 rg.track_gain = (info->replaygain.track_gain | |
424 ? atof(info->replaygain.track_gain) | |
425 : 0.0); | |
426 rg.track_peak = (info->replaygain.track_peak | |
427 ? atof(info->replaygain.track_peak) | |
428 : 0.0); | |
429 rg.album_gain = (info->replaygain.album_gain | |
430 ? atof(info->replaygain.album_gain) | |
431 : 0.0); | |
432 rg.album_peak = (info->replaygain.album_peak | |
433 ? atof(info->replaygain.album_peak) | |
434 : 0.0); | |
435 } else { | |
436 rg.track_gain = 0.0; | |
437 rg.track_peak = 0.0; | |
438 rg.album_gain = 0.0; | |
439 rg.album_peak = 0.0; | |
440 } | |
441 | |
442 return rg; | |
443 } |