arrow key music selection now functions

This commit is contained in:
Harrison Deng 2017-11-11 20:24:48 -06:00
parent 16992e1345
commit 30f7df2ad0
4 changed files with 14 additions and 14 deletions

View File

@ -5,8 +5,6 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException; import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException;
import org.jaudiotagger.audio.exceptions.ReadOnlyFileException; import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
@ -135,11 +133,11 @@ public class Mp3Manager implements MusicManager {
if (currentByteSet != null) { if (currentByteSet != null) {
samples[sid] += (workset[1] << 8) + (workset[0] & 0x00ff); samples[sid] += (workset[1] << 8) + (workset[0] & 0x00ff);
if (channels > 1) { if (channels > 1) {
samples[sid] += (workset[3] << 8) + (workset[2] & 0x00ff); short altChan = (short) ((workset[3] << 8) + (workset[2] & 0x00ff));
samples[sid] /= 2;
samples[sid] = altChan > samples[sid] ? altChan : samples[sid];
} }
framesRead ++; framesRead ++;
samples[sid] /= Short.MAX_VALUE+1; samples[sid] /= Short.MAX_VALUE+1;
} }
} }

View File

@ -64,11 +64,10 @@ public class WavDecoder {
if (audioInputStream.read(buffer) > 0) { if (audioInputStream.read(buffer) > 0) {
samples[sampleID] += (buffer[1] << 8) + (buffer[0] & 0x00ff); samples[sampleID] += (buffer[1] << 8) + (buffer[0] & 0x00ff);
if (audioInputStream.getFormat().getChannels() > 1) { if (audioInputStream.getFormat().getChannels() > 1) {
samples[sampleID] += (buffer[3] << 8) + (buffer[2] & 0x00ff); short altChan = (short) ((buffer[3] << 8) + (buffer[2] & 0x00ff));
samples[sampleID] /= 2; samples[sampleID] = altChan > samples[sampleID] ? altChan : samples[sampleID];
} }
framesRead ++; framesRead ++;
samples[sampleID] /= Short.MAX_VALUE+1; samples[sampleID] /= Short.MAX_VALUE+1;
} }

View File

@ -35,11 +35,12 @@ public class MusicSelectable extends WidgetGroup implements Disposable {
private VerticalGroup vGroup; private VerticalGroup vGroup;
private MusicSelectionPage msp;
public MusicSelectable(FileHandle musicFile, Preferences musicAnnotation, Skin skin, Texture defaultAlbumC, MusicSelectionPage msp) { public MusicSelectable(FileHandle musicFile, Preferences musicAnnotation, Skin skin, Texture defaultAlbumC, MusicSelectionPage msp) {
table = new Table(skin); table = new Table(skin);
table.setBackground("holo-pane"); table.setBackground("holo-pane");
vGroup = new VerticalGroup(); vGroup = new VerticalGroup();
this.msp = msp;
setName(musicFile.name()); setName(musicFile.name());
table.defaults().pad(10f); table.defaults().pad(10f);
@ -131,6 +132,7 @@ public class MusicSelectable extends WidgetGroup implements Disposable {
public void select() { public void select() {
table.setBackground("holo-pane-down"); table.setBackground("holo-pane-down");
selected = true; selected = true;
msp.setCurrentlySelected(this);
} }
public void deselect() { public void deselect() {

View File

@ -112,19 +112,20 @@ public class MusicSelectionPage extends Page {
addListener(new InputListener() { addListener(new InputListener() {
@Override @Override
public boolean keyDown(InputEvent event, int keycode) { public boolean keyDown(InputEvent event, int keycode) {
Gdx.app.debug("MusicSelectionPage", "Scrolling");
int index; int index;
if (keycode == Keys.DOWN) { if (keycode == Keys.DOWN) {
if ((index = (songTable.getChildren().indexOf(currentlySelected, true) - 1)) < 0) { if ((index = (songTable.getChildren().indexOf(currentlySelected, true) + 1)) == songTable.getChildren().size) {
index = songTable.getChildren().size; index = 0;
} }
deselectAll(); deselectAll();
((MusicSelectable)songTable.getChildren().get(index)).select(); ((MusicSelectable)songTable.getChildren().get(index)).select();
scrollbar.scrollTo(currentlySelected.getX(), currentlySelected.getY(), currentlySelected.getWidth(), currentlySelected.getHeight()); scrollbar.scrollTo(currentlySelected.getX(), currentlySelected.getY(), currentlySelected.getWidth(), currentlySelected.getHeight());
} }
if (keycode == Keys.UP) { if (keycode == Keys.UP) {
if ((index = (songTable.getChildren().indexOf(currentlySelected, true) + 1)) < songTable.getChildren().size -1) { if ((index = (songTable.getChildren().indexOf(currentlySelected, true) - 1)) < 0) {
index = 0;
index = songTable.getChildren().size-1;
} }
deselectAll(); deselectAll();
((MusicSelectable)songTable.getChildren().get(index)).select(); ((MusicSelectable)songTable.getChildren().get(index)).select();