From 419499503f793525850542c99625cca28bccb892 Mon Sep 17 00:00:00 2001
From: tobias <tobias.ullerich@icloud.com>
Date: Wed, 10 Aug 2016 19:05:33 +0200
Subject: [PATCH] Multiple Pad Playing Settings und Implementierung

---
 .../tobias/playpad/assets/lang/ui_de.properties  |  3 ++-
 .../assets/view/option/profile/generalTab.fxml   |  4 +---
 .../assets/view/option/profile/playerTab.fxml    |  7 +++++++
 .../option/profile/PlayerTabViewController.java  |  6 ++++++
 PlayWallCore/src/de/tobias/playpad/pad/Pad.java  |  1 +
 .../de/tobias/playpad/pad/PadStatusListener.java | 16 ++++++++++++++++
 .../tobias/playpad/settings/ProfileSettings.java | 16 ++++++++++++++++
 7 files changed, 49 insertions(+), 4 deletions(-)

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 883a13e0..7611aa26 100644
--- a/PlayWall/assets/de/tobias/playpad/assets/lang/ui_de.properties
+++ b/PlayWall/assets/de/tobias/playpad/assets/lang/ui_de.properties
@@ -34,7 +34,6 @@ settings.gen.label.view=Ansicht:
 settings.gen.label.pages=Anzahl der Seiten:
 settings.gen.label.columns=Anzahl der Spalten:
 settings.gen.label.rows=Anzahl der Reihen:
-settings.gen.label.additional=Erweitert:
 settings.gen.label.liveMode=Live Modus:
 settings.gen.checkbox.liveMode=Aktivieren
 settings.gen.label.liveMode.settings=Einstellungen �ndern:
@@ -58,6 +57,8 @@ settings.midi.label.device=Midi-Ger
 
 settings.layout.label.type=Layout Type:
 
+settings.player.label.modus=Wiedergabemodus:
+settings.player.checkbox.modus=Mehrere Player gleichzeitig wiedergeben
 settings.player.label.warning=Warnhinweise:
 settings.player.label.fade=Ein-/Ausblenden:
 settings.player.label.fadeIn=Einblenden (in s):
diff --git a/PlayWall/assets/de/tobias/playpad/assets/view/option/profile/generalTab.fxml b/PlayWall/assets/de/tobias/playpad/assets/view/option/profile/generalTab.fxml
index e0e5718c..9682eb43 100644
--- a/PlayWall/assets/de/tobias/playpad/assets/view/option/profile/generalTab.fxml
+++ b/PlayWall/assets/de/tobias/playpad/assets/view/option/profile/generalTab.fxml
@@ -5,10 +5,8 @@
 <?import javafx.scene.control.*?>
 <?import javafx.scene.layout.*?>
 
-
-<VBox spacing="14.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
+<VBox prefWidth="800.0" spacing="14.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
    <children>
-      <Label text="%settings.gen.label.additional" underline="true" />
       <HBox spacing="14.0">
          <children>
             <Label alignment="BASELINE_RIGHT" maxWidth="1.7976931348623157E308" prefWidth="150.0" text="%settings.gen.label.liveMode" />
diff --git a/PlayWall/assets/de/tobias/playpad/assets/view/option/profile/playerTab.fxml b/PlayWall/assets/de/tobias/playpad/assets/view/option/profile/playerTab.fxml
index c20941be..7b9c18cd 100644
--- a/PlayWall/assets/de/tobias/playpad/assets/view/option/profile/playerTab.fxml
+++ b/PlayWall/assets/de/tobias/playpad/assets/view/option/profile/playerTab.fxml
@@ -7,6 +7,13 @@
 
 <VBox spacing="14.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
    <children>
+      <HBox spacing="14.0">
+         <children>
+            <Label alignment="CENTER_RIGHT" prefWidth="150.0" text="%settings.player.label.modus" />
+            <CheckBox fx:id="playerModus" layoutX="150.0" mnemonicParsing="false" text="%settings.player.checkbox.modus" />
+         </children>
+      </HBox>
+      <Separator prefWidth="200.0" />
       <Label text="%settings.player.label.fade" underline="true" />
       <VBox fx:id="fadeContainer" minHeight="20.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
       <Separator prefWidth="200.0" />
diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/option/profile/PlayerTabViewController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/option/profile/PlayerTabViewController.java
index a8893d91..46ac63ee 100644
--- a/PlayWall/src/de/tobias/playpad/viewcontroller/option/profile/PlayerTabViewController.java
+++ b/PlayWall/src/de/tobias/playpad/viewcontroller/option/profile/PlayerTabViewController.java
@@ -13,11 +13,15 @@ import de.tobias.playpad.viewcontroller.settings.FadeViewController;
 import de.tobias.playpad.viewcontroller.settings.WarningFeedbackViewController;
 import de.tobias.utils.util.Localization;
 import javafx.fxml.FXML;
+import javafx.scene.control.CheckBox;
 import javafx.scene.control.ComboBox;
 import javafx.scene.layout.VBox;
 
 public class PlayerTabViewController extends ProfileSettingsTabViewController {
 
+	// Modus
+	@FXML private CheckBox playerModus;
+
 	// Player
 	@FXML private VBox warningFeedbackContainer;
 	@FXML private VBox fadeContainer;
@@ -52,6 +56,7 @@ public class PlayerTabViewController extends ProfileSettingsTabViewController {
 	public void loadSettings(Profile profile) {
 		ProfileSettings profileSettings = profile.getProfileSettings();
 
+		playerModus.setSelected(profile.getProfileSettings().isMultiplePlayer());
 		timeDisplayComboBox.setValue(profileSettings.getPlayerTimeDisplayMode());
 	}
 
@@ -60,6 +65,7 @@ public class PlayerTabViewController extends ProfileSettingsTabViewController {
 		ProfileSettings profileSettings = profile.getProfileSettings();
 
 		// Player
+		profileSettings.setMultiplePlayer(playerModus.isSelected());
 		profileSettings.setPlayerTimeDisplayMode(timeDisplayComboBox.getValue());
 	}
 
diff --git a/PlayWallCore/src/de/tobias/playpad/pad/Pad.java b/PlayWallCore/src/de/tobias/playpad/pad/Pad.java
index b9e0ae36..06cb57b8 100644
--- a/PlayWallCore/src/de/tobias/playpad/pad/Pad.java
+++ b/PlayWallCore/src/de/tobias/playpad/pad/Pad.java
@@ -138,6 +138,7 @@ public class Pad {
 		if (status == PadStatus.STOP && getStatus() == PadStatus.READY) {
 			return;
 		}
+
 		this.statusProperty.set(status);
 	}
 
diff --git a/PlayWallCore/src/de/tobias/playpad/pad/PadStatusListener.java b/PlayWallCore/src/de/tobias/playpad/pad/PadStatusListener.java
index a355c6f9..f5ba2d87 100644
--- a/PlayWallCore/src/de/tobias/playpad/pad/PadStatusListener.java
+++ b/PlayWallCore/src/de/tobias/playpad/pad/PadStatusListener.java
@@ -3,6 +3,8 @@ package de.tobias.playpad.pad;
 import de.tobias.playpad.PlayPadPlugin;
 import de.tobias.playpad.pad.conntent.play.Fadeable;
 import de.tobias.playpad.pad.conntent.play.Pauseable;
+import de.tobias.playpad.settings.Profile;
+import de.tobias.playpad.settings.ProfileSettings;
 import javafx.beans.value.ChangeListener;
 import javafx.beans.value.ObservableValue;
 
@@ -10,6 +12,9 @@ public class PadStatusListener implements ChangeListener<PadStatus> {
 
 	private Pad pad;
 
+	// Utils für Single Pad Playing
+	private static Pad currentPlayingPad; // Nur wenn ProfileSettings.isMultiplePlayer == false
+
 	public PadStatusListener(Pad pad) {
 		this.pad = pad;
 	}
@@ -17,11 +22,22 @@ public class PadStatusListener implements ChangeListener<PadStatus> {
 	@Override
 	public void changed(ObservableValue<? extends PadStatus> observable, PadStatus oldValue, PadStatus newValue) {
 		PadSettings padSettings = pad.getPadSettings();
+		ProfileSettings profileSettings = Profile.currentProfile().getProfileSettings();
 
 		if (newValue == PadStatus.PLAY) {
 			if (pad.getContent() != null) {
 				PlayPadPlugin.getImplementation().getPadListener().forEach(listener -> listener.onPlay(pad));
 
+				// bei Single Pad Playing wird das alte Pad beendet.
+				if (!profileSettings.isMultiplePlayer()) {
+					if (currentPlayingPad != null) {
+						if (currentPlayingPad.getStatus() == PadStatus.PLAY || currentPlayingPad.getStatus() == PadStatus.PAUSE) {
+							currentPlayingPad.setStatus(PadStatus.STOP);
+						}
+					}
+					currentPlayingPad = pad;
+				}
+
 				if (pad.getContent() instanceof Fadeable) {
 					if (oldValue == PadStatus.PAUSE && padSettings.getFade().isFadeInPause()) {
 						((Fadeable) pad.getContent()).fadeIn();
diff --git a/PlayWallCore/src/de/tobias/playpad/settings/ProfileSettings.java b/PlayWallCore/src/de/tobias/playpad/settings/ProfileSettings.java
index f31720c2..017e3777 100644
--- a/PlayWallCore/src/de/tobias/playpad/settings/ProfileSettings.java
+++ b/PlayWallCore/src/de/tobias/playpad/settings/ProfileSettings.java
@@ -47,6 +47,7 @@ public class ProfileSettings implements SettingsSerializable {
 	@Storable private String mainLayoutType = PlayPadPlugin.getRegistryCollection().getMainLayouts().getDefaultID();
 
 	// Cart Settings
+	@Storable private boolean multiplePlayer = true;
 	@Storable private Warning warningFeedback = new Warning(Duration.seconds(5));
 
 	@Storable private boolean midiActive = false;
@@ -146,6 +147,10 @@ public class ProfileSettings implements SettingsSerializable {
 		return audioUserInfo;
 	}
 
+	public boolean isMultiplePlayer() {
+		return multiplePlayer;
+	}
+
 	// Setter
 	public void setMidiDeviceName(String midiDevice) {
 		this.midiDevice = midiDevice;
@@ -211,6 +216,10 @@ public class ProfileSettings implements SettingsSerializable {
 		this.audioClass = audioClass;
 	}
 
+	public void setMultiplePlayer(boolean multiplePlayer) {
+		this.multiplePlayer = multiplePlayer;
+	}
+
 	// Properties
 	public DoubleProperty volumeProperty() {
 		return volumeProperty;
@@ -224,6 +233,7 @@ public class ProfileSettings implements SettingsSerializable {
 	private static final String AUDIO_USER_INFO_ELEMENT = "AudioUserInfo";
 	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";
 	private static final String LIVE_MODE_ELEMENT = "LiveMode";
 	private static final String LIVE_MODE_PAGE_ATTR = "page";
 	private static final String LIVE_MODE_DRAG_ATTR = "drag";
@@ -260,6 +270,10 @@ public class ProfileSettings implements SettingsSerializable {
 				profileSettings.setMainLayoutType(root.element(MAIN_LAYOUT_TYPE_ELEMENT).getStringValue());
 			}
 
+			if (root.element(MULTIPLE_PLAYER_ELEMENT) != null) {
+				profileSettings.setMultiplePlayer(Boolean.valueOf(root.element(MULTIPLE_PLAYER_ELEMENT).getStringValue()));
+			}
+
 			if (root.element(WARNING_ELEMENT) != null) {
 				Warning warning = Warning.load(root.element(WARNING_ELEMENT));
 				if (warning != null) {
@@ -342,6 +356,8 @@ public class ProfileSettings implements SettingsSerializable {
 		fade.save(root.addElement(FADE_ELEMENT));
 		root.addElement(TIME_DISPLAY_ELEMENT).addText(player_timeDisplayMode.name());
 
+		root.addElement(MULTIPLE_PLAYER_ELEMENT).addText(String.valueOf(multiplePlayer));
+
 		Element liveElement = root.addElement(LIVE_MODE_ELEMENT);
 		liveElement.addText(String.valueOf(liveMode));
 		liveElement.addAttribute(LIVE_MODE_PAGE_ATTR, String.valueOf(liveModePage));
-- 
GitLab