recursive music search added and tested

This commit is contained in:
Harrison Deng 2017-12-03 18:44:05 -06:00
parent 316c419b99
commit 516ed746d7
4 changed files with 31 additions and 12 deletions

View File

@ -19,17 +19,27 @@ public class MusicList extends Observable {
fhac = new FileHandleAlphabeticalComparator(); fhac = new FileHandleAlphabeticalComparator();
} }
private Array<FileHandle> recursiveMusicFileList(FileHandle fileHandle) {
Array<FileHandle> musicFiles = new Array<>();
FileHandle[] files = fileHandle.list();
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
musicFiles.addAll(recursiveMusicFileList(files[i]));
} else {
if (files[i].extension().equalsIgnoreCase("wav") || files[i].extension().equalsIgnoreCase("mp3")) {
musicFiles.add(files[i]);
}
}
}
return musicFiles;
}
public void refresh() { public void refresh() {
searched = true; searched = true;
musicList.clear(); musicList.clear();
Gdx.app.debug("SongController", "Searching path: " + searchPath); Gdx.app.debug("SongController", "Searching path: " + searchPath);
if (Gdx.files.absolute(searchPath).exists() && Gdx.files.absolute(searchPath).isDirectory()) { if (Gdx.files.absolute(searchPath).exists() && Gdx.files.absolute(searchPath).isDirectory()) {
musicList.addAll(Gdx.files.absolute(searchPath).list((dir, name) -> { musicList.addAll(recursiveMusicFileList(Gdx.files.absolute(searchPath)));
if (name.endsWith("mp3") || name.endsWith("wav")) {
return true;
}
return false;
}));
} }
if (!Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3").exists()) { if (!Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3").exists()) {
Gdx.files.internal("music/Alan Walker - Spectre.mp3").copyTo(Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3")); Gdx.files.internal("music/Alan Walker - Spectre.mp3").copyTo(Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3"));
@ -80,4 +90,5 @@ public class MusicList extends Observable {
public boolean isSearched() { public boolean isSearched() {
return searched; return searched;
} }
} }

View File

@ -15,12 +15,16 @@ public class AudioAnalyzer implements Disposable {
private PruneFluxRunnable pfr; private PruneFluxRunnable pfr;
private PeakDetectionRunnable pdr; private PeakDetectionRunnable pdr;
private MusicManager musicManager;
public AudioAnalyzer(MusicManager musicManager) { public AudioAnalyzer(MusicManager musicManager) {
exec = Executors.newSingleThreadExecutor(); exec = Executors.newSingleThreadExecutor();
sfar = new SpectralFluxAnalysisRunnable(musicManager); sfar = new SpectralFluxAnalysisRunnable(musicManager);
tcr = new ThresholdCalcRunnable(sfar); tcr = new ThresholdCalcRunnable(sfar);
pfr = new PruneFluxRunnable(tcr); pfr = new PruneFluxRunnable(tcr);
pdr = new PeakDetectionRunnable(pfr, sfar.getPUID()); pdr = new PeakDetectionRunnable(pfr, sfar.getPUID());
this.musicManager = musicManager;
} }
public void start() { public void start() {
@ -40,10 +44,15 @@ public class AudioAnalyzer implements Disposable {
@Override @Override
public void dispose() { public void dispose() {
stop(); stop();
musicManager.dispose();
exec.shutdown(); exec.shutdown();
} }
public boolean isDone() { public boolean isDone() {
return (sfar.isDone() && tcr.isDone() && pfr.isDone() && pdr.isDone()); if ((sfar.isDone() && tcr.isDone() && pfr.isDone() && pdr.isDone())) {
dispose();
return true;
}
return false;
} }
} }

View File

@ -34,7 +34,7 @@ public class Visualizer extends Widget {
} }
vis.modify(delta); vis.modify(delta);
setVisualizerPosProp(); updateVisualizerProperties();
if (updatePositioning) { if (updatePositioning) {
vis.updatePositionInfo(); vis.updatePositionInfo();
vis.setxPos((getWidth() - vis.getActualWidth())/2f); vis.setxPos((getWidth() - vis.getActualWidth())/2f);
@ -61,7 +61,7 @@ public class Visualizer extends Widget {
super.setColor(r, g, b, a); super.setColor(r, g, b, a);
} }
public void setVisualizerPosProp() { public void updateVisualizerProperties() {
vis.setHeight(getHeight()); vis.setHeight(getHeight());
vis.setWidth(getWidth()); vis.setWidth(getWidth());
vis.setxPos(getX()); vis.setxPos(getX());
@ -75,7 +75,7 @@ public class Visualizer extends Widget {
} }
public void updateVisualPosition() { public void updateVisualPosition() {
setVisualizerPosProp(); updateVisualizerProperties();
vis.updatePositionInfo(); vis.updatePositionInfo();
vis.setxPos(((vis.getWidth() - vis.getActualWidth())/2f)); vis.setxPos(((vis.getWidth() - vis.getActualWidth())/2f));
Gdx.app.debug("Visualizer", "currently offseting visualizer by (px): " + vis.getxPos()); Gdx.app.debug("Visualizer", "currently offseting visualizer by (px): " + vis.getxPos());

View File

@ -187,6 +187,7 @@ public class MusicSelectionPage extends Page implements Observer {
selectables.clear(); selectables.clear();
musicInfoTable.clear(); musicInfoTable.clear();
musicSubInfo.clear(); musicSubInfo.clear();
extraInfoDone = false;
for (int i = 0; i < selectables.size; i++) { for (int i = 0; i < selectables.size; i++) {
selectables.get(i).dispose(); selectables.get(i).dispose();
@ -326,7 +327,5 @@ public class MusicSelectionPage extends Page implements Observer {
ratedDifficulty.setText("Rated Difficulty: " + difficulty); ratedDifficulty.setText("Rated Difficulty: " + difficulty);
albumCover.setDrawable((new TextureRegionDrawable(new TextureRegion(currentlySelected.getAudioInfo().getAlbumCover())))); albumCover.setDrawable((new TextureRegionDrawable(new TextureRegion(currentlySelected.getAudioInfo().getAlbumCover()))));
} }
} }