P4SDevice.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. #ifndef _P4SDEVICE_H_
  2. #define _P4SDEVICE_H_
  3. #ifndef _UNICODE
  4. #define _UNICODE
  5. #endif
  6. #ifndef UNICODE
  7. #define UNICODE
  8. #endif
  9. #include <windows.h>
  10. #include <windowsx.h>
  11. #include <stdio.h>
  12. #include <tchar.h>
  13. #include <shlobj.h>
  14. #include "..\..\General\gen_ml/itemlist.h"
  15. #include "..\..\General\gen_ml/ml.h"
  16. #include "..\..\Library\ml_pmp/pmp.h"
  17. #include "..\..\Library\ml_pmp/transcoder.h"
  18. #include "../winamp/wa_ipc.h"
  19. #include "../winamp/ipc_pe.h"
  20. #include "../Agave/Language/api_language.h"
  21. #include <api/service/waServiceFactory.h>
  22. #include "resource1.h"
  23. #include <tataki/bitmap/bitmap.h>
  24. #include <tataki/canvas/bltcanvas.h>
  25. #include <api/service/svcs/svc_imgload.h>
  26. #include <api/service/svcs/svc_imgwrite.h>
  27. #include <api/memmgr/api_memmgr.h>
  28. extern api_memmgr *memoryManager;
  29. #define WASABI_API_MEMMGR memoryManager
  30. #include "../Agave/AlbumArt/api_albumart.h"
  31. extern api_albumart *albumArtApi;
  32. #define AGAVE_API_ALBUMART albumArtApi
  33. #include "../devices/api_devicemanager.h"
  34. extern api_devicemanager *deviceManagerApi;
  35. #define AGAVE_API_DEVICEMANAGER deviceManagerApi
  36. class P4SDevice;
  37. class MyProgress;
  38. class TransferItem;
  39. #ifndef __RPC__in
  40. #define __RPC__in
  41. #define __RPC__in_opt
  42. #define __RPC__in_ecount_full(x)
  43. #define __RPC__in_ecount_full_opt(x)
  44. #define __RPC__in_ecount_full_string(x)
  45. #define __RPC__inout
  46. #define __RPC__inout_opt
  47. #define __RPC__deref_opt_inout_opt
  48. #define __RPC__deref_inout_ecount_full_opt_string(x)
  49. #define __RPC__inout_ecount_full(x)
  50. #define __RPC__out
  51. #define __RPC__out_ecount_full(x)
  52. #define __RPC__out_ecount_full_string(x)
  53. #define __RPC__out_ecount_part(x,y)
  54. #define __RPC__deref_out_ecount_full_opt(x)
  55. #define __RPC__deref_out_opt_string
  56. #define __RPC__deref_out_opt
  57. #endif
  58. #include "WMDRMDeviceApp.h"
  59. #include "msWMDM.h" // Include headers for Windows Media Device Manager.
  60. #include "Sac.h" // Include authentication headers.
  61. #include "Scclient.h" // Include authentication client headers.
  62. #include "MyProgress.h"
  63. #include "resource1.h"
  64. extern PMPDevicePlugin plugin;
  65. class Playlist {
  66. public:
  67. wchar_t name[128];
  68. IWMDMStorage4 * storage;
  69. C_ItemList songs;
  70. IWMDMMetaData * meta;
  71. bool modified;
  72. Playlist() : storage(0),meta(0),modified(false){ name[0]=0; }
  73. };
  74. class Song {
  75. public:
  76. IWMDMStorage4 * storage;
  77. IWMDMMetaData * meta;
  78. bool video;
  79. bool modified;
  80. wchar_t * artist, * album;
  81. IWMDMStorage4 * alb;
  82. IWMDMMetaData * albmeta;
  83. Song() {artist=album=NULL; storage=0; meta=0; video = 0; modified = 0; alb=0; albmeta=0;}
  84. virtual ~Song() {if(artist) free(artist); if(album) free(album); if(alb) alb->Release(); if(albmeta) albmeta->Release();}
  85. };
  86. class TransferItem {
  87. public:
  88. int phase;
  89. void * callbackContext;
  90. void (*callback)(void * callbackContext, wchar_t * status);
  91. wchar_t *file;
  92. const itemRecordW * track;
  93. songid_t * songid;
  94. int * killswitch;
  95. P4SDevice * dev;
  96. IWMDMMetaData * meta;
  97. IWMDMProgress * progress;
  98. int pc;
  99. bool video;
  100. };
  101. class P4SDevice : public Device {
  102. public:
  103. bool requiresALB;
  104. int error;
  105. Transcoder * transcoder;
  106. wchar_t *musicDir, *videoDir;
  107. bool noMetadata, supportsVideo;
  108. __int64 transferQueueSize;
  109. C_ItemList playlists;
  110. C_ItemList albfiles;
  111. IWMDMStorage4 * playlistsDir;
  112. wchar_t name[100];
  113. IWMDMDevice3* WMDevice;
  114. P4SDevice(IWMDMDevice3* pIDevice,bool noMetadata);
  115. virtual void Load();
  116. virtual ~P4SDevice();
  117. void traverseStorage(IWMDMStorage * store, int level=0, wchar_t * artist=0, wchar_t * album=0);
  118. void foundSong(IWMDMStorage4 * store, IWMDMMetaData * meta, bool video, int pl=0,wchar_t * artist=0, wchar_t * album=0, IWMDMStorage4 * alb=0, IWMDMMetaData * albmeta=0);
  119. void foundPlaylist(IWMDMStorage4 * store, IWMDMMetaData * meta);
  120. bool songsEqual(songid_t a, songid_t b);
  121. int songsCmp(songid_t a, songid_t b);
  122. virtual __int64 getDeviceCapacityAvailable(); // in bytes
  123. virtual __int64 getDeviceCapacityTotal(); // in bytes
  124. virtual void Eject(){Close();}; // if you ejected successfully, you MUST call plugin.deviceDisconnected(this) and delete this;
  125. virtual void Close(); // save any changes, and call plugin.deviceDisconnected(this) AND delete this;
  126. virtual void doTransfer(TransferItem * t);
  127. // return the songid when transfer is finished.
  128. // call the callback with a percentage and the number of bytes copied so far every so often (to update the GUI)
  129. // return 0 for success, -1 for failed or cancelled
  130. virtual int transferTrackToDevice(const itemRecordW * track, // the track to transfer
  131. void * callbackContext, //pass this to the callback
  132. void (*callback)(void * callbackContext, wchar_t * status), // call this every so often so the GUI can be updated. Including when finished!
  133. songid_t * songid, // fill in the songid when you are finished
  134. int * killswitch // if this gets set to 1, the transfer has been cancelled by the user
  135. );
  136. virtual int trackAddedToTransferQueue(const itemRecordW * track); // return 0 to accept, -1 for "not enough space", -2 for "incorrect format"
  137. virtual void trackRemovedFromTransferQueue(const itemRecordW * track);
  138. virtual __int64 getTrackSizeOnDevice(const itemRecordW * track); // return the amount of space taken up on the device by the track, or 0 for incompatable (usually the filesize, unless you are transcoding)
  139. virtual void deleteTrack(songid_t songid); // physically remove from device. Be sure to remove it from all the playlists!
  140. virtual void commitChanges(); // optional. Will be called at a good time to save changes
  141. virtual int getPlaylistCount(); // always at least 1. playlistnumber 0 is the Master Playlist containing all tracks.
  142. // PlaylistName(0) should return the name of the device.
  143. virtual void getPlaylistName(int playlistnumber, wchar_t * buf, int len);
  144. virtual int getPlaylistLength(int playlistnumber);
  145. virtual songid_t getPlaylistTrack(int playlistnumber,int songnum); // returns a songid
  146. virtual void setPlaylistName(int playlistnumber, const wchar_t *buf); // playlistnumber != 0!!
  147. virtual void playlistSwapItems(int playlistnumber, int posA, int posB); // swap the songs at position posA and posB
  148. virtual void sortPlaylist(int playlistnumber, int sortBy);
  149. virtual void addTrackToPlaylist(int playlistnumber, songid_t songid); // adds songid to the end of the playlist
  150. virtual void removeTrackFromPlaylist(int playlistnumber, int songnum); //where songnum is the position of the track in the playlist
  151. virtual void deletePlaylist(int playlistnumber);
  152. virtual int newPlaylist(const wchar_t * name); // create empty playlist, returns playlistnumber
  153. virtual void getTrackArtist(songid_t songid, wchar_t * buf, int len);
  154. virtual void getTrackAlbum(songid_t songid, wchar_t * buf, int len);
  155. virtual void getTrackTitle(songid_t songid, wchar_t * buf, int len);
  156. virtual int getTrackTrackNum(songid_t songid);
  157. virtual int getTrackDiscNum(songid_t songid){return -1;}
  158. virtual void getTrackGenre(songid_t songid, wchar_t * buf, int len);
  159. virtual int getTrackYear(songid_t songid);
  160. virtual __int64 getTrackSize(songid_t songid); // in bytes
  161. virtual int getTrackLength(songid_t songid); // in millisecs
  162. virtual int getTrackBitrate(songid_t songid); // in kbps
  163. virtual int getTrackPlayCount(songid_t songid);
  164. virtual int getTrackRating(songid_t songid); //0-5
  165. virtual __time64_t getTrackLastPlayed(songid_t songid); // in unix time format
  166. virtual __time64_t getTrackLastUpdated(songid_t songid); // in unix time format
  167. virtual void getTrackAlbumArtist(songid_t songid, wchar_t * buf, int len);
  168. virtual void getTrackComposer(songid_t songid, wchar_t * buf, int len);
  169. virtual int getTrackType(songid_t songid);
  170. virtual void getTrackExtraInfo(songid_t songid, const wchar_t *field, wchar_t * buf, int len);
  171. Song * lastChange;
  172. void PreCommit(Song * song);
  173. // feel free to ignore any you don't support
  174. virtual void setTrackArtist(songid_t songid, const wchar_t * value);
  175. virtual void setTrackAlbum(songid_t songid, const wchar_t * value);
  176. virtual void setTrackTitle(songid_t songid, const wchar_t * value);
  177. virtual void setTrackTrackNum(songid_t songid, int value);
  178. virtual void setTrackDiscNum(songid_t songid, int value){};
  179. virtual void setTrackGenre(songid_t songid, const wchar_t * value);
  180. virtual void setTrackYear(songid_t songid, int year);
  181. virtual void setTrackPlayCount(songid_t songid, int value);
  182. virtual void setTrackRating(songid_t songid, int value);
  183. virtual void setTrackLastPlayed(songid_t songid, __time64_t value); // in unix time format
  184. virtual void setTrackLastUpdated(songid_t songid, __time64_t value); // in unix time format
  185. virtual void setTrackAlbumArtist(songid_t songid, const wchar_t * value);
  186. virtual void setTrackComposer(songid_t songid, const wchar_t * value);
  187. virtual void setTrackExtraInfo(songid_t songid, const wchar_t * field, const wchar_t * value) {}; //optional
  188. virtual bool playTracks(songid_t * songidList, int listLength, int startPlaybackAt, bool enqueue){return false;}; // return false if unsupported
  189. virtual intptr_t extraActions(intptr_t param1, intptr_t param2, intptr_t param3,intptr_t param4);
  190. virtual bool copyToHardDriveSupported() {return true;}
  191. virtual __int64 songSizeOnHardDrive(songid_t song) {return getTrackSize(song);} // how big a song will be when copied back. Return -1 for not supported.
  192. virtual int copyToHardDrive(songid_t song, // the song to copy
  193. 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).
  194. void * callbackContext, //pass this to the callback
  195. void (*callback)(void * callbackContext, wchar_t * status), // call this every so often so the GUI can be updated. Including when finished!
  196. int * killswitch // if this gets set to anything other than zero, the transfer has been cancelled by the user
  197. ); // -1 for failed/not supported. 0 for success.
  198. virtual void setArt(songid_t songid, void *buf, int w, int h); //buf is in format ARGB32*
  199. virtual pmpart_t getArt(songid_t songid);
  200. virtual void releaseArt(pmpart_t art);
  201. virtual int drawArt(pmpart_t art, HDC dc, int x, int y, int w, int h);
  202. virtual void getArtNaturalSize(pmpart_t art, int *w, int *h);
  203. virtual void setArtNaturalSize(pmpart_t art, int w, int h);
  204. virtual void getArtData(pmpart_t art, void* data); // data ARGB32* is at natural size
  205. virtual bool artIsEqual(pmpart_t a, pmpart_t b);
  206. };
  207. #endif // _P4SDEVICE_H_