From 373a524010194e58c426cee8397d8696dca40bed Mon Sep 17 00:00:00 2001 From: Recrown Date: Tue, 12 Sep 2017 19:48:51 -0500 Subject: [PATCH] fixed sync issue with songs (not sure what de-sync caused by as issue does not exist on other computer) --- .../rhythmbullet/audio/AudioAnalyzer.java | 4 +- .../rhythmbullet/audio/AudioDataPackage.java | 6 +- .../rhythmbullet/audio/Mp3AudioData.java | 51 ++++++++++++----- .../{MusicDataPack.java => MusicManager.java} | 29 +++++----- .../zero1hd/rhythmbullet/audio/SongList.java | 4 +- ...ontroller.java => SongListController.java} | 14 ++--- .../rhythmbullet/audio/WavAudioData.java | 57 +++++++++++++------ .../rhythmbullet/audio/map/GamePlayMap.java | 8 +-- .../audio/visualizer/BasicVisualizer.java | 8 +-- .../audio/visualizer/VisualizerCore.java | 24 ++++---- .../events/OnDifferentSongListener.java | 4 +- .../rhythmbullet/screens/GameScreen.java | 10 ++-- .../rhythmbullet/screens/MainMenu.java | 11 ++-- .../rhythmbullet/stages/CreativeHUD.java | 2 +- .../zero1hd/rhythmbullet/stages/GameHUD.java | 7 ++- .../rhythmbullet/stages/GamePlayArea.java | 2 +- .../ui/components/AudioGraph.java | 6 +- .../ui/components/AudioGraphRelation.java | 6 +- .../ui/components/Visualizer.java | 6 +- .../rhythmbullet/ui/pages/AnalyzePage.java | 6 +- .../rhythmbullet/ui/pages/MainPage.java | 10 ++-- .../rhythmbullet/ui/pages/OptionsPage.java | 6 +- .../rhythmbullet/ui/windows/BeatViewer.java | 6 +- .../ui/windows/MusicController.java | 43 +++++++------- .../ui/windows/MusicSelector.java | 4 +- .../rhythmbullet/ui/windows/VolumeWindow.java | 10 ++-- 26 files changed, 200 insertions(+), 144 deletions(-) rename core/src/zero1hd/rhythmbullet/audio/{MusicDataPack.java => MusicManager.java} (73%) rename core/src/zero1hd/rhythmbullet/audio/{SongController.java => SongListController.java} (84%) diff --git a/core/src/zero1hd/rhythmbullet/audio/AudioAnalyzer.java b/core/src/zero1hd/rhythmbullet/audio/AudioAnalyzer.java index 112e93f..9a0371f 100755 --- a/core/src/zero1hd/rhythmbullet/audio/AudioAnalyzer.java +++ b/core/src/zero1hd/rhythmbullet/audio/AudioAnalyzer.java @@ -12,7 +12,7 @@ import zero1hd.rhythmbullet.util.MiniSender; public class AudioAnalyzer { private boolean containsData; - private MusicDataPack musicInfo; + private MusicManager musicInfo; float[] audioPCM; float[] spectrum; @@ -56,7 +56,7 @@ public class AudioAnalyzer { private float secondsPerWindow; private AudioDataPackage pack; - public AudioAnalyzer(MusicDataPack audiofile) { + public AudioAnalyzer(MusicManager audiofile) { sender = new MiniSender(); analysisAlgorithm = () -> { diff --git a/core/src/zero1hd/rhythmbullet/audio/AudioDataPackage.java b/core/src/zero1hd/rhythmbullet/audio/AudioDataPackage.java index e8887fb..eb99285 100755 --- a/core/src/zero1hd/rhythmbullet/audio/AudioDataPackage.java +++ b/core/src/zero1hd/rhythmbullet/audio/AudioDataPackage.java @@ -9,7 +9,7 @@ public class AudioDataPackage { private FloatArray mPeaks; private FloatArray umPeaks; - private MusicDataPack musicInfo; + private MusicManager musicInfo; private float bassMaxVal, bassAvg; private float mMaxVal, mAvg; @@ -64,7 +64,7 @@ public class AudioDataPackage { this.uMAvg = uMAvg; } - public void setMusicInfo(MusicDataPack musicInfo) { + public void setMusicInfo(MusicManager musicInfo) { if (this.musicInfo != null) { throw new InvalidParameterException("There is already music information in this package."); } @@ -108,7 +108,7 @@ public class AudioDataPackage { } } - public MusicDataPack getMusicInfo() { + public MusicManager getMusicInfo() { if (musicInfo == null) { throw new NullPointerException("Music info hasn't been baked in..."); } diff --git a/core/src/zero1hd/rhythmbullet/audio/Mp3AudioData.java b/core/src/zero1hd/rhythmbullet/audio/Mp3AudioData.java index b13c3b6..c9e122a 100755 --- a/core/src/zero1hd/rhythmbullet/audio/Mp3AudioData.java +++ b/core/src/zero1hd/rhythmbullet/audio/Mp3AudioData.java @@ -9,6 +9,7 @@ import org.jaudiotagger.tag.TagException; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.audio.Music; +import com.badlogic.gdx.audio.Music.OnCompletionListener; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.utils.GdxRuntimeException; @@ -20,7 +21,7 @@ import javazoom.jl.decoder.Header; import javazoom.jl.decoder.MP3Decoder; import javazoom.jl.decoder.OutputBuffer; -public class Mp3AudioData implements MusicDataPack { +public class Mp3AudioData implements MusicManager { private int readWindowSize = 1024; private int currentReadWindowIndex; @@ -64,7 +65,6 @@ public class Mp3AudioData implements MusicDataPack { playbackMusic = Gdx.audio.newMusic(audioFile); - reset(); } @Override @@ -77,21 +77,11 @@ public class Mp3AudioData implements MusicDataPack { return readIndex; } - @Override - public void reset() { - playbackMusic.stop(); - } - @Override public int getReadWindowSize() { return readWindowSize; } - @Override - public Music getPlaybackMusic() { - return playbackMusic; - } - @Override public long getSampleCount() { return sampleCount; @@ -99,7 +89,7 @@ public class Mp3AudioData implements MusicDataPack { @Override public void dispose() { - reset(); + playbackMusic.stop(); playbackMusic.dispose(); try { bitstream.close(); @@ -184,4 +174,39 @@ public class Mp3AudioData implements MusicDataPack { public int getCurrentReadWindowIndex() { return currentReadWindowIndex; } + + @Override + public void pause() { + playbackMusic.pause(); + } + + @Override + public void play() { + playbackMusic.play(); + } + + @Override + public boolean isPlaying() { + return playbackMusic.isPlaying(); + } + + @Override + public float getPosition() { + return playbackMusic.getPosition(); + } + + @Override + public void setPosition(float position) { + playbackMusic.setPosition(position); + } + + @Override + public void setOnCompletionListener(OnCompletionListener listener) { + playbackMusic.setOnCompletionListener(listener); + } + + @Override + public void setVolume(float percent) { + playbackMusic.setVolume(percent); + } } diff --git a/core/src/zero1hd/rhythmbullet/audio/MusicDataPack.java b/core/src/zero1hd/rhythmbullet/audio/MusicManager.java similarity index 73% rename from core/src/zero1hd/rhythmbullet/audio/MusicDataPack.java rename to core/src/zero1hd/rhythmbullet/audio/MusicManager.java index 304f480..594fdf5 100755 --- a/core/src/zero1hd/rhythmbullet/audio/MusicDataPack.java +++ b/core/src/zero1hd/rhythmbullet/audio/MusicManager.java @@ -1,10 +1,10 @@ package zero1hd.rhythmbullet.audio; -import com.badlogic.gdx.audio.Music; +import com.badlogic.gdx.audio.Music.OnCompletionListener; import com.badlogic.gdx.utils.Disposable; -public interface MusicDataPack extends Disposable { +public interface MusicManager extends Disposable { /** * sets a integer variable to the current window of audio data the playback is at. * Useful for efficiency because we compute once for that frame then get the values everytime it is required instead of calculating every time we get the index. @@ -17,23 +17,12 @@ public interface MusicDataPack extends Disposable { */ public int getPlaybackIndexPosition(); - /** - * Completely resets the current audio data. Think of pooling, except, only one instance which is reused instead of multiple. - */ - public void reset(); - /** * returns the read window size. * @return */ public int getReadWindowSize(); - /** - * Gets the object to play the music. Contains playback data. - * @return - */ - public Music getPlaybackMusic(); - /** * read in samples and fills the array. * @param samples the array that should contain said samples @@ -65,4 +54,18 @@ public interface MusicDataPack extends Disposable { * @return */ public int getCurrentReadWindowIndex(); + + public void pause(); + + public void play(); + + public boolean isPlaying(); + + public float getPosition(); + + public void setPosition(float position); + + public void setOnCompletionListener(OnCompletionListener listener); + + public void setVolume(float percent); } diff --git a/core/src/zero1hd/rhythmbullet/audio/SongList.java b/core/src/zero1hd/rhythmbullet/audio/SongList.java index db6c1ec..dd1c5bc 100755 --- a/core/src/zero1hd/rhythmbullet/audio/SongList.java +++ b/core/src/zero1hd/rhythmbullet/audio/SongList.java @@ -26,7 +26,7 @@ public class SongList { this.searchPath = searchPath; } - public MusicDataPack getAudioData(FileHandle file) { + public MusicManager getAudioData(FileHandle file) { if (file.extension().equalsIgnoreCase("wav")) { return new WavAudioData(file); } else if (file.extension().equalsIgnoreCase("mp3")) { @@ -35,7 +35,7 @@ public class SongList { return null; } - public MusicDataPack getMusicInfoFromIndex(int index) { + public MusicManager getMusicInfoFromIndex(int index) { if (index > songList.size) { return null; } diff --git a/core/src/zero1hd/rhythmbullet/audio/SongController.java b/core/src/zero1hd/rhythmbullet/audio/SongListController.java similarity index 84% rename from core/src/zero1hd/rhythmbullet/audio/SongController.java rename to core/src/zero1hd/rhythmbullet/audio/SongListController.java index d40de6d..98eba3c 100755 --- a/core/src/zero1hd/rhythmbullet/audio/SongController.java +++ b/core/src/zero1hd/rhythmbullet/audio/SongListController.java @@ -11,9 +11,9 @@ import com.badlogic.gdx.utils.Array; import zero1hd.rhythmbullet.events.OnDifferentSongListener; -public class SongController implements OnCompletionListener { +public class SongListController implements OnCompletionListener { private SongList songList; - private MusicDataPack mdp; + private MusicManager mdp; private int currentPlaybackID; private boolean autoPlay; private boolean shuffle; @@ -22,7 +22,7 @@ public class SongController implements OnCompletionListener { private Array listeners; private Preferences prefs; - public SongController(SongList songList, Preferences prefs) { + public SongListController(SongList songList, Preferences prefs) { if (prefs == null) throw new NullPointerException("preferences can't be null..."); if (songList == null) throw new NullPointerException("song list can't be null..."); if (!songList.isSearched()) throw new InvalidParameterException("Song list has to be searched already."); @@ -35,8 +35,8 @@ public class SongController implements OnCompletionListener { } public void play() { - mdp.getPlaybackMusic().play(); - mdp.getPlaybackMusic().setVolume(prefs.getFloat("music vol"));; + mdp.play(); + mdp.setVolume(prefs.getFloat("music vol")); } public void setSongByIndex(int index) { @@ -101,7 +101,7 @@ public class SongController implements OnCompletionListener { if (mdp == null) { mdp = songList.getAudioData(Gdx.files.internal("music/default.mp3")); } - mdp.getPlaybackMusic().setOnCompletionListener(this); + mdp.setOnCompletionListener(this); sendEvent(); } @@ -123,7 +123,7 @@ public class SongController implements OnCompletionListener { listeners.removeValue(listener, true); } - public MusicDataPack getCurrentSong() { + public MusicManager getCurrentSong() { return mdp; } } diff --git a/core/src/zero1hd/rhythmbullet/audio/WavAudioData.java b/core/src/zero1hd/rhythmbullet/audio/WavAudioData.java index 528b4ca..ebf56a9 100755 --- a/core/src/zero1hd/rhythmbullet/audio/WavAudioData.java +++ b/core/src/zero1hd/rhythmbullet/audio/WavAudioData.java @@ -7,20 +7,20 @@ import javax.sound.sampled.AudioFormat; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.audio.Music; +import com.badlogic.gdx.audio.Music.OnCompletionListener; import com.badlogic.gdx.files.FileHandle; import zero1hd.rhythmbullet.audio.wavedecoder.WavDecoder; -public class WavAudioData implements MusicDataPack { +public class WavAudioData implements MusicManager { private int readWindowSize = 1024; private AudioFormat format; private int readIndex; private int currentReadWindowIndex; - Music playbackMusic; + private Music playbackMusic; WavDecoder decoder; public WavAudioData(FileHandle file) { - reset(); try { decoder = new WavDecoder(file); } catch (InvalidParameterException | IOException e) { @@ -41,22 +41,10 @@ public class WavAudioData implements MusicDataPack { return readIndex; } - @Override - public void reset() { - if (playbackMusic != null) { - playbackMusic.stop(); - } - } - @Override public int getReadWindowSize() { return readWindowSize; } - - @Override - public Music getPlaybackMusic() { - return playbackMusic; - } @Override public int readSamples(float[] samples) { @@ -80,7 +68,7 @@ public class WavAudioData implements MusicDataPack { @Override public void dispose() { - reset(); + playbackMusic.stop(); playbackMusic.dispose(); decoder.cleanAndClose(); } @@ -99,4 +87,41 @@ public class WavAudioData implements MusicDataPack { public int getCurrentReadWindowIndex() { return currentReadWindowIndex; } + + @Override + public void pause() { + playbackMusic.pause(); + } + + @Override + public void play() { + System.out.println("Play is being called HERE!!"); + playbackMusic.play(); + } + + @Override + public boolean isPlaying() { + return playbackMusic.isPlaying(); + } + + @Override + public float getPosition() { + return playbackMusic.getPosition(); + } + + @Override + public void setPosition(float position) { + playbackMusic.setPosition(position); + + } + + @Override + public void setOnCompletionListener(OnCompletionListener listener) { + playbackMusic.setOnCompletionListener(listener); + } + + @Override + public void setVolume(float percent) { + playbackMusic.setVolume(percent); + } } diff --git a/core/src/zero1hd/rhythmbullet/audio/map/GamePlayMap.java b/core/src/zero1hd/rhythmbullet/audio/map/GamePlayMap.java index 80e532f..d6a3251 100755 --- a/core/src/zero1hd/rhythmbullet/audio/map/GamePlayMap.java +++ b/core/src/zero1hd/rhythmbullet/audio/map/GamePlayMap.java @@ -1,13 +1,13 @@ package zero1hd.rhythmbullet.audio.map; -import zero1hd.rhythmbullet.audio.MusicDataPack; +import zero1hd.rhythmbullet.audio.MusicManager; import zero1hd.rhythmbullet.entity.Entity; import zero1hd.rhythmbullet.entity.EntityFrame; import zero1hd.rhythmbullet.entity.coordinator.Coordinator; import zero1hd.rhythmbullet.entity.coordinator.CoordinatorFrame; public class GamePlayMap { - private MusicDataPack musicData; + private MusicManager musicData; private MapWindowData[] spawnList; private boolean building; private int index; @@ -17,7 +17,7 @@ public class GamePlayMap { * GamePlayMap is what the game area will use to generate entities and judge current audio data * @param audioData audio data */ - public GamePlayMap(MusicDataPack audioData, int totalWindows) { + public GamePlayMap(MusicManager audioData, int totalWindows) { this.musicData = audioData; spawnList = new MapWindowData[totalWindows]; hudType = new byte[totalWindows]; @@ -68,7 +68,7 @@ public class GamePlayMap { index = spawnList.length-1; } - public MusicDataPack getMusicData() { + public MusicManager getMusicData() { return musicData; } diff --git a/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java b/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java index cc6ee86..dd66659 100755 --- a/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java +++ b/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java @@ -10,7 +10,7 @@ import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; -import zero1hd.rhythmbullet.audio.MusicDataPack; +import zero1hd.rhythmbullet.audio.MusicManager; public class BasicVisualizer extends VisualizerCore { private Pixmap pixmap; @@ -52,7 +52,7 @@ public class BasicVisualizer extends VisualizerCore { @Override public void render(Batch batch, float parentAlpha) { - if (cmi != null) { + if (mm != null) { //Averaging bins together for (int i = 0; i < barCount; i++) { bars[i].setSize(barWidth, 0); @@ -85,8 +85,8 @@ public class BasicVisualizer extends VisualizerCore { } @Override - public void setMDP(MusicDataPack mdp) { - super.setMDP(mdp); + public void setMM(MusicManager mdp) { + super.setMM(mdp); float validBins = (5000/((mdp.getSampleRate()/2)/((audioPCM.length/2)+1))); Gdx.app.debug("Visualizer", "valid frequency bins " + validBins); binsPerBar = MathUtils.round((validBins/barCount)); diff --git a/core/src/zero1hd/rhythmbullet/audio/visualizer/VisualizerCore.java b/core/src/zero1hd/rhythmbullet/audio/visualizer/VisualizerCore.java index 6883805..fcf693e 100755 --- a/core/src/zero1hd/rhythmbullet/audio/visualizer/VisualizerCore.java +++ b/core/src/zero1hd/rhythmbullet/audio/visualizer/VisualizerCore.java @@ -4,10 +4,10 @@ import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.utils.Disposable; import edu.emory.mathcs.jtransforms.fft.FloatFFT_1D; -import zero1hd.rhythmbullet.audio.MusicDataPack; +import zero1hd.rhythmbullet.audio.MusicManager; public class VisualizerCore implements Disposable { - protected MusicDataPack cmi; + protected MusicManager mm; private FloatFFT_1D fft; float[] audioPCM; protected int width, height; @@ -22,18 +22,22 @@ public class VisualizerCore implements Disposable { } public void calculate() { - if (cmi != null) { - if (cmi.getPlaybackIndexPosition() > cmi.getCurrentReadWindowIndex()) { - cmi.readSamples(audioPCM); - fft.realForward(audioPCM); + if (mm != null) { + mm.playbackIndexUpdate(); + if (mm.getPlaybackIndexPosition() > mm.getCurrentReadWindowIndex()) { + while (mm.getPlaybackIndexPosition() > mm.getCurrentReadWindowIndex()) { + mm.readSamples(audioPCM); + fft.realForward(audioPCM); + System.out.println(mm.getPlaybackIndexPosition() + " " + mm.getCurrentReadWindowIndex()); + } } } } - public void setMDP(MusicDataPack cmi) { - this.cmi = cmi; - fft = new FloatFFT_1D(cmi.getReadWindowSize()); - audioPCM = new float[cmi.getReadWindowSize()]; + public void setMM(MusicManager mm) { + this.mm = mm; + fft = new FloatFFT_1D(mm.getReadWindowSize()); + audioPCM = new float[mm.getReadWindowSize()]; } public void render(Batch batch, float parentAlpha) { diff --git a/core/src/zero1hd/rhythmbullet/events/OnDifferentSongListener.java b/core/src/zero1hd/rhythmbullet/events/OnDifferentSongListener.java index 6d76ee3..c27fa03 100755 --- a/core/src/zero1hd/rhythmbullet/events/OnDifferentSongListener.java +++ b/core/src/zero1hd/rhythmbullet/events/OnDifferentSongListener.java @@ -1,6 +1,6 @@ package zero1hd.rhythmbullet.events; -import zero1hd.rhythmbullet.audio.MusicDataPack; +import zero1hd.rhythmbullet.audio.MusicManager; public interface OnDifferentSongListener { @@ -8,5 +8,5 @@ public interface OnDifferentSongListener { * Called whenever the Song Controller moves to a different song. * @param mdp contains the next songs basic music system. */ - public void onDifferentSong(MusicDataPack mdp); + public void onDifferentSong(MusicManager mdp); } diff --git a/core/src/zero1hd/rhythmbullet/screens/GameScreen.java b/core/src/zero1hd/rhythmbullet/screens/GameScreen.java index 5439f9b..7a08e15 100755 --- a/core/src/zero1hd/rhythmbullet/screens/GameScreen.java +++ b/core/src/zero1hd/rhythmbullet/screens/GameScreen.java @@ -14,7 +14,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.ImageButton; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import zero1hd.rhythmbullet.RhythmBullet; -import zero1hd.rhythmbullet.audio.MusicDataPack; +import zero1hd.rhythmbullet.audio.MusicManager; import zero1hd.rhythmbullet.audio.map.GamePlayMap; import zero1hd.rhythmbullet.stages.GameHUD; import zero1hd.rhythmbullet.stages.GamePlayArea; @@ -27,7 +27,7 @@ public class GameScreen extends ScreenAdapter { protected InputMultiplexer inputs; public RhythmBullet core; - private MusicDataPack music; + private MusicManager music; private ShaderProgram gaussianBlurShader; private ShaderProgram brightFilterShader; @@ -69,7 +69,7 @@ public class GameScreen extends ScreenAdapter { public void setGamePlayMap(GamePlayMap gpm) { music = gpm.getMusicData(); gameArea.setAudioMap(gpm); - gameHUD.setMusic(gpm.getMusicData().getPlaybackMusic()); + gameHUD.setMusic(gpm.getMusicData()); } @Override @@ -222,7 +222,7 @@ public class GameScreen extends ScreenAdapter { gameHUD.getViewport().apply(); gameHUD.draw(); - if (music != null && !music.getPlaybackMusic().isPlaying()) { + if (music != null && !music.isPlaying()) { end(true); } @@ -278,7 +278,7 @@ public class GameScreen extends ScreenAdapter { if (music == null) throw new NullPointerException("Idiot, you can't have a music game not have music on the gameplay screen..."); Gdx.input.setInputProcessor(inputs); if (!gameHUD.isPaused()) { - music.getPlaybackMusic().play(); + music.play(); } } } \ No newline at end of file diff --git a/core/src/zero1hd/rhythmbullet/screens/MainMenu.java b/core/src/zero1hd/rhythmbullet/screens/MainMenu.java index 68d16a0..2ae2d9a 100755 --- a/core/src/zero1hd/rhythmbullet/screens/MainMenu.java +++ b/core/src/zero1hd/rhythmbullet/screens/MainMenu.java @@ -12,7 +12,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.utils.viewport.ScreenViewport; import zero1hd.rhythmbullet.RhythmBullet; -import zero1hd.rhythmbullet.audio.SongController; +import zero1hd.rhythmbullet.audio.SongListController; import zero1hd.rhythmbullet.audio.SongList; import zero1hd.rhythmbullet.ui.pages.CreditsPage; import zero1hd.rhythmbullet.ui.pages.MainPage; @@ -31,7 +31,7 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter { private RhythmBullet core; - private SongController sc; + private SongListController sc; private float lerpAlpha; public MainMenu(final RhythmBullet core) { this.core = core; @@ -42,11 +42,9 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter { songList.setSearchPath(core.getPrefs().getString("music dir")); songList.refresh(); - sc = new SongController(songList, core.getPrefs()); + sc = new SongListController(songList, core.getPrefs()); sc.setAutoPlay(true); sc.setShuffle(true); - sc.play(); - postTransition(); } @@ -111,6 +109,7 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter { @Override public void show() { Gdx.input.setInputProcessor(stage); + sc.play(); calcLerpAlpha(Gdx.graphics.getWidth()); super.show(); } @@ -139,8 +138,6 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter { stage.getCamera().position.lerp(targetPosition, lerpAlpha); } - sc.getCurrentSong().playbackIndexUpdate(); - super.render(delta); } diff --git a/core/src/zero1hd/rhythmbullet/stages/CreativeHUD.java b/core/src/zero1hd/rhythmbullet/stages/CreativeHUD.java index 6d8960a..222bcf0 100755 --- a/core/src/zero1hd/rhythmbullet/stages/CreativeHUD.java +++ b/core/src/zero1hd/rhythmbullet/stages/CreativeHUD.java @@ -279,7 +279,7 @@ public class CreativeHUD extends Stage implements MiniListener { mGraphWindow.normalDataG1 = adp.getmMaxVal(); mGraphWindow.avgG1 = adp.getmAvg(); gpa.setAudioMap(mapGen.getMap()); - ghud.setMusic(adp.getMusicInfo().getPlaybackMusic()); + ghud.setMusic(adp.getMusicInfo()); break; default: break; diff --git a/core/src/zero1hd/rhythmbullet/stages/GameHUD.java b/core/src/zero1hd/rhythmbullet/stages/GameHUD.java index 36c5fdd..24e744c 100755 --- a/core/src/zero1hd/rhythmbullet/stages/GameHUD.java +++ b/core/src/zero1hd/rhythmbullet/stages/GameHUD.java @@ -7,8 +7,8 @@ import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Pixmap.Format; -import com.badlogic.gdx.graphics.Texture.TextureFilter; import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.Texture.TextureFilter; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.actions.Actions; @@ -19,6 +19,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import zero1hd.rhythmbullet.RhythmBullet; +import zero1hd.rhythmbullet.audio.MusicManager; import zero1hd.rhythmbullet.ui.components.HealthBar; import zero1hd.rhythmbullet.ui.windows.FPSWindow; import zero1hd.rhythmbullet.ui.windows.PauseMenu; @@ -38,7 +39,7 @@ public class GameHUD extends Stage { private Image leftStatusBar; private Image rightStatusBar; private GamePlayArea gpa; - private Music music; + private MusicManager music; private ScoreManager sm; private Color original, bass, um; @@ -203,7 +204,7 @@ public class GameHUD extends Stage { return false; } - public void setMusic(Music music) { + public void setMusic(MusicManager music) { this.music = music; } diff --git a/core/src/zero1hd/rhythmbullet/stages/GamePlayArea.java b/core/src/zero1hd/rhythmbullet/stages/GamePlayArea.java index eb88446..3a66881 100755 --- a/core/src/zero1hd/rhythmbullet/stages/GamePlayArea.java +++ b/core/src/zero1hd/rhythmbullet/stages/GamePlayArea.java @@ -59,7 +59,7 @@ public class GamePlayArea extends Stage { @Override public void act(float delta) { MapWindowData mwd; - if (audioMap != null && audioMap.getMusicData().getPlaybackMusic().isPlaying()) { + if (audioMap != null && audioMap.getMusicData().isPlaying()) { audioMap.getMusicData().playbackIndexUpdate(); if ((mwd = audioMap.getCurrentWindowBasedOnIndex()) != null) { EntitySpawnInfo[] currentSpawnInfo = mwd.getArray(); diff --git a/core/src/zero1hd/rhythmbullet/ui/components/AudioGraph.java b/core/src/zero1hd/rhythmbullet/ui/components/AudioGraph.java index 9c29ff8..aaa00f8 100755 --- a/core/src/zero1hd/rhythmbullet/ui/components/AudioGraph.java +++ b/core/src/zero1hd/rhythmbullet/ui/components/AudioGraph.java @@ -9,10 +9,10 @@ import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.utils.FloatArray; -import zero1hd.rhythmbullet.audio.MusicDataPack; +import zero1hd.rhythmbullet.audio.MusicManager; public class AudioGraph extends Actor { - private MusicDataPack audioData; + private MusicManager audioData; ShapeRenderer shapeRender; FloatArray mainGraph; FloatArray overlayGraph; @@ -134,7 +134,7 @@ public class AudioGraph extends Actor { * @param dataSet2 overlay graph. This one can be null. * @param audioData actual basic audio information for index position */ - public void setGraphingData(FloatArray dataSet1, FloatArray dataSet2, MusicDataPack audioData) { + public void setGraphingData(FloatArray dataSet1, FloatArray dataSet2, MusicManager audioData) { this.mainGraph = dataSet1; this.overlayGraph = dataSet2; if (dataSet2 == null) { diff --git a/core/src/zero1hd/rhythmbullet/ui/components/AudioGraphRelation.java b/core/src/zero1hd/rhythmbullet/ui/components/AudioGraphRelation.java index 6f992d5..8d7a506 100755 --- a/core/src/zero1hd/rhythmbullet/ui/components/AudioGraphRelation.java +++ b/core/src/zero1hd/rhythmbullet/ui/components/AudioGraphRelation.java @@ -9,10 +9,10 @@ import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.utils.FloatArray; -import zero1hd.rhythmbullet.audio.MusicDataPack; +import zero1hd.rhythmbullet.audio.MusicManager; public class AudioGraphRelation extends Actor { - private MusicDataPack audioData; + private MusicManager audioData; ShapeRenderer shapeRender; FloatArray mainGraph; FloatArray overlayGraph; @@ -134,7 +134,7 @@ public class AudioGraphRelation extends Actor { * @param dataSet2 overlay graph. This one can be null. * @param audioData actual basic audio information for index position */ - public void setGraphingData(FloatArray dataSet1, FloatArray dataSet2, MusicDataPack audioData) { + public void setGraphingData(FloatArray dataSet1, FloatArray dataSet2, MusicManager audioData) { this.mainGraph = dataSet1; this.overlayGraph = dataSet2; if (dataSet2 == null) { diff --git a/core/src/zero1hd/rhythmbullet/ui/components/Visualizer.java b/core/src/zero1hd/rhythmbullet/ui/components/Visualizer.java index 6044222..a294f17 100755 --- a/core/src/zero1hd/rhythmbullet/ui/components/Visualizer.java +++ b/core/src/zero1hd/rhythmbullet/ui/components/Visualizer.java @@ -4,7 +4,7 @@ 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.MusicManager; import zero1hd.rhythmbullet.audio.visualizer.BasicVisualizer; public class Visualizer extends Widget { @@ -31,8 +31,8 @@ public class Visualizer extends Widget { } - public void setMDP(MusicDataPack mdp) { - vis.setMDP(mdp); + public void setMDP(MusicManager mdp) { + vis.setMM(mdp); } @Override diff --git a/core/src/zero1hd/rhythmbullet/ui/pages/AnalyzePage.java b/core/src/zero1hd/rhythmbullet/ui/pages/AnalyzePage.java index e2c3e7b..cd20ff5 100755 --- a/core/src/zero1hd/rhythmbullet/ui/pages/AnalyzePage.java +++ b/core/src/zero1hd/rhythmbullet/ui/pages/AnalyzePage.java @@ -19,7 +19,7 @@ import com.badlogic.gdx.utils.Disposable; import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.audio.AudioAnalyzer; -import zero1hd.rhythmbullet.audio.MusicDataPack; +import zero1hd.rhythmbullet.audio.MusicManager; import zero1hd.rhythmbullet.audio.SongInfo; import zero1hd.rhythmbullet.audio.map.GamePlayMap; import zero1hd.rhythmbullet.audio.map.RhythmMapAlgorithm; @@ -32,7 +32,7 @@ public class AnalyzePage extends Page implements MiniListener, Disposable { private AnalyzePage ap = this; AudioAnalyzer audioAnalyzer; - MusicDataPack music; + MusicManager music; RhythmMapAlgorithm mapGenAlgorithm; private Table songInfo; @@ -186,7 +186,7 @@ public class AnalyzePage extends Page implements MiniListener, Disposable { addActor(back); } - public void setSong(MusicDataPack music, SongInfo audioInfo, MiniListener listener) { + public void setSong(MusicManager music, SongInfo audioInfo, MiniListener listener) { confirmed = false; confirmDiffButton.setDisabled(false); sensitivityRating.setDisabled(false); diff --git a/core/src/zero1hd/rhythmbullet/ui/pages/MainPage.java b/core/src/zero1hd/rhythmbullet/ui/pages/MainPage.java index 32feb7c..7ebf01a 100755 --- a/core/src/zero1hd/rhythmbullet/ui/pages/MainPage.java +++ b/core/src/zero1hd/rhythmbullet/ui/pages/MainPage.java @@ -15,8 +15,8 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import zero1hd.rhythmbullet.RhythmBullet; -import zero1hd.rhythmbullet.audio.MusicDataPack; -import zero1hd.rhythmbullet.audio.SongController; +import zero1hd.rhythmbullet.audio.MusicManager; +import zero1hd.rhythmbullet.audio.SongListController; import zero1hd.rhythmbullet.audio.visualizer.BasicVisualizer; import zero1hd.rhythmbullet.events.OnDifferentSongListener; import zero1hd.rhythmbullet.screens.PreGameScreen; @@ -32,10 +32,10 @@ public class MainPage extends Page implements OnDifferentSongListener { private TextButton credits; private WidgetGroup playButton; - private SongController sc; + private SongListController sc; private Visualizer hvisual; - public MainPage(RhythmBullet core, Vector3 targetPosition, SongController sc) { + public MainPage(RhythmBullet core, Vector3 targetPosition, SongListController sc) { hvisual = new Visualizer(); this.sc = sc; sc.addOnDifferentSongListener(this); @@ -129,7 +129,7 @@ public class MainPage extends Page implements OnDifferentSongListener { } @Override - public void onDifferentSong(MusicDataPack mdp) { + public void onDifferentSong(MusicManager mdp) { hvisual.setMDP(mdp); } } diff --git a/core/src/zero1hd/rhythmbullet/ui/pages/OptionsPage.java b/core/src/zero1hd/rhythmbullet/ui/pages/OptionsPage.java index 93a2d37..ed6e97c 100755 --- a/core/src/zero1hd/rhythmbullet/ui/pages/OptionsPage.java +++ b/core/src/zero1hd/rhythmbullet/ui/pages/OptionsPage.java @@ -17,7 +17,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextField; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import zero1hd.rhythmbullet.RhythmBullet; -import zero1hd.rhythmbullet.audio.SongController; +import zero1hd.rhythmbullet.audio.SongListController; import zero1hd.rhythmbullet.screens.CreativeScreen; import zero1hd.rhythmbullet.screens.MainMenu; @@ -27,7 +27,7 @@ public class OptionsPage extends Page { private ProgressBar fxVolSlider; private TextField directoryField; - public OptionsPage(RhythmBullet core, Vector3 targetPosition, MoreOptionsPage moreOptionsPage, SongController sc) { + public OptionsPage(RhythmBullet core, Vector3 targetPosition, MoreOptionsPage moreOptionsPage, SongListController sc) { optionsTable.defaults().spaceLeft(40f).padTop(5f).padBottom(5f).left(); Label optionGeneralTitle = new Label("General", core.getDefaultSkin(), "large-font", core.getDefaultSkin().getColor("default")); @@ -45,7 +45,7 @@ public class OptionsPage extends Page { @Override public void changed(ChangeEvent event, Actor actor) { musicVolPercentage.setText(MathUtils.round(musicVolSlider.getValue()) + "%"); - sc.getCurrentSong().getPlaybackMusic().setVolume(musicVolSlider.getPercent()); + sc.getCurrentSong().setVolume(musicVolSlider.getPercent()); core.getPrefs().putFloat("music vol", musicVolSlider.getPercent()); } diff --git a/core/src/zero1hd/rhythmbullet/ui/windows/BeatViewer.java b/core/src/zero1hd/rhythmbullet/ui/windows/BeatViewer.java index 2a58337..1a9a59c 100755 --- a/core/src/zero1hd/rhythmbullet/ui/windows/BeatViewer.java +++ b/core/src/zero1hd/rhythmbullet/ui/windows/BeatViewer.java @@ -10,12 +10,12 @@ import com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup; import com.badlogic.gdx.scenes.scene2d.ui.Window; import zero1hd.rhythmbullet.audio.AudioDataPackage; -import zero1hd.rhythmbullet.audio.MusicDataPack; +import zero1hd.rhythmbullet.audio.MusicManager; public class BeatViewer extends Window { Pixmap lights; int songIndex; - MusicDataPack music; + MusicManager music; Texture lightOn; private AudioDataPackage data; @@ -125,7 +125,7 @@ public class BeatViewer extends Window { super.act(delta); } - public void setMusic(MusicDataPack audioData, AudioDataPackage adp) { + public void setMusic(MusicManager audioData, AudioDataPackage adp) { this.music = audioData; this.data = adp; } diff --git a/core/src/zero1hd/rhythmbullet/ui/windows/MusicController.java b/core/src/zero1hd/rhythmbullet/ui/windows/MusicController.java index f1e8850..212d2d2 100755 --- a/core/src/zero1hd/rhythmbullet/ui/windows/MusicController.java +++ b/core/src/zero1hd/rhythmbullet/ui/windows/MusicController.java @@ -15,13 +15,13 @@ import com.badlogic.gdx.scenes.scene2d.ui.Window; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; -import zero1hd.rhythmbullet.audio.MusicDataPack; +import zero1hd.rhythmbullet.audio.MusicManager; public class MusicController extends Window implements OnCompletionListener { Skin skin; private Image togglePlay; private TextField info; - private MusicDataPack audiofile; + private MusicManager audiofile; public MusicController(final Skin skin) { super("Playback Controller", skin, "tinted"); @@ -34,10 +34,8 @@ public class MusicController extends Window implements OnCompletionListener { @Override public void changed(ChangeEvent event, Actor actor) { - if (audiofile.getPlaybackMusic() != null) { - audiofile.getPlaybackMusic().setPosition(audiofile.getPlaybackMusic().getPosition() - 2); - info.setText(String.valueOf(MathUtils.round(audiofile.getPlaybackMusic().getPosition())) + " sec"); - } + audiofile.setPosition(audiofile.getPosition() - 2); + info.setText(String.valueOf(MathUtils.round(audiofile.getPosition())) + " sec"); } }); @@ -53,14 +51,14 @@ public class MusicController extends Window implements OnCompletionListener { @Override public void clicked(InputEvent event, float x, float y) { if (audiofile != null) { - if (audiofile.getPlaybackMusic().isPlaying()) { - audiofile.getPlaybackMusic().pause(); + if (audiofile.isPlaying()) { + audiofile.pause(); togglePlay.setDrawable(skin.getDrawable("arrow")); } else { togglePlay.setDrawable(skin.getDrawable("pause")); - audiofile.getPlaybackMusic().play(); + audiofile.play(); } } super.clicked(event, x, y); @@ -73,9 +71,9 @@ public class MusicController extends Window implements OnCompletionListener { @Override public void changed(ChangeEvent event, Actor actor) { if (audiofile != null) { - audiofile.getPlaybackMusic().play(); - audiofile.getPlaybackMusic().setPosition(audiofile.getPlaybackMusic().getPosition() + 2); - info.setText(String.valueOf(MathUtils.round(audiofile.getPlaybackMusic().getPosition())) + " sec"); + audiofile.play(); + audiofile.setPosition(audiofile.getPosition() + 2); + info.setText(String.valueOf(MathUtils.round(audiofile.getPosition())) + " sec"); } } }); @@ -85,8 +83,8 @@ public class MusicController extends Window implements OnCompletionListener { info = new TextField(null, skin, "ui") { @Override public void act(float delta) { - if (audiofile != null && audiofile.getPlaybackMusic().isPlaying()) { - setText(String.valueOf(MathUtils.round(audiofile.getPlaybackMusic().getPosition())) + " sec"); + if (audiofile != null && audiofile.isPlaying()) { + setText(String.valueOf(MathUtils.round(audiofile.getPosition())) + " sec"); } super.act(delta); } @@ -99,7 +97,7 @@ public class MusicController extends Window implements OnCompletionListener { public boolean keyUp(InputEvent event, int keycode) { if (keycode == Keys.ENTER) { if (!info.getText().replaceAll("(?![0-9])\\S+", "").trim().isEmpty()) { - audiofile.getPlaybackMusic().setPosition(Float.valueOf(info.getText().replaceAll("(?![0-9])\\S+", "").trim())); + audiofile.setPosition(Float.valueOf(info.getText().replaceAll("(?![0-9])\\S+", "").trim())); } } return super.keyUp(event, keycode); @@ -110,22 +108,25 @@ public class MusicController extends Window implements OnCompletionListener { setSize(260, 75); } - public void setAudiofile(MusicDataPack audiofile) { + public void setAudiofile(MusicManager audiofile) { this.audiofile = audiofile; + if (this.audiofile != null) { + this.audiofile.dispose(); + this.audiofile = null; + } if (audiofile == null) { togglePlay.setDrawable(skin.getDrawable("loading")); info.setText("Analyzing..."); } else { - audiofile.reset(); togglePlay.setDrawable(skin.getDrawable("arrow")); info.setText("Ready."); - audiofile.getPlaybackMusic().play(); - audiofile.getPlaybackMusic().pause(); - audiofile.getPlaybackMusic().setOnCompletionListener(this); + audiofile.play(); + audiofile.pause(); + audiofile.setOnCompletionListener(this); } } - public MusicDataPack getAudiofile() { + public MusicManager getAudiofile() { return audiofile; } diff --git a/core/src/zero1hd/rhythmbullet/ui/windows/MusicSelector.java b/core/src/zero1hd/rhythmbullet/ui/windows/MusicSelector.java index e2574ff..cf6447d 100755 --- a/core/src/zero1hd/rhythmbullet/ui/windows/MusicSelector.java +++ b/core/src/zero1hd/rhythmbullet/ui/windows/MusicSelector.java @@ -11,7 +11,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Window; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.utils.Array; -import zero1hd.rhythmbullet.audio.MusicDataPack; +import zero1hd.rhythmbullet.audio.MusicManager; import zero1hd.rhythmbullet.audio.SongList; import zero1hd.rhythmbullet.util.MiniEvents; import zero1hd.rhythmbullet.util.MiniSender; @@ -88,7 +88,7 @@ public class MusicSelector extends Window { return isBack; } - public MusicDataPack getSelectedMusic() { + public MusicManager getSelectedMusic() { if (selectedMusic != null) { return songList.getAudioData(selectedMusic); } else { diff --git a/core/src/zero1hd/rhythmbullet/ui/windows/VolumeWindow.java b/core/src/zero1hd/rhythmbullet/ui/windows/VolumeWindow.java index c8a8801..5f6f839 100755 --- a/core/src/zero1hd/rhythmbullet/ui/windows/VolumeWindow.java +++ b/core/src/zero1hd/rhythmbullet/ui/windows/VolumeWindow.java @@ -9,7 +9,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Slider; import com.badlogic.gdx.scenes.scene2d.ui.Window; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; -import zero1hd.rhythmbullet.audio.MusicDataPack; +import zero1hd.rhythmbullet.audio.MusicManager; public class VolumeWindow extends Window { @@ -17,7 +17,7 @@ public class VolumeWindow extends Window { private Slider musicVolSlider; private Preferences prefs; - private MusicDataPack music; + private MusicManager music; public VolumeWindow(String title, Skin skin, Preferences prefs) { super(title, skin, "tinted"); this.prefs = prefs; @@ -35,7 +35,7 @@ public class VolumeWindow extends Window { save(); musicVolPercentage.setText(MathUtils.round(musicVolSlider.getValue()) + "%"); if (music != null) { - music.getPlaybackMusic().setVolume(musicVolSlider.getValue()/100f); + music.setVolume(musicVolSlider.getValue()/100f); } } }); @@ -67,10 +67,10 @@ public class VolumeWindow extends Window { prefs.flush(); } - public void setMusic(MusicDataPack music) { + public void setMusic(MusicManager music) { this.music = music; if (music != null) { - music.getPlaybackMusic().setVolume(prefs.getFloat("music vol")/100f); + music.setVolume(prefs.getFloat("music vol")/100f); } } }