Skip to content

Commit

Permalink
Updated classes for the changes in the StreamDeckCore library
Browse files Browse the repository at this point in the history
  • Loading branch information
VVEIRD committed Sep 21, 2018
1 parent 0098110 commit c9ce937
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -638,54 +639,24 @@ public static List<Sound> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void run() {
@Override
public void onKeyEvent(KeyEvent event) {
lastPressed = System.currentTimeMillis();
this.streamDeck.setBrightness(75);
this.streamDeck.setBrightness(60);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<String> 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)
Expand All @@ -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<children.length&&countSI<maxItems;childIndex++) {
if(children[childIndex] != null) {
this.getChildren()[countSI<4? countSI : countSI+1] = children[childIndex];
Expand All @@ -58,27 +65,27 @@ public SoundBoardCategoryItem(String folderName, StreamItem parent, SoundBoardCa
// Create children for next page
SoundItem[] nextPageChildren = Arrays.copyOfRange(children, childIndex, children.length);
// Create next page
SoundBoardCategoryItem next = new SoundBoardCategoryItem(folderName, parent, this, nextPageChildren);
SoundBoardCategoryItem next = new SoundBoardCategoryItem(folderName, parent, this, nextPageChildren, buttonCount);
next.setTextPosition(TEXT_POS_CENTER);
next.setText("Next");
this.getChildren()[10] = new NextItem(next);
this.getChildren()[buttonCount-5] = new NextItem(next);
}
}

public void setGlobalItem(int index, StreamItem item) {
if(index < 0 || index >= 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{
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,7 +41,7 @@ private StreamItem[] createCategoryItems(Map<String, List<Sound>> ambience) {
for(int i=0;i<soundItems.length;i++) {
soundItems[i] = new SoundItem(sounds.get(i));
}
PagedFolderItem categoryItem = new PagedFolderItem(category, this, null, soundItems);
PagedFolderItem categoryItem = new PagedFolderItem(category, this, null, soundItems, AudioApp.getStreamDeck().getKeySize());
AudioApp.addStatusBarItems(categoryItem, categoryItem.getChildren());
result[catCount++] = categoryItem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ private StreamItem[] createCategoryItems(Map<String, List<Sound>> 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"));
Expand Down

0 comments on commit c9ce937

Please sign in to comment.