de.sciss.synth.proc.AuralSystem.scala Maven / Gradle / Ivy
/*
* AuralSystem.scala
* (SoundProcesses)
*
* Copyright (c) 2010-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.synth.proc
import impl.{AuralSystemImpl => Impl}
import de.sciss.lucre.synth.{Server, Txn}
object AuralSystem {
def apply(): AuralSystem = Impl()
def start(config: Server.Config = Server.Config(), connect: Boolean = false)(implicit tx: Txn): AuralSystem = {
val res = apply()
res.start(config, connect = connect)
res
}
/** Creates an offline-server based aural system.
* It is important that the `AuralSystem` is eventually
* disposed again, calling the `stop` method.
*/
def offline(server: Server.Offline)(implicit tx: Txn): AuralSystem = {
val res = apply()
res.offline(server)
res
}
trait Client {
def auralStarted(s: Server)(implicit tx: Txn): Unit
def auralStopped() (implicit tx: Txn): Unit
}
}
/** An `AuralSystem` is the logical representation of a sound synthesis server, whether running or not.
* To use an aural system, a client connects via `addClient`. The client will be notified when the
* server is up and running.
*/
trait AuralSystem {
import AuralSystem.Client
/** Boots the server. This method must be called from within a transaction. */
def start(config: Server.Config = Server.Config(), connect: Boolean = false)(implicit tx: Txn): Unit
private[proc] def offline(server: Server.Offline)(implicit tx: Txn): Unit
/** Quits the server. This method must not be called from within a transaction. */
def stop()(implicit tx: Txn): Unit
/** Adds a client to the system. It is safe to call this method both inside and
* outside of a transaction. If called inside a transaction, this is transaction
* safe (no duplicate registration if the transaction is retried).
*
* @param c the client to register. If the server is already running, the client
* will _not_ be immediately notified.
*/
def addClient (c: Client)(implicit tx: Txn): Unit
/** Removes a client to the system. It is safe to call this method both inside and
* outside of a transaction. If called inside a transaction, this is transaction
* safe.
*
* @param c the client to unregister. It is allowed to call this method even if
* the client was already unregistered.
*/
def removeClient(c: Client)(implicit tx: Txn): Unit
/** Registers a callback to be invoked when the server has been booted.
* If the server is already running, this has no effect. This method is transaction safe.
*
* The function is always execution _outside_ of a transaction.
*/
def whenStarted(fun: Server => Unit)(implicit tx: Txn): Unit
def serverOption(implicit tx: Txn): Option[Server]
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy