1
0

usbdevice.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. #pragma once
  2. #include <windows.h>
  3. #include <Dbt.h>
  4. #include "../../Library/ml_pmp/transcoder.h"
  5. #include "../../Library/ml_pmp/pmp.h"
  6. #include "../nde/nde_c.h"
  7. #include "../nu/AutoLock.h"
  8. #include <vector>
  9. #define NDE_CACHE_DAT L"winamp_metadata.dat"
  10. #define NDE_CACHE_IDX L"winamp_metadata.idx"
  11. //Filename="E:\Howling Bells - Into The Chaos.MP3"
  12. //Artist="Howling Bells"
  13. //Album="E:"
  14. //Title="Into The Chaos"
  15. //Genre=""
  16. //AlbumArtist=""
  17. //Publisher=""
  18. //Composer=""
  19. //Year="0"
  20. //Track="0"
  21. //Bitrate="0"
  22. //Playcount="0"
  23. //Discnum="0"
  24. //Length="0"
  25. //Size="7767879"
  26. enum
  27. {
  28. NDE_USB_FAILURE=0,
  29. NDE_USB_SUCCESS=1,
  30. };
  31. enum
  32. {
  33. DEVICEVIEW_COL_FILENAME = 0,
  34. DEVICEVIEW_COL_ARTIST=1,
  35. DEVICEVIEW_COL_ALBUM=2,
  36. DEVICEVIEW_COL_TITLE=3,
  37. DEVICEVIEW_COL_GENRE=4,
  38. DEVICEVIEW_COL_ALBUM_ARTIST=5,
  39. DEVICEVIEW_COL_PUBLISHER=6,
  40. DEVICEVIEW_COL_COMPOSER=7,
  41. DEVICEVIEW_COL_YEAR=8,
  42. DEVICEVIEW_COL_TRACK=9,
  43. DEVICEVIEW_COL_BITRATE=10,
  44. DEVICEVIEW_COL_DISC_NUMBER=11,
  45. DEVICEVIEW_COL_LENGTH=12,
  46. DEVICEVIEW_COL_SIZE=13,
  47. DEVICEVIEW_COL_PLAY_COUNT=14,
  48. };
  49. #define TAG_CACHE L"winamp_metadata.dat"
  50. #define FIELD_LENGTH 1024
  51. class UsbSong {
  52. public:
  53. UsbSong();
  54. wchar_t filename[MAX_PATH];
  55. wchar_t artist[FIELD_LENGTH];
  56. wchar_t album[FIELD_LENGTH];
  57. wchar_t title[FIELD_LENGTH];
  58. wchar_t genre[FIELD_LENGTH];
  59. wchar_t albumartist[FIELD_LENGTH];
  60. wchar_t publisher[FIELD_LENGTH];
  61. wchar_t composer[FIELD_LENGTH];
  62. int year,track,length,discnum,bitrate,playcount;
  63. __int64 size;
  64. BOOL filled;
  65. wchar_t ext[ 6 ];
  66. };
  67. enum DeviceType {
  68. TYPE_OTHER,
  69. TYPE_PSP,
  70. };
  71. class USBPlaylist;
  72. class USBDevice : public Device
  73. {
  74. public:
  75. USBDevice(wchar_t drive, pmpDeviceLoading * load);
  76. ~USBDevice();
  77. USBDevice();
  78. void fileProbe(wchar_t * indir);
  79. void tag(void); //load ID3 tags from cache or mp3 file
  80. void createDeviceFields();
  81. int openDeviceDatabase();
  82. int openDeviceTable();
  83. void closeDeviceTable();
  84. static void CloseDatabase();
  85. void refreshNDECache(void);
  86. void fillMetaData(UsbSong *s);
  87. static int getFileInfoW(const wchar_t *filename, const wchar_t *metadata, wchar_t *dest, size_t len);
  88. void setupTranscoder();
  89. USBPlaylist* getMasterPlaylist();
  90. UsbSong* findSongInMasterPlaylist(const wchar_t *songfn);
  91. void writeRecordToDB(UsbSong* songToPrint);
  92. //////////////////////////////////////////
  93. virtual __int64 getDeviceCapacityAvailable(); // in bytes
  94. virtual __int64 getDeviceCapacityTotal(); // in bytes
  95. virtual void Eject(); // if you ejected successfully, you MUST call PMP_IPC_DEVICEDISCONNECTED and delete this;
  96. virtual void Close(); // save any changes, and call PMP_IPC_DEVICEDISCONNECTED AND delete this;
  97. // return 0 for success, -1 for failed or cancelled
  98. virtual int transferTrackToDevice(const itemRecordW * track, // the track to transfer
  99. void * callbackContext, //pass this to the callback
  100. void (*callback)(void *callbackContext, wchar_t *status), // call this every so often so the GUI can be updated. Including when finished!
  101. songid_t * songid, // fill in the songid when you are finished
  102. int * killswitch // if this gets set to anything other than zero, the transfer has been cancelled by the user
  103. );
  104. virtual int trackAddedToTransferQueue(const itemRecordW *track); // return 0 to accept, -1 for "not enough space", -2 for "incorrect format"
  105. virtual void trackRemovedFromTransferQueue(const itemRecordW *track);
  106. // return the amount of space that will be taken up on the device by the track (once it has been tranferred)
  107. // or 0 for incompatable. This is usually the filesize, unless you are transcoding. An estimate is acceptable.
  108. virtual __int64 getTrackSizeOnDevice(const itemRecordW *track);
  109. virtual void deleteTrack(songid_t songid); // physically remove from device. Be sure to remove it from all the playlists!
  110. virtual void commitChanges(); // optional. Will be called at a good time to save changes
  111. virtual int getPlaylistCount(); // always at least 1. playlistnumber 0 is the Master Playlist containing all tracks.
  112. // PlaylistName(0) should return the name of the device.
  113. virtual void getPlaylistName(int playlistnumber, wchar_t *buf, int len);
  114. virtual int getPlaylistLength(int playlistnumber);
  115. virtual songid_t getPlaylistTrack(int playlistnumber,int songnum); // returns a songid
  116. virtual void setPlaylistName(int playlistnumber, const wchar_t *buf); // with playlistnumber==0, set the name of the device.
  117. virtual void playlistSwapItems(int playlistnumber, int posA, int posB); // swap the songs at position posA and posB
  118. virtual void sortPlaylist(int playlistnumber, int sortBy);
  119. virtual void addTrackToPlaylist(int playlistnumber, songid_t songid); // adds songid to the end of the playlist
  120. virtual void removeTrackFromPlaylist(int playlistnumber, int songnum); //where songnum is the position of the track in the playlist
  121. virtual void deletePlaylist(int playlistnumber);
  122. virtual int newPlaylist(const wchar_t *name); // create empty playlist, returns playlistnumber. -1 for failed.
  123. virtual void getTrackArtist(songid_t songid, wchar_t *buf, int len);
  124. virtual void getTrackAlbum(songid_t songid, wchar_t *buf, int len);
  125. virtual void getTrackTitle(songid_t songid, wchar_t *buf, int len);
  126. virtual int getTrackTrackNum(songid_t songid);
  127. virtual int getTrackDiscNum(songid_t songid);
  128. virtual void getTrackGenre(songid_t songid, wchar_t * buf, int len);
  129. virtual int getTrackYear(songid_t songid);
  130. virtual __int64 getTrackSize(songid_t songid); // in bytes
  131. virtual int getTrackLength(songid_t songid); // in millisecs
  132. virtual int getTrackBitrate(songid_t songid); // in kbps
  133. virtual int getTrackPlayCount(songid_t songid);
  134. virtual int getTrackRating(songid_t songid); //0-5
  135. virtual __time64_t getTrackLastPlayed(songid_t songid); // in unix time format
  136. virtual __time64_t getTrackLastUpdated(songid_t songid); // in unix time format
  137. virtual void getTrackAlbumArtist(songid_t songid, wchar_t *buf, int len);
  138. virtual void getTrackPublisher(songid_t songid, wchar_t *buf, int len);
  139. virtual void getTrackComposer(songid_t songid, wchar_t *buf, int len);
  140. virtual int getTrackType(songid_t songid);
  141. virtual void getTrackExtraInfo(songid_t songid, const wchar_t *field, wchar_t *buf, int len) ; //optional
  142. // feel free to ignore any you don't support
  143. virtual void setTrackArtist(songid_t songid, const wchar_t *value);
  144. virtual void setTrackAlbum(songid_t songid, const wchar_t *value);
  145. virtual void setTrackTitle(songid_t songid, const wchar_t *value);
  146. virtual void setTrackTrackNum(songid_t songid, int value);
  147. virtual void setTrackDiscNum(songid_t songid, int value);
  148. virtual void setTrackGenre(songid_t songid, const wchar_t *value);
  149. virtual void setTrackYear(songid_t songid, int year);
  150. virtual void setTrackPlayCount(songid_t songid, int value);
  151. virtual void setTrackRating(songid_t songid, int value);
  152. virtual void setTrackLastPlayed(songid_t songid, __time64_t value); // in unix time format
  153. virtual void setTrackLastUpdated(songid_t songid, __time64_t value); // in unix time format
  154. virtual void setTrackAlbumArtist(songid_t songid, const wchar_t *value);
  155. virtual void setTrackPublisher(songid_t songid, const wchar_t *value);
  156. virtual void setTrackComposer(songid_t songid, const wchar_t *value);
  157. virtual void setTrackExtraInfo(songid_t songid, const wchar_t *field, const wchar_t *value) ; //optional
  158. virtual bool playTracks(songid_t * songidList, int listLength, int startPlaybackAt, bool enqueue); // return false if unsupported
  159. virtual intptr_t extraActions(intptr_t param1, intptr_t param2, intptr_t param3,intptr_t param4);
  160. virtual bool copyToHardDriveSupported();
  161. virtual __int64 songSizeOnHardDrive(songid_t song); // how big a song will be when copied back. Return -1 for not supported.
  162. virtual int copyToHardDrive(songid_t song, // the song to copy
  163. wchar_t * path, // path to copy to, in the form "c:\directory\song". The directory will already be created, you must append ".mp3" or whatever to this string! (there is space for at least 10 new characters).
  164. void * callbackContext, //pass this to the callback
  165. void (*callback)(void * callbackContext, wchar_t * status), // call this every so often so the GUI can be updated. Including when finished!
  166. int * killswitch // if this gets set to anything other than zero, the transfer has been cancelled by the user
  167. ); // -1 for failed/not supported. 0 for success.
  168. // art functions
  169. virtual void setArt(songid_t songid, void *buf, int w, int h); //buf is in format ARGB32*
  170. virtual pmpart_t getArt(songid_t songid);
  171. virtual void releaseArt(pmpart_t art);
  172. virtual int drawArt(pmpart_t art, HDC dc, int x, int y, int w, int h);
  173. virtual void getArtNaturalSize(pmpart_t art, int *w, int *h);
  174. virtual void setArtNaturalSize(pmpart_t art, int w, int h);
  175. virtual void getArtData(pmpart_t art, void* data); // data ARGB32* is at natural size
  176. virtual bool artIsEqual(pmpart_t a, pmpart_t b);
  177. // Additional attributes
  178. Transcoder *transcoder;
  179. wchar_t drive;
  180. DeviceType devType;
  181. wchar_t iniFile[MAX_PATH];
  182. wchar_t pldir[MAX_PATH];
  183. wchar_t songFormat[MAX_PATH];
  184. wchar_t supportedFormats[MAX_PATH];
  185. wchar_t purgeFolders[2];
  186. int pl_write_mode; // used to determine how the playlists are stored
  187. __int64 transferQueueLength;
  188. std::vector<USBPlaylist*> usbPlaylists;
  189. bool cacheUpToDate; //whether or not to output on device disconnect
  190. bool loadedUpToDate; //whether or not songs in memory are tagged and correct
  191. static nde_database_t discDB;
  192. nde_table_t deviceTable;
  193. Nullsoft::Utility::LockGuard dbcs;
  194. wchar_t ndeDataFile[100];
  195. wchar_t ndeIndexFile[100];
  196. private:
  197. // update a track with new metadata (string)
  198. void updateTrackField(UsbSong* song, unsigned int col, const void* newValue, int fieldType);
  199. bool readRecordFromDB(UsbSong* song);
  200. bool songChanged(UsbSong* song);
  201. };
  202. class USBArt
  203. {
  204. public:
  205. USBArt(ARGB32 *bits, int w, int h);
  206. ~USBArt();
  207. ARGB32 *bits;
  208. int w,h;
  209. };