progress towards optimizations
This commit is contained in:
parent
6f59e2f236
commit
fbbd079154
@ -350,7 +350,7 @@ holo-pane-down
|
||||
rotate: false
|
||||
xy: 133, 8
|
||||
size: 20, 20
|
||||
split: 4, 4, 4, 4
|
||||
split: 2, 2, 2, 2
|
||||
orig: 20, 20
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
@ -209,6 +209,7 @@ public class Mp3Manager implements MusicManager {
|
||||
|
||||
@Override
|
||||
public void play() {
|
||||
Gdx.app.debug("Mp3Manager", "MP3 Playing...");
|
||||
playbackMusic.play();
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,6 @@ public class MusicInfo implements Disposable {
|
||||
|
||||
private long durationInSeconds;
|
||||
private String songName;
|
||||
private Texture albumCover;
|
||||
private String author;
|
||||
private int previousTop;
|
||||
private int ratedDifficulty;
|
||||
@ -118,11 +117,7 @@ public class MusicInfo implements Disposable {
|
||||
public String getMusicName() {
|
||||
return songName.replace('_', ' ');
|
||||
}
|
||||
|
||||
public Texture getAlbumCover() {
|
||||
return albumCover;
|
||||
}
|
||||
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
@ -138,10 +133,9 @@ public class MusicInfo implements Disposable {
|
||||
public boolean isInvalidMusic() {
|
||||
return invalidMusic;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
albumCover.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,6 +56,7 @@ public class MusicList extends Observable {
|
||||
setChanged();
|
||||
Sort.instance().sort(musicList, fhac);
|
||||
searched = true;
|
||||
|
||||
if (notify) {
|
||||
notifyObservers();
|
||||
}
|
||||
@ -69,10 +70,10 @@ public class MusicList extends Observable {
|
||||
searched = false;
|
||||
exec.submit(() -> {
|
||||
refresh(false);
|
||||
Gdx.app.debug("Asynch-MusicList", "Async refresh done. Notification has been sent.");
|
||||
Gdx.app.postRunnable(() -> {
|
||||
notifyObservers();
|
||||
searched = true;
|
||||
Gdx.app.debug("Asynch-MusicList", "Async refresh done. Notification has been sent.");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -27,8 +27,12 @@ public class MusicListController extends Observable implements OnCompletionListe
|
||||
rand = new Random();
|
||||
}
|
||||
|
||||
/**
|
||||
* This play method automatically sets the volume.
|
||||
*/
|
||||
public void play() {
|
||||
if (mm != null) {
|
||||
Gdx.app.debug("MusicListController", "Playing from MLC.");
|
||||
mm.play();
|
||||
mm.setVolume(prefs.getFloat("music vol", 1f));
|
||||
} else {
|
||||
|
@ -76,7 +76,7 @@ public class MusicSelectable extends WidgetGroup implements Disposable {
|
||||
|
||||
@Override
|
||||
public void layout() {
|
||||
displayName.setTargetWidth((int) (getWidth()/3f));
|
||||
displayName.setTargetWidth((int) (getWidth()*0.43f));
|
||||
authorLabel.setTargetWidth((int) (getWidth()/3f));
|
||||
displayName.resize();
|
||||
authorLabel.resize();
|
||||
|
@ -119,12 +119,11 @@ public class MainPage extends Page implements Observer {
|
||||
MusicManager mm = mlc.getCurrentMusicManager();
|
||||
updateVisualsForDifferentSong(mm);
|
||||
mMenu.getMusicSelectionPage().refreshUIList();
|
||||
mMenu.getMusicSelectionPage().selectMusicUI(mm);
|
||||
mlc.play();
|
||||
} else if (o == mlc) {
|
||||
MusicManager mm = mlc.getCurrentMusicManager();
|
||||
mlc.play();
|
||||
updateVisualsForDifferentSong(mm);
|
||||
mm.play();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,6 @@ import zero1hd.rhythmbullet.graphics.ui.components.ScrollText;
|
||||
|
||||
public class MusicSelectionPage extends Page implements Observer {
|
||||
Preferences musicFileAnnotation;
|
||||
private boolean extraInfoDone;
|
||||
|
||||
private MusicListController mc;
|
||||
private MusicInfoController mic;
|
||||
@ -50,13 +49,13 @@ public class MusicSelectionPage extends Page implements Observer {
|
||||
private Label songLength;
|
||||
private Label previousTop;
|
||||
private Label ratedDifficulty;
|
||||
private Texture albumCoverTexture;
|
||||
private Image albumCover;
|
||||
|
||||
private AssetManager assets;
|
||||
private MusicSelectable currentlySelected;
|
||||
|
||||
private Skin skin;
|
||||
private AssetManager assets;
|
||||
|
||||
private boolean down, up;
|
||||
private int musicSelectableIndex;
|
||||
|
||||
@ -68,11 +67,11 @@ public class MusicSelectionPage extends Page implements Observer {
|
||||
|
||||
public MusicSelectionPage(Skin skin, MusicListController musicListController, AssetManager assetManager, Vector3 cameraTarget, AnalysisPage ap) {
|
||||
setTextureBackground(assetManager.get("gradients.atlas", TextureAtlas.class).findRegion("red-round"));
|
||||
this.assets = assetManager;
|
||||
this.skin = skin;
|
||||
this.mc = musicListController;
|
||||
mic = new MusicInfoController(mc.getMusicList());
|
||||
musicFileAnnotation = Gdx.app.getPreferences("music_file_annotation");
|
||||
this.assets = assetManager;
|
||||
musicTable = new Table();
|
||||
musicTableScrollPane = new ScrollPane(musicTable, skin);
|
||||
musicTable.defaults().spaceTop(5f).spaceBottom(5f);
|
||||
@ -185,10 +184,15 @@ public class MusicSelectionPage extends Page implements Observer {
|
||||
musicTable.add(selectables.get(uiSongCount)).expandX().fillX();
|
||||
uiSongCount++;
|
||||
musicTable.row();
|
||||
}
|
||||
if (mic.isDoneLoading() && uiSongInfoCount < selectables.size) {
|
||||
if (uiSongCount == mc.getMusicList().getAmountOfMusic()) {
|
||||
selectMusicUI(mc.getCurrentMusicManager());
|
||||
}
|
||||
} else if (uiSongInfoCount < selectables.size && mic.isDoneLoading() ) {
|
||||
selectables.get(uiSongInfoCount).updateInfo(mic.getSongInfoArray().get(uiSongInfoCount));
|
||||
uiSongInfoCount++;
|
||||
if (uiSongInfoCount == selectables.size) {
|
||||
updateInformation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,13 +208,12 @@ public class MusicSelectionPage extends Page implements Observer {
|
||||
for (int i = 0; i < selectables.size; i++) {
|
||||
selectables.get(i).dispose();
|
||||
}
|
||||
mic.loadSongInfo();
|
||||
musicTable.clear();
|
||||
selectables.clear();
|
||||
musicInfoTable.clear();
|
||||
musicSubInfo.clear();
|
||||
extraInfoDone = false;
|
||||
uiSongCount = 0;
|
||||
mic.loadSongInfo();
|
||||
uiSongInfoCount = 0;
|
||||
|
||||
Gdx.app.debug("MusicSelectionPage", "Refreshing...");
|
||||
@ -252,7 +255,7 @@ public class MusicSelectionPage extends Page implements Observer {
|
||||
this.currentlySelected = currentlySelected;
|
||||
songSelectionTimer = 1f;
|
||||
|
||||
if (extraInfoDone) {
|
||||
if (mic.isDoneLoading()) {
|
||||
updateInformation();
|
||||
}
|
||||
}
|
||||
@ -308,9 +311,13 @@ public class MusicSelectionPage extends Page implements Observer {
|
||||
* This should only be called when everything is loaded.
|
||||
*/
|
||||
private void updateInformation() {
|
||||
Gdx.app.debug("MusicSelectionPage", "Updating song info panel...");
|
||||
if (currentlySelected == null) throw new NullPointerException("Buddy, you need to update this page to have the proper current music selected...");
|
||||
songTitle.setText(currentlySelected.getMusicInfo().getMusicName(), null);
|
||||
author.setText("Author: " + currentlySelected.getMusicInfo().getAuthor());
|
||||
|
||||
if (albumCoverTexture != null) {
|
||||
albumCoverTexture.dispose();
|
||||
}
|
||||
long lengthInSeconds = currentlySelected.getMusicInfo().getDurationInSeconds();
|
||||
int min = (int) (lengthInSeconds/60);
|
||||
int sec = (int) (lengthInSeconds - (min*60));
|
||||
@ -320,7 +327,11 @@ public class MusicSelectionPage extends Page implements Observer {
|
||||
|
||||
String difficulty = (getSelectedMusicInfo().getRatedDifficulty() == -1 ? "N/A" : String.valueOf(getSelectedMusicInfo().getRatedDifficulty()));
|
||||
ratedDifficulty.setText("Rated Difficulty: " + difficulty);
|
||||
|
||||
albumCover.setDrawable((new TextureRegionDrawable(new TextureRegion(currentlySelected.getMusicInfo().getAlbumCover()))));
|
||||
albumCoverTexture = currentlySelected.getMusicInfo().loadTexture();
|
||||
if (albumCoverTexture != null) {
|
||||
albumCover.setDrawable((new TextureRegionDrawable(new TextureRegion(albumCoverTexture))));
|
||||
} else {
|
||||
albumCover.setDrawable((new TextureRegionDrawable(new TextureRegion(assets.get("defaultCover.png", Texture.class)))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,138 +0,0 @@
|
||||
package zero1hd.rhythmbullet.graphics.ui.windows;
|
||||
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.audio.Music;
|
||||
import com.badlogic.gdx.audio.Music.OnCompletionListener;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputListener;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Window;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
|
||||
import zero1hd.rhythmbullet.audio.MusicManager;
|
||||
|
||||
public class MusicController extends Window implements OnCompletionListener {
|
||||
Skin skin;
|
||||
private Image togglePlay;
|
||||
private TextField info;
|
||||
private MusicManager audiofile;
|
||||
|
||||
public MusicController(final Skin skin) {
|
||||
super("Playback Controller", skin, "tinted");
|
||||
|
||||
defaults().space(5f);
|
||||
|
||||
this.skin = skin;
|
||||
final ImageButton rewind = new ImageButton(skin.getDrawable("left-double-arrow"));
|
||||
rewind.addListener(new ChangeListener() {
|
||||
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
audiofile.setPosition(audiofile.getPositionInSeconds() - 2);
|
||||
info.setText(String.valueOf(MathUtils.round(audiofile.getPositionInSeconds())) + " sec");
|
||||
}
|
||||
});
|
||||
|
||||
add(rewind).center();
|
||||
|
||||
togglePlay = new Image(skin.getDrawable("loading")) {
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
super.act(delta);
|
||||
}
|
||||
};
|
||||
togglePlay.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
if (audiofile != null) {
|
||||
if (audiofile.isPlaying()) {
|
||||
audiofile.pause();
|
||||
|
||||
togglePlay.setDrawable(skin.getDrawable("arrow"));
|
||||
|
||||
} else {
|
||||
togglePlay.setDrawable(skin.getDrawable("pause"));
|
||||
audiofile.play();
|
||||
}
|
||||
}
|
||||
super.clicked(event, x, y);
|
||||
}
|
||||
});
|
||||
add(togglePlay).minWidth(togglePlay.getDrawable().getMinWidth()).center();
|
||||
|
||||
final ImageButton fastForward = new ImageButton(skin.getDrawable("right-double-arrow"));
|
||||
fastForward.addListener(new ChangeListener() {
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
if (audiofile != null) {
|
||||
audiofile.play();
|
||||
audiofile.setPosition(audiofile.getPositionInSeconds() + 2);
|
||||
info.setText(String.valueOf(MathUtils.round(audiofile.getPositionInSeconds())) + " sec");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
add(fastForward);
|
||||
|
||||
info = new TextField(null, skin, "ui") {
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
if (audiofile != null && audiofile.isPlaying()) {
|
||||
setText(String.valueOf(MathUtils.round(audiofile.getPositionInSeconds())) + " sec");
|
||||
}
|
||||
super.act(delta);
|
||||
}
|
||||
};
|
||||
add(info);
|
||||
|
||||
|
||||
addListener(new InputListener() {
|
||||
@Override
|
||||
public boolean keyUp(InputEvent event, int keycode) {
|
||||
if (keycode == Keys.ENTER) {
|
||||
if (!info.getText().replaceAll("(?![0-9])\\S+", "").trim().isEmpty()) {
|
||||
audiofile.setPosition(Float.valueOf(info.getText().replaceAll("(?![0-9])\\S+", "").trim()));
|
||||
}
|
||||
}
|
||||
return super.keyUp(event, keycode);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
setSize(260, 75);
|
||||
}
|
||||
|
||||
public void setAudiofile(MusicManager audiofile) {
|
||||
this.audiofile = audiofile;
|
||||
if (this.audiofile != null) {
|
||||
this.audiofile.dispose();
|
||||
this.audiofile = null;
|
||||
}
|
||||
if (audiofile == null) {
|
||||
togglePlay.setDrawable(skin.getDrawable("loading"));
|
||||
info.setText("Analyzing...");
|
||||
} else {
|
||||
togglePlay.setDrawable(skin.getDrawable("arrow"));
|
||||
info.setText("Ready.");
|
||||
audiofile.play();
|
||||
audiofile.pause();
|
||||
audiofile.setOnCompletionListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
public MusicManager getAudiofile() {
|
||||
return audiofile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompletion(Music music) {
|
||||
audiofile.dispose();
|
||||
audiofile = null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user