Added option to disable sound effects from loading. (partially resolves issue #1)

- By default, sound effects will be disabled on Linux due to driver issues.

Other changes:
- Minor corner-case fix in song selection. (since 95f969f)

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2014-07-10 22:01:39 -04:00
parent 842563c6a5
commit 5aa9620834
3 changed files with 37 additions and 3 deletions

View File

@ -185,6 +185,9 @@ public class SoundController {
* Loads all sound files.
*/
public static void init() {
if (Options.isSoundDisabled())
return;
// TODO: support MP3 sounds?
currentFileIndex = 0;

View File

@ -143,7 +143,8 @@ public class Options extends BasicGameState {
FIXED_AR,
FIXED_OD,
LOAD_VERBOSE,
CHECKPOINT;
CHECKPOINT,
DISABLE_SOUNDS;
};
/**
@ -197,7 +198,8 @@ public class Options extends BasicGameState {
GameOption.MUSIC_VOLUME,
GameOption.EFFECT_VOLUME,
GameOption.HITSOUND_VOLUME,
GameOption.MUSIC_OFFSET
GameOption.MUSIC_OFFSET,
GameOption.DISABLE_SOUNDS
};
/**
@ -366,6 +368,15 @@ public class Options extends BasicGameState {
*/
private static int checkpoint = 0;
/**
* Whether or not to disable all sounds.
* This will prevent SoundController from loading sound files.
* <p>
* By default, sound is disabled on Linux due to possible driver issues.
*/
private static boolean disableSound =
(System.getProperty("os.name").toLowerCase().indexOf("linux") > -1);
/**
* Game option coordinate modifiers (for drawing).
*/
@ -616,6 +627,9 @@ public class Options extends BasicGameState {
case LOAD_VERBOSE:
loadVerbose = !loadVerbose;
break;
case DISABLE_SOUNDS:
disableSound = !disableSound;
break;
default:
break;
}
@ -815,6 +829,12 @@ public class Options extends BasicGameState {
"Adjust this value if hit objects are out of sync."
);
break;
case DISABLE_SOUNDS:
drawOption(pos, "Disable All Sound Effects",
disableSound ? "Yes" : "No",
"May resolve Linux sound driver issues. Requires a restart."
);
break;
case BACKGROUND_DIM:
drawOption(pos, "Background Dim",
String.format("%d%%", backgroundDim),
@ -1125,6 +1145,12 @@ public class Options extends BasicGameState {
*/
public static int getCheckpoint() { return checkpoint * 1000; }
/**
* Returns whether or not all sound effects are disabled.
* @return true if disabled
*/
public static boolean isSoundDisabled() { return disableSound; }
/**
* Sets the track checkpoint time, if within bounds.
* @param time the track position (in ms)
@ -1273,6 +1299,9 @@ public class Options extends BasicGameState {
if (i >= -500 && i <= 500)
musicOffset = i;
break;
case "DisableSound":
disableSound = Boolean.parseBoolean(value);
break;
case "DimLevel":
i = Integer.parseInt(value);
if (i >= 0 && i <= 100)
@ -1367,6 +1396,8 @@ public class Options extends BasicGameState {
writer.newLine();
writer.write(String.format("Offset = %d", musicOffset));
writer.newLine();
writer.write(String.format("DisableSound = %b", disableSound));
writer.newLine();
writer.write(String.format("DimLevel = %d", backgroundDim));
writer.newLine();
writer.write(String.format("ForceDefaultPlayfield = %b", forceDefaultPlayfield));

View File

@ -569,7 +569,7 @@ public class SongMenu extends BasicGameState {
pos = (int) (Math.random() * length);
// change the focus node
if (flag || (startNode.index == 0 && startNode.prev == null))
if (flag || (startNode.index == 0 && startNode.osuFileIndex == -1 && startNode.prev == null))
startNode = node;
focusNode = Opsu.groups.getNode(node, pos);
MusicController.play(focusNode.osuFiles.get(focusNode.osuFileIndex), true);