Skip to content

Commit

Permalink
Added option to disable sound effects from loading. (partially resolv…
Browse files Browse the repository at this point in the history
…es 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>
  • Loading branch information
itdelatrisu committed Jul 11, 2014
1 parent 842563c commit 5aa9620
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/itdelatrisu/opsu/SoundController.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ private static Clip loadClip(String ref) {
* Loads all sound files.
*/
public static void init() {
if (Options.isSoundDisabled())
return;

// TODO: support MP3 sounds?
currentFileIndex = 0;

Expand Down
35 changes: 33 additions & 2 deletions src/itdelatrisu/opsu/states/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ private static enum GameOption {
FIXED_AR,
FIXED_OD,
LOAD_VERBOSE,
CHECKPOINT;
CHECKPOINT,
DISABLE_SOUNDS;
};

/**
Expand Down Expand Up @@ -197,7 +198,8 @@ private static enum GameOption {
GameOption.MUSIC_VOLUME,
GameOption.EFFECT_VOLUME,
GameOption.HITSOUND_VOLUME,
GameOption.MUSIC_OFFSET
GameOption.MUSIC_OFFSET,
GameOption.DISABLE_SOUNDS
};

/**
Expand Down Expand Up @@ -366,6 +368,15 @@ private static enum GameOption {
*/
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).
*/
Expand Down Expand Up @@ -616,6 +627,9 @@ public void mousePressed(int button, int x, int y) {
case LOAD_VERBOSE:
loadVerbose = !loadVerbose;
break;
case DISABLE_SOUNDS:
disableSound = !disableSound;
break;
default:
break;
}
Expand Down Expand Up @@ -815,6 +829,12 @@ private void drawOption(GameOption option, int pos) {
"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),
Expand Down Expand Up @@ -1125,6 +1145,12 @@ public static void setDisplayMode(AppGameContainer app) throws SlickException {
*/
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)
Expand Down Expand Up @@ -1273,6 +1299,9 @@ public static void parseOptions() {
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)
Expand Down Expand Up @@ -1367,6 +1396,8 @@ public static void saveOptions() {
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));
Expand Down
2 changes: 1 addition & 1 deletion src/itdelatrisu/opsu/states/SongMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ public OsuGroupNode setFocus(OsuGroupNode node, int pos, boolean flag) {
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);
Expand Down

0 comments on commit 5aa9620

Please sign in to comment.