diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2020-04-02 17:15:47 -0600 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2020-04-02 19:45:31 -0600 |
commit | 04551c39f6be5406bb35b4214cc408340a46ca6e (patch) | |
tree | d5d132d4d6d9a94bfbdd75db15f5ceeade3f2289 /libs/backends | |
parent | 30766c75e855be26072cd8a6631cb5b9c532b466 (diff) |
use PortEngineSharedImpl with DummyAudioBackend
Diffstat (limited to 'libs/backends')
-rw-r--r-- | libs/backends/dummy/dummy_audiobackend.cc | 640 | ||||
-rw-r--r-- | libs/backends/dummy/dummy_audiobackend.h | 144 |
2 files changed, 84 insertions, 700 deletions
diff --git a/libs/backends/dummy/dummy_audiobackend.cc b/libs/backends/dummy/dummy_audiobackend.cc index a9d39478fd..bf87b3275c 100644 --- a/libs/backends/dummy/dummy_audiobackend.cc +++ b/libs/backends/dummy/dummy_audiobackend.cc @@ -36,9 +36,10 @@ #include "pbd/error.h" #include "pbd/compose.h" -#include "ardour/port_manager.h" #include "pbd/i18n.h" +#include "ardour/port_manager.h" + using namespace ARDOUR; static std::string s_instance_name; @@ -57,6 +58,7 @@ static int64_t _x_get_monotonic_usec() { DummyAudioBackend::DummyAudioBackend (AudioEngine& e, AudioBackendInfo& info) : AudioBackend (e, info) + , PortEngineSharedImpl (e, s_instance_name) , _running (false) , _freewheel (false) , _freewheeling (false) @@ -261,18 +263,18 @@ DummyAudioBackend::set_buffer_size (uint32_t bs) */ LatencyRange lr; lr.min = lr.max = _systemic_input_latency; - for (std::vector<DummyAudioPort*>::const_iterator it = _system_inputs.begin (); it != _system_inputs.end (); ++it) { + for (std::vector<BackendPort*>::const_iterator it = _system_inputs.begin (); it != _system_inputs.end (); ++it) { set_latency_range (*it, false, lr); } - for (std::vector<DummyMidiPort*>::const_iterator it = _system_midi_in.begin (); it != _system_midi_in.end (); ++it) { + for (std::vector<BackendPort*>::const_iterator it = _system_midi_in.begin (); it != _system_midi_in.end (); ++it) { set_latency_range (*it, false, lr); } lr.min = lr.max = _systemic_output_latency; - for (std::vector<DummyAudioPort*>::const_iterator it = _system_outputs.begin (); it != _system_outputs.end (); ++it) { + for (std::vector<BackendPort*>::const_iterator it = _system_outputs.begin (); it != _system_outputs.end (); ++it) { set_latency_range (*it, true, lr); } - for (std::vector<DummyMidiPort*>::const_iterator it = _system_midi_out.begin (); it != _system_midi_out.end (); ++it) { + for (std::vector<BackendPort*>::const_iterator it = _system_midi_out.begin (); it != _system_midi_out.end (); ++it) { set_latency_range (*it, true, lr); } @@ -441,21 +443,7 @@ DummyAudioBackend::_start (bool /*for_latency_measurement*/) return BackendReinitializationError; } - if (_ports.size () || _portmap.size ()) { - PBD::warning << _("DummyAudioBackend: recovering from unclean shutdown, port registry is not empty.") << endmsg; - for (PortIndex::const_iterator it = _ports.begin (); it != _ports.end (); ++it) { - PBD::info << _("DummyAudioBackend: port '") << (*it)->name () << "' exists." << endmsg; - } - for (PortMap::const_iterator it = _portmap.begin (); it != _portmap.end (); ++it) { - PBD::info << _("DummyAudioBackend: portmap '") << (*it).first << "' exists." << endmsg; - } - _system_inputs.clear(); - _system_outputs.clear(); - _system_midi_in.clear(); - _system_midi_out.clear(); - _ports.clear(); - _portmap.clear(); - } + clear_ports (); if (register_system_ports()) { PBD::error << _("DummyAudioBackend: failed to register system ports.") << endmsg; @@ -643,195 +631,6 @@ DummyAudioBackend::my_name () const return _instance_name; } -uint32_t -DummyAudioBackend::port_name_size () const -{ - return 256; -} - -int -DummyAudioBackend::set_port_name (PortEngine::PortHandle port, const std::string& name) -{ - std::string newname (_instance_name + ":" + name); - - if (!valid_port (port)) { - PBD::error << _("DummyBackend::set_port_name: Invalid Port(s)") << endmsg; - return -1; - } - - if (find_port (newname)) { - PBD::error << _("DummyBackend::set_port_name: Port with given name already exists") << endmsg; - return -1; - } - - DummyPort* p = static_cast<DummyPort*>(port); - _portmap.erase (p->name()); - _portmap.insert (make_pair (newname, p)); - return p->set_name (newname); -} - -std::string -DummyAudioBackend::get_port_name (PortEngine::PortHandle port) const -{ - if (!valid_port (port)) { - PBD::error << _("DummyBackend::get_port_name: Invalid Port(s)") << endmsg; - return std::string (); - } - return static_cast<DummyPort*>(port)->name (); -} - -PortFlags -DummyAudioBackend::get_port_flags (PortEngine::PortHandle port) const -{ - if (!valid_port (port)) { - PBD::error << _("DummyBackend::get_port_flags: Invalid Port(s)") << endmsg; - return PortFlags (0); - } - return static_cast<DummyPort*>(port)->flags (); -} - -int -DummyAudioBackend::get_port_property (PortHandle port, const std::string& key, std::string& value, std::string& type) const -{ - if (!valid_port (port)) { - PBD::warning << _("DummyBackend::get_port_property: Invalid Port(s)") << endmsg; - return -1; - } - if (key == "http://jackaudio.org/metadata/pretty-name") { - type = ""; - value = static_cast<DummyPort*>(port)->pretty_name (); - if (!value.empty()) { - return 0; - } - } - return -1; -} - -int -DummyAudioBackend::set_port_property (PortHandle port, const std::string& key, const std::string& value, const std::string& type) -{ - if (!valid_port (port)) { - PBD::warning << _("DummyBackend::set_port_property: Invalid Port(s)") << endmsg; - return -1; - } - if (key == "http://jackaudio.org/metadata/pretty-name" && type.empty ()) { - static_cast<DummyPort*>(port)->set_pretty_name (value); - return 0; - } - return -1; -} - -PortEngine::PortHandle -DummyAudioBackend::get_port_by_name (const std::string& name) const -{ - PortHandle port = (PortHandle) find_port (name); - return port; -} - -int -DummyAudioBackend::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) { - DummyPort* 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 -DummyAudioBackend::port_data_type (PortEngine::PortHandle port) const -{ - if (!valid_port (port)) { - return DataType::NIL; - } - return static_cast<DummyPort*>(port)->type (); -} - -PortEngine::PortHandle -DummyAudioBackend::register_port ( - const std::string& name, - ARDOUR::DataType type, - ARDOUR::PortFlags flags) -{ - if (name.size () == 0) { return 0; } - if (flags & IsPhysical) { return 0; } - if (!_running) { - PBD::info << _("DummyBackend::register_port: Engine is not running.") << endmsg; - } - return add_port (_instance_name + ":" + name, type, flags); -} - -PortEngine::PortHandle -DummyAudioBackend::add_port ( - const std::string& name, - ARDOUR::DataType type, - ARDOUR::PortFlags flags) -{ - assert(name.size ()); - if (find_port (name)) { - PBD::error << _("DummyBackend::register_port: Port already exists:") - << " (" << name << ")" << endmsg; - return 0; - } - DummyPort* port = NULL; - switch (type) { - case DataType::AUDIO: - port = new DummyAudioPort (*this, name, flags); - break; - case DataType::MIDI: - port = new DummyMidiPort (*this, name, flags); - break; - default: - PBD::error << _("DummyBackend::register_port: Invalid Data Type.") << endmsg; - return 0; - } - - _ports.insert (port); - _portmap.insert (make_pair (name, port)); - - return port; -} - -void -DummyAudioBackend::unregister_port (PortEngine::PortHandle port_handle) -{ - if (!_running) { - PBD::info << _("DummyBackend::unregister_port: Engine is not running.") << endmsg; - assert (!valid_port (port_handle)); - return; - } - DummyPort* port = static_cast<DummyPort*>(port_handle); - PortIndex::iterator i = std::find (_ports.begin(), _ports.end(), static_cast<DummyPort*>(port_handle)); - if (i == _ports.end ()) { - PBD::error << _("DummyBackend::unregister_port: Failed to find port") << endmsg; - return; - } - disconnect_all(port_handle); - _portmap.erase (port->name()); - _ports.erase (i); - delete port; -} - int DummyAudioBackend::register_system_ports() { @@ -957,163 +756,41 @@ DummyAudioBackend::register_system_ports() } void -DummyAudioBackend::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++; - DummyPort* port = *cur; - if (! system_only || (port->is_physical () && port->is_terminal ())) { - port->disconnect_all (); - _portmap.erase (port->name()); - delete port; - _ports.erase (cur); - } - } -} - -void DummyAudioBackend::update_system_port_latecies () { - for (std::vector<DummyAudioPort*>::const_iterator it = _system_inputs.begin (); it != _system_inputs.end (); ++it) { + for (std::vector<BackendPort*>::const_iterator it = _system_inputs.begin (); it != _system_inputs.end (); ++it) { (*it)->update_connected_latency (true); } - for (std::vector<DummyAudioPort*>::const_iterator it = _system_outputs.begin (); it != _system_outputs.end (); ++it) { + for (std::vector<BackendPort*>::const_iterator it = _system_outputs.begin (); it != _system_outputs.end (); ++it) { (*it)->update_connected_latency (false); } - for (std::vector<DummyMidiPort*>::const_iterator it = _system_midi_in.begin (); it != _system_midi_in.end (); ++it) { + for (std::vector<BackendPort*>::const_iterator it = _system_midi_in.begin (); it != _system_midi_in.end (); ++it) { (*it)->update_connected_latency (true); } - for (std::vector<DummyMidiPort*>::const_iterator it = _system_midi_out.begin (); it != _system_midi_out.end (); ++it) { + for (std::vector<BackendPort*>::const_iterator it = _system_midi_out.begin (); it != _system_midi_out.end (); ++it) { (*it)->update_connected_latency (false); } } -int -DummyAudioBackend::connect (const std::string& src, const std::string& dst) -{ - DummyPort* src_port = find_port (src); - DummyPort* dst_port = find_port (dst); - - if (!src_port) { - PBD::error << _("DummyBackend::connect: Invalid Source port:") - << " (" << src <<")" << endmsg; - return -1; - } - if (!dst_port) { - PBD::error << _("DummyBackend::connect: Invalid Destination port:") - << " (" << dst <<")" << endmsg; - return -1; - } - return src_port->connect (dst_port); -} - -int -DummyAudioBackend::disconnect (const std::string& src, const std::string& dst) -{ - DummyPort* src_port = find_port (src); - DummyPort* dst_port = find_port (dst); - - if (!src_port || !dst_port) { - PBD::error << _("DummyBackend::disconnect: Invalid Port(s)") << endmsg; - return -1; - } - return src_port->disconnect (dst_port); -} - -int -DummyAudioBackend::connect (PortEngine::PortHandle src, const std::string& dst) -{ - DummyPort* dst_port = find_port (dst); - if (!valid_port (src)) { - PBD::error << _("DummyBackend::connect: Invalid Source Port Handle") << endmsg; - return -1; - } - if (!dst_port) { - PBD::error << _("DummyBackend::connect: Invalid Destination Port") - << " (" << dst << ")" << endmsg; - return -1; - } - return static_cast<DummyPort*>(src)->connect (dst_port); -} - -int -DummyAudioBackend::disconnect (PortEngine::PortHandle src, const std::string& dst) -{ - DummyPort* dst_port = find_port (dst); - if (!valid_port (src) || !dst_port) { - PBD::error << _("DummyBackend::disconnect: Invalid Port(s)") << endmsg; - return -1; - } - return static_cast<DummyPort*>(src)->disconnect (dst_port); -} - -int -DummyAudioBackend::disconnect_all (PortEngine::PortHandle port) -{ - if (!valid_port (port)) { - PBD::error << _("DummyBackend::disconnect_all: Invalid Port") << endmsg; - return -1; - } - static_cast<DummyPort*>(port)->disconnect_all (); - return 0; -} - -bool -DummyAudioBackend::connected (PortEngine::PortHandle port, bool /* process_callback_safe*/) -{ - if (!valid_port (port)) { - PBD::error << _("DummyBackend::disconnect_all: Invalid Port") << endmsg; - return false; - } - return static_cast<DummyPort*>(port)->is_connected (); -} - -bool -DummyAudioBackend::connected_to (PortEngine::PortHandle src, const std::string& dst, bool /*process_callback_safe*/) -{ - DummyPort* dst_port = find_port (dst); -#ifndef NDEBUG - if (!valid_port (src) || !dst_port) { - PBD::error << _("DummyBackend::connected_to: Invalid Port") << endmsg; - return false; - } -#endif - return static_cast<DummyPort*>(src)->is_connected (dst_port); -} - -bool -DummyAudioBackend::physically_connected (PortEngine::PortHandle port, bool /*process_callback_safe*/) +BackendPort* +DummyAudioBackend::port_factory (std::string const & name, ARDOUR::DataType type, ARDOUR::PortFlags flags) { - if (!valid_port (port)) { - PBD::error << _("DummyBackend::physically_connected: Invalid Port") << endmsg; - return false; - } - return static_cast<DummyPort*>(port)->is_physically_connected (); -} - -int -DummyAudioBackend::get_connections (PortEngine::PortHandle port, std::vector<std::string>& names, bool /*process_callback_safe*/) -{ - if (!valid_port (port)) { - PBD::error << _("DummyBackend::get_connections: Invalid Port") << endmsg; - return -1; - } - - assert (0 == names.size ()); + BackendPort* port = 0; - const std::set<DummyPort*>& connected_ports = static_cast<DummyPort*>(port)->get_connections (); - - for (std::set<DummyPort*>::const_iterator i = connected_ports.begin (); i != connected_ports.end (); ++i) { - names.push_back ((*i)->name ()); + switch (type) { + case DataType::AUDIO: + port = new DummyAudioPort (*this, name, flags); + break; + case DataType::MIDI: + port = new DummyMidiPort (*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 */ @@ -1243,82 +920,6 @@ DummyAudioBackend::get_latency_range (PortEngine::PortHandle port, bool for_play return r; } -/* Discovering physical ports */ - -bool -DummyAudioBackend::port_is_physical (PortEngine::PortHandle port) const -{ - if (!valid_port (port)) { - PBD::error << _("DummyPort::port_is_physical (): invalid port.") << endmsg; - return false; - } - return static_cast<DummyPort*>(port)->is_physical (); -} - -void -DummyAudioBackend::get_physical_outputs (DataType type, std::vector<std::string>& port_names) -{ - for (PortIndex::iterator i = _ports.begin (); i != _ports.end (); ++i) { - DummyPort* port = *i; - if ((port->type () == type) && port->is_input () && port->is_physical ()) { - port_names.push_back (port->name ()); - } - } -} - -void -DummyAudioBackend::get_physical_inputs (DataType type, std::vector<std::string>& port_names) -{ - for (PortIndex::iterator i = _ports.begin (); i != _ports.end (); ++i) { - DummyPort* port = *i; - if ((port->type () == type) && port->is_output () && port->is_physical ()) { - port_names.push_back (port->name ()); - } - } -} - -ChanCount -DummyAudioBackend::n_physical_outputs () const -{ - int n_midi = 0; - int n_audio = 0; - for (PortIndex::const_iterator i = _ports.begin (); i != _ports.end (); ++i) { - DummyPort* port = *i; - if (port->is_output () && port->is_physical ()) { - switch (port->type ()) { - case DataType::AUDIO: ++n_audio; break; - case DataType::MIDI: ++n_midi; break; - default: break; - } - } - } - ChanCount cc; - cc.set (DataType::AUDIO, n_audio); - cc.set (DataType::MIDI, n_midi); - return cc; -} - -ChanCount -DummyAudioBackend::n_physical_inputs () const -{ - int n_midi = 0; - int n_audio = 0; - for (PortIndex::const_iterator i = _ports.begin (); i != _ports.end (); ++i) { - DummyPort* port = *i; - if (port->is_input () && port->is_physical ()) { - switch (port->type ()) { - case DataType::AUDIO: ++n_audio; break; - case DataType::MIDI: ++n_midi; break; - default: break; - } - } - } - ChanCount cc; - cc.set (DataType::AUDIO, n_audio); - cc.set (DataType::MIDI, n_midi); - return cc; -} - /* Getting access to the data buffer for a port */ void* @@ -1351,11 +952,11 @@ DummyAudioBackend::main_process_thread () } // re-set input buffers, generate on demand. - for (std::vector<DummyAudioPort*>::const_iterator it = _system_inputs.begin (); it != _system_inputs.end (); ++it) { - (*it)->next_period(); + for (std::vector<BackendPort*>::const_iterator it = _system_inputs.begin (); it != _system_inputs.end (); ++it) { + static_cast<DummyPort*>(*it)->next_period(); } - for (std::vector<DummyMidiPort*>::const_iterator it = _system_midi_in.begin (); it != _system_midi_in.end (); ++it) { - (*it)->next_period(); + for (std::vector<BackendPort*>::const_iterator it = _system_midi_in.begin (); it != _system_midi_in.end (); ++it) { + static_cast<DummyPort*>(*it)->next_period(); } if (engine.process_callback (samples_per_period)) { @@ -1366,28 +967,28 @@ DummyAudioBackend::main_process_thread () if (_device == _("Loopback") && _midi_mode != MidiToAudio) { int opn = 0; int opc = _system_outputs.size(); - for (std::vector<DummyAudioPort*>::const_iterator it = _system_inputs.begin (); it != _system_inputs.end (); ++it, ++opn) { - DummyAudioPort* op = _system_outputs[(opn % opc)]; - (*it)->fill_wavetable ((const float*)op->get_buffer (samples_per_period), samples_per_period); + for (std::vector<BackendPort*>::const_iterator it = _system_inputs.begin (); it != _system_inputs.end (); ++it, ++opn) { + DummyAudioPort* op = static_cast<DummyAudioPort*> (_system_outputs[(opn % opc)]); + static_cast<DummyAudioPort*>(*it)->fill_wavetable ((const float*)op->get_buffer (samples_per_period), samples_per_period); } } if (_midi_mode == MidiLoopback) { int opn = 0; int opc = _system_midi_out.size(); - for (std::vector<DummyMidiPort*>::const_iterator it = _system_midi_in.begin (); it != _system_midi_in.end (); ++it, ++opn) { - DummyMidiPort* op = _system_midi_out[(opn % opc)]; + for (std::vector<BackendPort*>::const_iterator it = _system_midi_in.begin (); it != _system_midi_in.end (); ++it, ++opn) { + DummyMidiPort* op = static_cast<DummyMidiPort*> (_system_midi_out[(opn % opc)]); op->get_buffer(0); // mix-down - (*it)->set_loopback (op->const_buffer()); + static_cast<DummyMidiPort*>(*it)->set_loopback (op->const_buffer()); } } else if (_midi_mode == MidiToAudio) { int opn = 0; int opc = _system_midi_out.size(); - for (std::vector<DummyAudioPort*>::const_iterator it = _system_inputs.begin (); it != _system_inputs.end (); ++it, ++opn) { - DummyMidiPort* op = _system_midi_out[(opn % opc)]; + for (std::vector<BackendPort*>::const_iterator it = _system_inputs.begin (); it != _system_inputs.end (); ++it, ++opn) { + DummyMidiPort* op = static_cast<DummyMidiPort*> (_system_midi_out[(opn % opc)]); op->get_buffer(0); // mix-down - (*it)->midi_to_wavetable (op->const_buffer(), samples_per_period); + static_cast<DummyAudioPort*>(*it)->midi_to_wavetable (op->const_buffer(), samples_per_period); } } @@ -1515,158 +1116,17 @@ extern "C" ARDOURBACKEND_API ARDOUR::AudioBackendInfo* descriptor () /******************************************************************************/ DummyPort::DummyPort (DummyAudioBackend &b, const std::string& name, PortFlags flags) - : _dummy_backend (b) - , _name (name) - , _flags (flags) + : BackendPort (b, name, flags) , _rseed (0) , _gen_cycle (false) + , _engine (b) { - _capture_latency_range.min = 0; - _capture_latency_range.max = 0; - _playback_latency_range.min = 0; - _playback_latency_range.max = 0; - _dummy_backend.port_connect_add_remove_callback(); + _backend.port_connect_add_remove_callback(); } -DummyPort::~DummyPort () { - disconnect_all (); - _dummy_backend.port_connect_add_remove_callback(); -} - - -int DummyPort::connect (DummyPort *port) -{ - if (!port) { - PBD::error << _("DummyPort::connect (): invalid (null) port") << endmsg; - return -1; - } - - if (type () != port->type ()) { - PBD::error << _("DummyPort::connect (): wrong port-type") << endmsg; - return -1; - } - - if (is_output () && port->is_output ()) { - PBD::error << _("DummyPort::connect (): cannot inter-connect output ports.") << endmsg; - return -1; - } - - if (is_input () && port->is_input ()) { - PBD::error << _("DummyPort::connect (): cannot inter-connect input ports.") << endmsg; - return -1; - } - - if (this == port) { - PBD::error << _("DummyPort::connect (): cannot self-connect ports.") << endmsg; - return -1; - } - - if (is_connected (port)) { -#if 0 // don't bother to warn about this for now. just ignore it - PBD::error << _("DummyPort::connect (): ports are already connected:") - << " (" << name () << ") -> (" << port->name () << ")" - << endmsg; -#endif - return -1; - } - - _connect (port, true); - return 0; -} - - -void DummyPort::_connect (DummyPort *port, bool callback) -{ - _connections.insert (port); - if (callback) { - port->_connect (this, false); - _dummy_backend.port_connect_callback (name(), port->name(), true); - } -} - -int DummyPort::disconnect (DummyPort *port) -{ - if (!port) { - PBD::error << _("DummyPort::disconnect (): invalid (null) port") << endmsg; - return -1; - } - - if (!is_connected (port)) { - PBD::error << _("DummyPort::disconnect (): ports are not connected:") - << " (" << name () << ") -> (" << port->name () << ")" - << endmsg; - return -1; - } - _disconnect (port, true); - return 0; -} - -void DummyPort::_disconnect (DummyPort *port, bool callback) -{ - std::set<DummyPort*>::iterator it = _connections.find (port); - assert (it != _connections.end ()); - _connections.erase (it); - if (callback) { - port->_disconnect (this, false); - _dummy_backend.port_connect_callback (name(), port->name(), false); - } -} - - -void DummyPort::disconnect_all () -{ - while (!_connections.empty ()) { - std::set<DummyPort*>::iterator it = _connections.begin (); - (*it)->_disconnect (this, false); - _dummy_backend.port_connect_callback (name(), (*it)->name(), false); - _connections.erase (it); - } -} - -bool -DummyPort::is_connected (const DummyPort *port) const -{ - return _connections.find (const_cast<DummyPort *>(port)) != _connections.end (); -} - -bool DummyPort::is_physically_connected () const -{ - for (std::set<DummyPort*>::const_iterator it = _connections.begin (); it != _connections.end (); ++it) { - if ((*it)->is_physical ()) { - return true; - } - } - return false; -} - -void -DummyPort::set_latency_range (const LatencyRange &latency_range, bool for_playback) -{ - if (for_playback) { - _playback_latency_range = latency_range; - } else { - _capture_latency_range = latency_range; - } - - for (std::set<DummyPort*>::const_iterator it = _connections.begin (); it != _connections.end (); ++it) { - if ((*it)->is_physical ()) { - (*it)->update_connected_latency (is_input ()); - } - } -} - -void -DummyPort::update_connected_latency (bool for_playback) +DummyPort::~DummyPort () { - LatencyRange lr; - lr.min = lr.max = 0; - for (std::set<DummyPort*>::const_iterator it = _connections.begin (); it != _connections.end (); ++it) { - LatencyRange l; - l = (*it)->latency_range (for_playback); - lr.min = std::max (lr.min, l.min); - lr.max = std::max (lr.max, l.max); - } - set_latency_range (lr, for_playback); + _backend.port_connect_add_remove_callback(); } void DummyPort::setup_random_number_generator () @@ -1712,8 +1172,8 @@ DummyPort::randf () pframes_t DummyPort::pulse_position () const { - samplecnt_t sr = _dummy_backend.sample_rate (); - samplepos_t st = _dummy_backend.sample_time_at_cycle_start(); + samplecnt_t sr = _engine.sample_rate (); + samplepos_t st = _engine.sample_time_at_cycle_start(); return (sr - (st % sr)) % sr; } @@ -2165,8 +1625,8 @@ void DummyAudioPort::generate (const pframes_t n_samples) void* DummyAudioPort::get_buffer (pframes_t n_samples) { if (is_input ()) { - const std::set<DummyPort *>& connections = get_connections (); - std::set<DummyPort*>::const_iterator it = connections.begin (); + const std::set<BackendPort *>& connections = get_connections (); + std::set<BackendPort*>::const_iterator it = connections.begin (); if (it == connections.end ()) { memset (_buffer, 0, n_samples * sizeof (Sample)); } else { @@ -2301,8 +1761,8 @@ void* DummyMidiPort::get_buffer (pframes_t n_samples) { if (is_input ()) { _buffer.clear (); - const std::set<DummyPort*>& connections = get_connections (); - for (std::set<DummyPort*>::const_iterator i = connections.begin (); + const std::set<BackendPort*>& connections = get_connections (); + for (std::set<BackendPort*>::const_iterator i = connections.begin (); i != connections.end (); ++i) { DummyMidiPort * source = static_cast<DummyMidiPort*>(*i); diff --git a/libs/backends/dummy/dummy_audiobackend.h b/libs/backends/dummy/dummy_audiobackend.h index d502f35c30..843debcccf 100644 --- a/libs/backends/dummy/dummy_audiobackend.h +++ b/libs/backends/dummy/dummy_audiobackend.h @@ -37,6 +37,7 @@ #include "ardour/types.h" #include "ardour/audio_backend.h" #include "ardour/dsp_load_calculator.h" +#include "ardour/port_engine_shared.h" namespace ARDOUR { @@ -69,59 +70,14 @@ class DummyMidiEvent { typedef std::vector<boost::shared_ptr<DummyMidiEvent> > DummyMidiBuffer; -class DummyPort { +class DummyPort : public BackendPort { protected: DummyPort (DummyAudioBackend &b, const std::string&, PortFlags); public: virtual ~DummyPort (); - 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; - - bool is_input () const { return flags () & IsInput; } - bool is_output () const { return flags () & IsOutput; } - bool is_physical () const { return flags () & IsPhysical; } - bool is_terminal () const { return flags () & IsTerminal; } - bool is_connected () const { return _connections.size () != 0; } - bool is_connected (const DummyPort *port) const; - bool is_physically_connected () const; - - const std::set<DummyPort *>& get_connections () const { return _connections; } - - int connect (DummyPort *port); - int disconnect (DummyPort *port); - void disconnect_all (); - - virtual void* get_buffer (pframes_t nframes) = 0; void next_period () { _gen_cycle = false; } - const LatencyRange latency_range (bool for_playback) const - { - return for_playback ? _playback_latency_range : _capture_latency_range; - } - - void set_latency_range (const LatencyRange &latency_range, bool for_playback); - - void update_connected_latency (bool for_playback); - - private: - DummyAudioBackend &_dummy_backend; - std::string _name; - std::string _pretty_name; - const PortFlags _flags; - LatencyRange _capture_latency_range; - LatencyRange _playback_latency_range; - std::set<DummyPort*> _connections; - - void _connect (DummyPort* , bool); - void _disconnect (DummyPort* , bool); - protected: /* random number generator */ void setup_random_number_generator (); @@ -135,6 +91,9 @@ class DummyPort { volatile bool _gen_cycle; Glib::Threads::Mutex generator_lock; + private: + AudioBackend& _engine; + }; // class DummyPort class DummyAudioPort : public DummyPort { @@ -227,7 +186,7 @@ class DummyMidiPort : public DummyPort { DummyMidiData::MIDISequence const * _midi_seq_dat; }; // class DummyMidiPort -class DummyAudioBackend : public AudioBackend { +class DummyAudioBackend : public AudioBackend, public PortEngineSharedImpl { friend class DummyPort; public: DummyAudioBackend (AudioEngine& e, AudioBackendInfo& info); @@ -326,33 +285,35 @@ class DummyAudioBackend : public AudioBackend { void* private_handle () const; const std::string& my_name () const; - uint32_t port_name_size () const; - - int set_port_name (PortHandle, const std::string&); - std::string get_port_name (PortHandle) const; - PortFlags get_port_flags (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 set_port_property (PortHandle, const std::string& key, const std::string& value, const std::string& type); - - int get_ports (const std::string& port_name_pattern, DataType type, PortFlags flags, std::vector<std::string>&) const; - DataType port_data_type (PortHandle) const; + /* PortEngine API - forwarded to PortEngineSharedImpl */ + + bool port_is_physical (PortEngine::PortHandle ph) const { return PortEngineSharedImpl::port_is_physical (ph); } + void get_physical_outputs (DataType type, std::vector<std::string>& results) { PortEngineSharedImpl::get_physical_outputs (type, results); } + void get_physical_inputs (DataType type, std::vector<std::string>& results) { PortEngineSharedImpl::get_physical_inputs (type, results); } + ChanCount n_physical_outputs () const { return PortEngineSharedImpl::n_physical_outputs (); } + ChanCount n_physical_inputs () const { return PortEngineSharedImpl::n_physical_inputs (); } + uint32_t port_name_size () const { return PortEngineSharedImpl::port_name_size(); } + int set_port_name (PortEngine::PortHandle ph, const std::string& name) { return PortEngineSharedImpl::set_port_name (ph, name); } + std::string get_port_name (PortEngine::PortHandle ph) const { return PortEngineSharedImpl::get_port_name (ph); } + PortFlags get_port_flags (PortEngine::PortHandle ph) const { return PortEngineSharedImpl::get_port_flags (ph); } + PortEngine::PortHandle get_port_by_name (std::string const & name) const { return PortEngineSharedImpl::get_port_by_name (name); } + int get_port_property (PortEngine::PortHandle ph, const std::string& key, std::string& value, std::string& type) const { return PortEngineSharedImpl::get_port_property (ph, key, value, type); } + int set_port_property (PortEngine::PortHandle ph, const std::string& key, const std::string& value, const std::string& type) { return PortEngineSharedImpl::set_port_property (ph, key, value, type); } + int get_ports (const std::string& port_name_pattern, DataType type, PortFlags flags, std::vector<std::string>& results) const { return PortEngineSharedImpl::get_ports (port_name_pattern, type, flags, results); } + DataType port_data_type (PortEngine::PortHandle ph) const { return PortEngineSharedImpl::port_data_type (ph); } + PortEngine::PortHandle register_port (const std::string& shortname, ARDOUR::DataType type, ARDOUR::PortFlags flags) { return PortEngineSharedImpl::register_port (shortname, type, flags); } + void unregister_port (PortHandle ph) { if (!_running) return; PortEngineSharedImpl::unregister_port (ph); } + int connect (const std::string& src, const std::string& dst) { return PortEngineSharedImpl::connect (src, dst); } + int disconnect (const std::string& src, const std::string& dst) { return PortEngineSharedImpl::disconnect (src, dst); } + int connect (PortEngine::PortHandle ph, const std::string& other) { return PortEngineSharedImpl::connect (ph, other); } + int disconnect (PortEngine::PortHandle ph, const std::string& other) { return PortEngineSharedImpl::disconnect (ph, other); } + int disconnect_all (PortEngine::PortHandle ph) { return PortEngineSharedImpl::disconnect_all (ph); } + bool connected (PortEngine::PortHandle ph, bool process_callback_safe) { return PortEngineSharedImpl::connected (ph, process_callback_safe); } + bool connected_to (PortEngine::PortHandle ph, const std::string& other, bool process_callback_safe) { return PortEngineSharedImpl::connected_to (ph, other, process_callback_safe); } + bool physically_connected (PortEngine::PortHandle ph, bool process_callback_safe) { return PortEngineSharedImpl::physically_connected (ph, process_callback_safe); } + int get_connections (PortEngine::PortHandle ph, std::vector<std::string>& results, bool process_callback_safe) { return PortEngineSharedImpl::get_connections (ph, results, process_callback_safe); } - PortHandle register_port (const std::string& shortname, ARDOUR::DataType, ARDOUR::PortFlags); - void unregister_port (PortHandle); - - int connect (const std::string& src, const std::string& dst); - int disconnect (const std::string& src, const std::string& dst); - int connect (PortHandle, const std::string&); - int disconnect (PortHandle, const std::string&); - int disconnect_all (PortHandle); - - bool connected (PortHandle, bool process_callback_safe); - bool connected_to (PortHandle, const std::string&, bool process_callback_safe); - bool physically_connected (PortHandle, bool process_callback_safe); - int get_connections (PortHandle, std::vector<std::string>&, bool process_callback_safe); /* MIDI */ int midi_event_get (pframes_t& timestamp, size_t& size, uint8_t const** buf, void* port_buffer, uint32_t event_index); @@ -372,14 +333,6 @@ class DummyAudioBackend : public AudioBackend { void set_latency_range (PortHandle, bool for_playback, LatencyRange); LatencyRange get_latency_range (PortHandle, bool for_playback); - /* Discovering physical ports */ - - bool port_is_physical (PortHandle) const; - void get_physical_outputs (DataType type, std::vector<std::string>&); - void get_physical_inputs (DataType type, std::vector<std::string>&); - ChanCount n_physical_outputs () const; - ChanCount n_physical_inputs () const; - /* Getting access to the data buffer for a port */ void* get_buffer (PortHandle, pframes_t); @@ -449,28 +402,9 @@ class DummyAudioBackend : public AudioBackend { }; /* port engine */ - PortHandle add_port (const std::string& shortname, ARDOUR::DataType, ARDOUR::PortFlags); int register_system_ports (); - void unregister_ports (bool system_only = false); void update_system_port_latecies (); - std::vector<DummyAudioPort *> _system_inputs; - std::vector<DummyAudioPort *> _system_outputs; - std::vector<DummyMidiPort *> _system_midi_in; - std::vector<DummyMidiPort *> _system_midi_out; - - struct SortByPortName - { - bool operator ()(const DummyPort* lhs, const DummyPort* rhs) const - { - return PBD::naturally_less (lhs->name ().c_str (), rhs->name ().c_str ()); - } - }; - - typedef std::map<std::string, DummyPort *> PortMap; // fast lookup in _ports - typedef std::set<DummyPort *, SortByPortName> PortIndex; // fast lookup in _ports - PortMap _portmap; - PortIndex _ports; struct PortConnectData { std::string a; @@ -497,17 +431,7 @@ class DummyAudioBackend : public AudioBackend { pthread_mutex_unlock (&_port_callback_mutex); } - bool valid_port (PortHandle port) const { - return std::find (_ports.begin(), _ports.end(), static_cast<DummyPort*>(port)) != _ports.end (); - } - - DummyPort* find_port (const std::string& port_name) const { - PortMap::const_iterator it = _portmap.find (port_name); - if (it == _portmap.end()) { - return NULL; - } - return (*it).second; - } + BackendPort* port_factory (std::string const & name, ARDOUR::DataType type, ARDOUR::PortFlags); }; // class DummyAudioBackend |