made visualizer horizontal, smoothed out bar movement
This commit is contained in:
parent
411ac59f6f
commit
354efc647a
@ -32,16 +32,15 @@ public class BasicVisualizer extends VisualizerCore {
|
|||||||
public BasicVisualizer() {
|
public BasicVisualizer() {
|
||||||
super(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()/2, 0, 0);
|
super(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()/2, 0, 0);
|
||||||
mirrors = new Array<>();
|
mirrors = new Array<>();
|
||||||
barHeightMultiplier = Gdx.graphics.getHeight()*0.01f;
|
barHeightMultiplier = Gdx.graphics.getHeight()*0.0075f;
|
||||||
pixmap = new Pixmap(2, 2, Format.RGBA8888);
|
pixmap = new Pixmap(2, 2, Format.RGBA8888);
|
||||||
pixmap.setColor(Color.WHITE);
|
pixmap.setColor(Color.WHITE);
|
||||||
pixmap.fill();
|
pixmap.fill();
|
||||||
barCount = 70;
|
barCount = 65;
|
||||||
smoothRange = 4;
|
smoothRange = 4;
|
||||||
angleRot = new Vector2(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation));
|
angleRot = new Vector2(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation));
|
||||||
textures = new Texture[barCount];
|
textures = new Texture[barCount];
|
||||||
bars = new Sprite[barCount];
|
bars = new Sprite[barCount];
|
||||||
spaceBetweenBars = 4;
|
|
||||||
|
|
||||||
for (int i = 0; i < textures.length; i++) {
|
for (int i = 0; i < textures.length; i++) {
|
||||||
textures[i] = new Texture(pixmap);
|
textures[i] = new Texture(pixmap);
|
||||||
@ -55,18 +54,6 @@ public class BasicVisualizer extends VisualizerCore {
|
|||||||
@Override
|
@Override
|
||||||
public void render(Batch batch, float parentAlpha) {
|
public void render(Batch batch, float parentAlpha) {
|
||||||
if (mm != null) {
|
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...
|
//Drawing...
|
||||||
for (int i = 0; i < barCount; i++) {
|
for (int i = 0; i < barCount; i++) {
|
||||||
int avg = 0;
|
int avg = 0;
|
||||||
@ -90,6 +77,19 @@ public class BasicVisualizer extends VisualizerCore {
|
|||||||
super.render(batch, parentAlpha);
|
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
|
@Override
|
||||||
public void setMM(MusicManager mdp) {
|
public void setMM(MusicManager mdp) {
|
||||||
super.setMM(mdp);
|
super.setMM(mdp);
|
||||||
|
@ -41,7 +41,10 @@ public class VisualizerCore implements Disposable {
|
|||||||
|
|
||||||
public void render(Batch batch, float parentAlpha) {
|
public void render(Batch batch, float parentAlpha) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void modify(float delta) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ public class TitleBarMesh implements Disposable {
|
|||||||
|
|
||||||
private float[] verts = new float[MAX_VERTS * TOTAL_VARS];
|
private float[] verts = new float[MAX_VERTS * TOTAL_VARS];
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public TitleBarMesh() {
|
public TitleBarMesh() {
|
||||||
shader = new ShaderProgram(Gdx.files.internal("shaders/mesh.vsh"), Gdx.files.internal("shaders/mesh.fsh"));
|
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"),
|
mesh = new Mesh(true, MAX_VERTS, 0, new VertexAttribute(Usage.Position, POSITION_VARS, "a_position"),
|
||||||
|
@ -4,9 +4,13 @@ import com.badlogic.gdx.Gdx;
|
|||||||
import com.badlogic.gdx.assets.AssetManager;
|
import com.badlogic.gdx.assets.AssetManager;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
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.graphics.g2d.Batch;
|
||||||
import com.badlogic.gdx.math.MathUtils;
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
import com.badlogic.gdx.scenes.scene2d.Group;
|
import com.badlogic.gdx.scenes.scene2d.Group;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||||
import com.badlogic.gdx.utils.Disposable;
|
import com.badlogic.gdx.utils.Disposable;
|
||||||
|
|
||||||
import zero1hd.rhythmbullet.audio.visualizer.MirrorVisualizer;
|
import zero1hd.rhythmbullet.audio.visualizer.MirrorVisualizer;
|
||||||
@ -15,29 +19,33 @@ import zero1hd.rhythmbullet.graphics.meshes.TitleBarMesh;
|
|||||||
public class TitleBarVisualizer extends Group implements Disposable {
|
public class TitleBarVisualizer extends Group implements Disposable {
|
||||||
private Visualizer visual;
|
private Visualizer visual;
|
||||||
private MirrorVisualizer visual2;
|
private MirrorVisualizer visual2;
|
||||||
private TitleBarMesh background;
|
private Texture bgTexture;
|
||||||
|
private Image bg;
|
||||||
public TitleBarVisualizer(AssetManager assets, OrthographicCamera camera) {
|
public TitleBarVisualizer(AssetManager assets, OrthographicCamera camera) {
|
||||||
if (assets == null) throw new NullPointerException("TitleBarVisualizer requires assets manager... ITS NULL YOU FOOL");
|
if (assets == null) throw new NullPointerException("TitleBarVisualizer requires assets manager... ITS NULL YOU FOOL");
|
||||||
visual = new Visualizer();
|
visual = new Visualizer();
|
||||||
visual.getVis().setSpaceBetweenBars(visual.getVis().getBarWidth()-3);
|
visual.getVis().setSpaceBetweenBars(visual.getVis().getBarWidth()-3);
|
||||||
addActor(visual);
|
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.setWidth(getWidth());
|
||||||
visual.setHeight(background.getHeight());
|
visual.setHeight(getHeight());
|
||||||
visual.getVis().flip();
|
visual.getVis().flip();
|
||||||
visual.getVis().reverse();
|
visual.getVis().reverse();
|
||||||
visual2 = new MirrorVisualizer();
|
visual2 = new MirrorVisualizer();
|
||||||
visual.getVis().addMirrorVisualizer(visual2);
|
visual.getVis().addMirrorVisualizer(visual2);
|
||||||
visual2.setRotation(visual.getRotation());
|
|
||||||
visual2.setyPos(MathUtils.round(getHeight()));
|
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
|
@Override
|
||||||
public void act(float delta) {
|
public void act(float delta) {
|
||||||
@ -46,9 +54,6 @@ public class TitleBarVisualizer extends Group implements Disposable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Batch batch, float parentAlpha) {
|
public void draw(Batch batch, float parentAlpha) {
|
||||||
batch.end();
|
|
||||||
background.draw();
|
|
||||||
batch.begin();
|
|
||||||
super.draw(batch, parentAlpha);
|
super.draw(batch, parentAlpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +63,7 @@ public class TitleBarVisualizer extends Group implements Disposable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
background.dispose();
|
bgTexture.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,6 +22,7 @@ public class Visualizer extends Widget {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void act(float delta) {
|
public void act(float delta) {
|
||||||
|
vis.modify(delta);
|
||||||
vis.setHeight(getHeight());
|
vis.setHeight(getHeight());
|
||||||
vis.setWidth(getWidth());
|
vis.setWidth(getWidth());
|
||||||
vis.setxPos(getX());
|
vis.setxPos(getX());
|
||||||
|
Loading…
Reference in New Issue
Block a user