prepared music for playlists

This commit is contained in:
Willem Cazander 2022-03-12 23:21:10 +01:00
parent 3d17c77cc5
commit eec062010d
7 changed files with 86 additions and 81 deletions

View file

@ -1,5 +1,6 @@
package love.distributedrebirth.gdxapp4d.app.tosamp;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
@ -7,6 +8,7 @@ import org.osgi.service.component.annotations.Reference;
import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxBootArgs;
import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxLog;
import love.distributedrebirth.gdxapp4d.tos4.service.SystemWarpShip;
import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4DeskAppService;
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppLauncher;
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppMenuSection;
@ -23,15 +25,18 @@ public class TosAmpComponent {
@Reference
private SystemGdxBootArgs bootArgs;
private final DeskAppLauncher launcher;
@Reference
private SystemWarpShip warpShip;
private DeskAppLauncher launcher;
public TosAmpComponent() {
launcher = new DeskAppLauncher(DeskAppMenuSection.MULTIMEDIA, "TosAmp", () -> new TosAmpDeskApp(bootArgs.getFileChooser()));
}
@Activate
void open() {
void open(final BundleContext context) {
log.debug(this, SystemGdxLog.ACTIVATE);
launcher = new DeskAppLauncher(DeskAppMenuSection.MULTIMEDIA, "TosAmp", () -> new TosAmpDeskApp(bootArgs.getFileChooser(), context, warpShip));
deskAppService.installDeskApp(launcher);
}

View file

@ -2,6 +2,8 @@ package love.distributedrebirth.gdxapp4d.app.tosamp;
import java.util.function.Consumer;
import org.osgi.framework.BundleContext;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
@ -12,6 +14,7 @@ import imgui.flag.ImGuiTableFlags;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
import love.distributedrebirth.gdxapp4d.app.tosamp.music.MusicManager;
import love.distributedrebirth.gdxapp4d.app.tosamp.music.MusicSong;
import love.distributedrebirth.gdxapp4d.tos4.service.SystemWarpShip;
import love.distributedrebirth.gdxapp4d.vrgem4.FontAwesomeIcons;
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.AbstractDeskApp;
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppContourSection;
@ -27,16 +30,16 @@ public class TosAmpDeskApp extends AbstractDeskApp implements DeskAppRenderer {
private final NativeFileChooser fileChooser;
private NativeFileChooserConfiguration fileChooserConfig;
public TosAmpDeskApp(NativeFileChooser fileChooser) {
public TosAmpDeskApp(NativeFileChooser fileChooser, BundleContext context, SystemWarpShip warpShip) {
this.fileChooser = fileChooser;
this.music = new MusicManager();
this.music.init(context, warpShip);
}
public void create() {
getContours().setTitle("\uf001 TosAmp");
getContours().registrateContour(DeskAppContourSection.MAIN, this);
getContours().registrateContour(DeskAppContourSection.FILE_NEW, new DeskAppRenderer() {
@Override
public void render() {
if (ImGui.menuItem(FontAwesomeIcons.Plus + " Add")) {
@ -44,7 +47,6 @@ public class TosAmpDeskApp extends AbstractDeskApp implements DeskAppRenderer {
NativeFileChooserCallbackAdapter.onFileChosen(v -> music.addBackgroundMusic(v)));
}
}
});
fileChooserConfig = new NativeFileChooserConfiguration();
fileChooserConfig.directory = Gdx.files.absolute(System.getProperty("user.home"));
@ -87,17 +89,17 @@ public class TosAmpDeskApp extends AbstractDeskApp implements DeskAppRenderer {
ImGui.tableSetupColumn("Name");
ImGui.tableHeadersRow();
int i=1;
for (MusicSong song:music.getBackgroundSongs()) {
for (MusicSong song:music.getMusicSongs()) {
ImGui.pushID(i);
ImGui.tableNextRow();
ImGui.tableNextColumn();
ImGui.selectable(""+i, song.isPlaying(), ImGuiSelectableFlags.None);
ImGui.selectable(""+i, music.isPlaying(song), ImGuiSelectableFlags.None);
ImGui.tableNextColumn();
if (ImGui.smallButton(">")) {
music.play(song);
}
ImGui.tableNextColumn();
ImGui.selectable(song.getName(), song.isPlaying(), ImGuiSelectableFlags.None);
ImGui.selectable(song.getName(), music.isPlaying(song), ImGuiSelectableFlags.None);
ImGui.popID();
i++;
}
@ -105,7 +107,7 @@ public class TosAmpDeskApp extends AbstractDeskApp implements DeskAppRenderer {
}
static class NativeFileChooserCallbackAdapter implements NativeFileChooserCallback {
@Override
public void onFileChosen(FileHandle file) {
}

View file

@ -1,14 +1,18 @@
package love.distributedrebirth.gdxapp4d.app.tosamp.music;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.osgi.framework.BundleContext;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Music.OnCompletionListener;
import com.badlogic.gdx.files.FileHandle;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
import love.distributedrebirth.gdxapp4d.tos4.service.SystemWarpShip;
/**
* Manages the background and others songs.
@ -16,28 +20,26 @@ import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
public class MusicManager {
// private final MusicSong introSong;
// private final MusicSong creditsSong;
private final List<MusicSong> backgroundSongs;
private final List<MusicSong> musicSongs;
private final NextSongListener nextSongListener;
private MusicSong currentSong = null;
private boolean noMusic = false;
private Music currentMusic = null;
public MusicManager() {
backgroundSongs = new ArrayList<>();
// introSong = new MusicSong(Gdx.audio.newMusic(Gdx.files.internal("music/panoramacircle-waterfowl.mp3")),"panoramacircle-waterfowl");
// creditsSong = new MusicSong(Gdx.audio.newMusic(Gdx.files.internal("music/idtech-doom-sigil.mp3")), "idtech-doom-sigil");
musicSongs = new ArrayList<>();
nextSongListener = new NextSongListener();
}
public void addBackgroundMusic(FileHandle file) {
Music music = Gdx.audio.newMusic(file);
music.setOnCompletionListener(nextSongListener);
backgroundSongs.add(new MusicSong(music, file.name()));
musicSongs.add(new MusicSong(file, file.name()));
}
public void init(boolean noMusic) {
this.noMusic = noMusic;
public void init(BundleContext context, SystemWarpShip warpShip) {
List<File> playlists = warpShip.searchMagic(context, "audio/mpegurl");
for (File playlist:playlists) {
System.out.println("Playlist: "+playlist);
}
/*
addBackgroundMusic(Gdx.files.internal("music/sanctumwave-risen.mp3"));
addBackgroundMusic(Gdx.files.internal("music/sanctumwave-devine-intellect.mp3"));
@ -49,15 +51,13 @@ public class MusicManager {
}
public void dispose() {
// introSong.music.dispose();
// creditsSong.music.dispose();
for (MusicSong song:backgroundSongs) {
song.music.dispose();
if (currentMusic != null) {
currentMusic.dispose();
}
}
public List<MusicSong> getBackgroundSongs() {
return backgroundSongs;
public List<MusicSong> getMusicSongs() {
return musicSongs;
}
public MusicSong getCurrentSong() {
@ -65,29 +65,21 @@ public class MusicManager {
}
public void stop() {
if (currentSong != null) {
currentSong.music.stop();
if (currentMusic != null) {
currentMusic.stop();
}
}
public void play(MusicSongType type) {
public void play() {
MusicSong nextSong = null;
if (MusicSongType.INTRO.equals(type)) {
// nextSong = introSong;
// play(nextSong);
} else if (MusicSongType.CREDITS.equals(type)) {
// nextSong = creditsSong;
// play(nextSong);
int currentBackground = musicSongs.indexOf(currentSong);
if (currentBackground == -1 && !musicSongs.isEmpty()) {
nextSong = musicSongs.get(0);
} else {
int currentBackground = backgroundSongs.indexOf(currentSong);
if (currentBackground == -1 && !backgroundSongs.isEmpty()) {
nextSong = backgroundSongs.get(0);
} else {
nextSong = currentSong;
}
if (!noMusic && nextSong!=null) {
play(nextSong);
}
nextSong = currentSong;
}
if (nextSong!=null) {
play(nextSong);
}
}
@ -97,11 +89,16 @@ public class MusicManager {
}
stop();
currentSong = song;
currentSong.music.play();
if (currentMusic != null) {
currentMusic.dispose();
}
currentMusic = Gdx.audio.newMusic(currentSong.getFileHandle());
currentMusic.setOnCompletionListener(nextSongListener);
currentMusic.play();
}
class NextSongListener implements OnCompletionListener {
@Override
public void onCompletion(Music music) {
next();
@ -110,34 +107,41 @@ public class MusicManager {
}
public void next() {
int currentBackground = backgroundSongs.indexOf(currentSong);
int currentBackground = musicSongs.indexOf(currentSong);
if (currentBackground == -1) {
return; // some other
}
if (currentBackground == backgroundSongs.size()-1) {
if (currentBackground == musicSongs.size()-1) {
currentBackground = -1; // loop to start
}
boolean play = currentSong.music.isPlaying();
currentSong.music.stop();
currentSong = backgroundSongs.get(currentBackground+1);
boolean play = currentMusic!=null && currentMusic.isPlaying();
stop();
currentSong = musicSongs.get(currentBackground+1);
if (play) {
currentSong.music.play();
play(currentSong);
}
}
public void prev() {
int currentBackground = backgroundSongs.indexOf(currentSong);
int currentBackground = musicSongs.indexOf(currentSong);
if (currentBackground == -1) {
return; // some other
}
if (currentBackground == 0) {
currentBackground = backgroundSongs.size(); // loop to end
currentBackground = musicSongs.size(); // loop to end
}
boolean play = currentSong.music.isPlaying();
currentSong.music.stop();
currentSong = backgroundSongs.get(currentBackground-1);
boolean play = currentMusic!=null && currentMusic.isPlaying();
stop();
currentSong = musicSongs.get(currentBackground-1);
if (play) {
currentSong.music.play();
play(currentSong);
}
}
public boolean isPlaying(MusicSong song) {
if (currentSong != null && currentSong.equals(song)) {
return currentMusic.isPlaying();
}
return false;
}
}

View file

@ -1,6 +1,6 @@
package love.distributedrebirth.gdxapp4d.app.tosamp.music;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.files.FileHandle;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
@ -9,19 +9,19 @@ import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
*/
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
public class MusicSong {
protected final Music music;
private final FileHandle fileHandle;
private final String name;
public MusicSong(Music music, String name) {
this.music = music;
public MusicSong(FileHandle fileHandle, String name) {
this.fileHandle = fileHandle;
this.name = name;
}
public FileHandle getFileHandle() {
return fileHandle;
}
public String getName() {
return name;
}
public boolean isPlaying() {
return music.isPlaying();
}
}

View file

@ -1,13 +0,0 @@
package love.distributedrebirth.gdxapp4d.app.tosamp.music;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
/**
* The song types.
*/
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
public enum MusicSongType {
INTRO,
CREDITS,
BACKGROUND
}

View file

@ -4,6 +4,8 @@
<entry key="1c2d010066a39d96ace8af0ecc37c72d6f79109f30939e2959befcd9ce25fc8d">../gdxapp4d-chain-sys-engine/src/main/chain</entry>
<entry key="f8be3b29da5b6b2cb464f781469ceede6ccfd848d158293a4cdffbc2c41a410b">../gdxapp4d-chain-sys-engine-fuel/src/main/chain</entry>
<entry key="8833aa29da5b6b2cb464f781469ceede6ccfd848d158293a4cdffbc2c41b58de">../gdxapp4d-chain-dep-osgi-scr/src/main/chain</entry>
<entry key="ffee3329da5b6b2cb4befcc14aac55de6777d848d158293a4cdffbc2c41b12ad">../gdxapp4d-chain-music-msx/src/main/chain</entry>
<entry key="eecc3329da5b6b2cb4befcc14aac55de6777d848d158293a4cdffbc2c41b75cd">../gdxapp4d-chain-music-templeos/src/main/chain</entry>
<entry key="9944bb29da5b6b2cb464f781469ceede6ccfd848d158293a4cdffbc2c41b62ed">../gdxapp4d-chain-sys-unicode4d/target/chain</entry>
<entry key="7744aa29da5b6b2cb4b8f781469c33de688fd848d158293a4cdddbc2c41b12aa">../gdxapp4d-app-calculator/src/main/chain</entry>

View file

@ -12,5 +12,10 @@
<link:chain key="5522aa29da5b6b2cb4befaa14aacaade6aafd848d158293a4cdffbc2c41b23bd"/>
<!-- Link app-notepad -->
<link:chain key="4411aa29da5b6b2cb4befcc14aac55de6fffd848d158293a4cdffbc2c41b83fb"/>
<!-- Link music-msx -->
<link:chain key="ffee3329da5b6b2cb4befcc14aac55de6777d848d158293a4cdffbc2c41b12ad"/>
<!-- Link music-templeos -->
<link:chain key="eecc3329da5b6b2cb4befcc14aac55de6777d848d158293a4cdffbc2c41b75cd"/>
</link:sea>
</root:ocean>