Esempio n. 1
0
void loop()
{
    eprintf("Polling device..\n");
	int i = 0;
	float j=1;
	while ((!terminate || i < 50) && !done) {
        j=i;
        mapper_timetag_t now;
        mapper_timetag_now(&now);
        mapper_device_start_queue(source, now);
		mapper_device_poll(source, 0);
        eprintf("Updating signal %s to %f\n", mapper_signal_name(sendsig), j);
        mapper_signal_update(sendsig, &j, 0, now);
		mapper_signal_update(sendsig1, &j, 0, now);
		mapper_device_send_queue(sendsig->device, now);
		sent = sent+2;
        mapper_device_poll(destination, 100);
        i++;

        if (!verbose) {
            printf("\r  Sent: %4i, Received: %4i   ", sent, received);
            fflush(stdout);
        }
    }
}
Esempio n. 2
0
// *********************************************************
// -(anything)----------------------------------------------
void impmap_list(impmap *x, t_symbol *s, int argc, t_atom *argv)
{
    if (x->mute)
        return;

    if (argc != x->size_out) {
        post("vector size mismatch");
        return;
    }

    int i = 0;

    mapper_timetag_now(&x->tt);
    mapper_device_start_queue(x->device, x->tt);

    mapper_signal *psig = mapper_device_signals(x->device, MAPPER_DIR_OUTGOING);
    while (psig) {
        if (*psig == x->dummy_output) {
            psig = mapper_signal_query_next(psig);
            continue;
        }
        t_signal_ref *ref = mapper_signal_user_data(*psig);
        int len = mapper_signal_length(*psig);
        float v[len];
        for (i = 0; i < len; i++) {
            v[i] = atom_getfloat(argv + ref->offset + i);
        }
        mapper_signal_update(*psig, v, 1, x->tt);

        psig = mapper_signal_query_next(psig);
    }
    mapper_device_send_queue(x->device, x->tt);
    outlet_anything(x->outlet2, gensym("out"), argc, argv);
}
Esempio n. 3
0
/*! Creation of a local source. */
int setup_source()
{
    char sig_name[20];
    source = mapper_device_new("testquery-send", 0, 0);
    if (!source)
        goto error;
    eprintf("source created.\n");

    int mn[]={0,0,0,0}, mx[]={10,10,10,10};

    for (int i = 0; i < 4; i++) {
        snprintf(sig_name, 20, "%s%i", "outsig_", i);
        sendsig[i] = mapper_device_add_output_signal(source, sig_name, i+1, 'i',
                                                     0, mn, mx);
        mapper_signal_set_callback(sendsig[i], query_response_handler);
        mapper_signal_update(sendsig[i], mn, 0, MAPPER_NOW);
    }

    eprintf("Output signals registered.\n");
    eprintf("Number of outputs: %d\n",
            mapper_device_num_signals(source, MAPPER_DIR_OUTGOING));

    return 0;

error:
    return 1;
}
Esempio n. 4
0
void loop()
{
    eprintf("-------------------- GO ! --------------------\n");
    int i = 10, j = 0, count;
    float value[] = {0., 0., 0., 0.};

    while ((!terminate || i < 50) && !done) {
        for (j = 0; j < 4; j++)
            value[j] = (i % 10) * 1.0f;
        for (j = 0; j < 4; j++) {
            mapper_signal_update(recvsig[j], value, 0, MAPPER_NOW);
        }
        eprintf("\ndestination values updated to %f -->\n", (i % 10) * 1.0f);
        for (j = 0; j < 4; j++) {
            sent += count = mapper_signal_query_remotes(sendsig[j], MAPPER_NOW);
            eprintf("Sent %i queries for sendsig[%i]\n", count, j);
        }
        mapper_device_poll(destination, 50);
        mapper_device_poll(source, 50);
        i++;

        if (!verbose) {
            printf("\r  Sent: %4i, Received: %4i   ", sent, received);
            fflush(stdout);
        }
    }
}
Esempio n. 5
0
// *********************************************************
// -(randomize)---------------------------------------------
void impmap_randomize(impmap *x)
{
    int i;
    float rand_val;

    if (x->ready) {
        mapper_timetag_now(&x->tt);
        mapper_device_start_queue(x->device, x->tt);
        mapper_signal *psig = mapper_device_signals(x->device, MAPPER_DIR_OUTGOING);
        while (psig) {
            if (*psig == x->dummy_output) {
                psig = mapper_signal_query_next(psig);
                continue;
            }
            t_signal_ref *ref = mapper_signal_user_data(*psig);
            if (mapper_signal_type(*psig) != 'f')
                continue;
            int length = mapper_signal_length(*psig);
            float v[length];
            float *min = (float*)mapper_signal_minimum(*psig);
            float *max = (float*)mapper_signal_maximum(*psig);
            for (i = 0; i < length; i++) {
                rand_val = (float)rand() / (float)RAND_MAX;
                if (min && max) {
                    v[i] = rand_val * (max[i] - min[i]) + min[i];
                }
                else {
                    // if ranges have not been declared, assume normalized between 0 and 1
                    v[i] = rand_val;
                }
                maxpd_atom_set_float(x->buffer_out + ref->offset + i, v[i]);
            }
            mapper_signal_update(*psig, v, 1, x->tt);
            psig = mapper_signal_query_next(psig);
        }
        mapper_device_send_queue(x->device, x->tt);
        outlet_anything(x->outlet2, gensym("out"), x->size_out, x->buffer_out);
    }
}