diff --git a/ShootingStars/lib/AudioProcessing-1.0.jar b/ShootingStars/lib/AudioProcessing-1.0.jar index 3ade434..dd2f7b2 100644 Binary files a/ShootingStars/lib/AudioProcessing-1.0.jar and b/ShootingStars/lib/AudioProcessing-1.0.jar differ diff --git a/ShootingStars/lib/commons-codec-1.4.jar b/ShootingStars/lib/commons-codec-1.4.jar new file mode 100644 index 0000000..458d432 Binary files /dev/null and b/ShootingStars/lib/commons-codec-1.4.jar differ diff --git a/ShootingStars/lib/commons-io-2.1.jar b/ShootingStars/lib/commons-io-2.1.jar new file mode 100644 index 0000000..b5c7d69 Binary files /dev/null and b/ShootingStars/lib/commons-io-2.1.jar differ diff --git a/ShootingStars/lib/commons-lang3-3.1.jar b/ShootingStars/lib/commons-lang3-3.1.jar new file mode 100644 index 0000000..a85e539 Binary files /dev/null and b/ShootingStars/lib/commons-lang3-3.1.jar differ diff --git a/ShootingStars/lib/commons-logging-1.1.1.jar b/ShootingStars/lib/commons-logging-1.1.1.jar new file mode 100644 index 0000000..1deef14 Binary files /dev/null and b/ShootingStars/lib/commons-logging-1.1.1.jar differ diff --git a/ShootingStars/lib/httpclient-4.1.3.jar b/ShootingStars/lib/httpclient-4.1.3.jar new file mode 100644 index 0000000..85c6ce4 Binary files /dev/null and b/ShootingStars/lib/httpclient-4.1.3.jar differ diff --git a/ShootingStars/lib/httpcore-4.1.4.jar b/ShootingStars/lib/httpcore-4.1.4.jar new file mode 100644 index 0000000..a4dc3e8 Binary files /dev/null and b/ShootingStars/lib/httpcore-4.1.4.jar differ diff --git a/ShootingStars/lib/jogg-0.0.7.jar b/ShootingStars/lib/jogg-0.0.7.jar new file mode 100644 index 0000000..1cbd1ad Binary files /dev/null and b/ShootingStars/lib/jogg-0.0.7.jar differ diff --git a/ShootingStars/lib/jorbis-0.0.15.jar b/ShootingStars/lib/jorbis-0.0.15.jar new file mode 100644 index 0000000..4cf51f9 Binary files /dev/null and b/ShootingStars/lib/jorbis-0.0.15.jar differ diff --git a/ShootingStars/lib/tritonus_jorbis-0.3.6.jar b/ShootingStars/lib/tritonus_jorbis-0.3.6.jar new file mode 100644 index 0000000..45b8fc1 Binary files /dev/null and b/ShootingStars/lib/tritonus_jorbis-0.3.6.jar differ diff --git a/ShootingStars/lib/vget-1.1.0.jar b/ShootingStars/lib/vget-1.1.0.jar new file mode 100644 index 0000000..213acf7 Binary files /dev/null and b/ShootingStars/lib/vget-1.1.0.jar differ diff --git a/ShootingStars/lib/wget-1.2.7.jar b/ShootingStars/lib/wget-1.2.7.jar new file mode 100644 index 0000000..0b1a24d Binary files /dev/null and b/ShootingStars/lib/wget-1.2.7.jar differ diff --git a/ShootingStars/lib/xmlpull-1.1.3.1.jar b/ShootingStars/lib/xmlpull-1.1.3.1.jar new file mode 100644 index 0000000..cbc149d Binary files /dev/null and b/ShootingStars/lib/xmlpull-1.1.3.1.jar differ diff --git a/ShootingStars/lib/xpp3_min-1.1.4c.jar b/ShootingStars/lib/xpp3_min-1.1.4c.jar new file mode 100644 index 0000000..813a9a8 Binary files /dev/null and b/ShootingStars/lib/xpp3_min-1.1.4c.jar differ diff --git a/ShootingStars/lib/xstream-1.4.2.jar b/ShootingStars/lib/xstream-1.4.2.jar new file mode 100644 index 0000000..fa8e2ed Binary files /dev/null and b/ShootingStars/lib/xstream-1.4.2.jar differ diff --git a/ShootingStars/nbproject/project.properties b/ShootingStars/nbproject/project.properties index 50cd7d0..d35b777 100644 --- a/ShootingStars/nbproject/project.properties +++ b/ShootingStars/nbproject/project.properties @@ -32,14 +32,28 @@ dist.javadoc.dir=${dist.dir}/javadoc endorsed.classpath= excludes= file.reference.AudioProcessing-1.0.jar=lib\\AudioProcessing-1.0.jar +file.reference.commons-codec-1.4.jar=lib\\commons-codec-1.4.jar +file.reference.commons-io-2.1.jar=lib\\commons-io-2.1.jar +file.reference.commons-lang3-3.1.jar=lib\\commons-lang3-3.1.jar +file.reference.commons-logging-1.1.1.jar=lib\\commons-logging-1.1.1.jar +file.reference.httpclient-4.1.3.jar=lib\\httpclient-4.1.3.jar +file.reference.httpcore-4.1.4.jar=lib\\httpcore-4.1.4.jar file.reference.jaudiotagger-2.2.0.jar=lib\\jaudiotagger-2.2.0.jar file.reference.jl1.0.1.jar=lib\\jl1.0.1.jar file.reference.jna-3.5.2.jar=lib\\jna-3.5.2.jar +file.reference.jogg-0.0.7.jar=lib\\jogg-0.0.7.jar +file.reference.jorbis-0.0.15.jar=lib\\jorbis-0.0.15.jar file.reference.mp3spi1.9.5.jar=lib\\mp3spi1.9.5.jar file.reference.platform-3.5.2.jar=lib\\platform-3.5.2.jar file.reference.tritonus_aos-0.3.6.jar=lib\\tritonus_aos-0.3.6.jar +file.reference.tritonus_jorbis-0.3.6.jar=lib\\tritonus_jorbis-0.3.6.jar file.reference.tritonus_share-0.3.6.jar=lib\\tritonus_share-0.3.6.jar +file.reference.vget-1.1.0.jar=lib\\vget-1.1.0.jar file.reference.vlcj-2.3.0.jar=lib\\vlcj-2.3.0.jar +file.reference.wget-1.2.7.jar=lib\\wget-1.2.7.jar +file.reference.xmlpull-1.1.3.1.jar=lib\\xmlpull-1.1.3.1.jar +file.reference.xpp3_min-1.1.4c.jar=lib\\xpp3_min-1.1.4c.jar +file.reference.xstream-1.4.2.jar=lib\\xstream-1.4.2.jar includes=** jar.archive.disabled=${jnlp.enabled} jar.compress=false @@ -57,7 +71,21 @@ javac.classpath=\ ${file.reference.tritonus_share-0.3.6.jar}:\ ${file.reference.AudioProcessing-1.0.jar}:\ ${libs.jme3-libraries-effects.classpath}:\ - ${file.reference.jaudiotagger-2.2.0.jar} + ${file.reference.jaudiotagger-2.2.0.jar}:\ + ${file.reference.commons-codec-1.4.jar}:\ + ${file.reference.commons-io-2.1.jar}:\ + ${file.reference.commons-lang3-3.1.jar}:\ + ${file.reference.commons-logging-1.1.1.jar}:\ + ${file.reference.httpclient-4.1.3.jar}:\ + ${file.reference.httpcore-4.1.4.jar}:\ + ${file.reference.jogg-0.0.7.jar}:\ + ${file.reference.jorbis-0.0.15.jar}:\ + ${file.reference.tritonus_jorbis-0.3.6.jar}:\ + ${file.reference.vget-1.1.0.jar}:\ + ${file.reference.wget-1.2.7.jar}:\ + ${file.reference.xmlpull-1.1.3.1.jar}:\ + ${file.reference.xpp3_min-1.1.4c.jar}:\ + ${file.reference.xstream-1.4.2.jar} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false diff --git a/ShootingStars/shootingstars.conf b/ShootingStars/shootingstars.conf index a117535..f981627 100644 --- a/ShootingStars/shootingstars.conf +++ b/ShootingStars/shootingstars.conf @@ -1,7 +1,7 @@ #jME3 AppSettings -#Fri Jun 14 08:27:23 CEST 2013 +#Fri Jun 14 11:11:30 CEST 2013 Renderer(string)=LWJGL-OpenGL2 -Width(int)=1360 +Width(int)=1366 DisableJoysticks(bool)=true SettingsDialogImage(string)= Title(string)=Shooting Stars @@ -12,13 +12,13 @@ Samples(int)=0 UseInput(bool)=true BitsPerPixel(int)=24 Frequency(int)=60 -Username(string)=Chris +Username(string)=Darth Affe DepthBits(int)=32 FXVolume(int)=85 Fullscreen(bool)=false AudioRenderer(string)=LWJGL StencilBits(int)=0 -PostProcessing(bool)=false +PostProcessing(bool)=true VSync(bool)=true FrameRate(int)=-1 SoundVolume(int)=24 diff --git a/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java b/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java index 3d41db5..fdf3c96 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java +++ b/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java @@ -29,7 +29,7 @@ import com.jme3.renderer.Camera; import com.jme3.renderer.ViewPort; import com.jme3.scene.Node; import org.wyrez.persij.PersiJContainer; -import org.wyrez.shootingstars.audiodata.AudioDataManager; +import org.wyrez.shootingstars.data.AudioDataManager; import org.wyrez.shootingstars.factories.Materials; import org.wyrez.shootingstars.game.GameSettings; import org.wyrez.shootingstars.states.GameState; @@ -46,14 +46,11 @@ public class ShootingStars extends SimpleApplication { private PersiJContainer container; private StateManager sManager; - private Screen screen; private OptionSettings optionSettings; - private GameSettings gameSettings; public ShootingStars() { super(new StatsAppState(), new DebugKeysAppState()); optionSettings = new OptionSettings(); - gameSettings = new GameSettings(); } @Override @@ -88,21 +85,21 @@ public class ShootingStars extends SimpleApplication { container.registerSingleton(AssetManager.class, assetManager); container.registerSingleton(ViewPort.class, viewPort); container.registerSingleton(OptionSettings.class, optionSettings); - container.registerSingleton(GameSettings.class, gameSettings); + container.registerType(GameSettings.class, true); container.registerType(StateManager.class, true); container.registerType(Screen.class, true); - container.registerType(AudioDataManager.class, true); + container.registerType(AudioDataManager.class, true); } - + private void initKeys() { - inputManager.addMapping("Pause", new KeyTrigger(KeyInput.KEY_P)); + inputManager.addMapping("Pause", new KeyTrigger(KeyInput.KEY_P)); inputManager.deleteMapping(INPUT_MAPPING_EXIT); - inputManager.addMapping("ESC", new KeyTrigger(KeyInput.KEY_ESCAPE)); - + inputManager.addMapping("ESC", new KeyTrigger(KeyInput.KEY_ESCAPE)); + } - + private void initSettings() { - if(optionSettings.saveExists()) { + if (optionSettings.saveExists()) { optionSettings.init(false); optionSettings.load(); } else { @@ -115,7 +112,7 @@ public class ShootingStars extends SimpleApplication { ShootingStars app = new ShootingStars(); //app.setSettings(optionSettings); - + app.start(); } } diff --git a/ShootingStars/src/org/wyrez/shootingstars/controls/GroundBorderGlowControl.java b/ShootingStars/src/org/wyrez/shootingstars/controls/GroundBorderGlowControl.java index 2e1315f..38700e6 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/controls/GroundBorderGlowControl.java +++ b/ShootingStars/src/org/wyrez/shootingstars/controls/GroundBorderGlowControl.java @@ -21,7 +21,7 @@ import com.jme3.math.ColorRGBA; import com.jme3.scene.Geometry; import com.jme3.scene.Spatial; import com.jme3.scene.control.Control; -import org.wyrez.shootingstars.audiodata.AudioDataManager; +import org.wyrez.shootingstars.data.AudioDataManager; /** * diff --git a/ShootingStars/src/org/wyrez/shootingstars/controls/GroundGlowControl.java b/ShootingStars/src/org/wyrez/shootingstars/controls/GroundGlowControl.java index e79746b..3673eac 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/controls/GroundGlowControl.java +++ b/ShootingStars/src/org/wyrez/shootingstars/controls/GroundGlowControl.java @@ -22,7 +22,7 @@ import com.jme3.scene.Geometry; import com.jme3.scene.Spatial; import com.jme3.scene.control.Control; import java.util.Random; -import org.wyrez.shootingstars.audiodata.AudioDataManager; +import org.wyrez.shootingstars.data.AudioDataManager; /** * diff --git a/ShootingStars/src/org/wyrez/shootingstars/controls/GroundMoveControl.java b/ShootingStars/src/org/wyrez/shootingstars/controls/GroundMoveControl.java index c05d1bb..be24d56 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/controls/GroundMoveControl.java +++ b/ShootingStars/src/org/wyrez/shootingstars/controls/GroundMoveControl.java @@ -20,7 +20,7 @@ import com.jme3.math.Vector3f; import com.jme3.scene.Spatial; import com.jme3.scene.control.Control; import java.util.Random; -import org.wyrez.shootingstars.audiodata.AudioDataManager; +import org.wyrez.shootingstars.data.AudioDataManager; /** * diff --git a/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerMoveControl.java b/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerMoveControl.java index f052630..0bc5220 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerMoveControl.java +++ b/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerMoveControl.java @@ -19,7 +19,7 @@ package org.wyrez.shootingstars.controls; import com.jme3.math.FastMath; import com.jme3.scene.Spatial; import com.jme3.scene.control.Control; -import org.wyrez.shootingstars.audiodata.AudioDataManager; +import org.wyrez.shootingstars.data.AudioDataManager; import org.wyrez.shootingstars.helper.MathHelper; import org.wyrez.shootingstars.helper.UserDataKeys; diff --git a/ShootingStars/src/org/wyrez/shootingstars/audiodata/AudioDataManager.java b/ShootingStars/src/org/wyrez/shootingstars/data/AudioDataManager.java similarity index 97% rename from ShootingStars/src/org/wyrez/shootingstars/audiodata/AudioDataManager.java rename to ShootingStars/src/org/wyrez/shootingstars/data/AudioDataManager.java index 3ff1ed8..83b6d87 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/audiodata/AudioDataManager.java +++ b/ShootingStars/src/org/wyrez/shootingstars/data/AudioDataManager.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.wyrez.shootingstars.audiodata; +package org.wyrez.shootingstars.data; import org.wyrez.audio.AudioProcessor; import org.wyrez.audio.decoder.DecoderFactory; @@ -22,7 +22,6 @@ import org.wyrez.audio.util.Band; import org.wyrez.audio.util.SampleBuffer; import org.wyrez.audio.util.SampleHelper; import org.wyrez.shootingstars.game.GameSettings; -import org.wyrez.shootingstars.states.GameState; import uk.co.caprica.vlcj.player.MediaPlayer; /** @@ -34,7 +33,7 @@ public class AudioDataManager { private static final int MIN_PEAK_DIFF = 13; //~198.8bpm private static final Band LOW_BAND = new Band(1f, 140); private static final Band MID_BAND = new Band(400f, 1200f); - private static final Band HIGH_BAND = new Band(4000f, 16000f); + private static final Band HIGH_BAND = new Band(2000f, 16000f); /**/ private AudioProcessor audioProcessorLowBand; private AudioProcessor audioProcessorMidBand; diff --git a/ShootingStars/src/org/wyrez/shootingstars/data/OggConverter.java b/ShootingStars/src/org/wyrez/shootingstars/data/OggConverter.java new file mode 100644 index 0000000..0653b75 --- /dev/null +++ b/ShootingStars/src/org/wyrez/shootingstars/data/OggConverter.java @@ -0,0 +1,77 @@ +package org.wyrez.shootingstars.data; + +/* + * Copyright (C) 2013 Darth Affe and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +import java.util.concurrent.CountDownLatch; +import uk.co.caprica.vlcj.player.MediaPlayer; +import uk.co.caprica.vlcj.player.MediaPlayerEventAdapter; +import uk.co.caprica.vlcj.player.MediaPlayerFactory; + +/** + * + * @author Darth Affe + */ +public class OggConverter { + + private CountDownLatch completionLatch; + private final MediaPlayerFactory mediaPlayerFactory; + private final MediaPlayer mediaPlayer; + private boolean success = false; + + public OggConverter() { + mediaPlayerFactory = new MediaPlayerFactory(); + mediaPlayer = mediaPlayerFactory.newHeadlessMediaPlayer(); + mediaPlayer.addMediaPlayerEventListener(new MediaPlayerEventAdapter() { + @Override + public void finished(MediaPlayer mediaPlayer) { + System.out.println("Rip completed successfully"); + success = true; + completionLatch.countDown(); + } + + @Override + public void error(MediaPlayer mediaPlayer) { + System.out.println("Rip failed"); + success = false; + completionLatch.countDown(); + } + }); + } + + public void convert(String in, String out, int bitrate) throws Exception { + System.out.println("Convert '" + in + "' to '" + out + "'..."); + completionLatch = new CountDownLatch(1); + mediaPlayer.playMedia(in, String.format( + "sout=#transcode{acodec=vorb,channels=2,ab=%d,samplerate=44100,vcodec=dummy}:standard{dst=%s,mux=ogg,access=file}", + bitrate, out)); + + try { + completionLatch.await(); + if (!success) { + throw new Exception("failed conversion..."); + } + } catch (InterruptedException e) { + System.out.println("failed..."); + throw new Exception("failed conversion..."); + } + } + + public void cleanup() { + mediaPlayer.release(); + mediaPlayerFactory.release(); + } +} diff --git a/ShootingStars/src/org/wyrez/shootingstars/data/YTDownloader.java b/ShootingStars/src/org/wyrez/shootingstars/data/YTDownloader.java new file mode 100644 index 0000000..bd1fe42 --- /dev/null +++ b/ShootingStars/src/org/wyrez/shootingstars/data/YTDownloader.java @@ -0,0 +1,73 @@ +package org.wyrez.shootingstars.data; + +/* + * Copyright (C) 2013 Darth Affe and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import com.github.axet.vget.VGet; +import com.github.axet.vget.info.VideoInfo; +import com.github.axet.vget.info.VideoInfo.VideoQuality; +import java.io.File; +import java.net.URL; + +/** + * + * @author Darth Affe + */ +public class YTDownloader { + + private File lastTarget; + + public YTDownloader() { + } + + public boolean download(String source, String targetFolder) { + System.out.println("downloading " + source); + boolean first = true; + boolean process = true; + VideoInfo info = null; + + while (process) { + try { + if (first) { + info = new VideoInfo(new URL(source)); + info.setUserQuality(VideoQuality.p720); + info.setVideoQuality(VideoQuality.p720); + } + VGet v = new VGet(info, new File(targetFolder)); + v.download(); + lastTarget = v.getTarget(); + System.out.println("success!"); + return true; + } catch (Exception e) { + if (first && info != null) { + System.out.println("failed... retry with other quality"); + info.setUserQuality(null); + info.setVideoQuality(null); + first = false; + } else { + process = false; + e.printStackTrace(); + } + } + } + return false; + } + + public File getLastTarget() { + return lastTarget; + } +} diff --git a/ShootingStars/src/org/wyrez/shootingstars/game/GameSettings.java b/ShootingStars/src/org/wyrez/shootingstars/game/GameSettings.java index 28357f7..e3de14f 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/game/GameSettings.java +++ b/ShootingStars/src/org/wyrez/shootingstars/game/GameSettings.java @@ -35,21 +35,13 @@ public class GameSettings { private boolean useVideo; public GameSettings() { -// this.audioFile = audioFile; -// if (videoFile == null) { -// videoFile = audioFile; -// useVideo = false; -// } else { -// this.videoFile = videoFile; -// useVideo = true; -// } } - + public void setAudioFile(String audioFile) { this.audioFile = audioFile; this.useVideo = false; } - + public void setVideoFile(String videoFile) { this.videoFile = videoFile; this.useVideo = true; @@ -62,8 +54,8 @@ public class GameSettings { public String getVideoFile() { return videoFile; } - - public boolean useVideo(){ + + public boolean useVideo() { return useVideo; } diff --git a/ShootingStars/src/org/wyrez/shootingstars/game/GlowingHexPrism.java b/ShootingStars/src/org/wyrez/shootingstars/game/GlowingHexPrism.java index 8284f40..1d2cdd6 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/game/GlowingHexPrism.java +++ b/ShootingStars/src/org/wyrez/shootingstars/game/GlowingHexPrism.java @@ -21,7 +21,7 @@ import com.jme3.math.ColorRGBA; import com.jme3.math.Vector3f; import com.jme3.scene.Geometry; import com.jme3.scene.Node; -import org.wyrez.shootingstars.audiodata.AudioDataManager; +import org.wyrez.shootingstars.data.AudioDataManager; import org.wyrez.shootingstars.controls.GroundGlowControl; import org.wyrez.shootingstars.factories.Materials; import org.wyrez.shootingstars.mesh.HexPrism; diff --git a/ShootingStars/src/org/wyrez/shootingstars/game/Ground.java b/ShootingStars/src/org/wyrez/shootingstars/game/Ground.java index b89cf9a..6448b98 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/game/Ground.java +++ b/ShootingStars/src/org/wyrez/shootingstars/game/Ground.java @@ -22,7 +22,7 @@ import com.jme3.math.FastMath; import com.jme3.math.Vector3f; import com.jme3.scene.Geometry; import com.jme3.scene.Node; -import org.wyrez.shootingstars.audiodata.AudioDataManager; +import org.wyrez.shootingstars.data.AudioDataManager; import org.wyrez.shootingstars.controls.GroundBorderGlowControl; import org.wyrez.shootingstars.controls.GroundGlowControl; import org.wyrez.shootingstars.controls.GroundMoveControl; diff --git a/ShootingStars/src/org/wyrez/shootingstars/helper/ChecksumHelper.java b/ShootingStars/src/org/wyrez/shootingstars/helper/ChecksumHelper.java new file mode 100644 index 0000000..933da62 --- /dev/null +++ b/ShootingStars/src/org/wyrez/shootingstars/helper/ChecksumHelper.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2013 Darth Affe and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.wyrez.shootingstars.helper; + +import java.io.File; +import java.io.FileInputStream; +import org.apache.commons.codec.digest.DigestUtils; + +/** + * + * @author Darth Affe + */ +public class ChecksumHelper { + + public static String createMD5(String path) throws Exception { + return DigestUtils.md5Hex(new FileInputStream(new File(path))); + } +} diff --git a/ShootingStars/src/org/wyrez/shootingstars/helper/PathHelper.java b/ShootingStars/src/org/wyrez/shootingstars/helper/PathHelper.java new file mode 100644 index 0000000..fae725c --- /dev/null +++ b/ShootingStars/src/org/wyrez/shootingstars/helper/PathHelper.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2013 Darth Affe and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.wyrez.shootingstars.helper; + +import java.io.File; + +/** + * + * @author Darth Affe + */ +public class PathHelper { + + private static final String CACHE_FOLDER = "cache/"; + + public static String getCacheFolder() { + File file = new File(CACHE_FOLDER); + if (!file.exists()) { + file.mkdirs(); + } + return CACHE_FOLDER; + } + + public static String replaceFileEnding(String path, String newEnding) { + return path.substring(0, path.lastIndexOf(".") + 1) + newEnding; + } +} diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java b/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java index 3caa89d..bb4fe4b 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java @@ -16,7 +16,6 @@ */ package org.wyrez.shootingstars.states; - import com.jme3.app.state.AbstractAppState; import com.jme3.app.state.AppStateManager; import com.jme3.asset.AssetManager; @@ -32,7 +31,7 @@ import com.jme3.scene.Geometry; import com.jme3.scene.Node; import com.jme3.scene.Spatial; import com.jme3.scene.shape.Box; -import org.wyrez.shootingstars.audiodata.AudioDataManager; +import org.wyrez.shootingstars.data.AudioDataManager; import org.wyrez.shootingstars.controls.PlayerCamControl; import org.wyrez.shootingstars.controls.PlayerMouseControl; import org.wyrez.shootingstars.controls.PlayerMoveControl; @@ -70,7 +69,6 @@ public class GameState extends AbstractAppState implements GameListener, ActionL private Spatial player; private boolean isRunning = false; - public GameState(Node rootNode, Screen screen, StateManager stateManager, AssetManager assetManager, ViewPort viewPort, InputManager inputManager, Camera camera, AudioDataManager audioDataManager, GameSettings settings) { @@ -102,16 +100,11 @@ public class GameState extends AbstractAppState implements GameListener, ActionL viewPort.addProcessor(fpp); } - public boolean initMediaPlayer() { - try { - mediaPlayer = mediaPlayerFactory.newDirectMediaPlayer(settings.getVideoFormat(), - settings.getVideoWidth(), settings.getVideoHeight(), - settings.getVideoWidth() * settings.getVideoDepth(), cinema); - mediaPlayer.prepareMedia(settings.getVideoFile()); - return true; - } catch (Exception ex) { - return false; - } + public void initMediaPlayer() throws Exception { + mediaPlayer = mediaPlayerFactory.newDirectMediaPlayer(settings.getVideoFormat(), + settings.getVideoWidth(), settings.getVideoHeight(), + settings.getVideoWidth() * settings.getVideoDepth(), cinema); + mediaPlayer.prepareMedia(settings.getVideoFile()); } public void loadCinema() { @@ -189,7 +182,7 @@ public class GameState extends AbstractAppState implements GameListener, ActionL public boolean isRunning() { return isRunning; } - + public void onAction(String name, boolean isPressed, float tpf) { if (name.equals("ESC") && !isPressed) { gui.showMenu(); diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/LoadingState.java b/ShootingStars/src/org/wyrez/shootingstars/states/LoadingState.java index 270023b..539d3aa 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/LoadingState.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/LoadingState.java @@ -18,8 +18,13 @@ package org.wyrez.shootingstars.states; import com.jme3.app.state.AbstractAppState; import com.jme3.app.state.AppStateManager; -import org.wyrez.shootingstars.audiodata.AudioDataManager; +import java.io.File; +import org.wyrez.shootingstars.data.AudioDataManager; +import org.wyrez.shootingstars.data.OggConverter; +import org.wyrez.shootingstars.game.GameSettings; import org.wyrez.shootingstars.gui.LoadingGui; +import org.wyrez.shootingstars.helper.ChecksumHelper; +import org.wyrez.shootingstars.helper.PathHelper; import org.wyrez.shootingstars.states.util.LoadingProgress; import tonegod.gui.core.Screen; @@ -33,12 +38,14 @@ public class LoadingState extends AbstractAppState { private LoadingGui gui; private AudioDataManager audioDataManager; private LoadingProgress currentProgress; + private GameSettings settings; public LoadingState(Screen screen, StateManager stateManager, - AudioDataManager audioDataManager) { + AudioDataManager audioDataManager, GameSettings settings) { this.stateManager = stateManager; this.gui = new LoadingGui(screen); this.audioDataManager = audioDataManager; + this.settings = settings; } @Override @@ -54,52 +61,73 @@ public class LoadingState extends AbstractAppState { @Override public void update(float tpf) { - switch (currentProgress) { - case START: - currentProgress = LoadingProgress.LOADING_CINEMA; - break; - case LOADING_CINEMA: - loadingCinema(); - currentProgress = LoadingProgress.INIT_AUDIO_PLAYER; - break; - case INIT_AUDIO_PLAYER: - initAudioPlayer(); - currentProgress = LoadingProgress.INIT_AUDIO_ANALYSIS; - break; - case INIT_AUDIO_ANALYSIS: - initAudioAnalysis(); - currentProgress = LoadingProgress.ANALYSE_LOW_BAND; - break; - case ANALYSE_LOW_BAND: - analyseLowBand(); - currentProgress = LoadingProgress.ANALYSE_MID_BAND; - break; - case ANALYSE_MID_BAND: - analyseMidBand(); - currentProgress = LoadingProgress.ANALYSE_HIGH_BAND; - break; - case ANALYSE_HIGH_BAND: - analyseHighBand(); - currentProgress = LoadingProgress.GENERATING_SCENE; - break; - case GENERATING_SCENE: - generateScene(); - currentProgress = LoadingProgress.LOADING_PLAYER; - break; - case LOADING_PLAYER: - loadPlayer(); - currentProgress = LoadingProgress.DONE; - break; - case DONE: - done(); - break; + try { + switch (currentProgress) { + case START: + currentProgress = LoadingProgress.LOADING_CINEMA; + break; + case LOADING_CINEMA: + loadingCinema(); + currentProgress = LoadingProgress.INIT_AUDIO_PLAYER; + break; + case INIT_AUDIO_PLAYER: + initAudioPlayer(); + currentProgress = LoadingProgress.INIT_AUDIO_ANALYSIS; + break; + case INIT_AUDIO_ANALYSIS: + if (initAudioAnalysis()) { + currentProgress = LoadingProgress.ANALYSE_LOW_BAND; + } else { + currentProgress = LoadingProgress.CONVERT_AUDIO; + } + break; + case CONVERT_AUDIO: + convertAudio(); + currentProgress = LoadingProgress.INIT_AUDIO_ANALYSIS; + break; + case ANALYSE_LOW_BAND: + analyseLowBand(); + currentProgress = LoadingProgress.ANALYSE_MID_BAND; + break; + case ANALYSE_MID_BAND: + analyseMidBand(); + currentProgress = LoadingProgress.ANALYSE_HIGH_BAND; + break; + case ANALYSE_HIGH_BAND: + analyseHighBand(); + currentProgress = LoadingProgress.GENERATING_SCENE; + break; + case GENERATING_SCENE: + generateScene(); + currentProgress = LoadingProgress.LOADING_PLAYER; + break; + case LOADING_PLAYER: + loadPlayer(); + currentProgress = LoadingProgress.DONE; + break; + case DONE: + done(); + break; + } + } catch (Exception ex) { + ex.printStackTrace(); + stateManager.setState(State.MENU); } gui.updateProgress(currentProgress); } - private void initAudioAnalysis() { + private boolean initAudioAnalysis() { GameState gs = stateManager.getState(State.GAME); - audioDataManager.initialize(gs.getSettings(), gs.getMediaPlayer()); //TODO path + return audioDataManager.initialize(gs.getSettings(), gs.getMediaPlayer()); + } + + private void convertAudio() throws Exception { + String sourceChecksum = ChecksumHelper.createMD5(settings.getVideoFile()); + String audioPath = PathHelper.getCacheFolder() + sourceChecksum + ".ogg"; + if (!new File(audioPath).exists()) { + new OggConverter().convert(settings.getVideoFile(), audioPath, 192); + } + settings.setAudioFile(audioPath); } private void analyseLowBand() { @@ -114,7 +142,7 @@ public class LoadingState extends AbstractAppState { audioDataManager.analyseHighBand(); } - private void initAudioPlayer() { + private void initAudioPlayer() throws Exception { GameState gs = stateManager.getState(State.GAME); gs.initMediaPlayer(); } diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/SelectTrackState.java b/ShootingStars/src/org/wyrez/shootingstars/states/SelectTrackState.java index 3e61f57..f9891b3 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/SelectTrackState.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/SelectTrackState.java @@ -29,20 +29,20 @@ import tonegod.gui.core.Screen; * * @author Snowsun */ -public class SelectTrackState extends AbstractAppState implements SelectFileListener{ +public class SelectTrackState extends AbstractAppState implements SelectFileListener { private StateManager stateManager; private GameSettings settings; private SelectTrackGUI gui; - + public SelectTrackState(Screen screen, StateManager stateManager, GameSettings settings) { this.stateManager = stateManager; this.settings = settings; this.gui = new SelectTrackGUI(screen, this); } - + @Override - public void stateAttached(AppStateManager stateManager) { + public void stateAttached(AppStateManager stateManager) { gui.attach(); } @@ -57,7 +57,7 @@ public class SelectTrackState extends AbstractAppState implements SelectFileList if (returnVal == JFileChooser.APPROVE_OPTION) { File file = jFileChooser.getSelectedFile(); - settings.setAudioFile(file.getAbsolutePath()); + settings.setVideoFile(file.getPath()); stateManager.setState(State.FILEMETAINFO); } } diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/YTDownloadState.java b/ShootingStars/src/org/wyrez/shootingstars/states/YTDownloadState.java index ca1657d..438c14c 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/YTDownloadState.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/YTDownloadState.java @@ -18,43 +18,45 @@ package org.wyrez.shootingstars.states; import com.jme3.app.state.AbstractAppState; import com.jme3.app.state.AppStateManager; +import org.wyrez.shootingstars.data.YTDownloader; import org.wyrez.shootingstars.game.GameSettings; import org.wyrez.shootingstars.gui.YTDownloadGUI; import org.wyrez.shootingstars.gui.listener.YTDownloadListener; +import org.wyrez.shootingstars.helper.PathHelper; import tonegod.gui.core.Screen; /** * * @author Snowsun */ -public class YTDownloadState extends AbstractAppState implements YTDownloadListener{ - +public class YTDownloadState extends AbstractAppState implements YTDownloadListener { + private StateManager stateManager; private GameSettings settings; private YTDownloadGUI gui; + private YTDownloader downloader; - - public YTDownloadState(Screen screen, StateManager stateManager, GameSettings settings) { + public YTDownloadState(Screen screen, StateManager stateManager, + GameSettings settings, YTDownloader downloader) { this.stateManager = stateManager; this.settings = settings; this.gui = new YTDownloadGUI(screen, this); + this.downloader = downloader; } - + @Override - public void stateAttached(AppStateManager stateManager) { + public void stateAttached(AppStateManager stateManager) { gui.attach(); } - + @Override public void stateDetached(AppStateManager stateManager) { gui.detach(); } public void downloadYTVideo(String url) { - //TODO: Download Video - System.out.println(url); + downloader.download(url, PathHelper.getCacheFolder()); + settings.setVideoFile(downloader.getLastTarget().getPath()); stateManager.setState(State.FILEMETAINFO); } - - } diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/util/LoadingProgress.java b/ShootingStars/src/org/wyrez/shootingstars/states/util/LoadingProgress.java index 549b273..0c00981 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/util/LoadingProgress.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/util/LoadingProgress.java @@ -26,6 +26,7 @@ public enum LoadingProgress { LOADING_CINEMA("Loading Cinema", 1), INIT_AUDIO_PLAYER("Loading Audio-Player...", 2), INIT_AUDIO_ANALYSIS("Creating Samples...", 3), + CONVERT_AUDIO("Converting...", 3), ANALYSE_LOW_BAND("Analyse Low-Band...", 4), ANALYSE_MID_BAND("Analyse Mid-Band...", 5), ANALYSE_HIGH_BAND("Analyse High-Band...", 6),