198
208
bool ExportMP2::Export(AudacityProject *project,
199
209
int channels, wxString fName,
200
bool selectionOnly, double t0, double t1, MixerSpec *mixerSpec)
210
bool selectionOnly, double t0, double t1, MixerSpec *mixerSpec, bool use_meta)
202
212
bool stereo = (channels == 2);
203
213
long bitrate = gPrefs->Read(wxT("/FileFormats/MP2Bitrate"), 160);
224
/* Put ID3 tags at beginning of file */
225
/*lda Check ShowId3Dialog flag for CleanSpeech */
226
bool showId3Dialog = project->GetShowId3Dialog();
234
// Put ID3 tags at beginning of file
227
235
Tags *tags = project->GetTags();
228
bool emptyTags = tags->IsEmpty();
229
if (showId3Dialog && emptyTags) {
230
if (!tags->ShowEditDialog(project,
231
_("Edit the ID3 tags for the MP3 file"),
233
return false; // used selected "cancel"
236
if (!tags->ShowEditDialog(project,
237
_("Edit the ID3 tags for the MP2 file"))) {
238
return false; // user selected "cancel"
237
241
FileIO outFile(fName, FileIO::Output);
243
247
char *id3buffer = NULL;
246
id3len = tags->ExportID3(&id3buffer, &endOfFile);
250
id3len = AddTags(project, &id3buffer, &endOfFile, tags);
251
if (id3len && !endOfFile)
248
252
outFile.Write(id3buffer, id3len);
250
254
// Values taken from the twolame simple encoder sample
251
const int pcmBufferSize = 16384 / 2; // number of samples
252
const int mp2BufferSize = 9216; // bytes
255
const int pcmBufferSize = 9216 / 2; // number of samples
256
const int mp2BufferSize = 16384 ; // bytes
254
258
// We allocate a buffer which is twice as big as the
255
259
// input buffer, which should always be enough.
265
269
stereo? 2: 1, pcmBufferSize, true,
266
270
rate, int16Sample, true, mixerSpec);
268
GetActiveProject()->ProgressShow(selectionOnly ?
272
GetActiveProject()->ProgressShow(wxFileName(fName).GetName(),
269
274
wxString::Format(_("Exporting selected audio at %d kbps"), bitrate) :
270
wxString::Format(_("Exporting entire file at %d kbps"), bitrate),
271
wxFileName(fName).GetName());
275
wxString::Format(_("Exporting entire file at %d kbps"), bitrate));
273
277
bool cancelling = false;
274
278
while(!cancelling) {
341
// returns buffer len; caller frees
342
int ExportMP2::AddTags(AudacityProject *project, char **buffer, bool *endOfFile, Tags *tags)
345
struct id3_tag *tp = id3_tag_new();
347
bool v2 = tags->GetID3V2();
350
for (bool cont = tags->GetFirst(n, v); cont; cont = tags->GetNext(n, v)) {
353
if (n.CmpNoCase(TAG_TITLE) == 0) {
354
name = ID3_FRAME_TITLE;
356
else if (n.CmpNoCase(TAG_ARTIST) == 0) {
357
name = ID3_FRAME_ARTIST;
359
else if (n.CmpNoCase(TAG_ALBUM) == 0) {
360
name = ID3_FRAME_ALBUM;
362
else if (n.CmpNoCase(TAG_YEAR) == 0) {
363
name = ID3_FRAME_YEAR;
365
else if (n.CmpNoCase(TAG_GENRE) == 0) {
366
name = ID3_FRAME_GENRE;
368
v.Printf(wxT("%d"), tags->GetGenre(v));
371
else if (n.CmpNoCase(TAG_COMMENTS) == 0) {
372
name = ID3_FRAME_COMMENT;
374
else if (n.CmpNoCase(TAG_TRACK) == 0) {
375
name = ID3_FRAME_TRACK;
378
struct id3_frame *frame = id3_frame_new(name);
381
if (!n.IsAscii() || !v.IsAscii()) {
382
id3_field_settextencoding(id3_frame_field(frame, 0), ID3_FIELD_TEXTENCODING_UTF_16);
385
id3_field_settextencoding(id3_frame_field(frame, 0), ID3_FIELD_TEXTENCODING_ISO_8859_1);
390
id3_utf8_ucs4duplicate((id3_utf8_t *) (const char *) v.mb_str(wxConvUTF8));
392
if (strcmp(name, ID3_FRAME_COMMENT) == 0) {
393
// A hack to get around iTunes not recognizing the comment. The
394
// language defaults to XXX and, since it's not a valid language,
395
// iTunes just ignores the tag. So, either set it to a valid language
396
// (which one???) or just clear it. Unfortunately, there's no supported
397
// way of clearing the field, so do it directly.
398
id3_field *f = id3_frame_field(frame, 1);
399
memset(f->immediate.value, 0, sizeof(f->immediate.value));
400
id3_field_setfullstring(id3_frame_field(frame, 3), ucs4);
402
else if (strcmp(name, "TXXX") == 0) {
403
id3_field_setstring(id3_frame_field(frame, 2), ucs4);
406
ucs4 = id3_utf8_ucs4duplicate((id3_utf8_t *) (const char *) n.mb_str(wxConvUTF8));
408
id3_field_setstring(id3_frame_field(frame, 1), ucs4);
411
id3_field_setstrings(id3_frame_field(frame, 1), 1, &ucs4);
416
id3_tag_attachframe(tp, frame);
420
tp->options &= (~ID3_TAG_OPTION_COMPRESSION); // No compression
422
// If this version of libid3tag supports it, use v2.3 ID3
423
// tags instead of the newer, but less well supported, v2.4
424
// that libid3tag uses by default.
425
#ifdef ID3_TAG_HAS_TAG_OPTION_ID3V2_3
426
tp->options |= ID3_TAG_OPTION_ID3V2_3;
432
tp->options |= ID3_TAG_OPTION_ID3V1;
438
len = id3_tag_render(tp, 0);
439
*buffer = (char *)malloc(len);
440
len = id3_tag_render(tp, (id3_byte_t *)*buffer);
445
#else //ifdef USE_LIBID3TAG
334
450
//----------------------------------------------------------------------------
336
452
//----------------------------------------------------------------------------