static inline int midi_port_open_jack(alsa_rawmidi_t *midi, midi_port_t *port, int type, const char *alias) { char name[128]; if (type & JackPortIsOutput) snprintf(name, sizeof(name), "system:midi_capture_%d", ++midi->midi_in_cnt); else snprintf(name, sizeof(name), "system:midi_playback_%d", ++midi->midi_out_cnt); port->jack = jack_port_register(midi->client, name, JACK_DEFAULT_MIDI_TYPE, type | JackPortIsPhysical | JackPortIsTerminal, 0); if (port->jack) jack_port_set_alias(port->jack, alias); return port->jack == NULL; }
static port_t* port_create(alsa_seqmidi_t *self, int type, snd_seq_addr_t addr, const snd_seq_port_info_t *info) { snd_seq_client_info_t* client_info; port_t *port; char *c; int err; int jack_caps; char name[128]; port = calloc(1, sizeof(port_t)); if (!port) return NULL; port->remote = addr; snd_seq_client_info_alloca (&client_info); snd_seq_get_any_client_info (self->seq, addr.client, client_info); snprintf(port->name, sizeof(port->name), "alsa_pcm:%s/midi_%s_%d", snd_seq_client_info_get_name(client_info), port_type[type].name, addr.port+1); // replace all offending characters by - for (c = port->name; *c; ++c) if (!isalnum(*c) && *c != '/' && *c != '_' && *c != ':' && *c != '(' && *c != ')') *c = '-'; jack_caps = port_type[type].jack_caps; /* mark anything that looks like a hardware port as physical&terminal */ if (snd_seq_port_info_get_type (info) & (SND_SEQ_PORT_TYPE_HARDWARE|SND_SEQ_PORT_TYPE_PORT|SND_SEQ_PORT_TYPE_SPECIFIC)) { jack_caps |= (JackPortIsPhysical | JackPortIsTerminal); } if (jack_caps & JackPortIsOutput) snprintf(name, sizeof(name), "system:midi_capture_%d", ++self->midi_in_cnt); else snprintf(name, sizeof(name), "system:midi_playback_%d", ++self->midi_out_cnt); port->jack_port = jack_port_register(self->jack, name, JACK_DEFAULT_MIDI_TYPE, jack_caps, 0); if (!port->jack_port) goto failed; jack_port_set_alias (port->jack_port, port->name); /* generate an alias */ snprintf(port->name, sizeof(port->name), "%s:midi/%s_%d", snd_seq_client_info_get_name (client_info), port_type[type].name, addr.port+1); // replace all offending characters by - for (c = port->name; *c; ++c) if (!isalnum(*c) && *c != '/' && *c != '_' && *c != ':' && *c != '(' && *c != ')') *c = '-'; jack_port_set_alias (port->jack_port, port->name); if (type == PORT_INPUT) err = alsa_connect_from(self, port->remote.client, port->remote.port); else err = snd_seq_connect_to(self->seq, self->port_id, port->remote.client, port->remote.port); if (err) goto failed; port->early_events = jack_ringbuffer_create(MAX_EVENT_SIZE*16); info_log("port created: %s", port->name); return port; failed: port_free(self, port); return NULL; }