resize tested and many issues fixed; horizontal visualizer scales to

height;
This commit is contained in:
2018-08-15 23:17:04 -05:00
parent 7a810299ce
commit 7fb42a63f8
6 changed files with 61 additions and 42 deletions

View File

@@ -148,7 +148,7 @@ public class RhythmBullet extends Game {
@Override
public void resize(int width, int height) {
Gdx.app.debug("RhythmBullet/resize", "Current size:" + screenWidth + "x" + screenHeight + " new size: " + width + "x" + height);
Gdx.app.debug("resize", "Current size:" + screenWidth + "x" + screenHeight + " new size: " + width + "x" + height);
if (width != screenWidth || height != screenHeight) {
screenWidth = Gdx.graphics.getWidth();
screenHeight = Gdx.graphics.getHeight();
@@ -167,8 +167,8 @@ public class RhythmBullet extends Game {
resizing = true;
assetManager.clear();
queueAssets();
super.resize(width, height);
}
super.resize(width, height);
}
public void queueAssets() {

View File

@@ -19,28 +19,43 @@ public class MusicList extends Observable {
private RecursiveMusicSearchThread searchThread;
private AudioProcessorFactory audioProcFactory;
private volatile boolean searched;
public MusicList(AudioProcessorFactory audioProcessorFactory) {
private String searchPath;
public MusicList(AudioProcessorFactory audioProcessorFactory, String searchPath) {
this.audioProcFactory = audioProcessorFactory;
musicList = new Array<>();
searchThread = new RecursiveMusicSearchThread("Music Search Thread");
setSearchPath(searchPath);
}
/**
* Wrapper method that uses async refresh.
* Also notifies listeners that are on the main thread.
* @param refresh does a search whether or not path has changed.
*/
public void asyncSearch() {
if (!searchThread.start()) {
searchThread.stop();
searchThread = new RecursiveMusicSearchThread("Music Search Thread");
searchThread.start();
public void asyncSearch(boolean refresh) {
if (refresh) {
if (searchThread != null) {
if (!searchThread.start()) {
searchThread.stop();
searchThread = new RecursiveMusicSearchThread("Music Search Thread", Gdx.files.absolute(searchPath));
searchThread.start();
}
} else {
searchThread = new RecursiveMusicSearchThread("Music Search Thread", Gdx.files.absolute(searchPath));
searchThread.start();
}
} else {
if (searched && !hasChanged()) {
setChanged();
notifyObservers();
} else {
asyncSearch(true);
}
}
}
public void setSearchPath(String searchPath) {
searchThread.setSearchDirectory(Gdx.files.absolute(searchPath));
setChanged();
hasChanged();
this.searchPath = searchPath;
}
/**
@@ -107,12 +122,9 @@ public class MusicList extends Observable {
private FileHandle directory;
private volatile boolean work;
public RecursiveMusicSearchThread(String name) {
public RecursiveMusicSearchThread(String name, FileHandle searchDirectory) {
this.threadName = name;
}
public void setSearchDirectory(FileHandle directory) {
this.directory = directory;
this.directory = searchDirectory;
}
@Override
@@ -131,6 +143,7 @@ public class MusicList extends Observable {
if (work) {
searched = true;
Gdx.app.debug("MusicList", "recursive async search completed.");
setChanged();
notifyObservers();
}
}

View File

@@ -23,7 +23,7 @@ public class DoubleHorizontalVisualizer implements Disposable {
private int boundaryThickness;
private float spacePercentage = 0.85f;
private int barCount = 80;
private float normalFactor = 3f;
private float normalFactor = 1.2f;
private float barChangeRate = 14f;
private int smoothRange = 1;
private int binsToInclude = 160;
@@ -55,13 +55,12 @@ public class DoubleHorizontalVisualizer implements Disposable {
if (color.g > 1f) color.g = 0f;
if (color.b > 1f) color.b = 0f;
if (color.a > 1f) color.a = 0.2f;
for (int bar = 0; bar < amplitudes.length; bar++) {
float normalizedAmplitude = 0;
for (int freq = bar*binsPerBar; freq < (bar*binsPerBar) + binsPerBar; freq++) {
normalizedAmplitude += Math.abs(pcm.getFrequencyBins()[freq]);
}
amplitudes[bar] += normalizedAmplitude * normalFactor;
amplitudes[bar] += normalizedAmplitude * normalFactor * (height/100f);
amplitudes[bar] /= binsPerBar;
}
for (int bar = 0; bar < barHeights.length; bar++) {