2 * Copyright (C) 2014 Robin Gareus <robin@gareus.org>
3 * Copyright (C) 2013 Paul Davis
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "dummy_audiobackend.h"
24 #include "pbd/error.h"
27 using namespace ARDOUR;
29 static std::string s_instance_name;
30 size_t DummyAudioBackend::_max_buffer_size = 8192;
32 DummyAudioBackend::DummyAudioBackend (AudioEngine& e)
35 , _freewheeling (false)
37 , _samples_per_period (1024)
41 , _systemic_input_latency (0)
42 , _systemic_output_latency (0)
43 , _processed_samples (0)
45 _instance_name = s_instance_name;
48 DummyAudioBackend::~DummyAudioBackend ()
52 /* AUDIOBACKEND API */
55 DummyAudioBackend::name () const
61 DummyAudioBackend::is_realtime () const
66 std::vector<AudioBackend::DeviceStatus>
67 DummyAudioBackend::enumerate_devices () const
69 std::vector<AudioBackend::DeviceStatus> s;
70 s.push_back (DeviceStatus (_("Dummy"), true));
75 DummyAudioBackend::available_sample_rates (const std::string&) const
77 std::vector<float> sr;
78 sr.push_back (8000.0);
79 sr.push_back (22050.0);
80 sr.push_back (24000.0);
81 sr.push_back (44100.0);
82 sr.push_back (48000.0);
83 sr.push_back (88200.0);
84 sr.push_back (96000.0);
85 sr.push_back (176400.0);
86 sr.push_back (192000.0);
91 DummyAudioBackend::available_buffer_sizes (const std::string&) const
93 std::vector<uint32_t> bs;
110 DummyAudioBackend::available_input_channel_count (const std::string&) const
116 DummyAudioBackend::available_output_channel_count (const std::string&) const
122 DummyAudioBackend::can_change_sample_rate_when_running () const
128 DummyAudioBackend::can_change_buffer_size_when_running () const
134 DummyAudioBackend::set_device_name (const std::string&)
140 DummyAudioBackend::set_sample_rate (float sr)
142 if (sr <= 0) { return -1; }
144 engine.sample_rate_change (sr);
149 DummyAudioBackend::set_buffer_size (uint32_t bs)
151 if (bs <= 0 || bs >= _max_buffer_size) {
154 _samples_per_period = bs;
155 engine.buffer_size_change (bs);
160 DummyAudioBackend::set_interleaved (bool yn)
162 if (!yn) { return 0; }
167 DummyAudioBackend::set_input_channels (uint32_t cc)
174 DummyAudioBackend::set_output_channels (uint32_t cc)
181 DummyAudioBackend::set_systemic_input_latency (uint32_t sl)
183 _systemic_input_latency = sl;
188 DummyAudioBackend::set_systemic_output_latency (uint32_t sl)
190 _systemic_output_latency = sl;
194 /* Retrieving parameters */
196 DummyAudioBackend::device_name () const
198 return _("Dummy Device");
202 DummyAudioBackend::sample_rate () const
208 DummyAudioBackend::buffer_size () const
210 return _samples_per_period;
214 DummyAudioBackend::interleaved () const
220 DummyAudioBackend::input_channels () const
226 DummyAudioBackend::output_channels () const
232 DummyAudioBackend::systemic_input_latency () const
234 return _systemic_input_latency;
238 DummyAudioBackend::systemic_output_latency () const
240 return _systemic_output_latency;
244 std::vector<std::string>
245 DummyAudioBackend::enumerate_midi_options () const
247 std::vector<std::string> m;
248 m.push_back (_("None"));
253 DummyAudioBackend::set_midi_option (const std::string&)
259 DummyAudioBackend::midi_option () const
266 static void * pthread_process (void *arg)
268 DummyAudioBackend *d = static_cast<DummyAudioBackend *>(arg);
269 d->main_process_thread ();
275 DummyAudioBackend::_start (bool /*for_latency_measurement*/)
278 PBD::error << _("DummyAudioBackend: already active.") << endmsg;
283 PBD::warning << _("DummyAudioBackend: recovering from unclean shutdown, port registry is not empty.") << endmsg;
287 if (register_system_ports()) {
288 PBD::error << _("DummyAudioBackend: failed to register system ports.") << endmsg;
292 if (engine.reestablish_ports ()) {
293 PBD::error << _("DummyAudioBackend: Could not re-establish ports.") << endmsg;
298 engine.reconnect_ports ();
300 if (pthread_create (&_main_thread, NULL, pthread_process, this)) {
301 PBD::error << _("DummyAudioBackend: cannot start.") << endmsg;
305 while (!_running && --timeout > 0) { usleep (1000); }
307 if (timeout == 0 || !_running) {
308 PBD::error << _("DummyAudioBackend: failed to start process thread.") << endmsg;
316 DummyAudioBackend::stop ()
324 if (pthread_join (_main_thread, &status)) {
325 PBD::error << _("DummyAudioBackend: failed to terminate.") << endmsg;
328 unregister_system_ports();
333 DummyAudioBackend::freewheel (bool onoff)
335 if (onoff == _freewheeling) {
338 _freewheeling = onoff;
339 engine.freewheel_callback (onoff);
344 DummyAudioBackend::dsp_load () const
346 return 100.f * _dsp_load;
350 DummyAudioBackend::raw_buffer_size (DataType t)
353 case DataType::AUDIO:
354 return _max_buffer_size * sizeof(Sample);
356 return _max_buffer_size; // XXX not really limited
363 DummyAudioBackend::sample_time ()
365 return _processed_samples;
369 DummyAudioBackend::sample_time_at_cycle_start ()
371 return _processed_samples;
375 DummyAudioBackend::samples_since_cycle_start ()
382 DummyAudioBackend::dummy_process_thread (void *arg)
384 ThreadData* td = reinterpret_cast<ThreadData*> (arg);
385 boost::function<void ()> f = td->f;
392 DummyAudioBackend::create_process_thread (boost::function<void()> func)
396 size_t stacksize = 100000;
398 pthread_attr_init (&attr);
399 pthread_attr_setstacksize (&attr, stacksize);
400 ThreadData* td = new ThreadData (this, func, stacksize);
402 if (pthread_create (&thread_id, &attr, dummy_process_thread, td)) {
403 PBD::error << _("AudioEngine: cannot create process thread.") << endmsg;
407 _threads.push_back (thread_id);
412 DummyAudioBackend::join_process_threads ()
416 for (std::vector<pthread_t>::const_iterator i = _threads.begin (); i != _threads.end (); ++i)
419 if (pthread_join (*i, &status)) {
420 PBD::error << _("AudioEngine: cannot terminate process thread.") << endmsg;
429 DummyAudioBackend::in_process_thread ()
431 for (std::vector<pthread_t>::const_iterator i = _threads.begin (); i != _threads.end (); ++i)
433 #ifdef COMPILER_MINGW
434 if (*i == GetCurrentThread ()) {
438 if (pthread_equal (*i, pthread_self ()) != 0) {
447 DummyAudioBackend::process_thread_count ()
449 return _threads.size ();
453 DummyAudioBackend::update_latencies ()
460 DummyAudioBackend::private_handle () const
466 DummyAudioBackend::my_name () const
468 return _instance_name;
472 DummyAudioBackend::available () const
478 DummyAudioBackend::port_name_size () const
484 DummyAudioBackend::set_port_name (PortEngine::PortHandle port, const std::string& name)
486 if (!valid_port (port)) {
487 PBD::error << _("DummyBackend::set_port_name: Invalid Port(s)") << endmsg;
490 return static_cast<DummyPort*>(port)->set_name (_instance_name + ":" + name);
494 DummyAudioBackend::get_port_name (PortEngine::PortHandle port) const
496 if (!valid_port (port)) {
497 PBD::error << _("DummyBackend::get_port_name: Invalid Port(s)") << endmsg;
498 return std::string ();
500 return static_cast<DummyPort*>(port)->name ();
503 PortEngine::PortHandle
504 DummyAudioBackend::get_port_by_name (const std::string& name) const
506 PortHandle port = (PortHandle) find_port (name);
511 DummyAudioBackend::get_ports (
512 const std::string& port_name_pattern,
513 DataType type, PortFlags flags,
514 std::vector<std::string>& port_names) const
518 bool use_regexp = false;
519 if (port_name_pattern.size () > 0) {
520 if (!regcomp (&port_regex, port_name_pattern.c_str (), REG_EXTENDED|REG_NOSUB)) {
524 for (size_t i = 0; i < _ports.size (); ++i) {
525 DummyPort* port = _ports[i];
526 if ((port->type () == type) && (port->flags () & flags)) {
527 if (!use_regexp || !regexec (&port_regex, port->name ().c_str (), 0, NULL, 0)) {
528 port_names.push_back (port->name ());
534 regfree (&port_regex);
540 DummyAudioBackend::port_data_type (PortEngine::PortHandle port) const
542 if (!valid_port (port)) {
543 return DataType::NIL;
545 return static_cast<DummyPort*>(port)->type ();
548 PortEngine::PortHandle
549 DummyAudioBackend::register_port (
550 const std::string& name,
551 ARDOUR::DataType type,
552 ARDOUR::PortFlags flags)
554 if (name.size () == 0) { return 0; }
555 if (flags & IsPhysical) { return 0; }
556 return add_port (_instance_name + ":" + name, type, flags);
559 PortEngine::PortHandle
560 DummyAudioBackend::add_port (
561 const std::string& name,
562 ARDOUR::DataType type,
563 ARDOUR::PortFlags flags)
565 assert(name.size ());
566 if (find_port (name)) {
567 PBD::error << _("DummyBackend::register_port: Port already exists:")
568 << " (" << name << ")" << endmsg;
571 DummyPort* port = NULL;
573 case DataType::AUDIO:
574 port = new DummyAudioPort (name, flags);
577 port = new DummyMidiPort (name, flags);
580 PBD::error << _("DummyBackend::register_port: Invalid Data Type.") << endmsg;
584 _ports.push_back (port);
590 DummyAudioBackend::unregister_port (PortEngine::PortHandle port_handle)
592 if (!valid_port (port_handle)) {
593 PBD::error << _("DummyBackend::unregister_port: Invalid Port.") << endmsg;
595 DummyPort* port = static_cast<DummyPort*>(port_handle);
596 std::vector<DummyPort*>::iterator i = std::find (_ports.begin (), _ports.end (), static_cast<DummyPort*>(port_handle));
597 if (i == _ports.end ()) {
598 PBD::error << _("DummyBackend::unregister_port: Failed to find port") << endmsg;
601 disconnect_all(port_handle);
607 DummyAudioBackend::register_system_ports()
611 const int a_ins = _n_inputs > 0 ? _n_inputs : 8;
612 const int a_out = _n_outputs > 0 ? _n_outputs : 8;
613 const int m_ins = 2; // TODO
617 lr.min = lr.max = _samples_per_period + _systemic_input_latency;
618 for (int i = 1; i <= a_ins; ++i) {
620 snprintf(tmp, sizeof(tmp), "system:capture_%d", i);
621 PortHandle p = add_port(std::string(tmp), DataType::AUDIO, static_cast<PortFlags>(IsOutput | IsPhysical | IsTerminal));
623 set_latency_range (p, false, lr);
626 lr.min = lr.max = _samples_per_period + _systemic_output_latency;
627 for (int i = 1; i <= a_out; ++i) {
629 snprintf(tmp, sizeof(tmp), "system:playback_%d", i);
630 PortHandle p = add_port(std::string(tmp), DataType::AUDIO, static_cast<PortFlags>(IsInput | IsPhysical | IsTerminal));
632 set_latency_range (p, false, lr);
636 lr.min = lr.max = _samples_per_period + _systemic_input_latency;
637 for (int i = 1; i <= m_ins; ++i) {
639 snprintf(tmp, sizeof(tmp), "system:midi_capture_%d", i);
640 PortHandle p = add_port(std::string(tmp), DataType::MIDI, static_cast<PortFlags>(IsOutput | IsPhysical | IsTerminal));
642 set_latency_range (p, false, lr);
645 lr.min = lr.max = _samples_per_period + _systemic_output_latency;
646 for (int i = 1; i <= m_out; ++i) {
648 snprintf(tmp, sizeof(tmp), "system:midi_playback_%d", i);
649 PortHandle p = add_port(std::string(tmp), DataType::MIDI, static_cast<PortFlags>(IsInput | IsPhysical | IsTerminal));
651 set_latency_range (p, false, lr);
658 DummyAudioBackend::unregister_system_ports()
661 while (i < _ports.size ()) {
662 DummyPort* port = _ports[i];
663 if (port->is_physical () && port->is_terminal ()) {
664 port->disconnect_all ();
665 _ports.erase (_ports.begin() + i);
673 DummyAudioBackend::connect (const std::string& src, const std::string& dst)
675 DummyPort* src_port = find_port (src);
676 DummyPort* dst_port = find_port (dst);
679 PBD::error << _("DummyBackend::connect: Invalid Source port:")
680 << " (" << src <<")" << endmsg;
684 PBD::error << _("DummyBackend::connect: Invalid Destination port:")
685 << " (" << dst <<")" << endmsg;
688 return src_port->connect (dst_port);
692 DummyAudioBackend::disconnect (const std::string& src, const std::string& dst)
694 DummyPort* src_port = find_port (src);
695 DummyPort* dst_port = find_port (dst);
697 if (!src_port || !dst_port) {
698 PBD::error << _("DummyBackend::disconnect: Invalid Port(s)") << endmsg;
701 return src_port->disconnect (dst_port);
705 DummyAudioBackend::connect (PortEngine::PortHandle src, const std::string& dst)
707 DummyPort* dst_port = find_port (dst);
708 if (!valid_port (src)) {
709 PBD::error << _("DummyBackend::connect: Invalid Source Port Handle") << endmsg;
713 PBD::error << _("DummyBackend::connect: Invalid Destination Port")
714 << " (" << dst << ")" << endmsg;
717 return static_cast<DummyPort*>(src)->connect (dst_port);
721 DummyAudioBackend::disconnect (PortEngine::PortHandle src, const std::string& dst)
723 DummyPort* dst_port = find_port (dst);
724 if (!valid_port (src) || !dst_port) {
725 PBD::error << _("DummyBackend::disconnect: Invalid Port(s)") << endmsg;
728 return static_cast<DummyPort*>(src)->disconnect (dst_port);
732 DummyAudioBackend::disconnect_all (PortEngine::PortHandle port)
734 if (!valid_port (port)) {
735 PBD::error << _("DummyBackend::disconnect_all: Invalid Port") << endmsg;
738 static_cast<DummyPort*>(port)->disconnect_all ();
743 DummyAudioBackend::connected (PortEngine::PortHandle port, bool /* process_callback_safe*/)
745 if (!valid_port (port)) {
746 PBD::error << _("DummyBackend::disconnect_all: Invalid Port") << endmsg;
749 return static_cast<DummyPort*>(port)->is_connected ();
753 DummyAudioBackend::connected_to (PortEngine::PortHandle src, const std::string& dst, bool /*process_callback_safe*/)
755 DummyPort* dst_port = find_port (dst);
756 if (!valid_port (src) || !dst_port) {
757 PBD::error << _("DummyBackend::connected_to: Invalid Port") << endmsg;
760 return static_cast<DummyPort*>(src)->is_connected (dst_port);
764 DummyAudioBackend::physically_connected (PortEngine::PortHandle port, bool /*process_callback_safe*/)
766 if (!valid_port (port)) {
767 PBD::error << _("DummyBackend::physically_connected: Invalid Port") << endmsg;
770 return static_cast<DummyPort*>(port)->is_physically_connected ();
774 DummyAudioBackend::get_connections (PortEngine::PortHandle port, std::vector<std::string>& names, bool /*process_callback_safe*/)
776 if (!valid_port (port)) {
777 PBD::error << _("DummyBackend::get_connections: Invalid Port") << endmsg;
781 assert (0 == names.size ());
783 const std::vector<DummyPort*>& connected_ports = static_cast<DummyPort*>(port)->get_connections ();
785 for (std::vector<DummyPort*>::const_iterator i = connected_ports.begin (); i != connected_ports.end (); ++i) {
786 names.push_back ((*i)->name ());
789 return (int)names.size ();
794 DummyAudioBackend::midi_event_get (
795 pframes_t& timestamp,
796 size_t& size, uint8_t** buf, void* port_buffer,
797 uint32_t event_index)
799 assert (buf && port_buffer);
800 DummyMidiBuffer& source = * static_cast<DummyMidiBuffer*>(port_buffer);
801 if (event_index >= source.size ()) {
804 DummyMidiEvent * const event = source[event_index].get ();
806 timestamp = event->timestamp ();
807 size = event->size ();
808 *buf = event->data ();
813 DummyAudioBackend::midi_event_put (
816 const uint8_t* buffer, size_t size)
818 assert (buffer && port_buffer);
819 DummyMidiBuffer& dst = * static_cast<DummyMidiBuffer*>(port_buffer);
820 if (dst.size () && (pframes_t)dst.back ()->timestamp () > timestamp) {
821 fprintf (stderr, "DummyMidiBuffer: it's too late for this event.\n");
824 dst.push_back (boost::shared_ptr<DummyMidiEvent>(new DummyMidiEvent (timestamp, buffer, size)));
829 DummyAudioBackend::get_midi_event_count (void* port_buffer)
831 assert (port_buffer && _running);
832 return static_cast<DummyMidiBuffer*>(port_buffer)->size ();
836 DummyAudioBackend::midi_clear (void* port_buffer)
838 assert (port_buffer && _running);
839 DummyMidiBuffer * buf = static_cast<DummyMidiBuffer*>(port_buffer);
847 DummyAudioBackend::can_monitor_input () const
853 DummyAudioBackend::request_input_monitoring (PortEngine::PortHandle, bool)
859 DummyAudioBackend::ensure_input_monitoring (PortEngine::PortHandle, bool)
865 DummyAudioBackend::monitoring_input (PortEngine::PortHandle)
870 /* Latency management */
873 DummyAudioBackend::set_latency_range (PortEngine::PortHandle port, bool for_playback, LatencyRange latency_range)
875 if (!valid_port (port)) {
876 PBD::error << _("DummyPort::set_latency_range (): invalid port.") << endmsg;
878 static_cast<DummyPort*>(port)->set_latency_range (latency_range, for_playback);
882 DummyAudioBackend::get_latency_range (PortEngine::PortHandle port, bool for_playback)
884 if (!valid_port (port)) {
885 PBD::error << _("DummyPort::get_latency_range (): invalid port.") << endmsg;
891 return static_cast<DummyPort*>(port)->latency_range (for_playback);
894 /* Discovering physical ports */
897 DummyAudioBackend::port_is_physical (PortEngine::PortHandle port) const
899 if (!valid_port (port)) {
900 PBD::error << _("DummyPort::port_is_physical (): invalid port.") << endmsg;
903 return static_cast<DummyPort*>(port)->is_physical ();
907 DummyAudioBackend::get_physical_outputs (DataType type, std::vector<std::string>& port_names)
909 for (size_t i = 0; i < _ports.size (); ++i) {
910 DummyPort* port = _ports[i];
911 if ((port->type () == type) && port->is_output () && port->is_physical ()) {
912 port_names.push_back (port->name ());
918 DummyAudioBackend::get_physical_inputs (DataType type, std::vector<std::string>& port_names)
920 for (size_t i = 0; i < _ports.size (); ++i) {
921 DummyPort* port = _ports[i];
922 if ((port->type () == type) && port->is_input () && port->is_physical ()) {
923 port_names.push_back (port->name ());
929 DummyAudioBackend::n_physical_outputs () const
933 for (size_t i = 0; i < _ports.size (); ++i) {
934 DummyPort* port = _ports[i];
935 if (port->is_output () && port->is_physical ()) {
936 switch (port->type ()) {
937 case DataType::AUDIO: ++n_audio; break;
938 case DataType::MIDI: ++n_midi; break;
944 cc.set (DataType::AUDIO, n_audio);
945 cc.set (DataType::MIDI, n_midi);
950 DummyAudioBackend::n_physical_inputs () const
954 for (size_t i = 0; i < _ports.size (); ++i) {
955 DummyPort* port = _ports[i];
956 if (port->is_input () && port->is_physical ()) {
957 switch (port->type ()) {
958 case DataType::AUDIO: ++n_audio; break;
959 case DataType::MIDI: ++n_midi; break;
965 cc.set (DataType::AUDIO, n_audio);
966 cc.set (DataType::MIDI, n_midi);
970 /* Getting access to the data buffer for a port */
973 DummyAudioBackend::get_buffer (PortEngine::PortHandle port, pframes_t nframes)
975 assert (port && _running);
976 assert (valid_port (port));
977 return static_cast<DummyPort*>(port)->get_buffer (nframes);
982 DummyAudioBackend::main_process_thread ()
984 AudioEngine::thread_init_callback (this);
986 _processed_samples = 0;
988 struct timeval clock1, clock2;
989 ::gettimeofday (&clock1, NULL);
991 if (engine.process_callback (_samples_per_period)) {
994 _processed_samples += _samples_per_period;
995 if (!_freewheeling) {
996 ::gettimeofday (&clock2, NULL);
997 const int elapsed_time = (clock2.tv_sec - clock1.tv_sec) * 1000000 + (clock2.tv_usec - clock1.tv_usec);
998 const int nomial_time = 1000000 * _samples_per_period / _samplerate;
999 _dsp_load = elapsed_time / (float) nomial_time;
1000 if (elapsed_time < nomial_time) {
1001 ::usleep (nomial_time - elapsed_time);
1003 ::usleep (100); // don't hog cpu
1007 ::usleep (100); // don't hog cpu
1009 ::gettimeofday (&clock1, NULL);
1016 /******************************************************************************/
1018 static boost::shared_ptr<DummyAudioBackend> _instance;
1020 static boost::shared_ptr<AudioBackend>
1021 backend_factory (AudioEngine& e)
1024 _instance.reset (new DummyAudioBackend (e));
1030 instantiate (const std::string& arg1, const std::string& /* arg2 */)
1032 s_instance_name = arg1;
1044 already_configured ()
1049 static ARDOUR::AudioBackendInfo _descriptor = {
1057 extern "C" ARDOURBACKEND_API ARDOUR::AudioBackendInfo* descriptor ()
1059 return &_descriptor;
1063 /******************************************************************************/
1064 DummyPort::DummyPort (const std::string& name, PortFlags flags)
1068 _capture_latency_range.min = 0;
1069 _capture_latency_range.max = 0;
1070 _playback_latency_range.min = 0;
1071 _playback_latency_range.max = 0;
1074 DummyPort::~DummyPort () {
1079 int DummyPort::connect (DummyPort *port)
1082 PBD::error << _("DummyPort::connect (): invalid (null) port") << endmsg;
1086 if (type () != port->type ()) {
1087 PBD::error << _("DummyPort::connect (): wrong port-type") << endmsg;
1091 if (is_output () && port->is_output ()) {
1092 PBD::error << _("DummyPort::connect (): cannot inter-connect output ports.") << endmsg;
1096 if (is_input () && port->is_input ()) {
1097 PBD::error << _("DummyPort::connect (): cannot inter-connect input ports.") << endmsg;
1102 PBD::error << _("DummyPort::connect (): cannot self-connect ports.") << endmsg;
1106 if (is_connected (port)) {
1107 #if 0 // don't bother to warn about this for now. just ignore it
1108 PBD::error << _("DummyPort::connect (): ports are already connected:")
1109 << " (" << name () << ") -> (" << port->name () << ")"
1115 _connect (port, true);
1120 void DummyPort::_connect (DummyPort *port, bool callback)
1122 _connections.push_back (port);
1124 port->_connect (this, false);
1128 int DummyPort::disconnect (DummyPort *port)
1131 PBD::error << _("DummyPort::disconnect (): invalid (null) port") << endmsg;
1135 if (!is_connected (port)) {
1136 PBD::error << _("DummyPort::disconnect (): ports are not connected:")
1137 << " (" << name () << ") -> (" << port->name () << ")"
1141 _disconnect (port, true);
1145 void DummyPort::_disconnect (DummyPort *port, bool callback)
1147 std::vector<DummyPort*>::iterator it = std::find (_connections.begin (), _connections.end (), port);
1149 assert (it != _connections.end ());
1151 _connections.erase (it);
1154 port->_disconnect (this, false);
1159 void DummyPort::disconnect_all ()
1161 while (!_connections.empty ()) {
1162 _connections.back ()->_disconnect (this, false);
1163 _connections.pop_back ();
1168 DummyPort::is_connected (const DummyPort *port) const
1170 return std::find (_connections.begin (), _connections.end (), port) != _connections.end ();
1173 bool DummyPort::is_physically_connected () const
1175 for (std::vector<DummyPort*>::const_iterator it = _connections.begin (); it != _connections.end (); ++it) {
1176 if ((*it)->is_physical ()) {
1183 /******************************************************************************/
1185 DummyAudioPort::DummyAudioPort (const std::string& name, PortFlags flags)
1186 : DummyPort (name, flags)
1188 memset (_buffer, 0, sizeof (_buffer));
1191 DummyAudioPort::~DummyAudioPort () { }
1193 void* DummyAudioPort::get_buffer (pframes_t n_samples)
1196 std::vector<DummyPort*>::const_iterator it = get_connections ().begin ();
1197 if (it == get_connections ().end ()) {
1198 memset (_buffer, 0, n_samples * sizeof (Sample));
1200 DummyAudioPort const * source = static_cast<const DummyAudioPort*>(*it);
1201 assert (source && source->is_output ());
1202 memcpy (_buffer, source->const_buffer (), n_samples * sizeof (Sample));
1203 while (++it != get_connections ().end ()) {
1204 source = static_cast<const DummyAudioPort*>(*it);
1205 assert (source && source->is_output ());
1206 Sample* dst = buffer ();
1207 const Sample* src = source->const_buffer ();
1208 for (uint32_t s = 0; s < n_samples; ++s, ++dst, ++src) {
1213 } else if (is_output () && is_physical () && is_terminal()) {
1214 memset (_buffer, 0, n_samples * sizeof (Sample));
1220 DummyMidiPort::DummyMidiPort (const std::string& name, PortFlags flags)
1221 : DummyPort (name, flags)
1226 DummyMidiPort::~DummyMidiPort () { }
1228 void* DummyMidiPort::get_buffer (pframes_t /* nframes */)
1232 for (std::vector<DummyPort*>::const_iterator i = get_connections ().begin ();
1233 i != get_connections ().end ();
1235 const DummyMidiBuffer src = static_cast<const DummyMidiPort*>(*i)->const_buffer ();
1236 for (DummyMidiBuffer::const_iterator it = src.begin (); it != src.end (); ++it) {
1237 _buffer.push_back (boost::shared_ptr<DummyMidiEvent>(new DummyMidiEvent (**it)));
1240 std::sort (_buffer.begin (), _buffer.end ());
1241 } else if (is_output () && is_physical () && is_terminal()) {
1247 DummyMidiEvent::DummyMidiEvent (const pframes_t timestamp, const uint8_t* data, size_t size)
1249 , _timestamp (timestamp)
1253 _data = (uint8_t*) malloc (size);
1254 memcpy (_data, data, size);
1258 DummyMidiEvent::DummyMidiEvent (const DummyMidiEvent& other)
1259 : _size (other.size ())
1260 , _timestamp (other.timestamp ())
1263 if (other.size () && other.const_data ()) {
1264 _data = (uint8_t*) malloc (other.size ());
1265 memcpy (_data, other.const_data (), other.size ());
1269 DummyMidiEvent::~DummyMidiEvent () {