Beispiel #1
0
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();
}
Beispiel #2
0
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);
}
Beispiel #3
0
void ScaleMethod(void *vs, int arglen, const void *vargs, OSCTimeTag when, NetworkReturnAddressPtr ra) {
    int i;
    OSCTimeTag now = OSCTT_CurrentTime();
    Boolean r;

    float newarg[1];
    float *ptrToArgs[1];
    char *address = "/sine1/f";
    int newarglen = 4;

/*    printf("*ScaleMethod (context %p, arglen %d, args %p, when %llx, ra %p)\n",
	   vs, arglen, vargs, when, ra); */

    ptrToArgs[0] = newarg;
    for (i = 0; i < 9; ++i) {
	newarg[0] = 100.f + i * 50.f;

	r = OSCScheduleInternalMessages(OSCTT_PlusSeconds(now, (float) i), 1, &address, &newarglen, ptrToArgs);

	if (r == FALSE) {
	    OSCWarning("ScaleMethod: OSCScheduleInternalMessages returned FALSE");
	}
    }

}
Beispiel #4
0
void MainLoop(ALport alp, FileDescriptor dacfd, FileDescriptor sockfd, SynthState *v1, SynthState *v2) {
/*    int hwm = 300, lwm = 256; */
    int hwm = 1000, lwm = 800;
    fd_set read_fds, write_fds;

    /* largest file descriptor to search for */    
    int	nfds = BIGGER_OF(dacfd, sockfd) + 1;

    printf("MainLoop: dacfd %d, sockfd %d, nfds %d\n", dacfd, sockfd, nfds);

    time_to_quit = 0;
    sigset(SIGINT, catch_sigint);       /* set sig handler       */

    while(!time_to_quit) {

	/* compute sine wave samples while the sound output buffer is below
	   the high water mark */

	while (ALgetfilled(alp) < hwm) {
	    Synthesize(alp, v1, v2);
	}

	/* Figure out the time tag corresponding to the time in the future that we haven't
	   computed any samples for yet. */
	OSCInvokeAllMessagesThatAreReady(OSCTT_PlusSeconds(OSCTT_CurrentTime(), 
							   ALgetfilled(alp) / the_sample_rate));

	/* set the low water mark, i.e. when we want control from select(2) */
	ALsetfillpoint(alp, OUTPUTQUEUESIZE - lwm);

	/* set up select */
	FD_ZERO(&read_fds);	/* clear read_fds */
	FD_ZERO(&write_fds);	/* clear write_fds */
	FD_SET(dacfd, &write_fds);
	FD_SET(sockfd, &read_fds); 

	FD_SET(0, &read_fds);	/* stdin */

	/* give control back to OS scheduler to put us to sleep until the DAC
	   queue drains and/or a character is available from standard input */

	if (select(nfds, &read_fds, &write_fds, (fd_set * )0, (struct timeval *)0) < 0) {
	    /* select reported an error */
	    perror("bad select"); 
	    goto quit;
	}

	if(FD_ISSET(sockfd, &read_fds)) {
	    ReceivePacket(sockfd);
	}

	/* is there a character in the queue? */
	if (FD_ISSET(0, &read_fds)) {
	    /* this will never block */
	    char c = getchar();

	    if (c == 'q') {
		/* quit */
		break;
	    } else if ((c <= '9') && (c >= '0')) {
		/* tweak frequency */
		v1->f = 440.0 + 100.0 * (c - '0');
	    }
	}
    }
quit:
    ALcloseport(alp);
    closeudp(sockfd);
}
Beispiel #5
0
main() {
    OSCbuf myBuf;
    OSCbuf *b = &myBuf;
    char bytes[SIZE];
    OSCTimeTag tt;

    printf("OSC_initBuffer\n");
    OSC_initBuffer(b, SIZE, bytes);

    PrintBuf(b);

    printf("Testing one-message packet\n");
    if (OSC_writeAddress(b, "/blah/bleh/singlemessage")) {
	printf("** ERROR: %s\n", OSC_errorMessage);
    }

    if (OSC_writeFloatArg(b, 1.23456f)) {
        printf("** ERROR: %s\n", OSC_errorMessage);
    }

    {
	float floatarray[10];
	int i;
	for (i = 0; i < 10; ++i) {
	    floatarray[i] = i * 10.0f;
	}
	if (OSC_writeFloatArgs(b, 10, floatarray)) {
	    printf("** ERROR: %s\n", OSC_errorMessage);
	}
    }

    if (OSC_writeIntArg(b, 123456)) {
        printf("** ERROR: %s\n", OSC_errorMessage);
    }

    if (OSC_writeStringArg(b, "This is a cool string, dude.")) {
        printf("** ERROR: %s\n", OSC_errorMessage);
    }

    PrintBuf(b);
    PrintPacket(b);

    printf("Resetting\n");
    OSC_resetBuffer(b);

    printf("Testing time tags\n");
    tt = OSCTT_CurrentTime();
    printf("Time now is %llx\n", tt);

    printf("Testing bundles\n");
    if (OSC_openBundle(b, tt)) {
	printf("** ERROR: %s\n", OSC_errorMessage);
    }

    if (OSC_writeAddress(b, "/a/hello")) {
        printf("** ERROR: %s\n", OSC_errorMessage);
    }

    if (OSC_writeIntArg(b, 16)) {
        printf("** ERROR: %s\n", OSC_errorMessage);
    }

    if (OSC_writeIntArg(b, 32)) {
        printf("** ERROR: %s\n", OSC_errorMessage);
    }

    if (OSC_openBundle(b, OSCTT_PlusSeconds(tt, 1.0f))) {
        printf("** ERROR: %s\n", OSC_errorMessage);
    }

    if (OSC_writeAddress(b, "/b/hello")) {
        printf("** ERROR: %s\n", OSC_errorMessage);
    }

    if (OSC_writeAddress(b, "/c/hello")) {
        printf("** ERROR: %s\n", OSC_errorMessage);
    }

    OSC_closeAllBundles(b);

    PrintBuf(b);
    PrintPacket(b);
}