From 9a4263e499b328a6943e75d97358933597d390cb Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 16 Oct 2012 18:45:39 +0000 Subject: converted OSCx to the Library Template and bumped the version to 0.3.1 svn path=/branches/pd-extended/0.43/externals/oscx/; revision=16399 --- src/INVENTORY.txt | 21 - src/Makefile.in | 65 --- src/OSC-common.h | 84 ---- src/OSC-pattern-match.c | 192 -------- src/OSC-pattern-match.h | 35 -- src/OSC-system-dependent.c | 82 ---- src/OSC.001 | 147 ------ src/OSC.c | 72 --- src/OSC.dsp | 152 ------- src/OSC.dsw | 29 -- src/OSCroute.c | 452 ------------------- src/TODO.txt | 27 -- src/VERSION | 1 - src/dumpOSC.c | 1056 -------------------------------------------- src/htmsocket.c | 387 ---------------- src/htmsocket.h | 48 -- src/sendOSC.c | 585 ------------------------ 17 files changed, 3435 deletions(-) delete mode 100644 src/INVENTORY.txt delete mode 100644 src/Makefile.in delete mode 100644 src/OSC-common.h delete mode 100644 src/OSC-pattern-match.c delete mode 100644 src/OSC-pattern-match.h delete mode 100644 src/OSC-system-dependent.c delete mode 100644 src/OSC.001 delete mode 100644 src/OSC.c delete mode 100644 src/OSC.dsp delete mode 100644 src/OSC.dsw delete mode 100644 src/OSCroute.c delete mode 100644 src/TODO.txt delete mode 100644 src/VERSION delete mode 100644 src/dumpOSC.c delete mode 100644 src/htmsocket.c delete mode 100644 src/htmsocket.h delete mode 100644 src/sendOSC.c (limited to 'src') diff --git a/src/INVENTORY.txt b/src/INVENTORY.txt deleted file mode 100644 index 98f3698..0000000 --- a/src/INVENTORY.txt +++ /dev/null @@ -1,21 +0,0 @@ -OSC protocol inventory for OSC4PD - -sendOSC, dumpOSC, OSCroute -========================== - INCLUDES - * typed and untyped packing of OSC messages - * #bundle packing - * transmission of OSC messages via UDP socket - - * receive OSC messages on UDP socket - * unpacking of typed and untyped OSC messages - * #bundle unpacking - - * static address resolution - * pattern matching - - OMITS - * working with timetags - * all advanced protocol features of documentation, typesigs, etc - * connection oriented communication - diff --git a/src/Makefile.in b/src/Makefile.in deleted file mode 100644 index 41032de..0000000 --- a/src/Makefile.in +++ /dev/null @@ -1,65 +0,0 @@ -# -# Copyright (C) 2004 Hans-Christoph Steiner -# -# 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., 675 Mass Ave, Cambridge, MA 02139, USA. - - -EXT=o -LIBS = @LIBS@ -LIBOSC = ../libOSC/@LIBOSC@ - -CFLAGS = @CFLAGS@ -INCLUDES = @INCLUDES@ -LDFLAGS = @LDFLAGS@ - -prefix=@prefix@ - -SOURCES = OSC-pattern-match.c OSC.c dumpOSC.c htmsocket.c OSCroute.c sendOSC.c OSC-system-dependent.c -TARGETS = $(SOURCES:.c=.o) -EXTS=sendOSC.@pd_suffix@ dumpOSC.@pd_suffix@ OSCroute.@pd_suffix@ - -# ----------------------- autoconf ----------------------- - -all: $(EXTS) - -lib: OSC.@pd_suffix@ - -dumpOSC.@pd_suffix@: dumpOSC.o - $(CC) $(LDFLAGS) -o dumpOSC.@pd_suffix@ $? $(LIBS) - -sendOSC.@pd_suffix@: sendOSC.o htmsocket.o OSC-system-dependent.o - $(CC) $(LDFLAGS) -o sendOSC.@pd_suffix@ $? $(LIBS) $(LIBOSC) - -OSCroute.@pd_suffix@: OSCroute.o OSC-pattern-match.o OSC-system-dependent.o - $(CC) $(LDFLAGS) -o OSCroute.@pd_suffix@ $? $(LIBS) - -OSC.@pd_suffix@: OSC.o sendOSC.o dumpOSC.o OSCroute.o htmsocket.o OSC-pattern-match.o OSC-system-dependent.o - $(CC) $(LDFLAGS) -o OSC.@pd_suffix@ $? $(LIBS) $(LIBOSC) - -$(TARGETS): %.o : %.c - $(CC) $(CFLAGS) $(INCLUDES) -c -o $*.o $*.c - -# ---------------------------------------------------------- - -install-doc: - @test -d $(prefix)/lib/pd/doc/5.reference || mkdir -p $(prefix)/lib/pd/doc/5.reference - cp -r ../doc/* $(prefix)/lib/pd/doc/5.reference/ - -install: install-doc - @test -d $(prefix)/lib/pd/extra || mkdir -p $(prefix)/lib/pd/extra - install -m644 *.@pd_suffix@ $(prefix)/lib/pd/extra - -clean: - rm -rf *.$(EXT) *.@pd_suffix@ diff --git a/src/OSC-common.h b/src/OSC-common.h deleted file mode 100644 index abea838..0000000 --- a/src/OSC-common.h +++ /dev/null @@ -1,84 +0,0 @@ -/* -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-common.h - Simple stuff to #include everywhere in the OSC package - - by Matt Wright, 3/13/98 -*/ - -#ifndef _OSC_COMMON_H -#define _OSC_COMMON_H - -/* Boolean type */ - -#ifndef TRUE -typedef int Boolean; -#define TRUE 1 -#define FALSE 0 -#endif - - -#ifdef _WIN32 - #include - #ifdef _DEBUG - #define DEBUG - #endif -#endif /* _WIN32 */ - -/* only needed on Microsoft compilers */ -#ifdef _MSC_VER - #ifdef OSC_EXPORTS - #define OSC_API __declspec(dllexport) - #else - #define OSC_API __declspec(dllimport) - #endif -#endif /* _MSC_VER */ - -//#define int32_t t_int - -/* Fixed byte width types */ -typedef int int4; /* 4 byte int */ - -/* Printing type procedures. All take printf-style format string */ - -/* Catastrophic failure: print message and halt system */ -void fatal_error(char *s, ...); - -/* Error message for user */ -void OSCProblem(char *s, ...); - -/* Warning for user */ -void OSCWarning(char *s, ...); - - - -#endif /* _OSC_COMMON_H */ - diff --git a/src/OSC-pattern-match.c b/src/OSC-pattern-match.c deleted file mode 100644 index 847ebb3..0000000 --- a/src/OSC-pattern-match.c +++ /dev/null @@ -1,192 +0,0 @@ -/* -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-common.h" -#include "OSC-pattern-match.h" - -static const char *theWholePattern; /* Just for warning messages */ - -static Boolean MatchBrackets (const char *pattern, const char *test); -static Boolean MatchList (const char *pattern, const char *test); - -Boolean 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 '}' : - OSCWarning("Spurious %c in pattern \".../%s/...\"",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 Boolean MatchBrackets (const char *pattern, const char *test) { - Boolean result; - Boolean negated = FALSE; - const char *p = pattern; - - if (pattern[1] == 0) { - OSCWarning("Unterminated [ in pattern \".../%s/...\"", theWholePattern); - return FALSE; - } - - if (pattern[1] == '!') { - negated = TRUE; - p++; - } - - while (*p != ']') { - if (*p == 0) { - OSCWarning("Unterminated [ in pattern \".../%s/...\"", 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) { - OSCWarning("Unterminated [ in pattern \".../%s/...\"", theWholePattern); - return FALSE; - } - p++; - } - - return PatternMatch (p+1,test+1); -} - -static Boolean MatchList (const char *pattern, const char *test) { - - const char *restOfPattern, *tp = test; - - - for(restOfPattern = pattern; *restOfPattern != '}'; restOfPattern++) { - if (*restOfPattern == 0) { - OSCWarning("Unterminated { in pattern \".../%s/...\"", 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++; - } - } - } - -} - - - diff --git a/src/OSC-pattern-match.h b/src/OSC-pattern-match.h deleted file mode 100644 index 653b54d..0000000 --- a/src/OSC-pattern-match.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -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.h -*/ - -Boolean PatternMatch (const char *pattern, const char *test); - diff --git a/src/OSC-system-dependent.c b/src/OSC-system-dependent.c deleted file mode 100644 index d4f9c50..0000000 --- a/src/OSC-system-dependent.c +++ /dev/null @@ -1,82 +0,0 @@ -/* -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-system-dependent.c - - Matt Wright, 3/13/98 - - File of procedures OSC has to call that are not part of the OSC package - and that you, the developer adding OSC addressability to an application, - must write in a way that makes sense in the context of your system. - - You should also look at OSC-timetag.c and see if there's a better way - to handle time tags on your system. - -*/ - -#include "OSC-common.h" - -/* Printing stuff: for now, use stderr. Some cleverer stuff we could do: - - - Make a silent mode where these don't do anything. - - Return error messages via OSC to some client -*/ - -#include -#include -#include - -void fatal_error(char *s, ...) { - va_list ap; - fprintf(stderr, "Fatal error: "); - va_start(ap, s); - vfprintf(stderr, s, ap); - fprintf(stderr, "\n"); - va_end(ap); - exit(-321); -} - -void OSCProblem(char *s, ...) { - va_list ap; - fprintf(stderr, "OSC Problem: "); - va_start(ap, s); - vfprintf(stderr, s, ap); - fprintf(stderr, "\n"); - va_end(ap); -} - -void OSCWarning(char *s, ...) { - va_list ap; - fprintf(stderr, "OSC Warning: "); - va_start(ap, s); - vfprintf(stderr, s, ap); - fprintf(stderr, "\n"); - va_end(ap); -} diff --git a/src/OSC.001 b/src/OSC.001 deleted file mode 100644 index b9dd0d4..0000000 --- a/src/OSC.001 +++ /dev/null @@ -1,147 +0,0 @@ -# Microsoft Developer Studio Project File - Name="OSC" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 5.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=OSC - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "OSC.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "OSC.mak" CFG="OSC - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "OSC - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "OSC - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE - -# Begin Project -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "OSC - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release" -# PROP Intermediate_Dir "Release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "RAFOSC_EXPORTS" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GX /O2 /I "../../../pd/src" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "OSC_EXPORTS" /D "NT" /YX /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 -# ADD LINK32 pd.lib libc.lib kernel32.lib wsock32.lib LIBOSC.lib /nologo /dll /machine:I386 /nodefaultlib /out:"../../../pd/extra/OSC.dll" /libpath:"../../../pd/lib" /libpath:"../../../pd/bin" -# SUBTRACT LINK32 /pdb:none - -!ELSEIF "$(CFG)" == "OSC - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug" -# PROP Intermediate_Dir "Debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MTd /W3 /GX /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "RAFOSC_EXPORTS" /YX /FD /ZI /GZ /c -# ADD CPP /nologo /MTd /W3 /GX /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "OSC_EXPORTS" /D "NT" /YX /FD /ZI /GZ /c -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 pd.lib libc.lib kernel32.lib wsock32.lib LIBOSC.lib /nologo /dll /debug /machine:I386 /nodefaultlib /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name "OSC - Win32 Release" -# Name "OSC - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\dumpOSC.c -# End Source File -# Begin Source File - -SOURCE=.\htmsocket.c -# End Source File -# Begin Source File - -SOURCE=".\OSC-pattern-match.c" -# End Source File -# Begin Source File - -SOURCE=.\OSC.c -# End Source File -# Begin Source File - -SOURCE=.\routeOSC.c -# End Source File -# Begin Source File - -SOURCE=.\sendOSC.c -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=.\htmsocket.h -# End Source File -# Begin Source File - -SOURCE=".\OSC-client.h" -# End Source File -# Begin Source File - -SOURCE=".\OSC-common.h" -# End Source File -# Begin Source File - -SOURCE=".\OSC-pattern-match.h" -# End Source File -# Begin Source File - -SOURCE=".\OSC-timetag.h" -# End Source File -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# End Group -# End Target -# End Project diff --git a/src/OSC.c b/src/OSC.c deleted file mode 100644 index 923c097..0000000 --- a/src/OSC.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - OpenSoundControl for PD - ------------- - -- init jdl at xdv dot org - -- tweaks for Win32 www.zeggz.com/raf 13-April-2002 - -- smoothed out build, clean up for Darwin 2004.04.04 - -- shoutz: miller and the others - -- Windows-ification by Piotr Majdak 30.08.2005 -*/ - -#if HAVE_CONFIG_H -#include -#endif - -#include -#include "OSC-common.h" - -#define VERSION "0.3" - -/* this is for when building with non-Microsoft compilers */ -#ifndef OSC_API -#define OSC_API -#endif - -typedef struct _OSC -{ - t_object x_obj; -} t_OSC; - - -OSC_API void OSC_setup(void); -OSC_API void OSC_version(t_OSC*); - -OSC_API void sendOSC_setup(void); -OSC_API void dumpOSC_setup(void); -OSC_API void OSCroute_setup(void); - - -static t_class* OSC_class; - - -static void* OSC_new(t_symbol* s) { - t_OSC *x = (t_OSC *)pd_new(OSC_class); - error("OSCx is deprecated! consider switching to mrpeach's osc & net objects"); - return (x); -} - - -OSC_API void OSC_version (t_OSC *x) { - - post("OSC4PD Version " VERSION "\n" - " Original code by matt wright. pd-fication jdl@xdv.org\n" - " Win32-port raf@interaccess.com unified versions hans@at.or.at\n" - " Adaptations for Windows: piotr@majdak.com\n" - " Compiled: "__DATE__); -} - -OSC_API void OSC_setup(void) { - OSC_class = class_new(gensym("OSC"), (t_newmethod)OSC_new, 0, - sizeof(t_OSC), 0,0); - class_addmethod(OSC_class, (t_method)OSC_version, gensym("version"), A_NULL, 0, 0); - - sendOSC_setup(); - dumpOSC_setup(); - OSCroute_setup(); - - post("O : Open Sound Control 4 PD, http://www.cnmat.berkeley.edu/OSC"); - post(" S : original code by matt wright, pd hakcs cxc, Win32-port raf@interaccess.com"); - post(" C: ver: "VERSION ", compiled: "__DATE__ " -- adapted by piotr@majdak.com"); - - error("OSCx is deprecated - ask IOhannes m zmoelnig why..."); -} diff --git a/src/OSC.dsp b/src/OSC.dsp deleted file mode 100644 index fc16ecd..0000000 --- a/src/OSC.dsp +++ /dev/null @@ -1,152 +0,0 @@ -# Microsoft Developer Studio Project File - Name="OSC" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=OSC - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "OSC.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "OSC.mak" CFG="OSC - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "OSC - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "OSC - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "OSC - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release" -# PROP Intermediate_Dir "Release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "RAFOSC_EXPORTS" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GX /O2 /I "c:\pd\src" /I "LIBOSC" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "OSC_EXPORTS" /D "NT" /YX /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 -# ADD LINK32 c:\pd\bin\pd.lib libc.lib kernel32.lib wsock32.lib LIBOSC/Release/LIBOSC.lib /nologo /dll /machine:I386 /nodefaultlib /libpath:"../../../pd/lib" /libpath:"../../../pd/bin" -# SUBTRACT LINK32 /pdb:none - -!ELSEIF "$(CFG)" == "OSC - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug" -# PROP Intermediate_Dir "Debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MTd /W3 /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "RAFOSC_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /GX /ZI /Od /I "c:\pd\src" /I "LIBOSC" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "OSC_EXPORTS" /D "NT" /YX /FD /GZ /c -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 c:\pd\bin\pd.lib libc.lib kernel32.lib wsock32.lib LIBOSC/Release/LIBOSC.lib /nologo /dll /debug /machine:I386 /nodefaultlib /pdbtype:sept /libpath:"c:\pd\src" - -!ENDIF - -# Begin Target - -# Name "OSC - Win32 Release" -# Name "OSC - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\dumpOSC.c -# End Source File -# Begin Source File - -SOURCE=.\htmsocket.c -# End Source File -# Begin Source File - -SOURCE=".\OSC-pattern-match.c" -# End Source File -# Begin Source File - -SOURCE=".\OSC-system-dependent.c" -# End Source File -# Begin Source File - -SOURCE=.\OSC.c -# End Source File -# Begin Source File - -SOURCE=.\OSCroute.c -# End Source File -# Begin Source File - -SOURCE=.\sendOSC.c -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=.\htmsocket.h -# End Source File -# Begin Source File - -SOURCE=".\OSC-client.h" -# End Source File -# Begin Source File - -SOURCE=".\OSC-common.h" -# End Source File -# Begin Source File - -SOURCE=".\OSC-pattern-match.h" -# End Source File -# Begin Source File - -SOURCE=".\OSC-timetag.h" -# End Source File -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# End Group -# End Target -# End Project diff --git a/src/OSC.dsw b/src/OSC.dsw deleted file mode 100644 index 293b7f7..0000000 --- a/src/OSC.dsw +++ /dev/null @@ -1,29 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 6.00 -# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! - -############################################################################### - -Project: "OSC"=.\OSC.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - diff --git a/src/OSCroute.c b/src/OSCroute.c deleted file mode 100644 index c3afc89..0000000 --- a/src/OSCroute.c +++ /dev/null @@ -1,452 +0,0 @@ -/* -Written by Adrian Freed, The Center for New Music and Audio Technologies, -University of California, Berkeley. Copyright (c) 1992,93,94,95,96,97,98,99,2000,01,02,03,04 -The Regents of the University of California (Regents). - -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 OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl -*/ - - /* OSC-route.c - Max object for OSC-style dispatching - - To-do: - - Match a pattern against a pattern? - [Done: Only Slash-Star is allowed, see MyPatternMatch.] - Declare outlet types / distinguish leaf nodes from other children - More sophisticated (2-pass?) allmessages scheme - set message? - - - pd - ------------- - -- tweaks for Win32 www.zeggz.com/raf 13-April-2002 - - - */ - -#if HAVE_CONFIG_H -#include -#endif - - -/* the required include files */ -#include "m_pd.h" -#include "OSC-common.h" -#include "OSC-pattern-match.h" - -#include -#ifdef _WIN32 - #include - #include -#endif - -/* structure definition of your object */ -#define MAX_NUM 128 -#define OSC_ROUTE_VERSION "1.05" -/* Version 1.04: Allows #1 thru #9 as typed-in arguments - Version 1.05: Allows "list" messages as well as "message" messages. -*/ - -static Boolean MyPatternMatch (const char *pattern, const char *test) -{ - // This allows the special case of "OSCroute /* " to be an outlet that - // matches anything; i.e., it always outputs the input with the first level - // of the address stripped off. - - if (test[0] == '*' && test[1] == '\0') { - return 1; - } else { - return PatternMatch(pattern, test); - } -} - - -static t_class *OSCroute_class; - -typedef struct _OSCroute -{ - t_object x_obj; // required header - t_int x_num; // Number of address prefixes we store - t_int x_complainmode; // Do we print a message if no match? - t_int x_sendmode; // use pd internal sends instead of outlets - char *x_prefixes[MAX_NUM]; - void *x_outlets[MAX_NUM+1]; -} t_OSCroute; - -t_symbol *ps_list, *ps_complain, *ps_emptySymbol; - -/* prototypes */ - -void OSCroute_doanything(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv); -void OSCroute_anything(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv); -void OSCroute_list(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv); -/* //void *OSCroute_new(t_symbol *s, int argc, atom *argv); */ -void *OSCroute_new(t_symbol *s, int argc, t_atom *argv); -void OSCroute_version (t_OSCroute *x); -/* void OSCroute_assist (OSCroute *x, void *box, long msg, long arg, */ -/* char *dstString); */ -void OSCroute_allmessages(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv); -#ifdef _MSC_VER -OSC_API void OSCroute_setup(void); -#else -void OSCroute_setup(void); -#endif /* _MSC_VER */ - -static char *NextSlashOrNull(char *p); -static void StrCopyUntilSlash(char *target, const char *source); - - -// free -static void OSCroute_free(t_OSCroute *x) -{ - // freebytes(x->x_vec, x->x_nelement * sizeof(*x->x_vec)); -} - -/* initialization routine */ - -// setup -#ifdef _MSC_VER - OSC_API void OSCroute_setup(void) { -#else -void OSCroute_setup(void) { -#endif - OSCroute_class = class_new(gensym("OSCroute"), (t_newmethod)OSCroute_new, - (t_method)OSCroute_free,sizeof(t_OSCroute), 0, A_GIMME, 0); - class_addlist(OSCroute_class, OSCroute_list); - class_addanything(OSCroute_class, OSCroute_anything); - class_addmethod(OSCroute_class, (t_method)OSCroute_version, gensym("version"), A_NULL, 0, 0); - class_sethelpsymbol(OSCroute_class, gensym("OSCroute-help.pd")); - - /* - class_addmethod(OSCroute_class, (t_method)OSCroute_connect, - gensym("connect"), A_SYMBOL, A_FLOAT, 0); - class_addmethod(OSCroute_class, (t_method)OSCroute_disconnect, - gensym("disconnect"), 0); - class_addmethod(OSCroute_class, (t_method)OSCroute_send, gensym("send"), - A_GIMME, 0); - */ -/* ps_list = gensym("list"); */ -/* ps_complain = gensym("complain"); */ - ps_emptySymbol = gensym(""); - - post("OSCroute object version " OSC_ROUTE_VERSION " by Matt Wright. pd: jdl Win32 raf."); - post("OSCroute Copyright © 1999 Regents of the Univ. of California. All Rights Reserved."); - error("[OSCroute]: OSCx is deprecated! \n\tConsider switching to mrpeach's [routeOSC]"); -} - - - -/* instance creation routine */ - -void *OSCroute_new(t_symbol *s, int argc, t_atom *argv) -{ - - t_OSCroute *x = (t_OSCroute *)pd_new(OSCroute_class); // get memory for a new object & initialize - - int i; //{{raf}} n not used - - // EnterCallback(); - - if (argc > MAX_NUM) { - post("* OSC-route: too many arguments: %ld (max %ld)", argc, MAX_NUM); - // ExitCallback(); - return 0; - } - - x->x_complainmode = 0; - x->x_num = 0; - for (i = 0; i < argc; ++i) { - if (argv[i].a_type == A_SYMBOL) { - if (argv[i].a_w.w_symbol->s_name[0] == '/') { - /* Now that's a nice prefix */ - x->x_prefixes[i] = argv[i].a_w.w_symbol->s_name; - ++(x->x_num); - } else if (argv[i].a_w.w_symbol->s_name[0] == '#' && - argv[i].a_w.w_symbol->s_name[1] >= '1' && - argv[i].a_w.w_symbol->s_name[1] <= '9') { - /* The Max programmer is trying to make a patch that will be - a subpatch with arguments. We have to make an outlet for this - argument. */ - x->x_prefixes[i] = "dummy"; - ++(x->x_num); - } else { - /* Maybe this is an option we support */ - -/* if (argv[i].a_w.w_sym == ps_complain) { */ -/* x->x_complainmode = 1; */ -/* } else { */ -/* post("* OSC-route: Unrecognized argument %s", argv[i].a_w.w_sym->s_name); */ -/* } */ - - } - - // no LONG - -/* } else if (argv[i].a_type == A_FLOAD) { */ -/* // Convert to a numeral. Max ints are -2147483648 to 2147483647 */ -/* char *string = getbytes(12); */ -/* // I can't be bothered to plug this 12 byte memory leak */ -/* if (string == 0) { */ -/* post("* OSC-route: out of memory!"); */ -/* // ExitCallback(); */ -/* return 0; */ -/* } */ -/* sprintf(string, "%d", argv[i].a_w.w_long); */ -/* x->x_prefixes[i] = string; */ -/* ++(x->x_num); */ - - } else if (argv[i].a_type == A_FLOAT) { - post("* OSC-route: float arguments are not OK."); - // ExitCallback(); - return 0; - } else { - post("* OSC-route: unrecognized argument type!"); - // ExitCallback(); - return 0; - } - } - - - /* Have to create the outlets in reverse order */ - /* well, not in pd ? */ - // for (i = x->x_num-1; i >= 0; --i) { - // for (i = 0; i <= x->x_num-1; i++) { - for (i = 0; i <= x->x_num; i++) { - // x->x_outlets[i] = listout(x); - x->x_outlets[i] = outlet_new(&x->x_obj, &s_list); - } - - // ExitCallback(); - return (x); -} - - -void OSCroute_version (t_OSCroute *x) { - // EnterCallback(); - post("OSCroute Version " OSC_ROUTE_VERSION - ", by Matt Wright. pd jdl, win32: raf.\nOSCroute Compiled " __TIME__ " " __DATE__); - // ExitCallback(); -} - -/* I don't know why these aren't defined in some Max #include file. */ -#define ASSIST_INLET 1 -#define ASSIST_OUTLET 2 - -void OSCroute_assist (t_OSCroute *x, void *box, long msg, long arg, - char *dstString) { - // EnterCallback(); - - if (msg==ASSIST_INLET) { - sprintf(dstString, "Incoming OSC messages"); - } else if (msg==ASSIST_OUTLET) { - if (arg < 0 || arg >= x->x_num) { - post("* OSCroute_assist: No outlet corresponds to arg %ld!", arg); - } else { - sprintf(dstString, "subaddress + args for prefix %s", x->x_prefixes[arg]); - } - } else { - post("* OSCroute_assist: unrecognized message %ld", msg); - } - - // ExitCallback(); -} - -void OSCroute_list(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv) { - // EnterCallback(); - if (argc > 0 && argv[0].a_type == A_SYMBOL) { - /* Ignore the fact that this is a "list" */ - OSCroute_doanything(x, argv[0].a_w.w_symbol, argc-1, argv+1); - } else if (argc > 0) { - // post("* OSC-route: invalid list beginning with a number"); - // output on unmatched outlet jdl 20020908 - if (argv[0].a_type == A_FLOAT) { - outlet_float(x->x_outlets[x->x_num], argv[0].a_w.w_float); - } else { - post("* OSC-route: unrecognized atom type!"); - } - } - else { - // output a bang on the rejected outlet if no arguments - outlet_bang(x->x_outlets[x->x_num]); - } - // ExitCallback(); -} - - -void OSCroute_anything(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv) { - // EnterCallback(); - OSCroute_doanything(x, s, argc, argv); - // ExitCallback(); -} - - - - -void OSCroute_doanything(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv) { - char *pattern, *nextSlash; - int i; - int matchedAnything; - // post("*** OSCroute_anything(s %s, argc %ld)", s->s_name, (long) argc); - - pattern = s->s_name; - if (pattern[0] != '/') { - post("* OSC-route: invalid message pattern %s does not begin with /", s->s_name); - outlet_anything(x->x_outlets[x->x_num], s, argc, argv); - return; - } - - matchedAnything = 0; - - nextSlash = NextSlashOrNull(pattern+1); - if (*nextSlash == '\0') { - /* last level of the address, so we'll output the argument list */ - - -#ifdef NULL_IS_DIFFERENT_FROM_BANG - if (argc==0) { - post("* OSC-route: why are you matching one level pattern %s with no args?", - pattern); - return; - } -#endif - - for (i = 0; i < x->x_num; ++i) { - if (MyPatternMatch(pattern+1, x->x_prefixes[i]+1)) { - ++matchedAnything; - - // I hate stupid Max lists with a special first element - if (argc == 0) { - outlet_bang(x->x_outlets[i]); - } else if (argv[0].a_type == A_SYMBOL) { - // Promote the symbol that was argv[0] to the special symbol - outlet_anything(x->x_outlets[i], argv[0].a_w.w_symbol, argc-1, argv+1); - } else if (argc > 1) { - // Multiple arguments starting with a number, so naturally we have - // to use a special function to output this "list", since it's what - // Max originally meant by "list". - outlet_list(x->x_outlets[i], 0L, argc, argv); - } else { - // There was only one argument, and it was a number, so we output it - // not as a list -/* if (argv[0].a_type == A_LONG) { */ - -/* outlet_int(x->x_outlets[i], argv[0].a_w.w_long); */ - // } else - if (argv[0].a_type == A_FLOAT) { - - outlet_float(x->x_outlets[i], argv[0].a_w.w_float); - } else { - post("* OSC-route: unrecognized atom type!"); - } - } - } - } - } else { - /* There's more address after this part, so our output list will begin with - the next slash. */ - t_symbol *restOfPattern = 0; /* avoid the gensym unless we have to output */ - char patternBegin[1000]; - - - /* Get the first level of the incoming pattern to match against all our prefixes */ - StrCopyUntilSlash(patternBegin, pattern+1); - - for (i = 0; i < x->x_num; ++i) { - if (MyPatternMatch(patternBegin, x->x_prefixes[i]+1)) { - ++matchedAnything; - if (restOfPattern == 0) { - restOfPattern = gensym(nextSlash); - } - outlet_anything(x->x_outlets[i], restOfPattern, argc, argv); - } - } - } - - if (x->x_complainmode) { - if (!matchedAnything) { - post("* OSC-route: pattern %s did not match any prefixes", pattern); - } - } - - // output unmatched data on rightmost outlet a la normal 'route' object, jdl 20020908 - if (!matchedAnything) { - outlet_anything(x->x_outlets[x->x_num], s, argc, argv); - } - - -} - -static char *NextSlashOrNull(char *p) { - while (*p != '/' && *p != '\0') { - p++; - } - return p; -} - -static void StrCopyUntilSlash(char *target, const char *source) { - while (*source != '/' && *source != '\0') { - *target = *source; - ++target; - ++source; - } - *target = 0; -} - -static int MyStrCopy(char *target, const char *source) { - int i = 0; - while (*source != '\0') { - *target = *source; - ++target; - ++source; - ++i; - } - *target = 0; - return i; -} - - - -void OSCroute_allmessages(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv) { - int i; - t_symbol *prefixSymbol = 0; - char prefixBuf[1000]; - char *endOfPrefix; - t_atom a[1]; - - if (argc >= 1 && argv[0].a_type == A_SYMBOL) { - prefixSymbol = argv[0].a_w.w_symbol; - endOfPrefix = prefixBuf + MyStrCopy(prefixBuf, - prefixSymbol->s_name); - } else { - prefixSymbol = ps_emptySymbol; - prefixBuf[0] = '\0'; - endOfPrefix = prefixBuf; - } - - - for (i = 0; i < x->x_num; ++i) { - post("OSC: %s%s", prefixSymbol->s_name, x->x_prefixes[i]); - MyStrCopy(endOfPrefix, x->x_prefixes[i]); - SETSYMBOL(a, gensym(prefixBuf)); - outlet_anything(x->x_outlets[i], s, 1, a); - } -} diff --git a/src/TODO.txt b/src/TODO.txt deleted file mode 100644 index 63c2d7b..0000000 --- a/src/TODO.txt +++ /dev/null @@ -1,27 +0,0 @@ - -for win32: port also the command line utilities (send, dump) - --pd object hierarchy extract and automatic address construction - a la [/hostname]/pd/patchname/subpatch/test ? - --dynamic space allocation for message buffers. - --configure proper (autoconf) - - -changelog: - -20020903: refixed MAXPDARG vs. MAX_ARGS bug causind sendOSC to crash - with msgs longer than 5 argmuents. ? - -20020305: -typetags in send and receive - sendOSC by default now send typetagged msgs - and dumOSC properly reads and outputs them. - -prior: - - -added OSCroute with source adapt from max object. - -fixed shared htmsock bug - -added sendtyped separately earlier and lost it again - - diff --git a/src/VERSION b/src/VERSION deleted file mode 100644 index be58634..0000000 --- a/src/VERSION +++ /dev/null @@ -1 +0,0 @@ -0.3 diff --git a/src/dumpOSC.c b/src/dumpOSC.c deleted file mode 100644 index 8d7de18..0000000 --- a/src/dumpOSC.c +++ /dev/null @@ -1,1056 +0,0 @@ -/* -Written by Matt Wright and Adrian Freed, The Center for New Music and -Audio Technologies, University of California, Berkeley. Copyright (c) -1992,93,94,95,96,97,98,99,2000,01,02,03,04 The Regents of the University of -California (Regents). - -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 OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl -*/ - - - /* - - dumpOSC.c - server that displays OpenSoundControl messages sent to it - for debugging client udp and UNIX protocol - - by Matt Wright, 6/3/97 - modified from dumpSC.c, by Matt Wright and Adrian Freed - - version 0.2: Added "-silent" option a.k.a. "-quiet" - - version 0.3: Incorporated patches from Nicola Bernardini to make - things Linux-friendly. Also added ntohl() in the right places - to support little-endian architectures. - - - - compile: - cc -o dumpOSC dumpOSC.c - - to-do: - - More robustness in saying exactly what's wrong with ill-formed - messages. (If they don't make sense, show exactly what was - received.) - - Time-based features: print time-received for each packet - - Clean up to separate OSC parsing code from socket/select stuff - - pd: branched from http://www.cnmat.berkeley.edu/OpenSoundControl/src/dumpOSC/dumpOSC.c - ------------- - -- added pd functions - -- socket is made differently than original via pd mechanisms - -- tweaks for Win32 www.zeggz.com/raf 13-April-2002 - -- the OSX changes from cnmat didnt make it here yet but this compiles - on OSX anyway. - -*/ - -#if HAVE_CONFIG_H -#include -#endif - -#include "m_pd.h" -//#include "m_imp.h" -#include "s_stuff.h" - -/* declarations */ - -// typedef void (*t_fdpollfn)(void *ptr, int fd); -//void sys_addpollfn(int fd, t_fdpollfn fn, void *ptr); - - -#if defined(__sgi) || defined(__linux) || defined(_WIN32) || defined(__APPLE__) - -#ifdef _WIN32 - #ifdef _MSC_VER - #include "OSC-common.h" - #endif /* _MSC_VER */ - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include -#else - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - //#include - - #ifdef NEED_SCHEDCTL_AND_LOCK - #include - #include - #endif -#endif /* _WIN32 */ - - -char *htm_error_string; -typedef int Boolean; -typedef void *OBJ; - -typedef struct ClientAddressStruct { - struct sockaddr_in cl_addr; - int clilen; - int sockfd; -} *ClientAddr; - - - -Boolean ShowBytes = FALSE; -Boolean Silent = FALSE; - -/* Declarations */ -#ifndef _WIN32 -static int unixinitudp(int chan); -#endif - -#ifdef _WIN32 - typedef unsigned __int64 osc_time_t; -#else - typedef unsigned long long osc_time_t; -#endif - - - -static int initudp(int chan); -static void closeudp(int sockfd); -Boolean ClientReply(int packetsize, void *packet, int socketfd, - void *clientaddresspointer, int clientaddressbufferlength); -void sgi_CleanExit(void); -Boolean sgi_HaveToQuit(void); -int RegisterPollingDevice(int fd, void (*callbackfunction)(int , void *), void *dummy); -static void catch_sigint(); -static int Synthmessage(char *m, int n, void *clientdesc, int clientdesclength, int fd) ; -char *DataAfterAlignedString(char *string, char *boundary) ; -Boolean IsNiceString(char *string, char *boundary) ; -void complain(char *s, ...); -osc_time_t ReadTime(const char* src); - -#define MAXMESG 32768 -static char mbuf[MAXMESG]; - -/* ----------------------------- dumpOSC ------------------------- */ - -#define MAXOUTAT 50 - -static t_class *dumpOSC_class; - -typedef struct _dumpOSC -{ - t_object x_obj; - t_outlet *x_msgout; - t_outlet *x_connectout; - t_atom x_outat[MAXOUTAT]; - int x_outatc; - t_binbuf *x_b; - int x_connectsocket; - int x_nconnections; - int x_udp; - struct sockaddr_in x_server; - int x_clilen; -} t_dumpOSC; - -void dumpOSC_ParsePacket(t_dumpOSC *x, char *buf, int n, ClientAddr returnAddr); -Boolean dumpOSC_SendReply(char *buf, int n, void *clientDesc, int clientDescLenght, int fd); -static void dumpOSC_Smessage(t_dumpOSC *x, char *address, void *v, int n, ClientAddr returnAddr); -static void dumpOSC_PrintTypeTaggedArgs(t_dumpOSC *x, void *v, int n); -static void dumpOSC_PrintHeuristicallyTypeGuessedArgs(t_dumpOSC *x, void *v, int n, int skipComma); - -static void dumpOSC_read(t_dumpOSC *x, int sockfd) { - int clilen = x->x_clilen; - int n; - struct ClientAddressStruct ras; - ClientAddr ra = &ras; - - //catchupflag= FALSE; - -/* if (ShowBytes) { */ -/* int i; */ -/* printf("%d byte message:\n", n); */ -/* for (i = 0; i < n; ++i) { */ -/* printf(" %x (%c)\t", m[i], m[i]); */ -/* if (i%4 == 3) printf("\n"); */ -/* } */ -/* printf("\n"); */ -/* } */ - - // return catchupflag; - //struct sockaddr_in x->x_server; - //while( (n = recvfrom(sockfd, mbuf, MAXMESG, 0, &cl_addr, &clilen)) >0) - // while(( - - #ifdef _WIN32 - if ((n = recvfrom(sockfd, mbuf, MAXMESG, 0, (SOCKADDR*)&x->x_server, &clilen)) >0) - #else - if ((n = recvfrom(sockfd, mbuf, MAXMESG, 0, (struct sockaddr *)&x->x_server, &clilen)) >0) - #endif - { - //int r; - ras.cl_addr = *((struct sockaddr_in *) &x->x_server); - ras.clilen = x->x_clilen; - ras.sockfd = x->x_connectsocket; - - #ifdef DEBUG - printf("dumpOSC_read: received UDP packet of length %d\n", n); - #endif - - //if(!dumpOSC_SendReply(mbuf, n, &x->x_server, clilen, sockfd)) - { - dumpOSC_ParsePacket(x, mbuf, n, ra); - } - //r = Synthmessage(mbuf, n, &x->x_server, clilen, sockfd); - //post ("%d", r); - //outlet_anything(x->x_msgout, at[msg].a_w.w_symbol, - // emsg-msg-1, at + msg + 1); - // outlet_list(x->x_msgout, 0, n, mbuf); - //if( sgi_HaveToQuit()) goto out; - //if(r>0) goto back; - //clilen = maxclilen; - } -} - -static void *dumpOSC_new(t_symbol *compatflag, - int argc, t_atom* argv) { - t_dumpOSC *x; - struct sockaddr_in server; - int clilen=sizeof(server); - int sockfd; - int portno=0; - int udp = 1; - t_symbol *castgroup=NULL; - - - if (argc == 1) { - if (argv[0].a_type==A_FLOAT) - portno = (int)argv[0].a_w.w_float; - else - return NULL; - } - - else if (argc == 2) { - if (argv[0].a_type==A_SYMBOL) - castgroup = argv[0].a_w.w_symbol; - else - return NULL; - - if (argv[1].a_type==A_FLOAT) - portno = (int)argv[1].a_w.w_float; - else - return NULL; - } - - else { - error("[dumpOSC] needs at least one argument (port number) to function"); - return NULL; - } - - - //x->x_b = binbuf_new(); - //x->x_outat = binbuf_getvec(x->x_b); - - //{{raf}} pointer not valid yet...moving this down - //x->x_outatc = 0; {{raf}} - - /* create a socket */ - if ((sockfd = socket(AF_INET, (udp ? SOCK_DGRAM : SOCK_STREAM), 0)) == -1) - { - sys_sockerror("socket"); - return (0); - } - - server.sin_family = AF_INET; - server.sin_addr.s_addr = INADDR_ANY; - /* assign server port number */ - server.sin_port = htons((u_short)portno); - - // ss 2006 - if (castgroup) { - struct ip_mreq mreq; - int t = 1; - mreq.imr_multiaddr.s_addr = inet_addr(castgroup->s_name); - mreq.imr_interface.s_addr = htonl(INADDR_ANY); - if (setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&t,sizeof(t)) < 0) { - sys_sockerror("setsockopt"); - } - if (setsockopt(sockfd,IPPROTO_IP,IP_ADD_MEMBERSHIP,(char*)&mreq,sizeof(mreq)) < 0) { - sys_sockerror("setsockopt"); - } - } - - /* name the socket */ - if (bind(sockfd, (struct sockaddr *)&server, sizeof(server)) < 0) - { - sys_sockerror("bind"); - sys_closesocket(sockfd); - return (0); - } - - x = (t_dumpOSC *)pd_new(dumpOSC_class); - x->x_outatc = 0; // {{raf}} now pointer is valid (less invalid) - - x->x_msgout = outlet_new(&x->x_obj, &s_anything); - - // if (udp) /* datagram protocol */ - { - - sys_addpollfn(sockfd, (t_fdpollfn)dumpOSC_read, x); - x->x_connectout = 0; - } - // else /* streaming protocol */ - /* { */ - /* if (listen(sockfd, 5) < 0) */ - /* { */ - /* sys_sockerror("listen"); */ - /* sys_closesocket(sockfd); */ - /* sockfd = -1; */ - /* } */ - /* else */ - /* { */ - /* sys_addpollfn(sockfd, (t_fdpollfn)dumpOSC_connectpoll, x); */ - /* x->x_connectout = outlet_new(&x->x_obj, &s_float); */ - /* } */ - /* } */ - - x->x_connectsocket = sockfd; - x->x_server = server; - x->x_clilen = clilen; - x->x_nconnections = 0; - x->x_udp = udp; - - return (x); -} - -static void dumpOSC_free(t_dumpOSC *x) -{ - /* LATER make me clean up open connections */ - if (x->x_connectsocket >= 0) - { - sys_rmpollfn(x->x_connectsocket); - sys_closesocket(x->x_connectsocket); - } -} - -#ifdef _MSC_VER -OSC_API void dumpOSC_setup(void) -#else -void dumpOSC_setup(void) -#endif -{ - dumpOSC_class = class_new(gensym("dumpOSC"), - (t_newmethod)dumpOSC_new, (t_method)dumpOSC_free, - sizeof(t_dumpOSC), CLASS_NOINLET, A_GIMME, 0); - class_sethelpsymbol(dumpOSC_class, gensym("dumpOSC-help.pd")); - - error("[dumpOSC]: OSCx is deprecated! \n\tConsider switching to mrpeach's [unpackOSC] and [udpreceive]"); -} - - -#ifndef _WIN32 - #define UNIXDG_PATH "/tmp/htm" - #define UNIXDG_TMP "/tmp/htm.XXXXXX" - static int unixinitudp(int chan) - { - struct sockaddr_un serv_addr; - int sockfd; - - if((sockfd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) - return sockfd; - - bzero((char *)&serv_addr, sizeof(serv_addr)); - serv_addr.sun_family = AF_UNIX; - strcpy(serv_addr.sun_path, UNIXDG_PATH); - sprintf(serv_addr.sun_path+strlen(serv_addr.sun_path), "%d", chan); - unlink(serv_addr.sun_path); - if(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr.sun_family)+strlen(serv_addr.sun_path)) < 0) - { - perror("unable to bind\n"); - return -1; - } - - fcntl(sockfd, F_SETFL, FNDELAY); - return sockfd; - } -#endif // #ifndef _WIN32 - - - -static int initudp(int chan) -{ - -#ifdef _WIN32 - struct sockaddr_in serv_addr; - unsigned int sockfd; - ULONG nonBlocking = (ULONG) TRUE; - - if( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) != INVALID_SOCKET ) { - ZeroMemory((char *)&serv_addr, sizeof(serv_addr)); - serv_addr.sin_family = AF_INET; - serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); - serv_addr.sin_port = htons(chan); - if(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) >= 0) { - // set for non-blocking mode - if(ioctlsocket(sockfd, FIONBIO, &nonBlocking) == SOCKET_ERROR) { - perror("unable to set non-blocking\n"); - return -1; - } - } - else { perror("unable to bind\n"); return -1; } - } - return (sockfd == INVALID_SOCKET ? -1 : (int)sockfd); -#else - struct sockaddr_in serv_addr; - int sockfd; - - if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) - return sockfd; - - bzero((char *)&serv_addr, sizeof(serv_addr)); - serv_addr.sin_family = AF_INET; - serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); - serv_addr.sin_port = htons(chan); - - if(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) - { - perror("unable to bind\n"); - return -1; - } - - fcntl(sockfd, F_SETFL, FNDELAY); - return sockfd; -#endif -} - -static void closeudp(int sockfd) { - #ifdef _WIN32 - closesocket(sockfd); - #else - close(sockfd); - #endif -} - -static Boolean catchupflag=FALSE; -Boolean ClientReply(int packetsize, void *packet, int socketfd, - void *clientaddresspointer, int clientaddressbufferlength) -{ - if(!clientaddresspointer) return FALSE; - catchupflag= TRUE; - return packetsize==sendto(socketfd, packet, packetsize, 0, clientaddresspointer, clientaddressbufferlength); -} - -static Boolean exitflag= FALSE; -void sgi_CleanExit(void) { - exitflag = TRUE; -} - -Boolean sgi_HaveToQuit(void) { - return exitflag; -} - - -/* file descriptor poll table */ -static int npolldevs =0; -typedef struct polldev -{ - int fd; - void (*callbackfunction)(int , void *); - void *dummy; -} polldev; -#define TABMAX 8 -static polldev polldevs[TABMAX]; - - -/* Register a device (referred to by a file descriptor that the caller - should have already successfully obtained from a system call) to be - polled as real-time constraints allowed. - - When a select(2) call indicates activity on the file descriptor, the - callback function is called with the file descripter as first - argument and the given dummy argument (presumably a pointer to the - instance variables associated with the device). -*/ -int RegisterPollingDevice(int fd, void (*callbackfunction)(int , void *), void *dummy) -{ - if(npolldevscl_addr.sin_addr.s_addr; - printf("Client address %p:\n", CA); - printf(" clilen %d, sockfd %d\n", CA->clilen, CA->sockfd); - printf(" sin_family %d, sin_port %d\n", CA->cl_addr.sin_family, - CA->cl_addr.sin_port); - printf(" address: (%lx) %s\n", addr, inet_ntoa(CA->cl_addr.sin_addr)); - - printf(" sin_zero = \"%c%c%c%c%c%c%c%c\"\n", - CA->cl_addr.sin_zero[0], - CA->cl_addr.sin_zero[1], - CA->cl_addr.sin_zero[2], - CA->cl_addr.sin_zero[3], - CA->cl_addr.sin_zero[4], - CA->cl_addr.sin_zero[5], - CA->cl_addr.sin_zero[6], - CA->cl_addr.sin_zero[7]); - - printf("\n"); -} - -//******************* - -/*void WriteTime(char* dst, osc_time_t osctime) -{ - *(int32_t*)dst = htonl((int32_t)(osctime >> 32)); - *(int32_t*)(dst+4) = htonl((int32_t)osctime); -} - -void WriteMode(char* dst) -{ - *(int32_t*)dst = htonl(0); -} - -osc_time_t ReadTime(const char* src) -{ - osc_time_t osctime = ntohl(*(int32_t*)src); - return (osctime << 32) + ntohl(*(int32_t*)(src+4)); -} - -double TimeToSeconds(osc_time_t osctime) -{ - return (double)osctime * 2.3283064365386962890625e-10 // 1/2^32 ; -// ^^^^^^^^^^^^^^^ isn't working on WIN32 (and on other machines: doesn't make sense!) -} - -int timeRound(double x) -{ - return x >= 0.0 ? x+0.5 : x-0.5; -} -*/ -/* -void WriteLogicalTime(char* dst) -{ - static double startTime = -1.0; - double sTime; - - // Initialisierung der Startzeit. - // Knnte effizienter (ohne 'if') auch irgendwo vorher passieren. - // Knnte wahrscheinlich auch 0.0 sein. - if (startTime < 0.0) { - startTime = clock_getlogicaltime(); - } - - sTime = clock_gettimesince(startTime) * 0.001; - *(int32_t*)dst = hton'K l((int32_t)sTime); - *(int32_t*)(dst+4) = htonl((int32_t)(4294967296.0 * sTime)); -} -*/ - -/*void WriteLogicalTime(char* dst) -{ - double sTime = clock_gettimesince(19230720) / 1000.0; - double tau = sTime - (double)timeRound(sTime); - - //fprintf(stderr, "sSec = %f tau = %f\n", sTime, tau); - - *(int32_t*)dst = htonl((int32_t)(sTime)); - *(int32_t*)(dst+4) = htonl((int32_t)(4294967296 * tau)); -} - -int dumpOSC_SendReply(char *buf, int n, void *clientDesc, int clientDescLenght, int fd) -{ - if((n == 24) && (strcmp(buf, "#time") == 0)) - { - osc_time_t t0, t1, t2; - double dt0, dt1, dt2; - - WriteMode(buf+6); - - t0 = ReadTime(buf+8); - - WriteLogicalTime(buf+16); - t1 = ReadTime(buf+16); // reverse - dt0 = TimeToSeconds(t0); // client time - dt1 = TimeToSeconds(t1); // server time - - // fprintf(stderr, "%f\t%f\t%f\n", dt0, dt1, dt0 - dt1); - - sendto(fd, buf, n, 0, (struct sockaddr *)clientDesc, clientDescLenght); - return TRUE; - } - else - { - return FALSE; - } -}*/ - -//********************** - -void dumpOSC_ParsePacket(t_dumpOSC *x, char *buf, int n, ClientAddr returnAddr) { - // t_dumpOSC *x; - int size, messageLen, i; - char *messageName; - char *args; - - //#ifdef PRINTADDRS - #ifdef DEBUG - //PrintClientAddr(returnAddr); - #endif - - - if ((n%4) != 0) { - complain("SynthControl packet size (%d) not a multiple of 4 bytes: dropping", n); - return; - } - - if ((n >= 8) && (strncmp(buf, "#bundle", 8) == 0)) { - /* This is a bundle message. */ - #ifdef DEBUG - printf("dumpOSC_ParsePacket: bundle msg: bundles not yet supported\n"); - #endif - - if (n < 16) { - complain("Bundle message too small (%d bytes) for time tag", n); - return; - } - - /* Print the time tag */ - #ifdef DEBUG - printf("[ %lx%08lx\n", ntohl(*((unsigned long *)(buf+8))), ntohl(*((unsigned long *)(buf+12)))); - #endif - - /* Note: if we wanted to actually use the time tag as a little-endian - 64-bit int, we'd have to word-swap the two 32-bit halves of it */ - - i = 16; /* Skip "#group\0" and time tag */ - - while(i n) { - complain("Bad size count %d in bundle (only %d bytes left in entire bundle)", - size, n-i-4); - return; - } - - /* Recursively handle element of bundle */ - dumpOSC_ParsePacket(x, buf+i+4, size, returnAddr); - i += 4 + size; - } - - if (i != n) { - complain("This can't happen"); - } - #ifdef DEBUG - printf("]\n"); - #endif - - } - else if ((n == 24) && (strcmp(buf, "#time") == 0)) - { - complain("Time message: %s\n :).\n", htm_error_string); - return; - - } - else - { - /* This is not a bundle message */ - - messageName = buf; - args = DataAfterAlignedString(messageName, buf+n); - if (args == 0) { - complain("Bad message name string: %s\nDropping entire message.\n", - htm_error_string); - return; - } - messageLen = args-messageName; - dumpOSC_Smessage(x, messageName, (void *)args, n-messageLen, returnAddr); - } -} - -#define SMALLEST_POSITIVE_FLOAT 0.000001f - -static void dumpOSC_Smessage(t_dumpOSC *x, char *address, void *v, int n, ClientAddr returnAddr) { - char *chars = v; - //t_atom at; - //t_atom myargv[50]; - - //int myargc = x->x_outatc; - //t_atom* mya = x->x_outat; - //int myi; - -#ifdef DEBUG - printf("%s ", address); -#endif - - // ztoln+cvt from envgen.c, ggee-0.18 .. - // outlet_anything's 'symbol' gets set to address - // so we dont need to append address to the atomlist - /* - SETSYMBOL(mya,gensym(address));myargc++; - x->x_outatc = myargc; - */ - - if (n != 0) { - if (chars[0] == ',') { - if (chars[1] != ',') { - /* This message begins with a type-tag string */ - dumpOSC_PrintTypeTaggedArgs(x, v, n); - } else { - /* Double comma means an escaped real comma, not a type string */ - dumpOSC_PrintHeuristicallyTypeGuessedArgs(x, v, n, 1); - } - } else { - dumpOSC_PrintHeuristicallyTypeGuessedArgs(x, v, n, 0); - } - } - - outlet_anything(x->x_msgout,gensym(address),x->x_outatc,(t_atom*)&x->x_outat); - x->x_outatc = 0; -#ifdef DEBUG - printf("\n"); -#endif - fflush(stdout); /* Added for Sami 5/21/98 */ -} - -static void dumpOSC_PrintTypeTaggedArgs(t_dumpOSC *x, void *v, int n) { - char *typeTags, *thisType; - char *p; - - int myargc = x->x_outatc; - t_atom* mya = x->x_outat; - //int myi; - - typeTags = v; - - if (!IsNiceString(typeTags, typeTags+n)) { - /* No null-termination, so maybe it wasn't a type tag - string after all */ - dumpOSC_PrintHeuristicallyTypeGuessedArgs(x, v, n, 0); - return; - } - - p = DataAfterAlignedString(typeTags, typeTags+n); - - - for (thisType = typeTags + 1; *thisType != 0; ++thisType) { - switch (*thisType) { - case 'i': case 'r': case 'm': case 'c': -#ifdef DEBUG - //post("integer: %d", ntohl(*((int *) p))); -#endif - /* Martin Peach fix for negative floats: - * was: SETFLOAT(mya+myargc,ntohl(*((int *) p))); - * now is: - */ - SETFLOAT(mya+myargc,(signed)ntohl(*((int *) p))); - myargc++; - - p += 4; - break; - - case 'f': { - int i = ntohl(*((int *) p)); - t_float *floatp = ((t_float *) (&i)); -#ifdef DEBUG - post("float: %f", *floatp); -#endif - SETFLOAT(mya+myargc,*floatp); - myargc++; - - p += 4; - } - break; - - case 'h': case 't': -#ifdef DEBUG - printf("[A 64-bit int] "); -#endif - post("[A 64-bit int] not implemented"); - - p += 8; - break; - - case 'd': -#ifdef DEBUG - printf("[A 64-bit float] "); -#endif - post("[A 64-bit float] not implemented"); - - p += 8; - break; - - case 's': case 'S': - if (!IsNiceString(p, typeTags+n)) { - post("Type tag said this arg is a string but it's not!\n"); - return; - } else { -#ifdef DEBUG - post("string: \"%s\"", p); -#endif - SETSYMBOL(mya+myargc,gensym(p)); - myargc++; - //outlet_list(x->x_msgout, 0,sizeof(p), p); - //outlet_anything(x->x_msgout, 0, sizeof(p), p); - p = DataAfterAlignedString(p, typeTags+n); - // append to output vector .. - } - break; - - case 'T': -#ifdef DEBUG - printf("[True] "); -#endif - SETFLOAT(mya+myargc,1.); - myargc++; - break; - case 'F': -#ifdef DEBUG - printf("[False] "); -#endif - SETFLOAT(mya+myargc,0.); - myargc++; - break; - case 'N': -#ifdef DEBUG - printf("[Nil]"); -#endif - post("sendOSC: [Nil] not implemented"); - break; - case 'I': -#ifdef DEBUG - printf("[Infinitum]"); -#endif - post("sendOSC: [Infinitum] not implemented"); - break; - - default: - post("sendOSC: [Unrecognized type tag %c]", *thisType); - // return; - } - } - x->x_outatc = myargc; -} - -static void dumpOSC_PrintHeuristicallyTypeGuessedArgs(t_dumpOSC *x, void *v, int n, int skipComma) { - int i, thisi; - t_float thisf; - int *ints; - char *chars; - char *string, *nextString; - - int myargc= x->x_outatc; - t_atom* mya = x->x_outat; - //int myi; - - union - { - float f; - int32_t i; - }u; - - /* Go through the arguments 32 bits at a time */ - ints = v; - chars = v; - - for (i = 0; i= -1000 && thisi <= 1000000) { -#ifdef DEBUG - printf("%d ", thisi); -#endif - // append to output vector .. - SETFLOAT(mya+myargc,(t_float) (thisi)); - myargc++; - // outlet_float(x->x_msgout, thisi); - i++; - } else if (thisf >= -1000.f && thisf <= 1000000.f && - (thisf <=0.0f || thisf >= SMALLEST_POSITIVE_FLOAT)) { -#ifdef DEBUG - printf("%f ", thisf); -#endif - // append to output vector .. - SETFLOAT(mya+myargc,thisf); - myargc++; - //outlet_float(x->x_msgout, thisf); - i++; - } else if (IsNiceString(string, chars+n)) { - nextString = DataAfterAlignedString(string, chars+n); -#ifdef DEBUG - printf("\"%s\" ", (i == 0 && skipComma) ? string +1 : string); -#endif - // append to output vector .. - SETSYMBOL(mya+myargc,gensym(string)); - myargc++; - //outlet_symbol(x->x_msgout, gensym((i == 0 && skipComma) ? string +1 : string)); - i += (nextString-string) / 4; - } else { - // unhandled .. ;) -#ifdef DEBUG - printf("0x%x xx", ints[i]); -#endif - i++; - } - x->x_outatc = myargc; - } -} - - -#define STRING_ALIGN_PAD 4 - -char *DataAfterAlignedString(char *string, char *boundary) -{ - /* The argument is a block of data beginning with a string. The - string has (presumably) been padded with extra null characters - so that the overall length is a multiple of STRING_ALIGN_PAD - bytes. Return a pointer to the next byte after the null - byte(s). The boundary argument points to the character after - the last valid character in the buffer---if the string hasn't - ended by there, something's wrong. - - If the data looks wrong, return 0, and set htm_error_string */ - - int i; - - if ((boundary - string) %4 != 0) { - fprintf(stderr, "Internal error: DataAfterAlignedString: bad boundary\n"); - return 0; - } - - for (i = 0; string[i] != '\0'; i++) { - if (string + i >= boundary) { - htm_error_string = "DataAfterAlignedString: Unreasonably long string"; - return 0; - } - } - - /* Now string[i] is the first null character */ - i++; - - for (; (i % STRING_ALIGN_PAD) != 0; i++) { - if (string + i >= boundary) { - htm_error_string = "DataAfterAlignedString: Unreasonably long string"; - return 0; - } - if (string[i] != '\0') { - htm_error_string = "DataAfterAlignedString: Incorrectly padded string."; - return 0; - } - } - - return string+i; -} - -Boolean IsNiceString(char *string, char *boundary) -{ - /* Arguments same as DataAfterAlignedString(). Is the given "string" - really a string? I.e., is it a sequence of isprint() characters - terminated with 1-4 null characters to align on a 4-byte boundary? */ - - int i; - - if ((boundary - string) %4 != 0) { - fprintf(stderr, "Internal error: IsNiceString: bad boundary\n"); - return 0; - } - - for (i = 0; string[i] != '\0'; i++) { - if (!isprint(string[i])) return FALSE; - if (string + i >= boundary) return FALSE; - } - - /* If we made it this far, it's a null-terminated sequence of printing characters - in the given boundary. Now we just make sure it's null padded... */ - - /* Now string[i] is the first null character */ - i++; - for (; (i % STRING_ALIGN_PAD) != 0; i++) { - if (string[i] != '\0') return FALSE; - } - - return TRUE; -} - - - - - - - - - -#include -void complain(char *s, ...) { - va_list ap; - va_start(ap, s); - fprintf(stderr, "*** ERROR: "); - vfprintf(stderr, s, ap); - fprintf(stderr, "\n"); - va_end(ap); -} - -#endif /* __sgi or LINUX or _WIN32 */ diff --git a/src/htmsocket.c b/src/htmsocket.c deleted file mode 100644 index 16a1050..0000000 --- a/src/htmsocket.c +++ /dev/null @@ -1,387 +0,0 @@ -/* -Written by Adrian Freed, The Center for New Music and Audio Technologies, -University of California, Berkeley. Copyright (c) 1992,93,94,95,96,97,98,99,2000,01,02,03,04 -The Regents of the University of California (Regents). - -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 OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl -*/ - - /* htmsocket.c - - Adrian Freed - send parameters to htm servers by udp or UNIX protocol - - Modified 6/6/96 by Matt Wright to understand symbolic host names - in addition to X.X.X.X addresses. - - pd: branched jdl - -- win additions raf 2002 - -- enabled broadcast jdl 2003 - */ - -#if HAVE_CONFIG_H -#include -#endif - -#ifdef __APPLE__ - #include -#endif - -#ifdef WIN32 - #include - #include - #include - #include - #include - #include - #include - #include "OSC-common.h" - #include - #include - #include -#else - #include - #include - #include - #include - #include - -// #include - #include - #include - #include - #include - #include - #include - - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include -// #include - - #include -#endif - -#define UNIXDG_PATH "/tmp/htm" -#define UNIXDG_TMP "/tmp/htm.XXXXXX" -#include "htmsocket.h" -typedef struct -{ - float srate; - - struct sockaddr_in serv_addr; /* udp socket */ - #ifndef WIN32 - struct sockaddr_un userv_addr; /* UNIX socket */ - #endif - int sockfd; /* socket file descriptor */ - int index, len,uservlen; - void *addr; - int id; -} desc; - -int IsAddressMulticast(unsigned long address) -{ - unsigned long adr = ntohl(address); - unsigned char A = (unsigned char)((adr & 0xFF000000) >> 24); - unsigned char B = (unsigned char)((adr & 0xFF0000) >> 16); - unsigned char C = (unsigned char)((adr & 0xFF00) >> 8); - - if (A==224 && B==0 && C==0) { - // This multicast group range is reserved for routing - // information and not meant to be used by applications. - return -1; - } - - // This is the multicast group IP range - if (A>=224 && A<=239) - return 1; - - return 0; -} - -/* open a socket for HTM communication to given host on given portnumber */ -/* if host is 0 then UNIX protocol is used (i.e. local communication */ -void *OpenHTMSocket(char *host, int portnumber, short *multicast_TTL) -{ - struct sockaddr_in cl_addr; - #ifndef WIN32 - int sockfd; - struct sockaddr_un ucl_addr; - #else - unsigned int sockfd; - #endif - - char oval = 1; - - desc *o; - o = malloc(sizeof(*o)); - if(!o) - return 0; - - #ifndef WIN32 - - if(!host) - { - char *mktemp(char *); - int clilen; - o->len = sizeof(ucl_addr); - /* - * Fill in the structure "userv_addr" with the address of the - * server that we want to send to. - */ - - bzero((char *) &o->userv_addr, sizeof(o->userv_addr)); - o->userv_addr.sun_family = AF_UNIX; - strcpy(o->userv_addr.sun_path, UNIXDG_PATH); - sprintf(o->userv_addr.sun_path+strlen(o->userv_addr.sun_path), "%d", portnumber); - o->uservlen = sizeof(o->userv_addr.sun_family) + strlen(o->userv_addr.sun_path); - o->addr = &(o->userv_addr); - /* - * Open a socket (a UNIX domain datagram socket). - */ - - if ( (sockfd = socket(AF_UNIX, SOCK_DGRAM, 0)) >= 0) - { - /* - * Bind a local address for us. - * In the UNIX domain we have to choose our own name (that - * should be unique). We'll use mktemp() to create a unique - * pathname, based on our process id. - */ - - bzero((char *) &ucl_addr, sizeof(ucl_addr)); /* zero out */ - ucl_addr.sun_family = AF_UNIX; - strcpy(ucl_addr.sun_path, UNIXDG_TMP); - - mktemp(ucl_addr.sun_path); - clilen = sizeof(ucl_addr.sun_family) + strlen(ucl_addr.sun_path); - - if (bind(sockfd, (struct sockaddr *) &ucl_addr, clilen) < 0) - { - perror("client: can't bind local address"); - close(sockfd); - sockfd = -1; - } - } - else - perror("unable to make socket\n"); - - }else - - #endif - - { - /* - * Fill in the structure "serv_addr" with the address of the - * server that we want to send to. - */ - o->len = sizeof(cl_addr); - - #ifdef WIN32 - ZeroMemory((char *)&o->serv_addr, sizeof(o->serv_addr)); - #else - bzero((char *)&o->serv_addr, sizeof(o->serv_addr)); - #endif - - o->serv_addr.sin_family = AF_INET; - - /* MW 6/6/96: Call gethostbyname() instead of inet_addr(), - so that host can be either an Internet host name (e.g., - "les") or an Internet address in standard dot notation - (e.g., "128.32.122.13") */ - { - struct hostent *hostsEntry; - unsigned long address; - - hostsEntry = gethostbyname(host); - if (hostsEntry == NULL) { - fprintf(stderr, "Couldn't decipher host name \"%s\"\n", host); - #ifndef WIN32 - herror(NULL); - #endif - return 0; - } - - address = *((unsigned long *) hostsEntry->h_addr_list[0]); - o->serv_addr.sin_addr.s_addr = address; - } - - /* was: o->serv_addr.sin_addr.s_addr = inet_addr(host); */ - - /* End MW changes */ - - /* - * Open a socket (a UDP domain datagram socket). - */ - - - #ifdef WIN32 - o->serv_addr.sin_port = htons((USHORT)portnumber); - o->addr = &(o->serv_addr); - if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) != INVALID_SOCKET) { - ZeroMemory((char *)&cl_addr, sizeof(cl_addr)); - cl_addr.sin_family = AF_INET; - cl_addr.sin_addr.s_addr = htonl(INADDR_ANY); - cl_addr.sin_port = htons(0); - - // enable broadcast: jdl ~2003 - if(setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &oval, sizeof(int)) == -1) { - perror("setsockopt broadcast"); - } - - // check if specified address is a multicast group: ss 2007 - int multicast = IsAddressMulticast(o->serv_addr.sin_addr.s_addr); - - if (multicast == -1) { - perror("Multicast group range 224.0.0.[0-255] is reserved.\n"); - *multicast_TTL = -2; - close(sockfd); - sockfd = -1; - } - else { - // set TTL according to whether we have a multicast group or not - if (multicast) { - if (*multicast_TTL<0) - *multicast_TTL = 1; - } else - *multicast_TTL = -1; - - // set multicast Time-To-Live only if it is a multicast group: ss 2007 - if(*multicast_TTL>=0) { - unsigned char ttl = (unsigned char)*multicast_TTL; - if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, - &ttl, sizeof(ttl)) == -1) - perror("setsockopt TTL"); - } - - if(bind(sockfd, (struct sockaddr *) &cl_addr, sizeof(cl_addr)) < 0) { - perror("could not bind\n"); - closesocket(sockfd); - sockfd = -1; - } - } - } - else { perror("unable to make socket\n");} - #else - o->serv_addr.sin_port = htons(portnumber); - o->addr = &(o->serv_addr); - if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) >= 0) { - bzero((char *)&cl_addr, sizeof(cl_addr)); - cl_addr.sin_family = AF_INET; - cl_addr.sin_addr.s_addr = htonl(INADDR_ANY); - cl_addr.sin_port = htons(0); - - // enable broadcast: jdl ~2003 - if(setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &oval, sizeof(int)) == -1) { - perror("setsockopt"); - } - - // check if specified address is a multicast group: ss 2007 - int multicast = IsAddressMulticast(o->serv_addr.sin_addr.s_addr); - - if (multicast == -1) { - perror("Multicast group range 224.0.0.[0-255] is reserved.\n"); - *multicast_TTL = -2; - close(sockfd); - sockfd = -1; - } - else { - // check if specified address is a multicast group: ss 2007 - if (multicast) { - if (*multicast_TTL<0) - *multicast_TTL = 1; - } else - *multicast_TTL = -1; - - // set multicast Time-To-Live only if it is a multicast group: ss 2007 - if(*multicast_TTL>=0) { - unsigned char ttl = (unsigned char)*multicast_TTL; - if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, - &ttl, sizeof(ttl)) == -1) - perror("setsockopt TTL"); - } - - if(bind(sockfd, (struct sockaddr *) &cl_addr, sizeof(cl_addr)) < 0) { - perror("could not bind\n"); - close(sockfd); - sockfd = -1; - } - } - } - else { perror("unable to make socket\n");} - #endif - } - #ifdef WIN32 - if(sockfd == INVALID_SOCKET) { - #else - if(sockfd < 0) { - #endif - free(o); - o = 0; - } - else - o->sockfd = sockfd; - return o; -} - - -#include - -static bool sendudp(const struct sockaddr *sp, int sockfd,int length, int count, void *b) -{ - int rcount; - if((rcount=sendto(sockfd, b, count, 0, sp, length)) != count) - { - printf("sockfd %d count %d rcount %dlength %d errno %d\n", sockfd,count,rcount,length, errno); - return FALSE; - } - return TRUE; -} -bool SendHTMSocket(void *htmsendhandle, int length_in_bytes, void *buffer) -{ - desc *o = (desc *)htmsendhandle; - return sendudp(o->addr, o->sockfd, o->len, length_in_bytes, buffer); -} -void CloseHTMSocket(void *htmsendhandle) -{ - desc *o = (desc *)htmsendhandle; - #ifdef WIN32 - if(SOCKET_ERROR == closesocket(o->sockfd)) { - perror("CloseHTMSocket::closesocket failed\n"); - return; - } - #else - if(close(o->sockfd) == -1) - { - perror("CloseHTMSocket::closesocket failed"); - return; - } - #endif - - free(o); -} diff --git a/src/htmsocket.h b/src/htmsocket.h deleted file mode 100644 index 685c1f7..0000000 --- a/src/htmsocket.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -Written by Adrian Freed, The Center for New Music and Audio Technologies, -University of California, Berkeley. Copyright (c) 1992,93,94,95,96,97,98,99,2000,01,02,03,04 -The Regents of the University of California (Regents). - -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 OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl -*/ - - - /* htmparam.h - - Adrian Freed - send parameters to htm servers by udp or UNIX protocol - */ -#ifndef TRUE -#define TRUE 1 -#define FALSE 0 -#endif -typedef int bool; - -/* open a socket for HTM communication to given host on given portnumber */ -/* if host is 0 then UNIX protocol is used (i.e. local communication) */ -void *OpenHTMSocket(char *host, int portnumber, short *multicast_TTL); - -/* send a buffer of data over htm socket, returns TRUE on success. - Note that udp sends rarely fail. UNIX sends fail if a kernal buffer overflows */ -bool SendHTMSocket(void *htmsendhandle, int length_in_bytes, void *buffer); - -/* close the socket(2) and release memory associated with it */ -void CloseHTMSocket(void *htmsendhandle); diff --git a/src/sendOSC.c b/src/sendOSC.c deleted file mode 100644 index ffbffab..0000000 --- a/src/sendOSC.c +++ /dev/null @@ -1,585 +0,0 @@ -/* -Written by Matt Wright, The Center for New Music and Audio Technologies, -University of California, Berkeley. Copyright (c) 1996,97,98,99,2000,01,02,03 -The Regents of the University of California (Regents). - -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 OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl -*/ - - - -/* sendOSC.c - - Matt Wright, 6/3/97 - based on sendOSC.c, which was based on a version by Adrian Freed - - Text-based OpenSoundControl client. User can enter messages via command - line arguments or standard input. - - Version 0.1: "play" feature - Version 0.2: Message type tags. - - pd version branched from http://www.cnmat.berkeley.edu/OpenSoundControl/src/sendOSC/sendOSC.c - ------------- - -- added bundle stuff to send. jdl 20020416 - -- tweaks for Win32 www.zeggz.com/raf 13-April-2002 - -- ost_at_test.at + i22_at_test.at, 2000-2002 - modified to compile as pd externel - --20060308 MP clear out some unused code and improve conversion from pd types to OSC types -*/ - -#if HAVE_CONFIG_H -#include -#endif - -#define MAX_ARGS 2000 -#define SC_BUFFER_SIZE 64000 - -#include "m_pd.h" - -#include "OSC-common.h" -#include "OSC-client.h" -#include "htmsocket.h" - -#include -#include - -#ifdef WIN32 -#include -#else -#include -#include -#include -#include -#include -#endif - -/////////////////////// -// from sendOSC - -typedef struct -{ - enum {INT_osc, FLOAT_osc, STRING_osc, NOTYPE_osc} type; - union - { - int i; - t_float f; - char *s; - } datum; -} typedArg; - - -//static int exitStatus = 0; -static int useTypeTags = 0; - -static char bufferForOSCbuf[SC_BUFFER_SIZE]; - - -///////// -// end from sendOSC - -static t_class *sendOSC_class; - -typedef struct _sendOSC -{ - t_object x_obj; - int x_protocol; // UDP/TCP (udp only atm) - t_int x_typetags; // typetag flag - void *x_htmsocket; // sending socket - int x_bundle; // bundle open flag - OSCbuf x_oscbuf[1]; // OSCbuffer - t_outlet *x_bdpthout;// bundle-depth floatoutlet -} t_sendOSC; - -static void *sendOSC_new(t_floatarg udpflag); -void sendOSC_openbundle(t_sendOSC *x); -static void sendOSC_closebundle(t_sendOSC *x); -static void sendOSC_settypetags(t_sendOSC *x, t_float *f); -static void sendOSC_connect(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv); -void sendOSC_disconnect(t_sendOSC *x); -static void sendOSC_sendtyped(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv); -void sendOSC_send(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv); -static void sendOSC_free(t_sendOSC *x); -void sendOSC_setup(void); -typedArg ParseAtom(t_atom *a); -int WriteMessage(OSCbuf *buf, char *messageName, int numArgs, typedArg *args); -void SendBuffer(void *htmsocket, OSCbuf *buf); -void SendData(void *htmsocket, int size, char *data); - -static void *sendOSC_new(t_floatarg udpflag) -{ - t_sendOSC *x = (t_sendOSC *)pd_new(sendOSC_class); - - outlet_new(&x->x_obj, &s_float); - x->x_htmsocket = 0; // {{raf}} - // set udp - x->x_protocol = SOCK_DGRAM; ////MP20060308// not SOCK_STREAM but we don't use it anyway... - // set typetags to 1 by default - x->x_typetags = 1; - // bundle is closed - x->x_bundle = 0; - OSC_initBuffer(x->x_oscbuf, SC_BUFFER_SIZE, bufferForOSCbuf); - x->x_bdpthout = outlet_new(&x->x_obj, 0); // outlet_float(); - //x->x_oscbuf = - return (x); -} - - -void sendOSC_openbundle(t_sendOSC *x) -{ - if (x->x_oscbuf->bundleDepth + 1 >= MAX_BUNDLE_NESTING || - OSC_openBundle(x->x_oscbuf, OSCTT_Immediately())) - { - error("Problem opening bundle: %s\n", OSC_errorMessage); - return; - } - x->x_bundle = 1; - outlet_float(x->x_bdpthout, (t_float)x->x_oscbuf->bundleDepth); -} - -static void sendOSC_closebundle(t_sendOSC *x) -{ - if (OSC_closeBundle(x->x_oscbuf)) - { - error("Problem closing bundle: %s\n", OSC_errorMessage); - return; - } - outlet_float(x->x_bdpthout, (t_float)x->x_oscbuf->bundleDepth); - // in bundle mode we send when bundle is closed? - if(!OSC_isBufferEmpty(x->x_oscbuf) > 0 && OSC_isBufferDone(x->x_oscbuf)) - { - // post("x_oscbuf: something inside me?"); - if (x->x_htmsocket) - { - SendBuffer(x->x_htmsocket, x->x_oscbuf); - } - else - { - post("sendOSC: not connected"); - } - OSC_initBuffer(x->x_oscbuf, SC_BUFFER_SIZE, bufferForOSCbuf); - x->x_bundle = 0; - return; - } - // post("x_oscbuf: something went wrong"); -} - -static void sendOSC_settypetags(t_sendOSC *x, t_float *f) - { - x->x_typetags = (int)f; - post("sendOSC.c: setting typetags %d",x->x_typetags); - } - -static void sendOSC_connect(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv) // t_symbol *hostname, t_floatarg fportno, int argc, t_atom *argv) -{ - t_float fportno=0; - t_symbol *hostname; - int portno = fportno; - short ttl=-1; - char *protocolStr; - /* create a socket */ - - if (argc < 2) - return; - - if (argv[0].a_type==A_SYMBOL) - hostname = argv[0].a_w.w_symbol; - else - return; - - if (argv[1].a_type==A_FLOAT) - portno = (int)argv[1].a_w.w_float; - else - return; - - if (argc >= 3) { - if (argv[2].a_type==A_FLOAT) - ttl = (short)(unsigned char)argv[2].a_w.w_float; - else - return; - } - - // make sure handle is available - if(x->x_htmsocket == 0) - { - x->x_htmsocket = OpenHTMSocket(hostname->s_name, portno, &ttl); - if (!x->x_htmsocket) { - post("sendOSC: Couldn't open socket: "); - if (ttl==-2) - post("sendOSC: Multicast group range 224.0.0.[0-255] is reserved.\n"); - } - else - { - switch (x->x_protocol) - { - case SOCK_DGRAM: - protocolStr = "UDP"; - break; - case SOCK_STREAM: - protocolStr = "TCP"; - break; - default: - protocolStr = "unknown"; - break; - } - if (ttl>=0) - post("sendOSC: connected to port %s:%d (hSock=%d) protocol = %s ttl = %d", - hostname->s_name, portno, x->x_htmsocket, protocolStr, ttl); - else - post("sendOSC: connected to port %s:%d (hSock=%d) protocol = %s", - hostname->s_name, portno, x->x_htmsocket, protocolStr); - outlet_float(x->x_obj.ob_outlet, 1); - } - } - else - perror("call to sendOSC_connect() against unavailable socket handle"); -} - -void sendOSC_disconnect(t_sendOSC *x) -{ - if (x->x_htmsocket) - { - post("sendOSC: disconnecting htmsock (hSock=%d)...", x->x_htmsocket); - CloseHTMSocket(x->x_htmsocket); - x->x_htmsocket = 0; // {{raf}} semi-quasi-semaphorize this - outlet_float(x->x_obj.ob_outlet, 0); - } - else - { - perror("call to sendOSC_disconnect() against unused socket handle"); - } -} - - -////////////////////////////////////////////////////////////////////// -// this is the real and only sending routine now, for both typed and -// undtyped mode. - -static void sendOSC_sendtyped(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv) -{ - char messageName[MAXPDSTRING]; - // char *token; - typedArg args[MAX_ARGS]; - int i; - - messageName[0] = '\0'; // empty - - if(argc>MAX_ARGS) - { - post ("sendOSC: too many arguments! (max: %d)", MAX_ARGS); - return; - } - - // this sock needs to be larger than 0, not >= .. - if (x->x_htmsocket > 0) - { -#ifdef DEBUG - post ("sendOSC: type tags? %d", useTypeTags); -#endif - - atom_string(&argv[0], messageName, MAXPDSTRING); -// messageName = strtok(targv[0], ","); - for (i = 0; i < argc-1; i++) - { -// token = strtok(targv[i],","); - - args[i] = ParseAtom(&argv[i+1]); -#ifdef DEBUG - switch (args[i].type) - { - case INT_osc: - printf("cell-cont: %d\n", args[i].datum.i); - break; - case FLOAT_osc: - printf("cell-cont: %f\n", args[i].datum.f); - break; - case STRING_osc: - printf("cell-cont: %s\n", args[i].datum.s); - break; - case NOTYPE_osc: - printf("unknown type\n"); - break; - } - printf(" type-id: %d\n", args[i].type); -#endif - } - - if(WriteMessage(x->x_oscbuf, messageName, i, args)) - { - post("sendOSC: usage error, write-msg failed: %s", OSC_errorMessage); - return; - } - - if(!x->x_bundle) - { - SendBuffer(x->x_htmsocket, x->x_oscbuf); - OSC_initBuffer(x->x_oscbuf, SC_BUFFER_SIZE, bufferForOSCbuf); - } - - } - else post("sendOSC: not connected"); -} - -void sendOSC_send(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv) -{ - if(!argc) - { - post("not sending empty message."); - return; - } - if(x->x_typetags) - { - useTypeTags = 1; - sendOSC_sendtyped(x,s,argc,argv); - useTypeTags = 0; - } - else - { - sendOSC_sendtyped(x,s,argc,argv); - } -} - -static void sendOSC_free(t_sendOSC *x) -{ - sendOSC_disconnect(x); -} - -void sendOSC_setup(void) -{ - sendOSC_class = class_new(gensym("sendOSC"), (t_newmethod)sendOSC_new, - (t_method)sendOSC_free, - sizeof(t_sendOSC), 0, A_DEFFLOAT, 0); - class_addmethod(sendOSC_class, (t_method)sendOSC_connect, - gensym("connect"), A_GIMME, 0); - class_addmethod(sendOSC_class, (t_method)sendOSC_disconnect, - gensym("disconnect"), 0); - class_addmethod(sendOSC_class, (t_method)sendOSC_settypetags, - gensym("typetags"), - A_FLOAT, 0); - class_addmethod(sendOSC_class, (t_method)sendOSC_send, - gensym("send"), - A_GIMME, 0); - class_addmethod(sendOSC_class, (t_method)sendOSC_send, - gensym("senduntyped"), - A_GIMME, 0); - class_addmethod(sendOSC_class, (t_method)sendOSC_send, - gensym("sendtyped"), - A_GIMME, 0); - class_addmethod(sendOSC_class, (t_method)sendOSC_openbundle, - gensym("["), - 0, 0); - class_addmethod(sendOSC_class, (t_method)sendOSC_closebundle, - gensym("]"), - 0, 0); - class_sethelpsymbol(sendOSC_class, gensym("sendOSC-help.pd")); - error("[sendOSC]: OSCx is deprecated! \n\tConsider switching to mrpeach's [packOSC] and [udpsend]"); -} - -/* Exit status codes: - 0: successful - 2: Message(s) dropped because of buffer overflow - 3: Socket error - 4: Usage error - 5: Internal error -*/ - - -typedArg ParseAtom(t_atom *a) -{ - typedArg returnVal; - t_float f; - t_int i; - t_symbol s; - char buf[MAXPDSTRING]; - - atom_string(a, buf, MAXPDSTRING); -#ifdef DEBUG - post("sendOSC: atom type %d (%s)", a->a_type, buf); -#endif - /* It might be an int, a float, or a string */ - switch (a->a_type) - { - - case A_FLOAT: - f = atom_getfloat(a); - i = atom_getint(a); - if (f == (t_float)i) - { // assume that if the int and float are the same, it's an int - returnVal.type = INT_osc; - returnVal.datum.i = i; - } - else - { - returnVal.type = FLOAT_osc; - returnVal.datum.f = f; - } - return returnVal; - case A_SYMBOL: - s = *atom_getsymbol(a); - returnVal.type = STRING_osc; - returnVal.datum.s = s.s_name; - return returnVal; - default: - atom_string(a, buf, MAXPDSTRING); - error("sendOSC: atom type %d not implemented (%s)", a->a_type, buf); - returnVal.type = NOTYPE_osc; - returnVal.datum.s = NULL; - return returnVal; -} -} - -int WriteMessage(OSCbuf *buf, char *messageName, int numArgs, typedArg *args) -{ - int j, returnVal; - - returnVal = 0; - -#ifdef DEBUG - printf("WriteMessage: %s ", messageName); - - for (j = 0; j < numArgs; j++) - { - switch (args[j].type) - { - case INT_osc: - printf("%d ", args[j].datum.i); - break; - - case FLOAT_osc: - printf("%f ", args[j].datum.f); - break; - - case STRING_osc: - printf("%s ", args[j].datum.s); - break; - - default: - error("Unrecognized arg type %d", args[j].type); - break; - } - } - printf("\n"); -#endif - - if (!useTypeTags) - { - returnVal = OSC_writeAddress(buf, messageName); - if (returnVal) - { - error("Problem writing address: %s\n", OSC_errorMessage); - } - } - else - { - /* First figure out the type tags */ - char typeTags[MAX_ARGS+2]; - - typeTags[0] = ','; - - for (j = 0; j < numArgs; ++j) - { - switch (args[j].type) - { - case INT_osc: - typeTags[j+1] = 'i'; - break; - - case FLOAT_osc: - typeTags[j+1] = 'f'; - break; - - case STRING_osc: - typeTags[j+1] = 's'; - break; - - default: - error("sendOSC: arg %d type is unrecognized(%d)", j, args[j].type); - break; - } - } - typeTags[j+1] = '\0'; - - returnVal = OSC_writeAddressAndTypes(buf, messageName, typeTags); - if (returnVal) - { - error("Problem writing address: %s\n", OSC_errorMessage); - } - } - - for (j = 0; j < numArgs; j++) - { - switch (args[j].type) - { - case INT_osc: - if ((returnVal = OSC_writeIntArg(buf, args[j].datum.i)) != 0) - { - return returnVal; - } - break; - - case FLOAT_osc: - if ((returnVal = OSC_writeFloatArg(buf, args[j].datum.f)) != 0) - { - return returnVal; - } - break; - - case STRING_osc: - if ((returnVal = OSC_writeStringArg(buf, args[j].datum.s)) != 0) - { - return returnVal; - } - break; - - default: - break; // just skip bad types (which we won't get anyway unless this code is buggy) - } - } - return returnVal; -} - -void SendBuffer(void *htmsocket, OSCbuf *buf) -{ -#ifdef DEBUG - printf("Sending buffer...\n"); -#endif - if (OSC_isBufferEmpty(buf)) - { - post("SendBuffer() called but buffer empty"); - return; - } - if (!OSC_isBufferDone(buf)) - { - fatal_error("SendBuffer() called but buffer not ready!, not exiting"); - return; //{{raf}} - } - SendData(htmsocket, OSC_packetSize(buf), OSC_getPacket(buf)); -} - -void SendData(void *htmsocket, int size, char *data) -{ - if (!SendHTMSocket(htmsocket, size, data)) - { - post("SendData::SendHTMSocket()failure -- not connected"); - CloseHTMSocket(htmsocket); -} -} - -- cgit v1.2.1