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 #undef _CRT_SECURE_NO_WARNINGS
31 #define _CRT_SECURE_NO_WARNINGS
33 #include "OscPrintReceivedElements.h"
44 std::ostream& operator<<( std::ostream & os,
45 const ReceivedMessageArgument& arg )
47 switch( arg.TypeTag() ){
60 case INFINITUM_TYPE_TAG:
65 os << "int32:" << arg.AsInt32Unchecked();
69 os << "float32:" << arg.AsFloatUnchecked();
75 s[0] = arg.AsCharUnchecked();
76 os << "char:'" << s << "'";
80 case RGBA_COLOR_TYPE_TAG:
82 uint32 color = arg.AsRgbaColorUnchecked();
85 << std::hex << std::setfill('0')
86 << std::setw(2) << (int)((color>>24) & 0xFF)
87 << std::setw(2) << (int)((color>>16) & 0xFF)
88 << std::setw(2) << (int)((color>>8) & 0xFF)
89 << std::setw(2) << (int)(color & 0xFF)
91 os.unsetf(std::ios::basefield);
95 case MIDI_MESSAGE_TYPE_TAG:
97 uint32 m = arg.AsMidiMessageUnchecked();
98 os << "midi (port, status, data1, data2):<<"
99 << std::hex << std::setfill('0')
100 << "0x" << std::setw(2) << (int)((m>>24) & 0xFF)
101 << " 0x" << std::setw(2) << (int)((m>>16) & 0xFF)
102 << " 0x" << std::setw(2) << (int)((m>>8) & 0xFF)
103 << " 0x" << std::setw(2) << (int)(m & 0xFF)
104 << std::setfill(' ') << ">>";
105 os.unsetf(std::ios::basefield);
110 os << "int64:" << arg.AsInt64Unchecked();
113 case TIME_TAG_TYPE_TAG:
115 os << "OSC-timetag:" << arg.AsTimeTagUnchecked();
118 (unsigned long)( arg.AsTimeTagUnchecked() >> 32 );
120 // strip trailing newline from string returned by ctime
121 const char *timeString = std::ctime( &t );
122 size_t len = strlen( timeString );
123 char *s = new char[ len + 1 ];
124 strcpy( s, timeString );
132 case DOUBLE_TYPE_TAG:
133 os << "double:" << arg.AsDoubleUnchecked();
136 case STRING_TYPE_TAG:
137 os << "OSC-string:`" << arg.AsStringUnchecked() << "'";
140 case SYMBOL_TYPE_TAG:
141 os << "OSC-string (symbol):`" << arg.AsSymbolUnchecked() << "'";
148 arg.AsBlobUnchecked( data, size );
149 os << "OSC-blob:<<" << std::hex << std::setfill('0');
150 unsigned char *p = (unsigned char*)data;
151 for( unsigned long i = 0; i < size; ++i ){
152 os << "0x" << std::setw(2) << int(p[i]);
156 os.unsetf(std::ios::basefield);
157 os << ">>" << std::setfill(' ');
169 std::ostream& operator<<( std::ostream & os, const ReceivedMessage& m )
172 if( m.AddressPatternIsUInt32() )
173 os << m.AddressPatternAsUInt32();
175 os << m.AddressPattern();
178 for( ReceivedMessage::const_iterator i = m.ArgumentsBegin();
179 i != m.ArgumentsEnd(); ++i ){
196 std::ostream& operator<<( std::ostream & os, const ReceivedBundle& b )
198 static int indent = 0;
200 for( int j=0; j < indent; ++j )
203 if( b.TimeTag() == 1 )
211 for( ReceivedBundle::const_iterator i = b.ElementsBegin();
212 i != b.ElementsEnd(); ++i ){
214 ReceivedBundle b(*i);
217 ReceivedMessage m(*i);
218 for( int j=0; j < indent; ++j )
226 for( int j=0; j < indent; ++j )
234 std::ostream& operator<<( std::ostream & os, const ReceivedPacket& p )
240 ReceivedMessage m(p);