72b42f93f4923ff5c96955626d2eef972b2fa4fc
2 oscpack -- Open Sound Control packet manipulation library
3 http://www.audiomulch.com/~rossb/oscpack
5 Copyright (c) 2004-2005 Ross Bencina <rossb@audiomulch.com>
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:
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
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.
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.
30 #include "OscPrintReceivedElements.h"
41 std::ostream
& operator<<( std::ostream
& os
,
42 const ReceivedMessageArgument
& arg
)
44 switch( arg
.TypeTag() ){
57 case INFINITUM_TYPE_TAG
:
62 os
<< "int32:" << arg
.AsInt32Unchecked();
66 os
<< "float32:" << arg
.AsFloatUnchecked();
72 s
[0] = arg
.AsCharUnchecked();
73 os
<< "char:'" << s
<< "'";
77 case RGBA_COLOR_TYPE_TAG
:
79 uint32 color
= arg
.AsRgbaColorUnchecked();
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)
88 os
.unsetf(std::ios::basefield
);
92 case MIDI_MESSAGE_TYPE_TAG
:
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
);
107 os
<< "int64:" << arg
.AsInt64Unchecked();
110 case TIME_TAG_TYPE_TAG
:
112 os
<< "OSC-timetag:" << arg
.AsTimeTagUnchecked();
115 (unsigned long)( arg
.AsTimeTagUnchecked() >> 32 );
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
);
129 case DOUBLE_TYPE_TAG
:
130 os
<< "double:" << arg
.AsDoubleUnchecked();
133 case STRING_TYPE_TAG
:
134 os
<< "OSC-string:`" << arg
.AsStringUnchecked() << "'";
137 case SYMBOL_TYPE_TAG
:
138 os
<< "OSC-string (symbol):`" << arg
.AsSymbolUnchecked() << "'";
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
]);
153 os
.unsetf(std::ios::basefield
);
154 os
<< ">>" << std::setfill(' ');
166 std::ostream
& operator<<( std::ostream
& os
, const ReceivedMessage
& m
)
169 os
<< "[" << m
.AddressPattern();
172 for( ReceivedMessage::const_iterator i
= m
.ArgumentsBegin();
173 i
!= m
.ArgumentsEnd(); ++i
){
190 std::ostream
& operator<<( std::ostream
& os
, const ReceivedBundle
& b
)
192 static int indent
= 0;
194 for( int j
=0; j
< indent
; ++j
)
197 if( b
.TimeTag() == 1 )
205 for( ReceivedBundle::const_iterator i
= b
.ElementsBegin();
206 i
!= b
.ElementsEnd(); ++i
){
208 ReceivedBundle
b(*i
);
211 ReceivedMessage
m(*i
);
212 for( int j
=0; j
< indent
; ++j
)
220 for( int j
=0; j
< indent
; ++j
)
228 std::ostream
& operator<<( std::ostream
& os
, const ReceivedPacket
& p
)
234 ReceivedMessage
m(p
);