Exemple #1
0
static int packOSC_writetypedmessage
(t_packOSC *x, OSCbuf *buf, char *messageName, int numArgs, typedArg *args, char *typeStr)
{
    int i, j, returnVal = OSC_writeAddressAndTypes(buf, messageName, typeStr);

    if (returnVal)
    {
        error("packOSC: Problem writing address. (%d)", returnVal);
        return returnVal;
    }
    for (j = i = 0; (typeStr[i+1]!= 0) || (j < numArgs); j++, i++)
    {
        while (typeStr[i+1] == 'T' || typeStr[i+1] == 'F' || typeStr[i+1] == 'I' || typeStr[i+1] == 'N')
        {
#ifdef DEBUG
            post("packOSC_writetypedmessage: NULL [%c]", typeStr[i+1]);
#endif
            returnVal = OSC_writeNullArg(buf, typeStr[i+1]);
            ++i;
        }
        if (j < numArgs)
        {
            switch (args[j].type)
            {
                case INT_osc:
#ifdef DEBUG
                    post("packOSC_writetypedmessage: int [%d]", args[j].datum.i);
#endif
                    returnVal = OSC_writeIntArg(buf, args[j].datum.i);
                    break;
                case FLOAT_osc:
#ifdef DEBUG
                    post("packOSC_writetypedmessage: float [%f]", args[j].datum.f);
#endif
                    returnVal = OSC_writeFloatArg(buf, args[j].datum.f);
                    break;
                case STRING_osc:
#ifdef DEBUG
                    post("packOSC_writetypedmessage: string [%s]", args[j].datum.s);
#endif
                    returnVal = OSC_writeStringArg(buf, args[j].datum.s);
                    break;
                case BLOB_osc:
                    /* write all the blob elements at once */
#ifdef DEBUG
                    post("packOSC_writetypedmessage calling OSC_writeBlobArg\n");
#endif
                    return OSC_writeBlobArg(buf, &args[j], numArgs-j);
                default:

                    break; /* types with no data */
            }
        }
    }
    return returnVal;
}
Exemple #2
0
static inline int
Osc_BuildFloatMessage(OSCbuf *buf, const char *address, float value)
{
	Uint32	size = Osc_StrPad32(strlen(address)) + 4 + sizeof(float);
	char	*data;

	if (!(data = malloc(size)))
		return 1;

	OSC_initBuffer(buf, size, data);

	if (OSC_writeAddressAndTypes(buf, (char*)address, ",f") ||
	    OSC_writeFloatArg(buf, value)) {
		free(data);
		return 1;
	}

	return 0;
}
Exemple #3
0
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;
}
Exemple #4
0
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:
	    printf("%d ", args[j].datum.i);
            break;

            case FLOAT:
	    printf("%f ", args[j].datum.f);
            break;

            case STRING:
	    printf("%s ", args[j].datum.s);
            break;

            default:
            fatal_error("Unrecognized arg type");
            exit(5);
        }
    }
    printf("\n");
#endif

    if (!useTypeTags) {
	returnVal = OSC_writeAddress(buf, messageName);
	if (returnVal) {
	    complain("Problem writing address: %s\n", OSC_errorMessage);
	}
    } else {
	/* First figure out the type tags */
	char typeTags[MAX_ARGS+2];
	int i;

	typeTags[0] = ',';

	for (i = 0; i < numArgs; ++i) {
	    switch (args[i].type) {
		case INT:
		typeTags[i+1] = 'i';
		break;

		case FLOAT:
		typeTags[i+1] = 'f';
		break;

		case STRING:
		typeTags[i+1] = 's';
		break;

		default:
		fatal_error("Unrecognized arg type");
		exit(5);
	    }
	}
	typeTags[i+1] = '\0';
	    
	returnVal = OSC_writeAddressAndTypes(buf, messageName, typeTags);
	if (returnVal) {
	    complain("Problem writing address: %s\n", OSC_errorMessage);
	}
    }

     for (j = 0; j < numArgs; j++) {
        switch (args[j].type) {
            case INT:
            if ((returnVal = OSC_writeIntArg(buf, args[j].datum.i)) != 0) {
		return returnVal;
	    }
            break;

            case FLOAT:
            if ((returnVal = OSC_writeFloatArg(buf, args[j].datum.f)) != 0) {
		return returnVal;
	    }
            break;

            case STRING:
            if ((returnVal = OSC_writeStringArg(buf, args[j].datum.s)) != 0) {
		return returnVal;
	    }
            break;

            default:
            fatal_error("Unrecognized arg type");
            exit(5);
        }
    }

    return returnVal;
}
Exemple #5
0
static int packOSC_writemessage(t_packOSC *x, OSCbuf *buf, char *messageName, int numArgs, typedArg *args)
{
    int j, returnVal = 0, numTags;

    if (!x->x_typetags)
    {
        returnVal = OSC_writeAddress(buf, messageName);
        if (returnVal)
        {
            post("packOSC: Problem writing address.");
        }
    }
    else
    {
        char *typeTags;

        /* First figure out the type tags */
        for (numTags = 0; numTags < numArgs; numTags++)
        {
            if (args[numTags].type == BLOB_osc) break; /* blob has one type tag and is the last element */
        }
        typeTags=(char*)getbytes(sizeof(char)*(numTags+2)); /* number of args + ',' + '\0' */

        typeTags[0] = ',';
        for (j = 0; j < numTags; ++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;
                case BLOB_osc:
                    typeTags[j+1] = 'b';
                    break;
                default:
                    error("packOSC: arg %d type is unrecognized(%d)", j, args[j].type);
                    break;
            }
        }
        typeTags[j+1] = '\0';
        returnVal = OSC_writeAddressAndTypes(buf, messageName, typeTags);
        if (returnVal)
        {
            error("packOSC: Problem writing address.");
        }
        freebytes(typeTags, sizeof(char)*(numTags+2));
    }
    for (j = 0; j < numArgs; j++)
    {
        switch (args[j].type)
        {
            case INT_osc:
                returnVal = OSC_writeIntArg(buf, args[j].datum.i);
                break;
            case FLOAT_osc:
                returnVal = OSC_writeFloatArg(buf, args[j].datum.f);
                break;
            case STRING_osc:
                returnVal = OSC_writeStringArg(buf, args[j].datum.s);
                break;
            case BLOB_osc:
#ifdef DEBUG
                post ("packOSC_writemessage calling OSC_writeBlobArg\n");
#endif
                return OSC_writeBlobArg(buf, &args[j], numArgs-j); /* All the remaining args are blob */
            default:
                break; /* just skip bad types (which we won't get anyway unless this code is buggy) */
        }
    }
    return returnVal;
}
Exemple #6
0
int
Osc_BuildMessage(OSCbuf *buf, const char *address, const char *types, ...)
{
	va_list	args;

	Uint32	size = Osc_StrPad32(strlen(address)) + Osc_StrPad32(strlen(types));
	char	*data = NULL;

	va_start(args, types);

	for (const char *p = types + 1; *p; p++)
		switch (*p) {
		case 'f':
		case 'i':
			va_arg(args, Uint32);
			size += sizeof(Uint32);
			break;

		case 's':
			size += Osc_StrPad32(strlen(va_arg(args, char*)));
			break;

		default:
			goto err;
		}

	va_end(args);
	va_start(args, types);

	if (!(data = malloc(size)))
		goto err;
	OSC_initBuffer(buf, size, data);

	if (OSC_writeAddressAndTypes(buf, (char*)address, (char*)types))
		goto err;

	for (const char *p = types + 1; *p; p++)
		switch (*p) {
		case 'f':
			if (OSC_writeFloatArg(buf, va_arg(args, float)))
				goto err;
			break;

		case 'i':
			if (OSC_writeIntArg(buf, va_arg(args, int)))
				goto err;
			break;

		case 's':
			if (OSC_writeStringArg(buf, va_arg(args, char*)))
				goto err;
			break;
		}

	va_end(args);
	return 0;

err:

	va_end(args);
	free(data);
	return 1;
}