All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.sciss.lucre.synth.State.scala Maven / Gradle / Ivy

There is a newer version: 3.30.0
Show newest version
/*
 *  State.scala
 *  (SoundProcesses)
 *
 *  Copyright (c) 2010-2019 Hanns Holger Rutz. All rights reserved.
 *
 *	This software is published under the GNU Lesser General Public License v2.1+
 *
 *
 *  For further information, please contact Hanns Holger Rutz at
 *  [email protected]
 */

package de.sciss.lucre.synth

import scala.concurrent.stm.Ref

object State {
  def apply(owner: Any, name: String, init: Boolean): State = new Impl(owner, name, init)

  private final class Impl(val owner: Any, val name: String, init: Boolean) extends State {
    val value = Ref(init)

    def swap(newValue: Boolean)(implicit tx: Txn): Boolean = value.swap(newValue)(tx.peer)

    def get(implicit tx: Txn): Boolean = value.get(tx.peer)
  }
}
sealed trait State {
  protected def value: Ref[Boolean]

  def swap(newValue: Boolean)(implicit tx: Txn): Boolean

  def get(implicit tx: Txn): Boolean

  final def set(newValue: Boolean)(implicit tx: Txn): Unit =
    value.set(newValue)(tx.peer)

  protected def owner: Any

  def name: String

  override def toString = s"<$owner $name>"
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy