fixed sync issue with songs (not sure what de-sync caused by as issue does not exist on other computer)

This commit is contained in:
Harrison Deng 2017-09-12 19:48:51 -05:00
parent d26cef0cb1
commit 373a524010
26 changed files with 200 additions and 144 deletions

View File

@ -12,7 +12,7 @@ import zero1hd.rhythmbullet.util.MiniSender;
public class AudioAnalyzer { public class AudioAnalyzer {
private boolean containsData; private boolean containsData;
private MusicDataPack musicInfo; private MusicManager musicInfo;
float[] audioPCM; float[] audioPCM;
float[] spectrum; float[] spectrum;
@ -56,7 +56,7 @@ public class AudioAnalyzer {
private float secondsPerWindow; private float secondsPerWindow;
private AudioDataPackage pack; private AudioDataPackage pack;
public AudioAnalyzer(MusicDataPack audiofile) { public AudioAnalyzer(MusicManager audiofile) {
sender = new MiniSender(); sender = new MiniSender();
analysisAlgorithm = () -> { analysisAlgorithm = () -> {

View File

@ -9,7 +9,7 @@ public class AudioDataPackage {
private FloatArray mPeaks; private FloatArray mPeaks;
private FloatArray umPeaks; private FloatArray umPeaks;
private MusicDataPack musicInfo; private MusicManager musicInfo;
private float bassMaxVal, bassAvg; private float bassMaxVal, bassAvg;
private float mMaxVal, mAvg; private float mMaxVal, mAvg;
@ -64,7 +64,7 @@ public class AudioDataPackage {
this.uMAvg = uMAvg; this.uMAvg = uMAvg;
} }
public void setMusicInfo(MusicDataPack musicInfo) { public void setMusicInfo(MusicManager musicInfo) {
if (this.musicInfo != null) { if (this.musicInfo != null) {
throw new InvalidParameterException("There is already music information in this package."); 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) { if (musicInfo == null) {
throw new NullPointerException("Music info hasn't been baked in..."); throw new NullPointerException("Music info hasn't been baked in...");
} }

View File

@ -9,6 +9,7 @@ import org.jaudiotagger.tag.TagException;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Music.OnCompletionListener;
import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.utils.GdxRuntimeException; import com.badlogic.gdx.utils.GdxRuntimeException;
@ -20,7 +21,7 @@ import javazoom.jl.decoder.Header;
import javazoom.jl.decoder.MP3Decoder; import javazoom.jl.decoder.MP3Decoder;
import javazoom.jl.decoder.OutputBuffer; import javazoom.jl.decoder.OutputBuffer;
public class Mp3AudioData implements MusicDataPack { public class Mp3AudioData implements MusicManager {
private int readWindowSize = 1024; private int readWindowSize = 1024;
private int currentReadWindowIndex; private int currentReadWindowIndex;
@ -64,7 +65,6 @@ public class Mp3AudioData implements MusicDataPack {
playbackMusic = Gdx.audio.newMusic(audioFile); playbackMusic = Gdx.audio.newMusic(audioFile);
reset();
} }
@Override @Override
@ -77,21 +77,11 @@ public class Mp3AudioData implements MusicDataPack {
return readIndex; return readIndex;
} }
@Override
public void reset() {
playbackMusic.stop();
}
@Override @Override
public int getReadWindowSize() { public int getReadWindowSize() {
return readWindowSize; return readWindowSize;
} }
@Override
public Music getPlaybackMusic() {
return playbackMusic;
}
@Override @Override
public long getSampleCount() { public long getSampleCount() {
return sampleCount; return sampleCount;
@ -99,7 +89,7 @@ public class Mp3AudioData implements MusicDataPack {
@Override @Override
public void dispose() { public void dispose() {
reset(); playbackMusic.stop();
playbackMusic.dispose(); playbackMusic.dispose();
try { try {
bitstream.close(); bitstream.close();
@ -184,4 +174,39 @@ public class Mp3AudioData implements MusicDataPack {
public int getCurrentReadWindowIndex() { public int getCurrentReadWindowIndex() {
return currentReadWindowIndex; 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);
}
} }

View File

@ -1,10 +1,10 @@
package zero1hd.rhythmbullet.audio; package zero1hd.rhythmbullet.audio;
import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.audio.Music.OnCompletionListener;
import com.badlogic.gdx.utils.Disposable; 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. * 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. * 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(); 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. * returns the read window size.
* @return * @return
*/ */
public int getReadWindowSize(); public int getReadWindowSize();
/**
* Gets the object to play the music. Contains playback data.
* @return
*/
public Music getPlaybackMusic();
/** /**
* read in samples and fills the array. * read in samples and fills the array.
* @param samples the array that should contain said samples * @param samples the array that should contain said samples
@ -65,4 +54,18 @@ public interface MusicDataPack extends Disposable {
* @return * @return
*/ */
public int getCurrentReadWindowIndex(); 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);
} }

View File

@ -26,7 +26,7 @@ public class SongList {
this.searchPath = searchPath; this.searchPath = searchPath;
} }
public MusicDataPack getAudioData(FileHandle file) { public MusicManager getAudioData(FileHandle file) {
if (file.extension().equalsIgnoreCase("wav")) { if (file.extension().equalsIgnoreCase("wav")) {
return new WavAudioData(file); return new WavAudioData(file);
} else if (file.extension().equalsIgnoreCase("mp3")) { } else if (file.extension().equalsIgnoreCase("mp3")) {
@ -35,7 +35,7 @@ public class SongList {
return null; return null;
} }
public MusicDataPack getMusicInfoFromIndex(int index) { public MusicManager getMusicInfoFromIndex(int index) {
if (index > songList.size) { if (index > songList.size) {
return null; return null;
} }

View File

@ -11,9 +11,9 @@ import com.badlogic.gdx.utils.Array;
import zero1hd.rhythmbullet.events.OnDifferentSongListener; import zero1hd.rhythmbullet.events.OnDifferentSongListener;
public class SongController implements OnCompletionListener { public class SongListController implements OnCompletionListener {
private SongList songList; private SongList songList;
private MusicDataPack mdp; private MusicManager mdp;
private int currentPlaybackID; private int currentPlaybackID;
private boolean autoPlay; private boolean autoPlay;
private boolean shuffle; private boolean shuffle;
@ -22,7 +22,7 @@ public class SongController implements OnCompletionListener {
private Array<OnDifferentSongListener> listeners; private Array<OnDifferentSongListener> listeners;
private Preferences prefs; 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 (prefs == null) throw new NullPointerException("preferences can't be null...");
if (songList == null) throw new NullPointerException("song list 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."); 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() { public void play() {
mdp.getPlaybackMusic().play(); mdp.play();
mdp.getPlaybackMusic().setVolume(prefs.getFloat("music vol"));; mdp.setVolume(prefs.getFloat("music vol"));
} }
public void setSongByIndex(int index) { public void setSongByIndex(int index) {
@ -101,7 +101,7 @@ public class SongController implements OnCompletionListener {
if (mdp == null) { if (mdp == null) {
mdp = songList.getAudioData(Gdx.files.internal("music/default.mp3")); mdp = songList.getAudioData(Gdx.files.internal("music/default.mp3"));
} }
mdp.getPlaybackMusic().setOnCompletionListener(this); mdp.setOnCompletionListener(this);
sendEvent(); sendEvent();
} }
@ -123,7 +123,7 @@ public class SongController implements OnCompletionListener {
listeners.removeValue(listener, true); listeners.removeValue(listener, true);
} }
public MusicDataPack getCurrentSong() { public MusicManager getCurrentSong() {
return mdp; return mdp;
} }
} }

View File

@ -7,20 +7,20 @@ import javax.sound.sampled.AudioFormat;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Music.OnCompletionListener;
import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.files.FileHandle;
import zero1hd.rhythmbullet.audio.wavedecoder.WavDecoder; import zero1hd.rhythmbullet.audio.wavedecoder.WavDecoder;
public class WavAudioData implements MusicDataPack { public class WavAudioData implements MusicManager {
private int readWindowSize = 1024; private int readWindowSize = 1024;
private AudioFormat format; private AudioFormat format;
private int readIndex; private int readIndex;
private int currentReadWindowIndex; private int currentReadWindowIndex;
Music playbackMusic; private Music playbackMusic;
WavDecoder decoder; WavDecoder decoder;
public WavAudioData(FileHandle file) { public WavAudioData(FileHandle file) {
reset();
try { try {
decoder = new WavDecoder(file); decoder = new WavDecoder(file);
} catch (InvalidParameterException | IOException e) { } catch (InvalidParameterException | IOException e) {
@ -41,23 +41,11 @@ public class WavAudioData implements MusicDataPack {
return readIndex; return readIndex;
} }
@Override
public void reset() {
if (playbackMusic != null) {
playbackMusic.stop();
}
}
@Override @Override
public int getReadWindowSize() { public int getReadWindowSize() {
return readWindowSize; return readWindowSize;
} }
@Override
public Music getPlaybackMusic() {
return playbackMusic;
}
@Override @Override
public int readSamples(float[] samples) { public int readSamples(float[] samples) {
int samplesRead = 0; int samplesRead = 0;
@ -80,7 +68,7 @@ public class WavAudioData implements MusicDataPack {
@Override @Override
public void dispose() { public void dispose() {
reset(); playbackMusic.stop();
playbackMusic.dispose(); playbackMusic.dispose();
decoder.cleanAndClose(); decoder.cleanAndClose();
} }
@ -99,4 +87,41 @@ public class WavAudioData implements MusicDataPack {
public int getCurrentReadWindowIndex() { public int getCurrentReadWindowIndex() {
return currentReadWindowIndex; 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);
}
} }

View File

@ -1,13 +1,13 @@
package zero1hd.rhythmbullet.audio.map; package zero1hd.rhythmbullet.audio.map;
import zero1hd.rhythmbullet.audio.MusicDataPack; import zero1hd.rhythmbullet.audio.MusicManager;
import zero1hd.rhythmbullet.entity.Entity; import zero1hd.rhythmbullet.entity.Entity;
import zero1hd.rhythmbullet.entity.EntityFrame; import zero1hd.rhythmbullet.entity.EntityFrame;
import zero1hd.rhythmbullet.entity.coordinator.Coordinator; import zero1hd.rhythmbullet.entity.coordinator.Coordinator;
import zero1hd.rhythmbullet.entity.coordinator.CoordinatorFrame; import zero1hd.rhythmbullet.entity.coordinator.CoordinatorFrame;
public class GamePlayMap { public class GamePlayMap {
private MusicDataPack musicData; private MusicManager musicData;
private MapWindowData[] spawnList; private MapWindowData[] spawnList;
private boolean building; private boolean building;
private int index; 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 * GamePlayMap is what the game area will use to generate entities and judge current audio data
* @param audioData audio data * @param audioData audio data
*/ */
public GamePlayMap(MusicDataPack audioData, int totalWindows) { public GamePlayMap(MusicManager audioData, int totalWindows) {
this.musicData = audioData; this.musicData = audioData;
spawnList = new MapWindowData[totalWindows]; spawnList = new MapWindowData[totalWindows];
hudType = new byte[totalWindows]; hudType = new byte[totalWindows];
@ -68,7 +68,7 @@ public class GamePlayMap {
index = spawnList.length-1; index = spawnList.length-1;
} }
public MusicDataPack getMusicData() { public MusicManager getMusicData() {
return musicData; return musicData;
} }

View File

@ -10,7 +10,7 @@ import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import zero1hd.rhythmbullet.audio.MusicDataPack; import zero1hd.rhythmbullet.audio.MusicManager;
public class BasicVisualizer extends VisualizerCore { public class BasicVisualizer extends VisualizerCore {
private Pixmap pixmap; private Pixmap pixmap;
@ -52,7 +52,7 @@ public class BasicVisualizer extends VisualizerCore {
@Override @Override
public void render(Batch batch, float parentAlpha) { public void render(Batch batch, float parentAlpha) {
if (cmi != null) { if (mm != null) {
//Averaging bins together //Averaging bins together
for (int i = 0; i < barCount; i++) { for (int i = 0; i < barCount; i++) {
bars[i].setSize(barWidth, 0); bars[i].setSize(barWidth, 0);
@ -85,8 +85,8 @@ public class BasicVisualizer extends VisualizerCore {
} }
@Override @Override
public void setMDP(MusicDataPack mdp) { public void setMM(MusicManager mdp) {
super.setMDP(mdp); super.setMM(mdp);
float validBins = (5000/((mdp.getSampleRate()/2)/((audioPCM.length/2)+1))); float validBins = (5000/((mdp.getSampleRate()/2)/((audioPCM.length/2)+1)));
Gdx.app.debug("Visualizer", "valid frequency bins " + validBins); Gdx.app.debug("Visualizer", "valid frequency bins " + validBins);
binsPerBar = MathUtils.round((validBins/barCount)); binsPerBar = MathUtils.round((validBins/barCount));

View File

@ -4,10 +4,10 @@ import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.utils.Disposable; import com.badlogic.gdx.utils.Disposable;
import edu.emory.mathcs.jtransforms.fft.FloatFFT_1D; import edu.emory.mathcs.jtransforms.fft.FloatFFT_1D;
import zero1hd.rhythmbullet.audio.MusicDataPack; import zero1hd.rhythmbullet.audio.MusicManager;
public class VisualizerCore implements Disposable { public class VisualizerCore implements Disposable {
protected MusicDataPack cmi; protected MusicManager mm;
private FloatFFT_1D fft; private FloatFFT_1D fft;
float[] audioPCM; float[] audioPCM;
protected int width, height; protected int width, height;
@ -22,18 +22,22 @@ public class VisualizerCore implements Disposable {
} }
public void calculate() { public void calculate() {
if (cmi != null) { if (mm != null) {
if (cmi.getPlaybackIndexPosition() > cmi.getCurrentReadWindowIndex()) { mm.playbackIndexUpdate();
cmi.readSamples(audioPCM); if (mm.getPlaybackIndexPosition() > mm.getCurrentReadWindowIndex()) {
while (mm.getPlaybackIndexPosition() > mm.getCurrentReadWindowIndex()) {
mm.readSamples(audioPCM);
fft.realForward(audioPCM); fft.realForward(audioPCM);
System.out.println(mm.getPlaybackIndexPosition() + " " + mm.getCurrentReadWindowIndex());
}
} }
} }
} }
public void setMDP(MusicDataPack cmi) { public void setMM(MusicManager mm) {
this.cmi = cmi; this.mm = mm;
fft = new FloatFFT_1D(cmi.getReadWindowSize()); fft = new FloatFFT_1D(mm.getReadWindowSize());
audioPCM = new float[cmi.getReadWindowSize()]; audioPCM = new float[mm.getReadWindowSize()];
} }
public void render(Batch batch, float parentAlpha) { public void render(Batch batch, float parentAlpha) {

View File

@ -1,6 +1,6 @@
package zero1hd.rhythmbullet.events; package zero1hd.rhythmbullet.events;
import zero1hd.rhythmbullet.audio.MusicDataPack; import zero1hd.rhythmbullet.audio.MusicManager;
public interface OnDifferentSongListener { public interface OnDifferentSongListener {
@ -8,5 +8,5 @@ public interface OnDifferentSongListener {
* Called whenever the Song Controller moves to a different song. * Called whenever the Song Controller moves to a different song.
* @param mdp contains the next songs basic music system. * @param mdp contains the next songs basic music system.
*/ */
public void onDifferentSong(MusicDataPack mdp); public void onDifferentSong(MusicManager mdp);
} }

View File

@ -14,7 +14,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.MusicDataPack; import zero1hd.rhythmbullet.audio.MusicManager;
import zero1hd.rhythmbullet.audio.map.GamePlayMap; import zero1hd.rhythmbullet.audio.map.GamePlayMap;
import zero1hd.rhythmbullet.stages.GameHUD; import zero1hd.rhythmbullet.stages.GameHUD;
import zero1hd.rhythmbullet.stages.GamePlayArea; import zero1hd.rhythmbullet.stages.GamePlayArea;
@ -27,7 +27,7 @@ public class GameScreen extends ScreenAdapter {
protected InputMultiplexer inputs; protected InputMultiplexer inputs;
public RhythmBullet core; public RhythmBullet core;
private MusicDataPack music; private MusicManager music;
private ShaderProgram gaussianBlurShader; private ShaderProgram gaussianBlurShader;
private ShaderProgram brightFilterShader; private ShaderProgram brightFilterShader;
@ -69,7 +69,7 @@ public class GameScreen extends ScreenAdapter {
public void setGamePlayMap(GamePlayMap gpm) { public void setGamePlayMap(GamePlayMap gpm) {
music = gpm.getMusicData(); music = gpm.getMusicData();
gameArea.setAudioMap(gpm); gameArea.setAudioMap(gpm);
gameHUD.setMusic(gpm.getMusicData().getPlaybackMusic()); gameHUD.setMusic(gpm.getMusicData());
} }
@Override @Override
@ -222,7 +222,7 @@ public class GameScreen extends ScreenAdapter {
gameHUD.getViewport().apply(); gameHUD.getViewport().apply();
gameHUD.draw(); gameHUD.draw();
if (music != null && !music.getPlaybackMusic().isPlaying()) { if (music != null && !music.isPlaying()) {
end(true); 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..."); 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); Gdx.input.setInputProcessor(inputs);
if (!gameHUD.isPaused()) { if (!gameHUD.isPaused()) {
music.getPlaybackMusic().play(); music.play();
} }
} }
} }

View File

@ -12,7 +12,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.viewport.ScreenViewport; import com.badlogic.gdx.utils.viewport.ScreenViewport;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.SongController; import zero1hd.rhythmbullet.audio.SongListController;
import zero1hd.rhythmbullet.audio.SongList; import zero1hd.rhythmbullet.audio.SongList;
import zero1hd.rhythmbullet.ui.pages.CreditsPage; import zero1hd.rhythmbullet.ui.pages.CreditsPage;
import zero1hd.rhythmbullet.ui.pages.MainPage; import zero1hd.rhythmbullet.ui.pages.MainPage;
@ -31,7 +31,7 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter {
private RhythmBullet core; private RhythmBullet core;
private SongController sc; private SongListController sc;
private float lerpAlpha; private float lerpAlpha;
public MainMenu(final RhythmBullet core) { public MainMenu(final RhythmBullet core) {
this.core = core; this.core = core;
@ -42,11 +42,9 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter {
songList.setSearchPath(core.getPrefs().getString("music dir")); songList.setSearchPath(core.getPrefs().getString("music dir"));
songList.refresh(); songList.refresh();
sc = new SongController(songList, core.getPrefs()); sc = new SongListController(songList, core.getPrefs());
sc.setAutoPlay(true); sc.setAutoPlay(true);
sc.setShuffle(true); sc.setShuffle(true);
sc.play();
postTransition(); postTransition();
} }
@ -111,6 +109,7 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter {
@Override @Override
public void show() { public void show() {
Gdx.input.setInputProcessor(stage); Gdx.input.setInputProcessor(stage);
sc.play();
calcLerpAlpha(Gdx.graphics.getWidth()); calcLerpAlpha(Gdx.graphics.getWidth());
super.show(); super.show();
} }
@ -139,8 +138,6 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter {
stage.getCamera().position.lerp(targetPosition, lerpAlpha); stage.getCamera().position.lerp(targetPosition, lerpAlpha);
} }
sc.getCurrentSong().playbackIndexUpdate();
super.render(delta); super.render(delta);
} }

View File

@ -279,7 +279,7 @@ public class CreativeHUD extends Stage implements MiniListener {
mGraphWindow.normalDataG1 = adp.getmMaxVal(); mGraphWindow.normalDataG1 = adp.getmMaxVal();
mGraphWindow.avgG1 = adp.getmAvg(); mGraphWindow.avgG1 = adp.getmAvg();
gpa.setAudioMap(mapGen.getMap()); gpa.setAudioMap(mapGen.getMap());
ghud.setMusic(adp.getMusicInfo().getPlaybackMusic()); ghud.setMusic(adp.getMusicInfo());
break; break;
default: default:
break; break;

View File

@ -7,8 +7,8 @@ import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format; 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;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions; 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 com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.MusicManager;
import zero1hd.rhythmbullet.ui.components.HealthBar; import zero1hd.rhythmbullet.ui.components.HealthBar;
import zero1hd.rhythmbullet.ui.windows.FPSWindow; import zero1hd.rhythmbullet.ui.windows.FPSWindow;
import zero1hd.rhythmbullet.ui.windows.PauseMenu; import zero1hd.rhythmbullet.ui.windows.PauseMenu;
@ -38,7 +39,7 @@ public class GameHUD extends Stage {
private Image leftStatusBar; private Image leftStatusBar;
private Image rightStatusBar; private Image rightStatusBar;
private GamePlayArea gpa; private GamePlayArea gpa;
private Music music; private MusicManager music;
private ScoreManager sm; private ScoreManager sm;
private Color original, bass, um; private Color original, bass, um;
@ -203,7 +204,7 @@ public class GameHUD extends Stage {
return false; return false;
} }
public void setMusic(Music music) { public void setMusic(MusicManager music) {
this.music = music; this.music = music;
} }

View File

@ -59,7 +59,7 @@ public class GamePlayArea extends Stage {
@Override @Override
public void act(float delta) { public void act(float delta) {
MapWindowData mwd; MapWindowData mwd;
if (audioMap != null && audioMap.getMusicData().getPlaybackMusic().isPlaying()) { if (audioMap != null && audioMap.getMusicData().isPlaying()) {
audioMap.getMusicData().playbackIndexUpdate(); audioMap.getMusicData().playbackIndexUpdate();
if ((mwd = audioMap.getCurrentWindowBasedOnIndex()) != null) { if ((mwd = audioMap.getCurrentWindowBasedOnIndex()) != null) {
EntitySpawnInfo[] currentSpawnInfo = mwd.getArray(); EntitySpawnInfo[] currentSpawnInfo = mwd.getArray();

View File

@ -9,10 +9,10 @@ import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.utils.FloatArray; import com.badlogic.gdx.utils.FloatArray;
import zero1hd.rhythmbullet.audio.MusicDataPack; import zero1hd.rhythmbullet.audio.MusicManager;
public class AudioGraph extends Actor { public class AudioGraph extends Actor {
private MusicDataPack audioData; private MusicManager audioData;
ShapeRenderer shapeRender; ShapeRenderer shapeRender;
FloatArray mainGraph; FloatArray mainGraph;
FloatArray overlayGraph; FloatArray overlayGraph;
@ -134,7 +134,7 @@ public class AudioGraph extends Actor {
* @param dataSet2 overlay graph. This one can be null. * @param dataSet2 overlay graph. This one can be null.
* @param audioData actual basic audio information for index position * @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.mainGraph = dataSet1;
this.overlayGraph = dataSet2; this.overlayGraph = dataSet2;
if (dataSet2 == null) { if (dataSet2 == null) {

View File

@ -9,10 +9,10 @@ import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.utils.FloatArray; import com.badlogic.gdx.utils.FloatArray;
import zero1hd.rhythmbullet.audio.MusicDataPack; import zero1hd.rhythmbullet.audio.MusicManager;
public class AudioGraphRelation extends Actor { public class AudioGraphRelation extends Actor {
private MusicDataPack audioData; private MusicManager audioData;
ShapeRenderer shapeRender; ShapeRenderer shapeRender;
FloatArray mainGraph; FloatArray mainGraph;
FloatArray overlayGraph; FloatArray overlayGraph;
@ -134,7 +134,7 @@ public class AudioGraphRelation extends Actor {
* @param dataSet2 overlay graph. This one can be null. * @param dataSet2 overlay graph. This one can be null.
* @param audioData actual basic audio information for index position * @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.mainGraph = dataSet1;
this.overlayGraph = dataSet2; this.overlayGraph = dataSet2;
if (dataSet2 == null) { if (dataSet2 == null) {

View File

@ -4,7 +4,7 @@ import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.ui.Widget; import com.badlogic.gdx.scenes.scene2d.ui.Widget;
import zero1hd.rhythmbullet.audio.MusicDataPack; import zero1hd.rhythmbullet.audio.MusicManager;
import zero1hd.rhythmbullet.audio.visualizer.BasicVisualizer; import zero1hd.rhythmbullet.audio.visualizer.BasicVisualizer;
public class Visualizer extends Widget { public class Visualizer extends Widget {
@ -31,8 +31,8 @@ public class Visualizer extends Widget {
} }
public void setMDP(MusicDataPack mdp) { public void setMDP(MusicManager mdp) {
vis.setMDP(mdp); vis.setMM(mdp);
} }
@Override @Override

View File

@ -19,7 +19,7 @@ import com.badlogic.gdx.utils.Disposable;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.AudioAnalyzer; import zero1hd.rhythmbullet.audio.AudioAnalyzer;
import zero1hd.rhythmbullet.audio.MusicDataPack; import zero1hd.rhythmbullet.audio.MusicManager;
import zero1hd.rhythmbullet.audio.SongInfo; import zero1hd.rhythmbullet.audio.SongInfo;
import zero1hd.rhythmbullet.audio.map.GamePlayMap; import zero1hd.rhythmbullet.audio.map.GamePlayMap;
import zero1hd.rhythmbullet.audio.map.RhythmMapAlgorithm; import zero1hd.rhythmbullet.audio.map.RhythmMapAlgorithm;
@ -32,7 +32,7 @@ public class AnalyzePage extends Page implements MiniListener, Disposable {
private AnalyzePage ap = this; private AnalyzePage ap = this;
AudioAnalyzer audioAnalyzer; AudioAnalyzer audioAnalyzer;
MusicDataPack music; MusicManager music;
RhythmMapAlgorithm mapGenAlgorithm; RhythmMapAlgorithm mapGenAlgorithm;
private Table songInfo; private Table songInfo;
@ -186,7 +186,7 @@ public class AnalyzePage extends Page implements MiniListener, Disposable {
addActor(back); addActor(back);
} }
public void setSong(MusicDataPack music, SongInfo audioInfo, MiniListener listener) { public void setSong(MusicManager music, SongInfo audioInfo, MiniListener listener) {
confirmed = false; confirmed = false;
confirmDiffButton.setDisabled(false); confirmDiffButton.setDisabled(false);
sensitivityRating.setDisabled(false); sensitivityRating.setDisabled(false);

View File

@ -15,8 +15,8 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.MusicDataPack; import zero1hd.rhythmbullet.audio.MusicManager;
import zero1hd.rhythmbullet.audio.SongController; import zero1hd.rhythmbullet.audio.SongListController;
import zero1hd.rhythmbullet.audio.visualizer.BasicVisualizer; import zero1hd.rhythmbullet.audio.visualizer.BasicVisualizer;
import zero1hd.rhythmbullet.events.OnDifferentSongListener; import zero1hd.rhythmbullet.events.OnDifferentSongListener;
import zero1hd.rhythmbullet.screens.PreGameScreen; import zero1hd.rhythmbullet.screens.PreGameScreen;
@ -32,10 +32,10 @@ public class MainPage extends Page implements OnDifferentSongListener {
private TextButton credits; private TextButton credits;
private WidgetGroup playButton; private WidgetGroup playButton;
private SongController sc; private SongListController sc;
private Visualizer hvisual; private Visualizer hvisual;
public MainPage(RhythmBullet core, Vector3 targetPosition, SongController sc) { public MainPage(RhythmBullet core, Vector3 targetPosition, SongListController sc) {
hvisual = new Visualizer(); hvisual = new Visualizer();
this.sc = sc; this.sc = sc;
sc.addOnDifferentSongListener(this); sc.addOnDifferentSongListener(this);
@ -129,7 +129,7 @@ public class MainPage extends Page implements OnDifferentSongListener {
} }
@Override @Override
public void onDifferentSong(MusicDataPack mdp) { public void onDifferentSong(MusicManager mdp) {
hvisual.setMDP(mdp); hvisual.setMDP(mdp);
} }
} }

View File

@ -17,7 +17,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.SongController; import zero1hd.rhythmbullet.audio.SongListController;
import zero1hd.rhythmbullet.screens.CreativeScreen; import zero1hd.rhythmbullet.screens.CreativeScreen;
import zero1hd.rhythmbullet.screens.MainMenu; import zero1hd.rhythmbullet.screens.MainMenu;
@ -27,7 +27,7 @@ public class OptionsPage extends Page {
private ProgressBar fxVolSlider; private ProgressBar fxVolSlider;
private TextField directoryField; 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(); optionsTable.defaults().spaceLeft(40f).padTop(5f).padBottom(5f).left();
Label optionGeneralTitle = new Label("General", core.getDefaultSkin(), "large-font", core.getDefaultSkin().getColor("default")); Label optionGeneralTitle = new Label("General", core.getDefaultSkin(), "large-font", core.getDefaultSkin().getColor("default"));
@ -45,7 +45,7 @@ public class OptionsPage extends Page {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
musicVolPercentage.setText(MathUtils.round(musicVolSlider.getValue()) + "%"); musicVolPercentage.setText(MathUtils.round(musicVolSlider.getValue()) + "%");
sc.getCurrentSong().getPlaybackMusic().setVolume(musicVolSlider.getPercent()); sc.getCurrentSong().setVolume(musicVolSlider.getPercent());
core.getPrefs().putFloat("music vol", musicVolSlider.getPercent()); core.getPrefs().putFloat("music vol", musicVolSlider.getPercent());
} }

View File

@ -10,12 +10,12 @@ import com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup;
import com.badlogic.gdx.scenes.scene2d.ui.Window; import com.badlogic.gdx.scenes.scene2d.ui.Window;
import zero1hd.rhythmbullet.audio.AudioDataPackage; import zero1hd.rhythmbullet.audio.AudioDataPackage;
import zero1hd.rhythmbullet.audio.MusicDataPack; import zero1hd.rhythmbullet.audio.MusicManager;
public class BeatViewer extends Window { public class BeatViewer extends Window {
Pixmap lights; Pixmap lights;
int songIndex; int songIndex;
MusicDataPack music; MusicManager music;
Texture lightOn; Texture lightOn;
private AudioDataPackage data; private AudioDataPackage data;
@ -125,7 +125,7 @@ public class BeatViewer extends Window {
super.act(delta); super.act(delta);
} }
public void setMusic(MusicDataPack audioData, AudioDataPackage adp) { public void setMusic(MusicManager audioData, AudioDataPackage adp) {
this.music = audioData; this.music = audioData;
this.data = adp; this.data = adp;
} }

View File

@ -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.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; 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 { public class MusicController extends Window implements OnCompletionListener {
Skin skin; Skin skin;
private Image togglePlay; private Image togglePlay;
private TextField info; private TextField info;
private MusicDataPack audiofile; private MusicManager audiofile;
public MusicController(final Skin skin) { public MusicController(final Skin skin) {
super("Playback Controller", skin, "tinted"); super("Playback Controller", skin, "tinted");
@ -34,10 +34,8 @@ public class MusicController extends Window implements OnCompletionListener {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
if (audiofile.getPlaybackMusic() != null) { audiofile.setPosition(audiofile.getPosition() - 2);
audiofile.getPlaybackMusic().setPosition(audiofile.getPlaybackMusic().getPosition() - 2); info.setText(String.valueOf(MathUtils.round(audiofile.getPosition())) + " sec");
info.setText(String.valueOf(MathUtils.round(audiofile.getPlaybackMusic().getPosition())) + " sec");
}
} }
}); });
@ -53,14 +51,14 @@ public class MusicController extends Window implements OnCompletionListener {
@Override @Override
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
if (audiofile != null) { if (audiofile != null) {
if (audiofile.getPlaybackMusic().isPlaying()) { if (audiofile.isPlaying()) {
audiofile.getPlaybackMusic().pause(); audiofile.pause();
togglePlay.setDrawable(skin.getDrawable("arrow")); togglePlay.setDrawable(skin.getDrawable("arrow"));
} else { } else {
togglePlay.setDrawable(skin.getDrawable("pause")); togglePlay.setDrawable(skin.getDrawable("pause"));
audiofile.getPlaybackMusic().play(); audiofile.play();
} }
} }
super.clicked(event, x, y); super.clicked(event, x, y);
@ -73,9 +71,9 @@ public class MusicController extends Window implements OnCompletionListener {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
if (audiofile != null) { if (audiofile != null) {
audiofile.getPlaybackMusic().play(); audiofile.play();
audiofile.getPlaybackMusic().setPosition(audiofile.getPlaybackMusic().getPosition() + 2); audiofile.setPosition(audiofile.getPosition() + 2);
info.setText(String.valueOf(MathUtils.round(audiofile.getPlaybackMusic().getPosition())) + " sec"); 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") { info = new TextField(null, skin, "ui") {
@Override @Override
public void act(float delta) { public void act(float delta) {
if (audiofile != null && audiofile.getPlaybackMusic().isPlaying()) { if (audiofile != null && audiofile.isPlaying()) {
setText(String.valueOf(MathUtils.round(audiofile.getPlaybackMusic().getPosition())) + " sec"); setText(String.valueOf(MathUtils.round(audiofile.getPosition())) + " sec");
} }
super.act(delta); super.act(delta);
} }
@ -99,7 +97,7 @@ public class MusicController extends Window implements OnCompletionListener {
public boolean keyUp(InputEvent event, int keycode) { public boolean keyUp(InputEvent event, int keycode) {
if (keycode == Keys.ENTER) { if (keycode == Keys.ENTER) {
if (!info.getText().replaceAll("(?![0-9])\\S+", "").trim().isEmpty()) { 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); return super.keyUp(event, keycode);
@ -110,22 +108,25 @@ public class MusicController extends Window implements OnCompletionListener {
setSize(260, 75); setSize(260, 75);
} }
public void setAudiofile(MusicDataPack audiofile) { public void setAudiofile(MusicManager audiofile) {
this.audiofile = audiofile; this.audiofile = audiofile;
if (this.audiofile != null) {
this.audiofile.dispose();
this.audiofile = null;
}
if (audiofile == null) { if (audiofile == null) {
togglePlay.setDrawable(skin.getDrawable("loading")); togglePlay.setDrawable(skin.getDrawable("loading"));
info.setText("Analyzing..."); info.setText("Analyzing...");
} else { } else {
audiofile.reset();
togglePlay.setDrawable(skin.getDrawable("arrow")); togglePlay.setDrawable(skin.getDrawable("arrow"));
info.setText("Ready."); info.setText("Ready.");
audiofile.getPlaybackMusic().play(); audiofile.play();
audiofile.getPlaybackMusic().pause(); audiofile.pause();
audiofile.getPlaybackMusic().setOnCompletionListener(this); audiofile.setOnCompletionListener(this);
} }
} }
public MusicDataPack getAudiofile() { public MusicManager getAudiofile() {
return audiofile; return audiofile;
} }

View File

@ -11,7 +11,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import zero1hd.rhythmbullet.audio.MusicDataPack; import zero1hd.rhythmbullet.audio.MusicManager;
import zero1hd.rhythmbullet.audio.SongList; import zero1hd.rhythmbullet.audio.SongList;
import zero1hd.rhythmbullet.util.MiniEvents; import zero1hd.rhythmbullet.util.MiniEvents;
import zero1hd.rhythmbullet.util.MiniSender; import zero1hd.rhythmbullet.util.MiniSender;
@ -88,7 +88,7 @@ public class MusicSelector extends Window {
return isBack; return isBack;
} }
public MusicDataPack getSelectedMusic() { public MusicManager getSelectedMusic() {
if (selectedMusic != null) { if (selectedMusic != null) {
return songList.getAudioData(selectedMusic); return songList.getAudioData(selectedMusic);
} else { } else {

View File

@ -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.ui.Window;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import zero1hd.rhythmbullet.audio.MusicDataPack; import zero1hd.rhythmbullet.audio.MusicManager;
public class VolumeWindow extends Window { public class VolumeWindow extends Window {
@ -17,7 +17,7 @@ public class VolumeWindow extends Window {
private Slider musicVolSlider; private Slider musicVolSlider;
private Preferences prefs; private Preferences prefs;
private MusicDataPack music; private MusicManager music;
public VolumeWindow(String title, Skin skin, Preferences prefs) { public VolumeWindow(String title, Skin skin, Preferences prefs) {
super(title, skin, "tinted"); super(title, skin, "tinted");
this.prefs = prefs; this.prefs = prefs;
@ -35,7 +35,7 @@ public class VolumeWindow extends Window {
save(); save();
musicVolPercentage.setText(MathUtils.round(musicVolSlider.getValue()) + "%"); musicVolPercentage.setText(MathUtils.round(musicVolSlider.getValue()) + "%");
if (music != null) { 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(); prefs.flush();
} }
public void setMusic(MusicDataPack music) { public void setMusic(MusicManager music) {
this.music = music; this.music = music;
if (music != null) { if (music != null) {
music.getPlaybackMusic().setVolume(prefs.getFloat("music vol")/100f); music.setVolume(prefs.getFloat("music vol")/100f);
} }
} }
} }