visualizer now more flexible, leading to new visualizer design for main

page
This commit is contained in:
Harrison Deng 2018-08-17 02:37:17 -05:00
parent 1e98d34035
commit 89e3abed63
2 changed files with 19 additions and 21 deletions

View File

@ -21,24 +21,25 @@ public class DoubleHorizontalVisualizer implements Disposable {
private int binsPerBar;
private float offset;
private int boundaryThickness;
private float baseSensitivity;
private float targetDelta;
private float spacePercentage = 0.85f;
private int barCount = 80;
private float normalFactor = 0.8f;
private float spacePercentage = 0.7f;
private int barCount = 90;
private float barChangeRate = 14f;
private int smoothRange = 1;
private int binsToInclude = 160;
private Color color = new Color(1f, 1f, 1f, 0.85f);
private int binsToInclude = 180;
private Color color = new Color(0.5f, 0.6f, 0.8f, 0.46f);
/**
*
* @param barCount amount of bars this visualizer should have.
* @param width the width of the visualizer.
* @param spacePercentage the percentage of a bar that should be space.
*/
public DoubleHorizontalVisualizer(int width, int height, int targetFPS, MusicController musicController, PCMSystem PCMSystem) {
public DoubleHorizontalVisualizer(int width, int height, float baseSensitivity, int boundaryThickness, int targetFPS, MusicController musicController, PCMSystem PCMSystem) {
this.barWidth = width/barCount;
this.spaceBetweenBars = MathUtils.round(barWidth * spacePercentage);
this.barWidth -= spaceBetweenBars;
this.baseSensitivity = baseSensitivity;
pcm = PCMSystem;
binsPerBar = (binsToInclude/barCount);
this.width = width;
@ -52,17 +53,13 @@ public class DoubleHorizontalVisualizer implements Disposable {
}
public void act(float delta) {
if (color.r > 1f) color.r = 0f;
if (color.g > 1f) color.g = 0f;
if (color.b > 1f) color.b = 0f;
if (color.a > 1f) color.a = 0.2f;
float[] freqBins = pcm.getFrequencyBins();
for (int bar = 0; bar < amplitudes.length; bar++) {
float normalizedAmplitude = 0;
for (int freq = bar*binsPerBar; freq < (bar*binsPerBar) + binsPerBar; freq++) {
normalizedAmplitude += Math.abs(freqBins[freq]);
}
amplitudes[bar] += normalizedAmplitude * normalFactor * (height/100f);
amplitudes[bar] += normalizedAmplitude * baseSensitivity;
amplitudes[bar] /= binsPerBar;
}
for (int bar = 0; bar < barHeights.length; bar++) {
@ -88,7 +85,6 @@ public class DoubleHorizontalVisualizer implements Disposable {
barHeights[bar] += pixelsMoved;
if (barHeights[bar] < 0) barHeights[bar] = 0;
if (barHeights[bar] > height) barHeights[bar] = height;
}
}
@ -99,8 +95,10 @@ public class DoubleHorizontalVisualizer implements Disposable {
shapeRenderer.begin(ShapeType.Filled);
shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
shapeRenderer.setTransformMatrix(batch.getTransformMatrix());
shapeRenderer.rect(x, y, width, boundaryThickness);
shapeRenderer.rect(x, y+height, width, -boundaryThickness);
if (boundaryThickness > 0) {
shapeRenderer.rect(x, y, width, boundaryThickness);
shapeRenderer.rect(x, y+height, width, -boundaryThickness);
}
for (int bar = 0; bar < barCount; bar++) {
shapeRenderer.setColor(color);

View File

@ -46,13 +46,13 @@ public class MainPage extends Page implements Observer {
this.mc = musicController;
this.mc.addObserver(this);
dhv = new DoubleHorizontalVisualizer((int) getWidth(), (int) (getHeight()*0.3), screenConfiguration.getFramesPerSecond(), mc, new PCMObtainer(mc));
dhv = new DoubleHorizontalVisualizer((int) getWidth(), (int) 0, 2.5f, 0, screenConfiguration.getFramesPerSecond(), mc, new PCMObtainer(mc));
dhv.setPosition(0, (int) ((getHeight() - dhv.getHeight())/2f));
title = new Image(assetManager.get("title.png", Texture.class));
title.setScale((dhv.getHeight() - 14)/title.getHeight());
if (title.getWidth()*title.getScaleX() > dhv.getWidth() - 30) {
title.setScale((dhv.getWidth() - 30)/title.getWidth()*getScaleX());
title.setScale((getHeight()/3f - 14)/title.getHeight());
if (title.getWidth()*title.getScaleX() > getWidth() - 30) {
title.setScale((getWidth() - 30)/title.getWidth()*getScaleX());
}
title.setPosition((getWidth()-title.getWidth()*title.getScaleX())/2f, (getHeight()-title.getHeight()*title.getScaleY())/2f);
addActor(title);
@ -62,7 +62,7 @@ public class MainPage extends Page implements Observer {
addActor(versionLabel);
menuTable = new Table();
menuTable.setSize(getWidth(), dhv.getY());
menuTable.setSize(getWidth(), title.getY());
menuTable.align(Align.center);
menuTable.defaults().space(10f);
addActor(menuTable);
@ -100,14 +100,14 @@ public class MainPage extends Page implements Observer {
@Override
public void act(float delta) {
super.act(delta);
dhv.act(delta);
super.act(delta);
}
@Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
dhv.draw(batch, parentAlpha);
super.draw(batch, parentAlpha);
}
@Override