コード例 #1
0
  public boolean init(VSDFile vf) {

    if (!initialized) {
      if (use_start_sound) {
        start_sound = new SoundBite(vf, start_file, name + "_Start", name + "_Start");
        start_sound.setLooped(false);
        start_sound.setGain(gain);
      }
      if (use_mid_sound) {
        mid_sound = new SoundBite(vf, mid_file, name + "_Mid", name + "_Mid");
        mid_sound.setLooped(false);
        mid_sound.setGain(gain);
      }
      if (use_end_sound) {
        end_sound = new SoundBite(vf, end_file, name + "_End", name + "_End");
        end_sound.setLooped(false);
        end_sound.setGain(gain);
      }
      if (use_short_sound) {
        short_sound = new SoundBite(vf, short_file, name + "_Short", name + "_Short");
        short_sound.setLooped(false);
        short_sound.setGain(gain);
      }
    }
    return (true);
  }
コード例 #2
0
  public void stop() {
    log.warn("Stopping");
    // make sure the start sound is killed
    if (use_start_sound) {
      start_sound.stop();
    }

    // If the mid sound is used, turn off the looping.
    // this will allow it to naturally die.
    if (use_mid_sound) {
      mid_sound.setLooped(false);
      mid_sound.fadeOut();
    }

    // If the timer is running, stop it.
    if (t != null) {
      t.stop();
    }

    // If we're using the end sound, stop the mid sound
    // and play the end sound.
    if (use_end_sound) {
      if (use_mid_sound) {
        mid_sound.stop();
      }
      end_sound.setLooped(false);
      end_sound.play();
    }
    is_playing = false;
  }
コード例 #3
0
 public void play() {
   if (use_short_sound) {
     short_sound.play();
     is_playing = false; // short sound, won't be playing long...
   } else {
     if (use_start_sound) {
       t =
           newTimer(
               start_sound.getLengthAsInt(),
               false,
               new ActionListener() {
                 public void actionPerformed(ActionEvent e) {
                   handleTimerPop(e);
                 }
               });
       start_sound.play();
       if (use_mid_sound) {
         t.start();
         is_playing = true;
       }
     } else if (use_mid_sound) {
       mid_sound.setLooped(true);
       mid_sound.play();
     }
   }
 }
コード例 #4
0
ファイル: SoundBite.java プロジェクト: KenC57/JMRI
 public final boolean init(VSDFile vf, BufferMode mode) {
   AudioManager am = jmri.InstanceManager.getDefault(jmri.AudioManager.class);
   if (!initialized) {
     try {
       sound_src = (AudioSource) am.provideAudio(SrcSysNamePrefix + system_name);
       sound_src.setUserName(BufUserNamePrefix + user_name);
       setLooped(false);
       if (mode == BufferMode.BOUND_MODE) {
         sound_buf = (AudioBuffer) am.provideAudio(BufSysNamePrefix + system_name);
         sound_buf.setUserName(BufUserNamePrefix + user_name);
         if (vf == null) {
           sound_buf.setURL(vsd_file_base + filename);
         } else {
           java.io.InputStream ins = vf.getInputStream(filename);
           if (ins != null) {
             sound_buf.setInputStream(ins);
           } else {
             return (false);
           }
         }
         sound_src.setAssignedBuffer(sound_buf);
         setLength();
       }
     } catch (AudioException | IllegalArgumentException ex) {
       log.warn("Problem creating SoundBite: " + ex);
     }
   }
   return (true);
 }
コード例 #5
0
 // Catch the timer pop after the start sound is played and trigger the (looped) sustain sound.
 protected void handleTimerPop(ActionEvent e) {
   log.info("Received timer pop after start sound played.");
   // TODO: Need to validate that this is the timer pop
   if (use_mid_sound) {
     mid_sound.setLooped(true);
     mid_sound.play();
   }
   t.stop();
 }
コード例 #6
0
 public void loop() {
   if (use_start_sound) {
     start_sound.setLooped(false);
     start_sound.play();
     t =
         newTimer(
             start_sound.getLengthAsInt() - 100,
             false,
             new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                 handleTimerPop(e);
               }
             });
     t.setRepeats(false); // timer pop only once to trigger the sustain sound.
     t.start();
   } else if (use_mid_sound) {
     mid_sound.setLooped(true);
     mid_sound.play();
   }
   is_playing = true;
 }