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 <itdelatrisu@gmail.com>
This commit is contained in:
parent
f0f8160fa1
commit
943c2af178
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,6 +1,7 @@
|
||||||
/.opsu_tmp/
|
/.opsu_tmp/
|
||||||
/Screenshots/
|
/Screenshots/
|
||||||
/Skins/
|
/Skins/
|
||||||
|
/SongPacks/
|
||||||
/Songs/
|
/Songs/
|
||||||
/.opsu.log
|
/.opsu.log
|
||||||
/.opsu.cfg
|
/.opsu.cfg
|
||||||
|
|
|
@ -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
|
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
|
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
|
### First Run
|
||||||
The `Music Offset` value will likely need to be adjusted when playing for the
|
The `Music Offset` value will likely need to be adjusted when playing for the
|
||||||
|
|
|
@ -56,9 +56,9 @@ public class MusicController {
|
||||||
private static File wavFile;
|
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.
|
// This class should not be instantiated.
|
||||||
private MusicController() {}
|
private MusicController() {}
|
||||||
|
@ -71,11 +71,11 @@ public class MusicController {
|
||||||
boolean play = (lastOsu == null || !osu.audioFilename.equals(lastOsu.audioFilename));
|
boolean play = (lastOsu == null || !osu.audioFilename.equals(lastOsu.audioFilename));
|
||||||
lastOsu = osu;
|
lastOsu = osu;
|
||||||
if (play) {
|
if (play) {
|
||||||
// TODO: properly interrupt instead of using deprecated conversion.stop();
|
// TODO: properly interrupt instead of using deprecated Thread.stop();
|
||||||
// interrupt the conversion
|
// interrupt the conversion/track loading
|
||||||
if (isConverting())
|
if (isTrackLoading())
|
||||||
// conversion.interrupt();
|
// trackLoader.interrupt();
|
||||||
conversion.stop();
|
trackLoader.stop();
|
||||||
|
|
||||||
if (wavFile != null)
|
if (wavFile != null)
|
||||||
wavFile.delete();
|
wavFile.delete();
|
||||||
|
@ -85,11 +85,16 @@ public class MusicController {
|
||||||
|
|
||||||
switch (OsuParser.getExtension(osu.audioFilename.getName())) {
|
switch (OsuParser.getExtension(osu.audioFilename.getName())) {
|
||||||
case "ogg":
|
case "ogg":
|
||||||
loadTrack(osu.audioFilename, osu.previewTime, loop);
|
trackLoader = new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
loadTrack(osu.audioFilename, osu.previewTime, loop);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
trackLoader.start();
|
||||||
break;
|
break;
|
||||||
case "mp3":
|
case "mp3":
|
||||||
// convert MP3 to WAV in a new conversion
|
trackLoader = new Thread() {
|
||||||
conversion = new Thread() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
convertMp3(osu.audioFilename);
|
convertMp3(osu.audioFilename);
|
||||||
|
@ -97,7 +102,7 @@ public class MusicController {
|
||||||
loadTrack(wavFile, osu.previewTime, loop);
|
loadTrack(wavFile, osu.previewTime, loop);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
conversion.start();
|
trackLoader.start();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
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() {
|
public static boolean isTrackLoading() {
|
||||||
return (conversion != null && conversion.isAlive());
|
return (trackLoader != null && trackLoader.isAlive());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -246,11 +251,11 @@ public class MusicController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the length of the track, in milliseconds.
|
* 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)
|
* @author bdk (http://slick.ninjacave.com/forum/viewtopic.php?t=2699)
|
||||||
*/
|
*/
|
||||||
public static int getTrackLength() {
|
public static int getTrackLength() {
|
||||||
if (!trackExists() || isConverting())
|
if (!trackExists() || isTrackLoading())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
float duration = 0f;
|
float duration = 0f;
|
||||||
|
@ -273,10 +278,10 @@ public class MusicController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the length of the track as a formatted string (M:SS).
|
* 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() {
|
public static String getTrackLengthString() {
|
||||||
if (isConverting())
|
if (isTrackLoading())
|
||||||
return "...";
|
return "...";
|
||||||
|
|
||||||
int duration = getTrackLength();
|
int duration = getTrackLength();
|
||||||
|
|
|
@ -135,7 +135,7 @@ public class OsuGroupList {
|
||||||
*/
|
*/
|
||||||
public OsuGroupNode getRandomNode() {
|
public OsuGroupNode getRandomNode() {
|
||||||
OsuGroupNode node = getBaseNode((int) (Math.random() * size()));
|
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;
|
node = node.next;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,7 +188,7 @@ public class MainMenu extends BasicGameState {
|
||||||
g.setColor(Utils.COLOR_BLACK_ALPHA);
|
g.setColor(Utils.COLOR_BLACK_ALPHA);
|
||||||
g.fillRoundRect(width - 168, 54, 148, 5, 4);
|
g.fillRoundRect(width - 168, 54, 148, 5, 4);
|
||||||
g.setColor(Color.white);
|
g.setColor(Color.white);
|
||||||
if (!MusicController.isConverting())
|
if (!MusicController.isTrackLoading())
|
||||||
g.fillRoundRect(width - 168, 54,
|
g.fillRoundRect(width - 168, 54,
|
||||||
148f * MusicController.getPosition() / MusicController.getTrackLength(), 5, 4);
|
148f * MusicController.getPosition() / MusicController.getTrackLength(), 5, 4);
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ public class MainMenu extends BasicGameState {
|
||||||
int lineHeight = Utils.FONT_MEDIUM.getLineHeight();
|
int lineHeight = Utils.FONT_MEDIUM.getLineHeight();
|
||||||
g.drawString(String.format("Loaded %d songs and %d beatmaps.",
|
g.drawString(String.format("Loaded %d songs and %d beatmaps.",
|
||||||
Opsu.groups.size(), Opsu.groups.getMapCount()), 25, 25);
|
Opsu.groups.size(), Opsu.groups.getMapCount()), 25, 25);
|
||||||
if (MusicController.isConverting())
|
if (MusicController.isTrackLoading())
|
||||||
g.drawString("Track loading...", 25, 25 + lineHeight);
|
g.drawString("Track loading...", 25, 25 + lineHeight);
|
||||||
else if (MusicController.trackExists()) {
|
else if (MusicController.trackExists()) {
|
||||||
g.drawString((MusicController.isPlaying()) ? "Now Playing:" : "Paused:", 25, 25 + lineHeight);
|
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 (musicPlay.contains(x, y)) {
|
||||||
if (MusicController.isPlaying())
|
if (MusicController.isPlaying())
|
||||||
MusicController.pause();
|
MusicController.pause();
|
||||||
else if (!MusicController.isConverting())
|
else if (!MusicController.isTrackLoading())
|
||||||
MusicController.resume();
|
MusicController.resume();
|
||||||
} else if (musicNext.contains(x, y)) {
|
} else if (musicNext.contains(x, y)) {
|
||||||
SongMenu menu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
|
SongMenu menu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
|
||||||
|
|
|
@ -1193,7 +1193,8 @@ public class Options extends BasicGameState {
|
||||||
if (oszDir != null && oszDir.isDirectory())
|
if (oszDir != null && oszDir.isDirectory())
|
||||||
return oszDir;
|
return oszDir;
|
||||||
|
|
||||||
oszDir = new File("").getAbsoluteFile();
|
oszDir = new File("SongPacks/");
|
||||||
|
oszDir.mkdir();
|
||||||
return oszDir;
|
return oszDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -606,7 +606,7 @@ public class SongMenu extends BasicGameState {
|
||||||
* @param osu the OsuFile to send to the game
|
* @param osu the OsuFile to send to the game
|
||||||
*/
|
*/
|
||||||
private void startGame() {
|
private void startGame() {
|
||||||
if (MusicController.isConverting())
|
if (MusicController.isTrackLoading())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SoundController.playSound(SoundController.SOUND_MENUHIT);
|
SoundController.playSound(SoundController.SOUND_MENUHIT);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user