id3lib
3.8.3
|
00001 // $Id: c_wrapper.cpp,v 1.22 2002/09/21 17:23:32 t1mpy Exp $ 00002 00003 // id3lib: a C++ library for creating and manipulating id3v1/v2 tags 00004 // Copyright 1999, 2000 Scott Thomas Haug 00005 // Copyright 2002 Thijmen Klok (thijmen@id3lib.org) 00006 00007 // This library is free software; you can redistribute it and/or modify it 00008 // under the terms of the GNU Library General Public License as published by 00009 // the Free Software Foundation; either version 2 of the License, or (at your 00010 // option) any later version. 00011 // 00012 // This library is distributed in the hope that it will be useful, but WITHOUT 00013 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00015 // License for more details. 00016 // 00017 // You should have received a copy of the GNU Library General Public License 00018 // along with this library; if not, write to the Free Software Foundation, 00019 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00020 00021 // The id3lib authors encourage improvements and optimisations to be sent to 00022 // the id3lib coordinator. Please see the README file for details on where to 00023 // send such submissions. See the AUTHORS file for a list of people who have 00024 // contributed to id3lib. See the ChangeLog file for a list of changes to 00025 // id3lib. These files are distributed with id3lib at 00026 // http://download.sourceforge.net/id3lib/ 00027 00028 //#include <string.h> 00029 #include "id3.h" 00030 #include "tag.h" 00031 #include "field.h" 00032 00033 #if defined HAVE_CONFIG_H 00034 #include <config.h> 00035 #endif 00036 00037 #ifdef __cplusplus 00038 extern "C" 00039 { 00040 #endif /* __cplusplus */ 00041 00042 // tag wrappers 00043 00044 #define ID3_CATCH(code) try { code; } catch (...) { } 00045 00046 ID3_C_EXPORT ID3Tag* CCONV 00047 ID3Tag_New(void) 00048 { 00049 ID3_Tag* tag = NULL; 00050 ID3_CATCH(tag = new ID3_Tag); 00051 return reinterpret_cast<ID3Tag *>(tag); 00052 } 00053 00054 00055 ID3_C_EXPORT void CCONV 00056 ID3Tag_Delete(ID3Tag *tag) 00057 { 00058 if (tag) 00059 { 00060 ID3_CATCH(delete reinterpret_cast<ID3_Tag*>(tag)); 00061 } 00062 } 00063 00064 00065 ID3_C_EXPORT void CCONV 00066 ID3Tag_Clear(ID3Tag *tag) 00067 { 00068 if (tag) 00069 { 00070 ID3_CATCH(reinterpret_cast<ID3_Tag*>(tag)->Clear()); 00071 } 00072 } 00073 00074 00075 ID3_C_EXPORT bool CCONV 00076 ID3Tag_HasChanged(const ID3Tag *tag) 00077 { 00078 bool changed = false; 00079 00080 if (tag) 00081 { 00082 ID3_CATCH(changed = reinterpret_cast<const ID3_Tag * >(tag)->HasChanged()); 00083 } 00084 00085 return changed; 00086 } 00087 00088 00089 ID3_C_EXPORT void CCONV 00090 ID3Tag_SetUnsync(ID3Tag *tag, bool unsync) 00091 { 00092 if (tag) 00093 { 00094 ID3_CATCH(reinterpret_cast<ID3_Tag *>(tag)->SetUnsync(unsync)); 00095 } 00096 } 00097 00098 00099 ID3_C_EXPORT void CCONV 00100 ID3Tag_SetExtendedHeader(ID3Tag *tag, bool ext) 00101 { 00102 if (tag) 00103 { 00104 ID3_CATCH(reinterpret_cast<ID3_Tag *>(tag)->SetExtendedHeader(ext)); 00105 } 00106 } 00107 00108 ID3_C_EXPORT void CCONV 00109 ID3Tag_SetPadding(ID3Tag *tag, bool pad) 00110 { 00111 if (tag) 00112 { 00113 ID3_CATCH(reinterpret_cast<ID3_Tag *>(tag)->SetPadding(pad)); 00114 } 00115 } 00116 00117 00118 ID3_C_EXPORT void CCONV 00119 ID3Tag_AddFrame(ID3Tag *tag, const ID3Frame *frame) 00120 { 00121 if (tag) 00122 { 00123 ID3_CATCH(reinterpret_cast<ID3_Tag *>(tag)->AddFrame(reinterpret_cast<const ID3_Frame *>(frame))); 00124 } 00125 } 00126 00127 00128 ID3_C_EXPORT bool CCONV 00129 ID3Tag_AttachFrame(ID3Tag *tag, ID3Frame *frame) 00130 { 00131 bool b = false; 00132 if (tag) 00133 { 00134 ID3_CATCH(b = reinterpret_cast<ID3_Tag *>(tag)->AttachFrame(reinterpret_cast<ID3_Frame *>(frame))); 00135 } 00136 return b; 00137 } 00138 00139 00140 ID3_C_EXPORT void CCONV 00141 ID3Tag_AddFrames(ID3Tag *tag, const ID3Frame *frames, size_t num) 00142 { 00143 if (tag) 00144 { 00145 ID3_CATCH(reinterpret_cast<ID3_Tag *>(tag)->AddFrames(reinterpret_cast<const ID3_Frame *>(frames), num)); 00146 } 00147 } 00148 00149 00150 ID3_C_EXPORT ID3Frame* CCONV 00151 ID3Tag_RemoveFrame(ID3Tag *tag, const ID3Frame *frame) 00152 { 00153 ID3_Frame* rem_frame = NULL; 00154 if (tag) 00155 { 00156 ID3_CATCH(rem_frame = reinterpret_cast<ID3_Tag *>(tag)->RemoveFrame(reinterpret_cast<const ID3_Frame *>(frame))); 00157 } 00158 return reinterpret_cast<ID3Frame*>(rem_frame); 00159 } 00160 00161 00162 ID3_C_EXPORT ID3_Err CCONV 00163 ID3Tag_Parse(ID3Tag *tag, const uchar header[ ID3_TAGHEADERSIZE ], 00164 const uchar *buffer) 00165 { 00166 size_t size = 0; 00167 if (tag) 00168 { 00169 ID3_CATCH(size = reinterpret_cast<ID3_Tag *>(tag)->Parse(header, buffer)); 00170 } 00171 return ID3E_NoError; 00172 } 00173 00174 00175 ID3_C_EXPORT size_t CCONV 00176 ID3Tag_Link(ID3Tag *tag, const char *fileName) 00177 { 00178 size_t offset = 0; 00179 if (tag) 00180 { 00181 ID3_CATCH(offset = reinterpret_cast<ID3_Tag *>(tag)->Link(fileName)); 00182 } 00183 return offset; 00184 } 00185 00186 ID3_C_EXPORT size_t CCONV 00187 ID3Tag_LinkWithFlags(ID3Tag *tag, const char *fileName, flags_t flags) 00188 { 00189 size_t offset = 0; 00190 if (tag) 00191 { 00192 ID3_CATCH(offset = reinterpret_cast<ID3_Tag *>(tag)->Link(fileName,flags)); 00193 } 00194 return offset; 00195 } 00196 00197 00198 00199 ID3_C_EXPORT ID3_Err CCONV 00200 ID3Tag_Update(ID3Tag *tag) 00201 { 00202 flags_t flags = 0; 00203 if (tag) 00204 { 00205 ID3_CATCH(flags = reinterpret_cast<ID3_Tag *>(tag)->Update()); 00206 } 00207 return ID3E_NoError; 00208 } 00209 00210 ID3_C_EXPORT ID3_Err CCONV 00211 ID3Tag_UpdateByTagType(ID3Tag *tag, flags_t tag_type) 00212 { 00213 flags_t flags = 0; 00214 if (tag) 00215 { 00216 ID3_CATCH(flags = reinterpret_cast<ID3_Tag *>(tag)->Update(tag_type)); 00217 } 00218 return ID3E_NoError; 00219 } 00220 00221 00222 ID3_C_EXPORT ID3_Err CCONV 00223 ID3Tag_Strip(ID3Tag *tag, flags_t ulTagFlags) 00224 { 00225 if (tag) 00226 { 00227 ID3_CATCH(reinterpret_cast<ID3_Tag *>(tag)->Strip(ulTagFlags)); 00228 } 00229 return ID3E_NoError; 00230 } 00231 00232 00233 ID3_C_EXPORT ID3Frame* CCONV 00234 ID3Tag_FindFrameWithID(const ID3Tag *tag, ID3_FrameID id) 00235 { 00236 ID3_Frame *frame = NULL; 00237 00238 if (tag) 00239 { 00240 ID3_CATCH(frame = reinterpret_cast<const ID3_Tag *>(tag)->Find(id)); 00241 } 00242 00243 return reinterpret_cast<ID3Frame *>(frame); 00244 } 00245 00246 00247 ID3_C_EXPORT ID3Frame* CCONV 00248 ID3Tag_FindFrameWithINT(const ID3Tag *tag, ID3_FrameID id, 00249 ID3_FieldID fld, uint32 data) 00250 { 00251 ID3_Frame *frame = NULL; 00252 00253 if (tag) 00254 { 00255 ID3_CATCH(frame = reinterpret_cast<const ID3_Tag *>(tag)->Find(id, fld, data)); 00256 } 00257 00258 return reinterpret_cast<ID3Frame *>(frame); 00259 } 00260 00261 00262 ID3_C_EXPORT ID3Frame* CCONV 00263 ID3Tag_FindFrameWithASCII(const ID3Tag *tag, ID3_FrameID id, 00264 ID3_FieldID fld, const char *data) 00265 { 00266 ID3_Frame *frame = NULL; 00267 00268 if (tag) 00269 { 00270 ID3_CATCH(frame = reinterpret_cast<const ID3_Tag *>(tag)->Find(id, fld, data)); 00271 } 00272 00273 return reinterpret_cast<ID3Frame *>(frame); 00274 } 00275 00276 00277 ID3_C_EXPORT ID3Frame* CCONV 00278 ID3Tag_FindFrameWithUNICODE(const ID3Tag *tag, ID3_FrameID id, 00279 ID3_FieldID fld, const unicode_t *data) 00280 { 00281 ID3_Frame *frame = NULL; 00282 00283 if (tag) 00284 { 00285 ID3_CATCH(frame = reinterpret_cast<const ID3_Tag *>(tag)->Find(id, fld, data)); 00286 } 00287 00288 return reinterpret_cast<ID3Frame *>(frame); 00289 } 00290 00291 00292 ID3_C_EXPORT size_t CCONV 00293 ID3Tag_NumFrames(const ID3Tag *tag) 00294 { 00295 size_t num = 0; 00296 00297 if (tag) 00298 { 00299 ID3_CATCH(num = reinterpret_cast<const ID3_Tag *>(tag)->NumFrames()); 00300 } 00301 00302 return num; 00303 } 00304 00305 00306 ID3_C_EXPORT bool CCONV 00307 ID3Tag_HasTagType(const ID3Tag *tag, ID3_TagType tt) 00308 { 00309 bool has_tt = false; 00310 00311 if (tag) 00312 { 00313 ID3_CATCH(has_tt = reinterpret_cast<const ID3_Tag *>(tag)->HasTagType(tt)); 00314 } 00315 00316 return has_tt; 00317 } 00318 00319 ID3_C_EXPORT ID3TagIterator* CCONV 00320 ID3Tag_CreateIterator(ID3Tag* tag) 00321 { 00322 ID3_Tag::Iterator* iter = NULL; 00323 00324 if (tag) 00325 { 00326 ID3_CATCH(iter = reinterpret_cast<ID3_Tag*>(tag)->CreateIterator()); 00327 } 00328 00329 return reinterpret_cast<ID3TagIterator*>(iter); 00330 } 00331 00332 ID3_C_EXPORT ID3TagConstIterator* CCONV 00333 ID3Tag_CreateConstIterator(const ID3Tag* tag) 00334 { 00335 ID3_Tag::ConstIterator* iter = NULL; 00336 00337 if (tag) 00338 { 00339 ID3_CATCH(iter = reinterpret_cast<const ID3_Tag*>(tag)->CreateIterator()); 00340 } 00341 00342 return reinterpret_cast<ID3TagConstIterator*>(iter); 00343 } 00344 00345 ID3_C_EXPORT void CCONV 00346 ID3TagIterator_Delete(ID3TagIterator *iter) 00347 { 00348 if (iter) 00349 { 00350 ID3_CATCH(delete reinterpret_cast<ID3_Tag::Iterator*>(iter)); 00351 } 00352 } 00353 00354 ID3_C_EXPORT ID3Frame* CCONV 00355 ID3TagIterator_GetNext(ID3TagIterator *iter) 00356 { 00357 ID3_Frame* frame = NULL; 00358 if (iter) 00359 { 00360 ID3_CATCH(frame = reinterpret_cast<ID3_Tag::Iterator*>(iter)->GetNext()); 00361 } 00362 return reinterpret_cast<ID3Frame*>(frame); 00363 } 00364 00365 ID3_C_EXPORT void CCONV 00366 ID3TagConstIterator_Delete(ID3TagConstIterator *iter) 00367 { 00368 if (iter) 00369 { 00370 ID3_CATCH(delete reinterpret_cast<ID3_Tag::ConstIterator*>(iter)); 00371 } 00372 } 00373 00374 ID3_C_EXPORT const ID3Frame* CCONV 00375 ID3TagConstIterator_GetNext(ID3TagConstIterator *iter) 00376 { 00377 const ID3_Frame* frame = NULL; 00378 if (iter) 00379 { 00380 ID3_CATCH(frame = reinterpret_cast<ID3_Tag::ConstIterator*>(iter)->GetNext()); 00381 } 00382 return reinterpret_cast<const ID3Frame*>(frame); 00383 } 00384 00385 // frame wrappers 00386 00387 ID3_C_EXPORT ID3Frame* CCONV 00388 ID3Frame_New(void) 00389 { 00390 ID3_Frame* frame = NULL; 00391 ID3_CATCH(frame = new ID3_Frame); 00392 return reinterpret_cast<ID3Frame *>(frame); 00393 } 00394 00395 ID3_C_EXPORT ID3Frame* CCONV 00396 ID3Frame_NewID(ID3_FrameID id) 00397 { 00398 ID3_Frame* frame = NULL; 00399 ID3_CATCH(frame = new ID3_Frame(id)); 00400 return reinterpret_cast<ID3Frame *>(frame); 00401 } 00402 00403 ID3_C_EXPORT void CCONV 00404 ID3Frame_Delete(ID3Frame *frame) 00405 { 00406 if (frame) 00407 { 00408 ID3_CATCH(delete reinterpret_cast<ID3_Frame *>(frame)); 00409 } 00410 } 00411 00412 00413 ID3_C_EXPORT void CCONV 00414 ID3Frame_Clear(ID3Frame *frame) 00415 { 00416 if (frame) 00417 { 00418 ID3_CATCH(reinterpret_cast<ID3_Frame *>(frame)->Clear()); 00419 } 00420 } 00421 00422 00423 ID3_C_EXPORT void CCONV 00424 ID3Frame_SetID(ID3Frame *frame, ID3_FrameID id) 00425 { 00426 if (frame) 00427 { 00428 ID3_CATCH(reinterpret_cast<ID3_Frame *>(frame)->SetID(id)); 00429 } 00430 } 00431 00432 00433 ID3_C_EXPORT ID3_FrameID CCONV 00434 ID3Frame_GetID(const ID3Frame *frame) 00435 { 00436 ID3_FrameID id = ID3FID_NOFRAME; 00437 00438 if (frame) 00439 { 00440 ID3_CATCH(id = reinterpret_cast<const ID3_Frame *>(frame)->GetID()); 00441 } 00442 00443 return id; 00444 } 00445 00446 00447 ID3_C_EXPORT ID3Field* CCONV 00448 ID3Frame_GetField(const ID3Frame *frame, ID3_FieldID name) 00449 { 00450 ID3_Field *field = NULL; 00451 00452 if (frame) 00453 { 00454 ID3_CATCH(field = reinterpret_cast<const ID3_Frame *>(frame)->GetField(name)); 00455 } 00456 00457 return reinterpret_cast<ID3Field *>(field); 00458 } 00459 00460 00461 ID3_C_EXPORT void CCONV 00462 ID3Frame_SetCompression(ID3Frame *frame, bool comp) 00463 { 00464 if (frame) 00465 { 00466 ID3_CATCH(reinterpret_cast<ID3_Frame *>(frame)->SetCompression(comp)); 00467 } 00468 } 00469 00470 00471 ID3_C_EXPORT bool CCONV 00472 ID3Frame_GetCompression(const ID3Frame *frame) 00473 { 00474 bool compressed = false; 00475 if (frame) 00476 { 00477 ID3_CATCH(compressed = reinterpret_cast<const ID3_Frame *>(frame)->GetCompression()); 00478 } 00479 return compressed; 00480 } 00481 00482 00483 // field wrappers 00484 00485 00486 ID3_C_EXPORT void CCONV 00487 ID3Field_Clear(ID3Field *field) 00488 { 00489 if (field) 00490 { 00491 ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->Clear()); 00492 } 00493 } 00494 00495 00496 ID3_C_EXPORT size_t CCONV 00497 ID3Field_Size(const ID3Field *field) 00498 { 00499 size_t size = 0; 00500 00501 if (field) 00502 { 00503 ID3_CATCH(size = reinterpret_cast<const ID3_Field *>(field)->Size()); 00504 } 00505 00506 return size; 00507 } 00508 00509 00510 ID3_C_EXPORT size_t CCONV 00511 ID3Field_GetNumTextItems(const ID3Field *field) 00512 { 00513 size_t items = 0; 00514 00515 if (field) 00516 { 00517 ID3_CATCH(items = reinterpret_cast<const ID3_Field *>(field)->GetNumTextItems()); 00518 } 00519 00520 return items; 00521 } 00522 00523 00524 ID3_C_EXPORT void CCONV 00525 ID3Field_SetINT(ID3Field *field, uint32 data) 00526 { 00527 if (field) 00528 { 00529 ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->Set(data)); 00530 } 00531 } 00532 00533 00534 ID3_C_EXPORT uint32 CCONV 00535 ID3Field_GetINT(const ID3Field *field) 00536 { 00537 uint32 value = 0; 00538 00539 if (field) 00540 { 00541 ID3_CATCH(value = reinterpret_cast<const ID3_Field *>(field)->Get()); 00542 } 00543 00544 return value; 00545 } 00546 00547 00548 ID3_C_EXPORT void CCONV 00549 ID3Field_SetUNICODE(ID3Field *field, const unicode_t *string) 00550 { 00551 if (field) 00552 { 00553 ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->Set(string)); 00554 } 00555 } 00556 00557 00558 ID3_C_EXPORT size_t CCONV 00559 ID3Field_GetUNICODE(const ID3Field *field, unicode_t *buffer, size_t maxChars) 00560 { 00561 size_t numChars = 0; 00562 00563 if (field) 00564 { 00565 ID3_CATCH(numChars = reinterpret_cast<const ID3_Field *>(field)->Get(buffer, maxChars)); 00566 } 00567 00568 return numChars; 00569 } 00570 00571 00572 ID3_C_EXPORT size_t CCONV 00573 ID3Field_GetUNICODEItem(const ID3Field *field, unicode_t *buffer, 00574 size_t maxChars, size_t itemNum) 00575 { 00576 size_t numChars = 0; 00577 00578 if (field) 00579 { 00580 ID3_CATCH(numChars = reinterpret_cast<const ID3_Field *>(field)->Get(buffer, maxChars, itemNum)); 00581 } 00582 00583 return numChars; 00584 } 00585 00586 00587 ID3_C_EXPORT void CCONV 00588 ID3Field_AddUNICODE(ID3Field *field, const unicode_t *string) 00589 { 00590 if (field) 00591 { 00592 ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->Add(string)); 00593 } 00594 } 00595 00596 00597 ID3_C_EXPORT void CCONV 00598 ID3Field_SetASCII(ID3Field *field, const char *string) 00599 { 00600 if (field) 00601 { 00602 ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->Set(string)); 00603 } 00604 } 00605 00606 00607 ID3_C_EXPORT size_t CCONV 00608 ID3Field_GetASCII(const ID3Field *field, char *buffer, size_t maxChars) 00609 { 00610 size_t numChars = 0; 00611 00612 if (field) 00613 { 00614 ID3_CATCH(numChars = reinterpret_cast<const ID3_Field *>(field)->Get(buffer, maxChars)); 00615 } 00616 00617 return numChars; 00618 } 00619 00620 ID3_C_EXPORT size_t CCONV 00621 ID3Field_GetASCIIItem(const ID3Field *field, char *buffer, 00622 size_t maxChars, size_t itemNum) 00623 { 00624 size_t numChars = 0; 00625 00626 if (field) 00627 { 00628 ID3_CATCH(numChars = reinterpret_cast<const ID3_Field *>(field)->Get(buffer, maxChars, itemNum)); 00629 } 00630 00631 return numChars; 00632 } 00633 00634 00635 ID3_C_EXPORT void CCONV 00636 ID3Field_AddASCII(ID3Field *field, const char *string) 00637 { 00638 if (field) 00639 { 00640 ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->Add(string)); 00641 } 00642 } 00643 00644 00645 ID3_C_EXPORT void CCONV 00646 ID3Field_SetBINARY(ID3Field *field, const uchar *data, size_t size) 00647 { 00648 if (field) 00649 { 00650 ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->Set(data, size)); 00651 } 00652 } 00653 00654 00655 ID3_C_EXPORT void CCONV 00656 ID3Field_GetBINARY(const ID3Field *field, uchar *buffer, size_t buffLength) 00657 { 00658 if (field) 00659 { 00660 ID3_CATCH(reinterpret_cast<const ID3_Field *>(field)->Get(buffer, buffLength)); 00661 } 00662 } 00663 00664 00665 ID3_C_EXPORT void CCONV 00666 ID3Field_FromFile(ID3Field *field, const char *fileName) 00667 { 00668 if (field) 00669 { 00670 ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->FromFile(fileName)); 00671 } 00672 } 00673 00674 00675 ID3_C_EXPORT void CCONV 00676 ID3Field_ToFile(const ID3Field *field, const char *fileName) 00677 { 00678 if (field) 00679 { 00680 ID3_CATCH(reinterpret_cast<const ID3_Field *>(field)->ToFile(fileName)); 00681 } 00682 } 00683 00684 ID3_C_EXPORT bool CCONV 00685 ID3Field_SetEncoding(ID3Field *field, ID3_TextEnc enc) 00686 { 00687 bool changed = false; 00688 if (field) 00689 { 00690 ID3_CATCH(changed = reinterpret_cast<ID3_Field *>(field)->SetEncoding(enc)); 00691 } 00692 return changed; 00693 } 00694 00695 ID3_C_EXPORT ID3_TextEnc CCONV 00696 ID3Field_GetEncoding(const ID3Field *field) 00697 { 00698 ID3_TextEnc enc = ID3TE_NONE; 00699 if (field) 00700 { 00701 ID3_CATCH(enc = reinterpret_cast<const ID3_Field *>(field)->GetEncoding()); 00702 } 00703 return enc; 00704 } 00705 00706 ID3_C_EXPORT bool CCONV 00707 ID3Field_IsEncodable(const ID3Field *field) 00708 { 00709 bool isEncodable = false; 00710 if (field) 00711 { 00712 ID3_CATCH(isEncodable = reinterpret_cast<const ID3_Field *>(field)->IsEncodable()); 00713 } 00714 return isEncodable; 00715 } 00716 00717 #ifdef __cplusplus 00718 } 00719 #endif /* __cplusplus */ 00720