Skip to content
Snippets Groups Projects
Commit eb3ea744 authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

Add fading to ContentPlayerPadContent

parent 0163e8b3
No related branches found
No related tags found
No related merge requests found
package de.tobias.playpad.pad.fade;
import javafx.animation.Transition;
/**
* A fade controller implementation, that handles fade scala linear.
*
* @author tobias
* @since 7.1.0
*/
public class LinearFadeController extends AbstractFadeController {
public LinearFadeController(FadeControllerDelegate fadeDelegate) {
super(fadeDelegate);
}
@Override
protected void interpolate(Transition transition, double frac, double from, double to) {
double diff = Math.abs(to - from);
if (from < to) { // Fade In
fadeDelegate.onFadeLevelChange(diff * frac);
} else { // Fade Out
fadeDelegate.onFadeLevelChange(from - (diff * frac));
}
}
}
...@@ -45,6 +45,7 @@ class ContentPlayerViewController extends NVC { ...@@ -45,6 +45,7 @@ class ContentPlayerViewController extends NVC {
val mediaView = mediaViews(mediaPlayer) val mediaView = mediaViews(mediaPlayer)
mediaView.setUserData(padIndex) mediaView.setUserData(padIndex)
mediaView.setOpacity(1.0)
if (!getChildren.contains(mediaView)) { if (!getChildren.contains(mediaView)) {
val index = activePlayers.indexOf(padIndex) val index = activePlayers.indexOf(padIndex)
...@@ -58,6 +59,13 @@ class ContentPlayerViewController extends NVC { ...@@ -58,6 +59,13 @@ class ContentPlayerViewController extends NVC {
} }
} }
def setFadeValue(mediaPlayer: MediaPlayer, value: Double): Unit ={
if (mediaViews.contains(mediaPlayer)) {
val mediaView = mediaViews(mediaPlayer)
mediaView.setOpacity(value)
}
}
def highlight(on: Boolean): Unit = { def highlight(on: Boolean): Unit = {
if (on) { if (on) {
setBackground(new Background(new BackgroundFill(Color.RED, CornerRadii.EMPTY, Insets.EMPTY))) setBackground(new Background(new BackgroundFill(Color.RED, CornerRadii.EMPTY, Insets.EMPTY)))
...@@ -69,7 +77,7 @@ class ContentPlayerViewController extends NVC { ...@@ -69,7 +77,7 @@ class ContentPlayerViewController extends NVC {
override def toString: String = f"MediaPlayerStack: ${getChildren.stream().map(view => f"MediaView: ${view.getUserData}").collect(Collectors.joining(", "))}" override def toString: String = f"MediaPlayerStack: ${getChildren.stream().map(view => f"MediaView: ${view.getUserData}").collect(Collectors.joining(", "))}"
} }
private val mediaPlayers: ListBuffer[MediaPlayerStack] = ListBuffer.empty private val mediaStacks: ListBuffer[MediaPlayerStack] = ListBuffer.empty
load("view", "PlayerView") load("view", "PlayerView")
applyViewControllerToStage applyViewControllerToStage
...@@ -89,7 +97,7 @@ class ContentPlayerViewController extends NVC { ...@@ -89,7 +97,7 @@ class ContentPlayerViewController extends NVC {
} }
def showMediaPlayer(padIndex: PadIndex, mediaPlayer: MediaPlayer, zones: Seq[PlayerInstance]): Unit = { def showMediaPlayer(padIndex: PadIndex, mediaPlayer: MediaPlayer, zones: Seq[PlayerInstance]): Unit = {
val iterator = this.mediaPlayers.iterator val iterator = this.mediaStacks.iterator
while (iterator.hasNext) { while (iterator.hasNext) {
val mediaPlayerStack = iterator.next() val mediaPlayerStack = iterator.next()
if (zones.contains(mediaPlayerStack.playerInstance)) { if (zones.contains(mediaPlayerStack.playerInstance)) {
...@@ -99,7 +107,7 @@ class ContentPlayerViewController extends NVC { ...@@ -99,7 +107,7 @@ class ContentPlayerViewController extends NVC {
} }
def disconnectMediaPlayer(mediaPlayer: MediaPlayer, zones: Seq[PlayerInstance]): Unit = { def disconnectMediaPlayer(mediaPlayer: MediaPlayer, zones: Seq[PlayerInstance]): Unit = {
val iterator = this.mediaPlayers.iterator val iterator = this.mediaStacks.iterator
while (iterator.hasNext) { while (iterator.hasNext) {
val mediaPlayerStack = iterator.next() val mediaPlayerStack = iterator.next()
if (zones.contains(mediaPlayerStack.playerInstance)) { if (zones.contains(mediaPlayerStack.playerInstance)) {
...@@ -112,10 +120,10 @@ class ContentPlayerViewController extends NVC { ...@@ -112,10 +120,10 @@ class ContentPlayerViewController extends NVC {
val parent = getParent.asInstanceOf[Pane] val parent = getParent.asInstanceOf[Pane]
parent.getChildren.clear() parent.getChildren.clear()
mediaPlayers.clear() mediaStacks.clear()
configuration.instances.forEach(player => { configuration.instances.forEach(player => {
val mediaPlayerStack = new MediaPlayerStack(player) val mediaPlayerStack = new MediaPlayerStack(player)
mediaPlayers.addOne(mediaPlayerStack) mediaStacks.addOne(mediaPlayerStack)
parent.getChildren.add(mediaPlayerStack) parent.getChildren.add(mediaPlayerStack)
}) })
...@@ -134,15 +142,24 @@ class ContentPlayerViewController extends NVC { ...@@ -134,15 +142,24 @@ class ContentPlayerViewController extends NVC {
}) })
} }
def addActivePadToList(padIndex: PadIndex, zones: Seq[PlayerInstance]): Unit = mediaPlayers def addActivePadToList(padIndex: PadIndex, zones: Seq[PlayerInstance]): Unit = getMediaStacks(zones)
.filter(mediaPlayer => zones.contains(mediaPlayer.playerInstance)) .foreach(mediaStack => mediaStack.addActivePad(padIndex))
.foreach(mediaPlayer => mediaPlayer.addActivePad(padIndex))
def removeActivePadFromList(padIndex: PadIndex, zones: Seq[PlayerInstance]): Unit = mediaPlayers def removeActivePadFromList(padIndex: PadIndex, zones: Seq[PlayerInstance]): Unit = getMediaStacks(zones)
.filter(mediaPlayer => zones.contains(mediaPlayer.playerInstance)) .foreach(mediaStack => mediaStack.removeActivePad(padIndex))
.foreach(mediaPlayer => mediaPlayer.removeActivePad(padIndex))
def highlight(zone: PlayerInstance, on: Boolean): Unit = { def highlight(zone: PlayerInstance, on: Boolean): Unit = {
mediaPlayers.filter(mediaPlayer => zone == mediaPlayer.playerInstance).head.highlight(on) getMediaStack(zone).head.highlight(on)
}
def setFadeValue(mediaPlayer: MediaPlayer, zones: Seq[PlayerInstance], value: Double): Unit = getMediaStacks(zones)
.foreach(mediaStack => mediaStack.setFadeValue(mediaPlayer, value))
private def getMediaStack(zone: PlayerInstance): ListBuffer[MediaPlayerStack] = {
getMediaStacks(List(zone))
}
private def getMediaStacks(zones: Seq[PlayerInstance]): ListBuffer[MediaPlayerStack] = {
mediaStacks.filter(mediaPlayer => zones.contains(mediaPlayer.playerInstance))
} }
} }
...@@ -6,6 +6,7 @@ import java.util.stream.Collectors ...@@ -6,6 +6,7 @@ import java.util.stream.Collectors
import de.tobias.playpad.pad.content.play.{Durationable, Pauseable} import de.tobias.playpad.pad.content.play.{Durationable, Pauseable}
import de.tobias.playpad.pad.content.{PadContent, Playlistable} import de.tobias.playpad.pad.content.{PadContent, Playlistable}
import de.tobias.playpad.pad.fade.{Fadeable, LinearFadeController}
import de.tobias.playpad.pad.mediapath.MediaPath import de.tobias.playpad.pad.mediapath.MediaPath
import de.tobias.playpad.pad.{Pad, PadStatus} import de.tobias.playpad.pad.{Pad, PadStatus}
import de.tobias.playpad.plugin.content.ContentPluginMain import de.tobias.playpad.plugin.content.ContentPluginMain
...@@ -21,7 +22,7 @@ import javafx.util.Duration ...@@ -21,7 +22,7 @@ import javafx.util.Duration
import scala.jdk.CollectionConverters._ import scala.jdk.CollectionConverters._
class ContentPlayerPadContent(val pad: Pad, val `type`: String) extends PadContent(pad) with Pauseable with Durationable with Playlistable { class ContentPlayerPadContent(val pad: Pad, val `type`: String) extends PadContent(pad) with Pauseable with Durationable with Playlistable with Fadeable {
private class MediaPlayerContainer(val path: MediaPath, val mediaPlayer: MediaPlayer) { private class MediaPlayerContainer(val path: MediaPath, val mediaPlayer: MediaPlayer) {
def play(): Unit = { def play(): Unit = {
...@@ -32,6 +33,8 @@ class ContentPlayerPadContent(val pad: Pad, val `type`: String) extends PadConte ...@@ -32,6 +33,8 @@ class ContentPlayerPadContent(val pad: Pad, val `type`: String) extends PadConte
mediaPlayer.seek(Duration.ZERO) mediaPlayer.seek(Duration.ZERO)
mediaPlayer.play() mediaPlayer.play()
getPad.setEof(false)
currentRunningIndexProperty.set(mediaPlayers.indexOf(this)) currentRunningIndexProperty.set(mediaPlayers.indexOf(this))
val controller = getPad.getController val controller = getPad.getController
...@@ -84,6 +87,9 @@ class ContentPlayerPadContent(val pad: Pad, val `type`: String) extends PadConte ...@@ -84,6 +87,9 @@ class ContentPlayerPadContent(val pad: Pad, val `type`: String) extends PadConte
private var showingLastFrame: Boolean = false private var showingLastFrame: Boolean = false
private var isPause: Boolean = false private var isPause: Boolean = false
private val fadeController = new LinearFadeController(value => ContentPluginMain.playerViewController
.setFadeValue(mediaPlayers(currentPlayingMediaIndex).mediaPlayer, getSelectedZones, value))
override def getType: String = `type` override def getType: String = `type`
override def currentPlayingMediaIndex: Int = currentRunningIndexProperty.get() override def currentPlayingMediaIndex: Int = currentRunningIndexProperty.get()
...@@ -128,7 +134,10 @@ class ContentPlayerPadContent(val pad: Pad, val `type`: String) extends PadConte ...@@ -128,7 +134,10 @@ class ContentPlayerPadContent(val pad: Pad, val `type`: String) extends PadConte
} }
def onEof(): Unit = { def onEof(): Unit = {
if (shouldShowLastFrame() && !showingLastFrame && !pad.getPadSettings.isLoop) { if (shouldShowLastFrame() && !showingLastFrame // Only is settings is enabled and not already in last frame state
&& !pad.getPadSettings.isLoop // Only go to last frame state, is looping is disabled
&& !isFadeActive // Only go to last frame state, if no fade is active (if eof is reached while fade out, the last frame should not be hold)
) {
getPad.setStatus(PadStatus.PAUSE) getPad.setStatus(PadStatus.PAUSE)
showingLastFrame = true showingLastFrame = true
return return
...@@ -172,6 +181,36 @@ class ContentPlayerPadContent(val pad: Pad, val `type`: String) extends PadConte ...@@ -172,6 +181,36 @@ class ContentPlayerPadContent(val pad: Pad, val `type`: String) extends PadConte
.toArray(size => new Array[ReadOnlyObjectProperty[Duration]](size)): _*) .toArray(size => new Array[ReadOnlyObjectProperty[Duration]](size)): _*)
} }
/*
Fadeable
*/
override def fadeIn(): Unit = {
val fadeIn = getPad.getPadSettings.getFade.getFadeIn
if (fadeIn.toMillis > 0) {
fadeController.fadeIn(fadeIn)
}
}
override def fadeOut(onFinish: Runnable): Unit = {
val fadeOut = getPad.getPadSettings.getFade.getFadeOut
if (fadeOut.toMillis > 0) {
fadeController.fadeOut(fadeOut, () => {
if (onFinish != null) onFinish.run()
updateVolume()
})
}
else {
onFinish.run()
}
}
override def isFadeActive: Boolean = fadeController.isFading
override def fade(from: Double, to: Double, duration: Duration, onFinish: Runnable): Unit = {
fadeController.fade(from, to, duration, onFinish)
}
/* /*
Loading Loading
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment