Commit bc4c8bc3 authored by sletz's avatar sletz
Browse files

Use SetAlias for port naming. Use jackd midi port naming scheme.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@1845 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 4c5a5203
......@@ -17,6 +17,10 @@ Tim Blechmann
Jackdmp changes log
---------------------------
2008-02-11 Stephane Letz <letz@grame.fr>
* Use SetAlias for port naming. Use jackd midi port naming scheme.
2008-02-08 Stephane Letz <letz@grame.fr>
* More robust external API.
......
......@@ -86,20 +86,22 @@ int JackAudioDriver::Attach()
{
JackPort* port;
jack_port_id_t port_index;
char buf[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
char name[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
char alias[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
unsigned long port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal;
int i;
JackLog("JackAudioDriver::Attach fBufferSize = %ld fSampleRate = %ld\n", fEngineControl->fBufferSize, fEngineControl->fSampleRate);
for (i = 0; i < fCaptureChannels; i++) {
snprintf(buf, sizeof(buf) - 1, "%s:%s:out%d", fClientControl->fName, fCaptureDriverName, i + 1);
if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, buf, JACK_DEFAULT_AUDIO_TYPE, (JackPortFlags)port_flags, fEngineControl->fBufferSize)) == NO_PORT) {
jack_error("driver: cannot register port for %s", buf);
snprintf(alias, sizeof(alias) - 1, "%s:%s:out%d", fClientControl->fName, fCaptureDriverName, i + 1);
snprintf(name, sizeof(name) - 1, "system:capture_%d", i + 1);
if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, name, JACK_DEFAULT_AUDIO_TYPE, (JackPortFlags)port_flags, fEngineControl->fBufferSize)) == NO_PORT) {
jack_error("driver: cannot register port for %s", alias);
return -1;
}
port = fGraphManager->GetPort(port_index);
port->Rename("system:capture_%d", i + 1);
port->SetAlias(alias);
port->SetLatency(fEngineControl->fBufferSize + fCaptureLatency);
fCapturePortList[i] = port_index;
JackLog("JackAudioDriver::Attach fCapturePortList[i] port_index = %ld\n", port_index);
......@@ -108,13 +110,14 @@ int JackAudioDriver::Attach()
port_flags = JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal;
for (i = 0; i < fPlaybackChannels; i++) {
snprintf(buf, sizeof(buf) - 1, "%s:%s:in%d", fClientControl->fName, fPlaybackDriverName, i + 1);
if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, buf, JACK_DEFAULT_AUDIO_TYPE, (JackPortFlags)port_flags, fEngineControl->fBufferSize)) == NO_PORT) {
jack_error("driver: cannot register port for %s", buf);
snprintf(alias, sizeof(alias) - 1, "%s:%s:in%d", fClientControl->fName, fPlaybackDriverName, i + 1);
snprintf(name, sizeof(name) - 1, "system:playback_%d", i + 1);
if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, alias, JACK_DEFAULT_AUDIO_TYPE, (JackPortFlags)port_flags, fEngineControl->fBufferSize)) == NO_PORT) {
jack_error("driver: cannot register port for %s", alias);
return -1;
}
port = fGraphManager->GetPort(port_index);
port->Rename("system:playback_%d", i + 1);
port->SetAlias(alias);
port->SetLatency(fEngineControl->fBufferSize + fPlaybackLatency);
fPlaybackPortList[i] = port_index;
JackLog("JackAudioDriver::Attach fPlaybackPortList[i] port_index = %ld\n", port_index);
......@@ -122,9 +125,9 @@ int JackAudioDriver::Attach()
// Monitor ports
if (fWithMonitorPorts) {
JackLog("Create monitor port \n");
snprintf(buf, sizeof(buf) - 1, "%s:%s:monitor_%u", fClientControl->fName, fPlaybackDriverName, i + 1);
if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, buf, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, fEngineControl->fBufferSize)) == NO_PORT) {
jack_error("Cannot register monitor port for %s", buf);
snprintf(name, sizeof(name) - 1, "%s:%s:monitor_%u", fClientControl->fName, fPlaybackDriverName, i + 1);
if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, fEngineControl->fBufferSize)) == NO_PORT) {
jack_error("Cannot register monitor port for %s", name);
return -1;
} else {
port = fGraphManager->GetPort(port_index);
......
......@@ -193,12 +193,6 @@ int JackPort::SetName(const char* new_name)
return 0;
}
void JackPort::Rename(const char* name, int index)
{
SetAlias(GetName());
snprintf(fName, sizeof(fName) - 1, name, index);
}
bool JackPort::NameEquals(const char* target)
{
char buf[JACK_PORT_NAME_SIZE + 1];
......
......@@ -81,7 +81,6 @@ class JackPort
const char* GetName() const;
const char* GetShortName() const;
int SetName(const char* name);
void Rename(const char* name, int index);
int GetAliases(char* const aliases[2]);
int SetAlias(const char* alias);
......
......@@ -2369,6 +2369,11 @@ void* JackAlsaDriver::port_get_buffer(int port, jack_nframes_t nframes)
return fGraphManager->GetBuffer(port, nframes);
}
int JackAlsaDriver::port_set_alias(int port, const char* name)
{
return fGraphManager->GetPort(port)->SetAlias(name);
}
jack_nframes_t JackAlsaDriver::get_sample_rate() const
{
return fEngineControl->fSampleRate;
......
......@@ -163,6 +163,7 @@ class JackAlsaDriver : public JackAudioDriver
int port_register(const char *port_name, const char *port_type, unsigned long flags, unsigned long buf_size);
int port_unregister(int port);
void* port_get_buffer(int port, jack_nframes_t nframes);
int port_set_alias(int port, const char* name);
jack_nframes_t get_sample_rate() const;
jack_nframes_t frame_time() const;
......
......@@ -34,6 +34,7 @@ int JACK_client_create_thread(jack_client_t *client, pthread_t *thread, int prio
jack_port_t* JACK_port_register(jack_client_t *client, const char *port_name, const char *port_type, unsigned long flags, unsigned long buffer_size);
int JACK_port_unregister(jack_client_t *, jack_port_t*);
void* JACK_port_get_buffer(jack_port_t*, jack_nframes_t);
int JACK_port_set_alias(jack_port_t* port, const char* name);
jack_nframes_t JACK_get_sample_rate(jack_client_t *);
jack_nframes_t JACK_frame_time(jack_client_t *);
......@@ -45,6 +46,7 @@ jack_nframes_t JACK_last_frame_time(jack_client_t *);
#define jack_port_register JACK_port_register
#define jack_port_unregister JACK_port_unregister
#define jack_port_get_buffer JACK_port_get_buffer
#define jack_port_set_alias JACK_port_set_alias
#define jack_get_sample_rate JACK_get_sample_rate
#define jack_frame_time JACK_frame_time
......
......@@ -44,6 +44,12 @@ void* JACK_port_get_buffer(jack_port_t *port, jack_nframes_t nframes)
return real->driver->port_get_buffer(real->port_id, nframes);
}
int JACK_port_set_alias(jack_port_t *port, const char* name)
{
fake_port_t* real = (fake_port_t*)port;
return real->driver->port_set_alias(real->port_id, name);
}
jack_nframes_t JACK_get_sample_rate(jack_client_t *client)
{
return ((JackAlsaDriver*)client)->get_sample_rate();
......
......@@ -176,6 +176,8 @@ struct alsa_rawmidi_t {
midi_stream_t in;
midi_stream_t out;
int midi_in_cnt;
int midi_out_cnt;
};
static int input_port_init(alsa_rawmidi_t *midi, midi_port_t *port);
......@@ -264,6 +266,8 @@ alsa_midi_t* alsa_rawmidi_new(jack_client_t *jack)
midi->ops.stop = alsa_rawmidi_stop;
midi->ops.read = alsa_rawmidi_read;
midi->ops.write = alsa_rawmidi_write;
midi->midi_in_cnt = 0;
midi->midi_out_cnt = 0;
return &midi->ops;
fail_3:
......@@ -417,10 +421,20 @@ void midi_port_init(const alsa_rawmidi_t *midi, midi_port_t *port, snd_rawmidi_i
}
static
inline int midi_port_open_jack(const alsa_rawmidi_t *midi, midi_port_t *port, int type, const char *name)
inline int midi_port_open_jack(const alsa_rawmidi_t *midi, midi_port_t *port, int type, const char *alias)
{
char name[64];
if (type & JackPortIsOutput)
snprintf(name, sizeof(name) - 1, "system:midi_capture_%d", ++midi->midi_in_cnt);
else
snprintf(name, sizeof(name) - 1, "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_port,alias);
return port->jack == NULL;
}
......
......@@ -106,6 +106,8 @@ typedef struct alsa_seqmidi {
stream_t stream[2];
char alsa_name[32];
int midi_in_cnt;
int midi_out_cnt;
} alsa_seqmidi_t;
struct alsa_midi_event {
......@@ -225,6 +227,8 @@ alsa_midi_t* alsa_seqmidi_new(jack_client_t *client, const char* alsa_name)
stream_init(self, PORT_INPUT);
stream_init(self, PORT_OUTPUT);
self->midi_in_cnt = 0;
self->midi_out_cnt = 0;
self->ops.destroy = alsa_seqmidi_delete;
self->ops.attach = alsa_seqmidi_attach;
self->ops.detach = alsa_seqmidi_detach;
......@@ -455,25 +459,34 @@ port_t* port_create(alsa_seqmidi_t *self, int type, snd_seq_addr_t addr, const s
port_t *port;
char *c;
int err;
char name[64];
port = calloc(1, sizeof(port_t));
if (!port)
return NULL;
port->remote = addr;
if (port_type[type].jack_caps & JackPortIsOutput)
snprintf(name, sizeof(name) - 1, "system:midi_capture_%d", ++self->midi_in_cnt);
else
snprintf(name, sizeof(name) - 1, "system:midi_playback_%d", ++self->midi_out_cnt);
snprintf(port->name, sizeof(port->name), "%s-%d-%d-%s",
port_type[type].name, addr.client, addr.port, snd_seq_port_info_get_name(info));
// replace all offending characters by -
for (c = port->name; *c; ++c)
if (!isalnum(*c))
*c = '-';
port->jack_port = jack_port_register(self->jack,
port->name, JACK_DEFAULT_MIDI_TYPE, port_type[type].jack_caps, 0);
name, JACK_DEFAULT_MIDI_TYPE, port_type[type].jack_caps, 0);
if (!port->jack_port)
goto failed;
jack_port_set_alias(port->jack_port, port->name);
if (type == PORT_INPUT)
err = alsa_connect_from(self, port->remote.client, port->remote.port);
......
......@@ -951,7 +951,8 @@ int JackCoreAudioDriver::Attach()
UInt32 size;
Boolean isWritable;
char channel_name[64];
char buf[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
char name[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
char alias[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
unsigned long port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal;
JackLog("JackCoreAudioDriver::Attach fBufferSize %ld fSampleRate %ld\n", fEngineControl->fBufferSize, fEngineControl->fSampleRate);
......@@ -965,13 +966,15 @@ int JackCoreAudioDriver::Attach()
err = AudioDeviceGetProperty(fDeviceID, i + 1, true, kAudioDevicePropertyChannelName, &size, channel_name);
if (err != noErr)
JackLog("AudioDeviceGetProperty kAudioDevicePropertyChannelName error \n");
snprintf(buf, sizeof(buf) - 1, "%s:%s:out_%s%u", fClientControl->fName, fCaptureDriverName, channel_name, i + 1);
snprintf(alias, sizeof(alias) - 1, "%s:%s:out_%s%u", fClientControl->fName, fCaptureDriverName, channel_name, i + 1);
} else {
snprintf(buf, sizeof(buf) - 1, "%s:%s:out%u", fClientControl->fName, fCaptureDriverName, i + 1);
snprintf(alias, sizeof(alias) - 1, "%s:%s:out%u", fClientControl->fName, fCaptureDriverName, i + 1);
}
if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, buf, JACK_DEFAULT_AUDIO_TYPE, (JackPortFlags)port_flags, fEngineControl->fBufferSize)) == NO_PORT) {
jack_error("Cannot register port for %s", buf);
snprintf(name, sizeof(name) - 1, "system:capture_%d", i + 1);
if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, name, JACK_DEFAULT_AUDIO_TYPE, (JackPortFlags)port_flags, fEngineControl->fBufferSize)) == NO_PORT) {
jack_error("Cannot register port for %s", name);
return -1;
}
......@@ -986,7 +989,7 @@ int JackCoreAudioDriver::Attach()
JackLog("AudioDeviceGetProperty kAudioDevicePropertySafetyOffset error \n");
port = fGraphManager->GetPort(port_index);
port->Rename("system:capture_%d", i + 1);
port->SetAlias(alias);
port->SetLatency(fEngineControl->fBufferSize + value1 + value2 + fCaptureLatency);
fCapturePortList[i] = port_index;
}
......@@ -1002,13 +1005,15 @@ int JackCoreAudioDriver::Attach()
err = AudioDeviceGetProperty(fDeviceID, i + 1, false, kAudioDevicePropertyChannelName, &size, channel_name);
if (err != noErr)
JackLog("AudioDeviceGetProperty kAudioDevicePropertyChannelName error \n");
snprintf(buf, sizeof(buf) - 1, "%s:%s:in_%s%u", fClientControl->fName, fPlaybackDriverName, channel_name, i + 1);
snprintf(alias, sizeof(alias) - 1, "%s:%s:in_%s%u", fClientControl->fName, fPlaybackDriverName, channel_name, i + 1);
} else {
snprintf(buf, sizeof(buf) - 1, "%s:%s:in%u", fClientControl->fName, fPlaybackDriverName, i + 1);
snprintf(alias, sizeof(alias) - 1, "%s:%s:in%u", fClientControl->fName, fPlaybackDriverName, i + 1);
}
snprintf(name, sizeof(name) - 1, "system:playback_%d", i + 1);
if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, buf, JACK_DEFAULT_AUDIO_TYPE, (JackPortFlags)port_flags, fEngineControl->fBufferSize)) == NO_PORT) {
jack_error("Cannot register port for %s", buf);
if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, name, JACK_DEFAULT_AUDIO_TYPE, (JackPortFlags)port_flags, fEngineControl->fBufferSize)) == NO_PORT) {
jack_error("Cannot register port for %s", name);
return -1;
}
......@@ -1023,16 +1028,16 @@ int JackCoreAudioDriver::Attach()
JackLog("AudioDeviceGetProperty kAudioDevicePropertySafetyOffset error \n");
port = fGraphManager->GetPort(port_index);
port->Rename("system:playback_%d", i + 1);
port->SetAlias(alias);
port->SetLatency(fEngineControl->fBufferSize + value1 + value2 + fPlaybackLatency);
fPlaybackPortList[i] = port_index;
// Monitor ports
if (fWithMonitorPorts) {
JackLog("Create monitor port \n");
snprintf(buf, sizeof(buf) - 1, "%s:%s:monitor_%u", fClientControl->fName, fPlaybackDriverName, i + 1);
if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, buf, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, fEngineControl->fBufferSize)) == NO_PORT) {
jack_error("Cannot register monitor port for %s", buf);
snprintf(name, sizeof(name) - 1, "%s:%s:monitor_%u", fClientControl->fName, fPlaybackDriverName, i + 1);
if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, fEngineControl->fBufferSize)) == NO_PORT) {
jack_error("Cannot register monitor port for %s", name);
return -1;
} else {
port = fGraphManager->GetPort(port_index);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment