From c9ce937a2850d8b003b01e96c25603871334aa10 Mon Sep 17 00:00:00 2001 From: WElRD Date: Fri, 21 Sep 2018 23:35:08 +0200 Subject: [PATCH] Updated classes for the changes in the StreamDeckCore library --- .../vv3ird/ESDSoundboardApp/AudioApp.java | 61 +++++-------------- .../DelayedReduceBrightness.java | 2 +- .../vv3ird/ESDSoundboardApp/config/Sound.java | 3 +- .../ngui/components/JSoundPanel.java | 2 +- .../ESDSoundboardApp/player/AudioPlayer.java | 1 + .../items/SoundBoardCategoryItem.java | 42 ++++++++----- .../streamdeck/items/SoundBoardItem.java | 6 +- .../streamdeck/items/SoundBoardItemNew.java | 4 +- 8 files changed, 53 insertions(+), 68 deletions(-) diff --git a/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/AudioApp.java b/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/AudioApp.java index 80df300..0c5ca5d 100644 --- a/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/AudioApp.java +++ b/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/AudioApp.java @@ -48,6 +48,7 @@ import vv3ird.ESDSoundboardApp.streamdeck.items.configuration.ConfigItem; import de.rcblum.stream.deck.StreamDeckController; import de.rcblum.stream.deck.device.IStreamDeck; +import de.rcblum.stream.deck.device.SoftStreamDeck; import de.rcblum.stream.deck.device.StreamDeckDevices; import de.rcblum.stream.deck.items.PagedFolderItem; import de.rcblum.stream.deck.items.StreamItem; @@ -412,7 +413,7 @@ private static void resetStreamDeckController() { for (SoundBoard sb : soundboardLibrary.values()) { sbItems[sbC++] = new SoundBoardItemNew(sb, null); } - PagedFolderItem root = new PagedFolderItem("root", null, null, sbItems); + PagedFolderItem root = new PagedFolderItem("root", null, null, sbItems, streamDeck.getKeySize()); AudioApp.addStatusBarItems(root, root.getChildren()); controller = new StreamDeckController(streamDeck, root); logger.debug("Done resetting controller"); @@ -638,54 +639,24 @@ public static List getAmbienceSounds() { } public static void main(String[] args) { - StreamItem[] sbItems = new StreamItem[soundboardLibrary.size()]; int sbC = 0; + streamDeck = StreamDeckDevices.getStreamDeck(); + if (streamDeck == null) + streamDeck = new SoftStreamDeck("Sound Board App", null); + StreamItem[] sbItems = new StreamItem[soundboardLibrary.size()]; for (SoundBoard sb : soundboardLibrary.values()) { sbItems[sbC++] = new SoundBoardItemNew(sb, null); } - PagedFolderItem root = new PagedFolderItem("root", null, null, sbItems); + PagedFolderItem root = new PagedFolderItem("root", null, null, sbItems, streamDeck.getKeySize()); AudioApp.addStatusBarItems(root, root.getChildren()); -// File lib = new File("sounds"); -// StreamItem[] categories = new StreamItem[15]; -// int catCount = 0; -// File[] categorieFiles = lib.listFiles(); -// if (categorieFiles == null || categorieFiles.length == 0) -// System.exit(4); -// for (File catFile : categorieFiles) { -// if (catFile.isDirectory()) { -// File[] audios = catFile.listFiles(); -// AudioItem[] audioItems = new AudioItem[15]; -// int count = 0; -// for (File file : audios) { -// if (count >= 14) -// break; -// if (!file.getAbsolutePath().endsWith(".mp3")) -// continue; -// AudioItem audioItem = new AudioItem(AUDIO_ICON, file.getAbsolutePath()); -// audioItem.setTextPosition(StreamItem.TEXT_POS_CENTER); -// audioItems[count++] = audioItem; -// if(count == 4) -// count++; -// } -// -// FolderItem categoryitem = new FolderItem(catFile.getName(), null, audioItems); -// categories[catCount++] = categoryitem; -// } -// } -// categories[14] = STOP_ITEM ; -// FolderItem root = new FolderItem("root", null, categories); - streamDeck = StreamDeckDevices.getStreamDeck(); - if (streamDeck != null) { - streamDeck.reset(); - streamDeck.addKeyListener(new DelayedReduceBrightness(streamDeck)); - StreamDeckController.setKeyDeadzone(50); - AudioApp.controller = new StreamDeckController(streamDeck, root); - AudioApp.controller.setBrightness(75); - } - else { - logger.error("No Stream Deck Device found. Please check your devices connection"); - logger.error("Shutting down"); - System.exit(5); - } + streamDeck.reset(); + streamDeck.addKeyListener(new DelayedReduceBrightness(streamDeck)); + StreamDeckController.setKeyDeadzone(50); + AudioApp.controller = new StreamDeckController(streamDeck, root); + AudioApp.controller.setBrightness(75); + } + + public static IStreamDeck getStreamDeck() { + return streamDeck; } } diff --git a/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/DelayedReduceBrightness.java b/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/DelayedReduceBrightness.java index b143fff..d2e1e2e 100644 --- a/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/DelayedReduceBrightness.java +++ b/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/DelayedReduceBrightness.java @@ -38,7 +38,7 @@ public void run() { @Override public void onKeyEvent(KeyEvent event) { lastPressed = System.currentTimeMillis(); - this.streamDeck.setBrightness(75); + this.streamDeck.setBrightness(60); } } diff --git a/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/config/Sound.java b/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/config/Sound.java index 587bc41..1a5b8da 100644 --- a/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/config/Sound.java +++ b/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/config/Sound.java @@ -87,8 +87,9 @@ public boolean hasNext() { @Override public String next() { checkLegacy(); + int currentIdx = this.currentFile; this.currentFile = this.currentFile+1 >= this.filePaths.length ? 0 : this.currentFile+1; - return this.filePaths[this.currentFile]; + return this.filePaths[currentIdx]; } public boolean isPlaylist() { diff --git a/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/ngui/components/JSoundPanel.java b/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/ngui/components/JSoundPanel.java index ce83cfd..cac6bfe 100644 --- a/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/ngui/components/JSoundPanel.java +++ b/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/ngui/components/JSoundPanel.java @@ -49,7 +49,7 @@ private void init(BufferedImage img, String text, Color background) { Color oldC = IconHelper.FRAME_COLOR; IconHelper.FRAME_COLOR = background; IconHelper.TEXT_BOX_ALPHA_VALUE = 150; - SDImage bImg = IconHelper.addText(img, text, IconHelper.TEXT_BOTTOM); + SDImage bImg = IconHelper.addText(img, text, IconHelper.TEXT_CENTER); IconHelper.FRAME_COLOR = oldC; IconHelper.TEXT_BOX_ALPHA_VALUE = alpha; setSize(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE); diff --git a/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/player/AudioPlayer.java b/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/player/AudioPlayer.java index b8eeb17..431c85f 100644 --- a/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/player/AudioPlayer.java +++ b/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/player/AudioPlayer.java @@ -98,6 +98,7 @@ public void removeLineListener(LineListener listener) public void open() throws IOException, LineUnavailableException, UnsupportedAudioFileException { String audioFile = sound.next(); + System.out.println("Opening audiofile: " + audioFile); intendetState = LineEvent.Type.OPEN; try { stream = getAudioStream(audioFile); diff --git a/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/streamdeck/items/SoundBoardCategoryItem.java b/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/streamdeck/items/SoundBoardCategoryItem.java index 34496ce..0159171 100644 --- a/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/streamdeck/items/SoundBoardCategoryItem.java +++ b/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/streamdeck/items/SoundBoardCategoryItem.java @@ -1,6 +1,7 @@ package vv3ird.ESDSoundboardApp.streamdeck.items; import java.util.Arrays; +import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -17,21 +18,27 @@ public class SoundBoardCategoryItem extends FolderItem { private static Logger logger = LogManager.getLogger(SoundBoardCategoryItem.class); - public SoundBoardCategoryItem(String folderName, StreamItem parent, SoundBoardCategoryItem previous, SoundItem[] children) { - super(folderName, parent, new StreamItem[15]); - children = children != null ? children : new SoundItem[15]; - int maxItems = 9; - // Create Sub-folder for more then 9/10 children (with parent/without parent) + public SoundBoardCategoryItem(String folderName, StreamItem parent, SoundBoardCategoryItem previous, SoundItem[] children, int buttonCount) { + super(folderName, parent, new StreamItem[buttonCount]); + children = children != null ? children : new SoundItem[buttonCount]; + int maxItems = buttonCount - 6; + // Create Sub-folder for more then 9/buttonCount-5 children (with parent/without parent) int countTotal= previous == null ? 1 : 0; if(previous == null) { List files = new LinkedList<>(); Arrays.asList(children).stream().map(s -> Arrays.asList(s.getSound().getFilePaths())).forEach(files::addAll); - String coverPath = Arrays.asList(children).stream().map(s -> s.getSound().getCoverPath()).findFirst().orElse("BLACK"); + Collections.sort(files); +// String coverPath = Arrays.asList(children).stream().map(s -> s.getSound().getCoverPath()).findFirst().orElse("BLACK"); Sound.Type type = Arrays.asList(children).stream().map(s -> s.getSound().getType()).findFirst().orElse(Sound.Type.AMBIENCE); - Sound playAllSound = new Sound(folderName + " - Play all", files.toArray(new String[0]), coverPath, type, null); + Sound playAllSound = new Sound(folderName + " - Play all", files.toArray(new String[0]), null, type, null); SoundItem playAll = new SoundItem(playAllSound); + playAll.setText( "Play all"); playAll.setParent(this); - this.getChildren()[0] = playAll; + this.getChildren()[buttonCount-2] = playAll; + playAllSound.resetCurrentFile(); + } + else { + this.getChildren()[buttonCount-2] = previous.getChild(buttonCount-2); } for (SoundItem streamItem : children) { if (streamItem != null) @@ -40,7 +47,7 @@ public SoundBoardCategoryItem(String folderName, StreamItem parent, SoundBoardCa // Fill current page int childIndex = 0; - int countSI = previous == null ? 1 : 0; + int countSI = 0; for(;childIndex= 15) throw new IndexOutOfBoundsException("Index must be between 0 and 14 inclusive"); this.getChildren()[index] = item; - if (this.getChildren()[10] != null && this.getChildren()[10] instanceof NextItem) { - ((NextItem)this.getChildren()[10]).setGlobalItem(index, item); + if (this.getChildren()[buttonCount-5] != null && this.getChildren()[buttonCount-5] instanceof NextItem) { + ((NextItem)this.getChildren()[buttonCount-5]).setGlobalItem(index, item); } } @Override public void setParent(StreamItem parent) { super.setParent(parent); - if (this.getChild(10) != null) - this.getChild(10).setParent(parent); + if (this.getChild(buttonCount-5) != null) + this.getChild(buttonCount-5).setParent(parent); } public static class NextItem extends FolderItem{ @@ -102,6 +109,11 @@ public AnimationStack getAnimation() { return next.getAnimation(); } + @Override + public int getChildCount() { + return next.getChildCount(); + } + @Override public int getChildId(StreamItem item) { return next.getChildId(item); diff --git a/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/streamdeck/items/SoundBoardItem.java b/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/streamdeck/items/SoundBoardItem.java index 8add756..377d517 100644 --- a/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/streamdeck/items/SoundBoardItem.java +++ b/ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/streamdeck/items/SoundBoardItem.java @@ -19,9 +19,9 @@ public SoundBoardItem(SoundBoard soundBoard, StreamItem parent) { StreamItem[] ambienceCategories = createCategoryItems(soundBoard.ambience); StreamItem[] effectCategories = createCategoryItems(soundBoard.effects); // Create Folders for ambience and effect sounds - PagedFolderItem ambience = new PagedFolderItem("Ambience", this, null, ambienceCategories); + PagedFolderItem ambience = new PagedFolderItem("Ambience", this, null, ambienceCategories, AudioApp.getStreamDeck().getKeySize()); AudioApp.addStatusBarItems(ambience, ambience.getChildren()); - PagedFolderItem effects = new PagedFolderItem("Effects", this, null, effectCategories); + PagedFolderItem effects = new PagedFolderItem("Effects", this, null, effectCategories, AudioApp.getStreamDeck().getKeySize()); AudioApp.addStatusBarItems(effects, effects.getChildren()); // Add to Folder this.getChildren()[8] = ambience; @@ -41,7 +41,7 @@ private StreamItem[] createCategoryItems(Map> ambience) { for(int i=0;i> ambience, Map< SoundBoardCategoryItem effectsCategoryItem = null; SoundBoardCategoryItem ambienceCategoryItem = null; if (ambienceItems != null) { - ambienceCategoryItem = new SoundBoardCategoryItem(category, this, null, ambienceItems); + ambienceCategoryItem = new SoundBoardCategoryItem(category, this, null, ambienceItems, AudioApp.getStreamDeck().getKeySize()); AudioApp.addStatusBarItems(ambienceCategoryItem, ambienceCategoryItem.getChildren()); } if (effectsItems != null) { - effectsCategoryItem = new SoundBoardCategoryItem(category, this, null, effectsItems); + effectsCategoryItem = new SoundBoardCategoryItem(category, this, null, effectsItems, AudioApp.getStreamDeck().getKeySize()); AudioApp.addStatusBarItems(effectsCategoryItem, effectsCategoryItem.getChildren()); ProxyItem p1 = new ProxyItem(ambienceCategoryItem, null); p1.setIcon(IconHelper.loadImageFromResourceSafe("/resources/icons/change.png"));