From 56d0ac2f51f4fe632411847259c20ee749d4676b Mon Sep 17 00:00:00 2001 From: Recrown Date: Mon, 6 Aug 2018 15:54:35 -0500 Subject: [PATCH] visualizer bars properly rendered; removed overlapping play calls; + minor fixes and changes --- .../rhythmbullet/audio/MusicController.java | 5 +---- .../zero1hd/rhythmbullet/audio/MusicList.java | 19 +++++++++++++++---- .../DoubleHorizontalVisualizer.java | 15 ++++++++++----- .../desktop/audio/visualizer/PCMObtainer.java | 7 ++++--- .../graphics/ui/components/MusicControls.java | 9 ++++++--- .../desktop/screens/main/MainPage.java | 4 ++-- 6 files changed, 38 insertions(+), 21 deletions(-) diff --git a/core/src/zero1hd/rhythmbullet/audio/MusicController.java b/core/src/zero1hd/rhythmbullet/audio/MusicController.java index f30d73a..cf2a85a 100755 --- a/core/src/zero1hd/rhythmbullet/audio/MusicController.java +++ b/core/src/zero1hd/rhythmbullet/audio/MusicController.java @@ -45,7 +45,7 @@ public class MusicController extends Observable implements OnCompletionListener, */ public void play() { if (music != null) { - Gdx.app.debug("MusicListController", "Playing from MLC."); + Gdx.app.debug("MusicController", "Playing from MLC."); music.play(); music.setVolume(prefs.getFloat("music vol", 1f)); notifyObservers(states.PLAYING); @@ -193,9 +193,6 @@ public class MusicController extends Observable implements OnCompletionListener, public void update(Observable o, Object arg) { if (o == musicList) { loadMusic(); - if (autoPlay) { - play(); - } } } diff --git a/core/src/zero1hd/rhythmbullet/audio/MusicList.java b/core/src/zero1hd/rhythmbullet/audio/MusicList.java index fa5271e..3c600c5 100755 --- a/core/src/zero1hd/rhythmbullet/audio/MusicList.java +++ b/core/src/zero1hd/rhythmbullet/audio/MusicList.java @@ -2,6 +2,8 @@ package zero1hd.rhythmbullet.audio; import java.util.Observable; +import javax.activity.InvalidActivityException; + import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.utils.Array; @@ -69,13 +71,19 @@ public class MusicList extends Observable { } public AudioProcessor newAudioProcessorFromIndex(int index) { - if (!searched) Gdx.app.debug("SongList", "Warning, this list hasn't even searched yet..."); + if (!searched) { + Gdx.app.debug("MusicList", "Warning, this list has not completed it's search..."); + Thread.dumpStack(); + } return newAudioProcessor(musicList.get(index)); } public FileHandle getSongFileHandleFromIndex(int index) { - if (!searched) Gdx.app.debug("SongList", "Warning, this list hasn't even searched yet..."); + if (!searched) { + Gdx.app.debug("MusicList", "Warning, this list has not completed it's search..."); + Thread.dumpStack(); + } return musicList.get(index); } @@ -115,8 +123,11 @@ public class MusicList extends Observable { if (work) { musicList = obtainedAudioFiles; musicList.add(Gdx.files.internal("music/Alan Walker - Spectre.mp3")); - notifyObservers(); - searched = true; + if (work) { + searched = true; + Gdx.app.debug("MusicList", "recursive async search completed."); + notifyObservers(); + } } } diff --git a/core/src/zero1hd/rhythmbullet/audio/visualizer/DoubleHorizontalVisualizer.java b/core/src/zero1hd/rhythmbullet/audio/visualizer/DoubleHorizontalVisualizer.java index 61d3228..b8175f9 100644 --- a/core/src/zero1hd/rhythmbullet/audio/visualizer/DoubleHorizontalVisualizer.java +++ b/core/src/zero1hd/rhythmbullet/audio/visualizer/DoubleHorizontalVisualizer.java @@ -69,15 +69,20 @@ public class DoubleHorizontalVisualizer { } public void draw(Batch batch, float parentAlpha) { + batch.end(); shapeRenderer.begin(ShapeType.Filled); - shapeRenderer.rect(x, y-2, width, y); - shapeRenderer.rect(x, y+height, width, y+height+2); - int beginX = x + spaceBetweenBars/2, beginY = y; + shapeRenderer.setColor(1f, 1f, 1f, 1f); + shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix()); + shapeRenderer.setTransformMatrix(batch.getTransformMatrix()); + shapeRenderer.rect(x, y, width, 2); + shapeRenderer.rect(x, y+height-2, width, 2); + int beginX = x + spaceBetweenBars/2, beginY = y; for (int bar = 0; bar < barCount; bar++) { - shapeRenderer.rect(beginX + spaceBetweenBars*bar, beginY+height, beginX+barWidth, beginY+barHeights[bar]+height); - shapeRenderer.rect(beginX + spaceBetweenBars*bar, beginY, beginX+barWidth, beginY+barHeights[barHeights.length - 1 - bar]); + shapeRenderer.rect(beginX + (spaceBetweenBars+barWidth)*bar, beginY+height, barWidth, barHeights[bar]); + shapeRenderer.rect(beginX + (spaceBetweenBars+barWidth)*bar, beginY-barHeights[barHeights.length - 1 - bar], barWidth, barHeights[barHeights.length - 1 - bar]); } shapeRenderer.end(); + batch.begin(); } public int getWidth() { diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/audio/visualizer/PCMObtainer.java b/desktop/src/zero1hd/rhythmbullet/desktop/audio/visualizer/PCMObtainer.java index 52746df..58bef8b 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/audio/visualizer/PCMObtainer.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/audio/visualizer/PCMObtainer.java @@ -112,6 +112,7 @@ public class PCMObtainer implements Observer, Disposable, PCMSystem { } private void setMusic() { + Gdx.app.debug("PCMObtainer", "music set."); try { Field sourceIDField = ClassReflection.getDeclaredField(OpenALMusic.class, "sourceID"); sourceIDField.setAccessible(true); @@ -155,7 +156,7 @@ public class PCMObtainer implements Observer, Disposable, PCMSystem { private class BufferStreamReadThread implements Runnable { private String name = "PCM-Audio-Processing"; private Thread thread; - private volatile boolean run; + private volatile boolean run = true; private boolean paused; private long timeOfLastRead; private int waitTime; @@ -212,9 +213,9 @@ public class PCMObtainer implements Observer, Disposable, PCMSystem { @Override public void update(Observable o, Object arg) { if (o == mc) { - if (arg.equals(mc.states.LOADED)) { + if (arg == mc.states.LOADED) { setMusic(); - } else if (arg.equals(mc.states.PLAYING)) { + } else if (arg == mc.states.PLAYING) { streamReadThread.start(); } } diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/MusicControls.java b/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/MusicControls.java index cedaa82..f8a248f 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/MusicControls.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/MusicControls.java @@ -1,11 +1,13 @@ package zero1hd.rhythmbullet.desktop.graphics.ui.components; import com.badlogic.gdx.scenes.scene2d.Actor; +import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.ui.CheckBox; import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup; import com.badlogic.gdx.scenes.scene2d.ui.ImageButton; import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; +import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import zero1hd.rhythmbullet.audio.MusicController; @@ -37,14 +39,15 @@ public class MusicControls extends HorizontalGroup { super.act(delta); } }; - play.addListener(new ChangeListener() { + play.addListener(new ClickListener() { @Override - public void changed(ChangeEvent event, Actor actor) { + public void clicked(InputEvent event, float x, float y) { if (play.isChecked()) { sc.play(); } else { sc.pause(); - } + } + super.clicked(event, x, y); } }); addActor(play); diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainPage.java b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainPage.java index dfcf23a..d1507a8 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainPage.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainPage.java @@ -99,13 +99,13 @@ public class MainPage extends Page implements Observer { @Override public void act(float delta) { -// dhv.act(delta); + dhv.act(delta); super.act(delta); } @Override public void draw(Batch batch, float parentAlpha) { -// dhv.draw(batch, parentAlpha); + dhv.draw(batch, parentAlpha); super.draw(batch, parentAlpha); }