Skip to content

Commit

Permalink
lib and client both compile
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Kane committed Jun 1, 2011
1 parent 3227a0c commit 4e132b8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 27 deletions.
44 changes: 20 additions & 24 deletions client/example_client.go
Expand Up @@ -6,7 +6,6 @@ import (
"osc"
"flag"
"fmt"
"unsafe"
)

var testdata string = "ABCDE"
Expand All @@ -28,35 +27,32 @@ func main() {
fmt.Printf("OSC error %d: %s\n", t.Errno(), t.Errstr())
}
} else {
m := make(osc.Message, 0)
m = append(m, 0.12345678)
C.lo_message_add_float(m, _Ctype_float(23.0))
if C.lo_send_message(t, C.CString("/foo/bar"), m) == -1 {
fmt.Printf("OSC error %d: %s\n", C.lo_address_errno(t), C.GoString(C.lo_address_errstr(t)))
m := new(osc.Message)
*m = make(osc.Message, 0)
m = m.Add(0.12345678)
m = m.Add(23.0)
if m.Send(t, "/foo/bar") == -1 {
fmt.Printf("OSC error %d: %s\n", t.Errno(), t.Errstr())
}
C.lo_message_free(m)

m = C.lo_message_new()
*m = make(osc.Message, 0)
/* send a message to /a/b/c/d with a mixtrure of float and string
* arguments */
C.lo_message_add_string(m, C.CString("one"))
C.lo_message_add_float(m, _Ctype_float(0.12345678))
C.lo_message_add_string(m, C.CString("three"))
C.lo_message_add_float(m, _Ctype_float(0.00000023001))
C.lo_message_add_float(m, _Ctype_float(1.0))
C.lo_send_message(t, C.CString("/a/b/c/d"), m)
C.lo_message_free(m)

m = C.lo_message_new()
m = m.Add("one")
m = m.Add(0.12345678)
m = m.Add("three")
m = m.Add(0.00000023001)
m = m.Add(1.0)
m.Send(t, "/a/b/c/d")

*m = make(osc.Message, 0)
/* send a 'blob' object to /a/b/c/d */
C.lo_message_add_blob(m, btest)
C.lo_send_message(t, C.CString("/a/b/c/d"), m)
C.lo_message_free(m)
m = m.Add(btest)
m.Send(t, "/a/b/c/d")

/* send a jamin scene change instruction with a 32bit integer argument */
m = C.lo_message_new()
C.lo_message_add_int32(m, _Ctypedef_int32_t(2))
C.lo_send_message(t, C.CString("/jamin/scene"), m)
C.lo_message_free(m)
*m = make(osc.Message, 0)
m = m.Add(2)
m.Send(t, "/jamin/scene")
}
}
30 changes: 27 additions & 3 deletions lib/osc.go
Expand Up @@ -51,10 +51,21 @@ func (this *InfinitumType) GetValue() interface{} {
type goTypeWrapper struct {
Arg
value interface{}
vtype OscType
}

func (this *goTypeWrapper) GetType() (o OscType) {
switch i := this.value.(type) {
func (this *goTypeWrapper) GetType() OscType {
return this.vtype
}

func (this *goTypeWrapper) GetValue() (interface{}) {
return this.value
}

func newWrapper(in interface{}) (out *goTypeWrapper) {
out = new(goTypeWrapper)
var o OscType
switch i := in.(type) {
case int32:
o = Int32
case float32:
Expand All @@ -75,15 +86,19 @@ func (this *goTypeWrapper) GetType() (o OscType) {
case MidiMsg:
o = MidiMsgCode
case bool:
if i, _ := this.value.(bool); i {
if ii, _ := in.(bool); ii {
o = True
} else {
o = False
}
case nil:
o = Nil
// no way to detect infinitum
default:
return nil
}
out.value = in
out.vtype = o
return
}

Expand Down Expand Up @@ -196,6 +211,15 @@ type Blob []byte
/* why use the message type before it's time to send it? */
type Message []Arg

func (this *Message) Add(e interface{}) (out *Message) {
ee := newWrapper(e)
if ee != nil {
m := append(*this, ee)
return &m
}
return this
}

func (this *Message) Send(targ *Address, path string) (ret int) {
ret = this.SendTimestamped(targ, Now, path)
return
Expand Down

0 comments on commit 4e132b8

Please sign in to comment.