예제 #1
0
파일: test.c 프로젝트: gautamb85/libmapper
/*! Creation of a local destination. */
int setup_destination()
{
    destination = mdev_new("testrecv", port, 0);
    if (!destination)
        goto error;
    printf("destination created.\n");

    float mn=0, mx=1;

    recvsig_1 = mdev_add_input(destination, "/insig_1", 1, 'f',
                               0, &mn, &mx, insig_handler, 0);
    recvsig_2 = mdev_add_input(destination, "/insig_2", 1, 'f',
                               0, &mn, &mx, insig_handler, 0);
    recvsig_3 = mdev_add_input(destination, "/insig_3", 3, 'f',
                               0, &mn, &mx, insig_handler, 0);
    recvsig_4 = mdev_add_input(destination, "/insig_4", 1, 'f',
                               0, &mn, &mx, insig_handler, 0);

    printf("Input signal /insig registered.\n");

    // Make sure we can add and remove inputs and inputs within crashing.
    mdev_remove_input(destination,
                      mdev_add_input(destination, "/insig_5", 1,
                                     'f', 0, &mn, &mx, 0, 0));

    printf("Number of inputs: %d\n", mdev_num_inputs(destination));

    return 0;

  error:
    return 1;
}
예제 #2
0
int setup_destination()
{
    destination = mdev_new("testrecv", port, 0);
    if (!destination)
        goto error;
    printf("destination created.\n");

    float mn=0, mx=1;
    recvsig = mdev_add_input(destination, "/insig", 3, 'f', 0,
                             &mn, &mx, insig_handler, 0);

    printf("Input signal /insig registered.\n");
    printf("Number of inputs: %d\n", mdev_num_inputs(destination));
    return 0;

  error:
    return 1;
}
예제 #3
0
/*! Creation of a local destination. */
int setup_destination()
{
    destination = mdev_new("testSpeedRecv", 0, 0);
    if (!destination)
        goto error;
    printf("destination created.\n");

    recvsig = mdev_add_input(destination, "/insig", 1, 'f',
                             0, 0, 0, insig_handler, 0);
    if (!recvsig)
        goto error;
    msig_reserve_instances(recvsig, 9);

    printf("Input signal registered.\n");
    printf("Number of inputs: %d\n", mdev_num_inputs(destination));

    return 0;

  error:
    return 1;
}
예제 #4
0
/*! Creation of a local destination. */
int setup_destination()
{
    char sig_name[10];
    destination = mdev_new("testrecv", port, 0);
    if (!destination)
        goto error;
    printf("destination created.\n");

    float mn=0, mx=1;
        
    for (int i = 0; i < 4; i++) {
        snprintf(sig_name, 10, "%s%i", "/insig_", i);
        recvsig[i] = mdev_add_input(destination, sig_name, 1, 
                                    'f', 0, &mn, &mx, insig_handler, 0);
    }

    printf("Input signal /insig registered.\n");
    printf("Number of inputs: %d\n", mdev_num_inputs(destination));

    return 0;

  error:
    return 1;
}
예제 #5
0
파일: testrecv.c 프로젝트: sofian/libmapper
int test_recv()
{
    mapper_device md = mdev_new("synth", 0, 0);
    if (!md)
        goto error;
    printf("Mapper device created.\n");

    float mn=0, mx=1;
    mapper_signal sig = 
        mdev_add_input(md, "/mapped1", 1, 'f', 0, &mn, &mx, handler, 0);

    printf("Input signal /mapped1 registered.\n");

    printf("Number of inputs: %d\n", mdev_num_inputs(md));

    printf("Waiting for port/ordinal allocation..\n");
    int i;
    for (i = 0; i < 10; i++) {
        mdev_poll(md, 500);
        if (mdev_ready(md))
            break;
        usleep(500 * 1000);
    }
    if (i >= 10) {
        printf("Timed out waiting for signal name.\n");
        goto error;
    }
	
	char port[10];
	sprintf(port, "%i", md->admin->port);
	printf("using port = %s\n", port);
	
	lo_address a = lo_address_new("localhost", port);
    if (!a) {
        printf("Error creating lo_address for test.\n");
        return 1;
    }

    printf("Polling device..\n");
    for (i = 0; i < 10; i++) {
        lo_send(a, sig->props.name, "f", (float) i);
		printf("Updating signal %s to %f\n", sig->props.name, (float) i);
        sent++;
        mdev_poll(md, 500);
		//usleep(500 * 1000);
    }

    if (sent != received) {
        printf("Not all sent values were received.\n");
        printf("Sent %d values, but %d received.\n", sent, received);
        goto error;
    }
    if (sent == 0) {
        printf("Unable to send any values.\n");
        goto error;
    }
    printf("Sent and received %d values.\n", sent);

    mdev_free(md);
    lo_address_free(a);
    return 0;

  error:
    if (md)
        mdev_free(md);
    lo_address_free(a);
    return 1;
}