From 354efc647afd04b192da46bb35f2fa3152b44cd3 Mon Sep 17 00:00:00 2001 From: Recrown Date: Tue, 3 Oct 2017 23:30:09 -0500 Subject: [PATCH] made visualizer horizontal, smoothed out bar movement --- .../audio/visualizer/BasicVisualizer.java | 30 ++++++++-------- .../audio/visualizer/VisualizerCore.java | 5 ++- .../graphics/meshes/TitleBarMesh.java | 2 +- .../ui/components/TitleBarVisualizer.java | 35 +++++++++++-------- .../graphics/ui/components/Visualizer.java | 1 + 5 files changed, 41 insertions(+), 32 deletions(-) diff --git a/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java b/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java index fea37d2..096bc71 100755 --- a/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java +++ b/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java @@ -32,16 +32,15 @@ public class BasicVisualizer extends VisualizerCore { public BasicVisualizer() { super(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()/2, 0, 0); mirrors = new Array<>(); - barHeightMultiplier = Gdx.graphics.getHeight()*0.01f; + barHeightMultiplier = Gdx.graphics.getHeight()*0.0075f; pixmap = new Pixmap(2, 2, Format.RGBA8888); pixmap.setColor(Color.WHITE); pixmap.fill(); - barCount = 70; + barCount = 65; smoothRange = 4; angleRot = new Vector2(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation)); textures = new Texture[barCount]; bars = new Sprite[barCount]; - spaceBetweenBars = 4; for (int i = 0; i < textures.length; i++) { textures[i] = new Texture(pixmap); @@ -55,18 +54,6 @@ public class BasicVisualizer extends VisualizerCore { @Override public void render(Batch batch, float parentAlpha) { if (mm != null) { - //Averaging bins together - for (int i = 0; i < barCount; i++) { - bars[i].setSize(barWidth, 0); - float barHeight = 0; - for (int j = 0; j < binsPerBar; j++) { - barHeight += Math.abs(audioPCM[j+i*binsPerBar]); - } - barHeight /= binsPerBar; - barHeight *= barHeightMultiplier; - bars[i].setSize(barWidth, barHeight); - } - //Drawing... for (int i = 0; i < barCount; i++) { int avg = 0; @@ -90,6 +77,19 @@ public class BasicVisualizer extends VisualizerCore { super.render(batch, parentAlpha); } + public void modify(float delta) { + //Averaging bins together + for (int i = 0; i < barCount; i++) { + float barHeight = 0; + for (int j = 0; j < binsPerBar; j++) { + barHeight += Math.abs(audioPCM[j+i*binsPerBar]); + } + barHeight /= binsPerBar; + barHeight *= barHeightMultiplier; + bars[i].setSize(barWidth, bars[i].getHeight() < barHeight ? barHeight : bars[i].getHeight() - 1800f*delta); + } + } + @Override public void setMM(MusicManager mdp) { super.setMM(mdp); diff --git a/core/src/zero1hd/rhythmbullet/audio/visualizer/VisualizerCore.java b/core/src/zero1hd/rhythmbullet/audio/visualizer/VisualizerCore.java index fa16a11..b110988 100755 --- a/core/src/zero1hd/rhythmbullet/audio/visualizer/VisualizerCore.java +++ b/core/src/zero1hd/rhythmbullet/audio/visualizer/VisualizerCore.java @@ -41,7 +41,10 @@ public class VisualizerCore implements Disposable { public void render(Batch batch, float parentAlpha) { } - + + public void modify(float delta) { + } + @Override public void dispose() { } diff --git a/core/src/zero1hd/rhythmbullet/graphics/meshes/TitleBarMesh.java b/core/src/zero1hd/rhythmbullet/graphics/meshes/TitleBarMesh.java index 1a28a31..4884590 100755 --- a/core/src/zero1hd/rhythmbullet/graphics/meshes/TitleBarMesh.java +++ b/core/src/zero1hd/rhythmbullet/graphics/meshes/TitleBarMesh.java @@ -25,7 +25,7 @@ public class TitleBarMesh implements Disposable { private float[] verts = new float[MAX_VERTS * TOTAL_VARS]; - +@Deprecated public TitleBarMesh() { shader = new ShaderProgram(Gdx.files.internal("shaders/mesh.vsh"), Gdx.files.internal("shaders/mesh.fsh")); mesh = new Mesh(true, MAX_VERTS, 0, new VertexAttribute(Usage.Position, POSITION_VARS, "a_position"), diff --git a/core/src/zero1hd/rhythmbullet/graphics/ui/components/TitleBarVisualizer.java b/core/src/zero1hd/rhythmbullet/graphics/ui/components/TitleBarVisualizer.java index 117a7b5..4e3392e 100755 --- a/core/src/zero1hd/rhythmbullet/graphics/ui/components/TitleBarVisualizer.java +++ b/core/src/zero1hd/rhythmbullet/graphics/ui/components/TitleBarVisualizer.java @@ -4,9 +4,13 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.assets.AssetManager; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.Pixmap; +import com.badlogic.gdx.graphics.Pixmap.Format; +import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.scenes.scene2d.Group; +import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.utils.Disposable; import zero1hd.rhythmbullet.audio.visualizer.MirrorVisualizer; @@ -15,29 +19,33 @@ import zero1hd.rhythmbullet.graphics.meshes.TitleBarMesh; public class TitleBarVisualizer extends Group implements Disposable { private Visualizer visual; private MirrorVisualizer visual2; - private TitleBarMesh background; - + private Texture bgTexture; + private Image bg; public TitleBarVisualizer(AssetManager assets, OrthographicCamera camera) { if (assets == null) throw new NullPointerException("TitleBarVisualizer requires assets manager... ITS NULL YOU FOOL"); visual = new Visualizer(); visual.getVis().setSpaceBetweenBars(visual.getVis().getBarWidth()-3); addActor(visual); - background = new TitleBarMesh(); - background.setHeight(MathUtils.round(Gdx.graphics.getHeight()*0.3f)); - - setRotation((float) (MathUtils.radiansToDegrees*Math.atan2(Gdx.graphics.getHeight()-background.getHeight(), Gdx.graphics.getWidth()))); - setSize((float) Math.sqrt(Gdx.graphics.getWidth()*Gdx.graphics.getWidth() + Gdx.graphics.getHeight()*Gdx.graphics.getHeight()), ((float) background.getHeight())*MathUtils.sinDeg(90f-getRotation())); - - background.setCam(camera); + setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()*0.3f); + setPosition(0, (Gdx.graphics.getHeight()-getHeight())/2f); visual.setWidth(getWidth()); - visual.setHeight(background.getHeight()); + visual.setHeight(getHeight()); visual.getVis().flip(); visual.getVis().reverse(); visual2 = new MirrorVisualizer(); visual.getVis().addMirrorVisualizer(visual2); - visual2.setRotation(visual.getRotation()); visual2.setyPos(MathUtils.round(getHeight())); + + Pixmap pixmap = new Pixmap(2, 2, Format.RGBA8888); + pixmap.setColor(Color.WHITE); + pixmap.fill(); + bgTexture = new Texture(pixmap); + pixmap.dispose(); + + bg = new Image(bgTexture); + bg.setSize(getWidth(), getHeight()); + addActor(bg); } @Override public void act(float delta) { @@ -46,9 +54,6 @@ public class TitleBarVisualizer extends Group implements Disposable { @Override public void draw(Batch batch, float parentAlpha) { - batch.end(); - background.draw(); - batch.begin(); super.draw(batch, parentAlpha); } @@ -58,7 +63,7 @@ public class TitleBarVisualizer extends Group implements Disposable { @Override public void dispose() { - background.dispose(); + bgTexture.dispose(); } @Override diff --git a/core/src/zero1hd/rhythmbullet/graphics/ui/components/Visualizer.java b/core/src/zero1hd/rhythmbullet/graphics/ui/components/Visualizer.java index e82a5c7..23ede89 100755 --- a/core/src/zero1hd/rhythmbullet/graphics/ui/components/Visualizer.java +++ b/core/src/zero1hd/rhythmbullet/graphics/ui/components/Visualizer.java @@ -22,6 +22,7 @@ public class Visualizer extends Widget { @Override public void act(float delta) { + vis.modify(delta); vis.setHeight(getHeight()); vis.setWidth(getWidth()); vis.setxPos(getX());