~hp/vm.lv2

2e59790b846ab720d6ee46a835dfcec10f46037a — Hanspeter Portner 1 year, 7 months ago
Squashed 'subprojects/props.lv2/' content from commit 769060d7

git-subtree-dir: subprojects/props.lv2
git-subtree-split: 769060d7beedaf0dc848d25947c28897eacf5196
A  => .gitignore +5 -0
@@ 1,5 @@
# SPDX-FileCopyrightText: Hanspeter Portner <dev@open-music-kontrollers.ch>
# SPDX-License-Identifier: CC0-1.0

tags
*.taghl

A  => .gitlab-ci.yml +5 -0
@@ 1,5 @@
# SPDX-FileCopyrightText: Hanspeter Portner <dev@open-music-kontrollers.ch>
# SPDX-License-Identifier: CC0-1.0

include:
  - local: 'gitlab-ci/generic.yml'

A  => LICENSES/Artistic-2.0.txt +85 -0
@@ 1,85 @@
The Artistic License 2.0

Copyright (c) 2000-2006, The Perl Foundation.

Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

Preamble

This license establishes the terms under which a given free software Package may be copied, modified, distributed, and/or redistributed. The intent is that the Copyright Holder maintains some artistic control over the development of that Package while still keeping the Package available as open source and free software.

You are always permitted to make arrangements wholly outside of this license directly with the Copyright Holder of a given Package.  If the terms of this license do not permit the full use that you propose to make of the Package, you should contact the Copyright Holder and seek a different licensing arrangement.

Definitions

     "Copyright Holder" means the individual(s) or organization(s) named in the copyright notice for the entire Package.

     "Contributor" means any party that has contributed code or other material to the Package, in accordance with the Copyright Holder's procedures.

     "You" and "your" means any person who would like to copy, distribute, or modify the Package.

     "Package" means the collection of files distributed by the Copyright Holder, and derivatives of that collection and/or of those files. A given Package may consist of either the Standard Version, or a Modified Version.

     "Distribute" means providing a copy of the Package or making it accessible to anyone else, or in the case of a company or organization, to others outside of your company or organization.

     "Distributor Fee" means any fee that you charge for Distributing this Package or providing support for this Package to another party.  It does not mean licensing fees.

     "Standard Version" refers to the Package if it has not been modified, or has been modified only in ways explicitly requested by the Copyright Holder.

     "Modified Version" means the Package, if it has been changed, and such changes were not explicitly requested by the Copyright Holder.

     "Original License" means this Artistic License as Distributed with the Standard Version of the Package, in its current version or as it may be modified by The Perl Foundation in the future.

     "Source" form means the source code, documentation source, and configuration files for the Package.

     "Compiled" form means the compiled bytecode, object code, binary, or any other form resulting from mechanical transformation or translation of the Source form.

Permission for Use and Modification Without Distribution

(1) You are permitted to use the Standard Version and create and use Modified Versions for any purpose without restriction, provided that you do not Distribute the Modified Version.

Permissions for Redistribution of the Standard Version

(2) You may Distribute verbatim copies of the Source form of the Standard Version of this Package in any medium without restriction, either gratis or for a Distributor Fee, provided that you duplicate all of the original copyright notices and associated disclaimers.  At your discretion, such verbatim copies may or may not include a Compiled form of the Package.

(3) You may apply any bug fixes, portability changes, and other modifications made available from the Copyright Holder.  The resulting Package will still be considered the Standard Version, and as such will be subject to the Original License.

Distribution of Modified Versions of the Package as Source

(4) You may Distribute your Modified Version as Source (either gratis or for a Distributor Fee, and with or without a Compiled form of the Modified Version) provided that you clearly document how it differs from the Standard Version, including, but not limited to, documenting any non-standard features, executables, or modules, and provided that you do at least ONE of the following:

     (a) make the Modified Version available to the Copyright Holder of the Standard Version, under the Original License, so that the Copyright Holder may include your modifications in the Standard Version.
     (b) ensure that installation of your Modified Version does not prevent the user installing or running the Standard Version. In addition, the Modified Version must bear a name that is different from the name of the Standard Version.
     (c) allow anyone who receives a copy of the Modified Version to make the Source form of the Modified Version available to others under

          (i) the Original License or
          (ii) a license that permits the licensee to freely copy, modify and redistribute the Modified Version using the same licensing terms that apply to the copy that the licensee received, and requires that the Source form of the Modified Version, and of any works derived from it, be made freely available in that license fees are prohibited but Distributor Fees are allowed.

Distribution of Compiled Forms of the Standard Version or Modified Versions without the Source

(5)  You may Distribute Compiled forms of the Standard Version without the Source, provided that you include complete instructions on how to get the Source of the Standard Version.  Such instructions must be valid at the time of your distribution.  If these instructions, at any time while you are carrying out such distribution, become invalid, you must provide new instructions on demand or cease further distribution. If you provide valid instructions or cease distribution within thirty days after you become aware that the instructions are invalid, then you do not forfeit any of your rights under this license.

(6)  You may Distribute a Modified Version in Compiled form without the Source, provided that you comply with Section 4 with respect to the Source of the Modified Version.

Aggregating or Linking the Package

(7)  You may aggregate the Package (either the Standard Version or Modified Version) with other packages and Distribute the resulting aggregation provided that you do not charge a licensing fee for the Package.  Distributor Fees are permitted, and licensing fees for other components in the aggregation are permitted. The terms of this license apply to the use and Distribution of the Standard or Modified Versions as included in the aggregation.

(8) You are permitted to link Modified and Standard Versions with other works, to embed the Package in a larger work of your own, or to build stand-alone binary or bytecode versions of applications that include the Package, and Distribute the result without restriction, provided the result does not expose a direct interface to the Package.

Items That are Not Considered Part of a Modified Version

(9) Works (including, but not limited to, modules and scripts) that merely extend or make use of the Package, do not, by themselves, cause the Package to be a Modified Version.  In addition, such works are not considered parts of the Package itself, and are not subject to the terms of this license.

General Provisions

(10)  Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

(11)  If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

(12)  This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

(13)  This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.

(14)  Disclaimer of Warranty:
THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

A  => LICENSES/CC0-1.0.txt +121 -0
@@ 1,121 @@
Creative Commons Legal Code

CC0 1.0 Universal

    CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
    LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
    ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
    INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
    REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
    PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
    THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
    HEREUNDER.

Statement of Purpose

The laws of most jurisdictions throughout the world automatically confer
exclusive Copyright and Related Rights (defined below) upon the creator
and subsequent owner(s) (each and all, an "owner") of an original work of
authorship and/or a database (each, a "Work").

Certain owners wish to permanently relinquish those rights to a Work for
the purpose of contributing to a commons of creative, cultural and
scientific works ("Commons") that the public can reliably and without fear
of later claims of infringement build upon, modify, incorporate in other
works, reuse and redistribute as freely as possible in any form whatsoever
and for any purposes, including without limitation commercial purposes.
These owners may contribute to the Commons to promote the ideal of a free
culture and the further production of creative, cultural and scientific
works, or to gain reputation or greater distribution for their Work in
part through the use and efforts of others.

For these and/or other purposes and motivations, and without any
expectation of additional consideration or compensation, the person
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
is an owner of Copyright and Related Rights in the Work, voluntarily
elects to apply CC0 to the Work and publicly distribute the Work under its
terms, with knowledge of his or her Copyright and Related Rights in the
Work and the meaning and intended legal effect of CC0 on those rights.

1. Copyright and Related Rights. A Work made available under CC0 may be
protected by copyright and related or neighboring rights ("Copyright and
Related Rights"). Copyright and Related Rights include, but are not
limited to, the following:

  i. the right to reproduce, adapt, distribute, perform, display,
     communicate, and translate a Work;
 ii. moral rights retained by the original author(s) and/or performer(s);
iii. publicity and privacy rights pertaining to a person's image or
     likeness depicted in a Work;
 iv. rights protecting against unfair competition in regards to a Work,
     subject to the limitations in paragraph 4(a), below;
  v. rights protecting the extraction, dissemination, use and reuse of data
     in a Work;
 vi. database rights (such as those arising under Directive 96/9/EC of the
     European Parliament and of the Council of 11 March 1996 on the legal
     protection of databases, and under any national implementation
     thereof, including any amended or successor version of such
     directive); and
vii. other similar, equivalent or corresponding rights throughout the
     world based on applicable law or treaty, and any national
     implementations thereof.

2. Waiver. To the greatest extent permitted by, but not in contravention
of, applicable law, Affirmer hereby overtly, fully, permanently,
irrevocably and unconditionally waives, abandons, and surrenders all of
Affirmer's Copyright and Related Rights and associated claims and causes
of action, whether now known or unknown (including existing as well as
future claims and causes of action), in the Work (i) in all territories
worldwide, (ii) for the maximum duration provided by applicable law or
treaty (including future time extensions), (iii) in any current or future
medium and for any number of copies, and (iv) for any purpose whatsoever,
including without limitation commercial, advertising or promotional
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
member of the public at large and to the detriment of Affirmer's heirs and
successors, fully intending that such Waiver shall not be subject to
revocation, rescission, cancellation, termination, or any other legal or
equitable action to disrupt the quiet enjoyment of the Work by the public
as contemplated by Affirmer's express Statement of Purpose.

3. Public License Fallback. Should any part of the Waiver for any reason
be judged legally invalid or ineffective under applicable law, then the
Waiver shall be preserved to the maximum extent permitted taking into
account Affirmer's express Statement of Purpose. In addition, to the
extent the Waiver is so judged Affirmer hereby grants to each affected
person a royalty-free, non transferable, non sublicensable, non exclusive,
irrevocable and unconditional license to exercise Affirmer's Copyright and
Related Rights in the Work (i) in all territories worldwide, (ii) for the
maximum duration provided by applicable law or treaty (including future
time extensions), (iii) in any current or future medium and for any number
of copies, and (iv) for any purpose whatsoever, including without
limitation commercial, advertising or promotional purposes (the
"License"). The License shall be deemed effective as of the date CC0 was
applied by Affirmer to the Work. Should any part of the License for any
reason be judged legally invalid or ineffective under applicable law, such
partial invalidity or ineffectiveness shall not invalidate the remainder
of the License, and in such case Affirmer hereby affirms that he or she
will not (i) exercise any of his or her remaining Copyright and Related
Rights in the Work or (ii) assert any associated claims and causes of
action with respect to the Work, in either case contrary to Affirmer's
express Statement of Purpose.

4. Limitations and Disclaimers.

 a. No trademark or patent rights held by Affirmer are waived, abandoned,
    surrendered, licensed or otherwise affected by this document.
 b. Affirmer offers the Work as-is and makes no representations or
    warranties of any kind concerning the Work, express, implied,
    statutory or otherwise, including without limitation warranties of
    title, merchantability, fitness for a particular purpose, non
    infringement, or the absence of latent or other defects, accuracy, or
    the present or absence of errors, whether or not discoverable, all to
    the greatest extent permissible under applicable law.
 c. Affirmer disclaims responsibility for clearing rights of other persons
    that may apply to the Work or any use thereof, including without
    limitation any person's Copyright and Related Rights in the Work.
    Further, Affirmer disclaims responsibility for obtaining any necessary
    consents, permissions or other rights required for any use of the
    Work.
 d. Affirmer understands and acknowledges that Creative Commons is not a
    party to this document and has no duty or obligation with respect to
    this CC0 or use of the Work.

A  => README.md +8 -0
@@ 1,8 @@
<!--
  -- (SPDX-FileCopyrightText: Hanspeter Portner <dev@open-music-kontrollers.ch>
  -- (SPDX-License-Identifier: CC0-1.0
  -->
# Props.lv2

## Utility header for property based LV2 plugins


A  => gitlab-ci/LICENSES/CC0-1.0.txt +29 -0
@@ 1,29 @@
Creative Commons Legal Code

CC0 1.0 Universal

CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER.

Statement of Purpose

The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").

Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.

For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.

    1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:
        i. the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
        ii. moral rights retained by the original author(s) and/or performer(s);
        iii. publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
        iv. rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
        v. rights protecting the extraction, dissemination, use and reuse of data in a Work;
        vi. database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
        vii. other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.
    2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.
    3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.
    4. Limitations and Disclaimers.
        a. No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
        b. Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
        c. Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
        d. Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.

A  => gitlab-ci/generic.yml +123 -0
@@ 1,123 @@
# SPDX-FileCopyrightText: Hanspeter Portner <dev@open-music-kontrollers.ch>
# SPDX-License-Identifier: CC0-1.0

stages:
  - prepare
  - build
  - deploy

variables:
  PKG_CONFIG_PATH: "/opt/lv2/lib/pkgconfig:/opt/${CI_BUILD_NAME}/lib/pkgconfig:/usr/lib/${CI_BUILD_NAME}/pkgconfig"
  BUILD_OPTS: ""

vars:
  stage: prepare
  script:
    - echo "VERSION=$( grep version meson_options.txt | cut -d\' -f6 )" > vars.env
  artifacts:
    reports:
      dotenv: vars.env

.native_template: &native_definition
  stage: build
  script:
    - meson --prefix="${CI_PROJECT_DIR}/${CI_PROJECT_NAME}-${VERSION}/${CI_BUILD_NAME}" -Dlv2libdir="" --cross-file "${CI_BUILD_NAME}" ${BUILD_OPTS} build
    - ninja -C build
    - ninja -C build test
    - meson test -C build --wrap="valgrind --leak-check=full --error-exitcode=1"
    - ninja -C build install

    - meson --prefix="${CI_PROJECT_DIR}/${CI_PROJECT_NAME}-${VERSION}/${CI_BUILD_NAME}" -Dlv2libdir="" --cross-file "${CI_BUILD_NAME}" ${BUILD_OPTS} -Db_sanitize=address sanitize
    - ninja -C sanitize
    - ninja -C sanitize test

    - scan-build --status-bugs meson --prefix="${CI_PROJECT_DIR}/${CI_PROJECT_NAME}-${VERSION}/${CI_BUILD_NAME}" -Dlv2libdir="" --cross-file "${CI_BUILD_NAME}" ${BUILD_OPTS} scanbuild
    - scan-build --status-bugs ninja -C scanbuild
    - scan-build --status-bugs ninja -C scanbuild test
  artifacts:
    name: "${CI_PROJECT_NAME}-${VERSION}-${CI_BUILD_NAME}"
    paths:
      - "${CI_PROJECT_NAME}-${VERSION}/${CI_BUILD_NAME}/"

.cross_template: &cross_definition
  stage: build
  script:
    - meson --prefix="${CI_PROJECT_DIR}/${CI_PROJECT_NAME}-${VERSION}/${CI_BUILD_NAME}" -Dlv2libdir="" --cross-file "${CI_BUILD_NAME}" ${BUILD_OPTS} build
    - ninja -C build
    - ninja -C build test
    - ninja -C build install
  artifacts:
    name: "${CI_PROJECT_NAME}-${VERSION}-${CI_BUILD_NAME}"
    paths:
      - "${CI_PROJECT_NAME}-${VERSION}/${CI_BUILD_NAME}/"

# build
.universal_linux_template_stretch: &universal_linux_definition_stretch
  image: ventosus/universal-linux-gnu:stretch
  <<: *cross_definition

.universal_linux_template_buster: &universal_linux_definition_buster
  image: ventosus/universal-linux-gnu:buster
  <<: *native_definition

.universal_linux_template_bullseye: &universal_linux_definition_bullseye
  image: ventosus/universal-linux-gnu:bullseye
  <<: *native_definition

.arm_linux_template_stretch: &arm_linux_definition_stretch
  image: ventosus/arm-linux-gnueabihf:stretch
  <<: *cross_definition

.arm_linux_template_buster: &arm_linux_definition_buster
  image: ventosus/arm-linux-gnueabihf:buster
  <<: *cross_definition

.arm_linux_template_bullseye: &arm_linux_definition_bullseye
  image: ventosus/arm-linux-gnueabihf:bullseye
  <<: *cross_definition

# build
x86_64-linux-gnu-stretch:
  <<: *universal_linux_definition_stretch

x86_64-linux-gnu-buster:
  <<: *universal_linux_definition_buster

x86_64-linux-gnu-bullseye:
  <<: *universal_linux_definition_bullseye

i686-linux-gnu-stretch:
  <<: *universal_linux_definition_stretch

i686-linux-gnu-buster:
  <<: *universal_linux_definition_buster

i686-linux-gnu-bullseye:
  <<: *universal_linux_definition_bullseye

arm-linux-gnueabihf-stretch:
  <<: *arm_linux_definition_stretch

arm-linux-gnueabihf-buster:
  <<: *arm_linux_definition_buster

arm-linux-gnueabihf-bullseye:
  <<: *arm_linux_definition_bullseye

aarch64-linux-gnu-stretch:
  <<: *arm_linux_definition_stretch

aarch64-linux-gnu-buster:
  <<: *arm_linux_definition_buster

aarch64-linux-gnu-bullseye:
  <<: *arm_linux_definition_bullseye

pack:
  stage: deploy
  script:
    - echo 'packing up'
  artifacts:
    name: "${CI_PROJECT_NAME}-${VERSION}"
    paths:
      - "${CI_PROJECT_NAME}-${VERSION}/"

A  => meson.build +121 -0
@@ 1,121 @@
# SPDX-FileCopyrightText: Hanspeter Portner <dev@open-music-kontrollers.ch>
# SPDX-License-Identifier: CC0-1.0

project('props.lv2', 'c', default_options : [
	'buildtype=release',
	'warning_level=3',
	'werror=false',
	'b_lto=true',
	'c_std=c11'])

lv2libdir = get_option('lv2libdir')

inst_dir = join_paths(lv2libdir, meson.project_name())

reuse = find_program('reuse', required : false)
cp = find_program('cp')
lv2_validate = find_program('lv2_validate', native : true, required : false)
sord_validate = find_program('sord_validate', native : true, required : false)
lv2lint = find_program('lv2lint', required : false)

add_project_arguments('-D_GNU_SOURCE', language : 'c')

conf_data = configuration_data()
cc = meson.get_compiler('c')

m_dep = cc.find_library('m')
lv2_dep = dependency('lv2', version : '>=1.14.0')

lib_deps = []
lib_deps += m_dep
lib_deps += lv2_dep

lib_incs = []
lib_incs += include_directories('')

lib_srcs = []
lib_srcs += join_paths('src', 'props.c')

props_lv2 = declare_dependency(
  include_directories : lib_incs,
  dependencies : lib_deps,
  sources : lib_srcs)

test_args = []
test_args += '-fvisibility=hidden'
test_args += '-ffast-math'

test_deps = []
test_deps += props_lv2

test_srcs = []
test_srcs += join_paths('test', 'props.c')

check_srcs = []
check_srcs += join_paths('test', 'props_test.c')

install = not meson.is_subproject()

mod = shared_module('props', test_srcs,
	c_args : test_args,
	name_prefix : '',
	dependencies : test_deps,
	install : install,
	install_dir : inst_dir)

version = get_option('version').split('.')
conf_data.set('MAJOR_VERSION', version[0])
conf_data.set('MINOR_VERSION', version[1])
conf_data.set('MICRO_VERSION', version[2])

suffix = mod.full_path().strip().split('.')[-1]
conf_data.set('MODULE_SUFFIX', '.' + suffix)

manifest_ttl = configure_file(
  input : join_paths('test', 'manifest.ttl.in'),
  output : 'manifest.ttl',
	configuration : conf_data,
	install : install,
	install_dir : inst_dir)

dsp_ttl = configure_file(
	input : join_paths('test', 'props.ttl'),
	output : 'props.ttl',
	copy : true,
	install : install,
	install_dir : inst_dir)

chunk_bin = configure_file(
	input : join_paths('test', 'chunk.bin'),
	output : 'chunk.bin',
	copy : true,
	install : install,
	install_dir : inst_dir)

props_test = executable('props_test', check_srcs,
	c_args : test_args,
	dependencies : test_deps,
	install : false)

test('Test', props_test,
	timeout : 240)

if lv2_validate.found() and sord_validate.found()
	test('LV2 validate', lv2_validate,
		args : [manifest_ttl, dsp_ttl])
endif

if lv2lint.found()
	test('LV2 lint', lv2lint,
    args : ['-M', 'pack',
      '-E', 'warn',
      '-I', meson.current_build_dir(),
			'http://open-music-kontrollers.ch/lv2/props#test'])
endif

if reuse.found()
  test('REUSE', reuse, args : [
    '--root', meson.current_source_dir(),
    'lint'
  ])
endif

A  => meson_options.txt +8 -0
@@ 1,8 @@
# SPDX-FileCopyrightText: Hanspeter Portner <dev@open-music-kontrollers.ch>
# SPDX-License-Identifier: CC0-1.0
#
option('lv2libdir',
	type : 'string',
	value : 'lib/lv2')

option('version', type : 'string', value : '0.1.195')

A  => props.lv2/props.h +198 -0
@@ 1,198 @@
/*
 * SPDX-FileCopyrightText: Hanspeter Portner <dev@open-music-kontrollers.ch>
 * SPDX-License-Identifier: Artistic-2.0
 */

#ifndef _LV2_PROPS_H_
#define _LV2_PROPS_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdlib.h>
#include <stdatomic.h>
#include <stdio.h>

#include <lv2/core/lv2.h>
#include <lv2/urid/urid.h>
#include <lv2/atom/atom.h>
#include <lv2/atom/forge.h>
#include <lv2/patch/patch.h>
#include <lv2/state/state.h>

// structures
typedef struct _props_def_t props_def_t;
typedef struct _props_impl_t props_impl_t;
typedef struct _props_dyn_t props_dyn_t;
typedef struct _props_t props_t;

typedef enum _props_dyn_ev_t {
	PROPS_DYN_EV_ADD,
	PROPS_DYN_EV_REM,
	PROPS_DYN_EV_SET
} props_dyn_ev_t;

// function callbacks
typedef void (*props_event_cb_t)(
	void *data,
	int64_t frames,
	props_impl_t *impl);

typedef void (*props_dyn_prop_cb_t)(
	void *data,
	props_dyn_ev_t ev,
	LV2_URID subj,
	LV2_URID prop,
	const LV2_Atom *body);

struct _props_def_t {
	const char *property;
	const char *type;
	const char *access;
	size_t offset;
	bool hidden;

	uint32_t max_size;
	props_event_cb_t event_cb;
};

struct _props_impl_t {
	LV2_URID property;
	LV2_URID type;
	LV2_URID access;

	struct {
		uint32_t size;
		void *body;
	} value;
	struct {
		uint32_t size;
		void *body;
	} stash;

	const props_def_t *def;

	atomic_int state;
	bool stashing;
};

struct _props_dyn_t {
	props_dyn_prop_cb_t prop;
};

struct _props_t {
	struct {
		LV2_URID subject;

		LV2_URID patch_get;
		LV2_URID patch_set;
		LV2_URID patch_put;
		LV2_URID patch_patch;
		LV2_URID patch_wildcard;
		LV2_URID patch_add;
		LV2_URID patch_remove;
		LV2_URID patch_subject;
		LV2_URID patch_body;
		LV2_URID patch_property;
		LV2_URID patch_value;
		LV2_URID patch_writable;
		LV2_URID patch_readable;
		LV2_URID patch_sequence;
		LV2_URID patch_error;
		LV2_URID patch_ack;

		LV2_URID atom_int;
		LV2_URID atom_long;
		LV2_URID atom_float;
		LV2_URID atom_double;
		LV2_URID atom_bool;
		LV2_URID atom_urid;
		LV2_URID atom_path;
		LV2_URID atom_literal;
		LV2_URID atom_vector;
		LV2_URID atom_object;
		LV2_URID atom_sequence;

		LV2_URID state_StateChanged;
	} urid;

	void *data;

	bool stashing;
	atomic_bool restoring;

	uint32_t max_size;

	const props_dyn_t *dyn;

	unsigned nimpls;
	props_impl_t impls [1];
};

#define PROPS_T(PROPS, MAX_NIMPLS) \
	props_t (PROPS); \
	props_impl_t _impls [MAX_NIMPLS]

// rt-safe
int
props_init(props_t *props, const char *subject,
	const props_def_t *defs, int nimpls,
	void *value_base, void *stash_base,
	LV2_URID_Map *map, void *data);

// rt-safe
void
props_dyn(props_t *props, const props_dyn_t *dyn);

// rt-safe
void
props_idle(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
	LV2_Atom_Forge_Ref *ref);

// rt-safe
int
props_advance(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
	const LV2_Atom_Object *obj, LV2_Atom_Forge_Ref *ref);

// rt-safe
void
props_set(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
	LV2_URID property, LV2_Atom_Forge_Ref *ref);

// rt-safe
void
props_get(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
	LV2_URID property, LV2_Atom_Forge_Ref *ref);

// rt-safe
void
props_stash(props_t *props, LV2_URID property);

// rt-safe
LV2_URID
props_map(props_t *props, const char *property);

// rt-safe
const char *
props_unmap(props_t *props, LV2_URID property);

void
props_update(props_t *props, LV2_URID property, LV2_URID type, uint32_t size,
	const void *body);

// non-rt
LV2_State_Status
props_save(props_t *props, LV2_State_Store_Function store,
	LV2_State_Handle state, uint32_t flags, const LV2_Feature *const *features);

// non-rt
LV2_State_Status
props_restore(props_t *props, LV2_State_Retrieve_Function retrieve,
	LV2_State_Handle state, uint32_t flags, const LV2_Feature *const *features);

#ifdef __cplusplus
}
#endif

#endif // _LV2_PROPS_H_

A  => src/props.c +1023 -0
@@ 1,1023 @@
/*
 * SPDX-FileCopyrightText: Hanspeter Portner <dev@open-music-kontrollers.ch>
 * SPDX-License-Identifier: Artistic-2.0
 */

#include <src/props_private.h>

static inline void
_props_impl_spin_lock(props_impl_t *impl, int from, int to)
{
	int expected = from;
	const int desired = to;

	while(!atomic_compare_exchange_strong_explicit(&impl->state, &expected, desired,
		memory_order_acquire, memory_order_acquire))
	{
		// spin
	}
}

static inline bool
_props_impl_try_lock(props_impl_t *impl, int from, int to)
{
	int expected = from;
	const int desired = to;

	return atomic_compare_exchange_strong_explicit(&impl->state, &expected, desired,
		memory_order_acquire, memory_order_acquire);
}

static inline void
_props_impl_unlock(props_impl_t *impl, int to)
{
	atomic_store_explicit(&impl->state, to, memory_order_release);
}

static inline bool
_props_restoring_get(props_t *props)
{
	return atomic_exchange_explicit(&props->restoring, false, memory_order_acquire);
}

static inline void
_props_restoring_set(props_t *props)
{
	atomic_store_explicit(&props->restoring, true, memory_order_release);
}

static inline void
_props_qsort(props_impl_t *A, int n)
{
	if(n < 2)
		return;

	const props_impl_t *p = A;

	int i = -1;
	int j = n;

	while(true)
	{
		do {
			i += 1;
		} while(A[i].property < p->property);

		do {
			j -= 1;
		} while(A[j].property > p->property);

		if(i >= j)
			break;

		const props_impl_t tmp = A[i];
		A[i] = A[j];
		A[j] = tmp;
	}

	_props_qsort(A, j + 1);
	_props_qsort(A + j + 1, n - j - 1);
}

props_impl_t *
_props_impl_get(props_t *props, LV2_URID property)
{
	props_impl_t *base = props->impls;

	for(int N = props->nimpls, half; N > 1; N -= half)
	{
		half = N/2;
		props_impl_t *dst = &base[half];
		base = (dst->property > property) ? base : dst;
	}

	return (base->property == property) ? base : NULL;
}

static inline LV2_Atom_Forge_Ref
_props_patch_set(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
	props_impl_t *impl, int32_t sequence_num)
{
	LV2_Atom_Forge_Frame obj_frame;

	LV2_Atom_Forge_Ref ref = lv2_atom_forge_frame_time(forge, frames);

	if(ref)
		ref = lv2_atom_forge_object(forge, &obj_frame, 0, props->urid.patch_set);
	{
		if(props->urid.subject) // is optional
		{
			if(ref)
				ref = lv2_atom_forge_key(forge, props->urid.patch_subject);
			if(ref)
				ref = lv2_atom_forge_urid(forge, props->urid.subject);
		}

		if(sequence_num) // is optional
		{
			if(ref)
				ref = lv2_atom_forge_key(forge, props->urid.patch_sequence);
			if(ref)
				ref = lv2_atom_forge_int(forge, sequence_num);
		}

		if(ref)
			ref = lv2_atom_forge_key(forge, props->urid.patch_property);
		if(ref)
			ref = lv2_atom_forge_urid(forge, impl->property);

		if(ref)
			lv2_atom_forge_key(forge, props->urid.patch_value);
		if(ref)
			ref = lv2_atom_forge_atom(forge, impl->value.size, impl->type);
		if(ref)
			ref = lv2_atom_forge_write(forge, impl->value.body, impl->value.size);
	}
	if(ref)
		lv2_atom_forge_pop(forge, &obj_frame);

	if(ref)
		ref = lv2_atom_forge_frame_time(forge, frames);
	if(ref)
		ref = lv2_atom_forge_object(forge, &obj_frame, 0, props->urid.state_StateChanged);
	if(ref)
		lv2_atom_forge_pop(forge, &obj_frame);

	return ref;
}

static inline LV2_Atom_Forge_Ref
_props_patch_get(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
	props_impl_t *impl, int32_t sequence_num)
{
	LV2_Atom_Forge_Frame obj_frame;

	LV2_Atom_Forge_Ref ref = lv2_atom_forge_frame_time(forge, frames);

	if(ref)
		ref = lv2_atom_forge_object(forge, &obj_frame, 0, props->urid.patch_get);
	{
		if(props->urid.subject) // is optional
		{
			if(ref)
				ref = lv2_atom_forge_key(forge, props->urid.patch_subject);
			if(ref)
				ref = lv2_atom_forge_urid(forge, props->urid.subject);
		}

		if(sequence_num) // is optional
		{
			if(ref)
				ref = lv2_atom_forge_key(forge, props->urid.patch_sequence);
			if(ref)
				ref = lv2_atom_forge_int(forge, sequence_num);
		}

		if(ref)
			ref = lv2_atom_forge_key(forge, props->urid.patch_property);
		if(ref)
			ref = lv2_atom_forge_urid(forge, impl->property);
	}
	if(ref)
		lv2_atom_forge_pop(forge, &obj_frame);

	return ref;
}

static inline LV2_Atom_Forge_Ref
_props_patch_error(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
	int32_t sequence_num)
{
	LV2_Atom_Forge_Frame obj_frame;

	LV2_Atom_Forge_Ref ref = lv2_atom_forge_frame_time(forge, frames);

	if(ref)
		ref = lv2_atom_forge_object(forge, &obj_frame, 0, props->urid.patch_error);
	{
		if(ref)
			ref = lv2_atom_forge_key(forge, props->urid.patch_sequence);
		if(ref)
			ref = lv2_atom_forge_int(forge, sequence_num);
	}
	if(ref)
		lv2_atom_forge_pop(forge, &obj_frame);

	return ref;
}

static inline LV2_Atom_Forge_Ref
_props_patch_ack(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
	int32_t sequence_num)
{
	LV2_Atom_Forge_Frame obj_frame;

	LV2_Atom_Forge_Ref ref = lv2_atom_forge_frame_time(forge, frames);

	if(ref)
		ref = lv2_atom_forge_object(forge, &obj_frame, 0, props->urid.patch_ack);
	{
		if(ref)
			ref = lv2_atom_forge_key(forge, props->urid.patch_sequence);
		if(ref)
			ref = lv2_atom_forge_int(forge, sequence_num);
	}
	if(ref)
		lv2_atom_forge_pop(forge, &obj_frame);

	return ref;
}

static inline void
_props_impl_stash(props_t *props, props_impl_t *impl)
{
	if(_props_impl_try_lock(impl, PROP_STATE_NONE, PROP_STATE_LOCK))
	{
		impl->stashing = false;
		impl->stash.size = impl->value.size;
		memcpy(impl->stash.body, impl->value.body, impl->value.size);

		_props_impl_unlock(impl, PROP_STATE_NONE);
	}
	else
	{
		impl->stashing = true; // try again later
		props->stashing = true;
	}
}

static inline void
_props_impl_restore(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
	props_impl_t *impl, LV2_Atom_Forge_Ref *ref)
{
	if(_props_impl_try_lock(impl, PROP_STATE_RESTORE, PROP_STATE_LOCK))
	{
		impl->stashing = false; // makes no sense to stash a recently restored value
		impl->value.size = impl->stash.size;
		memcpy(impl->value.body, impl->stash.body, impl->stash.size);

		_props_impl_unlock(impl, PROP_STATE_NONE);

		if(*ref && !impl->def->hidden)
			*ref = _props_patch_set(props, forge, frames, impl, 0);

		const props_def_t *def = impl->def;
		if(def->event_cb)
			def->event_cb(props->data, 0, impl);
	}
}

static inline void
_props_impl_set(props_t *props, props_impl_t *impl, LV2_URID type,
	uint32_t size, const void *body)
{
	if(  (impl->type == type)
		&& ( (impl->def->max_size == 0) || (size <= impl->def->max_size)) )
	{
		impl->value.size = size;
		memcpy(impl->value.body, body, size);

		_props_impl_stash(props, impl);
	}
}

static inline int
_props_impl_init(props_t *props, props_impl_t *impl, const props_def_t *def,
	void *value_base, void *stash_base, LV2_URID_Map *map)
{
	if(!def->property || !def->type)
		return 0;

	const LV2_URID type = map->map(map->handle, def->type);
	const LV2_URID property = map->map(map->handle, def->property);
	const LV2_URID access = def->access
		? map->map(map->handle, def->access)
		: map->map(map->handle, LV2_PATCH__writable);

	if(!type || !property || !access)
		return 0;

	impl->property = property;
	impl->access = access;
	impl->def = def;
	impl->value.body = (uint8_t *)value_base + def->offset;
	impl->stash.body = (uint8_t *)stash_base + def->offset;

	uint32_t size;
	if(  (type == props->urid.atom_int)
		|| (type == props->urid.atom_float)
		|| (type == props->urid.atom_bool)
		|| (type == props->urid.atom_urid) )
	{
		size = 4;
	}
	else if((type == props->urid.atom_long)
		|| (type == props->urid.atom_double) )
	{
		size = 8;
	}
	else if(type == props->urid.atom_literal)
	{
		size = sizeof(LV2_Atom_Literal_Body);
	}
	else if(type == props->urid.atom_vector)
	{
		size = sizeof(LV2_Atom_Vector_Body);
	}
	else if(type == props->urid.atom_object)
	{
		size = sizeof(LV2_Atom_Object_Body);
	}
	else if(type == props->urid.atom_sequence)
	{
		size = sizeof(LV2_Atom_Sequence_Body);
	}
	else
	{
		size = 0; // assume everything else as having size 0
	}

	impl->type = type;
	impl->value.size = size;
	impl->stash.size = size;

	atomic_init(&impl->state, PROP_STATE_NONE);

	// update maximal value size
	const uint32_t max_size = def->max_size
		? def->max_size
		: size;

	if(max_size > props->max_size)
	{
		props->max_size = max_size;
	}

	return 1;
}

int
props_init(props_t *props, const char *subject,
	const props_def_t *defs, int nimpls,
	void *value_base, void *stash_base,
	LV2_URID_Map *map, void *data)
{
	if(!props || !defs || !value_base || !stash_base || !map)
		return 0;

	props->nimpls = nimpls;
	props->data = data;

	props->urid.subject = subject ? map->map(map->handle, subject) : 0;

	props->urid.patch_get = map->map(map->handle, LV2_PATCH__Get);
	props->urid.patch_set = map->map(map->handle, LV2_PATCH__Set);
	props->urid.patch_put = map->map(map->handle, LV2_PATCH__Put);
	props->urid.patch_patch = map->map(map->handle, LV2_PATCH__Patch);
	props->urid.patch_wildcard = map->map(map->handle, LV2_PATCH__wildcard);
	props->urid.patch_add = map->map(map->handle, LV2_PATCH__add);
	props->urid.patch_remove = map->map(map->handle, LV2_PATCH__remove);
	props->urid.patch_subject = map->map(map->handle, LV2_PATCH__subject);
	props->urid.patch_body = map->map(map->handle, LV2_PATCH__body);
	props->urid.patch_property = map->map(map->handle, LV2_PATCH__property);
	props->urid.patch_value = map->map(map->handle, LV2_PATCH__value);
	props->urid.patch_writable = map->map(map->handle, LV2_PATCH__writable);
	props->urid.patch_readable = map->map(map->handle, LV2_PATCH__readable);
	props->urid.patch_sequence = map->map(map->handle, LV2_PATCH__sequenceNumber);
	props->urid.patch_ack = map->map(map->handle, LV2_PATCH__Ack);
	props->urid.patch_error = map->map(map->handle, LV2_PATCH__Error);

	props->urid.atom_int = map->map(map->handle, LV2_ATOM__Int);
	props->urid.atom_long = map->map(map->handle, LV2_ATOM__Long);
	props->urid.atom_float = map->map(map->handle, LV2_ATOM__Float);
	props->urid.atom_double = map->map(map->handle, LV2_ATOM__Double);
	props->urid.atom_bool = map->map(map->handle, LV2_ATOM__Bool);
	props->urid.atom_urid = map->map(map->handle, LV2_ATOM__URID);
	props->urid.atom_path = map->map(map->handle, LV2_ATOM__Path);
	props->urid.atom_literal = map->map(map->handle, LV2_ATOM__Literal);
	props->urid.atom_vector = map->map(map->handle, LV2_ATOM__Vector);
	props->urid.atom_object = map->map(map->handle, LV2_ATOM__Object);
	props->urid.atom_sequence = map->map(map->handle, LV2_ATOM__Sequence);

	props->urid.state_StateChanged = map->map(map->handle, LV2_STATE__StateChanged);

	atomic_init(&props->restoring, false);

	int status = 1;
	for(unsigned i = 0; i < props->nimpls; i++)
	{
		props_impl_t *impl = &props->impls[i];

		status = status
			&& _props_impl_init(props, impl, &defs[i], value_base, stash_base, map);
	}

	_props_qsort(props->impls, props->nimpls);

	return status;
}

void
props_dyn(props_t *props, const props_dyn_t *dyn)
{
	props->dyn = dyn;
}

void
props_idle(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
	LV2_Atom_Forge_Ref *ref)
{
	if(_props_restoring_get(props))
	{
		for(unsigned i = 0; i < props->nimpls; i++)
		{
			props_impl_t *impl = &props->impls[i];

			_props_impl_restore(props, forge, frames, impl, ref);
		}
	}

	if(props->stashing)
	{
		props->stashing = false;

		for(unsigned i = 0; i < props->nimpls; i++)
		{
			props_impl_t *impl = &props->impls[i];

			if(impl->stashing)
				_props_impl_stash(props, impl);
		}
	}
}

int
props_advance(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
	const LV2_Atom_Object *obj, LV2_Atom_Forge_Ref *ref)
{
	if(!lv2_atom_forge_is_object_type(forge, obj->atom.type))
	{
		return 0;
	}

	if(obj->body.otype == props->urid.patch_get)
	{
		const LV2_Atom_URID *subject = NULL;
		const LV2_Atom_URID *property = NULL;
		const LV2_Atom_Int *sequence = NULL;

		lv2_atom_object_get(obj,
			props->urid.patch_subject, &subject,
			props->urid.patch_property, &property,
			props->urid.patch_sequence, &sequence,
			0);

		// check for a matching optional subject
		if(  (subject && props->urid.subject)
			&& ( (subject->atom.type != props->urid.atom_urid)
				|| (subject->body != props->urid.subject) ) )
		{
			return 0;
		}

		int32_t sequence_num = 0;
		if(sequence && (sequence->atom.type == props->urid.atom_int))
		{
			sequence_num = sequence->body;
		}

		if(!property)
		{
			for(unsigned i = 0; i < props->nimpls; i++)
			{
				props_impl_t *impl = &props->impls[i];

				if(*ref && !impl->def->hidden)
					*ref = _props_patch_set(props, forge, frames, impl, sequence_num);
			}

			return 1;
		}
		else if(property->atom.type == props->urid.atom_urid)
		{
			props_impl_t *impl = _props_impl_get(props, property->body);

			if(impl)
			{
				if(*ref && !impl->def->hidden)
					*ref = _props_patch_set(props, forge, frames, impl, sequence_num);

				return 1;
			}
			else if(sequence_num)
			{
				if(*ref)
					*ref = _props_patch_error(props, forge, frames, sequence_num);
			}
		}
		else if(sequence_num)
		{
			if(*ref)
				*ref = _props_patch_error(props, forge, frames, sequence_num);
		}
	}
	else if(obj->body.otype == props->urid.patch_set)
	{
		const LV2_Atom_URID *subject = NULL;
		const LV2_Atom_URID *property = NULL;
		const LV2_Atom_Int *sequence = NULL;
		const LV2_Atom *value = NULL;

		lv2_atom_object_get(obj,
			props->urid.patch_subject, &subject,
			props->urid.patch_property, &property,
			props->urid.patch_sequence, &sequence,
			props->urid.patch_value, &value,
			0);

		// check for a matching optional subject
		if(  (subject && props->urid.subject)
			&& ( (subject->atom.type != props->urid.atom_urid)
				|| (subject->body != props->urid.subject) ) )
		{
			return 0;
		}

		int32_t sequence_num = 0;
		if(sequence && (sequence->atom.type == props->urid.atom_int))
		{
			sequence_num = sequence->body;
		}

		if(!property || (property->atom.type != props->urid.atom_urid) || !value)
		{
			if(sequence_num)
			{
				if(ref)
					*ref = _props_patch_error(props, forge, frames, sequence_num);
			}

			return 0;
		}

		props_impl_t *impl = _props_impl_get(props, property->body);
		if(impl)
		{
			_props_impl_set(props, impl, value->type, value->size,
				LV2_ATOM_BODY_CONST(value));

			// send on (e.g. to UI)
			if(*ref && !impl->def->hidden)
				*ref = _props_patch_set(props, forge, frames, impl, sequence_num);

			const props_def_t *def = impl->def;
			if(def->event_cb)
				def->event_cb(props->data, frames, impl);

			if(sequence_num)
			{
				if(*ref)
					*ref = _props_patch_ack(props, forge, frames, sequence_num);
			}

			return 1;
		}
		else if(props->dyn && props->dyn->prop)
		{
			const LV2_URID subj = subject ? subject->body : 0;

			props->dyn->prop(props->data, PROPS_DYN_EV_SET, subj, property->body, value);

			//TODO send ack
		}
		else if(sequence_num)
		{
			if(*ref)
				*ref = _props_patch_error(props, forge, frames, sequence_num);
		}
	}
	else if(obj->body.otype == props->urid.patch_put)
	{
		const LV2_Atom_URID *subject = NULL;
		const LV2_Atom_Int *sequence = NULL;
		const LV2_Atom_Object *body = NULL;

		lv2_atom_object_get(obj,
			props->urid.patch_subject, &subject,
			props->urid.patch_sequence, &sequence,
			props->urid.patch_body, &body,
			0);

		// check for a matching optional subject
		if(  (subject && props->urid.subject)
			&& ( (subject->atom.type != props->urid.atom_urid)
				|| (subject->body != props->urid.subject) ) )
		{
			return 0;
		}

		int32_t sequence_num = 0;
		if(sequence && (sequence->atom.type == props->urid.atom_int))
		{
			sequence_num = sequence->body;
		}

		if(!body || !lv2_atom_forge_is_object_type(forge, body->atom.type))
		{
			if(sequence_num)
			{
				if(*ref)
					*ref = _props_patch_error(props, forge, frames, sequence_num);
			}

			return 0;
		}

		LV2_ATOM_OBJECT_FOREACH(body, prop)
		{
			const LV2_URID property = prop->key;
			const LV2_Atom *value = &prop->value;

			props_impl_t *impl = _props_impl_get(props, property);
			if(impl)
			{
				_props_impl_set(props, impl, value->type, value->size,
					LV2_ATOM_BODY_CONST(value));

				// send on (e.g. to UI)
				if(*ref && !impl->def->hidden)
					*ref = _props_patch_set(props, forge, frames, impl, sequence_num);

				const props_def_t *def = impl->def;
				if(def->event_cb)
					def->event_cb(props->data, frames, impl);
			}
			else if(props->dyn && props->dyn->prop)
			{
				const LV2_URID subj = subject ? subject->body : 0;

				props->dyn->prop(props->data, PROPS_DYN_EV_SET, subj, property, value);

			//TODO send ack
			}
		}

		if(sequence_num)
		{
			if(*ref)
				*ref = _props_patch_ack(props, forge, frames, sequence_num);
		}

		return 1;
	}
	else if(obj->body.otype == props->urid.patch_patch)
	{
		const LV2_Atom_URID *subject = NULL;
		const LV2_Atom_Int *sequence = NULL;
		const LV2_Atom_Object *add = NULL;
		const LV2_Atom_Object *rem = NULL;

		lv2_atom_object_get(obj,
			props->urid.patch_subject, &subject,
			props->urid.patch_sequence, &sequence,
			props->urid.patch_add, &add,
			props->urid.patch_remove, &rem,
			0);

		LV2_URID subj = 0;
		if(subject && (subject->atom.type == props->urid.atom_urid))
		{
			subj = subject->body;
		}

		int32_t sequence_num = 0;
		if(sequence && (sequence->atom.type == props->urid.atom_int))
		{
			sequence_num = sequence->body;
		}

		if(rem && lv2_atom_forge_is_object_type(forge, rem->atom.type))
		{
			LV2_ATOM_OBJECT_FOREACH(rem, prop)
			{
				const LV2_URID property = prop->key;
				const LV2_Atom *value = &prop->value;

				if(props->dyn && props->dyn->prop)
				{
					props->dyn->prop(props->data, PROPS_DYN_EV_REM, subj, property, value);
				}
			}
		}

		if(add && lv2_atom_forge_is_object_type(forge, add->atom.type))
		{
			LV2_ATOM_OBJECT_FOREACH(add, prop)
			{
				const LV2_URID property = prop->key;
				const LV2_Atom *value = &prop->value;

				if(props->dyn && props->dyn->prop)
				{
					props->dyn->prop(props->data, PROPS_DYN_EV_ADD, subj, property, value);
				}
			}
		}

		if(sequence_num && *ref)
		{
			*ref = _props_patch_ack(props, forge, frames, sequence_num);
		}

		return 1;
	}

	return 0; // did not handle a patch event
}

void
props_set(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
	LV2_URID property, LV2_Atom_Forge_Ref *ref)
{
	props_impl_t *impl = _props_impl_get(props, property);

	if(impl)
	{
		_props_impl_stash(props, impl);

		if(*ref && !impl->def->hidden) //TODO use patch:sequenceNumber
			*ref = _props_patch_set(props, forge, frames, impl, 0);
	}
}

void
props_get(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
	LV2_URID property, LV2_Atom_Forge_Ref *ref)
{
	props_impl_t *impl = _props_impl_get(props, property);

	if(impl)
	{
		if(*ref && !impl->def->hidden) //TODO use patch:sequenceNumber
			*ref = _props_patch_get(props, forge, frames, impl, 0);
	}
}

void
props_stash(props_t *props, LV2_URID property)
{
	props_impl_t *impl = _props_impl_get(props, property);

	if(impl)
		_props_impl_stash(props, impl);
}

LV2_URID
props_map(props_t *props, const char *uri)
{
	for(unsigned i = 0; i < props->nimpls; i++)
	{
		props_impl_t *impl = &props->impls[i];

		if(!strcmp(impl->def->property, uri))
			return impl->property;
	}

	return 0;
}

const char *
props_unmap(props_t *props, LV2_URID property)
{
	props_impl_t *impl = _props_impl_get(props, property);

	if(impl)
		return impl->def->property;

	return NULL;
}

void
props_update(props_t *props, LV2_URID property, LV2_URID type, uint32_t size,
	const void *body)
{
	props_impl_t *impl = _props_impl_get(props, property);

	if (impl)
	{
		_props_impl_set(props, impl, type, size, body);
	}
}

static inline int
_copy_file(const char *to, const char *from)
{
	FILE *dst = NULL;
	FILE *src = NULL;
	int ch;

	dst = fopen(to, "wb");
	if(!dst)
	{
		return 1;
	}

	src = fopen(from, "rb");
	if(!src)
	{
		fclose(dst);

		return 1;
	}

	while( (ch = fgetc(src)) != EOF)
	{
		fputc(ch, dst);
	}

	fclose(dst);
	fclose(src);

	return 0;
}

static inline void
_free_path(const LV2_State_Free_Path *free_path, char *path)
{
	if(free_path && free_path->free_path)
	{
		free_path->free_path(free_path->handle, path);
	}
	else
	{
		free(path);
	}
}

LV2_State_Status
props_save(props_t *props, LV2_State_Store_Function store,
	LV2_State_Handle state, uint32_t flags, const LV2_Feature *const *features)
{
	const LV2_State_Map_Path *map_path = NULL;
	const LV2_State_Make_Path *make_path = NULL;
	const LV2_State_Free_Path *free_path = NULL;

	// set POD flag if not already set by host
	flags |= LV2_STATE_IS_POD;

	for(unsigned i = 0; features[i]; i++)
	{
		if(!strcmp(features[i]->URI, LV2_STATE__mapPath))
		{
			map_path = features[i]->data;
		}
		else if(!strcmp(features[i]->URI, LV2_STATE__makePath))
		{
			make_path = features[i]->data;
		}
		else if(!strcmp(features[i]->URI, LV2_STATE__freePath))
		{
			free_path = features[i]->data;
		}
	}

	void *body = malloc(props->max_size); // create memory to store widest value
	if(body)
	{
		for(unsigned i = 0; i < props->nimpls; i++)
		{
			props_impl_t *impl = &props->impls[i];

			if(impl->access == props->urid.patch_readable)
				continue; // skip read-only, as it makes no sense to restore them

			// always clear memory
			memset(body, 0x0, props->max_size);

			_props_impl_spin_lock(impl, PROP_STATE_NONE, PROP_STATE_LOCK);

			// create temporary copy of value, store() may well be blocking
			const uint32_t size = impl->stash.size;
			memcpy(body, impl->stash.body, size);

			_props_impl_unlock(impl, PROP_STATE_NONE);

			if(  map_path && map_path->abstract_path
				&& (impl->type == props->urid.atom_path) )
			{
				const char *path = strstr(body, "file://") == body
					? (char *)body + 7 // skip "file://"
					: (char *)body;

				char *abstract = NULL;

				if(  make_path && make_path->path
					&& (strstr(path, "/tmp") == path) )
				{
					char *absolute = make_path->path(make_path->handle, basename(path));

					if(absolute)
					{
						if(_copy_file(absolute, path) == 0)
						{
							abstract = map_path->abstract_path(map_path->handle, absolute);
						}

						_free_path(free_path, absolute);
					}
				}
				else
				{
					abstract = map_path->abstract_path(map_path->handle, path);
				}

				if(abstract)
				{
					const uint32_t sz = strlen(abstract) + 1;
					store(state, impl->property, abstract, sz, impl->type, flags);

					_free_path(free_path, abstract);
				}
			}
			else // !Path
			{
				store(state, impl->property, body, size, impl->type, flags);
			}
		}

		free(body);
	}

	return LV2_STATE_SUCCESS;
}

LV2_State_Status
props_restore(props_t *props, LV2_State_Retrieve_Function retrieve,
	LV2_State_Handle state, uint32_t flags __attribute__((unused)),
	const LV2_Feature *const *features)
{
	const LV2_State_Map_Path *map_path = NULL;
	const LV2_State_Free_Path *free_path = NULL;

	for(unsigned i = 0; features[i]; i++)
	{
		if(!strcmp(features[i]->URI, LV2_STATE__mapPath))
		{
			map_path = features[i]->data;
		}
		if(!strcmp(features[i]->URI, LV2_STATE__freePath))
		{
			free_path = features[i]->data;
		}
	}

	for(unsigned i = 0; i < props->nimpls; i++)
	{
		props_impl_t *impl = &props->impls[i];

		if(impl->access == props->urid.patch_readable)
			continue; // skip read-only, as it makes no sense to restore them

		size_t size;
		uint32_t type;
		uint32_t _flags;
		const void *body = retrieve(state, impl->property, &size, &type, &_flags);

		if(  body
			&& (type == impl->type)
			&& ( (impl->def->max_size == 0) || (size <= impl->def->max_size) ) )
		{
			if(  map_path && map_path->absolute_path
				&& (type == props->urid.atom_path) )
			{
				char *absolute = map_path->absolute_path(map_path->handle, body);
				if(absolute)
				{
					const uint32_t sz = strlen(absolute) + 1;

					_props_impl_spin_lock(impl, PROP_STATE_NONE, PROP_STATE_LOCK);

					impl->stash.size = sz;
					memcpy(impl->stash.body, absolute, sz);

					_props_impl_unlock(impl, PROP_STATE_RESTORE);

					_free_path(free_path, absolute);
				}
			}
			else // !Path
			{
				_props_impl_spin_lock(impl, PROP_STATE_NONE, PROP_STATE_LOCK);

				impl->stash.size = size;
				memcpy(impl->stash.body, body, size);

				_props_impl_unlock(impl, PROP_STATE_RESTORE);
			}
		}
	}

	_props_restoring_set(props);

	return LV2_STATE_SUCCESS;
}

A  => src/props_private.h +21 -0
@@ 1,21 @@
/*
 * SPDX-FileCopyrightText: Hanspeter Portner <dev@open-music-kontrollers.ch>
 * SPDX-License-Identifier: Artistic-2.0
 */

#include <props.lv2/props.h>

#ifndef _LV2_PROPS_PRIVATE_H_
#define _LV2_PROPS_PRIVATE_H_

// enumerations
typedef enum _props_state_t {
	PROP_STATE_NONE    = 0,
	PROP_STATE_LOCK    = 1,
	PROP_STATE_RESTORE = 2
} props_state_t;

props_impl_t *
_props_impl_get(props_t *props, LV2_URID property);

#endif // _LV2_PROPS_PRIVATE_H_

A  => test/chunk.bin +0 -0
A  => test/chunk.bin.license +2 -0
@@ 1,2 @@
SPDX-FileCopyrightText: Hanspeter Portner <dev@open-music-kontrollers.ch>
SPDX-License-Identifier: CC0-1.0

A  => test/manifest.ttl.in +16 -0
@@ 1,16 @@
# SPDX-FileCopyrightText: Hanspeter Portner <dev@open-music-kontrollers.ch>
# SPDX-License-Identifier: Artistic-2.0

@prefix lv2:      <http://lv2plug.in/ns/lv2core#> .
@prefix owl:			<http://www.w3.org/2002/07/owl#> .
@prefix rdfs:     <http://www.w3.org/2000/01/rdf-schema#> .

@prefix props:		<http://open-music-kontrollers.ch/lv2/props#> .

# Orbit Looper
props:test
	a lv2:Plugin ;
	lv2:minorVersion @MINOR_VERSION@ ;
	lv2:microVersion @MICRO_VERSION@ ;
	lv2:binary <props@MODULE_SUFFIX@> ;
	rdfs:seeAlso <props.ttl> .

A  => test/props.c +302 -0
@@ 1,302 @@
/*
 * SPDX-FileCopyrightText: Hanspeter Portner <dev@open-music-kontrollers.ch>
 * SPDX-License-Identifier: Artistic-2.0
 */

#include <stdio.h>

#include <props.lv2/props.h>

#include <lv2/log/log.h>
#include <lv2/log/logger.h>

#define PROPS_PREFIX		"http://open-music-kontrollers.ch/lv2/props#"
#define PROPS_TEST_URI	PROPS_PREFIX"test"

#define MAX_NPROPS 7
#define MAX_STRLEN 256

typedef struct _plugstate_t plugstate_t;
typedef struct _plughandle_t plughandle_t;

struct _plugstate_t {
	int32_t val1;
	int64_t val2;
	float val3;
	double val4;
	char val5 [MAX_STRLEN];
	char val6 [MAX_STRLEN];
	uint8_t val7 [MAX_STRLEN];
};

struct _plughandle_t {
	LV2_URID_Map *map;
	LV2_Log_Log *log;
	LV2_Log_Logger logger;
	LV2_Atom_Forge forge;
	LV2_Atom_Forge_Ref ref;

	PROPS_T(props, MAX_NPROPS);
	plugstate_t state;
	plugstate_t stash;

	struct {
		LV2_URID val2;
		LV2_URID val4;
	} urid;

	const LV2_Atom_Sequence *event_in;
	LV2_Atom_Sequence *event_out;
};

static void
_intercept(void *data, int64_t frames __attribute__((unused)), props_impl_t *impl)
{
	plughandle_t *handle = data;

	lv2_log_trace(&handle->logger, "SET     : %s\n", impl->def->property);
}

static void
_intercept_stat1(void *data, int64_t frames, props_impl_t *impl)
{
	plughandle_t *handle = data;

	_intercept(data, frames, impl);

	handle->state.val2 = handle->state.val1 * 2;

	props_set(&handle->props, &handle->forge, frames, handle->urid.val2, &handle->ref);
}

static void
_intercept_stat3(void *data, int64_t frames, props_impl_t *impl)
{
	plughandle_t *handle = data;

	_intercept(data, frames, impl);

	handle->state.val4 = handle->state.val3 * 2;

	props_set(&handle->props, &handle->forge, frames, handle->urid.val4, &handle->ref);
}

static void
_intercept_stat6(void *data, int64_t frames, props_impl_t *impl)
{
	_intercept(data, frames, impl);
}

static const props_def_t defs [MAX_NPROPS] = {
	{
		.property = PROPS_PREFIX"statInt",
		.offset = offsetof(plugstate_t, val1),
		.type = LV2_ATOM__Int,
		.event_cb = _intercept_stat1,
	},
	{
		.property = PROPS_PREFIX"statLong",
		.access = LV2_PATCH__readable,
		.offset = offsetof(plugstate_t, val2),
		.type = LV2_ATOM__Long,
		.event_cb = _intercept,
	},
	{
		.property = PROPS_PREFIX"statFloat",
		.offset = offsetof(plugstate_t, val3),
		.type = LV2_ATOM__Float,
		.event_cb = _intercept_stat3,
	},
	{	
		.property = PROPS_PREFIX"statDouble",
		.access = LV2_PATCH__readable,
		.offset = offsetof(plugstate_t, val4),
		.type = LV2_ATOM__Double,
		.event_cb = _intercept,
	},
	{
		.property = PROPS_PREFIX"statString",
		.offset = offsetof(plugstate_t, val5),
		.type = LV2_ATOM__String,
		.event_cb = _intercept,
		.max_size = MAX_STRLEN // strlen
	},
	{
		.property = PROPS_PREFIX"statPath",
		.offset = offsetof(plugstate_t, val6),
		.type = LV2_ATOM__Path,
		.event_cb = _intercept_stat6,
		.max_size = MAX_STRLEN // strlen
	},
	{
		.property = PROPS_PREFIX"statChunk",
		.offset = offsetof(plugstate_t, val7),
		.type = LV2_ATOM__Chunk,
		.event_cb = _intercept,
		.max_size = MAX_STRLEN // strlen
	}
};

static LV2_Handle
instantiate(const LV2_Descriptor* descriptor,
	double rate __attribute__((unused)),
	const char *bundle_path __attribute__((unused)),
	const LV2_Feature *const *features)
{
	plughandle_t *handle = calloc(1, sizeof(plughandle_t));
	if(!handle)
		return NULL;

	for(unsigned i=0; features[i]; i++)
	{
		if(!strcmp(features[i]->URI, LV2_URID__map))
			handle->map = features[i]->data;
		else if(!strcmp(features[i]->URI, LV2_LOG__log))
			handle->log = features[i]->data;
	}

	if(!handle->map)
	{
		fprintf(stderr,
			"%s: Host does not support urid:map\n", descriptor->URI);
		free(handle);
		return NULL;
	}
	if(!handle->log)
	{
		fprintf(stderr,
			"%s: Host does not support log:log\n", descriptor->URI);
		free(handle);
		return NULL;
	}

	lv2_log_logger_init(&handle->logger, handle->map, handle->log);
	lv2_atom_forge_init(&handle->forge, handle->map);

	if(!props_init(&handle->props, descriptor->URI,
		defs, MAX_NPROPS, &handle->state, &handle->stash,
		handle->map, handle))
	{
		lv2_log_error(&handle->logger, "failed to initialize property structure\n");
		free(handle);
		return NULL;
	}

	handle->urid.val2 = props_map(&handle->props, PROPS_PREFIX"statLong");
	handle->urid.val4 = props_map(&handle->props, PROPS_PREFIX"statDouble");

	return handle;
}

static void
connect_port(LV2_Handle instance, uint32_t port, void *data)
{
	plughandle_t *handle = (plughandle_t *)instance;

	switch(port)
	{
		case 0:
			handle->event_in = (const LV2_Atom_Sequence *)data;
			break;
		case 1:
			handle->event_out = (LV2_Atom_Sequence *)data;
			break;
		default:
			break;
	}
}

static void
run(LV2_Handle instance, uint32_t nsamples __attribute__((unused)))
{
	plughandle_t *handle = instance;

	uint32_t capacity = handle->event_out->atom.size;
	LV2_Atom_Forge_Frame frame;
	lv2_atom_forge_set_buffer(&handle->forge, (uint8_t *)handle->event_out, capacity);
	handle->ref = lv2_atom_forge_sequence_head(&handle->forge, &frame, 0);

	props_idle(&handle->props, &handle->forge, 0, &handle->ref);

	LV2_ATOM_SEQUENCE_FOREACH(handle->event_in, ev)
	{
		const LV2_Atom_Object *obj = (const LV2_Atom_Object *)&ev->body;

		if(handle->ref)
			props_advance(&handle->props, &handle->forge, ev->time.frames, obj, &handle->ref);
	}

	if(handle->ref)
		lv2_atom_forge_pop(&handle->forge, &frame);
	else
		lv2_atom_sequence_clear(handle->event_out);
}

static void
cleanup(LV2_Handle instance)
{
	plughandle_t *handle = instance;

	free(handle);
}

static LV2_State_Status
_state_save(LV2_Handle instance, LV2_State_Store_Function store,
	LV2_State_Handle state, uint32_t flags,
	const LV2_Feature *const *features)
{
	plughandle_t *handle = (plughandle_t *)instance;

	return props_save(&handle->props, store, state, flags, features);
}

static LV2_State_Status
_state_restore(LV2_Handle instance, LV2_State_Retrieve_Function retrieve,
	LV2_State_Handle state, uint32_t flags,
	const LV2_Feature *const *features)
{
	plughandle_t *handle = (plughandle_t *)instance;

	return props_restore(&handle->props, retrieve, state, flags, features);
}

LV2_State_Interface state_iface = {
	.save = _state_save,
	.restore = _state_restore
};

static const void *
extension_data(const char *uri)
{
	if(!strcmp(uri, LV2_STATE__interface))
		return &state_iface;
	return NULL;
}

const LV2_Descriptor props_test = {
	.URI						= PROPS_TEST_URI,
	.instantiate		= instantiate,
	.connect_port		= connect_port,
	.activate				= NULL,
	.run						= run,
	.deactivate			= NULL,
	.cleanup				= cleanup,
	.extension_data	= extension_data
};

#ifdef _WIN32
__declspec(dllexport)
#else
__attribute__((visibility("default")))
#endif
const LV2_Descriptor*
lv2_descriptor(uint32_t index)
{
	switch(index)
	{
		case 0:
			return &props_test;
		default:
			return NULL;
	}
}

A  => test/props.ttl +139 -0
@@ 1,139 @@
# SPDX-FileCopyrightText: Hanspeter Portner <dev@open-music-kontrollers.ch>
# SPDX-License-Identifier: Artistic-2.0

@prefix owl:			<http://www.w3.org/2002/07/owl#> .
@prefix foaf:			<http://xmlns.com/foaf/0.1/> .
@prefix doap:			<http://usefulinc.com/ns/doap#> .
@prefix rdf:			<http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: 		<http://www.w3.org/2000/01/rdf-schema#> .
@prefix lv2:			<http://lv2plug.in/ns/lv2core#> .
@prefix atom:			<http://lv2plug.in/ns/ext/atom#> .
@prefix urid:			<http://lv2plug.in/ns/ext/urid#> .
@prefix state:		<http://lv2plug.in/ns/ext/state#> .
@prefix patch:		<http://lv2plug.in/ns/ext/patch#> .
@prefix log:			<http://lv2plug.in/ns/ext/log#> .
@prefix units:		<http://lv2plug.in/ns/extensions/units#> .
@prefix xsd:			<http://www.w3.org/2001/XMLSchema#> .

@prefix omk:			<http://open-music-kontrollers.ch/ventosus#> .
@prefix proj:			<http://open-music-kontrollers.ch/lv2/> .
@prefix props:		<http://open-music-kontrollers.ch/lv2/props#> .

# Maintainer
omk:me
	a foaf:Person ;
	foaf:name "Hanspeter Portner" ;
	foaf:mbox <mailto:dev@open-music-kontrollers.ch> ;
	foaf:homepage <http://open-music-kontrollers.ch> .

# Project
proj:props
	a doap:Project ;
	doap:maintainer omk:me ;
	doap:name "Props Bundle" .

props:statInt
	a lv2:Parameter ;
	rdfs:range atom:Int ;
	rdfs:label "statInt" ;
	rdfs:comment "This is a 32-bit integer" ;
	units:unit units:hz ;
	lv2:minimum 0 ;
	lv2:maximum 10 .

props:statLong
	a lv2:Parameter ;
	rdfs:range atom:Long ;
	rdfs:label "statLong" ;
	rdfs:comment "This is a 64-bit integer" ;
	units:unit units:khz ;
	lv2:minimum 0 ;
	lv2:maximum 20 .

props:statFloat
	a lv2:Parameter ;
	rdfs:range atom:Float ;
	rdfs:label "statFloat" ;
	rdfs:comment "This is a 32-bit float" ;
	units:unit units:mhz ;
	lv2:minimum -0.5 ;
	lv2:maximum 0.5 .

props:statDouble
	a lv2:Parameter ;
	rdfs:range atom:Double ;
	rdfs:label "statDouble" ;
	rdfs:comment "This is a 64-bit double" ;
	units:unit units:db ;
	lv2:minimum -1.0 ;
	lv2:maximum 1.0 .

props:statString
	a lv2:Parameter ;
	rdfs:range atom:String ;
	rdfs:label "statString" ;
	rdfs:comment "This is a string" .

props:statPath
	a lv2:Parameter ;
	rdfs:range atom:Path ;
	rdfs:label "statPath" ;
	rdfs:comment "This is a path" .

props:statChunk
	a lv2:Parameter ;
	rdfs:range atom:Chunk;
	rdfs:label "statChunk" ;
	rdfs:comment "This is a chunk" .

# Looper Test
props:test
	a lv2:Plugin ,
		lv2:ConverterPlugin ;
	doap:name "Props Test" ;
	doap:license <https://spdx.org/licenses/Artistic-2.0> ;
	lv2:project proj:props ;
	lv2:requiredFeature urid:map, log:log, state:loadDefaultState ;
	lv2:optionalFeature lv2:isLive, lv2:hardRTCapable, state:threadSafeRestore ;
	lv2:extensionData	state:interface ;

	lv2:port [
		# sink event port
	  a lv2:InputPort ,
			atom:AtomPort ;
		atom:bufferType atom:Sequence ;
		atom:supports patch:Message ;
		lv2:index 0 ;
		lv2:symbol "event_in" ;
		lv2:name "Event Input" ;
		lv2:designation lv2:control ;
	] , [
		# source event port
	  a lv2:OutputPort ,
			atom:AtomPort ;
		atom:bufferType atom:Sequence ;
		atom:supports patch:Message ;
		lv2:index 1 ;
		lv2:symbol "event_out" ;
		lv2:name "Event Output" ;
		lv2:designation lv2:control ;
	] ;

	patch:writable
		props:statInt ,
		props:statFloat ,
		props:statString ,
		props:statPath ,
		props:statChunk ;

	patch:readable
		props:statLong ,
		props:statDouble ;

	state:state [
		props:statInt 4 ;
		props:statFloat "0.4"^^xsd:float ;
		props:statString "Hello world" ;
		props:statPath <> ;
		props:statChunk "AQIDBAUGBw=="^^xsd:base64Binary ;
	] .

A  => test/props_test.c +650 -0
@@ 1,650 @@
/*
 * SPDX-FileCopyrightText: Hanspeter Portner <dev@open-music-kontrollers.ch>
 * SPDX-License-Identifier: Artistic-2.0
 */

#include <assert.h>

#include <src/props_private.h>

#define MAX_URIDS 128
#define STR_SIZE 32
#define CHUNK_SIZE 16
#define VEC_SIZE 13

#define PROPS_PREFIX		"http://open-music-kontrollers.ch/lv2/props#"
#define PROPS_TEST_URI	PROPS_PREFIX"test"

typedef struct _plugstate_t plugstate_t;
typedef struct _urid_t urid_t;
typedef struct _handle_t handle_t;
typedef void (*test_t)(handle_t *handle);
typedef void *(*ser_atom_realloc_t)(void *data, void *buf, size_t size);
typedef void  (*ser_atom_free_t)(void *data, void *buf);

typedef struct _ser_atom_t ser_atom_t;

struct _plugstate_t {
	int32_t b32;
	int32_t i32;
	int64_t i64;
	float f32;
	double f64;
	uint32_t urid;
	char str [STR_SIZE];
	char uri [STR_SIZE];
	char path [STR_SIZE];
	uint8_t chunk [CHUNK_SIZE];
	LV2_Atom_Literal_Body lit;
		char lit_body [STR_SIZE];
	LV2_Atom_Vector_Body vec;
		int32_t vec_body [VEC_SIZE];
	LV2_Atom_Object_Body obj; //FIXME
	LV2_Atom_Sequence_Body seq; //FIXME
};

struct _urid_t {
	LV2_URID urid;
	char *uri;
};

enum {
	PROP_b32 = 0,
	PROP_i32,
	PROP_i64,
	PROP_f32,
	PROP_f64,
	PROP_urid,
	PROP_str,
	PROP_uri,
	PROP_path,
	PROP_chunk,
	PROP_lit,
	PROP_vec,
	PROP_obj,
	PROP_seq,

	MAX_NPROPS
};

struct _handle_t {
	PROPS_T(props, MAX_NPROPS);
	plugstate_t state;
	plugstate_t stash;

	LV2_URID_Map map;

	urid_t urids [MAX_URIDS];
	LV2_URID urid;
};

struct _ser_atom_t {
	ser_atom_realloc_t realloc;
	ser_atom_free_t free;
	void *data;

	size_t size;
	size_t offset;
	union {
		uint8_t *buf;
		LV2_Atom *atom;
	};
};

static LV2_Atom_Forge_Ref
_ser_atom_sink(LV2_Atom_Forge_Sink_Handle handle, const void *buf,
	uint32_t size)
{
	ser_atom_t *ser = handle;
	const size_t needed = ser->offset + size;

	while(needed > ser->size)
	{
		const size_t augmented = ser->size
			? ser->size << 1
			: 1024;
		uint8_t *grown = ser->realloc(ser->data, ser->buf, augmented);
		if(!grown) // out-of-memory
		{
			return 0;
		}

		ser->buf = grown;
		ser->size = augmented;
	}

	const LV2_Atom_Forge_Ref ref = ser->offset + 1;
	memcpy(&ser->buf[ser->offset], buf, size);
	ser->offset += size;

	return ref;
}

static LV2_Atom *
_ser_atom_deref(LV2_Atom_Forge_Sink_Handle handle, LV2_Atom_Forge_Ref ref)
{
	ser_atom_t *ser = handle;

	if(!ref) // invalid reference
	{
		return NULL;
	}

	const size_t offset = ref - 1;
	return (LV2_Atom *)&ser->buf[offset];
}

static void *
_ser_atom_realloc(void *data, void *buf, size_t size)
{
	(void)data;

	return realloc(buf, size);
}

static void
_ser_atom_free(void *data, void *buf)
{
	(void)data;

	free(buf);
}

static int
ser_atom_deinit(ser_atom_t *ser)
{
	if(!ser)
	{
		return -1;
	}

	if(ser->buf)
	{
		ser->free(ser->data, ser->buf);
	}

	ser->size = 0;
	ser->offset = 0;
	ser->buf = NULL;

	return 0;
}

static int
ser_atom_funcs(ser_atom_t *ser, ser_atom_realloc_t realloc,
	ser_atom_free_t free, void *data)
{
	if(!ser || !realloc || !free || ser_atom_deinit(ser))
	{
		return -1;
	}

	ser->realloc = realloc;
	ser->free = free;
	ser->data = data;

	return 0;
}

static int
ser_atom_init(ser_atom_t *ser)
{
	if(!ser)
	{
		return -1;
	}

	ser->size = 0;
	ser->offset = 0;
	ser->buf = NULL;

	return ser_atom_funcs(ser, _ser_atom_realloc, _ser_atom_free, NULL);
}

#if 0
static int
ser_atom_reset(ser_atom_t *ser, LV2_Atom_Forge *forge)
{
	if(!ser || !forge)
	{
		return -1;
	}

	lv2_atom_forge_set_sink(forge, _ser_atom_sink, _ser_atom_deref, ser);

	ser->offset = 0;

	return 0;
}
#endif

static LV2_Atom *
ser_atom_get(ser_atom_t *ser)
{
	if(!ser)
	{
		return NULL;
	}

	return ser->atom;
}

static LV2_URID
_map(LV2_URID_Map_Handle instance, const char *uri)
{
	handle_t *handle = instance;

	urid_t *itm;
	for(itm=handle->urids; itm->urid; itm++)
	{
		if(!strcmp(itm->uri, uri))
		{
			return itm->urid;
		}
	}

	assert(handle->urid + 1 < MAX_URIDS);

	// create new
	itm->urid = ++handle->urid;
	itm->uri = strdup(uri);

	return itm->urid;
}

static void
_map_free(handle_t *handle)
{
	for(unsigned i = 0; i < MAX_URIDS; i++)
	{
		urid_t *itm = &handle->urids[i];

		if(itm->uri)
		{
			free(itm->uri);
		}

		memset(itm, 0x0, sizeof(urid_t));
	}
}

static const props_def_t defs [MAX_NPROPS] = {
	[PROP_b32] = {
		.property = PROPS_PREFIX"b32",
		.offset = offsetof(plugstate_t, b32),
		.type = LV2_ATOM__Bool
	},
	[PROP_i32] = {
		.property = PROPS_PREFIX"i32",
		.offset = offsetof(plugstate_t, i32),
		.type = LV2_ATOM__Int
	},
	[PROP_i64] = {
		.property = PROPS_PREFIX"i64",
		.offset = offsetof(plugstate_t, i64),
		.type = LV2_ATOM__Long
	},
	[PROP_f32] = {
		.property = PROPS_PREFIX"f32",
		.offset = offsetof(plugstate_t, f32),
		.type = LV2_ATOM__Float
	},
	[PROP_f64] = {
		.property = PROPS_PREFIX"f64",
		.offset = offsetof(plugstate_t, f64),
		.type = LV2_ATOM__Double
	},
	[PROP_urid] = {
		.property = PROPS_PREFIX"urid",
		.offset = offsetof(plugstate_t, urid),
		.type = LV2_ATOM__URID
	},
	[PROP_str] = {
		.property = PROPS_PREFIX"str",
		.offset = offsetof(plugstate_t, str),
		.type = LV2_ATOM__String,
		.max_size = STR_SIZE
	},
	[PROP_uri] = {
		.property = PROPS_PREFIX"uri",
		.offset = offsetof(plugstate_t, uri),
		.type = LV2_ATOM__URI,
		.max_size = STR_SIZE
	},
	[PROP_path] = {
		.property = PROPS_PREFIX"path",
		.offset = offsetof(plugstate_t, path),
		.type = LV2_ATOM__Path,
		.max_size = STR_SIZE
	},
	[PROP_chunk] = {
		.property = PROPS_PREFIX"chunk",
		.offset = offsetof(plugstate_t, chunk),
		.type = LV2_ATOM__Chunk,
		.max_size = CHUNK_SIZE
	},
	[PROP_lit] = {
		.property = PROPS_PREFIX"lit",
		.offset = offsetof(plugstate_t, lit),
		.type = LV2_ATOM__Literal,
		.max_size = sizeof(LV2_Atom_Literal_Body) + STR_SIZE
	},
	[PROP_vec] = {
		.property = PROPS_PREFIX"vec",
		.offset = offsetof(plugstate_t, vec),
		.type = LV2_ATOM__Literal,
		.max_size = sizeof(LV2_Atom_Vector_Body) + VEC_SIZE*sizeof(int32_t)
	},
	[PROP_obj] = {
		.property = PROPS_PREFIX"obj",
		.offset = offsetof(plugstate_t, obj),
		.type = LV2_ATOM__Object,
		.max_size = sizeof(LV2_Atom_Object_Body) + 0 //FIXME
	},
	[PROP_seq] = {
		.property = PROPS_PREFIX"seq",
		.offset = offsetof(plugstate_t, seq),
		.type = LV2_ATOM__Sequence,
		.max_size = sizeof(LV2_Atom_Sequence_Body) + 0 //FIXME
	}
};

static void
_test_1(handle_t *handle)
{
	assert(handle);

	props_t *props = &handle->props;
	plugstate_t *state = &handle->state;
	plugstate_t *stash = &handle->stash;
	LV2_URID_Map *map = &handle->map;

	for(unsigned i = 0; i < MAX_NPROPS; i++)
	{
		const props_def_t *def = &defs[i];

		const LV2_URID property = props_map(props, def->property);
		assert(property != 0);
		assert(property == map->map(map->handle, def->property));

		assert(strcmp(props_unmap(props, property), def->property) == 0);

		props_impl_t *impl = _props_impl_get(props, property);
		assert(impl);

		const LV2_URID type = map->map(map->handle, def->type);
		const LV2_URID access = map->map(map->handle, def->access
			? def->access : LV2_PATCH__writable);

		assert(impl->property == property);
		assert(impl->type == type);
		assert(impl->access == access);

		assert(impl->def == def);

		assert(atomic_load(&impl->state) == PROP_STATE_NONE);
		assert(impl->stashing == false);

		switch(i)
		{
			case PROP_b32:
			{
				assert(impl->value.size == sizeof(state->b32));
				assert(impl->value.body == &state->b32);

				assert(impl->stash.size == sizeof(stash->b32));
				assert(impl->stash.body == &stash->b32);
			} break;
			case PROP_i32:
			{
				assert(impl->value.size == sizeof(state->i32));
				assert(impl->value.body == &state->i32);

				assert(impl->stash.size == sizeof(stash->i32));
				assert(impl->stash.body == &stash->i32);
			} break;
			case PROP_i64:
			{
				assert(impl->value.size == sizeof(state->i64));
				assert(impl->value.body == &state->i64);

				assert(impl->stash.size == sizeof(stash->i64));
				assert(impl->stash.body == &stash->i64);
			} break;
			case PROP_f32:
			{
				assert(impl->value.size == sizeof(state->f32));
				assert(impl->value.body == &state->f32);

				assert(impl->stash.size == sizeof(stash->f32));
				assert(impl->stash.body == &stash->f32);
			} break;
			case PROP_f64:
			{
				assert(impl->value.size == sizeof(state->f64));
				assert(impl->value.body == &state->f64);

				assert(impl->stash.size == sizeof(stash->f64));
				assert(impl->stash.body == &stash->f64);
			} break;
			case PROP_urid:
			{
				assert(impl->value.size == sizeof(state->urid));
				assert(impl->value.body == &state->urid);

				assert(impl->stash.size == sizeof(stash->urid));
				assert(impl->stash.body == &stash->urid);
			} break;
			case PROP_str:
			{
				assert(impl->value.size == 0);
				assert(impl->value.body == &state->str);

				assert(impl->stash.size == 0);
				assert(impl->stash.body == &stash->str);
			} break;
			case PROP_uri:
			{
				assert(impl->value.size == 0);
				assert(impl->value.body == &state->uri);

				assert(impl->stash.size == 0);
				assert(impl->stash.body == &stash->uri);
			} break;
			case PROP_path:
			{
				assert(impl->value.size == 0);
				assert(impl->value.body == &state->path);

				assert(impl->stash.size == 0);
				assert(impl->stash.body == &stash->path);
			} break;
			case PROP_chunk:
			{
				assert(impl->value.size == 0);
				assert(impl->value.body == &state->chunk);

				assert(impl->stash.size == 0);
				assert(impl->stash.body == &stash->chunk);
			} break;
			case PROP_lit:
			{
				assert(impl->value.size == sizeof(state->lit));
				assert(impl->value.body == &state->lit);

				assert(impl->stash.size == sizeof(stash->lit));
				assert(impl->stash.body == &stash->lit);
			} break;
			case PROP_vec:
			{
				assert(impl->value.size == sizeof(state->vec));
				assert(impl->value.body == &state->vec);

				assert(impl->stash.size == sizeof(stash->vec));
				assert(impl->stash.body == &stash->vec);
			} break;
			case PROP_obj:
			{
				assert(impl->value.size == sizeof(state->obj));
				assert(impl->value.body == &state->obj);

				assert(impl->stash.size == sizeof(stash->obj));
				assert(impl->stash.body == &stash->obj);
			} break;
			case PROP_seq:
			{
				assert(impl->value.size == sizeof(state->seq));
				assert(impl->value.body == &state->seq);

				assert(impl->stash.size == sizeof(stash->seq));
				assert(impl->stash.body == &stash->seq);
			} break;
			default:
			{
				assert(false);
			} break;
		}
	}
}

static void
_test_2(handle_t *handle)
{
	assert(handle);

	props_t *props = &handle->props;
	plugstate_t *state = &handle->state;
	plugstate_t *stash = &handle->stash;
	LV2_URID_Map *map = &handle->map;

	LV2_Atom_Forge forge;
	LV2_Atom_Forge_Frame frame;
	LV2_Atom_Forge_Ref ref;
	ser_atom_t ser;

	lv2_atom_forge_init(&forge, map);
	assert(ser_atom_init(&ser) == 0);

	lv2_atom_forge_set_sink(&forge, _ser_atom_sink, _ser_atom_deref, &ser);

	ref = lv2_atom_forge_sequence_head(&forge, &frame, 0);
	assert(ref);

	props_idle(props, &forge, 0, &ref);
	assert(ref);

	const LV2_URID property = props_map(props, defs[0].property);
	assert(property);

	state->b32 = true;

	props_set(props, &forge, 1, property, &ref);
	assert(ref);

	state->b32 = false;

	lv2_atom_forge_pop(&forge, &frame);

	const LV2_Atom_Sequence *seq = (const LV2_Atom_Sequence *)ser_atom_get(&ser);
	assert(seq);

	unsigned nevs = 0;
	LV2_ATOM_SEQUENCE_FOREACH(seq, ev)
	{
		const LV2_Atom *atom = &ev->body;

		assert(ev->time.frames == 1);
		assert(atom->type == forge.Object);

		const LV2_Atom_Object *obj = (const LV2_Atom_Object *)atom;
		assert(obj->body.id == 0);

		if(obj->body.otype == props->urid.state_StateChanged)
		{
			continue;
		}

		assert(obj->body.otype == props->urid.patch_set);

		unsigned nprops = 0;
		LV2_ATOM_OBJECT_FOREACH(obj, prop)
		{
			assert(prop->context == 0);

			if(prop->key == props->urid.patch_subject)
			{
				const LV2_Atom_URID *val = (const LV2_Atom_URID *)&prop->value;

				assert(val->atom.type == forge.URID);
				assert(val->atom.size == sizeof(uint32_t));
				assert(val->body == props->urid.subject);

				nprops |= 0x1;
			}
			else if(prop->key == props->urid.patch_property)
			{
				const LV2_Atom_URID *val = (const LV2_Atom_URID *)&prop->value;

				assert(val->atom.type == forge.URID);
				assert(val->atom.size == sizeof(uint32_t));
				assert(val->body == property);

				nprops |= 0x2;
			}
			else if(prop->key == props->urid.patch_value)
			{
				const LV2_Atom_Bool *val = (const LV2_Atom_Bool *)&prop->value;

				assert(val->atom.type == forge.Bool);
				assert(val->atom.size == sizeof(int32_t));
				assert(val->body == true);

				nprops |= 0x4;
			}
			else
			{
				assert(false);
			}
		}
		assert(nprops == 0x7);

		assert(props_advance(props, &forge, ev->time.frames, obj, &ref) == 1);

		assert(state->b32 == true);
		assert(stash->b32 == true);

		nevs |= 0x1;
	}
	assert(nevs == 0x1);

	assert(ser_atom_deinit(&ser) == 0);
}

static const test_t tests [] = {
	_test_1,
	_test_2,
	NULL
};

int
main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
{
	static handle_t handle;

	for(const test_t *test = tests; *test; test++)
	{
		memset(&handle, 0, sizeof(handle));

		handle.map.handle = &handle;
		handle.map.map = _map;

		assert(props_init(&handle.props, PROPS_PREFIX"subj", defs, MAX_NPROPS,
			&handle.state, &handle.stash, &handle.map, NULL) == 1);

		(*test)(&handle);

		_map_free(&handle);
	}

	return 0;
}