VST report audioMasterPinConnected according to Pin Management
[ardour.git] / libs / ardour / rdff.c
index 28fd63c4c4e8b88b99843d7a4ec4d83b1a53e578..ca8e1abf1fd6d07a155ea957c2cca4123188e7b6 100644 (file)
@@ -1,21 +1,18 @@
 /*
   RDFF - RDF in RIFF
   Copyright 2011 David Robillard <http://drobilla.net>
-  This 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 software 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 sofware; if not, write to the Free Software
-  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  02110-1301 USA.
+
+  Permission to use, copy, modify, and/or distribute this software for any
+  purpose with or without fee is hereby granted, provided that the above
+  copyright notice and this permission notice appear in all copies.
+
+  THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
 
 #include <assert.h>
@@ -29,8 +26,8 @@
 #define CHUNK_ID_LEN 4
 
 static const char FILE_TYPE[CHUNK_ID_LEN]  = "RDFF";  /* RDFF File ID */
-static const char CHUNK_KVAL[CHUNK_ID_LEN] = "KVAL";  /* Key/Value Chunk ID */
-static const char CHUNK_URID[CHUNK_ID_LEN] = "URID";  /* URI-ID Chunk ID*/
+static const char CHUNK_TRIP[CHUNK_ID_LEN] = "trip";  /* Triple Chunk ID */
+static const char CHUNK_URID[CHUNK_ID_LEN] = "urid";  /* URI-ID Chunk ID*/
 
 struct _RDFF {
        FILE*    fd;
@@ -52,7 +49,7 @@ rdff_open(const char* path, bool write)
        if (write) {
                fwrite("RIFF", CHUNK_ID_LEN, 1, fd);    /* RIFF chunk ID */
                fwrite(&size, sizeof(size), 1, fd);     /* RIFF chunk size */
-               fwrite(FILE_TYPE, CHUNK_ID_LEN, 1, fd); /* LV2 RIFF file type */
+               fwrite(FILE_TYPE, CHUNK_ID_LEN, 1, fd); /* File type */
        } else {
                char magic[CHUNK_ID_LEN];
                if (fread(magic, CHUNK_ID_LEN, 1, fd) != 1
@@ -71,7 +68,8 @@ rdff_open(const char* path, bool write)
                if (fread(magic, CHUNK_ID_LEN, 1, fd) != 1
                    || strncmp(magic, FILE_TYPE, CHUNK_ID_LEN)) {
                        fclose(fd);
-                       fprintf(stderr, "%s: error: not an LV2 RIFF file\n", path);
+                       fprintf(stderr, "%s: error: not an %s RIFF file\n",
+                               FILE_TYPE, path);
                        return NULL;
                }
        }
@@ -91,8 +89,8 @@ rdff_open(const char* path, bool write)
 RDFFStatus
 rdff_write_uri(RDFF        file,
                uint32_t    id,
-               const char* uri,
-               uint32_t    len)
+               uint32_t    len,
+               const char* uri)
 {
        const uint32_t chunk_size = sizeof(id) + len + 1;
        WRITE(CHUNK_URID,  CHUNK_ID_LEN,       1, file->fd);
@@ -107,20 +105,22 @@ rdff_write_uri(RDFF        file,
 }
 
 RDFFStatus
-rdff_write_value(RDFF        file,
-                 uint32_t    key,
-                 const void* value,
-                 uint32_t    size,
-                 uint32_t    type)
+rdff_write_triple(RDFF        file,
+                  uint32_t    subject,
+                  uint32_t    predicate,
+                  uint32_t    object_type,
+                  uint32_t    object_size,
+                  const void* object)
 {
-       const uint32_t chunk_size = sizeof(key) + sizeof(type) + sizeof(size) + size;
-       WRITE(CHUNK_KVAL,  CHUNK_ID_LEN,       1, file->fd);
-       WRITE(&chunk_size, sizeof(chunk_size), 1, file->fd);
-       WRITE(&key,        sizeof(key),        1, file->fd);
-       WRITE(&type,       sizeof(type),       1, file->fd);
-       WRITE(&size,       sizeof(size),       1, file->fd);
-       WRITE(value,       size,               1, file->fd);
-       if ((size % 2)) {
+       const uint32_t chunk_size = sizeof(RDFFTripleChunk) + object_size;
+       WRITE(CHUNK_TRIP,   CHUNK_ID_LEN,        1, file->fd);
+       WRITE(&chunk_size,  sizeof(chunk_size),  1, file->fd);
+       WRITE(&subject,     sizeof(subject),     1, file->fd);
+       WRITE(&predicate,   sizeof(predicate),   1, file->fd);
+       WRITE(&object_type, sizeof(object_type), 1, file->fd);
+       WRITE(&object_size, sizeof(object_size), 1, file->fd);
+       WRITE(object,       object_size,         1, file->fd);
+       if ((object_size % 2)) {
                WRITE("", 1, 1, file->fd);  /* write pad */
        }
        file->size += 8 + chunk_size;
@@ -154,6 +154,19 @@ rdff_read_chunk(RDFF        file,
        return RDFF_STATUS_OK;
 }
 
+bool
+rdff_chunk_is_uri(RDFFChunk* chunk)
+
+{
+       return !strncmp(chunk->type, CHUNK_URID, CHUNK_ID_LEN);
+}
+
+bool
+rdff_chunk_is_triple(RDFFChunk* chunk)
+{
+       return !strncmp(chunk->type, CHUNK_TRIP, CHUNK_ID_LEN);
+}
+
 void
 rdff_close(RDFF file)
 {
@@ -192,17 +205,18 @@ main(int argc, char** argv)
        char uri[64];
        for (int i = 0; i < N_URIS; ++i) {
                snprintf(uri, sizeof(uri), "http://example.org/uri%02d", i + 1);
-               rdff_write_uri(file, i + 1, uri, strlen(uri) + 1);
+               rdff_write_uri(file, i + 1, strlen(uri), uri);
        }
-       
+
        char val[6];
        for (int i = 0; i < N_RECORDS; ++i) {
                snprintf(val, sizeof(val), "VAL%02d", i);
-               rdff_write_value(file,
-                                     rand() % N_URIS,
-                                     val,
-                                     sizeof(val),
-                                     0);
+               rdff_write_triple(file,
+                                 0,
+                                 rand() % N_URIS,
+                                 0,
+                                 sizeof(val),
+                                 val);
        }
 
        rdff_close(file);
@@ -215,8 +229,8 @@ main(int argc, char** argv)
        chunk->size = 0;
        for (int i = 0; i < N_URIS; ++i) {
                if (rdff_read_chunk(file, &chunk)
-                   || strncmp(chunk->type, "URID", 4)) {
-                       fprintf(stderr, "error: expected URID chunk\n");
+                   || strncmp(chunk->type, CHUNK_URID, 4)) {
+                       fprintf(stderr, "error: expected %s chunk\n", CHUNK_URID);
                        goto fail;
                }
                RDFFURIChunk* body = (RDFFURIChunk*)chunk->data;
@@ -225,12 +239,12 @@ main(int argc, char** argv)
 
        for (int i = 0; i < N_RECORDS; ++i) {
                if (rdff_read_chunk(file, &chunk)
-                   || strncmp(chunk->type, "KVAL", 4)) {
-                       fprintf(stderr, "error: expected KVAL chunk\n");
+                   || strncmp(chunk->type, CHUNK_TRIP, 4)) {
+                       fprintf(stderr, "error: expected %s chunk\n", CHUNK_TRIP);
                        goto fail;
                }
-               RDFFValueChunk* body = (RDFFValueChunk*)chunk->data;
-               printf("KEY %d = %s\n", body->key, body->value);
+               RDFFTripleChunk* body = (RDFFTripleChunk*)chunk->data;
+               printf("KEY %d = %s\n", body->predicate, body->object);
        }
 
        free(chunk);