From 943c2af178255c79c5732e677d33199b5509fd10 Mon Sep 17 00:00:00 2001 From: Jeffrey Han Date: Tue, 15 Jul 2014 00:20:36 -0400 Subject: [PATCH] Resolved some reported issues. - Threaded OGG loading (in addition to MP3) to eliminate delays in song select menu. (reported by xasuma) - Changed default OSZ unpacking location to a "SongPacks" directory to prevent unintended unpacking. (reported by Lanturn) - Fixed a null pointer for a corner case in 'getRandomNode()'. (reported by @iceblade112) Signed-off-by: Jeffrey Han --- .gitignore | 1 + README.md | 2 +- src/itdelatrisu/opsu/MusicController.java | 41 +++++++++++++---------- src/itdelatrisu/opsu/OsuGroupList.java | 2 +- src/itdelatrisu/opsu/states/MainMenu.java | 6 ++-- src/itdelatrisu/opsu/states/Options.java | 3 +- src/itdelatrisu/opsu/states/SongMenu.java | 2 +- 7 files changed, 32 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 2ced573a..20d893d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /.opsu_tmp/ /Screenshots/ /Skins/ +/SongPacks/ /Songs/ /.opsu.log /.opsu.cfg diff --git a/README.md b/README.md index 2ddd1c07..f35ac5fd 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ configuration file to the path of the root song directory. Note that beatmaps are typically delivered as OSZ files. These can be extracted with any ZIP tool, and opsu! will automatically extract them into the songs -folder if placed in the root directory. +folder if placed in the `SongPacks` directory. ### First Run The `Music Offset` value will likely need to be adjusted when playing for the diff --git a/src/itdelatrisu/opsu/MusicController.java b/src/itdelatrisu/opsu/MusicController.java index e044fecb..83370519 100644 --- a/src/itdelatrisu/opsu/MusicController.java +++ b/src/itdelatrisu/opsu/MusicController.java @@ -56,9 +56,9 @@ public class MusicController { private static File wavFile; /** - * Thread for MP3 conversions. + * Thread for loading tracks. */ - private static Thread conversion; + private static Thread trackLoader; // This class should not be instantiated. private MusicController() {} @@ -71,11 +71,11 @@ public class MusicController { boolean play = (lastOsu == null || !osu.audioFilename.equals(lastOsu.audioFilename)); lastOsu = osu; if (play) { - // TODO: properly interrupt instead of using deprecated conversion.stop(); - // interrupt the conversion - if (isConverting()) -// conversion.interrupt(); - conversion.stop(); + // TODO: properly interrupt instead of using deprecated Thread.stop(); + // interrupt the conversion/track loading + if (isTrackLoading()) +// trackLoader.interrupt(); + trackLoader.stop(); if (wavFile != null) wavFile.delete(); @@ -85,11 +85,16 @@ public class MusicController { switch (OsuParser.getExtension(osu.audioFilename.getName())) { case "ogg": - loadTrack(osu.audioFilename, osu.previewTime, loop); + trackLoader = new Thread() { + @Override + public void run() { + loadTrack(osu.audioFilename, osu.previewTime, loop); + } + }; + trackLoader.start(); break; case "mp3": - // convert MP3 to WAV in a new conversion - conversion = new Thread() { + trackLoader = new Thread() { @Override public void run() { convertMp3(osu.audioFilename); @@ -97,7 +102,7 @@ public class MusicController { loadTrack(wavFile, osu.previewTime, loop); } }; - conversion.start(); + trackLoader.start(); break; default: break; @@ -149,10 +154,10 @@ public class MusicController { } /** - * Returns true if a conversion is running. + * Returns true if a track is being loaded. */ - public static boolean isConverting() { - return (conversion != null && conversion.isAlive()); + public static boolean isTrackLoading() { + return (trackLoader != null && trackLoader.isAlive()); } /** @@ -246,11 +251,11 @@ public class MusicController { /** * Gets the length of the track, in milliseconds. - * Returns 0 if no file is loaded or an MP3 is currently being converted. + * Returns 0 if no file is loaded or a track is currently being loaded. * @author bdk (http://slick.ninjacave.com/forum/viewtopic.php?t=2699) */ public static int getTrackLength() { - if (!trackExists() || isConverting()) + if (!trackExists() || isTrackLoading()) return 0; float duration = 0f; @@ -273,10 +278,10 @@ public class MusicController { /** * Gets the length of the track as a formatted string (M:SS). - * Returns "--" if an MP3 is currently being converted. + * Returns "--" if a track is currently being loaded. */ public static String getTrackLengthString() { - if (isConverting()) + if (isTrackLoading()) return "..."; int duration = getTrackLength(); diff --git a/src/itdelatrisu/opsu/OsuGroupList.java b/src/itdelatrisu/opsu/OsuGroupList.java index 72277d5a..e877ea5c 100644 --- a/src/itdelatrisu/opsu/OsuGroupList.java +++ b/src/itdelatrisu/opsu/OsuGroupList.java @@ -135,7 +135,7 @@ public class OsuGroupList { */ public OsuGroupNode getRandomNode() { OsuGroupNode node = getBaseNode((int) (Math.random() * size())); - if (node.index == expandedIndex) // don't choose an expanded group node + if (node != null && node.index == expandedIndex) // don't choose an expanded group node node = node.next; return node; } diff --git a/src/itdelatrisu/opsu/states/MainMenu.java b/src/itdelatrisu/opsu/states/MainMenu.java index 5ac9a3a7..5db6ae3b 100644 --- a/src/itdelatrisu/opsu/states/MainMenu.java +++ b/src/itdelatrisu/opsu/states/MainMenu.java @@ -188,7 +188,7 @@ public class MainMenu extends BasicGameState { g.setColor(Utils.COLOR_BLACK_ALPHA); g.fillRoundRect(width - 168, 54, 148, 5, 4); g.setColor(Color.white); - if (!MusicController.isConverting()) + if (!MusicController.isTrackLoading()) g.fillRoundRect(width - 168, 54, 148f * MusicController.getPosition() / MusicController.getTrackLength(), 5, 4); @@ -197,7 +197,7 @@ public class MainMenu extends BasicGameState { int lineHeight = Utils.FONT_MEDIUM.getLineHeight(); g.drawString(String.format("Loaded %d songs and %d beatmaps.", Opsu.groups.size(), Opsu.groups.getMapCount()), 25, 25); - if (MusicController.isConverting()) + if (MusicController.isTrackLoading()) g.drawString("Track loading...", 25, 25 + lineHeight); else if (MusicController.trackExists()) { g.drawString((MusicController.isPlaying()) ? "Now Playing:" : "Paused:", 25, 25 + lineHeight); @@ -290,7 +290,7 @@ public class MainMenu extends BasicGameState { if (musicPlay.contains(x, y)) { if (MusicController.isPlaying()) MusicController.pause(); - else if (!MusicController.isConverting()) + else if (!MusicController.isTrackLoading()) MusicController.resume(); } else if (musicNext.contains(x, y)) { SongMenu menu = (SongMenu) game.getState(Opsu.STATE_SONGMENU); diff --git a/src/itdelatrisu/opsu/states/Options.java b/src/itdelatrisu/opsu/states/Options.java index f0026a18..da11cbfa 100644 --- a/src/itdelatrisu/opsu/states/Options.java +++ b/src/itdelatrisu/opsu/states/Options.java @@ -1193,7 +1193,8 @@ public class Options extends BasicGameState { if (oszDir != null && oszDir.isDirectory()) return oszDir; - oszDir = new File("").getAbsoluteFile(); + oszDir = new File("SongPacks/"); + oszDir.mkdir(); return oszDir; } diff --git a/src/itdelatrisu/opsu/states/SongMenu.java b/src/itdelatrisu/opsu/states/SongMenu.java index a97a083f..9ae9ec78 100644 --- a/src/itdelatrisu/opsu/states/SongMenu.java +++ b/src/itdelatrisu/opsu/states/SongMenu.java @@ -606,7 +606,7 @@ public class SongMenu extends BasicGameState { * @param osu the OsuFile to send to the game */ private void startGame() { - if (MusicController.isConverting()) + if (MusicController.isTrackLoading()) return; SoundController.playSound(SoundController.SOUND_MENUHIT);