mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-07 07:14:56 +01:00
Use C++ for LV2 event buffer
This will allow to throw fatal exceptions when malloc fails.
This commit is contained in:
parent
0bf42af59d
commit
cb5b955a74
7 changed files with 37 additions and 44 deletions
|
|
@ -41,7 +41,6 @@ struct _VstMidiEvent;
|
||||||
typedef struct _VstMidiEvent VstMidiEvent;
|
typedef struct _VstMidiEvent VstMidiEvent;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct LV2_Evbuf_Impl LV2_Evbuf;
|
|
||||||
|
|
||||||
namespace ARDOUR {
|
namespace ARDOUR {
|
||||||
|
|
||||||
|
|
@ -50,6 +49,8 @@ class AudioBuffer;
|
||||||
class MidiBuffer;
|
class MidiBuffer;
|
||||||
class PortSet;
|
class PortSet;
|
||||||
|
|
||||||
|
struct LV2_Evbuf;
|
||||||
|
|
||||||
/** A set of buffers of various types.
|
/** A set of buffers of various types.
|
||||||
*
|
*
|
||||||
* These are mainly accessed from Session and passed around as scratch buffers
|
* These are mainly accessed from Session and passed around as scratch buffers
|
||||||
|
|
|
||||||
|
|
@ -14,21 +14,16 @@
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LV2_EVBUF_H
|
#pragma once
|
||||||
#define LV2_EVBUF_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
namespace ARDOUR {
|
||||||
extern "C" {
|
|
||||||
#else
|
|
||||||
#include <stdbool.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
An abstract/opaque LV2 event buffer.
|
An abstract/opaque LV2 event buffer.
|
||||||
*/
|
*/
|
||||||
typedef struct LV2_Evbuf_Impl LV2_Evbuf;
|
struct LV2_Evbuf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
An iterator over an LV2_Evbuf.
|
An iterator over an LV2_Evbuf.
|
||||||
|
|
@ -140,8 +135,4 @@ lv2_evbuf_write(LV2_Evbuf_Iterator* iter,
|
||||||
uint32_t size,
|
uint32_t size,
|
||||||
const uint8_t* data);
|
const uint8_t* data);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* LV2_EVBUF_H */
|
|
||||||
|
|
@ -46,7 +46,6 @@
|
||||||
#define PATH_MAX 1024
|
#define PATH_MAX 1024
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct LV2_Evbuf_Impl LV2_Evbuf;
|
|
||||||
|
|
||||||
namespace ARDOUR {
|
namespace ARDOUR {
|
||||||
|
|
||||||
|
|
@ -59,6 +58,7 @@ const void* lv2plugin_get_port_value(const char* port_symbol,
|
||||||
|
|
||||||
class AudioEngine;
|
class AudioEngine;
|
||||||
class Session;
|
class Session;
|
||||||
|
struct LV2_Evbuf;
|
||||||
|
|
||||||
class LIBARDOUR_API LV2Plugin : public ARDOUR::Plugin, public ARDOUR::Workee
|
class LIBARDOUR_API LV2Plugin : public ARDOUR::Plugin, public ARDOUR::Workee
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@
|
||||||
#include "ardour/port.h"
|
#include "ardour/port.h"
|
||||||
#include "ardour/port_set.h"
|
#include "ardour/port_set.h"
|
||||||
#include "ardour/lv2_plugin.h"
|
#include "ardour/lv2_plugin.h"
|
||||||
#include "lv2_evbuf.h"
|
#include "ardour/lv2_evbuf.h"
|
||||||
#include "ardour/uri_map.h"
|
#include "ardour/uri_map.h"
|
||||||
#if defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT || defined MACVST_SUPPORT
|
#if defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT || defined MACVST_SUPPORT
|
||||||
#include "ardour/vestige/vestige.h"
|
#include "ardour/vestige/vestige.h"
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,11 @@
|
||||||
#include <lv2/lv2plug.in/ns/ext/event/event.h>
|
#include <lv2/lv2plug.in/ns/ext/event/event.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "lv2_evbuf.h"
|
#include "ardour/lv2_evbuf.h"
|
||||||
|
|
||||||
struct LV2_Evbuf_Impl {
|
using namespace ARDOUR;
|
||||||
|
|
||||||
|
struct ARDOUR::LV2_Evbuf {
|
||||||
uint32_t capacity;
|
uint32_t capacity;
|
||||||
uint32_t atom_Chunk;
|
uint32_t atom_Chunk;
|
||||||
uint32_t atom_Sequence;
|
uint32_t atom_Sequence;
|
||||||
|
|
@ -42,9 +44,9 @@ lv2_evbuf_pad_size(uint32_t size)
|
||||||
}
|
}
|
||||||
|
|
||||||
LV2_Evbuf*
|
LV2_Evbuf*
|
||||||
lv2_evbuf_new(uint32_t capacity,
|
ARDOUR::lv2_evbuf_new (uint32_t capacity,
|
||||||
uint32_t atom_Chunk,
|
uint32_t atom_Chunk,
|
||||||
uint32_t atom_Sequence)
|
uint32_t atom_Sequence)
|
||||||
{
|
{
|
||||||
// FIXME: memory must be 64-bit aligned
|
// FIXME: memory must be 64-bit aligned
|
||||||
LV2_Evbuf* evbuf = (LV2_Evbuf*)malloc(
|
LV2_Evbuf* evbuf = (LV2_Evbuf*)malloc(
|
||||||
|
|
@ -57,13 +59,13 @@ lv2_evbuf_new(uint32_t capacity,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
lv2_evbuf_free(LV2_Evbuf* evbuf)
|
ARDOUR::lv2_evbuf_free (LV2_Evbuf* evbuf)
|
||||||
{
|
{
|
||||||
free(evbuf);
|
free(evbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
lv2_evbuf_reset(LV2_Evbuf* evbuf, bool input)
|
ARDOUR::lv2_evbuf_reset (LV2_Evbuf* evbuf, bool input)
|
||||||
{
|
{
|
||||||
if (input) {
|
if (input) {
|
||||||
evbuf->atom.atom.size = sizeof(LV2_Atom_Sequence_Body);
|
evbuf->atom.atom.size = sizeof(LV2_Atom_Sequence_Body);
|
||||||
|
|
@ -75,7 +77,7 @@ lv2_evbuf_reset(LV2_Evbuf* evbuf, bool input)
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t
|
uint32_t
|
||||||
lv2_evbuf_get_size(LV2_Evbuf* evbuf)
|
ARDOUR::lv2_evbuf_get_size (LV2_Evbuf* evbuf)
|
||||||
{
|
{
|
||||||
assert(evbuf->atom.atom.type != evbuf->atom_Sequence
|
assert(evbuf->atom.atom.type != evbuf->atom_Sequence
|
||||||
|| evbuf->atom.atom.size >= sizeof(LV2_Atom_Sequence_Body));
|
|| evbuf->atom.atom.size >= sizeof(LV2_Atom_Sequence_Body));
|
||||||
|
|
@ -86,26 +88,26 @@ lv2_evbuf_get_size(LV2_Evbuf* evbuf)
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t
|
uint32_t
|
||||||
lv2_evbuf_get_capacity(LV2_Evbuf* evbuf)
|
ARDOUR::lv2_evbuf_get_capacity (LV2_Evbuf* evbuf)
|
||||||
{
|
{
|
||||||
return evbuf->capacity;
|
return evbuf->capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void*
|
void*
|
||||||
lv2_evbuf_get_buffer(LV2_Evbuf* evbuf)
|
ARDOUR::lv2_evbuf_get_buffer (LV2_Evbuf* evbuf)
|
||||||
{
|
{
|
||||||
return &evbuf->atom;
|
return &evbuf->atom;
|
||||||
}
|
}
|
||||||
|
|
||||||
LV2_Evbuf_Iterator
|
LV2_Evbuf_Iterator
|
||||||
lv2_evbuf_begin(LV2_Evbuf* evbuf)
|
ARDOUR::lv2_evbuf_begin (LV2_Evbuf* evbuf)
|
||||||
{
|
{
|
||||||
LV2_Evbuf_Iterator iter = { evbuf, 0 };
|
LV2_Evbuf_Iterator iter = { evbuf, 0 };
|
||||||
return iter;
|
return iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
LV2_Evbuf_Iterator
|
LV2_Evbuf_Iterator
|
||||||
lv2_evbuf_end(LV2_Evbuf* evbuf)
|
ARDOUR::lv2_evbuf_end (LV2_Evbuf* evbuf)
|
||||||
{
|
{
|
||||||
const uint32_t size = lv2_evbuf_get_size(evbuf);
|
const uint32_t size = lv2_evbuf_get_size(evbuf);
|
||||||
const LV2_Evbuf_Iterator iter = { evbuf, lv2_evbuf_pad_size(size) };
|
const LV2_Evbuf_Iterator iter = { evbuf, lv2_evbuf_pad_size(size) };
|
||||||
|
|
@ -113,13 +115,13 @@ lv2_evbuf_end(LV2_Evbuf* evbuf)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
lv2_evbuf_is_valid(LV2_Evbuf_Iterator iter)
|
ARDOUR::lv2_evbuf_is_valid(LV2_Evbuf_Iterator iter)
|
||||||
{
|
{
|
||||||
return iter.offset < lv2_evbuf_get_size(iter.evbuf);
|
return iter.offset < lv2_evbuf_get_size(iter.evbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
LV2_Evbuf_Iterator
|
LV2_Evbuf_Iterator
|
||||||
lv2_evbuf_next(LV2_Evbuf_Iterator iter)
|
ARDOUR::lv2_evbuf_next (LV2_Evbuf_Iterator iter)
|
||||||
{
|
{
|
||||||
if (!lv2_evbuf_is_valid(iter)) {
|
if (!lv2_evbuf_is_valid(iter)) {
|
||||||
return iter;
|
return iter;
|
||||||
|
|
@ -140,12 +142,12 @@ lv2_evbuf_next(LV2_Evbuf_Iterator iter)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
lv2_evbuf_get(LV2_Evbuf_Iterator iter,
|
ARDOUR::lv2_evbuf_get (LV2_Evbuf_Iterator iter,
|
||||||
uint32_t* samples,
|
uint32_t* samples,
|
||||||
uint32_t* subframes,
|
uint32_t* subframes,
|
||||||
uint32_t* type,
|
uint32_t* type,
|
||||||
uint32_t* size,
|
uint32_t* size,
|
||||||
uint8_t** data)
|
uint8_t** data)
|
||||||
{
|
{
|
||||||
*samples = *subframes = *type = *size = 0;
|
*samples = *subframes = *type = *size = 0;
|
||||||
*data = NULL;
|
*data = NULL;
|
||||||
|
|
@ -168,12 +170,12 @@ lv2_evbuf_get(LV2_Evbuf_Iterator iter,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
lv2_evbuf_write(LV2_Evbuf_Iterator* iter,
|
ARDOUR::lv2_evbuf_write (LV2_Evbuf_Iterator* iter,
|
||||||
uint32_t samples,
|
uint32_t samples,
|
||||||
uint32_t subframes,
|
uint32_t subframes,
|
||||||
uint32_t type,
|
uint32_t type,
|
||||||
uint32_t size,
|
uint32_t size,
|
||||||
const uint8_t* data)
|
const uint8_t* data)
|
||||||
{
|
{
|
||||||
LV2_Atom_Sequence* aseq = (LV2_Atom_Sequence*)&iter->evbuf->atom;
|
LV2_Atom_Sequence* aseq = (LV2_Atom_Sequence*)&iter->evbuf->atom;
|
||||||
|
|
||||||
|
|
@ -64,6 +64,7 @@
|
||||||
#include "ardour/audioengine.h"
|
#include "ardour/audioengine.h"
|
||||||
#include "ardour/directory_names.h"
|
#include "ardour/directory_names.h"
|
||||||
#include "ardour/debug.h"
|
#include "ardour/debug.h"
|
||||||
|
#include "ardour/lv2_evbuf.h"
|
||||||
#include "ardour/lv2_plugin.h"
|
#include "ardour/lv2_plugin.h"
|
||||||
#include "ardour/midi_patch_manager.h"
|
#include "ardour/midi_patch_manager.h"
|
||||||
#include "ardour/session.h"
|
#include "ardour/session.h"
|
||||||
|
|
@ -116,8 +117,6 @@
|
||||||
#include <lv2/lv2plug.in/ns/ext/options/options.h>
|
#include <lv2/lv2plug.in/ns/ext/options/options.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "lv2_evbuf.h"
|
|
||||||
|
|
||||||
#ifdef HAVE_SUIL
|
#ifdef HAVE_SUIL
|
||||||
#include <suil/suil.h>
|
#include <suil/suil.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -435,7 +435,7 @@ def build(bld):
|
||||||
#obj.add_objects = 'default/libs/surfaces/control_protocol/smpte_1.o'
|
#obj.add_objects = 'default/libs/surfaces/control_protocol/smpte_1.o'
|
||||||
|
|
||||||
if bld.is_defined('HAVE_LILV') :
|
if bld.is_defined('HAVE_LILV') :
|
||||||
obj.source += ['lv2_plugin.cc', 'lv2_evbuf.c', 'uri_map.cc']
|
obj.source += ['lv2_plugin.cc', 'lv2_evbuf.cc', 'uri_map.cc']
|
||||||
obj.uselib += ['LILV']
|
obj.uselib += ['LILV']
|
||||||
if bld.is_defined('HAVE_SUIL'):
|
if bld.is_defined('HAVE_SUIL'):
|
||||||
if bld.is_defined('YTK'):
|
if bld.is_defined('YTK'):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue