diff --git a/PlayWall/src/de/tobias/playpad/audio/ClipAudioHandler.java b/PlayWall/src/de/tobias/playpad/audio/ClipAudioHandler.java index 235b0455c069d0ebd61505bf9995b1edbea28b51..e9e4d6cfa9bf494fba31062d3d29ffa619479b8a 100644 --- a/PlayWall/src/de/tobias/playpad/audio/ClipAudioHandler.java +++ b/PlayWall/src/de/tobias/playpad/audio/ClipAudioHandler.java @@ -177,7 +177,7 @@ public class ClipAudioHandler extends AudioHandler { * @param volume * [0, 1] */ - private void setVolume(double volume) { + public void setVolume(double volume) { if (volumeControl != null) { if (volume == 1.0) { volumeControl.setValue(0); diff --git a/PlayWall/src/de/tobias/playpad/audio/JavaFXAudioHandler.java b/PlayWall/src/de/tobias/playpad/audio/JavaFXAudioHandler.java index a51a95c82104478992328406eab1cf45395c4b0f..a1c001b15aa3face5a103f2e3e4b3bd3df2cea64 100644 --- a/PlayWall/src/de/tobias/playpad/audio/JavaFXAudioHandler.java +++ b/PlayWall/src/de/tobias/playpad/audio/JavaFXAudioHandler.java @@ -83,6 +83,13 @@ public class JavaFXAudioHandler extends AudioHandler implements Equalizable { if (player != null) player.setVolume(volume * masterVolume * customVolume); } + + @Override + public void setVolume(double volume) { + if (player != null) { + player.setVolume(volume); + } + } @Override public boolean isMediaLoaded() { diff --git a/PlayWall/src/de/tobias/playpad/audio/TinyAudioHandler.java b/PlayWall/src/de/tobias/playpad/audio/TinyAudioHandler.java index 26c418195d351bd343a6f828b859c13be3fc1602..e78b7be10492f1791e04c89ed95286dddd96e332 100644 --- a/PlayWall/src/de/tobias/playpad/audio/TinyAudioHandler.java +++ b/PlayWall/src/de/tobias/playpad/audio/TinyAudioHandler.java @@ -206,6 +206,13 @@ public class TinyAudioHandler extends AudioHandler { music.setVolume(volume * masterVolume * customVolume); } } + + @Override + public void setVolume(double volume) { + if (music != null) { + music.setVolume(volume); + } + } @Override public boolean isMediaLoaded() { diff --git a/PlayWall/src/de/tobias/playpad/pad/content/AudioContent.java b/PlayWall/src/de/tobias/playpad/pad/content/AudioContent.java index 5740b39ae23884ca466fd2397357450873361f15..b34fd90868d42fee4186e065b8aeac89f6804d2e 100644 --- a/PlayWall/src/de/tobias/playpad/pad/content/AudioContent.java +++ b/PlayWall/src/de/tobias/playpad/pad/content/AudioContent.java @@ -11,18 +11,18 @@ import de.tobias.playpad.PlayPadPlugin; import de.tobias.playpad.audio.AudioHandler; import de.tobias.playpad.audio.AudioRegistry; import de.tobias.playpad.audio.Equalizable; +import de.tobias.playpad.audio.fade.Fading; import de.tobias.playpad.pad.Pad; -import de.tobias.playpad.pad.PadSettings; import de.tobias.playpad.pad.PadStatus; import de.tobias.playpad.pad.conntent.PadContent; import de.tobias.playpad.pad.conntent.path.SinglePathContent; import de.tobias.playpad.pad.conntent.play.Durationable; import de.tobias.playpad.pad.conntent.play.Fadeable; +import de.tobias.playpad.pad.conntent.play.IVolume; import de.tobias.playpad.pad.conntent.play.Pauseable; import de.tobias.playpad.project.ProjectExporter; import de.tobias.playpad.registry.NoSuchComponentException; -import de.tobias.playpad.settings.Profile; -import de.tobias.playpad.settings.ProfileSettings; +import de.tobias.playpad.volume.VolumeManager; import de.tobias.utils.util.ZipFile; import javafx.animation.Transition; import javafx.application.Platform; @@ -33,7 +33,7 @@ import javafx.beans.value.ChangeListener; import javafx.scene.media.AudioEqualizer; import javafx.util.Duration; -public class AudioContent extends PadContent implements Pauseable, Durationable, Fadeable, Equalizable, SinglePathContent { +public class AudioContent extends PadContent implements Pauseable, Durationable, Fadeable, Equalizable, SinglePathContent, IVolume { private static final String TYPE = "audio"; @@ -44,7 +44,8 @@ public class AudioContent extends PadContent implements Pauseable, Durationable, private ObjectProperty<Duration> positionProperty = new SimpleObjectProperty<>(); private ChangeListener<Number> volumeListener; - private ChangeListener<Number> customVolumeListener; + + private Fading fading; private transient Transition transition; @@ -52,13 +53,7 @@ public class AudioContent extends PadContent implements Pauseable, Durationable, super(pad); volumeListener = (a, b, c) -> { - ProfileSettings profileSettings = Profile.currentProfile().getProfileSettings(); - audioHandler.setVolume(c.doubleValue(), profileSettings.getVolume(), pad.getCustomVolume()); - }; - customVolumeListener = (a, b, c) -> - { - ProfileSettings profileSettings = Profile.currentProfile().getProfileSettings(); - audioHandler.setVolume(pad.getPadSettings().getVolume(), profileSettings.getVolume(), c.doubleValue()); + updateVolume(); }; } @@ -79,10 +74,9 @@ public class AudioContent extends PadContent implements Pauseable, Durationable, } @Override - public void setMasterVolume(double masterVolume) { - if (audioHandler != null) { - audioHandler.setVolume(getPad().getPadSettings().getVolume(), masterVolume, getPad().getCustomVolume()); - } + public void updateVolume() { + double volume = Pad.getVolumeManager().computeVolume(getPad()); + audioHandler.setVolume(volume); } @Override @@ -92,7 +86,6 @@ public class AudioContent extends PadContent implements Pauseable, Durationable, @Override public void play() { - getPad().setCustomVolume(1); getPad().setEof(false); audioHandler.play(); } @@ -110,31 +103,10 @@ public class AudioContent extends PadContent implements Pauseable, Durationable, @Override public void fadeIn() { - if (transition != null) { - transition.stop(); - } - Pad pad = getPad(); if (pad.getPadSettings().getFade().getFadeIn().toMillis() > 0) { - double masterVolume = Profile.currentProfile().getProfileSettings().getVolume(); - audioHandler.setVolume(0, masterVolume, pad.getCustomVolume()); - transition = new Transition() { - - { - setCycleDuration(pad.getPadSettings().getFade().getFadeIn()); - } - - @Override - protected void interpolate(double frac) { - audioHandler.setVolume(frac * pad.getPadSettings().getVolume(), masterVolume, pad.getCustomVolume()); - } - }; - transition.setOnFinished(e -> - { - transition = null; - }); - transition.play(); + fading.fadeIn(pad.getPadSettings().getFade().getFadeIn()); } } @@ -145,31 +117,11 @@ public class AudioContent extends PadContent implements Pauseable, Durationable, } if (getPad().getPadSettings().getFade().getFadeOut().toMillis() > 0) { - transition = new Transition() { - - { - setCycleDuration(getPad().getPadSettings().getFade().getFadeOut()); - } - - @Override - protected void interpolate(double frac) { - double masterVolume = Profile.currentProfile().getProfileSettings().getVolume(); - PadSettings padSettings = getPad().getPadSettings(); - - audioHandler.setVolume(padSettings.getVolume() - frac * padSettings.getVolume(), masterVolume, getPad().getCustomVolume()); - } - }; - transition.setOnFinished(event -> + fading.fadeOut(getPad().getPadSettings().getFade().getFadeOut(), () -> { onFinish.run(); - - double masterVolume = Profile.currentProfile().getProfileSettings().getVolume(); - PadSettings padSettings = getPad().getPadSettings(); - - audioHandler.setVolume(padSettings.getVolume(), masterVolume, getPad().getCustomVolume()); - transition = null; + updateVolume(); }); - transition.play(); } else { onFinish.run(); } @@ -183,6 +135,14 @@ public class AudioContent extends PadContent implements Pauseable, Durationable, return false; } + @Override + public void setFadeLevel(double level) { + Pad pad = getPad(); + VolumeManager manager = Pad.getVolumeManager(); + + audioHandler.setVolume(level * manager.computeVolume(pad)); + } + @Override public AudioEqualizer getAudioEqualizer() { if (audioHandler instanceof Equalizable) { @@ -222,6 +182,8 @@ public class AudioContent extends PadContent implements Pauseable, Durationable, AudioRegistry audioRegistry = PlayPadPlugin.getRegistryCollection().getAudioHandlers(); audioHandler = audioRegistry.getCurrentAudioHandler().createAudioHandler(this); + fading = new Fading(this); + if (Files.exists(path)) { audioHandler.loadMedia(new Path[] { path }); @@ -229,7 +191,6 @@ public class AudioContent extends PadContent implements Pauseable, Durationable, positionProperty.bind(audioHandler.positionProperty()); getPad().getPadSettings().volumeProperty().addListener(volumeListener); - getPad().customVolumeProperty().addListener(customVolumeListener); } else { // getPad().throwException(path, new FileNotFoundException()); TODO Error Handling User } @@ -241,7 +202,6 @@ public class AudioContent extends PadContent implements Pauseable, Durationable, positionProperty.unbind(); getPad().getPadSettings().volumeProperty().removeListener(volumeListener); - getPad().customVolumeProperty().removeListener(customVolumeListener); if (audioHandler != null) audioHandler.unloadMedia(); diff --git a/PlayWall/src/de/tobias/playpad/trigger/VolumeTriggerItem.java b/PlayWall/src/de/tobias/playpad/trigger/VolumeTriggerItem.java index 208dc5a8d982b769d7a0d05a4e5d8de8ddf805a9..282bb4cedb75c979f4f2dbb166ec0f6b698e0048 100644 --- a/PlayWall/src/de/tobias/playpad/trigger/VolumeTriggerItem.java +++ b/PlayWall/src/de/tobias/playpad/trigger/VolumeTriggerItem.java @@ -56,11 +56,12 @@ public class VolumeTriggerItem extends TriggerItem { protected void interpolate(double frac) { for (Pad p : project.getPads()) { if (p.getIndex() != pad.getIndex()) { - if (p.getCustomVolume() > volume) { - p.setCustomVolume(currentValue - frac * (currentValue - volume)); - } else { - p.setCustomVolume(currentValue + frac * (volume - currentValue)); - } + // TODO Volume Trigger Implemeitation + // if (p.getCustomVolume() > volume) { + // p.setCustomVolume(currentValue - frac * (currentValue - volume)); + // } else { + // p.setCustomVolume(currentValue + frac * (volume - currentValue)); + // } } } } diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewController.java index 0b614e0086686b8298b69b88c94fc809c3594ab2..b260afc55ff730a6f5126a9ac2fa592223e1b485 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewController.java @@ -113,7 +113,7 @@ public class MainViewController extends ViewController implements IMainViewContr layoutActions = new ArrayList<>(); // Init Listener - volumeChangeListener = new VolumeChangeListener(this); + volumeChangeListener = new VolumeChangeListener(openProject); lockedListener = new LockedListener(this); layoutChangedListener = new LayoutChangedListener(); initMapper(openProject); @@ -512,16 +512,6 @@ public class MainViewController extends ViewController implements IMainViewContr return currentPageShowing; } - @Override - public void setGlobalVolume(double volume) { - if (openProject != null) { - for (Pad pad : openProject.getPads()) { - if (pad != null) - pad.setMasterVolume(volume); - } - } - } - // Settings @Override public void reloadSettings(Profile old, Profile currentProfile) { diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/main/VolumeChangeListener.java b/PlayWall/src/de/tobias/playpad/viewcontroller/main/VolumeChangeListener.java index 2d017c45054c6cc0a50273085ea55886c5765d3d..382803a4290b5c1611ed74a4731c4502c1bf5a66 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/main/VolumeChangeListener.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/main/VolumeChangeListener.java @@ -1,18 +1,30 @@ package de.tobias.playpad.viewcontroller.main; +import de.tobias.playpad.pad.Pad; +import de.tobias.playpad.pad.PadStatus; +import de.tobias.playpad.project.Project; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; public class VolumeChangeListener implements ChangeListener<Number> { - private IMainViewController mainViewController; + private Project openProject; - public VolumeChangeListener(IMainViewController mainViewController) { - this.mainViewController = mainViewController; + public VolumeChangeListener(Project openProject) { + this.openProject = openProject; + } + + public void setOpenProject(Project openProject) { + this.openProject = openProject; } @Override public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { - mainViewController.setGlobalVolume(newValue.doubleValue()); + if (openProject != null) { + for (Pad pad : openProject.getPads()) { + if (pad != null && pad.getStatus() != PadStatus.EMPTY) + pad.getContent().updateVolume(); + } + } } } diff --git a/PlayWall/src/de/tobias/playpad/volume/GlobalVolume.java b/PlayWall/src/de/tobias/playpad/volume/GlobalVolume.java new file mode 100644 index 0000000000000000000000000000000000000000..d416c051002d05176f25dcc67f9c744a48440352 --- /dev/null +++ b/PlayWall/src/de/tobias/playpad/volume/GlobalVolume.java @@ -0,0 +1,16 @@ +package de.tobias.playpad.volume; + +import de.tobias.playpad.pad.Pad; +import de.tobias.playpad.settings.Profile; + +public class GlobalVolume implements VolumeFilter { + + @Override + public double getVolume(Pad pad) { + if (Profile.currentProfile() != null) { + return Profile.currentProfile().getProfileSettings().getVolume(); + } else { + return 1.0; + } + } +} diff --git a/PlayWall/src/de/tobias/playpad/volume/PadVolume.java b/PlayWall/src/de/tobias/playpad/volume/PadVolume.java new file mode 100644 index 0000000000000000000000000000000000000000..4781bd629b4256cef761054a66e063e1e289d244 --- /dev/null +++ b/PlayWall/src/de/tobias/playpad/volume/PadVolume.java @@ -0,0 +1,11 @@ +package de.tobias.playpad.volume; + +import de.tobias.playpad.pad.Pad; + +public class PadVolume implements VolumeFilter { + + @Override + public double getVolume(Pad pad) { + return pad.getPadSettings().getVolume(); + } +} diff --git a/PlayWallCore/src/de/tobias/playpad/audio/AudioHandler.java b/PlayWallCore/src/de/tobias/playpad/audio/AudioHandler.java index dee8a0e13d6a7268720ec5a9c093099a4c2e4ab9..ebe336c824d5878fd544e18a664010c1a52396af 100644 --- a/PlayWallCore/src/de/tobias/playpad/audio/AudioHandler.java +++ b/PlayWallCore/src/de/tobias/playpad/audio/AudioHandler.java @@ -34,6 +34,9 @@ public abstract class AudioHandler { public abstract ReadOnlyObjectProperty<Duration> durationProperty(); + public abstract void setVolume(double volume); + + @Deprecated public abstract void setVolume(double volume, double masterVolume, double customVolume); public abstract boolean isMediaLoaded(); diff --git a/PlayWallCore/src/de/tobias/playpad/audio/fade/Fadeable.java b/PlayWallCore/src/de/tobias/playpad/audio/fade/Fadeable.java new file mode 100644 index 0000000000000000000000000000000000000000..1f888187677aa19a144dc837997efabf7b837f42 --- /dev/null +++ b/PlayWallCore/src/de/tobias/playpad/audio/fade/Fadeable.java @@ -0,0 +1,13 @@ +package de.tobias.playpad.audio.fade; + +/** + * Schnittstelle, die für das Faden die Lautstärke in der Audio Implementierung setzt. + * + * @author tobias + * + * @since 6.0.0 + */ +public interface Fadeable { + + public void setVolume(double vol); +} diff --git a/PlayWallCore/src/de/tobias/playpad/audio/fade/Fading.java b/PlayWallCore/src/de/tobias/playpad/audio/fade/Fading.java new file mode 100644 index 0000000000000000000000000000000000000000..5fe281b641efba4fb06f3cfc05eced1515fa5029 --- /dev/null +++ b/PlayWallCore/src/de/tobias/playpad/audio/fade/Fading.java @@ -0,0 +1,95 @@ +package de.tobias.playpad.audio.fade; + +import de.tobias.playpad.pad.conntent.play.IVolume; +import javafx.animation.Transition; +import javafx.util.Duration; + +/** + * Fading utils. + * + * @author tobias + * + * @since 6.0.0 + */ +public class Fading { + + private IVolume iVolume; + private Transition currentFadeTransition; + + private double velocity = 1; + + public Fading(IVolume iVolume) { + this.iVolume = iVolume; + } + + public double getVelocity() { + return velocity; + } + + public void setVelocity(double velocity) { + this.velocity = velocity; + } + + public void fadeIn(Duration duration) { + fade(0, 1, duration, null); + } + + public void fadeIn(Duration duration, Runnable onFinsih) { + fade(0, 1, duration, onFinsih); + } + + public void fadeOut(Duration duration) { + fade(1, 0, duration, null); + } + + public void fadeOut(Duration duration, Runnable onFinish) { + fade(1, 0, duration, onFinish); + } + + public boolean isFading() { + return currentFadeTransition != null; + } + + private void fade(double from, double to, Duration duration, Runnable onFinish) { + if (currentFadeTransition != null) { + currentFadeTransition.stop(); + } + + currentFadeTransition = new Transition() { + + { + setCycleDuration(duration); + } + + @Override + protected void interpolate(double frac) { + double diff = Math.abs(to - from); + if (from < to) { // Fade In + double fade = fadeInVolumeMultiplier(frac, velocity); + iVolume.setFadeLevel(from + fade * diff); + } else { // Fade Out + double fade = fadeOutVolumeMultiplier(frac, velocity); + double newValue = to + fade * diff; + iVolume.setFadeLevel(newValue); + } + } + }; + currentFadeTransition.setOnFinished(e -> + { + currentFadeTransition = null; + if (onFinish != null) { + onFinish.run(); + } + }); + currentFadeTransition.play(); + } + + protected double fadeInVolumeMultiplier(double time, double velocity) { + return Math.pow(Math.E, velocity * (time - 1)) * time; + } + + protected double fadeOutVolumeMultiplier(double time, double velocity) { + return Math.pow(Math.E, -velocity * time) * (1 - time); + } + +} diff --git a/PlayWallCore/src/de/tobias/playpad/pad/Pad.java b/PlayWallCore/src/de/tobias/playpad/pad/Pad.java index 2acbc96a6684b83dda1a246462a41d6eb23e69d7..1707bb189b290398ed55985aac0742c387c694dd 100644 --- a/PlayWallCore/src/de/tobias/playpad/pad/Pad.java +++ b/PlayWallCore/src/de/tobias/playpad/pad/Pad.java @@ -12,11 +12,10 @@ import de.tobias.playpad.pad.viewcontroller.IPadViewController; import de.tobias.playpad.project.Project; import de.tobias.playpad.project.page.PadIndex; import de.tobias.playpad.registry.NoSuchComponentException; -import javafx.beans.property.DoubleProperty; +import de.tobias.playpad.volume.VolumeManager; import javafx.beans.property.IntegerProperty; import javafx.beans.property.ObjectProperty; import javafx.beans.property.ReadOnlyIntegerProperty; -import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleStringProperty; @@ -24,6 +23,12 @@ import javafx.beans.property.StringProperty; public class Pad { + private static final VolumeManager volumeManager; + + static { + volumeManager = new VolumeManager(); + } + // Verwaltung private UUID uuid; private IntegerProperty indexProperty = new SimpleIntegerProperty(); @@ -38,9 +43,6 @@ public class Pad { // Settings private PadSettings padSettings; - // Custom Volume - private transient DoubleProperty customVolumeProperty = new SimpleDoubleProperty(1.0); - // Global Listener (unabhängig von der UI), für Core Functions wie Play, Pause private transient PadStatusListener padStatusListener; @@ -199,12 +201,6 @@ public class Pad { return padSettings; } - public void setMasterVolume(double volume) { - if (getContent() != null) { - getContent().setMasterVolume(volume); - } - } - public boolean isEof() { return eof; } @@ -284,16 +280,8 @@ public class Pad { return (indexProperty.get() + 1) + " - " + nameProperty.get(); } - // TODO Reorder - public void setCustomVolume(double volume) { - customVolumeProperty.set(volume); - } - - public double getCustomVolume() { - return customVolumeProperty.get(); - } - - public DoubleProperty customVolumeProperty() { - return customVolumeProperty; + // Volume Manager + public static VolumeManager getVolumeManager() { + return volumeManager; } } diff --git a/PlayWallCore/src/de/tobias/playpad/pad/conntent/PadContent.java b/PlayWallCore/src/de/tobias/playpad/pad/conntent/PadContent.java index d54338010dd6d7fbfbfff67f804816004e186d3f..d9b655cb38def31558466793b3286d570becf600 100644 --- a/PlayWallCore/src/de/tobias/playpad/pad/conntent/PadContent.java +++ b/PlayWallCore/src/de/tobias/playpad/pad/conntent/PadContent.java @@ -63,7 +63,7 @@ public abstract class PadContent { */ public abstract void unloadMedia(); - public abstract void setMasterVolume(double masterVolume); + public abstract void updateVolume(); @Override protected void finalize() throws Throwable { diff --git a/PlayWallCore/src/de/tobias/playpad/pad/conntent/play/IVolume.java b/PlayWallCore/src/de/tobias/playpad/pad/conntent/play/IVolume.java new file mode 100644 index 0000000000000000000000000000000000000000..f681dd20a0b8d43ef54e6554c3cbcd0d15133aab --- /dev/null +++ b/PlayWallCore/src/de/tobias/playpad/pad/conntent/play/IVolume.java @@ -0,0 +1,13 @@ +package de.tobias.playpad.pad.conntent.play; + +/** + * Schnittstelle für das Pad, sodass es Lautstärke erhält. + * + * @author tobias + * + * @since 6.0.0 + */ +public interface IVolume { + + public void setFadeLevel(double level); +} diff --git a/PlayWallCore/src/de/tobias/playpad/viewcontroller/main/IMainViewController.java b/PlayWallCore/src/de/tobias/playpad/viewcontroller/main/IMainViewController.java index 4a6bb28d49299a18a4dac4725e04e72fe68ddf06..29941d200665aeea35c4eee8d0b4ad4b13c4dda4 100644 --- a/PlayWallCore/src/de/tobias/playpad/viewcontroller/main/IMainViewController.java +++ b/PlayWallCore/src/de/tobias/playpad/viewcontroller/main/IMainViewController.java @@ -118,14 +118,6 @@ public interface IMainViewController extends NotificationHandler { */ public MidiListener getMidiHandler(); - /** - * Setzt das Globale Volume bei den Kacheln des aktuellen Projekts. - * - * @param doubleValue - * [0..1] - */ - public void setGlobalVolume(double doubleValue); - /** * Setzt das MainLayout des Hauptfensters. * diff --git a/PlayWallCore/src/de/tobias/playpad/volume/VolumeFilter.java b/PlayWallCore/src/de/tobias/playpad/volume/VolumeFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..805fc4387578b4f6601b8beb2a73d58a7970e470 --- /dev/null +++ b/PlayWallCore/src/de/tobias/playpad/volume/VolumeFilter.java @@ -0,0 +1,19 @@ +package de.tobias.playpad.volume; + +import de.tobias.playpad.pad.Pad; + +/** + * Interface, um das Volume eines Pad zu beeinflussen. Es muss dem VolumeManager hinzugefügt werden. + * + * @author tobias + * + * @sinve 6.0.0 + * + * @see VolumeManager#addFilter(VolumeFilter) + */ +@FunctionalInterface +public interface VolumeFilter { + + double getVolume(Pad pad); + +} diff --git a/PlayWallCore/src/de/tobias/playpad/volume/VolumeManager.java b/PlayWallCore/src/de/tobias/playpad/volume/VolumeManager.java new file mode 100644 index 0000000000000000000000000000000000000000..8a809d40be62223c8fa99ab307f68912547594bf --- /dev/null +++ b/PlayWallCore/src/de/tobias/playpad/volume/VolumeManager.java @@ -0,0 +1,36 @@ +package de.tobias.playpad.volume; + +import java.util.ArrayList; +import java.util.List; + +import de.tobias.playpad.pad.Pad; + +public class VolumeManager { + + private List<VolumeFilter> filters; + + public VolumeManager() { + this.filters = new ArrayList<>(); + } + + public void addFilter(VolumeFilter filter) { + filters.add(filter); + } + + public void removeFilter(VolumeFilter filter) { + filters.remove(filter); + } + + public double computeVolume(Pad pad) { + double volume = 1; + for (VolumeFilter filter : filters) { + volume *= filter.getVolume(pad); + + if (volume == 0) { + break; + } + } + return volume; + } + +} diff --git a/PlayWallPlugins/mediaplugin/de/tobias/playpad/mediaplugin/image/ImageContent.java b/PlayWallPlugins/mediaplugin/de/tobias/playpad/mediaplugin/image/ImageContent.java index 9472dff4c3dfe81747d58cd9987ac5ac01871177..60a7195c4f219ebafff26e8c7b0c61ecf300f0b2 100644 --- a/PlayWallPlugins/mediaplugin/de/tobias/playpad/mediaplugin/image/ImageContent.java +++ b/PlayWallPlugins/mediaplugin/de/tobias/playpad/mediaplugin/image/ImageContent.java @@ -1,6 +1,5 @@ package de.tobias.playpad.mediaplugin.image; -import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -45,7 +44,7 @@ public class ImageContent extends PadContent { } @Override - public void setMasterVolume(double masterVolume) { + public void updateVolume() { } @Override diff --git a/PlayWallPlugins/mediaplugin/de/tobias/playpad/mediaplugin/video/VideoContent.java b/PlayWallPlugins/mediaplugin/de/tobias/playpad/mediaplugin/video/VideoContent.java index cab86a4660c6e35ba74a71cd4bc344ab264dcfa0..6b622b5ad39953513b37d8488534a3fd2b342a0d 100644 --- a/PlayWallPlugins/mediaplugin/de/tobias/playpad/mediaplugin/video/VideoContent.java +++ b/PlayWallPlugins/mediaplugin/de/tobias/playpad/mediaplugin/video/VideoContent.java @@ -15,7 +15,7 @@ import de.tobias.playpad.pad.conntent.PadContent; import de.tobias.playpad.pad.conntent.play.Durationable; import de.tobias.playpad.pad.conntent.play.Pauseable; import de.tobias.playpad.project.ProjectExporter; -import de.tobias.playpad.settings.Profile; +import de.tobias.playpad.volume.VolumeManager; import de.tobias.utils.util.ZipFile; import javafx.application.Platform; import javafx.beans.property.ObjectProperty; @@ -40,7 +40,6 @@ public class VideoContent extends PadContent implements Pauseable, Durationable private transient ObjectProperty<Duration> positionProperty = new SimpleObjectProperty<>(); private transient ChangeListener<Number> padVolumeListener; - private transient ChangeListener<Number> customVolumeListener; private transient boolean holdLastFrame = false; @@ -48,12 +47,7 @@ public class VideoContent extends PadContent implements Pauseable, Durationable super(pad); padVolumeListener = (a, b, c) -> { - player.setVolume(c.doubleValue() * Profile.currentProfile().getProfileSettings().getVolume() * getPad().getCustomVolume()); - }; - customVolumeListener = (a, b, c) -> - { - player.setVolume( - getPad().getPadSettings().getVolume() * Profile.currentProfile().getProfileSettings().getVolume() * c.doubleValue()); + updateVolume(); }; } @@ -78,9 +72,11 @@ public class VideoContent extends PadContent implements Pauseable, Durationable } @Override - public void setMasterVolume(double masterVolume) { + public void updateVolume() { if (player != null) { - player.setVolume(getPad().getPadSettings().getVolume() * masterVolume * getPad().getCustomVolume()); + VolumeManager manager = Pad.getVolumeManager(); + double volume = manager.computeVolume(getPad()); + player.setVolume(volume); } } @@ -91,7 +87,6 @@ public class VideoContent extends PadContent implements Pauseable, Durationable @Override public void play() { - getPad().setCustomVolume(1.0); getPad().setEof(false); MediaPluginImpl.getInstance().getVideoViewController().setMediaPlayer(player, getPad()); if (holdLastFrame) { @@ -209,7 +204,6 @@ public class VideoContent extends PadContent implements Pauseable, Durationable positionProperty.bind(player.currentTimeProperty()); getPad().getPadSettings().volumeProperty().addListener(padVolumeListener); - getPad().customVolumeProperty().addListener(customVolumeListener); } } @@ -219,7 +213,6 @@ public class VideoContent extends PadContent implements Pauseable, Durationable positionProperty.unbind(); getPad().getPadSettings().volumeProperty().removeListener(padVolumeListener); - getPad().customVolumeProperty().removeListener(customVolumeListener); player = null; media = null;