/*---------------------------------------------------------------------------- ChucK Concurrent, On-the-fly Audio Programming Language Compiler and Virtual Machine Copyright (c) 2004 Ge Wang and Perry R. Cook. All rights reserved. http://chuck.stanford.edu/ http://chuck.cs.princeton.edu/ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 U.S.A.-----------------------------------------------------------------------------*/ //-----------------------------------------------------------------------------// file: util_opsc.cpp// desc: utility for open sound control//// author: Philip L. Davidson (philipd@alumni.princeton.edu)// Ge Wang (gewang@cs.princeton.edu)// date: Spring 2005//-----------------------------------------------------------------------------#include "util_opsc.h" //chuck networking code#include "util_network.h"#include "util_thread.h" #include "chuck_errmsg.h"#include "chuck_vm.h" #include <algorithm>#include <cstdio>using namespace std; // FROM PLATFORM.H -UDP TRANSMITTER / RECEIVER #if defined(__PLATFORM_WIN32__)// 2022 QTSIN added winsock2.h and wsw2tcpip.h#include <winsock2.h>#include <ws2tcpip.h>#include <windows.h>#else#include <sys/types.h>#include <sys/socket.h>#include <sys/time.h>#include <unistd.h>#include <netinet/in.h>#include <netinet/tcp.h>#include <arpa/inet.h>#include <netdb.h>#endif // 1.4.1.0 (ge) added#if _MSC_VER#define snprintf _snprintf#endif #if defined(__MACOSX_CORE__)#define SOCKET int#define SOCKADDR_IN struct sockaddr_in#elif !defined(SOCKADDR_IN)#define SOCKET int#define SOCKADDR_IN struct sockaddr_in#endif // squeeze the whole wad of OSC-Kit code in here. // OSC-pattern-match.cpp /*Copyright � 1998. The Regents of the University of California (Regents).All Rights Reserved. Written by Matt Wright, The Center for New Music and Audio Technologies,University of California, Berkeley. Permission to use, copy, modify, distribute, and distribute modified versionsof this software and its documentation without fee and without a signedlicensing agreement, is hereby granted, provided that the above copyrightnotice, this paragraph and the following two paragraphs appear in all copies,modifications, and distributions. IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISINGOUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HASBEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULARPURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDEDHEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDEMAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. The OpenSound Control WWW page is http://www.cnmat.berkeley.edu/OpenSoundControl*/ /* OSC-pattern-match.c Matt Wright, 3/16/98 Adapted from oscpattern.c, by Matt Wright and Amar Chaudhury */ // #include "OSC-pattern-match.h" static const char *theWholePattern; /* Just for warning messages */ static bool MatchBrackets( const char * pattern, const char * test );static bool MatchList( const char * pattern, const char * test ); bool PatternMatch( const char * pattern, const char * test ){ theWholePattern = pattern; if( pattern == 0 || pattern[0] == 0 ) { return test[0] == 0; } if( test[0] == 0 ) { if(pattern[0] == '*') return PatternMatch (pattern+1,test); else return FALSE; } switch( pattern[0] ) { case 0 : return test[0] == 0; case '?' : return PatternMatch (pattern + 1, test + 1); case '*' : if( PatternMatch (pattern+1, test) ) { return TRUE; } else { return PatternMatch (pattern, test+1); } case ']' : case '}' : CK_FPRINTF_STDERR( "[chuck](via OSC): spurious %c in pattern \".../%s/...\"\n", pattern[0], theWholePattern ); return FALSE; case '[' : return MatchBrackets (pattern,test); case '{' : return MatchList (pattern,test); case '\\' : if(pattern[1] == 0) { return test[0] == 0; } else if(pattern[1] == test[0]) { return PatternMatch (pattern+2,test+1); } else { return FALSE; } default : if(pattern[0] == test[0]) { return PatternMatch (pattern+1,test+1); } else { return FALSE; } }} /* we know that pattern[0] == '[' and test[0] != 0 */ static bool MatchBrackets( const char * pattern, const char * test ){ bool result; bool negated = FALSE; const char *p = pattern; if(pattern[1] == 0) { CK_FPRINTF_STDERR( "[chuck](via OSC): unterminated [ in pattern \".../%s/...\"\n", theWholePattern ); return FALSE; } if(pattern[1] == '!') { negated = TRUE; p++; } while (*p != ']') { if(*p == 0) { CK_FPRINTF_STDERR( "[chuck](via OSC): unterminated [ in pattern \".../%s/...\"\n", theWholePattern ); return FALSE; } if(p[1] == '-' && p[2] != 0) { if(test[0] >= p[0] && test[0] <= p[2]) { result = !negated; goto advance; } } if(p[0] == test[0]) { result = !negated; goto advance; } p++; } result = negated; advance: if(!result) return FALSE; while (*p != ']') { if(*p == 0) { CK_FPRINTF_STDERR( "[chuck](via OSC): unterminated [ in pattern \".../%s/...\"\n", theWholePattern ); return FALSE; } p++; } return PatternMatch (p+1,test+1);} static bool MatchList( const char * pattern, const char * test ){ const char *restOfPattern, *tp = test; for(restOfPattern = pattern; *restOfPattern != '}'; restOfPattern++) { if(*restOfPattern == 0) { CK_FPRINTF_STDERR( "[chuck](via OSC): unterminated { in pattern \".../%s/...\"\n", theWholePattern ); return FALSE; } } restOfPattern++; /* skip close curly brace */ pattern++; /* skip open curly brace */ while( 1 ) { if(*pattern == ',') { if(PatternMatch (restOfPattern, tp)) { return TRUE; } else { tp = test; ++pattern; } } else if(*pattern == '}') { return PatternMatch (restOfPattern, tp); } else if(*pattern == *tp) { ++pattern; ++tp; } else { tp = test; while (*pattern != ',' && *pattern != '}') { pattern++; } if(*pattern == ',') { pattern++; } } }} // end OSC-pattern-match.h // OSC-timetag.cpp /*Copyright (c) 1998. The Regents of the University of California (Regents).All Rights Reserved. Permission to use, copy, modify, and distribute this software and itsdocumentation for educational, research, and not-for-profit purposes, withoutfee and without a signed licensing agreement, is hereby granted, provided thatthe above copyright notice, this paragraph and the following two paragraphsappear in all copies, modifications, and distributions. Contact The Office ofTechnology Licensing, UC Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley,CA 94720-1620, (510) 643-7201, for commercial licensing opportunities. Written by Matt Wright, The Center for New Music and Audio Technologies,University of California, Berkeley. IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. The OpenSound Control WWW page is http://www.cnmat.berkeley.edu/OpenSoundControl*/ /* OSC_timeTag.c: library for manipulating OSC time tags Matt Wright, 5/29/97 Version 0.2 (9/11/98): cleaned up so no explicit type names in the .c file.*/ //#include "OSC-timetag.h" #ifdef HAS8BYTEINT#define TWO_TO_THE_32_FLOAT 4294967296.0f OSCTimeTag OSCTT_Immediately(void) { return (OSCTimeTag) 1;} OSCTimeTag OSCTT_BiggestPossibleTimeTag(void) { return (OSCTimeTag) 0xffffffffffffffff;} OSCTimeTag OSCTT_PlusSeconds(OSCTimeTag original, float secondsOffset) { int64 offset = (int64) (secondsOffset * TWO_TO_THE_32_FLOAT); /* printf("* OSCTT_PlusSeconds %llx plus %f seconds (i.e., %lld offset) is %llx\n", original, secondsOffset, offset, original + offset); */ return original + offset;} int OSCTT_Compare(OSCTimeTag left, OSCTimeTag right){#if 0 printf("***** OSCTT_Compare(%llx, %llx): %d\n", left, right, (left<right) ? -1 : ((left == right) ? 0 : 1));#endif if(left < right) { return -1; } else if(left == right) { return 0; } else { return 1; }} #ifdef __sgi#include <sys/time.h> #define SECONDS_FROM_1900_to_1970 2208988800 /* 17 leap years */#define TWO_TO_THE_32_OVER_ONE_MILLION 4295 OSCTimeTag OSCTT_CurrentTime(void) { uint64 result; uint32 usecOffset; struct timeval tv; struct timezone tz; BSDgettimeofday(&tv, &tz); /* First get the seconds right */ result = (unsigned) SECONDS_FROM_1900_to_1970 + (unsigned) tv.tv_sec - (unsigned) 60 * tz.tz_minuteswest + (unsigned) (tz.tz_dsttime ? 3600 : 0); #if 0 /* No timezone, no DST version ... */ result = (unsigned) SECONDS_FROM_1900_to_1970 + (unsigned) tv.tv_sec;#endif /* make seconds the high-order 32 bits */ result = result << 32; /* Now get the fractional part. */ usecOffset = (unsigned) tv.tv_usec * (unsigned) TWO_TO_THE_32_OVER_ONE_MILLION; /* printf("** %ld microsec is offset %x\n", tv.tv_usec, usecOffset); */ result += usecOffset; /* printf("* OSCTT_CurrentTime is %llx\n", result); */ return result;} #else /* __sgi */ /* Instead of asking your operating system what time it is, it might be clever to find out the current time at the instant your application starts audio processing, and then keep track of the number of samples output to know how much time has passed. */ /* Loser version for systems that have no ability to tell the current time: */OSCTimeTag OSCTT_CurrentTime(void) { return (OSCTimeTag) 1;} #endif /* __sgi */ #else /* Not HAS8BYTEINT */ OSCTimeTag OSCTT_CurrentTime(void) { OSCTimeTag result; result.seconds = 0; result.fraction = 1; return result;} OSCTimeTag OSCTT_BiggestPossibleTimeTag(void) { OSCTimeTag result; result.seconds = 0xffffffff; result.fraction = 0xffffffff; return result;} OSCTimeTag OSCTT_Immediately(void) { OSCTimeTag result; result.seconds = 0; result.fraction = 1; return result;} OSCTimeTag OSCTT_PlusSeconds(OSCTimeTag original, float secondsOffset) { OSCTimeTag result; result.seconds = 0; result.fraction = 1; return result;} int OSCTT_Compare(OSCTimeTag left, OSCTimeTag right) { /* Untested! */ int highResult = left.seconds - right.seconds; if(highResult != 0) return highResult; return left.fraction - right.fraction;} #endif /* HAS8BYTEINT */ // end OSC-timetag.cpp // OSC-client.cpp /*Copyright (c) 1996. The Regents of the University of California (Regents).All Rights Reserved. Permission to use, copy, modify, and distribute this software and itsdocumentation for educational, research, and not-for-profit purposes, withoutfee and without a signed licensing agreement, is hereby granted, provided thatthe above copyright notice, this paragraph and the following two paragraphsappear in all copies, modifications, and distributions. Contact The Office ofTechnology Licensing, UC Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley,CA 94720-1620, (510) 643-7201, for commercial licensing opportunities. Written by Matt Wright, The Center for New Music and Audio Technologies,University of California, Berkeley. IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.*/ /* Author: Matt Wright Version 2.2: Calls htonl in the right places 20000620 Version 2.3: Gets typed messages right. */ /* Here are the possible values of the state field: */ #define EMPTY 0 /* Nothing written to packet yet */#define ONE_MSG_ARGS 1 /* Packet has a single message; gathering arguments */#define NEED_COUNT 2 /* Just opened a bundle; must write message name or open another bundle */#define GET_ARGS 3 /* Getting arguments to a message. If we see a messageLines 1–500 of 2527. Load more
/*---------------------------------------------------------------------------- ChucK Concurrent, On-the-fly Audio Programming Language Compiler and Virtual Machine Copyright (c) 2004 Ge Wang and Perry R. Cook. All rights reserved. http://chuck.stanford.edu/ http://chuck.cs.princeton.edu/ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 U.S.A. -----------------------------------------------------------------------------*/ //----------------------------------------------------------------------------- // file: util_opsc.cpp // desc: utility for open sound control // // author: Philip L. Davidson (philipd@alumni.princeton.edu) // Ge Wang (gewang@cs.princeton.edu) // date: Spring 2005 //----------------------------------------------------------------------------- #include "util_opsc.h" //chuck networking code #include "util_network.h" #include "util_thread.h" #include "chuck_errmsg.h" #include "chuck_vm.h" #include <algorithm> #include <cstdio> using namespace std; // FROM PLATFORM.H -UDP TRANSMITTER / RECEIVER #if defined(__PLATFORM_WIN32__) // 2022 QTSIN added winsock2.h and wsw2tcpip.h #include <winsock2.h> #include <ws2tcpip.h> #include <windows.h> #else #include <sys/types.h> #include <sys/socket.h> #include <sys/time.h> #include <unistd.h> #include <netinet/in.h> #include <netinet/tcp.h> #include <arpa/inet.h> #include <netdb.h> #endif // 1.4.1.0 (ge) added #if _MSC_VER #define snprintf _snprintf #endif #if defined(__MACOSX_CORE__) #define SOCKET int #define SOCKADDR_IN struct sockaddr_in #elif !defined(SOCKADDR_IN) #define SOCKET int #define SOCKADDR_IN struct sockaddr_in #endif // squeeze the whole wad of OSC-Kit code in here. // OSC-pattern-match.cpp /* Copyright � 1998. The Regents of the University of California (Regents). All Rights Reserved. Written by Matt Wright, The Center for New Music and Audio Technologies, University of California, Berkeley. Permission to use, copy, modify, distribute, and distribute modified versions of this software and its documentation without fee and without a signed licensing agreement, is hereby granted, provided that the above copyright notice, this paragraph and the following two paragraphs appear in all copies, modifications, and distributions. IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. The OpenSound Control WWW page is http://www.cnmat.berkeley.edu/OpenSoundControl */ /* OSC-pattern-match.c Matt Wright, 3/16/98 Adapted from oscpattern.c, by Matt Wright and Amar Chaudhury */ // #include "OSC-pattern-match.h" static const char *theWholePattern; /* Just for warning messages */ static bool MatchBrackets( const char * pattern, const char * test ); static bool MatchList( const char * pattern, const char * test ); bool PatternMatch( const char * pattern, const char * test ) { theWholePattern = pattern; if( pattern == 0 || pattern[0] == 0 ) { return test[0] == 0; } if( test[0] == 0 ) { if(pattern[0] == '*') return PatternMatch (pattern+1,test); else return FALSE; } switch( pattern[0] ) { case 0 : return test[0] == 0; case '?' : return PatternMatch (pattern + 1, test + 1); case '*' : if( PatternMatch (pattern+1, test) ) { return TRUE; } else { return PatternMatch (pattern, test+1); } case ']' : case '}' : CK_FPRINTF_STDERR( "[chuck](via OSC): spurious %c in pattern \".../%s/...\"\n", pattern[0], theWholePattern ); return FALSE; case '[' : return MatchBrackets (pattern,test); case '{' : return MatchList (pattern,test); case '\\' : if(pattern[1] == 0) { return test[0] == 0; } else if(pattern[1] == test[0]) { return PatternMatch (pattern+2,test+1); } else { return FALSE; } default : if(pattern[0] == test[0]) { return PatternMatch (pattern+1,test+1); } else { return FALSE; } } } /* we know that pattern[0] == '[' and test[0] != 0 */ static bool MatchBrackets( const char * pattern, const char * test ) { bool result; bool negated = FALSE; const char *p = pattern; if(pattern[1] == 0) { CK_FPRINTF_STDERR( "[chuck](via OSC): unterminated [ in pattern \".../%s/...\"\n", theWholePattern ); return FALSE; } if(pattern[1] == '!') { negated = TRUE; p++; } while (*p != ']') { if(*p == 0) { CK_FPRINTF_STDERR( "[chuck](via OSC): unterminated [ in pattern \".../%s/...\"\n", theWholePattern ); return FALSE; } if(p[1] == '-' && p[2] != 0) { if(test[0] >= p[0] && test[0] <= p[2]) { result = !negated; goto advance; } } if(p[0] == test[0]) { result = !negated; goto advance; } p++; } result = negated; advance: if(!result) return FALSE; while (*p != ']') { if(*p == 0) { CK_FPRINTF_STDERR( "[chuck](via OSC): unterminated [ in pattern \".../%s/...\"\n", theWholePattern ); return FALSE; } p++; } return PatternMatch (p+1,test+1); } static bool MatchList( const char * pattern, const char * test ) { const char *restOfPattern, *tp = test; for(restOfPattern = pattern; *restOfPattern != '}'; restOfPattern++) { if(*restOfPattern == 0) { CK_FPRINTF_STDERR( "[chuck](via OSC): unterminated { in pattern \".../%s/...\"\n", theWholePattern ); return FALSE; } } restOfPattern++; /* skip close curly brace */ pattern++; /* skip open curly brace */ while( 1 ) { if(*pattern == ',') { if(PatternMatch (restOfPattern, tp)) { return TRUE; } else { tp = test; ++pattern; } } else if(*pattern == '}') { return PatternMatch (restOfPattern, tp); } else if(*pattern == *tp) { ++pattern; ++tp; } else { tp = test; while (*pattern != ',' && *pattern != '}') { pattern++; } if(*pattern == ',') { pattern++; } } } } // end OSC-pattern-match.h // OSC-timetag.cpp /* Copyright (c) 1998. The Regents of the University of California (Regents). All Rights Reserved. Permission to use, copy, modify, and distribute this software and its documentation for educational, research, and not-for-profit purposes, without fee and without a signed licensing agreement, is hereby granted, provided that the above copyright notice, this paragraph and the following two paragraphs appear in all copies, modifications, and distributions. Contact The Office of Technology Licensing, UC Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, (510) 643-7201, for commercial licensing opportunities. Written by Matt Wright, The Center for New Music and Audio Technologies, University of California, Berkeley. IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. The OpenSound Control WWW page is http://www.cnmat.berkeley.edu/OpenSoundControl */ /* OSC_timeTag.c: library for manipulating OSC time tags Matt Wright, 5/29/97 Version 0.2 (9/11/98): cleaned up so no explicit type names in the .c file. */ //#include "OSC-timetag.h" #ifdef HAS8BYTEINT #define TWO_TO_THE_32_FLOAT 4294967296.0f OSCTimeTag OSCTT_Immediately(void) { return (OSCTimeTag) 1; } OSCTimeTag OSCTT_BiggestPossibleTimeTag(void) { return (OSCTimeTag) 0xffffffffffffffff; } OSCTimeTag OSCTT_PlusSeconds(OSCTimeTag original, float secondsOffset) { int64 offset = (int64) (secondsOffset * TWO_TO_THE_32_FLOAT); /* printf("* OSCTT_PlusSeconds %llx plus %f seconds (i.e., %lld offset) is %llx\n", original, secondsOffset, offset, original + offset); */ return original + offset; } int OSCTT_Compare(OSCTimeTag left, OSCTimeTag right) { #if 0 printf("***** OSCTT_Compare(%llx, %llx): %d\n", left, right, (left<right) ? -1 : ((left == right) ? 0 : 1)); #endif if(left < right) { return -1; } else if(left == right) { return 0; } else { return 1; } } #ifdef __sgi #include <sys/time.h> #define SECONDS_FROM_1900_to_1970 2208988800 /* 17 leap years */ #define TWO_TO_THE_32_OVER_ONE_MILLION 4295 OSCTimeTag OSCTT_CurrentTime(void) { uint64 result; uint32 usecOffset; struct timeval tv; struct timezone tz; BSDgettimeofday(&tv, &tz); /* First get the seconds right */ result = (unsigned) SECONDS_FROM_1900_to_1970 + (unsigned) tv.tv_sec - (unsigned) 60 * tz.tz_minuteswest + (unsigned) (tz.tz_dsttime ? 3600 : 0); #if 0 /* No timezone, no DST version ... */ result = (unsigned) SECONDS_FROM_1900_to_1970 + (unsigned) tv.tv_sec; #endif /* make seconds the high-order 32 bits */ result = result << 32; /* Now get the fractional part. */ usecOffset = (unsigned) tv.tv_usec * (unsigned) TWO_TO_THE_32_OVER_ONE_MILLION; /* printf("** %ld microsec is offset %x\n", tv.tv_usec, usecOffset); */ result += usecOffset; /* printf("* OSCTT_CurrentTime is %llx\n", result); */ return result; } #else /* __sgi */ /* Instead of asking your operating system what time it is, it might be clever to find out the current time at the instant your application starts audio processing, and then keep track of the number of samples output to know how much time has passed. */ /* Loser version for systems that have no ability to tell the current time: */ OSCTimeTag OSCTT_CurrentTime(void) { return (OSCTimeTag) 1; } #endif /* __sgi */ #else /* Not HAS8BYTEINT */ OSCTimeTag OSCTT_CurrentTime(void) { OSCTimeTag result; result.seconds = 0; result.fraction = 1; return result; } OSCTimeTag OSCTT_BiggestPossibleTimeTag(void) { OSCTimeTag result; result.seconds = 0xffffffff; result.fraction = 0xffffffff; return result; } OSCTimeTag OSCTT_Immediately(void) { OSCTimeTag result; result.seconds = 0; result.fraction = 1; return result; } OSCTimeTag OSCTT_PlusSeconds(OSCTimeTag original, float secondsOffset) { OSCTimeTag result; result.seconds = 0; result.fraction = 1; return result; } int OSCTT_Compare(OSCTimeTag left, OSCTimeTag right) { /* Untested! */ int highResult = left.seconds - right.seconds; if(highResult != 0) return highResult; return left.fraction - right.fraction; } #endif /* HAS8BYTEINT */ // end OSC-timetag.cpp // OSC-client.cpp /* Copyright (c) 1996. The Regents of the University of California (Regents). All Rights Reserved. Permission to use, copy, modify, and distribute this software and its documentation for educational, research, and not-for-profit purposes, without fee and without a signed licensing agreement, is hereby granted, provided that the above copyright notice, this paragraph and the following two paragraphs appear in all copies, modifications, and distributions. Contact The Office of Technology Licensing, UC Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, (510) 643-7201, for commercial licensing opportunities. Written by Matt Wright, The Center for New Music and Audio Technologies, University of California, Berkeley. IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. */ /* Author: Matt Wright Version 2.2: Calls htonl in the right places 20000620 Version 2.3: Gets typed messages right. */ /* Here are the possible values of the state field: */ #define EMPTY 0 /* Nothing written to packet yet */ #define ONE_MSG_ARGS 1 /* Packet has a single message; gathering arguments */ #define NEED_COUNT 2 /* Just opened a bundle; must write message name or open another bundle */ #define GET_ARGS 3 /* Getting arguments to a message. If we see a message