de.sciss.fscape.stream.RunningWindowSum.scala Maven / Gradle / Ivy
/*
* RunningWindowSum.scala
* (FScape)
*
* Copyright (c) 2001-2016 Hanns Holger Rutz. All rights reserved.
*
* This software is published under the GNU General Public License v2+
*
*
* For further information, please contact Hanns Holger Rutz at
* [email protected]
*/
package de.sciss.fscape
package stream
import akka.stream.{Attributes, FanInShape3}
import de.sciss.fscape.stream.impl.{FilterIn3DImpl, RunningWindowValueImpl, StageImpl, NodeImpl}
object RunningWindowSum {
def apply(in: OutD, size: OutI, trig: OutI)(implicit b: Builder): OutD = {
val stage0 = new Stage
val stage = b.add(stage0)
b.connect(in , stage.in0)
b.connect(size, stage.in1)
b.connect(trig, stage.in2)
stage.out
}
private final val name = "RunningWindowSum"
private type Shape = FanInShape3[BufD, BufI, BufI, BufD]
private final class Stage(implicit ctrl: Control) extends StageImpl[Shape](name) {
val shape = new FanInShape3(
in0 = InD (s"$name.in" ),
in1 = InI (s"$name.size"),
in2 = InI (s"$name.trig"),
out = OutD(s"$name.out" )
)
def createLogic(attr: Attributes) = new Logic(shape)
}
private final class Logic(shape: Shape)(implicit ctrl: Control)
extends NodeImpl(name, shape)
with RunningWindowValueImpl[Shape]
with FilterIn3DImpl[BufD, BufI, BufI] {
protected def combine(a: Double, b: Double): Double = a + b
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy