More tutorial bits and playing with OSC

This commit is contained in:
Dan Buch 2015-10-23 13:35:43 -04:00
parent c8eff8a629
commit 8500a540ed
3 changed files with 91 additions and 2 deletions

43
sclang-play/oscfun.go Normal file
View File

@ -0,0 +1,43 @@
package main
import (
"fmt"
"net"
"github.com/hypebeast/go-osc/osc"
)
func main() {
// client := osc.NewClient("localhost", 9949)
msg := osc.NewMessage("/osc/address")
msg.Append(int32(111))
msg.Append(true)
msg.Append("hello")
fmt.Printf("Sending: %#v\n", msg)
// err := client.Send(msg)
err := sendTCP(msg)
if err != nil {
fmt.Printf("ERROR: %#v\n", err)
}
}
func sendTCP(packet osc.Packet) error {
conn, err := net.Dial("tcp", "127.0.0.1:9949")
if err != nil {
return err
}
defer conn.Close()
data, err := packet.ToByteArray()
if err != nil {
return err
}
_, err = conn.Write(data)
if err != nil {
return err
}
return nil
}

40
sclang-play/oscfun.sc Normal file
View File

@ -0,0 +1,40 @@
(
n = NetAddr("127.0.0.1", 8765);
n.sendMsg("/good/news", "haaay");
)
(
f = { |msg, time, addr|
if((addr.port == 8765) && (msg[0] != '/status.reply'), {
"time: % sender: %\nmessage: %\n".postf(time, addr, msg);
});
};
thisProcess.addOSCRecvFunc(f);
)
(
thisProcess.replaceOSCRecvFunc(f, f);
)
(
thisProcess.removeOSCRecvFunc(f);
)
(
thisProcess.openUDPPort(1121);
)
(
thisProcess.stop;
)
(
thisProcess.openPorts;
)
(
// OSCFunc.trace(false);
s.quit;
s.boot;
// OSCFunc.trace(true);
)

View File

@ -38,6 +38,12 @@
}.play; }.play;
) )
(
{
Pan2.ar(SinOsc.ar(440, 0, 0.2), SinOsc.kr(0.5));
}.play;
)
( (
{ {
Pan2.ar(PinkNoise.ar(0.2), -0.3); Pan2.ar(PinkNoise.ar(0.2), -0.3);
@ -221,7 +227,7 @@
1.wait; 1.wait;
z = Synth("tutorial-args", ["freq", 880, "out", 1]); z = Synth("tutorial-args", ["freq", 880, "out", 1]);
1.wait; 1.wait;
x.free; y.free; z.free; //x.free; y.free; z.free;
}).play; }).play;
) )
@ -240,6 +246,6 @@
1.wait; 1.wait;
x.set(\freq, 880, \out, 1); x.set(\freq, 880, \out, 1);
1.wait; 1.wait;
x.free; //x.free;
}).play; }).play;
) )