1
0

id3_misc_support.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // The authors have released ID3Lib as Public Domain (PD) and claim no copyright,
  2. // patent or other intellectual property protection in this work. This means that
  3. // it may be modified, redistributed and used in commercial and non-commercial
  4. // software and hardware without restrictions. ID3Lib is distributed on an "AS IS"
  5. // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
  6. //
  7. // The ID3Lib authors encourage improvements and optimisations to be sent to the
  8. // ID3Lib coordinator, currently Dirk Mahoney ([email protected]). Approved
  9. // submissions may be altered, and will be included and released under these terms.
  10. //
  11. // Mon Nov 23 18:34:01 1998
  12. #include "id3_misc_support.h"
  13. int ID3_UnicodeToLatin(char *latin, const wchar_t *unicode, luint len, int inLen)
  14. {
  15. if (unicode && latin && len)
  16. return WideCharToMultiByte(28591, 0, unicode, inLen/*-1*/, latin, len, NULL, NULL) - 1;
  17. else if (latin && len)
  18. latin[0]=0;
  19. return 0;
  20. }
  21. int ID3_UnicodeToLocal(char *local, const wchar_t *unicode, luint len, int inLen)
  22. {
  23. if (unicode && local && len)
  24. return WideCharToMultiByte(CP_ACP, 0, unicode, inLen/*-1*/, local, len, NULL, NULL)-1;
  25. else if (local && len)
  26. local[0]=0;
  27. return 0;
  28. }
  29. int ID3_UnicodeToUTF8(char *local, const wchar_t *unicode, luint len, int inLen)
  30. {
  31. if (unicode && local && len)
  32. return WideCharToMultiByte(CP_UTF8, 0, unicode, inLen/*-1*/, local, len, NULL, NULL)-1;
  33. else if (local && len)
  34. local[0]=0;
  35. return 0;
  36. }
  37. void ID3_AddArtist(ID3_Tag *tag, char *text)
  38. {
  39. if (tag->Find(ID3FID_LEADARTIST ) == NULL &&
  40. tag->Find (ID3FID_BAND ) == NULL &&
  41. tag->Find (ID3FID_CONDUCTOR ) == NULL &&
  42. tag->Find (ID3FID_COMPOSER ) == NULL &&
  43. text && text[0])
  44. {
  45. ID3_Frame *artistFrame=new ID3_Frame;
  46. artistFrame->SetID(ID3FID_LEADARTIST);
  47. artistFrame->Field(ID3FN_TEXT).SetLocal(text);
  48. tag->AddFrame(artistFrame, true);
  49. }
  50. return;
  51. }
  52. void ID3_AddArtist_Latin(ID3_Tag *tag, char *text)
  53. {
  54. if (tag->Find (ID3FID_LEADARTIST ) == NULL &&
  55. tag->Find (ID3FID_BAND ) == NULL &&
  56. tag->Find (ID3FID_CONDUCTOR ) == NULL &&
  57. tag->Find (ID3FID_COMPOSER ) == NULL &&
  58. text && text[0])
  59. {
  60. ID3_Frame *artistFrame= new ID3_Frame;
  61. artistFrame->SetID (ID3FID_LEADARTIST);
  62. artistFrame->Field(ID3FN_TEXT).SetLatin(text);
  63. tag->AddFrame (artistFrame, true );
  64. }
  65. return;
  66. }
  67. void ID3_AddAlbum(ID3_Tag *tag, char *text)
  68. {
  69. if (tag->Find (ID3FID_ALBUM ) == NULL && strlen (text ) > 0 )
  70. {
  71. ID3_Frame *albumFrame;
  72. if (albumFrame = new ID3_Frame )
  73. {
  74. albumFrame->SetID (ID3FID_ALBUM );
  75. albumFrame->Field(ID3FN_TEXT).SetLocal(text);
  76. tag->AddFrame (albumFrame, true );
  77. }
  78. else
  79. ID3_THROW (ID3E_NoMemory );
  80. }
  81. return;
  82. }
  83. void ID3_AddAlbum_Latin(ID3_Tag *tag, char *text)
  84. {
  85. if (tag->Find(ID3FID_ALBUM) == NULL
  86. && text && text[0])
  87. {
  88. ID3_Frame *albumFrame = new ID3_Frame;
  89. albumFrame->SetID (ID3FID_ALBUM );
  90. albumFrame->Field(ID3FN_TEXT).SetLocal(text);
  91. tag->AddFrame (albumFrame, true );
  92. }
  93. return;
  94. }
  95. void ID3_AddTitle(ID3_Tag *tag, char *text)
  96. {
  97. if (tag->Find(ID3FID_TITLE) == NULL
  98. && text && text[0])
  99. {
  100. ID3_Frame *titleFrame;
  101. if (titleFrame = new ID3_Frame)
  102. {
  103. titleFrame->SetID(ID3FID_TITLE);
  104. titleFrame->Field(ID3FN_TEXT).SetLocal(text);
  105. tag->AddFrame (titleFrame, true );
  106. }
  107. else
  108. ID3_THROW(ID3E_NoMemory);
  109. }
  110. return;
  111. }
  112. void ID3_AddTitle_Latin(ID3_Tag *tag, char *text)
  113. {
  114. if (tag->Find(ID3FID_TITLE) == NULL
  115. && text && text[0])
  116. {
  117. ID3_Frame *titleFrame= new ID3_Frame;
  118. titleFrame->SetID(ID3FID_TITLE);
  119. titleFrame->Field(ID3FN_TEXT).SetLatin(text);
  120. tag->AddFrame(titleFrame, true);
  121. }
  122. return;
  123. }
  124. void ID3_AddLyrics(ID3_Tag *tag, char *text)
  125. {
  126. if (tag->Find (ID3FID_UNSYNCEDLYRICS ) == NULL && strlen (text ) > 0 )
  127. {
  128. ID3_Frame *lyricsFrame;
  129. if (lyricsFrame = new ID3_Frame )
  130. {
  131. lyricsFrame->SetID (ID3FID_UNSYNCEDLYRICS );
  132. lyricsFrame->Field(ID3FN_LANGUAGE).SetLatin("eng");
  133. lyricsFrame->Field(ID3FN_TEXT ).SetLocal(text);
  134. tag->AddFrame (lyricsFrame, true );
  135. }
  136. else
  137. ID3_THROW (ID3E_NoMemory );
  138. }
  139. return;
  140. }