wa2cfgitems.cpp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. #include <precomp.h>
  2. #include "wa2cfgitems.h"
  3. #include "wa2wndembed.h"
  4. #include "wa2core.h"
  5. #include <api/config/options.h>
  6. #include "wa2frontend.h"
  7. #include "../../Plugins/Output/out_ds/ds_ipc.h"
  8. #include <bfc/parse/pathparse.h>
  9. #include "gen.h"
  10. #include "resource.h"
  11. #include "../Agave/Language/api_language.h"
  12. // cfg item callbacks
  13. void setCrossfader(int crossfade);
  14. void onWa2CrossfadeChange(int crossfade);
  15. void setOnTop(int ontop);
  16. void onWa2OnTopChanged(int ontop);
  17. int my_set = 0;
  18. int disable_set_wa2_repeat = 0;
  19. //---------------------------------------------------------
  20. // playlist editor cfg items
  21. //---------------------------------------------------------
  22. _bool shuffle(L"Shuffle", FALSE);
  23. _int repeat(L"Repeat", 0);
  24. _bool visrandom(L"Random", FALSE);
  25. Wa2PlEditCfgItems::Wa2PlEditCfgItems() : CfgItemI(L"Playlist Editor", pleditWndGuid) {
  26. registerAttribute(&shuffle, new int_attrCB(Wa2PlEditCfgItems::onSetShuffle));
  27. registerAttribute(&repeat, new int_attrCB(Wa2PlEditCfgItems::onSetRepeat));
  28. WASABI_API_CONFIG->config_registerCfgItem(this);
  29. shuffle.setValueAsInt(g_Core->getShuffle());
  30. disable_set_wa2_repeat = 1;
  31. repeat.setValueAsInt(g_Core->getRepeat());
  32. disable_set_wa2_repeat = 0;
  33. }
  34. Wa2PlEditCfgItems::~Wa2PlEditCfgItems() {
  35. WASABI_API_CONFIG->config_deregisterCfgItem(this);
  36. }
  37. void Wa2PlEditCfgItems::onSetRepeat(int set) {
  38. my_set = 1;
  39. ASSERT(g_Core != NULL);
  40. if (!disable_set_wa2_repeat) {
  41. // if (!!set != !!g_Core->getRepeat()) // FG> do NOT uncomment this
  42. g_Core->setRepeat(set);
  43. }
  44. my_set = 0;
  45. }
  46. void Wa2PlEditCfgItems::onSetShuffle(BOOL set) {
  47. my_set = 1;
  48. ASSERT(g_Core != NULL);
  49. if (!!set != !!g_Core->getShuffle())
  50. g_Core->setShuffle(set);
  51. my_set = 0;
  52. }
  53. //---------------------------------------------------------
  54. static _bool prevent_videostoponclose(L"Prevent video playback Stop on video window Close", FALSE);
  55. static _bool prevent_videoresize(L"Prevent video resize", FALSE); // 5.32+
  56. static _bool show_videownd_on_play(L"Show video wnd on play"); // 5.36+
  57. static _bool hide_videownd_on_stop(L"Hide video wnd on stop"); // 5.36+
  58. int preventvc_savedvalued = -1;
  59. int preventvresize_savedvalued = -1;
  60. SkinTweaks::SkinTweaks() : CfgItemI(L"SkinTweaks", skinTweaksGuid)
  61. {
  62. registerAttribute(&prevent_videostoponclose, new int_attrCB(SkinTweaks::onPreventVideoStopChanged));
  63. registerAttribute(&prevent_videoresize, new int_attrCB(SkinTweaks::onPreventVideoResize));
  64. }
  65. //---------------------------------------------------------
  66. AvsCfg::AvsCfg() : CfgItemI(L"Avs", avs_guid) {
  67. registerAttribute(&visrandom, new int_attrCB(AvsCfg::onVisRandomChanged));
  68. }
  69. //---------------------------------------------------------
  70. void SkinTweaks::onPreventVideoStopChanged(BOOL set) {
  71. if (set) {
  72. if (preventvc_savedvalued == -1) {
  73. preventvc_savedvalued = wa2.getStopOnVideoClose();
  74. wa2.setStopOnVideoClose(0);
  75. }
  76. } else {
  77. if (preventvc_savedvalued != -1) {
  78. wa2.setStopOnVideoClose(preventvc_savedvalued);
  79. preventvc_savedvalued = -1;
  80. }
  81. }
  82. }
  83. void SkinTweaks::onPreventVideoResize(BOOL set) {
  84. if (set) {
  85. if (preventvresize_savedvalued == -1) {
  86. preventvresize_savedvalued = wa2.GetVideoResize();
  87. wa2.SetVideoResize(0);
  88. }
  89. } else {
  90. if (preventvresize_savedvalued != -1) {
  91. wa2.SetVideoResize(preventvresize_savedvalued);
  92. preventvresize_savedvalued = -1;
  93. }
  94. }
  95. }
  96. //---------------------------------------------------------
  97. void AvsCfg::onVisRandomChanged(BOOL set) {
  98. extern int disable_send_visrandom;
  99. if (!disable_send_visrandom) {
  100. disable_send_visrandom = 1;
  101. wa2.visRandom(set);
  102. disable_send_visrandom = 0;
  103. }
  104. }
  105. //---------------------------------------------------------
  106. Options *options;
  107. CustomOptionsMenuItems *optionsmenuitems;
  108. CustomWindowsMenuItems *windowsmenuitems;
  109. SkinTweaks *skintweaks;
  110. Crossfader *crossfader;
  111. AvsCfg *avscfg;
  112. //---------------------------------------------------------
  113. Wa2CfgItems::Wa2CfgItems() {
  114. // set up main options
  115. WASABI_API_CONFIG->config_registerCfgItem((options = new Options()));
  116. // set up custom options menu items
  117. WASABI_API_CONFIG->config_registerCfgItem((optionsmenuitems = new CustomOptionsMenuItems()));
  118. // set up custom windows menu items
  119. WASABI_API_CONFIG->config_registerCfgItem((windowsmenuitems = new CustomWindowsMenuItems()));
  120. // set up skintweaks options menu items
  121. WASABI_API_CONFIG->config_registerCfgItem((skintweaks = new SkinTweaks()));
  122. // set up crossfader options menu item
  123. WASABI_API_CONFIG->config_registerCfgItem((crossfader = new Crossfader()));
  124. // set up avs cfg item
  125. WASABI_API_CONFIG->config_registerCfgItem((avscfg = new AvsCfg()));
  126. }
  127. Wa2CfgItems::~Wa2CfgItems() {
  128. WASABI_API_CONFIG->config_deregisterCfgItem(options);
  129. WASABI_API_CONFIG->config_deregisterCfgItem(optionsmenuitems);
  130. WASABI_API_CONFIG->config_deregisterCfgItem(windowsmenuitems);
  131. WASABI_API_CONFIG->config_deregisterCfgItem(skintweaks);
  132. WASABI_API_CONFIG->config_deregisterCfgItem(crossfader);
  133. WASABI_API_CONFIG->config_deregisterCfgItem(avscfg);
  134. delete options;
  135. options = NULL;
  136. delete optionsmenuitems;
  137. optionsmenuitems = NULL;
  138. delete windowsmenuitems;
  139. windowsmenuitems = NULL;
  140. delete skintweaks;
  141. skintweaks = NULL;
  142. delete crossfader;
  143. crossfader = NULL;
  144. delete avscfg;
  145. avscfg = NULL;
  146. }
  147. //-----------------------------------------------------------------------------------------------
  148. // always on top was toggled in freeform skin
  149. //-----------------------------------------------------------------------------------------------
  150. void setOnTop(int ontop) {
  151. if (!!ontop != !!wa2.isOnTop()) wa2.setOnTop(!!ontop);
  152. }
  153. //-----------------------------------------------------------------------------------------------
  154. // setontop was toggled in wa2
  155. //-----------------------------------------------------------------------------------------------
  156. void onWa2OnTopChanged(int ontop) {
  157. cfg_options_alwaysontop.setValueAsInt(!!ontop);
  158. }
  159. //-----------------------------------------------------------------------------------------------
  160. // Crossfader cfgitem - monitors out_ds
  161. //-----------------------------------------------------------------------------------------------
  162. _int crossfade_time(L"Crossfade time", 2); // in seconds
  163. HWND output_ipc = NULL;
  164. static WNDPROC oldOutputIPCProc;
  165. int syncing_crossfade = 0;
  166. int using_dsound = 0;
  167. extern HWND last_dlg_parent;
  168. // sync out_ds with gen_ff
  169. void syncOutputCrossfade() {
  170. if (output_ipc == NULL) return;
  171. SendMessageW(output_ipc, WM_DS_IPC, crossfade_time.getValueAsInt() * 1000, DS_IPC_SET_CROSSFADE_TIME);
  172. if (using_dsound) SendMessageW(output_ipc, WM_DS_IPC, cfg_audiooptions_crossfader.getValueAsInt(), DS_IPC_SET_CROSSFADE);
  173. }
  174. // sync gen_ff with out_ds, can't happen if out_ds isn't the selected plugin since this occurs when the user changes his config, and he needs to select out_ds to access its config
  175. void syncGenFFCrossfade() {
  176. syncing_crossfade = 1;
  177. if (output_ipc == NULL) return;
  178. crossfade_time.setValueAsInt(SendMessageW(output_ipc, WM_DS_IPC, 0, DS_IPC_GET_CROSSFADE_TIME) / 1000);
  179. cfg_audiooptions_crossfader.setValueAsInt(SendMessageW(output_ipc, WM_DS_IPC, 0, DS_IPC_GET_CROSSFADE));
  180. syncing_crossfade = 0;
  181. }
  182. // called when gen_ff changes the crossfade time setting
  183. void onSetCrossfadeTime(int sectime) {
  184. if (syncing_crossfade) return;
  185. syncOutputCrossfade();
  186. }
  187. // called when gen_ff toggles crossfading
  188. void setCrossfader(int crossfade) {
  189. if (syncing_crossfade) return;
  190. if (crossfade && (!output_ipc || !using_dsound)) {
  191. cfg_audiooptions_crossfader.setValueAsInt(0);
  192. char title[256] = {0};
  193. int r = MessageBoxA(last_dlg_parent ? last_dlg_parent : wa2.getMainWindow(),
  194. WASABI_API_LNGSTRING(IDS_CROSSFADER_ONLY_UNDER_OUT_DS),
  195. WASABI_API_LNGSTRING_BUF(IDS_NOT_SUPPORTED,title,256), MB_YESNO);
  196. if (r == IDYES) {
  197. SendMessageW(wa2.getMainWindow(),WM_WA_IPC,32,IPC_OPENPREFSTOPAGE);
  198. }
  199. }
  200. syncOutputCrossfade();
  201. }
  202. // ----------------------- ipc hook
  203. extern int m_are_we_loaded;
  204. static DWORD WINAPI outputIPCProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam) {
  205. if (m_are_we_loaded) {
  206. switch (uMsg) {
  207. case WM_DS_IPC:
  208. switch (lParam) {
  209. case DS_IPC_CB_CFGREFRESH:
  210. syncGenFFCrossfade();
  211. break;
  212. case DS_IPC_CB_ONSHUTDOWN:
  213. output_ipc = NULL;
  214. break;
  215. }
  216. break;
  217. }
  218. }
  219. return CallWindowProc(oldOutputIPCProc, hwndDlg, uMsg, wParam, lParam);
  220. }
  221. void hookOutputIPC() {
  222. oldOutputIPCProc = (WNDPROC)SetWindowLongPtrW(output_ipc, GWLP_WNDPROC, (LONG_PTR)outputIPCProc);
  223. }
  224. // not called in fact, since we never need to let go of it
  225. void unhookOutputIPC() {
  226. SetWindowLongPtrW(output_ipc, GWLP_WNDPROC, (LONG_PTR)oldOutputIPCProc);
  227. }
  228. BOOL CALLBACK findOutputIPCProc( HWND hwnd, LPARAM lParam )
  229. {
  230. char cn[ 256 ] = { 0 };
  231. GetClassNameA( hwnd, cn, 255 ); cn[ 255 ] = 0; // Must stay in ANSI mode
  232. if ( STRCASEEQL( cn, DS_IPC_CLASSNAME ) )
  233. {
  234. output_ipc = hwnd;
  235. return FALSE;
  236. }
  237. return TRUE;
  238. }
  239. // ------------------------- output plugin changed !
  240. void Crossfader::onOutputChanged() {
  241. if (!(output_ipc && IsWindow(output_ipc))) {
  242. output_ipc = NULL;
  243. EnumChildWindows(wa2.getMainWindow(), findOutputIPCProc, 0);
  244. if (output_ipc) {
  245. hookOutputIPC();
  246. }
  247. }
  248. const char* outputPluginPath = wa2.getOutputPlugin();
  249. PathParser pp(outputPluginPath);
  250. using_dsound = STRCASEEQLSAFE(pp.getLastString(), "out_ds.dll");
  251. if (!using_dsound) {
  252. cfg_audiooptions_crossfader.setValueAsInt(0);
  253. } else
  254. syncGenFFCrossfade();
  255. }
  256. // ------------------------------------------------------------------------
  257. Crossfader::Crossfader() : CfgItemI(L"Crossfader", crossfaderGuid) {
  258. registerAttribute(&crossfade_time, new int_attrCB(onSetCrossfadeTime));
  259. }
  260. Crossfader::~Crossfader() {
  261. unhookOutputIPC();
  262. }