main_buttons.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /** (c) Nullsoft, Inc. C O N F I D E N T I A L
  2. ** Filename:
  3. ** Project:
  4. ** Description:
  5. ** Author:
  6. ** Created:
  7. **/
  8. #include "Main.h"
  9. #include "resource.h"
  10. extern "C" extern int g_stopaftercur;
  11. // button 1 (prev) functions
  12. int Main_OnButton1(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
  13. {
  14. if (id == WINAMP_BUTTON1_SHIFT) SendMessageW(hwnd, WM_COMMAND, WINAMP_REW5S, 0);
  15. else if (id == WINAMP_BUTTON1_CTRL)
  16. {
  17. PlayList_setposition(0);
  18. if (config_shuffle) PlayList_randpos( -BIGINT);
  19. PlayList_getcurrent(FileName, FileTitle, FileTitleNum);
  20. if (playing) StartPlaying();
  21. else StopPlaying(0);
  22. }
  23. else
  24. {
  25. int nitem = SendMessageW(hMainWindow, WM_WA_IPC, 0, IPC_GET_PREVIOUS_PLITEM);
  26. if (nitem != -1)
  27. {
  28. PlayList_setposition(nitem);
  29. PlayList_getcurrent(FileName, FileTitle, FileTitleNum);
  30. StartPlaying();
  31. }
  32. else
  33. {
  34. int s = 1;
  35. if (!config_shuffle && PlayList_advance( -1) < 0)
  36. {
  37. s = 0;
  38. if (config_repeat)
  39. {
  40. s = 1;
  41. PlayList_advance(BIGINT);
  42. }
  43. }
  44. if (s)
  45. {
  46. if (PlayList_getlength())
  47. {
  48. if (config_shuffle)
  49. {
  50. if (PlayList_randpos( -1)) return 1;
  51. }
  52. PlayList_getcurrent(FileName, FileTitle, FileTitleNum);
  53. if (playing)
  54. {
  55. StopPlaying(0);
  56. StartPlaying();
  57. }
  58. else StopPlaying(0);
  59. }
  60. }
  61. }
  62. }
  63. return 1;
  64. } // Main_OnButton1
  65. // button 2 (play) functions
  66. int Main_OnButton2(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
  67. {
  68. PlayList_resetcurrent();
  69. if (!playing)
  70. {
  71. if (!no_notify_play)
  72. {
  73. FileName[0] = 0;
  74. PlayList_getcurrent(FileName, FileTitle, FileTitleNum);
  75. }
  76. if (id == WINAMP_BUTTON2_CTRL)
  77. SendMessageW(hwnd, WM_COMMAND, WINAMP_FILE_LOC, 0);
  78. else if (!FileName[0] || id == WINAMP_BUTTON2_SHIFT)
  79. {
  80. SendMessageW(hwnd, WM_COMMAND, WINAMP_FILE_PLAY, 0);
  81. }
  82. else
  83. {
  84. StartPlaying();
  85. }
  86. }
  87. else
  88. {
  89. if (id == WINAMP_BUTTON2_CTRL)
  90. SendMessageW(hwnd, WM_COMMAND, WINAMP_FILE_LOC, 0);
  91. else if (id == WINAMP_BUTTON2_SHIFT)
  92. SendMessageW(hwnd, WM_COMMAND, WINAMP_FILE_PLAY, 0);
  93. else if (paused) UnPausePlaying();
  94. else
  95. {
  96. PlayList_getcurrent(FileName, FileTitle, FileTitleNum);
  97. StartPlaying();
  98. }
  99. }
  100. return 1;
  101. } // Main_OnButton2
  102. // button 3 (pause) functions
  103. int Main_OnButton3(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
  104. {
  105. if (playing)
  106. {
  107. if (paused) UnPausePlaying();
  108. else PausePlaying();
  109. }
  110. return 1;
  111. }
  112. // button 4 (stop) functions
  113. int Main_OnButton4(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
  114. {
  115. if (playing)
  116. {
  117. if (id == WINAMP_BUTTON4_CTRL)
  118. {
  119. HMENU m;
  120. int r;
  121. g_stopaftercur = !g_stopaftercur;
  122. r = g_stopaftercur ? MF_CHECKED : MF_UNCHECKED;
  123. CheckMenuItem(main_menu, WINAMP_BUTTON4_CTRL, r);
  124. m = GetSubMenu(top_menu, 3);
  125. CheckMenuItem(m, WINAMP_BUTTON4_CTRL, r);
  126. return 1;
  127. }
  128. if (id == WINAMP_BUTTON4_SHIFT && !paused)
  129. {
  130. // double v=0;
  131. int x = 256;
  132. int v = config_volume;
  133. // double v = (double)(int)config_volume;
  134. //double dv;// = -v / 256.;//(double)x;
  135. int delay = 8;//2000 / x;
  136. // v = (double)config_volume;
  137. //dv = -v / 256.;
  138. while (x--)
  139. {
  140. if (v < 0) v = 0;
  141. in_setvol((int)v);
  142. // v += dv;
  143. v--;
  144. Sleep(delay);
  145. }
  146. Sleep(100);
  147. PausePlaying();
  148. in_flush(in_getouttime());
  149. in_setvol(config_volume);
  150. }
  151. StopPlaying(0);
  152. }
  153. return 1;
  154. }
  155. // button 5 (next) fucntions
  156. int Main_OnButton5(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
  157. {
  158. if (id == WINAMP_BUTTON5_SHIFT)
  159. SendMessageW(hwnd, WM_COMMAND, WINAMP_FFWD5S, 0);
  160. else if (id == WINAMP_BUTTON5_CTRL)
  161. {
  162. PlayList_setposition(BIGINT);
  163. if (config_shuffle)
  164. {
  165. PlayList_randpos( -BIGINT);
  166. PlayList_randpos(PlayList_getlength() - 1);
  167. }
  168. PlayList_getcurrent(FileName, FileTitle, FileTitleNum);
  169. if (playing) StartPlaying();
  170. else StopPlaying(0);
  171. }
  172. else
  173. {
  174. int nitem = SendMessageW(hMainWindow, WM_WA_IPC, 0, IPC_GET_NEXT_PLITEM);
  175. if (nitem != -1)
  176. {
  177. PlayList_setposition(nitem);
  178. PlayList_getcurrent(FileName, FileTitle, FileTitleNum);
  179. StartPlaying();
  180. }
  181. else if (!config_shuffle && PlayList_advance(1) < 0)
  182. {
  183. if (config_repeat)
  184. {
  185. PlayList_setposition(0);
  186. PlayList_getcurrent(FileName, FileTitle, FileTitleNum);
  187. if (playing)
  188. {
  189. StopPlaying(0);
  190. StartPlaying();
  191. }
  192. else StopPlaying(0);
  193. }
  194. }
  195. else
  196. {
  197. if (!PlayList_getlength()) return 1;
  198. if (config_shuffle)
  199. {
  200. int lp = PlayList_getPosition();
  201. int q = PlayList_randpos(1);
  202. if (q || PlayList_getlength() == 1)
  203. {
  204. if (!config_repeat) return 1;
  205. PlayList_randpos( -BIGINT);
  206. }
  207. if (PlayList_getPosition() == lp && PlayList_getlength() > 1)
  208. {
  209. PlayList_randpos(1);
  210. }
  211. }
  212. else
  213. {
  214. // 5.64 - if pledit is cleared, shuffle is off & we're playing
  215. // then we set playing to go back to the start of the playlist
  216. // as we get complaints it'll go to #2 instead of #1 as shown.
  217. if (plcleared)
  218. {
  219. plcleared = 0;
  220. PlayList_setposition(0);
  221. }
  222. }
  223. PlayList_getcurrent(FileName, FileTitle, FileTitleNum);
  224. if (playing)
  225. {
  226. StopPlaying(0);
  227. StartPlaying();
  228. }
  229. else StopPlaying(0);
  230. }
  231. }
  232. return 1;
  233. } // Main_OnButton5()