From 324e3afe5acdea21f7f5cdc18ec7c5a54405ab57 Mon Sep 17 00:00:00 2001 From: Recrown Date: Tue, 7 Aug 2018 23:53:48 -0500 Subject: [PATCH] multiple order changes with notifiers and other method calls; added copying of default music file to special directory; --- .../rhythmbullet/audio/MinimalAudioHeader.java | 3 ++- .../zero1hd/rhythmbullet/audio/MusicController.java | 3 ++- core/src/zero1hd/rhythmbullet/audio/MusicList.java | 11 ++++++++--- .../graphics/ui/components/MusicSelectable.java | 2 +- .../desktop/audio/visualizer/PCMObtainer.java | 3 ++- .../desktop/screens/main/MusicSelectionPage.java | 6 +----- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/core/src/zero1hd/rhythmbullet/audio/MinimalAudioHeader.java b/core/src/zero1hd/rhythmbullet/audio/MinimalAudioHeader.java index 33efdca..97762e0 100755 --- a/core/src/zero1hd/rhythmbullet/audio/MinimalAudioHeader.java +++ b/core/src/zero1hd/rhythmbullet/audio/MinimalAudioHeader.java @@ -12,6 +12,7 @@ import org.jaudiotagger.audio.mp3.MP3AudioHeader; import org.jaudiotagger.audio.mp3.MP3File; import org.jaudiotagger.tag.TagException; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; public class MinimalAudioHeader { @@ -19,7 +20,7 @@ public class MinimalAudioHeader { private SupportedFormats format; private FileHandle musicFile; public MinimalAudioHeader(FileHandle musicFile) { - this.musicFile = musicFile; + format = SupportedFormats.valueOf(musicFile.extension().toUpperCase()); try { AudioFile file = AudioFileIO.read(musicFile.file()); diff --git a/core/src/zero1hd/rhythmbullet/audio/MusicController.java b/core/src/zero1hd/rhythmbullet/audio/MusicController.java index cf2a85a..56af6c7 100755 --- a/core/src/zero1hd/rhythmbullet/audio/MusicController.java +++ b/core/src/zero1hd/rhythmbullet/audio/MusicController.java @@ -166,10 +166,11 @@ public class MusicController extends Observable implements OnCompletionListener, music.setOnCompletionListener(this); setChanged(); + + notifyObservers(states.LOADED); if (autoPlay) { play(); } - notifyObservers(states.LOADED); } } diff --git a/core/src/zero1hd/rhythmbullet/audio/MusicList.java b/core/src/zero1hd/rhythmbullet/audio/MusicList.java index 3c600c5..2489d14 100755 --- a/core/src/zero1hd/rhythmbullet/audio/MusicList.java +++ b/core/src/zero1hd/rhythmbullet/audio/MusicList.java @@ -2,8 +2,6 @@ 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; @@ -120,9 +118,16 @@ public class MusicList extends Observable { @Override public void run() { Array obtainedAudioFiles = recursiveMusicSearch(directory); + if (Gdx.files.external("RhythmBullet").exists()) { + if (!Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3").exists()) { + Gdx.files.internal("music/Alan Walker - Spectre.mp3").copyTo(Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3")); + } + } else { + Gdx.files.internal("music/Alan Walker - Spectre.mp3").copyTo(Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3")); + } if (work) { musicList = obtainedAudioFiles; - musicList.add(Gdx.files.internal("music/Alan Walker - Spectre.mp3")); + musicList.add(Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3")); if (work) { searched = true; Gdx.app.debug("MusicList", "recursive async search completed."); diff --git a/core/src/zero1hd/rhythmbullet/graphics/ui/components/MusicSelectable.java b/core/src/zero1hd/rhythmbullet/graphics/ui/components/MusicSelectable.java index e1683a7..133ea07 100755 --- a/core/src/zero1hd/rhythmbullet/graphics/ui/components/MusicSelectable.java +++ b/core/src/zero1hd/rhythmbullet/graphics/ui/components/MusicSelectable.java @@ -33,9 +33,9 @@ public class MusicSelectable extends Button { this.metadata = metadata; this.defaultAlbumArt = defaultAlbumArt; this.queueList = queueList; + album = new Image(defaultAlbumArt); add(album).expand().left(); - informationTable = new Table(); name = new ShortenedLabel(metadata.getTitle(), skin, "default-font", skin.getColor("default")); informationTable.add(name).colspan(2).expandX(); diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/audio/visualizer/PCMObtainer.java b/desktop/src/zero1hd/rhythmbullet/desktop/audio/visualizer/PCMObtainer.java index 58bef8b..158e017 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/audio/visualizer/PCMObtainer.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/audio/visualizer/PCMObtainer.java @@ -63,6 +63,7 @@ public class PCMObtainer implements Observer, Disposable, PCMSystem { PCM[sid] = chanVal; } } + System.out.println(PCM[0]); PCM[sid] /= Short.MAX_VALUE + 1f; } @@ -140,7 +141,7 @@ public class PCMObtainer implements Observer, Disposable, PCMSystem { @Override public float[] getFrequencyBins() { if (updated) { - synchronized (PCM) { + synchronized (this) { fft.fft(PCM); System.arraycopy(PCM, 1, frequencyBins, 0, frequencyBins.length); } diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MusicSelectionPage.java b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MusicSelectionPage.java index e91731e..4b6f126 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MusicSelectionPage.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MusicSelectionPage.java @@ -268,11 +268,7 @@ public class MusicSelectionPage extends Page implements Observer { @Override public void update(Observable o, Object arg) { - if (o == mc && arg.equals(mc.states.LOADED)) { - if (selectables.getChecked().getFileHandle() != mc.getCurrentMusicFileHandle()) { - selectables.setChecked(mc.getCurrentlyPlayingIndex()); - } - } else if (o == mmc) { + if (o == mmc) { thread.start(); } }