Created
October 30, 2012 11:14
-
-
Save miguel-negrao/3979645 to your computer and use it in GitHub Desktop.
ScalaColliderZ example 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import de.sciss.synth._ | |
import ugen._ | |
import scalaz._ | |
import Scalaz._ | |
import concurrent._ | |
import org.friendlyvirus.mn.ScalaColliderZ._ | |
object Test1 { | |
def main(args: Array[String]) { | |
Server.test{ s=> | |
//Create two promises, one for loading a buffer and another for sending a SynthDef | |
val p1:Promise[Buffer] = BufferPromise.read(Server.default, "sounds/a11wlk01.wav") | |
val p2:Promise[SynthDef] = (SynthDef("play"){ Out.ar(0, PlayBuf.ar(1, "bufNum".kr(0) )) }).loadP(s) | |
//Combine the two promises using an Applicative Functor. The function supplied will only be executed once | |
// both promises are fulfilled. The function supplied takes a buffer and a Synthdef and returns a Synth, therefore | |
// x will be a Promise[Synth]. We can then continue to compute on the Synth as if it was already here by using | |
// map, flatMap, fold, etc | |
val x:Promise[Synth] = (p1 |@| p2){ (buffer, synthDef) => Synth.play("play",Seq("bufNum"->buffer.id)) } | |
x.map( x => println(x) ) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment