History

Merge remote-tracking branch 'origin/main' into qt6-main

Spencer Salazars committed 3 years ago

Commit 2fbfa982 parents 0506c4a d0ee61c263 files · +29036 −10344Browse files

Showing the changes to src/core/util_opsc.cpp (1 of 263 files). Show all

Unified · Split

src/core/util_opsc.cpp+254−275
@@ -44,7 +44,7 @@ · 43 unmodified lines
4444 using namespace std;
4545
4646
47−// FROM PLATFORM.H -UDP TRANSMITTER / RECEIVER
47+// FROM PLATFORM.H -UDP TRANSMITTER / RECEIVER
4848
4949 #if defined(__PLATFORM_WIN32__)
5050 // 2022 QTSIN added winsock2.h and wsw2tcpip.h
@@ -76,12 +76,12 @@ using namespace std; · 25 unmodified lines
7676 #endif
7777
7878
79−// squeeze the whole wad of OSC-Kit code in here.
79+// squeeze the whole wad of OSC-Kit code in here.
8080
8181 // OSC-pattern-match.cpp
8282
8383 /*
84−Copyright � 1998. The Regents of the University of California (Regents).
84+Copyright � 1998. The Regents of the University of California (Regents).
8585 All Rights Reserved.
8686
8787 Written by Matt Wright, The Center for New Music and Audio Technologies,
@@ -104,7 +104,7 @@ PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED · 16 unmodified lines
104104 HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
105105 MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
106106
107−The OpenSound Control WWW page is
107+The OpenSound Control WWW page is
108108 http://www.cnmat.berkeley.edu/OpenSoundControl
109109 */
110110
@@ -126,23 +126,23 @@ static bool MatchList( const char * pattern, const char * test ); · 15 unmodified lines
126126 bool PatternMatch( const char * pattern, const char * test )
127127 {
128128 theWholePattern = pattern;
129−
129+
130130 if( pattern == 0 || pattern[0] == 0 ) {
131131 return test[0] == 0;
132− }
133−
132+ }
133+
134134 if( test[0] == 0 ) {
135135 if(pattern[0] == '*')
136136 return PatternMatch (pattern+1,test);
137137 else
138138 return FALSE;
139139 }
140−
140+
141141 switch( pattern[0] )
142142 {
143143 case 0 : return test[0] == 0;
144144 case '?' : return PatternMatch (pattern + 1, test + 1);
145− case '*' :
145+ case '*' :
146146 if( PatternMatch (pattern+1, test) ) {
147147 return TRUE;
148148 } else {
@@ -156,7 +156,7 @@ bool PatternMatch( const char * pattern, const char * test ) · 7 unmodified lines
156156 return MatchBrackets (pattern,test);
157157 case '{' :
158158 return MatchList (pattern,test);
159− case '\\' :
159+ case '\\' :
160160 if(pattern[1] == 0) {
161161 return test[0] == 0;
162162 } else if(pattern[1] == test[0]) {
@@ -204,7 +204,7 @@ static bool MatchBrackets( const char * pattern, const char * test ) · 41 unmodified lines
204204 goto advance;
205205 }
206206 }
207−
207+
208208 if(p[0] == test[0]) {
209209 result = !negated;
210210 goto advance;
@@ -304,7 +304,7 @@ University of California, Berkeley. · 93 unmodified lines
304304 REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
305305 ENHANCEMENTS, OR MODIFICATIONS.
306306
307−The OpenSound Control WWW page is
307+The OpenSound Control WWW page is
308308 http://www.cnmat.berkeley.edu/OpenSoundControl
309309 */
310310
@@ -369,21 +369,21 @@ OSCTimeTag OSCTT_CurrentTime(void) { · 58 unmodified lines
369369 BSDgettimeofday(&tv, &tz);
370370
371371 /* First get the seconds right */
372− result = (unsigned) SECONDS_FROM_1900_to_1970 +
373− (unsigned) tv.tv_sec -
372+ result = (unsigned) SECONDS_FROM_1900_to_1970 +
373+ (unsigned) tv.tv_sec -
374374 (unsigned) 60 * tz.tz_minuteswest +
375375 (unsigned) (tz.tz_dsttime ? 3600 : 0);
376376
377377 #if 0
378378 /* No timezone, no DST version ... */
379− result = (unsigned) SECONDS_FROM_1900_to_1970 +
379+ result = (unsigned) SECONDS_FROM_1900_to_1970 +
380380 (unsigned) tv.tv_sec;
381381 #endif
382382
383383
384384 /* make seconds the high-order 32 bits */
385385 result = result << 32;
386−
386+
387387 /* Now get the fractional part. */
388388 usecOffset = (unsigned) tv.tv_usec * (unsigned) TWO_TO_THE_32_OVER_ONE_MILLION;
389389 /* printf("** %ld microsec is offset %x\n", tv.tv_usec, usecOffset); */
@@ -397,7 +397,7 @@ OSCTimeTag OSCTT_CurrentTime(void) { · 7 unmodified lines
397397 #else /* __sgi */
398398
399399 /* Instead of asking your operating system what time it is, it might be
400− clever to find out the current time at the instant your application
400+ clever to find out the current time at the instant your application
401401 starts audio processing, and then keep track of the number of samples
402402 output to know how much time has passed. */
403403
@@ -484,7 +484,7 @@ University of California, Berkeley. · 80 unmodified lines
484484 */
485485
486486
487−/*
487+/*
488488 Author: Matt Wright
489489 Version 2.2: Calls htonl in the right places 20000620
490490 Version 2.3: Gets typed messages right.
@@ -500,7 +500,7 @@ University of California, Berkeley. · 9 unmodified lines
500500 #define GET_ARGS 3 /* Getting arguments to a message. If we see a message
501501 name or a bundle open/close then the current message
502502 will end. */
503−#define DONE 4 /* All open bundles have been closed, so can't write
503+#define DONE 4 /* All open bundles have been closed, so can't write
504504 anything else */
505505
506506
@@ -521,7 +521,7 @@ void OSC_initBuffer(OSCbuf *buf, int size, char *byteArray) { · 14 unmodified lines
521521 OSC_resetBuffer(buf);
522522 }
523523
524−void OSC_resetBuffer(OSCbuf *buf) {
524+void OSC_resetBuffer(OSCbuf *buf) {
525525 buf->bufptr = buf->buffer;
526526 buf->state = EMPTY;
527527 buf->bundleDepth = 0;
@@ -632,7 +632,7 @@ int OSC_openBundle(OSCbuf *buf, OSCTimeTag tt) · 104 unmodified lines
632632 intp[1] = htonl(intp[1]);
633633
634634 #ifdef HAS8BYTEINT
635− { /* tt is a 64-bit int so we have to swap the two 32-bit words.
635+ { /* tt is a 64-bit int so we have to swap the two 32-bit words.
636636 (Otherwise tt is a struct of two 32-bit words, and even though
637637 each word was wrong-endian, they were in the right order
638638 in the struct.) */
@@ -696,7 +696,7 @@ int OSC_closeAllBundles(OSCbuf *buf) · 57 unmodified lines
696696 while (buf->bundleDepth > 0) {
697697 OSC_closeBundle(buf);
698698 }
699−
699+
700700 buf->typeStringPtr = 0;
701701 return 0;
702702 }
@@ -757,11 +757,11 @@ int OSC_writeAddressAndTypes(OSCbuf *buf, char *name, char *types) · 54 unmodified lines
757757
758758 paddedLength = OSC_effectiveStringLength(types);
759759
760− CheckOverflow(buf, paddedLength);
760+ CheckOverflow(buf, paddedLength);
761761
762762 buf->typeStringPtr = buf->bufptr + 1; /* skip comma */
763763 buf->bufptr += OSC_padString(buf->bufptr, types);
764−
764+
765765 buf->gettingFirstUntypedArg = 0;
766766
767767 return 0;
@@ -783,9 +783,9 @@ static int CheckTypeTag(OSCbuf *buf, char expectedType) · 15 unmodified lines
783783 printf("* Expected %c, string now %s\n", expectedType, buf->typeStringPtr);
784784 }
785785
786− return 9;
786+ return 9;
787787 }
788−
788+
789789 ++(buf->typeStringPtr);
790790 }
791791
@@ -863,7 +863,7 @@ int OSC_writeStringArg(OSCbuf *buf, char *arg) · 71 unmodified lines
863863 tag string. */
864864
865865 CheckOverflow(buf, len+4); /* Too conservative */
866− buf->bufptr +=
866+ buf->bufptr +=
867867 OSC_padStringWithAnExtraStupidComma(buf->bufptr, arg);
868868 } else {
869869 CheckOverflow(buf, len);
@@ -889,7 +889,7 @@ static int strlen(char *s) { · 19 unmodified lines
889889 int OSC_effectiveStringLength(char *string)
890890 {
891891 t_CKINT len = strlen(string) + 1; /* We need space for the null char. */
892−
892+
893893 /* Round up len to next multiple of STRING_ALIGN_PAD to account for alignment padding */
894894 if((len % STRING_ALIGN_PAD) != 0) {
895895 len += STRING_ALIGN_PAD - (len % STRING_ALIGN_PAD);
@@ -902,11 +902,11 @@ int OSC_effectiveStringLength(char *string) · 6 unmodified lines
902902 static int OSC_padString(char *dest, const char *str)
903903 {
904904 int i;
905−
905+
906906 for(i = 0; str[i] != '\0'; i++) {
907907 dest[i] = str[i];
908908 }
909−
909+
910910 return OSC_WritePadding(dest, i);
911911 }
912912
@@ -914,7 +914,7 @@ static int OSC_padString(char *dest, const char *str) · 1 unmodified line
914914 static int OSC_padStringWithAnExtraStupidComma(char *dest, const char *str)
915915 {
916916 int i;
917−
917+
918918 dest[0] = ',';
919919 for(i = 0; str[i] != '\0'; i++) {
920920 dest[i+1] = str[i];
@@ -922,7 +922,7 @@ static int OSC_padStringWithAnExtraStupidComma(char *dest, const char *str) · 1 unmodified line
922922
923923 return OSC_WritePadding(dest, i+1);
924924 }
925−
925+
926926
927927 static int OSC_WritePadding(char *dest, int i)
928928 {
@@ -948,7 +948,7 @@ static int OSC_WritePadding(char *dest, int i) · 19 unmodified lines
948948 #include "util_network.h"
949949 #include "util_thread.h"
950950
951−// FROM PLATFORM.H -UDP TRANSMITTER / RECEIVER
951+// FROM PLATFORM.H -UDP TRANSMITTER / RECEIVER
952952
953953 #if defined(__PLATFORM_WIN32__)
954954 #include <winsock.h>
@@ -975,27 +975,27 @@ enum udp_stat { UDP_NOINIT, UDP_UNBOUND, UDP_BOUND, UDP_READY, UDP_ERROR, UDP_NU · 20 unmodified lines
975975
976976 /* in the .h so that OSC can subclass it
977977
978−class UDP_Subscriber {
978+class UDP_Subscriber {
979979 virtual void onRecieve( char * mesg, int mesgLen ) = 0;
980980 virtual bool subscribe( int port );
981981 virtual bool unsubscribe();
982− virtual int& port(); //get/set the value of the subscriber's current port.
982+ virtual int& port(); //get/set the value of the subscriber's current port.
983983 }
984−
984+
985985 */
986986
987−class DefUDP_Subscriber : public UDP_Subscriber {
987+class DefUDP_Subscriber : public UDP_Subscriber {
988988 public:
989989 int _port;
990990 void onReceive ( char * mesg, int mesgLen ) {} // ignore
991991 int& port() { return _port; }
992992 };
993993
994−class UDP_Port_Listener {
994+class UDP_Port_Listener {
995995 private:
996996 UDP_Receiver* m_in;
997997 bool m_port;
998−
998+
999999 XThread* m_thread;
10001000 XMutex* m_mutex;
10011001
@@ -1015,9 +1015,9 @@ public: · 13 unmodified lines
10151015 int recv_mesg();
10161016 bool add ( UDP_Subscriber * );
10171017 bool drop ( UDP_Subscriber * );
1018− int nsubs();
1018+ int nsubs();
10191019
1020− bool listening;
1020+ bool listening;
10211021 };
10221022
10231023
@@ -1055,9 +1055,9 @@ public: · 31 unmodified lines
10551055 ~UDP_Receiver() { }
10561056 void init();
10571057 bool bind_to_port(int port);
1058− int recv_next(char *buffer, int size);
1058+ int recv_next(char *buffer, int size);
10591059 void close_sock();
1060− udp_stat status();
1060+ udp_stat status();
10611061 };
10621062
10631063
@@ -1069,17 +1069,17 @@ protected: · 5 unmodified lines
10691069 ck_socket _sock;
10701070 SOCKADDR_IN _host_addr;
10711071 udp_stat _status;
1072−
1072+
10731073 public:
10741074 UDP_Transmitter() {
1075− _status = UDP_NOINIT;
1075+ _status = UDP_NOINIT;
10761076 }
10771077 virtual ~UDP_Transmitter() {}
10781078 void init();
1079−
1079+
10801080 void set_host(char * hostaddress, int port);
10811081 int send(char *buffer, int size);
1082− udp_stat status(void) { return _status; }
1082+ udp_stat status(void) { return _status; }
10831083 void close_sock();
10841084 };
10851085
@@ -1092,8 +1092,8 @@ UDP_Port_Manager * UDP_Port_Manager::instance() · 6 unmodified lines
10921092 _inst = new UDP_Port_Manager();
10931093 assert( _inst );
10941094 }
1095−
1096− return _inst;
1095+
1096+ return _inst;
10971097 }
10981098
10991099 UDP_Port_Manager::UDP_Port_Manager() {
@@ -1121,26 +1121,26 @@ bool UDP_Port_Manager::unsubscribe( UDP_Subscriber * sub ) · 21 unmodified lines
11211121 if( sub->port() < 0 )
11221122 {
11231123 EM_log( CK_LOG_INFO, "error, subscriber's port < 0, return false" );
1124− return false;
1124+ return false;
11251125 }
1126−
1126+
11271127 if( _listeners.count( sub->port() ) == 0 )
11281128 {
11291129 EM_log( CK_LOG_INFO, "error, cannot unsubscribe: port %d not in use", sub->port() );
1130− return false;
1130+ return false;
11311131 }
11321132 else
11331133 {
11341134 int pp = sub->port();
11351135 UDP_Port_Listener * listener = _listeners[pp];
11361136 bool ret = listener->drop( sub );
1137− //check empty
1138− if( listener->nsubs() == 0 ) {
1139− EM_log( CK_LOG_INFO, "PortManager: Listener on port %d is empty - removing", sub->port() );
1137+ //check empty
1138+ if( listener->nsubs() == 0 ) {
1139+ EM_log( CK_LOG_INFO, "PortManager: Listener on port %d is empty - removing", sub->port() );
11401140 delete listener;
11411141 _listeners.erase( pp );
11421142 }
1143− return ret;
1143+ return ret;
11441144 }
11451145 }
11461146
@@ -1156,7 +1156,7 @@ UDP_Port_Listener::~UDP_Port_Listener() · 9 unmodified lines
11561156 {
11571157 //CK_FPRINTF_STDERR( "port listener destructor\n" );
11581158 close();
1159− // usleep( 10 ); // do we need this ?
1159+ // usleep( 10 ); // do we need this ?
11601160 delete m_in;
11611161 delete m_mutex;
11621162 delete m_thread;
@@ -1180,7 +1180,7 @@ bool UDP_Port_Listener::add( UDP_Subscriber * sub ) · 17 unmodified lines
11801180 {
11811181 EM_log(CK_LOG_INFO, "UDP_Port_Listener: adding subscriber" );
11821182 m_subscribers.push_back( sub );
1183− sub->port() = m_port;
1183+ sub->port() = m_port;
11841184 m_mutex->release();
11851185 return true;
11861186 }
@@ -1271,7 +1271,7 @@ void UDP_Port_Listener::close() · 84 unmodified lines
12711271 int UDP_Port_Listener::recv_mesg()
12721272 {
12731273 int mLen = m_in->recv_next( m_inbuf, m_inbufsize );
1274−
1274+
12751275 if( mLen == 0 )
12761276 {
12771277 EM_log( CK_LOG_INFO, "recvLen 0 on socket, returning 0" );
@@ -1298,12 +1298,12 @@ bool UDP_Subscriber::subscribe( int p ) · 20 unmodified lines
12981298 return false; // already subscribed
12991299 }
13001300 else if( UDP_Port_Manager::instance()->subscribe( this, p ) )
1301− {
1301+ {
13021302 port() = p;
13031303 return true;
13041304 }
1305− else
1306− {
1305+ else
1306+ {
13071307 port() = -1;
13081308 return false;
13091309 }
@@ -1322,22 +1322,22 @@ bool UDP_Subscriber::unsubscribe() · 12 unmodified lines
13221322 }
13231323 else
13241324 {
1325− return false; // could not unsubscribe?
1325+ return false; // could not unsubscribe?
13261326 }
13271327 }
13281328
13291329
13301330
1331−UDP_Receiver::UDP_Receiver()
1332−{
1333− _status = UDP_NOINIT;
1331+UDP_Receiver::UDP_Receiver()
1332+{
1333+ _status = UDP_NOINIT;
13341334 }
13351335
13361336
13371337 void UDP_Receiver::init()
1338−{
1339− //open port
1340− _sock = ck_udp_create();
1338+{
1339+ //open port
1340+ _sock = ck_udp_create();
13411341 _status = ( _sock != NULL ) ? UDP_UNBOUND : UDP_ERROR;
13421342 }
13431343
@@ -1358,10 +1358,10 @@ bool UDP_Receiver::bind_to_port(int port) · 14 unmodified lines
13581358 udp_stat UDP_Receiver::status() { return _status; }
13591359
13601360 int UDP_Receiver::recv_next(char * buffer, int bsize)
1361−{
1362− if( _status != UDP_BOUND )
1361+{
1362+ if( _status != UDP_BOUND )
13631363 {
1364− EM_log( CK_LOG_SYSTEM, "(via OSC): recv -> socket not bound!"); return 0;
1364+ EM_log( CK_LOG_SYSTEM, "(via OSC): recv -> socket not bound!"); return 0;
13651365 }
13661366
13671367 _remote_addr_len = sizeof(_remote_addr);
@@ -1382,7 +1382,7 @@ void UDP_Transmitter::init() · 14 unmodified lines
13821382 {
13831383 //open socket
13841384 _sock = ck_udp_create();
1385− _status = ( _sock != NULL ) ? UDP_READY : UDP_ERROR;
1385+ _status = ( _sock != NULL ) ? UDP_READY : UDP_ERROR;
13861386 }
13871387
13881388
@@ -1407,7 +1407,7 @@ void UDP_Transmitter::set_host( char * hostaddress, int port ) · 18 unmodified lines
14071407 }
14081408 memcpy(&_host_addr.sin_addr, host->h_addr_list[0], host->h_length);
14091409 // printf(" ...set\n");
1410− }
1410+ }
14111411 // else printf(" ...set\n");
14121412 _status = UDP_READY;
14131413 }
@@ -1433,43 +1433,43 @@ void UDP_Transmitter::close_sock() · 19 unmodified lines
14331433
14341434 // OSC_TRANSMITTER
14351435
1436−OSC_Transmitter::OSC_Transmitter() {
1436+OSC_Transmitter::OSC_Transmitter() {
14371437 _out = new UDP_Transmitter();
14381438 _holdMessage = false;
14391439 init();
14401440 }
14411441
1442−OSC_Transmitter::OSC_Transmitter( UDP_Transmitter * out ) {
1442+OSC_Transmitter::OSC_Transmitter( UDP_Transmitter * out ) {
14431443 _out = out;
14441444 _holdMessage = false;
14451445 }
14461446
1447−OSC_Transmitter::~OSC_Transmitter() { delete _out; }
1447+OSC_Transmitter::~OSC_Transmitter() { delete _out; }
14481448
1449−void
1450−OSC_Transmitter::init() {
1449+void
1450+OSC_Transmitter::init() {
14511451 if( _out->status() == UDP_NOINIT ) _out->init();
14521452 OSC_initBuffer(&_osc, sizeof(_buffer), _buffer );
14531453 }
14541454
1455−void
1456−OSC_Transmitter::setHost( char * hadd, int p ) {
1455+void
1456+OSC_Transmitter::setHost( char * hadd, int p ) {
14571457 _out->set_host(hadd, p);
14581458 }
14591459
14601460 void
1461−OSC_Transmitter::presend( char * buf, int sz ) {
1461+OSC_Transmitter::presend( char * buf, int sz ) {
14621462 _out->send(buf,sz);
14631463 }
14641464
14651465 void
1466−OSC_Transmitter::openBundle( OSCTimeTag t) {
1466+OSC_Transmitter::openBundle( OSCTimeTag t) {
14671467 OSC_openBundle( &_osc, t);
14681468 }
14691469
14701470
14711471 void
1472−OSC_Transmitter::closeBundle() {
1472+OSC_Transmitter::closeBundle() {
14731473 OSC_closeBundle( &_osc );
14741474 tryMessage();
14751475 }
@@ -1485,13 +1485,13 @@ OSC_Transmitter::addMessage( char *address, char * args, ...) · 9 unmodified lines
14851485
14861486 va_list tags; // pointer to list of arguments
14871487 va_start(tags, args); // parses the string for variables
1488−
1488+
14891489 OSC_writeAddressAndTypes( &_osc, address, args );
14901490
14911491 t_CKINT argnum = strlen(args);
14921492 t_CKINT osc_err = 0;
14931493 for(t_CKINT j = 1; !osc_err && j < argnum; j++ ) {
1494− switch ( args[j] ) {
1494+ switch ( args[j] ) {
14951495 case 'i':
14961496 osc_err = OSC_writeIntArg ( &_osc, va_arg(tags, int) );
14971497 break;
@@ -1500,11 +1500,11 @@ OSC_Transmitter::addMessage( char *address, char * args, ...) · 2 unmodified lines
15001500 break;
15011501 case 's':
15021502 osc_err = OSC_writeStringArg ( &_osc, va_arg(tags, char *) );
1503− break;
1503+ break;
15041504 }
15051505 }
15061506
1507− if( osc_err ) {
1507+ if( osc_err ) {
15081508 EM_log( CK_LOG_SYSTEM, "(via OSC): error writing packet: %d %s...", osc_err, OSC_errorMessage );
15091509 // failure action???
15101510 }
@@ -1514,43 +1514,43 @@ OSC_Transmitter::addMessage( char *address, char * args, ...) · 3 unmodified lines
15141514 }
15151515
15161516 void
1517−OSC_Transmitter::startMessage( char * spec ) {
1518−
1517+OSC_Transmitter::startMessage( char * spec ) {
1518+
15191519 t_CKINT len = strlen( spec );
1520−
1520+
15211521 char * comma = strchr( spec, ',');
15221522 char * space = strchr ( spec, ' ');
1523− int coff = ( comma == NULL ) ? len : comma - spec;
1524− int spoff = ( space == NULL ) ? len : space - spec;
1523+ int coff = ( comma == NULL ) ? len : comma - spec;
1524+ int spoff = ( space == NULL ) ? len : space - spec;
15251525 int off = min ( coff, spoff );
1526−
1526+
15271527 if( off < len )
15281528 spec[off] = '\0';
1529−
1529+
15301530 startMessage( spec, spec + off + 1 );
15311531 }
15321532
15331533 void
15341534 OSC_Transmitter::startMessage( char * address, char * args )
1535−{
1535+{
15361536 // OSC_writeAddressAndTypes( &_osc, address, args );
15371537 char addrfix[512];
15381538 t_CKINT addrlen = strlen( address );
15391539 // int mx = strlen(address) + strlen(args) + 1; // either we need to add a comma to args,
1540− // or it's got junk in it.
1540+ // or it's got junk in it.
15411541 // char addrfix[] = new char[mx]; // (char*) malloc( mx * sizeof( char ) );
15421542 strcpy ( addrfix, address );
15431543 addrfix[addrlen] = '\0';
15441544 addrfix[addrlen+1] = ',';
15451545 char * argptr = addrfix + (addrlen + 2);
15461546 char * p_args = args;
1547− while ( *p_args != '\0' ) {
1547+ while ( *p_args != '\0' ) {
15481548 if( *p_args != ',' && *p_args != ' ' ) {
1549− *argptr = *p_args;
1549+ *argptr = *p_args;
15501550 argptr++;
15511551 }
15521552 p_args++;
1553− }
1553+ }
15541554 *argptr = '\0';
15551555
15561556 OSC_writeAddressAndTypes( &_osc, addrfix, addrfix + addrlen + 1); //expects the ',' before spec tag.
@@ -1560,46 +1560,46 @@ OSC_Transmitter::startMessage( char * address, char * args ) · 3 unmodified lines
15601560 }
15611561
15621562 void
1563−OSC_Transmitter::addInt ( int4byte i ) {
1563+OSC_Transmitter::addInt ( int4byte i ) {
15641564 int osc_err = OSC_writeIntArg ( &_osc, i );
1565− if( osc_err ) {
1565+ if( osc_err ) {
15661566 CK_FPRINTF_STDERR( "[chuck](via OSC): error writing packet: %d %s\n", osc_err, OSC_errorMessage );
15671567 //failure action???
1568− }
1568+ }
15691569 tryMessage();
15701570 }
15711571
15721572 void
1573−OSC_Transmitter::addFloat ( float f ) {
1573+OSC_Transmitter::addFloat ( float f ) {
15741574 int osc_err = OSC_writeFloatArg ( &_osc, f );
1575− if( osc_err ) {
1575+ if( osc_err ) {
15761576 CK_FPRINTF_STDERR( "[chuck](via OSC): error writing packet: %d %s\n", osc_err, OSC_errorMessage );
15771577 //failure action???
1578− }
1578+ }
15791579 tryMessage();
15801580 }
15811581
15821582 void
1583−OSC_Transmitter::addString ( char * s ) {
1583+OSC_Transmitter::addString ( char * s ) {
15841584 int osc_err = OSC_writeStringArg ( &_osc, s );
1585− if( osc_err ) {
1585+ if( osc_err ) {
15861586 CK_FPRINTF_STDERR( "[chuck](via OSC): error writing packet: %d %s\n", osc_err, OSC_errorMessage );
15871587 //failure action???
1588− }
1588+ }
15891589 tryMessage();
15901590 }
15911591
15921592 bool
1593−OSC_Transmitter::packetReady() {
1593+OSC_Transmitter::packetReady() {
15941594 if( _holdMessage ) return false; //message hold is on
15951595 if( _osc.typeStringPtr ) { //if it's been typed, check that type is complete
15961596 if( CheckTypeTag(&_osc, '\0' ) ) return false;
1597− }
1597+ }
15981598 return ( OSC_isBufferDone(&_osc) != 0 );
15991599 }
16001600
16011601 void
1602−OSC_Transmitter::tryMessage() {
1602+OSC_Transmitter::tryMessage() {
16031603 if( !packetReady() ) return;
16041604
16051605 _out->send( OSC_getPacket(&_osc), OSC_packetSize(&_osc) );
@@ -1607,13 +1607,13 @@ OSC_Transmitter::tryMessage() { · 1 unmodified line
16071607 }
16081608
16091609 void
1610−OSC_Transmitter::holdMessage(bool b) {
1610+OSC_Transmitter::holdMessage(bool b) {
16111611 _holdMessage = b;
16121612 }
16131613
16141614 void
1615−OSC_Transmitter::kickMessage() {
1616− if( !OSC_isBufferDone(&_osc) ) {
1615+OSC_Transmitter::kickMessage() {
1616+ if( !OSC_isBufferDone(&_osc) ) {
16171617 CK_FPRINTF_STDERR( "[chuck](via OSC): error -> sending incomplete packet!\n" );
16181618 }
16191619 _out->send( OSC_getPacket(&_osc), OSC_packetSize(&_osc) );
@@ -1691,7 +1691,7 @@ OSC_Receiver::~OSC_Receiver() · 71 unmodified lines
16911691
16921692 // 1.3.1.1: moving this outside the loop, oops
16931693 free( _inbox );
1694−
1694+
16951695 // clean up
16961696 SAFE_DELETE( _io_mutex );
16971697 SAFE_DELETE( _address_mutex );
@@ -1702,7 +1702,7 @@ OSC_Receiver::~OSC_Receiver() · 4 unmodified lines
17021702 // m_vmRef->destroy_event_buffer( m_event_buffer );
17031703 // m_event_buffer = NULL;
17041704 // }
1705−
1705+
17061706 // delete _in;
17071707 }
17081708
@@ -1726,19 +1726,19 @@ THREAD_RETURN (THREAD_TYPE osc_recv_thread)( void * data ) · 17 unmodified lines
17261726 int&
17271727 OSC_Receiver::port() { return _port; }
17281728
1729−void
1730−OSC_Receiver::onReceive( char * mesg, int mesgLen ) {
1729+void
1730+OSC_Receiver::onReceive( char * mesg, int mesgLen ) {
17311731 handle_mesg( mesg, mesgLen );
17321732 }
17331733
17341734 void
1735−OSC_Receiver::bind_to_port(int port ) {
1735+OSC_Receiver::bind_to_port(int port ) {
17361736 _tmp_port = port;
17371737 // _in->bind_to_port(port);
17381738 }
17391739
17401740 bool
1741−OSC_Receiver::listen( int port ) {
1741+OSC_Receiver::listen( int port ) {
17421742 bind_to_port ( port );
17431743 return listen();
17441744 }
@@ -1754,13 +1754,13 @@ OSC_Receiver::listen() · 9 unmodified lines
17541754 {
17551755 if( m_event_buffer == NULL )
17561756 m_event_buffer = m_vmRef->create_event_buffer();
1757−
1757+
17581758 unsubscribe(); // in case we're connected.
1759−
1759+
17601760 return subscribe( _tmp_port );
17611761
17621762 /*
1763− if( !_listening ) {
1763+ if( !_listening ) {
17641764 _listening = true;
17651765 _io_thread->start( osc_recv_thread, (void*)this );
17661766 }
@@ -1771,31 +1771,31 @@ OSC_Receiver::listen() · 4 unmodified lines
17711771
17721772
17731773 void
1774−OSC_Receiver::close_sock() {
1774+OSC_Receiver::close_sock() {
17751775 unsubscribe();
17761776 // _in->close_sock();
17771777 }
17781778
17791779 void
1780−OSC_Receiver::recv_mesg() {
1781− // this is when OSC_Receiver was
1780+OSC_Receiver::recv_mesg() {
1781+ // this is when OSC_Receiver was
17821782 // used as the port-manager. now this code ( and callback ) are in UDP_Port_Listener interface,
1783− // which OSC_Receiver subclasses
1783+ // which OSC_Receiver subclasses
17841784
17851785 /*
17861786 _mesglen = _in->recv_next( _inbuf, _inbufsize );
1787− if( _mesglen > 0 ) {
1787+ if( _mesglen > 0 ) {
17881788 //parse();
17891789 handle_mesg(_inbuf, _mesglen);
17901790 }
17911791 */
17921792 }
1793−
1793+
17941794
17951795 bool OSC_Receiver::has_mesg()
17961796 {
1797− // EM_log( CK_LOG_FINER, "OSC has message?" );
1798− return ( _started && ( _in_read+1 ) % _inbox_size != _in_write );
1797+ // EM_log( CK_LOG_FINER, "OSC has message?" );
1798+ return ( _started && ( _in_read+1 ) % _inbox_size != _in_write );
17991799 }
18001800
18011801 bool OSC_Receiver::get_mesg( OSCMesg * bucket )
@@ -1804,7 +1804,7 @@ bool OSC_Receiver::get_mesg( OSCMesg * bucket ) · 2 unmodified lines
18041804
18051805 if( has_mesg() )
18061806 {
1807− // next write _may_ fuck with _in_read
1807+ // next write _may_ fuck with _in_read
18081808 // where when resizing the buffer...
18091809 *bucket = *next_read();
18101810 // CK_FPRINTF_STDERR( "r" ); //read: %d of %d \n", _in_read, _inbox_size);
@@ -1826,7 +1826,7 @@ void OSC_Receiver::parse( char * mesg, int mesgLen ) · 15 unmodified lines
18261826
18271827 // log
18281828 EM_log( CK_LOG_FINER, "OSC_Receiver: print message length %d", mesgLen );
1829−
1829+
18301830 for( i = 0 ; i < mesgLen; i++ )
18311831 {
18321832 CK_FPRINTF_STDERR( "\t%c(%0x):", mesg[i], mesg[i] );
@@ -1837,25 +1837,25 @@ void OSC_Receiver::parse( char * mesg, int mesgLen ) · 4 unmodified lines
18371837
18381838 void
18391839 OSC_Receiver::next_write()
1840−{
1841− // called by the UDP client ( blocks )
1840+{
1841+ // called by the UDP client ( blocks )
18421842
1843− if( !_started ) {
1844− _started = true;
1845− }
1843+ if( !_started ) {
1844+ _started = true;
1845+ }
18461846
18471847 int next = (_in_write+1) % _inbox_size;
1848−
1849− if( next == _in_read ) {
1850−
1848+
1849+ if( next == _in_read ) {
1850+
18511851 // CK_FPRINTF_STDERR( "OSC::need to resize..." );
1852−
1852+
18531853 _io_mutex->acquire(); //don't let next read return a bogus pointer
18541854
1855− if( _inbox_size < OSCINBOXMAX) {
1856−
1855+ if( _inbox_size < OSCINBOXMAX) {
1856+
18571857 // LOCK MUTEX (on next_read)
1858− // prevents
1858+ // prevents
18591859
18601860 // mesgs might move around, but their data doesn't..(this is good)..
18611861 // if we return an OSCmesg* to an out-of-thread function, it can expire.
@@ -1866,43 +1866,43 @@ OSC_Receiver::next_write() · 4 unmodified lines
18661866 // perhaps a monolithic chunk of memory is a better option...
18671867 // but what if we want to handle multiple messages at once?
18681868
1869− // orrr..if we follow timetags and need semirandom access to
1869+ // orrr..if we follow timetags and need semirandom access to
18701870 // mesg contents for scheduling bundles..hmm.
1871−
1871+
18721872 // make a separate case for scheduled messages...
18731873 // throw them into a heap...
18741874
18751875 // fuck...back to the todo...
1876−
1876+
18771877 int new_size = ( _inbox_size * 2 > OSCINBOXMAX ) ? OSCINBOXMAX : _inbox_size * 2 ;
18781878
18791879 bool err = false;
18801880
1881− // okay. read and write may be anywhere.
1881+ // okay. read and write may be anywhere.
18821882 if( _in_write > _in_read ) {
18831883 // easy case
18841884 _inbox = (OSCMesg* ) realloc ((void*)_inbox, new_size * sizeof(*_inbox) );
18851885 err = (!_inbox);
18861886 // indices are still valid
18871887 }
1888− else {
1888+ else {
18891889 // write is behind read in the buffer
1890− // copy into buffer so that contents remain contiguous
1890+ // copy into buffer so that contents remain contiguous
18911891 // note:: copy the buffers between write and read...
18921892 // they may have valid packet pointers.......
18931893
18941894 OSCMesg * new_inbox =(OSCMesg*)malloc ( new_size * sizeof(*new_inbox) );
18951895 err = (!new_inbox);
1896−
1897− if( !err ) {
1896+
1897+ if( !err ) {
18981898 int _read_tail = _inbox_size - _in_read;
18991899 memcpy( (void*)new_inbox, (void*)(_inbox+_in_read), (_read_tail) * sizeof(*_inbox) );
19001900 memcpy( (void*)(new_inbox+_read_tail), (void*)_inbox, (_in_read ) * sizeof(*_inbox) );
1901−
1901+
19021902 // update indices
19031903 _in_read = 0;
19041904 _in_write = (_in_write + _read_tail);
1905−
1905+
19061906 free ( _inbox );
19071907 _inbox = new_inbox;
19081908 }
@@ -1910,12 +1910,12 @@ OSC_Receiver::next_write() · 1 unmodified line
19101910 else err = true;
19111911 }
19121912
1913−
1914− if( !err ) {
1913+
1914+ if( !err ) {
19151915 // new inbox elements need their payload pointers init to NULL
1916− for( int i = _inbox_size; i < new_size; i++ ) _inbox[i].payload = NULL;
1916+ for( int i = _inbox_size; i < new_size; i++ ) _inbox[i].payload = NULL;
19171917 }
1918− else {
1918+ else {
19191919 // CK_FPRINTF_STDERR( "oh no!! buffer reallocation error!\n" );
19201920 exit(0);
19211921 }
@@ -1926,9 +1926,9 @@ OSC_Receiver::next_write() · 4 unmodified lines
19261926 // CK_FPRINTF_STDERR( "(%d)", _inbox_size );
19271927 // UNLOCK MUTEX
19281928 }
1929− else {
1929+ else {
19301930 // CK_FPRINTF_STDERR( "max buffer...dropping old mesg %d\n", next );
1931− _in_read = (next+1)%_inbox_size;
1931+ _in_read = (next+1)%_inbox_size;
19321932 }
19331933
19341934 _io_mutex->release();
@@ -1939,17 +1939,17 @@ OSC_Receiver::next_write() · 4 unmodified lines
19391939
19401940
19411941 OSCMesg*
1942−OSC_Receiver::next_read() {
1943− int next = ( _in_read + 1 ) % _inbox_size;
1942+OSC_Receiver::next_read() {
1943+ int next = ( _in_read + 1 ) % _inbox_size;
19441944 if( next == _in_write ) return NULL; // can't intrude on write
1945−
1945+
19461946 _in_read = next; //advance
19471947 OSCMesg* ret= _inbox + _in_read; // return this pointer
19481948 return ret;
19491949 }
19501950
19511951 void
1952−OSC_Receiver::set_mesg(OSCMesg* mrp, char * buf, int len ) {
1952+OSC_Receiver::set_mesg(OSCMesg* mrp, char * buf, int len ) {
19531953
19541954 // put pointers in the appropriate places
19551955 // this means that mrp has no idea whether
@@ -1959,17 +1959,17 @@ OSC_Receiver::set_mesg(OSCMesg* mrp, char * buf, int len ) { · 3 unmodified lines
19591959 mrp->len = len; //total size of message
19601960 mrp->address = buf;
19611961 mrp->types = mrp->address + strlen(mrp->address) + 4 - strlen(mrp->address)%4;
1962− if( mrp->types[0] == ',') {
1962+ if( mrp->types[0] == ',') {
19631963 // typed message
1964− mrp->data= mrp->types + strlen(mrp->types) + 4 - strlen(mrp->types)%4;
1964+ mrp->data= mrp->types + strlen(mrp->types) + 4 - strlen(mrp->types)%4;
19651965 }
1966− else {
1967− // untyped message.
1966+ else {
1967+ // untyped message.
19681968 // should there be a warning?
19691969 // classes that handle mesgs
19701970 // should take care of that.
1971− mrp->data = mrp->types;
1972− mrp->types = NULL;
1971+ mrp->data = mrp->types;
1972+ mrp->types = NULL;
19731973 }
19741974
19751975 }
@@ -1977,9 +1977,9 @@ OSC_Receiver::set_mesg(OSCMesg* mrp, char * buf, int len ) { · 1 unmodified line
19771977 void
19781978 OSC_Receiver::handle_mesg( char * buf, int len )
19791979 {
1980− // this is called sequentially by the receiving thread.
1980+ // this is called sequentially by the receiving thread.
19811981 if( buf[0] == '#' ) { handle_bundle( buf, len ); return; }
1982−
1982+
19831983 OSCMesg * mrp = write();
19841984
19851985 if( mrp->payload == NULL ) {
@@ -1994,7 +1994,7 @@ OSC_Receiver::handle_mesg( char * buf, int len ) · 8 unmodified lines
19941994 distribute_message( mrp ); // copy message to any & all matching address spaces
19951995
19961996 // the distribute message will copy any necessary data into the addr object's private queue.
1997− // so we don't need to buffer here.. ( totally wasting the kick-ass expanding buffer i have in this class...drat )
1997+ // so we don't need to buffer here.. ( totally wasting the kick-ass expanding buffer i have in this class...drat )
19981998
19991999 // next_write();
20002000 }
@@ -2005,11 +2005,11 @@ void OSC_Receiver::handle_bundle( char * b, int len ) · 4 unmodified lines
20052005 // just immediately unpack everything
20062006
20072007 // CK_FPRINTF_STDERR( "bundle (length %d)\n", len );
2008−
2008+
20092009 int off = 16; //skip "#bundle\0timetags"
20102010
2011− while ( off < len )
2012− {
2011+ while ( off < len )
2012+ {
20132013 char * z = b+off;
20142014 unsigned long size = ntohl(*((unsigned long*)z));
20152015
@@ -2070,7 +2070,7 @@ void OSC_Receiver::remove_address( OSC_Address_Space *odd ) · 54 unmodified lines
20702070 _address_space[i] = _address_space[--_address_num];
20712071 }
20722072 }
2073−
2073+
20742074 // release (added 1.3.1.1)
20752075 _address_mutex->release();
20762076 }
@@ -2095,61 +2095,61 @@ void OSC_Receiver::distribute_message( OSCMesg * msg ) · 18 unmodified lines
20952095 ((Chuck_Event *)_address_space[i]->SELF)->queue_broadcast( m_event_buffer );
20962096 }
20972097 }
2098−
2098+
20992099 // release (added 1.3.1.1)
21002100 _address_mutex->release();
21012101 }
21022102
21032103
2104−// OSC SOURCE ( Parser )
2105−// rename to OSC_address ?
2104+// OSC SOURCE ( Parser )
2105+// rename to OSC_address ?
21062106
21072107 // this is an OSC_Address_Space - we register it to a particular receiver
2108−// the receiver matches an incoming message against registered
2109−// address and sends the message to all that match.
2108+// the receiver matches an incoming message against registered
2109+// address and sends the message to all that match.
21102110
21112111 // OSCMesg may still have pointers to a mysterious void.
21122112 // we should copy values locally for string and blob.
21132113
2114−// public for of inherited chuck_event mfunc.
2114+// public for of inherited chuck_event mfunc.
21152115
2116−const char * osc_typename_strings[] = {
2117− "untyped",
2118− "no arguments",
2119− "integer",
2120− "float",
2121− "string",
2122− "blob",
2123− "ERROR: num types exceeded"
2116+const char * osc_typename_strings[] = {
2117+ "untyped",
2118+ "no arguments",
2119+ "integer",
2120+ "float",
2121+ "string",
2122+ "blob",
2123+ "ERROR: num types exceeded"
21242124 };
21252125
21262126
21272127
2128−OSC_Address_Space::OSC_Address_Space() {
2128+OSC_Address_Space::OSC_Address_Space() {
21292129 init();
21302130 setSpec( "/undefined/default,i" );
21312131 }
21322132
21332133
2134−OSC_Address_Space::OSC_Address_Space( const char * spec ) {
2134+OSC_Address_Space::OSC_Address_Space( const char * spec ) {
21352135 init();
21362136 setSpec( spec );
21372137 }
21382138
2139−OSC_Address_Space::OSC_Address_Space( const char * addr, const char * types) {
2139+OSC_Address_Space::OSC_Address_Space( const char * addr, const char * types) {
21402140 init();
21412141 setSpec( addr, types );
21422142 }
21432143
21442144 void
2145−OSC_Address_Space::init() {
2145+OSC_Address_Space::init() {
21462146 _receiver = NULL;
21472147 SELF = NULL;
2148− _queueSize = 512; // start queue size at 512 // 64.
2148+ _queueSize = 512; // start queue size at 512 // 64.
21492149 _dataSize = 0;
21502150 _cur_mesg = NULL;
21512151 _queue = NULL;
2152− _cur_value = 0;
2152+ _cur_value = 0;
21532153 _current_data = NULL;
21542154 _buffer_mutex = new XMutex();
21552155 }
@@ -2163,29 +2163,29 @@ OSC_Address_Space::~OSC_Address_Space() · 7 unmodified lines
21632163 }
21642164
21652165 void
2166−OSC_Address_Space::setReceiver(OSC_Receiver * recv) {
2166+OSC_Address_Space::setReceiver(OSC_Receiver * recv) {
21672167 _receiver = recv;
21682168 }
21692169
21702170 void
2171−OSC_Address_Space::setSpec( const char *addr, const char * types ) {
2171+OSC_Address_Space::setSpec( const char *addr, const char * types ) {
21722172 if( snprintf( _spec, sizeof _spec, "%s,%s", addr, types ) >= sizeof _spec) {
21732173 // TODO: handle the overflow more gracefully.
21742174 EM_log(CK_LOG_SEVERE, "OSC_Address_Space::setSpec: Not enough space in _spec buffer, data was truncated.");
21752175 }
21762176 scanSpec();
2177− _needparse = true;
2178− parseSpec();
2177+ _needparse = true;
2178+ parseSpec();
21792179 }
21802180
2181−void
2182−OSC_Address_Space::setSpec( const char *c ) {
2183− strncpy ( _spec, c, 512);
2181+void
2182+OSC_Address_Space::setSpec( const char *c ) {
2183+ strncpy ( _spec, c, 512);
21842184 scanSpec();
2185− _needparse = true;
2186− parseSpec();
2185+ _needparse = true;
2186+ parseSpec();
21872187 }
2188−
2188+
21892189 void
21902190 OSC_Address_Space::scanSpec() { //this allows for sloppy-ish definitions in type string
21912191 //assumes that a potential spec is already in _spec;
@@ -2193,32 +2193,32 @@ OSC_Address_Space::scanSpec() { //this allows for sloppy-ish definitions in type · 1 unmodified line
21932193 char * pwrite;
21942194 pread = pwrite = (char*)_spec;
21952195 bool in_type = false;
2196− while ( *pread != '\0' ) {
2197− if( *pread == ',' || *pread == ' ' ) {
2196+ while ( *pread != '\0' ) {
2197+ if( *pread == ',' || *pread == ' ' ) {
21982198 if( !in_type ) {
21992199 in_type = true;
22002200 *pwrite = ',';
22012201 pwrite++;
22022202 } // otherwise, we ignore
2203− else if( *pread == ' ' ) {
2204− EM_log(CK_LOG_INFO, "OSC-Address-Space: spaces in OSC type tag string! ignoring");
2205− }
2203+ else if( *pread == ' ' ) {
2204+ EM_log(CK_LOG_INFO, "OSC-Address-Space: spaces in OSC type tag string! ignoring");
2205+ }
22062206 }
2207− else {
2207+ else {
22082208 if( pwrite != pread ) { *pwrite = *pread; }
22092209 pwrite++;
22102210 }
22112211 pread++;
22122212 }
22132213 if( !in_type ) {
2214− //no type args found, add a comma to indicate a zero-arg string.
2214+ //no type args found, add a comma to indicate a zero-arg string.
22152215 *(pwrite++) = ',';
22162216 }
2217− *pwrite = '\0'; //if pread terminates, so does pwrite.
2217+ *pwrite = '\0'; //if pread terminates, so does pwrite.
22182218 }
22192219
22202220 void
2221−OSC_Address_Space::parseSpec() {
2221+OSC_Address_Space::parseSpec() {
22222222
22232223 if( !_needparse ) return;
22242224
@@ -2247,18 +2247,18 @@ OSC_Address_Space::resizeQueue( int n ) · 22 unmodified lines
22472247 {
22482248 if( n <= _queueSize )
22492249 return; // only grows
2250−
2250+
22512251 // lock
22522252 _buffer_mutex->acquire();
22532253
2254− // it's possible that between the test above and now,
2254+ // it's possible that between the test above and now,
22552255 // qread has moved on and we actually DO have space..
22562256
22572257 EM_log( CK_LOG_INFO, "OSC_Address (%s) -- buffer full ( r:%d , w:%d, of %d(x%d) ), resizing...",
22582258 _address, _qread, _qwrite, _queueSize, _dataSize );
22592259 // CK_FPRINTF_STDERR( "--- hasMesg ( %d ) nextMesg ( %d )\n", (int) has_mesg(), (int)next_mesg() );
22602260
2261− // we're the server... all we know is that the contents of qread are in the current_buffer,
2261+ // we're the server... all we know is that the contents of qread are in the current_buffer,
22622262 // so we can move the data, but we don't want to move ahead and lose it just yet.
22632263
22642264 // compute chunk size
@@ -2273,21 +2273,21 @@ OSC_Address_Space::resizeQueue( int n ) · 8 unmodified lines
22732273 // copy
22742274 if( _qread < _qwrite )
22752275 {
2276− // we're doing this because qwrite is out of room.
2276+ // we're doing this because qwrite is out of room.
22772277 // so if qwrite is already greater than qread,
2278− // just copy the whole thing to the start of the new buffer ( adding more space to the end )
2278+ // just copy the whole thing to the start of the new buffer ( adding more space to the end )
22792279 memcpy( (void*)_new_queue, (const void*)_queue, _queueSize * chunkSize);
2280− // _qwrite and _qread can stay right where they are.
2280+ // _qwrite and _qread can stay right where they are.
22812281 // CK_FPRINTF_STDERR( "resize - case 1\n" );
22822282 }
22832283 else
2284− {
2284+ {
22852285 // _qread is in front of _qwrite, so we must unwrap, and place _qread at the
22862286 // front of the queue, and qwrite at the end, preserving all elements that qread
22872287 // is waiting to consume.
22882288 int nread = _queueSize - _qread;
2289− memcpy( (void*)_new_queue,
2290− (const void*)(_queue + _qread * _dataSize),
2289+ memcpy( (void*)_new_queue,
2290+ (const void*)(_queue + _qread * _dataSize),
22912291 (nread) * chunkSize);
22922292 memcpy( (void*)(_new_queue + nread * _dataSize),
22932293 (const void*)_queue,
@@ -2297,18 +2297,18 @@ OSC_Address_Space::resizeQueue( int n ) · 3 unmodified lines
22972297 // EM_log(CK_LOG_INFO, "resize - case 2\n");
22982298 }
22992299
2300− _queueSize = _newQSize;
2301− opsc_data * trash = _queue;
2300+ _queueSize = _newQSize;
2301+ opsc_data * trash = _queue;
23022302 _queue = _new_queue;
23032303 free ( (void*)trash );
23042304
2305− // don't move qread or qwrite until we're done.
2305+ // don't move qread or qwrite until we're done.
23062306 _buffer_mutex->release();
23072307 }
23082308
23092309
23102310 void
2311−OSC_Address_Space::resizeData( int n ) {
2311+OSC_Address_Space::resizeData( int n ) {
23122312 if( _dataSize == n ) return;
23132313 _dataSize = n;
23142314 int queueLen = _queueSize * _dataSize * sizeof( opsc_data );
@@ -2322,20 +2322,20 @@ bool · 7 unmodified lines
23222322 OSC_Address_Space::message_matches( OSCMesg * m ) {
23232323
23242324 //this should test for type as well.
2325−
2325+
23262326 bool addr_match;
23272327 if( strcmp ( m->address, _address ) == 0 ) addr_match = true;
23282328 else addr_match = PatternMatch( m->address, _address);
23292329 if( !addr_match ) return false;
23302330
2331− //address AND type must match
2331+ //address AND type must match
23322332 //but there should be an option for the blank 'information about this' pattern
23332333
23342334 char * type = m->types+1;
2335− if( m->types == NULL || strcmp( _type , type ) != 0 ) {
2335+ if( m->types == NULL || strcmp( _type , type ) != 0 ) {
23362336 // if( type )
23372337 // CK_FPRINTF_STDERR( "error, mismatched type string( %s ) vs ( %s ) \n", _type, type );
2338−// else
2338+// else
23392339 // CK_FPRINTF_STDERR( "error, missing type string (expecting %s) \n", _type );
23402340 return false;
23412341 }
@@ -2343,7 +2343,7 @@ OSC_Address_Space::message_matches( OSCMesg * m ) { · 1 unmodified line
23432343 }
23442344
23452345
2346−bool OSC_Address_Space::try_queue_mesg( OSCMesg * m )
2346+bool OSC_Address_Space::try_queue_mesg( OSCMesg * m )
23472347 {
23482348 if( !message_matches( m ) ) return false;
23492349 queue_mesg( m );
@@ -2367,7 +2367,6 @@ bool OSC_Address_Space::next_mesg() · 17 unmodified lines
23672367 // lock
23682368 _buffer_mutex->acquire();
23692369
2370− // TODO: ge uhhhh should release mutex?
23712370 if( has_mesg() )
23722371 {
23732372 // move qread forward
@@ -2384,35 +2383,15 @@ bool OSC_Address_Space::next_mesg() · 10 unmodified lines
23842383 // release
23852384 _buffer_mutex->release();
23862385 return false;
2387−
2388−// if( has_mesg() )
2389−// {
2390−// _buffer_mutex->acquire();
2391−//
2392−// // TODO: ge uhhhh should release mutex?
2393−// if( !has_mesg() ) return false;
2394−//
2395−// // move qread forward
2396−// _qread = ( _qread + 1 ) % _queueSize;
2397−// memcpy( _current_data, _queue + _qread * _dataSize, _dataSize * sizeof( opsc_data ) );
2398−// _cur_mesg = _current_data;
2399−// _cur_value = 0;
2400−//
2401−// _buffer_mutex->release();
2402−//
2403−// return true;
2404−// }
2405−//
2406−// return false;
24072386 }
24082387
24092388 bool OSC_Address_Space::vcheck( osc_datatype tt )
24102389 {
2411− if( !_cur_mesg )
2390+ if( !_cur_mesg )
24122391 {
24132392 EM_log( CK_LOG_SEVERE, "OscEvent: getVal(): nextMsg() must be called before reading data..." );
24142393 return false;
2415− }
2394+ }
24162395 else if( _cur_value < 0 || _cur_value >= _dataSize )
24172396 {
24182397 EM_log( CK_LOG_SEVERE, "OscEvent: read position %d outside message ...", _cur_value );
@@ -2442,7 +2421,7 @@ char * OSC_Address_Space::next_string() · 23 unmodified lines
24422421 return (vcheck(OSC_STRING)) ? _cur_mesg[_cur_value++].s : NULL ;
24432422 }
24442423
2445−char *
2424+char *
24462425 OSC_Address_Space::next_string_dup()
24472426 {
24482427 if( !vcheck(OSC_STRING) ) return NULL;
@@ -2453,62 +2432,62 @@ OSC_Address_Space::next_string_dup() · 4 unmodified lines
24532432 }
24542433
24552434 char *
2456−OSC_Address_Space::next_blob() {
2435+OSC_Address_Space::next_blob() {
24572436 return ( vcheck(OSC_BLOB) ) ? _cur_mesg[_cur_value++].s : NULL ;
24582437 }
24592438
24602439 void
2461−OSC_Address_Space::queue_mesg( OSCMesg * m )
2440+OSC_Address_Space::queue_mesg( OSCMesg * m )
24622441 {
2463− // in the server thread.
2442+ // in the server thread.
24642443 int nqw = ( _qwrite + 1 ) % _queueSize;
24652444 EM_log( CK_LOG_FINE, "OSC address(%s): read: %d write: %d size: %d", _address, _qread, _qwrite, _queueSize );
24662445
24672446 if( nqw == _qread ) {
2468− if( _queueSize < OSC_ADDRESS_QUEUE_MAX ) {
2447+ if( _queueSize < OSC_ADDRESS_QUEUE_MAX ) {
24692448 resizeQueue( _queueSize * 2 );
24702449 nqw = ( _qwrite + 1 ) % _queueSize; // _qwrite, _qread may have changed.
24712450 }
2472− else {
2451+ else {
24732452 EM_log( CK_LOG_INFO, "OSC_Address_Space(%s): message queue reached max size %d...", _address, _queueSize );
24742453 EM_log( CK_LOG_INFO, "...(dropping oldest message %d)", _qread );
24752454
24762455 // bump!
24772456 _buffer_mutex->acquire();
2478− _qread = ( _qread + 1 ) % _queueSize;
2457+ _qread = ( _qread + 1 ) % _queueSize;
24792458 _buffer_mutex->release();
24802459 }
24812460 }
24822461
24832462 _vals = _queue + _qwrite * _dataSize;
24842463
2485− if( _noArgs ) { // if address takes no arguments,
2464+ if( _noArgs ) { // if address takes no arguments,
24862465 _vals[0].t = OSC_NOARGS;
24872466 }
2488− else {
2467+ else {
24892468 char * type = m->types+1;
24902469 char * data = m->data;
2491−
2470+
24922471 unsigned int endy;
24932472 int i=0;
2494−
2473+
24952474 float *fp;
24962475 int *ip;
24972476 t_CKINT clen;
2498− while ( *type != '\0' ) {
2499− switch ( *type ) {
2477+ while ( *type != '\0' ) {
2478+ switch ( *type ) {
25002479 case 'f':
25012480 endy = ntohl(*((unsigned long*)data));
25022481 fp = (float*)(&endy);
25032482 _vals[i].t = OSC_FLOAT;
2504− _vals[i].f = *fp;
2483+ _vals[i].f = *fp;
25052484 data += 4;
25062485 break;
25072486 case 'i':
25082487 endy = ntohl(*((unsigned long*)data));
25092488 ip = (int4byte*)(&endy);
25102489 _vals[i].t = OSC_INT;
2511− _vals[i].i = *ip;
2490+ _vals[i].i = *ip;
25122491 data += 4;
25132492 break;
25142493 case 's':
@@ -2535,7 +2514,7 @@ OSC_Address_Space::queue_mesg( OSCMesg * m ) · 20 unmodified lines
25352514 type++;
25362515 }
25372516 }
2538−
2517+
25392518 _qwrite = nqw;
25402519
25412520 //review

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t