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();
}
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() {
searched = true;
musicList.clear();
Gdx.app.debug("SongController", "Searching path: " + searchPath);
if (Gdx.files.absolute(searchPath).exists() && Gdx.files.absolute(searchPath).isDirectory()) {
musicList.addAll(Gdx.files.absolute(searchPath).list((dir, name) -> {
if (name.endsWith("mp3") || name.endsWith("wav")) {
return true;
}
return false;
}));
musicList.addAll(recursiveMusicFileList(Gdx.files.absolute(searchPath)));
}
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"));
@ -80,4 +90,5 @@ public class MusicList extends Observable {
public boolean isSearched() {
return searched;
}
}

View File

@ -15,12 +15,16 @@ public class AudioAnalyzer implements Disposable {
private PruneFluxRunnable pfr;
private PeakDetectionRunnable pdr;
private MusicManager musicManager;
public AudioAnalyzer(MusicManager musicManager) {
exec = Executors.newSingleThreadExecutor();
sfar = new SpectralFluxAnalysisRunnable(musicManager);
tcr = new ThresholdCalcRunnable(sfar);
pfr = new PruneFluxRunnable(tcr);
pdr = new PeakDetectionRunnable(pfr, sfar.getPUID());
this.musicManager = musicManager;
}
public void start() {
@ -40,10 +44,15 @@ public class AudioAnalyzer implements Disposable {
@Override
public void dispose() {
stop();
musicManager.dispose();
exec.shutdown();
}
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);
setVisualizerPosProp();
updateVisualizerProperties();
if (updatePositioning) {
vis.updatePositionInfo();
vis.setxPos((getWidth() - vis.getActualWidth())/2f);
@ -61,7 +61,7 @@ public class Visualizer extends Widget {
super.setColor(r, g, b, a);
}
public void setVisualizerPosProp() {
public void updateVisualizerProperties() {
vis.setHeight(getHeight());
vis.setWidth(getWidth());
vis.setxPos(getX());
@ -75,7 +75,7 @@ public class Visualizer extends Widget {
}
public void updateVisualPosition() {
setVisualizerPosProp();
updateVisualizerProperties();
vis.updatePositionInfo();
vis.setxPos(((vis.getWidth() - vis.getActualWidth())/2f));
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();
musicInfoTable.clear();
musicSubInfo.clear();
extraInfoDone = false;
for (int i = 0; i < selectables.size; i++) {
selectables.get(i).dispose();
@ -326,7 +327,5 @@ public class MusicSelectionPage extends Page implements Observer {
ratedDifficulty.setText("Rated Difficulty: " + difficulty);
albumCover.setDrawable((new TextureRegionDrawable(new TextureRegion(currentlySelected.getAudioInfo().getAlbumCover()))));
}
}