aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuenter Geiger <ggeiger@users.sourceforge.net>2003-06-10 20:32:14 +0000
committerGuenter Geiger <ggeiger@users.sourceforge.net>2003-06-10 20:32:14 +0000
commit0529f61465173366becf5ea71dacc210e2e60fcf (patch)
tree76712cf3cdc4bf16c6969fbfa355e154e11b11b0
parent5c5bcd1690d44a352905a298af164ca3af36eb1a (diff)
time master code by klaus@epy.co.at
svn path=/trunk/externals/OSCx/; revision=693
-rw-r--r--OSC/OSC.c54
-rw-r--r--OSC/dumpOSC.c90
-rw-r--r--send+dump/dumpOSC.c2
3 files changed, 105 insertions, 41 deletions
diff --git a/OSC/OSC.c b/OSC/OSC.c
index 10e719f..8a85566 100644
--- a/OSC/OSC.c
+++ b/OSC/OSC.c
@@ -4,55 +4,41 @@
-------------
-- tweaks for Win32 www.zeggz.com/raf 13-April-2002
- */
+*/
-#ifndef VERSION
- #ifdef WIN32
- #define VERSION "0.01-w32"
- #else
- #define VERSION "0.01"
- #endif
-#endif
-
-#ifndef __DATE__
-#define __DATE__ "without using a gnu compiler"
-#endif
-
#include <m_pd.h>
+#include "OSC-common.h"
+#define VERSION "0.2"
+
+#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;
-#ifdef WIN32
- #include "OSC-common.h"
- 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);
-#else
- void OSC_version();
- void sendOSC_setup();
- void dumpOSC_setup();
- void OSCroute_setup();
-#endif
static void* OSC_new(t_symbol* s) {
t_OSC *x = (t_OSC *)pd_new(OSC_class);
return (x);
}
-#ifdef WIN32
- OSC_API void OSC_version (t_OSC *x) {
-#else
- void OSC_version (t_OSC *x) {
-#endif
+
+OSC_API void OSC_version (t_OSC *x) {
+
// EnterCallback();
post("OSC4PD Version " VERSION
"\n ¯\\ original code by matt wright. pd-fication jdl@xdv.org\n"
@@ -60,11 +46,7 @@ static void* OSC_new(t_symbol* s) {
// ExitCallback();
}
-#ifdef WIN32
- OSC_API void OSC_setup(void) {
-#else
- void OSC_setup(void) {
-#endif
+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);
diff --git a/OSC/dumpOSC.c b/OSC/dumpOSC.c
index 1d82a2c..cbb4514 100644
--- a/OSC/dumpOSC.c
+++ b/OSC/dumpOSC.c
@@ -108,7 +108,7 @@ void sys_addpollfn(int fd, t_fdpollfn fn, void *ptr);
#include <signal.h>
#include <grp.h>
#include <sys/file.h>
- #include <sys/prctl.h>
+ //#include <sys/prctl.h>
#ifdef NEED_SCHEDCTL_AND_LOCK
#include <sys/schedctl.h>
@@ -127,6 +127,8 @@ typedef struct ClientAddressStruct {
int sockfd;
} *ClientAddr;
+typedef unsigned long long osc_time_t;
+
Boolean ShowBytes = FALSE;
Boolean Silent = FALSE;
@@ -173,6 +175,7 @@ typedef struct _dumpOSC
} 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);
@@ -213,8 +216,11 @@ static void dumpOSC_read(t_dumpOSC *x, int sockfd) {
#ifdef DEBUG
printf("dumpOSC_read: received UDP packet of length %d\n", n);
#endif
- dumpOSC_ParsePacket(x, mbuf, n, ra);
-
+
+ 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,
@@ -490,6 +496,74 @@ void PrintClientAddr(ClientAddr CA) {
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 */;
+}
+
+int timeRound(double x)
+{
+ return x >= 0.0 ? x+0.5 : x-0.5;
+}
+
+void WriteLogicalTime(char* dst)
+{
+ double sTime = clock_gettimesince(19230720) / 1000.0;
+ double tau = sTime - 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));
+}
+
+Boolean 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;
@@ -553,7 +627,15 @@ void dumpOSC_ParsePacket(t_dumpOSC *x, char *buf, int n, ClientAddr returnAddr)
printf("]\n");
#endif
- } else {
+ }
+ 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;
diff --git a/send+dump/dumpOSC.c b/send+dump/dumpOSC.c
index 083aed0..fc53fd5 100644
--- a/send+dump/dumpOSC.c
+++ b/send+dump/dumpOSC.c
@@ -60,7 +60,7 @@ Technologies, University of California, Berkeley.
*/
-#if defined(__sgi) || defined(__linux)
+#ifdef unix
#include <stdio.h>
#include <string.h>
#include <stdlib.h>