1
0

r_svp.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. LICENSE
  3. -------
  4. Copyright 2005 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. #include <windows.h>
  25. #include <commctrl.h>
  26. #include "r_defs.h"
  27. #include "resource.h"
  28. #include "../Agave/Language/api_language.h"
  29. extern HINSTANCE g_hInstance;
  30. #include "svp_vis.h"
  31. #ifndef LASER
  32. #define C_THISCLASS C_SVPClass
  33. #define MOD_NAME "Render / SVP Loader"
  34. class C_THISCLASS : public C_RBASE {
  35. protected:
  36. public:
  37. C_THISCLASS();
  38. virtual ~C_THISCLASS();
  39. virtual int render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h);
  40. virtual char *get_desc() { static char desc[128]; return (!desc[0]?WASABI_API_LNGSTRING_BUF(IDS_RENDER_SVP_LOADER,desc,128):desc); }
  41. virtual HWND conf(HINSTANCE hInstance, HWND hwndParent);
  42. virtual void load_config(unsigned char *data, int len);
  43. virtual int save_config(unsigned char *data);
  44. char m_library[MAX_PATH];
  45. void SetLibrary();
  46. HMODULE hLibrary;
  47. CRITICAL_SECTION cs;
  48. VisInfo *vi;
  49. VisData vd;
  50. };
  51. #define PUT_INT(y) data[pos]=(y)&255; data[pos+1]=(y>>8)&255; data[pos+2]=(y>>16)&255; data[pos+3]=(y>>24)&255
  52. #define GET_INT() (data[pos]|(data[pos+1]<<8)|(data[pos+2]<<16)|(data[pos+3]<<24))
  53. void C_THISCLASS::load_config(unsigned char *data, int len)
  54. {
  55. int pos=0;
  56. if (pos+MAX_PATH <= len)
  57. {
  58. memcpy(m_library,data+pos,MAX_PATH);
  59. pos+=MAX_PATH;
  60. SetLibrary();
  61. }
  62. }
  63. int C_THISCLASS::save_config(unsigned char *data)
  64. {
  65. int pos=0;
  66. memcpy(data+pos,m_library,MAX_PATH);
  67. pos+=MAX_PATH;
  68. return pos;
  69. }
  70. void C_THISCLASS::SetLibrary()
  71. {
  72. EnterCriticalSection(&cs);
  73. if (hLibrary)
  74. {
  75. if (vi) vi->SaveSettings("avs.ini");
  76. vi=NULL;
  77. FreeLibrary(hLibrary);
  78. hLibrary=NULL;
  79. }
  80. if (!m_library[0]) { LeaveCriticalSection(&cs); return; }
  81. char buf1[MAX_PATH];
  82. strcpy(buf1,g_path);
  83. strcat(buf1,"\\");
  84. strcat(buf1,m_library);
  85. vi=NULL;
  86. hLibrary = LoadLibrary(buf1);
  87. if (hLibrary)
  88. {
  89. VisInfo* (*qm)(void);
  90. qm=(struct _VisInfo *(__cdecl *)(void))GetProcAddress(hLibrary,"QueryModule");
  91. if (!qm)
  92. qm=(struct _VisInfo *(__cdecl *)(void))GetProcAddress(hLibrary,"?QueryModule@@YAPAUUltraVisInfo@@XZ");
  93. if (!qm || !(vi=qm()))
  94. {
  95. vi=NULL;
  96. FreeLibrary(hLibrary);
  97. hLibrary=NULL;
  98. }
  99. }
  100. if (vi) {
  101. vi->OpenSettings("avs.ini"); vi->Initialize();
  102. }
  103. LeaveCriticalSection(&cs);
  104. }
  105. C_THISCLASS::C_THISCLASS()
  106. {
  107. InitializeCriticalSection(&cs);
  108. m_library[0]=0;
  109. hLibrary=0;
  110. vi=NULL;
  111. }
  112. C_THISCLASS::~C_THISCLASS()
  113. {
  114. if (vi) vi->SaveSettings("avs.ini");
  115. if (hLibrary) FreeLibrary(hLibrary);
  116. DeleteCriticalSection(&cs);
  117. }
  118. int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h)
  119. {
  120. if (isBeat&0x80000000) return 0;
  121. EnterCriticalSection(&cs);
  122. if (vi)
  123. {
  124. // if (vi->lRequired & VI_WAVEFORM)
  125. {
  126. int ch,p;
  127. for (ch = 0; ch < 2; ch ++)
  128. {
  129. unsigned char *v=(unsigned char *)visdata[1][ch];
  130. for (p = 0; p < 512; p ++)
  131. vd.Waveform[ch][p]=v[p];
  132. }
  133. }
  134. // if (vi->lRequired & VI_SPECTRUM)
  135. {
  136. int ch,p;
  137. for (ch = 0; ch < 2; ch ++)
  138. {
  139. unsigned char *v=(unsigned char *) visdata[0][ch];
  140. for (p = 0; p < 256; p ++)
  141. vd.Spectrum[ch][p]=v[p*2]/2+v[p*2+1]/2;
  142. }
  143. }
  144. vd.MillSec=GetTickCount();
  145. vi->Render((unsigned long *)framebuffer,w,h,w,&vd);
  146. }
  147. LeaveCriticalSection(&cs);
  148. return 0;
  149. }
  150. C_RBASE *R_SVP(char *desc)
  151. {
  152. if (desc) { strcpy(desc,MOD_NAME); return NULL; }
  153. return (C_RBASE *) new C_THISCLASS();
  154. }
  155. static C_THISCLASS *g_this;
  156. static BOOL CALLBACK g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  157. {
  158. switch (uMsg)
  159. {
  160. case WM_INITDIALOG:
  161. loadComboBox(GetDlgItem(hwndDlg,IDC_COMBO1), "*.SVP", g_this->m_library);
  162. loadComboBox(GetDlgItem(hwndDlg,IDC_COMBO1), "*.UVS", g_this->m_library);
  163. return 1;
  164. case WM_COMMAND:
  165. switch (LOWORD(wParam))
  166. {
  167. case IDC_COMBO1:
  168. {
  169. int a=SendDlgItemMessage(hwndDlg,IDC_COMBO1,CB_GETCURSEL,0,0);
  170. if (a != CB_ERR)
  171. {
  172. if (SendDlgItemMessage(hwndDlg,IDC_COMBO1,CB_GETLBTEXT,a,(LPARAM)g_this->m_library) == CB_ERR)
  173. {
  174. g_this->m_library[0]=0;
  175. }
  176. }
  177. else
  178. g_this->m_library[0]=0;
  179. g_this->SetLibrary();
  180. }
  181. return 0;
  182. }
  183. return 0;
  184. }
  185. return 0;
  186. }
  187. HWND C_THISCLASS::conf(HINSTANCE hInstance, HWND hwndParent)
  188. {
  189. g_this = this;
  190. return WASABI_API_CREATEDIALOG(IDC_CFG_SVP,hwndParent,g_DlgProc);
  191. }
  192. #else
  193. C_RBASE *R_SVP(char *desc)
  194. { return NULL; }
  195. #endif