Mercurial > hg > aimc
comparison external/oscpack/tests/OscSendTests.cpp @ 509:0284d2152e17
Add support for outputting featutes using OSC (for use with the Wekinator, etc).
author | tomwalters@google.com |
---|---|
date | Fri, 22 Jun 2012 12:22:08 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
508:d609725e568a | 509:0284d2152e17 |
---|---|
1 /* | |
2 oscpack -- Open Sound Control packet manipulation library | |
3 http://www.audiomulch.com/~rossb/oscpack | |
4 | |
5 Copyright (c) 2004-2005 Ross Bencina <rossb@audiomulch.com> | |
6 | |
7 Permission is hereby granted, free of charge, to any person obtaining | |
8 a copy of this software and associated documentation files | |
9 (the "Software"), to deal in the Software without restriction, | |
10 including without limitation the rights to use, copy, modify, merge, | |
11 publish, distribute, sublicense, and/or sell copies of the Software, | |
12 and to permit persons to whom the Software is furnished to do so, | |
13 subject to the following conditions: | |
14 | |
15 The above copyright notice and this permission notice shall be | |
16 included in all copies or substantial portions of the Software. | |
17 | |
18 Any person wishing to distribute modifications to the Software is | |
19 requested to send the modifications to the original developer so that | |
20 they can be incorporated into the canonical version. | |
21 | |
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
25 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR | |
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |
27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
29 */ | |
30 #include "OscSendTests.h" | |
31 | |
32 #include <iostream> | |
33 #include <string.h> | |
34 | |
35 #include "osc/OscOutboundPacketStream.h" | |
36 | |
37 #include "ip/UdpSocket.h" | |
38 #include "ip/IpEndpointName.h" | |
39 | |
40 #define IP_MTU_SIZE 1536 | |
41 | |
42 namespace osc{ | |
43 | |
44 void RunSendTests( const IpEndpointName& host ) | |
45 { | |
46 char buffer[IP_MTU_SIZE]; | |
47 osc::OutboundPacketStream p( buffer, IP_MTU_SIZE ); | |
48 UdpTransmitSocket socket( host ); | |
49 | |
50 p.Clear(); | |
51 p << osc::BeginMessage( "/test1" ) | |
52 << true << 23 << (float)3.1415 << "hello" << osc::EndMessage; | |
53 socket.Send( p.Data(), p.Size() ); | |
54 | |
55 // test1 message with too few arguments | |
56 p.Clear(); | |
57 p << osc::BeginMessage( "/test1" ) | |
58 << true << osc::EndMessage; | |
59 socket.Send( p.Data(), p.Size() ); | |
60 | |
61 // test1 message with too many arguments | |
62 p.Clear(); | |
63 p << osc::BeginMessage( "/test1" ) | |
64 << true << 23 << (float)3.1415 << "hello" << 42 << osc::EndMessage; | |
65 socket.Send( p.Data(), p.Size() ); | |
66 | |
67 // test1 message with wrong argument type | |
68 p.Clear(); | |
69 p << osc::BeginMessage( "/test1" ) | |
70 << true << 1.0 << (float)3.1415 << "hello" << osc::EndMessage; | |
71 socket.Send( p.Data(), p.Size() ); | |
72 | |
73 p.Clear(); | |
74 p << osc::BeginMessage( "/test2" ) | |
75 << true << 23 << (float)3.1415 << "hello" << osc::EndMessage; | |
76 socket.Send( p.Data(), p.Size() ); | |
77 | |
78 // send four /test3 messages, each with a different type of argument | |
79 p.Clear(); | |
80 p << osc::BeginMessage( "/test3" ) | |
81 << true << osc::EndMessage; | |
82 socket.Send( p.Data(), p.Size() ); | |
83 | |
84 p.Clear(); | |
85 p << osc::BeginMessage( "/test3" ) | |
86 << 23 << osc::EndMessage; | |
87 socket.Send( p.Data(), p.Size() ); | |
88 | |
89 p.Clear(); | |
90 p << osc::BeginMessage( "/test3" ) | |
91 << (float)3.1415 << osc::EndMessage; | |
92 socket.Send( p.Data(), p.Size() ); | |
93 | |
94 p.Clear(); | |
95 p << osc::BeginMessage( "/test3" ) | |
96 << "hello" << osc::EndMessage; | |
97 socket.Send( p.Data(), p.Size() ); | |
98 | |
99 | |
100 // send a bundle | |
101 p.Clear(); | |
102 p << osc::BeginBundle(); | |
103 | |
104 p << osc::BeginMessage( "/no_arguments" ) | |
105 << osc::EndMessage; | |
106 | |
107 p << osc::BeginMessage( "/a_bool" ) | |
108 << true << osc::EndMessage; | |
109 | |
110 p << osc::BeginMessage( "/a_bool" ) | |
111 << false << osc::EndMessage; | |
112 | |
113 p << osc::BeginMessage( "/a_bool" ) | |
114 << (bool)1234 << osc::EndMessage; | |
115 | |
116 p << osc::BeginMessage( "/nil" ) | |
117 << osc::Nil << osc::EndMessage; | |
118 | |
119 p << osc::BeginMessage( "/inf" ) | |
120 << osc::Infinitum << osc::EndMessage; | |
121 | |
122 p << osc::BeginMessage( "/an_int" ) << 1234 << osc::EndMessage; | |
123 | |
124 p << osc::BeginMessage( "/a_float" ) | |
125 << 3.1415926f << osc::EndMessage; | |
126 | |
127 p << osc::BeginMessage( "/a_char" ) | |
128 << 'c' << osc::EndMessage; | |
129 | |
130 p << osc::BeginMessage( "/an_rgba_color" ) | |
131 << osc::RgbaColor(0x22334455) << osc::EndMessage; | |
132 | |
133 p << osc::BeginMessage( "/a_midi_message" ) | |
134 << MidiMessage(0x7F) << osc::EndMessage; | |
135 | |
136 p << osc::BeginMessage( "/an_int64" ) | |
137 << (int64)(0xFFFFFFF) << osc::EndMessage; | |
138 | |
139 p << osc::BeginMessage( "/a_time_tag" ) | |
140 << osc::TimeTag(0xFFFFFFFUL) << osc::EndMessage; | |
141 | |
142 p << osc::BeginMessage( "/a_double" ) | |
143 << (double)3.1415926 << osc::EndMessage; | |
144 | |
145 p << osc::BeginMessage( "/a_string" ) | |
146 << "hello world" << osc::EndMessage; | |
147 | |
148 p << osc::BeginMessage( "/a_symbol" ) | |
149 << osc::Symbol("foobar") << osc::EndMessage; | |
150 | |
151 // blob | |
152 { | |
153 char blobData[] = "abcd"; | |
154 | |
155 p << osc::BeginMessage( "/a_blob" ) | |
156 << osc::Blob( blobData, 4 ) | |
157 << osc::EndMessage; | |
158 } | |
159 | |
160 p << osc::EndBundle; | |
161 socket.Send( p.Data(), p.Size() ); | |
162 | |
163 | |
164 | |
165 // nested bundles, and multiple messages in bundles... | |
166 p.Clear(); | |
167 p << osc::BeginBundle( 1234 ) | |
168 << osc::BeginMessage( "/an_int" ) << 1 << osc::EndMessage | |
169 << osc::BeginMessage( "/an_int" ) << 2 << osc::EndMessage | |
170 << osc::BeginMessage( "/an_int" ) << 3 << osc::EndMessage | |
171 << osc::BeginMessage( "/an_int" ) << 4 << osc::EndMessage | |
172 << osc::BeginBundle( 12345 ) | |
173 << osc::BeginMessage( "/an_int" ) << 5 << osc::EndMessage | |
174 << osc::BeginMessage( "/an_int" ) << 6 << osc::EndMessage | |
175 << osc::EndBundle | |
176 << osc::EndBundle; | |
177 | |
178 socket.Send( p.Data(), p.Size() ); | |
179 } | |
180 | |
181 } // namespace osc | |
182 | |
183 #ifndef NO_OSC_TEST_MAIN | |
184 | |
185 int main(int argc, char* argv[]) | |
186 { | |
187 if( argc >= 2 && strcmp( argv[1], "-h" ) == 0 ){ | |
188 std::cout << "usage: OscSendTests [hostname [port]]\n"; | |
189 return 0; | |
190 } | |
191 | |
192 char *hostName = "localhost"; | |
193 int port = 7000; | |
194 | |
195 if( argc >= 2 ) | |
196 hostName = argv[1]; | |
197 | |
198 if( argc >= 3 ) | |
199 port = atoi( argv[2] ); | |
200 | |
201 | |
202 IpEndpointName host( hostName, port ); | |
203 | |
204 char hostIpAddress[ IpEndpointName::ADDRESS_STRING_LENGTH ]; | |
205 host.AddressAsString( hostIpAddress ); | |
206 | |
207 std::cout << "sending test messages to " << hostName | |
208 << " (" << hostIpAddress << ") on port " << port << "...\n"; | |
209 | |
210 osc::RunSendTests( host ); | |
211 } | |
212 | |
213 #endif /* NO_OSC_TEST_MAIN */ |