resize tested and many issues fixed; horizontal visualizer scales to
height;
This commit is contained in:
parent
7a810299ce
commit
7fb42a63f8
@ -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() {
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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++) {
|
||||
|
@ -14,11 +14,10 @@ public class DesktopLauncher {
|
||||
config.resizable = false;
|
||||
config.useHDPI = true;
|
||||
config.samples = 2;
|
||||
|
||||
config.width = 128;
|
||||
config.height = 128;
|
||||
core = new RhythmBullet();
|
||||
core.setup(new SplashScreen(), new DesktopAssetPack());
|
||||
new LwjglApplication(core, config);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,8 @@ import zero1hd.rhythmbullet.graphics.ui.Page;
|
||||
import zero1hd.rhythmbullet.util.ResizeReadyScreen;
|
||||
|
||||
public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
|
||||
private boolean resizing;
|
||||
|
||||
private Stage stage;
|
||||
private Vector3 cameraPosition;
|
||||
private Listeners listeners;
|
||||
@ -56,8 +58,7 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
|
||||
stage = new Stage(new ScreenViewport());
|
||||
cameraPosition = new Vector3(stage.getCamera().position);
|
||||
|
||||
MusicList musicList = new MusicList(new DesktopAudioProcessorFactory());
|
||||
musicList.setSearchPath(core.getPreferences().getString("music dir"));
|
||||
MusicList musicList = new MusicList(new DesktopAudioProcessorFactory(), core.getPreferences().getString("music dir"));
|
||||
musicController = new MusicController(musicList, core.getPreferences());
|
||||
musicController.setAutoPlay(true);
|
||||
musicController.setShuffle(true);
|
||||
@ -65,6 +66,7 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
|
||||
musicMetadataController = new MusicMetadataController(musicList);
|
||||
|
||||
listeners = new Listeners();
|
||||
screenBatch = new SpriteBatch();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -89,20 +91,24 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
|
||||
}
|
||||
|
||||
private void draw() {
|
||||
stage.getViewport().apply();
|
||||
screenBatch.begin();
|
||||
screenBatch.draw(background, 0, 0, stage.getWidth(), stage.getHeight());
|
||||
screenBatch.end();
|
||||
stage.draw();
|
||||
if (!resizing) {
|
||||
stage.getViewport().apply();
|
||||
screenBatch.begin();
|
||||
screenBatch.draw(background, 0, 0, stage.getViewport().getScreenWidth(), stage.getViewport().getScreenHeight());
|
||||
screenBatch.end();
|
||||
stage.draw();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preAssetLoad() {
|
||||
resizing = true;
|
||||
stage.clear();
|
||||
bloomShader.dispose();
|
||||
bloomShader = null;
|
||||
if (bloomShader != null) {
|
||||
bloomShader.dispose();
|
||||
bloomShader = null;
|
||||
}
|
||||
background = null;
|
||||
screenBatch.dispose();
|
||||
musicController.deleteObservers();
|
||||
}
|
||||
|
||||
@ -110,9 +116,6 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
|
||||
public void postAssetLoad() {
|
||||
|
||||
background = rhythmBullet.getAssetManager().get("backgrounds/mainBG.png", Texture.class);
|
||||
screenBatch = new SpriteBatch();
|
||||
|
||||
|
||||
|
||||
mainPage = new MainPage(musicController, rhythmBullet.getAssetManager(), rhythmBullet.getSkin(), listeners.musicSelectionPageButtonListener, listeners.optionsPageButtonListener);
|
||||
stage.addActor(mainPage);
|
||||
@ -161,9 +164,8 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
|
||||
|
||||
musicController.addObserver(musicSelectionPage);
|
||||
musicController.addObserver(mainPage);
|
||||
|
||||
musicController.getMusicList().asyncSearch();
|
||||
|
||||
musicController.getMusicList().asyncSearch(false);
|
||||
resizing = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -271,9 +273,15 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
|
||||
ChangeListener bloomLevelShaderListener = new ChangeListener() {
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
if (graphicsPage.getBloomLevel() > 0) {
|
||||
int bloomLevel = 0;
|
||||
if (graphicsPage != null) {
|
||||
bloomLevel = graphicsPage.getBloomLevel();
|
||||
} else {
|
||||
bloomLevel = rhythmBullet.getPreferences().getInteger("glow shader");
|
||||
}
|
||||
if (bloomLevel > 0) {
|
||||
if (bloomShader == null) bloomShader = new BloomShader(screenBatch);
|
||||
bloomShader.setBloomLevel((int) graphicsPage.getBloomLevel());
|
||||
bloomShader.setBloomLevel(bloomLevel);
|
||||
} else if (bloomShader != null) {
|
||||
bloomShader.dispose();
|
||||
bloomShader = null;
|
||||
|
@ -86,7 +86,7 @@ public class OptionsPage extends Page {
|
||||
musicSearchTimer -= delta;
|
||||
if (musicSearchTimer <= 0) {
|
||||
musicController.getMusicList().setSearchPath(directoryField.getText());
|
||||
musicController.getMusicList().asyncSearch();
|
||||
musicController.getMusicList().asyncSearch(false);
|
||||
}
|
||||
}
|
||||
super.act(delta);
|
||||
|
Loading…
x
Reference in New Issue
Block a user