OSCTimeTag ParseTimeTag(char *s) { char *p, *newline; typedArg arg; p = s; while (isspace(*p)) p++; if (*p == '\0') return OSCTT_Immediately(); if (*p == '+') { /* Time tag is for some time in the future. It should be a number of seconds as an int or float */ newline = strchr(s, '\n'); if (newline != NULL) *newline = '\0'; p++; /* Skip '+' */ while (isspace(*p)) p++; arg = ParseToken(p); if (arg.type == STRING) { complain("warning: inscrutable time tag request: %s\n", s); return OSCTT_Immediately(); } else if (arg.type == INT) { return OSCTT_PlusSeconds(OSCTT_CurrentTime(), (float) arg.datum.i); } else if (arg.type == FLOAT) { return OSCTT_PlusSeconds(OSCTT_CurrentTime(), arg.datum.f); } else { fatal_error("This can't happen!"); } } if (isdigit(*p) || (*p >= 'a' && *p <='f') || (*p >= 'A' && *p <='F')) { /* They specified the 8-byte tag in hex */ OSCTimeTag tt; if (sscanf(p, "%llx", &tt) != 1) { complain("warning: couldn't parse time tag %s\n", s); return OSCTT_Immediately(); } #ifndef HAS8BYTEINT if (ntohl(1) != 1) { /* tt is a struct of seconds and fractional part, and this machine is little-endian, so sscanf wrote each half of the time tag in the wrong half of the struct. */ uint4 temp; temp = tt.seconds; tt.seconds = tt.fraction ; tt.fraction = temp; } #endif return tt; } complain("warning: invalid time tag: %s\n", s); return OSCTT_Immediately(); }
main() { OSCTimeTag now, later; now = OSCTT_CurrentTime(); printf("Now it's %llu (0x%llx)\n", now, now); printf("Immediately would be %llu (0x%llx)\n", OSCTT_Immediately(), OSCTT_Immediately()); later = OSCTT_PlusSeconds(now, 1.0f); printf("One second from now would be %llu (0x%llx)\n", later, later); now = OSCTT_CurrentTime(); printf("And *now* it's %llu (0x%llx)\n", now, now); }
void OSCAcceptPacket(OSCPacketBuffer packet) { if ((packet->n % 4) != 0) { OSCProblem("OSC packet size (%d bytes) not a multiple of 4.", packet->n); DropPacket(packet); return; } #ifdef DEBUG printf("OSCAcceptPacket(OSCPacketBuffer %p, buf %p, size %d)\n", packet, packet->buf, packet->n); #endif /* If the packet came from the user, it's return address is OK. */ packet->returnAddrOK = TRUE; InsertBundleOrMessage(packet->buf, packet->n, packet, OSCTT_Immediately()); #ifdef PARANOID if (packet->refcount == 0) { if (freePackets != packet) { fatal_error("OSCAcceptPacket: packet refcount 0, but it's not the head of the free list!"); } } #endif OSCInvokeAllMessagesThatAreReady(globals.lastTimeTag); }
Boolean OSCSendInternalMessageWithRSVP(char *address, int arglen, void *args, NetworkReturnAddressPtr returnAddr) { callbackList l = OSCDispatchMessage(address); if (l == 0) return FALSE; CallWholeCallbackList(l, arglen, args, OSCTT_Immediately(), returnAddr); return TRUE; }
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, (float)x->x_oscbuf->bundleDepth); }
static void packOSC_openbundle(t_packOSC *x) { int result; if (x->x_timeTagOffset == -1) result = OSC_openBundle(x->x_oscbuf, OSCTT_Immediately()); else result = OSC_openBundle(x->x_oscbuf, OSCTT_CurrentTimePlusOffset((uint4)x->x_timeTagOffset)); if (result != 0) { /* reset the buffer */ OSC_initBuffer(x->x_oscbuf, x->x_buflength, x->x_bufferForOSCbuf); x->x_bundle = 0; } else x->x_bundle = 1; outlet_float(x->x_bdpthout, (float)x->x_oscbuf->bundleDepth); }
void CommandLineMode(int argc, char *argv[], void *htmsocket) { char *messageName; char *token; typedArg args[MAX_ARGS]; int i,j, numArgs; OSCbuf buf[1]; OSC_initBuffer(buf, SC_BUFFER_SIZE, bufferForOSCbuf); if (argc > 1) { if (OSC_openBundle(buf, OSCTT_Immediately())) { complain("Problem opening bundle: %s\n", OSC_errorMessage); return; } } for (i = 0; i < argc; i++) { messageName = strtok(argv[i], ","); if (messageName == NULL) { break; } j = 0; while ((token = strtok(NULL, ",")) != NULL) { args[j] = ParseToken(token); j++; if (j >= MAX_ARGS) { complain("Sorry; your message has more than MAX_ARGS (%d) arguments; ignoring the rest.\n", MAX_ARGS); break; } } numArgs = j; WriteMessage(buf, messageName, numArgs, args); } if (argc > 1) { if (OSC_closeBundle(buf)) { complain("Problem closing bundle: %s\n", OSC_errorMessage); return; } } SendBuffer(htmsocket, buf); }
Boolean OSCInitReceive(struct OSCReceiveMemoryTuner *t) { globals.recvBufSize = t->receiveBufferSize; globals.InitTimeMalloc = t->InitTimeMemoryAllocator; globals.RealTimeMemoryAllocator = t->RealTimeMemoryAllocator; globals.TheQueue = OSCNewQueue(t->numQueuedObjects, t->InitTimeMemoryAllocator); if (globals.TheQueue == 0) return FALSE; globals.lastTimeTag = OSCTT_Immediately(); globals.timePassed = TRUE; if (InitPackets(t->receiveBufferSize, SizeOfNetworkReturnAddress(), t->numReceiveBuffers) == FALSE) return FALSE; if (InitQueuedData(t->numQueuedObjects) == FALSE) return FALSE; if (InitCallbackListNodes(t->numCallbackListNodes, t->InitTimeMemoryAllocator) == FALSE) return FALSE; return TRUE; }
void ParseInteractiveLine(OSCbuf *buf, char *mesg) { char *messageName, *token, *p; typedArg args[MAX_ARGS]; int thisArg; p = mesg; while (isspace(*p)) p++; if (*p == '\0') return; messageName = p; if (strcmp(messageName, "play\n") == 0) { /* Special kludge feature to save typing */ typedArg arg; if (OSC_openBundle(buf, OSCTT_Immediately())) { complain("Problem opening bundle: %s\n", OSC_errorMessage); return; } arg.type = INT; arg.datum.i = 0; WriteMessage(buf, "/voices/0/tp/timbre_index", 1, &arg); arg.type = FLOAT; arg.datum.i = 0.0f; WriteMessage(buf, "/voices/0/tm/goto", 1, &arg); if (OSC_closeBundle(buf)) { complain("Problem closing bundle: %s\n", OSC_errorMessage); } return; } while (!isspace(*p) && *p != '\0') p++; if (isspace(*p)) { *p = '\0'; p++; } thisArg = 0; while (*p != '\0') { /* flush leading whitespace */ while (isspace(*p)) p++; if (*p == '\0') break; if (*p == '"') { /* A string argument: scan for close quotes */ p++; args[thisArg].type = STRING; args[thisArg].datum.s = p; while (*p != '"') { if (*p == '\0') { complain("Unterminated quote mark: ignoring line\n"); return; } p++; } *p = '\0'; p++; } else { token = p; while (!isspace(*p) && (*p != '\0')) p++; if (isspace(*p)) { *p = '\0'; p++; } args[thisArg] = ParseToken(token); } thisArg++; if (thisArg >= MAX_ARGS) { complain("Sorry, your message has more than MAX_ARGS (%d) arguments; ignoring the rest.\n", MAX_ARGS); break; } } if (WriteMessage(buf, messageName, thisArg, args) != 0) { complain("Problem sending message: %s\n", OSC_errorMessage); } }