DBitemrecord.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #include "main.h"
  2. #include "ml_local.h"
  3. #ifdef _M_IX86
  4. const size_t convert_max_characters = 16; // it's actually 11, but this probably causes less memory fragmentation
  5. #elif defined(_M_X64)
  6. const size_t convert_max_characters = 20;
  7. #endif
  8. bool compat_mode = false;
  9. typedef void (__fastcall *FieldFunc)(itemRecordW *obj, nde_field_t f);
  10. #define FIELD_FUNC(field) field ## Func
  11. #define STRINGFIELD_FUNC(item) static void __fastcall FIELD_FUNC(item)(itemRecordW *obj, nde_field_t f) { obj-> ## item = NDE_StringField_GetString(f); ndestring_retain(obj-> ## item); }
  12. #define INTFIELD_FUNC(item) static void __fastcall FIELD_FUNC(item)(itemRecordW *obj, nde_field_t f) { obj-> ## item = NDE_IntegerField_GetValue(f); }
  13. #define EXT_STRINGFIELD_FUNC(field) static void __fastcall FIELD_FUNC(field)(itemRecordW *obj, nde_field_t f) { setRecordExtendedItem_fast(obj, extended_fields.field, NDE_StringField_GetString(f)); }
  14. #define EXT_INTFIELD_FUNC(field) static void __fastcall FIELD_FUNC(field)(itemRecordW *obj, nde_field_t f) { wchar_t *temp = ndestring_malloc(convert_max_characters*sizeof(wchar_t)); unsigned int v = NDE_IntegerField_GetValue(f); wsprintfW(temp, L"%u", v); setRecordExtendedItem_fast(obj, extended_fields.field, temp); ndestring_release(temp); }
  15. #define REALSIZE_INTFIELD_FUNC(field) static void __fastcall FIELD_FUNC(field)(itemRecordW *obj, nde_field_t f) {\
  16. wchar_t *temp = ndestring_malloc(convert_max_characters*sizeof(wchar_t));\
  17. __int64 v = NDE_Int64Field_GetValue(f);\
  18. obj-> ## field = (v > 0 ? ((int)(compat_mode ? v >> 10 : v)) : 0);\
  19. wsprintfW(temp, L"%ld", v);\
  20. setRecordExtendedItem_fast(obj, extended_fields.realsize, temp);\
  21. ndestring_release(temp);\
  22. }
  23. STRINGFIELD_FUNC(title);
  24. STRINGFIELD_FUNC(artist);
  25. STRINGFIELD_FUNC(album);
  26. INTFIELD_FUNC(year);
  27. STRINGFIELD_FUNC(genre);
  28. STRINGFIELD_FUNC(comment);
  29. INTFIELD_FUNC(track);
  30. INTFIELD_FUNC(length);
  31. INTFIELD_FUNC(type);
  32. INTFIELD_FUNC(lastupd);
  33. INTFIELD_FUNC(lastplay);
  34. INTFIELD_FUNC(rating);
  35. INTFIELD_FUNC(playcount);
  36. INTFIELD_FUNC(filetime);
  37. // use a custom version to set 'filesize' and 'realsize' to ensure compatibility
  38. REALSIZE_INTFIELD_FUNC(filesize);
  39. INTFIELD_FUNC(bitrate);
  40. INTFIELD_FUNC(disc);
  41. STRINGFIELD_FUNC(albumartist);
  42. STRINGFIELD_FUNC(replaygain_album_gain);
  43. STRINGFIELD_FUNC(replaygain_track_gain);
  44. STRINGFIELD_FUNC(publisher);
  45. STRINGFIELD_FUNC(composer);
  46. INTFIELD_FUNC(bpm);
  47. INTFIELD_FUNC(discs);
  48. INTFIELD_FUNC(tracks);
  49. EXT_INTFIELD_FUNC(ispodcast);
  50. EXT_STRINGFIELD_FUNC(podcastchannel);
  51. EXT_INTFIELD_FUNC(podcastpubdate);
  52. EXT_STRINGFIELD_FUNC(GracenoteFileID);
  53. EXT_STRINGFIELD_FUNC(GracenoteExtData);
  54. EXT_INTFIELD_FUNC(lossless);
  55. STRINGFIELD_FUNC(category);
  56. EXT_STRINGFIELD_FUNC(codec);
  57. EXT_STRINGFIELD_FUNC(director);
  58. EXT_STRINGFIELD_FUNC(producer);
  59. EXT_INTFIELD_FUNC(width);
  60. EXT_INTFIELD_FUNC(height);
  61. EXT_STRINGFIELD_FUNC(mimetype);
  62. EXT_INTFIELD_FUNC(dateadded);
  63. static void __fastcall NullFieldFunction(itemRecordW *obj, nde_field_t f) {}
  64. static FieldFunc field_functions[] =
  65. {
  66. NullFieldFunction, // filename
  67. FIELD_FUNC(title),
  68. FIELD_FUNC(artist),
  69. FIELD_FUNC(album),
  70. FIELD_FUNC(year),
  71. FIELD_FUNC(genre),
  72. FIELD_FUNC(comment),
  73. FIELD_FUNC(track),
  74. FIELD_FUNC(length),
  75. FIELD_FUNC(type),
  76. FIELD_FUNC(lastupd),
  77. FIELD_FUNC(lastplay),
  78. FIELD_FUNC(rating),
  79. NullFieldFunction, // skip lucky number 13
  80. NullFieldFunction, // gracenote ID
  81. FIELD_FUNC(playcount),
  82. FIELD_FUNC(filetime),
  83. FIELD_FUNC(filesize),
  84. FIELD_FUNC(bitrate),
  85. FIELD_FUNC(disc),
  86. FIELD_FUNC(albumartist),
  87. FIELD_FUNC(replaygain_album_gain),
  88. FIELD_FUNC(replaygain_track_gain),
  89. FIELD_FUNC(publisher),
  90. FIELD_FUNC(composer),
  91. FIELD_FUNC(bpm),
  92. FIELD_FUNC(discs),
  93. FIELD_FUNC(tracks),
  94. FIELD_FUNC(ispodcast),
  95. FIELD_FUNC(podcastchannel),
  96. FIELD_FUNC(podcastpubdate),
  97. FIELD_FUNC(GracenoteFileID),
  98. FIELD_FUNC(GracenoteExtData),
  99. FIELD_FUNC(lossless),
  100. FIELD_FUNC(category),
  101. FIELD_FUNC(codec),
  102. FIELD_FUNC(director),
  103. FIELD_FUNC(producer),
  104. FIELD_FUNC(width),
  105. FIELD_FUNC(height),
  106. FIELD_FUNC(mimetype),
  107. FIELD_FUNC(dateadded),
  108. };
  109. static int StoreField(void *record, nde_field_t field, void *context)
  110. {
  111. unsigned char id = NDE_Field_GetID(field);
  112. if (id < sizeof(field_functions)/sizeof(*field_functions))
  113. {
  114. FieldFunc field_function = field_functions[id];
  115. field_function((itemRecordW *)context, field);
  116. }
  117. return 1;
  118. }
  119. static void initRecord(itemRecordW *p)
  120. {
  121. if (p)
  122. {
  123. p->title=0;
  124. p->album=0;
  125. p->artist=0;
  126. p->comment=0;
  127. p->genre=0;
  128. p->albumartist=0;
  129. p->replaygain_album_gain=0;
  130. p->replaygain_track_gain=0;
  131. p->publisher=0;
  132. p->composer=0;
  133. p->year=-1;
  134. p->track=-1;
  135. p->tracks=-1;
  136. p->length=-1;
  137. p->rating=-1;
  138. p->playcount=-1;
  139. p->lastplay=-1;
  140. p->lastupd=-1;
  141. p->filetime=-1;
  142. p->filesize=-1;
  143. p->bitrate=-1;
  144. p->type=-1;
  145. p->disc=-1;
  146. p->discs=-1;
  147. p->bpm=-1;
  148. p->extended_info=0;
  149. p->category=0;
  150. }
  151. }
  152. __int64 ScannerRefToObjCacheNFNW(nde_scanner_t s, itemRecordW *obj, bool compat)
  153. {
  154. initRecord(obj);
  155. compat_mode = compat;
  156. NDE_Scanner_WalkFields(s, StoreField, obj);
  157. return obj->filesize;
  158. }
  159. __int64 ScannerRefToObjCacheNFNW(nde_scanner_t s, itemRecordListW *obj, bool compat)
  160. {
  161. compat_mode = compat;
  162. __int64 retval = ScannerRefToObjCacheNFNW(s, &obj->Items[obj->Size], compat);
  163. obj->Size++;
  164. return retval;
  165. }