1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
|
// $Id: c_wrapper.cpp,v 1.22 2002/09/21 17:23:32 t1mpy Exp $
// id3lib: a C++ library for creating and manipulating id3v1/v2 tags
// Copyright 1999, 2000 Scott Thomas Haug
// Copyright 2002 Thijmen Klok (thijmen@id3lib.org)
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Library General Public License as published by
// the Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
// License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with this library; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// The id3lib authors encourage improvements and optimisations to be sent to
// the id3lib coordinator. Please see the README file for details on where to
// send such submissions. See the AUTHORS file for a list of people who have
// contributed to id3lib. See the ChangeLog file for a list of changes to
// id3lib. These files are distributed with id3lib at
// http://download.sourceforge.net/id3lib/
//#include <string.h>
#include "id3.h"
#include "tag.h"
#include "field.h"
#if defined HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
// tag wrappers
#define ID3_CATCH(code) try { code; } catch (...) { }
ID3_C_EXPORT ID3Tag* CCONV
ID3Tag_New(void)
{
ID3_Tag* tag = NULL;
ID3_CATCH(tag = new ID3_Tag);
return reinterpret_cast<ID3Tag *>(tag);
}
ID3_C_EXPORT void CCONV
ID3Tag_Delete(ID3Tag *tag)
{
if (tag)
{
ID3_CATCH(delete reinterpret_cast<ID3_Tag*>(tag));
}
}
ID3_C_EXPORT void CCONV
ID3Tag_Clear(ID3Tag *tag)
{
if (tag)
{
ID3_CATCH(reinterpret_cast<ID3_Tag*>(tag)->Clear());
}
}
ID3_C_EXPORT bool CCONV
ID3Tag_HasChanged(const ID3Tag *tag)
{
bool changed = false;
if (tag)
{
ID3_CATCH(changed = reinterpret_cast<const ID3_Tag * >(tag)->HasChanged());
}
return changed;
}
ID3_C_EXPORT void CCONV
ID3Tag_SetUnsync(ID3Tag *tag, bool unsync)
{
if (tag)
{
ID3_CATCH(reinterpret_cast<ID3_Tag *>(tag)->SetUnsync(unsync));
}
}
ID3_C_EXPORT void CCONV
ID3Tag_SetExtendedHeader(ID3Tag *tag, bool ext)
{
if (tag)
{
ID3_CATCH(reinterpret_cast<ID3_Tag *>(tag)->SetExtendedHeader(ext));
}
}
ID3_C_EXPORT void CCONV
ID3Tag_SetPadding(ID3Tag *tag, bool pad)
{
if (tag)
{
ID3_CATCH(reinterpret_cast<ID3_Tag *>(tag)->SetPadding(pad));
}
}
ID3_C_EXPORT void CCONV
ID3Tag_AddFrame(ID3Tag *tag, const ID3Frame *frame)
{
if (tag)
{
ID3_CATCH(reinterpret_cast<ID3_Tag *>(tag)->AddFrame(reinterpret_cast<const ID3_Frame *>(frame)));
}
}
ID3_C_EXPORT bool CCONV
ID3Tag_AttachFrame(ID3Tag *tag, ID3Frame *frame)
{
bool b = false;
if (tag)
{
ID3_CATCH(b = reinterpret_cast<ID3_Tag *>(tag)->AttachFrame(reinterpret_cast<ID3_Frame *>(frame)));
}
return b;
}
ID3_C_EXPORT void CCONV
ID3Tag_AddFrames(ID3Tag *tag, const ID3Frame *frames, size_t num)
{
if (tag)
{
ID3_CATCH(reinterpret_cast<ID3_Tag *>(tag)->AddFrames(reinterpret_cast<const ID3_Frame *>(frames), num));
}
}
ID3_C_EXPORT ID3Frame* CCONV
ID3Tag_RemoveFrame(ID3Tag *tag, const ID3Frame *frame)
{
ID3_Frame* rem_frame = NULL;
if (tag)
{
ID3_CATCH(rem_frame = reinterpret_cast<ID3_Tag *>(tag)->RemoveFrame(reinterpret_cast<const ID3_Frame *>(frame)));
}
return reinterpret_cast<ID3Frame*>(rem_frame);
}
ID3_C_EXPORT ID3_Err CCONV
ID3Tag_Parse(ID3Tag *tag, const uchar header[ ID3_TAGHEADERSIZE ],
const uchar *buffer)
{
size_t size = 0;
if (tag)
{
ID3_CATCH(size = reinterpret_cast<ID3_Tag *>(tag)->Parse(header, buffer));
}
return ID3E_NoError;
}
ID3_C_EXPORT size_t CCONV
ID3Tag_Link(ID3Tag *tag, const char *fileName)
{
size_t offset = 0;
if (tag)
{
ID3_CATCH(offset = reinterpret_cast<ID3_Tag *>(tag)->Link(fileName));
}
return offset;
}
ID3_C_EXPORT size_t CCONV
ID3Tag_LinkWithFlags(ID3Tag *tag, const char *fileName, flags_t flags)
{
size_t offset = 0;
if (tag)
{
ID3_CATCH(offset = reinterpret_cast<ID3_Tag *>(tag)->Link(fileName,flags));
}
return offset;
}
ID3_C_EXPORT ID3_Err CCONV
ID3Tag_Update(ID3Tag *tag)
{
flags_t flags = 0;
if (tag)
{
ID3_CATCH(flags = reinterpret_cast<ID3_Tag *>(tag)->Update());
}
return ID3E_NoError;
}
ID3_C_EXPORT ID3_Err CCONV
ID3Tag_UpdateByTagType(ID3Tag *tag, flags_t tag_type)
{
flags_t flags = 0;
if (tag)
{
ID3_CATCH(flags = reinterpret_cast<ID3_Tag *>(tag)->Update(tag_type));
}
return ID3E_NoError;
}
ID3_C_EXPORT ID3_Err CCONV
ID3Tag_Strip(ID3Tag *tag, flags_t ulTagFlags)
{
if (tag)
{
ID3_CATCH(reinterpret_cast<ID3_Tag *>(tag)->Strip(ulTagFlags));
}
return ID3E_NoError;
}
ID3_C_EXPORT ID3Frame* CCONV
ID3Tag_FindFrameWithID(const ID3Tag *tag, ID3_FrameID id)
{
ID3_Frame *frame = NULL;
if (tag)
{
ID3_CATCH(frame = reinterpret_cast<const ID3_Tag *>(tag)->Find(id));
}
return reinterpret_cast<ID3Frame *>(frame);
}
ID3_C_EXPORT ID3Frame* CCONV
ID3Tag_FindFrameWithINT(const ID3Tag *tag, ID3_FrameID id,
ID3_FieldID fld, uint32 data)
{
ID3_Frame *frame = NULL;
if (tag)
{
ID3_CATCH(frame = reinterpret_cast<const ID3_Tag *>(tag)->Find(id, fld, data));
}
return reinterpret_cast<ID3Frame *>(frame);
}
ID3_C_EXPORT ID3Frame* CCONV
ID3Tag_FindFrameWithASCII(const ID3Tag *tag, ID3_FrameID id,
ID3_FieldID fld, const char *data)
{
ID3_Frame *frame = NULL;
if (tag)
{
ID3_CATCH(frame = reinterpret_cast<const ID3_Tag *>(tag)->Find(id, fld, data));
}
return reinterpret_cast<ID3Frame *>(frame);
}
ID3_C_EXPORT ID3Frame* CCONV
ID3Tag_FindFrameWithUNICODE(const ID3Tag *tag, ID3_FrameID id,
ID3_FieldID fld, const unicode_t *data)
{
ID3_Frame *frame = NULL;
if (tag)
{
ID3_CATCH(frame = reinterpret_cast<const ID3_Tag *>(tag)->Find(id, fld, data));
}
return reinterpret_cast<ID3Frame *>(frame);
}
ID3_C_EXPORT size_t CCONV
ID3Tag_NumFrames(const ID3Tag *tag)
{
size_t num = 0;
if (tag)
{
ID3_CATCH(num = reinterpret_cast<const ID3_Tag *>(tag)->NumFrames());
}
return num;
}
ID3_C_EXPORT bool CCONV
ID3Tag_HasTagType(const ID3Tag *tag, ID3_TagType tt)
{
bool has_tt = false;
if (tag)
{
ID3_CATCH(has_tt = reinterpret_cast<const ID3_Tag *>(tag)->HasTagType(tt));
}
return has_tt;
}
ID3_C_EXPORT ID3TagIterator* CCONV
ID3Tag_CreateIterator(ID3Tag* tag)
{
ID3_Tag::Iterator* iter = NULL;
if (tag)
{
ID3_CATCH(iter = reinterpret_cast<ID3_Tag*>(tag)->CreateIterator());
}
return reinterpret_cast<ID3TagIterator*>(iter);
}
ID3_C_EXPORT ID3TagConstIterator* CCONV
ID3Tag_CreateConstIterator(const ID3Tag* tag)
{
ID3_Tag::ConstIterator* iter = NULL;
if (tag)
{
ID3_CATCH(iter = reinterpret_cast<const ID3_Tag*>(tag)->CreateIterator());
}
return reinterpret_cast<ID3TagConstIterator*>(iter);
}
ID3_C_EXPORT void CCONV
ID3TagIterator_Delete(ID3TagIterator *iter)
{
if (iter)
{
ID3_CATCH(delete reinterpret_cast<ID3_Tag::Iterator*>(iter));
}
}
ID3_C_EXPORT ID3Frame* CCONV
ID3TagIterator_GetNext(ID3TagIterator *iter)
{
ID3_Frame* frame = NULL;
if (iter)
{
ID3_CATCH(frame = reinterpret_cast<ID3_Tag::Iterator*>(iter)->GetNext());
}
return reinterpret_cast<ID3Frame*>(frame);
}
ID3_C_EXPORT void CCONV
ID3TagConstIterator_Delete(ID3TagConstIterator *iter)
{
if (iter)
{
ID3_CATCH(delete reinterpret_cast<ID3_Tag::ConstIterator*>(iter));
}
}
ID3_C_EXPORT const ID3Frame* CCONV
ID3TagConstIterator_GetNext(ID3TagConstIterator *iter)
{
const ID3_Frame* frame = NULL;
if (iter)
{
ID3_CATCH(frame = reinterpret_cast<ID3_Tag::ConstIterator*>(iter)->GetNext());
}
return reinterpret_cast<const ID3Frame*>(frame);
}
// frame wrappers
ID3_C_EXPORT ID3Frame* CCONV
ID3Frame_New(void)
{
ID3_Frame* frame = NULL;
ID3_CATCH(frame = new ID3_Frame);
return reinterpret_cast<ID3Frame *>(frame);
}
ID3_C_EXPORT ID3Frame* CCONV
ID3Frame_NewID(ID3_FrameID id)
{
ID3_Frame* frame = NULL;
ID3_CATCH(frame = new ID3_Frame(id));
return reinterpret_cast<ID3Frame *>(frame);
}
ID3_C_EXPORT void CCONV
ID3Frame_Delete(ID3Frame *frame)
{
if (frame)
{
ID3_CATCH(delete reinterpret_cast<ID3_Frame *>(frame));
}
}
ID3_C_EXPORT void CCONV
ID3Frame_Clear(ID3Frame *frame)
{
if (frame)
{
ID3_CATCH(reinterpret_cast<ID3_Frame *>(frame)->Clear());
}
}
ID3_C_EXPORT void CCONV
ID3Frame_SetID(ID3Frame *frame, ID3_FrameID id)
{
if (frame)
{
ID3_CATCH(reinterpret_cast<ID3_Frame *>(frame)->SetID(id));
}
}
ID3_C_EXPORT ID3_FrameID CCONV
ID3Frame_GetID(const ID3Frame *frame)
{
ID3_FrameID id = ID3FID_NOFRAME;
if (frame)
{
ID3_CATCH(id = reinterpret_cast<const ID3_Frame *>(frame)->GetID());
}
return id;
}
ID3_C_EXPORT ID3Field* CCONV
ID3Frame_GetField(const ID3Frame *frame, ID3_FieldID name)
{
ID3_Field *field = NULL;
if (frame)
{
ID3_CATCH(field = reinterpret_cast<const ID3_Frame *>(frame)->GetField(name));
}
return reinterpret_cast<ID3Field *>(field);
}
ID3_C_EXPORT void CCONV
ID3Frame_SetCompression(ID3Frame *frame, bool comp)
{
if (frame)
{
ID3_CATCH(reinterpret_cast<ID3_Frame *>(frame)->SetCompression(comp));
}
}
ID3_C_EXPORT bool CCONV
ID3Frame_GetCompression(const ID3Frame *frame)
{
bool compressed = false;
if (frame)
{
ID3_CATCH(compressed = reinterpret_cast<const ID3_Frame *>(frame)->GetCompression());
}
return compressed;
}
// field wrappers
ID3_C_EXPORT void CCONV
ID3Field_Clear(ID3Field *field)
{
if (field)
{
ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->Clear());
}
}
ID3_C_EXPORT size_t CCONV
ID3Field_Size(const ID3Field *field)
{
size_t size = 0;
if (field)
{
ID3_CATCH(size = reinterpret_cast<const ID3_Field *>(field)->Size());
}
return size;
}
ID3_C_EXPORT size_t CCONV
ID3Field_GetNumTextItems(const ID3Field *field)
{
size_t items = 0;
if (field)
{
ID3_CATCH(items = reinterpret_cast<const ID3_Field *>(field)->GetNumTextItems());
}
return items;
}
ID3_C_EXPORT void CCONV
ID3Field_SetINT(ID3Field *field, uint32 data)
{
if (field)
{
ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->Set(data));
}
}
ID3_C_EXPORT uint32 CCONV
ID3Field_GetINT(const ID3Field *field)
{
uint32 value = 0;
if (field)
{
ID3_CATCH(value = reinterpret_cast<const ID3_Field *>(field)->Get());
}
return value;
}
ID3_C_EXPORT void CCONV
ID3Field_SetUNICODE(ID3Field *field, const unicode_t *string)
{
if (field)
{
ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->Set(string));
}
}
ID3_C_EXPORT size_t CCONV
ID3Field_GetUNICODE(const ID3Field *field, unicode_t *buffer, size_t maxChars)
{
size_t numChars = 0;
if (field)
{
ID3_CATCH(numChars = reinterpret_cast<const ID3_Field *>(field)->Get(buffer, maxChars));
}
return numChars;
}
ID3_C_EXPORT size_t CCONV
ID3Field_GetUNICODEItem(const ID3Field *field, unicode_t *buffer,
size_t maxChars, size_t itemNum)
{
size_t numChars = 0;
if (field)
{
ID3_CATCH(numChars = reinterpret_cast<const ID3_Field *>(field)->Get(buffer, maxChars, itemNum));
}
return numChars;
}
ID3_C_EXPORT void CCONV
ID3Field_AddUNICODE(ID3Field *field, const unicode_t *string)
{
if (field)
{
ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->Add(string));
}
}
ID3_C_EXPORT void CCONV
ID3Field_SetASCII(ID3Field *field, const char *string)
{
if (field)
{
ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->Set(string));
}
}
ID3_C_EXPORT size_t CCONV
ID3Field_GetASCII(const ID3Field *field, char *buffer, size_t maxChars)
{
size_t numChars = 0;
if (field)
{
ID3_CATCH(numChars = reinterpret_cast<const ID3_Field *>(field)->Get(buffer, maxChars));
}
return numChars;
}
ID3_C_EXPORT size_t CCONV
ID3Field_GetASCIIItem(const ID3Field *field, char *buffer,
size_t maxChars, size_t itemNum)
{
size_t numChars = 0;
if (field)
{
ID3_CATCH(numChars = reinterpret_cast<const ID3_Field *>(field)->Get(buffer, maxChars, itemNum));
}
return numChars;
}
ID3_C_EXPORT void CCONV
ID3Field_AddASCII(ID3Field *field, const char *string)
{
if (field)
{
ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->Add(string));
}
}
ID3_C_EXPORT void CCONV
ID3Field_SetBINARY(ID3Field *field, const uchar *data, size_t size)
{
if (field)
{
ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->Set(data, size));
}
}
ID3_C_EXPORT void CCONV
ID3Field_GetBINARY(const ID3Field *field, uchar *buffer, size_t buffLength)
{
if (field)
{
ID3_CATCH(reinterpret_cast<const ID3_Field *>(field)->Get(buffer, buffLength));
}
}
ID3_C_EXPORT void CCONV
ID3Field_FromFile(ID3Field *field, const char *fileName)
{
if (field)
{
ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->FromFile(fileName));
}
}
ID3_C_EXPORT void CCONV
ID3Field_ToFile(const ID3Field *field, const char *fileName)
{
if (field)
{
ID3_CATCH(reinterpret_cast<const ID3_Field *>(field)->ToFile(fileName));
}
}
ID3_C_EXPORT bool CCONV
ID3Field_SetEncoding(ID3Field *field, ID3_TextEnc enc)
{
bool changed = false;
if (field)
{
ID3_CATCH(changed = reinterpret_cast<ID3_Field *>(field)->SetEncoding(enc));
}
return changed;
}
ID3_C_EXPORT ID3_TextEnc CCONV
ID3Field_GetEncoding(const ID3Field *field)
{
ID3_TextEnc enc = ID3TE_NONE;
if (field)
{
ID3_CATCH(enc = reinterpret_cast<const ID3_Field *>(field)->GetEncoding());
}
return enc;
}
ID3_C_EXPORT bool CCONV
ID3Field_IsEncodable(const ID3Field *field)
{
bool isEncodable = false;
if (field)
{
ID3_CATCH(isEncodable = reinterpret_cast<const ID3_Field *>(field)->IsEncodable());
}
return isEncodable;
}
#ifdef __cplusplus
}
#endif /* __cplusplus */
|