Exemple #1
0
func (this Message) SendTimestamped(targ *Address, time Timetag, path string) (ret int) {
	// build a new lo_message
	//    fmt.Printf("send timestamped %v %v\n", time, this)
	m, ret := this.build_lo_message()
	if m == nil {
		//        fmt.Printf("m nil ret %d\n", ret)
		return
	}
	if ret < 0 {
		C.lo_message_free(m)
		//        fmt.Printf("ret negative %d\n", ret)
		return
	}
	defer C.lo_message_free(m)
	s := C.CString(path)
	defer C.free(unsafe.Pointer(s))
	ret = int(C.lo_send_message(targ.lo_address, s, m))
	//    fmt.Printf("ret %d\n", ret)
	return
}
Exemple #2
0
func (this Message) build_lo_message() (m C.lo_message, ret int) {
	m = C.lo_message_new()
	if m == nil {
		ret = -1
		return
	}
	for _, arg := range this {
		//        fmt.Printf("%d %s %v\n", n, arg.GetType(), arg.GetValue())
		switch arg.GetType() {
		case Int32:
			ret = int(C.lo_message_add_int32(m, C.int32_t(arg.GetValue().(Int32Type))))
		case Float:
			ret = int(C.lo_message_add_float(m, C.float(arg.GetValue().(FloatType))))
		case BlobCode:
			a, i := arg.GetValue().(Blob)
			if !i {
				ret = -2
				break
			}

			b := C.lo_blob_new(C.int32_t(len(a)), unsafe.Pointer(&(a[0])))
			if b == nil {
				ret = -3
				break
			}
			defer C.lo_blob_free(C.lo_blob(b))
			ret = int(C.lo_message_add_blob(m, b))
		case Int64:
			ret = int(C.lo_message_add_int64(m, C.int64_t(arg.GetValue().(Int64Type))))
		case TimetagCode:
			ret = int(C.lo_message_add_timetag(m, C.lo_timetag{arg.GetValue().(Timetag).Sec, arg.GetValue().(Timetag).Frac}))
		case Double:
			ret = int(C.lo_message_add_double(m, C.double(arg.GetValue().(DoubleType))))
		case Symbol:
			s := C.CString(string(arg.GetValue().(SymbolType)))
			if s == nil {
				ret = -4
				break
			}
			defer C.free(unsafe.Pointer(s))
			ret = int(C.lo_message_add_symbol(m, s))
		case String:
			s := C.CString(string(arg.GetValue().(StringType)))
			if s == nil {
				ret = -4
				break
			}
			defer C.free(unsafe.Pointer(s))
			ret = int(C.lo_message_add_string(m, s))
		case Char:
			ret = int(C.lo_message_add_char(m, arg.GetValue().(C.char)))
		case MidiMsgCode:
			mm := arg.GetValue().(MidiMsg)
			ret = int(C.lo_message_add_midi(m, (*C.uint8_t)(unsafe.Pointer(&mm))))
		case True:
			ret = int(C.lo_message_add_true(m))
		case False:
			ret = int(C.lo_message_add_false(m))
		case Nil:
			ret = int(C.lo_message_add_nil(m))
		case Infinitum:
			ret = int(C.lo_message_add_infinitum(m))
		default:
			ret = -5
		}
		if ret < 0 {
			C.lo_message_free(m)
			m = nil
			return
		}
	}
	return
}