From a52e5fc0ed1adc4b8f132b5d3b16315cc6df79ae Mon Sep 17 00:00:00 2001 From: Recrown Date: Sun, 28 May 2017 17:30:35 -0500 Subject: [PATCH] fixed and cleaned code up --- build.gradle | 27 ++++++++----------- .../zero1hd/polyjet/audio/AudioAnalyzer.java | 5 +++- core/src/zero1hd/polyjet/audio/AudioInfo.java | 2 +- .../zero1hd/polyjet/audio/Mp3AudioData.java | 8 +++++- .../polyjet/audio/RhythmMapAlgorithm.java | 6 +++-- core/src/zero1hd/polyjet/entity/Entities.java | 5 ++++ .../polyjet/screens/PreGameScreen.java | 5 +--- .../polyjet/ui/builders/MusicSelectable.java | 2 +- .../zero1hd/polyjet/ui/pages/AnalyzePage.java | 12 ++++----- .../polyjet/ui/pages/MusicSelectionPage.java | 3 ++- .../polyjet/ui/stages/CreativeStage.java | 10 ++++--- .../polyjet/ui/windows/BeatViewer.java | 6 +++-- 12 files changed, 53 insertions(+), 38 deletions(-) create mode 100755 core/src/zero1hd/polyjet/entity/Entities.java diff --git a/build.gradle b/build.gradle index 0f26a17..8900c00 100755 --- a/build.gradle +++ b/build.gradle @@ -41,14 +41,7 @@ project(":desktop") { compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion" compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop" compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop" - - compile group: 'com.googlecode.soundlibs', name: 'mp3spi', version: '1.9.5-1' - - compile "org.apache.commons:commons-math3:3.2" - - compile "com.github.rwl:jtransforms:2.4.0" - - compile "org:jaudiotagger:2.0.3" + compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop" } } @@ -71,14 +64,13 @@ project(":android") { natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a" natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86" natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64" - - compile group: 'com.googlecode.soundlibs', name: 'mp3spi', version: '1.9.5-1' - - compile "org.apache.commons:commons-math3:3.2" - - compile "com.github.rwl:jtransforms:2.4.0" - - compile "org:jaudiotagger:2.0.3" + compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion" + natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi" + natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a" + natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-arm64-v8a" + natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86" + natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86_64" + compile "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion" } } @@ -89,8 +81,11 @@ project(":core") { dependencies { compile "com.badlogicgames.gdx:gdx:$gdxVersion" compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion" + compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion" + compile "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion" compile group: 'com.googlecode.soundlibs', name: 'mp3spi', version: '1.9.5-1' + compile group: 'com.googlecode.soundlibs', name: 'jlayer', version: '1.0.1-1' compile "org.apache.commons:commons-math3:3.2" diff --git a/core/src/zero1hd/polyjet/audio/AudioAnalyzer.java b/core/src/zero1hd/polyjet/audio/AudioAnalyzer.java index 32c89c9..91aa0db 100755 --- a/core/src/zero1hd/polyjet/audio/AudioAnalyzer.java +++ b/core/src/zero1hd/polyjet/audio/AudioAnalyzer.java @@ -104,7 +104,6 @@ public class AudioAnalyzer { seedDigit ++; } - float fluxVal = 0; //bass detection fluxVal = 0; @@ -305,4 +304,8 @@ public class AudioAnalyzer { public void stop() { work = false; } + + public int getPUID() { + return PUID; + } } diff --git a/core/src/zero1hd/polyjet/audio/AudioInfo.java b/core/src/zero1hd/polyjet/audio/AudioInfo.java index 1509c93..782c625 100755 --- a/core/src/zero1hd/polyjet/audio/AudioInfo.java +++ b/core/src/zero1hd/polyjet/audio/AudioInfo.java @@ -46,7 +46,7 @@ public class AudioInfo implements Disposable { e.printStackTrace(); } - invalidMusic = true; +// invalidMusic = true; } else { diff --git a/core/src/zero1hd/polyjet/audio/Mp3AudioData.java b/core/src/zero1hd/polyjet/audio/Mp3AudioData.java index db01f84..72bcc70 100755 --- a/core/src/zero1hd/polyjet/audio/Mp3AudioData.java +++ b/core/src/zero1hd/polyjet/audio/Mp3AudioData.java @@ -19,6 +19,9 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.files.FileHandle; +import javazoom.jl.decoder.Decoder; +import javazoom.spi.mpeg.sampled.convert.DecodedMpegAudioInputStream; + public class Mp3AudioData implements AudioData { private int readWindowSize = 1024; @@ -31,7 +34,10 @@ public class Mp3AudioData implements AudioData { private int sampleCount; private AudioInputStream in; - + + DecodedMpegAudioInputStream dStream; + + Decoder decoder = new Decoder(); public Mp3AudioData(FileHandle audioFile) { try { sampleCount = (int) new MP3File(audioFile.file()).getMP3AudioHeader().getNumberOfFrames(); diff --git a/core/src/zero1hd/polyjet/audio/RhythmMapAlgorithm.java b/core/src/zero1hd/polyjet/audio/RhythmMapAlgorithm.java index d0d27af..adc30fd 100755 --- a/core/src/zero1hd/polyjet/audio/RhythmMapAlgorithm.java +++ b/core/src/zero1hd/polyjet/audio/RhythmMapAlgorithm.java @@ -1,15 +1,17 @@ package zero1hd.polyjet.audio; +import org.apache.commons.math3.random.MersenneTwister; + public class RhythmMapAlgorithm implements Runnable { AudioAnalyzer analyzer; - + MersenneTwister rand; public RhythmMapAlgorithm(AudioAnalyzer analyzer) { this.analyzer = analyzer; + rand = new MersenneTwister(analyzer.getPUID()); } @Override public void run() { - // TODO Auto-generated method stub } } diff --git a/core/src/zero1hd/polyjet/entity/Entities.java b/core/src/zero1hd/polyjet/entity/Entities.java new file mode 100755 index 0000000..a2fcc4e --- /dev/null +++ b/core/src/zero1hd/polyjet/entity/Entities.java @@ -0,0 +1,5 @@ +package zero1hd.polyjet.entity; + +public enum Entities { + Bar_Beat, Void_Circle; +} diff --git a/core/src/zero1hd/polyjet/screens/PreGameScreen.java b/core/src/zero1hd/polyjet/screens/PreGameScreen.java index 9d99763..f7f190b 100755 --- a/core/src/zero1hd/polyjet/screens/PreGameScreen.java +++ b/core/src/zero1hd/polyjet/screens/PreGameScreen.java @@ -24,9 +24,7 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, M MusicSelectionPage ms; AnalyzePage ap; - private Vector3 cameraPos; - private Polyjet core; public PreGameScreen(Polyjet core) { @@ -61,7 +59,7 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, M switch (ID) { case MUSIC_SELECTED: cameraPos.x = 1.5f*Gdx.graphics.getWidth(); - ap.setSong(Audio.getAudioData(ms.getSelectedMusic()), ms.getSelectedMusicInfo()); + ap.setSong(Audio.getAudioData(ms.getSelectedMusic()), ms.getSelectedMusicInfo(), this); break; case SPECTRAL_FLUX_DONE: break; @@ -91,7 +89,6 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, M stage.addActor(ms); ap = new AnalyzePage(core.getDefaultSkin(), core.getAssetManager()); - ap.getAudioAnalyzer().sender.addListener(this); ap.miniSender.addListener(this); ap.setPosition(Gdx.graphics.getWidth(), ap.getY()); stage.addActor(ap); diff --git a/core/src/zero1hd/polyjet/ui/builders/MusicSelectable.java b/core/src/zero1hd/polyjet/ui/builders/MusicSelectable.java index 616edf5..f0d434f 100755 --- a/core/src/zero1hd/polyjet/ui/builders/MusicSelectable.java +++ b/core/src/zero1hd/polyjet/ui/builders/MusicSelectable.java @@ -43,7 +43,7 @@ public class MusicSelectable extends Button implements Disposable { } - public void addInfoToPanel(ScrollPane scroller, float coverSize) { + public void addInfoToPanel(float coverSize) { displayName = new ScrollText(audioInfo.getSongName(), skin, true); defaults().align(Align.top); diff --git a/core/src/zero1hd/polyjet/ui/pages/AnalyzePage.java b/core/src/zero1hd/polyjet/ui/pages/AnalyzePage.java index e32989e..a5c6457 100755 --- a/core/src/zero1hd/polyjet/ui/pages/AnalyzePage.java +++ b/core/src/zero1hd/polyjet/ui/pages/AnalyzePage.java @@ -16,6 +16,7 @@ import zero1hd.polyjet.audio.AudioAnalyzer; import zero1hd.polyjet.audio.AudioData; import zero1hd.polyjet.audio.AudioInfo; import zero1hd.polyjet.util.MiniEvents; +import zero1hd.polyjet.util.MiniListener; public class AnalyzePage extends Page { AudioAnalyzer audioAnalyzer; @@ -58,7 +59,7 @@ public class AnalyzePage extends Page { addActor(back); } - public void setSong(AudioData music, AudioInfo audioInfo) { + public void setSong(AudioData music, AudioInfo audioInfo, MiniListener listener) { songInfo.clear(); audioAnalyzer = new AudioAnalyzer(); @@ -75,7 +76,9 @@ public class AnalyzePage extends Page { @Override public void act(float delta) { - status.setText("Initial analysis: " + audioAnalyzer.getProgress()); + if (music != null) { + status.setText("Initial analysis: " + audioAnalyzer.getProgress()); + } super.act(delta); } @@ -86,11 +89,8 @@ public class AnalyzePage extends Page { return false; } } + public void clearAudioData() { music = null; } - - public AudioAnalyzer getAudioAnalyzer() { - return audioAnalyzer; - } } diff --git a/core/src/zero1hd/polyjet/ui/pages/MusicSelectionPage.java b/core/src/zero1hd/polyjet/ui/pages/MusicSelectionPage.java index 3275f67..07d0622 100755 --- a/core/src/zero1hd/polyjet/ui/pages/MusicSelectionPage.java +++ b/core/src/zero1hd/polyjet/ui/pages/MusicSelectionPage.java @@ -2,6 +2,7 @@ package zero1hd.polyjet.ui.pages; import java.io.File; import java.io.FilenameFilter; +import java.util.Arrays; import java.util.logging.Level; import java.util.logging.Logger; @@ -104,7 +105,7 @@ public class MusicSelectionPage extends Page { public void run() { Gdx.app.debug("Music Search Thread", "Finished loading: " + selectable.getName()); musicChoices.add(selectable).prefSize(panelWidthCalc(getWidth()), musicChoiceScroller.getHeight()); - selectable.addInfoToPanel(musicChoiceScroller, panelWidthCalc(getWidth()) - 20f); + selectable.addInfoToPanel(panelWidthCalc(getWidth()) - 20f); selectable.addListener(new ChangeListener() { @Override diff --git a/core/src/zero1hd/polyjet/ui/stages/CreativeStage.java b/core/src/zero1hd/polyjet/ui/stages/CreativeStage.java index 61c2acd..ea2f6b6 100755 --- a/core/src/zero1hd/polyjet/ui/stages/CreativeStage.java +++ b/core/src/zero1hd/polyjet/ui/stages/CreativeStage.java @@ -46,7 +46,7 @@ public class CreativeStage extends Stage implements MiniListener { fpsViewer = new FPSWindow("FPS", core.getDefaultSkin()); - beatViewer = new BeatViewer("Beat", core.getDefaultSkin(), core, analyzer); + beatViewer = new BeatViewer("Beat", core.getDefaultSkin(), core); graphViewer = new GraphWindow("Peak Values", core.getDefaultSkin()); volumeWindow = new VolumeWindow("Volume adjustments", core.getDefaultSkin(), core.getPrefs()); @@ -198,7 +198,7 @@ public class CreativeStage extends Stage implements MiniListener { break; case MUSIC_SELECTED: - beatViewer.setMusic(null); + beatViewer.setMusic(null, null); volumeWindow.setMusic(null); graphViewer.setData(null, null, null); musicPlayBackControls.setAudiofile(null); @@ -213,9 +213,13 @@ public class CreativeStage extends Stage implements MiniListener { case MUSIC_DATA_CLEANED: musicPlayBackControls.setAudiofile(musicSelector.getSelectedMusic()); volumeWindow.setMusic(musicPlayBackControls.getAudiofile()); - beatViewer.setMusic(musicPlayBackControls.getAudiofile()); + beatViewer.setMusic(musicPlayBackControls.getAudiofile(), analyzer); graphViewer.setData(analyzer.getBassPeaks(), analyzer.getUMPeaks(), musicPlayBackControls.getAudiofile()); break; + case MAP_GENERATED: + break; + default: + break; } } } diff --git a/core/src/zero1hd/polyjet/ui/windows/BeatViewer.java b/core/src/zero1hd/polyjet/ui/windows/BeatViewer.java index e0a97bd..85d5128 100755 --- a/core/src/zero1hd/polyjet/ui/windows/BeatViewer.java +++ b/core/src/zero1hd/polyjet/ui/windows/BeatViewer.java @@ -18,8 +18,9 @@ public class BeatViewer extends Window { int songIndex; AudioData music; Texture lightOn; + private AudioAnalyzer data; - public BeatViewer(String title, Skin skin, Polyjet core, final AudioAnalyzer data) { + public BeatViewer(String title, Skin skin, Polyjet core) { super(title, skin); defaults().space(5f); setSize(64, 100); @@ -111,7 +112,8 @@ public class BeatViewer extends Window { super.act(delta); } - public void setMusic(AudioData audioData) { + public void setMusic(AudioData audioData, AudioAnalyzer analyzer) { this.music = audioData; + this.data = analyzer; } }