fixing errors
This commit is contained in:
parent
dd4d6b502a
commit
0fff556332
@ -1,12 +1,11 @@
|
||||
package zero1hd.polyjet.audio;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.FloatArray;
|
||||
|
||||
import edu.emory.mathcs.jtransforms.fft.FloatFFT_1D;
|
||||
import zero1hd.polyjet.util.MiniEvents;
|
||||
import zero1hd.polyjet.util.MiniListener;
|
||||
import zero1hd.polyjet.util.MiniSender;
|
||||
|
||||
public class AudioAnalyzer {
|
||||
private boolean containsData;
|
||||
@ -45,11 +44,12 @@ public class AudioAnalyzer {
|
||||
int UMThresholdCalcRange;
|
||||
int bassThresholdCalcRange;
|
||||
|
||||
private Array<MiniListener> listeners;
|
||||
public MiniSender sender;
|
||||
|
||||
private volatile int progress;
|
||||
public AudioAnalyzer() {
|
||||
listeners = new Array<>();
|
||||
sender = new MiniSender();
|
||||
|
||||
|
||||
analysisAlgorithm = new Runnable() {
|
||||
|
||||
@ -113,7 +113,7 @@ public class AudioAnalyzer {
|
||||
shrinkData();
|
||||
containsData = true;
|
||||
|
||||
send(MiniEvents.SPECTRAL_FLUX_DONE);
|
||||
sender.send(MiniEvents.SPECTRAL_FLUX_DONE);
|
||||
}
|
||||
};
|
||||
|
||||
@ -196,6 +196,8 @@ public class AudioAnalyzer {
|
||||
Gdx.app.debug("Audio Analyzer", "overlapped beats checked.");
|
||||
|
||||
finalized = true;
|
||||
|
||||
sender.send(MiniEvents.MUSIC_DATA_CLEANED);
|
||||
}
|
||||
};
|
||||
|
||||
@ -304,14 +306,4 @@ public class AudioAnalyzer {
|
||||
public boolean isFinalized() {
|
||||
return finalized;
|
||||
}
|
||||
|
||||
public void addListener(MiniListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void send(MiniEvents ID) {
|
||||
while (listeners.iterator().hasNext()) {
|
||||
listeners.iterator().next().handle(ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,10 +8,11 @@ import javax.sound.sampled.AudioFormat;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.audio.Music;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
|
||||
import zero1hd.wavedecoder.WavDecoder;
|
||||
|
||||
public class WavAudioData implements AudioData {
|
||||
public class WavAudioData implements AudioData, Disposable {
|
||||
private int readWindowSize = 1024;
|
||||
private AudioFormat format;
|
||||
int readIndex;
|
||||
@ -46,8 +47,6 @@ public class WavAudioData implements AudioData {
|
||||
public void reset() {
|
||||
if (playbackMusic != null) {
|
||||
playbackMusic.stop();
|
||||
playbackMusic.dispose();
|
||||
playbackMusic = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,4 +74,9 @@ public class WavAudioData implements AudioData {
|
||||
public int getSampleCount() {
|
||||
return decoder.getDataSize()/(2*decoder.getChannels());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
playbackMusic.dispose();
|
||||
}
|
||||
}
|
||||
|
@ -53,8 +53,7 @@ public class MusicSelectionPage extends Page {
|
||||
});
|
||||
addActor(back);
|
||||
|
||||
loadingWindow = new LoadingWindow(core.getDefaultSkin(), "tinted", true, core.getAssetManager(), core.prefs.getFloat("fx vol"));
|
||||
loadingWindow.setPosition((getWidth()-loadingWindow.getWidth())/2f, (getHeight()-loadingWindow.getHeight())/2f);
|
||||
loadingWindow.setPosition((getWidth()-loadingWindow.getWidth())/2f, (getHeight()-loadingWindow.getHeight())/2f);
|
||||
addActor(loadingWindow);
|
||||
loadingWindow.playOpenSound();
|
||||
loadingWindow.setMovable(false);
|
||||
|
@ -17,6 +17,7 @@ public class Page extends Group {
|
||||
|
||||
public Page() {
|
||||
setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
listeners = new Array<>();
|
||||
setTouchable(Touchable.childrenOnly);
|
||||
}
|
||||
|
||||
@ -39,6 +40,9 @@ public class Page extends Group {
|
||||
}
|
||||
|
||||
public void addListener(MiniListener handler) {
|
||||
if (listeners == null) {
|
||||
Gdx.app.log("Test", "URS STEWPID");
|
||||
}
|
||||
listeners.add(handler);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.Window;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
import zero1hd.polyjet.audio.Audio;
|
||||
import zero1hd.polyjet.audio.AudioAnalyzer;
|
||||
import zero1hd.polyjet.audio.AudioData;
|
||||
import zero1hd.polyjet.screens.MainMenu;
|
||||
@ -39,15 +38,14 @@ public class CreativeStage extends Stage implements MiniListener {
|
||||
AudioAnalyzer analyzer;
|
||||
Window toolbox;
|
||||
Polyjet core;
|
||||
private AudioData audioWrapper;
|
||||
|
||||
public CreativeStage(final Polyjet core, final MainMenu mainMenu) {
|
||||
this.core = core;
|
||||
analyzer = new AudioAnalyzer();
|
||||
analyzer.addListener(this);
|
||||
analyzer.sender.addListener(this);
|
||||
|
||||
musicSelector = new MusicSelector("Select Audio File", core.getDefaultSkin(), core.prefs.getString("music dir"), "default");
|
||||
musicSelector.addListener(this);
|
||||
musicSelector.miniSender.addListener(this);
|
||||
musicSelector.postInit();
|
||||
musicSelector.refresh();
|
||||
|
||||
@ -196,7 +194,6 @@ public class CreativeStage extends Stage implements MiniListener {
|
||||
public void dispose() {
|
||||
analyzer.resetVars();
|
||||
analyzer.shrinkData();
|
||||
audioWrapper.reset();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@ -208,13 +205,13 @@ public class CreativeStage extends Stage implements MiniListener {
|
||||
volumeWindow.setMusic(null);
|
||||
graphViewer.setData(null, null, null);
|
||||
musicPlayBackControls.setAudiofile(null);
|
||||
analyzer.startAnalyticalThread(Audio.getAudioData(musicSelector.getSelectedMusic()));
|
||||
analyzer.startAnalyticalThread(musicSelector.getSelectedMusic());
|
||||
break;
|
||||
case SPECTRAL_FLUX_DONE:
|
||||
analyzer.runThresholdCleaning();
|
||||
break;
|
||||
case MUSIC_DATA_CLEANED:
|
||||
musicPlayBackControls.setAudiofile(Audio.getAudioData(musicSelector.getSelectedMusic()));
|
||||
musicPlayBackControls.setAudiofile(musicSelector.getSelectedMusic());
|
||||
volumeWindow.setMusic(musicPlayBackControls.getAudiofile());
|
||||
beatViewer.setMusic(musicPlayBackControls.getAudiofile());
|
||||
graphViewer.setData(analyzer.getBassPeaks(), analyzer.getUMPeaks(), musicPlayBackControls.getAudiofile());
|
||||
|
@ -115,19 +115,17 @@ public class MusicController extends Window {
|
||||
|
||||
|
||||
public void setAudiofile(AudioData audiofile) {
|
||||
this.audiofile.reset();
|
||||
this.audiofile = audiofile;
|
||||
|
||||
if (audiofile == null) {
|
||||
togglePlay.setDrawable(skin.getDrawable("loading"));
|
||||
info.setText("Analyzing...");
|
||||
} else {
|
||||
audiofile.reset();
|
||||
togglePlay.setDrawable(skin.getDrawable("arrow"));
|
||||
info.setText("Ready.");
|
||||
audiofile.getPlaybackMusic().play();
|
||||
audiofile.getPlaybackMusic().pause();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public AudioData getAudiofile() {
|
||||
|
@ -11,8 +11,10 @@ import com.badlogic.gdx.scenes.scene2d.ui.Window;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import zero1hd.polyjet.audio.Audio;
|
||||
import zero1hd.polyjet.audio.AudioData;
|
||||
import zero1hd.polyjet.util.MiniEvents;
|
||||
import zero1hd.polyjet.util.MiniListener;
|
||||
import zero1hd.polyjet.util.MiniSender;
|
||||
|
||||
public class MusicSelector extends Window {
|
||||
boolean confirmed;
|
||||
@ -22,8 +24,7 @@ public class MusicSelector extends Window {
|
||||
private List<String> musicList;
|
||||
private String path;
|
||||
private ScrollPane listScroller;
|
||||
|
||||
private Array<MiniListener> listeners;
|
||||
public MiniSender miniSender;
|
||||
|
||||
public MusicSelector(String title, Skin skin, final String path, String listStyle) {
|
||||
super(title, skin);
|
||||
@ -32,7 +33,7 @@ public class MusicSelector extends Window {
|
||||
padLeft(5f);
|
||||
padRight(5f);
|
||||
|
||||
listeners = new Array<>();
|
||||
miniSender = new MiniSender();
|
||||
|
||||
setSize(Gdx.graphics.getWidth()*0.5f, Gdx.graphics.getHeight()*0.5f);
|
||||
|
||||
@ -46,7 +47,7 @@ public class MusicSelector extends Window {
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
confirmed = true;
|
||||
selectedMusic = Gdx.files.absolute(path+System.getProperty("file.separator")+musicList.getSelected());
|
||||
send(MiniEvents.MUSIC_SELECTED);
|
||||
miniSender.send(MiniEvents.MUSIC_SELECTED);
|
||||
}
|
||||
});
|
||||
add(confirmButton).right();
|
||||
@ -86,17 +87,7 @@ public class MusicSelector extends Window {
|
||||
return isBack;
|
||||
}
|
||||
|
||||
public FileHandle getSelectedMusic() {
|
||||
return selectedMusic;
|
||||
}
|
||||
|
||||
private void send(MiniEvents ID) {
|
||||
while (listeners.iterator().hasNext()) {
|
||||
listeners.iterator().next().handle(ID);
|
||||
}
|
||||
}
|
||||
|
||||
public void addListener(MiniListener handler) {
|
||||
listeners.add(handler);
|
||||
public AudioData getSelectedMusic() {
|
||||
return Audio.getAudioData(selectedMusic);
|
||||
}
|
||||
}
|
||||
|
25
core/src/zero1hd/polyjet/util/MiniSender.java
Executable file
25
core/src/zero1hd/polyjet/util/MiniSender.java
Executable file
@ -0,0 +1,25 @@
|
||||
package zero1hd.polyjet.util;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
public class MiniSender {
|
||||
private Array<MiniListener> listeners;
|
||||
|
||||
public MiniSender() {
|
||||
listeners = new Array<MiniListener>();
|
||||
}
|
||||
|
||||
public void send(MiniEvents ID) {
|
||||
for (MiniListener listener : listeners) {
|
||||
listener.handle(ID);
|
||||
}
|
||||
}
|
||||
|
||||
public void addListener(MiniListener handler) {
|
||||
listeners.add(handler);
|
||||
}
|
||||
|
||||
public void removeListener(MiniListener listener) {
|
||||
listeners.removeValue(listener, true);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user