1
0

pluginshell.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. /*
  2. LICENSE
  3. -------
  4. Copyright 2005-2013 Nullsoft, Inc.
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted provided that the following conditions are met:
  8. * Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above copyright notice,
  11. this list of conditions and the following disclaimer in the documentation
  12. and/or other materials provided with the distribution.
  13. * Neither the name of Nullsoft nor the names of its contributors may be used to
  14. endorse or promote products derived from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  16. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  21. IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  22. OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #ifndef __NULLSOFT_DX9_PLUGIN_SHELL_H__
  25. #define __NULLSOFT_DX9_PLUGIN_SHELL_H__ 1
  26. #include "shell_defines.h"
  27. #include "dxcontext.h"
  28. #include "fft.h"
  29. #include "defines.h"
  30. #include "textmgr.h"
  31. #include "icon_t.h"
  32. #include <vector>
  33. #define TIME_HIST_SLOTS 128 // # of slots used if fps > 60. half this many if fps==30.
  34. #define MAX_SONGS_PER_PAGE 40
  35. typedef struct
  36. {
  37. wchar_t szFace[256];
  38. int nSize; // size requested @ font creation time
  39. int bBold;
  40. int bItalic;
  41. int bAntiAliased;
  42. } td_fontinfo;
  43. typedef struct
  44. {
  45. float imm[2][3]; // bass, mids, treble, no damping, for each channel (long-term average is 1)
  46. float avg[2][3]; // bass, mids, treble, some damping, for each channel (long-term average is 1)
  47. float med_avg[2][3]; // bass, mids, treble, more damping, for each channel (long-term average is 1)
  48. float long_avg[2][3]; // bass, mids, treble, heavy damping, for each channel (long-term average is 1)
  49. float infinite_avg[2][3]; // bass, mids, treble: winamp's average output levels. (1)
  50. float fWaveform[2][576]; // Not all 576 are valid! - only NUM_WAVEFORM_SAMPLES samples are valid for each channel (note: NUM_WAVEFORM_SAMPLES is declared in shell_defines.h)
  51. float fSpectrum[2][NUM_FREQUENCIES]; // NUM_FREQUENCIES samples for each channel (note: NUM_FREQUENCIES is declared in shell_defines.h)
  52. } td_soundinfo; // ...range is 0 Hz to 22050 Hz, evenly spaced.
  53. class CPluginShell
  54. {
  55. public:
  56. // GET METHODS
  57. // ------------------------------------------------------------
  58. int GetFrame(); // returns current frame # (starts at zero)
  59. float GetTime(); // returns current animation time (in seconds) (starts at zero) (updated once per frame)
  60. float GetFps(); // returns current estimate of framerate (frames per second)
  61. eScrMode GetScreenMode(); // returns WINDOWED, FULLSCREEN, FAKE_FULLSCREEN, DESKTOP, or NOT_YET_KNOWN (if called before or during OverrideDefaults()).
  62. HWND GetWinampWindow(); // returns handle to Winamp main window
  63. HINSTANCE GetInstance(); // returns handle to the plugin DLL module; used for things like loading resources (dialogs, bitmaps, icons...) that are built into the plugin.
  64. wchar_t* GetPluginsDirPath(); // usually returns 'c:\\program files\\winamp\\plugins\\'
  65. wchar_t* GetConfigIniFile(); // usually returns 'c:\\program files\\winamp\\plugins\\something.ini' - filename is determined from identifiers in 'defines.h'
  66. char* GetConfigIniFileA();
  67. protected:
  68. // GET METHODS THAT ONLY WORK ONCE DIRECTX IS READY
  69. // ------------------------------------------------------------
  70. // The following 'Get' methods are only available after DirectX has been initialized.
  71. // If you call these from OverrideDefaults, MyPreInitialize, or MyReadConfig,
  72. // they will return NULL (zero).
  73. // ------------------------------------------------------------
  74. HWND GetPluginWindow(); // returns handle to the plugin window. NOT persistent; can change!
  75. int GetWidth(); // returns width of plugin window interior, in pixels. Note: in windowed mode, this is a fudged, larger, aligned value, and on final display, it gets cropped.
  76. int GetHeight(); // returns height of plugin window interior, in pixels. Note: in windowed mode, this is a fudged, larger, aligned value, and on final display, it gets cropped.
  77. int GetBitDepth(); // returns 8, 16, 24 (rare), or 32
  78. LPDIRECT3DDEVICE9 GetDevice(); // returns a pointer to the DirectX 8 Device. NOT persistent; can change!
  79. D3DCAPS9* GetCaps(); // returns a pointer to the D3DCAPS9 structer for the device. NOT persistent; can change.
  80. D3DFORMAT GetBackBufFormat(); // returns the pixelformat of the back buffer (probably D3DFMT_R8G8B8, D3DFMT_A8R8G8B8, D3DFMT_X8R8G8B8, D3DFMT_R5G6B5, D3DFMT_X1R5G5B5, D3DFMT_A1R5G5B5, D3DFMT_A4R4G4B4, D3DFMT_R3G3B2, D3DFMT_A8R3G3B2, D3DFMT_X4R4G4B4, or D3DFMT_UNKNOWN)
  81. D3DFORMAT GetBackBufZFormat(); // returns the pixelformat of the back buffer's Z buffer (probably D3DFMT_D16_LOCKABLE, D3DFMT_D32, D3DFMT_D15S1, D3DFMT_D24S8, D3DFMT_D16, D3DFMT_D24X8, D3DFMT_D24X4S4, or D3DFMT_UNKNOWN)
  82. char* GetDriverFilename(); // returns a text string with the filename of the current display adapter driver, such as "nv4_disp.dll"
  83. char* GetDriverDescription(); // returns a text string describing the current display adapter, such as "NVIDIA GeForce4 Ti 4200"
  84. // FONTS & TEXT
  85. // ------------------------------------------------------------
  86. public:
  87. LPD3DXFONT GetFont(eFontIndex idx); // returns a D3DX font handle for drawing text; see shell_defines.h for the definition of the 'eFontIndex' enum.
  88. int GetFontHeight(eFontIndex idx); // returns the height of the font, in pixels; see shell_defines.h for the definition of the 'eFontIndex' enum.
  89. CTextManager m_text;
  90. protected:
  91. // MISC
  92. // ------------------------------------------------------------
  93. td_soundinfo m_sound; // a structure always containing the most recent sound analysis information; defined in pluginshell.h.
  94. void SuggestHowToFreeSomeMem(); // gives the user a 'smart' messagebox that suggests how they can free up some video memory.
  95. // CONFIG PANEL SETTINGS
  96. // ------------------------------------------------------------
  97. // *** only read/write these values during CPlugin::OverrideDefaults! ***
  98. int m_start_fullscreen; // 0 or 1
  99. int m_start_desktop; // 0 or 1
  100. int m_fake_fullscreen_mode; // 0 or 1
  101. int m_max_fps_fs; // 1-120, or 0 for 'unlimited'
  102. int m_max_fps_dm; // 1-120, or 0 for 'unlimited'
  103. int m_max_fps_w; // 1-120, or 0 for 'unlimited'
  104. int m_show_press_f1_msg; // 0 or 1
  105. int m_allow_page_tearing_w; // 0 or 1
  106. int m_allow_page_tearing_fs; // 0 or 1
  107. int m_allow_page_tearing_dm; // 0 or 1
  108. int m_minimize_winamp; // 0 or 1
  109. int m_desktop_show_icons; // 0 or 1
  110. int m_desktop_textlabel_boxes; // 0 or 1
  111. int m_desktop_manual_icon_scoot; // 0 or 1
  112. int m_desktop_555_fix; // 0 = 555, 1 = 565, 2 = 888
  113. int m_dualhead_horz; // 0 = both, 1 = left, 2 = right
  114. int m_dualhead_vert; // 0 = both, 1 = top, 2 = bottom
  115. int m_save_cpu; // 0 or 1
  116. int m_skin; // 0 or 1
  117. int m_fix_slow_text; // 0 or 1
  118. td_fontinfo m_fontinfo[NUM_BASIC_FONTS + NUM_EXTRA_FONTS];
  119. D3DDISPLAYMODE m_disp_mode_fs; // a D3DDISPLAYMODE struct that specifies the width, height, refresh rate, and color format to use when the plugin goes fullscreen.
  120. // PURE VIRTUAL FUNCTIONS (...must be implemented by derived classes)
  121. // ------------------------------------------------------------
  122. virtual void OverrideDefaults() = 0;
  123. virtual void MyPreInitialize() = 0;
  124. virtual void MyReadConfig() = 0;
  125. virtual void MyWriteConfig() = 0;
  126. virtual int AllocateMyNonDx9Stuff() = 0;
  127. virtual void CleanUpMyNonDx9Stuff() = 0;
  128. virtual int AllocateMyDX9Stuff() = 0;
  129. virtual void CleanUpMyDX9Stuff(int final_cleanup) = 0;
  130. virtual void MyRenderFn(int redraw) = 0;
  131. virtual void MyRenderUI(int *upper_left_corner_y, int *upper_right_corner_y, int *lower_left_corner_y, int *lower_right_corner_y, int xL, int xR) = 0;
  132. virtual LRESULT MyWindowProc(HWND hWnd, unsigned uMsg, WPARAM wParam, LPARAM lParam) = 0;
  133. virtual BOOL MyConfigTabProc(int nPage, HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) = 0;
  134. virtual void OnAltK() { }; // doesn't *have* to be implemented
  135. //=====================================================================================================================
  136. private:
  137. // GENERAL PRIVATE STUFF
  138. eScrMode m_screenmode; // // WINDOWED, FULLSCREEN, or FAKE_FULLSCREEN (i.e. running in a full-screen-sized window)
  139. int m_frame; // current frame #, starting at zero
  140. float m_time; // current animation time in seconds; starts at zero.
  141. float m_fps; // current estimate of frames per second
  142. HWND m_hWndWinamp; // handle to Winamp window
  143. HINSTANCE m_hInstance; // handle to application instance
  144. DXContext* m_lpDX; // pointer to DXContext object
  145. wchar_t m_szPluginsDirPath[MAX_PATH]; // usually 'c:\\program files\\winamp\\plugins\\'
  146. wchar_t m_szConfigIniFile[MAX_PATH]; // usually 'c:\\program files\\winamp\\plugins\\something.ini' - filename is determined from identifiers in 'defines.h'
  147. char m_szConfigIniFileA[MAX_PATH]; // usually 'c:\\program files\\winamp\\plugins\\something.ini' - filename is determined from identifiers in 'defines.h'
  148. // FONTS
  149. IDirect3DTexture9* m_lpDDSText;
  150. LPD3DXFONT m_d3dx_font[NUM_BASIC_FONTS + NUM_EXTRA_FONTS];
  151. LPD3DXFONT m_d3dx_desktop_font;
  152. HFONT m_font[NUM_BASIC_FONTS + NUM_EXTRA_FONTS];
  153. HFONT m_font_desktop;
  154. // PRIVATE CONFIG PANEL SETTINGS
  155. D3DMULTISAMPLE_TYPE m_multisample_fullscreen;
  156. D3DMULTISAMPLE_TYPE m_multisample_desktop;
  157. D3DMULTISAMPLE_TYPE m_multisample_windowed;
  158. GUID m_adapter_guid_fullscreen;
  159. GUID m_adapter_guid_desktop;
  160. GUID m_adapter_guid_windowed;
  161. char m_adapter_devicename_fullscreen[256]; // these are also necessary sometimes,
  162. char m_adapter_devicename_desktop[256]; // for example, when a laptop (single adapter)
  163. char m_adapter_devicename_windowed[256]; // drives two displays! DeviceName will be \\.\Display1 and \\.\Display2 or something.
  164. // PRIVATE RUNTIME SETTINGS
  165. int m_lost_focus; // ~mostly for fullscreen mode
  166. int m_hidden; // ~mostly for windowed mode
  167. int m_resizing; // ~mostly for windowed mode
  168. int m_show_help;
  169. int m_show_playlist;
  170. int m_playlist_pos; // current selection on (plugin's) playlist menu
  171. int m_playlist_pageups; // can be + or -
  172. int m_playlist_top_idx; // used to track when our little playlist cache (m_playlist) needs updated.
  173. int m_playlist_btm_idx; // used to track when our little playlist cache (m_playlist) needs updated.
  174. int m_playlist_width_pixels; // considered invalid whenever 'm_playlist_top_idx' is -1.
  175. wchar_t m_playlist[MAX_SONGS_PER_PAGE][256]; // considered invalid whenever 'm_playlist_top_idx' is -1.
  176. int m_exiting;
  177. int m_upper_left_corner_y;
  178. int m_lower_left_corner_y;
  179. int m_upper_right_corner_y;
  180. int m_lower_right_corner_y;
  181. int m_left_edge;
  182. int m_right_edge;
  183. int m_force_accept_WM_WINDOWPOSCHANGING;
  184. // PRIVATE - GDI STUFF
  185. HMENU m_main_menu;
  186. HMENU m_context_menu;
  187. // PRIVATE - DESKTOP MODE STUFF
  188. //typedef std::list<icon_t> IconList;
  189. typedef std::vector<icon_t> IconList;
  190. IconList m_icon_list;
  191. IDirect3DTexture9* m_desktop_icons_texture[MAX_ICON_TEXTURES];
  192. HWND m_hWndProgMan;
  193. HWND m_hWndDesktop;
  194. HWND m_hWndDesktopListView;
  195. char m_szDesktopFolder[MAX_PATH]; // *without* the final backslash
  196. int m_desktop_icon_size;
  197. int m_desktop_dragging; // '1' when user is dragging icons around
  198. int m_desktop_box; // '1' when user is drawing a box
  199. BYTE m_desktop_drag_pidl[1024]; // cast this to ITEMIDLIST
  200. POINT m_desktop_drag_startpos; // applies to dragging or box-drawing
  201. POINT m_desktop_drag_curpos; // applies to dragging or box-drawing
  202. int m_desktop_wc_registered;
  203. DWORD m_desktop_bk_color;
  204. DWORD m_desktop_text_color;
  205. DWORD m_desktop_sel_color;
  206. DWORD m_desktop_sel_text_color;
  207. int m_desktop_icon_state; // 0=uninit, 1=total refresh in progress, 2=ready, 3=update in progress
  208. int m_desktop_icon_count;
  209. int m_desktop_icon_update_frame;
  210. CRITICAL_SECTION m_desktop_cs;
  211. int m_desktop_icons_disabled;
  212. int m_vms_desktop_loaded;
  213. int m_desktop_hook_set;
  214. bool m_bClearVJWindow;
  215. // PRIVATE - MORE TIMEKEEPING
  216. protected:
  217. double m_last_raw_time;
  218. LARGE_INTEGER m_high_perf_timer_freq; // 0 if high-precision timer not available
  219. private:
  220. float m_time_hist[TIME_HIST_SLOTS]; // cumulative
  221. int m_time_hist_pos;
  222. LARGE_INTEGER m_prev_end_of_frame;
  223. // PRIVATE AUDIO PROCESSING DATA
  224. FFT m_fftobj;
  225. float m_oldwave[2][576]; // for wave alignment
  226. int m_prev_align_offset[2]; // for wave alignment
  227. int m_align_weights_ready;
  228. public:
  229. CPluginShell();
  230. ~CPluginShell();
  231. // called by vis.cpp, on behalf of Winamp:
  232. int PluginPreInitialize(HWND hWinampWnd, HINSTANCE hWinampInstance);
  233. int PluginInitialize();
  234. int PluginRender(unsigned char *pWaveL, unsigned char *pWaveR);
  235. void PluginQuit();
  236. void ToggleHelp();
  237. void TogglePlaylist();
  238. void READ_FONT(int n);
  239. void WRITE_FONT(int n);
  240. // config panel / windows messaging processes:
  241. static LRESULT CALLBACK WindowProc(HWND hWnd, unsigned uMsg, WPARAM wParam, LPARAM lParam);
  242. static LRESULT CALLBACK DesktopWndProc(HWND hWnd, unsigned uMsg, WPARAM wParam, LPARAM lParam);
  243. static LRESULT CALLBACK VJModeWndProc(HWND hWnd, unsigned uMsg, WPARAM wParam, LPARAM lParam);
  244. static INT_PTR CALLBACK ConfigDialogProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
  245. static INT_PTR CALLBACK TabCtrlProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
  246. static INT_PTR CALLBACK FontDialogProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
  247. static INT_PTR CALLBACK DesktopOptionsDialogProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
  248. static INT_PTR CALLBACK DualheadDialogProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
  249. private:
  250. void PushWindowToJustBeforeDesktop(HWND h);
  251. void DrawAndDisplay(int redraw);
  252. void ReadConfig();
  253. void WriteConfig();
  254. void DoTime();
  255. void AnalyzeNewSound(unsigned char *pWaveL, unsigned char *pWaveR);
  256. void AlignWaves();
  257. int InitDirectX();
  258. void CleanUpDirectX();
  259. int InitGDIStuff();
  260. void CleanUpGDIStuff();
  261. int AllocateDX9Stuff();
  262. void CleanUpDX9Stuff(int final_cleanup);
  263. int InitNondx9Stuff();
  264. void CleanUpNondx9Stuff();
  265. int InitVJStuff(RECT* pClientRect=NULL);
  266. void CleanUpVJStuff();
  267. int AllocateFonts(IDirect3DDevice9 *pDevice);
  268. void CleanUpFonts();
  269. void AllocateTextSurface();
  270. void ToggleDesktop();
  271. void OnUserResizeWindow();
  272. void OnUserResizeTextWindow();
  273. void PrepareFor2DDrawing_B(IDirect3DDevice9 *pDevice, int w, int h);
  274. void RenderBuiltInTextMsgs();
  275. int GetCanvasMarginX(); // returns the # of pixels that exist on the canvas, on each side, that the user will never see. Mainly here for windowed mode, where sometimes, up to 15 pixels get cropped at edges of the screen.
  276. int GetCanvasMarginY(); // returns the # of pixels that exist on the canvas, on each side, that the user will never see. Mainly here for windowed mode, where sometimes, up to 15 pixels get cropped at edges of the screen.
  277. public:
  278. void ToggleFullScreen();
  279. void DrawDarkTranslucentBox(RECT* pr);
  280. protected:
  281. void RenderPlaylist();
  282. void StuffParams(DXCONTEXT_PARAMS *pParams);
  283. void EnforceMaxFPS();
  284. // DESKTOP MODE FUNCTIONS (found in desktop_mode.cpp)
  285. int InitDesktopMode();
  286. void CleanUpDesktopMode();
  287. int CreateDesktopIconTexture(IDirect3DTexture9** ppTex);
  288. void DeselectDesktop();
  289. void UpdateDesktopBitmaps();
  290. int StuffIconBitmaps(int iStartIconIdx, int iTexNum, int *show_msgs);
  291. void RenderDesktop();
  292. // SEPARATE TEXT WINDOW (FOR VJ MODE)
  293. int m_vj_mode;
  294. int m_hidden_textwnd;
  295. int m_resizing_textwnd;
  296. protected:
  297. HWND m_hTextWnd;
  298. private:
  299. int m_nTextWndWidth;
  300. int m_nTextWndHeight;
  301. bool m_bTextWindowClassRegistered;
  302. LPDIRECT3D9 m_vjd3d9;
  303. LPDIRECT3DDEVICE9 m_vjd3d9_device;
  304. //HDC m_memDC; // memory device context
  305. //HBITMAP m_memBM, m_oldBM;
  306. //HBRUSH m_hBlackBrush;
  307. // WINDOWPROC FUNCTIONS
  308. LRESULT PluginShellWindowProc(HWND hWnd, unsigned uMsg, WPARAM wParam, LPARAM lParam); // in windowproc.cpp
  309. LRESULT PluginShellDesktopWndProc(HWND hWnd, unsigned uMsg, WPARAM wParam, LPARAM lParam);
  310. LRESULT PluginShellVJModeWndProc(HWND hWnd, unsigned uMsg, WPARAM wParam, LPARAM lParam);
  311. // CONFIG PANEL FUNCTIONS:
  312. BOOL PluginShellConfigDialogProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
  313. BOOL PluginShellConfigTab1Proc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
  314. BOOL PluginShellFontDialogProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
  315. BOOL PluginShellDesktopOptionsDialogProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
  316. BOOL PluginShellDualheadDialogProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
  317. bool InitConfig(HWND hDialogWnd);
  318. void EndConfig();
  319. void UpdateAdapters(int screenmode);
  320. void UpdateFSAdapterDispModes(); // (fullscreen only)
  321. void UpdateDispModeMultiSampling(int screenmode);
  322. void UpdateMaxFps(int screenmode);
  323. int GetCurrentlySelectedAdapter(int screenmode);
  324. void SaveDisplayMode();
  325. void SaveMultiSamp(int screenmode);
  326. void SaveAdapter(int screenmode);
  327. void SaveMaxFps(int screenmode);
  328. void OnTabChanged(int nNewTab);
  329. LPDIRECT3DDEVICE9 GetTextDevice() { return (m_vjd3d9_device) ? m_vjd3d9_device : m_lpDX->m_lpDevice; }
  330. // CHANGES:
  331. friend class CShaderParams;
  332. };
  333. #endif