From d26cef0cb1ede4f1dda6ba8b6eb4d6b480345e11 Mon Sep 17 00:00:00 2001 From: Recrown Date: Tue, 12 Sep 2017 16:12:34 -0500 Subject: [PATCH] added actor version of visualizer --- .../audio/visualizer/BasicVisualizer.java | 28 ++++++ .../audio/visualizer/VisualizerCore.java | 22 +++-- .../rhythmbullet/screens/PreGameScreen.java | 2 +- .../ui/components/Visualizer.java | 89 ++++++++++++++++++- .../rhythmbullet/ui/pages/MainPage.java | 9 +- 5 files changed, 135 insertions(+), 15 deletions(-) diff --git a/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java b/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java index 691caaa..cc6ee86 100755 --- a/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java +++ b/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java @@ -107,4 +107,32 @@ public class BasicVisualizer extends VisualizerCore { bars[i].setPosition(xPos + barSpace*angleRad.x, yPos + barSpace*angleRad.y); } } + + @Override + public void setHeight(int height) { + updatePositionInfo(); + super.setHeight(height); + } + + @Override + public void setWidth(int width) { + updatePositionInfo(); + super.setWidth(width); + } + + @Override + public void setxPos(int xPos) { + updatePositionInfo(); + super.setxPos(xPos); + } + + @Override + public void setyPos(int yPos) { + updatePositionInfo(); + super.setyPos(yPos); + } + + public void setRotation(float rotation) { + this.rotation = rotation; + } } diff --git a/core/src/zero1hd/rhythmbullet/audio/visualizer/VisualizerCore.java b/core/src/zero1hd/rhythmbullet/audio/visualizer/VisualizerCore.java index 9c98041..6883805 100755 --- a/core/src/zero1hd/rhythmbullet/audio/visualizer/VisualizerCore.java +++ b/core/src/zero1hd/rhythmbullet/audio/visualizer/VisualizerCore.java @@ -21,15 +21,11 @@ public class VisualizerCore implements Disposable { this.yPos = y; } - public void update() { + public void calculate() { if (cmi != null) { if (cmi.getPlaybackIndexPosition() > cmi.getCurrentReadWindowIndex()) { cmi.readSamples(audioPCM); fft.realForward(audioPCM); -// Gdx.app.debug("Visualizer", "Proper read"); - } else { -// System.out.println(audioPCM[16]); -// Gdx.app.debug("Visualizer", "Not reading so music can catch up."); } } } @@ -47,4 +43,20 @@ public class VisualizerCore implements Disposable { public void dispose() { } + public void setxPos(int xPos) { + this.xPos = xPos; + } + + public void setyPos(int yPos) { + this.yPos = yPos; + } + + public void setWidth(int width) { + this.width = width; + } + + public void setHeight(int height) { + this.height = height; + } + } diff --git a/core/src/zero1hd/rhythmbullet/screens/PreGameScreen.java b/core/src/zero1hd/rhythmbullet/screens/PreGameScreen.java index 29a0b6a..c824de6 100755 --- a/core/src/zero1hd/rhythmbullet/screens/PreGameScreen.java +++ b/core/src/zero1hd/rhythmbullet/screens/PreGameScreen.java @@ -35,7 +35,7 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, M @Override public void render(float delta) { - Gdx.gl.glClearColor(1f, 1f, 1f, 1f); + Gdx.gl.glClearColor(0f, 0f, 0f, 1f); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); stage.getViewport().apply(); diff --git a/core/src/zero1hd/rhythmbullet/ui/components/Visualizer.java b/core/src/zero1hd/rhythmbullet/ui/components/Visualizer.java index 45837e2..6044222 100755 --- a/core/src/zero1hd/rhythmbullet/ui/components/Visualizer.java +++ b/core/src/zero1hd/rhythmbullet/ui/components/Visualizer.java @@ -1,13 +1,94 @@ package zero1hd.rhythmbullet.ui.components; -import com.badlogic.gdx.scenes.scene2d.Actor; +import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.scenes.scene2d.ui.Widget; +import zero1hd.rhythmbullet.audio.MusicDataPack; import zero1hd.rhythmbullet.audio.visualizer.BasicVisualizer; -public class Visualizer extends Actor { - private BasicVisualizer hVis; +public class Visualizer extends Widget { + private BasicVisualizer vis; + private Vector2 coords; + private Vector2 size; public Visualizer() { - hVis = new BasicVisualizer(); + vis = new BasicVisualizer(); + coords = new Vector2(); + size = new Vector2(); + } + + @Override + public void draw(Batch batch, float parentAlpha) { + vis.render(batch, parentAlpha); + super.draw(batch, parentAlpha); + } + + @Override + public void act(float delta) { + vis.calculate(); + super.act(delta); + } + + + public void setMDP(MusicDataPack mdp) { + vis.setMDP(mdp); + } + + @Override + public void setX(float x) { + coords.set(getX(), getY()); + getStage().stageToScreenCoordinates(coords); + vis.setxPos((int) coords.x); + super.setX(x); + } + + @Override + public void setY(float y) { + coords.set(getX(), getY()); + getStage().stageToScreenCoordinates(coords); + vis.setyPos((int) coords.y); + super.setY(y); + } + + @Override + public void setWidth(float width) { + size.set(getWidth(), getHeight()); + getStage().stageToScreenCoordinates(size); + vis.setWidth((int) size.x); + super.setWidth(width); + } + + @Override + public void setHeight(float height) { + size.set(getWidth(), getHeight()); + getStage().stageToScreenCoordinates(size); + vis.setWidth((int) size.y); + super.setHeight(height); + } + + @Override + public void setSize(float width, float height) { + setHeight(height); + setWidth(width); + } + + @Override + public void setPosition(float x, float y) { + setX(x); + setY(y); + super.setPosition(x, y); + } + + @Override + public void setRotation(float degrees) { + vis.setRotation(degrees); + super.setRotation(degrees); + } + + @Override + public void layout() { + vis.updatePositionInfo(); + super.layout(); } } diff --git a/core/src/zero1hd/rhythmbullet/ui/pages/MainPage.java b/core/src/zero1hd/rhythmbullet/ui/pages/MainPage.java index 075f1e8..32feb7c 100755 --- a/core/src/zero1hd/rhythmbullet/ui/pages/MainPage.java +++ b/core/src/zero1hd/rhythmbullet/ui/pages/MainPage.java @@ -20,6 +20,7 @@ import zero1hd.rhythmbullet.audio.SongController; import zero1hd.rhythmbullet.audio.visualizer.BasicVisualizer; import zero1hd.rhythmbullet.events.OnDifferentSongListener; import zero1hd.rhythmbullet.screens.PreGameScreen; +import zero1hd.rhythmbullet.ui.components.Visualizer; public class MainPage extends Page implements OnDifferentSongListener { private Image title; @@ -32,14 +33,14 @@ public class MainPage extends Page implements OnDifferentSongListener { private WidgetGroup playButton; private SongController sc; - private BasicVisualizer hvisual; + private Visualizer hvisual; public MainPage(RhythmBullet core, Vector3 targetPosition, SongController sc) { - hvisual = new BasicVisualizer(); + hvisual = new Visualizer(); this.sc = sc; sc.addOnDifferentSongListener(this); hvisual.setMDP(sc.getCurrentSong()); - + addActor(hvisual); title = new Image(core.getAssetManager().get("title.png", Texture.class)); title.setPosition(10, getHeight() - title.getHeight()-30); addActor(title); @@ -124,8 +125,6 @@ public class MainPage extends Page implements OnDifferentSongListener { @Override public void draw(Batch batch, float parentAlpha) { - hvisual.update(); - hvisual.render(batch, parentAlpha); super.draw(batch, parentAlpha); }