From 164d27234006cc8a7c6ba1934ae5cce791b69854 Mon Sep 17 00:00:00 2001 From: Awlex Date: Tue, 11 Oct 2016 18:06:59 +0200 Subject: [PATCH 1/2] Muting 'Applause' after leaving resultscreen closes #27 --- src/itdelatrisu/opsu/audio/MultiClip.java | 10 ++++++++++ src/itdelatrisu/opsu/audio/SoundController.java | 15 ++++++++++++++- src/itdelatrisu/opsu/states/GameRanking.java | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/itdelatrisu/opsu/audio/MultiClip.java b/src/itdelatrisu/opsu/audio/MultiClip.java index f4f18ac9..df02e6aa 100644 --- a/src/itdelatrisu/opsu/audio/MultiClip.java +++ b/src/itdelatrisu/opsu/audio/MultiClip.java @@ -235,4 +235,14 @@ public class MultiClip { // reset extra clip count extraClips = 0; } + + /** + * Mute the Clip (because destroying it, won't stop it) + */ + public void mute() { + try { + ((FloatControl) getClip().getControl(FloatControl.Type.MASTER_GAIN)).setValue((float) (Math.log(Float.MIN_VALUE) / Math.log(10.0) * 20.0)); + } catch (Exception e) { + } + } } diff --git a/src/itdelatrisu/opsu/audio/SoundController.java b/src/itdelatrisu/opsu/audio/SoundController.java index 73d00c3d..dced5c3a 100644 --- a/src/itdelatrisu/opsu/audio/SoundController.java +++ b/src/itdelatrisu/opsu/audio/SoundController.java @@ -44,7 +44,8 @@ import org.newdawn.slick.util.ResourceLoader; * Note: Uses Java Sound because OpenAL lags too much for accurate hit sounds. */ public class SoundController { - /** Interface for all (non-music) sound components. */ + + /** Interface for all (non-music) sound components. */ public interface SoundComponent { /** * Returns the Clip associated with the sound component. @@ -56,6 +57,9 @@ public class SoundController { /** The current track being played, if any. */ private static MultiClip currentTrack; + /** The current SoundComponent being played, if any */ + private static MultiClip currentSoundComponent; + /** Sample volume multiplier, from timing points [0, 1]. */ private static float sampleVolumeMultiplier = 1f; @@ -264,6 +268,8 @@ public class SoundController { if (clip == null) // clip failed to load properly return; + currentSoundComponent = clip; + if (volume > 0f && !isMuted) { try { clip.start(volume, listener); @@ -378,4 +384,11 @@ public class SoundController { currentTrack = null; } } + + public static void muteSoundComponent() { + if (currentSoundComponent != null) { + currentSoundComponent.mute(); + currentSoundComponent = null; + } + } } diff --git a/src/itdelatrisu/opsu/states/GameRanking.java b/src/itdelatrisu/opsu/states/GameRanking.java index 5ade7f2b..fb5c91e5 100644 --- a/src/itdelatrisu/opsu/states/GameRanking.java +++ b/src/itdelatrisu/opsu/states/GameRanking.java @@ -240,6 +240,7 @@ public class GameRanking extends BasicGameState { * Returns to the song menu. */ private void returnToSongMenu() { + SoundController.muteSoundComponent(); SoundController.playSound(SoundEffect.MENUBACK); SongMenu songMenu = (SongMenu) game.getState(Opsu.STATE_SONGMENU); if (data.isGameplay()) From d8aaa3e5a4fc124b041719c20f728d4044c14439 Mon Sep 17 00:00:00 2001 From: yugecin Date: Tue, 11 Oct 2016 18:36:28 +0200 Subject: [PATCH 2/2] tabs --- src/itdelatrisu/opsu/audio/MultiClip.java | 23 +++++++++++-------- .../opsu/audio/SoundController.java | 16 ++++++------- src/itdelatrisu/opsu/states/GameRanking.java | 2 +- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/itdelatrisu/opsu/audio/MultiClip.java b/src/itdelatrisu/opsu/audio/MultiClip.java index df02e6aa..0be76c64 100644 --- a/src/itdelatrisu/opsu/audio/MultiClip.java +++ b/src/itdelatrisu/opsu/audio/MultiClip.java @@ -236,13 +236,18 @@ public class MultiClip { extraClips = 0; } - /** - * Mute the Clip (because destroying it, won't stop it) - */ - public void mute() { - try { - ((FloatControl) getClip().getControl(FloatControl.Type.MASTER_GAIN)).setValue((float) (Math.log(Float.MIN_VALUE) / Math.log(10.0) * 20.0)); - } catch (Exception e) { - } - } + /** + * 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(); + } + } } diff --git a/src/itdelatrisu/opsu/audio/SoundController.java b/src/itdelatrisu/opsu/audio/SoundController.java index dced5c3a..e9b4f9a6 100644 --- a/src/itdelatrisu/opsu/audio/SoundController.java +++ b/src/itdelatrisu/opsu/audio/SoundController.java @@ -57,8 +57,8 @@ public class SoundController { /** The current track being played, if any. */ private static MultiClip currentTrack; - /** The current SoundComponent being played, if any */ - private static MultiClip currentSoundComponent; + /** The current SoundComponent being played, if any */ + private static MultiClip currentSoundComponent; /** Sample volume multiplier, from timing points [0, 1]. */ private static float sampleVolumeMultiplier = 1f; @@ -385,10 +385,10 @@ public class SoundController { } } - public static void muteSoundComponent() { - if (currentSoundComponent != null) { - currentSoundComponent.mute(); - currentSoundComponent = null; - } - } + public static void muteSoundComponent() { + if (currentSoundComponent != null) { + currentSoundComponent.mute(); + currentSoundComponent = null; + } + } } diff --git a/src/itdelatrisu/opsu/states/GameRanking.java b/src/itdelatrisu/opsu/states/GameRanking.java index fb5c91e5..fe7450fd 100644 --- a/src/itdelatrisu/opsu/states/GameRanking.java +++ b/src/itdelatrisu/opsu/states/GameRanking.java @@ -240,7 +240,7 @@ public class GameRanking extends BasicGameState { * Returns to the song menu. */ private void returnToSongMenu() { - SoundController.muteSoundComponent(); + SoundController.muteSoundComponent(); SoundController.playSound(SoundEffect.MENUBACK); SongMenu songMenu = (SongMenu) game.getState(Opsu.STATE_SONGMENU); if (data.isGameplay())