made visualizer horizontal, smoothed out bar movement

This commit is contained in:
Harrison Deng 2017-10-03 23:30:09 -05:00
parent 411ac59f6f
commit 354efc647a
5 changed files with 41 additions and 32 deletions

View File

@ -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);

View File

@ -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() {
}

View File

@ -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"),

View File

@ -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

View File

@ -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());