changed Test
[ModSynth.git] / com / wha / modsynth / JackIO.scala
blob842733afa5cd599cfed3f182314754eff1df3995
1 package com.wha.modsynth;
2 import scala.actors._
3 import scala.actors.Actor._
4 import scala.concurrent.SyncVar;
6 import de.gulden.framework.jjack._;
8 class JackIO extends Module {
9 var inBuf = new SyncVar[List[List[float]]]
10 var outBuf = new SyncVar[List[List[float]]]
12 val name = "JackIn"
14 class JackProcessor(ji: Module) extends JJackAudioProcessor with Actor {
15 override def process(e: JJackAudioEvent) = {
16 log("in process")
17 val channels = e.countChannels
18 outBuf.unset
19 inBuf.set(for (i <- List.range(0, channels))
20 yield {
21 val in = e.getInput(i)
22 for (j <- List.range(0, in.capacity)) yield in.get(j)})
23 ji ! new Audio(inBuf.get)
24 doOut(e, outBuf.get)
27 def act() {
32 val jackProcessor = new JackProcessor(this)
34 def doOut(e: JJackAudioEvent, b: List[List[float]]) : Unit = {
35 log("in doOut")
36 val channels = e.countChannels
37 List.range(0, channels).foreach(i => {
38 log("output channel: " + i)
39 val out = e.getOutput(i)
40 b(i).foreach(sample => out.put(sample))})
43 override def doAudio(buf: List[List[float]]) = {
44 log("in doAudio " + inBuf.isSet)
45 if (inBuf.isSet) {
46 val b = transformAudio(buf)
47 inBuf.unset
48 outputs foreach (x => {log("sending audio to " + x.name); x ! new Audio(b)})
50 else {
51 outBuf.set(buf)