finished adding album cover for music selection, properly read different wav headers now

This commit is contained in:
Harrison Deng 2017-04-25 15:23:01 -05:00
parent 3d52583de2
commit dd729cffd7
4 changed files with 93 additions and 97 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

@ -26,19 +26,18 @@ public class MusicSelectable extends Button implements Disposable {
private String songName; private String songName;
private Texture albumCover; private Texture albumCover;
WavInfo wavinfo; WavInfo wavinfo;
private int previousTop;
private int ratedDifficulty;
private byte[] albumWorkBytes; private byte[] albumWorkBytes;
private volatile Image imageIcon; private Image imageIcon;
private Label displayName; private Label displayName;
private Label runTime; private Label runTime;
private Skin skin; private Skin skin;
public MusicSelectable(FileHandle musicFile, Preferences musicData, final Skin skin, Texture defaultAlbumC) { public MusicSelectable(FileHandle musicFile, Preferences musicData, final Skin skin, Texture defaultAlbumC) {
super(skin, "info-button"); super(skin, "info-button");
this.skin = skin; this.skin = skin;
debug();
this.albumCover = defaultAlbumC; this.albumCover = defaultAlbumC;
if (musicFile.extension().toLowerCase().equals("mp3")) { if (musicFile.extension().toLowerCase().equals("mp3")) {
@ -67,13 +66,12 @@ public class MusicSelectable extends Button implements Disposable {
if (songName == null || songName.isEmpty()) { if (songName == null || songName.isEmpty()) {
songName = musicFile.nameWithoutExtension(); songName = musicFile.nameWithoutExtension();
} }
previousTop = musicData.getInteger(songName + ":previous top");
ratedDifficulty = musicData.getInteger(songName + ":difficulty");
} }
public synchronized void addInfoToPanel() { public void addInfoToPanel(float width) {
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
if (albumWorkBytes != null && !invalidMusic) { if (albumWorkBytes != null && !invalidMusic) {
Pixmap albumArt = new Pixmap(albumWorkBytes, 0, albumWorkBytes.length); Pixmap albumArt = new Pixmap(albumWorkBytes, 0, albumWorkBytes.length);
albumCover = new Texture(albumArt); albumCover = new Texture(albumArt);
@ -84,20 +82,16 @@ public class MusicSelectable extends Button implements Disposable {
if (invalidMusic) { if (invalidMusic) {
imageIcon.setColor(Color.RED); imageIcon.setColor(Color.RED);
} }
System.out.println("invalid or null"); Gdx.app.debug("UI", "album cover invalid or null for image: " + songName);
} }
float scale = getWidth()/imageIcon.getWidth(); add(imageIcon).prefSize(width, width).spaceBottom(20f);
imageIcon.setScale(scale);
// imageIcon.setSize(scale*imageIcon.getWidth(), scale*imageIcon.getHeight());
add(imageIcon);
row(); row();
displayName = new Label(songName, skin); displayName = new Label(songName, skin);
displayName.setWrap(true); displayName.setWrap(true);
add(displayName).prefWidth(getPrefWidth()-5).center(); add(displayName).prefWidth(width-5).center();
row(); row();
@ -112,7 +106,21 @@ public class MusicSelectable extends Button implements Disposable {
runTime = new Label(formattedSecond, skin); runTime = new Label(formattedSecond, skin);
add(runTime); add(runTime);
} }
});
public int getPreviousTop() {
return previousTop;
}
public int getRatedDifficulty() {
return ratedDifficulty;
}
public Texture getAlbumCover() {
return albumCover;
}
public WavInfo getWavinfo() {
return wavinfo;
} }
@Override @Override

View File

@ -2,7 +2,6 @@ package zero1hd.polyjet.ui.pages;
import java.io.File; import java.io.File;
import java.io.FilenameFilter; import java.io.FilenameFilter;
import java.util.concurrent.CountDownLatch;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences; import com.badlogic.gdx.Preferences;
@ -12,7 +11,6 @@ import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.actions.Actions; import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane; import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
@ -66,33 +64,12 @@ public class MusicSelectionPage extends Page {
} }
public void beginMusicSearch() { public void beginMusicSearch() {
Thread musicFinder = new Thread(new MusicFinderRunnable(Gdx.files.absolute(core.prefs.getString("music dir")), core.defaultSkin, 0)); new Thread(new Runnable() {
musicFinder.start();
}
class MusicFinderRunnable implements Runnable {
private FileHandle[] musicFiles;
private int startingID;
private Skin skin;
private FileHandle musicDir;
// private CountDownLatch latch;
private volatile MusicSelectable selectable;
public MusicFinderRunnable(FileHandle musicDir, Skin skin, int startingID) {
super();
this.startingID = startingID;
this.skin = skin;
this.musicDir = musicDir;
// latch = new CountDownLatch(1);
}
@Override @Override
public void run() { public void run() {
musicFiles = musicDir.list(new FilenameFilter() { FileHandle[] musicFiles = new FileHandle(core.prefs.getString("music dir")).list(new FilenameFilter() {
@Override @Override
public boolean accept(File dir, String name) { public boolean accept(File dir, String name) {
if (name.endsWith("mp3") || name.endsWith("wav")) { if (name.endsWith("mp3") || name.endsWith("wav")) {
@ -101,10 +78,19 @@ public class MusicSelectionPage extends Page {
return false; return false;
} }
}); });
int startingID = 0;
for (int music = startingID; music < musicFiles.length && music < 15; music++) { for (int music = startingID; music < musicFiles.length && music < 15; music++) {
selectable = new MusicSelectable(musicFiles[music], musicFileAnnotation, skin, core.assetManager.get("defaultCover.png", Texture.class)); final MusicSelectable selectable = new MusicSelectable(musicFiles[music], musicFileAnnotation, core.defaultSkin, core.assetManager.get("defaultCover.png", Texture.class));
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
selectable.addInfoToPanel(0.2f*getWidth()-10);
musicChoices.add(selectable).prefSize(0.2f*getWidth(), 0.8f*getHeight()); musicChoices.add(selectable).prefSize(0.2f*getWidth(), 0.8f*getHeight());
} }
});
} }
} }
}).start();
}
} }

View File

@ -6,8 +6,6 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.security.InvalidParameterException; import java.security.InvalidParameterException;
import com.badlogic.gdx.Gdx;
public class WavInfo { public class WavInfo {
private int channels; private int channels;
private double sampleRate; private double sampleRate;
@ -59,16 +57,16 @@ public class WavInfo {
byteRate = littleEndianIntBytes(); //4 byteRate = littleEndianIntBytes(); //4
readStream.skip(4); //38 readStream.skip(4);
// System.out.println(readBytesToString(4).equals("data")); String moreInfo = readBytesToString(4);
if (moreInfo.equals("LIST")) { // 4
if (!readBytesToString(4).equals("data")) { // 4 readStream.skip(30);
Gdx.app.debug("Audio", "sample rate: " + sampleRate); if (!readBytesToString(4).equals("data")) {
Gdx.app.debug("Audio", "Data chunk size: " + dataSize); throw new InvalidParameterException("failed to read data with extra info.");
Gdx.app.debug("Audio", "Channel count: " + channels); }
} else if (!moreInfo.equals("data")) {
throw new InvalidParameterException("initial data section tag not found on wav: " + fileName); throw new InvalidParameterException("failed to read data.");
} }
readStream.skip(4); readStream.skip(4);
@ -122,4 +120,8 @@ public class WavInfo {
public long getDurationInSeconds() { public long getDurationInSeconds() {
return (long) (dataSize/byteRate); return (long) (dataSize/byteRate);
} }
public String getFileName() {
return fileName;
}
} }