pmp.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. #ifndef __PMP_H_
  2. #define __PMP_H_
  3. #define WIN32_LEAN_AND_MEAN
  4. #include <windows.h> // needed for HDC and stuff
  5. #include <stddef.h>
  6. #include "..\..\General\gen_ml/ml.h" // for itemRecordW
  7. // make sure you include ml.h before you include this, wherever you include it.
  8. #ifdef __cplusplus
  9. class api_service;
  10. #endif
  11. typedef intptr_t songid_t;
  12. typedef intptr_t pmpart_t;
  13. // What metadata the device supports
  14. #define SUPPORTS_ARTIST 0x00000001
  15. #define SUPPORTS_ALBUM 0x00000002
  16. #define SUPPORTS_TITLE 0x00000004
  17. #define SUPPORTS_TRACKNUM 0x00000008
  18. #define SUPPORTS_DISCNUM 0x00000010
  19. #define SUPPORTS_GENRE 0x00000020
  20. #define SUPPORTS_YEAR 0x00000040
  21. #define SUPPORTS_SIZE 0x00000080
  22. #define SUPPORTS_LENGTH 0x00000100
  23. #define SUPPORTS_BITRATE 0x00000200
  24. #define SUPPORTS_PLAYCOUNT 0x00000400
  25. #define SUPPORTS_RATING 0x00000800
  26. #define SUPPORTS_LASTPLAYED 0x00001000
  27. #define SUPPORTS_LASTUPDATED 0x00002000
  28. #define SUPPORTS_ALBUMARTIST 0x00004000
  29. #define SUPPORTS_COMPOSER 0x00008000
  30. #define SUPPORTS_PUBLISHER 0x00010000
  31. #define SUPPORTS_ALBUMART 0x00020000
  32. #define SUPPORTS_MIMETYPE 0x00040000
  33. #define SUPPORTS_DATEADDED 0x00080000
  34. // constants for sorting playlists
  35. #define SORTBY_ARTIST 0
  36. #define SORTBY_ALBUM 1
  37. #define SORTBY_TITLE 2
  38. #define SORTBY_TRACKNUM 3
  39. #define SORTBY_DISCNUM 4
  40. #define SORTBY_GENRE 5
  41. #define SORTBY_RATING 6
  42. #define SORTBY_PLAYCOUNT 7
  43. #define SORTBY_LASTPLAYED 8
  44. #define SORTBY_DATEADDED 9
  45. // for get/setTrackExtraInfo, FIELD_* will be passed in as the "field" parameter. check using "if(!wcscmp(field,FIELD_*))" or similar
  46. #define FIELD_EXTENSION L"ext" // return the file extention, eg L"mp3". Only needed for indirect playback, will never be set.
  47. // firstly a little clarification between what a playlistnumber is and a songid is.
  48. // playlist numbers are always 0,1,2,...,getPlaylistCount() (thus, if playlist 1 is deleted,
  49. // the number of all playlists except 0 change)
  50. // songids are unique identifiers which persist even when other songs are removed.
  51. // Feel free to use a pointer OR an integer as a songid.
  52. // NOTE: wherever stated, len means number of characters NOT bytes available in the buffer
  53. /* benski> All calls will be made on the 'main thread', with the following exceptions
  54. transferTrackToDevice() on the transfer thread
  55. trackRemovedFromTransferQueue() on the transfer thread
  56. copyToHardDrive() on the transfer thread
  57. */
  58. class Device {
  59. protected:
  60. Device() {}
  61. ~Device() {}
  62. public:
  63. virtual __int64 getDeviceCapacityAvailable()=0; // in bytes
  64. virtual __int64 getDeviceCapacityTotal()=0; // in bytes
  65. virtual void Eject()=0; // if you ejected successfully, you MUST call PMP_IPC_DEVICEDISCONNECTED and delete this;
  66. virtual void Close()=0; // save any changes, and call PMP_IPC_DEVICEDISCONNECTED AND delete this;
  67. // return 0 for success, -1 for failed or cancelled
  68. virtual int transferTrackToDevice(const itemRecordW * track, // the track to transfer
  69. void * callbackContext, //pass this to the callback
  70. void (*callback)(void *callbackContext, wchar_t *status), // call this every so often so the GUI can be updated. Including when finished!
  71. songid_t * songid, // fill in the songid when you are finished
  72. int * killswitch // if this gets set to anything other than zero, the transfer has been cancelled by the user
  73. )=0;
  74. virtual int trackAddedToTransferQueue(const itemRecordW *track)=0; // return 0 to accept, -1 for "not enough space", -2 for "incorrect format"
  75. virtual void trackRemovedFromTransferQueue(const itemRecordW *track)=0;
  76. // return the amount of space that will be taken up on the device by the track (once it has been tranferred)
  77. // or 0 for incompatable. This is usually the filesize, unless you are transcoding. An estimate is acceptable.
  78. virtual __int64 getTrackSizeOnDevice(const itemRecordW *track)=0;
  79. virtual void deleteTrack(songid_t songid)=0; // physically remove from device. Be sure to remove it from all the playlists!
  80. virtual void commitChanges(){} // optional. Will be called at a good time to save changes
  81. virtual int getPlaylistCount()=0; // always at least 1. playlistnumber 0 is the Master Playlist containing all tracks.
  82. // PlaylistName(0) should return the name of the device.
  83. virtual void getPlaylistName(int playlistnumber, wchar_t *buf, int len)=0;
  84. virtual int getPlaylistLength(int playlistnumber)=0;
  85. virtual songid_t getPlaylistTrack(int playlistnumber,int songnum)=0; // returns a songid
  86. virtual void setPlaylistName(int playlistnumber, const wchar_t *buf)=0; // with playlistnumber==0, set the name of the device.
  87. virtual void playlistSwapItems(int playlistnumber, int posA, int posB)=0; // swap the songs at position posA and posB
  88. virtual void sortPlaylist(int playlistnumber, int sortBy)=0;
  89. virtual void addTrackToPlaylist(int playlistnumber, songid_t songid)=0; // adds songid to the end of the playlist
  90. virtual void removeTrackFromPlaylist(int playlistnumber, int songnum)=0; //where songnum is the position of the track in the playlist
  91. virtual void deletePlaylist(int playlistnumber)=0;
  92. virtual int newPlaylist(const wchar_t *name)=0; // create empty playlist, returns playlistnumber. -1 for failed.
  93. virtual void getTrackArtist(songid_t songid, wchar_t *buf, int len)=0;
  94. virtual void getTrackAlbum(songid_t songid, wchar_t *buf, int len)=0;
  95. virtual void getTrackTitle(songid_t songid, wchar_t *buf, int len)=0;
  96. virtual int getTrackTrackNum(songid_t songid)=0;
  97. virtual int getTrackDiscNum(songid_t songid)=0;
  98. virtual void getTrackGenre(songid_t songid, wchar_t * buf, int len)=0;
  99. virtual int getTrackYear(songid_t songid)=0;
  100. virtual __int64 getTrackSize(songid_t songid)=0; // in bytes
  101. virtual int getTrackLength(songid_t songid)=0; // in millisecs
  102. virtual int getTrackBitrate(songid_t songid)=0; // in kbps
  103. virtual int getTrackPlayCount(songid_t songid)=0;
  104. virtual int getTrackRating(songid_t songid)=0; //0-5
  105. virtual __time64_t getTrackLastPlayed(songid_t songid)=0; // in unix time format
  106. virtual __time64_t getTrackLastUpdated(songid_t songid)=0; // in unix time format
  107. virtual void getTrackAlbumArtist(songid_t songid, wchar_t *buf, int len){};
  108. virtual void getTrackPublisher(songid_t songid, wchar_t *buf, int len){};
  109. virtual void getTrackComposer(songid_t songid, wchar_t *buf, int len){};
  110. virtual void getTrackMimeType(songid_t songid, wchar_t *buf, int len){};
  111. virtual __time64_t getTrackDateAdded(songid_t songid){ return -1; }; // in unix time format
  112. virtual int getTrackType(songid_t songid) { return 0; }
  113. virtual void getTrackExtraInfo(songid_t songid, const wchar_t *field, wchar_t *buf, int len) {}; //optional
  114. // feel free to ignore any you don't support
  115. virtual void setTrackArtist(songid_t songid, const wchar_t *value)=0;
  116. virtual void setTrackAlbum(songid_t songid, const wchar_t *value)=0;
  117. virtual void setTrackTitle(songid_t songid, const wchar_t *value)=0;
  118. virtual void setTrackTrackNum(songid_t songid, int value)=0;
  119. virtual void setTrackDiscNum(songid_t songid, int value)=0;
  120. virtual void setTrackGenre(songid_t songid, const wchar_t *value)=0;
  121. virtual void setTrackYear(songid_t songid, int year)=0;
  122. virtual void setTrackPlayCount(songid_t songid, int value)=0;
  123. virtual void setTrackRating(songid_t songid, int value)=0;
  124. virtual void setTrackLastPlayed(songid_t songid, __time64_t value)=0; // in unix time format
  125. virtual void setTrackLastUpdated(songid_t songid, __time64_t value)=0; // in unix time format
  126. virtual void setTrackAlbumArtist(songid_t songid, const wchar_t *value){};
  127. virtual void setTrackPublisher(songid_t songid, const wchar_t *value){};
  128. virtual void setTrackComposer(songid_t songid, const wchar_t *value){};
  129. virtual void setTrackExtraInfo(songid_t songid, const wchar_t *field, const wchar_t *value) {}; //optional
  130. virtual bool playTracks(songid_t * songidList, int listLength, int startPlaybackAt, bool enqueue)=0; // return false if unsupported
  131. virtual intptr_t extraActions(intptr_t param1, intptr_t param2, intptr_t param3,intptr_t param4){return 0;}
  132. virtual bool copyToHardDriveSupported() {return false;}
  133. virtual __int64 songSizeOnHardDrive(songid_t song) {return -1;} // how big a song will be when copied back. Return -1 for not supported.
  134. virtual int copyToHardDrive(songid_t song, // the song to copy
  135. 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).
  136. void * callbackContext, //pass this to the callback
  137. void (*callback)(void * callbackContext, wchar_t * status), // call this every so often so the GUI can be updated. Including when finished!
  138. int * killswitch // if this gets set to anything other than zero, the transfer has been cancelled by the user
  139. ) {return -1;} // -1 for failed/not supported. 0 for success.
  140. // art functions
  141. virtual void setArt(songid_t songid, void *buf, int w, int h){} //buf is in format ARGB32*
  142. virtual pmpart_t getArt(songid_t songid){return NULL;}
  143. virtual void releaseArt(pmpart_t art){}
  144. virtual int drawArt(pmpart_t art, HDC dc, int x, int y, int w, int h) {return 0;}
  145. virtual void getArtNaturalSize(pmpart_t art, int *w, int *h){*w=*h=0;}
  146. virtual void setArtNaturalSize(pmpart_t art, int w, int h){}
  147. virtual void getArtData(pmpart_t art, void* data){} // data ARGB32* is at natural size
  148. virtual bool artIsEqual(pmpart_t a, pmpart_t b){return false;}
  149. };
  150. #define PMPHDR_VER 0x10
  151. /*
  152. 0x10 is for Winamp 5.66+
  153. - it adds passing a api_service *service
  154. 0x9 is for Winamp 5.63+
  155. - it now requires that plugins handle addTrackToPlaylist(0, ...)
  156. so plugins that don't want to directly add to their database via transferTrackToDevice() [which happens off-thread]
  157. can do it during addTrackToPlaylist(0, ...) [which happens on the main thread]
  158. - changes description from char* to wchar_t* (as there's no 3rd party pmp_* we can make such a breaking change)
  159. */
  160. // The MessageProc could recieve any of the following..
  161. #define PMP_DEVICECHANGE 0x100 // param1=WPARAM, param2=LPARAM. See http://msdn.microsoft.com/library/en-us/devio/base/wm_devicechange.asp
  162. #define PMP_CONFIG 0x101 // param1 will be the parent HWND. return 1 if you implement this
  163. #define PMP_NO_CONFIG 0x102 // return TRUE to allow the plug-in config button to be disabled as applicable
  164. // use SendMessage(hwndPortablesParent,WM_PMP_IPC,param,PMP_IPC_*); on any of the following
  165. #define WM_PMP_IPC WM_USER+10
  166. #define PMP_IPC_DEVICECONNECTED 0x100 // pass a Device *
  167. #define PMP_IPC_DEVICEDISCONNECTED 0x101 // pass a Device *
  168. #define PMP_IPC_DEVICELOADING 0x102 // pass a pmpDeviceLoading *.
  169. // This is optional, call PMP_IPC_DEVICECONNECTED when loading is finished
  170. // or PMP_IPC_DEVICEDISCONNECTED to cancel.
  171. // while a device is being loaded, DEVICE_SET_ICON will be called, nothing else.
  172. #define PMP_IPC_DEVICENAMECHANGED 0x103 // pass a Device *
  173. // added 5.64+
  174. #define PMP_IPC_DEVICECLOUDTRANSFER 0x104 // pass a cloudDeviceTransfer *
  175. // added 5.64+
  176. #define PMP_IPC_GETCLOUDTRANSFERS 0x105 // pass a Cloudfiles * (defined as typedef nu::PtrList<wchar_t>)
  177. // added 5.64+
  178. typedef struct {
  179. wchar_t filenames[MAX_PATH + 1]; // list of filename(s) to transfer to the cloud device
  180. void * device_token; // token identifier of the cloud device to transfer to
  181. } cloudDeviceTransfer; // added 5.64+
  182. typedef struct {
  183. Device * dev;
  184. // filled in by ml_pmp
  185. void (*UpdateCaption)(wchar_t * caption, void * context); // call this with the context to update the caption
  186. void * context;
  187. } pmpDeviceLoading;
  188. typedef struct {
  189. HWND parent;
  190. const char * dev_name;
  191. } pmpDevicePrefsView;
  192. #define PMP_IPC_GET_TRANSCODER 0x200 // returns a Transcoder*, pass your Device* (you must have previously called PMP_IPC_DEVICECONNECTED)
  193. #define PMP_IPC_RELEASE_TRANSCODER 0x201 // pass your Transcoder*, no return value
  194. #define PMP_IPC_ENUM_ACTIVE_DRIVES 0x300 // pass your function in wParam, or if you pass wParam = 0, it will return a function pointer (type ENUMDRIVES) you can call directly
  195. typedef void (*ENUM_DRIVES_CALLBACK)(wchar_t, UINT);
  196. typedef void (*ENUMDRIVES)(ENUM_DRIVES_CALLBACK callback);
  197. #define PMP_IPC_GET_INI_FILE 0x301 // pass a Device*, returns a wchar_t*
  198. #define PMP_IPC_GET_PREFS_VIEW 0x302 // pass a pmpDevicePrefsView*, returns a HWND
  199. // The following may be recieved by Device::extraActions (as param1)
  200. #define DEVICE_SET_ICON 0x0 // param2 is of type MLTREEIMAGE *, modify it to use your own icon for the device in the ML tree
  201. #define DEVICE_SUPPORTED_METADATA 0x1 // return a load of SUPPORTS_* ORed together. If you return 0, all is assumed.
  202. #define DEVICE_DOES_NOT_SUPPORT_EDITING_METADATA 0x3 // return 1 if metadata cannot be edited, 0 otherwise.
  203. #define DEVICE_CAN_RENAME_DEVICE 0x4 // return 1 if the device can be renamed. setPlaylistName(0,name) will be used to rename the device
  204. #define DEVICE_GET_INI_FILE 0x5 // param2 is wchar_t * of length MAX_PATH. Fill it with the location of the inifile that should be used.
  205. #define DEVICE_GET_PREFS_DIALOG 0x6 // param2 is a pref_tab*, fill it in if you want to put your own config in. On WM_INITDIALOG lParam will be a prefsParam *
  206. #define DEVICE_REFRESH 0x7 // F5 was pressed. return 1 to do an in-place update
  207. #define DEVICE_ADDPODCASTGROUP 0x8 // for ipod. param2=int playlistid, param3=int position, param4=wchar_t* channelname
  208. #define DEVICE_ADDPODCASTGROUP_FINISH 0x9 // for ipod. param2=int playlistid
  209. #define DEVICE_SUPPORTS_VIDEO 0xA // return 1 if you support video
  210. #define DEVICE_DONE_SETTING 0xB // param2=songid_t, tells your plugin that a series of setTrack*() functions are done being called for a particular track
  211. #define DEVICE_VETO_ENCODER 0xC // param2==fourcc. return 1 to remove the encoder from the transcoding preferences
  212. #define DEVICE_GET_ICON 0xD // param2=width, param3=height, param4 = wchar_t[260] to put your path into (possibly res:// protocol)
  213. #define DEVICE_SUPPORTS_PODCASTS 0xE // return 0 if you support podcasts. return 1 if you don't want them transferred
  214. #define DEVICE_GET_CONNECTION_TYPE 0xF // return 1 if you support. param2 is a const char ** that you should set to a static connect type string.
  215. #define DEVICE_GET_UNIQUE_ID 0x10 // return 1 if you support. copy a unique name into param2 (char *), param3 will be the allocated size (# of characters)
  216. #define DEVICE_GET_MODEL 0x11 // return 1 if you support, param2 = (wchar_t*)buffer - model name; param3 = (unsigned int)bufferSize - buffer size; param4 - not used.
  217. #define DEVICE_SENDTO_UNSUPPORTED 0x12 // return 1 if you don't support send-to
  218. #define DEVICE_GET_DISPLAY_TYPE 0x13 // return 1 if you support, param2 = (wchar_t*)buffer - model name; param3 = (unsigned int)bufferSize - buffer size; param4 - not used.
  219. #define DEVICE_VETO_TRANSCODING 0x14 // return 1 if you don't support transcoding and don't want to show the 'Transcoding' preference tab (also see DEVICE_VETO_ENCODER)
  220. #define DEVICE_GET_PREFS_PARENT 0x15 // return prefsDlgRecW * of the parent preference page you want the device preference page to be a child off. return 0 for default placing
  221. #define DEVICE_GET_CLOUD_SOURCES_MENU 0x16 // return HMENU if you support cloud source menus and have one to provide (only called as needed). param2=(int*)num_cloud_devices. param4=(int)songid i.e. clicked item or -1 for selection
  222. #define DEVICE_DO_CLOUD_SOURCES_MENU 0x17 // a cloud sources menu item was clicked. param2=(int)menu_id from the menu provided via DEVICE_GET_CLOUD_SOURCES_MENU.
  223. // param3=(int)mode where 0 is via submenu and 1 is the menu only i.e. single-selection.
  224. // param4=(CItemList*) of songid_t so it is possible to do multiple selection handling
  225. // return 1 if needing the item to be removed from the view
  226. #define DEVICE_IS_CLOUD_TX_DEVICE 0x18 // param1=(nx_string_t) return 1 if device token matches ours
  227. #define DEVICE_SYNC_UNSUPPORTED 0x19 // return 1 if you don't support sync
  228. #define DEVICE_GET_CLOUD_DEVICE_ID 0x20 // return the device id
  229. #define DEVICE_NOT_READY_TO_VIEW 0x21 // return 1 if view is not ready to be shown
  230. #define DEVICE_GET_NODE_ICON_ID 0x22 // return the resource id of the node icon
  231. #define DEVICE_PLAYLISTS_UNSUPPORTED 0x23 // return 1 if you don't support playlists
  232. #define DEVICE_DOES_NOT_SUPPORT_REMOVE 0x24 // return 1 if you don't support remove / eject
  233. #define CLOUD_SOURCE_MENUS 60000
  234. #define CLOUD_SOURCE_MENUS_UPPER 60000 + 20
  235. #define CLOUD_SOURCE_MENUS_PL_UPPER 60000 + 200
  236. typedef struct {
  237. wchar_t title[98];
  238. int res_id;
  239. DLGPROC dlg_proc;
  240. HINSTANCE hinst;
  241. } pref_tab;
  242. typedef struct {
  243. HWND parent;
  244. Device * dev;
  245. void (*config_tab_init)(HWND tab,HWND m_hwndDlg); // call this on WM_INITDIALOG
  246. } prefsParam;
  247. typedef struct {
  248. int version; // should be PMPHDR_VER
  249. wchar_t *description; // a textual desciption (including version info)
  250. int ( __cdecl *init)(); // called when winamp is loaded, for any one-time init
  251. void ( __cdecl *quit)(); // called when winamp is unloaded, for any one-time deinit
  252. INT_PTR ( __cdecl *MessageProc)(int msg, INT_PTR param1, INT_PTR param2, INT_PTR param3);
  253. // All the following data is filled in by ml_pmp
  254. HWND hwndWinampParent; // send this any of the WM_WA_IPC messages
  255. HWND hwndLibraryParent; // send this any of the WM_ML_IPC messages
  256. HWND hwndPortablesParent; // send this any of the WM_PMP_IPC messages
  257. HINSTANCE hDllInstance; // this plugins instance
  258. // filled in by Winamp (added 5.66+ to replace need to call IPC_GET_API_SERVICE on loading)
  259. #ifdef __cplusplus
  260. api_service *service;
  261. #else
  262. void * service;
  263. #endif
  264. } PMPDevicePlugin;
  265. // return values from the init(..) which determines if Winamp will continue loading
  266. // and handling the plugin or if it will disregard the load attempt. If PMP_INIT_FAILURE
  267. // is returned then the plugin will be listed as [NOT LOADED] on the plug-in prefs page.
  268. #define PMP_INIT_SUCCESS 0
  269. #define PMP_INIT_FAILURE 1
  270. // return values from the winampUninstallPlugin(HINSTANCE hdll, HWND parent, int param)
  271. // which determine if we can uninstall the plugin immediately or on winamp restart
  272. #define PMP_PLUGIN_UNINSTALL_NOW 0x0
  273. #define PMP_PLUGIN_UNINSTALL_REBOOT 0x1
  274. #endif