13
0

Use ASIO specific device channel names for port properties/pretty names

This commit is contained in:
Tim Mayberry 2015-08-04 15:29:03 +10:00
parent 61e851da08
commit 66cafd10d5
4 changed files with 78 additions and 2 deletions

View File

@ -792,6 +792,28 @@ PortAudioBackend::get_port_name (PortEngine::PortHandle port) const
return static_cast<PamPort*>(port)->name ();
}
int
PortAudioBackend::get_port_property (PortHandle port,
const std::string& key,
std::string& value,
std::string& type) const
{
if (!valid_port (port)) {
PBD::error << _ ("PortAudioBackend::get_port_name: Invalid Port(s)")
<< endmsg;
return -1;
}
if (key == "http://jackaudio.org/metadata/pretty-name") {
type = "";
value = static_cast<PamPort*>(port)->pretty_name ();
if (!value.empty()) {
return 0;
}
}
return -1;
}
PortEngine::PortHandle
PortAudioBackend::get_port_by_name (const std::string& name) const
{
@ -915,7 +937,10 @@ PortAudioBackend::register_system_audio_ports()
PortHandle p = add_port(std::string(tmp), DataType::AUDIO, static_cast<PortFlags>(IsOutput | IsPhysical | IsTerminal));
if (!p) return -1;
set_latency_range (p, false, lr);
_system_inputs.push_back(static_cast<PortAudioPort*>(p));
PortAudioPort* audio_port = static_cast<PortAudioPort*>(p);
audio_port->set_pretty_name (
_pcmio->get_input_channel_name (name_to_id (_input_audio_device), i));
_system_inputs.push_back (audio_port);
}
lr.min = lr.max = portaudio_reported_output_latency + (_measure_latency ? 0 : _systemic_audio_output_latency);
@ -925,7 +950,10 @@ PortAudioBackend::register_system_audio_ports()
PortHandle p = add_port(std::string(tmp), DataType::AUDIO, static_cast<PortFlags>(IsInput | IsPhysical | IsTerminal));
if (!p) return -1;
set_latency_range (p, true, lr);
_system_outputs.push_back(static_cast<PamPort*>(p));
PortAudioPort* audio_port = static_cast<PortAudioPort*>(p);
audio_port->set_pretty_name (
_pcmio->get_output_channel_name (name_to_id (_output_audio_device), i));
_system_outputs.push_back(audio_port);
}
return 0;
}

View File

@ -65,9 +65,11 @@ class PamPort { // PortAudio / PortMidi Backend Port
virtual ~PamPort ();
const std::string& name () const { return _name; }
const std::string& pretty_name () const { return _pretty_name; }
PortFlags flags () const { return _flags; }
int set_name (const std::string &name) { _name = name; return 0; }
int set_pretty_name (const std::string& name) { _pretty_name = name; return 0;}
virtual DataType type () const = 0;
@ -107,6 +109,7 @@ class PamPort { // PortAudio / PortMidi Backend Port
private:
PortAudioBackend &_osx_backend;
std::string _name;
std::string _pretty_name;
const PortFlags _flags;
LatencyRange _capture_latency_range;
LatencyRange _playback_latency_range;
@ -261,6 +264,7 @@ class PortAudioBackend : public AudioBackend {
int set_port_name (PortHandle, const std::string&);
std::string get_port_name (PortHandle) const;
PortHandle get_port_by_name (const std::string&) const;
int get_port_property (PortHandle, const std::string& key, std::string& value, std::string& type) const;
int get_ports (const std::string& port_name_pattern, DataType type, PortFlags flags, std::vector<std::string>&) const;

View File

@ -737,6 +737,47 @@ PortAudioIO::next_cycle (uint32_t n_samples)
return xrun ? 1 : 0;
}
std::string
PortAudioIO::get_input_channel_name (int device_id, uint32_t channel) const
{
#ifdef WITH_ASIO
const char* channel_name;
// This will return an error for non-ASIO devices so no need to check if
// the device_id corresponds to an ASIO device.
PaError err = PaAsio_GetInputChannelName (device_id, channel, &channel_name);
if (err == paNoError) {
DEBUG_AUDIO (
string_compose ("Input channel name for device %1, channel %2 is %3\n",
device_id,
channel,
channel_name));
return channel_name;
}
#endif
return std::string();
}
std::string
PortAudioIO::get_output_channel_name (int device_id, uint32_t channel) const
{
#ifdef WITH_ASIO
const char* channel_name;
PaError err = PaAsio_GetOutputChannelName (device_id, channel, &channel_name);
if (err == paNoError) {
DEBUG_AUDIO (
string_compose ("Output channel name for device %1, channel %2 is %3\n",
device_id,
channel,
channel_name));
return channel_name;
}
#endif
return std::string();
}
#ifdef INTERLEAVED_INPUT

View File

@ -81,6 +81,9 @@ public:
uint32_t n_playback_channels (void) const { return _playback_channels; }
uint32_t n_capture_channels (void) const { return _capture_channels; }
std::string get_input_channel_name (int device_id, uint32_t channel) const;
std::string get_output_channel_name (int device_id, uint32_t channel) const;
double sample_rate (void) const { return _cur_sample_rate; }
uint32_t capture_latency (void) const { return _cur_input_latency; }
uint32_t playback_latency (void) const { return _cur_output_latency; }