From 239ec39da6583e6e00cd03fa3bde8f1e27016b4d Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 17 Oct 2007 16:49:31 +0000 Subject: new internal port type, round I, plus tiny fix for legalize_for_xml() (also for 2.0-ongoing) git-svn-id: svn://localhost/ardour2/trunk@2559 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/route_time_axis.cc | 2 +- libs/ardour/SConscript | 2 + libs/ardour/ardour/audio_buffer.h | 6 ++ libs/ardour/ardour/audio_port.h | 7 +- libs/ardour/ardour/audioengine.h | 9 +- libs/ardour/ardour/buffer.h | 7 ++ libs/ardour/ardour/internal_audio_port.h | 55 +++++++++++ libs/ardour/ardour/internal_port.h | 82 ++++++++++++++++ libs/ardour/ardour/midi_buffer.h | 2 + libs/ardour/ardour/types.h | 5 + libs/ardour/audio_buffer.cc | 43 +++++--- libs/ardour/audio_port.cc | 7 ++ libs/ardour/audioengine.cc | 93 +++++++++++++++--- libs/ardour/internal_audio_port.cc | 70 +++++++++++++ libs/ardour/internal_port.cc | 164 +++++++++++++++++++++++++++++++ libs/ardour/io.cc | 12 +-- libs/ardour/jack_port.cc | 1 + libs/ardour/midi_buffer.cc | 25 +++-- 18 files changed, 545 insertions(+), 47 deletions(-) create mode 100644 libs/ardour/ardour/internal_audio_port.h create mode 100644 libs/ardour/ardour/internal_port.h create mode 100644 libs/ardour/internal_audio_port.cc create mode 100644 libs/ardour/internal_port.cc diff --git a/gtk2_ardour/route_time_axis.cc b/gtk2_ardour/route_time_axis.cc index b5f04f537b..38e5a4c330 100644 --- a/gtk2_ardour/route_time_axis.cc +++ b/gtk2_ardour/route_time_axis.cc @@ -1694,7 +1694,7 @@ static string legalize_for_xml_node (string str) { string::size_type pos; - string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+=:"; + string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_=:"; string legal; legal = str; diff --git a/libs/ardour/SConscript b/libs/ardour/SConscript index 556c6c3c9b..4d68dc7725 100644 --- a/libs/ardour/SConscript +++ b/libs/ardour/SConscript @@ -65,6 +65,8 @@ gain.cc gdither.cc globals.cc import.cc +internal_port.cc +internal_audio_port.cc io.cc io_processor.cc jack_port.cc diff --git a/libs/ardour/ardour/audio_buffer.h b/libs/ardour/ardour/audio_buffer.h index b2c62466bf..9342ac196b 100644 --- a/libs/ardour/ardour/audio_buffer.h +++ b/libs/ardour/ardour/audio_buffer.h @@ -102,6 +102,12 @@ public: _silent = false; } + /** Reallocate the buffer used internally to handle at least @nframes of data + * + * Constructor MUST have been passed capacity!=0 or this will die (to prevent mem leaks). + */ + void resize (size_t nframes); + const Sample* data () const { return _data; } Sample* data () { return _data; } diff --git a/libs/ardour/ardour/audio_port.h b/libs/ardour/ardour/audio_port.h index c6df9e0a2f..035ac9ed5f 100644 --- a/libs/ardour/ardour/audio_port.h +++ b/libs/ardour/ardour/audio_port.h @@ -35,11 +35,11 @@ class AudioPort : public virtual Port { public: DataType type() const { return DataType::AUDIO; } - Buffer& get_buffer () { + virtual Buffer& get_buffer () { return _buffer; } - AudioBuffer& get_audio_buffer() { + virtual AudioBuffer& get_audio_buffer() { return _buffer; } @@ -70,7 +70,8 @@ class AudioPort : public virtual Port { protected: friend class AudioEngine; - AudioPort (); + AudioPort (); // data buffer comes from elsewhere (e.g. JACK) + AudioPort (nframes_t); // data buffer owned by ardour void reset (); /* engine isn't supposed to access below here */ diff --git a/libs/ardour/ardour/audioengine.h b/libs/ardour/ardour/audioengine.h index 17ba9f9614..34f7eb8c22 100644 --- a/libs/ardour/ardour/audioengine.h +++ b/libs/ardour/ardour/audioengine.h @@ -42,6 +42,7 @@ namespace ARDOUR { class Session; class Port; +class InternalPort; class AudioEngine : public sigc::trackable { @@ -113,8 +114,8 @@ class AudioEngine : public sigc::trackable virtual const char *what() const throw() { return "could not connect to engine backend"; } }; - Port *register_input_port (DataType type, const std::string& portname); - Port *register_output_port (DataType type, const std::string& portname); + Port *register_input_port (PortType, DataType, const std::string& portname); + Port *register_output_port (PortType, DataType, const std::string& portname); int unregister_port (Port &); int connect (const std::string& source, const std::string& destination); @@ -219,11 +220,13 @@ class AudioEngine : public sigc::trackable SerializedRCUManager ports; - Port *register_port (DataType type, const std::string& portname, bool input); + Port *register_port (PortType ptype, DataType type, const std::string& portname, bool input); int process_callback (nframes_t nframes); void remove_all_ports (); + InternalPort* get_internal_port (const std::string& short_name); + typedef std::pair PortConnection; typedef std::list PortConnections; diff --git a/libs/ardour/ardour/buffer.h b/libs/ardour/ardour/buffer.h index 18c83f8bfb..fd94360226 100644 --- a/libs/ardour/ardour/buffer.h +++ b/libs/ardour/ardour/buffer.h @@ -59,6 +59,13 @@ public: DataType type() const { return _type; } bool silent() const { return _silent; } + + /** Reallocate the buffer used internally to handle at least @a size_t units of data. + * + * The buffer is not silent after this operation. the @a capacity argument + * passed to the constructor must have been non-zero. + */ + virtual void resize(size_t) = 0; /** Clear (eg zero, or empty) buffer starting at TIME @a offset */ virtual void silence(nframes_t len, nframes_t offset=0) = 0; diff --git a/libs/ardour/ardour/internal_audio_port.h b/libs/ardour/ardour/internal_audio_port.h new file mode 100644 index 0000000000..7b70989d4b --- /dev/null +++ b/libs/ardour/ardour/internal_audio_port.h @@ -0,0 +1,55 @@ +/* + Copyright (C) 2007 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + $Id: port.h 712 2006-07-28 01:08:57Z drobilla $ +*/ + +#ifndef __ardour_internal_audio_port_h__ +#define __ardour_internal_audio_port_h__ + +#include +#include +#include +#include +#include + +namespace ARDOUR { + +class AudioEngine; +class InternalAudioPort : public AudioPort, public InternalPort { + public: + void cycle_start(nframes_t nframes) { + _buffer.silence (nframes); + } + + AudioBuffer& get_audio_buffer(); + + void set_mixdown_function (void (*func)(const std::list&, AudioBuffer&, nframes_t, nframes_t)); + void reset (); + + protected: + friend class AudioEngine; + + InternalAudioPort (const std::string& name, Flags flags); + void (*_mixdown)(const std::list&, AudioBuffer&, nframes_t, nframes_t); + + static void default_mixdown (const std::list&, AudioBuffer&, nframes_t, nframes_t); +}; + +} // namespace ARDOUR + +#endif /* __ardour_internal_audio_port_h__ */ diff --git a/libs/ardour/ardour/internal_port.h b/libs/ardour/ardour/internal_port.h new file mode 100644 index 0000000000..e6053c0e58 --- /dev/null +++ b/libs/ardour/ardour/internal_port.h @@ -0,0 +1,82 @@ +/* + Copyright (C) 2007 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef __ardour_internal_port_h__ +#define __ardour_internal_port_h__ + +#include + +#include +#include +#include + +namespace ARDOUR { + +class AudioEngine; +class Buffer; + +/** Abstract class representing internal (ardour<->ardour only) ports + */ +class InternalPort : public virtual Port { + public: + + ~InternalPort(); + + std::string short_name(); + + int set_name (std::string str); + + int connected () const; + + int reestablish (); + + bool connected_to (const std::string& portname) const; + + const char ** get_connections () const; + bool monitoring_input () const { return false; } + + void ensure_monitor_input (bool yn) {} + void request_monitor_input (bool yn) {} + + nframes_t latency () const { return _latency; } + nframes_t total_latency() const { return _latency; } + + void set_latency (nframes_t nframes); + + static void connect (InternalPort& src, InternalPort& dst); + static void disconnect (InternalPort& a, InternalPort& b); + + protected: + friend class AudioEngine; + + InternalPort (const std::string&, DataType type, Flags flags); + + int disconnect (); + void recompute_total_latency() const; + + std::list _connections; + nframes_t _latency; + + static AudioEngine* engine; + static void set_engine (AudioEngine* e); +}; + +} // namespace ARDOUR + +#endif /* __ardour_internal_port_h__ */ diff --git a/libs/ardour/ardour/midi_buffer.h b/libs/ardour/ardour/midi_buffer.h index 2ba6a0990b..953d424296 100644 --- a/libs/ardour/ardour/midi_buffer.h +++ b/libs/ardour/ardour/midi_buffer.h @@ -42,6 +42,8 @@ public: bool push_back(const ARDOUR::MidiEvent& event); bool push_back(const jack_midi_event_t& event); Byte* reserve(double time, size_t size); + + void resize(size_t); bool merge(const MidiBuffer& a, const MidiBuffer& b); diff --git a/libs/ardour/ardour/types.h b/libs/ardour/ardour/types.h index 5b50713313..0c5a8e044f 100644 --- a/libs/ardour/ardour/types.h +++ b/libs/ardour/ardour/types.h @@ -379,6 +379,11 @@ namespace ARDOUR { SrcFastest }; + enum PortType { + Jack, + Internal + }; + } // namespace ARDOUR std::istream& operator>>(std::istream& o, ARDOUR::SampleFormat& sf); diff --git a/libs/ardour/audio_buffer.cc b/libs/ardour/audio_buffer.cc index 059b61ed2f..b07f70be1f 100644 --- a/libs/ardour/audio_buffer.cc +++ b/libs/ardour/audio_buffer.cc @@ -29,19 +29,13 @@ namespace ARDOUR { AudioBuffer::AudioBuffer(size_t capacity) : Buffer(DataType::AUDIO, capacity) - , _owns_data(false) - , _data(NULL) + , _owns_data (false) + , _data (0) { - _size = capacity; // For audio buffers, size = capacity (always) - if (capacity > 0) { -#ifdef NO_POSIX_MEMALIGN - _data = (Sample *) malloc(sizeof(Sample) * capacity); -#else - posix_memalign((void**)&_data, CPU_CACHE_ALIGN, sizeof(Sample) * capacity); -#endif - assert(_data); - _owns_data = true; - clear(); + if (_capacity) { + _owns_data = true; // prevent resize() from gagging + resize (_capacity); + silence (_capacity); } } @@ -51,6 +45,31 @@ AudioBuffer::~AudioBuffer() free(_data); } +void +AudioBuffer::resize (size_t size) +{ + assert (_owns_data); + + if (size < _capacity) { + return; + } + + if (_data) { + free (_data); + } + + _capacity = size; + _size = size; + _silent = false; + +#ifdef NO_POSIX_MEMALIGN + _data = (Sample *) malloc(sizeof(Sample) * _capacity); +#else + posix_memalign((void**)&_data, CPU_CACHE_ALIGN, sizeof(Sample) * _capacity); +#endif + + _owns_data = true; +} } // namespace ARDOUR diff --git a/libs/ardour/audio_port.cc b/libs/ardour/audio_port.cc index 23c8ab8335..aa8b363134 100644 --- a/libs/ardour/audio_port.cc +++ b/libs/ardour/audio_port.cc @@ -33,6 +33,13 @@ AudioPort::AudioPort() reset(); } +AudioPort::AudioPort(nframes_t nframes) + : _buffer (nframes) +{ + _type = DataType::AUDIO; + reset(); +} + void AudioPort::reset() { diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc index 63a51b76c4..4552de1186 100644 --- a/libs/ardour/audioengine.cc +++ b/libs/ardour/audioengine.cc @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -508,17 +509,33 @@ AudioEngine::remove_session () } Port * -AudioEngine::register_port (DataType type, const string& portname, bool input) +AudioEngine::register_port (PortType ptype, DataType dtype, const string& portname, bool input) { Port* newport = 0; try { - if (type == DataType::AUDIO) - newport = new JackAudioPort (portname, (input ? Port::IsInput : Port::IsOutput)); - else if (type == DataType::MIDI) - newport = new JackMidiPort (portname, (input ? Port::IsInput : Port::IsOutput)); - else - throw unknown_type(); + switch (ptype) { + case Jack: + if (dtype == DataType::AUDIO) { + newport = new JackAudioPort (portname, (input ? Port::IsInput : Port::IsOutput)); + } else if (dtype == DataType::MIDI) { + newport = new JackMidiPort (portname, (input ? Port::IsInput : Port::IsOutput)); + } else { + throw unknown_type(); + } + break; + + case Internal: + if (dtype == DataType::AUDIO) { + newport = new InternalAudioPort (portname, (input ? Port::IsInput : Port::IsOutput)); + } else if (dtype == DataType::MIDI) { + error << _("Internal MIDI ports are not implemented yet!") << endmsg; + throw unknown_type(); + } else { + throw unknown_type(); + } + break; + } if (newport != 0) { RCUWriter writer (ports); @@ -535,16 +552,30 @@ AudioEngine::register_port (DataType type, const string& portname, bool input) } } +InternalPort* +AudioEngine::get_internal_port (const std::string& short_name) +{ + boost::shared_ptr p = ports.reader(); + + for (Ports::iterator i = p->begin(); i != p->end(); ++i) { + if ((*i)->short_name() == short_name) { + return dynamic_cast (*i); + } + } + return 0; +} + + Port * -AudioEngine::register_input_port (DataType type, const string& portname) +AudioEngine::register_input_port (PortType ptype, DataType type, const string& portname) { - return register_port (type, portname, true); + return register_port (ptype, type, portname, true); } Port * -AudioEngine::register_output_port (DataType type, const string& portname) +AudioEngine::register_output_port (PortType ptype, DataType type, const string& portname) { - return register_port (type, portname, false); + return register_port (ptype, type, portname, false); } int @@ -565,7 +596,6 @@ AudioEngine::unregister_port (Port& port) for (Ports::iterator i = ps->begin(); i != ps->end(); ++i) { if ((*i) == &port) { remove_connections_for (port); - cerr << "eraseing " << (*i)->name() << endl; delete *i; ps->erase (i); break; @@ -581,6 +611,8 @@ AudioEngine::unregister_port (Port& port) int AudioEngine::connect (const string& source, const string& destination) { + int ret; + if (!_running) { if (!_has_run) { fatal << _("connect called before engine was started") << endmsg; @@ -589,11 +621,26 @@ AudioEngine::connect (const string& source, const string& destination) return -1; } } - + string s = make_port_name_non_relative (source); string d = make_port_name_non_relative (destination); + + if (source.substr (0, 9) == "internal:") { + if (destination.substr (0, 9) == "internal:") { + InternalPort* src = get_internal_port (source); + InternalPort* dst = get_internal_port (destination); + + InternalPort::connect (*src, *dst); + ret = 0; - int ret = jack_connect (_jack, s.c_str(), d.c_str()); + } else { + ret = -1; + } + + } else { + + ret = jack_connect (_jack, s.c_str(), d.c_str()); + } if (ret == 0) { pair c (s, d); @@ -614,6 +661,8 @@ AudioEngine::connect (const string& source, const string& destination) int AudioEngine::disconnect (const string& source, const string& destination) { + int ret; + if (!_running) { if (!_has_run) { fatal << _("disconnect called before engine was started") << endmsg; @@ -626,7 +675,21 @@ AudioEngine::disconnect (const string& source, const string& destination) string s = make_port_name_non_relative (source); string d = make_port_name_non_relative (destination); - int ret = jack_disconnect (_jack, s.c_str(), d.c_str()); + if (source.substr (0, 9) == "internal:") { + if (destination.substr (0, 9) == "internal:") { + InternalPort* src = get_internal_port (source); + InternalPort* dst = get_internal_port (destination); + + InternalPort::disconnect (*src, *dst); + ret = 0; + } else { + ret = -1; + } + + } else { + + ret = jack_disconnect (_jack, s.c_str(), d.c_str()); + } if (ret == 0) { pair c (s, d); diff --git a/libs/ardour/internal_audio_port.cc b/libs/ardour/internal_audio_port.cc new file mode 100644 index 0000000000..f5c5c5dee9 --- /dev/null +++ b/libs/ardour/internal_audio_port.cc @@ -0,0 +1,70 @@ +/* + Copyright (C) 2006 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include +#include +#include + +using namespace ARDOUR; +using namespace std; + +void +InternalAudioPort::default_mixdown (const list& ports, AudioBuffer& dest, nframes_t cnt, nframes_t offset) +{ + list::const_iterator p = ports.begin(); + + dest.read_from ((dynamic_cast(*p))->get_audio_buffer(), cnt, offset); + + for (; p != ports.end(); ++p) { + dest.accumulate_from ((dynamic_cast(*p))->get_audio_buffer(), cnt, offset); + } +} + +InternalAudioPort::InternalAudioPort(const string& name, Flags flgs) + : AudioPort (engine->frames_per_cycle()) + , InternalPort (name, DataType::AUDIO, flgs) +{ + _mixdown = default_mixdown; +} + +void +InternalAudioPort::set_mixdown_function (void (*func)(const list&, AudioBuffer&, nframes_t, nframes_t)) +{ + _mixdown = func; +} + +void +InternalAudioPort::reset () +{ + _buffer.resize (engine->frames_per_cycle()); + _buffer.silence (_buffer.size()); +} + +AudioBuffer& +InternalAudioPort::get_audio_buffer () +{ + if (_connections.empty()) { + return AudioPort::get_audio_buffer(); + } + + /* XXX what about offset/size being more dynamic ? */ + + (*_mixdown) (_connections, _buffer, _buffer.size(), 0); + + return _buffer; +} diff --git a/libs/ardour/internal_port.cc b/libs/ardour/internal_port.cc new file mode 100644 index 0000000000..3854931819 --- /dev/null +++ b/libs/ardour/internal_port.cc @@ -0,0 +1,164 @@ +/* + Copyright (C) 2007 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include +#include +#include + +#include "i18n.h" + +using namespace ARDOUR; +using namespace std; + +AudioEngine* InternalPort::engine = 0; + +void +InternalPort::set_engine (AudioEngine* e) +{ + engine = e; +} + +InternalPort::InternalPort (const string& str, DataType type, Flags flags) +{ + set_name (str); + _type = type; + _flags = flags; +} + +InternalPort::~InternalPort () +{ + disconnect (); +} + +void +InternalPort::set_latency (nframes_t val) +{ + _latency = val; +} + +bool +InternalPort::connected_to (const string& portname) const +{ + /* caller must hold process lock */ + + for (list::const_iterator p = _connections.begin(); p != _connections.end(); ++p) { + if ((*p)->name() == portname) { + return true; + } + } + + return false; +} + +const char** +InternalPort::get_connections () const +{ + /* caller must hold process lock */ + + int i; + list::const_iterator p; + + if (_connections.empty()) { + return 0; + } + + char **names = (char**) malloc (sizeof (char*) * ( _connections.size() + 1)); + + + for (i = 0, p = _connections.begin(); p != _connections.end(); ++p, ++i) { + names[i] = (char*) (*p)->name().c_str(); + } + + names[i] = 0; + + return (const char**) names; +} + +int +InternalPort::connected() const +{ + /* caller must hold process lock */ + return !_connections.empty(); +} + +int +InternalPort::set_name (string str) +{ + _name = "internal:"; + _name += str; + + return 0; +} + +string +InternalPort::short_name () +{ + return _name.substr (9); +} + +void +InternalPort::connect (InternalPort& src, InternalPort& dst) +{ + /* caller must hold process lock */ + + src._connections.push_back (&dst); + dst._connections.push_back (&src); +} + +void +InternalPort::disconnect (InternalPort& a, InternalPort& b) +{ + /* caller must hold process lock */ + a._connections.remove (&b); + b._connections.remove (&a); +} + +int +InternalPort::disconnect () +{ + /* caller must hold process lock */ + + for (list::const_iterator p = _connections.begin(); p != _connections.end(); ) { + list::const_iterator tmp; + + tmp = p; + ++tmp; + + disconnect (*this, **p); + + p = tmp; + } + + _connections.clear (); + + return 0; +} + +int +InternalPort::reestablish () +{ + return 0; +} + +void +InternalPort::recompute_total_latency () const +{ + return; +} + diff --git a/libs/ardour/io.cc b/libs/ardour/io.cc index 0c4ee41496..95f40f1f80 100644 --- a/libs/ardour/io.cc +++ b/libs/ardour/io.cc @@ -602,7 +602,7 @@ IO::add_output_port (string destination, void* src, DataType type) snprintf (name, sizeof (name), _("%s/out %u"), _name.c_str(), find_output_port_hole()); } - if ((our_port = _session.engine().register_output_port (type, name)) == 0) { + if ((our_port = _session.engine().register_output_port (Jack, type, name)) == 0) { error << string_compose(_("IO: cannot register output port %1"), name) << endmsg; return -1; } @@ -713,7 +713,7 @@ IO::add_input_port (string source, void* src, DataType type) snprintf (name, sizeof (name), _("%s/in %u"), _name.c_str(), find_input_port_hole()); } - if ((our_port = _session.engine().register_input_port (type, name)) == 0) { + if ((our_port = _session.engine().register_input_port (Jack, type, name)) == 0) { error << string_compose(_("IO: cannot register input port %1"), name) << endmsg; return -1; } @@ -822,7 +822,7 @@ IO::ensure_inputs_locked (ChanCount count, bool clear, void* src) try { - if ((input_port = _session.engine().register_input_port (*t, buf)) == 0) { + if ((input_port = _session.engine().register_input_port (Jack, *t, buf)) == 0) { error << string_compose(_("IO: cannot register input port %1"), buf) << endmsg; return -1; } @@ -938,7 +938,7 @@ IO::ensure_io (ChanCount in, ChanCount out, bool clear, void* src) } try { - if ((port = _session.engine().register_input_port (*t, buf)) == 0) { + if ((port = _session.engine().register_input_port (Jack, *t, buf)) == 0) { error << string_compose(_("IO: cannot register input port %1"), buf) << endmsg; return -1; } @@ -970,7 +970,7 @@ IO::ensure_io (ChanCount in, ChanCount out, bool clear, void* src) } try { - if ((port = _session.engine().register_output_port (*t, buf)) == 0) { + if ((port = _session.engine().register_output_port (Jack, *t, buf)) == 0) { error << string_compose(_("IO: cannot register output port %1"), buf) << endmsg; return -1; } @@ -1090,7 +1090,7 @@ IO::ensure_outputs_locked (ChanCount count, bool clear, void* src) snprintf (buf, sizeof (buf), _("%s/out %u"), _name.c_str(), find_output_port_hole()); } - if ((output_port = _session.engine().register_output_port (*t, buf)) == 0) { + if ((output_port = _session.engine().register_output_port (Jack, *t, buf)) == 0) { error << string_compose(_("IO: cannot register output port %1"), buf) << endmsg; return -1; } diff --git a/libs/ardour/jack_port.cc b/libs/ardour/jack_port.cc index 7f56e396ce..221e46b076 100644 --- a/libs/ardour/jack_port.cc +++ b/libs/ardour/jack_port.cc @@ -109,3 +109,4 @@ JackPort::recompute_total_latency () const #endif } + diff --git a/libs/ardour/midi_buffer.cc b/libs/ardour/midi_buffer.cc index e971e9ae8f..52f04eaf91 100644 --- a/libs/ardour/midi_buffer.cc +++ b/libs/ardour/midi_buffer.cc @@ -38,20 +38,31 @@ MidiBuffer::MidiBuffer(size_t capacity) , _events(NULL) , _data(NULL) { - assert(capacity > 0); + _data = 0; + resize (_capacity); + silence(_capacity); +} - _size = 0; +void +MidiBuffer::resize (size_t size) +{ + assert(size > 0); + if (_data) { + free (_data); + } + + _size = 0; + _capacity = size; #ifdef NO_POSIX_MEMALIGN - _events = (MidiEvent *) malloc(sizeof(MidiEvent) * capacity); - _data = (Byte *) malloc(sizeof(Byte) * capacity * MAX_EVENT_SIZE); + _events = (MidiEvent *) malloc(sizeof(MidiEvent) * _capacity); + _data = (Byte *) malloc(sizeof(Byte) * _capacity * MAX_EVENT_SIZE); #else - posix_memalign((void**)&_events, CPU_CACHE_ALIGN, sizeof(MidiEvent) * capacity); - posix_memalign((void**)&_data, CPU_CACHE_ALIGN, sizeof(Byte) * capacity * MAX_EVENT_SIZE); + posix_memalign((void**)&_events, CPU_CACHE_ALIGN, sizeof(MidiEvent) * _capacity); + posix_memalign((void**)&_data, CPU_CACHE_ALIGN, sizeof(Byte) * _capacity * MAX_EVENT_SIZE); #endif assert(_data); assert(_events); - silence(_capacity); } void -- cgit v1.2.3