de.sciss.mellite.impl.InterpreterSingleton.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mellite_2.13.0-M5 Show documentation
Show all versions of mellite_2.13.0-M5 Show documentation
A computer music application based on SoundProcesses
The newest version!
/*
* InterpreterSingleton.scala
* (Mellite)
*
* Copyright (c) 2012-2019 Hanns Holger Rutz. All rights reserved.
*
* This software is published under the GNU Affero General Public License v3+
*
*
* For further information, please contact Hanns Holger Rutz at
* [email protected]
*/
package de.sciss.mellite
package impl
import de.sciss.scalainterpreter.Interpreter
import scala.collection.immutable.{IndexedSeq => Vec}
object InterpreterSingleton {
private val sync = new AnyRef
private var funs = Vec .empty[Interpreter => Unit]
private var inOpt = Option.empty[Interpreter]
// object Result {
// var value : Any = ()
// }
//
// def wrap( code: String ) : String = {
// "de.sciss.mellite.gui.impl.InterpreterSingleton.Result.value = {" + code + "}"
// }
def apply(fun: Interpreter => Unit): Unit =
sync.synchronized {
inOpt match {
case Some(in) =>
fun(in)
case _ =>
makeOne
funs :+= fun
}
}
private lazy val makeOne: Unit = {
val cfg = Interpreter.Config()
cfg.imports ++= Seq(
"de.sciss.synth",
"synth._",
"ugen._"
)
// cfg.bindings += NamedParam( Result )
Interpreter.async(cfg).foreach { in =>
sync.synchronized {
inOpt = Some(in)
val f = funs
funs = Vector.empty
f.foreach(_.apply(in))
}
}
}
}