Add fft, 2d_fft and sinwave to examples.
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / architecture / osclib / oscpack / osc / OscPrintReceivedElements.cpp
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 "OscPrintReceivedElements.h"
31
32 #include <iostream>
33 #include <iomanip>
34 #include <ctime>
35 #include <string.h>
36
37
38 namespace osc{
39
40
41 std::ostream& operator<<( std::ostream & os,
42 const ReceivedMessageArgument& arg )
43 {
44 switch( arg.TypeTag() ){
45 case TRUE_TYPE_TAG:
46 os << "bool:true";
47 break;
48
49 case FALSE_TYPE_TAG:
50 os << "bool:false";
51 break;
52
53 case NIL_TYPE_TAG:
54 os << "(Nil)";
55 break;
56
57 case INFINITUM_TYPE_TAG:
58 os << "(Infinitum)";
59 break;
60
61 case INT32_TYPE_TAG:
62 os << "int32:" << arg.AsInt32Unchecked();
63 break;
64
65 case FLOAT_TYPE_TAG:
66 os << "float32:" << arg.AsFloatUnchecked();
67 break;
68
69 case CHAR_TYPE_TAG:
70 {
71 char s[2] = {0};
72 s[0] = arg.AsCharUnchecked();
73 os << "char:'" << s << "'";
74 }
75 break;
76
77 case RGBA_COLOR_TYPE_TAG:
78 {
79 uint32 color = arg.AsRgbaColorUnchecked();
80
81 os << "RGBA:0x"
82 << std::hex << std::setfill('0')
83 << std::setw(2) << (int)((color>>24) & 0xFF)
84 << std::setw(2) << (int)((color>>16) & 0xFF)
85 << std::setw(2) << (int)((color>>8) & 0xFF)
86 << std::setw(2) << (int)(color & 0xFF)
87 << std::setfill(' ');
88 os.unsetf(std::ios::basefield);
89 }
90 break;
91
92 case MIDI_MESSAGE_TYPE_TAG:
93 {
94 uint32 m = arg.AsMidiMessageUnchecked();
95 os << "midi (port, status, data1, data2):<<"
96 << std::hex << std::setfill('0')
97 << "0x" << std::setw(2) << (int)((m>>24) & 0xFF)
98 << " 0x" << std::setw(2) << (int)((m>>16) & 0xFF)
99 << " 0x" << std::setw(2) << (int)((m>>8) & 0xFF)
100 << " 0x" << std::setw(2) << (int)(m & 0xFF)
101 << std::setfill(' ') << ">>";
102 os.unsetf(std::ios::basefield);
103 }
104 break;
105
106 case INT64_TYPE_TAG:
107 os << "int64:" << arg.AsInt64Unchecked();
108 break;
109
110 case TIME_TAG_TYPE_TAG:
111 {
112 os << "OSC-timetag:" << arg.AsTimeTagUnchecked();
113
114 std::time_t t =
115 (unsigned long)( arg.AsTimeTagUnchecked() >> 32 );
116
117 // strip trailing newline from string returned by ctime
118 const char *timeString = std::ctime( &t );
119 size_t len = strlen( timeString );
120 char *s = new char[ len + 1 ];
121 strcpy( s, timeString );
122 if( len )
123 s[ len - 1 ] = '\0';
124
125 os << " " << s;
126 }
127 break;
128
129 case DOUBLE_TYPE_TAG:
130 os << "double:" << arg.AsDoubleUnchecked();
131 break;
132
133 case STRING_TYPE_TAG:
134 os << "OSC-string:`" << arg.AsStringUnchecked() << "'";
135 break;
136
137 case SYMBOL_TYPE_TAG:
138 os << "OSC-string (symbol):`" << arg.AsSymbolUnchecked() << "'";
139 break;
140
141 case BLOB_TYPE_TAG:
142 {
143 unsigned long size;
144 const void *data;
145 arg.AsBlobUnchecked( data, size );
146 os << "OSC-blob:<<" << std::hex << std::setfill('0');
147 unsigned char *p = (unsigned char*)data;
148 for( unsigned long i = 0; i < size; ++i ){
149 os << "0x" << std::setw(2) << int(p[i]);
150 if( i != size-1 )
151 os << ' ';
152 }
153 os.unsetf(std::ios::basefield);
154 os << ">>" << std::setfill(' ');
155 }
156 break;
157
158 default:
159 os << "unknown";
160 }
161
162 return os;
163 }
164
165
166 std::ostream& operator<<( std::ostream & os, const ReceivedMessage& m )
167 {
168
169 os << "[" << m.AddressPattern();
170 bool first = true;
171
172 for( ReceivedMessage::const_iterator i = m.ArgumentsBegin();
173 i != m.ArgumentsEnd(); ++i ){
174 if( first ){
175 os << " ";
176 first = false;
177 }else{
178 os << ", ";
179 }
180
181 os << *i;
182 }
183
184 os << "]";
185
186 return os;
187 }
188
189
190 std::ostream& operator<<( std::ostream & os, const ReceivedBundle& b )
191 {
192 static int indent = 0;
193
194 for( int j=0; j < indent; ++j )
195 os << " ";
196 os << "{ ( ";
197 if( b.TimeTag() == 1 )
198 os << "immediate";
199 else
200 os << b.TimeTag();
201 os << " )\n";
202
203 ++indent;
204
205 for( ReceivedBundle::const_iterator i = b.ElementsBegin();
206 i != b.ElementsEnd(); ++i ){
207 if( i->IsBundle() ){
208 ReceivedBundle b(*i);
209 os << b << "\n";
210 }else{
211 ReceivedMessage m(*i);
212 for( int j=0; j < indent; ++j )
213 os << " ";
214 os << m << "\n";
215 }
216 }
217
218 --indent;
219
220 for( int j=0; j < indent; ++j )
221 os << " ";
222 os << "}";
223
224 return os;
225 }
226
227
228 std::ostream& operator<<( std::ostream & os, const ReceivedPacket& p )
229 {
230 if( p.IsBundle() ){
231 ReceivedBundle b(p);
232 os << b << "\n";
233 }else{
234 ReceivedMessage m(p);
235 os << m << "\n";
236 }
237
238 return os;
239 }
240
241 } // namespace osc