2008-06-02 17:41:35 -04:00
|
|
|
/*
|
2009-10-14 12:10:01 -04:00
|
|
|
Copyright (C) 2006 Paul Davis
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
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.
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
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.
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2009-07-12 20:26:28 -04:00
|
|
|
|
|
|
|
#ifdef WAF_BUILD
|
|
|
|
#include "libardour-config.h"
|
|
|
|
#endif
|
|
|
|
|
2009-01-30 02:40:13 -05:00
|
|
|
#include <iostream>
|
2008-06-02 17:41:35 -04:00
|
|
|
#include <algorithm>
|
2011-12-22 15:14:47 -05:00
|
|
|
#include <sstream>
|
2011-07-22 11:44:13 -04:00
|
|
|
|
2011-04-22 23:34:42 -04:00
|
|
|
#include "pbd/compose.h"
|
2012-05-24 13:43:13 -04:00
|
|
|
#include "pbd/failed_constructor.h"
|
2011-07-22 11:44:13 -04:00
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/buffer.h"
|
2009-05-04 11:50:51 -04:00
|
|
|
#include "ardour/buffer_set.h"
|
2011-03-05 18:14:39 -05:00
|
|
|
#include "ardour/debug.h"
|
2009-05-04 11:50:51 -04:00
|
|
|
#include "ardour/midi_buffer.h"
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/port.h"
|
|
|
|
#include "ardour/port_set.h"
|
2014-11-01 23:29:10 -04:00
|
|
|
#include "ardour/uri_map.h"
|
2011-05-14 13:59:16 -04:00
|
|
|
#ifdef LV2_SUPPORT
|
2009-05-04 16:11:02 -04:00
|
|
|
#include "ardour/lv2_plugin.h"
|
2012-02-24 23:16:42 -05:00
|
|
|
#include "lv2_evbuf.h"
|
2009-05-04 16:11:02 -04:00
|
|
|
#endif
|
2011-11-21 20:28:27 -05:00
|
|
|
#if defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT
|
2011-09-20 16:29:47 -04:00
|
|
|
#include "ardour/vestige/aeffectx.h"
|
|
|
|
#endif
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
namespace ARDOUR {
|
|
|
|
|
|
|
|
/** Create a new, empty BufferSet */
|
|
|
|
BufferSet::BufferSet()
|
|
|
|
: _is_mirror(false)
|
|
|
|
{
|
2009-05-04 11:50:51 -04:00
|
|
|
for (size_t i=0; i < DataType::num_types; ++i) {
|
|
|
|
_buffers.push_back(BufferVec());
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
_count.reset();
|
|
|
|
_available.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
BufferSet::~BufferSet()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Destroy all contained buffers.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
BufferSet::clear()
|
|
|
|
{
|
|
|
|
if (!_is_mirror) {
|
|
|
|
for (std::vector<BufferVec>::iterator i = _buffers.begin(); i != _buffers.end(); ++i) {
|
|
|
|
for (BufferVec::iterator j = (*i).begin(); j != (*i).end(); ++j) {
|
|
|
|
delete *j;
|
|
|
|
}
|
|
|
|
(*i).clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_buffers.clear();
|
|
|
|
_count.reset();
|
|
|
|
_available.reset();
|
2010-07-11 17:55:11 -04:00
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
#if defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT
|
2010-07-11 17:55:11 -04:00
|
|
|
for (VSTBuffers::iterator i = _vst_buffers.begin(); i != _vst_buffers.end(); ++i) {
|
|
|
|
delete *i;
|
|
|
|
}
|
|
|
|
|
|
|
|
_vst_buffers.clear ();
|
2011-06-01 12:50:12 -04:00
|
|
|
#endif
|
2011-09-20 16:29:47 -04:00
|
|
|
|
2015-09-12 14:05:25 -04:00
|
|
|
#ifdef LV2_SUPPORT
|
|
|
|
for (LV2Buffers::iterator i = _lv2_buffers.begin(); i != _lv2_buffers.end(); ++i) {
|
2015-09-12 22:08:49 -04:00
|
|
|
free ((*i).second);
|
2015-09-12 14:05:25 -04:00
|
|
|
}
|
|
|
|
_lv2_buffers.clear ();
|
|
|
|
#endif
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2011-01-10 11:23:54 -05:00
|
|
|
/** Set up this BufferSet so that its data structures mirror a PortSet's buffers.
|
|
|
|
* This is quite expensive and not RT-safe, so it should not be called in a process context;
|
2013-08-09 13:38:09 -04:00
|
|
|
* get_backend_port_addresses() will fill in a structure set up by this method.
|
2011-07-12 21:00:53 -04:00
|
|
|
*
|
|
|
|
* XXX: this *is* called in a process context; I'm not sure quite what `should not' means above.
|
2008-06-02 17:41:35 -04:00
|
|
|
*/
|
|
|
|
void
|
2011-01-10 11:23:54 -05:00
|
|
|
BufferSet::attach_buffers (PortSet& ports)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2011-07-22 11:44:13 -04:00
|
|
|
const ChanCount& count (ports.count());
|
|
|
|
|
|
|
|
clear ();
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
|
2011-07-22 11:44:13 -04:00
|
|
|
_buffers.push_back (BufferVec());
|
2008-06-02 17:41:35 -04:00
|
|
|
BufferVec& v = _buffers[*t];
|
2011-07-22 11:44:13 -04:00
|
|
|
v.assign (count.n (*t), (Buffer*) 0);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
_count = ports.count();
|
The great audio processing overhaul.
The vast majority of Route signal processing is now simply in the list of
processors. There are definitely regressions here, but there's also
a lot of things fixed. It's far too much work to let diverge anymore
regardless, so here it is.
The basic model is: A route has a fixed set of input channels (matching
its JACK input ports and diskstream). The first processor takes this
as input. The next processor is configured using the first processor's
output as input, and is allowed to choose whatever output it wants
given that input... and so on, and so on. Finally, the last processor's
requested output is used to set up the panner and create whatever Jack
ports are needed to output the data.
All 'special' internal processors (meter, fader, amp, insert, send) are
currently transparent: they read any input, and return the same set
of channels back (unmodified, except for amp).
User visible changes:
* LV2 Instrument support (tracks with both MIDI and audio channels)
* MIDI in/out plugin support
* Generic plugin replication (for MIDI plugins, MIDI/audio plugins)
* Movable meter point
Known Bugs:
* Things seem to get weird on loaded sessions
* Output delivery is sketchy
* 2.0 session loading was probably already broken...
but it's definitely broken now :)
Please test this and file bugs if you have any time...
git-svn-id: svn://localhost/ardour2/branches/3.0@5055 d708f5d6-7413-0410-9779-e7cbd77b26cf
2009-05-07 02:30:50 -04:00
|
|
|
_available = ports.count();
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2011-07-22 11:44:13 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
_is_mirror = true;
|
|
|
|
}
|
|
|
|
|
2013-08-09 13:27:05 -04:00
|
|
|
/** Write the backend port addresses from a PortSet into our data structures. This
|
2011-01-10 11:23:54 -05:00
|
|
|
* call assumes that attach_buffers() has already been called for the same PortSet.
|
2011-07-22 11:44:13 -04:00
|
|
|
* Does not allocate, so RT-safe BUT you can only call Port::get_buffer() from
|
|
|
|
* the process() callback tree anyway, so this has to be called in RT context.
|
2011-01-10 11:23:54 -05:00
|
|
|
*/
|
|
|
|
void
|
2013-08-09 13:27:05 -04:00
|
|
|
BufferSet::get_backend_port_addresses (PortSet& ports, framecnt_t nframes)
|
2011-01-10 11:23:54 -05:00
|
|
|
{
|
|
|
|
assert (_count == ports.count ());
|
|
|
|
assert (_available == ports.count ());
|
|
|
|
assert (_is_mirror);
|
|
|
|
|
|
|
|
assert (_buffers.size() == DataType::num_types);
|
|
|
|
|
|
|
|
for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
|
|
|
|
BufferVec& v = _buffers[*t];
|
|
|
|
|
|
|
|
assert (v.size() == ports.num_ports (*t));
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
for (PortSet::iterator p = ports.begin(*t); p != ports.end(*t); ++p) {
|
2011-03-07 14:06:42 -05:00
|
|
|
v[i] = &p->get_buffer (nframes);
|
2011-01-10 11:23:54 -05:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
/** Ensure that there are @a num_buffers buffers of type @a type available,
|
|
|
|
* each of size at least @a buffer_size
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
BufferSet::ensure_buffers(DataType type, size_t num_buffers, size_t buffer_capacity)
|
|
|
|
{
|
|
|
|
assert(type != DataType::NIL);
|
|
|
|
assert(type < _buffers.size());
|
|
|
|
|
The great audio processing overhaul.
The vast majority of Route signal processing is now simply in the list of
processors. There are definitely regressions here, but there's also
a lot of things fixed. It's far too much work to let diverge anymore
regardless, so here it is.
The basic model is: A route has a fixed set of input channels (matching
its JACK input ports and diskstream). The first processor takes this
as input. The next processor is configured using the first processor's
output as input, and is allowed to choose whatever output it wants
given that input... and so on, and so on. Finally, the last processor's
requested output is used to set up the panner and create whatever Jack
ports are needed to output the data.
All 'special' internal processors (meter, fader, amp, insert, send) are
currently transparent: they read any input, and return the same set
of channels back (unmodified, except for amp).
User visible changes:
* LV2 Instrument support (tracks with both MIDI and audio channels)
* MIDI in/out plugin support
* Generic plugin replication (for MIDI plugins, MIDI/audio plugins)
* Movable meter point
Known Bugs:
* Things seem to get weird on loaded sessions
* Output delivery is sketchy
* 2.0 session loading was probably already broken...
but it's definitely broken now :)
Please test this and file bugs if you have any time...
git-svn-id: svn://localhost/ardour2/branches/3.0@5055 d708f5d6-7413-0410-9779-e7cbd77b26cf
2009-05-07 02:30:50 -04:00
|
|
|
if (num_buffers == 0) {
|
2008-06-02 17:41:35 -04:00
|
|
|
return;
|
The great audio processing overhaul.
The vast majority of Route signal processing is now simply in the list of
processors. There are definitely regressions here, but there's also
a lot of things fixed. It's far too much work to let diverge anymore
regardless, so here it is.
The basic model is: A route has a fixed set of input channels (matching
its JACK input ports and diskstream). The first processor takes this
as input. The next processor is configured using the first processor's
output as input, and is allowed to choose whatever output it wants
given that input... and so on, and so on. Finally, the last processor's
requested output is used to set up the panner and create whatever Jack
ports are needed to output the data.
All 'special' internal processors (meter, fader, amp, insert, send) are
currently transparent: they read any input, and return the same set
of channels back (unmodified, except for amp).
User visible changes:
* LV2 Instrument support (tracks with both MIDI and audio channels)
* MIDI in/out plugin support
* Generic plugin replication (for MIDI plugins, MIDI/audio plugins)
* Movable meter point
Known Bugs:
* Things seem to get weird on loaded sessions
* Output delivery is sketchy
* 2.0 session loading was probably already broken...
but it's definitely broken now :)
Please test this and file bugs if you have any time...
git-svn-id: svn://localhost/ardour2/branches/3.0@5055 d708f5d6-7413-0410-9779-e7cbd77b26cf
2009-05-07 02:30:50 -04:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
// The vector of buffers of the type we care about
|
|
|
|
BufferVec& bufs = _buffers[type];
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
// If we're a mirror just make sure we're ok
|
|
|
|
if (_is_mirror) {
|
|
|
|
assert(_count.get(type) >= num_buffers);
|
|
|
|
assert(bufs[0]->type() == type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there's not enough or they're too small, just nuke the whole thing and
|
|
|
|
// rebuild it (so I'm lazy..)
|
|
|
|
if (bufs.size() < num_buffers
|
2013-11-29 22:26:33 -05:00
|
|
|
|| (bufs.size() > 0 && bufs[0]->capacity() < buffer_capacity)) {
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
// Nuke it
|
|
|
|
for (BufferVec::iterator i = bufs.begin(); i != bufs.end(); ++i) {
|
|
|
|
delete (*i);
|
|
|
|
}
|
|
|
|
bufs.clear();
|
|
|
|
|
|
|
|
// Rebuild it
|
2009-05-04 11:50:51 -04:00
|
|
|
for (size_t i = 0; i < num_buffers; ++i) {
|
2008-06-02 17:41:35 -04:00
|
|
|
bufs.push_back(Buffer::create(type, buffer_capacity));
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
_available.set(type, num_buffers);
|
2009-07-01 09:36:50 -04:00
|
|
|
_count.set (type, num_buffers);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2011-05-14 13:59:16 -04:00
|
|
|
#ifdef LV2_SUPPORT
|
2009-05-04 11:50:51 -04:00
|
|
|
// Ensure enough low level MIDI format buffers are available for conversion
|
|
|
|
// in both directions (input & output, out-of-place)
|
The great audio processing overhaul.
The vast majority of Route signal processing is now simply in the list of
processors. There are definitely regressions here, but there's also
a lot of things fixed. It's far too much work to let diverge anymore
regardless, so here it is.
The basic model is: A route has a fixed set of input channels (matching
its JACK input ports and diskstream). The first processor takes this
as input. The next processor is configured using the first processor's
output as input, and is allowed to choose whatever output it wants
given that input... and so on, and so on. Finally, the last processor's
requested output is used to set up the panner and create whatever Jack
ports are needed to output the data.
All 'special' internal processors (meter, fader, amp, insert, send) are
currently transparent: they read any input, and return the same set
of channels back (unmodified, except for amp).
User visible changes:
* LV2 Instrument support (tracks with both MIDI and audio channels)
* MIDI in/out plugin support
* Generic plugin replication (for MIDI plugins, MIDI/audio plugins)
* Movable meter point
Known Bugs:
* Things seem to get weird on loaded sessions
* Output delivery is sketchy
* 2.0 session loading was probably already broken...
but it's definitely broken now :)
Please test this and file bugs if you have any time...
git-svn-id: svn://localhost/ardour2/branches/3.0@5055 d708f5d6-7413-0410-9779-e7cbd77b26cf
2009-05-07 02:30:50 -04:00
|
|
|
if (type == DataType::MIDI && _lv2_buffers.size() < _buffers[type].size() * 2 + 1) {
|
2009-05-04 11:50:51 -04:00
|
|
|
while (_lv2_buffers.size() < _buffers[type].size() * 2) {
|
2012-02-24 23:16:42 -05:00
|
|
|
_lv2_buffers.push_back(
|
2012-02-28 22:21:37 -05:00
|
|
|
std::make_pair(false, lv2_evbuf_new(buffer_capacity,
|
|
|
|
LV2_EVBUF_EVENT,
|
2014-11-01 23:29:10 -04:00
|
|
|
URIMap::instance().urids.atom_Chunk,
|
|
|
|
URIMap::instance().urids.atom_Sequence)));
|
2009-05-04 11:50:51 -04:00
|
|
|
}
|
|
|
|
}
|
2009-05-04 16:11:02 -04:00
|
|
|
#endif
|
2009-05-04 11:50:51 -04:00
|
|
|
|
2011-11-21 12:42:29 -05:00
|
|
|
#if defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT
|
2010-07-11 17:55:11 -04:00
|
|
|
// As above but for VST
|
|
|
|
if (type == DataType::MIDI) {
|
|
|
|
while (_vst_buffers.size() < _buffers[type].size()) {
|
|
|
|
_vst_buffers.push_back (new VSTBuffer (buffer_capacity));
|
|
|
|
}
|
|
|
|
}
|
2011-06-01 12:50:12 -04:00
|
|
|
#endif
|
2010-07-11 17:55:11 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
// Post-conditions
|
|
|
|
assert(bufs[0]->type() == type);
|
|
|
|
assert(bufs.size() >= num_buffers);
|
|
|
|
assert(bufs.size() == _available.get(type));
|
|
|
|
assert(bufs[0]->capacity() >= buffer_capacity);
|
|
|
|
}
|
|
|
|
|
2009-07-01 09:36:50 -04:00
|
|
|
/** Ensure that the number of buffers of each type @a type matches @a chns
|
|
|
|
* and each buffer is of size at least @a buffer_capacity
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
BufferSet::ensure_buffers(const ChanCount& chns, size_t buffer_capacity)
|
|
|
|
{
|
2010-08-20 16:00:08 -04:00
|
|
|
for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) {
|
|
|
|
ensure_buffers (*i, chns.get (*i), buffer_capacity);
|
2009-07-01 09:36:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
/** Get the capacity (size) of the available buffers of the given type.
|
|
|
|
*
|
|
|
|
* All buffers of a certain type always have the same capacity.
|
|
|
|
*/
|
|
|
|
size_t
|
|
|
|
BufferSet::buffer_capacity(DataType type) const
|
|
|
|
{
|
|
|
|
assert(_available.get(type) > 0);
|
|
|
|
return _buffers[type][0]->capacity();
|
|
|
|
}
|
|
|
|
|
2009-05-04 11:50:51 -04:00
|
|
|
Buffer&
|
|
|
|
BufferSet::get(DataType type, size_t i)
|
|
|
|
{
|
The great audio processing overhaul.
The vast majority of Route signal processing is now simply in the list of
processors. There are definitely regressions here, but there's also
a lot of things fixed. It's far too much work to let diverge anymore
regardless, so here it is.
The basic model is: A route has a fixed set of input channels (matching
its JACK input ports and diskstream). The first processor takes this
as input. The next processor is configured using the first processor's
output as input, and is allowed to choose whatever output it wants
given that input... and so on, and so on. Finally, the last processor's
requested output is used to set up the panner and create whatever Jack
ports are needed to output the data.
All 'special' internal processors (meter, fader, amp, insert, send) are
currently transparent: they read any input, and return the same set
of channels back (unmodified, except for amp).
User visible changes:
* LV2 Instrument support (tracks with both MIDI and audio channels)
* MIDI in/out plugin support
* Generic plugin replication (for MIDI plugins, MIDI/audio plugins)
* Movable meter point
Known Bugs:
* Things seem to get weird on loaded sessions
* Output delivery is sketchy
* 2.0 session loading was probably already broken...
but it's definitely broken now :)
Please test this and file bugs if you have any time...
git-svn-id: svn://localhost/ardour2/branches/3.0@5055 d708f5d6-7413-0410-9779-e7cbd77b26cf
2009-05-07 02:30:50 -04:00
|
|
|
assert(i < _available.get(type));
|
2009-05-04 11:50:51 -04:00
|
|
|
return *_buffers[type][i];
|
|
|
|
}
|
|
|
|
|
2009-10-19 21:24:31 -04:00
|
|
|
const Buffer&
|
|
|
|
BufferSet::get(DataType type, size_t i) const
|
|
|
|
{
|
|
|
|
assert(i < _available.get(type));
|
|
|
|
return *_buffers[type][i];
|
|
|
|
}
|
|
|
|
|
2011-05-14 13:59:16 -04:00
|
|
|
#ifdef LV2_SUPPORT
|
2009-05-04 16:11:02 -04:00
|
|
|
|
2013-06-02 18:48:17 -04:00
|
|
|
void
|
|
|
|
BufferSet::ensure_lv2_bufsize(bool input, size_t i, size_t buffer_capacity)
|
|
|
|
{
|
|
|
|
assert(count().get(DataType::MIDI) > i);
|
|
|
|
|
|
|
|
LV2Buffers::value_type b = _lv2_buffers.at(i * 2 + (input ? 0 : 1));
|
|
|
|
LV2_Evbuf* evbuf = b.second;
|
|
|
|
|
|
|
|
if (lv2_evbuf_get_capacity(evbuf) >= buffer_capacity) return;
|
|
|
|
|
|
|
|
lv2_evbuf_free(b.second);
|
|
|
|
_lv2_buffers.at(i * 2 + (input ? 0 : 1)) =
|
|
|
|
std::make_pair(false, lv2_evbuf_new(
|
|
|
|
buffer_capacity,
|
|
|
|
LV2_EVBUF_EVENT,
|
2014-11-01 23:29:10 -04:00
|
|
|
URIMap::instance().urids.atom_Chunk,
|
|
|
|
URIMap::instance().urids.atom_Sequence));
|
2013-06-02 18:48:17 -04:00
|
|
|
}
|
|
|
|
|
2012-02-24 23:16:42 -05:00
|
|
|
LV2_Evbuf*
|
2012-02-28 22:21:37 -05:00
|
|
|
BufferSet::get_lv2_midi(bool input, size_t i, bool old_api)
|
2009-05-04 11:50:51 -04:00
|
|
|
{
|
2012-02-24 23:16:42 -05:00
|
|
|
assert(count().get(DataType::MIDI) > i);
|
2011-06-01 12:50:12 -04:00
|
|
|
|
2012-02-24 23:16:42 -05:00
|
|
|
LV2Buffers::value_type b = _lv2_buffers.at(i * 2 + (input ? 0 : 1));
|
|
|
|
LV2_Evbuf* evbuf = b.second;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2012-11-17 23:35:31 -05:00
|
|
|
lv2_evbuf_set_type(evbuf, old_api ? LV2_EVBUF_EVENT : LV2_EVBUF_ATOM);
|
2012-02-28 22:21:37 -05:00
|
|
|
lv2_evbuf_reset(evbuf, input);
|
2012-02-24 23:16:42 -05:00
|
|
|
return evbuf;
|
2009-05-04 11:50:51 -04:00
|
|
|
}
|
|
|
|
|
2013-05-19 11:19:01 -04:00
|
|
|
void
|
|
|
|
BufferSet::forward_lv2_midi(LV2_Evbuf* buf, size_t i, bool purge_ardour_buffer)
|
|
|
|
{
|
|
|
|
MidiBuffer& mbuf = get_midi(i);
|
|
|
|
if (purge_ardour_buffer) {
|
|
|
|
mbuf.silence(0, 0);
|
|
|
|
}
|
|
|
|
for (LV2_Evbuf_Iterator i = lv2_evbuf_begin(buf);
|
|
|
|
lv2_evbuf_is_valid(i);
|
|
|
|
i = lv2_evbuf_next(i)) {
|
|
|
|
uint32_t frames, subframes, type, size;
|
|
|
|
uint8_t* data;
|
|
|
|
lv2_evbuf_get(i, &frames, &subframes, &type, &size, &data);
|
2014-11-01 23:29:10 -04:00
|
|
|
if (type == URIMap::instance().urids.midi_MidiEvent) {
|
2013-05-19 11:19:01 -04:00
|
|
|
mbuf.push_back(frames, size, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-04 11:50:51 -04:00
|
|
|
void
|
|
|
|
BufferSet::flush_lv2_midi(bool input, size_t i)
|
|
|
|
{
|
2012-02-24 23:16:42 -05:00
|
|
|
MidiBuffer& mbuf = get_midi(i);
|
|
|
|
LV2Buffers::value_type b = _lv2_buffers.at(i * 2 + (input ? 0 : 1));
|
|
|
|
LV2_Evbuf* evbuf = b.second;
|
2009-05-04 11:50:51 -04:00
|
|
|
|
|
|
|
mbuf.silence(0, 0);
|
2012-02-24 23:16:42 -05:00
|
|
|
for (LV2_Evbuf_Iterator i = lv2_evbuf_begin(evbuf);
|
|
|
|
lv2_evbuf_is_valid(i);
|
|
|
|
i = lv2_evbuf_next(i)) {
|
2009-05-04 11:50:51 -04:00
|
|
|
uint32_t frames;
|
|
|
|
uint32_t subframes;
|
2012-02-24 23:16:42 -05:00
|
|
|
uint32_t type;
|
|
|
|
uint32_t size;
|
2009-05-04 11:50:51 -04:00
|
|
|
uint8_t* data;
|
2012-02-24 23:16:42 -05:00
|
|
|
lv2_evbuf_get(i, &frames, &subframes, &type, &size, &data);
|
2011-06-01 12:50:12 -04:00
|
|
|
#ifndef NDEBUG
|
2011-12-09 14:36:20 -05:00
|
|
|
DEBUG_TRACE (PBD::DEBUG::LV2, string_compose ("(FLUSH) MIDI event of size %1\n", size));
|
|
|
|
for (uint16_t x = 0; x < size; ++x) {
|
|
|
|
DEBUG_TRACE (PBD::DEBUG::LV2, string_compose ("\tByte[%1] = %2\n", x, (int) data[x]));
|
|
|
|
}
|
2011-03-05 18:14:39 -05:00
|
|
|
#endif
|
2014-11-01 23:29:10 -04:00
|
|
|
if (type == URIMap::instance().urids.midi_MidiEvent) {
|
2012-11-17 23:35:31 -05:00
|
|
|
// TODO: Make Ardour event buffers generic so plugins can communicate
|
|
|
|
mbuf.push_back(frames, size, data);
|
|
|
|
}
|
2009-05-04 11:50:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-14 13:59:16 -04:00
|
|
|
#endif /* LV2_SUPPORT */
|
2010-07-11 17:55:11 -04:00
|
|
|
|
2011-11-21 12:42:29 -05:00
|
|
|
#if defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT
|
2010-07-11 17:55:11 -04:00
|
|
|
|
|
|
|
VstEvents*
|
|
|
|
BufferSet::get_vst_midi (size_t b)
|
|
|
|
{
|
|
|
|
MidiBuffer& m = get_midi (b);
|
|
|
|
VSTBuffer* vst = _vst_buffers[b];
|
|
|
|
|
|
|
|
vst->clear ();
|
|
|
|
|
|
|
|
for (MidiBuffer::iterator i = m.begin(); i != m.end(); ++i) {
|
|
|
|
vst->push_back (*i);
|
|
|
|
}
|
2011-06-01 12:50:12 -04:00
|
|
|
|
2010-07-11 17:55:11 -04:00
|
|
|
return vst->events();
|
|
|
|
}
|
|
|
|
|
|
|
|
BufferSet::VSTBuffer::VSTBuffer (size_t c)
|
|
|
|
: _capacity (c)
|
|
|
|
{
|
|
|
|
_events = static_cast<VstEvents*> (malloc (sizeof (VstEvents) + _capacity * sizeof (VstEvent *)));
|
|
|
|
_midi_events = static_cast<VstMidiEvent*> (malloc (sizeof (VstMidiEvent) * _capacity));
|
|
|
|
|
|
|
|
if (_events == 0 || _midi_events == 0) {
|
|
|
|
free (_events);
|
|
|
|
free (_midi_events);
|
|
|
|
throw failed_constructor ();
|
|
|
|
}
|
|
|
|
|
|
|
|
_events->numEvents = 0;
|
|
|
|
_events->reserved = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BufferSet::VSTBuffer::~VSTBuffer ()
|
|
|
|
{
|
|
|
|
free (_events);
|
|
|
|
free (_midi_events);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BufferSet::VSTBuffer::clear ()
|
|
|
|
{
|
|
|
|
_events->numEvents = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-12-03 17:26:29 -05:00
|
|
|
BufferSet::VSTBuffer::push_back (Evoral::MIDIEvent<framepos_t> const & ev)
|
2010-07-11 17:55:11 -04:00
|
|
|
{
|
|
|
|
if (ev.size() > 3) {
|
|
|
|
/* XXX: this will silently drop MIDI messages longer than 3 bytes, so
|
|
|
|
they won't be passed to VST plugins or VSTis
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int const n = _events->numEvents;
|
|
|
|
assert (n < (int) _capacity);
|
|
|
|
|
|
|
|
_events->events[n] = reinterpret_cast<VstEvent*> (_midi_events + n);
|
|
|
|
VstMidiEvent* v = reinterpret_cast<VstMidiEvent*> (_events->events[n]);
|
2011-06-01 12:50:12 -04:00
|
|
|
|
2010-07-11 17:55:11 -04:00
|
|
|
v->type = kVstMidiType;
|
|
|
|
v->byteSize = sizeof (VstMidiEvent);
|
|
|
|
v->deltaFrames = ev.time ();
|
|
|
|
|
|
|
|
v->flags = 0;
|
|
|
|
v->detune = 0;
|
|
|
|
v->noteLength = 0;
|
|
|
|
v->noteOffset = 0;
|
|
|
|
v->reserved1 = 0;
|
|
|
|
v->reserved2 = 0;
|
|
|
|
v->noteOffVelocity = 0;
|
|
|
|
memcpy (v->midiData, ev.buffer(), ev.size());
|
|
|
|
v->midiData[3] = 0;
|
|
|
|
|
|
|
|
_events->numEvents++;
|
|
|
|
}
|
|
|
|
|
2011-11-21 12:42:29 -05:00
|
|
|
#endif /* WINDOWS_VST_SUPPORT */
|
2009-05-04 16:11:02 -04:00
|
|
|
|
2011-10-17 16:35:55 -04:00
|
|
|
/** Copy buffers of one type from `in' to this BufferSet */
|
|
|
|
void
|
|
|
|
BufferSet::read_from (const BufferSet& in, framecnt_t nframes, DataType type)
|
|
|
|
{
|
|
|
|
assert (available().get (type) >= in.count().get (type));
|
|
|
|
|
|
|
|
BufferSet::iterator o = begin (type);
|
|
|
|
for (BufferSet::const_iterator i = in.begin (type); i != in.end (type); ++i, ++o) {
|
|
|
|
o->read_from (*i, nframes);
|
|
|
|
}
|
|
|
|
|
|
|
|
_count.set (type, in.count().get (type));
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Copy buffers of all types from `in' to this BufferSet */
|
2008-06-02 17:41:35 -04:00
|
|
|
void
|
2010-12-03 17:26:29 -05:00
|
|
|
BufferSet::read_from (const BufferSet& in, framecnt_t nframes)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
assert(available() >= in.count());
|
|
|
|
|
|
|
|
// Copy all buffers 1:1
|
|
|
|
for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
|
2011-10-17 16:35:55 -04:00
|
|
|
read_from (in, nframes, *t);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-16 10:58:33 -04:00
|
|
|
void
|
2010-12-03 17:26:29 -05:00
|
|
|
BufferSet::merge_from (const BufferSet& in, framecnt_t nframes)
|
2009-06-16 10:58:33 -04:00
|
|
|
{
|
2009-06-29 10:29:53 -04:00
|
|
|
/* merge all input buffers into out existing buffers.
|
|
|
|
|
|
|
|
NOTE: if "in" contains more buffers than this set,
|
|
|
|
we will drop the extra buffers.
|
|
|
|
|
|
|
|
*/
|
2009-06-16 10:58:33 -04:00
|
|
|
|
|
|
|
for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
|
|
|
|
BufferSet::iterator o = begin(*t);
|
2009-10-19 21:24:31 -04:00
|
|
|
for (BufferSet::const_iterator i = in.begin(*t); i != in.end(*t) && o != end (*t); ++i, ++o) {
|
2009-06-16 10:58:33 -04:00
|
|
|
o->merge_from (*i, nframes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-12-03 17:26:29 -05:00
|
|
|
BufferSet::silence (framecnt_t nframes, framecnt_t offset)
|
2009-06-16 10:58:33 -04:00
|
|
|
{
|
|
|
|
for (std::vector<BufferVec>::iterator i = _buffers.begin(); i != _buffers.end(); ++i) {
|
|
|
|
for (BufferVec::iterator b = i->begin(); b != i->end(); ++b) {
|
|
|
|
(*b)->silence (nframes, offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
} // namespace ARDOUR
|
|
|
|
|