]> git.mxchange.org Git - flightgear.git/blobdiff - src/Sound/soundmgr.cxx
Converted if ( string == "" ) constructs to if ( string.empty() )
[flightgear.git] / src / Sound / soundmgr.cxx
index eb51afac65d836bdd020673c2d0e259743f44f5c..edd46700d4fa4a05b80148f6aa55b757a31b4eda 100644 (file)
 //
 
 // constructor
-FGSimpleSound::FGSimpleSound( string file ) {
+FGSimpleSound::FGSimpleSound( string file )
+  : pitch(1.0),
+    volume(1.0),
+    requests(0)
+{
     SGPath slfile( globals->get_fg_root() );
     slfile.append( file );
     sample = new slSample ( (char *)slfile.c_str() );
@@ -49,7 +53,11 @@ FGSimpleSound::FGSimpleSound( string file ) {
     volume_envelope->setStep ( 0, 0.01, 1.0 );
 }
 
-FGSimpleSound::FGSimpleSound( unsigned char *buffer, int len ) {
+FGSimpleSound::FGSimpleSound( unsigned char *buffer, int len )
+  : pitch(1.0),
+    volume(1.0),
+    requests(0)
+{
     sample = new slSample ( buffer, len );
     pitch_envelope = new slEnvelope( 1, SL_SAMPLE_ONE_SHOT );
     volume_envelope = new slEnvelope( 1, SL_SAMPLE_ONE_SHOT );
@@ -64,17 +72,34 @@ FGSimpleSound::~FGSimpleSound() {
     delete sample;
 }
 
-void FGSimpleSound::play_once( slScheduler *sched ) {
-    sched->stopSample(sample);
-    sched->playSample(sample);
+void FGSimpleSound::play( slScheduler *sched, bool looped ) {
+    
+    requests++;
+    if (requests > 1)
+       return;
+
+    // sched->stopSample(sample);
+    if (looped)
+       sched->loopSample(sample);
+    else
+       sched->playSample(sample);
+    
     sched->addSampleEnvelope(sample, 0, 0, pitch_envelope, SL_PITCH_ENVELOPE);
     sched->addSampleEnvelope(sample, 0, 1, volume_envelope, SL_VOLUME_ENVELOPE);
 }
 
-void FGSimpleSound::play_looped( slScheduler *sched ) {
-    sched->loopSample(sample);
-    sched->addSampleEnvelope(sample, 0, 0, pitch_envelope, SL_PITCH_ENVELOPE);
-    sched->addSampleEnvelope(sample, 0, 1, volume_envelope, SL_VOLUME_ENVELOPE);
+void FGSimpleSound::stop( slScheduler *sched, bool quick ) {
+
+    if (quick)
+       requests = 0;
+    else
+       if (--requests < 0)
+          requests = 0;
+
+    if (requests > 0)
+       return;
+
+    sched->stopSample( sample );
 }
 
 //
@@ -220,7 +245,7 @@ bool FGSoundMgr::add( FGSimpleSound *sound, const string& refname ) {
 FGSimpleSound *FGSoundMgr::add( const string& refname, const string &file ) {
      FGSimpleSound *sound;
 
-    if (file == (string)"")
+    if (file.empty())
        return NULL;
 
     sample_map_iterator it = samples.find(file);