annotate src/flacng/tools.c @ 2284:d19b53359b24

cleaned up the sndfile wav plugin, currently limiting it ONLY TO WAV PLAYBACK. if somebody is more experienced with it and wants to restore the other formats, go ahead (maybe change the name of the plugin too?).
author mf0102 <0102@gmx.at>
date Wed, 09 Jan 2008 15:41:22 +0100
parents 5395c85a8724
children f1b6f1b2cdb3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
62 info->replaygain.ref_loud = NULL;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
63 info->replaygain.track_gain = NULL;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
64 info->replaygain.track_peak = NULL;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
65 info->replaygain.album_gain = NULL;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
66 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
67 reset_info(info, FALSE);
930
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
68
1401
263d72004333 - Introduce a mutex for test_info and lock appropriately
Ralf Ertzinger <ralf@skytale.net>
parents: 1272
diff changeset
69 info->mutex = g_mutex_new();
263d72004333 - Introduce a mutex for test_info and lock appropriately
Ralf Ertzinger <ralf@skytale.net>
parents: 1272
diff changeset
70
930
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
71 _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
72
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
73 _LEAVE info;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
74 }
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
2266
5395c85a8724 Make flacng plugin to clean up after itself (Bugzilla #19)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 2140
diff changeset
78 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
79 {
5395c85a8724 Make flacng plugin to clean up after itself (Bugzilla #19)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 2140
diff changeset
80 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
81 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
82 free(info);
5395c85a8724 Make flacng plugin to clean up after itself (Bugzilla #19)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 2140
diff changeset
83 }
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
1272
47559538ce3d - stop read_metadata from stomping on the wrong file descriptors
Ralf Ertzinger <ralf@skytale.net>
parents: 1255
diff changeset
87 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
88
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
89 _ENTER;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
90
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
91 _DEBUG("Using callback_info %s", info->name);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
92
1272
47559538ce3d - stop read_metadata from stomping on the wrong file descriptors
Ralf Ertzinger <ralf@skytale.net>
parents: 1255
diff changeset
93 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
94 _DEBUG("Closing fd");
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
95 aud_vfs_fclose(info->input_stream);
930
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
96 }
1272
47559538ce3d - stop read_metadata from stomping on the wrong file descriptors
Ralf Ertzinger <ralf@skytale.net>
parents: 1255
diff changeset
97 info->input_stream = NULL;
930
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
98
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
99 // 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
100 info->stream.samplerate = 0;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
101 info->stream.bits_per_sample = 0;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
102 info->stream.channels = 0;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
103 info->stream.samples = 0;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
104 info->stream.has_seektable = FALSE;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
105 info->buffer_free = BUFFER_SIZE_SAMP;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
106 info->buffer_used = 0;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
107 info->write_pointer = info->output_buffer;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
108 info->read_max = -1;
1041
ertzing
parents: 1040
diff changeset
109 info->testing = FALSE;
930
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
110
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 * Clear the stream and frame information
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
113 */
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
114 info->stream.bits_per_sample = 0;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
115 info->stream.samplerate = 0;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
116 info->stream.channels = 0;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
117 info->stream.samples = 0;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
118
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
119 if (NULL != info->comment.artist) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
120 free(info->comment.artist);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
121 info->comment.artist = NULL;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
122 }
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 if (NULL != info->comment.album) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
125 free(info->comment.album);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
126 info->comment.album = NULL;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
127 }
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 if (NULL != info->comment.title) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
130 free(info->comment.title);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
131 info->comment.title = NULL;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
132 }
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 if (NULL != info->comment.tracknumber) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
135 free(info->comment.tracknumber);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
136 info->comment.tracknumber = NULL;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
137 }
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 if (NULL != info->comment.genre) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
140 free(info->comment.genre);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
141 info->comment.genre = NULL;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
142 }
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 if (NULL != info->replaygain.ref_loud) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
145 free(info->replaygain.ref_loud);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
146 info->replaygain.ref_loud = NULL;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
147 }
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
148
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
149 if (NULL != info->replaygain.track_gain) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
150 free(info->replaygain.track_gain);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
151 info->replaygain.track_gain = NULL;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
152 }
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 if (NULL != info->replaygain.track_peak) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
155 free(info->replaygain.track_peak);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
156 info->replaygain.track_peak = NULL;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
157 }
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 if (NULL != info->replaygain.album_gain) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
160 free(info->replaygain.album_gain);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
161 info->replaygain.album_gain = NULL;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
162 }
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 if (NULL != info->replaygain.album_peak) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
165 free(info->replaygain.album_peak);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
166 info->replaygain.album_peak = NULL;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
167 }
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 info->replaygain.has_rg = FALSE;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
170
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
171 if (NULL != info->comment.date) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
172 free(info->comment.date);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
173 info->comment.date = NULL;
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
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
176 info->frame.bits_per_sample = 0;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
177 info->frame.samplerate = 0;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
178 info->frame.channels = 0;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
179
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
180 info->metadata_changed = FALSE;
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 _LEAVE;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
183 }
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
184
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
1255
37598c8f4425 - Add flac_is_our_fd()
Ralf Ertzinger <ralf@skytale.net>
parents: 1246
diff changeset
187 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
188
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
189 FLAC__StreamDecoderState ret;
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 _ENTER;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
192
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
193 _DEBUG("Using callback_info %s", info->name);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
194
1272
47559538ce3d - stop read_metadata from stomping on the wrong file descriptors
Ralf Ertzinger <ralf@skytale.net>
parents: 1255
diff changeset
195 reset_info(info, FALSE);
47559538ce3d - stop read_metadata from stomping on the wrong file descriptors
Ralf Ertzinger <ralf@skytale.net>
parents: 1255
diff changeset
196
47559538ce3d - stop read_metadata from stomping on the wrong file descriptors
Ralf Ertzinger <ralf@skytale.net>
parents: 1255
diff changeset
197 info->input_stream = fd;
47559538ce3d - stop read_metadata from stomping on the wrong file descriptors
Ralf Ertzinger <ralf@skytale.net>
parents: 1255
diff changeset
198
930
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
199 /*
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
200 * Reset the decoder
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
201 */
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
202 if (false == FLAC__stream_decoder_reset(decoder)) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
203 _ERROR("Could not reset the decoder!");
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
204 _LEAVE FALSE;
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
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 * 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
209 */
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
210
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
211 info->read_max = 8192;
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 /*
1041
ertzing
parents: 1040
diff changeset
214 * We are not sure if this is an actual flac file, so do not
ertzing
parents: 1040
diff changeset
215 * complain too much about errors in the stream
ertzing
parents: 1040
diff changeset
216 */
ertzing
parents: 1040
diff changeset
217 info->testing = TRUE;
ertzing
parents: 1040
diff changeset
218
ertzing
parents: 1040
diff changeset
219 /*
930
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
220 * Try to decode the metadata
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
221 */
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
222 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
223 ret = FLAC__stream_decoder_get_state(decoder);
1246
626f78ff2439 - Add FLAC 1.1.2 compatibility
sun@fc5-buildsys
parents: 1044
diff changeset
224 _DEBUG("Could not read the metadata: %s(%d)!",
626f78ff2439 - Add FLAC 1.1.2 compatibility
sun@fc5-buildsys
parents: 1044
diff changeset
225 FLAC__StreamDecoderStateString[ret], ret);
1255
37598c8f4425 - Add flac_is_our_fd()
Ralf Ertzinger <ralf@skytale.net>
parents: 1246
diff changeset
226 /* 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
227 reset_info(info, FALSE);
930
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
228 _LEAVE FALSE;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
229 }
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
230
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
231 /*
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
232 * Seems to be a FLAC stream. Allow further reading
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
233 */
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
234
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
235 info->read_max = -1;
1041
ertzing
parents: 1040
diff changeset
236 info->testing = FALSE;
930
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 _LEAVE TRUE;
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 /* --- */
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
242
1435
654aa79e43ef flacng: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1401
diff changeset
243 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
244
1435
654aa79e43ef flacng: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1401
diff changeset
245 Tuple *out;
930
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 _ENTER;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
248
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
249 _DEBUG("Using callback_info %s", info->name);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
250
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1687
diff changeset
251 out = aud_tuple_new_from_filename(filename);
930
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
252
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1687
diff changeset
253 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
254 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
255
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1687
diff changeset
256 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
257 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
258 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
259 aud_tuple_associate_string(out, FIELD_GENRE, NULL, info->comment.genre);
1435
654aa79e43ef flacng: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1401
diff changeset
260
930
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
261 if (info->comment.tracknumber != NULL)
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1687
diff changeset
262 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
263
930
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
264 if (info->comment.date != NULL)
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1687
diff changeset
265 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
266
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
267 /*
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
268 * Calculate the stream length (milliseconds)
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
269 */
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
270 if (0 == info->stream.samplerate) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
271 _ERROR("Invalid sample rate for stream!");
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1687
diff changeset
272 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
273 } else {
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1687
diff changeset
274 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
275 _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
276 }
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
277
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
278 _DEBUG("Tuple created: [%p]", out);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
279
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
280 _LEAVE out;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
281 }
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
282
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 gchar* get_title(const gchar* filename, callback_info* info) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
286
1435
654aa79e43ef flacng: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents: 1401
diff changeset
287 Tuple *input;
930
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
288 gchar *title;
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 _ENTER;
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 _DEBUG("Using callback_info %s", info->name);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
293
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
294 input = get_tuple(filename, info);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
295
2055
2f2ffbc2d04d gentitle changes
William Pitcock <nenolod@atheme.org>
parents: 1978
diff changeset
296 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
297
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1687
diff changeset
298 aud_tuple_free(input);
930
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
299
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
300 _DEBUG("Title created: <%s>", title);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
301
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
302 _LEAVE title;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
303 }
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
304
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
305 /* --- */
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 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
308
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
309 /*
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
310 * We are currently interested in comments of type
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
311 * - ARTIST
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
312 * - ALBUM
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
313 * - TITLE
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
314 * - TRACKNUMBER
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 * We have to create copies of the value string.
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
317 */
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
318
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
319 gchar** destination = NULL;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
320 gboolean rg = FALSE;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
321
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
322 _ENTER;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
323
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
324 _DEBUG("Using callback_info %s", info->name);
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 if (0 == strcasecmp(key, "ARTIST")) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
327 _DEBUG("Found key ARTIST");
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
328 destination = &(info->comment.artist);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
329 }
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 if (0 == strcasecmp(key, "ALBUM")) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
332 _DEBUG("Found key ALBUM");
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
333 destination = &(info->comment.album);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
334 }
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
335
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
336 if (0 == strcasecmp(key, "TITLE")) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
337 _DEBUG("Found key TITLE");
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
338 destination = &(info->comment.title);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
339 }
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
340
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
341 if (0 == strcasecmp(key, "TRACKNUMBER")) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
342 _DEBUG("Found key TRACKNUMBER");
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
343 destination = &(info->comment.tracknumber);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
344 }
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
345
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
346 if (0 == strcasecmp(key, "REPLAYGAIN_REFERENCE_LOUDNESS")) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
347 _DEBUG("Found key REPLAYGAIN_REFERENCE_LOUDNESS");
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
348 destination = &(info->replaygain.ref_loud);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
349 rg = TRUE;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
350 }
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 if (0 == strcasecmp(key, "REPLAYGAIN_TRACK_GAIN")) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
353 _DEBUG("Found key REPLAYGAIN_TRACK_GAIN");
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
354 destination = &(info->replaygain.track_gain);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
355 rg = TRUE;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
356 }
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
357
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
358 if (0 == strcasecmp(key, "REPLAYGAIN_TRACK_PEAK")) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
359 _DEBUG("Found key REPLAYGAIN_TRACK_PEAK");
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
360 destination = &(info->replaygain.track_peak);
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_ALBUM_GAIN")) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
365 _DEBUG("Found key REPLAYGAIN_ALBUM_GAIN");
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
366 destination = &(info->replaygain.album_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_ALBUM_PEAK")) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
371 _DEBUG("Found key REPLAYGAIN_ALBUM_PEAK");
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
372 destination = &(info->replaygain.album_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, "DATE")) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
377 _DEBUG("Found key DATE");
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
378 destination = &(info->comment.date);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
379 }
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 if (0 == strcasecmp(key, "GENRE")) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
382 _DEBUG("Found key GENRE");
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
383 destination = &(info->comment.genre);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
384 }
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
385
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
386 if (NULL != destination) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
387 if (NULL != *destination) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
388 g_free(*destination);
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
389 }
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
390
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
391 if (NULL == (*destination = g_strdup(value))) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
392 _ERROR("Could not allocate memory for comment!");
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
393 _LEAVE;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
394 }
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
395 }
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 if (rg) {
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
398 info->replaygain.has_rg = TRUE;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
399 }
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
400
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
401 _LEAVE;
2f742d127b3e [svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff changeset
402 }