Merge branch 'pullreq'

This commit is contained in:
yugecin 2016-10-11 18:36:47 +02:00
commit 86f6b168d8
3 changed files with 30 additions and 1 deletions

View File

@ -235,4 +235,19 @@ public class MultiClip {
// reset extra clip count // reset extra clip count
extraClips = 0; extraClips = 0;
} }
/**
* Mute the Clip (because destroying it, won't stop it)
*/
public void mute() {
try {
Clip c = getClip();
if (c == null) {
return;
}
((FloatControl) c.getControl(FloatControl.Type.MASTER_GAIN)).setValue((float) (Math.log(Float.MIN_VALUE) / Math.log(10.0) * 20.0));
} catch (LineUnavailableException e) {
e.printStackTrace();
}
}
} }

View File

@ -44,7 +44,8 @@ import org.newdawn.slick.util.ResourceLoader;
* Note: Uses Java Sound because OpenAL lags too much for accurate hit sounds. * Note: Uses Java Sound because OpenAL lags too much for accurate hit sounds.
*/ */
public class SoundController { public class SoundController {
/** Interface for all (non-music) sound components. */
/** Interface for all (non-music) sound components. */
public interface SoundComponent { public interface SoundComponent {
/** /**
* Returns the Clip associated with the sound component. * Returns the Clip associated with the sound component.
@ -56,6 +57,9 @@ public class SoundController {
/** The current track being played, if any. */ /** The current track being played, if any. */
private static MultiClip currentTrack; private static MultiClip currentTrack;
/** The current SoundComponent being played, if any */
private static MultiClip currentSoundComponent;
/** Sample volume multiplier, from timing points [0, 1]. */ /** Sample volume multiplier, from timing points [0, 1]. */
private static float sampleVolumeMultiplier = 1f; private static float sampleVolumeMultiplier = 1f;
@ -264,6 +268,8 @@ public class SoundController {
if (clip == null) // clip failed to load properly if (clip == null) // clip failed to load properly
return; return;
currentSoundComponent = clip;
if (volume > 0f && !isMuted) { if (volume > 0f && !isMuted) {
try { try {
clip.start(volume, listener); clip.start(volume, listener);
@ -378,4 +384,11 @@ public class SoundController {
currentTrack = null; currentTrack = null;
} }
} }
public static void muteSoundComponent() {
if (currentSoundComponent != null) {
currentSoundComponent.mute();
currentSoundComponent = null;
}
}
} }

View File

@ -240,6 +240,7 @@ public class GameRanking extends BasicGameState {
* Returns to the song menu. * Returns to the song menu.
*/ */
private void returnToSongMenu() { private void returnToSongMenu() {
SoundController.muteSoundComponent();
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
SongMenu songMenu = (SongMenu) game.getState(Opsu.STATE_SONGMENU); SongMenu songMenu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
if (data.isGameplay()) if (data.isGameplay())