Stopper.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. ** Copyright (C) 2008 Nullsoft, Inc.
  3. **
  4. ** This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held
  5. ** liable for any damages arising from the use of this software.
  6. **
  7. ** Permission is granted to anyone to use this software for any purpose, including commercial applications, and to
  8. ** alter it and redistribute it freely, subject to the following restrictions:
  9. **
  10. ** 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software.
  11. ** If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  12. **
  13. ** 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  14. **
  15. ** 3. This notice may not be removed or altered from any source distribution.
  16. **
  17. ** Author: Ben Allison [email protected]
  18. ** Created: January 31, 2008
  19. **
  20. */
  21. #include "Stopper.h"
  22. #include "main.h"
  23. #include "../Winamp/wa_ipc.h"
  24. Stopper::Stopper() : isplaying(0), timems(0)
  25. {
  26. }
  27. void Stopper::ChangeTracking(bool mode)
  28. {
  29. SendMessage(plugin.hMainWindow, WM_USER, mode, IPC_ALLOW_PLAYTRACKING); // enable / disable stats updating
  30. }
  31. void Stopper::Stop()
  32. {
  33. isplaying = SendMessage(plugin.hMainWindow, WM_USER, 0, IPC_ISPLAYING);
  34. if (isplaying)
  35. {
  36. ChangeTracking(0); // disable stats updating
  37. timems = SendMessage(plugin.hMainWindow, WM_USER, 0, IPC_GETOUTPUTTIME);
  38. SendMessage(plugin.hMainWindow, WM_COMMAND, 40047, 0); // Stop
  39. }
  40. }
  41. void Stopper::Play()
  42. {
  43. if (isplaying) // this works _most_ of the time, not sure why a small portion of the time it doesnt hrmph :/
  44. // ideally we should replace it with a system that pauses the decode thread, closes its file,
  45. // does the shit, and reopens and reseeks to the new offset. for gaplessness
  46. {
  47. if (timems)
  48. {
  49. m_force_seek = timems; // SendMessage(mod.hMainWindow,WM_USER,timems,106);
  50. }
  51. else
  52. m_force_seek = -1;
  53. SendMessage(plugin.hMainWindow, WM_COMMAND, 40045, 0); // Play
  54. //m_force_seek = -1;
  55. if (isplaying & 2)
  56. {
  57. SendMessage(plugin.hMainWindow, WM_COMMAND, 40046, 0); // Pause
  58. }
  59. ChangeTracking(1); // enable stats updating
  60. }
  61. }