Merge remote-tracking branch 'remotes/original/master' into upstream

# Conflicts:
#	src/itdelatrisu/opsu/Container.java
#	src/itdelatrisu/opsu/GameData.java
#	src/itdelatrisu/opsu/Options.java
#	src/itdelatrisu/opsu/audio/MusicController.java
#	src/itdelatrisu/opsu/objects/Circle.java
#	src/itdelatrisu/opsu/objects/Slider.java
#	src/itdelatrisu/opsu/render/CurveRenderState.java
#	src/itdelatrisu/opsu/states/Game.java
#	src/itdelatrisu/opsu/states/MainMenu.java
#	src/itdelatrisu/opsu/states/SongMenu.java
#	src/itdelatrisu/opsu/ui/Colors.java
#	src/itdelatrisu/opsu/ui/MenuButton.java
This commit is contained in:
yugecin
2016-12-24 14:35:20 +01:00
36 changed files with 1667 additions and 569 deletions

View File

@@ -78,6 +78,12 @@ public class MusicController {
/** The track dim level, if dimmed. */
private static float dimLevel = 1f;
/** Current timing point index in the track, advanced by {@link #getBeatProgress()}. */
private static int timingPointIndex;
/** Last non-inherited timing point. */
private static TimingPoint lastTimingPoint;
// This class should not be instantiated.
private MusicController() {}
@@ -94,7 +100,6 @@ public class MusicController {
final File audioFile = beatmap.audioFilename;
if (!audioFile.isFile() && !ResourceLoader.resourceExists(audioFile.getPath())) {
UI.sendBarNotification(String.format("Could not find track '%s'.", audioFile.getName()));
System.out.println(beatmap);
return;
}
@@ -136,8 +141,10 @@ public class MusicController {
player.addListener(new MusicListener() {
@Override
public void musicEnded(Music music) {
if (music == player) // don't fire if music swapped
if (music == player) { // don't fire if music swapped
trackEnded = true;
resetTimingPoint();
}
}
@Override
@@ -159,6 +166,7 @@ public class MusicController {
setVolume(Options.getMusicVolume() * Options.getMasterVolume());
trackEnded = false;
pauseTime = 0f;
resetTimingPoint();
if (loop)
player.loop();
else
@@ -187,34 +195,81 @@ public class MusicController {
/**
* Gets the progress of the current beat.
* @return progress as a value in [0, 1], where 0 means a beat just happend and 1 means the next beat is coming now.
* @return a beat progress value [0,1) where 0 marks the current beat and
* 1 marks the next beat, or {@code null} if no timing information
* is available (e.g. music paused, no timing points)
*/
public static Double getBeatProgress() {
if (!isPlaying() || getBeatmap() == null) {
public static Float getBeatProgress() {
if (!updateTimingPoint())
return null;
}
// calculate beat progress
int trackPosition = Math.max(0, getPosition());
double beatLength = lastTimingPoint.getBeatLength() * 100.0;
int beatTime = lastTimingPoint.getTime();
if (trackPosition < beatTime)
trackPosition += (beatLength / 100.0) * (beatTime / lastTimingPoint.getBeatLength());
return (float) ((((trackPosition - beatTime) * 100.0) % beatLength) / beatLength);
}
/**
* Gets the progress of the current measure.
* @return a measure progress value [0,1) where 0 marks the start of the measure and
* 1 marks the start of the next measure, or {@code null} if no timing information
* is available (e.g. music paused, no timing points)
*/
public static Float getMeasureProgress() { return getMeasureProgress(1); }
/**
* Gets the progress of the current measure.
* @param k the meter multiplier
* @return a measure progress value [0,1) where 0 marks the start of the measure and
* 1 marks the start of the next measure, or {@code null} if no timing information
* is available (e.g. music paused, no timing points)
*/
public static Float getMeasureProgress(int k) {
if (!updateTimingPoint())
return null;
// calculate measure progress
int trackPosition = Math.max(0, getPosition());
double measureLength = lastTimingPoint.getBeatLength() * lastTimingPoint.getMeter() * k * 100.0;
int beatTime = lastTimingPoint.getTime();
if (trackPosition < beatTime)
trackPosition += (measureLength / 100.0) * (beatTime / lastTimingPoint.getBeatLength());
return (float) ((((trackPosition - beatTime) * 100.0) % measureLength) / measureLength);
}
/**
* Updates the timing point information for the current track position.
* @return {@code false} if timing point information is not available, {@code true} otherwise
*/
private static boolean updateTimingPoint() {
Beatmap map = getBeatmap();
if (map.timingPoints == null) {
return null;
if (!isPlaying() || map == null || map.timingPoints == null || map.timingPoints.isEmpty())
return false;
// initialization
if (timingPointIndex == 0 && lastTimingPoint == null && !map.timingPoints.isEmpty()) {
TimingPoint timingPoint = map.timingPoints.get(0);
if (!timingPoint.isInherited())
lastTimingPoint = timingPoint;
}
int trackposition = getPosition();
TimingPoint p = null;
float beatlen = 0f;
int time = 0;
for (TimingPoint pts : map.timingPoints) {
if (p == null || pts.getTime() < getPosition()) {
p = pts;
if (!p.isInherited() && p.getBeatLength() > 0) {
beatlen = p.getBeatLength();
time = p.getTime();
}
}
// advance timing point index, record last non-inherited timing point
int trackPosition = getPosition();
for (int i = timingPointIndex + 1; i < map.timingPoints.size(); i++) {
TimingPoint timingPoint = map.timingPoints.get(i);
if (trackPosition < timingPoint.getTime())
break;
timingPointIndex = i;
if (!timingPoint.isInherited() && timingPoint.getBeatLength() > 0)
lastTimingPoint = timingPoint;
}
if (p == null) {
return null;
}
double beatLength = beatlen * 100;
return (((trackposition * 100 - time * 100) % beatLength) / beatLength);
if (lastTimingPoint == null)
return false; // no timing info
return true;
}
/**
@@ -258,8 +313,10 @@ public class MusicController {
public static void stop() {
if (isPlaying())
player.stop();
if (trackExists())
if (trackExists()) {
pauseTime = 0f;
resetTimingPoint();
}
}
/**
@@ -298,7 +355,11 @@ public class MusicController {
* @param position the new track position (in ms)
*/
public static boolean setPosition(int position) {
return (trackExists() && position >= 0 && player.setPosition(position / 1000f));
if (!trackExists() || position < 0)
return false;
resetTimingPoint();
return (player.setPosition(position / 1000f));
}
/**
@@ -339,6 +400,7 @@ public class MusicController {
public static void play(boolean loop) {
if (trackExists()) {
trackEnded = false;
resetTimingPoint();
if (loop)
player.loop();
else
@@ -409,6 +471,14 @@ public class MusicController {
setVolume(volume);
}
/**
* Resets timing point information.
*/
private static void resetTimingPoint() {
timingPointIndex = 0;
lastTimingPoint = null;
}
/**
* Completely resets MusicController state.
* <p>
@@ -427,7 +497,7 @@ public class MusicController {
try {
trackLoader.join();
} catch (InterruptedException e) {
e.printStackTrace();
ErrorHandler.error(null, e, true);
}
}
trackLoader = null;
@@ -439,6 +509,7 @@ public class MusicController {
themePlaying = false;
pauseTime = 0f;
trackDimmed = false;
resetTimingPoint();
// releases all sources from previous tracks
destroyOpenAL();