From 89e3abed63eefb2f057e61cd93a5da547f95fbb5 Mon Sep 17 00:00:00 2001 From: Recrown Date: Fri, 17 Aug 2018 02:37:17 -0500 Subject: [PATCH] visualizer now more flexible, leading to new visualizer design for main page --- .../DoubleHorizontalVisualizer.java | 26 +++++++++---------- .../desktop/screens/main/MainPage.java | 14 +++++----- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/core/src/zero1hd/rhythmbullet/audio/visualizer/DoubleHorizontalVisualizer.java b/core/src/zero1hd/rhythmbullet/audio/visualizer/DoubleHorizontalVisualizer.java index bb3c4d5..ea65981 100755 --- a/core/src/zero1hd/rhythmbullet/audio/visualizer/DoubleHorizontalVisualizer.java +++ b/core/src/zero1hd/rhythmbullet/audio/visualizer/DoubleHorizontalVisualizer.java @@ -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); diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainPage.java b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainPage.java index 0333c93..9e73461 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainPage.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainPage.java @@ -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