1 #include <calf/osctl.h>
4 #include <sys/socket.h>
12 std::string
osc_data::to_string() const
17 case osc_i32
: ss
<< i32val
; break;
18 case osc_i64
: ss
<< (int64_t)tsval
; break;
19 case osc_f32
: ss
<< f32val
; break;
20 case osc_ts
: ss
<< tsval
; break;
21 case osc_string
: return strval
;
22 case osc_string_alt
: return strval
;
23 case osc_blob
: return strval
;
24 case osc_true
: return "TRUE";
25 case osc_false
: return "FALSE";
26 case osc_nil
: return "NIL";
27 case osc_inf
: return "INF";
28 case osc_start_array
: return "[";
29 case osc_end_array
: return "]";
37 const char *osctl::osc_type_name(osc_type type
)
41 case osc_i32
: return "i32";
42 case osc_i64
: return "i64";
43 case osc_f32
: return "f32";
44 case osc_ts
: return "ts";
45 case osc_string
: return "str";
46 case osc_string_alt
: return "stralt";
47 case osc_blob
: return "blob";
48 case osc_char
: return "char";
49 case osc_rgba
: return "rgba";
50 case osc_midi
: return "midi";
51 case osc_true
: return "TRUE";
52 case osc_false
: return "FALSE";
53 case osc_nil
: return "NIL";
54 case osc_inf
: return "INF";
55 case osc_start_array
: return "[";
56 case osc_end_array
: return "]";
63 void osc_stream::read(osc_type type
, osc_data
&od
)
70 copy_from(&od
.i32val
, 4);
71 od
.i32val
= ntohl(od
.i32val
);
74 copy_from(&od
.tsval
, 8);
76 uint32_t a
= ntohl(od
.tsval
), b
= ntohl(od
.tsval
>> 32);
77 od
.tsval
= (((uint64_t)a
) << 32) | b
;
83 int len
= 0, maxlen
= 0;
84 maxlen
= buffer
.length() - pos
;
85 while(len
< maxlen
&& buffer
[pos
+ len
])
87 od
.strval
= buffer
.substr(pos
, len
);
88 pos
+= (len
+ 4) &~ 3;
92 copy_from(&od
.i32val
, 4);
93 od
.i32val
= ntohl(od
.i32val
);
94 od
.strval
= buffer
.substr(pos
, od
.i32val
);
95 pos
+= (od
.i32val
+ 3) &~ 3;
107 void osc_stream::write(const osc_data
&od
)
115 val
= ntohl(od
.i32val
);
116 buffer
+= string((const char *)&val
, 4);
120 uint64_t ts
= od
.tsval
;
122 uint32_t a
= ntohl(od
.tsval
), b
= ntohl(od
.tsval
>> 32);
123 ts
= (((uint64_t)a
) << 32) | b
;
125 buffer
+= string((const char *)&ts
, 8);
133 buffer
+= string((const char *)&val
, 4 - (od
.strval
.length() & 3));
138 val
= ntohl(od
.strval
.length());
139 buffer
+= string((const char *)&val
, 4);
142 buffer
+= string((const char *)&val
, 4 - (od
.strval
.length() & 3));
154 void osc_stream::read(const char *tags
, vector
<osc_data
> &data
)
158 data
.push_back(osc_data());
159 read((osc_type
)*tags
++, *data
.rbegin());
163 void osc_stream::write(const vector
<osc_data
> &data
)
165 unsigned int pos
= 0;
167 while(pos
< data
.size())
171 void osc_message_dump::receive_osc_message(std::string address
, std::string type_tag
, const std::vector
<osc_data
> &args
)
173 printf("address: %s, type tag: %s\n", address
.c_str(), type_tag
.c_str());
174 for (unsigned int i
= 0; i
< args
.size(); i
++)
176 printf("argument %d is %s\n", i
, args
[i
].to_string().c_str());