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

View file

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

View file

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

View file

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