From 66cafd10d51994dffe7d73f3bb9b837f05378f49 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Tue, 4 Aug 2015 15:29:03 +1000 Subject: [PATCH] Use ASIO specific device channel names for port properties/pretty names --- libs/backends/portaudio/portaudio_backend.cc | 32 ++++++++++++++- libs/backends/portaudio/portaudio_backend.h | 4 ++ libs/backends/portaudio/portaudio_io.cc | 41 ++++++++++++++++++++ libs/backends/portaudio/portaudio_io.h | 3 ++ 4 files changed, 78 insertions(+), 2 deletions(-) diff --git a/libs/backends/portaudio/portaudio_backend.cc b/libs/backends/portaudio/portaudio_backend.cc index fef0984750..0356025c9c 100644 --- a/libs/backends/portaudio/portaudio_backend.cc +++ b/libs/backends/portaudio/portaudio_backend.cc @@ -792,6 +792,28 @@ PortAudioBackend::get_port_name (PortEngine::PortHandle port) const return static_cast(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(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(IsOutput | IsPhysical | IsTerminal)); if (!p) return -1; set_latency_range (p, false, lr); - _system_inputs.push_back(static_cast(p)); + PortAudioPort* audio_port = static_cast(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(IsInput | IsPhysical | IsTerminal)); if (!p) return -1; set_latency_range (p, true, lr); - _system_outputs.push_back(static_cast(p)); + PortAudioPort* audio_port = static_cast(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; } diff --git a/libs/backends/portaudio/portaudio_backend.h b/libs/backends/portaudio/portaudio_backend.h index b0cc68715f..f1ff790e5e 100644 --- a/libs/backends/portaudio/portaudio_backend.h +++ b/libs/backends/portaudio/portaudio_backend.h @@ -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&) const; diff --git a/libs/backends/portaudio/portaudio_io.cc b/libs/backends/portaudio/portaudio_io.cc index 5ba424c26d..6693c88af9 100644 --- a/libs/backends/portaudio/portaudio_io.cc +++ b/libs/backends/portaudio/portaudio_io.cc @@ -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 diff --git a/libs/backends/portaudio/portaudio_io.h b/libs/backends/portaudio/portaudio_io.h index 3d52ae6509..ff40b711c3 100644 --- a/libs/backends/portaudio/portaudio_io.h +++ b/libs/backends/portaudio/portaudio_io.h @@ -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; }