music selection screen now changes song; currently playing song is now highlighted on screen open;

This commit is contained in:
Harrison Deng 2017-11-23 20:14:17 -06:00
parent 6cc9288c13
commit 8cebf891a0
16 changed files with 275 additions and 219 deletions

View File

@ -43,12 +43,14 @@ public class Mp3Manager implements MusicManager {
private byte[] workset; private byte[] workset;
private int indexHead = -1; private int indexHead = -1;
private FileHandle file;
ReentrantLock lock = new ReentrantLock(); ReentrantLock lock = new ReentrantLock();
private ExecutorService exec; private ExecutorService exec;
private String basicSongName; private String basicSongName;
public Mp3Manager(FileHandle audioFile) { public Mp3Manager(FileHandle audioFile) {
this.file = audioFile;
lock = new ReentrantLock(); lock = new ReentrantLock();
this.basicSongName = audioFile.name(); this.basicSongName = audioFile.name();
exec = Executors.newSingleThreadExecutor(); exec = Executors.newSingleThreadExecutor();
@ -250,4 +252,9 @@ public class Mp3Manager implements MusicManager {
public String getBasicSongName() { public String getBasicSongName() {
return basicSongName; return basicSongName;
} }
@Override
public FileHandle getMusicFile() {
return file;
}
} }

View File

@ -6,11 +6,11 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
public class SongList extends Observable { public class MusicList extends Observable {
private Array<FileHandle> songList; private Array<FileHandle> songList;
private String searchPath; private String searchPath;
private boolean searched; private boolean searched;
public SongList() { public MusicList() {
songList = new Array<>(); songList = new Array<>();
} }
@ -53,7 +53,7 @@ public class SongList extends Observable {
return getAudioData(songList.get(index)); return getAudioData(songList.get(index));
} }
public int getAmountOfSongs() { public int getAmountOfMusic() {
return songList.size; return songList.size;
} }

View File

@ -0,0 +1,138 @@
package zero1hd.rhythmbullet.audio;
import java.security.InvalidParameterException;
import java.util.Observable;
import java.util.Random;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Music.OnCompletionListener;
public class MusicListController extends Observable implements OnCompletionListener {
private MusicList musicList;
private MusicManager mm;
private int currentPlaybackID;
private boolean autoPlay;
private boolean shuffle;
private Random rand;
private Preferences prefs;
public MusicListController(MusicList musicList, Preferences prefs) {
if (prefs == null) throw new NullPointerException("preferences can't be null...");
if (musicList == null) throw new NullPointerException("music list can't be null...");
if (!musicList.isSearched()) throw new InvalidParameterException("music list has to be searched already.");
this.prefs = prefs;
this.musicList = musicList;
rand = new Random();
changeMusic();
}
public void play() {
mm.play();
mm.setVolume(prefs.getFloat("music vol", 1f));
}
public void setMusicByIndex(int index) {
this.currentPlaybackID = index;
changeMusic();
}
public void skip() {
currentPlaybackID++;
if (shuffle) {
shuffle(false);
}
changeMusic();
}
public void previous() {
currentPlaybackID--;
if (shuffle) {
shuffle(false);
}
changeMusic();
}
@Override
public void onCompletion(Music music) {
if (autoPlay) {
if (shuffle) {
if (musicList.getAmountOfMusic() != 0) {
currentPlaybackID = rand.nextInt(musicList.getAmountOfMusic());
} else {
currentPlaybackID = 0;
}
} else {
currentPlaybackID++;
if (currentPlaybackID > musicList.getAmountOfMusic()) {
currentPlaybackID = 0;
}
}
changeMusic();
play();
}
}
/**
* Shuffles the controller whether the shuffle boolean is true or false.
* @param load whether this method should also make sure to load the music, dispose of the last one, etc. Normally called unless you plan to manually call it elswhere.
*/
public void shuffle(boolean load) {
if (musicList.getAmountOfMusic() == 0) {
currentPlaybackID = 0;
} else {
currentPlaybackID = rand.nextInt(musicList.getAmountOfMusic());
}
if (load) {
changeMusic();
}
}
public void setAutoPlay(boolean autoPlay) {
this.autoPlay = autoPlay;
}
public void setShuffle(boolean shuffle) {
this.shuffle = shuffle;
}
public boolean isShuffle() {
return shuffle;
}
public boolean isAutoPlay() {
return autoPlay;
}
private void changeMusic() {
if (mm != null) {
mm.dispose();
}
if (currentPlaybackID < 0) {
currentPlaybackID = musicList.getAmountOfMusic();
}
this.mm = musicList.getMusicInfoFromIndex(currentPlaybackID);
if (mm == null) {
if (!Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3").exists()) {
Gdx.files.internal("music/Alan Walker - Spectre.mp3").copyTo(Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3"));
}
mm = musicList.getAudioData(Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3"));
}
mm.setOnCompletionListener(this);
setChanged();
notifyObservers(mm);
}
public MusicList getMusicList() {
return musicList;
}
public MusicManager getCurrentMusicManager() {
return mm;
}
}

View File

@ -2,6 +2,7 @@
package zero1hd.rhythmbullet.audio; package zero1hd.rhythmbullet.audio;
import com.badlogic.gdx.audio.Music.OnCompletionListener; import com.badlogic.gdx.audio.Music.OnCompletionListener;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Disposable; import com.badlogic.gdx.utils.Disposable;
public interface MusicManager extends Disposable { public interface MusicManager extends Disposable {
@ -81,4 +82,9 @@ public interface MusicManager extends Disposable {
* @return basic song name * @return basic song name
*/ */
public String getBasicSongName(); public String getBasicSongName();
/**
* @return the song filehandle.
*/
public FileHandle getMusicFile();
} }

View File

@ -1,137 +0,0 @@
package zero1hd.rhythmbullet.audio;
import java.security.InvalidParameterException;
import java.util.Observable;
import java.util.Random;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Music.OnCompletionListener;
public class SongListController extends Observable implements OnCompletionListener {
private SongList songList;
private MusicManager mdp;
private int currentPlaybackID;
private boolean autoPlay;
private boolean shuffle;
private Random rand;
private Preferences prefs;
public SongListController(SongList songList, Preferences prefs) {
if (prefs == null) throw new NullPointerException("preferences can't be null...");
if (songList == null) throw new NullPointerException("song list can't be null...");
if (!songList.isSearched()) throw new InvalidParameterException("Song list has to be searched already.");
this.prefs = prefs;
this.songList = songList;
rand = new Random();
changeSong();
}
public void play() {
mdp.play();
mdp.setVolume(prefs.getFloat("music vol", 1f));
}
public void setSongByIndex(int index) {
this.currentPlaybackID = index;
changeSong();
}
public void skip() {
currentPlaybackID++;
changeSong();
}
public void previous() {
currentPlaybackID--;
changeSong();
}
@Override
public void onCompletion(Music music) {
if (autoPlay) {
if (shuffle) {
if (songList.getAmountOfSongs() != 0) {
currentPlaybackID = rand.nextInt(songList.getAmountOfSongs());
} else {
currentPlaybackID = 0;
}
} else {
currentPlaybackID++;
if (currentPlaybackID > songList.getAmountOfSongs()) {
currentPlaybackID = 0;
}
}
changeSong();
play();
}
}
public void shuffle() {
if (songList.getAmountOfSongs() == 0) {
currentPlaybackID = 0;
} else {
currentPlaybackID = rand.nextInt(songList.getAmountOfSongs());
}
changeSong();
}
public void setAutoPlay(boolean autoPlay) {
this.autoPlay = autoPlay;
}
public void setShuffle(boolean shuffle) {
this.shuffle = shuffle;
}
public boolean isShuffle() {
return shuffle;
}
public boolean isAutoPlay() {
return autoPlay;
}
private void changeSong() {
if (mdp != null) {
mdp.dispose();
}
if (shuffle) {
if (songList.getAmountOfSongs() == 0) {
currentPlaybackID = 0;
} else {
currentPlaybackID = rand.nextInt(songList.getAmountOfSongs());
}
} else {
if (currentPlaybackID > songList.getAmountOfSongs() -1) {
currentPlaybackID = 0;
}
}
if (currentPlaybackID < 0) {
currentPlaybackID = songList.getAmountOfSongs();
}
this.mdp = songList.getMusicInfoFromIndex(currentPlaybackID);
if (mdp == null) {
if (!Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3").exists()) {
Gdx.files.internal("music/Alan Walker - Spectre.mp3").copyTo(Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3"));
}
mdp = songList.getAudioData(Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3"));
}
mdp.setOnCompletionListener(this);
setChanged();
notifyObservers(mdp);
}
public SongList getSongList() {
return songList;
}
public MusicManager getCurrentSong() {
return mdp;
}
}

View File

@ -19,9 +19,10 @@ public class WAVManager implements MusicManager {
private int currentReadWindowIndex; private int currentReadWindowIndex;
private Music playbackMusic; private Music playbackMusic;
WavDecoder decoder; WavDecoder decoder;
private FileHandle file;
private String basicSongName; private String basicSongName;
public WAVManager(FileHandle file) { public WAVManager(FileHandle file) {
this.file = file;
basicSongName = file.name(); basicSongName = file.name();
try { try {
decoder = new WavDecoder(file); decoder = new WavDecoder(file);
@ -134,4 +135,9 @@ public class WAVManager implements MusicManager {
public String getBasicSongName() { public String getBasicSongName() {
return basicSongName; return basicSongName;
} }
@Override
public FileHandle getMusicFile() {
return file;
}
} }

View File

@ -7,21 +7,21 @@ import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import zero1hd.rhythmbullet.audio.SongListController; import zero1hd.rhythmbullet.audio.MusicListController;
public class MusicControls extends HorizontalGroup { public class MusicControls extends HorizontalGroup {
private SongListController sc; private MusicListController sc;
private ImageButton reverse, forward; private ImageButton reverse, forward;
private CheckBox shuffle, play; private CheckBox shuffle, play;
private float disableTimer; private float disableTimer;
public MusicControls(Skin skin, SongListController sc) { public MusicControls(Skin skin, MusicListController sc) {
this.sc = sc; this.sc = sc;
reverse = new ImageButton(skin, "rewind-button"); reverse = new ImageButton(skin, "rewind-button");
reverse.addListener(new ChangeListener() { reverse.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
boolean wasPlaying = sc.getCurrentSong().isPlaying(); boolean wasPlaying = sc.getCurrentMusicManager().isPlaying();
sc.previous(); sc.previous();
if (wasPlaying) { if (wasPlaying) {
sc.play(); sc.play();
@ -37,7 +37,7 @@ public class MusicControls extends HorizontalGroup {
play = new CheckBox(null, skin, "play-button") { play = new CheckBox(null, skin, "play-button") {
@Override @Override
public void act(float delta) { public void act(float delta) {
play.setChecked(sc.getCurrentSong().isPlaying()); play.setChecked(sc.getCurrentMusicManager().isPlaying());
super.act(delta); super.act(delta);
} }
}; };
@ -45,9 +45,9 @@ public class MusicControls extends HorizontalGroup {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
if (play.isChecked()) { if (play.isChecked()) {
sc.getCurrentSong().play(); sc.getCurrentMusicManager().play();
} else { } else {
sc.getCurrentSong().pause(); sc.getCurrentMusicManager().pause();
} }
} }
}); });
@ -57,7 +57,7 @@ public class MusicControls extends HorizontalGroup {
forward.addListener(new ChangeListener() { forward.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
boolean wasPlaying = sc.getCurrentSong().isPlaying(); boolean wasPlaying = sc.getCurrentMusicManager().isPlaying();
sc.skip(); sc.skip();
if (wasPlaying) { if (wasPlaying) {
sc.play(); sc.play();

View File

@ -67,7 +67,6 @@ public class MusicSelectable extends WidgetGroup implements Disposable {
addListener(new ClickListener() { addListener(new ClickListener() {
@Override @Override
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
msp.deselectAll();
select(); select();
super.clicked(event, x, y); super.clicked(event, x, y);
} }
@ -125,7 +124,12 @@ public class MusicSelectable extends WidgetGroup implements Disposable {
return songInfo.isInvalidMusic(); return songInfo.isInvalidMusic();
} }
/**
* Selects this panel
* @param updateGlobalSelection whether or not to tell everything that this is selected. Usually true unless you set the global somewhere else.
*/
public void select() { public void select() {
msp.deselectAll();
table.setBackground("holo-pane-down"); table.setBackground("holo-pane-down");
selected = true; selected = true;
msp.setCurrentlySelected(this); msp.setCurrentlySelected(this);

View File

@ -16,7 +16,7 @@ import com.badlogic.gdx.utils.Align;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.MusicManager; import zero1hd.rhythmbullet.audio.MusicManager;
import zero1hd.rhythmbullet.audio.SongListController; import zero1hd.rhythmbullet.audio.MusicListController;
import zero1hd.rhythmbullet.graphics.ui.components.MusicControls; import zero1hd.rhythmbullet.graphics.ui.components.MusicControls;
import zero1hd.rhythmbullet.graphics.ui.components.ScrollText; import zero1hd.rhythmbullet.graphics.ui.components.ScrollText;
import zero1hd.rhythmbullet.graphics.ui.components.TitleBarVisualizer; import zero1hd.rhythmbullet.graphics.ui.components.TitleBarVisualizer;
@ -25,7 +25,7 @@ import zero1hd.rhythmbullet.screens.MainMenu;
public class MainPage extends Page implements Observer { public class MainPage extends Page implements Observer {
private Label versionLabel; private Label versionLabel;
private SongListController sc; private MusicListController sc;
private TitleBarVisualizer titleBar; private TitleBarVisualizer titleBar;
private Table table; private Table table;
private TextButton playButton; private TextButton playButton;
@ -35,7 +35,7 @@ public class MainPage extends Page implements Observer {
private MusicControls musicControls; private MusicControls musicControls;
private ScrollText scrollText; private ScrollText scrollText;
public MainPage(RhythmBullet core, Vector3 targetPosition, SongListController sc, MainMenu mm) { public MainPage(RhythmBullet core, Vector3 targetPosition, MusicListController sc, MainMenu mm) {
this.sc = sc; this.sc = sc;
setTextureBackground(core.getAssetManager().get("gradients.atlas", TextureAtlas.class).findRegion("red-linear")); setTextureBackground(core.getAssetManager().get("gradients.atlas", TextureAtlas.class).findRegion("red-linear"));
@ -120,6 +120,6 @@ public class MainPage extends Page implements Observer {
public void updateVisualsForDifferentSong(MusicManager mm) { public void updateVisualsForDifferentSong(MusicManager mm) {
titleBar.getHvisual().setMM(mm); titleBar.getHvisual().setMM(mm);
scrollText.setText(mm.getBasicSongName(), null); scrollText.setText("Currently playing: " + mm.getBasicSongName(), null);
} }
} }

View File

@ -27,17 +27,18 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import zero1hd.rhythmbullet.audio.MusicManager;
import zero1hd.rhythmbullet.audio.SongInfo; import zero1hd.rhythmbullet.audio.SongInfo;
import zero1hd.rhythmbullet.audio.SongList; import zero1hd.rhythmbullet.audio.MusicListController;
import zero1hd.rhythmbullet.graphics.ui.components.MusicSelectable; import zero1hd.rhythmbullet.graphics.ui.components.MusicSelectable;
import zero1hd.rhythmbullet.graphics.ui.components.ScrollText; import zero1hd.rhythmbullet.graphics.ui.components.ScrollText;
public class MusicSelectionPage extends Page implements Observer { public class MusicSelectionPage extends Page implements Observer {
Preferences musicFileAnnotation; Preferences musicFileAnnotation;
private SongList songList; private MusicListController mc;
private Array<MusicSelectable> selectables; private Array<MusicSelectable> selectables;
private Table songTable; private Table musicTable;
private ScrollPane scrollbar; private ScrollPane scrollbar;
private TextButton back; private TextButton back;
@ -61,10 +62,10 @@ public class MusicSelectionPage extends Page implements Observer {
private Texture white; private Texture white;
private boolean down, up; private boolean down, up;
private int index; private int musicSelectableIndex;
private float scrollTimer, scrollDelay = 0.2f, scrollDelMod; private float scrollTimer, scrollDelay = 0.2f, scrollDelMod, songSelectionTimer;
public MusicSelectionPage(Skin skin, SongList songList, AssetManager assetManager, Vector3 cameraTarget) { public MusicSelectionPage(Skin skin, MusicListController musicList, AssetManager assetManager, Vector3 cameraTarget) {
super("Select music", skin); super("Select music", skin);
songInfoTable = new Table(); songInfoTable = new Table();
songTitle = new ScrollText("", null, skin, false, false); songTitle = new ScrollText("", null, skin, false, false);
@ -75,12 +76,12 @@ public class MusicSelectionPage extends Page implements Observer {
setTextureBackground(assetManager.get("gradients.atlas", TextureAtlas.class).findRegion("red-round")); setTextureBackground(assetManager.get("gradients.atlas", TextureAtlas.class).findRegion("red-round"));
this.skin = skin; this.skin = skin;
this.songList = songList; this.mc = musicList;
musicFileAnnotation = Gdx.app.getPreferences("music_file_annotation"); musicFileAnnotation = Gdx.app.getPreferences("music_file_annotation");
this.assets = assetManager; this.assets = assetManager;
songTable = new Table(); musicTable = new Table();
songTable.defaults().spaceBottom(10f); musicTable.defaults().spaceBottom(10f);
scrollbar = new ScrollPane(songTable, skin); scrollbar = new ScrollPane(musicTable, skin);
scrollbar.setSize(0.45f*getWidth(), getHeightBelowTitle()); scrollbar.setSize(0.45f*getWidth(), getHeightBelowTitle());
scrollbar.setFadeScrollBars(false); scrollbar.setFadeScrollBars(false);
scrollbar.setOverscroll(false, false); scrollbar.setOverscroll(false, false);
@ -153,6 +154,7 @@ public class MusicSelectionPage extends Page implements Observer {
if (scrollTimer <= 0) { if (scrollTimer <= 0) {
scrollTimer = scrollDelay*scrollDelMod; scrollTimer = scrollDelay*scrollDelMod;
scrollDown(); scrollDown();
} else { } else {
scrollTimer -= delta; scrollTimer -= delta;
} }
@ -169,6 +171,13 @@ public class MusicSelectionPage extends Page implements Observer {
scrollTimer -= delta; scrollTimer -= delta;
} }
} }
if (songSelectionTimer > 0f) {
songSelectionTimer -= delta;
if (songSelectionTimer <= 0f) {
playCurrentMusic();
}
}
super.act(delta); super.act(delta);
} }
@ -181,20 +190,20 @@ public class MusicSelectionPage extends Page implements Observer {
} }
public void refresh() { public void refresh() {
songTable.clear(); musicTable.clear();
selectables.clear(); selectables.clear();
for (int i = 0; i < selectables.size; i++) { for (int i = 0; i < selectables.size; i++) {
selectables.get(i).dispose(); selectables.get(i).dispose();
} }
Gdx.app.debug("MusicSelectionPage", "Refreshing..."); Gdx.app.debug("MusicSelectionPage", "Refreshing...");
for (int i = 0; i < songList.getAmountOfSongs(); i++) { for (int i = 0; i < mc.getMusicList().getAmountOfMusic(); i++) {
MusicSelectable selectable = new MusicSelectable(songList.getSongFileHandleFromIndex(i), musicFileAnnotation, skin, assets.get("defaultCover.png", Texture.class), this); MusicSelectable selectable = new MusicSelectable(mc.getMusicList().getSongFileHandleFromIndex(i), musicFileAnnotation, skin, assets.get("defaultCover.png", Texture.class), this);
selectables.add(selectable); selectables.add(selectable);
songTable.add(selectable).expandX().fillX(); musicTable.add(selectable).expandX().fillX();
songTable.row(); musicTable.row();
} }
ExecutorService exec = Executors.newSingleThreadExecutor(); ExecutorService exec = Executors.newSingleThreadExecutor();
@ -230,32 +239,54 @@ public class MusicSelectionPage extends Page implements Observer {
public void setCurrentlySelected(MusicSelectable currentlySelected) { public void setCurrentlySelected(MusicSelectable currentlySelected) {
this.currentlySelected = currentlySelected; this.currentlySelected = currentlySelected;
songSelectionTimer = 1f;
} }
private void scrollDown() { private void scrollDown() {
if ((index = (songTable.getChildren().indexOf(currentlySelected, true) + 1)) == songTable.getChildren().size) { if ((musicSelectableIndex = (musicTable.getChildren().indexOf(currentlySelected, true) + 1)) == musicTable.getChildren().size) {
index = 0; musicSelectableIndex = 0;
} }
deselectAll(); ((MusicSelectable)musicTable.getChildren().get(musicSelectableIndex)).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());
} }
private void scrollUp() { private void scrollUp() {
if ((index = (songTable.getChildren().indexOf(currentlySelected, true) - 1)) < 0) { if ((musicSelectableIndex = (musicTable.getChildren().indexOf(currentlySelected, true) - 1)) < 0) {
index = songTable.getChildren().size-1; musicSelectableIndex = musicTable.getChildren().size-1;
} }
deselectAll(); deselectAll();
((MusicSelectable)musicTable.getChildren().get(musicSelectableIndex)).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());
} }
@Override @Override
public void update(Observable o, Object arg) { public void update(Observable o, Object arg) {
if (o == songList) { MusicManager mm = (MusicManager) arg;
deselectAll(); if (o == mc) {
selectSong(mm);
}
}
public void selectSong(MusicManager mm) {
if (currentlySelected == null || mm.getMusicFile() != currentlySelected.getMusicFile()) {
for (int i = 0; i < selectables.size; i++) {
if (selectables.get(i).getMusicFile() == mm.getMusicFile()) {
selectables.get(i).select();
musicSelectableIndex = i;
break;
}
}
}
}
public void playCurrentMusic() {
if (currentlySelected.getMusicFile() != mc.getCurrentMusicManager().getMusicFile()) {
int index = mc.getMusicList().getSongList().indexOf(currentlySelected.getMusicFile(), true);
boolean playing = mc.getCurrentMusicManager().isPlaying();
mc.setMusicByIndex(index);
if (playing) {
mc.play();
}
} }
} }
} }

View File

@ -19,7 +19,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.SongListController; import zero1hd.rhythmbullet.audio.MusicListController;
import zero1hd.rhythmbullet.screens.CreativeScreen; import zero1hd.rhythmbullet.screens.CreativeScreen;
import zero1hd.rhythmbullet.screens.MainMenu; import zero1hd.rhythmbullet.screens.MainMenu;
@ -30,7 +30,7 @@ public class OptionsPage extends Page {
private TextField directoryField; private TextField directoryField;
private float musicSearchTimer; private float musicSearchTimer;
public OptionsPage(RhythmBullet core, Vector3 targetPosition, KeybindOptionsPage moreOptionsPage, SongListController sc) { public OptionsPage(RhythmBullet core, Vector3 targetPosition, KeybindOptionsPage moreOptionsPage, MusicListController sc) {
super("General", core.getDefaultSkin()); super("General", core.getDefaultSkin());
setTextureBackground(core.getAssetManager().get("gradients.atlas", TextureAtlas.class).findRegion("red-round")); setTextureBackground(core.getAssetManager().get("gradients.atlas", TextureAtlas.class).findRegion("red-round"));
//Back button //Back button
@ -62,7 +62,7 @@ public class OptionsPage extends Page {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
musicVolPercentage.setText(MathUtils.round(musicVolSlider.getValue()) + "%"); musicVolPercentage.setText(MathUtils.round(musicVolSlider.getValue()) + "%");
sc.getCurrentSong().setVolume(musicVolSlider.getPercent()); sc.getCurrentMusicManager().setVolume(musicVolSlider.getPercent());
core.getPrefs().putFloat("music vol", musicVolSlider.getPercent()); core.getPrefs().putFloat("music vol", musicVolSlider.getPercent());
} }
@ -91,16 +91,16 @@ public class OptionsPage extends Page {
Label musicDirectoryLabel = new Label("Music Directory: ", core.getDefaultSkin()); Label musicDirectoryLabel = new Label("Music Directory: ", core.getDefaultSkin());
optionsTable.add(musicDirectoryLabel).left(); optionsTable.add(musicDirectoryLabel).left();
Label songCount = new Label("Songs: " + sc.getSongList().getAmountOfSongs(), core.getDefaultSkin(), "sub-font", core.getDefaultSkin().getColor("default")); Label songCount = new Label("Songs: " + sc.getMusicList().getAmountOfMusic(), core.getDefaultSkin(), "sub-font", core.getDefaultSkin().getColor("default"));
directoryField = new TextField(null, core.getDefaultSkin() ) { directoryField = new TextField(null, core.getDefaultSkin() ) {
@Override @Override
public void act(float delta) { public void act(float delta) {
if (musicSearchTimer > 0) { if (musicSearchTimer > 0) {
musicSearchTimer -= delta; musicSearchTimer -= delta;
if (musicSearchTimer <= 0) { if (musicSearchTimer <= 0) {
sc.getSongList().setSearchPath(directoryField.getText()); sc.getMusicList().setSearchPath(directoryField.getText());
sc.getSongList().refresh(); sc.getMusicList().refresh();
songCount.setText("Songs: " + sc.getSongList().getAmountOfSongs()); songCount.setText("Songs: " + sc.getMusicList().getAmountOfMusic());
} }
} }
super.act(delta); super.act(delta);
@ -154,7 +154,7 @@ public class OptionsPage extends Page {
Gdx.app.debug("Debug Field", debugCodeField.getText()); Gdx.app.debug("Debug Field", debugCodeField.getText());
if (debugCodeField.getText().equals("creative")) { if (debugCodeField.getText().equals("creative")) {
Gdx.app.debug("Debug Field", "going to creative test room..."); Gdx.app.debug("Debug Field", "going to creative test room...");
core.setScreen(new CreativeScreen(core, (MainMenu) core.getScreen(), sc.getSongList())); core.setScreen(new CreativeScreen(core, (MainMenu) core.getScreen(), sc.getMusicList()));
} }
} }
return super.keyUp(event, keycode); return super.keyUp(event, keycode);

View File

@ -12,7 +12,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import zero1hd.rhythmbullet.audio.MusicManager; import zero1hd.rhythmbullet.audio.MusicManager;
import zero1hd.rhythmbullet.audio.SongList; import zero1hd.rhythmbullet.audio.MusicList;
import zero1hd.rhythmbullet.util.MiniEvents; import zero1hd.rhythmbullet.util.MiniEvents;
import zero1hd.rhythmbullet.util.MiniSender; import zero1hd.rhythmbullet.util.MiniSender;
@ -23,10 +23,10 @@ public class MusicSelector extends Window {
Array<String> fileNames; Array<String> fileNames;
private List<String> musicList; private List<String> musicList;
private ScrollPane listScroller; private ScrollPane listScroller;
private SongList songList; private MusicList songList;
public MiniSender miniSender; public MiniSender miniSender;
public MusicSelector(String title, Skin skin, final String path, SongList songList) { public MusicSelector(String title, Skin skin, final String path, MusicList songList) {
super(title, skin, "tinted"); super(title, skin, "tinted");
padTop(25f); padTop(25f);
padLeft(5f); padLeft(5f);

View File

@ -3,7 +3,7 @@ package zero1hd.rhythmbullet.screens;
import com.badlogic.gdx.Preferences; import com.badlogic.gdx.Preferences;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.SongList; import zero1hd.rhythmbullet.audio.MusicList;
import zero1hd.rhythmbullet.stages.CreativeHUD; import zero1hd.rhythmbullet.stages.CreativeHUD;
public class CreativeScreen extends GameScreen { public class CreativeScreen extends GameScreen {
@ -11,7 +11,7 @@ public class CreativeScreen extends GameScreen {
Preferences prefs; Preferences prefs;
public CreativeScreen(RhythmBullet core, MainMenu mainMenu, SongList sl) { public CreativeScreen(RhythmBullet core, MainMenu mainMenu, MusicList sl) {
super(core, mainMenu); super(core, mainMenu);
chud = new CreativeHUD(core, mainMenu, gameArea, gameHUD, sl); chud = new CreativeHUD(core, mainMenu, gameArea, gameHUD, sl);
inputs.addProcessor(chud); inputs.addProcessor(chud);

View File

@ -22,8 +22,8 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.viewport.ScreenViewport; import com.badlogic.gdx.utils.viewport.ScreenViewport;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.SongList; import zero1hd.rhythmbullet.audio.MusicList;
import zero1hd.rhythmbullet.audio.SongListController; import zero1hd.rhythmbullet.audio.MusicListController;
import zero1hd.rhythmbullet.graphics.ui.pages.CreditsPage; import zero1hd.rhythmbullet.graphics.ui.pages.CreditsPage;
import zero1hd.rhythmbullet.graphics.ui.pages.KeybindOptionsPage; import zero1hd.rhythmbullet.graphics.ui.pages.KeybindOptionsPage;
import zero1hd.rhythmbullet.graphics.ui.pages.MainPage; import zero1hd.rhythmbullet.graphics.ui.pages.MainPage;
@ -45,7 +45,7 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter, Observ
private RhythmBullet core; private RhythmBullet core;
private SongListController sc; private MusicListController mc;
private float lerpAlpha; private float lerpAlpha;
private ShaderProgram gaussianBlurShader; private ShaderProgram gaussianBlurShader;
@ -65,13 +65,13 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter, Observ
stage = new Stage(new ScreenViewport()); stage = new Stage(new ScreenViewport());
cameraPosition = new Vector3(stage.getCamera().position); cameraPosition = new Vector3(stage.getCamera().position);
SongList songList = new SongList(); MusicList songList = new MusicList();
songList.setSearchPath(core.getPrefs().getString("music dir")); songList.setSearchPath(core.getPrefs().getString("music dir"));
songList.refresh(); songList.refresh();
sc = new SongListController(songList, core.getPrefs()); mc = new MusicListController(songList, core.getPrefs());
sc.setAutoPlay(true); mc.setAutoPlay(true);
sc.setShuffle(true); mc.setShuffle(true);
sc.shuffle(); mc.shuffle(true);
postTransition(); postTransition();
} }
@ -80,7 +80,7 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter, Observ
public void postTransition() { public void postTransition() {
attemptLoadShaders(); attemptLoadShaders();
mainPage = new MainPage(core, cameraPosition, sc, this); mainPage = new MainPage(core, cameraPosition, mc, this);
mainPage.setPosition(0, 0); mainPage.setPosition(0, 0);
stage.addActor(mainPage); stage.addActor(mainPage);
//End main menu //End main menu
@ -94,7 +94,7 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter, Observ
graphicsPage.setPosition(-1f*Gdx.graphics.getWidth(), 1f*Gdx.graphics.getHeight()); graphicsPage.setPosition(-1f*Gdx.graphics.getWidth(), 1f*Gdx.graphics.getHeight());
stage.addActor(graphicsPage); stage.addActor(graphicsPage);
optionsPage = new OptionsPage(core, cameraPosition, keybindPage, sc); optionsPage = new OptionsPage(core, cameraPosition, keybindPage, mc);
optionsPage.setPosition(-Gdx.graphics.getWidth(), 0); optionsPage.setPosition(-Gdx.graphics.getWidth(), 0);
stage.addActor(optionsPage); stage.addActor(optionsPage);
@ -102,7 +102,7 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter, Observ
creditsPage.setPosition(0, Gdx.graphics.getHeight()); creditsPage.setPosition(0, Gdx.graphics.getHeight());
stage.addActor(creditsPage); stage.addActor(creditsPage);
musicSelectionPage = new MusicSelectionPage(core.getDefaultSkin(), sc.getSongList(), core.getAssetManager(), cameraPosition); musicSelectionPage = new MusicSelectionPage(core.getDefaultSkin(), mc, core.getAssetManager(), cameraPosition);
musicSelectionPage.setPosition(1f*Gdx.graphics.getWidth(), 0f); musicSelectionPage.setPosition(1f*Gdx.graphics.getWidth(), 0f);
stage.addActor(musicSelectionPage); stage.addActor(musicSelectionPage);
@ -131,11 +131,11 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter, Observ
super.clicked(event, x, y); super.clicked(event, x, y);
} }
}); });
sc.deleteObservers(); mc.deleteObservers();
sc.addObserver(mainPage); mc.addObserver(mainPage);
mainPage.updateVisualsForDifferentSong(sc.getCurrentSong()); mc.addObserver(musicSelectionPage);
mainPage.updateVisualsForDifferentSong(mc.getCurrentMusicManager());
sc.getSongList().addObserver(this); mc.getMusicList().addObserver(this);
Gdx.app.debug("Post Transition", "Beginning screen setup for Main menu."); Gdx.app.debug("Post Transition", "Beginning screen setup for Main menu.");
} }
@ -293,7 +293,8 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter, Observ
@Override @Override
public void show() { public void show() {
Gdx.input.setInputProcessor(stage); Gdx.input.setInputProcessor(stage);
sc.play(); mc.play();
musicSelectionPage.selectSong(mc.getCurrentMusicManager());
calcLerpAlpha(Gdx.graphics.getWidth()); calcLerpAlpha(Gdx.graphics.getWidth());
super.show(); super.show();
} }
@ -369,7 +370,7 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter, Observ
@Override @Override
public void update(Observable o, Object arg) { public void update(Observable o, Object arg) {
if (o == sc.getSongList()) { if (o == mc.getMusicList()) {
musicSelectionPage.refresh(); musicSelectionPage.refresh();
} }
} }

View File

@ -8,7 +8,7 @@ import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.viewport.ScreenViewport; import com.badlogic.gdx.utils.viewport.ScreenViewport;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.SongList; import zero1hd.rhythmbullet.audio.MusicListController;
import zero1hd.rhythmbullet.graphics.ui.pages.AnalyzePage; import zero1hd.rhythmbullet.graphics.ui.pages.AnalyzePage;
import zero1hd.rhythmbullet.graphics.ui.pages.MusicSelectionPage; import zero1hd.rhythmbullet.graphics.ui.pages.MusicSelectionPage;
import zero1hd.rhythmbullet.util.MiniEvents; import zero1hd.rhythmbullet.util.MiniEvents;
@ -23,13 +23,13 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, M
public AnalyzePage ap; public AnalyzePage ap;
private Vector3 cameraPos; private Vector3 cameraPos;
private RhythmBullet core; private RhythmBullet core;
private SongList songList; private MusicListController songListController;
public PreGameScreen(RhythmBullet core, SongList songList) { public PreGameScreen(RhythmBullet core, MusicListController songList) {
stage = new Stage(new ScreenViewport()); stage = new Stage(new ScreenViewport());
cameraPos = new Vector3(stage.getCamera().position); cameraPos = new Vector3(stage.getCamera().position);
this.core = core; this.core = core;
this.songList = songList; this.songListController = songList;
postTransition(); postTransition();
} }
@ -64,7 +64,7 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, M
switch (ID) { switch (ID) {
case MUSIC_SELECTED: case MUSIC_SELECTED:
cameraPos.x = 1.5f*Gdx.graphics.getWidth(); cameraPos.x = 1.5f*Gdx.graphics.getWidth();
ap.setSong(songList.getAudioData(ms.getSelectedMusic()), ms.getSelectedMusicInfo(), this); ap.setSong(songListController.getMusicList().getAudioData(ms.getSelectedMusic()), ms.getSelectedMusicInfo(), this);
break; break;
case BACK: case BACK:
if (cameraPos.x == 1.5f*Gdx.graphics.getWidth()) { if (cameraPos.x == 1.5f*Gdx.graphics.getWidth()) {
@ -87,7 +87,7 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, M
@Override @Override
public void postTransition() { public void postTransition() {
ms = new MusicSelectionPage(core.getDefaultSkin(), songList, core.getAssetManager(), cameraPos); ms = new MusicSelectionPage(core.getDefaultSkin(), songListController, core.getAssetManager(), cameraPos);
ms.miniSender.addListener(this); ms.miniSender.addListener(this);
stage.addActor(ms); stage.addActor(ms);

View File

@ -16,7 +16,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.AudioAnalyzer; import zero1hd.rhythmbullet.audio.AudioAnalyzer;
import zero1hd.rhythmbullet.audio.AudioDataPackage; import zero1hd.rhythmbullet.audio.AudioDataPackage;
import zero1hd.rhythmbullet.audio.SongList; import zero1hd.rhythmbullet.audio.MusicList;
import zero1hd.rhythmbullet.audio.map.RhythmMapAlgorithm; import zero1hd.rhythmbullet.audio.map.RhythmMapAlgorithm;
import zero1hd.rhythmbullet.graphics.ui.components.AudioGraph; import zero1hd.rhythmbullet.graphics.ui.components.AudioGraph;
import zero1hd.rhythmbullet.graphics.ui.windows.BeatViewer; import zero1hd.rhythmbullet.graphics.ui.windows.BeatViewer;
@ -47,7 +47,7 @@ public class CreativeHUD extends Stage implements MiniListener {
GamePlayArea gpa; GamePlayArea gpa;
GameHUD ghud; GameHUD ghud;
public CreativeHUD(final RhythmBullet core, final MainMenu mainMenu, final GamePlayArea gpa, GameHUD ghud, SongList sl) { public CreativeHUD(final RhythmBullet core, final MainMenu mainMenu, final GamePlayArea gpa, GameHUD ghud, MusicList sl) {
this.gpa = gpa; this.gpa = gpa;
this.ghud = ghud; this.ghud = ghud;