wa2coreactions.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. #include <precomp.h>
  2. #include "wa2frontend.h"
  3. #include "wa2core.h"
  4. #include "wa2coreactions.h"
  5. #include "main.h"
  6. #include <api/core/api_core.h>
  7. #include <api/locales/xlatstr.h>
  8. //-----------------------------------------------------------------------------------------------
  9. CoreActions::CoreActions()
  10. {
  11. registerAction( L"prev", ACTION_PREV );
  12. registerAction( L"play", ACTION_PLAY );
  13. registerAction( L"pause", ACTION_PAUSE );
  14. registerAction( L"stop", ACTION_STOP );
  15. registerAction( L"next", ACTION_NEXT );
  16. registerAction( L"eject", ACTION_EJECT );
  17. registerAction( L"eject_url", ACTION_EJECTURL );
  18. registerAction( L"eject_dir", ACTION_EJECTDIR );
  19. registerAction( L"seek", ACTION_SEEK );
  20. registerAction( L"volume", ACTION_VOLUME );
  21. registerAction( L"pan", ACTION_PAN );
  22. registerAction( L"volume_up", ACTION_VOLUME_UP );
  23. registerAction( L"volume_down", ACTION_VOLUME_DOWN );
  24. registerAction( L"rewind_5s", ACTION_REWIND_5S );
  25. registerAction( L"ffwd_5s", ACTION_FFWD_5S );
  26. registerAction( L"toggle_repeat", ACTION_TOGGLE_REPEAT );
  27. registerAction( L"toggle_shuffle", ACTION_TOGGLE_SHUFFLE );
  28. registerAction( L"toggle_crossfader", ACTION_TOGGLE_CROSSFADER );
  29. registerAction( L"mute", ACTION_MUTE );
  30. registerAction( L"eq_toggle", ACTION_EQ_TOGGLE );
  31. registerAction( L"eq_preamp", ACTION_EQ_PREAMP );
  32. registerAction( L"eq_band", ACTION_EQ_BAND );
  33. registerAction( L"eq_auto", ACTION_EQ_AUTO );
  34. registerAction( L"eq_reset", ACTION_EQ_RESET );
  35. // these were duped?
  36. // yes, for wa3alpha skins compatibility
  37. registerAction( L"toggle_repeat", ACTION_TOGGLE_REPEAT );
  38. registerAction( L"toggle_shuffle", ACTION_TOGGLE_SHUFFLE );
  39. registerAction( L"toggle_crossfader", ACTION_TOGGLE_CROSSFADER );
  40. for ( int i = 0; i < 4; i++ )
  41. registerAction( StringPrintfW( L"play_cd%d", i + 1 ), ACTION_PLAY_CD + i );
  42. // Martin> Moved from menuaction.cpp
  43. registerAction( L"WA5:Prefs", ACTION_PREFS );
  44. }
  45. //-----------------------------------------------------------------------------------------------
  46. CoreActions::~CoreActions()
  47. {}
  48. //-----------------------------------------------------------------------------------------------
  49. int CoreActions::onActionId(int pvtid, const wchar_t *action, const wchar_t *param /* =NULL */, int p1 /* =0 */, int p2 /* =0 */, void *data /* =NULL */, int datalen /* =0 */, ifc_window *source /* =NULL */)
  50. {
  51. if (g_Core == NULL) return 0;
  52. int a = WTOI(param);
  53. switch (pvtid)
  54. {
  55. case ACTION_PREV:
  56. if (Std::keyDown(VK_SHIFT))
  57. {
  58. wa2.rewind5s();
  59. }
  60. else if (Std::keyDown(VK_CONTROL))
  61. {
  62. wa2.startOfPlaylist();
  63. }
  64. else
  65. {
  66. if (a)
  67. wa2.previousPopupMenu();
  68. else
  69. g_Core->userButton(UserButton::PREV);
  70. }
  71. break;
  72. case ACTION_PLAY:
  73. if (Std::keyDown(VK_SHIFT))
  74. {
  75. wa2.openFileDialog(source ? source->gethWnd() : WASABI_API_WND->main_getRootWnd()->gethWnd());
  76. }
  77. else if (Std::keyDown(VK_CONTROL))
  78. {
  79. wa2.openUrlDialog(source ? source->gethWnd() : WASABI_API_WND->main_getRootWnd()->gethWnd());
  80. }
  81. else
  82. {
  83. if (a)
  84. wa2.playPopupMenu();
  85. else
  86. g_Core->userButton(UserButton::PLAY);
  87. }
  88. break;
  89. case ACTION_PAUSE:
  90. if (a)
  91. wa2.pausePopupMenu();
  92. else
  93. g_Core->userButton(UserButton::PAUSE);
  94. break;
  95. case ACTION_STOP:
  96. if (Std::keyDown(VK_SHIFT))
  97. {
  98. wa2.stopWithFade();
  99. }
  100. else if (Std::keyDown(VK_CONTROL))
  101. {
  102. wa2.stopAfterCurrent();
  103. }
  104. else
  105. {
  106. if (a)
  107. wa2.stopPopupMenu();
  108. else
  109. g_Core->userButton(UserButton::STOP);
  110. }
  111. break;
  112. case ACTION_NEXT:
  113. if (Std::keyDown(VK_SHIFT))
  114. {
  115. wa2.forward5s();
  116. }
  117. else if (Std::keyDown(VK_CONTROL))
  118. {
  119. wa2.endOfPlaylist();
  120. }
  121. else
  122. {
  123. if (a)
  124. wa2.nextPopupMenu();
  125. else if (a == 0)
  126. g_Core->userButton(UserButton::NEXT);
  127. }
  128. break;
  129. case ACTION_EJECT:
  130. if (Std::keyDown(VK_SHIFT))
  131. {
  132. wa2.openDirectoryDialog(source ? source->gethWnd() : WASABI_API_WND->main_getRootWnd()->gethWnd());
  133. }
  134. else if (Std::keyDown(VK_CONTROL))
  135. {
  136. wa2.openUrlDialog(source ? source->gethWnd() : WASABI_API_WND->main_getRootWnd()->gethWnd());
  137. }
  138. else
  139. {
  140. if (a)
  141. wa2.ejectPopupMenu();
  142. else
  143. wa2.openFileDialog(source ? source->gethWnd() : wa2.getMainWindow());
  144. }
  145. break;
  146. case ACTION_EJECTURL:
  147. if (a == 0)
  148. {
  149. wa2.openUrlDialog(source ? source->gethWnd() : wa2.getMainWindow()); break;
  150. }
  151. else return 0;
  152. case ACTION_EJECTDIR:
  153. if (a == 0)
  154. {
  155. wa2.openDirectoryDialog(source ? source->gethWnd() : wa2.getMainWindow()); break;
  156. }
  157. else return 0;
  158. case ACTION_VOLUME_UP:
  159. if (a == 0)
  160. {
  161. g_Core->setVolume(MIN(g_Core->getVolume() + 5, 255)); break;
  162. }
  163. else return 0;
  164. case ACTION_VOLUME_DOWN:
  165. if (a == 0)
  166. {
  167. g_Core->setVolume(MIN(g_Core->getVolume() - 5, 255)); break;
  168. }
  169. else return 0;
  170. case ACTION_REWIND_5S:
  171. if (a == 0)
  172. {
  173. g_Core->setPosition(MAX(g_Core->getPosition() - 5000, 0)); break;
  174. }
  175. else return 0;
  176. case ACTION_FFWD_5S:
  177. if (a == 0)
  178. {
  179. g_Core->setPosition(MIN(g_Core->getPosition() + 5000, g_Core->getLength())); break;
  180. }
  181. else return 0;
  182. case ACTION_EQ_AUTO:
  183. if (a == 0)
  184. {
  185. g_Core->setEQAuto(!g_Core->getEQAuto()); break;
  186. }
  187. else return 0;
  188. case ACTION_EQ_TOGGLE:
  189. if (a == 0)
  190. {
  191. g_Core->setEQStatus(!g_Core->getEQStatus()); break;
  192. }
  193. else return 0;
  194. case ACTION_EQ_RESET:
  195. if (a == 0)
  196. {
  197. {
  198. for (int i = 0;i < 10;i++) g_Core->setEqBand(i, 0);
  199. }
  200. break;
  201. }
  202. else return 0;
  203. //case ACTION_MUTE: g_Core->setMute(!g_Core->getMute()); break;
  204. case ACTION_TOGGLE_REPEAT:
  205. if (a == 0)
  206. {
  207. wa2.setRepeat(!wa2.getRepeat());
  208. }
  209. else return 0;
  210. break;
  211. case ACTION_TOGGLE_SHUFFLE:
  212. if (a == 0)
  213. {
  214. wa2.setShuffle(!wa2.getShuffle());
  215. }
  216. else
  217. return 0;
  218. break;
  219. case ACTION_TOGGLE_CROSSFADER:
  220. break; // todo
  221. // Martin> Moved from menuactions.cpp
  222. case ACTION_PREFS:
  223. {
  224. // check if param is set, otherwise we will get a crash
  225. if (param != NULL)
  226. {
  227. int prefsPage = _wtoi(param);
  228. SendMessageW(wa2.getMainWindow(),WM_WA_IPC,prefsPage,IPC_OPENPREFSTOPAGE);
  229. }
  230. break;
  231. }
  232. }
  233. if (pvtid >= ACTION_PLAY_CD && pvtid < ACTION_PLAY_CD + 16)
  234. {
  235. if (a == 0)
  236. {
  237. wa2.playAudioCD(pvtid - ACTION_PLAY_CD);
  238. }
  239. else return 0;
  240. }
  241. return 1;
  242. }
  243. const wchar_t *CoreActions::getHelp(int action)
  244. {
  245. static StringW name;
  246. switch (action)
  247. {
  248. // TODO: benski> move to win32 resources and let them get translated via gen_ff.lng
  249. case ACTION_PREV: name = _(L"Previous track"); break;
  250. case ACTION_PAUSE: name = _(L"Pause/Resume playback"); break;
  251. case ACTION_STOP: name = _(L"Stop playback"); break;
  252. case ACTION_NEXT: name = _(L"Next track"); break;
  253. case ACTION_EJECT: name = _(L"Load file"); break;
  254. case ACTION_EJECTURL: name = _(L"Load URL"); break;
  255. case ACTION_EJECTDIR: name = _(L"Load directory"); break;
  256. case ACTION_SEEK: name = _(L"Seek"); break;
  257. case ACTION_VOLUME: name = _(L"Volume"); break;
  258. case ACTION_PAN: name = _(L"Panning"); break;
  259. case ACTION_EQ_TOGGLE: name = _(L"Toggle equalizer"); break;
  260. case ACTION_EQ_PREAMP: name = _(L"Toggle preamplifier"); break;
  261. case ACTION_EQ_BAND: name = _(L"Change equalizer band"); break;
  262. case ACTION_EQ_AUTO: name = _(L"Auto equalizer"); break;
  263. case ACTION_EQ_RESET: name = _(L"Reset equalizer"); break;
  264. case ACTION_VOLUME_UP: name = _(L"Volume up"); break;
  265. case ACTION_VOLUME_DOWN: name = _(L"Volume down"); break;
  266. case ACTION_REWIND_5S: name = _(L"Rewind 5 seconds"); break;
  267. case ACTION_FFWD_5S: name = _(L"Fast forward 5 seconds"); break;
  268. case ACTION_MUTE: name = _(L"Mute/Unmute sound"); break;
  269. case ACTION_TOGGLE_REPEAT: name = _(L"Toggle repeat"); break;
  270. case ACTION_TOGGLE_SHUFFLE: name = _(L"Toggle shuffle"); break;
  271. case ACTION_TOGGLE_CROSSFADER: name = _(L"Toggle crossfader"); break;
  272. }
  273. return name;
  274. }