diff options
Diffstat (limited to 'libs/backends/coreaudio/coreaudio_backend.cc')
-rw-r--r-- | libs/backends/coreaudio/coreaudio_backend.cc | 338 |
1 files changed, 14 insertions, 324 deletions
diff --git a/libs/backends/coreaudio/coreaudio_backend.cc b/libs/backends/coreaudio/coreaudio_backend.cc index 13d739ebf6..8001a095bc 100644 --- a/libs/backends/coreaudio/coreaudio_backend.cc +++ b/libs/backends/coreaudio/coreaudio_backend.cc @@ -936,194 +936,6 @@ CoreAudioBackend::my_name () const return _instance_name; } -uint32_t -CoreAudioBackend::port_name_size () const -{ - return 256; -} - -int -CoreAudioBackend::set_port_name (PortEngine::PortHandle port, const std::string& name) -{ - std::string newname (_instance_name + ":" + name); - if (!valid_port (port)) { - PBD::warning << _("CoreAudioBackend::set_port_name: Invalid Port(s)") << endmsg; - return -1; - } - if (find_port (newname)) { - PBD::error << _("CoreAudioBackend::set_port_name: Port with given name already exists") << endmsg; - return -1; - } - - CoreBackendPort* p = static_cast<CoreBackendPort*>(port); - pthread_mutex_lock (&_port_registration_mutex); - _portmap.erase (p->name()); - _portmap.insert (make_pair (newname, p)); - pthread_mutex_unlock (&_port_registration_mutex); - return p->set_name (newname); -} - -std::string -CoreAudioBackend::get_port_name (PortEngine::PortHandle port) const -{ - if (!valid_port (port)) { - PBD::warning << _("CoreAudioBackend::get_port_name: Invalid Port(s)") << endmsg; - return std::string (); - } - return static_cast<CoreBackendPort*>(port)->name (); -} - -PortFlags -CoreAudioBackend::get_port_flags (PortEngine::PortHandle port) const -{ - if (!valid_port (port)) { - PBD::warning << _("CoreAudioBackend::get_port_flags: Invalid Port(s)") << endmsg; - return PortFlags (0); - } - return static_cast<CoreBackendPort*>(port)->flags (); -} - -int -CoreAudioBackend::get_port_property (PortHandle port, const std::string& key, std::string& value, std::string& type) const -{ - if (!valid_port (port)) { - PBD::warning << _("CoreAudioBackend::get_port_property: Invalid Port(s)") << endmsg; - return -1; - } - if (key == "http://jackaudio.org/metadata/pretty-name") { - type = ""; - value = static_cast<CoreBackendPort*>(port)->pretty_name (); - if (!value.empty()) { - return 0; - } - } - return -1; -} - -int -CoreAudioBackend::set_port_property (PortHandle port, const std::string& key, const std::string& value, const std::string& type) -{ - if (!valid_port (port)) { - PBD::warning << _("CoreAudioBackend::set_port_property: Invalid Port(s)") << endmsg; - return -1; - } - if (key == "http://jackaudio.org/metadata/pretty-name" && type.empty ()) { - static_cast<CoreBackendPort*>(port)->set_pretty_name (value); - return 0; - } - return -1; -} - -PortEngine::PortHandle -CoreAudioBackend::get_port_by_name (const std::string& name) const -{ - PortHandle port = (PortHandle) find_port (name); - return port; -} - -int -CoreAudioBackend::get_ports ( - const std::string& port_name_pattern, - DataType type, PortFlags flags, - std::vector<std::string>& port_names) const -{ - int rv = 0; - regex_t port_regex; - bool use_regexp = false; - if (port_name_pattern.size () > 0) { - if (!regcomp (&port_regex, port_name_pattern.c_str (), REG_EXTENDED|REG_NOSUB)) { - use_regexp = true; - } - } - - for (PortIndex::const_iterator i = _ports.begin (); i != _ports.end (); ++i) { - CoreBackendPort* port = *i; - if ((port->type () == type) && flags == (port->flags () & flags)) { - if (!use_regexp || !regexec (&port_regex, port->name ().c_str (), 0, NULL, 0)) { - port_names.push_back (port->name ()); - ++rv; - } - } - } - if (use_regexp) { - regfree (&port_regex); - } - return rv; -} - -DataType -CoreAudioBackend::port_data_type (PortEngine::PortHandle port) const -{ - if (!valid_port (port)) { - return DataType::NIL; - } - return static_cast<CoreBackendPort*>(port)->type (); -} - -PortEngine::PortHandle -CoreAudioBackend::register_port ( - const std::string& name, - ARDOUR::DataType type, - ARDOUR::PortFlags flags) -{ - if (name.size () == 0) { return 0; } - if (flags & IsPhysical) { return 0; } - return add_port (_instance_name + ":" + name, type, flags); -} - -PortEngine::PortHandle -CoreAudioBackend::add_port ( - const std::string& name, - ARDOUR::DataType type, - ARDOUR::PortFlags flags) -{ - assert(name.size ()); - if (find_port (name)) { - PBD::warning << _("CoreAudioBackend::register_port: Port already exists:") - << " (" << name << ")" << endmsg; - return 0; - } - CoreBackendPort* port = NULL; - switch (type) { - case DataType::AUDIO: - port = new CoreAudioPort (*this, name, flags); - break; - case DataType::MIDI: - port = new CoreMidiPort (*this, name, flags); - break; - default: - PBD::error << _("CoreAudioBackend::register_port: Invalid Data Type.") << endmsg; - return 0; - } - - pthread_mutex_lock (&_port_registration_mutex); - _ports.insert (port); - _portmap.insert (make_pair (name, port)); - pthread_mutex_unlock (&_port_registration_mutex); - - return port; -} - -void -CoreAudioBackend::unregister_port (PortEngine::PortHandle port_handle) -{ - if (!_run) { - return; - } - CoreBackendPort* port = static_cast<CoreBackendPort*>(port_handle); - PortIndex::iterator i = std::find (_ports.begin(), _ports.end(), static_cast<CoreBackendPort*>(port_handle)); - if (i == _ports.end ()) { - PBD::warning << _("CoreAudioBackend::unregister_port: Failed to find port") << endmsg; - return; - } - disconnect_all(port_handle); - pthread_mutex_lock (&_port_registration_mutex); - _portmap.erase (port->name()); - _ports.erase (i); - pthread_mutex_unlock (&_port_registration_mutex); - delete port; -} - int CoreAudioBackend::register_system_audio_ports() { @@ -1287,146 +1099,24 @@ CoreAudioBackend::coremidi_rediscover() pthread_mutex_unlock (&_process_callback_mutex); } -void -CoreAudioBackend::unregister_ports (bool system_only) -{ - _system_inputs.clear(); - _system_outputs.clear(); - _system_midi_in.clear(); - _system_midi_out.clear(); - - for (PortIndex::iterator i = _ports.begin (); i != _ports.end ();) { - PortIndex::iterator cur = i++; - CoreBackendPort* port = *cur; - if (! system_only || (port->is_physical () && port->is_terminal ())) { - port->disconnect_all (); - _portmap.erase (port->name()); - delete port; - _ports.erase (cur); - } - } -} - -int -CoreAudioBackend::connect (const std::string& src, const std::string& dst) -{ - CoreBackendPort* src_port = find_port (src); - CoreBackendPort* dst_port = find_port (dst); - - if (!src_port) { - PBD::warning << _("CoreAudioBackend::connect: Invalid Source port:") - << " (" << src <<")" << endmsg; - return -1; - } - if (!dst_port) { - PBD::warning << _("CoreAudioBackend::connect: Invalid Destination port:") - << " (" << dst <<")" << endmsg; - return -1; - } - return src_port->connect (dst_port); -} - -int -CoreAudioBackend::disconnect (const std::string& src, const std::string& dst) -{ - CoreBackendPort* src_port = find_port (src); - CoreBackendPort* dst_port = find_port (dst); - - if (!src_port || !dst_port) { - PBD::warning << _("CoreAudioBackend::disconnect: Invalid Port(s)") << endmsg; - return -1; - } - return src_port->disconnect (dst_port); -} - -int -CoreAudioBackend::connect (PortEngine::PortHandle src, const std::string& dst) -{ - CoreBackendPort* dst_port = find_port (dst); - if (!valid_port (src)) { - PBD::warning << _("CoreAudioBackend::connect: Invalid Source Port Handle") << endmsg; - return -1; - } - if (!dst_port) { - PBD::warning << _("CoreAudioBackend::connect: Invalid Destination Port") - << " (" << dst << ")" << endmsg; - return -1; - } - return static_cast<CoreBackendPort*>(src)->connect (dst_port); -} - -int -CoreAudioBackend::disconnect (PortEngine::PortHandle src, const std::string& dst) -{ - CoreBackendPort* dst_port = find_port (dst); - if (!valid_port (src) || !dst_port) { - PBD::warning << _("CoreAudioBackend::disconnect: Invalid Port(s)") << endmsg; - return -1; - } - return static_cast<CoreBackendPort*>(src)->disconnect (dst_port); -} - -int -CoreAudioBackend::disconnect_all (PortEngine::PortHandle port) -{ - if (!valid_port (port)) { - PBD::warning << _("CoreAudioBackend::disconnect_all: Invalid Port") << endmsg; - return -1; - } - static_cast<CoreBackendPort*>(port)->disconnect_all (); - return 0; -} - -bool -CoreAudioBackend::connected (PortEngine::PortHandle port, bool /* process_callback_safe*/) -{ - if (!valid_port (port)) { - PBD::warning << _("CoreAudioBackend::disconnect_all: Invalid Port") << endmsg; - return false; - } - return static_cast<CoreBackendPort*>(port)->is_connected (); -} - -bool -CoreAudioBackend::connected_to (PortEngine::PortHandle src, const std::string& dst, bool /*process_callback_safe*/) -{ - CoreBackendPort* dst_port = find_port (dst); -#ifndef NDEBUG - if (!valid_port (src) || !dst_port) { - PBD::warning << _("CoreAudioBackend::connected_to: Invalid Port") << endmsg; - return false; - } -#endif - return static_cast<CoreBackendPort*>(src)->is_connected (dst_port); -} - -bool -CoreAudioBackend::physically_connected (PortEngine::PortHandle port, bool /*process_callback_safe*/) -{ - if (!valid_port (port)) { - PBD::warning << _("CoreAudioBackend::physically_connected: Invalid Port") << endmsg; - return false; - } - return static_cast<CoreBackendPort*>(port)->is_physically_connected (); -} - -int -CoreAudioBackend::get_connections (PortEngine::PortHandle port, std::vector<std::string>& names, bool /*process_callback_safe*/) +BackendPort* +CoreAudioBackend::port_factory (std::string const & name, ARDOUR::DataType type, ARDOUR::PortFlags flags) { - if (!valid_port (port)) { - PBD::warning << _("CoreAudioBackend::get_connections: Invalid Port") << endmsg; - return -1; - } + BackendPort* port = 0; - assert (0 == names.size ()); - - const std::set<CoreBackendPort*>& connected_ports = static_cast<CoreBackendPort*>(port)->get_connections (); - - for (std::set<CoreBackendPort*>::const_iterator i = connected_ports.begin (); i != connected_ports.end (); ++i) { - names.push_back ((*i)->name ()); + switch (type) { + case DataType::AUDIO: + port = new CoreAudioPort (*this, name, flags); + break; + case DataType::MIDI: + port = new CoreMidiPort (*this, name, flags); + break; + default: + PBD::error << string_compose (_("%1::register_port: Invalid Data Type."), _instance_name) << endmsg; + return 0; } - return (int)names.size (); + return port; } /* MIDI */ |