void connect_signals() { char source_name[1024], destination_name[1024]; printf("%s\n", mdev_name(source)); printf("%s\n", mdev_name(destination)); lo_address a = lo_address_new_from_url("osc.udp://224.0.1.3:7570"); lo_address_set_ttl(a, 1); lo_send(a, "/link", "ss", mdev_name(source), mdev_name(destination)); int j = 50; while (j >= 0) { mdev_poll(source, 10); mdev_poll(destination, 10); j--; } msig_full_name(sendsig, source_name, 1024); msig_full_name(recvsig, destination_name, 1024); lo_send(a, "/connect", "ss", source_name, destination_name); lo_address_free(a); }
void loop() { printf("-------------------- GO ! --------------------\n"); int i = 0; if (automate) { char source_name[1024], destination_name[1024]; printf("%s\n", mdev_name(source)); printf("%s\n", mdev_name(destination)); lo_address a = lo_address_new_from_url("osc.udp://224.0.1.3:7570"); lo_address_set_ttl(a, 1); lo_send(a, "/link", "ss", mdev_name(source), mdev_name(destination)); msig_full_name(sendsig, source_name, 1024); msig_full_name(recvsig, destination_name, 1024); lo_send(a, "/connect", "ssss", source_name, destination_name, "@mode", "reverse"); lo_address_free(a); } while (i >= 0 && !done) { msig_update_float(recvsig, ((i % 10) * 1.0f)); printf("\ndestination value updated to %f -->\n", (i % 10) * 1.0f); mdev_poll(destination, 1); mdev_poll(source, 100); i++; } }
int setup_router() { const char *host = "localhost"; router = mapper_router_new(source, host, destination->admin->port.value, mdev_name(destination)); mdev_add_router(source, router); printf("Router to %s:%d added.\n", host, port); char signame_in[1024]; if (!msig_full_name(recvsig, signame_in, 1024)) { printf("Could not get destination signal name.\n"); return 1; } char signame_out[1024]; if (!msig_full_name(sendsig, signame_out, 1024)) { printf("Could not get source signal name.\n"); return 1; } printf("Mapping signal %s -> %s\n", signame_out, signame_in); mapper_connection c = mapper_router_add_connection(router, sendsig, recvsig->props.name, 'f', 3); const char *expr = "y=x*10"; mapper_connection_set_expression(c, sendsig, expr); return 0; }
int setup_router() { const char *host = "localhost"; router = mapper_router_new(source, host, destination->props.port, mdev_name(destination), 0); mdev_add_router(source, router); printf("Router to %s:%d added.\n", host, destination->props.port); char signame_in[1024]; if (!msig_full_name(recvsig, signame_in, 1024)) { printf("Could not get destination signal name.\n"); return 1; } char signame_out[1024]; if (!msig_full_name(sendsig, signame_out, 1024)) { printf("Could not get source signal name.\n"); return 1; } printf("Connecting signal %s -> %s\n", signame_out, signame_in); mapper_connection c = mapper_router_add_connection(router, sendsig, recvsig->props.name, 'f', 1); mapper_connection_range_t range; range.src_min = 0; range.src_max = 1; range.dest_min = -10; range.dest_max = 10; range.known = CONNECTION_RANGE_KNOWN; mapper_connection_set_linear_range(c, &range); return 0; }
void connect_signals() { char source_name[1024], destination_name[1024]; printf("%s\n", mdev_name(source)); printf("%s\n", mdev_name(destination)); lo_address a = lo_address_new_from_url("osc.udp://224.0.1.3:7570"); lo_address_set_ttl(a, 1); lo_send(a, "/link", "ss", mdev_name(source), mdev_name(destination)); // wait for link to be processed int j = 50; while (j >= 0) { mdev_poll(source, 10); mdev_poll(destination, 10); j--; } msig_full_name(sendsig, source_name, 1024); msig_full_name(recvsig, destination_name, 1024); lo_send(a, "/connect", "ssssss", source_name, destination_name, "@mode", "expression", "@expression", "y=y{-1}+1"); lo_address_free(a); // wait for connection to be processed j = 50; while (j >= 0) { mdev_poll(source, 10); mdev_poll(destination, 10); j--; } }
mapper_connection mapper_receiver_add_connection(mapper_receiver r, mapper_signal sig, const char *src_name, char src_type, int src_length) { /* Currently, fail if lengths don't match. TODO: In the future, * we'll have to examine the expression to see if its input and * output lengths are compatible. */ if (sig->props.length != src_length) { char n[1024]; msig_full_name(sig, n, 1024); trace("rejecting connection %s -> %s%s because lengths " "don't match (not yet supported)\n", n, r->props.src_name, src_name); return 0; } // find signal in signal connection list mapper_receiver_signal rs = r->signals; while (rs && rs->signal != sig) rs = rs->next; // if not found, create a new list entry if (!rs) { rs = (mapper_receiver_signal) calloc(1, sizeof(struct _mapper_link_signal)); rs->signal = sig; rs->next = r->signals; r->signals = rs; } mapper_connection c = (mapper_connection) calloc(1, sizeof(struct _mapper_connection)); c->props.src_name = strdup(src_name); c->props.src_type = src_type; c->props.src_length = src_length; c->props.dest_name = strdup(sig->props.name); c->props.dest_type = sig->props.type; c->props.dest_length = sig->props.length; c->props.mode = MO_UNDEFINED; c->props.expression = strdup("y=x"); c->props.clip_min = CT_NONE; c->props.clip_max = CT_NONE; c->props.muted = 0; c->props.extra = table_new(); int len = strlen(src_name) + 5; c->props.query_name = malloc(len); snprintf(c->props.query_name, len, "%s%s", src_name, "/got"); // add new connection to this signal's list c->next = rs->connections; rs->connections = c; c->parent = rs; r->n_connections++; return c; }
int setup_connection() { mval src_min, src_max, dest_min, dest_max; src_min.f = 0.; src_max.f = 1.; dest_min.f = -10.; dest_max.f = 10.; mapper_monitor mon = mapper_monitor_new(source->admin, 0); char src_name[1024], dest_name[1024]; mapper_monitor_link(mon, mdev_name(source), mdev_name(destination), 0, 0); msig_full_name(sendsig, src_name, 1024); msig_full_name(recvsig, dest_name, 1024); mapper_connection_range_t range; range.src_min = &src_min; range.src_max = &src_max; range.dest_min = &dest_min; range.dest_max = &dest_max; range.known = CONNECTION_RANGE_KNOWN; mapper_db_connection_t props; props.range = range; props.src_length = 1; props.dest_length = 1; props.src_type = 'f'; props.dest_type = 'f'; props.mode = MO_LINEAR; mapper_monitor_connect(mon, src_name, dest_name, &props, CONNECTION_RANGE_KNOWN | CONNECTION_MODE); // poll devices for a bit to allow time for connection int i = 0; while (i++ < 10) { mdev_poll(destination, 10); mdev_poll(source, 10); } mapper_monitor_free(mon); return 0; }
void loop() { printf("-------------------- GO ! --------------------\n"); int i = 0, j = 0, count; if (automate) { char source_name[1024], destination_name[1024]; printf("%s\n", mdev_name(source)); printf("%s\n", mdev_name(destination)); lo_address a = lo_address_new_from_url("osc.udp://224.0.1.3:7570"); lo_address_set_ttl(a, 1); lo_send(a, "/link", "ss", mdev_name(source), mdev_name(destination)); for (int i = 0; i < 4; i++) { msig_full_name(sendsig[i], source_name, 1024); msig_full_name(recvsig[i], destination_name, 1024); lo_send(a, "/connect", "ss", source_name, destination_name); } lo_address_free(a); } while (i >= 0 && !done) { for (j = 0; j < 4; j++) { msig_update_float(recvsig[j], ((i % 10) * 1.0f)); } printf("\ndestination values updated to %d -->\n", i % 10); for (j = 0; j < 4; j++) { count = msig_query_remote(sendsig[j], dummysig[j]); printf("Sent %i queries for sendsig[%i]\n", count, j); } mdev_poll(destination, 100); mdev_poll(source, 0); i++; usleep(500 * 1000); } }
void loop() { printf("-------------------- GO ! --------------------\n"); int i = 0; if (automate) { char source_name_1[1024], destination_name_1[1024]; char source_name_2[1024], destination_name_2[1024]; printf("%s\n", mdev_name(source)); printf("%s\n", mdev_name(destination)); lo_address a = lo_address_new_from_url("osc.udp://224.0.1.3:7570"); lo_address_set_ttl(a, 1); lo_send(a, "/link", "ss", mdev_name(source), mdev_name(destination)); msig_full_name(sendsig_1, source_name_1, 1024); msig_full_name(recvsig_1, destination_name_1, 1024); lo_send(a, "/connect", "ss", source_name_1, destination_name_1); msig_full_name(sendsig_2, source_name_2, 1024); msig_full_name(recvsig_2, destination_name_2, 1024); lo_send(a, "/connect", "ss", source_name_2, destination_name_2); lo_address_free(a); } while (i >= 0 && !done) { mdev_poll(source, 0); msig_update_float(source->outputs[0], ((i % 10) * 1.0f)); msig_update_float(source->outputs[1], ((i % 10) * 1.0f)); printf("source value updated to %d -->\n", i % 10); printf("Received %i messages.\n\n", mdev_poll(destination, 100)); i++; } }
int setup_connection() { int count = 0; mapper_monitor mon = mapper_monitor_new(source->admin, 0); if (!mon) goto error; char src_name[1024], dest_name[1024]; mapper_monitor_link(mon, mdev_name(source), mdev_name(destination), 0, 0); while (!done && !source->routers) { if (count++ > 50) goto error; mdev_poll(source, 10); mdev_poll(destination, 10); } msig_full_name(sendsig, src_name, 1024); msig_full_name(recvsig, dest_name, 1024); mapper_monitor_connect(mon, src_name, dest_name, 0, 0); // wait until connection has been established while (!done && !source->routers->num_connections) { if (count++ > 50) goto error; mdev_poll(source, 10); mdev_poll(destination, 10); } eprintf("Connection established.\n"); mapper_monitor_free(mon); return 0; error: return 1; }
/* TODO: Bundle messages together that happen in the same call to poll(). */ void text_write_value(mapper_signal msig, void *v, mapper_timetag_t *tt) { int i; char str[1024], *path = str; msig_full_name(msig, path, 1024); if (path[0]=='/') path ++; while (path[0] && path[0]!='/') path ++; lo_timetag now; lo_timetag_now(&now); mapper_db_signal mprop = msig_properties(msig); if (!tt || !tt->sec) fprintf(output_file, "%u %u %s %c ", now.sec, now.frac, path, mprop->type); else fprintf(output_file, "%u %u %s %c ", tt->sec, tt->frac, path, mprop->type); if (mprop->type == 'i') { for (i=0; i<mprop->length; i++) fprintf(output_file, " %d", ((int*)v)[i]); } else if (mprop->type == 'f') { for (i=0; i<mprop->length; i++) fprintf(output_file, " %g", ((float*)v)[i]); } fprintf(output_file, "\n"); fflush(output_file); if (now.sec > last_write.sec) { printf("."); fflush(stdout); last_write = now; } }