@@ -341,14 +341,13 @@ int PlayerAServer::read_answer(char *buf, int maxsize) const
341341 return -1 ;
342342}
343343
344- PlayerAServer::Source::Source (const Audio *audio, PlayerAServer *player )
345- : Player::Source (audio)
344+ PlayerAServer::Source::Source (Player *player, const Audio *audio )
345+ : Player::Source (player, audio)
346346 , asHandle (-1 )
347347 , odirection (0.0 )
348348 , ointensity (0.0 )
349349 , opitch (1.0 )
350350 , ov (0.0 , 0.0 , 0.0 )
351- , player (player)
352351{
353352 loadAudio (audio);
354353}
@@ -359,6 +358,8 @@ PlayerAServer::Source::Source(const Audio *audio, PlayerAServer *player)
359358
360359void PlayerAServer::Source::loadAudio (const Audio *audio)
361360{
361+ const PlayerAServer *player = (PlayerAServer *)this ->player ;
362+
362363 if (!player)
363364 return ;
364365
@@ -443,6 +444,7 @@ void PlayerAServer::Source::setAudio(const Audio *audio)
443444 if (asHandle >= 0 )
444445 {
445446 snprintf (msg, sizeof (msg), " RHDL %d" , asHandle);
447+ const PlayerAServer *player = (PlayerAServer *)this ->player ;
446448 player->send_cmd (msg);
447449 }
448450
@@ -460,6 +462,7 @@ PlayerAServer::Source::~Source()
460462 if (asHandle >= 0 )
461463 {
462464 snprintf (msg, sizeof (msg), " RHDL %d" , asHandle);
465+ const PlayerAServer *player = (PlayerAServer *)this ->player ;
463466 player->send_cmd (msg);
464467 }
465468}
@@ -471,6 +474,7 @@ void PlayerAServer::Source::play(double start)
471474 if (asHandle >= 0 )
472475 {
473476 snprintf (msg, sizeof (msg), " PLAY %d %f" , asHandle, start);
477+ const PlayerAServer *player = (PlayerAServer *)this ->player ;
474478 if (player->send_cmd (msg) < 0 )
475479 {
476480 CERR << " playing handle " << asHandle << " failed" << endl;
@@ -494,30 +498,21 @@ void PlayerAServer::Source::stop()
494498 if (asHandle >= 0 )
495499 {
496500 snprintf (msg, sizeof (msg), " STOP %d" , asHandle);
501+ const PlayerAServer *player = (PlayerAServer *)this ->player ;
497502 player->send_cmd (msg);
498503 }
499504}
500505
501- int PlayerAServer::Source::update (const Player *genericPlayer, char *buf, int bufsize )
506+ void PlayerAServer::Source::update (const Player *genericPlayer)
502507{
503- Player::Source::update (genericPlayer, buf, bufsize );
508+ Player::Source::update (genericPlayer);
504509
505510 // dynamic_cast causes problems on gcc2 systems
506511 // const PlayerAServer *player = dynamic_cast<const PlayerAServer *>(genericPlayer);
507512 const PlayerAServer *player = (const PlayerAServer *)(genericPlayer);
508- if (!player)
509- {
510- return -1 ;
511- }
512-
513- if (asHandle < 0 )
513+ if (!player || asHandle < 0 || !isPlaying ())
514514 {
515- return -1 ;
516- }
517-
518- if (!isPlaying ())
519- {
520- return -1 ;
515+ return ;
521516 }
522517
523518 char msg[MAX_BUFLEN ];
@@ -559,8 +554,6 @@ int PlayerAServer::Source::update(const Player *genericPlayer, char *buf, int bu
559554 player->send_cmd (msg);
560555 opitch = pitch;
561556 }
562-
563- return 0 ;
564557}
565558
566559void PlayerAServer::Source::setLoop (bool loop)
@@ -572,12 +565,13 @@ void PlayerAServer::Source::setLoop(bool loop)
572565 if (asHandle >= 0 )
573566 {
574567 snprintf (msg, sizeof (msg), " SSLP %d %d" , asHandle, loop ? 1 : 0 );
568+ const PlayerAServer *player = (PlayerAServer *)this ->player ;
575569 player->send_cmd (msg);
576570 }
577571}
578572
579- Player::Source *
580- PlayerAServer::newSource ( const Audio *audio)
573+ std::unique_ptr< Player::Source>
574+ PlayerAServer::makeSource (Player *player, const Audio *audio)
581575{
582- return new Source (audio, this );
576+ return std::make_unique<PlayerAServer:: Source>( this , audio );
583577}
0 commit comments