Player.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "Player.h"
  2. using namespace GSL;
  3. GSLPlayer *_player = 0;
  4. #ifdef WIN32
  5. void CALLBACK AudioOutProc( HWAVEOUT hOut, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2 )
  6. {
  7. _player->sendSoundMSG( hOut, uMsg, dwInstance, dwParam1, dwParam2 );
  8. }
  9. #endif
  10. // Inhalt der GSLPlayer Klasse aus Player.h
  11. // Konstruktor
  12. GSLPlayer::GSLPlayer()
  13. {
  14. }
  15. // Destruktor
  16. GSLPlayer::~GSLPlayer()
  17. {
  18. sounds.leeren();
  19. }
  20. // nicht constant
  21. bool GSLPlayer::addSound( GSLSound *snd )
  22. {
  23. cs.lock();
  24. int anz = sounds.getEintragAnzahl();
  25. for( int i = 0; i < anz; i++ )
  26. {
  27. if( sounds.z( i ) == snd )
  28. {
  29. snd->release();
  30. cs.unlock();
  31. return 0;
  32. }
  33. }
  34. sounds.add( snd );
  35. cs.unlock();
  36. return 1;
  37. }
  38. void GSLPlayer::removeSound( GSLSound *zSnd )
  39. {
  40. cs.lock();
  41. int anz = sounds.getEintragAnzahl();
  42. for( int i = 0; i < anz; i++ )
  43. {
  44. if( sounds.z( i ) == zSnd )
  45. {
  46. cs.unlock();
  47. sounds.remove( i );
  48. return;
  49. }
  50. }
  51. cs.unlock();
  52. }
  53. #ifdef WIN32
  54. void GSLPlayer::sendSoundMSG( HWAVEOUT hOut, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2 )
  55. {
  56. cs.lock();
  57. int anz = sounds.getEintragAnzahl();
  58. for( int i = 0; i < anz; i++ )
  59. {
  60. if( sounds.z( i ) && sounds.z( i )->getHandle() == hOut )
  61. {
  62. sounds.z( i )->msg( uMsg, dwInstance, dwParam1, dwParam2 );
  63. break;
  64. }
  65. }
  66. cs.unlock();
  67. }
  68. #endif