code cleanup
This commit is contained in:
parent
901594608c
commit
1e98d34035
@ -102,9 +102,29 @@ public class ScrollText extends Widget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void scroll(float delta) {
|
||||||
|
if (text1Offset >= -text1Width) {
|
||||||
|
text1Offset -= 60*delta;
|
||||||
|
|
||||||
|
|
||||||
|
if ((text1Offset < - Math.abs((text1Width - clipBounds.getWidth())) - 50) || text2Offset != clipBounds.getWidth()) {
|
||||||
|
text2Offset -= 60*delta;
|
||||||
|
if (text2Offset <= -text2Width) {
|
||||||
|
text2Offset = clipBounds.getWidth();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
text2Offset -= 60*delta;
|
||||||
|
if (text2Offset < - Math.abs((text2Width - clipBounds.getWidth())) - 50) {
|
||||||
|
text1Offset = clipBounds.getWidth();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void act(float delta) {
|
public void act(float delta) {
|
||||||
setSize(getWidth(), textHeight + 4);
|
|
||||||
clipBounds.setSize(getWidth()-2, getHeight()*1.5f);
|
clipBounds.setSize(getWidth()-2, getHeight()*1.5f);
|
||||||
if (dupFirstText) {
|
if (dupFirstText) {
|
||||||
if (text1Width > clipBounds.getWidth()) {
|
if (text1Width > clipBounds.getWidth()) {
|
||||||
@ -130,26 +150,6 @@ public class ScrollText extends Widget {
|
|||||||
super.act(delta);
|
super.act(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scroll(float delta) {
|
|
||||||
if (text1Offset >= -text1Width) {
|
|
||||||
text1Offset -= 60*delta;
|
|
||||||
|
|
||||||
|
|
||||||
if ((text1Offset < - Math.abs((text1Width - clipBounds.getWidth())) - 50) || text2Offset != clipBounds.getWidth()) {
|
|
||||||
text2Offset -= 60*delta;
|
|
||||||
if (text2Offset <= -text2Width) {
|
|
||||||
text2Offset = clipBounds.getWidth();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
text2Offset -= 60*delta;
|
|
||||||
if (text2Offset < - Math.abs((text2Width - clipBounds.getWidth())) - 50) {
|
|
||||||
text1Offset = clipBounds.getWidth();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Batch batch, float parentAlpha) {
|
public void draw(Batch batch, float parentAlpha) {
|
||||||
if (background != null) {
|
if (background != null) {
|
||||||
|
@ -17,7 +17,6 @@ public class DesktopLauncher {
|
|||||||
config.samples = 2;
|
config.samples = 2;
|
||||||
config.width = 512;
|
config.width = 512;
|
||||||
config.height = 512;
|
config.height = 512;
|
||||||
System.setProperty("org.lwjgl.opengl.Window.undecorated", "true");
|
|
||||||
core = new RhythmBullet();
|
core = new RhythmBullet();
|
||||||
core.setup(new SplashScreen(), new DesktopAssetPack(), screenConfig);
|
core.setup(new SplashScreen(), new DesktopAssetPack(), screenConfig);
|
||||||
new LwjglApplication(core, config);
|
new LwjglApplication(core, config);
|
||||||
|
@ -32,7 +32,7 @@ public class PCMObtainer implements Observer, PCMSystem {
|
|||||||
private float[] frequencyBins = new float[windowSize / 2];
|
private float[] frequencyBins = new float[windowSize / 2];
|
||||||
private FloatFFT_1D fft = new FloatFFT_1D(windowSize);
|
private FloatFFT_1D fft = new FloatFFT_1D(windowSize);
|
||||||
private ShortBuffer playingBuffer;
|
private ShortBuffer playingBuffer;
|
||||||
private ShortBuffer compareBuffer;
|
private ShortBuffer intermediateBuffer;
|
||||||
private ShortBuffer buffer;
|
private ShortBuffer buffer;
|
||||||
private int sourceID;
|
private int sourceID;
|
||||||
private int channelCount;
|
private int channelCount;
|
||||||
@ -50,7 +50,7 @@ public class PCMObtainer implements Observer, PCMSystem {
|
|||||||
bufferField.setAccessible(true);
|
bufferField.setAccessible(true);
|
||||||
buffer = ((ByteBuffer) bufferField.get(null)).asShortBuffer().asReadOnlyBuffer();
|
buffer = ((ByteBuffer) bufferField.get(null)).asShortBuffer().asReadOnlyBuffer();
|
||||||
playingBuffer = ShortBuffer.allocate(buffer.capacity());
|
playingBuffer = ShortBuffer.allocate(buffer.capacity());
|
||||||
compareBuffer = ShortBuffer.allocate(buffer.capacity());
|
intermediateBuffer = ShortBuffer.allocate(buffer.capacity());
|
||||||
} catch (IllegalArgumentException | SecurityException | ReflectionException e) {
|
} catch (IllegalArgumentException | SecurityException | ReflectionException e) {
|
||||||
Gdx.app.debug("Visualizer reflection", "Failed attempt at retrieving tempBuffer field.", e);
|
Gdx.app.debug("Visualizer reflection", "Failed attempt at retrieving tempBuffer field.", e);
|
||||||
Gdx.app.exit();
|
Gdx.app.exit();
|
||||||
@ -79,13 +79,13 @@ public class PCMObtainer implements Observer, PCMSystem {
|
|||||||
|
|
||||||
// Begin comparison
|
// Begin comparison
|
||||||
buffer.rewind();
|
buffer.rewind();
|
||||||
if (compareBuffer.compareTo(buffer) != 0) {
|
if (intermediateBuffer.compareTo(buffer) != 0) {
|
||||||
bufferChanged();
|
bufferChanged();
|
||||||
|
|
||||||
// Begin copying current buffer to the comparison buffer
|
// Begin copying current buffer to the comparison buffer
|
||||||
compareBuffer.clear();
|
intermediateBuffer.clear();
|
||||||
compareBuffer.put(buffer);
|
intermediateBuffer.put(buffer);
|
||||||
compareBuffer.flip();
|
intermediateBuffer.flip();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset buffer to proper position.
|
// Reset buffer to proper position.
|
||||||
@ -94,7 +94,7 @@ public class PCMObtainer implements Observer, PCMSystem {
|
|||||||
|
|
||||||
private void bufferChanged() {
|
private void bufferChanged() {
|
||||||
playingBuffer.position(0);
|
playingBuffer.position(0);
|
||||||
playingBuffer.put(compareBuffer);
|
playingBuffer.put(intermediateBuffer);
|
||||||
|
|
||||||
synchronizeBufferWithPlayback();
|
synchronizeBufferWithPlayback();
|
||||||
}
|
}
|
||||||
@ -158,7 +158,6 @@ public class PCMObtainer implements Observer, PCMSystem {
|
|||||||
private volatile boolean run = true;
|
private volatile boolean run = true;
|
||||||
private long timeOfLastRead;
|
private long timeOfLastRead;
|
||||||
private long waitTime;
|
private long waitTime;
|
||||||
private boolean read = true;
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (run) {
|
while (run) {
|
||||||
@ -167,12 +166,11 @@ public class PCMObtainer implements Observer, PCMSystem {
|
|||||||
timeOfLastRead = TimeUtils.millis();
|
timeOfLastRead = TimeUtils.millis();
|
||||||
|
|
||||||
//calculate current pcm data and notify that there is new data
|
//calculate current pcm data and notify that there is new data
|
||||||
if (read) {
|
|
||||||
calcPCMData();
|
calcPCMData();
|
||||||
fft.realForward(PCM);
|
fft.realForward(PCM);
|
||||||
updated = true;
|
updated = true;
|
||||||
windowsRead++;
|
windowsRead++;
|
||||||
}
|
|
||||||
//contemplate synchronization
|
//contemplate synchronization
|
||||||
try {
|
try {
|
||||||
currentPlaybackWindow = MathUtils.round((mc.getCurrentPosition() * sampleRate) / windowSize);
|
currentPlaybackWindow = MathUtils.round((mc.getCurrentPosition() * sampleRate) / windowSize);
|
||||||
@ -182,9 +180,8 @@ public class PCMObtainer implements Observer, PCMSystem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (windowsRead != currentPlaybackWindow) {
|
if (windowsRead != currentPlaybackWindow) {
|
||||||
read = synchronizeBufferWithPlayback();
|
synchronizeBufferWithPlayback();
|
||||||
}
|
}
|
||||||
|
|
||||||
//wait for a bit before reading again depending on the speed at which the system does playback.
|
//wait for a bit before reading again depending on the speed at which the system does playback.
|
||||||
waitTime = Math.max(0, millisPerWindow - TimeUtils.timeSinceMillis(timeOfLastRead));
|
waitTime = Math.max(0, millisPerWindow - TimeUtils.timeSinceMillis(timeOfLastRead));
|
||||||
try {
|
try {
|
||||||
@ -203,6 +200,7 @@ public class PCMObtainer implements Observer, PCMSystem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Gdx.app.debug(thread.getName(), "stopped");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
@ -218,7 +216,6 @@ public class PCMObtainer implements Observer, PCMSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
Gdx.app.debug("PCMObtainer", "stopping " + thread.getName());
|
|
||||||
run = false;
|
run = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,6 @@ public class MusicControls extends HorizontalGroup {
|
|||||||
addActor(shuffle);
|
addActor(shuffle);
|
||||||
space(15);
|
space(15);
|
||||||
|
|
||||||
invalidate();
|
setSize(getMinWidth(), getMinHeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,12 +88,12 @@ public class MainPage extends Page implements Observer {
|
|||||||
menuTable.add(quitButton).fillX();
|
menuTable.add(quitButton).fillX();
|
||||||
|
|
||||||
musicControls = new MusicControls(skin, mc);
|
musicControls = new MusicControls(skin, mc);
|
||||||
musicControls.setPosition((getWidth()-musicControls.getMinWidth() - 20f), getHeight()-musicControls.getMinHeight()-20f);
|
musicControls.setPosition((getWidth()-musicControls.getWidth() - 15f), 15f);
|
||||||
addActor(musicControls);
|
addActor(musicControls);
|
||||||
|
|
||||||
scrollText = new ScrollText("...", "...", skin, false, true);
|
scrollText = new ScrollText("...", "...", skin, false, true);
|
||||||
scrollText.setWidth(0.5f*getWidth());
|
scrollText.setWidth(0.5f*getWidth());
|
||||||
scrollText.setPosition(15, getHeight() - scrollText.getHeight()-25f);
|
scrollText.setPosition(15, getHeight() - scrollText.getHeight()-30f);
|
||||||
addActor(scrollText);
|
addActor(scrollText);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user