Пример #1
0
// *********************************************************
// -(poll libmapper)----------------------------------------
void impmap_poll(impmap *x)
{
    mapper_device_poll(x->device, 0);
    if (!x->ready) {
        if (mapper_device_ready(x->device)) {
            x->ready = 1;

            // create a new generic output signal
            x->dummy_output = mapper_device_add_output_signal(x->device,
                                                              "CONNECT_TO_DESTINATION",
                                                              1, 'f', 0, 0, 0);

            // create a new generic input signal
            x->dummy_input = mapper_device_add_input_signal(x->device,
                                                            "CONNECT_TO_SOURCE",
                                                            1, 'f', 0, 0, 0, 0, x);

            impmap_print_properties(x);
        }
    }
    if (x->new_in) {
        outlet_anything(x->outlet1, gensym("list"), x->size_in, x->buffer_in);
        x->new_in = 0;
    }
    clock_delay(x->clock, INTERVAL);  // Set clock to go off after delay
}
Пример #2
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;
}
Пример #3
0
int setup_sources()
{
    int i, mni=0, mxi=1;
    sources = (mapper_device*)calloc(1, num_sources * sizeof(mapper_device));
    sendsigs = (mapper_signal*)calloc(1, num_sources * sizeof(mapper_signal));

    for (i = 0; i < num_sources; i++) {
        sources[i] = mapper_device_new("testconvergent-send", 0, 0);
        if (!sources[i])
            goto error;
        sendsigs[i] = mapper_device_add_output_signal(sources[i], "sendsig", 1,
                                                      'i', 0, &mni, &mxi);
        if (!sendsigs[i])
            goto error;
        eprintf("source %d created.\n", i);
    }
    return 0;

  error:
    for (i = 0; i < num_sources; i++) {
        if (sources[i])
            mapper_device_free(sources[i]);
    }
    return 1;
}
Пример #4
0
int setup_source()
{
    source = mapper_device_new("testqueue-send", port, 0);
    if (!source)
        goto error;
    eprintf("source created.\n");

    float mn=0, mx=1;

    sendsig = mapper_device_add_output_signal(source, "outsig", 1, 'f', 0,
                                              &mn, &mx);
    sendsig1= mapper_device_add_output_signal(source, "outsig1", 1, 'f', 0,
                                              &mn, &mx);

    eprintf("Output signal 'outsig' registered.\n");
    eprintf("Number of outputs: %d\n",
            mapper_device_num_signals(source, MAPPER_DIR_OUTGOING));
    return 0;

  error:
    return 1;
}
Пример #5
0
// *********************************************************
// -(connection handler)------------------------------------
void impmap_on_map(mapper_device dev, mapper_map map, mapper_record_event e)
{
    // if connected involves current generic signal, create a new generic signal
    impmap *x = (void*)mapper_device_user_data(dev);
    if (!x) {
        post("error in connect handler: user_data is NULL");
        return;
    }
    if (!x->ready) {
        post("error in connect handler: device not ready");
        return;
    }

    // retrieve devices and signals
    mapper_slot slot = mapper_map_slot(map, MAPPER_LOC_SOURCE, 0);
    mapper_signal src_sig = mapper_slot_signal(slot);
    mapper_device src_dev = mapper_signal_device(src_sig);
    slot = mapper_map_slot(map, MAPPER_LOC_DESTINATION, 0);
    mapper_signal dst_sig = mapper_slot_signal(slot);
    mapper_device dst_dev = mapper_signal_device(dst_sig);

    // sanity check: don't allow self-connections
    if (src_dev == dst_dev) {
        mapper_map_release(map);
        return;
    }

    char full_name[256];

    if (e == MAPPER_ADDED) {
        if (src_dev == x->device) {
            snprintf(full_name, 256, "%s/%s", mapper_device_name(dst_dev),
                     mapper_signal_name(dst_sig));
            if (strcmp(mapper_signal_name(src_sig), full_name) == 0) {
                // <thisDev>:<dstDevName>/<dstSigName> -> <dstDev>:<dstSigName>
                return;
            }
            if (mapper_device_num_signals(x->device, MAPPER_DIR_OUTGOING) >= MAX_LIST) {
                post("Max outputs reached!");
                return;
            }
            // unmap the generic signal
            mapper_map_release(map);

            // add a matching output signal
            int i, length = mapper_signal_length(dst_sig);
            char type = mapper_signal_type(dst_sig);
            void *min = mapper_signal_minimum(dst_sig);
            void *max = mapper_signal_maximum(dst_sig);

            float *minf = 0, *maxf = 0;
            if (type == 'f') {
                minf = (float*)min;
                maxf = (float*)max;
            }
            else {
                if (min) {
                    minf = alloca(length * sizeof(float));
                    if (type == 'i') {
                        int *mini = (int*)min;
                        for (i = 0; i < length; i++)
                            minf[i] = (float)mini[i];
                    }
                    else if (type == 'd') {
                        double *mind = (double*)min;
                        for (i = 0; i < length; i++)
                            minf[i] = (float)mind[i];
                    }
                    else
                        minf = 0;
                }
                if (max) {
                    maxf = alloca(length * sizeof(float));
                    if (type == 'i') {
                        int *maxi = (int*)max;
                        for (i = 0; i < length; i++)
                            maxf[i] = (float)maxi[i];
                    }
                    else if (type == 'd') {
                        double *maxd = (double*)max;
                        for (i = 0; i < length; i++)
                            maxf[i] = (float)maxd[i];
                    }
                    else
                        maxf = 0;
                }
            }
            src_sig = mapper_device_add_output_signal(x->device, full_name,
                                                      length, 'f', 0, minf, maxf);
            if (!src_sig) {
                post("error creating new source signal!");
                return;
            }
            mapper_signal_set_callback(src_sig, impmap_on_query);

            // map the new signal
            map = mapper_map_new(1, &src_sig, 1, &dst_sig);
            mapper_map_set_mode(map, MAPPER_MODE_EXPRESSION);
            mapper_map_set_expression(map, "y=x");
            mapper_map_push(map);

            impmap_update_output_vector_positions(x);

            //output numOutputs
            maxpd_atom_set_int(&x->msg_buffer,
                               mapper_device_num_signals(x->device, MAPPER_DIR_OUTGOING) - 1);
            outlet_anything(x->outlet3, gensym("numOutputs"), 1, &x->msg_buffer);
        }
        else if (dst_dev == x->device) {
            snprintf(full_name, 256, "%s/%s", mapper_device_name(src_dev),
                     mapper_signal_name(src_sig));
            if (strcmp(mapper_signal_name(dst_sig), full_name) == 0) {
                // <srcDevName>:<srcSigName> -> <thisDev>:<srcDevName>/<srcSigName>
                return;
            }
            if (mapper_device_num_signals(x->device, MAPPER_DIR_INCOMING) >= MAX_LIST) {
                post("Max inputs reached!");
                return;
            }
            // unmap the generic signal
            mapper_map_release(map);

            // add a matching input signal
            int i, length = mapper_signal_length(src_sig);
            char type = mapper_signal_type(src_sig);
            void *min = mapper_signal_minimum(src_sig);
            void *max = mapper_signal_maximum(src_sig);

            float *minf = 0, *maxf = 0;
            if (type == 'f') {
                minf = (float*)min;
                maxf = (float*)max;
            }
            else {
                if (min) {
                    minf = alloca(length * sizeof(float));
                    if (type == 'i') {
                        int *mini = (int*)min;
                        for (i = 0; i < length; i++)
                        minf[i] = (float)mini[i];
                    }
                    else if (type == 'd') {
                        double *mind = (double*)min;
                        for (i = 0; i < length; i++)
                        minf[i] = (float)mind[i];
                    }
                    else
                        minf = 0;
                }
                if (max) {
                    maxf = alloca(length * sizeof(float));
                    if (type == 'i') {
                        int *maxi = (int*)max;
                        for (i = 0; i < length; i++)
                        maxf[i] = (float)maxi[i];
                    }
                    else if (type == 'd') {
                        double *maxd = (double*)max;
                        for (i = 0; i < length; i++)
                        maxf[i] = (float)maxd[i];
                    }
                    else
                        maxf = 0;
                }
            }
            dst_sig = mapper_device_add_input_signal(x->device, full_name,
                                                     length, 'f', 0, minf, maxf,
                                                     impmap_on_input, 0);
            if (!dst_sig) {
                post("error creating new destination signal!");
                return;
            }

            // map the new signal
            map = mapper_map_new(1, &src_sig, 1, &dst_sig);
            mapper_map_set_mode(map, MAPPER_MODE_EXPRESSION);
            mapper_map_set_expression(map, "y=x");
            mapper_map_push(map);

            impmap_update_input_vector_positions(x);

            //output numInputs
            maxpd_atom_set_int(&x->msg_buffer,
                               mapper_device_num_signals(x->device, MAPPER_DIR_INCOMING) - 1);
            outlet_anything(x->outlet3, gensym("numInputs"), 1, &x->msg_buffer);
        }
    }
    else if (e == MAPPER_REMOVED) {
        if (src_sig == x->dummy_input || src_sig == x->dummy_output
            || dst_sig == x->dummy_input || dst_sig == x->dummy_output)
            return;
        if (src_dev == x->device) {
            snprintf(full_name, 256, "%s/%s", mapper_device_name(dst_dev),
                     mapper_signal_name(dst_sig));
            if (strcmp(mapper_signal_name(src_sig), full_name) != 0)
                return;
            // remove signal
            mapper_device_remove_signal(x->device, src_sig);
            impmap_update_input_vector_positions(x);

            //output numOutputs
            maxpd_atom_set_int(&x->msg_buffer,
                               mapper_device_num_signals(x->device, MAPPER_DIR_OUTGOING) - 1);
            outlet_anything(x->outlet3, gensym("numOutputs"), 1, &x->msg_buffer);
        }
        else if (dst_dev == x->device) {
            snprintf(full_name, 256, "%s/%s", mapper_device_name(src_dev),
                     mapper_signal_name(src_sig));
            if (strcmp(mapper_signal_name(dst_sig), full_name) != 0)
                return;
            // remove signal
            mapper_device_remove_signal(x->device, dst_sig);
            impmap_update_input_vector_positions(x);

            //output numInputs
            maxpd_atom_set_int(&x->msg_buffer,
                               mapper_device_num_signals(x->device, MAPPER_DIR_INCOMING) - 1);
            outlet_anything(x->outlet3, gensym("numInputs"), 1, &x->msg_buffer);
        }
    }
}