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

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

There is a newer version: 3.30.0
Show newest version
/*
 *  Txn.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 de.sciss.lucre.stm.TxnLike
import de.sciss.lucre.synth.impl.TxnPlainImpl
import de.sciss.osc
import de.sciss.synth.message

import scala.collection.immutable.{IndexedSeq => Vec}
import scala.concurrent.stm.InTxn

object Txn {
  def wrap(itx: InTxn): Txn = new TxnPlainImpl(itx, 0L)

  type Message = osc.Message with message.Send

  /** A data type encapsulating an outgoing OSC bundle for this transaction. */
  final class Bundle(val stamp: Int, val messages: Vec[Message]) {
    def append(msg: Message): Bundle = new Bundle(stamp, messages :+ msg)

    def isEmpty : Boolean = messages.isEmpty
    def nonEmpty: Boolean = messages.nonEmpty

    /** A bundle depends on messages with any smaller time stamp (this stamp minus one). */
    def depStamp: Int = stamp - 1

    override def toString = s"Bundle($stamp, $messages)"
  }

  type Bundles = Vec[Bundle]
}

/** The `Txn` trait is declared without representation type parameter in order to keep the real-time sound
  * synthesis API clutter free. The sound synthesis is always ephemeral, so does not need to know anything
  * about the underlying system. What the process transaction provides is a package private
  * `addMessage` method for staging OSC messages which are flushed at the end of a successful transaction.
  */
trait Txn extends TxnLike {
  /** Or zero if not scheduled. */
  def systemTimeNanoSec: Long

  def addMessage(resource: Resource, m: osc.Message with message.Send, dependencies: Seq[Resource] = Nil): Unit
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy