ASDevice.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #define _WIN32_DCOM
  2. #include <winsock2.h>
  3. #include <windows.h>
  4. #include <windowsx.h>
  5. #include <rapi2.h>
  6. #include <shlobj.h>
  7. //#include <vector>
  8. #include <algorithm>
  9. #include <vector>
  10. #include "../Winamp/wa_ipc.h"
  11. #include "../Plugins/General/gen_ml/ml.h"
  12. #include "../Plugins/Library/ml_pmp/pmp.h"
  13. #include "../Plugins/Library/ml_pmp/transcoder.h"
  14. #include "../nu/AutoWide.h"
  15. #include "../nu/AutoChar.h"
  16. #include <api/service/waservicefactory.h>
  17. #include "../playlist/ifc_playlistloader.h"
  18. #include "../xml/ifc_xmlreadercallback.h"
  19. #include "../xml/obj_xml.h"
  20. #include "../xml/api__xml.h"
  21. #include "../Agave/Language/api_language.h"
  22. #include "resource.h"
  23. typedef struct {
  24. RAPIDEVICEID id;
  25. bool marked;
  26. } ejectedDevice;
  27. extern PMPDevicePlugin plugin;
  28. extern std::vector<ejectedDevice*> ejected;
  29. #define fieldlen 128
  30. class Song {
  31. public:
  32. wchar_t artist[fieldlen],album[fieldlen],title[fieldlen];
  33. wchar_t fn[MAX_PATH];
  34. int track;
  35. __int64 size;
  36. bool video;
  37. Song(const wchar_t * path, LPCE_FIND_DATA f, bool video);
  38. Song();
  39. };
  40. class Playlist {
  41. public:
  42. std::vector<Song*> songs;
  43. wchar_t name[fieldlen];
  44. wchar_t fn[MAX_PATH];
  45. bool dirty;
  46. Playlist(const wchar_t * path, LPCE_FIND_DATA f);
  47. Playlist(const wchar_t * name);
  48. };
  49. class ASDevice : public Device {
  50. public:
  51. wchar_t musicFolder[MAX_PATH];
  52. wchar_t videoFolder[MAX_PATH];
  53. wchar_t playlistFolder[MAX_PATH];
  54. wchar_t playlistFormat[16];
  55. IRAPIDevice *pIDevice;
  56. IRAPISession *pISession;
  57. Transcoder * transcoder;
  58. RAPI_DEVICEINFO devInfo;
  59. __int64 transferQueueSize;
  60. std::vector<Playlist*> playlists;
  61. void Find(const wchar_t * dir);
  62. void FoundFile(const wchar_t * path, LPCE_FIND_DATA f);
  63. void WritePlaylist(Playlist * pl);
  64. void ReadPlaylist(Playlist * pl);
  65. ASDevice(IRAPIDevice *pIDevice,IRAPISession *pISession);
  66. ~ASDevice();
  67. virtual __int64 getDeviceCapacityAvailable(); // in bytes
  68. virtual __int64 getDeviceCapacityTotal(); // in bytes
  69. virtual void Eject();
  70. virtual void Close(); // save any changes, and call PMP_IPC_DEVICEDISCONNECTED AND delete this;
  71. // return 0 for success, -1 for failed or cancelled
  72. virtual int transferTrackToDevice(const itemRecordW * track, // the track to transfer
  73. void * callbackContext, //pass this to the callback
  74. void (*callback)(void * callbackContext, wchar_t * status), // call this every so often so the GUI can be updated. Including when finished!
  75. songid_t * songid, // fill in the songid when you are finished
  76. int * killswitch // if this gets set to anything other than zero, the transfer has been cancelled by the user
  77. );
  78. virtual int trackAddedToTransferQueue(const itemRecordW * track); // return 0 to accept, -1 for "not enough space", -2 for "incorrect format"
  79. virtual void trackRemovedFromTransferQueue(const itemRecordW * track);
  80. // return the amount of space that will be taken up on the device by the track (once it has been tranferred)
  81. // or 0 for incompatable. This is usually the filesize, unless you are transcoding. An estimate is acceptable.
  82. virtual __int64 getTrackSizeOnDevice(const itemRecordW * track);
  83. virtual void deleteTrack(songid_t songid); // physically remove from device. Be sure to remove it from all the playlists!
  84. virtual void commitChanges(); // optional. Will be called at a good time to save changes
  85. virtual int getPlaylistCount(); // always at least 1. playlistnumber 0 is the Master Playlist containing all tracks.
  86. // PlaylistName(0) should return the name of the device.
  87. virtual void getPlaylistName(int playlistnumber, wchar_t * buf, int len);
  88. virtual int getPlaylistLength(int playlistnumber);
  89. virtual songid_t getPlaylistTrack(int playlistnumber,int songnum); // returns a songid
  90. virtual void setPlaylistName(int playlistnumber, const wchar_t * buf); // with playlistnumber==0, set the name of the device.
  91. virtual void playlistSwapItems(int playlistnumber, int posA, int posB); // swap the songs at position posA and posB
  92. virtual void sortPlaylist(int playlistnumber, int sortBy);
  93. virtual void addTrackToPlaylist(int playlistnumber, songid_t songid); // adds songid to the end of the playlist
  94. virtual void removeTrackFromPlaylist(int playlistnumber, int songnum); //where songnum is the position of the track in the playlist
  95. virtual void deletePlaylist(int playlistnumber);
  96. virtual int newPlaylist(const wchar_t * name); // create empty playlist, returns playlistnumber. -1 for failed.
  97. virtual void getTrackArtist(songid_t songid, wchar_t * buf, int len);
  98. virtual void getTrackAlbum(songid_t songid, wchar_t * buf, int len);
  99. virtual void getTrackTitle(songid_t songid, wchar_t * buf, int len);
  100. virtual int getTrackTrackNum(songid_t songid);
  101. virtual int getTrackDiscNum(songid_t songid){return -1;}
  102. virtual void getTrackGenre(songid_t songid, wchar_t * buf, int len){buf[0]=0;}
  103. virtual int getTrackYear(songid_t songid){return -1;}
  104. virtual __int64 getTrackSize(songid_t songid); // in bytes
  105. virtual int getTrackLength(songid_t songid){return -1;} // in millisecs
  106. virtual int getTrackBitrate(songid_t songid){return -1;} // in kbps
  107. virtual int getTrackPlayCount(songid_t songid){return 0;}
  108. virtual int getTrackRating(songid_t songid){return 0;} //0-5
  109. virtual __time64_t getTrackLastPlayed(songid_t songid){return 0;} // in unix time format
  110. virtual __time64_t getTrackLastUpdated(songid_t songid){return 0;} // in unix time format
  111. virtual int getTrackType(songid_t songid) { return ((Song *)songid)->video?1:0; }
  112. virtual void getTrackExtraInfo(songid_t songid, const wchar_t * field, wchar_t * buf, int len); //optional
  113. // feel free to ignore any you don't support
  114. virtual void setTrackArtist(songid_t songid, const wchar_t * value){}
  115. virtual void setTrackAlbum(songid_t songid, const wchar_t * value){}
  116. virtual void setTrackTitle(songid_t songid, const wchar_t * value){}
  117. virtual void setTrackTrackNum(songid_t songid, int value){}
  118. virtual void setTrackDiscNum(songid_t songid, int value){}
  119. virtual void setTrackGenre(songid_t songid, const wchar_t * value){}
  120. virtual void setTrackYear(songid_t songid, int year){}
  121. virtual void setTrackPlayCount(songid_t songid, int value){}
  122. virtual void setTrackRating(songid_t songid, int value){}
  123. virtual void setTrackLastPlayed(songid_t songid, __time64_t value){} // in unix time format
  124. virtual void setTrackLastUpdated(songid_t songid, __time64_t value){} // in unix time format
  125. virtual void setTrackExtraInfo(songid_t songid, const wchar_t * field, const wchar_t * value) {}; //optional
  126. virtual bool playTracks(songid_t * songidList, int listLength, int startPlaybackAt, bool enqueue){return false;} // return false if unsupported
  127. virtual intptr_t extraActions(intptr_t param1, intptr_t param2, intptr_t param3,intptr_t param4);
  128. // new methods as of PMPHDR_VER 0x002
  129. virtual bool copyToHardDriveSupported() {return true;}
  130. virtual __int64 songSizeOnHardDrive(songid_t song) {return getTrackSize(song);} // how big a song will be when copied back. Return -1 for not supported.
  131. virtual int copyToHardDrive(songid_t song, // the song to copy
  132. 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).
  133. void * callbackContext, //pass this to the callback
  134. void (*callback)(void * callbackContext, wchar_t * status), // call this every so often so the GUI can be updated. Including when finished!
  135. int * killswitch // if this gets set to anything other than zero, the transfer has been cancelled by the user
  136. ); // -1 for failed/not supported. 0 for success.
  137. };
  138. extern std::vector<ASDevice*> devices;