aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-06-05 19:47:16 +0000
committerDavid Robillard <d@drobilla.net>2012-06-05 19:47:16 +0000
commitc04965a404e216b34844cce2c93e89f1f0045442 (patch)
treeb47edbd426f258747c163b9ed3d92a7bd6f3d3b7
parent9d786d82d4f139c5e20c59e42926d20b7a221614 (diff)
downloadjalv-c04965a404e216b34844cce2c93e89f1f0045442.tar.gz
jalv-c04965a404e216b34844cce2c93e89f1f0045442.tar.bz2
jalv-c04965a404e216b34844cce2c93e89f1f0045442.zip
Use LV2 buf-size extension.
git-svn-id: http://svn.drobilla.net/lad/trunk/jalv@4493 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--src/jalv.c46
-rw-r--r--src/jalv_internal.h1
-rw-r--r--wscript2
3 files changed, 47 insertions, 2 deletions
diff --git a/src/jalv.c b/src/jalv.c
index 2c2a77c..7e70ee4 100644
--- a/src/jalv.c
+++ b/src/jalv.c
@@ -37,6 +37,7 @@
#endif
#include "lv2/lv2plug.in/ns/ext/atom/atom.h"
+#include "lv2/lv2plug.in/ns/ext/buf-size/buf-size.h"
#include "lv2/lv2plug.in/ns/ext/event/event.h"
#include "lv2/lv2plug.in/ns/ext/presets/presets.h"
#include "lv2/lv2plug.in/ns/ext/time/time.h"
@@ -108,13 +109,15 @@ static LV2_Feature instance_feature = { NS_EXT "instance-access", NULL };
static LV2_Feature make_path_feature = { LV2_STATE__makePath, NULL };
static LV2_Feature schedule_feature = { LV2_WORKER__schedule, NULL };
static LV2_Feature log_feature = { LV2_LOG__log, NULL };
+static LV2_Feature buf_size_feature = { LV2_BUF_SIZE__access, NULL };
-const LV2_Feature* features[9] = {
+const LV2_Feature* features[10] = {
&uri_map_feature, &map_feature, &unmap_feature,
&instance_feature,
&make_path_feature,
&schedule_feature,
&log_feature,
+ &buf_size_feature,
NULL
};
@@ -306,6 +309,7 @@ int
jack_buffer_size_cb(jack_nframes_t nframes, void* data)
{
Jalv* const host = (Jalv*)data;
+ host->block_length = nframes;
host->buf_size_set = true;
#ifdef jack_port_type_get_buffer_size
host->midi_buf_size = jack_port_type_get_buffer_size(
@@ -648,6 +652,40 @@ jalv_emit_ui_events(Jalv* host)
return true;
}
+static LV2_Buf_Size_Status
+jalv_get_sample_count(LV2_Buf_Size_Access_Handle handle,
+ uint32_t* min,
+ uint32_t* max,
+ uint32_t* multiple_of,
+ uint32_t* power_of)
+{
+ Jalv* jalv = (Jalv*)handle;
+ // TODO: Is this actually guaranteed with Jack2?
+ *min = jalv->block_length;
+ *max = jalv->block_length;
+ *multiple_of = 1;
+ *power_of = 0;
+ if (!(jalv->block_length & (jalv->block_length - 1))) {
+ // Block length is a power of 2
+ *power_of = 2;
+ *multiple_of = 2;
+ }
+ return 0;
+}
+
+static size_t
+jalv_get_buf_size(LV2_Buf_Size_Access_Handle handle,
+ LV2_URID type,
+ LV2_URID subtype)
+{
+ Jalv* jalv = (Jalv*)handle;
+ if (!jalv->buf_size_set) {
+ fprintf(stderr, "Buffer size requested but it is not yet known.\n");
+ return 0;
+ }
+ return 0;
+}
+
static void
signal_handler(int ignored)
{
@@ -660,6 +698,7 @@ main(int argc, char** argv)
Jalv host;
memset(&host, '\0', sizeof(Jalv));
host.prog_name = argv[0];
+ host.block_length = 4096; // Should be set by jack_buffer_size_cb
host.midi_buf_size = 1024; // Should be set by jack_buffer_size_cb
host.play_state = JALV_PAUSED;
@@ -714,6 +753,10 @@ main(int argc, char** argv)
LV2_Log_Log log = { &host, jalv_printf, jalv_vprintf };
log_feature.data = &log;
+ LV2_Buf_Size_Access access = { &host, sizeof(LV2_Buf_Size_Access),
+ jalv_get_sample_count, jalv_get_buf_size };
+ buf_size_feature.data = &access;
+
zix_sem_init(&exit_sem, 0);
host.done = &exit_sem;
@@ -841,6 +884,7 @@ main(int argc, char** argv)
if (!host.jack_client)
die("Failed to connect to JACK.\n");
+ host.block_length = jack_get_buffer_size(host.jack_client);
#ifdef HAVE_JACK_PORT_TYPE_GET_BUFFER_SIZE
host.midi_buf_size = jack_port_type_get_buffer_size(
host.jack_client, JACK_DEFAULT_MIDI_TYPE);
diff --git a/src/jalv_internal.h b/src/jalv_internal.h
index b76af60..9a58d1d 100644
--- a/src/jalv_internal.h
+++ b/src/jalv_internal.h
@@ -163,6 +163,7 @@ typedef struct {
SuilInstance* ui_instance; ///< Plugin UI instance (shared library)
void* window; ///< Window (if applicable)
struct Port* ports; ///< Port array of size num_ports
+ uint32_t block_length; ///< Jack buffer size (block length)
size_t midi_buf_size; ///< Size of MIDI port buffers
uint32_t num_ports; ///< Size of the two following arrays:
uint32_t longest_sym; ///< Longest port symbol
diff --git a/wscript b/wscript
index a0ed02b..ffad7f6 100644
--- a/wscript
+++ b/wscript
@@ -33,7 +33,7 @@ def configure(conf):
autowaf.configure(conf)
autowaf.display_header('Jalv Configuration')
- autowaf.check_pkg(conf, 'lv2', atleast_version='1.0.0', uselib_store='LV2')
+ autowaf.check_pkg(conf, 'lv2', atleast_version='1.0.5', uselib_store='LV2')
autowaf.check_pkg(conf, 'lilv-0', uselib_store='LILV',
atleast_version='0.14.0', mandatory=True)
autowaf.check_pkg(conf, 'serd-0', uselib_store='SERD',