aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2019-06-14 11:03:02 +0200
committerHanspeter Portner <dev@open-music-kontrollers.ch>2019-06-14 11:03:02 +0200
commitc04f3bcdc8b380d4ef3931d89d337ce68d607aca (patch)
tree646084dfe01f7f9338690deb768ed3d91ece887b
parentc9bb19d7bf4e5c6dbb81c9b564a331beb26c00f5 (diff)
downloadosc.lv2-c04f3bcdc8b380d4ef3931d89d337ce68d607aca.tar.xz
prototype reader message path matching.
-rw-r--r--VERSION2
-rw-r--r--osc.lv2/reader.h51
-rw-r--r--osc.lv2/util.h4
3 files changed, 54 insertions, 3 deletions
diff --git a/VERSION b/VERSION
index 841597f..025c316 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.119
+0.1.121
diff --git a/osc.lv2/reader.h b/osc.lv2/reader.h
index 8e0ae45..b2dd827 100644
--- a/osc.lv2/reader.h
+++ b/osc.lv2/reader.h
@@ -24,14 +24,26 @@
#include <osc.lv2/osc.h>
#include <osc.lv2/endian.h>
+#include <osc.lv2/util.h>
#ifdef __cplusplus
extern "C" {
#endif
+
+typedef struct _LV2_OSC_Tree LV2_OSC_Tree;
typedef struct _LV2_OSC_Reader LV2_OSC_Reader;
typedef struct _LV2_OSC_Item LV2_OSC_Item;
typedef struct _LV2_OSC_Arg LV2_OSC_Arg;
+typedef void (*LV2_OSC_Branch)(const char *path, LV2_OSC_Reader *reader,
+ LV2_OSC_Arg *arg, void *data);
+
+struct _LV2_OSC_Tree {
+ const char *name;
+ const LV2_OSC_Tree *trees;
+ LV2_OSC_Branch branch;
+ void *data;
+};
struct _LV2_OSC_Reader {
const uint8_t *buf;
@@ -564,6 +576,45 @@ lv2_osc_reader_is_message(LV2_OSC_Reader *reader)
return reader->ptr[0] == '/'; //FIXME check path
}
+static inline void
+_lv2_osc_trees_internal(LV2_OSC_Reader *reader, const char *path, const char *from,
+ LV2_OSC_Arg *arg, const LV2_OSC_Tree *trees)
+{
+ const char *ptr = strchr(from, '/');
+
+ const size_t len = ptr
+ ? (size_t)(ptr - from)
+ : strlen(from);
+
+ for(const LV2_OSC_Tree *tree = trees; tree && tree->name; tree++)
+ {
+ if(lv2_osc_pattern_match(from, tree->name, len))
+ {
+ if(tree->trees && ptr)
+ {
+ from = &ptr[1];
+
+ _lv2_osc_trees_internal(reader, path, from, arg, tree->trees);
+ }
+ else if(tree->branch && !ptr)
+ {
+ LV2_OSC_Reader reader_clone = *reader;
+ tree->branch(path, &reader_clone, arg, tree->data);
+ }
+ }
+ }
+}
+
+static inline void
+lv2_osc_reader_match(LV2_OSC_Reader *reader, size_t len, const LV2_OSC_Tree *trees)
+{
+ LV2_OSC_Arg *arg = OSC_READER_MESSAGE_BEGIN(reader, len);
+ const char *path = arg->path;
+ const char *from = &path[1];
+
+ _lv2_osc_trees_internal(reader, path, from, arg, trees);
+}
+
#ifdef __cplusplus
} // extern "C"
#endif
diff --git a/osc.lv2/util.h b/osc.lv2/util.h
index 0a0be1c..86d38ad 100644
--- a/osc.lv2/util.h
+++ b/osc.lv2/util.h
@@ -71,7 +71,7 @@ static const char valid_format_chars [] = {
};
static bool
-_lv2_osc_pattern_match(const char *from, const char *name, size_t len)
+lv2_osc_pattern_match(const char *from, const char *name, size_t len)
{
size_t nbrace = 0;
@@ -144,7 +144,7 @@ _lv2_osc_hooks_internal(const char *path, const char *from,
for(const LV2_OSC_Hook *hook = hooks; hook && hook->name; hook++)
{
- if(_lv2_osc_pattern_match(from, hook->name, len))
+ if(lv2_osc_pattern_match(from, hook->name, len))
{
if(hook->hooks && ptr)
{