From b84a3d6280ef7778d3fdf12446c55ae0078229d8 Mon Sep 17 00:00:00 2001 From: Recrown Date: Fri, 24 Aug 2018 01:59:23 -0500 Subject: [PATCH] cleaned up code; status bar on main menu shows more info; --- .../rhythmbullet/audio/MusicController.java | 8 +++---- .../zero1hd/rhythmbullet/audio/MusicList.java | 21 ++++++++-------- .../desktop/screens/main/MainPage.java | 24 +++++++++++++++---- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/core/src/zero1hd/rhythmbullet/audio/MusicController.java b/core/src/zero1hd/rhythmbullet/audio/MusicController.java index 4dc4bea..46b3ae2 100755 --- a/core/src/zero1hd/rhythmbullet/audio/MusicController.java +++ b/core/src/zero1hd/rhythmbullet/audio/MusicController.java @@ -19,7 +19,7 @@ import com.badlogic.gdx.files.FileHandle; */ public class MusicController extends Observable implements OnCompletionListener, Observer { public final class States { - public final Integer LOADED = new Integer(0), PLAYING = new Integer(1); + public final Integer LOADED = new Integer(0), PLAYING = new Integer(1), PAUSED = new Integer(2); } public final States states = new States(); @@ -63,6 +63,8 @@ public class MusicController extends Observable implements OnCompletionListener, public void pause() { if (music != null) { music.pause(); + setChanged(); + notifyObservers(states.PAUSED); } } @@ -164,9 +166,7 @@ public class MusicController extends Observable implements OnCompletionListener, currentlyPlayingIndex = 0; } if (musicList.getTotal() != 0) { - FileHandle musicFile = musicList.getAudioFileHandle(currentlyPlayingIndex); - if (musicFile == null) return; - this.music = Gdx.audio.newMusic(musicFile); + this.music = Gdx.audio.newMusic(musicList.getAudioFileHandle(currentlyPlayingIndex)); music.setOnCompletionListener(this); setChanged(); diff --git a/core/src/zero1hd/rhythmbullet/audio/MusicList.java b/core/src/zero1hd/rhythmbullet/audio/MusicList.java index d75eb21..7b2b461 100755 --- a/core/src/zero1hd/rhythmbullet/audio/MusicList.java +++ b/core/src/zero1hd/rhythmbullet/audio/MusicList.java @@ -18,7 +18,7 @@ import zero1hd.rhythmbullet.audio.processor.WAVAudioProcessor; */ public class MusicList extends Observable { public final class States { - public final Integer LOADING = new Integer(0), COMPLETE = new Integer(1); + public final Integer LOADING = new Integer(0), COMPLETE = new Integer(1), EMPTY = new Integer(2); } public States states = new States(); private Array musicList; @@ -73,6 +73,10 @@ public class MusicList extends Observable { setChanged(); } + public String getSearchPath() { + return searchPath; + } + /** * @param file * @return a {@link AudioProcessor} of the given music file. Will return null if theres a format error. @@ -122,14 +126,7 @@ public class MusicList extends Observable { } public FileHandle getAudioFileHandle(int index) { - FileHandle file = musicList.get(index); - if (file != null) { - return file; - } - - asyncSearch(true); - - return null; + return musicList.get(index); } public int getIndexOfFileHandle(FileHandle file) { @@ -169,7 +166,11 @@ public class MusicList extends Observable { searched = true; Gdx.app.debug("MusicList", "recursive async search completed."); setChanged(); - notifyObservers(states.COMPLETE); + if (musicList.size != 0) { + notifyObservers(states.COMPLETE); + } else { + notifyObservers(states.EMPTY); + } } } diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainPage.java b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainPage.java index aee9141..3bf582b 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainPage.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainPage.java @@ -47,6 +47,7 @@ public class MainPage extends Page implements Observer { super(0, 0); this.mc = musicController; this.mc.addObserver(this); + mc.getMusicList().addObserver(this); this.amc = mmc; this.amc.addObserver(this); @@ -116,21 +117,36 @@ public class MainPage extends Page implements Observer { @Override public void dispose() { dhv.dispose(); + mc.getMusicList().deleteObserver(this); super.dispose(); } @Override public void update(Observable o, Object arg) { if (o == mc) { - if (amc.isSameSizeMusicList()) { - scrollText.setText("Currently playing: " + amc.getAudioMetadata(mc.getCurrentMusicFileHandle()).getTitle(), null); - } else { - scrollText.setText("Currently playing: " + mc.getCurrentMusicFileHandle().nameWithoutExtension().replace('_', ' '), null); + if (arg == mc.states.LOADED) { + if (amc.isSameSizeMusicList()) { + scrollText.setText("Currently playing: " + amc.getAudioMetadata(mc.getCurrentMusicFileHandle()).getTitle(), null); + } else { + scrollText.setText("Currently playing: " + mc.getCurrentMusicFileHandle().nameWithoutExtension().replace('_', ' '), null); + } + } else if (arg == mc.states.PAUSED) { + if (amc.isSameSizeMusicList()) { + scrollText.setText("Currently paused: " + amc.getAudioMetadata(mc.getCurrentMusicFileHandle()).getTitle(), null); + } else { + scrollText.setText("Currently paused: " + mc.getCurrentMusicFileHandle().nameWithoutExtension().replace('_', ' '), null); + } } } else if (o == amc) { if (amc.size() != 0) { scrollText.setText("Currently playing: " + amc.getAudioMetadata(mc.getCurrentMusicFileHandle()).getTitle(), null); } + } else if (o == mc.getMusicList()) { + if (arg == mc.getMusicList().states.EMPTY) { + scrollText.setText("Couldn't find MP3/WAV files", null); + } else if (arg == mc.getMusicList().states.LOADING) { + scrollText.setText("Loading...", null); + } } } }