1
0

androiddevice.h 9.7 KB

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