From 8b3467349d338d2656a4e98327f9437ae6105357 Mon Sep 17 00:00:00 2001 From: tobias <tobias.ullerich@icloud.com> Date: Thu, 8 Sep 2016 12:08:05 +0200 Subject: [PATCH] Add settings for peak meter --- .../tobias/playpad/assets/lang/_de.properties | 7 +- .../playpad/assets/lang/ui_de.properties | 2 + .../assets/view/option/profile/audioTab.fxml | 31 ++++++-- PlayWall/src/de/tobias/playpad/Strings.java | 5 +- .../pad/content/AudioContentConnect.java | 47 ------------ .../playpad/pad/content/AudioContentView.java | 76 +++++++++++++++++++ .../profile/AudioTabViewController.java | 27 ++++++- .../de/tobias/playpad/pad/view/PeakMeter.java | 14 +++- .../de/tobias/playpad/settings/PeakType.java | 8 ++ .../playpad/settings/ProfileSettings.java | 14 ++++ 10 files changed, 167 insertions(+), 64 deletions(-) create mode 100644 PlayWall/src/de/tobias/playpad/pad/content/AudioContentView.java create mode 100644 PlayWallCore/src/de/tobias/playpad/settings/PeakType.java diff --git a/PlayWall/assets/de/tobias/playpad/assets/lang/_de.properties b/PlayWall/assets/de/tobias/playpad/assets/lang/_de.properties index cae22092..134add5b 100644 --- a/PlayWall/assets/de/tobias/playpad/assets/lang/_de.properties +++ b/PlayWall/assets/de/tobias/playpad/assets/lang/_de.properties @@ -266,4 +266,9 @@ MainLayout.Touch=Touchmodus # Suche Search.Button=Suchen Search.Placeholder=Suche -Search.Alert.NoMatches=Keine Treffer gefunden. \ No newline at end of file +Search.Alert.NoMatches=Keine Treffer gefunden. + +#Peak Settings +PeakType.NONE=Keine Anzeige +PeakType.LEFT=Nur Links +PeakType.BOTH=Stereo \ No newline at end of file diff --git a/PlayWall/assets/de/tobias/playpad/assets/lang/ui_de.properties b/PlayWall/assets/de/tobias/playpad/assets/lang/ui_de.properties index 9438e06b..6ea5b921 100644 --- a/PlayWall/assets/de/tobias/playpad/assets/lang/ui_de.properties +++ b/PlayWall/assets/de/tobias/playpad/assets/lang/ui_de.properties @@ -177,6 +177,8 @@ plugin.label.restart=Einige plugin.label.updateInfo=Erweiterungen k�nnen in den Aktualisierungseinstellungen aktualisiert werden. plugin.button.finish=Fertig +settings.audio.peak=Audio Level pro Kachel: +settings.audio.peak.info=Das Audio Level Meter gibt es nur bei bestimmten Ausgabetpyen settings.audio.type=Ausgabetype w�hlen: newProject.label.name=Name: diff --git a/PlayWall/assets/de/tobias/playpad/assets/view/option/profile/audioTab.fxml b/PlayWall/assets/de/tobias/playpad/assets/view/option/profile/audioTab.fxml index 86cb23c1..0cbad562 100644 --- a/PlayWall/assets/de/tobias/playpad/assets/view/option/profile/audioTab.fxml +++ b/PlayWall/assets/de/tobias/playpad/assets/view/option/profile/audioTab.fxml @@ -1,17 +1,36 @@ <?xml version="1.0" encoding="UTF-8"?> +<?import javafx.geometry.*?> <?import java.lang.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> -<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> +<VBox spacing="14.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> <children> - <HBox layoutX="14.0" layoutY="14.0" spacing="14.0"> + <HBox alignment="CENTER_LEFT" spacing="14.0"> <children> - <Label alignment="BASELINE_RIGHT" layoutX="14.0" layoutY="19.0" maxHeight="1.7976931348623157E308" prefWidth="150.0" text="%settings.audio.type" /> - <ComboBox fx:id="audioTypeComboBox" layoutX="156.0" layoutY="14.0" prefHeight="26.0" prefWidth="226.0" /> + <Label prefWidth="150.0" text="%settings.audio.peak" /> + <ComboBox fx:id="peakTypeComboBox" prefWidth="150.0" /> </children> </HBox> - <AnchorPane fx:id="audioUserInfoSettings" layoutX="14.0" layoutY="53.0" prefHeight="312.0" prefWidth="617.0" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="53.0" /> + <Label text="%settings.audio.peak.info"> + <VBox.margin> + <Insets left="164.0" /> + </VBox.margin> + </Label> + <VBox layoutX="14.0" layoutY="14.0" spacing="14.0"> + <children> + <HBox layoutX="14.0" layoutY="14.0" spacing="14.0"> + <children> + <Label alignment="BASELINE_RIGHT" layoutX="14.0" layoutY="19.0" maxHeight="1.7976931348623157E308" prefWidth="150.0" text="%settings.audio.type" /> + <ComboBox fx:id="audioTypeComboBox" layoutX="156.0" layoutY="14.0" prefHeight="26.0" prefWidth="226.0" /> + </children> + </HBox> + <AnchorPane fx:id="audioUserInfoSettings" layoutX="14.0" layoutY="53.0" prefHeight="312.0" prefWidth="617.0" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="53.0" /> + </children> + </VBox> </children> -</AnchorPane> + <padding> + <Insets bottom="14.0" left="14.0" right="14.0" top="14.0" /> + </padding> +</VBox> diff --git a/PlayWall/src/de/tobias/playpad/Strings.java b/PlayWall/src/de/tobias/playpad/Strings.java index ecd9bf62..987411fc 100644 --- a/PlayWall/src/de/tobias/playpad/Strings.java +++ b/PlayWall/src/de/tobias/playpad/Strings.java @@ -46,8 +46,7 @@ public class Strings { // UI - Window - Main public static final String UI_Window_Main_CloseRequest = "UI.Window.Main.CloseRequest"; - @Deprecated - public static final String UI_Window_Main_SaveRequest = "UI.Window.Main.SaveRequest"; + @Deprecated public static final String UI_Window_Main_SaveRequest = "UI.Window.Main.SaveRequest"; public static final String UI_Window_Main_PageButton = "UI.Window.Main.PageButton"; // UI - Dialog - Launch @@ -256,4 +255,6 @@ public class Strings { public static final String Search_Button = "Search.Button"; public static final String Search_Placeholder = "Search.Placeholder"; public static final String Search_Alert_NoMatches = "Search.Alert.NoMatches"; + + public static final String PeakType = "PeakType."; } diff --git a/PlayWall/src/de/tobias/playpad/pad/content/AudioContentConnect.java b/PlayWall/src/de/tobias/playpad/pad/content/AudioContentConnect.java index ae3ea494..cd37defb 100644 --- a/PlayWall/src/de/tobias/playpad/pad/content/AudioContentConnect.java +++ b/PlayWall/src/de/tobias/playpad/pad/content/AudioContentConnect.java @@ -1,12 +1,10 @@ package de.tobias.playpad.pad.content; import de.tobias.playpad.Strings; -import de.tobias.playpad.audio.Peakable; import de.tobias.playpad.pad.Pad; import de.tobias.playpad.pad.conntent.PadContent; import de.tobias.playpad.pad.conntent.PadContentConnect; import de.tobias.playpad.pad.view.IPadContentView; -import de.tobias.playpad.pad.view.PeakMeter; import de.tobias.playpad.viewcontroller.option.ProfileSettingsTabViewController; import de.tobias.playpad.viewcontroller.option.profile.AudioTabViewController; import de.tobias.utils.ui.icon.FontAwesomeType; @@ -14,13 +12,8 @@ import de.tobias.utils.ui.icon.FontIcon; import de.tobias.utils.util.Localization; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; -import javafx.geometry.Pos; import javafx.scene.Node; -import javafx.scene.control.Label; import javafx.scene.layout.Pane; -import javafx.scene.layout.Priority; -import javafx.scene.layout.VBox; -import javafx.scene.text.TextAlignment; public class AudioContentConnect extends PadContentConnect { @@ -53,7 +46,6 @@ public class AudioContentConnect extends PadContentConnect { public IPadContentView getPadContentPreview(Pad pad, Pane parentNode) { if (pad.getContent() != null) { AudioContentView view = new AudioContentView(pad, parentNode); - return view; } else { return null; @@ -65,45 +57,6 @@ public class AudioContentConnect extends PadContentConnect { return new AudioTabViewController(activePlayer); } - private class AudioContentView implements IPadContentView { - - private Label nameLabel; - private PeakMeter meter; - - public AudioContentView(Pad pad, Pane parentNode) { - nameLabel = new Label(); - nameLabel.textProperty().bind(pad.nameProperty()); - - nameLabel.setWrapText(true); - nameLabel.setAlignment(Pos.CENTER); - nameLabel.setTextAlignment(TextAlignment.CENTER); - - AudioContent content = (AudioContent) pad.getContent(); - if (content.getAudioHandler() instanceof Peakable) { - Peakable peakable = (Peakable) content.getAudioHandler(); - meter = new PeakMeter(peakable); - } - - nameLabel.prefWidthProperty().bind(parentNode.widthProperty()); - nameLabel.setMaxHeight(Double.MAX_VALUE); - VBox.setVgrow(nameLabel, Priority.ALWAYS); - } - - @Override - public Node getNode() { - if (meter != null) { - return new VBox(7, nameLabel, meter); - } else { - return new VBox(7, nameLabel); - } - } - - @Override - public void unconnect() { - nameLabel.textProperty().unbind(); - } - } - // UI - DnD @Override public StringProperty displayProperty() { diff --git a/PlayWall/src/de/tobias/playpad/pad/content/AudioContentView.java b/PlayWall/src/de/tobias/playpad/pad/content/AudioContentView.java new file mode 100644 index 00000000..6442edb2 --- /dev/null +++ b/PlayWall/src/de/tobias/playpad/pad/content/AudioContentView.java @@ -0,0 +1,76 @@ +package de.tobias.playpad.pad.content; + +import de.tobias.playpad.audio.Peakable; +import de.tobias.playpad.pad.Pad; +import de.tobias.playpad.pad.view.IPadContentView; +import de.tobias.playpad.pad.view.PeakMeter; +import de.tobias.playpad.settings.PeakType; +import de.tobias.playpad.settings.Profile; +import de.tobias.playpad.settings.ProfileSettings; +import javafx.collections.ListChangeListener; +import javafx.geometry.Pos; +import javafx.scene.Node; +import javafx.scene.control.Label; +import javafx.scene.layout.Pane; +import javafx.scene.layout.Priority; +import javafx.scene.layout.VBox; +import javafx.scene.text.TextAlignment; + +class AudioContentView implements IPadContentView { + + private VBox vbox; + private Label nameLabel; + private PeakMeter meter; + + public AudioContentView(Pad pad, Pane parentNode) { + ProfileSettings settings = Profile.currentProfile().getProfileSettings(); + + nameLabel = new Label(); + nameLabel.textProperty().bind(pad.nameProperty()); + + nameLabel.setWrapText(true); + nameLabel.setAlignment(Pos.CENTER); + nameLabel.setTextAlignment(TextAlignment.CENTER); + + AudioContent content = (AudioContent) pad.getContent(); + if (content.getAudioHandler() instanceof Peakable && settings.getPeakType() != PeakType.NONE) { + Peakable peakable = (Peakable) content.getAudioHandler(); + meter = new PeakMeter(peakable, settings.getPeakType()); + } + + nameLabel.prefWidthProperty().bind(parentNode.widthProperty()); + nameLabel.setMaxHeight(Double.MAX_VALUE); + VBox.setVgrow(nameLabel, Priority.ALWAYS); + + if (meter != null) { + vbox = new VBox(7, nameLabel, meter); + } else { + vbox = new VBox(7, nameLabel); + } + vbox.getStyleClass().addListener(new ListChangeListener<String>() { + + @Override + public void onChanged(javafx.collections.ListChangeListener.Change<? extends String> c) { + while (c.next()) { + for (String remitem : c.getRemoved()) { + nameLabel.getStyleClass().remove(remitem); + + } + for (String additem : c.getAddedSubList()) { + nameLabel.getStyleClass().add(additem); + } + } + } + }); + } + + @Override + public Node getNode() { + return vbox; + } + + @Override + public void unconnect() { + nameLabel.textProperty().unbind(); + } +} \ No newline at end of file diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/option/profile/AudioTabViewController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/option/profile/AudioTabViewController.java index e83f9a00..f699c194 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/option/profile/AudioTabViewController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/option/profile/AudioTabViewController.java @@ -6,13 +6,16 @@ import de.tobias.playpad.Strings; import de.tobias.playpad.audio.AudioRegistry; import de.tobias.playpad.project.Project; import de.tobias.playpad.registry.NoSuchComponentException; +import de.tobias.playpad.settings.PeakType; import de.tobias.playpad.settings.Profile; import de.tobias.playpad.settings.ProfileSettings; import de.tobias.playpad.viewcontroller.AudioHandlerViewController; +import de.tobias.playpad.viewcontroller.cell.EnumCell; import de.tobias.playpad.viewcontroller.main.IMainViewController; import de.tobias.playpad.viewcontroller.option.IProfileReloadTask; import de.tobias.playpad.viewcontroller.option.ProfileSettingsTabViewController; import de.tobias.utils.util.Localization; +import javafx.application.Platform; import javafx.concurrent.Task; import javafx.fxml.FXML; import javafx.scene.control.ComboBox; @@ -21,10 +24,14 @@ import javafx.scene.layout.AnchorPane; public class AudioTabViewController extends ProfileSettingsTabViewController implements IProfileReloadTask { // Audio + @FXML private ComboBox<PeakType> peakTypeComboBox; @FXML private ComboBox<String> audioTypeComboBox; @FXML private AnchorPane audioUserInfoSettings; + private AudioHandlerViewController audioViewController; + private boolean changeAudioSettings; + private boolean changePeakSettings; public AudioTabViewController(boolean playerActive) { super("audioTab", "de/tobias/playpad/assets/view/option/profile/", PlayPadMain.getUiResourceBundle()); @@ -39,6 +46,15 @@ public class AudioTabViewController extends ProfileSettingsTabViewController imp public void init() { ProfileSettings profileSettings = Profile.currentProfile().getProfileSettings(); + // Peak Mode + peakTypeComboBox.getItems().setAll(PeakType.values()); + peakTypeComboBox.setCellFactory(list -> new EnumCell<>(Strings.PeakType)); + peakTypeComboBox.setButtonCell(new EnumCell<>(Strings.PeakType)); + peakTypeComboBox.getSelectionModel().selectedItemProperty().addListener((a, b, c) -> + { + changePeakSettings = true; + }); + // Audio Classes AudioRegistry audioHandlerRegistry = PlayPadPlugin.getRegistryCollection().getAudioHandlers(); audioTypeComboBox.getItems().addAll(audioHandlerRegistry.getTypes()); @@ -80,7 +96,7 @@ public class AudioTabViewController extends ProfileSettingsTabViewController imp ProfileSettings profileSettings = profile.getProfileSettings(); audioTypeComboBox.getSelectionModel().select(profileSettings.getAudioClass()); - + peakTypeComboBox.setValue(profileSettings.getPeakType()); } @Override @@ -88,7 +104,7 @@ public class AudioTabViewController extends ProfileSettingsTabViewController imp ProfileSettings profileSettings = profile.getProfileSettings(); profileSettings.setAudioClass(audioTypeComboBox.getValue()); - + profileSettings.setPeakType(peakTypeComboBox.getValue()); } @Override @@ -98,7 +114,7 @@ public class AudioTabViewController extends ProfileSettingsTabViewController imp changeAudioSettings = true; } } - return changeAudioSettings; + return changeAudioSettings || changePeakSettings; } @Override @@ -109,7 +125,10 @@ public class AudioTabViewController extends ProfileSettingsTabViewController imp updateTitle(name()); updateProgress(-1, -1); - project.loadPadsContent(); + if (changeAudioSettings) + project.loadPadsContent(); + if (changePeakSettings || changeAudioSettings) + Platform.runLater(() -> controller.showPage(controller.getPage())); return null; } }; diff --git a/PlayWallCore/src/de/tobias/playpad/pad/view/PeakMeter.java b/PlayWallCore/src/de/tobias/playpad/pad/view/PeakMeter.java index 01f694bb..4fba1960 100644 --- a/PlayWallCore/src/de/tobias/playpad/pad/view/PeakMeter.java +++ b/PlayWallCore/src/de/tobias/playpad/pad/view/PeakMeter.java @@ -2,6 +2,7 @@ package de.tobias.playpad.pad.view; import de.tobias.playpad.audio.Peakable; import de.tobias.playpad.audio.Peakable.Channel; +import de.tobias.playpad.settings.PeakType; import javafx.beans.value.ChangeListener; import javafx.scene.control.ProgressBar; import javafx.scene.layout.VBox; @@ -14,17 +15,19 @@ public class PeakMeter extends VBox { private ChangeListener<Number> leftListener; private ChangeListener<Number> rightListener; - public PeakMeter(Peakable peakable) { + public PeakMeter(Peakable peakable, PeakType type) { progressbarLeft = new ProgressBar(0); progressbarRight = new ProgressBar(0); - leftListener = (a, b, c) -> { + leftListener = (a, b, c) -> + { double value = (c.doubleValue() + 60) * 1 / 60; if (value < 0) value = 0; progressbarLeft.setProgress(value); }; - rightListener = (a, b, c) -> { + rightListener = (a, b, c) -> + { double value = (c.doubleValue() + 60) * 1 / 60; if (value < 0) value = 0; @@ -40,6 +43,9 @@ public class PeakMeter extends VBox { peakable.audioLevelProperty(Channel.LEFT).addListener(leftListener); peakable.audioLevelProperty(Channel.RIGHT).addListener(rightListener); - getChildren().addAll(progressbarLeft, progressbarRight); + setSpacing(4); + getChildren().addAll(progressbarLeft); + if (type == PeakType.BOTH) + getChildren().addAll(progressbarRight); } } \ No newline at end of file diff --git a/PlayWallCore/src/de/tobias/playpad/settings/PeakType.java b/PlayWallCore/src/de/tobias/playpad/settings/PeakType.java new file mode 100644 index 00000000..61d68612 --- /dev/null +++ b/PlayWallCore/src/de/tobias/playpad/settings/PeakType.java @@ -0,0 +1,8 @@ +package de.tobias.playpad.settings; + +public enum PeakType { + + NONE, + LEFT, + BOTH; +} diff --git a/PlayWallCore/src/de/tobias/playpad/settings/ProfileSettings.java b/PlayWallCore/src/de/tobias/playpad/settings/ProfileSettings.java index 0c3e79c7..78f25318 100644 --- a/PlayWallCore/src/de/tobias/playpad/settings/ProfileSettings.java +++ b/PlayWallCore/src/de/tobias/playpad/settings/ProfileSettings.java @@ -36,6 +36,7 @@ public class ProfileSettings implements SettingsSerializable { @Storable private boolean midiActive = false; // Audio Output + @Storable private PeakType peakType = PeakType.LEFT; @Storable private String audioClass = PlayPadPlugin.getRegistryCollection().getAudioHandlers().getDefaultID(); @Storable private HashMap<String, Object> audioUserInfo = new HashMap<>(); @@ -104,6 +105,10 @@ public class ProfileSettings implements SettingsSerializable { return player_timeDisplayMode; } + public PeakType getPeakType() { + return peakType; + } + public String getAudioClass() { return audioClass; } @@ -153,6 +158,10 @@ public class ProfileSettings implements SettingsSerializable { this.player_timeDisplayMode = player_timeDisplayMode; } + public void setPeakType(PeakType peakType) { + this.peakType = peakType; + } + public void setAudioClass(String audioClass) { this.audioClass = audioClass; } @@ -171,6 +180,7 @@ public class ProfileSettings implements SettingsSerializable { private static final String VOLUME_ELEMENT = "Volume"; private static final String KEY_ATTRIBUTE = "key"; private static final String AUDIO_USER_INFO_ELEMENT = "AudioUserInfo"; + private static final String PEAK_TYPE_ELEMENT = "PeakType"; private static final String AUDIO_CLASS_ELEMENT = "AudioClass"; private static final String WINDOW_ALWAYS_ON_TOP_ELEMENT = "WindowAlwaysOnTop"; private static final String MULTIPLE_PLAYER_ELEMENT = "MultiplePlayer"; @@ -232,6 +242,9 @@ public class ProfileSettings implements SettingsSerializable { if (root.element(WINDOW_ALWAYS_ON_TOP_ELEMENT) != null) profileSettings.setWindowAlwaysOnTop(Boolean.valueOf(root.element(WINDOW_ALWAYS_ON_TOP_ELEMENT).getStringValue())); + + if (root.element(PEAK_TYPE_ELEMENT) != null) + profileSettings.setPeakType(PeakType.valueOf(root.element(PEAK_TYPE_ELEMENT).getStringValue())); if (root.element(AUDIO_CLASS_ELEMENT) != null) profileSettings.setAudioClass(root.element(AUDIO_CLASS_ELEMENT).getStringValue()); @@ -275,6 +288,7 @@ public class ProfileSettings implements SettingsSerializable { root.addElement(WINDOW_ALWAYS_ON_TOP_ELEMENT).addText(String.valueOf(windowAlwaysOnTop)); // Audio + root.addElement(PEAK_TYPE_ELEMENT).addText(peakType.name()); root.addElement(AUDIO_CLASS_ELEMENT).addText(audioClass); Element userInfoElement = root.addElement(AUDIO_USER_INFO_ELEMENT); for (String key : audioUserInfo.keySet()) { -- GitLab