From eec062010de26e780b2166db1a5c67742c9b6c48 Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Sat, 12 Mar 2022 23:21:10 +0100 Subject: [PATCH] prepared music for playlists --- .../gdxapp4d/app/tosamp/TosAmpComponent.java | 11 +- .../gdxapp4d/app/tosamp/TosAmpDeskApp.java | 16 +-- .../app/tosamp/music/MusicManager.java | 104 +++++++++--------- .../gdxapp4d/app/tosamp/music/MusicSong.java | 16 +-- .../app/tosamp/music/MusicSongType.java | 13 --- gdxapp4d-boot-desktop/local-override.xml | 2 + .../src/main/chain/warp-sea.xml | 5 + 7 files changed, 86 insertions(+), 81 deletions(-) delete mode 100644 gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/music/MusicSongType.java diff --git a/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/TosAmpComponent.java b/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/TosAmpComponent.java index 88e93559..5f6da4bc 100644 --- a/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/TosAmpComponent.java +++ b/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/TosAmpComponent.java @@ -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); } diff --git a/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/TosAmpDeskApp.java b/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/TosAmpDeskApp.java index 9ff73b76..a0ae7217 100644 --- a/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/TosAmpDeskApp.java +++ b/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/TosAmpDeskApp.java @@ -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) { } diff --git a/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/music/MusicManager.java b/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/music/MusicManager.java index 11736868..a56c4c28 100644 --- a/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/music/MusicManager.java +++ b/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/music/MusicManager.java @@ -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 backgroundSongs; + private final List 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 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 getBackgroundSongs() { - return backgroundSongs; + public List 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; + } } diff --git a/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/music/MusicSong.java b/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/music/MusicSong.java index 307d93a8..ecd51232 100644 --- a/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/music/MusicSong.java +++ b/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/music/MusicSong.java @@ -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(); - } } \ No newline at end of file diff --git a/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/music/MusicSongType.java b/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/music/MusicSongType.java deleted file mode 100644 index 04a562e6..00000000 --- a/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/music/MusicSongType.java +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/gdxapp4d-boot-desktop/local-override.xml b/gdxapp4d-boot-desktop/local-override.xml index 9f277d21..5369dbaf 100644 --- a/gdxapp4d-boot-desktop/local-override.xml +++ b/gdxapp4d-boot-desktop/local-override.xml @@ -4,6 +4,8 @@ ../gdxapp4d-chain-sys-engine/src/main/chain ../gdxapp4d-chain-sys-engine-fuel/src/main/chain ../gdxapp4d-chain-dep-osgi-scr/src/main/chain + ../gdxapp4d-chain-music-msx/src/main/chain + ../gdxapp4d-chain-music-templeos/src/main/chain ../gdxapp4d-chain-sys-unicode4d/target/chain ../gdxapp4d-app-calculator/src/main/chain diff --git a/gdxapp4d-chain-sys-engine-fuel/src/main/chain/warp-sea.xml b/gdxapp4d-chain-sys-engine-fuel/src/main/chain/warp-sea.xml index f3cd9400..9dcedbce 100644 --- a/gdxapp4d-chain-sys-engine-fuel/src/main/chain/warp-sea.xml +++ b/gdxapp4d-chain-sys-engine-fuel/src/main/chain/warp-sea.xml @@ -12,5 +12,10 @@ + + + + +