Showing the changes to src/core/util_opsc.cpp (1 of 263 files). Show all
Unified · Split
| @@ -44,7 +44,7 @@ · 43 unmodified lines | |||
| 44 | using namespace std; | 44 | using namespace std; |
| 45 | 45 | ||
| 46 | 46 | ||
| 47 | // FROM PLATFORM.H -UDP TRANSMITTER / RECEIVER | 47 | // FROM PLATFORM.H -UDP TRANSMITTER / RECEIVER |
| 48 | 48 | ||
| 49 | #if defined(__PLATFORM_WIN32__) | 49 | #if defined(__PLATFORM_WIN32__) |
| 50 | // 2022 QTSIN added winsock2.h and wsw2tcpip.h | 50 | // 2022 QTSIN added winsock2.h and wsw2tcpip.h |
| @@ -76,12 +76,12 @@ using namespace std; · 25 unmodified lines | |||
| 76 | #endif | 76 | #endif |
| 77 | 77 | ||
| 78 | 78 | ||
| 79 | // squeeze the whole wad of OSC-Kit code in here. | 79 | // squeeze the whole wad of OSC-Kit code in here. |
| 80 | 80 | ||
| 81 | // OSC-pattern-match.cpp | 81 | // OSC-pattern-match.cpp |
| 82 | 82 | ||
| 83 | /* | 83 | /* |
| 84 | Copyright � 1998. The Regents of the University of California (Regents). | 84 | Copyright � 1998. The Regents of the University of California (Regents). |
| 85 | All Rights Reserved. | 85 | All Rights Reserved. |
| 86 | 86 | ||
| 87 | Written by Matt Wright, The Center for New Music and Audio Technologies, | 87 | 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 | |||
| 104 | HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE | 104 | HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE |
| 105 | MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 105 | MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 106 | 106 | ||
| 107 | The OpenSound Control WWW page is | 107 | The OpenSound Control WWW page is |
| 108 | http://www.cnmat.berkeley.edu/OpenSoundControl | 108 | http://www.cnmat.berkeley.edu/OpenSoundControl |
| 109 | */ | 109 | */ |
| 110 | 110 | ||
| @@ -126,23 +126,23 @@ static bool MatchList( const char * pattern, const char * test ); · 15 unmodified lines | |||
| 126 | bool PatternMatch( const char * pattern, const char * test ) | 126 | bool PatternMatch( const char * pattern, const char * test ) |
| 127 | { | 127 | { |
| 128 | theWholePattern = pattern; | 128 | theWholePattern = pattern; |
| 129 | 129 | ||
| 130 | if( pattern == 0 || pattern[0] == 0 ) { | 130 | if( pattern == 0 || pattern[0] == 0 ) { |
| 131 | return test[0] == 0; | 131 | return test[0] == 0; |
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | if( test[0] == 0 ) { | 134 | if( test[0] == 0 ) { |
| 135 | if(pattern[0] == '*') | 135 | if(pattern[0] == '*') |
| 136 | return PatternMatch (pattern+1,test); | 136 | return PatternMatch (pattern+1,test); |
| 137 | else | 137 | else |
| 138 | return FALSE; | 138 | return FALSE; |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | switch( pattern[0] ) | 141 | switch( pattern[0] ) |
| 142 | { | 142 | { |
| 143 | case 0 : return test[0] == 0; | 143 | case 0 : return test[0] == 0; |
| 144 | case '?' : return PatternMatch (pattern + 1, test + 1); | 144 | case '?' : return PatternMatch (pattern + 1, test + 1); |
| 145 | case '*' : | 145 | case '*' : |
| 146 | if( PatternMatch (pattern+1, test) ) { | 146 | if( PatternMatch (pattern+1, test) ) { |
| 147 | return TRUE; | 147 | return TRUE; |
| 148 | } else { | 148 | } else { |
| @@ -156,7 +156,7 @@ bool PatternMatch( const char * pattern, const char * test ) · 7 unmodified lines | |||
| 156 | return MatchBrackets (pattern,test); | 156 | return MatchBrackets (pattern,test); |
| 157 | case '{' : | 157 | case '{' : |
| 158 | return MatchList (pattern,test); | 158 | return MatchList (pattern,test); |
| 159 | case '\\' : | 159 | case '\\' : |
| 160 | if(pattern[1] == 0) { | 160 | if(pattern[1] == 0) { |
| 161 | return test[0] == 0; | 161 | return test[0] == 0; |
| 162 | } else if(pattern[1] == test[0]) { | 162 | } else if(pattern[1] == test[0]) { |
| @@ -204,7 +204,7 @@ static bool MatchBrackets( const char * pattern, const char * test ) · 41 unmodified lines | |||
| 204 | goto advance; | 204 | goto advance; |
| 205 | } | 205 | } |
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | if(p[0] == test[0]) { | 208 | if(p[0] == test[0]) { |
| 209 | result = !negated; | 209 | result = !negated; |
| 210 | goto advance; | 210 | goto advance; |
| @@ -304,7 +304,7 @@ University of California, Berkeley. · 93 unmodified lines | |||
| 304 | REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, | 304 | REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, |
| 305 | ENHANCEMENTS, OR MODIFICATIONS. | 305 | ENHANCEMENTS, OR MODIFICATIONS. |
| 306 | 306 | ||
| 307 | The OpenSound Control WWW page is | 307 | The OpenSound Control WWW page is |
| 308 | http://www.cnmat.berkeley.edu/OpenSoundControl | 308 | http://www.cnmat.berkeley.edu/OpenSoundControl |
| 309 | */ | 309 | */ |
| 310 | 310 | ||
| @@ -369,21 +369,21 @@ OSCTimeTag OSCTT_CurrentTime(void) { · 58 unmodified lines | |||
| 369 | BSDgettimeofday(&tv, &tz); | 369 | BSDgettimeofday(&tv, &tz); |
| 370 | 370 | ||
| 371 | /* First get the seconds right */ | 371 | /* First get the seconds right */ |
| 372 | result = (unsigned) SECONDS_FROM_1900_to_1970 + | 372 | result = (unsigned) SECONDS_FROM_1900_to_1970 + |
| 373 | (unsigned) tv.tv_sec - | 373 | (unsigned) tv.tv_sec - |
| 374 | (unsigned) 60 * tz.tz_minuteswest + | 374 | (unsigned) 60 * tz.tz_minuteswest + |
| 375 | (unsigned) (tz.tz_dsttime ? 3600 : 0); | 375 | (unsigned) (tz.tz_dsttime ? 3600 : 0); |
| 376 | 376 | ||
| 377 | #if 0 | 377 | #if 0 |
| 378 | /* No timezone, no DST version ... */ | 378 | /* No timezone, no DST version ... */ |
| 379 | result = (unsigned) SECONDS_FROM_1900_to_1970 + | 379 | result = (unsigned) SECONDS_FROM_1900_to_1970 + |
| 380 | (unsigned) tv.tv_sec; | 380 | (unsigned) tv.tv_sec; |
| 381 | #endif | 381 | #endif |
| 382 | 382 | ||
| 383 | 383 | ||
| 384 | /* make seconds the high-order 32 bits */ | 384 | /* make seconds the high-order 32 bits */ |
| 385 | result = result << 32; | 385 | result = result << 32; |
| 386 | 386 | ||
| 387 | /* Now get the fractional part. */ | 387 | /* Now get the fractional part. */ |
| 388 | usecOffset = (unsigned) tv.tv_usec * (unsigned) TWO_TO_THE_32_OVER_ONE_MILLION; | 388 | usecOffset = (unsigned) tv.tv_usec * (unsigned) TWO_TO_THE_32_OVER_ONE_MILLION; |
| 389 | /* printf("** %ld microsec is offset %x\n", tv.tv_usec, usecOffset); */ | 389 | /* printf("** %ld microsec is offset %x\n", tv.tv_usec, usecOffset); */ |
| @@ -397,7 +397,7 @@ OSCTimeTag OSCTT_CurrentTime(void) { · 7 unmodified lines | |||
| 397 | #else /* __sgi */ | 397 | #else /* __sgi */ |
| 398 | 398 | ||
| 399 | /* Instead of asking your operating system what time it is, it might be | 399 | /* 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 |
| 401 | starts audio processing, and then keep track of the number of samples | 401 | starts audio processing, and then keep track of the number of samples |
| 402 | output to know how much time has passed. */ | 402 | output to know how much time has passed. */ |
| 403 | 403 | ||
| @@ -484,7 +484,7 @@ University of California, Berkeley. · 80 unmodified lines | |||
| 484 | */ | 484 | */ |
| 485 | 485 | ||
| 486 | 486 | ||
| 487 | /* | 487 | /* |
| 488 | Author: Matt Wright | 488 | Author: Matt Wright |
| 489 | Version 2.2: Calls htonl in the right places 20000620 | 489 | Version 2.2: Calls htonl in the right places 20000620 |
| 490 | Version 2.3: Gets typed messages right. | 490 | Version 2.3: Gets typed messages right. |
| @@ -500,7 +500,7 @@ University of California, Berkeley. · 9 unmodified lines | |||
| 500 | #define GET_ARGS 3 /* Getting arguments to a message. If we see a message | 500 | #define GET_ARGS 3 /* Getting arguments to a message. If we see a message |
| 501 | name or a bundle open/close then the current message | 501 | name or a bundle open/close then the current message |
| 502 | will end. */ | 502 | 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 |
| 504 | anything else */ | 504 | anything else */ |
| 505 | 505 | ||
| 506 | 506 | ||
| @@ -521,7 +521,7 @@ void OSC_initBuffer(OSCbuf *buf, int size, char *byteArray) { · 14 unmodified lines | |||
| 521 | OSC_resetBuffer(buf); | 521 | OSC_resetBuffer(buf); |
| 522 | } | 522 | } |
| 523 | 523 | ||
| 524 | void OSC_resetBuffer(OSCbuf *buf) { | 524 | void OSC_resetBuffer(OSCbuf *buf) { |
| 525 | buf->bufptr = buf->buffer; | 525 | buf->bufptr = buf->buffer; |
| 526 | buf->state = EMPTY; | 526 | buf->state = EMPTY; |
| 527 | buf->bundleDepth = 0; | 527 | buf->bundleDepth = 0; |
| @@ -632,7 +632,7 @@ int OSC_openBundle(OSCbuf *buf, OSCTimeTag tt) · 104 unmodified lines | |||
| 632 | intp[1] = htonl(intp[1]); | 632 | intp[1] = htonl(intp[1]); |
| 633 | 633 | ||
| 634 | #ifdef HAS8BYTEINT | 634 | #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. |
| 636 | (Otherwise tt is a struct of two 32-bit words, and even though | 636 | (Otherwise tt is a struct of two 32-bit words, and even though |
| 637 | each word was wrong-endian, they were in the right order | 637 | each word was wrong-endian, they were in the right order |
| 638 | in the struct.) */ | 638 | in the struct.) */ |
| @@ -696,7 +696,7 @@ int OSC_closeAllBundles(OSCbuf *buf) · 57 unmodified lines | |||
| 696 | while (buf->bundleDepth > 0) { | 696 | while (buf->bundleDepth > 0) { |
| 697 | OSC_closeBundle(buf); | 697 | OSC_closeBundle(buf); |
| 698 | } | 698 | } |
| 699 | 699 | ||
| 700 | buf->typeStringPtr = 0; | 700 | buf->typeStringPtr = 0; |
| 701 | return 0; | 701 | return 0; |
| 702 | } | 702 | } |
| @@ -757,11 +757,11 @@ int OSC_writeAddressAndTypes(OSCbuf *buf, char *name, char *types) · 54 unmodified lines | |||
| 757 | 757 | ||
| 758 | paddedLength = OSC_effectiveStringLength(types); | 758 | paddedLength = OSC_effectiveStringLength(types); |
| 759 | 759 | ||
| 760 | CheckOverflow(buf, paddedLength); | 760 | CheckOverflow(buf, paddedLength); |
| 761 | 761 | ||
| 762 | buf->typeStringPtr = buf->bufptr + 1; /* skip comma */ | 762 | buf->typeStringPtr = buf->bufptr + 1; /* skip comma */ |
| 763 | buf->bufptr += OSC_padString(buf->bufptr, types); | 763 | buf->bufptr += OSC_padString(buf->bufptr, types); |
| 764 | 764 | ||
| 765 | buf->gettingFirstUntypedArg = 0; | 765 | buf->gettingFirstUntypedArg = 0; |
| 766 | 766 | ||
| 767 | return 0; | 767 | return 0; |
| @@ -783,9 +783,9 @@ static int CheckTypeTag(OSCbuf *buf, char expectedType) · 15 unmodified lines | |||
| 783 | printf("* Expected %c, string now %s\n", expectedType, buf->typeStringPtr); | 783 | printf("* Expected %c, string now %s\n", expectedType, buf->typeStringPtr); |
| 784 | } | 784 | } |
| 785 | 785 | ||
| 786 | return 9; | 786 | return 9; |
| 787 | } | 787 | } |
| 788 | 788 | ||
| 789 | ++(buf->typeStringPtr); | 789 | ++(buf->typeStringPtr); |
| 790 | } | 790 | } |
| 791 | 791 | ||
| @@ -863,7 +863,7 @@ int OSC_writeStringArg(OSCbuf *buf, char *arg) · 71 unmodified lines | |||
| 863 | tag string. */ | 863 | tag string. */ |
| 864 | 864 | ||
| 865 | CheckOverflow(buf, len+4); /* Too conservative */ | 865 | CheckOverflow(buf, len+4); /* Too conservative */ |
| 866 | buf->bufptr += | 866 | buf->bufptr += |
| 867 | OSC_padStringWithAnExtraStupidComma(buf->bufptr, arg); | 867 | OSC_padStringWithAnExtraStupidComma(buf->bufptr, arg); |
| 868 | } else { | 868 | } else { |
| 869 | CheckOverflow(buf, len); | 869 | CheckOverflow(buf, len); |
| @@ -889,7 +889,7 @@ static int strlen(char *s) { · 19 unmodified lines | |||
| 889 | int OSC_effectiveStringLength(char *string) | 889 | int OSC_effectiveStringLength(char *string) |
| 890 | { | 890 | { |
| 891 | t_CKINT len = strlen(string) + 1; /* We need space for the null char. */ | 891 | t_CKINT len = strlen(string) + 1; /* We need space for the null char. */ |
| 892 | 892 | ||
| 893 | /* Round up len to next multiple of STRING_ALIGN_PAD to account for alignment padding */ | 893 | /* Round up len to next multiple of STRING_ALIGN_PAD to account for alignment padding */ |
| 894 | if((len % STRING_ALIGN_PAD) != 0) { | 894 | if((len % STRING_ALIGN_PAD) != 0) { |
| 895 | len += STRING_ALIGN_PAD - (len % STRING_ALIGN_PAD); | 895 | len += STRING_ALIGN_PAD - (len % STRING_ALIGN_PAD); |
| @@ -902,11 +902,11 @@ int OSC_effectiveStringLength(char *string) · 6 unmodified lines | |||
| 902 | static int OSC_padString(char *dest, const char *str) | 902 | static int OSC_padString(char *dest, const char *str) |
| 903 | { | 903 | { |
| 904 | int i; | 904 | int i; |
| 905 | 905 | ||
| 906 | for(i = 0; str[i] != '\0'; i++) { | 906 | for(i = 0; str[i] != '\0'; i++) { |
| 907 | dest[i] = str[i]; | 907 | dest[i] = str[i]; |
| 908 | } | 908 | } |
| 909 | 909 | ||
| 910 | return OSC_WritePadding(dest, i); | 910 | return OSC_WritePadding(dest, i); |
| 911 | } | 911 | } |
| 912 | 912 | ||
| @@ -914,7 +914,7 @@ static int OSC_padString(char *dest, const char *str) · 1 unmodified line | |||
| 914 | static int OSC_padStringWithAnExtraStupidComma(char *dest, const char *str) | 914 | static int OSC_padStringWithAnExtraStupidComma(char *dest, const char *str) |
| 915 | { | 915 | { |
| 916 | int i; | 916 | int i; |
| 917 | 917 | ||
| 918 | dest[0] = ','; | 918 | dest[0] = ','; |
| 919 | for(i = 0; str[i] != '\0'; i++) { | 919 | for(i = 0; str[i] != '\0'; i++) { |
| 920 | dest[i+1] = str[i]; | 920 | dest[i+1] = str[i]; |
| @@ -922,7 +922,7 @@ static int OSC_padStringWithAnExtraStupidComma(char *dest, const char *str) · 1 unmodified line | |||
| 922 | 922 | ||
| 923 | return OSC_WritePadding(dest, i+1); | 923 | return OSC_WritePadding(dest, i+1); |
| 924 | } | 924 | } |
| 925 | 925 | ||
| 926 | 926 | ||
| 927 | static int OSC_WritePadding(char *dest, int i) | 927 | static int OSC_WritePadding(char *dest, int i) |
| 928 | { | 928 | { |
| @@ -948,7 +948,7 @@ static int OSC_WritePadding(char *dest, int i) · 19 unmodified lines | |||
| 948 | #include "util_network.h" | 948 | #include "util_network.h" |
| 949 | #include "util_thread.h" | 949 | #include "util_thread.h" |
| 950 | 950 | ||
| 951 | // FROM PLATFORM.H -UDP TRANSMITTER / RECEIVER | 951 | // FROM PLATFORM.H -UDP TRANSMITTER / RECEIVER |
| 952 | 952 | ||
| 953 | #if defined(__PLATFORM_WIN32__) | 953 | #if defined(__PLATFORM_WIN32__) |
| 954 | #include <winsock.h> | 954 | #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 | |||
| 975 | 975 | ||
| 976 | /* in the .h so that OSC can subclass it | 976 | /* in the .h so that OSC can subclass it |
| 977 | 977 | ||
| 978 | class UDP_Subscriber { | 978 | class UDP_Subscriber { |
| 979 | virtual void onRecieve( char * mesg, int mesgLen ) = 0; | 979 | virtual void onRecieve( char * mesg, int mesgLen ) = 0; |
| 980 | virtual bool subscribe( int port ); | 980 | virtual bool subscribe( int port ); |
| 981 | virtual bool unsubscribe(); | 981 | 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. |
| 983 | } | 983 | } |
| 984 | 984 | ||
| 985 | */ | 985 | */ |
| 986 | 986 | ||
| 987 | class DefUDP_Subscriber : public UDP_Subscriber { | 987 | class DefUDP_Subscriber : public UDP_Subscriber { |
| 988 | public: | 988 | public: |
| 989 | int _port; | 989 | int _port; |
| 990 | void onReceive ( char * mesg, int mesgLen ) {} // ignore | 990 | void onReceive ( char * mesg, int mesgLen ) {} // ignore |
| 991 | int& port() { return _port; } | 991 | int& port() { return _port; } |
| 992 | }; | 992 | }; |
| 993 | 993 | ||
| 994 | class UDP_Port_Listener { | 994 | class UDP_Port_Listener { |
| 995 | private: | 995 | private: |
| 996 | UDP_Receiver* m_in; | 996 | UDP_Receiver* m_in; |
| 997 | bool m_port; | 997 | bool m_port; |
| 998 | 998 | ||
| 999 | XThread* m_thread; | 999 | XThread* m_thread; |
| 1000 | XMutex* m_mutex; | 1000 | XMutex* m_mutex; |
| 1001 | 1001 | ||
| @@ -1015,9 +1015,9 @@ public: · 13 unmodified lines | |||
| 1015 | int recv_mesg(); | 1015 | int recv_mesg(); |
| 1016 | bool add ( UDP_Subscriber * ); | 1016 | bool add ( UDP_Subscriber * ); |
| 1017 | bool drop ( UDP_Subscriber * ); | 1017 | bool drop ( UDP_Subscriber * ); |
| 1018 | int nsubs(); | 1018 | int nsubs(); |
| 1019 | 1019 | ||
| 1020 | bool listening; | 1020 | bool listening; |
| 1021 | }; | 1021 | }; |
| 1022 | 1022 | ||
| 1023 | 1023 | ||
| @@ -1055,9 +1055,9 @@ public: · 31 unmodified lines | |||
| 1055 | ~UDP_Receiver() { } | 1055 | ~UDP_Receiver() { } |
| 1056 | void init(); | 1056 | void init(); |
| 1057 | bool bind_to_port(int port); | 1057 | bool bind_to_port(int port); |
| 1058 | int recv_next(char *buffer, int size); | 1058 | int recv_next(char *buffer, int size); |
| 1059 | void close_sock(); | 1059 | void close_sock(); |
| 1060 | udp_stat status(); | 1060 | udp_stat status(); |
| 1061 | }; | 1061 | }; |
| 1062 | 1062 | ||
| 1063 | 1063 | ||
| @@ -1069,17 +1069,17 @@ protected: · 5 unmodified lines | |||
| 1069 | ck_socket _sock; | 1069 | ck_socket _sock; |
| 1070 | SOCKADDR_IN _host_addr; | 1070 | SOCKADDR_IN _host_addr; |
| 1071 | udp_stat _status; | 1071 | udp_stat _status; |
| 1072 | 1072 | ||
| 1073 | public: | 1073 | public: |
| 1074 | UDP_Transmitter() { | 1074 | UDP_Transmitter() { |
| 1075 | _status = UDP_NOINIT; | 1075 | _status = UDP_NOINIT; |
| 1076 | } | 1076 | } |
| 1077 | virtual ~UDP_Transmitter() {} | 1077 | virtual ~UDP_Transmitter() {} |
| 1078 | void init(); | 1078 | void init(); |
| 1079 | 1079 | ||
| 1080 | void set_host(char * hostaddress, int port); | 1080 | void set_host(char * hostaddress, int port); |
| 1081 | int send(char *buffer, int size); | 1081 | int send(char *buffer, int size); |
| 1082 | udp_stat status(void) { return _status; } | 1082 | udp_stat status(void) { return _status; } |
| 1083 | void close_sock(); | 1083 | void close_sock(); |
| 1084 | }; | 1084 | }; |
| 1085 | 1085 | ||
| @@ -1092,8 +1092,8 @@ UDP_Port_Manager * UDP_Port_Manager::instance() · 6 unmodified lines | |||
| 1092 | _inst = new UDP_Port_Manager(); | 1092 | _inst = new UDP_Port_Manager(); |
| 1093 | assert( _inst ); | 1093 | assert( _inst ); |
| 1094 | } | 1094 | } |
| 1095 | 1095 | ||
| 1096 | return _inst; | 1096 | return _inst; |
| 1097 | } | 1097 | } |
| 1098 | 1098 | ||
| 1099 | UDP_Port_Manager::UDP_Port_Manager() { | 1099 | UDP_Port_Manager::UDP_Port_Manager() { |
| @@ -1121,26 +1121,26 @@ bool UDP_Port_Manager::unsubscribe( UDP_Subscriber * sub ) · 21 unmodified lines | |||
| 1121 | if( sub->port() < 0 ) | 1121 | if( sub->port() < 0 ) |
| 1122 | { | 1122 | { |
| 1123 | EM_log( CK_LOG_INFO, "error, subscriber's port < 0, return false" ); | 1123 | EM_log( CK_LOG_INFO, "error, subscriber's port < 0, return false" ); |
| 1124 | return false; | 1124 | return false; |
| 1125 | } | 1125 | } |
| 1126 | 1126 | ||
| 1127 | if( _listeners.count( sub->port() ) == 0 ) | 1127 | if( _listeners.count( sub->port() ) == 0 ) |
| 1128 | { | 1128 | { |
| 1129 | EM_log( CK_LOG_INFO, "error, cannot unsubscribe: port %d not in use", sub->port() ); | 1129 | EM_log( CK_LOG_INFO, "error, cannot unsubscribe: port %d not in use", sub->port() ); |
| 1130 | return false; | 1130 | return false; |
| 1131 | } | 1131 | } |
| 1132 | else | 1132 | else |
| 1133 | { | 1133 | { |
| 1134 | int pp = sub->port(); | 1134 | int pp = sub->port(); |
| 1135 | UDP_Port_Listener * listener = _listeners[pp]; | 1135 | UDP_Port_Listener * listener = _listeners[pp]; |
| 1136 | bool ret = listener->drop( sub ); | 1136 | bool ret = listener->drop( sub ); |
| 1137 | //check empty | 1137 | //check empty |
| 1138 | if( listener->nsubs() == 0 ) { | 1138 | if( listener->nsubs() == 0 ) { |
| 1139 | EM_log( CK_LOG_INFO, "PortManager: Listener on port %d is empty - removing", sub->port() ); | 1139 | EM_log( CK_LOG_INFO, "PortManager: Listener on port %d is empty - removing", sub->port() ); |
| 1140 | delete listener; | 1140 | delete listener; |
| 1141 | _listeners.erase( pp ); | 1141 | _listeners.erase( pp ); |
| 1142 | } | 1142 | } |
| 1143 | return ret; | 1143 | return ret; |
| 1144 | } | 1144 | } |
| 1145 | } | 1145 | } |
| 1146 | 1146 | ||
| @@ -1156,7 +1156,7 @@ UDP_Port_Listener::~UDP_Port_Listener() · 9 unmodified lines | |||
| 1156 | { | 1156 | { |
| 1157 | //CK_FPRINTF_STDERR( "port listener destructor\n" ); | 1157 | //CK_FPRINTF_STDERR( "port listener destructor\n" ); |
| 1158 | close(); | 1158 | close(); |
| 1159 | // usleep( 10 ); // do we need this ? | 1159 | // usleep( 10 ); // do we need this ? |
| 1160 | delete m_in; | 1160 | delete m_in; |
| 1161 | delete m_mutex; | 1161 | delete m_mutex; |
| 1162 | delete m_thread; | 1162 | delete m_thread; |
| @@ -1180,7 +1180,7 @@ bool UDP_Port_Listener::add( UDP_Subscriber * sub ) · 17 unmodified lines | |||
| 1180 | { | 1180 | { |
| 1181 | EM_log(CK_LOG_INFO, "UDP_Port_Listener: adding subscriber" ); | 1181 | EM_log(CK_LOG_INFO, "UDP_Port_Listener: adding subscriber" ); |
| 1182 | m_subscribers.push_back( sub ); | 1182 | m_subscribers.push_back( sub ); |
| 1183 | sub->port() = m_port; | 1183 | sub->port() = m_port; |
| 1184 | m_mutex->release(); | 1184 | m_mutex->release(); |
| 1185 | return true; | 1185 | return true; |
| 1186 | } | 1186 | } |
| @@ -1271,7 +1271,7 @@ void UDP_Port_Listener::close() · 84 unmodified lines | |||
| 1271 | int UDP_Port_Listener::recv_mesg() | 1271 | int UDP_Port_Listener::recv_mesg() |
| 1272 | { | 1272 | { |
| 1273 | int mLen = m_in->recv_next( m_inbuf, m_inbufsize ); | 1273 | int mLen = m_in->recv_next( m_inbuf, m_inbufsize ); |
| 1274 | 1274 | ||
| 1275 | if( mLen == 0 ) | 1275 | if( mLen == 0 ) |
| 1276 | { | 1276 | { |
| 1277 | EM_log( CK_LOG_INFO, "recvLen 0 on socket, returning 0" ); | 1277 | EM_log( CK_LOG_INFO, "recvLen 0 on socket, returning 0" ); |
| @@ -1298,12 +1298,12 @@ bool UDP_Subscriber::subscribe( int p ) · 20 unmodified lines | |||
| 1298 | return false; // already subscribed | 1298 | return false; // already subscribed |
| 1299 | } | 1299 | } |
| 1300 | else if( UDP_Port_Manager::instance()->subscribe( this, p ) ) | 1300 | else if( UDP_Port_Manager::instance()->subscribe( this, p ) ) |
| 1301 | { | 1301 | { |
| 1302 | port() = p; | 1302 | port() = p; |
| 1303 | return true; | 1303 | return true; |
| 1304 | } | 1304 | } |
| 1305 | else | 1305 | else |
| 1306 | { | 1306 | { |
| 1307 | port() = -1; | 1307 | port() = -1; |
| 1308 | return false; | 1308 | return false; |
| 1309 | } | 1309 | } |
| @@ -1322,22 +1322,22 @@ bool UDP_Subscriber::unsubscribe() · 12 unmodified lines | |||
| 1322 | } | 1322 | } |
| 1323 | else | 1323 | else |
| 1324 | { | 1324 | { |
| 1325 | return false; // could not unsubscribe? | 1325 | return false; // could not unsubscribe? |
| 1326 | } | 1326 | } |
| 1327 | } | 1327 | } |
| 1328 | 1328 | ||
| 1329 | 1329 | ||
| 1330 | 1330 | ||
| 1331 | UDP_Receiver::UDP_Receiver() | 1331 | UDP_Receiver::UDP_Receiver() |
| 1332 | { | 1332 | { |
| 1333 | _status = UDP_NOINIT; | 1333 | _status = UDP_NOINIT; |
| 1334 | } | 1334 | } |
| 1335 | 1335 | ||
| 1336 | 1336 | ||
| 1337 | void UDP_Receiver::init() | 1337 | void UDP_Receiver::init() |
| 1338 | { | 1338 | { |
| 1339 | //open port | 1339 | //open port |
| 1340 | _sock = ck_udp_create(); | 1340 | _sock = ck_udp_create(); |
| 1341 | _status = ( _sock != NULL ) ? UDP_UNBOUND : UDP_ERROR; | 1341 | _status = ( _sock != NULL ) ? UDP_UNBOUND : UDP_ERROR; |
| 1342 | } | 1342 | } |
| 1343 | 1343 | ||
| @@ -1358,10 +1358,10 @@ bool UDP_Receiver::bind_to_port(int port) · 14 unmodified lines | |||
| 1358 | udp_stat UDP_Receiver::status() { return _status; } | 1358 | udp_stat UDP_Receiver::status() { return _status; } |
| 1359 | 1359 | ||
| 1360 | int UDP_Receiver::recv_next(char * buffer, int bsize) | 1360 | int UDP_Receiver::recv_next(char * buffer, int bsize) |
| 1361 | { | 1361 | { |
| 1362 | if( _status != UDP_BOUND ) | 1362 | if( _status != UDP_BOUND ) |
| 1363 | { | 1363 | { |
| 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; |
| 1365 | } | 1365 | } |
| 1366 | 1366 | ||
| 1367 | _remote_addr_len = sizeof(_remote_addr); | 1367 | _remote_addr_len = sizeof(_remote_addr); |
| @@ -1382,7 +1382,7 @@ void UDP_Transmitter::init() · 14 unmodified lines | |||
| 1382 | { | 1382 | { |
| 1383 | //open socket | 1383 | //open socket |
| 1384 | _sock = ck_udp_create(); | 1384 | _sock = ck_udp_create(); |
| 1385 | _status = ( _sock != NULL ) ? UDP_READY : UDP_ERROR; | 1385 | _status = ( _sock != NULL ) ? UDP_READY : UDP_ERROR; |
| 1386 | } | 1386 | } |
| 1387 | 1387 | ||
| 1388 | 1388 | ||
| @@ -1407,7 +1407,7 @@ void UDP_Transmitter::set_host( char * hostaddress, int port ) · 18 unmodified lines | |||
| 1407 | } | 1407 | } |
| 1408 | memcpy(&_host_addr.sin_addr, host->h_addr_list[0], host->h_length); | 1408 | memcpy(&_host_addr.sin_addr, host->h_addr_list[0], host->h_length); |
| 1409 | // printf(" ...set\n"); | 1409 | // printf(" ...set\n"); |
| 1410 | } | 1410 | } |
| 1411 | // else printf(" ...set\n"); | 1411 | // else printf(" ...set\n"); |
| 1412 | _status = UDP_READY; | 1412 | _status = UDP_READY; |
| 1413 | } | 1413 | } |
| @@ -1433,43 +1433,43 @@ void UDP_Transmitter::close_sock() · 19 unmodified lines | |||
| 1433 | 1433 | ||
| 1434 | // OSC_TRANSMITTER | 1434 | // OSC_TRANSMITTER |
| 1435 | 1435 | ||
| 1436 | OSC_Transmitter::OSC_Transmitter() { | 1436 | OSC_Transmitter::OSC_Transmitter() { |
| 1437 | _out = new UDP_Transmitter(); | 1437 | _out = new UDP_Transmitter(); |
| 1438 | _holdMessage = false; | 1438 | _holdMessage = false; |
| 1439 | init(); | 1439 | init(); |
| 1440 | } | 1440 | } |
| 1441 | 1441 | ||
| 1442 | OSC_Transmitter::OSC_Transmitter( UDP_Transmitter * out ) { | 1442 | OSC_Transmitter::OSC_Transmitter( UDP_Transmitter * out ) { |
| 1443 | _out = out; | 1443 | _out = out; |
| 1444 | _holdMessage = false; | 1444 | _holdMessage = false; |
| 1445 | } | 1445 | } |
| 1446 | 1446 | ||
| 1447 | OSC_Transmitter::~OSC_Transmitter() { delete _out; } | 1447 | OSC_Transmitter::~OSC_Transmitter() { delete _out; } |
| 1448 | 1448 | ||
| 1449 | void | 1449 | void |
| 1450 | OSC_Transmitter::init() { | 1450 | OSC_Transmitter::init() { |
| 1451 | if( _out->status() == UDP_NOINIT ) _out->init(); | 1451 | if( _out->status() == UDP_NOINIT ) _out->init(); |
| 1452 | OSC_initBuffer(&_osc, sizeof(_buffer), _buffer ); | 1452 | OSC_initBuffer(&_osc, sizeof(_buffer), _buffer ); |
| 1453 | } | 1453 | } |
| 1454 | 1454 | ||
| 1455 | void | 1455 | void |
| 1456 | OSC_Transmitter::setHost( char * hadd, int p ) { | 1456 | OSC_Transmitter::setHost( char * hadd, int p ) { |
| 1457 | _out->set_host(hadd, p); | 1457 | _out->set_host(hadd, p); |
| 1458 | } | 1458 | } |
| 1459 | 1459 | ||
| 1460 | void | 1460 | void |
| 1461 | OSC_Transmitter::presend( char * buf, int sz ) { | 1461 | OSC_Transmitter::presend( char * buf, int sz ) { |
| 1462 | _out->send(buf,sz); | 1462 | _out->send(buf,sz); |
| 1463 | } | 1463 | } |
| 1464 | 1464 | ||
| 1465 | void | 1465 | void |
| 1466 | OSC_Transmitter::openBundle( OSCTimeTag t) { | 1466 | OSC_Transmitter::openBundle( OSCTimeTag t) { |
| 1467 | OSC_openBundle( &_osc, t); | 1467 | OSC_openBundle( &_osc, t); |
| 1468 | } | 1468 | } |
| 1469 | 1469 | ||
| 1470 | 1470 | ||
| 1471 | void | 1471 | void |
| 1472 | OSC_Transmitter::closeBundle() { | 1472 | OSC_Transmitter::closeBundle() { |
| 1473 | OSC_closeBundle( &_osc ); | 1473 | OSC_closeBundle( &_osc ); |
| 1474 | tryMessage(); | 1474 | tryMessage(); |
| 1475 | } | 1475 | } |
| @@ -1485,13 +1485,13 @@ OSC_Transmitter::addMessage( char *address, char * args, ...) · 9 unmodified lines | |||
| 1485 | 1485 | ||
| 1486 | va_list tags; // pointer to list of arguments | 1486 | va_list tags; // pointer to list of arguments |
| 1487 | va_start(tags, args); // parses the string for variables | 1487 | va_start(tags, args); // parses the string for variables |
| 1488 | 1488 | ||
| 1489 | OSC_writeAddressAndTypes( &_osc, address, args ); | 1489 | OSC_writeAddressAndTypes( &_osc, address, args ); |
| 1490 | 1490 | ||
| 1491 | t_CKINT argnum = strlen(args); | 1491 | t_CKINT argnum = strlen(args); |
| 1492 | t_CKINT osc_err = 0; | 1492 | t_CKINT osc_err = 0; |
| 1493 | for(t_CKINT j = 1; !osc_err && j < argnum; j++ ) { | 1493 | for(t_CKINT j = 1; !osc_err && j < argnum; j++ ) { |
| 1494 | switch ( args[j] ) { | 1494 | switch ( args[j] ) { |
| 1495 | case 'i': | 1495 | case 'i': |
| 1496 | osc_err = OSC_writeIntArg ( &_osc, va_arg(tags, int) ); | 1496 | osc_err = OSC_writeIntArg ( &_osc, va_arg(tags, int) ); |
| 1497 | break; | 1497 | break; |
| @@ -1500,11 +1500,11 @@ OSC_Transmitter::addMessage( char *address, char * args, ...) · 2 unmodified lines | |||
| 1500 | break; | 1500 | break; |
| 1501 | case 's': | 1501 | case 's': |
| 1502 | osc_err = OSC_writeStringArg ( &_osc, va_arg(tags, char *) ); | 1502 | osc_err = OSC_writeStringArg ( &_osc, va_arg(tags, char *) ); |
| 1503 | break; | 1503 | break; |
| 1504 | } | 1504 | } |
| 1505 | } | 1505 | } |
| 1506 | 1506 | ||
| 1507 | if( osc_err ) { | 1507 | if( osc_err ) { |
| 1508 | EM_log( CK_LOG_SYSTEM, "(via OSC): error writing packet: %d %s...", osc_err, OSC_errorMessage ); | 1508 | EM_log( CK_LOG_SYSTEM, "(via OSC): error writing packet: %d %s...", osc_err, OSC_errorMessage ); |
| 1509 | // failure action??? | 1509 | // failure action??? |
| 1510 | } | 1510 | } |
| @@ -1514,43 +1514,43 @@ OSC_Transmitter::addMessage( char *address, char * args, ...) · 3 unmodified lines | |||
| 1514 | } | 1514 | } |
| 1515 | 1515 | ||
| 1516 | void | 1516 | void |
| 1517 | OSC_Transmitter::startMessage( char * spec ) { | 1517 | OSC_Transmitter::startMessage( char * spec ) { |
| 1518 | 1518 | ||
| 1519 | t_CKINT len = strlen( spec ); | 1519 | t_CKINT len = strlen( spec ); |
| 1520 | 1520 | ||
| 1521 | char * comma = strchr( spec, ','); | 1521 | char * comma = strchr( spec, ','); |
| 1522 | char * space = strchr ( spec, ' '); | 1522 | char * space = strchr ( spec, ' '); |
| 1523 | int coff = ( comma == NULL ) ? len : comma - spec; | 1523 | int coff = ( comma == NULL ) ? len : comma - spec; |
| 1524 | int spoff = ( space == NULL ) ? len : space - spec; | 1524 | int spoff = ( space == NULL ) ? len : space - spec; |
| 1525 | int off = min ( coff, spoff ); | 1525 | int off = min ( coff, spoff ); |
| 1526 | 1526 | ||
| 1527 | if( off < len ) | 1527 | if( off < len ) |
| 1528 | spec[off] = '\0'; | 1528 | spec[off] = '\0'; |
| 1529 | 1529 | ||
| 1530 | startMessage( spec, spec + off + 1 ); | 1530 | startMessage( spec, spec + off + 1 ); |
| 1531 | } | 1531 | } |
| 1532 | 1532 | ||
| 1533 | void | 1533 | void |
| 1534 | OSC_Transmitter::startMessage( char * address, char * args ) | 1534 | OSC_Transmitter::startMessage( char * address, char * args ) |
| 1535 | { | 1535 | { |
| 1536 | // OSC_writeAddressAndTypes( &_osc, address, args ); | 1536 | // OSC_writeAddressAndTypes( &_osc, address, args ); |
| 1537 | char addrfix[512]; | 1537 | char addrfix[512]; |
| 1538 | t_CKINT addrlen = strlen( address ); | 1538 | t_CKINT addrlen = strlen( address ); |
| 1539 | // int mx = strlen(address) + strlen(args) + 1; // either we need to add a comma to args, | 1539 | // 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. |
| 1541 | // char addrfix[] = new char[mx]; // (char*) malloc( mx * sizeof( char ) ); | 1541 | // char addrfix[] = new char[mx]; // (char*) malloc( mx * sizeof( char ) ); |
| 1542 | strcpy ( addrfix, address ); | 1542 | strcpy ( addrfix, address ); |
| 1543 | addrfix[addrlen] = '\0'; | 1543 | addrfix[addrlen] = '\0'; |
| 1544 | addrfix[addrlen+1] = ','; | 1544 | addrfix[addrlen+1] = ','; |
| 1545 | char * argptr = addrfix + (addrlen + 2); | 1545 | char * argptr = addrfix + (addrlen + 2); |
| 1546 | char * p_args = args; | 1546 | char * p_args = args; |
| 1547 | while ( *p_args != '\0' ) { | 1547 | while ( *p_args != '\0' ) { |
| 1548 | if( *p_args != ',' && *p_args != ' ' ) { | 1548 | if( *p_args != ',' && *p_args != ' ' ) { |
| 1549 | *argptr = *p_args; | 1549 | *argptr = *p_args; |
| 1550 | argptr++; | 1550 | argptr++; |
| 1551 | } | 1551 | } |
| 1552 | p_args++; | 1552 | p_args++; |
| 1553 | } | 1553 | } |
| 1554 | *argptr = '\0'; | 1554 | *argptr = '\0'; |
| 1555 | 1555 | ||
| 1556 | OSC_writeAddressAndTypes( &_osc, addrfix, addrfix + addrlen + 1); //expects the ',' before spec tag. | 1556 | 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 | |||
| 1560 | } | 1560 | } |
| 1561 | 1561 | ||
| 1562 | void | 1562 | void |
| 1563 | OSC_Transmitter::addInt ( int4byte i ) { | 1563 | OSC_Transmitter::addInt ( int4byte i ) { |
| 1564 | int osc_err = OSC_writeIntArg ( &_osc, i ); | 1564 | int osc_err = OSC_writeIntArg ( &_osc, i ); |
| 1565 | if( osc_err ) { | 1565 | if( osc_err ) { |
| 1566 | CK_FPRINTF_STDERR( "[chuck](via OSC): error writing packet: %d %s\n", osc_err, OSC_errorMessage ); | 1566 | CK_FPRINTF_STDERR( "[chuck](via OSC): error writing packet: %d %s\n", osc_err, OSC_errorMessage ); |
| 1567 | //failure action??? | 1567 | //failure action??? |
| 1568 | } | 1568 | } |
| 1569 | tryMessage(); | 1569 | tryMessage(); |
| 1570 | } | 1570 | } |
| 1571 | 1571 | ||
| 1572 | void | 1572 | void |
| 1573 | OSC_Transmitter::addFloat ( float f ) { | 1573 | OSC_Transmitter::addFloat ( float f ) { |
| 1574 | int osc_err = OSC_writeFloatArg ( &_osc, f ); | 1574 | int osc_err = OSC_writeFloatArg ( &_osc, f ); |
| 1575 | if( osc_err ) { | 1575 | if( osc_err ) { |
| 1576 | CK_FPRINTF_STDERR( "[chuck](via OSC): error writing packet: %d %s\n", osc_err, OSC_errorMessage ); | 1576 | CK_FPRINTF_STDERR( "[chuck](via OSC): error writing packet: %d %s\n", osc_err, OSC_errorMessage ); |
| 1577 | //failure action??? | 1577 | //failure action??? |
| 1578 | } | 1578 | } |
| 1579 | tryMessage(); | 1579 | tryMessage(); |
| 1580 | } | 1580 | } |
| 1581 | 1581 | ||
| 1582 | void | 1582 | void |
| 1583 | OSC_Transmitter::addString ( char * s ) { | 1583 | OSC_Transmitter::addString ( char * s ) { |
| 1584 | int osc_err = OSC_writeStringArg ( &_osc, s ); | 1584 | int osc_err = OSC_writeStringArg ( &_osc, s ); |
| 1585 | if( osc_err ) { | 1585 | if( osc_err ) { |
| 1586 | CK_FPRINTF_STDERR( "[chuck](via OSC): error writing packet: %d %s\n", osc_err, OSC_errorMessage ); | 1586 | CK_FPRINTF_STDERR( "[chuck](via OSC): error writing packet: %d %s\n", osc_err, OSC_errorMessage ); |
| 1587 | //failure action??? | 1587 | //failure action??? |
| 1588 | } | 1588 | } |
| 1589 | tryMessage(); | 1589 | tryMessage(); |
| 1590 | } | 1590 | } |
| 1591 | 1591 | ||
| 1592 | bool | 1592 | bool |
| 1593 | OSC_Transmitter::packetReady() { | 1593 | OSC_Transmitter::packetReady() { |
| 1594 | if( _holdMessage ) return false; //message hold is on | 1594 | if( _holdMessage ) return false; //message hold is on |
| 1595 | if( _osc.typeStringPtr ) { //if it's been typed, check that type is complete | 1595 | if( _osc.typeStringPtr ) { //if it's been typed, check that type is complete |
| 1596 | if( CheckTypeTag(&_osc, '\0' ) ) return false; | 1596 | if( CheckTypeTag(&_osc, '\0' ) ) return false; |
| 1597 | } | 1597 | } |
| 1598 | return ( OSC_isBufferDone(&_osc) != 0 ); | 1598 | return ( OSC_isBufferDone(&_osc) != 0 ); |
| 1599 | } | 1599 | } |
| 1600 | 1600 | ||
| 1601 | void | 1601 | void |
| 1602 | OSC_Transmitter::tryMessage() { | 1602 | OSC_Transmitter::tryMessage() { |
| 1603 | if( !packetReady() ) return; | 1603 | if( !packetReady() ) return; |
| 1604 | 1604 | ||
| 1605 | _out->send( OSC_getPacket(&_osc), OSC_packetSize(&_osc) ); | 1605 | _out->send( OSC_getPacket(&_osc), OSC_packetSize(&_osc) ); |
| @@ -1607,13 +1607,13 @@ OSC_Transmitter::tryMessage() { · 1 unmodified line | |||
| 1607 | } | 1607 | } |
| 1608 | 1608 | ||
| 1609 | void | 1609 | void |
| 1610 | OSC_Transmitter::holdMessage(bool b) { | 1610 | OSC_Transmitter::holdMessage(bool b) { |
| 1611 | _holdMessage = b; | 1611 | _holdMessage = b; |
| 1612 | } | 1612 | } |
| 1613 | 1613 | ||
| 1614 | void | 1614 | void |
| 1615 | OSC_Transmitter::kickMessage() { | 1615 | OSC_Transmitter::kickMessage() { |
| 1616 | if( !OSC_isBufferDone(&_osc) ) { | 1616 | if( !OSC_isBufferDone(&_osc) ) { |
| 1617 | CK_FPRINTF_STDERR( "[chuck](via OSC): error -> sending incomplete packet!\n" ); | 1617 | CK_FPRINTF_STDERR( "[chuck](via OSC): error -> sending incomplete packet!\n" ); |
| 1618 | } | 1618 | } |
| 1619 | _out->send( OSC_getPacket(&_osc), OSC_packetSize(&_osc) ); | 1619 | _out->send( OSC_getPacket(&_osc), OSC_packetSize(&_osc) ); |
| @@ -1691,7 +1691,7 @@ OSC_Receiver::~OSC_Receiver() · 71 unmodified lines | |||
| 1691 | 1691 | ||
| 1692 | // 1.3.1.1: moving this outside the loop, oops | 1692 | // 1.3.1.1: moving this outside the loop, oops |
| 1693 | free( _inbox ); | 1693 | free( _inbox ); |
| 1694 | 1694 | ||
| 1695 | // clean up | 1695 | // clean up |
| 1696 | SAFE_DELETE( _io_mutex ); | 1696 | SAFE_DELETE( _io_mutex ); |
| 1697 | SAFE_DELETE( _address_mutex ); | 1697 | SAFE_DELETE( _address_mutex ); |
| @@ -1702,7 +1702,7 @@ OSC_Receiver::~OSC_Receiver() · 4 unmodified lines | |||
| 1702 | // m_vmRef->destroy_event_buffer( m_event_buffer ); | 1702 | // m_vmRef->destroy_event_buffer( m_event_buffer ); |
| 1703 | // m_event_buffer = NULL; | 1703 | // m_event_buffer = NULL; |
| 1704 | // } | 1704 | // } |
| 1705 | 1705 | ||
| 1706 | // delete _in; | 1706 | // delete _in; |
| 1707 | } | 1707 | } |
| 1708 | 1708 | ||
| @@ -1726,19 +1726,19 @@ THREAD_RETURN (THREAD_TYPE osc_recv_thread)( void * data ) · 17 unmodified lines | |||
| 1726 | int& | 1726 | int& |
| 1727 | OSC_Receiver::port() { return _port; } | 1727 | OSC_Receiver::port() { return _port; } |
| 1728 | 1728 | ||
| 1729 | void | 1729 | void |
| 1730 | OSC_Receiver::onReceive( char * mesg, int mesgLen ) { | 1730 | OSC_Receiver::onReceive( char * mesg, int mesgLen ) { |
| 1731 | handle_mesg( mesg, mesgLen ); | 1731 | handle_mesg( mesg, mesgLen ); |
| 1732 | } | 1732 | } |
| 1733 | 1733 | ||
| 1734 | void | 1734 | void |
| 1735 | OSC_Receiver::bind_to_port(int port ) { | 1735 | OSC_Receiver::bind_to_port(int port ) { |
| 1736 | _tmp_port = port; | 1736 | _tmp_port = port; |
| 1737 | // _in->bind_to_port(port); | 1737 | // _in->bind_to_port(port); |
| 1738 | } | 1738 | } |
| 1739 | 1739 | ||
| 1740 | bool | 1740 | bool |
| 1741 | OSC_Receiver::listen( int port ) { | 1741 | OSC_Receiver::listen( int port ) { |
| 1742 | bind_to_port ( port ); | 1742 | bind_to_port ( port ); |
| 1743 | return listen(); | 1743 | return listen(); |
| 1744 | } | 1744 | } |
| @@ -1754,13 +1754,13 @@ OSC_Receiver::listen() · 9 unmodified lines | |||
| 1754 | { | 1754 | { |
| 1755 | if( m_event_buffer == NULL ) | 1755 | if( m_event_buffer == NULL ) |
| 1756 | m_event_buffer = m_vmRef->create_event_buffer(); | 1756 | m_event_buffer = m_vmRef->create_event_buffer(); |
| 1757 | 1757 | ||
| 1758 | unsubscribe(); // in case we're connected. | 1758 | unsubscribe(); // in case we're connected. |
| 1759 | 1759 | ||
| 1760 | return subscribe( _tmp_port ); | 1760 | return subscribe( _tmp_port ); |
| 1761 | 1761 | ||
| 1762 | /* | 1762 | /* |
| 1763 | if( !_listening ) { | 1763 | if( !_listening ) { |
| 1764 | _listening = true; | 1764 | _listening = true; |
| 1765 | _io_thread->start( osc_recv_thread, (void*)this ); | 1765 | _io_thread->start( osc_recv_thread, (void*)this ); |
| 1766 | } | 1766 | } |
| @@ -1771,31 +1771,31 @@ OSC_Receiver::listen() · 4 unmodified lines | |||
| 1771 | 1771 | ||
| 1772 | 1772 | ||
| 1773 | void | 1773 | void |
| 1774 | OSC_Receiver::close_sock() { | 1774 | OSC_Receiver::close_sock() { |
| 1775 | unsubscribe(); | 1775 | unsubscribe(); |
| 1776 | // _in->close_sock(); | 1776 | // _in->close_sock(); |
| 1777 | } | 1777 | } |
| 1778 | 1778 | ||
| 1779 | void | 1779 | void |
| 1780 | OSC_Receiver::recv_mesg() { | 1780 | OSC_Receiver::recv_mesg() { |
| 1781 | // this is when OSC_Receiver was | 1781 | // this is when OSC_Receiver was |
| 1782 | // used as the port-manager. now this code ( and callback ) are in UDP_Port_Listener interface, | 1782 | // 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 |
| 1784 | 1784 | ||
| 1785 | /* | 1785 | /* |
| 1786 | _mesglen = _in->recv_next( _inbuf, _inbufsize ); | 1786 | _mesglen = _in->recv_next( _inbuf, _inbufsize ); |
| 1787 | if( _mesglen > 0 ) { | 1787 | if( _mesglen > 0 ) { |
| 1788 | //parse(); | 1788 | //parse(); |
| 1789 | handle_mesg(_inbuf, _mesglen); | 1789 | handle_mesg(_inbuf, _mesglen); |
| 1790 | } | 1790 | } |
| 1791 | */ | 1791 | */ |
| 1792 | } | 1792 | } |
| 1793 | 1793 | ||
| 1794 | 1794 | ||
| 1795 | bool OSC_Receiver::has_mesg() | 1795 | bool OSC_Receiver::has_mesg() |
| 1796 | { | 1796 | { |
| 1797 | // EM_log( CK_LOG_FINER, "OSC has message?" ); | 1797 | // EM_log( CK_LOG_FINER, "OSC has message?" ); |
| 1798 | return ( _started && ( _in_read+1 ) % _inbox_size != _in_write ); | 1798 | return ( _started && ( _in_read+1 ) % _inbox_size != _in_write ); |
| 1799 | } | 1799 | } |
| 1800 | 1800 | ||
| 1801 | bool OSC_Receiver::get_mesg( OSCMesg * bucket ) | 1801 | bool OSC_Receiver::get_mesg( OSCMesg * bucket ) |
| @@ -1804,7 +1804,7 @@ bool OSC_Receiver::get_mesg( OSCMesg * bucket ) · 2 unmodified lines | |||
| 1804 | 1804 | ||
| 1805 | if( has_mesg() ) | 1805 | if( has_mesg() ) |
| 1806 | { | 1806 | { |
| 1807 | // next write _may_ fuck with _in_read | 1807 | // next write _may_ fuck with _in_read |
| 1808 | // where when resizing the buffer... | 1808 | // where when resizing the buffer... |
| 1809 | *bucket = *next_read(); | 1809 | *bucket = *next_read(); |
| 1810 | // CK_FPRINTF_STDERR( "r" ); //read: %d of %d \n", _in_read, _inbox_size); | 1810 | // 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 | |||
| 1826 | 1826 | ||
| 1827 | // log | 1827 | // log |
| 1828 | EM_log( CK_LOG_FINER, "OSC_Receiver: print message length %d", mesgLen ); | 1828 | EM_log( CK_LOG_FINER, "OSC_Receiver: print message length %d", mesgLen ); |
| 1829 | 1829 | ||
| 1830 | for( i = 0 ; i < mesgLen; i++ ) | 1830 | for( i = 0 ; i < mesgLen; i++ ) |
| 1831 | { | 1831 | { |
| 1832 | CK_FPRINTF_STDERR( "\t%c(%0x):", mesg[i], mesg[i] ); | 1832 | 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 | |||
| 1837 | 1837 | ||
| 1838 | void | 1838 | void |
| 1839 | OSC_Receiver::next_write() | 1839 | OSC_Receiver::next_write() |
| 1840 | { | 1840 | { |
| 1841 | // called by the UDP client ( blocks ) | 1841 | // called by the UDP client ( blocks ) |
| 1842 | 1842 | ||
| 1843 | if( !_started ) { | 1843 | if( !_started ) { |
| 1844 | _started = true; | 1844 | _started = true; |
| 1845 | } | 1845 | } |
| 1846 | 1846 | ||
| 1847 | int next = (_in_write+1) % _inbox_size; | 1847 | int next = (_in_write+1) % _inbox_size; |
| 1848 | 1848 | ||
| 1849 | if( next == _in_read ) { | 1849 | if( next == _in_read ) { |
| 1850 | 1850 | ||
| 1851 | // CK_FPRINTF_STDERR( "OSC::need to resize..." ); | 1851 | // CK_FPRINTF_STDERR( "OSC::need to resize..." ); |
| 1852 | 1852 | ||
| 1853 | _io_mutex->acquire(); //don't let next read return a bogus pointer | 1853 | _io_mutex->acquire(); //don't let next read return a bogus pointer |
| 1854 | 1854 | ||
| 1855 | if( _inbox_size < OSCINBOXMAX) { | 1855 | if( _inbox_size < OSCINBOXMAX) { |
| 1856 | 1856 | ||
| 1857 | // LOCK MUTEX (on next_read) | 1857 | // LOCK MUTEX (on next_read) |
| 1858 | // prevents | 1858 | // prevents |
| 1859 | 1859 | ||
| 1860 | // mesgs might move around, but their data doesn't..(this is good).. | 1860 | // mesgs might move around, but their data doesn't..(this is good).. |
| 1861 | // if we return an OSCmesg* to an out-of-thread function, it can expire. | 1861 | // 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 | |||
| 1866 | // perhaps a monolithic chunk of memory is a better option... | 1866 | // perhaps a monolithic chunk of memory is a better option... |
| 1867 | // but what if we want to handle multiple messages at once? | 1867 | // but what if we want to handle multiple messages at once? |
| 1868 | 1868 | ||
| 1869 | // orrr..if we follow timetags and need semirandom access to | 1869 | // orrr..if we follow timetags and need semirandom access to |
| 1870 | // mesg contents for scheduling bundles..hmm. | 1870 | // mesg contents for scheduling bundles..hmm. |
| 1871 | 1871 | ||
| 1872 | // make a separate case for scheduled messages... | 1872 | // make a separate case for scheduled messages... |
| 1873 | // throw them into a heap... | 1873 | // throw them into a heap... |
| 1874 | 1874 | ||
| 1875 | // fuck...back to the todo... | 1875 | // fuck...back to the todo... |
| 1876 | 1876 | ||
| 1877 | int new_size = ( _inbox_size * 2 > OSCINBOXMAX ) ? OSCINBOXMAX : _inbox_size * 2 ; | 1877 | int new_size = ( _inbox_size * 2 > OSCINBOXMAX ) ? OSCINBOXMAX : _inbox_size * 2 ; |
| 1878 | 1878 | ||
| 1879 | bool err = false; | 1879 | bool err = false; |
| 1880 | 1880 | ||
| 1881 | // okay. read and write may be anywhere. | 1881 | // okay. read and write may be anywhere. |
| 1882 | if( _in_write > _in_read ) { | 1882 | if( _in_write > _in_read ) { |
| 1883 | // easy case | 1883 | // easy case |
| 1884 | _inbox = (OSCMesg* ) realloc ((void*)_inbox, new_size * sizeof(*_inbox) ); | 1884 | _inbox = (OSCMesg* ) realloc ((void*)_inbox, new_size * sizeof(*_inbox) ); |
| 1885 | err = (!_inbox); | 1885 | err = (!_inbox); |
| 1886 | // indices are still valid | 1886 | // indices are still valid |
| 1887 | } | 1887 | } |
| 1888 | else { | 1888 | else { |
| 1889 | // write is behind read in the buffer | 1889 | // 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 |
| 1891 | // note:: copy the buffers between write and read... | 1891 | // note:: copy the buffers between write and read... |
| 1892 | // they may have valid packet pointers....... | 1892 | // they may have valid packet pointers....... |
| 1893 | 1893 | ||
| 1894 | OSCMesg * new_inbox =(OSCMesg*)malloc ( new_size * sizeof(*new_inbox) ); | 1894 | OSCMesg * new_inbox =(OSCMesg*)malloc ( new_size * sizeof(*new_inbox) ); |
| 1895 | err = (!new_inbox); | 1895 | err = (!new_inbox); |
| 1896 | 1896 | ||
| 1897 | if( !err ) { | 1897 | if( !err ) { |
| 1898 | int _read_tail = _inbox_size - _in_read; | 1898 | int _read_tail = _inbox_size - _in_read; |
| 1899 | memcpy( (void*)new_inbox, (void*)(_inbox+_in_read), (_read_tail) * sizeof(*_inbox) ); | 1899 | memcpy( (void*)new_inbox, (void*)(_inbox+_in_read), (_read_tail) * sizeof(*_inbox) ); |
| 1900 | memcpy( (void*)(new_inbox+_read_tail), (void*)_inbox, (_in_read ) * sizeof(*_inbox) ); | 1900 | memcpy( (void*)(new_inbox+_read_tail), (void*)_inbox, (_in_read ) * sizeof(*_inbox) ); |
| 1901 | 1901 | ||
| 1902 | // update indices | 1902 | // update indices |
| 1903 | _in_read = 0; | 1903 | _in_read = 0; |
| 1904 | _in_write = (_in_write + _read_tail); | 1904 | _in_write = (_in_write + _read_tail); |
| 1905 | 1905 | ||
| 1906 | free ( _inbox ); | 1906 | free ( _inbox ); |
| 1907 | _inbox = new_inbox; | 1907 | _inbox = new_inbox; |
| 1908 | } | 1908 | } |
| @@ -1910,12 +1910,12 @@ OSC_Receiver::next_write() · 1 unmodified line | |||
| 1910 | else err = true; | 1910 | else err = true; |
| 1911 | } | 1911 | } |
| 1912 | 1912 | ||
| 1913 | 1913 | ||
| 1914 | if( !err ) { | 1914 | if( !err ) { |
| 1915 | // new inbox elements need their payload pointers init to NULL | 1915 | // 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; |
| 1917 | } | 1917 | } |
| 1918 | else { | 1918 | else { |
| 1919 | // CK_FPRINTF_STDERR( "oh no!! buffer reallocation error!\n" ); | 1919 | // CK_FPRINTF_STDERR( "oh no!! buffer reallocation error!\n" ); |
| 1920 | exit(0); | 1920 | exit(0); |
| 1921 | } | 1921 | } |
| @@ -1926,9 +1926,9 @@ OSC_Receiver::next_write() · 4 unmodified lines | |||
| 1926 | // CK_FPRINTF_STDERR( "(%d)", _inbox_size ); | 1926 | // CK_FPRINTF_STDERR( "(%d)", _inbox_size ); |
| 1927 | // UNLOCK MUTEX | 1927 | // UNLOCK MUTEX |
| 1928 | } | 1928 | } |
| 1929 | else { | 1929 | else { |
| 1930 | // CK_FPRINTF_STDERR( "max buffer...dropping old mesg %d\n", next ); | 1930 | // 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; |
| 1932 | } | 1932 | } |
| 1933 | 1933 | ||
| 1934 | _io_mutex->release(); | 1934 | _io_mutex->release(); |
| @@ -1939,17 +1939,17 @@ OSC_Receiver::next_write() · 4 unmodified lines | |||
| 1939 | 1939 | ||
| 1940 | 1940 | ||
| 1941 | OSCMesg* | 1941 | OSCMesg* |
| 1942 | OSC_Receiver::next_read() { | 1942 | OSC_Receiver::next_read() { |
| 1943 | int next = ( _in_read + 1 ) % _inbox_size; | 1943 | int next = ( _in_read + 1 ) % _inbox_size; |
| 1944 | if( next == _in_write ) return NULL; // can't intrude on write | 1944 | if( next == _in_write ) return NULL; // can't intrude on write |
| 1945 | 1945 | ||
| 1946 | _in_read = next; //advance | 1946 | _in_read = next; //advance |
| 1947 | OSCMesg* ret= _inbox + _in_read; // return this pointer | 1947 | OSCMesg* ret= _inbox + _in_read; // return this pointer |
| 1948 | return ret; | 1948 | return ret; |
| 1949 | } | 1949 | } |
| 1950 | 1950 | ||
| 1951 | void | 1951 | void |
| 1952 | OSC_Receiver::set_mesg(OSCMesg* mrp, char * buf, int len ) { | 1952 | OSC_Receiver::set_mesg(OSCMesg* mrp, char * buf, int len ) { |
| 1953 | 1953 | ||
| 1954 | // put pointers in the appropriate places | 1954 | // put pointers in the appropriate places |
| 1955 | // this means that mrp has no idea whether | 1955 | // 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 | |||
| 1959 | mrp->len = len; //total size of message | 1959 | mrp->len = len; //total size of message |
| 1960 | mrp->address = buf; | 1960 | mrp->address = buf; |
| 1961 | mrp->types = mrp->address + strlen(mrp->address) + 4 - strlen(mrp->address)%4; | 1961 | mrp->types = mrp->address + strlen(mrp->address) + 4 - strlen(mrp->address)%4; |
| 1962 | if( mrp->types[0] == ',') { | 1962 | if( mrp->types[0] == ',') { |
| 1963 | // typed message | 1963 | // 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; |
| 1965 | } | 1965 | } |
| 1966 | else { | 1966 | else { |
| 1967 | // untyped message. | 1967 | // untyped message. |
| 1968 | // should there be a warning? | 1968 | // should there be a warning? |
| 1969 | // classes that handle mesgs | 1969 | // classes that handle mesgs |
| 1970 | // should take care of that. | 1970 | // should take care of that. |
| 1971 | mrp->data = mrp->types; | 1971 | mrp->data = mrp->types; |
| 1972 | mrp->types = NULL; | 1972 | mrp->types = NULL; |
| 1973 | } | 1973 | } |
| 1974 | 1974 | ||
| 1975 | } | 1975 | } |
| @@ -1977,9 +1977,9 @@ OSC_Receiver::set_mesg(OSCMesg* mrp, char * buf, int len ) { · 1 unmodified line | |||
| 1977 | void | 1977 | void |
| 1978 | OSC_Receiver::handle_mesg( char * buf, int len ) | 1978 | OSC_Receiver::handle_mesg( char * buf, int len ) |
| 1979 | { | 1979 | { |
| 1980 | // this is called sequentially by the receiving thread. | 1980 | // this is called sequentially by the receiving thread. |
| 1981 | if( buf[0] == '#' ) { handle_bundle( buf, len ); return; } | 1981 | if( buf[0] == '#' ) { handle_bundle( buf, len ); return; } |
| 1982 | 1982 | ||
| 1983 | OSCMesg * mrp = write(); | 1983 | OSCMesg * mrp = write(); |
| 1984 | 1984 | ||
| 1985 | if( mrp->payload == NULL ) { | 1985 | if( mrp->payload == NULL ) { |
| @@ -1994,7 +1994,7 @@ OSC_Receiver::handle_mesg( char * buf, int len ) · 8 unmodified lines | |||
| 1994 | distribute_message( mrp ); // copy message to any & all matching address spaces | 1994 | distribute_message( mrp ); // copy message to any & all matching address spaces |
| 1995 | 1995 | ||
| 1996 | // the distribute message will copy any necessary data into the addr object's private queue. | 1996 | // 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 ) |
| 1998 | 1998 | ||
| 1999 | // next_write(); | 1999 | // next_write(); |
| 2000 | } | 2000 | } |
| @@ -2005,11 +2005,11 @@ void OSC_Receiver::handle_bundle( char * b, int len ) · 4 unmodified lines | |||
| 2005 | // just immediately unpack everything | 2005 | // just immediately unpack everything |
| 2006 | 2006 | ||
| 2007 | // CK_FPRINTF_STDERR( "bundle (length %d)\n", len ); | 2007 | // CK_FPRINTF_STDERR( "bundle (length %d)\n", len ); |
| 2008 | 2008 | ||
| 2009 | int off = 16; //skip "#bundle\0timetags" | 2009 | int off = 16; //skip "#bundle\0timetags" |
| 2010 | 2010 | ||
| 2011 | while ( off < len ) | 2011 | while ( off < len ) |
| 2012 | { | 2012 | { |
| 2013 | char * z = b+off; | 2013 | char * z = b+off; |
| 2014 | unsigned long size = ntohl(*((unsigned long*)z)); | 2014 | unsigned long size = ntohl(*((unsigned long*)z)); |
| 2015 | 2015 | ||
| @@ -2070,7 +2070,7 @@ void OSC_Receiver::remove_address( OSC_Address_Space *odd ) · 54 unmodified lines | |||
| 2070 | _address_space[i] = _address_space[--_address_num]; | 2070 | _address_space[i] = _address_space[--_address_num]; |
| 2071 | } | 2071 | } |
| 2072 | } | 2072 | } |
| 2073 | 2073 | ||
| 2074 | // release (added 1.3.1.1) | 2074 | // release (added 1.3.1.1) |
| 2075 | _address_mutex->release(); | 2075 | _address_mutex->release(); |
| 2076 | } | 2076 | } |
| @@ -2095,61 +2095,61 @@ void OSC_Receiver::distribute_message( OSCMesg * msg ) · 18 unmodified lines | |||
| 2095 | ((Chuck_Event *)_address_space[i]->SELF)->queue_broadcast( m_event_buffer ); | 2095 | ((Chuck_Event *)_address_space[i]->SELF)->queue_broadcast( m_event_buffer ); |
| 2096 | } | 2096 | } |
| 2097 | } | 2097 | } |
| 2098 | 2098 | ||
| 2099 | // release (added 1.3.1.1) | 2099 | // release (added 1.3.1.1) |
| 2100 | _address_mutex->release(); | 2100 | _address_mutex->release(); |
| 2101 | } | 2101 | } |
| 2102 | 2102 | ||
| 2103 | 2103 | ||
| 2104 | // OSC SOURCE ( Parser ) | 2104 | // OSC SOURCE ( Parser ) |
| 2105 | // rename to OSC_address ? | 2105 | // rename to OSC_address ? |
| 2106 | 2106 | ||
| 2107 | // this is an OSC_Address_Space - we register it to a particular receiver | 2107 | // this is an OSC_Address_Space - we register it to a particular receiver |
| 2108 | // the receiver matches an incoming message against registered | 2108 | // the receiver matches an incoming message against registered |
| 2109 | // address and sends the message to all that match. | 2109 | // address and sends the message to all that match. |
| 2110 | 2110 | ||
| 2111 | // OSCMesg may still have pointers to a mysterious void. | 2111 | // OSCMesg may still have pointers to a mysterious void. |
| 2112 | // we should copy values locally for string and blob. | 2112 | // we should copy values locally for string and blob. |
| 2113 | 2113 | ||
| 2114 | // public for of inherited chuck_event mfunc. | 2114 | // public for of inherited chuck_event mfunc. |
| 2115 | 2115 | ||
| 2116 | const char * osc_typename_strings[] = { | 2116 | const char * osc_typename_strings[] = { |
| 2117 | "untyped", | 2117 | "untyped", |
| 2118 | "no arguments", | 2118 | "no arguments", |
| 2119 | "integer", | 2119 | "integer", |
| 2120 | "float", | 2120 | "float", |
| 2121 | "string", | 2121 | "string", |
| 2122 | "blob", | 2122 | "blob", |
| 2123 | "ERROR: num types exceeded" | 2123 | "ERROR: num types exceeded" |
| 2124 | }; | 2124 | }; |
| 2125 | 2125 | ||
| 2126 | 2126 | ||
| 2127 | 2127 | ||
| 2128 | OSC_Address_Space::OSC_Address_Space() { | 2128 | OSC_Address_Space::OSC_Address_Space() { |
| 2129 | init(); | 2129 | init(); |
| 2130 | setSpec( "/undefined/default,i" ); | 2130 | setSpec( "/undefined/default,i" ); |
| 2131 | } | 2131 | } |
| 2132 | 2132 | ||
| 2133 | 2133 | ||
| 2134 | OSC_Address_Space::OSC_Address_Space( const char * spec ) { | 2134 | OSC_Address_Space::OSC_Address_Space( const char * spec ) { |
| 2135 | init(); | 2135 | init(); |
| 2136 | setSpec( spec ); | 2136 | setSpec( spec ); |
| 2137 | } | 2137 | } |
| 2138 | 2138 | ||
| 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) { |
| 2140 | init(); | 2140 | init(); |
| 2141 | setSpec( addr, types ); | 2141 | setSpec( addr, types ); |
| 2142 | } | 2142 | } |
| 2143 | 2143 | ||
| 2144 | void | 2144 | void |
| 2145 | OSC_Address_Space::init() { | 2145 | OSC_Address_Space::init() { |
| 2146 | _receiver = NULL; | 2146 | _receiver = NULL; |
| 2147 | SELF = NULL; | 2147 | SELF = NULL; |
| 2148 | _queueSize = 512; // start queue size at 512 // 64. | 2148 | _queueSize = 512; // start queue size at 512 // 64. |
| 2149 | _dataSize = 0; | 2149 | _dataSize = 0; |
| 2150 | _cur_mesg = NULL; | 2150 | _cur_mesg = NULL; |
| 2151 | _queue = NULL; | 2151 | _queue = NULL; |
| 2152 | _cur_value = 0; | 2152 | _cur_value = 0; |
| 2153 | _current_data = NULL; | 2153 | _current_data = NULL; |
| 2154 | _buffer_mutex = new XMutex(); | 2154 | _buffer_mutex = new XMutex(); |
| 2155 | } | 2155 | } |
| @@ -2163,29 +2163,29 @@ OSC_Address_Space::~OSC_Address_Space() · 7 unmodified lines | |||
| 2163 | } | 2163 | } |
| 2164 | 2164 | ||
| 2165 | void | 2165 | void |
| 2166 | OSC_Address_Space::setReceiver(OSC_Receiver * recv) { | 2166 | OSC_Address_Space::setReceiver(OSC_Receiver * recv) { |
| 2167 | _receiver = recv; | 2167 | _receiver = recv; |
| 2168 | } | 2168 | } |
| 2169 | 2169 | ||
| 2170 | void | 2170 | void |
| 2171 | OSC_Address_Space::setSpec( const char *addr, const char * types ) { | 2171 | OSC_Address_Space::setSpec( const char *addr, const char * types ) { |
| 2172 | if( snprintf( _spec, sizeof _spec, "%s,%s", addr, types ) >= sizeof _spec) { | 2172 | if( snprintf( _spec, sizeof _spec, "%s,%s", addr, types ) >= sizeof _spec) { |
| 2173 | // TODO: handle the overflow more gracefully. | 2173 | // TODO: handle the overflow more gracefully. |
| 2174 | EM_log(CK_LOG_SEVERE, "OSC_Address_Space::setSpec: Not enough space in _spec buffer, data was truncated."); | 2174 | EM_log(CK_LOG_SEVERE, "OSC_Address_Space::setSpec: Not enough space in _spec buffer, data was truncated."); |
| 2175 | } | 2175 | } |
| 2176 | scanSpec(); | 2176 | scanSpec(); |
| 2177 | _needparse = true; | 2177 | _needparse = true; |
| 2178 | parseSpec(); | 2178 | parseSpec(); |
| 2179 | } | 2179 | } |
| 2180 | 2180 | ||
| 2181 | void | 2181 | void |
| 2182 | OSC_Address_Space::setSpec( const char *c ) { | 2182 | OSC_Address_Space::setSpec( const char *c ) { |
| 2183 | strncpy ( _spec, c, 512); | 2183 | strncpy ( _spec, c, 512); |
| 2184 | scanSpec(); | 2184 | scanSpec(); |
| 2185 | _needparse = true; | 2185 | _needparse = true; |
| 2186 | parseSpec(); | 2186 | parseSpec(); |
| 2187 | } | 2187 | } |
| 2188 | 2188 | ||
| 2189 | void | 2189 | void |
| 2190 | OSC_Address_Space::scanSpec() { //this allows for sloppy-ish definitions in type string | 2190 | OSC_Address_Space::scanSpec() { //this allows for sloppy-ish definitions in type string |
| 2191 | //assumes that a potential spec is already in _spec; | 2191 | //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 | |||
| 2193 | char * pwrite; | 2193 | char * pwrite; |
| 2194 | pread = pwrite = (char*)_spec; | 2194 | pread = pwrite = (char*)_spec; |
| 2195 | bool in_type = false; | 2195 | bool in_type = false; |
| 2196 | while ( *pread != '\0' ) { | 2196 | while ( *pread != '\0' ) { |
| 2197 | if( *pread == ',' || *pread == ' ' ) { | 2197 | if( *pread == ',' || *pread == ' ' ) { |
| 2198 | if( !in_type ) { | 2198 | if( !in_type ) { |
| 2199 | in_type = true; | 2199 | in_type = true; |
| 2200 | *pwrite = ','; | 2200 | *pwrite = ','; |
| 2201 | pwrite++; | 2201 | pwrite++; |
| 2202 | } // otherwise, we ignore | 2202 | } // otherwise, we ignore |
| 2203 | else if( *pread == ' ' ) { | 2203 | else if( *pread == ' ' ) { |
| 2204 | EM_log(CK_LOG_INFO, "OSC-Address-Space: spaces in OSC type tag string! ignoring"); | 2204 | EM_log(CK_LOG_INFO, "OSC-Address-Space: spaces in OSC type tag string! ignoring"); |
| 2205 | } | 2205 | } |
| 2206 | } | 2206 | } |
| 2207 | else { | 2207 | else { |
| 2208 | if( pwrite != pread ) { *pwrite = *pread; } | 2208 | if( pwrite != pread ) { *pwrite = *pread; } |
| 2209 | pwrite++; | 2209 | pwrite++; |
| 2210 | } | 2210 | } |
| 2211 | pread++; | 2211 | pread++; |
| 2212 | } | 2212 | } |
| 2213 | if( !in_type ) { | 2213 | 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. |
| 2215 | *(pwrite++) = ','; | 2215 | *(pwrite++) = ','; |
| 2216 | } | 2216 | } |
| 2217 | *pwrite = '\0'; //if pread terminates, so does pwrite. | 2217 | *pwrite = '\0'; //if pread terminates, so does pwrite. |
| 2218 | } | 2218 | } |
| 2219 | 2219 | ||
| 2220 | void | 2220 | void |
| 2221 | OSC_Address_Space::parseSpec() { | 2221 | OSC_Address_Space::parseSpec() { |
| 2222 | 2222 | ||
| 2223 | if( !_needparse ) return; | 2223 | if( !_needparse ) return; |
| 2224 | 2224 | ||
| @@ -2247,18 +2247,18 @@ OSC_Address_Space::resizeQueue( int n ) · 22 unmodified lines | |||
| 2247 | { | 2247 | { |
| 2248 | if( n <= _queueSize ) | 2248 | if( n <= _queueSize ) |
| 2249 | return; // only grows | 2249 | return; // only grows |
| 2250 | 2250 | ||
| 2251 | // lock | 2251 | // lock |
| 2252 | _buffer_mutex->acquire(); | 2252 | _buffer_mutex->acquire(); |
| 2253 | 2253 | ||
| 2254 | // it's possible that between the test above and now, | 2254 | // it's possible that between the test above and now, |
| 2255 | // qread has moved on and we actually DO have space.. | 2255 | // qread has moved on and we actually DO have space.. |
| 2256 | 2256 | ||
| 2257 | EM_log( CK_LOG_INFO, "OSC_Address (%s) -- buffer full ( r:%d , w:%d, of %d(x%d) ), resizing...", | 2257 | EM_log( CK_LOG_INFO, "OSC_Address (%s) -- buffer full ( r:%d , w:%d, of %d(x%d) ), resizing...", |
| 2258 | _address, _qread, _qwrite, _queueSize, _dataSize ); | 2258 | _address, _qread, _qwrite, _queueSize, _dataSize ); |
| 2259 | // CK_FPRINTF_STDERR( "--- hasMesg ( %d ) nextMesg ( %d )\n", (int) has_mesg(), (int)next_mesg() ); | 2259 | // CK_FPRINTF_STDERR( "--- hasMesg ( %d ) nextMesg ( %d )\n", (int) has_mesg(), (int)next_mesg() ); |
| 2260 | 2260 | ||
| 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, |
| 2262 | // so we can move the data, but we don't want to move ahead and lose it just yet. | 2262 | // so we can move the data, but we don't want to move ahead and lose it just yet. |
| 2263 | 2263 | ||
| 2264 | // compute chunk size | 2264 | // compute chunk size |
| @@ -2273,21 +2273,21 @@ OSC_Address_Space::resizeQueue( int n ) · 8 unmodified lines | |||
| 2273 | // copy | 2273 | // copy |
| 2274 | if( _qread < _qwrite ) | 2274 | if( _qread < _qwrite ) |
| 2275 | { | 2275 | { |
| 2276 | // we're doing this because qwrite is out of room. | 2276 | // we're doing this because qwrite is out of room. |
| 2277 | // so if qwrite is already greater than qread, | 2277 | // 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 ) |
| 2279 | memcpy( (void*)_new_queue, (const void*)_queue, _queueSize * chunkSize); | 2279 | 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. |
| 2281 | // CK_FPRINTF_STDERR( "resize - case 1\n" ); | 2281 | // CK_FPRINTF_STDERR( "resize - case 1\n" ); |
| 2282 | } | 2282 | } |
| 2283 | else | 2283 | else |
| 2284 | { | 2284 | { |
| 2285 | // _qread is in front of _qwrite, so we must unwrap, and place _qread at the | 2285 | // _qread is in front of _qwrite, so we must unwrap, and place _qread at the |
| 2286 | // front of the queue, and qwrite at the end, preserving all elements that qread | 2286 | // front of the queue, and qwrite at the end, preserving all elements that qread |
| 2287 | // is waiting to consume. | 2287 | // is waiting to consume. |
| 2288 | int nread = _queueSize - _qread; | 2288 | int nread = _queueSize - _qread; |
| 2289 | memcpy( (void*)_new_queue, | 2289 | memcpy( (void*)_new_queue, |
| 2290 | (const void*)(_queue + _qread * _dataSize), | 2290 | (const void*)(_queue + _qread * _dataSize), |
| 2291 | (nread) * chunkSize); | 2291 | (nread) * chunkSize); |
| 2292 | memcpy( (void*)(_new_queue + nread * _dataSize), | 2292 | memcpy( (void*)(_new_queue + nread * _dataSize), |
| 2293 | (const void*)_queue, | 2293 | (const void*)_queue, |
| @@ -2297,18 +2297,18 @@ OSC_Address_Space::resizeQueue( int n ) · 3 unmodified lines | |||
| 2297 | // EM_log(CK_LOG_INFO, "resize - case 2\n"); | 2297 | // EM_log(CK_LOG_INFO, "resize - case 2\n"); |
| 2298 | } | 2298 | } |
| 2299 | 2299 | ||
| 2300 | _queueSize = _newQSize; | 2300 | _queueSize = _newQSize; |
| 2301 | opsc_data * trash = _queue; | 2301 | opsc_data * trash = _queue; |
| 2302 | _queue = _new_queue; | 2302 | _queue = _new_queue; |
| 2303 | free ( (void*)trash ); | 2303 | free ( (void*)trash ); |
| 2304 | 2304 | ||
| 2305 | // don't move qread or qwrite until we're done. | 2305 | // don't move qread or qwrite until we're done. |
| 2306 | _buffer_mutex->release(); | 2306 | _buffer_mutex->release(); |
| 2307 | } | 2307 | } |
| 2308 | 2308 | ||
| 2309 | 2309 | ||
| 2310 | void | 2310 | void |
| 2311 | OSC_Address_Space::resizeData( int n ) { | 2311 | OSC_Address_Space::resizeData( int n ) { |
| 2312 | if( _dataSize == n ) return; | 2312 | if( _dataSize == n ) return; |
| 2313 | _dataSize = n; | 2313 | _dataSize = n; |
| 2314 | int queueLen = _queueSize * _dataSize * sizeof( opsc_data ); | 2314 | int queueLen = _queueSize * _dataSize * sizeof( opsc_data ); |
| @@ -2322,20 +2322,20 @@ bool · 7 unmodified lines | |||
| 2322 | OSC_Address_Space::message_matches( OSCMesg * m ) { | 2322 | OSC_Address_Space::message_matches( OSCMesg * m ) { |
| 2323 | 2323 | ||
| 2324 | //this should test for type as well. | 2324 | //this should test for type as well. |
| 2325 | 2325 | ||
| 2326 | bool addr_match; | 2326 | bool addr_match; |
| 2327 | if( strcmp ( m->address, _address ) == 0 ) addr_match = true; | 2327 | if( strcmp ( m->address, _address ) == 0 ) addr_match = true; |
| 2328 | else addr_match = PatternMatch( m->address, _address); | 2328 | else addr_match = PatternMatch( m->address, _address); |
| 2329 | if( !addr_match ) return false; | 2329 | if( !addr_match ) return false; |
| 2330 | 2330 | ||
| 2331 | //address AND type must match | 2331 | //address AND type must match |
| 2332 | //but there should be an option for the blank 'information about this' pattern | 2332 | //but there should be an option for the blank 'information about this' pattern |
| 2333 | 2333 | ||
| 2334 | char * type = m->types+1; | 2334 | char * type = m->types+1; |
| 2335 | if( m->types == NULL || strcmp( _type , type ) != 0 ) { | 2335 | if( m->types == NULL || strcmp( _type , type ) != 0 ) { |
| 2336 | // if( type ) | 2336 | // if( type ) |
| 2337 | // CK_FPRINTF_STDERR( "error, mismatched type string( %s ) vs ( %s ) \n", _type, type ); | 2337 | // CK_FPRINTF_STDERR( "error, mismatched type string( %s ) vs ( %s ) \n", _type, type ); |
| 2338 | // else | 2338 | // else |
| 2339 | // CK_FPRINTF_STDERR( "error, missing type string (expecting %s) \n", _type ); | 2339 | // CK_FPRINTF_STDERR( "error, missing type string (expecting %s) \n", _type ); |
| 2340 | return false; | 2340 | return false; |
| 2341 | } | 2341 | } |
| @@ -2343,7 +2343,7 @@ OSC_Address_Space::message_matches( OSCMesg * m ) { · 1 unmodified line | |||
| 2343 | } | 2343 | } |
| 2344 | 2344 | ||
| 2345 | 2345 | ||
| 2346 | bool OSC_Address_Space::try_queue_mesg( OSCMesg * m ) | 2346 | bool OSC_Address_Space::try_queue_mesg( OSCMesg * m ) |
| 2347 | { | 2347 | { |
| 2348 | if( !message_matches( m ) ) return false; | 2348 | if( !message_matches( m ) ) return false; |
| 2349 | queue_mesg( m ); | 2349 | queue_mesg( m ); |
| @@ -2367,7 +2367,6 @@ bool OSC_Address_Space::next_mesg() · 17 unmodified lines | |||
| 2367 | // lock | 2367 | // lock |
| 2368 | _buffer_mutex->acquire(); | 2368 | _buffer_mutex->acquire(); |
| 2369 | 2369 | ||
| 2370 | // TODO: ge uhhhh should release mutex? | ||
| 2371 | if( has_mesg() ) | 2370 | if( has_mesg() ) |
| 2372 | { | 2371 | { |
| 2373 | // move qread forward | 2372 | // move qread forward |
| @@ -2384,35 +2383,15 @@ bool OSC_Address_Space::next_mesg() · 10 unmodified lines | |||
| 2384 | // release | 2383 | // release |
| 2385 | _buffer_mutex->release(); | 2384 | _buffer_mutex->release(); |
| 2386 | return false; | 2385 | 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; | ||
| 2407 | } | 2386 | } |
| 2408 | 2387 | ||
| 2409 | bool OSC_Address_Space::vcheck( osc_datatype tt ) | 2388 | bool OSC_Address_Space::vcheck( osc_datatype tt ) |
| 2410 | { | 2389 | { |
| 2411 | if( !_cur_mesg ) | 2390 | if( !_cur_mesg ) |
| 2412 | { | 2391 | { |
| 2413 | EM_log( CK_LOG_SEVERE, "OscEvent: getVal(): nextMsg() must be called before reading data..." ); | 2392 | EM_log( CK_LOG_SEVERE, "OscEvent: getVal(): nextMsg() must be called before reading data..." ); |
| 2414 | return false; | 2393 | return false; |
| 2415 | } | 2394 | } |
| 2416 | else if( _cur_value < 0 || _cur_value >= _dataSize ) | 2395 | else if( _cur_value < 0 || _cur_value >= _dataSize ) |
| 2417 | { | 2396 | { |
| 2418 | EM_log( CK_LOG_SEVERE, "OscEvent: read position %d outside message ...", _cur_value ); | 2397 | 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 | |||
| 2442 | return (vcheck(OSC_STRING)) ? _cur_mesg[_cur_value++].s : NULL ; | 2421 | return (vcheck(OSC_STRING)) ? _cur_mesg[_cur_value++].s : NULL ; |
| 2443 | } | 2422 | } |
| 2444 | 2423 | ||
| 2445 | char * | 2424 | char * |
| 2446 | OSC_Address_Space::next_string_dup() | 2425 | OSC_Address_Space::next_string_dup() |
| 2447 | { | 2426 | { |
| 2448 | if( !vcheck(OSC_STRING) ) return NULL; | 2427 | if( !vcheck(OSC_STRING) ) return NULL; |
| @@ -2453,62 +2432,62 @@ OSC_Address_Space::next_string_dup() · 4 unmodified lines | |||
| 2453 | } | 2432 | } |
| 2454 | 2433 | ||
| 2455 | char * | 2434 | char * |
| 2456 | OSC_Address_Space::next_blob() { | 2435 | OSC_Address_Space::next_blob() { |
| 2457 | return ( vcheck(OSC_BLOB) ) ? _cur_mesg[_cur_value++].s : NULL ; | 2436 | return ( vcheck(OSC_BLOB) ) ? _cur_mesg[_cur_value++].s : NULL ; |
| 2458 | } | 2437 | } |
| 2459 | 2438 | ||
| 2460 | void | 2439 | void |
| 2461 | OSC_Address_Space::queue_mesg( OSCMesg * m ) | 2440 | OSC_Address_Space::queue_mesg( OSCMesg * m ) |
| 2462 | { | 2441 | { |
| 2463 | // in the server thread. | 2442 | // in the server thread. |
| 2464 | int nqw = ( _qwrite + 1 ) % _queueSize; | 2443 | int nqw = ( _qwrite + 1 ) % _queueSize; |
| 2465 | EM_log( CK_LOG_FINE, "OSC address(%s): read: %d write: %d size: %d", _address, _qread, _qwrite, _queueSize ); | 2444 | EM_log( CK_LOG_FINE, "OSC address(%s): read: %d write: %d size: %d", _address, _qread, _qwrite, _queueSize ); |
| 2466 | 2445 | ||
| 2467 | if( nqw == _qread ) { | 2446 | if( nqw == _qread ) { |
| 2468 | if( _queueSize < OSC_ADDRESS_QUEUE_MAX ) { | 2447 | if( _queueSize < OSC_ADDRESS_QUEUE_MAX ) { |
| 2469 | resizeQueue( _queueSize * 2 ); | 2448 | resizeQueue( _queueSize * 2 ); |
| 2470 | nqw = ( _qwrite + 1 ) % _queueSize; // _qwrite, _qread may have changed. | 2449 | nqw = ( _qwrite + 1 ) % _queueSize; // _qwrite, _qread may have changed. |
| 2471 | } | 2450 | } |
| 2472 | else { | 2451 | else { |
| 2473 | EM_log( CK_LOG_INFO, "OSC_Address_Space(%s): message queue reached max size %d...", _address, _queueSize ); | 2452 | EM_log( CK_LOG_INFO, "OSC_Address_Space(%s): message queue reached max size %d...", _address, _queueSize ); |
| 2474 | EM_log( CK_LOG_INFO, "...(dropping oldest message %d)", _qread ); | 2453 | EM_log( CK_LOG_INFO, "...(dropping oldest message %d)", _qread ); |
| 2475 | 2454 | ||
| 2476 | // bump! | 2455 | // bump! |
| 2477 | _buffer_mutex->acquire(); | 2456 | _buffer_mutex->acquire(); |
| 2478 | _qread = ( _qread + 1 ) % _queueSize; | 2457 | _qread = ( _qread + 1 ) % _queueSize; |
| 2479 | _buffer_mutex->release(); | 2458 | _buffer_mutex->release(); |
| 2480 | } | 2459 | } |
| 2481 | } | 2460 | } |
| 2482 | 2461 | ||
| 2483 | _vals = _queue + _qwrite * _dataSize; | 2462 | _vals = _queue + _qwrite * _dataSize; |
| 2484 | 2463 | ||
| 2485 | if( _noArgs ) { // if address takes no arguments, | 2464 | if( _noArgs ) { // if address takes no arguments, |
| 2486 | _vals[0].t = OSC_NOARGS; | 2465 | _vals[0].t = OSC_NOARGS; |
| 2487 | } | 2466 | } |
| 2488 | else { | 2467 | else { |
| 2489 | char * type = m->types+1; | 2468 | char * type = m->types+1; |
| 2490 | char * data = m->data; | 2469 | char * data = m->data; |
| 2491 | 2470 | ||
| 2492 | unsigned int endy; | 2471 | unsigned int endy; |
| 2493 | int i=0; | 2472 | int i=0; |
| 2494 | 2473 | ||
| 2495 | float *fp; | 2474 | float *fp; |
| 2496 | int *ip; | 2475 | int *ip; |
| 2497 | t_CKINT clen; | 2476 | t_CKINT clen; |
| 2498 | while ( *type != '\0' ) { | 2477 | while ( *type != '\0' ) { |
| 2499 | switch ( *type ) { | 2478 | switch ( *type ) { |
| 2500 | case 'f': | 2479 | case 'f': |
| 2501 | endy = ntohl(*((unsigned long*)data)); | 2480 | endy = ntohl(*((unsigned long*)data)); |
| 2502 | fp = (float*)(&endy); | 2481 | fp = (float*)(&endy); |
| 2503 | _vals[i].t = OSC_FLOAT; | 2482 | _vals[i].t = OSC_FLOAT; |
| 2504 | _vals[i].f = *fp; | 2483 | _vals[i].f = *fp; |
| 2505 | data += 4; | 2484 | data += 4; |
| 2506 | break; | 2485 | break; |
| 2507 | case 'i': | 2486 | case 'i': |
| 2508 | endy = ntohl(*((unsigned long*)data)); | 2487 | endy = ntohl(*((unsigned long*)data)); |
| 2509 | ip = (int4byte*)(&endy); | 2488 | ip = (int4byte*)(&endy); |
| 2510 | _vals[i].t = OSC_INT; | 2489 | _vals[i].t = OSC_INT; |
| 2511 | _vals[i].i = *ip; | 2490 | _vals[i].i = *ip; |
| 2512 | data += 4; | 2491 | data += 4; |
| 2513 | break; | 2492 | break; |
| 2514 | case 's': | 2493 | case 's': |
| @@ -2535,7 +2514,7 @@ OSC_Address_Space::queue_mesg( OSCMesg * m ) · 20 unmodified lines | |||
| 2535 | type++; | 2514 | type++; |
| 2536 | } | 2515 | } |
| 2537 | } | 2516 | } |
| 2538 | 2517 | ||
| 2539 | _qwrite = nqw; | 2518 | _qwrite = nqw; |
| 2540 | 2519 | ||
| 2541 | //review | 2520 | //review |