Mercurial > audlegacy-plugins
annotate src/musepack/libmpc.cxx @ 2198:32f9f1e4a9ec
removed debugging stuff...
author | Eugene Zagidullin <e.asphyx@gmail.com> |
---|---|
date | Thu, 29 Nov 2007 04:17:51 +0300 |
parents | 5fea114ca11e |
children | 769e17da93dd |
rev | line source |
---|---|
232 | 1 #include "libmpc.h" |
2 | |
3 #define FORCED_THREAD_STACKSIZE 1024 * 1000 | |
4 #define REMOVE_NONEXISTANT_TAG(x) if (!*x) { x = NULL; } | |
5 | |
6 using TagLib::MPC::File; | |
7 using TagLib::Tag; | |
8 using TagLib::String; | |
9 using TagLib::APE::ItemListMap; | |
10 | |
1044
b1128efde471
[svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents:
659
diff
changeset
|
11 const gchar *mpc_fmts[] = { "mpc", NULL }; |
372
a157306caf03
[svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents:
368
diff
changeset
|
12 |
232 | 13 InputPlugin MpcPlugin = { |
14 NULL, //File Handle FILE* handle | |
15 NULL, //Filename char* filename | |
1185 | 16 (gchar *)"Musepack Audio Plugin", |
232 | 17 mpcOpenPlugin, //Open Plugin [CALLBACK] |
1621
031e91938009
musepack: C++ at it's worst.
William Pitcock <nenolod@atheme.org>
parents:
1510
diff
changeset
|
18 NULL, //Cleanup [UNUSED] |
232 | 19 mpcAboutBox, //Show About box [CALLBACK] |
20 mpcConfigBox, //Show Configure box [CALLBACK] | |
1621
031e91938009
musepack: C++ at it's worst.
William Pitcock <nenolod@atheme.org>
parents:
1510
diff
changeset
|
21 FALSE, //Enabled/Disabled [BOOLEAN] |
260
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
22 mpcIsOurFile, //Check if it's our file [CALLBACK] |
232 | 23 NULL, //Scan the directory [UNUSED] |
24 mpcPlay, //Play [CALLBACK] | |
25 mpcStop, //Stop [CALLBACK] | |
26 mpcPause, //Pause [CALLBACK] | |
27 mpcSeek, //Seek [CALLBACK] | |
28 NULL, //Set EQ [CALLBACK] | |
29 mpcGetTime, //Get Time [CALLBACK] | |
30 NULL, //Get Volume [UNUSED] | |
31 NULL, //Set Volume [UNUSED] | |
32 NULL, //Obsolete [UNUSED] | |
33 NULL, //Visual plugins add_vis_pcm(int time, AFormat fmt, int nch, int length, void *ptr) | |
34 NULL, //Set Info Settings set_info(char *title, int length, int rate, int freq, int nch) | |
35 NULL, //set Info Text set_info_text(char* text) | |
36 mpcGetSongInfo, //Get Title String callback [CALLBACK] | |
37 mpcFileInfoBox, //Show File Info Box [CALLBACK] | |
38 NULL, //Output Plugin Handle OutputPlugin output | |
254 | 39 mpcGetSongTuple,//Acquire tuple for song [CALLBACK] |
40 NULL, | |
41 NULL, | |
42 mpcIsOurFD, | |
1044
b1128efde471
[svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents:
659
diff
changeset
|
43 (gchar **)mpc_fmts |
232 | 44 }; |
45 | |
1079 | 46 InputPlugin *mpc_iplist[] = { &MpcPlugin, NULL }; |
47 | |
1395
761e17b23e0c
added Discovery plugin type
Cristi Magherusan <majeru@atheme-project.org>
parents:
1357
diff
changeset
|
48 DECLARE_PLUGIN(musepack, NULL, NULL, mpc_iplist, NULL, NULL, NULL, NULL,NULL); |
232 | 49 |
50 static PluginConfig pluginConfig = {0}; | |
51 static Widgets widgets = {0}; | |
52 static MpcDecoder mpcDecoder = {0}; | |
53 static TrackInfo track = {0}; | |
54 | |
55 static GThread *threadHandle; | |
56 GStaticMutex threadMutex = G_STATIC_MUTEX_INIT; | |
57 | |
58 /* | |
59 * VFS callback implementation, adapted from mpc_reader.c. | |
60 * This _IS_ very sick, but it works. -nenolod | |
61 */ | |
62 static mpc_int32_t | |
1978 | 63 aud_vfs_fread_impl(void *data, void *ptr, mpc_int32_t size) |
232 | 64 { |
65 mpc_reader_file *d = (mpc_reader_file *) data; | |
66 VFSFile *file = (VFSFile *) d->file; | |
67 | |
1978 | 68 return (mpc_int32_t) aud_vfs_fread(ptr, 1, size, file); |
232 | 69 } |
70 | |
71 static mpc_bool_t | |
1978 | 72 aud_vfs_fseek_impl(void *data, mpc_int32_t offset) |
232 | 73 { |
74 mpc_reader_file *d = (mpc_reader_file *) data; | |
75 VFSFile *file = (VFSFile *) d->file; | |
76 | |
1978 | 77 return d->is_seekable ? aud_vfs_fseek(file, offset, SEEK_SET) == 0 : FALSE; |
232 | 78 } |
79 | |
80 static mpc_int32_t | |
1978 | 81 aud_vfs_ftell_impl(void *data) |
232 | 82 { |
83 mpc_reader_file *d = (mpc_reader_file *) data; | |
84 VFSFile *file = (VFSFile *) d->file; | |
85 | |
1978 | 86 return aud_vfs_ftell(file); |
232 | 87 } |
88 | |
89 static mpc_int32_t | |
1978 | 90 aud_vfs_getsize_impl(void *data) |
232 | 91 { |
92 mpc_reader_file *d = (mpc_reader_file *) data; | |
93 | |
94 return d->file_size; | |
95 } | |
96 | |
97 static mpc_bool_t | |
1978 | 98 aud_vfs_canseek_impl(void *data) |
232 | 99 { |
100 mpc_reader_file *d = (mpc_reader_file *) data; | |
101 | |
102 return d->is_seekable; | |
103 } | |
104 | |
105 /* | |
106 * This sets up an mpc_reader_file object to read from VFS instead of libc. | |
107 * Essentially, we use this instead of the normal constructor. | |
108 * - nenolod | |
109 */ | |
110 void | |
111 mpc_reader_setup_file_vfs(mpc_reader_file *p_reader, VFSFile *input) | |
112 { | |
1978 | 113 p_reader->reader.seek = aud_vfs_fseek_impl; |
114 p_reader->reader.read = aud_vfs_fread_impl; | |
115 p_reader->reader.tell = aud_vfs_ftell_impl; | |
116 p_reader->reader.get_size = aud_vfs_getsize_impl; | |
117 p_reader->reader.canseek = aud_vfs_canseek_impl; | |
232 | 118 p_reader->reader.data = p_reader; |
119 | |
120 p_reader->file = (FILE *) input; // no worries, it gets cast back -nenolod | |
121 p_reader->is_seekable = TRUE; // XXX streams | |
122 | |
1978 | 123 aud_vfs_fseek(input, 0, SEEK_END); |
124 p_reader->file_size = aud_vfs_ftell(input); | |
125 aud_vfs_fseek(input, 0, SEEK_SET); | |
232 | 126 } |
127 | |
128 static void mpcOpenPlugin() | |
129 { | |
130 ConfigDb *cfg; | |
2113 | 131 cfg = aud_cfg_db_open(); |
132 aud_cfg_db_get_bool(cfg, "musepack", "clipPrevention", &pluginConfig.clipPrevention); | |
133 aud_cfg_db_get_bool(cfg, "musepack", "albumGain", &pluginConfig.albumGain); | |
134 aud_cfg_db_get_bool(cfg, "musepack", "dynamicBitrate", &pluginConfig.dynamicBitrate); | |
135 aud_cfg_db_get_bool(cfg, "musepack", "replaygain", &pluginConfig.replaygain); | |
136 aud_cfg_db_close(cfg); | |
232 | 137 } |
138 | |
139 static void mpcAboutBox() | |
140 { | |
141 GtkWidget* aboutBox = widgets.aboutBox; | |
142 if (aboutBox) | |
143 gdk_window_raise(aboutBox->window); | |
144 else | |
145 { | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
146 char* titleText = g_strdup_printf(_("Musepack Decoder Plugin 1.2")); |
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
147 const char* contentText = _("Plugin code by\nBenoit Amiaux\nMartin Spuler\nKuniklo\n\nGet latest version at http://musepack.net\n"); |
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
148 const char* buttonText = _("Nevermind"); |
1677
f6f5603a0954
xmms_show_message() changed to audacious_info_dialog()
Matti Hamalainen <ccr@tnsp.org>
parents:
1676
diff
changeset
|
149 aboutBox = audacious_info_dialog(titleText, contentText, buttonText, FALSE, NULL, NULL); |
232 | 150 widgets.aboutBox = aboutBox; |
151 g_signal_connect(G_OBJECT(aboutBox), "destroy", G_CALLBACK(gtk_widget_destroyed), &widgets.aboutBox); | |
152 } | |
153 } | |
154 | |
155 static void mpcConfigBox() | |
156 { | |
157 GtkWidget* configBox = widgets.configBox; | |
158 if(configBox) | |
159 gdk_window_raise(configBox->window); | |
160 else | |
161 { | |
162 configBox = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
163 gtk_window_set_type_hint(GTK_WINDOW(configBox), GDK_WINDOW_TYPE_HINT_DIALOG); | |
164 widgets.configBox = configBox; | |
165 g_signal_connect(G_OBJECT(configBox), "destroy", G_CALLBACK(gtk_widget_destroyed), &widgets.configBox); | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
166 gtk_window_set_title(GTK_WINDOW(configBox), _("Musepack Decoder Configuration")); |
232 | 167 gtk_window_set_policy(GTK_WINDOW(configBox), FALSE, FALSE, FALSE); |
168 gtk_container_border_width(GTK_CONTAINER(configBox), 10); | |
169 | |
170 GtkWidget* notebook = gtk_notebook_new(); | |
171 GtkWidget* vbox = gtk_vbox_new(FALSE, 10); | |
172 gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0); | |
173 gtk_container_add(GTK_CONTAINER(configBox), vbox); | |
174 | |
175 //General Settings Tab | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
176 GtkWidget* generalSet = gtk_frame_new(_("General Settings")); |
232 | 177 gtk_container_border_width(GTK_CONTAINER(generalSet), 5); |
178 | |
179 GtkWidget* gSvbox = gtk_vbox_new(FALSE, 10); | |
180 gtk_container_border_width(GTK_CONTAINER(gSvbox), 5); | |
181 gtk_container_add(GTK_CONTAINER(generalSet), gSvbox); | |
182 | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
183 GtkWidget* bitrateCheck = gtk_check_button_new_with_label(_("Enable Dynamic Bitrate Display")); |
232 | 184 widgets.bitrateCheck = bitrateCheck; |
185 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bitrateCheck), pluginConfig.dynamicBitrate); | |
186 gtk_box_pack_start(GTK_BOX(gSvbox), bitrateCheck, FALSE, FALSE, 0); | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
187 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), generalSet, gtk_label_new(_("Plugin"))); |
232 | 188 |
189 //ReplayGain Settings Tab | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
190 GtkWidget* replaygainSet = gtk_frame_new(_("ReplayGain Settings")); |
232 | 191 gtk_container_border_width(GTK_CONTAINER(replaygainSet), 5); |
192 | |
193 GtkWidget* rSVbox = gtk_vbox_new(FALSE, 10); | |
194 gtk_container_border_width(GTK_CONTAINER(rSVbox), 5); | |
195 gtk_container_add(GTK_CONTAINER(replaygainSet), rSVbox); | |
196 | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
197 GtkWidget* clippingCheck = gtk_check_button_new_with_label(_("Enable Clipping Prevention")); |
232 | 198 widgets.clippingCheck = clippingCheck; |
199 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(clippingCheck), pluginConfig.clipPrevention); | |
200 gtk_box_pack_start(GTK_BOX(rSVbox), clippingCheck, FALSE, FALSE, 0); | |
201 | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
202 GtkWidget* replaygainCheck = gtk_check_button_new_with_label(_("Enable ReplayGain")); |
232 | 203 widgets.replaygainCheck = replaygainCheck; |
204 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(replaygainCheck), pluginConfig.replaygain); | |
205 gtk_box_pack_start(GTK_BOX(rSVbox), replaygainCheck, FALSE, FALSE, 0); | |
206 | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
207 GtkWidget* replaygainType = gtk_frame_new(_("ReplayGain Type")); |
232 | 208 gtk_box_pack_start(GTK_BOX(rSVbox), replaygainType, FALSE, FALSE, 0); |
209 g_signal_connect(G_OBJECT(replaygainCheck), "toggled", G_CALLBACK(toggleSwitch), replaygainType); | |
210 | |
211 GtkWidget* rgVbox = gtk_vbox_new(FALSE, 5); | |
212 gtk_container_set_border_width(GTK_CONTAINER(rgVbox), 5); | |
213 gtk_container_add(GTK_CONTAINER(replaygainType), rgVbox); | |
214 | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
215 GtkWidget* trackCheck = gtk_radio_button_new_with_label(NULL, _("Use Track Gain")); |
232 | 216 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(trackCheck), !pluginConfig.albumGain); |
217 gtk_box_pack_start(GTK_BOX(rgVbox), trackCheck, FALSE, FALSE, 0); | |
218 | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
219 GtkWidget* albumCheck = gtk_radio_button_new_with_label(gtk_radio_button_group(GTK_RADIO_BUTTON(trackCheck)), _("Use Album Gain")); |
232 | 220 widgets.albumCheck = albumCheck; |
221 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(albumCheck), pluginConfig.albumGain); | |
222 gtk_box_pack_start(GTK_BOX(rgVbox), albumCheck, FALSE, FALSE, 0); | |
223 gtk_widget_set_sensitive(replaygainType, pluginConfig.replaygain); | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
224 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), replaygainSet, gtk_label_new(_("ReplayGain"))); |
232 | 225 |
226 //Buttons | |
227 GtkWidget* buttonBox = gtk_hbutton_box_new(); | |
228 gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_END); | |
229 gtk_button_box_set_spacing(GTK_BUTTON_BOX(buttonBox), 5); | |
230 gtk_box_pack_start(GTK_BOX(vbox), buttonBox, FALSE, FALSE, 0); | |
231 | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
232 GtkWidget* okButton = gtk_button_new_with_label(_("Ok")); |
232 | 233 g_signal_connect(G_OBJECT(okButton), "clicked", G_CALLBACK(saveConfigBox), NULL); |
234 GTK_WIDGET_SET_FLAGS(okButton, GTK_CAN_DEFAULT); | |
235 gtk_box_pack_start(GTK_BOX(buttonBox), okButton, TRUE, TRUE, 0); | |
236 | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
237 GtkWidget* cancelButton = gtk_button_new_with_label(_("Cancel")); |
232 | 238 g_signal_connect_swapped(G_OBJECT(cancelButton), "clicked", G_CALLBACK(gtk_widget_destroy), GTK_OBJECT(widgets.configBox)); |
239 GTK_WIDGET_SET_FLAGS(cancelButton, GTK_CAN_DEFAULT); | |
240 gtk_widget_grab_default(cancelButton); | |
241 gtk_box_pack_start(GTK_BOX(buttonBox), cancelButton, TRUE, TRUE, 0); | |
242 | |
243 gtk_widget_show_all(configBox); | |
244 } | |
245 } | |
246 | |
247 static void toggleSwitch(GtkWidget* p_Widget, gpointer p_Data) | |
248 { | |
249 gtk_widget_set_sensitive(GTK_WIDGET(p_Data), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_Widget))); | |
250 } | |
251 | |
252 static void saveConfigBox(GtkWidget* p_Widget, gpointer p_Data) | |
253 { | |
254 ConfigDb* cfg; | |
255 GtkToggleButton* tb; | |
256 | |
257 tb = GTK_TOGGLE_BUTTON(widgets.replaygainCheck); | |
258 pluginConfig.replaygain = gtk_toggle_button_get_active(tb); | |
259 tb = GTK_TOGGLE_BUTTON(widgets.clippingCheck); | |
260 pluginConfig.clipPrevention = gtk_toggle_button_get_active(tb); | |
261 tb = GTK_TOGGLE_BUTTON(widgets.bitrateCheck); | |
262 pluginConfig.dynamicBitrate = gtk_toggle_button_get_active(tb); | |
263 tb = GTK_TOGGLE_BUTTON(widgets.albumCheck); | |
264 pluginConfig.albumGain = gtk_toggle_button_get_active(tb); | |
265 | |
2113 | 266 cfg = aud_cfg_db_open(); |
232 | 267 |
2113 | 268 aud_cfg_db_set_bool(cfg, "musepack", "clipPrevention", pluginConfig.clipPrevention); |
269 aud_cfg_db_set_bool(cfg, "musepack", "albumGain", pluginConfig.albumGain); | |
270 aud_cfg_db_set_bool(cfg, "musepack", "dynamicBitrate", pluginConfig.dynamicBitrate); | |
271 aud_cfg_db_set_bool(cfg, "musepack", "replaygain", pluginConfig.replaygain); | |
232 | 272 |
2113 | 273 aud_cfg_db_close(cfg); |
232 | 274 |
275 gtk_widget_destroy (widgets.configBox); | |
276 } | |
277 | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
278 static gint mpcIsOurFile(gchar* p_Filename) |
260
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
279 { |
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
280 VFSFile *file; |
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
281 gchar magic[3]; |
1978 | 282 if ((file = aud_vfs_fopen(p_Filename, "rb"))) { |
283 aud_vfs_fread(magic, 1, 3, file); | |
260
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
284 if (!memcmp(magic, "MP+", 3)) { |
1978 | 285 aud_vfs_fclose(file); |
260
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
286 return 1; |
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
287 } |
1978 | 288 aud_vfs_fclose(file); |
260
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
289 } |
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
290 return 0; |
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
291 } |
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
292 |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
293 static gint mpcIsOurFD(gchar* p_Filename, VFSFile* file) |
232 | 294 { |
254 | 295 gchar magic[3]; |
1978 | 296 aud_vfs_fread(magic, 1, 3, file); |
260
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
297 if (!memcmp(magic, "MP+", 3)) |
254 | 298 return 1; |
299 return 0; | |
232 | 300 } |
301 | |
567 | 302 static void mpcPlay(InputPlayback *data) |
232 | 303 { |
304 mpcDecoder.offset = -1; | |
305 mpcDecoder.isAlive = true; | |
306 mpcDecoder.isOutput = false; | |
307 mpcDecoder.isPause = false; | |
1357
cf46ed0ee590
musepack: new threading model
William Pitcock <nenolod@atheme-project.org>
parents:
1304
diff
changeset
|
308 threadHandle = g_thread_self(); |
1447
195b5657303e
updated input plugins to use set_pb_ready to signal to the core that they're ready for playback
Giacomo Lozito <james@develia.org>
parents:
1438
diff
changeset
|
309 data->set_pb_ready(data); |
1986 | 310 decodeStream(data); |
232 | 311 } |
312 | |
567 | 313 static void mpcStop(InputPlayback *data) |
232 | 314 { |
315 setAlive(false); | |
316 if (threadHandle) | |
317 { | |
318 g_thread_join(threadHandle); | |
319 if (mpcDecoder.isOutput) | |
320 { | |
567 | 321 data->output->buffer_free(); |
322 data->output->close_audio(); | |
232 | 323 mpcDecoder.isOutput = false; |
324 } | |
325 } | |
326 } | |
327 | |
567 | 328 static void mpcPause(InputPlayback *data, short p_Pause) |
232 | 329 { |
330 lockAcquire(); | |
331 mpcDecoder.isPause = p_Pause; | |
567 | 332 data->output->pause(p_Pause); |
232 | 333 lockRelease(); |
334 } | |
335 | |
567 | 336 static void mpcSeek(InputPlayback *data, int p_Offset) |
232 | 337 { |
338 lockAcquire(); | |
339 mpcDecoder.offset = static_cast<double> (p_Offset); | |
567 | 340 data->output->flush(1000 * p_Offset); |
232 | 341 lockRelease(); |
342 } | |
343 | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
344 static gint mpcGetTime(InputPlayback *data) |
232 | 345 { |
346 if(!isAlive()) | |
347 return -1; | |
567 | 348 return data->output->output_time(); |
232 | 349 } |
350 | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
351 static Tuple *mpcGetSongTuple(gchar* p_Filename) |
232 | 352 { |
1978 | 353 VFSFile *input = aud_vfs_fopen(p_Filename, "rb"); |
1438
dc3e28d3b92a
mpc: convert, wma: fixes
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
354 Tuple *tuple = NULL; |
232 | 355 |
356 if(input) | |
357 { | |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1704
diff
changeset
|
358 tuple = aud_tuple_new_from_filename(p_Filename); |
232 | 359 |
360 MpcInfo tags = getTags(p_Filename); | |
361 | |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1704
diff
changeset
|
362 aud_tuple_associate_string(tuple, FIELD_DATE, NULL, tags.date); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1704
diff
changeset
|
363 aud_tuple_associate_string(tuple, FIELD_TITLE, NULL, tags.title); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1704
diff
changeset
|
364 aud_tuple_associate_string(tuple, FIELD_ARTIST, NULL, tags.artist); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1704
diff
changeset
|
365 aud_tuple_associate_string(tuple, FIELD_ALBUM, NULL, tags.album); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1704
diff
changeset
|
366 aud_tuple_associate_int(tuple, FIELD_TRACK_NUMBER, NULL, tags.track); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1704
diff
changeset
|
367 aud_tuple_associate_int(tuple, FIELD_YEAR, NULL, tags.year); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1704
diff
changeset
|
368 aud_tuple_associate_string(tuple, FIELD_GENRE, NULL, tags.genre); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1704
diff
changeset
|
369 aud_tuple_associate_string(tuple, FIELD_COMMENT, NULL, tags.comment); |
1438
dc3e28d3b92a
mpc: convert, wma: fixes
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
370 |
232 | 371 freeTags(tags); |
372 | |
373 mpc_streaminfo info; | |
374 mpc_reader_file reader; | |
375 mpc_reader_setup_file_vfs(&reader, input); | |
376 mpc_streaminfo_read(&info, &reader.reader); | |
377 | |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1704
diff
changeset
|
378 aud_tuple_associate_int(tuple, FIELD_LENGTH, NULL, static_cast<int> (1000 * mpc_streaminfo_get_length(&info))); |
1478
dd05a74648a7
Improve ${codec} and ${quality} tuples.
William Pitcock <nenolod@atheme-project.org>
parents:
1477
diff
changeset
|
379 |
dd05a74648a7
Improve ${codec} and ${quality} tuples.
William Pitcock <nenolod@atheme-project.org>
parents:
1477
diff
changeset
|
380 gchar *scratch = g_strdup_printf("Musepack v%d (encoder %s)", info.stream_version, info.encoder); |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1704
diff
changeset
|
381 aud_tuple_associate_string(tuple, FIELD_CODEC, NULL, scratch); |
1478
dd05a74648a7
Improve ${codec} and ${quality} tuples.
William Pitcock <nenolod@atheme-project.org>
parents:
1477
diff
changeset
|
382 g_free(scratch); |
dd05a74648a7
Improve ${codec} and ${quality} tuples.
William Pitcock <nenolod@atheme-project.org>
parents:
1477
diff
changeset
|
383 |
dd05a74648a7
Improve ${codec} and ${quality} tuples.
William Pitcock <nenolod@atheme-project.org>
parents:
1477
diff
changeset
|
384 scratch = g_strdup_printf("lossy (%s)", info.profile_name); |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1704
diff
changeset
|
385 aud_tuple_associate_string(tuple, FIELD_QUALITY, NULL, scratch); |
1478
dd05a74648a7
Improve ${codec} and ${quality} tuples.
William Pitcock <nenolod@atheme-project.org>
parents:
1477
diff
changeset
|
386 g_free(scratch); |
dd05a74648a7
Improve ${codec} and ${quality} tuples.
William Pitcock <nenolod@atheme-project.org>
parents:
1477
diff
changeset
|
387 |
1978 | 388 aud_vfs_fclose(input); |
232 | 389 } |
390 else | |
391 { | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
392 gchar* temp = g_strdup_printf("[xmms-musepack] mpcGetSongInfo is unable to open %s\n", p_Filename); |
232 | 393 perror(temp); |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
394 g_free(temp); |
232 | 395 } |
396 | |
397 return tuple; | |
398 } | |
399 | |
400 static void mpcGetSongInfo(char* p_Filename, char** p_Title, int* p_Length) | |
401 { | |
1978 | 402 VFSFile *input = aud_vfs_fopen(p_Filename, "rb"); |
232 | 403 if(input) |
404 { | |
405 MpcInfo tags = getTags(p_Filename); | |
406 *p_Title = mpcGenerateTitle(tags, p_Filename); | |
407 freeTags(tags); | |
408 mpc_streaminfo info; | |
409 mpc_reader_file reader; | |
410 mpc_reader_setup_file_vfs(&reader, input); | |
411 mpc_streaminfo_read(&info, &reader.reader); | |
412 *p_Length = static_cast<int> (1000 * mpc_streaminfo_get_length(&info)); | |
1978 | 413 aud_vfs_fclose(input); |
232 | 414 } |
415 else | |
416 { | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
417 gchar* temp = g_strdup_printf("[xmms-musepack] mpcGetSongInfo is unable to open %s\n", p_Filename); |
232 | 418 perror(temp); |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
419 g_free(temp); |
232 | 420 } |
421 } | |
422 | |
423 static void freeTags(MpcInfo& tags) | |
424 { | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
425 g_free(tags.title); |
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
426 g_free(tags.artist); |
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
427 g_free(tags.album); |
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
428 g_free(tags.comment); |
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
429 g_free(tags.genre); |
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
430 g_free(tags.date); |
232 | 431 } |
432 | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
433 static MpcInfo getTags(const gchar* p_Filename) |
232 | 434 { |
1477
04311d687e94
fix musepack tag retrieval
William Pitcock <nenolod@atheme-project.org>
parents:
1473
diff
changeset
|
435 gchar *pRealFilename = g_filename_from_uri(p_Filename, NULL, NULL); |
04311d687e94
fix musepack tag retrieval
William Pitcock <nenolod@atheme-project.org>
parents:
1473
diff
changeset
|
436 File oFile(pRealFilename ? pRealFilename : p_Filename, false); |
04311d687e94
fix musepack tag retrieval
William Pitcock <nenolod@atheme-project.org>
parents:
1473
diff
changeset
|
437 g_free(pRealFilename); |
232 | 438 Tag* poTag = oFile.tag(); |
439 MpcInfo tags = {0}; | |
440 tags.title = g_strdup(poTag->title().toCString(true)); | |
441 REMOVE_NONEXISTANT_TAG(tags.title); | |
442 tags.artist = g_strdup(poTag->artist().toCString(true)); | |
443 REMOVE_NONEXISTANT_TAG(tags.artist); | |
444 tags.album = g_strdup(poTag->album().toCString(true)); | |
445 REMOVE_NONEXISTANT_TAG(tags.album); | |
446 tags.genre = g_strdup(poTag->genre().toCString(true)); | |
447 REMOVE_NONEXISTANT_TAG(tags.genre); | |
448 tags.comment = g_strdup(poTag->comment().toCString(true)); | |
449 REMOVE_NONEXISTANT_TAG(tags.comment); | |
450 tags.year = poTag->year(); | |
451 tags.track = poTag->track(); | |
659
d1a03def0021
[svn] - disable broken APETag support for now, can cause crashes
nenolod
parents:
567
diff
changeset
|
452 #if 0 |
232 | 453 TagLib::APE::Tag* ape = oFile.APETag(false); |
454 if(ape) | |
455 { | |
456 ItemListMap map = ape->itemListMap(); | |
457 if(map.contains("YEAR")) | |
458 { | |
459 tags.date = g_strdup(map["YEAR"].toString().toCString(true)); | |
460 } | |
461 else | |
462 { | |
463 tags.date = g_strdup_printf("%d", tags.year); | |
464 } | |
465 } | |
659
d1a03def0021
[svn] - disable broken APETag support for now, can cause crashes
nenolod
parents:
567
diff
changeset
|
466 #endif |
232 | 467 return tags; |
468 } | |
469 | |
470 static void mpcFileInfoBox(char* p_Filename) | |
471 { | |
472 GtkWidget* infoBox = widgets.infoBox; | |
473 | |
474 if(infoBox) | |
475 gdk_window_raise(infoBox->window); | |
476 else | |
477 { | |
478 infoBox = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
479 gtk_window_set_type_hint(GTK_WINDOW(infoBox), GDK_WINDOW_TYPE_HINT_DIALOG); | |
480 widgets.infoBox = infoBox; | |
481 gtk_window_set_policy(GTK_WINDOW(infoBox), FALSE, FALSE, FALSE); | |
482 g_signal_connect(G_OBJECT(infoBox), "destroy", G_CALLBACK(closeInfoBox), NULL); | |
483 gtk_container_set_border_width(GTK_CONTAINER(infoBox), 10); | |
484 | |
485 GtkWidget* iVbox = gtk_vbox_new(FALSE, 10); | |
486 gtk_container_add(GTK_CONTAINER(infoBox), iVbox); | |
487 | |
488 GtkWidget* filenameHbox = gtk_hbox_new(FALSE, 5); | |
489 gtk_box_pack_start(GTK_BOX(iVbox), filenameHbox, FALSE, TRUE, 0); | |
490 | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
491 GtkWidget* fileLabel = gtk_label_new(_("Filename:")); |
232 | 492 gtk_box_pack_start(GTK_BOX(filenameHbox), fileLabel, FALSE, TRUE, 0); |
493 | |
494 GtkWidget* fileEntry = gtk_entry_new(); | |
495 widgets.fileEntry = fileEntry; | |
496 gtk_editable_set_editable(GTK_EDITABLE(fileEntry), FALSE); | |
497 gtk_box_pack_start(GTK_BOX(filenameHbox), fileEntry, TRUE, TRUE, 0); | |
498 | |
499 GtkWidget* iHbox = gtk_hbox_new(FALSE, 10); | |
500 gtk_box_pack_start(GTK_BOX(iVbox), iHbox, FALSE, TRUE, 0); | |
501 | |
502 GtkWidget* leftBox = gtk_vbox_new(FALSE, 10); | |
503 gtk_box_pack_start(GTK_BOX(iHbox), leftBox, FALSE, FALSE, 0); | |
504 | |
505 //Tag labels | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
506 GtkWidget* tagFrame = gtk_frame_new(_("Musepack Tag")); |
232 | 507 gtk_box_pack_start(GTK_BOX(leftBox), tagFrame, FALSE, FALSE, 0); |
508 gtk_widget_set_sensitive(tagFrame, TRUE); | |
509 | |
510 GtkWidget* iTable = gtk_table_new(5, 5, FALSE); | |
511 gtk_container_set_border_width(GTK_CONTAINER(iTable), 5); | |
512 gtk_container_add(GTK_CONTAINER(tagFrame), iTable); | |
513 | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
514 mpcGtkTagLabel(_("Title:"), 0, 1, 0, 1, iTable); |
232 | 515 GtkWidget* titleEntry = mpcGtkTagEntry(1, 4, 0, 1, 0, iTable); |
516 widgets.titleEntry = titleEntry; | |
517 | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
518 mpcGtkTagLabel(_("Artist:"), 0, 1, 1, 2, iTable); |
232 | 519 GtkWidget* artistEntry = mpcGtkTagEntry(1, 4, 1, 2, 0, iTable); |
520 widgets.artistEntry = artistEntry; | |
521 | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
522 mpcGtkTagLabel(_("Album:"), 0, 1, 2, 3, iTable); |
232 | 523 GtkWidget* albumEntry = mpcGtkTagEntry(1, 4, 2, 3, 0, iTable); |
524 widgets.albumEntry = albumEntry; | |
525 | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
526 mpcGtkTagLabel(_("Comment:"), 0, 1, 3, 4, iTable); |
232 | 527 GtkWidget* commentEntry = mpcGtkTagEntry(1, 4, 3, 4, 0, iTable); |
528 widgets.commentEntry = commentEntry; | |
529 | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
530 mpcGtkTagLabel(_("Year:"), 0, 1, 4, 5, iTable); |
232 | 531 GtkWidget* yearEntry = mpcGtkTagEntry(1, 2, 4, 5, 4, iTable); |
532 widgets.yearEntry = yearEntry; | |
533 gtk_widget_set_usize(yearEntry, 4, -1); | |
534 | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
535 mpcGtkTagLabel(_("Track:"), 2, 3, 4, 5, iTable); |
232 | 536 GtkWidget* trackEntry = mpcGtkTagEntry(3, 4, 4, 5, 4, iTable); |
537 widgets.trackEntry = trackEntry; | |
538 gtk_widget_set_usize(trackEntry, 3, -1); | |
539 | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
540 mpcGtkTagLabel(_("Genre:"), 0, 1, 5, 6, iTable); |
232 | 541 GtkWidget* genreEntry = mpcGtkTagEntry(1, 4, 5, 6, 0, iTable); |
542 widgets.genreEntry = genreEntry; | |
543 gtk_widget_set_usize(genreEntry, 20, -1); | |
544 | |
545 //Buttons | |
546 GtkWidget* buttonBox = gtk_hbutton_box_new(); | |
547 gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_END); | |
548 gtk_button_box_set_spacing(GTK_BUTTON_BOX(buttonBox), 5); | |
549 gtk_box_pack_start(GTK_BOX(leftBox), buttonBox, FALSE, FALSE, 0); | |
550 | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
551 GtkWidget* saveButton = mpcGtkButton(_("Save"), buttonBox); |
232 | 552 g_signal_connect(G_OBJECT(saveButton), "clicked", G_CALLBACK(saveTags), NULL); |
553 | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
554 GtkWidget* removeButton = mpcGtkButton(_("Remove Tag"), buttonBox); |
232 | 555 g_signal_connect_swapped(G_OBJECT(removeButton), "clicked", G_CALLBACK(removeTags), NULL); |
556 | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
557 GtkWidget* cancelButton = mpcGtkButton(_("Cancel"), buttonBox); |
232 | 558 g_signal_connect_swapped(G_OBJECT(cancelButton), "clicked", G_CALLBACK(closeInfoBox), NULL); |
559 gtk_widget_grab_default(cancelButton); | |
560 | |
561 //File information | |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
562 GtkWidget* infoFrame = gtk_frame_new(_("Musepack Info")); |
232 | 563 gtk_box_pack_start(GTK_BOX(iHbox), infoFrame, FALSE, FALSE, 0); |
564 | |
565 GtkWidget* infoVbox = gtk_vbox_new(FALSE, 5); | |
566 gtk_container_add(GTK_CONTAINER(infoFrame), infoVbox); | |
567 gtk_container_set_border_width(GTK_CONTAINER(infoVbox), 10); | |
568 gtk_box_set_spacing(GTK_BOX(infoVbox), 0); | |
569 | |
570 GtkWidget* streamLabel = mpcGtkLabel(infoVbox); | |
571 GtkWidget* encoderLabel = mpcGtkLabel(infoVbox); | |
572 GtkWidget* profileLabel = mpcGtkLabel(infoVbox); | |
573 GtkWidget* bitrateLabel = mpcGtkLabel(infoVbox); | |
574 GtkWidget* rateLabel = mpcGtkLabel(infoVbox); | |
575 GtkWidget* channelsLabel = mpcGtkLabel(infoVbox); | |
576 GtkWidget* lengthLabel = mpcGtkLabel(infoVbox); | |
577 GtkWidget* fileSizeLabel = mpcGtkLabel(infoVbox); | |
578 GtkWidget* trackPeakLabel = mpcGtkLabel(infoVbox); | |
579 GtkWidget* trackGainLabel = mpcGtkLabel(infoVbox); | |
580 GtkWidget* albumPeakLabel = mpcGtkLabel(infoVbox); | |
581 GtkWidget* albumGainLabel = mpcGtkLabel(infoVbox); | |
582 | |
1978 | 583 VFSFile *input = aud_vfs_fopen(p_Filename, "rb"); |
232 | 584 if(input) |
585 { | |
586 mpc_streaminfo info; | |
587 mpc_reader_file reader; | |
588 mpc_reader_setup_file_vfs(&reader, input); | |
589 mpc_streaminfo_read(&info, &reader.reader); | |
590 | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
591 gint time = static_cast<int> (mpc_streaminfo_get_length(&info)); |
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
592 gint minutes = time / 60; |
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
593 gint seconds = time % 60; |
232 | 594 |
1304
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
595 mpcGtkPrintLabel(streamLabel, _("Streamversion %d"), info.stream_version); |
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
596 mpcGtkPrintLabel(encoderLabel, _("Encoder: %s"), info.encoder); |
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
597 mpcGtkPrintLabel(profileLabel, _("Profile: %s"), info.profile_name); |
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
598 mpcGtkPrintLabel(bitrateLabel, _("Average bitrate: %6.1f kbps"), info.average_bitrate * 1.e-3); |
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
599 mpcGtkPrintLabel(rateLabel, _("Samplerate: %d Hz"), info.sample_freq); |
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
600 mpcGtkPrintLabel(channelsLabel, _("Channels: %d"), info.channels); |
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
601 mpcGtkPrintLabel(lengthLabel, _("Length: %d:\%.2d"), minutes, seconds); |
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
602 mpcGtkPrintLabel(fileSizeLabel, _("File size: %d Bytes"), info.total_file_length); |
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
603 mpcGtkPrintLabel(trackPeakLabel, _("Track Peak: %5u"), info.peak_title); |
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
604 mpcGtkPrintLabel(trackGainLabel, _("Track Gain: %-+2.2f dB"), 0.01 * info.gain_title); |
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
605 mpcGtkPrintLabel(albumPeakLabel, _("Album Peak: %5u"), info.peak_album); |
f34112ab9101
As usual, "i18n" modifications.
Stany HENRY <StrassBoy@gmail.com>
parents:
1185
diff
changeset
|
606 mpcGtkPrintLabel(albumGainLabel, _("Album Gain: %-+5.2f dB"), 0.01 * info.gain_album); |
232 | 607 |
608 MpcInfo tags = getTags(p_Filename); | |
609 gtk_entry_set_text(GTK_ENTRY(titleEntry), tags.title); | |
610 gtk_entry_set_text(GTK_ENTRY(artistEntry), tags.artist); | |
611 gtk_entry_set_text(GTK_ENTRY(albumEntry), tags.album); | |
612 gtk_entry_set_text(GTK_ENTRY(commentEntry), tags.comment); | |
613 gtk_entry_set_text(GTK_ENTRY(genreEntry), tags.genre); | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
614 gchar* entry = g_strdup_printf ("%d", tags.track); |
232 | 615 gtk_entry_set_text(GTK_ENTRY(trackEntry), entry); |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
616 g_free(entry); |
232 | 617 entry = g_strdup_printf ("%d", tags.year); |
618 gtk_entry_set_text(GTK_ENTRY(yearEntry), entry); | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
619 g_free(entry); |
232 | 620 entry = g_filename_display_name(p_Filename); |
621 gtk_entry_set_text(GTK_ENTRY(fileEntry), entry); | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
622 g_free(entry); |
232 | 623 freeTags(tags); |
1978 | 624 aud_vfs_fclose(input); |
232 | 625 } |
626 else | |
627 { | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
628 gchar* temp = g_strdup_printf("[xmms-musepack] mpcFileInfoBox is unable to read tags from %s", p_Filename); |
232 | 629 perror(temp); |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
630 g_free(temp); |
232 | 631 } |
632 | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
633 gchar* name = g_filename_display_basename(p_Filename); |
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
634 gchar* text = g_strdup_printf(_("File Info - %s"), name); |
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
635 g_free(name); |
232 | 636 gtk_window_set_title(GTK_WINDOW(infoBox), text); |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
637 g_free(text); |
232 | 638 |
639 gtk_widget_show_all(infoBox); | |
640 } | |
641 } | |
642 | |
1044
b1128efde471
[svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents:
659
diff
changeset
|
643 static void mpcGtkPrintLabel(GtkWidget* widget, const char* format,...) |
232 | 644 { |
645 va_list args; | |
646 | |
647 va_start(args, format); | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
648 gchar* temp = g_strdup_vprintf(format, args); |
232 | 649 va_end(args); |
650 | |
651 gtk_label_set_text(GTK_LABEL(widget), temp); | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
652 g_free(temp); |
232 | 653 } |
654 | |
1044
b1128efde471
[svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents:
659
diff
changeset
|
655 static GtkWidget* mpcGtkTagLabel(const char* p_Text, int a, int b, int c, int d, GtkWidget* p_Box) |
232 | 656 { |
657 GtkWidget* label = gtk_label_new(p_Text); | |
658 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | |
659 gtk_table_attach(GTK_TABLE(p_Box), label, a, b, c, d, GTK_FILL, GTK_FILL, 5, 5); | |
660 return label; | |
661 } | |
662 | |
663 static GtkWidget* mpcGtkTagEntry(int a, int b, int c, int d, int p_Size, GtkWidget* p_Box) | |
664 { | |
665 GtkWidget* entry; | |
666 if(p_Size == 0) | |
667 entry = gtk_entry_new(); | |
668 else | |
669 entry = gtk_entry_new_with_max_length(p_Size); | |
670 gtk_table_attach(GTK_TABLE(p_Box), entry, a, b, c, d, | |
671 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND | GTK_SHRINK), | |
672 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND | GTK_SHRINK), 0, 5); | |
673 return entry; | |
674 } | |
675 | |
676 static GtkWidget* mpcGtkLabel(GtkWidget* p_Box) | |
677 { | |
678 GtkWidget* label = gtk_label_new(""); | |
679 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
680 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); | |
681 gtk_box_pack_start(GTK_BOX(p_Box), label, FALSE, FALSE, 0); | |
682 return label; | |
683 } | |
684 | |
1044
b1128efde471
[svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents:
659
diff
changeset
|
685 static GtkWidget* mpcGtkButton(const char* p_Text, GtkWidget* p_Box) |
232 | 686 { |
687 GtkWidget* button = gtk_button_new_with_label(p_Text); | |
688 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
689 gtk_box_pack_start(GTK_BOX(p_Box), button, TRUE, TRUE, 0); | |
690 return button; | |
691 } | |
692 | |
693 static void removeTags(GtkWidget * w, gpointer data) | |
694 { | |
695 File oFile(gtk_entry_get_text(GTK_ENTRY(widgets.fileEntry))); | |
696 oFile.remove(); | |
697 oFile.save(); | |
698 closeInfoBox(NULL, NULL); | |
699 } | |
700 | |
701 static void saveTags(GtkWidget* w, gpointer data) | |
702 { | |
703 File oFile(gtk_entry_get_text(GTK_ENTRY(widgets.fileEntry))); | |
704 Tag* poTag = oFile.tag(); | |
705 | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
706 gchar* cAlbum = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.albumEntry))); |
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
707 gchar* cArtist = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.artistEntry))); |
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
708 gchar* cTitle = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.titleEntry))); |
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
709 gchar* cGenre = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.genreEntry))); |
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
710 gchar* cComment = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.commentEntry))); |
232 | 711 |
712 const String album = String(cAlbum, TagLib::String::UTF8); | |
713 const String artist = String(cArtist, TagLib::String::UTF8); | |
714 const String title = String(cTitle, TagLib::String::UTF8); | |
715 const String genre = String(cGenre, TagLib::String::UTF8); | |
716 const String comment = String(cComment, TagLib::String::UTF8); | |
717 | |
718 poTag->setAlbum(album); | |
719 poTag->setArtist(artist); | |
720 poTag->setTitle(title); | |
721 poTag->setGenre(genre); | |
722 poTag->setComment(comment); | |
723 poTag->setYear(atoi(gtk_entry_get_text(GTK_ENTRY(widgets.yearEntry)))); | |
724 poTag->setTrack(atoi(gtk_entry_get_text(GTK_ENTRY(widgets.trackEntry)))); | |
725 | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
726 g_free(cAlbum); |
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
727 g_free(cArtist); |
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
728 g_free(cTitle); |
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
729 g_free(cGenre); |
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
730 g_free(cComment); |
232 | 731 |
732 oFile.save(); | |
733 closeInfoBox(NULL, NULL); | |
734 } | |
735 | |
736 static void closeInfoBox(GtkWidget* w, gpointer data) | |
737 { | |
738 gtk_widget_destroy(widgets.infoBox); | |
739 widgets.infoBox = NULL; | |
740 } | |
741 | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
742 static char* mpcGenerateTitle(const MpcInfo& p_Tags, gchar* p_Filename) |
232 | 743 { |
1438
dc3e28d3b92a
mpc: convert, wma: fixes
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
744 Tuple* tuple = mpcGetSongTuple(p_Filename); |
dc3e28d3b92a
mpc: convert, wma: fixes
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
745 |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
746 gchar* title = aud_tuple_formatter_make_title_string(tuple, aud_get_gentitle_format()); |
232 | 747 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1704
diff
changeset
|
748 aud_tuple_free((void *) tuple); |
232 | 749 return title; |
750 } | |
751 | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
752 static void* endThread(gchar* p_FileName, VFSFile * p_FileHandle, bool release) |
232 | 753 { |
754 if(release) | |
755 lockRelease(); | |
756 if(mpcDecoder.isError) | |
757 { | |
758 perror(mpcDecoder.isError); | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
759 g_free(mpcDecoder.isError); |
232 | 760 mpcDecoder.isError = NULL; |
761 } | |
762 setAlive(false); | |
763 if(p_FileHandle) | |
1978 | 764 aud_vfs_fclose(p_FileHandle); |
232 | 765 if(track.display) |
766 { | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
767 g_free(track.display); |
232 | 768 track.display = NULL; |
769 } | |
770 return 0; | |
771 } | |
772 | |
1986 | 773 static void* decodeStream(InputPlayback *data) |
232 | 774 { |
775 lockAcquire(); | |
2119
5fea114ca11e
Use a #define for config ID.
Matti Hamalainen <ccr@tnsp.org>
parents:
2116
diff
changeset
|
776 gchar* filename = data->filename; |
1978 | 777 VFSFile *input = aud_vfs_fopen(filename, "rb"); |
232 | 778 if (!input) |
779 { | |
780 mpcDecoder.isError = g_strdup_printf("[xmms-musepack] decodeStream is unable to open %s", filename); | |
781 return endThread(filename, input, true); | |
782 } | |
783 | |
784 mpc_reader_file reader; | |
785 mpc_reader_setup_file_vfs(&reader, input); | |
786 | |
787 mpc_streaminfo info; | |
788 if (mpc_streaminfo_read(&info, &reader.reader) != ERROR_CODE_OK) | |
789 { | |
790 mpcDecoder.isError = g_strdup_printf("[xmms-musepack] decodeStream is unable to read %s", filename); | |
791 return endThread(filename, input, true); | |
792 } | |
793 | |
794 MpcInfo tags = getTags(filename); | |
795 track.display = mpcGenerateTitle(tags, filename); | |
796 track.length = static_cast<int> (1000 * mpc_streaminfo_get_length(&info)); | |
797 track.bitrate = static_cast<int> (info.average_bitrate); | |
798 track.sampleFreq = info.sample_freq; | |
799 track.channels = info.channels; | |
800 freeTags(tags); | |
801 | |
1986 | 802 data->set_params(data, track.display, track.length, track.bitrate, track.sampleFreq, track.channels); |
232 | 803 |
804 mpc_decoder decoder; | |
805 mpc_decoder_setup(&decoder, &reader.reader); | |
806 if (!mpc_decoder_initialize(&decoder, &info)) | |
807 { | |
808 mpcDecoder.isError = g_strdup_printf("[xmms-musepack] decodeStream is unable to initialize decoder on %s", filename); | |
809 return endThread(filename, input, true); | |
810 } | |
811 | |
812 setReplaygain(info, decoder); | |
813 | |
814 MPC_SAMPLE_FORMAT sampleBuffer[MPC_DECODER_BUFFER_LENGTH]; | |
815 char xmmsBuffer[MPC_DECODER_BUFFER_LENGTH * 4]; | |
816 | |
817 if (!MpcPlugin.output->open_audio(FMT_S16_LE, track.sampleFreq, track.channels)) | |
818 { | |
819 mpcDecoder.isError = g_strdup_printf("[xmms-musepack] decodeStream is unable to open an audio output"); | |
820 return endThread(filename, input, true); | |
821 } | |
822 else | |
823 { | |
824 mpcDecoder.isOutput = true; | |
825 } | |
826 | |
827 lockRelease(); | |
828 | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
829 gint counter = 2 * track.sampleFreq / 3; |
232 | 830 while (isAlive()) |
831 { | |
832 if (getOffset() != -1) | |
833 { | |
834 mpc_decoder_seek_seconds(&decoder, mpcDecoder.offset); | |
835 setOffset(-1); | |
836 } | |
837 | |
838 lockAcquire(); | |
839 short iPlaying = MpcPlugin.output->buffer_playing()? 1 : 0; | |
2111
ac599b9b0490
Use GLib types; Also g_free() MUST be used when memory is allocated via any
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
840 gint iFree = MpcPlugin.output->buffer_free(); |
232 | 841 if (!mpcDecoder.isPause && iFree >= ((1152 * 4) << iPlaying)) |
842 { | |
1998
8f3188746b64
chase last changeset in aud
William Pitcock <nenolod@atheme.org>
parents:
1986
diff
changeset
|
843 unsigned status = processBuffer(data, sampleBuffer, xmmsBuffer, decoder); |
232 | 844 if (status == (unsigned) (-1)) |
845 { | |
846 mpcDecoder.isError = g_strdup_printf("[xmms-musepack] error from internal decoder on %s", filename); | |
847 return endThread(filename, input, true); | |
848 } | |
849 if (status == 0 && iPlaying == 0) | |
850 return endThread(filename, input, true); | |
851 | |
852 lockRelease(); | |
853 | |
854 if(pluginConfig.dynamicBitrate) | |
855 { | |
856 counter -= status; | |
857 if(counter < 0) | |
858 { | |
1986 | 859 data->set_params(data, track.display, track.length, track.bitrate, track.sampleFreq, track.channels); |
232 | 860 counter = 2 * track.sampleFreq / 3; |
861 } | |
862 } | |
863 } | |
864 else | |
865 { | |
866 lockRelease(); | |
1676
aee4ebea943a
xmms_usleep() was removed, use g_usleep()
Matti Hamalainen <ccr@tnsp.org>
parents:
1621
diff
changeset
|
867 g_usleep(10000); |
232 | 868 } |
869 } | |
870 return endThread(filename, input, false); | |
871 } | |
872 | |
1998
8f3188746b64
chase last changeset in aud
William Pitcock <nenolod@atheme.org>
parents:
1986
diff
changeset
|
873 static int processBuffer(InputPlayback *playback, |
8f3188746b64
chase last changeset in aud
William Pitcock <nenolod@atheme.org>
parents:
1986
diff
changeset
|
874 MPC_SAMPLE_FORMAT* sampleBuffer, char* xmmsBuffer, mpc_decoder& decoder) |
232 | 875 { |
876 mpc_uint32_t vbrAcc = 0; | |
877 mpc_uint32_t vbrUpd = 0; | |
878 | |
879 unsigned status = mpc_decoder_decode(&decoder, sampleBuffer, &vbrAcc, &vbrUpd); | |
880 copyBuffer(sampleBuffer, xmmsBuffer, status); | |
881 | |
882 if (pluginConfig.dynamicBitrate) | |
883 { | |
884 track.bitrate = static_cast<int> (vbrUpd * track.sampleFreq / 1152); | |
885 } | |
886 | |
1998
8f3188746b64
chase last changeset in aud
William Pitcock <nenolod@atheme.org>
parents:
1986
diff
changeset
|
887 playback->pass_audio(playback, FMT_S16_LE, track.channels, status * 4, xmmsBuffer, NULL); |
232 | 888 return status; |
889 } | |
890 | |
891 static void setReplaygain(mpc_streaminfo& info, mpc_decoder& decoder) | |
892 { | |
893 if(!pluginConfig.replaygain && !pluginConfig.clipPrevention) | |
894 return; | |
895 | |
896 int peak = pluginConfig.albumGain ? info.peak_album : info.peak_title; | |
897 double gain = pluginConfig.albumGain ? info.gain_album : info.gain_title; | |
898 | |
899 if(!peak) | |
900 peak = 32767; | |
901 if(!gain) | |
902 gain = 1.; | |
903 | |
904 double clip = 32767. / peak; | |
905 gain = exp((M_LN10 / 2000.) * gain); | |
906 | |
907 if(pluginConfig.clipPrevention && !pluginConfig.replaygain) | |
908 gain = clip; | |
909 else if(pluginConfig.replaygain && pluginConfig.clipPrevention) | |
910 if(clip < gain) | |
911 gain = clip; | |
912 | |
913 mpc_decoder_scale_output(&decoder, gain); | |
914 } | |
915 | |
916 inline static void lockAcquire() | |
917 { | |
918 g_static_mutex_lock(&threadMutex); | |
919 } | |
920 | |
921 inline static void lockRelease() | |
922 { | |
923 g_static_mutex_unlock(&threadMutex); | |
924 } | |
925 | |
926 inline static bool isAlive() | |
927 { | |
928 lockAcquire(); | |
929 bool isAlive = mpcDecoder.isAlive; | |
930 lockRelease(); | |
931 return isAlive; | |
932 } | |
933 | |
934 inline static bool isPause() | |
935 { | |
936 lockAcquire(); | |
937 bool isPause = mpcDecoder.isPause; | |
938 lockRelease(); | |
939 return isPause; | |
940 } | |
941 | |
942 inline static void setAlive(bool isAlive) | |
943 { | |
944 lockAcquire(); | |
945 mpcDecoder.isAlive = isAlive; | |
946 lockRelease(); | |
947 } | |
948 | |
949 inline static double getOffset() | |
950 { | |
951 lockAcquire(); | |
952 double offset = mpcDecoder.offset; | |
953 lockRelease(); | |
954 return offset; | |
955 } | |
956 | |
957 inline static void setOffset(double offset) | |
958 { | |
959 lockAcquire(); | |
960 mpcDecoder.offset = offset; | |
961 lockRelease(); | |
962 } |