aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.clang-tidy22
-rw-r--r--.gitignore18
-rw-r--r--.gitmodules3
-rw-r--r--.reuse/dep512
-rw-r--r--COPYING16
-rw-r--r--INSTALL59
-rw-r--r--INSTALL.md76
-rw-r--r--LICENSES/0BSD.txt12
l---------LICENSES/ISC.txt1
-rw-r--r--NEWS48
-rw-r--r--doc/jalv.13
-rw-r--r--doc/jalv.gtk.158
-rw-r--r--doc/jalv.gtk3.13
-rw-r--r--doc/jalv.qt5.13
-rw-r--r--doc/meson.build12
-rw-r--r--jalv.ttl29
-rw-r--r--meson.build430
-rw-r--r--meson/suppressions/meson.build185
-rw-r--r--meson_options.txt38
-rw-r--r--src/attributes.h15
-rw-r--r--src/backend.h38
-rw-r--r--src/control.c125
-rw-r--r--src/control.h103
-rw-r--r--src/frontend.h53
-rw-r--r--src/jack.c111
-rw-r--r--src/jalv.c1003
-rw-r--r--src/jalv_config.h181
-rw-r--r--src/jalv_console.c105
-rw-r--r--src/jalv_gtk.c488
-rw-r--r--src/jalv_internal.h481
-rw-r--r--src/jalv_qt.cpp88
-rw-r--r--src/jalv_qt.hpp74
-rw-r--r--src/log.c105
-rw-r--r--src/log.h74
-rw-r--r--src/lv2_evbuf.c84
-rw-r--r--src/lv2_evbuf.h21
-rw-r--r--src/nodes.h56
-rw-r--r--src/options.h35
-rw-r--r--src/port.h35
-rw-r--r--src/portaudio.c55
-rw-r--r--src/state.c56
-rw-r--r--src/state.h64
-rw-r--r--src/symap.c143
-rw-r--r--src/symap.h40
-rw-r--r--src/types.h22
-rw-r--r--src/urids.h48
-rw-r--r--src/worker.c240
-rw-r--r--src/worker.h101
-rw-r--r--src/zix/common.h138
-rw-r--r--src/zix/ring.c224
-rw-r--r--src/zix/ring.h141
-rw-r--r--src/zix/sem.h242
-rw-r--r--src/zix/thread.h132
-rw-r--r--subprojects/lilv.wrap8
-rw-r--r--subprojects/lv2.wrap8
-rw-r--r--subprojects/serd.wrap8
-rw-r--r--subprojects/sord.wrap8
-rw-r--r--subprojects/sratom.wrap8
-rw-r--r--subprojects/suil.wrap8
-rw-r--r--subprojects/zix.wrap14
-rw-r--r--test/meson.build42
-rwxr-xr-xwaf27
m---------waflib0
-rw-r--r--wscript420
64 files changed, 3257 insertions, 3243 deletions
diff --git a/.clang-tidy b/.clang-tidy
index 0c011a4..6262c89 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -1,23 +1,20 @@
Checks: >
*,
+ -*-c-arrays,
-*-magic-numbers,
-*-named-parameter,
-*-narrowing-conversions,
- -*-reserved-identifier,
- -*-uppercase-literal-suffix,
-altera-*,
+ -bugprone-assignment-in-if-condition,
-bugprone-branch-clone,
-bugprone-easily-swappable-parameters,
- -bugprone-macro-parentheses,
- -cert-dcl37-c,
- -cert-dcl51-cpp,
+ -bugprone-suspicious-realloc-usage,
+ -cert-err33-c,
-cert-err34-c,
- -clang-analyzer-core.CallAndMessage,
- -clang-analyzer-optin.cplusplus.VirtualCall,
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
+ -clang-analyzer-valist.Uninitialized,
-concurrency-mt-unsafe,
-cppcoreguidelines-avoid-non-const-global-variables,
- -cppcoreguidelines-macro-usage,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-reinterpret-cast,
@@ -29,11 +26,20 @@ Checks: >
-llvm-header-guard,
-llvmlibc-*,
-misc-no-recursion,
+ -misc-use-anonymous-namespace,
+ -modernize-macro-to-enum,
+ -modernize-use-nodiscard,
-modernize-use-trailing-return-type,
-readability-function-cognitive-complexity,
+ -readability-identifier-length,
-readability-implicit-bool-conversion,
-readability-non-const-parameter,
-readability-static-accessed-through-instance,
+CheckOptions:
+ - key: hicpp-uppercase-literal-suffix.NewSuffixes
+ value: 'L;U;UL;ULL'
+ - key: readability-uppercase-literal-suffix.NewSuffixes
+ value: 'L;U;UL;ULL'
WarningsAsErrors: '*'
HeaderFilterRegex: '.*'
FormatStyle: file
diff --git a/.gitignore b/.gitignore
index 204c242..82f3f01 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,14 @@
-build/**
-.waf-*
-.lock-waf*
-__pycache__
+# Copyright 2019-2022 David Robillard <d@drobilla.net>
+# SPDX-License-Identifier: 0BSD OR ISC
+
+build/
+subprojects/lilv/
+subprojects/lv2/
+subprojects/packagecache/
+subprojects/serd/
+subprojects/sord/
+subprojects/sphinxygen-1.0.4/
+subprojects/sratom/
+subprojects/suil/
+subprojects/zix-0.4.0/
+subprojects/zix/
diff --git a/.gitmodules b/.gitmodules
deleted file mode 100644
index b2babe7..0000000
--- a/.gitmodules
+++ /dev/null
@@ -1,3 +0,0 @@
-[submodule "waflib"]
- path = waflib
- url = ../autowaf.git
diff --git a/.reuse/dep5 b/.reuse/dep5
new file mode 100644
index 0000000..110b66c
--- /dev/null
+++ b/.reuse/dep5
@@ -0,0 +1,12 @@
+Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+Upstream-Name: jalv
+Upstream-Contact: David Robillard <d@drobilla.net>
+Source: https://gitlab.com/drobilla/jalv
+
+Files: .clang* .clant.json .gitignore AUTHORS NEWS jalv.desktop.in jalv.ttl
+Copyright: 2010-2022 David Robillard <d@drobilla.net>
+License: 0BSD OR ISC
+
+Files: INSTALL.md README.md doc/*.1
+Copyright: 2011-2020 David Robillard <d@drobilla.net>
+License: ISC
diff --git a/COPYING b/COPYING
index cc89191..ee1dda7 100644
--- a/COPYING
+++ b/COPYING
@@ -1,13 +1,13 @@
-Copyright 2011-2019 David Robillard <d@drobilla.net>
+Copyright 2011-2022 David Robillard <d@drobilla.net>
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.
+THE 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.
diff --git a/INSTALL b/INSTALL
deleted file mode 100644
index 623cddd..0000000
--- a/INSTALL
+++ /dev/null
@@ -1,59 +0,0 @@
-Installation Instructions
-=========================
-
-Basic Installation
-------------------
-
-Building this software requires only Python. To install with default options:
-
- ./waf configure
- ./waf
- ./waf install
-
-You may need to become root for the install stage, for example:
-
- sudo ./waf install
-
-Configuration Options
----------------------
-
-All supported options can be viewed using the command:
-
- ./waf --help
-
-Most options only need to be passed during the configure stage, for example:
-
- ./waf configure --prefix=/usr
- ./waf
- ./waf install
-
-Compiler Configuration
-----------------------
-
-Several standard environment variables can be used to control how compilers are
-invoked:
-
- * CC: Path to C compiler
- * CFLAGS: C compiler options
- * CXX: Path to C++ compiler
- * CXXFLAGS: C++ compiler options
- * CPPFLAGS: C preprocessor options
- * LINKFLAGS: Linker options
-
-Installation Directories
-------------------------
-
-The --prefix option (or the PREFIX environment variable) can be used to change
-the prefix which all files are installed under. There are also several options
-allowing for more fine-tuned control, see the --help output for details.
-
-Packaging
----------
-
-Everything can be installed to a specific root directory by passing a --destdir
-option to the install stage (or setting the DESTDIR environment variable),
-which adds a prefix to all install paths. For example:
-
- ./waf configure --prefix=/usr
- ./waf
- ./waf install --destdir=/tmp/package
diff --git a/INSTALL.md b/INSTALL.md
new file mode 100644
index 0000000..37ec9e8
--- /dev/null
+++ b/INSTALL.md
@@ -0,0 +1,76 @@
+Installation Instructions
+=========================
+
+Prerequisites
+-------------
+
+To build from source, you will need:
+
+ * A relatively modern C compiler (GCC, Clang, and MSVC are known to work).
+
+ * [Meson](http://mesonbuild.com/), which depends on
+ [Python](http://python.org/).
+
+This is a brief overview of building this project with meson. See the meson
+documentation for more detailed information.
+
+Configuration
+-------------
+
+The build is configured with the `setup` command, which creates a new build
+directory with the given name:
+
+ meson setup build
+
+Some environment variables are read during `setup` and stored with the
+configuration:
+
+ * `CC`: Path to C compiler.
+ * `CFLAGS`: C compiler options.
+ * `CXX`: Path to C++ compiler.
+ * `CXXFLAGS`: C++ compiler options.
+ * `LDFLAGS`: Linker options.
+
+However, it is better to use meson options for configuration. All options can
+be inspected with the `configure` command from within the build directory:
+
+ cd build
+ meson configure
+
+Options can be set by passing C-style "define" options to `configure`:
+
+ meson configure -Dc_args="-march=native" -Dprefix="/opt/mypackage/"
+
+Note that some options, such as `strict` and `werror` are for
+developer/maintainer use only. Please don't file issues about anything that
+happens when they are enabled.
+
+Building
+--------
+
+From within a configured build directory, everything can be built with the
+`compile` command:
+
+ meson compile
+
+Similarly, tests can be run with the `test` command:
+
+ meson test
+
+Meson can also generate a project for several popular IDEs, see the `backend`
+option for details.
+
+Installation
+------------
+
+A compiled project can be installed with the `install` command:
+
+ meson install
+
+You may need to acquire root permissions to install to a system-wide prefix.
+For packaging, the installation may be staged to a directory using the
+`DESTDIR` environment variable or the `--destdir` option:
+
+ DESTDIR=/tmp/mypackage/ meson install
+
+ meson install --destdir=/tmp/mypackage/
diff --git a/LICENSES/0BSD.txt b/LICENSES/0BSD.txt
new file mode 100644
index 0000000..b3e8cfd
--- /dev/null
+++ b/LICENSES/0BSD.txt
@@ -0,0 +1,12 @@
+Copyright 2011-2022 David Robillard <d@drobilla.net>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted.
+
+THE 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.
diff --git a/LICENSES/ISC.txt b/LICENSES/ISC.txt
new file mode 120000
index 0000000..012065c
--- /dev/null
+++ b/LICENSES/ISC.txt
@@ -0,0 +1 @@
+../COPYING \ No newline at end of file
diff --git a/NEWS b/NEWS
index 1d55187..5285c35 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,18 @@
-jalv (1.6.7) unstable;
+jalv (1.6.9) unstable; urgency=medium
+
+ * Add missing short versions of command line options
+ * Add option to install tool man pages
+ * Build Qt UI with -fPIC
+ * Clean up command line help output
+ * Fix clashing command line options
+ * Remove Gtk2 interface
+ * Replace use of deprecated Gtk interfaces
+ * Switch to external zix dependency
+ * Use Gtk switches instead of checkboxes for toggle controls
+
+ -- David Robillard <d@drobilla.net> Thu, 14 Mar 2024 18:26:10 +0000
+
+jalv (1.6.8) stable; urgency=medium
* Add Gtk plugin selector UI and desktop file
* Add missing option in console help output
@@ -6,16 +20,26 @@ jalv (1.6.7) unstable;
* Build Qt interface as C++14
* Change no-menu short option to m to avoid clash with jack-name
* Clean up and modernize code
+ * Fix "preset" console command when "presets" hasn't been called
* Fix MSVC build
+ * Fix atom buffer alignment
* Fix crash when running jalv without arguments
+ * Fix man page headers
+ * Fix memory leaks
* Fix outdated man pages
+ * Fix spurious transport messages
+ * Fix thread-safety of plugin/UI communication rings
* Flush stdout after printing control values in console interface
+ * Print status information consistently to stdout
+ * Propagate worker errors to the scheduler when possible
* Remove Gtkmm interface
* Remove Qt4 support
+ * Support both rdfs:label and lv2:name for port group labels
+ * Switch to meson build system
- -- David Robillard <d@drobilla.net> Mon, 30 May 2022 19:42:05 +0000
+ -- David Robillard <d@drobilla.net> Sat, 10 Sep 2022 00:43:05 +0000
-jalv (1.6.6) stable;
+jalv (1.6.6) stable; urgency=medium
* Add a command line argument to select a specific UI
* Explicitly support lv2:inPlaceBroken
@@ -25,14 +49,14 @@ jalv (1.6.6) stable;
-- David Robillard <d@drobilla.net> Thu, 07 Jan 2021 22:05:38 +0000
-jalv (1.6.4) stable;
+jalv (1.6.4) stable; urgency=medium
* Support rdfs:label for port groups
* Use screen refresh rate with Gtk3 and Qt5
-- David Robillard <d@drobilla.net> Sun, 10 Nov 2019 21:56:49 +0000
-jalv (1.6.2) stable;
+jalv (1.6.2) stable; urgency=medium
* Add jalv -i option to ignore stdin for background use
* Add several commands to console interface
@@ -48,7 +72,7 @@ jalv (1.6.2) stable;
-- David Robillard <d@drobilla.net> Thu, 06 Jun 2019 20:38:01 +0000
-jalv (1.6.0) stable;
+jalv (1.6.0) stable; urgency=medium
* Add PortAudio backend (compile time option, audio only)
* Add Qt5 version
@@ -74,7 +98,7 @@ jalv (1.6.0) stable;
-- David Robillard <d@drobilla.net> Wed, 04 Jan 2017 17:24:58 +0000
-jalv (1.4.6) stable;
+jalv (1.4.6) stable; urgency=medium
* Add option to print control output changes to stdout
* Add support for data-access extension (based on patch by Filipe Coelho)
@@ -89,7 +113,7 @@ jalv (1.4.6) stable;
-- David Robillard <d@drobilla.net> Fri, 08 Aug 2014 22:30:28 +0000
-jalv (1.4.4) stable;
+jalv (1.4.4) stable; urgency=medium
* Add --no-menu option for jalv.gtk
* Add -c option for setting controls from the command line
@@ -102,7 +126,7 @@ jalv (1.4.4) stable;
-- David Robillard <d@drobilla.net> Sat, 04 Jan 2014 21:11:45 +0000
-jalv (1.4.2) stable;
+jalv (1.4.2) stable; urgency=medium
* Add command-line option to control UI update frequency
* Fix crash when running "jalv" with bad command line arguments
@@ -117,7 +141,7 @@ jalv (1.4.2) stable;
-- David Robillard <d@drobilla.net> Fri, 09 Aug 2013 14:40:20 +0000
-jalv (1.4.0) stable;
+jalv (1.4.0) stable; urgency=medium
* Add menu bar and pass parent widget in Qt version for true UI embedding
* Add spinbuttons for precisely setting control values
@@ -130,7 +154,7 @@ jalv (1.4.0) stable;
-- David Robillard <d@drobilla.net> Sat, 23 Feb 2013 03:35:22 +0000
-jalv (1.2.0) stable;
+jalv (1.2.0) stable; urgency=medium
* Add Gtk3 UI
* Fix Jack Session support
@@ -146,7 +170,7 @@ jalv (1.2.0) stable;
-- David Robillard <d@drobilla.net> Sun, 14 Oct 2012 22:38:53 +0000
-jalv (1.0.0) stable;
+jalv (1.0.0) stable; urgency=medium
* Initial release
diff --git a/doc/jalv.1 b/doc/jalv.1
index 91976b2..068596c 100644
--- a/doc/jalv.1
+++ b/doc/jalv.1
@@ -48,7 +48,7 @@ Print control output changes to stdout.
\fB\-s\fR
Show plugin UI if possible.
-This option only works when plugins provide a UI that is usable via the non-embeddable showHide interface. For other, embeddable UIs, use jalv.gtk(1) or jalv.qt(1).
+This option only works when plugins provide a UI that is usable via the non-embeddable showHide interface. For other, embeddable UIs, use jalv.gtk3(1) or jalv.qt5(1).
.TP
\fB\-t\fR
@@ -72,7 +72,6 @@ The Jalv prompt supports several commands for interactive control:
\fBSYMBOL = VALUE\fR Set control value by symbol
.SH "SEE ALSO"
-.BR jalv.gtk(1),
.BR jalv.gtk3(1),
.BR jalv.qt5(2),
.BR lv2ls(1),
diff --git a/doc/jalv.gtk.1 b/doc/jalv.gtk.1
deleted file mode 100644
index c9dd284..0000000
--- a/doc/jalv.gtk.1
+++ /dev/null
@@ -1,58 +0,0 @@
-.TH JALV.GTK "18 Feb 2017"
-
-.SH NAME
-.B jalv.gtk \- Run an LV2 plugin as a JACK application (Gtk version).
-
-.SH SYNOPSIS
-.B jalv.gtk [OPTION]... PLUGIN_URI
-
-.SH OPTIONS
-
-.TP
-\fB\-b SIZE\fR
-Buffer size for plugin <=> UI communication.
-
-.TP
-\fB\-c SYM=VAL\fR
-Set control value (e.g. "vol=1.4").
-
-.TP
-\fB\-d\fR, \fB\-\-dump\fR
-Dump plugin <=> UI communication.
-
-.TP
-\fB\-U URI\fR
-Load the UI with the given URI.
-
-.TP
-\fB\-g\fR, \fB\-\-generic\-ui\fR
-Use Jalv generic UI and not the plugin UI.
-
-.TP
-\fB\-h\fR, \fB\-\-help\fR
-Print the command line options.
-
-.TP
-\fB\-l DIR\fR, \fB\-\-load DIR\fR
-Load state from state directory.
-
-.TP
-\fB\-p\fR, \fB\-\-print\-controls\fR
-Print control output changes to stdout.
-
-.TP
-\fB\-t\fR, \fB\-\-trace\fR
-Print trace messages from plugin.
-
-.SH "SEE ALSO"
-.BR jalv(1),
-.BR jalv.gtk3(1),
-.BR jalv.qt5(1),
-.BR lv2ls(1),
-.BR jackd(1)
-
-.SH AUTHOR
-jalv was written by David Robillard <d@drobilla.net>
-.PP
-This manual page was written by Jaromír Mikes <mira.mikes@seznam.cz>
-and David Robillard <d@drobilla.net>
diff --git a/doc/jalv.gtk3.1 b/doc/jalv.gtk3.1
index 51540c8..1cb8dc1 100644
--- a/doc/jalv.gtk3.1
+++ b/doc/jalv.gtk3.1
@@ -1,4 +1,4 @@
-.TH JALV.GTK "27 May 2022"
+.TH JALV.GTK3 1 "27 May 2022"
.SH NAME
.B jalv.gtk \- Run an LV2 plugin as a JACK application (Gtk3 version).
@@ -46,7 +46,6 @@ Print trace messages from plugin.
.SH "SEE ALSO"
.BR jalv(1),
-.BR jalv.gtk(1),
.BR jalv.qt5(1),
.BR lv2ls(1),
.BR jackd(1)
diff --git a/doc/jalv.qt5.1 b/doc/jalv.qt5.1
index 8dc1fdb..14fa57f 100644
--- a/doc/jalv.qt5.1
+++ b/doc/jalv.qt5.1
@@ -1,4 +1,4 @@
-.TH JALV.QT 1 "19 Apr 2012"
+.TH JALV.QT5 1 "19 Apr 2012"
.SH NAME
.B jalv.qt \- Run an LV2 plugin as a JACK application (Qt version).
@@ -13,7 +13,6 @@ developer testing purposes, for a production ready program use jalv.gtk.
.SH "SEE ALSO"
.BR jalv(1),
-.BR jalv.gtk(1),
.BR jalv.gtk3(1),
.BR lv2ls(1),
.BR jackd(1)
diff --git a/doc/meson.build b/doc/meson.build
new file mode 100644
index 0000000..be25581
--- /dev/null
+++ b/doc/meson.build
@@ -0,0 +1,12 @@
+# Copyright 2022-2023 David Robillard <d@drobilla.net>
+# SPDX-License-Identifier: 0BSD OR ISC
+
+install_man(files('jalv.1'))
+
+if not get_option('gtk3').disabled()
+ install_man(files('jalv.gtk3.1'))
+endif
+
+if not get_option('qt5').disabled()
+ install_man(files('jalv.qt5.1'))
+endif
diff --git a/jalv.ttl b/jalv.ttl
new file mode 100644
index 0000000..317ae54
--- /dev/null
+++ b/jalv.ttl
@@ -0,0 +1,29 @@
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix doap: <http://usefulinc.com/ns/doap#> .
+@prefix foaf: <http://xmlns.com/foaf/0.1/> .
+
+<http://drobilla.net/drobilla#me>
+ a foaf:Person ;
+ rdfs:seeAlso <http://drobilla.net/drobilla> ;
+ foaf:mbox <mailto:d@drobilla.net> ;
+ foaf:name "David Robillard" ;
+ foaf:nick "drobilla" .
+
+<http://drobilla.net/software/jalv>
+ a doap:Project ;
+ doap:blog <https://drobilla.net/category/jalv/> ;
+ doap:bug-database <https://gitlab.com/drobilla/jalv/issues> ;
+ doap:description "C library for hosting LV2 plugins" ;
+ doap:developer <http://drobilla.net/drobilla#me> ;
+ doap:download-page <http://download.drobilla.net/> ;
+ doap:homepage <http://drobilla.net/software/jalv> ;
+ doap:implements <http://lv2plug.in/ns/lv2core#> ;
+ doap:license <http://opensource.org/licenses/isc> ;
+ doap:maintainer <http://drobilla.net/drobilla#me> ;
+ doap:name "Jalv" ;
+ doap:programming-language "C" ;
+ doap:repository [
+ a doap:GitBranch ;
+ doap:location <https://gitlab.com/drobilla/jalv.git>
+ ] .
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..c73c612
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,430 @@
+# Copyright 2020-2022 David Robillard <d@drobilla.net>
+# SPDX-License-Identifier: 0BSD OR ISC
+
+project(
+ 'jalv',
+ ['c', 'cpp'],
+ default_options: [
+ 'b_ndebug=if-release',
+ 'buildtype=release',
+ 'c_std=c99',
+ 'cpp_std=c++14',
+ ],
+ license: 'ISC',
+ meson_version: '>= 0.56.0',
+ version: '1.6.9',
+)
+
+jalv_src_root = meson.current_source_dir()
+major_version = meson.project_version().split('.')[0]
+version_suffix = '@0@-@1@'.format(meson.project_name(), major_version)
+
+#######################
+# Compilers and Flags #
+#######################
+
+# Required tools
+cc = meson.get_compiler('c')
+
+# Optional C++ support
+if add_languages(['cpp'], native: false, required: get_option('cxx'))
+ cpp = meson.get_compiler('cpp')
+endif
+
+# Set global warning suppressions
+subdir('meson/suppressions')
+add_project_arguments(c_suppressions, language: ['c'])
+if is_variable('cpp')
+ add_project_arguments(cpp_suppressions, language: ['cpp'])
+endif
+
+#######################
+# Common Dependencies #
+#######################
+
+m_dep = cc.find_library('m', required: false)
+
+thread_dep = dependency('threads')
+
+zix_dep = dependency(
+ 'zix-0',
+ default_options: [
+ 'benchmarks=disabled',
+ 'docs=disabled',
+ 'tests=disabled',
+ 'tests_cpp=disabled',
+ ],
+ fallback: ['zix', 'zix_dep'],
+ version: '>= 0.4.0',
+)
+
+serd_dep = dependency(
+ 'serd-0',
+ default_options: [
+ 'docs=disabled',
+ 'tests=disabled',
+ 'tools=disabled',
+ ],
+ fallback: ['serd', 'serd_dep'],
+ version: '>= 0.32.2',
+)
+
+sord_dep = dependency(
+ 'sord-0',
+ default_options: [
+ 'docs=disabled',
+ 'tests=disabled',
+ 'tools=disabled',
+ ],
+ fallback: ['sord', 'sord_dep'],
+ version: '>= 0.16.16',
+)
+
+lv2_dep = dependency(
+ 'lv2',
+ default_options: [
+ 'docs=disabled',
+ 'old_headers=false',
+ 'plugins=disabled',
+ 'tests=disabled',
+ ],
+ fallback: ['lv2', 'lv2_dep'],
+ version: '>= 1.18.0',
+)
+
+sratom_dep = dependency(
+ 'sratom-0',
+ default_options: [
+ 'docs=disabled',
+ 'tests=disabled',
+ ],
+ fallback: ['sratom', 'sratom_dep'],
+ version: '>= 0.6.4',
+)
+
+lilv_dep = dependency(
+ 'lilv-0',
+ default_options: [
+ 'bindings_py=disabled',
+ 'docs=disabled',
+ 'tests=disabled',
+ 'tools=disabled',
+ ],
+ fallback: ['lilv', 'lilv_dep'],
+ version: '>= 0.24.24',
+)
+
+suil_dep = dependency(
+ 'suil-0',
+ default_options: [
+ 'docs=disabled',
+ 'tests=disabled',
+ ],
+ fallback: ['suil', 'suil_dep'],
+ required: get_option('suil'),
+ version: '>= 0.10.0',
+)
+
+###########
+# Drivers #
+###########
+
+portaudio_dep = dependency(
+ 'portaudio-2.0',
+ include_type: 'system',
+ required: get_option('portaudio'),
+ version: '>= 2.0.0',
+)
+
+jack_dep = dependency(
+ 'jack',
+ include_type: 'system',
+ required: get_option('jack'),
+ version: '>= 0.120.0',
+)
+
+backend_sources = files()
+if get_option('jack').enabled() and get_option('portaudio').enabled()
+ error('Only one of jack and portaudio can be enabled')
+elif get_option('jack').enabled()
+ backend_dep = jack_dep
+ backend_sources += files('src/jack.c')
+elif get_option('portaudio').enabled()
+ backend_dep = portaudio_dep
+ backend_sources += files('src/portaudio.c')
+elif jack_dep.found()
+ backend_dep = jack_dep
+ backend_sources += files('src/jack.c')
+else
+ backend_dep = portaudio_dep
+ backend_sources += files('src/portaudio.c')
+endif
+
+if not backend_dep.found()
+ error('No backend found, either jack or portaudio is required')
+endif
+
+##########################
+# Platform Configuration #
+##########################
+
+platform_defines = [
+ '-DJALV_VERSION="@0@"'.format(meson.project_version()),
+]
+
+suil_defines = ['-DHAVE_SUIL=@0@'.format(suil_dep.found().to_int())]
+
+# Determine whether to use POSIX
+no_posix = get_option('posix').disabled() or host_machine.system() == 'windows'
+if no_posix
+ platform_defines += ['-DJALV_NO_POSIX']
+elif host_machine.system() == 'darwin'
+ platform_defines += [
+ '-D_DARWIN_C_SOURCE',
+ '-D_POSIX_C_SOURCE=200809L',
+ '-D_XOPEN_SOURCE=600',
+ ]
+else
+ platform_defines += [
+ '-D_BSD_SOURCE',
+ '-D_DEFAULT_SOURCE',
+ '-D_POSIX_C_SOURCE=200809L',
+ '-D_XOPEN_SOURCE=600',
+ ]
+endif
+
+# Build platform-specific configuration arguments
+if get_option('checks').disabled()
+ # Generic build without platform-specific features
+ platform_defines += ['-DJALV_NO_DEFAULT_CONFIG']
+elif get_option('checks').enabled()
+ # Only use the features detected by the build system
+ platform_defines += ['-DJALV_NO_DEFAULT_CONFIG']
+
+ if no_posix
+ platform_defines += ['-DHAVE_FILENO=0']
+ platform_defines += ['-DHAVE_ISATTY=0']
+ platform_defines += ['-DHAVE_MLOCK=0']
+ platform_defines += ['-DHAVE_POSIX_MEMALIGN=0']
+ platform_defines += ['-DHAVE_SIGACTION=0']
+ else
+ fileno_code = '''#include <stdio.h>
+int main(void) { return fileno(stdin); }'''
+
+ isatty_code = '''#include <unistd.h>
+int main(void) { return isatty(0); }'''
+
+ mlock_code = '''#include <sys/mman.h>
+int main(void) { return mlock(0, 0); }'''
+
+ posix_memalign_code = '''#include <stdlib.h>
+int main(void) { void* mem; posix_memalign(&mem, 8, 8); }'''
+
+ sigaction_code = '''#include <signal.h>
+int main(void) { return sigaction(SIGINT, 0, 0); }'''
+
+ platform_defines += '-DHAVE_FILENO=@0@'.format(
+ cc.compiles(fileno_code, args: platform_defines, name: 'fileno').to_int(),
+ )
+
+ platform_defines += '-DHAVE_ISATTY=@0@'.format(
+ cc.compiles(isatty_code, args: platform_defines, name: 'isatty').to_int(),
+ )
+
+ platform_defines += '-DHAVE_MLOCK=@0@'.format(
+ cc.compiles(mlock_code, args: platform_defines, name: 'mlock').to_int(),
+ )
+
+ platform_defines += '-DHAVE_POSIX_MEMALIGN=@0@'.format(
+ cc.compiles(
+ posix_memalign_code,
+ args: platform_defines,
+ name: 'posix_memalign',
+ ).to_int(),
+ )
+
+ platform_defines += '-DHAVE_SIGACTION=@0@'.format(
+ cc.compiles(sigaction_code, args: platform_defines, name: 'sigaction').to_int(),
+ )
+ endif
+
+ jack_metadata_code = '''#include <jack/metadata.h>
+int main(void) { return !!&jack_set_property; }'''
+
+ jack_port_type_get_buffer_size_code = '''#include <jack/jack.h>
+int main(void) { return !!&jack_port_type_get_buffer_size; }'''
+
+ platform_defines += '-DHAVE_JACK_METADATA=@0@'.format(
+ cc.compiles(
+ jack_metadata_code,
+ args: platform_defines,
+ name: 'jack_metadata',
+ ).to_int(),
+ )
+
+ platform_defines += '-DHAVE_JACK_PORT_TYPE_GET_BUFFER_SIZE=@0@'.format(
+ cc.compiles(
+ jack_port_type_get_buffer_size_code,
+ args: platform_defines,
+ name: 'jack_port_type_get_buffer_size',
+ ).to_int(),
+ )
+endif
+
+############
+# Programs #
+############
+
+sources = (
+ backend_sources + files(
+ 'src/control.c',
+ 'src/jalv.c',
+ 'src/log.c',
+ 'src/lv2_evbuf.c',
+ 'src/state.c',
+ 'src/symap.c',
+ 'src/worker.c',
+ )
+)
+
+common_dependencies = [
+ backend_dep,
+ lilv_dep,
+ m_dep,
+ serd_dep,
+ sratom_dep,
+ suil_dep,
+ thread_dep,
+ zix_dep,
+]
+
+# Internal JACK client library
+if jack_dep.found()
+ shared_library(
+ 'jalv',
+ sources + files('src/jalv_console.c'),
+ c_args: c_suppressions + platform_defines + ['-DHAVE_SUIL=0'],
+ dependencies: common_dependencies,
+ include_directories: include_directories('src'),
+ install: true,
+ install_dir: get_option('prefix') / get_option('libdir') / 'jack',
+ name_prefix: '',
+ )
+endif
+
+# Console version
+executable(
+ 'jalv',
+ sources + files('src/jalv_console.c'),
+ c_args: c_suppressions + platform_defines + suil_defines,
+ dependencies: common_dependencies + [suil_dep],
+ include_directories: include_directories('src'),
+ install: true,
+)
+
+# Gtk 3.0 GUI version
+if not get_option('gtk3').disabled()
+ gdk3_dep = dependency(
+ 'gdk-3.0',
+ include_type: 'system',
+ required: get_option('gtk3'),
+ version: '>= 3.12.0',
+ )
+
+ gtk3_dep = dependency(
+ 'gtk+-3.0',
+ include_type: 'system',
+ required: get_option('gtk3'),
+ version: '>= 3.12.0',
+ )
+
+ if gdk3_dep.found() and gtk3_dep.found()
+ config = configuration_data()
+ config.set('APP_INSTALL_NAME', 'jalv.gtk3')
+ config.set('APP_HUMAN_NAME', 'Jalv')
+ config.set('BINDIR', get_option('prefix') / get_option('bindir'))
+
+ configure_file(
+ configuration: config,
+ input: files('jalv.desktop.in'),
+ install: true,
+ install_dir: get_option('datadir') / 'applications',
+ output: 'jalv.desktop',
+ )
+
+ executable(
+ 'jalv.gtk3',
+ sources + files('src/jalv_gtk.c'),
+ c_args: c_suppressions + platform_defines + suil_defines,
+ dependencies: common_dependencies + [gdk3_dep, gtk3_dep, suil_dep],
+ include_directories: include_directories('src'),
+ install: true,
+ )
+ endif
+endif
+
+# Qt 5 GUI version
+if not get_option('qt5').disabled()
+ qt5_dep = dependency(
+ 'Qt5Widgets',
+ include_type: 'system',
+ required: get_option('qt5'),
+ version: '>= 5.1.0',
+ )
+
+ moc = find_program('moc-qt5', required: false)
+ if not moc.found()
+ moc = find_program('moc', required: get_option('qt5'))
+ endif
+
+ if moc.found()
+ qt_args = []
+ if cpp.get_id() in ['clang', 'gcc']
+ qt_args = ['-fPIC']
+ endif
+
+ jalv_qt_hpp = files(jalv_src_root / 'src' / 'jalv_qt.hpp')
+
+ jalv_qt5_meta_cpp = custom_target(
+ 'jalv_qt5_meta.cpp',
+ capture: true,
+ command: [moc, '@INPUT@'],
+ input: jalv_qt_hpp,
+ output: 'jalv_qt5_meta.cpp',
+ )
+
+ executable(
+ 'jalv.qt5',
+ sources + files('src/jalv_qt.cpp') + [jalv_qt5_meta_cpp],
+ c_args: c_suppressions + platform_defines + suil_defines,
+ cpp_args: cpp_suppressions + platform_defines + suil_defines + qt_args,
+ dependencies: common_dependencies + [qt5_dep, suil_dep],
+ include_directories: include_directories('src'),
+ install: true,
+ )
+ endif
+endif
+
+#################
+# Documentation #
+#################
+
+if not get_option('man').disabled()
+ subdir('doc')
+endif
+
+#########
+# Tests #
+#########
+
+if not get_option('tests').disabled()
+ subdir('test')
+endif
+
+if not meson.is_subproject()
+ summary('Install prefix', get_option('prefix'))
+ summary('Executables', get_option('prefix') / get_option('bindir'))
+ summary('Man pages', get_option('prefix') / get_option('mandir'))
+
+ summary('Backend', backend_dep.name())
+endif
diff --git a/meson/suppressions/meson.build b/meson/suppressions/meson.build
new file mode 100644
index 0000000..b338d31
--- /dev/null
+++ b/meson/suppressions/meson.build
@@ -0,0 +1,185 @@
+# Copyright 2020-2023 David Robillard <d@drobilla.net>
+# SPDX-License-Identifier: 0BSD OR ISC
+
+# Project-specific warning suppressions
+
+warning_level = get_option('warning_level')
+
+#####
+# C #
+#####
+
+if is_variable('cc')
+ c_suppressions = []
+
+ if cc.get_id() == 'clang'
+ if warning_level == 'everything'
+ c_suppressions += [
+ '-Wno-bad-function-cast',
+ '-Wno-cast-align',
+ '-Wno-cast-function-type-strict',
+ '-Wno-cast-qual',
+ '-Wno-declaration-after-statement',
+ '-Wno-disabled-macro-expansion',
+ '-Wno-documentation-unknown-command', # MacOS
+ '-Wno-double-promotion',
+ '-Wno-float-conversion',
+ '-Wno-float-equal',
+ '-Wno-format-nonliteral',
+ '-Wno-implicit-float-conversion',
+ '-Wno-missing-noreturn',
+ '-Wno-padded',
+ '-Wno-reserved-id-macro', # MacOS
+ '-Wno-shorten-64-to-32',
+ '-Wno-sign-conversion',
+ '-Wno-switch-enum',
+ '-Wno-unsafe-buffer-usage',
+ '-Wno-unused-macros',
+ ]
+
+ if not meson.is_cross_build()
+ c_suppressions += [
+ '-Wno-poison-system-directories',
+ ]
+ endif
+ endif
+
+ if warning_level in ['everything', '3']
+ c_suppressions += [
+ '-Wno-nullability-extension',
+ ]
+ endif
+
+ if warning_level in ['everything', '3', '2']
+ c_suppressions += [
+ '-Wno-unused-parameter',
+ ]
+ endif
+
+ if host_machine.system() == 'darwin'
+ c_suppressions += [
+ '-Wno-documentation', # JACK
+ '-Wno-documentation-deprecated-sync', # JACK
+ ]
+ elif host_machine.system() == 'freebsd'
+ c_suppressions += [
+ '-Wno-c11-extensions', # isnan and friends
+ ]
+ endif
+
+ elif cc.get_id() == 'gcc'
+ if warning_level == 'everything'
+ c_suppressions += [
+ '-Wno-bad-function-cast',
+ '-Wno-c++-compat',
+ '-Wno-cast-align',
+ '-Wno-cast-qual',
+ '-Wno-conversion',
+ '-Wno-double-promotion',
+ '-Wno-float-equal',
+ '-Wno-format-nonliteral',
+ '-Wno-inline',
+ '-Wno-padded',
+ '-Wno-strict-overflow',
+ '-Wno-suggest-attribute=const',
+ '-Wno-suggest-attribute=pure',
+ '-Wno-switch-default',
+ '-Wno-switch-enum',
+ '-Wno-unsuffixed-float-constants',
+ '-Wno-unused-const-variable',
+ '-Wno-unused-macros',
+ ]
+ endif
+
+ if warning_level in ['everything', '3', '2']
+ c_suppressions += [
+ '-Wno-unused-parameter',
+ ]
+ endif
+
+ elif cc.get_id() == 'msvc'
+ if warning_level == 'everything'
+ c_suppressions += [
+ '/wd4061', # enumerator in switch is not explicitly handled
+ '/wd4090', # different const qualifiers
+ '/wd4100', # unreferenced formal parameter
+ '/wd4191', # unsafe function conversion
+ '/wd4200', # zero-sized array in struct/union
+ '/wd4242', # possible loss of data from float conversion
+ '/wd4244', # possible loss of data from integer conversion
+ '/wd4267', # possible loss of data from size conversion
+ '/wd4365', # signed/unsigned mismatch
+ '/wd4514', # unreferenced inline function has been removed
+ '/wd4706', # assignment within conditional expression
+ '/wd4710', # function not inlined
+ '/wd4711', # function selected for automatic inline expansion
+ '/wd4800', # implicit conversion from int to bool
+ '/wd4820', # padding added after construct
+ '/wd4996', # POSIX name for this item is deprecated
+ '/wd5045', # compiler will insert Spectre mitigation
+ ]
+ endif
+ endif
+
+ c_suppressions = cc.get_supported_arguments(c_suppressions)
+endif
+
+#######
+# C++ #
+#######
+
+if is_variable('cpp')
+ cpp_suppressions = []
+
+ if cpp.get_id() == 'clang'
+ if warning_level == 'everything'
+ cpp_suppressions += [
+ '-Wno-c++98-compat-pedantic',
+ '-Wno-cast-align', # MacOS
+ '-Wno-cast-qual', # MacOS
+ '-Wno-documentation-unknown-command', # MacOS
+ '-Wno-double-promotion',
+ '-Wno-float-conversion',
+ '-Wno-implicit-float-conversion',
+ '-Wno-old-style-cast', # MacOS
+ '-Wno-padded',
+ '-Wno-redundant-parens',
+ '-Wno-reserved-id-macro', # MacOS
+ '-Wno-shorten-64-to-32',
+ '-Wno-sign-conversion',
+ '-Wno-unsafe-buffer-usage',
+ '-Wno-weak-vtables',
+ '-Wno-zero-as-null-pointer-constant', # MacOS
+ ]
+
+ if not meson.is_cross_build()
+ cpp_suppressions += [
+ '-Wno-poison-system-directories',
+ ]
+ endif
+ endif
+
+ if warning_level in ['everything', '3']
+ cpp_suppressions += [
+ '-Wno-nullability-extension',
+ ]
+ endif
+
+ elif cpp.get_id() == 'gcc'
+ if warning_level == 'everything'
+ cpp_suppressions += [
+ '-Wno-cast-align', # LV2
+ '-Wno-cast-qual', # LV2
+ '-Wno-conversion',
+ '-Wno-effc++',
+ '-Wno-padded',
+ '-Wno-strict-overflow',
+ '-Wno-suggest-attribute=const',
+ '-Wno-suggest-attribute=pure',
+ '-Wno-unused-const-variable',
+ ]
+ endif
+ endif
+
+ cpp_suppressions = cpp.get_supported_arguments(cpp_suppressions)
+endif
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..b5979d5
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,38 @@
+# Copyright 2020-2023 David Robillard <d@drobilla.net>
+# SPDX-License-Identifier: 0BSD OR ISC
+
+option('checks', type: 'feature', value: 'enabled', yield: true,
+ description: 'Check for platform-specific features')
+
+option('cxx', type: 'feature', value: 'auto', yield: true,
+ description: 'Build C++ programs')
+
+option('gtk3', type: 'feature', value: 'auto', yield: true,
+ description: 'Build Gtk3 GUI')
+
+option('portaudio', type: 'feature', value: 'auto', yield: true,
+ description: 'Build PortAudio driver')
+
+option('jack', type: 'feature', value: 'auto', yield: true,
+ description: 'Build JACK driver')
+
+option('lint', type: 'boolean', value: false, yield: true,
+ description: 'Run code quality checks')
+
+option('man', type: 'feature', value: 'enabled', yield: true,
+ description: 'Install man pages')
+
+option('posix', type: 'feature', value: 'auto', yield: true,
+ description: 'Use POSIX system facilities')
+
+option('qt5', type: 'feature', value: 'auto', yield: true,
+ description: 'Build Qt5 GUI')
+
+option('suil', type: 'feature', value: 'auto', yield: true,
+ description: 'Use suil to load plugin UIs')
+
+option('title', type: 'string', value: 'Jalv',
+ description: 'Project title')
+
+option('tests', type: 'feature', value: 'auto', yield: true,
+ description: 'Build tests')
diff --git a/src/attributes.h b/src/attributes.h
new file mode 100644
index 0000000..88a3e41
--- /dev/null
+++ b/src/attributes.h
@@ -0,0 +1,15 @@
+// Copyright 2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#ifndef JALV_ATTRIBUTES_H
+#define JALV_ATTRIBUTES_H
+
+#ifdef __cplusplus
+# define JALV_BEGIN_DECLS extern "C" {
+# define JALV_END_DECLS }
+#else
+# define JALV_BEGIN_DECLS
+# define JALV_END_DECLS
+#endif
+
+#endif // JALV_ATTRIBUTES_H
diff --git a/src/backend.h b/src/backend.h
new file mode 100644
index 0000000..2965378
--- /dev/null
+++ b/src/backend.h
@@ -0,0 +1,38 @@
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#ifndef JALV_BACKEND_H
+#define JALV_BACKEND_H
+
+#include "attributes.h"
+#include "types.h"
+
+#include <stdint.h>
+
+JALV_BEGIN_DECLS
+
+// Interface that must be implemented by audio/MIDI backends
+
+/// Initialize the audio and MIDI systems
+JalvBackend*
+jalv_backend_init(Jalv* jalv);
+
+/// Activate the backend and start processing audio
+void
+jalv_backend_activate(Jalv* jalv);
+
+/// Deactivate the backend and stop processing audio
+void
+jalv_backend_deactivate(Jalv* jalv);
+
+/// Close the backend
+void
+jalv_backend_close(Jalv* jalv);
+
+/// Expose a port to the system (if applicable) and connect it to its buffer
+void
+jalv_backend_activate_port(Jalv* jalv, uint32_t port_index);
+
+JALV_END_DECLS
+
+#endif // JALV_BACKEND_H
diff --git a/src/control.c b/src/control.c
index 9c48713..7150032 100644
--- a/src/control.c
+++ b/src/control.c
@@ -1,22 +1,9 @@
-/*
- Copyright 2007-2022 David Robillard <d@drobilla.net>
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
- 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.
+#include "control.h"
- 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.
-*/
-
-#define _POSIX_C_SOURCE 200809L
-
-#include "jalv_internal.h"
+#include "log.h"
#include "lilv/lilv.h"
#include "lv2/atom/atom.h"
@@ -25,7 +12,6 @@
#include <stdbool.h>
#include <stdint.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -44,51 +30,52 @@ scale_point_cmp(const ScalePoint* a, const ScalePoint* b)
}
ControlID*
-new_port_control(Jalv* jalv, uint32_t index)
+new_port_control(LilvWorld* const world,
+ const LilvPlugin* const plugin,
+ const LilvPort* const port,
+ uint32_t port_index,
+ const float sample_rate,
+ const JalvNodes* const nodes,
+ LV2_Atom_Forge* const forge)
{
- struct Port* port = &jalv->ports[index];
- const LilvPort* lport = port->lilv_port;
- const LilvPlugin* plug = jalv->plugin;
- const JalvNodes* nodes = &jalv->nodes;
-
ControlID* id = (ControlID*)calloc(1, sizeof(ControlID));
- id->jalv = jalv;
id->type = PORT;
- id->node = lilv_node_duplicate(lilv_port_get_node(plug, lport));
- id->symbol = lilv_node_duplicate(lilv_port_get_symbol(plug, lport));
- id->label = lilv_port_get_name(plug, lport);
- id->index = index;
- id->group = lilv_port_get(plug, lport, jalv->nodes.pg_group);
- id->value_type = jalv->forge.Float;
- id->is_writable = lilv_port_is_a(plug, lport, nodes->lv2_InputPort);
- id->is_readable = lilv_port_is_a(plug, lport, nodes->lv2_OutputPort);
- id->is_toggle = lilv_port_has_property(plug, lport, nodes->lv2_toggled);
- id->is_integer = lilv_port_has_property(plug, lport, nodes->lv2_integer);
+ id->node = lilv_node_duplicate(lilv_port_get_node(plugin, port));
+ id->symbol = lilv_node_duplicate(lilv_port_get_symbol(plugin, port));
+ id->label = lilv_port_get_name(plugin, port);
+ id->forge = forge;
+ id->index = port_index;
+ id->group = lilv_port_get(plugin, port, nodes->pg_group);
+ id->value_type = forge->Float;
+ id->is_writable = lilv_port_is_a(plugin, port, nodes->lv2_InputPort);
+ id->is_readable = lilv_port_is_a(plugin, port, nodes->lv2_OutputPort);
+ id->is_toggle = lilv_port_has_property(plugin, port, nodes->lv2_toggled);
+ id->is_integer = lilv_port_has_property(plugin, port, nodes->lv2_integer);
id->is_enumeration =
- lilv_port_has_property(plug, lport, nodes->lv2_enumeration);
+ lilv_port_has_property(plugin, port, nodes->lv2_enumeration);
id->is_logarithmic =
- lilv_port_has_property(plug, lport, nodes->pprops_logarithmic);
+ lilv_port_has_property(plugin, port, nodes->pprops_logarithmic);
- lilv_port_get_range(plug, lport, &id->def, &id->min, &id->max);
- if (lilv_port_has_property(plug, lport, jalv->nodes.lv2_sampleRate)) {
+ lilv_port_get_range(plugin, port, &id->def, &id->min, &id->max);
+ if (lilv_port_has_property(plugin, port, nodes->lv2_sampleRate)) {
// Adjust range for lv2:sampleRate controls
if (lilv_node_is_float(id->min) || lilv_node_is_int(id->min)) {
- const float min = lilv_node_as_float(id->min) * jalv->sample_rate;
+ const float min = lilv_node_as_float(id->min) * sample_rate;
lilv_node_free(id->min);
- id->min = lilv_new_float(jalv->world, min);
+ id->min = lilv_new_float(world, min);
}
if (lilv_node_is_float(id->max) || lilv_node_is_int(id->max)) {
- const float max = lilv_node_as_float(id->max) * jalv->sample_rate;
+ const float max = lilv_node_as_float(id->max) * sample_rate;
lilv_node_free(id->max);
- id->max = lilv_new_float(jalv->world, max);
+ id->max = lilv_new_float(world, max);
}
}
// Get scale points
- LilvScalePoints* sp = lilv_port_get_scale_points(plug, lport);
+ LilvScalePoints* sp = lilv_port_get_scale_points(plugin, port);
if (sp) {
id->points =
(ScalePoint*)malloc(lilv_scale_points_size(sp) * sizeof(ScalePoint));
@@ -120,34 +107,36 @@ new_port_control(Jalv* jalv, uint32_t index)
}
static bool
-has_range(Jalv* jalv, const LilvNode* subject, const char* range_uri)
+has_range(LilvWorld* const world,
+ const JalvNodes* const nodes,
+ const LilvNode* const subject,
+ const char* const range_uri)
{
- LilvNode* range = lilv_new_uri(jalv->world, range_uri);
- const bool result =
- lilv_world_ask(jalv->world, subject, jalv->nodes.rdfs_range, range);
+ LilvNode* range = lilv_new_uri(world, range_uri);
+ const bool result = lilv_world_ask(world, subject, nodes->rdfs_range, range);
lilv_node_free(range);
return result;
}
ControlID*
-new_property_control(Jalv* jalv, const LilvNode* property)
+new_property_control(LilvWorld* const world,
+ const LilvNode* property,
+ const JalvNodes* const nodes,
+ LV2_URID_Map* const map,
+ LV2_Atom_Forge* const forge)
{
ControlID* id = (ControlID*)calloc(1, sizeof(ControlID));
- id->jalv = jalv;
id->type = PROPERTY;
id->node = lilv_node_duplicate(property);
- id->symbol = lilv_world_get_symbol(jalv->world, property);
- id->property = jalv->map.map(jalv, lilv_node_as_uri(property));
-
- id->label =
- lilv_world_get(jalv->world, property, jalv->nodes.rdfs_label, NULL);
- id->min =
- lilv_world_get(jalv->world, property, jalv->nodes.lv2_minimum, NULL);
- id->max =
- lilv_world_get(jalv->world, property, jalv->nodes.lv2_maximum, NULL);
- id->def =
- lilv_world_get(jalv->world, property, jalv->nodes.lv2_default, NULL);
+ id->symbol = lilv_world_get_symbol(world, property);
+ id->forge = forge;
+ id->property = map->map(map->handle, lilv_node_as_uri(property));
+
+ id->label = lilv_world_get(world, property, nodes->rdfs_label, NULL);
+ id->min = lilv_world_get(world, property, nodes->lv2_minimum, NULL);
+ id->max = lilv_world_get(world, property, nodes->lv2_maximum, NULL);
+ id->def = lilv_world_get(world, property, nodes->lv2_default, NULL);
const char* const types[] = {LV2_ATOM__Int,
LV2_ATOM__Long,
@@ -159,20 +148,20 @@ new_property_control(Jalv* jalv, const LilvNode* property)
NULL};
for (const char* const* t = types; *t; ++t) {
- if (has_range(jalv, property, *t)) {
- id->value_type = jalv->map.map(jalv, *t);
+ if (has_range(world, nodes, property, *t)) {
+ id->value_type = map->map(map->handle, *t);
break;
}
}
- id->is_toggle = (id->value_type == jalv->forge.Bool);
+ id->is_toggle = (id->value_type == forge->Bool);
id->is_integer =
- (id->value_type == jalv->forge.Int || id->value_type == jalv->forge.Long);
+ (id->value_type == forge->Int || id->value_type == forge->Long);
if (!id->value_type) {
- fprintf(stderr,
- "Unknown value type for property <%s>\n",
- lilv_node_as_string(property));
+ jalv_log(JALV_LOG_WARNING,
+ "Unknown value type for property <%s>\n",
+ lilv_node_as_string(property));
}
return id;
diff --git a/src/control.h b/src/control.h
new file mode 100644
index 0000000..46ca360
--- /dev/null
+++ b/src/control.h
@@ -0,0 +1,103 @@
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#ifndef JALV_CONTROL_H
+#define JALV_CONTROL_H
+
+#include "attributes.h"
+#include "nodes.h"
+
+#include "lilv/lilv.h"
+#include "lv2/atom/forge.h"
+#include "lv2/urid/urid.h"
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+
+JALV_BEGIN_DECLS
+
+// Plugin control utilities
+
+/// Type of plugin control
+typedef enum {
+ PORT, ///< Control port
+ PROPERTY ///< Property (set via atom message)
+} ControlType;
+
+// "Interesting" value in a control's value range
+typedef struct {
+ float value;
+ char* label;
+} ScalePoint;
+
+/// Plugin control
+typedef struct {
+ ControlType type; ///< Type of control
+ LilvNode* node; ///< Port or property
+ LilvNode* symbol; ///< Symbol
+ LilvNode* label; ///< Human readable label
+ LV2_Atom_Forge* forge; ///< Forge (for URIDs)
+ LV2_URID property; ///< Iff type == PROPERTY
+ uint32_t index; ///< Iff type == PORT
+ LilvNode* group; ///< Port/control group, or NULL
+ void* widget; ///< Control Widget
+ size_t n_points; ///< Number of scale points
+ ScalePoint* points; ///< Scale points
+ LV2_URID value_type; ///< Type of control value
+ LilvNode* min; ///< Minimum value
+ LilvNode* max; ///< Maximum value
+ LilvNode* def; ///< Default value
+ bool is_toggle; ///< Boolean (0 and 1 only)
+ bool is_integer; ///< Integer values only
+ bool is_enumeration; ///< Point values only
+ bool is_logarithmic; ///< Logarithmic scale
+ bool is_writable; ///< Writable (input)
+ bool is_readable; ///< Readable (output)
+} ControlID;
+
+/// Set of plugin controls
+typedef struct {
+ size_t n_controls;
+ ControlID** controls;
+} Controls;
+
+/// Control change event, sent through ring buffers for UI updates
+typedef struct {
+ uint32_t index;
+ uint32_t protocol;
+ uint32_t size;
+ // Followed immediately by size bytes of data
+} ControlChange;
+
+/// Order scale points by value
+int
+scale_point_cmp(const ScalePoint* a, const ScalePoint* b);
+
+/// Create a new ID for a control port
+ControlID*
+new_port_control(LilvWorld* world,
+ const LilvPlugin* plugin,
+ const LilvPort* port,
+ uint32_t port_index,
+ float sample_rate,
+ const JalvNodes* nodes,
+ LV2_Atom_Forge* forge);
+
+/// Create a new ID for a property-based parameter
+ControlID*
+new_property_control(LilvWorld* world,
+ const LilvNode* property,
+ const JalvNodes* nodes,
+ LV2_URID_Map* map,
+ LV2_Atom_Forge* forge);
+
+void
+add_control(Controls* controls, ControlID* control);
+
+ControlID*
+get_property_control(const Controls* controls, LV2_URID property);
+
+JALV_END_DECLS
+
+#endif // JALV_CONTROL_H
diff --git a/src/frontend.h b/src/frontend.h
new file mode 100644
index 0000000..774796d
--- /dev/null
+++ b/src/frontend.h
@@ -0,0 +1,53 @@
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#ifndef JALV_UI_H
+#define JALV_UI_H
+
+#include "attributes.h"
+#include "options.h"
+#include "types.h"
+
+#include "lilv/lilv.h"
+
+#include <stdbool.h>
+
+JALV_BEGIN_DECLS
+
+// Interface that must be implemented by UIs
+
+/// Read command-line arguments and set `opts` accordingly
+int
+jalv_frontend_init(int* argc, char*** argv, JalvOptions* opts);
+
+/// Return the URI of the "native" LV2 UI type
+const char*
+jalv_frontend_ui_type(void);
+
+/// Return true if an interactive frontend is available
+bool
+jalv_frontend_discover(Jalv* jalv);
+
+/// Return the ideal refresh rate of the frontend in Hz
+float
+jalv_frontend_refresh_rate(Jalv* jalv);
+
+/// Return the scale factor of the frontend (for example 2.0 for double sized)
+float
+jalv_frontend_scale_factor(Jalv* jalv);
+
+/// Attempt to get a plugin URI selection from the user
+LilvNode*
+jalv_frontend_select_plugin(Jalv* jalv);
+
+/// Open and run the frontend interface, signalling jalv.done when finished
+int
+jalv_frontend_open(Jalv* jalv);
+
+/// Quit and close the frontend interface
+int
+jalv_frontend_close(Jalv* jalv);
+
+JALV_END_DECLS
+
+#endif // JALV_UI_H
diff --git a/src/jack.c b/src/jack.c
index 09f8855..de8517a 100644
--- a/src/jack.c
+++ b/src/jack.c
@@ -1,28 +1,20 @@
-/*
- Copyright 2007-2022 David Robillard <d@drobilla.net>
-
- 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.
-*/
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+#include "backend.h"
+
+#include "frontend.h"
#include "jalv_config.h"
#include "jalv_internal.h"
+#include "log.h"
#include "lv2_evbuf.h"
+#include "port.h"
+#include "types.h"
#include "lilv/lilv.h"
#include "lv2/atom/atom.h"
#include "lv2/atom/forge.h"
-#include "sratom/sratom.h"
-#include "zix/ring.h"
+#include "lv2/urid/urid.h"
#include "zix/sem.h"
#include <jack/jack.h>
@@ -30,7 +22,7 @@
#include <jack/transport.h>
#include <jack/types.h>
-#ifdef HAVE_JACK_METADATA
+#if USE_JACK_METADATA
# include <jack/metadata.h>
#endif
@@ -41,7 +33,13 @@
#include <stdlib.h>
#include <string.h>
-struct JalvBackend {
+#ifdef __clang__
+# define REALTIME __attribute__((annotate("realtime")))
+#else
+# define REALTIME
+#endif
+
+struct JalvBackendImpl {
jack_client_t* client; ///< Jack client
bool is_internal_client; ///< Running inside jackd
};
@@ -61,7 +59,7 @@ jack_buffer_size_cb(jack_nframes_t nframes, void* data)
Jalv* const jalv = (Jalv*)data;
jalv->block_length = nframes;
jalv->buf_size_set = true;
-#ifdef HAVE_JACK_PORT_TYPE_GET_BUFFER_SIZE
+#if USE_JACK_PORT_TYPE_GET_BUFFER_SIZE
jalv->midi_buf_size = jack_port_type_get_buffer_size(jalv->backend->client,
JACK_DEFAULT_MIDI_TYPE);
#endif
@@ -74,7 +72,7 @@ static void
jack_shutdown_cb(void* data)
{
Jalv* const jalv = (Jalv*)data;
- jalv_close_ui(jalv);
+ jalv_frontend_close(jalv);
zix_sem_post(&jalv->done);
}
@@ -91,9 +89,10 @@ jack_process_cb(jack_nframes_t nframes, void* data)
(jack_transport_query(client, &pos) == JackTransportRolling);
// If transport state is not as expected, then something has changed
+ const bool has_bbt = (pos.valid & JackPositionBBT);
const bool xport_changed =
(rolling != jalv->rolling || pos.frame != jalv->position ||
- pos.beats_per_minute != jalv->bpm);
+ (has_bbt && pos.beats_per_minute != jalv->bpm));
uint8_t pos_buf[256];
LV2_Atom* lv2_pos = (LV2_Atom*)pos_buf;
@@ -107,7 +106,7 @@ jack_process_cb(jack_nframes_t nframes, void* data)
lv2_atom_forge_long(forge, pos.frame);
lv2_atom_forge_key(forge, jalv->urids.time_speed);
lv2_atom_forge_float(forge, rolling ? 1.0 : 0.0);
- if (pos.valid & JackPositionBBT) {
+ if (has_bbt) {
lv2_atom_forge_key(forge, jalv->urids.time_barBeat);
lv2_atom_forge_float(forge,
pos.beat - 1 + (pos.tick / pos.ticks_per_beat));
@@ -121,25 +120,12 @@ jack_process_cb(jack_nframes_t nframes, void* data)
lv2_atom_forge_float(forge, pos.beats_per_minute);
}
- if (jalv->opts.dump) {
- char* str = sratom_to_turtle(jalv->sratom,
- &jalv->unmap,
- "time:",
- NULL,
- NULL,
- lv2_pos->type,
- lv2_pos->size,
- LV2_ATOM_BODY(lv2_pos));
- jalv_ansi_start(stdout, 36);
- printf("\n## Position ##\n%s\n", str);
- jalv_ansi_reset(stdout);
- free(str);
- }
+ jalv_dump_atom(jalv, stdout, "Position", lv2_pos, 32);
}
// Update transport state to expected values for next cycle
jalv->position = rolling ? pos.frame + nframes : pos.frame;
- jalv->bpm = pos.beats_per_minute;
+ jalv->bpm = has_bbt ? pos.beats_per_minute : jalv->bpm;
jalv->rolling = rolling;
switch (jalv->play_state) {
@@ -171,7 +157,7 @@ jack_process_cb(jack_nframes_t nframes, void* data)
// Connect plugin port directly to Jack port buffer
lilv_instance_connect_port(
jalv->instance, p, jack_port_get_buffer(port->sys_port, nframes));
-#ifdef HAVE_JACK_METADATA
+#if USE_JACK_METADATA
} else if (port->type == TYPE_CV && port->sys_port) {
// Connect plugin port directly to Jack port buffer
lilv_instance_connect_port(
@@ -183,12 +169,8 @@ jack_process_cb(jack_nframes_t nframes, void* data)
// Write transport change event if applicable
LV2_Evbuf_Iterator iter = lv2_evbuf_begin(port->evbuf);
if (xport_changed) {
- lv2_evbuf_write(&iter,
- 0,
- 0,
- lv2_pos->type,
- lv2_pos->size,
- (const uint8_t*)LV2_ATOM_BODY(lv2_pos));
+ lv2_evbuf_write(
+ &iter, 0, 0, lv2_pos->type, lv2_pos->size, LV2_ATOM_BODY(lv2_pos));
}
if (jalv->request_update) {
@@ -196,12 +178,8 @@ jack_process_cb(jack_nframes_t nframes, void* data)
const LV2_Atom_Object get = {
{sizeof(LV2_Atom_Object_Body), jalv->urids.atom_Object},
{0, jalv->urids.patch_Get}};
- lv2_evbuf_write(&iter,
- 0,
- 0,
- get.atom.type,
- get.atom.size,
- (const uint8_t*)LV2_ATOM_BODY_CONST(&get));
+ lv2_evbuf_write(
+ &iter, 0, 0, get.atom.type, get.atom.size, LV2_ATOM_BODY_CONST(&get));
}
if (port->sys_port) {
@@ -247,9 +225,9 @@ jack_process_cb(jack_nframes_t nframes, void* data)
// Get event from LV2 buffer
uint32_t frames = 0;
uint32_t subframes = 0;
- uint32_t type = 0;
+ LV2_URID type = 0;
uint32_t size = 0;
- uint8_t* body = NULL;
+ void* body = NULL;
lv2_evbuf_get(i, &frames, &subframes, &type, &size, &body);
if (buf && type == jalv->urids.midi_MidiEvent) {
@@ -259,20 +237,12 @@ jack_process_cb(jack_nframes_t nframes, void* data)
if (jalv->has_ui) {
// Forward event to UI
- jalv_send_to_ui(jalv, p, type, size, body);
+ jalv_write_event(jalv, jalv->plugin_to_ui, p, size, type, body);
}
}
} else if (send_ui_updates && port->flow == FLOW_OUTPUT &&
port->type == TYPE_CONTROL) {
- char buf[sizeof(ControlChange) + sizeof(float)];
- ControlChange* ev = (ControlChange*)buf;
- ev->index = p;
- ev->protocol = 0;
- ev->size = sizeof(float);
- *(float*)(ev + 1) = port->control;
- if (zix_ring_write(jalv->plugin_events, buf, sizeof(buf)) < sizeof(buf)) {
- fprintf(stderr, "Plugin => UI buffer overflow!\n");
- }
+ jalv_write_control(jalv, jalv->plugin_to_ui, p, port->control);
}
}
@@ -367,13 +337,13 @@ jalv_backend_init(Jalv* jalv)
return NULL;
}
- printf("JACK Name: %s\n", jack_get_client_name(client));
+ jalv_log(JALV_LOG_INFO, "JACK Name: %s\n", jack_get_client_name(client));
// Set audio engine properties
jalv->sample_rate = (float)jack_get_sample_rate(client);
jalv->block_length = jack_get_buffer_size(client);
jalv->midi_buf_size = 4096;
-#ifdef HAVE_JACK_PORT_TYPE_GET_BUFFER_SIZE
+#if USE_JACK_PORT_TYPE_GET_BUFFER_SIZE
jalv->midi_buf_size =
jack_port_type_get_buffer_size(client, JACK_DEFAULT_MIDI_TYPE);
#endif
@@ -452,7 +422,7 @@ jalv_backend_activate_port(Jalv* jalv, uint32_t port_index)
port->sys_port = jack_port_register(
client, lilv_node_as_string(sym), JACK_DEFAULT_AUDIO_TYPE, jack_flags, 0);
break;
-#ifdef HAVE_JACK_METADATA
+#if USE_JACK_METADATA
case TYPE_CV:
port->sys_port = jack_port_register(
client, lilv_node_as_string(sym), JACK_DEFAULT_AUDIO_TYPE, jack_flags, 0);
@@ -479,7 +449,7 @@ jalv_backend_activate_port(Jalv* jalv, uint32_t port_index)
break;
}
-#ifdef HAVE_JACK_METADATA
+#if USE_JACK_METADATA
if (port->sys_port) {
// Set port order to index
char index_str[16];
@@ -507,7 +477,7 @@ jack_initialize(jack_client_t* const client, const char* const load_init)
{
const size_t args_len = strlen(load_init);
if (args_len > JACK_LOAD_INIT_LIMIT) {
- fprintf(stderr, "error: Too many arguments given\n");
+ jalv_log(JALV_LOG_ERR, "Too many arguments given\n");
return -1;
}
@@ -527,7 +497,8 @@ jack_initialize(jack_client_t* const client, const char* const load_init)
// Build full command line with "program" name for building argv
const size_t cmd_len = strlen("jalv ") + args_len;
char* const cmd = (char*)calloc(cmd_len + 1, 1);
- snprintf(cmd, cmd_len + 1, "jalv %s", load_init);
+ memcpy(cmd, "jalv ", strlen("jalv ") + 1);
+ memcpy(cmd + 5, load_init, args_len + 1);
// Build argv
int argc = 0;
@@ -559,7 +530,7 @@ jack_finish(void* const arg)
Jalv* const jalv = (Jalv*)arg;
if (jalv) {
if (jalv_close(jalv)) {
- fprintf(stderr, "Failed to close Jalv\n");
+ jalv_log(JALV_LOG_ERR, "Failed to close Jalv\n");
}
free(jalv);
diff --git a/src/jalv.c b/src/jalv.c
index f41423c..be45aa4 100644
--- a/src/jalv.c
+++ b/src/jalv.c
@@ -1,26 +1,18 @@
-/*
- Copyright 2007-2022 David Robillard <d@drobilla.net>
-
- 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.
-*/
-
-#define _POSIX_C_SOURCE 200809L // for mkdtemp
-#define _XOPEN_SOURCE 600 // for S_IFMT and S_IFDIF
-#define _DARWIN_C_SOURCE // for mkdtemp on Darwin
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+#include "backend.h"
+#include "control.h"
+#include "frontend.h"
#include "jalv_config.h"
#include "jalv_internal.h"
+#include "log.h"
#include "lv2_evbuf.h"
+#include "nodes.h"
+#include "port.h"
+#include "state.h"
+#include "types.h"
+#include "urids.h"
#include "worker.h"
#include "lilv/lilv.h"
@@ -30,6 +22,7 @@
#include "lv2/buf-size/buf-size.h"
#include "lv2/core/lv2.h"
#include "lv2/data-access/data-access.h"
+#include "lv2/instance-access/instance-access.h"
#include "lv2/log/log.h"
#include "lv2/midi/midi.h"
#include "lv2/options/options.h"
@@ -47,17 +40,19 @@
#include "serd/serd.h"
#include "sratom/sratom.h"
#include "symap.h"
-#include "zix/common.h"
+#include "zix/attributes.h"
#include "zix/ring.h"
#include "zix/sem.h"
-#ifdef HAVE_SUIL
+#if USE_SUIL
# include "suil/suil.h"
#endif
-#ifdef _WIN32
+#if defined(_WIN32)
# include <io.h> // for _mktemp
# define snprintf _snprintf
+#elif defined(__APPLE__)
+# include <unistd.h> // for mkdtemp on Darwin
#endif
#include <assert.h>
@@ -82,7 +77,7 @@
#endif
#ifndef ARRAY_SIZE
-# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
+# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#endif
#ifndef MSG_BUFFER_SIZE
@@ -151,7 +146,7 @@ feature_is_supported(Jalv* jalv, const char* uri)
static void
die(const char* msg)
{
- fprintf(stderr, "%s\n", msg);
+ jalv_log(JALV_LOG_ERR, "%s\n", msg);
exit(EXIT_FAILURE);
}
@@ -199,12 +194,19 @@ create_port(Jalv* jalv, uint32_t port_index, float default_value)
port->type = TYPE_CONTROL;
port->control = isnan(default_value) ? 0.0f : default_value;
if (!hidden) {
- add_control(&jalv->controls, new_port_control(jalv, port->index));
+ add_control(&jalv->controls,
+ new_port_control(jalv->world,
+ jalv->plugin,
+ port->lilv_port,
+ port->index,
+ jalv->sample_rate,
+ &jalv->nodes,
+ &jalv->forge));
}
} else if (lilv_port_is_a(
jalv->plugin, port->lilv_port, jalv->nodes.lv2_AudioPort)) {
port->type = TYPE_AUDIO;
-#ifdef HAVE_JACK_METADATA
+#if USE_JACK_METADATA
} else if (lilv_port_is_a(
jalv->plugin, port->lilv_port, jalv->nodes.lv2_CVPort)) {
port->type = TYPE_CV;
@@ -247,10 +249,9 @@ jalv_create_ports(Jalv* jalv)
if (jalv->ports[index].type == TYPE_EVENT) {
jalv->control_in = index;
} else {
- fprintf(stderr,
- "warning: Non-event port %u has lv2:control designation, "
- "ignored\n",
- index);
+ jalv_log(JALV_LOG_WARNING,
+ "Non-event port %u has lv2:control designation, ignored\n",
+ index);
}
}
@@ -261,24 +262,25 @@ jalv_create_ports(Jalv* jalv)
void
jalv_allocate_port_buffers(Jalv* jalv)
{
+ const LV2_URID atom_Chunk = jalv->map.map(
+ jalv->map.handle, lilv_node_as_string(jalv->nodes.atom_Chunk));
+
+ const LV2_URID atom_Sequence = jalv->map.map(
+ jalv->map.handle, lilv_node_as_string(jalv->nodes.atom_Sequence));
+
for (uint32_t i = 0; i < jalv->num_ports; ++i) {
struct Port* const port = &jalv->ports[i];
- switch (port->type) {
- case TYPE_EVENT: {
+ if (port->type == TYPE_EVENT) {
lv2_evbuf_free(port->evbuf);
- const size_t buf_size =
- (port->buf_size > 0) ? port->buf_size : jalv->midi_buf_size;
- port->evbuf = lv2_evbuf_new(
- buf_size,
- jalv->map.map(jalv->map.handle,
- lilv_node_as_string(jalv->nodes.atom_Chunk)),
- jalv->map.map(jalv->map.handle,
- lilv_node_as_string(jalv->nodes.atom_Sequence)));
+
+ const size_t size = port->buf_size ? port->buf_size : jalv->midi_buf_size;
+
+ port->evbuf = lv2_evbuf_new(size, atom_Chunk, atom_Sequence);
+
lilv_instance_connect_port(
jalv->instance, i, lv2_evbuf_get_buffer(port->evbuf));
- }
- default:
- break;
+
+ lv2_evbuf_reset(port->evbuf, port->flow == FLOW_INPUT);
}
}
}
@@ -350,7 +352,9 @@ jalv_create_controls(Jalv* jalv, bool writable)
}
}
- record = new_property_control(jalv, property);
+ record = new_property_control(
+ jalv->world, property, &jalv->nodes, &jalv->map, &jalv->forge);
+
if (writable) {
record->is_writable = true;
} else {
@@ -360,9 +364,9 @@ jalv_create_controls(Jalv* jalv, bool writable)
if (record->value_type) {
add_control(&jalv->controls, record);
} else {
- fprintf(stderr,
- "Parameter <%s> has unknown value type, ignored\n",
- lilv_node_as_string(record->node));
+ jalv_log(JALV_LOG_WARNING,
+ "Parameter <%s> has unknown value type, ignored\n",
+ lilv_node_as_string(record->node));
free(record);
}
}
@@ -373,14 +377,14 @@ jalv_create_controls(Jalv* jalv, bool writable)
}
void
-jalv_set_control(const ControlID* control,
+jalv_set_control(Jalv* jalv,
+ const ControlID* control,
uint32_t size,
LV2_URID type,
const void* body)
{
- Jalv* jalv = control->jalv;
if (control->type == PORT && type == jalv->forge.Float) {
- struct Port* port = &control->jalv->ports[control->index];
+ struct Port* port = &jalv->ports[control->index];
port->control = *(const float*)body;
} else if (control->type == PROPERTY) {
// Copy forge since it is used by process thread
@@ -397,26 +401,42 @@ jalv_set_control(const ControlID* control,
lv2_atom_forge_write(&forge, body, size);
const LV2_Atom* atom = lv2_atom_forge_deref(&forge, frame.ref);
- jalv_ui_write(jalv,
- jalv->control_in,
- lv2_atom_total_size(atom),
- jalv->urids.atom_eventTransfer,
- atom);
+ jalv_send_to_plugin(jalv,
+ jalv->control_in,
+ lv2_atom_total_size(atom),
+ jalv->urids.atom_eventTransfer,
+ atom);
}
}
+#if USE_SUIL
+static uint32_t
+jalv_ui_port_index(void* const controller, const char* symbol)
+{
+ Jalv* const jalv = (Jalv*)controller;
+ struct Port* port = jalv_port_by_symbol(jalv, symbol);
+
+ return port ? port->index : LV2UI_INVALID_PORT_INDEX;
+}
+#endif
+
void
jalv_ui_instantiate(Jalv* jalv, const char* native_ui_type, void* parent)
{
-#ifdef HAVE_SUIL
- jalv->ui_host = suil_host_new(jalv_ui_write, jalv_ui_port_index, NULL, NULL);
+#if USE_SUIL
+ jalv->ui_host =
+ suil_host_new(jalv_send_to_plugin, jalv_ui_port_index, NULL, NULL);
+
+ const LV2_Feature parent_feature = {LV2_UI__parent, parent};
- const LV2_Feature parent_feature = {LV2_UI__parent, parent};
const LV2_Feature instance_feature = {
- NS_EXT "instance-access", lilv_instance_get_handle(jalv->instance)};
- const LV2_Feature data_feature = {LV2_DATA_ACCESS_URI,
+ LV2_INSTANCE_ACCESS_URI, lilv_instance_get_handle(jalv->instance)};
+
+ const LV2_Feature data_feature = {LV2_DATA_ACCESS_URI,
&jalv->features.ext_data};
- const LV2_Feature idle_feature = {LV2_UI__idleInterface, NULL};
+
+ const LV2_Feature idle_feature = {LV2_UI__idleInterface, NULL};
+
const LV2_Feature* ui_features[] = {&jalv->features.map_feature,
&jalv->features.unmap_feature,
&instance_feature,
@@ -473,51 +493,66 @@ jalv_ui_is_resizable(Jalv* jalv)
return !fs_matches && !nrs_matches;
}
-void
-jalv_ui_write(void* const jalv_handle,
- uint32_t port_index,
- uint32_t buffer_size,
- uint32_t protocol,
- const void* buffer)
+static void
+jalv_send_control_to_plugin(Jalv* const jalv,
+ uint32_t port_index,
+ uint32_t buffer_size,
+ const void* buffer)
{
- Jalv* const jalv = (Jalv*)jalv_handle;
+ if (buffer_size != sizeof(float)) {
+ jalv_log(JALV_LOG_ERR, "UI wrote invalid control size %u\n", buffer_size);
- if (protocol != 0 && protocol != jalv->urids.atom_eventTransfer) {
- fprintf(stderr,
- "UI write with unsupported protocol %u (%s)\n",
- protocol,
- unmap_uri(jalv, protocol));
- return;
+ } else {
+ jalv_write_control(
+ jalv, jalv->ui_to_plugin, port_index, *(const float*)buffer);
}
+}
- if (port_index >= jalv->num_ports) {
- fprintf(stderr, "UI write to out of range port index %u\n", port_index);
- return;
- }
+static void
+jalv_send_event_to_plugin(Jalv* const jalv,
+ uint32_t port_index,
+ uint32_t buffer_size,
+ const void* buffer)
+{
+ const LV2_Atom* const atom = (const LV2_Atom*)buffer;
- if (jalv->opts.dump && protocol == jalv->urids.atom_eventTransfer) {
- const LV2_Atom* atom = (const LV2_Atom*)buffer;
- char* str = sratom_to_turtle(jalv->sratom,
- &jalv->unmap,
- "jalv:",
- NULL,
- NULL,
- atom->type,
- atom->size,
- LV2_ATOM_BODY_CONST(atom));
- jalv_ansi_start(stdout, 36);
- printf("\n## UI => Plugin (%u bytes) ##\n%s\n", atom->size, str);
- jalv_ansi_reset(stdout);
- free(str);
+ if (buffer_size < sizeof(LV2_Atom)) {
+ jalv_log(JALV_LOG_ERR, "UI wrote impossible atom size\n");
+
+ } else if (sizeof(LV2_Atom) + atom->size != buffer_size) {
+ jalv_log(JALV_LOG_ERR, "UI wrote corrupt atom size\n");
+
+ } else {
+ jalv_dump_atom(jalv, stdout, "UI => Plugin", atom, 36);
+ jalv_write_event(
+ jalv, jalv->ui_to_plugin, port_index, atom->size, atom->type, atom + 1U);
}
+}
- char buf[MSG_BUFFER_SIZE];
- ControlChange* ev = (ControlChange*)buf;
- ev->index = port_index;
- ev->protocol = protocol;
- ev->size = buffer_size;
- memcpy(ev + 1, buffer, buffer_size);
- zix_ring_write(jalv->ui_events, buf, sizeof(ControlChange) + buffer_size);
+void
+jalv_send_to_plugin(void* const jalv_handle,
+ uint32_t port_index,
+ uint32_t buffer_size,
+ uint32_t protocol,
+ const void* buffer)
+{
+ Jalv* const jalv = (Jalv*)jalv_handle;
+
+ if (port_index >= jalv->num_ports) {
+ jalv_log(JALV_LOG_ERR, "UI wrote to invalid port index %u\n", port_index);
+
+ } else if (protocol == 0U) {
+ jalv_send_control_to_plugin(jalv, port_index, buffer_size, buffer);
+
+ } else if (protocol == jalv->urids.atom_eventTransfer) {
+ jalv_send_event_to_plugin(jalv, port_index, buffer_size, buffer);
+
+ } else {
+ jalv_log(JALV_LOG_ERR,
+ "UI wrote with unsupported protocol %u (%s)\n",
+ protocol,
+ unmap_uri(jalv, protocol));
+ }
}
void
@@ -527,14 +562,24 @@ jalv_apply_ui_events(Jalv* jalv, uint32_t nframes)
return;
}
- ControlChange ev;
- const size_t space = zix_ring_read_space(jalv->ui_events);
+ ControlChange ev = {0U, 0U, 0U};
+ const size_t space = zix_ring_read_space(jalv->ui_to_plugin);
for (size_t i = 0; i < space; i += sizeof(ev) + ev.size) {
- zix_ring_read(jalv->ui_events, (char*)&ev, sizeof(ev));
+ if (zix_ring_read(jalv->ui_to_plugin, &ev, sizeof(ev)) != sizeof(ev)) {
+ jalv_log(JALV_LOG_ERR, "Failed to read header from UI ring buffer\n");
+ break;
+ }
- char body[MSG_BUFFER_SIZE];
- if (zix_ring_read(jalv->ui_events, body, ev.size) != ev.size) {
- fprintf(stderr, "error: Error reading from UI ring buffer\n");
+ struct {
+ union {
+ LV2_Atom atom;
+ float control;
+ } head;
+ uint8_t body[MSG_BUFFER_SIZE];
+ } buffer;
+
+ if (zix_ring_read(jalv->ui_to_plugin, &buffer, ev.size) != ev.size) {
+ jalv_log(JALV_LOG_ERR, "Failed to read from UI ring buffer\n");
break;
}
@@ -542,32 +587,19 @@ jalv_apply_ui_events(Jalv* jalv, uint32_t nframes)
struct Port* const port = &jalv->ports[ev.index];
if (ev.protocol == 0) {
assert(ev.size == sizeof(float));
- port->control = *(float*)body;
+ port->control = buffer.head.control;
} else if (ev.protocol == jalv->urids.atom_eventTransfer) {
LV2_Evbuf_Iterator e = lv2_evbuf_end(port->evbuf);
- const LV2_Atom* const atom = (const LV2_Atom*)body;
- lv2_evbuf_write(&e,
- nframes,
- 0,
- atom->type,
- atom->size,
- (const uint8_t*)LV2_ATOM_BODY_CONST(atom));
+ const LV2_Atom* const atom = &buffer.head.atom;
+ lv2_evbuf_write(
+ &e, nframes, 0, atom->type, atom->size, LV2_ATOM_BODY_CONST(atom));
} else {
- fprintf(
- stderr, "error: Unknown control change protocol %u\n", ev.protocol);
+ jalv_log(
+ JALV_LOG_ERR, "Unknown control change protocol %u\n", ev.protocol);
}
}
}
-uint32_t
-jalv_ui_port_index(void* const controller, const char* symbol)
-{
- Jalv* const jalv = (Jalv*)controller;
- struct Port* port = jalv_port_by_symbol(jalv, symbol);
-
- return port ? port->index : LV2UI_INVALID_PORT_INDEX;
-}
-
void
jalv_init_ui(Jalv* jalv)
{
@@ -587,41 +619,93 @@ jalv_init_ui(Jalv* jalv)
lv2_atom_forge_object(&forge, &frame, 0, jalv->urids.patch_Get);
const LV2_Atom* atom = lv2_atom_forge_deref(&forge, frame.ref);
- jalv_ui_write(jalv,
- jalv->control_in,
- lv2_atom_total_size(atom),
- jalv->urids.atom_eventTransfer,
- atom);
+ jalv_send_to_plugin(jalv,
+ jalv->control_in,
+ lv2_atom_total_size(atom),
+ jalv->urids.atom_eventTransfer,
+ atom);
lv2_atom_forge_pop(&forge, &frame);
}
}
-bool
-jalv_send_to_ui(Jalv* jalv,
- uint32_t port_index,
- uint32_t type,
- uint32_t size,
- const void* body)
+static int
+jalv_write_control_change(Jalv* const jalv,
+ ZixRing* const target,
+ const void* const header,
+ const uint32_t header_size,
+ const void* const body,
+ const uint32_t body_size)
{
- // TODO: Be more disciminate about what to send
- char evbuf[sizeof(ControlChange) + sizeof(LV2_Atom)];
- ControlChange* ev = (ControlChange*)evbuf;
- ev->index = port_index;
- ev->protocol = jalv->urids.atom_eventTransfer;
- ev->size = sizeof(LV2_Atom) + size;
-
- LV2_Atom* atom = (LV2_Atom*)(ev + 1);
- atom->type = type;
- atom->size = size;
-
- if (zix_ring_write_space(jalv->plugin_events) >= sizeof(evbuf) + size) {
- zix_ring_write(jalv->plugin_events, evbuf, sizeof(evbuf));
- zix_ring_write(jalv->plugin_events, (const char*)body, size);
- return true;
+ ZixRingTransaction tx = zix_ring_begin_write(target);
+ if (zix_ring_amend_write(target, &tx, header, header_size) ||
+ zix_ring_amend_write(target, &tx, body, body_size)) {
+ jalv_log(JALV_LOG_ERR,
+ target == jalv->plugin_to_ui ? "Plugin => UI buffer overflow"
+ : "UI => Plugin buffer overflow");
+ return -1;
}
- fprintf(stderr, "Plugin => UI buffer overflow!\n");
- return false;
+ zix_ring_commit_write(target, &tx);
+ return 0;
+}
+
+int
+jalv_write_event(Jalv* const jalv,
+ ZixRing* const target,
+ const uint32_t port_index,
+ const uint32_t size,
+ const LV2_URID type,
+ const void* const body)
+{
+ // TODO: Be more discriminate about what to send
+
+ typedef struct {
+ ControlChange change;
+ LV2_Atom atom;
+ } Header;
+
+ const Header header = {
+ {port_index, jalv->urids.atom_eventTransfer, sizeof(LV2_Atom) + size},
+ {size, type}};
+
+ return jalv_write_control_change(
+ jalv, target, &header, sizeof(header), body, size);
+}
+
+int
+jalv_write_control(Jalv* const jalv,
+ ZixRing* const target,
+ const uint32_t port_index,
+ const float value)
+{
+ const ControlChange header = {port_index, 0, sizeof(value)};
+
+ return jalv_write_control_change(
+ jalv, target, &header, sizeof(header), &value, sizeof(value));
+}
+
+void
+jalv_dump_atom(Jalv* const jalv,
+ FILE* const stream,
+ const char* const label,
+ const LV2_Atom* const atom,
+ const int color)
+{
+ if (jalv->opts.dump) {
+ char* const str = sratom_to_turtle(jalv->sratom,
+ &jalv->unmap,
+ "jalv:",
+ NULL,
+ NULL,
+ atom->type,
+ atom->size,
+ LV2_ATOM_BODY_CONST(atom));
+
+ jalv_ansi_start(stream, color);
+ fprintf(stream, "\n# %s (%u bytes):\n%s\n", label, atom->size, str);
+ jalv_ansi_reset(stream);
+ free(str);
+ }
}
bool
@@ -633,14 +717,11 @@ jalv_run(Jalv* jalv, uint32_t nframes)
// Run plugin for this cycle
lilv_instance_run(jalv->instance, nframes);
- // Process any worker replies
- jalv_worker_emit_responses(&jalv->state_worker, jalv->instance);
- jalv_worker_emit_responses(&jalv->worker, jalv->instance);
-
- // Notify the plugin the run() cycle is finished
- if (jalv->worker.iface && jalv->worker.iface->end_run) {
- jalv->worker.iface->end_run(jalv->instance->lv2_handle);
- }
+ // Process any worker replies and end the cycle
+ LV2_Handle handle = lilv_instance_get_handle(jalv->instance);
+ jalv_worker_emit_responses(jalv->state_worker, handle);
+ jalv_worker_emit_responses(jalv->worker, handle);
+ jalv_worker_end_run(jalv->worker);
// Check if it's time to send updates to the UI
jalv->event_delta_t += nframes;
@@ -658,40 +739,27 @@ int
jalv_update(Jalv* jalv)
{
// Check quit flag and close if set
- if (zix_sem_try_wait(&jalv->done)) {
- jalv_close_ui(jalv);
+ if (!zix_sem_try_wait(&jalv->done)) {
+ jalv_frontend_close(jalv);
return 0;
}
// Emit UI events
ControlChange ev;
- const size_t space = zix_ring_read_space(jalv->plugin_events);
+ const size_t space = zix_ring_read_space(jalv->plugin_to_ui);
for (size_t i = 0; i + sizeof(ev) < space; i += sizeof(ev) + ev.size) {
// Read event header to get the size
- zix_ring_read(jalv->plugin_events, (char*)&ev, sizeof(ev));
+ zix_ring_read(jalv->plugin_to_ui, &ev, sizeof(ev));
// Resize read buffer if necessary
jalv->ui_event_buf = realloc(jalv->ui_event_buf, ev.size);
void* const buf = jalv->ui_event_buf;
// Read event body
- zix_ring_read(jalv->plugin_events, (char*)buf, ev.size);
-
- if (jalv->opts.dump && ev.protocol == jalv->urids.atom_eventTransfer) {
- // Dump event in Turtle to the console
- LV2_Atom* atom = (LV2_Atom*)buf;
- char* str = sratom_to_turtle(jalv->ui_sratom,
- &jalv->unmap,
- "jalv:",
- NULL,
- NULL,
- atom->type,
- atom->size,
- LV2_ATOM_BODY(atom));
- jalv_ansi_start(stdout, 35);
- printf("\n## Plugin => UI (%u bytes) ##\n%s\n", atom->size, str);
- jalv_ansi_reset(stdout);
- free(str);
+ zix_ring_read(jalv->plugin_to_ui, buf, ev.size);
+
+ if (ev.protocol == jalv->urids.atom_eventTransfer) {
+ jalv_dump_atom(jalv, stdout, "Plugin => UI", (const LV2_Atom*)buf, 35);
}
jalv_ui_port_event(jalv, ev.index, ev.size, ev.protocol, buf);
@@ -710,18 +778,19 @@ jalv_apply_control_arg(Jalv* jalv, const char* s)
char sym[256];
float val = 0.0f;
if (sscanf(s, "%[^=]=%f", sym, &val) != 2) {
- fprintf(stderr, "warning: Ignoring invalid value `%s'\n", s);
+ jalv_log(JALV_LOG_WARNING, "Ignoring invalid value `%s'\n", s);
return false;
}
ControlID* control = jalv_control_by_symbol(jalv, sym);
if (!control) {
- fprintf(stderr, "warning: Ignoring value for unknown control `%s'\n", sym);
+ jalv_log(
+ JALV_LOG_WARNING, "Ignoring value for unknown control `%s'\n", sym);
return false;
}
- jalv_set_control(control, sizeof(float), jalv->urids.atom_Float, &val);
- printf("%s = %f\n", sym, val);
+ jalv_set_control(jalv, control, sizeof(float), jalv->urids.atom_Float, &val);
+ jalv_log(JALV_LOG_INFO, "%s = %f\n", sym, val);
return true;
}
@@ -744,7 +813,7 @@ setup_signals(Jalv* const jalv)
{
exit_sem = &jalv->done;
-#ifdef HAVE_SIGACTION
+#if !defined(_WIN32) && USE_SIGACTION
struct sigaction action;
sigemptyset(&action.sa_mask);
action.sa_flags = 0;
@@ -761,7 +830,7 @@ setup_signals(Jalv* const jalv)
static const LilvUI*
jalv_select_custom_ui(const Jalv* const jalv)
{
- const char* const native_ui_type_uri = jalv_native_ui_type();
+ const char* const native_ui_type_uri = jalv_frontend_ui_type();
if (jalv->opts.ui_uri) {
// Specific UI explicitly requested by user
@@ -772,7 +841,7 @@ jalv_select_custom_ui(const Jalv* const jalv)
return ui;
}
-#ifdef HAVE_SUIL
+#if USE_SUIL
if (native_ui_type_uri) {
// Try to find an embeddable UI
LilvNode* native_type = lilv_new_uri(jalv->world, native_ui_type_uri);
@@ -817,181 +886,285 @@ jalv_select_custom_ui(const Jalv* const jalv)
return NULL;
}
-int
-jalv_open(Jalv* const jalv, int* argc, char*** argv)
+static void
+jalv_init_urids(Symap* const symap, JalvURIDs* const urids)
{
- jalv->prog_name = (*argv)[0];
- jalv->block_length = 4096; // Should be set by backend
- jalv->midi_buf_size = 1024; // Should be set by backend
- jalv->play_state = JALV_PAUSED;
- jalv->bpm = 120.0f;
- jalv->control_in = (uint32_t)-1;
+#define MAP_URI(uri) symap_map(symap, (uri))
+
+ urids->atom_Float = MAP_URI(LV2_ATOM__Float);
+ urids->atom_Int = MAP_URI(LV2_ATOM__Int);
+ urids->atom_Object = MAP_URI(LV2_ATOM__Object);
+ urids->atom_Path = MAP_URI(LV2_ATOM__Path);
+ urids->atom_String = MAP_URI(LV2_ATOM__String);
+ urids->atom_eventTransfer = MAP_URI(LV2_ATOM__eventTransfer);
+ urids->bufsz_maxBlockLength = MAP_URI(LV2_BUF_SIZE__maxBlockLength);
+ urids->bufsz_minBlockLength = MAP_URI(LV2_BUF_SIZE__minBlockLength);
+ urids->bufsz_sequenceSize = MAP_URI(LV2_BUF_SIZE__sequenceSize);
+ urids->log_Error = MAP_URI(LV2_LOG__Error);
+ urids->log_Trace = MAP_URI(LV2_LOG__Trace);
+ urids->log_Warning = MAP_URI(LV2_LOG__Warning);
+ urids->midi_MidiEvent = MAP_URI(LV2_MIDI__MidiEvent);
+ urids->param_sampleRate = MAP_URI(LV2_PARAMETERS__sampleRate);
+ urids->patch_Get = MAP_URI(LV2_PATCH__Get);
+ urids->patch_Put = MAP_URI(LV2_PATCH__Put);
+ urids->patch_Set = MAP_URI(LV2_PATCH__Set);
+ urids->patch_body = MAP_URI(LV2_PATCH__body);
+ urids->patch_property = MAP_URI(LV2_PATCH__property);
+ urids->patch_value = MAP_URI(LV2_PATCH__value);
+ urids->time_Position = MAP_URI(LV2_TIME__Position);
+ urids->time_bar = MAP_URI(LV2_TIME__bar);
+ urids->time_barBeat = MAP_URI(LV2_TIME__barBeat);
+ urids->time_beatUnit = MAP_URI(LV2_TIME__beatUnit);
+ urids->time_beatsPerBar = MAP_URI(LV2_TIME__beatsPerBar);
+ urids->time_beatsPerMinute = MAP_URI(LV2_TIME__beatsPerMinute);
+ urids->time_frame = MAP_URI(LV2_TIME__frame);
+ urids->time_speed = MAP_URI(LV2_TIME__speed);
+ urids->ui_scaleFactor = MAP_URI(LV2_UI__scaleFactor);
+ urids->ui_updateRate = MAP_URI(LV2_UI__updateRate);
-#ifdef HAVE_SUIL
- suil_init(argc, argv, SUIL_ARG_NONE);
-#endif
+#undef MAP_URI
+}
- int ret = 0;
- if ((ret = jalv_init(argc, argv, &jalv->opts))) {
- jalv_close(jalv);
- return ret;
- }
+static void
+jalv_init_nodes(LilvWorld* const world, JalvNodes* const nodes)
+{
+#define MAP_NODE(uri) lilv_new_uri(world, (uri))
- jalv->symap = symap_new();
- zix_sem_init(&jalv->symap_lock, 1);
- zix_sem_init(&jalv->work_lock, 1);
+ nodes->atom_AtomPort = MAP_NODE(LV2_ATOM__AtomPort);
+ nodes->atom_Chunk = MAP_NODE(LV2_ATOM__Chunk);
+ nodes->atom_Float = MAP_NODE(LV2_ATOM__Float);
+ nodes->atom_Path = MAP_NODE(LV2_ATOM__Path);
+ nodes->atom_Sequence = MAP_NODE(LV2_ATOM__Sequence);
+ nodes->lv2_AudioPort = MAP_NODE(LV2_CORE__AudioPort);
+ nodes->lv2_CVPort = MAP_NODE(LV2_CORE__CVPort);
+ nodes->lv2_ControlPort = MAP_NODE(LV2_CORE__ControlPort);
+ nodes->lv2_InputPort = MAP_NODE(LV2_CORE__InputPort);
+ nodes->lv2_OutputPort = MAP_NODE(LV2_CORE__OutputPort);
+ nodes->lv2_connectionOptional = MAP_NODE(LV2_CORE__connectionOptional);
+ nodes->lv2_control = MAP_NODE(LV2_CORE__control);
+ nodes->lv2_default = MAP_NODE(LV2_CORE__default);
+ nodes->lv2_enumeration = MAP_NODE(LV2_CORE__enumeration);
+ nodes->lv2_extensionData = MAP_NODE(LV2_CORE__extensionData);
+ nodes->lv2_integer = MAP_NODE(LV2_CORE__integer);
+ nodes->lv2_maximum = MAP_NODE(LV2_CORE__maximum);
+ nodes->lv2_minimum = MAP_NODE(LV2_CORE__minimum);
+ nodes->lv2_name = MAP_NODE(LV2_CORE__name);
+ nodes->lv2_reportsLatency = MAP_NODE(LV2_CORE__reportsLatency);
+ nodes->lv2_sampleRate = MAP_NODE(LV2_CORE__sampleRate);
+ nodes->lv2_symbol = MAP_NODE(LV2_CORE__symbol);
+ nodes->lv2_toggled = MAP_NODE(LV2_CORE__toggled);
+ nodes->midi_MidiEvent = MAP_NODE(LV2_MIDI__MidiEvent);
+ nodes->pg_group = MAP_NODE(LV2_PORT_GROUPS__group);
+ nodes->pprops_logarithmic = MAP_NODE(LV2_PORT_PROPS__logarithmic);
+ nodes->pprops_notOnGUI = MAP_NODE(LV2_PORT_PROPS__notOnGUI);
+ nodes->pprops_rangeSteps = MAP_NODE(LV2_PORT_PROPS__rangeSteps);
+ nodes->pset_Preset = MAP_NODE(LV2_PRESETS__Preset);
+ nodes->pset_bank = MAP_NODE(LV2_PRESETS__bank);
+ nodes->rdfs_comment = MAP_NODE(LILV_NS_RDFS "comment");
+ nodes->rdfs_label = MAP_NODE(LILV_NS_RDFS "label");
+ nodes->rdfs_range = MAP_NODE(LILV_NS_RDFS "range");
+ nodes->rsz_minimumSize = MAP_NODE(LV2_RESIZE_PORT__minimumSize);
+ nodes->ui_showInterface = MAP_NODE(LV2_UI__showInterface);
+ nodes->work_interface = MAP_NODE(LV2_WORKER__interface);
+ nodes->work_schedule = MAP_NODE(LV2_WORKER__schedule);
+ nodes->end = NULL;
+
+#undef MAP_NODE
+}
+
+static void
+jalv_init_env(SerdEnv* const env)
+{
+ serd_env_set_prefix_from_strings(
+ env, (const uint8_t*)"patch", (const uint8_t*)LV2_PATCH_PREFIX);
+ serd_env_set_prefix_from_strings(
+ env, (const uint8_t*)"time", (const uint8_t*)LV2_TIME_PREFIX);
+ serd_env_set_prefix_from_strings(
+ env, (const uint8_t*)"xsd", (const uint8_t*)NS_XSD);
+}
+static void
+jalv_init_features(Jalv* const jalv)
+{
+ // urid:map
jalv->map.handle = jalv;
jalv->map.map = map_uri;
init_feature(&jalv->features.map_feature, LV2_URID__map, &jalv->map);
- jalv->worker.jalv = jalv;
- jalv->state_worker.jalv = jalv;
-
+ // urid:unmap
jalv->unmap.handle = jalv;
jalv->unmap.unmap = unmap_uri;
init_feature(&jalv->features.unmap_feature, LV2_URID__unmap, &jalv->unmap);
- lv2_atom_forge_init(&jalv->forge, &jalv->map);
-
- jalv->env = serd_env_new(NULL);
- serd_env_set_prefix_from_strings(
- jalv->env, (const uint8_t*)"patch", (const uint8_t*)LV2_PATCH_PREFIX);
- serd_env_set_prefix_from_strings(
- jalv->env, (const uint8_t*)"time", (const uint8_t*)LV2_TIME_PREFIX);
- serd_env_set_prefix_from_strings(
- jalv->env, (const uint8_t*)"xsd", (const uint8_t*)NS_XSD);
-
- jalv->sratom = sratom_new(&jalv->map);
- jalv->ui_sratom = sratom_new(&jalv->map);
- sratom_set_env(jalv->sratom, jalv->env);
- sratom_set_env(jalv->ui_sratom, jalv->env);
-
-#define MAP_URI(uri) symap_map(jalv->symap, (uri))
-
- jalv->urids.atom_Float = MAP_URI(LV2_ATOM__Float);
- jalv->urids.atom_Int = MAP_URI(LV2_ATOM__Int);
- jalv->urids.atom_Object = MAP_URI(LV2_ATOM__Object);
- jalv->urids.atom_Path = MAP_URI(LV2_ATOM__Path);
- jalv->urids.atom_String = MAP_URI(LV2_ATOM__String);
- jalv->urids.atom_eventTransfer = MAP_URI(LV2_ATOM__eventTransfer);
- jalv->urids.bufsz_maxBlockLength = MAP_URI(LV2_BUF_SIZE__maxBlockLength);
- jalv->urids.bufsz_minBlockLength = MAP_URI(LV2_BUF_SIZE__minBlockLength);
- jalv->urids.bufsz_sequenceSize = MAP_URI(LV2_BUF_SIZE__sequenceSize);
- jalv->urids.log_Error = MAP_URI(LV2_LOG__Error);
- jalv->urids.log_Trace = MAP_URI(LV2_LOG__Trace);
- jalv->urids.log_Warning = MAP_URI(LV2_LOG__Warning);
- jalv->urids.midi_MidiEvent = MAP_URI(LV2_MIDI__MidiEvent);
- jalv->urids.param_sampleRate = MAP_URI(LV2_PARAMETERS__sampleRate);
- jalv->urids.patch_Get = MAP_URI(LV2_PATCH__Get);
- jalv->urids.patch_Put = MAP_URI(LV2_PATCH__Put);
- jalv->urids.patch_Set = MAP_URI(LV2_PATCH__Set);
- jalv->urids.patch_body = MAP_URI(LV2_PATCH__body);
- jalv->urids.patch_property = MAP_URI(LV2_PATCH__property);
- jalv->urids.patch_value = MAP_URI(LV2_PATCH__value);
- jalv->urids.time_Position = MAP_URI(LV2_TIME__Position);
- jalv->urids.time_bar = MAP_URI(LV2_TIME__bar);
- jalv->urids.time_barBeat = MAP_URI(LV2_TIME__barBeat);
- jalv->urids.time_beatUnit = MAP_URI(LV2_TIME__beatUnit);
- jalv->urids.time_beatsPerBar = MAP_URI(LV2_TIME__beatsPerBar);
- jalv->urids.time_beatsPerMinute = MAP_URI(LV2_TIME__beatsPerMinute);
- jalv->urids.time_frame = MAP_URI(LV2_TIME__frame);
- jalv->urids.time_speed = MAP_URI(LV2_TIME__speed);
- jalv->urids.ui_scaleFactor = MAP_URI(LV2_UI__scaleFactor);
- jalv->urids.ui_updateRate = MAP_URI(LV2_UI__updateRate);
-
-#undef MAP_URI
-
-#ifdef _WIN32
- jalv->temp_dir = jalv_strdup("jalvXXXXXX");
- _mktemp(jalv->temp_dir);
-#else
- char* templ = jalv_strdup("/tmp/jalv-XXXXXX");
- jalv->temp_dir = jalv_strjoin(mkdtemp(templ), "/");
- free(templ);
-#endif
-
+ // state:makePath
jalv->features.make_path.handle = jalv;
jalv->features.make_path.path = jalv_make_path;
init_feature(&jalv->features.make_path_feature,
LV2_STATE__makePath,
&jalv->features.make_path);
- jalv->features.sched.handle = &jalv->worker;
+ // worker:schedule (normal)
jalv->features.sched.schedule_work = jalv_worker_schedule;
init_feature(
&jalv->features.sched_feature, LV2_WORKER__schedule, &jalv->features.sched);
- jalv->features.ssched.handle = &jalv->state_worker;
+ // worker:schedule (state)
jalv->features.ssched.schedule_work = jalv_worker_schedule;
init_feature(&jalv->features.state_sched_feature,
LV2_WORKER__schedule,
&jalv->features.ssched);
- jalv->features.llog.handle = jalv;
+ // log:log
+ jalv->features.llog.handle = &jalv->log;
jalv->features.llog.printf = jalv_printf;
jalv->features.llog.vprintf = jalv_vprintf;
init_feature(&jalv->features.log_feature, LV2_LOG__log, &jalv->features.llog);
+ // (options:options is initialized later by jalv_init_options())
+
+ // state:threadSafeRestore
+ init_feature(
+ &jalv->features.safe_restore_feature, LV2_STATE__threadSafeRestore, NULL);
+
+ // ui:requestValue
jalv->features.request_value.handle = jalv;
init_feature(&jalv->features.request_value_feature,
LV2_UI__requestValue,
&jalv->features.request_value);
+}
- zix_sem_init(&jalv->done, 0);
+static void
+jalv_init_options(Jalv* const jalv)
+{
+ const LV2_Options_Option options[ARRAY_SIZE(jalv->features.options)] = {
+ {LV2_OPTIONS_INSTANCE,
+ 0,
+ jalv->urids.param_sampleRate,
+ sizeof(float),
+ jalv->urids.atom_Float,
+ &jalv->sample_rate},
+ {LV2_OPTIONS_INSTANCE,
+ 0,
+ jalv->urids.bufsz_minBlockLength,
+ sizeof(int32_t),
+ jalv->urids.atom_Int,
+ &jalv->block_length},
+ {LV2_OPTIONS_INSTANCE,
+ 0,
+ jalv->urids.bufsz_maxBlockLength,
+ sizeof(int32_t),
+ jalv->urids.atom_Int,
+ &jalv->block_length},
+ {LV2_OPTIONS_INSTANCE,
+ 0,
+ jalv->urids.bufsz_sequenceSize,
+ sizeof(int32_t),
+ jalv->urids.atom_Int,
+ &jalv->midi_buf_size},
+ {LV2_OPTIONS_INSTANCE,
+ 0,
+ jalv->urids.ui_updateRate,
+ sizeof(float),
+ jalv->urids.atom_Float,
+ &jalv->ui_update_hz},
+ {LV2_OPTIONS_INSTANCE,
+ 0,
+ jalv->urids.ui_scaleFactor,
+ sizeof(float),
+ jalv->urids.atom_Float,
+ &jalv->ui_scale_factor},
+ {LV2_OPTIONS_INSTANCE, 0, 0, 0, 0, NULL}};
- zix_sem_init(&jalv->paused, 0);
- zix_sem_init(&jalv->worker.sem, 0);
+ memcpy(jalv->features.options, options, sizeof(jalv->features.options));
- // Find all installed plugins
- LilvWorld* world = lilv_world_new();
+ init_feature(&jalv->features.options_feature,
+ LV2_OPTIONS__options,
+ (void*)jalv->features.options);
+}
+
+static void
+jalv_init_display(Jalv* const jalv)
+{
+ if (!jalv->opts.update_rate) {
+ // Calculate a reasonable UI update frequency
+ jalv->ui_update_hz = jalv_frontend_refresh_rate(jalv);
+ } else {
+ // Use user-specified UI update rate
+ jalv->ui_update_hz = jalv->opts.update_rate;
+ jalv->ui_update_hz = MAX(1.0f, jalv->ui_update_hz);
+ }
+
+ if (!jalv->opts.scale_factor) {
+ // Calculate the monitor's scale factor
+ jalv->ui_scale_factor = jalv_frontend_scale_factor(jalv);
+ } else {
+ // Use user-specified UI scale factor
+ jalv->ui_scale_factor = jalv->opts.scale_factor;
+ }
+
+ // The UI can only go so fast, clamp to reasonable limits
+ jalv->ui_update_hz = MIN(60, jalv->ui_update_hz);
+ jalv->opts.buffer_size = MAX(4096, jalv->opts.buffer_size);
+ jalv_log(JALV_LOG_INFO, "Comm buffers: %u bytes\n", jalv->opts.buffer_size);
+ jalv_log(JALV_LOG_INFO, "Update rate: %.01f Hz\n", jalv->ui_update_hz);
+ jalv_log(JALV_LOG_INFO, "Scale factor: %.01f\n", jalv->ui_scale_factor);
+}
+
+int
+jalv_open(Jalv* const jalv, int* argc, char*** argv)
+{
+#if USE_SUIL
+ suil_init(argc, argv, SUIL_ARG_NONE);
+#endif
+
+ // Parse command-line arguments
+ int ret = 0;
+ if ((ret = jalv_frontend_init(argc, argv, &jalv->opts))) {
+ jalv_close(jalv);
+ return ret;
+ }
+
+ // Load the LV2 world
+ LilvWorld* const world = lilv_world_new();
lilv_world_load_all(world);
- jalv->world = world;
- const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
-#define MAP_NODE(uri) lilv_new_uri(world, (uri))
+ jalv->world = world;
+ jalv->env = serd_env_new(NULL);
+ jalv->symap = symap_new();
+ jalv->block_length = 4096U;
+ jalv->midi_buf_size = 1024U;
+ jalv->play_state = JALV_PAUSED;
+ jalv->bpm = 120.0f;
+ jalv->control_in = (uint32_t)-1;
+ jalv->log.urids = &jalv->urids;
+ jalv->log.tracing = jalv->opts.trace;
+
+ zix_sem_init(&jalv->symap_lock, 1);
+ zix_sem_init(&jalv->work_lock, 1);
+ zix_sem_init(&jalv->done, 0);
+ zix_sem_init(&jalv->paused, 0);
- // Cache URIs for concepts we'll use
- jalv->nodes.atom_AtomPort = MAP_NODE(LV2_ATOM__AtomPort);
- jalv->nodes.atom_Chunk = MAP_NODE(LV2_ATOM__Chunk);
- jalv->nodes.atom_Float = MAP_NODE(LV2_ATOM__Float);
- jalv->nodes.atom_Path = MAP_NODE(LV2_ATOM__Path);
- jalv->nodes.atom_Sequence = MAP_NODE(LV2_ATOM__Sequence);
- jalv->nodes.lv2_AudioPort = MAP_NODE(LV2_CORE__AudioPort);
- jalv->nodes.lv2_CVPort = MAP_NODE(LV2_CORE__CVPort);
- jalv->nodes.lv2_ControlPort = MAP_NODE(LV2_CORE__ControlPort);
- jalv->nodes.lv2_InputPort = MAP_NODE(LV2_CORE__InputPort);
- jalv->nodes.lv2_OutputPort = MAP_NODE(LV2_CORE__OutputPort);
- jalv->nodes.lv2_connectionOptional = MAP_NODE(LV2_CORE__connectionOptional);
- jalv->nodes.lv2_control = MAP_NODE(LV2_CORE__control);
- jalv->nodes.lv2_default = MAP_NODE(LV2_CORE__default);
- jalv->nodes.lv2_enumeration = MAP_NODE(LV2_CORE__enumeration);
- jalv->nodes.lv2_extensionData = MAP_NODE(LV2_CORE__extensionData);
- jalv->nodes.lv2_integer = MAP_NODE(LV2_CORE__integer);
- jalv->nodes.lv2_maximum = MAP_NODE(LV2_CORE__maximum);
- jalv->nodes.lv2_minimum = MAP_NODE(LV2_CORE__minimum);
- jalv->nodes.lv2_name = MAP_NODE(LV2_CORE__name);
- jalv->nodes.lv2_reportsLatency = MAP_NODE(LV2_CORE__reportsLatency);
- jalv->nodes.lv2_sampleRate = MAP_NODE(LV2_CORE__sampleRate);
- jalv->nodes.lv2_symbol = MAP_NODE(LV2_CORE__symbol);
- jalv->nodes.lv2_toggled = MAP_NODE(LV2_CORE__toggled);
- jalv->nodes.midi_MidiEvent = MAP_NODE(LV2_MIDI__MidiEvent);
- jalv->nodes.pg_group = MAP_NODE(LV2_PORT_GROUPS__group);
- jalv->nodes.pprops_logarithmic = MAP_NODE(LV2_PORT_PROPS__logarithmic);
- jalv->nodes.pprops_notOnGUI = MAP_NODE(LV2_PORT_PROPS__notOnGUI);
- jalv->nodes.pprops_rangeSteps = MAP_NODE(LV2_PORT_PROPS__rangeSteps);
- jalv->nodes.pset_Preset = MAP_NODE(LV2_PRESETS__Preset);
- jalv->nodes.pset_bank = MAP_NODE(LV2_PRESETS__bank);
- jalv->nodes.rdfs_comment = MAP_NODE(LILV_NS_RDFS "comment");
- jalv->nodes.rdfs_label = MAP_NODE(LILV_NS_RDFS "label");
- jalv->nodes.rdfs_range = MAP_NODE(LILV_NS_RDFS "range");
- jalv->nodes.rsz_minimumSize = MAP_NODE(LV2_RESIZE_PORT__minimumSize);
- jalv->nodes.ui_showInterface = MAP_NODE(LV2_UI__showInterface);
- jalv->nodes.work_interface = MAP_NODE(LV2_WORKER__interface);
- jalv->nodes.work_schedule = MAP_NODE(LV2_WORKER__schedule);
- jalv->nodes.end = NULL;
+ jalv_init_env(jalv->env);
+ jalv_init_urids(jalv->symap, &jalv->urids);
+ jalv_init_nodes(world, &jalv->nodes);
+ jalv_init_features(jalv);
+ lv2_atom_forge_init(&jalv->forge, &jalv->map);
-#undef MAP_NODE
+ // Set up atom reading and writing environment
+ jalv->sratom = sratom_new(&jalv->map);
+ sratom_set_env(jalv->sratom, jalv->env);
+ jalv->ui_sratom = sratom_new(&jalv->map);
+ sratom_set_env(jalv->ui_sratom, jalv->env);
+
+ // Create temporary directory for plugin state
+#ifdef _WIN32
+ jalv->temp_dir = jalv_strdup("jalvXXXXXX");
+ _mktemp(jalv->temp_dir);
+#else
+ char* templ = jalv_strdup("/tmp/jalv-XXXXXX");
+ jalv->temp_dir = jalv_strjoin(mkdtemp(templ), "/");
+ free(templ);
+#endif
// Get plugin URI from loaded state or command line
LilvState* state = NULL;
@@ -1008,7 +1181,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv)
jalv->world, &jalv->map, NULL, jalv->opts.load);
}
if (!state) {
- fprintf(stderr, "Failed to load state from %s\n", jalv->opts.load);
+ jalv_log(JALV_LOG_ERR, "Failed to load state from %s\n", jalv->opts.load);
jalv_close(jalv);
return -2;
}
@@ -1018,25 +1191,38 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv)
}
if (!plugin_uri) {
- plugin_uri = jalv_select_plugin(jalv);
+ plugin_uri = jalv_frontend_select_plugin(jalv);
}
if (!plugin_uri) {
- fprintf(stderr, "Missing plugin URI, try lv2ls to list plugins\n");
+ jalv_log(JALV_LOG_ERR, "Missing plugin URI, try lv2ls to list plugins\n");
jalv_close(jalv);
return -3;
}
// Find plugin
- printf("Plugin: %s\n", lilv_node_as_string(plugin_uri));
+ const char* const plugin_uri_str = lilv_node_as_string(plugin_uri);
+ const LilvPlugins* const plugins = lilv_world_get_all_plugins(world);
+ jalv_log(JALV_LOG_INFO, "Plugin: %s\n", plugin_uri_str);
jalv->plugin = lilv_plugins_get_by_uri(plugins, plugin_uri);
lilv_node_free(plugin_uri);
if (!jalv->plugin) {
- fprintf(stderr, "Failed to find plugin\n");
+ jalv_log(JALV_LOG_ERR, "Failed to find plugin\n");
jalv_close(jalv);
return -4;
}
+ // Create workers if necessary
+ if (lilv_plugin_has_extension_data(jalv->plugin,
+ jalv->nodes.work_interface)) {
+ jalv->worker = jalv_worker_new(&jalv->work_lock, true);
+ jalv->features.sched.handle = jalv->worker;
+ if (jalv->safe_restore) {
+ jalv->state_worker = jalv_worker_new(&jalv->work_lock, false);
+ jalv->features.ssched.handle = jalv->state_worker;
+ }
+ }
+
// Load preset, if specified
if (jalv->opts.preset) {
LilvNode* preset = lilv_new_uri(jalv->world, jalv->opts.preset);
@@ -1046,7 +1232,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv)
jalv->preset = state;
lilv_node_free(preset);
if (!state) {
- fprintf(stderr, "Failed to find preset <%s>\n", jalv->opts.preset);
+ jalv_log(JALV_LOG_ERR, "Failed to find preset <%s>\n", jalv->opts.preset);
jalv_close(jalv);
return -5;
}
@@ -1070,7 +1256,8 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv)
jalv->uis = lilv_plugin_get_uis(jalv->plugin);
if (!jalv->opts.generic_ui) {
if ((jalv->ui = jalv_select_custom_ui(jalv))) {
- const char* host_type_uri = jalv_native_ui_type();
+#if USE_SUIL
+ const char* host_type_uri = jalv_frontend_ui_type();
if (host_type_uri) {
LilvNode* host_type = lilv_new_uri(jalv->world, host_type_uri);
@@ -1081,16 +1268,14 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv)
lilv_node_free(host_type);
}
- }
- }
+#endif
- // Create ringbuffers for UI if necessary
- if (jalv->ui) {
- fprintf(stderr,
- "UI: %s\n",
- lilv_node_as_uri(lilv_ui_get_uri(jalv->ui)));
- } else {
- fprintf(stderr, "UI: None\n");
+ if (jalv->ui) {
+ jalv_log(JALV_LOG_INFO,
+ "UI: %s\n",
+ lilv_node_as_uri(lilv_ui_get_uri(jalv->ui)));
+ }
+ }
}
// Create port and control structures
@@ -1099,14 +1284,14 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv)
jalv_create_controls(jalv, false);
if (!(jalv->backend = jalv_backend_init(jalv))) {
- fprintf(stderr, "Failed to connect to audio system\n");
+ jalv_log(JALV_LOG_ERR, "Failed to connect to audio system\n");
jalv_close(jalv);
return -6;
}
- printf("Sample rate: %u Hz\n", (uint32_t)jalv->sample_rate);
- printf("Block length: %u frames\n", jalv->block_length);
- printf("MIDI buffers: %zu bytes\n", jalv->midi_buf_size);
+ jalv_log(JALV_LOG_INFO, "Sample rate: %u Hz\n", (uint32_t)jalv->sample_rate);
+ jalv_log(JALV_LOG_INFO, "Block length: %u frames\n", jalv->block_length);
+ jalv_log(JALV_LOG_INFO, "MIDI buffers: %zu bytes\n", jalv->midi_buf_size);
if (jalv->opts.buffer_size == 0) {
/* The UI ring is fed by plugin output ports (usually one), and the UI
@@ -1117,83 +1302,14 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv)
jalv->opts.buffer_size = jalv->midi_buf_size * N_BUFFER_CYCLES;
}
- if (jalv->opts.update_rate == 0.0) {
- // Calculate a reasonable UI update frequency
- jalv->ui_update_hz = jalv_ui_refresh_rate(jalv);
- } else {
- // Use user-specified UI update rate
- jalv->ui_update_hz = jalv->opts.update_rate;
- jalv->ui_update_hz = MAX(1.0f, jalv->ui_update_hz);
- }
-
- if (jalv->opts.scale_factor == 0.0) {
- // Calculate the monitor's scale factor
- jalv->ui_scale_factor = jalv_ui_scale_factor(jalv);
- } else {
- // Use user-specified UI scale factor
- jalv->ui_scale_factor = jalv->opts.scale_factor;
- }
-
- // The UI can only go so fast, clamp to reasonable limits
- jalv->ui_update_hz = MIN(60, jalv->ui_update_hz);
- jalv->opts.buffer_size = MAX(4096, jalv->opts.buffer_size);
- fprintf(stderr, "Comm buffers: %u bytes\n", jalv->opts.buffer_size);
- fprintf(stderr, "Update rate: %.01f Hz\n", jalv->ui_update_hz);
- fprintf(stderr, "Scale factor: %.01f\n", jalv->ui_scale_factor);
-
- // Build options array to pass to plugin
- const LV2_Options_Option options[ARRAY_SIZE(jalv->features.options)] = {
- {LV2_OPTIONS_INSTANCE,
- 0,
- jalv->urids.param_sampleRate,
- sizeof(float),
- jalv->urids.atom_Float,
- &jalv->sample_rate},
- {LV2_OPTIONS_INSTANCE,
- 0,
- jalv->urids.bufsz_minBlockLength,
- sizeof(int32_t),
- jalv->urids.atom_Int,
- &jalv->block_length},
- {LV2_OPTIONS_INSTANCE,
- 0,
- jalv->urids.bufsz_maxBlockLength,
- sizeof(int32_t),
- jalv->urids.atom_Int,
- &jalv->block_length},
- {LV2_OPTIONS_INSTANCE,
- 0,
- jalv->urids.bufsz_sequenceSize,
- sizeof(int32_t),
- jalv->urids.atom_Int,
- &jalv->midi_buf_size},
- {LV2_OPTIONS_INSTANCE,
- 0,
- jalv->urids.ui_updateRate,
- sizeof(float),
- jalv->urids.atom_Float,
- &jalv->ui_update_hz},
- {LV2_OPTIONS_INSTANCE,
- 0,
- jalv->urids.ui_scaleFactor,
- sizeof(float),
- jalv->urids.atom_Float,
- &jalv->ui_scale_factor},
- {LV2_OPTIONS_INSTANCE, 0, 0, 0, 0, NULL}};
- memcpy(jalv->features.options, options, sizeof(jalv->features.options));
-
- init_feature(&jalv->features.options_feature,
- LV2_OPTIONS__options,
- (void*)jalv->features.options);
-
- init_feature(
- &jalv->features.safe_restore_feature, LV2_STATE__threadSafeRestore, NULL);
+ jalv_init_display(jalv);
+ jalv_init_options(jalv);
// Create Plugin <=> UI communication buffers
- jalv->ui_events = zix_ring_new(jalv->opts.buffer_size);
- jalv->plugin_events = zix_ring_new(jalv->opts.buffer_size);
- zix_ring_mlock(jalv->ui_events);
- zix_ring_mlock(jalv->plugin_events);
+ jalv->ui_to_plugin = zix_ring_new(NULL, jalv->opts.buffer_size);
+ jalv->plugin_to_ui = zix_ring_new(NULL, jalv->opts.buffer_size);
+ zix_ring_mlock(jalv->ui_to_plugin);
+ zix_ring_mlock(jalv->plugin_to_ui);
// Build feature list for passing to plugins
const LV2_Feature* const features[] = {&jalv->features.map_feature,
@@ -1209,7 +1325,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv)
jalv->feature_list = (const LV2_Feature**)calloc(1, sizeof(features));
if (!jalv->feature_list) {
- fprintf(stderr, "Failed to allocate feature list\n");
+ jalv_log(JALV_LOG_ERR, "Failed to allocate feature list\n");
jalv_close(jalv);
return -7;
}
@@ -1220,7 +1336,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv)
LILV_FOREACH (nodes, f, req_feats) {
const char* uri = lilv_node_as_uri(lilv_nodes_get(req_feats, f));
if (!feature_is_supported(jalv, uri)) {
- fprintf(stderr, "Feature %s is not supported\n", uri);
+ jalv_log(JALV_LOG_ERR, "Feature %s is not supported\n", uri);
jalv_close(jalv);
return -8;
}
@@ -1231,37 +1347,36 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv)
jalv->instance = lilv_plugin_instantiate(
jalv->plugin, jalv->sample_rate, jalv->feature_list);
if (!jalv->instance) {
- fprintf(stderr, "Failed to instantiate plugin.\n");
+ jalv_log(JALV_LOG_ERR, "Failed to instantiate plugin\n");
jalv_close(jalv);
return -9;
}
+ // Point things to the instance that require it
+
jalv->features.ext_data.data_access =
lilv_instance_get_descriptor(jalv->instance)->extension_data;
- fprintf(stderr, "\n");
- if (!jalv->buf_size_set) {
- jalv_allocate_port_buffers(jalv);
- }
+ const LV2_Worker_Interface* worker_iface =
+ (const LV2_Worker_Interface*)lilv_instance_get_extension_data(
+ jalv->instance, LV2_WORKER__interface);
- // Create workers if necessary
- if (lilv_plugin_has_extension_data(jalv->plugin,
- jalv->nodes.work_interface)) {
- const LV2_Worker_Interface* iface =
- (const LV2_Worker_Interface*)lilv_instance_get_extension_data(
- jalv->instance, LV2_WORKER__interface);
+ jalv_worker_start(jalv->worker, worker_iface, jalv->instance->lv2_handle);
+ jalv_worker_start(
+ jalv->state_worker, worker_iface, jalv->instance->lv2_handle);
- jalv_worker_init(jalv, &jalv->worker, iface, true);
- if (jalv->safe_restore) {
- jalv_worker_init(jalv, &jalv->state_worker, iface, false);
- }
+ jalv_log(JALV_LOG_INFO, "\n");
+ if (!jalv->buf_size_set) {
+ jalv_allocate_port_buffers(jalv);
}
// Apply loaded state to plugin instance if necessary
if (state) {
jalv_apply_state(jalv, state);
+ lilv_state_free(state);
}
+ // Apply initial controls from command-line arguments
if (jalv->opts.controls) {
for (char** c = jalv->opts.controls; *c; ++c) {
jalv_apply_control_arg(jalv, *c);
@@ -1286,9 +1401,9 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv)
lilv_instance_activate(jalv->instance);
// Discover UI
- jalv->has_ui = jalv_discover_ui(jalv);
+ jalv->has_ui = jalv_frontend_discover(jalv);
- // Activate Jack
+ // Activate audio backend
jalv_backend_activate(jalv);
jalv->play_state = JALV_RUNNING;
@@ -1298,12 +1413,8 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv)
int
jalv_close(Jalv* const jalv)
{
- jalv->exit = true;
-
- fprintf(stderr, "Exiting...\n");
-
// Terminate the worker
- jalv_worker_finish(&jalv->worker);
+ jalv_worker_exit(jalv->worker);
// Deactivate audio
if (jalv->backend) {
@@ -1319,10 +1430,11 @@ jalv_close(Jalv* const jalv)
}
// Destroy the worker
- jalv_worker_destroy(&jalv->worker);
+ jalv_worker_free(jalv->worker);
+ jalv_worker_free(jalv->state_worker);
// Deactivate plugin
-#ifdef HAVE_SUIL
+#if USE_SUIL
suil_instance_free(jalv->ui_instance);
#endif
if (jalv->instance) {
@@ -1332,14 +1444,14 @@ jalv_close(Jalv* const jalv)
// Clean up
free(jalv->ports);
- zix_ring_free(jalv->ui_events);
- zix_ring_free(jalv->plugin_events);
+ zix_ring_free(jalv->ui_to_plugin);
+ zix_ring_free(jalv->plugin_to_ui);
for (LilvNode** n = (LilvNode**)&jalv->nodes; *n; ++n) {
lilv_node_free(*n);
}
symap_free(jalv->symap);
zix_sem_destroy(&jalv->symap_lock);
-#ifdef HAVE_SUIL
+#if USE_SUIL
suil_host_free(jalv->ui_host);
#endif
@@ -1358,6 +1470,7 @@ jalv_close(Jalv* const jalv)
sratom_free(jalv->sratom);
sratom_free(jalv->ui_sratom);
+ serd_env_free(jalv->env);
lilv_uis_free(jalv->uis);
lilv_world_free(jalv->world);
@@ -1389,7 +1502,7 @@ main(int argc, char** argv)
setup_signals(&jalv);
// Run UI (or prompt at console)
- jalv_open_ui(&jalv);
+ jalv_frontend_open(&jalv);
// Wait for finish signal from UI or signal handler
zix_sem_wait(&jalv.done);
diff --git a/src/jalv_config.h b/src/jalv_config.h
new file mode 100644
index 0000000..3d0133e
--- /dev/null
+++ b/src/jalv_config.h
@@ -0,0 +1,181 @@
+// Copyright 2021-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+/*
+ Configuration header that defines reasonable defaults at compile time.
+
+ This allows compile-time configuration from the command line, while still
+ allowing the source to be built "as-is" without any configuration. The idea
+ is to support an advanced build system with configuration checks, while still
+ allowing the code to be simply "thrown at a compiler" with features
+ determined from the compiler or system headers. Everything can be
+ overridden, so it should never be necessary to edit this file to build
+ successfully.
+
+ To ensure that all configure checks are performed, the build system can
+ define JALV_NO_DEFAULT_CONFIG to disable defaults. In this case, it must
+ define all HAVE_FEATURE symbols below to 1 or 0 to enable or disable
+ features. Any missing definitions will generate a compiler warning.
+
+ To ensure that this header is always included properly, all code that uses
+ configuration variables includes this header and checks their value with #if
+ (not #ifdef). Variables like USE_FEATURE are internal and should never be
+ defined on the command line.
+*/
+
+#ifndef JALV_CONFIG_H
+#define JALV_CONFIG_H
+
+// Define version unconditionally so a warning will catch a mismatch
+#define JALV_VERSION "1.6.9"
+
+#if !defined(JALV_NO_DEFAULT_CONFIG)
+
+// We need unistd.h to check _POSIX_VERSION
+# ifndef JALV_NO_POSIX
+# ifdef __has_include
+# if __has_include(<unistd.h>)
+# include <unistd.h>
+# endif
+# elif defined(__unix__)
+# include <unistd.h>
+# endif
+# endif
+
+// POSIX.1-2001: fileno()
+# ifndef HAVE_FILENO
+# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L
+# define HAVE_FILENO 1
+# else
+# define HAVE_FILENO 0
+# endif
+# endif
+
+// POSIX.1-2001: isatty()
+# ifndef HAVE_ISATTY
+# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L
+# define HAVE_ISATTY 1
+# else
+# define HAVE_ISATTY 0
+# endif
+# endif
+
+// POSIX.1-2001: mlock()
+# ifndef HAVE_MLOCK
+# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L
+# define HAVE_MLOCK 1
+# else
+# define HAVE_MLOCK 0
+# endif
+# endif
+
+// POSIX.1-2001: posix_memalign()
+# ifndef HAVE_POSIX_MEMALIGN
+# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L
+# define HAVE_POSIX_MEMALIGN 1
+# else
+# define HAVE_POSIX_MEMALIGN 0
+# endif
+# endif
+
+// POSIX.1-2001: sigaction()
+# ifndef HAVE_SIGACTION
+# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L
+# define HAVE_SIGACTION 1
+# else
+# define HAVE_SIGACTION 0
+# endif
+# endif
+
+// Suil
+# ifndef HAVE_SUIL
+# ifdef __has_include
+# if __has_include("suil/suil.h")
+# define HAVE_SUIL 1
+# else
+# define HAVE_SUIL 0
+# endif
+# endif
+# endif
+
+// JACK metadata API
+# ifndef HAVE_JACK_METADATA
+# ifdef __has_include
+# if __has_include("jack/metadata.h")
+# define HAVE_JACK_METADATA 1
+# else
+# define HAVE_JACK_METADATA 0
+# endif
+# endif
+# endif
+
+// JACK jack_port_type_get_buffer_size() function
+# ifndef HAVE_JACK_PORT_TYPE_GET_BUFFER_SIZE
+# ifdef __has_include
+# if __has_include("jack/midiport.h")
+# define HAVE_JACK_PORT_TYPE_GET_BUFFER_SIZE 1
+# else
+# define HAVE_JACK_PORT_TYPE_GET_BUFFER_SIZE 0
+# endif
+# endif
+# endif
+
+#endif // !defined(JALV_NO_DEFAULT_CONFIG)
+
+/*
+ Make corresponding USE_FEATURE defines based on the HAVE_FEATURE defines from
+ above or the command line. The code checks for these using #if (not #ifdef),
+ so there will be an undefined warning if it checks for an unknown feature,
+ and this header is always required by any code that checks for features, even
+ if the build system defines them all.
+*/
+
+#if HAVE_FILENO
+# define USE_FILENO 1
+#else
+# define USE_FILENO 0
+#endif
+
+#if HAVE_ISATTY
+# define USE_ISATTY 1
+#else
+# define USE_ISATTY 0
+#endif
+
+#if HAVE_MLOCK
+# define USE_MLOCK 1
+#else
+# define USE_MLOCK 0
+#endif
+
+#if HAVE_POSIX_MEMALIGN
+# define USE_POSIX_MEMALIGN 1
+#else
+# define USE_POSIX_MEMALIGN 0
+#endif
+
+#if HAVE_SIGACTION
+# define USE_SIGACTION 1
+#else
+# define USE_SIGACTION 0
+#endif
+
+#if HAVE_SUIL
+# define USE_SUIL 1
+#else
+# define USE_SUIL 0
+#endif
+
+#if HAVE_JACK_METADATA
+# define USE_JACK_METADATA 1
+#else
+# define USE_JACK_METADATA 0
+#endif
+
+#if HAVE_JACK_PORT_TYPE_GET_BUFFER_SIZE
+# define USE_JACK_PORT_TYPE_GET_BUFFER_SIZE 1
+#else
+# define USE_JACK_PORT_TYPE_GET_BUFFER_SIZE 0
+#endif
+
+#endif // JALV_CONFIG_H
diff --git a/src/jalv_console.c b/src/jalv_console.c
index 2ff2076..635b668 100644
--- a/src/jalv_console.c
+++ b/src/jalv_console.c
@@ -1,33 +1,25 @@
-/*
- Copyright 2007-2022 David Robillard <d@drobilla.net>
-
- 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.
-*/
-
-#define _POSIX_C_SOURCE 200809L
-#define _XOPEN_SOURCE 600
-#define _BSD_SOURCE 1
-#define _DEFAULT_SOURCE 1
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+#include "control.h"
+#include "frontend.h"
#include "jalv_config.h"
#include "jalv_internal.h"
+#include "log.h"
+#include "options.h"
+#include "port.h"
+#include "state.h"
+#include "types.h"
#include "lilv/lilv.h"
#include "lv2/ui/ui.h"
-#include "suil/suil.h"
-#include "zix/common.h"
+#include "zix/attributes.h"
#include "zix/sem.h"
+#if USE_SUIL
+# include "suil/suil.h"
+#endif
+
#ifdef _WIN32
# include <synchapi.h>
#else
@@ -45,20 +37,21 @@ print_usage(const char* name, bool error)
{
FILE* const os = error ? stderr : stdout;
fprintf(os, "Usage: %s [OPTION...] PLUGIN_URI\n", name);
- fprintf(os, "Run an LV2 plugin as a Jack application.\n");
- fprintf(os, " -b SIZE Buffer size for plugin <=> UI communication\n");
- fprintf(os, " -c SYM=VAL Set control value (e.g. \"vol=1.4\")\n");
- fprintf(os, " -d Dump plugin <=> UI communication\n");
- fprintf(os, " -h Display this help and exit\n");
- fprintf(os, " -i Ignore keyboard input, run non-interactively\n");
- fprintf(os, " -l DIR Load state from save directory\n");
- fprintf(os, " -n NAME JACK client name\n");
- fprintf(os, " -p Print control output changes to stdout\n");
- fprintf(os, " -s Show plugin UI if possible\n");
- fprintf(os, " -t Print trace messages from plugin\n");
- fprintf(os, " -U URI Load the UI with the given URI\n");
- fprintf(os, " -V Display version information and exit\n");
- fprintf(os, " -x Exact JACK client name (exit if taken)\n");
+ fprintf(os,
+ "Run an LV2 plugin as a Jack application.\n"
+ " -b SIZE Buffer size for plugin <=> UI communication\n"
+ " -c SYM=VAL Set control value (e.g. \"vol=1.4\")\n"
+ " -d Dump plugin <=> UI communication\n"
+ " -h Display this help and exit\n"
+ " -i Ignore keyboard input, run non-interactively\n"
+ " -l DIR Load state from save directory\n"
+ " -n NAME JACK client name\n"
+ " -p Print control output changes to stdout\n"
+ " -s Show plugin UI if possible\n"
+ " -t Print trace messages from plugin\n"
+ " -U URI Load the UI with the given URI\n"
+ " -V Display version information and exit\n"
+ " -x Exit if the requested JACK client name is taken.\n");
return error ? 1 : 0;
}
@@ -80,14 +73,22 @@ jalv_ui_port_event(Jalv* jalv,
uint32_t protocol,
const void* buffer)
{
+#if USE_SUIL
if (jalv->ui_instance) {
suil_instance_port_event(
jalv->ui_instance, port_index, buffer_size, protocol, buffer);
}
+#else
+ (void)jalv;
+ (void)port_index;
+ (void)buffer_size;
+ (void)protocol;
+ (void)buffer;
+#endif
}
int
-jalv_init(int* argc, char*** argv, JalvOptions* opts)
+jalv_frontend_init(int* argc, char*** argv, JalvOptions* opts)
{
int n_controls = 0;
int a = 1;
@@ -156,7 +157,7 @@ jalv_init(int* argc, char*** argv, JalvOptions* opts)
}
const char*
-jalv_native_ui_type(void)
+jalv_frontend_ui_type(void)
{
return NULL;
}
@@ -169,7 +170,10 @@ jalv_print_controls(Jalv* jalv, bool writable, bool readable)
if ((control->is_writable && writable) ||
(control->is_readable && readable)) {
struct Port* const port = &jalv->ports[control->index];
- printf("%s = %f\n", lilv_node_as_string(control->symbol), port->control);
+ jalv_log(JALV_LOG_INFO,
+ "%s = %f\n",
+ lilv_node_as_string(control->symbol),
+ port->control);
}
}
@@ -208,6 +212,7 @@ jalv_process_command(Jalv* jalv, const char* cmd)
jalv_load_presets(jalv, jalv_print_preset, NULL);
} else if (sscanf(cmd, "preset %1023[a-zA-Z0-9_:/-.#]\n", sym) == 1) {
LilvNode* preset = lilv_new_uri(jalv->world, sym);
+ lilv_world_load_resource(jalv->world, preset);
jalv_apply_preset(jalv, preset);
lilv_node_free(preset);
jalv_print_controls(jalv, true, false);
@@ -245,7 +250,7 @@ jalv_process_command(Jalv* jalv, const char* cmd)
}
bool
-jalv_discover_ui(Jalv* jalv)
+jalv_frontend_discover(Jalv* jalv)
{
return jalv->opts.show_ui;
}
@@ -253,11 +258,11 @@ jalv_discover_ui(Jalv* jalv)
static bool
jalv_run_custom_ui(Jalv* jalv)
{
-#ifdef HAVE_SUIL
+#if USE_SUIL
const LV2UI_Idle_Interface* idle_iface = NULL;
const LV2UI_Show_Interface* show_iface = NULL;
if (jalv->ui && jalv->opts.show_ui) {
- jalv_ui_instantiate(jalv, jalv_native_ui_type(), NULL);
+ jalv_ui_instantiate(jalv, jalv_frontend_ui_type(), NULL);
idle_iface = (const LV2UI_Idle_Interface*)suil_instance_extension_data(
jalv->ui_instance, LV2_UI__idleInterface);
show_iface = (const LV2UI_Show_Interface*)suil_instance_extension_data(
@@ -268,7 +273,7 @@ jalv_run_custom_ui(Jalv* jalv)
show_iface->show(suil_instance_get_handle(jalv->ui_instance));
// Drive idle interface until interrupted
- while (!zix_sem_try_wait(&jalv->done)) {
+ while (zix_sem_try_wait(&jalv->done)) {
jalv_update(jalv);
if (idle_iface->idle(suil_instance_get_handle(jalv->ui_instance))) {
break;
@@ -284,36 +289,38 @@ jalv_run_custom_ui(Jalv* jalv)
show_iface->hide(suil_instance_get_handle(jalv->ui_instance));
return true;
}
+#else
+ (void)jalv;
#endif
return false;
}
float
-jalv_ui_refresh_rate(Jalv* ZIX_UNUSED(jalv))
+jalv_frontend_refresh_rate(Jalv* ZIX_UNUSED(jalv))
{
return 30.0f;
}
float
-jalv_ui_scale_factor(Jalv* ZIX_UNUSED(jalv))
+jalv_frontend_scale_factor(Jalv* ZIX_UNUSED(jalv))
{
return 1.0f;
}
LilvNode*
-jalv_select_plugin(Jalv* jalv)
+jalv_frontend_select_plugin(Jalv* jalv)
{
(void)jalv;
return NULL;
}
int
-jalv_open_ui(Jalv* jalv)
+jalv_frontend_open(Jalv* jalv)
{
if (!jalv_run_custom_ui(jalv) && !jalv->opts.non_interactive) {
// Primitive command prompt for setting control values
- while (!zix_sem_try_wait(&jalv->done)) {
+ while (zix_sem_try_wait(&jalv->done)) {
char line[1024];
printf("> ");
if (fgets(line, sizeof(line), stdin)) {
@@ -333,7 +340,7 @@ jalv_open_ui(Jalv* jalv)
}
int
-jalv_close_ui(Jalv* jalv)
+jalv_frontend_close(Jalv* jalv)
{
zix_sem_post(&jalv->done);
return 0;
diff --git a/src/jalv_gtk.c b/src/jalv_gtk.c
index 348dd3c..5b7240b 100644
--- a/src/jalv_gtk.c
+++ b/src/jalv_gtk.c
@@ -1,35 +1,26 @@
-/*
- Copyright 2007-2022 David Robillard <d@drobilla.net>
-
- 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.
-*/
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+#include "control.h"
+#include "frontend.h"
#include "jalv_internal.h"
+#include "log.h"
+#include "options.h"
+#include "port.h"
+#include "state.h"
+#include "types.h"
#include "lilv/lilv.h"
#include "lv2/atom/atom.h"
#include "lv2/atom/forge.h"
#include "lv2/atom/util.h"
-#include "lv2/core/attributes.h"
#include "lv2/core/lv2.h"
#include "lv2/ui/ui.h"
#include "lv2/urid/urid.h"
#include "suil/suil.h"
-#include "zix/common.h"
+#include "zix/attributes.h"
#include "zix/sem.h"
-LV2_DISABLE_DEPRECATION_WARNINGS
-
#include <gdk/gdk.h>
#include <glib-object.h>
#include <glib.h>
@@ -44,6 +35,16 @@ LV2_DISABLE_DEPRECATION_WARNINGS
#include <stdlib.h>
#include <string.h>
+/* TODO: Gtk only provides one pointer for value changed callbacks, which we
+ use for the ControlID. So, there is no easy way to pass both a ControlID
+ and Jalv which is needed to actually do anything with a control. Work
+ around this by statically storing the Jalv instance. Since this UI isn't a
+ module, this isn't the end of the world, but a global "god pointer" is a
+ pretty bad smell. Refactoring things to be more modular or changing how Gtk
+ signals are connected would be a good idea.
+*/
+static Jalv* s_jalv = NULL;
+
static GtkCheckMenuItem* active_preset_item = NULL;
static bool updating = false;
@@ -56,44 +57,9 @@ typedef struct {
static float
get_float(const LilvNode* node, float fallback)
{
- if (lilv_node_is_float(node) || lilv_node_is_int(node)) {
- return lilv_node_as_float(node);
- }
-
- return fallback;
-}
-
-static GtkWidget*
-new_box(gboolean horizontal, gint spacing)
-{
-#if GTK_MAJOR_VERSION == 3
- return gtk_box_new(horizontal ? GTK_ORIENTATION_HORIZONTAL
- : GTK_ORIENTATION_VERTICAL,
- spacing);
-#else
- return (horizontal ? gtk_hbox_new(FALSE, spacing)
- : gtk_vbox_new(FALSE, spacing));
-#endif
-}
-
-static GtkWidget*
-new_hscale(gdouble min, gdouble max, gdouble step)
-{
-#if GTK_MAJOR_VERSION == 3
- return gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, min, max, step);
-#else
- return gtk_hscale_new_with_range(min, max, step);
-#endif
-}
-
-static void
-size_request(GtkWidget* widget, GtkRequisition* req)
-{
-#if GTK_MAJOR_VERSION == 3
- gtk_widget_get_preferred_size(widget, NULL, req);
-#else
- gtk_widget_size_request(widget, req);
-#endif
+ return (lilv_node_is_float(node) || lilv_node_is_int(node))
+ ? lilv_node_as_float(node)
+ : fallback;
}
static void
@@ -103,30 +69,23 @@ on_window_destroy(GtkWidget* ZIX_UNUSED(widget), gpointer ZIX_UNUSED(data))
}
int
-jalv_init(int* argc, char*** argv, JalvOptions* opts)
+jalv_frontend_init(int* argc, char*** argv, JalvOptions* opts)
{
- GOptionEntry entries[] = {
- {"load",
- 'l',
- 0,
- G_OPTION_ARG_STRING,
- &opts->load,
- "Load state from save directory",
- "DIR"},
+ const GOptionEntry entries[] = {
{"preset",
- 'p',
+ 'P',
0,
G_OPTION_ARG_STRING,
&opts->preset,
"Load state from preset",
"URI"},
- {"dump",
- 'd',
+ {"scale-factor",
+ 'S',
0,
- G_OPTION_ARG_NONE,
- &opts->dump,
- "Dump plugin <=> UI communication",
- NULL},
+ G_OPTION_ARG_DOUBLE,
+ &opts->scale_factor,
+ "UI scale factor",
+ "SCALE"},
{"ui-uri",
'U',
0,
@@ -134,20 +93,41 @@ jalv_init(int* argc, char*** argv, JalvOptions* opts)
&opts->ui_uri,
"Load the UI with the given URI",
"URI"},
- {"trace",
- 't',
+ {"buffer-size",
+ 'b',
+ 0,
+ G_OPTION_ARG_INT,
+ &opts->buffer_size,
+ "Buffer size for plugin <=> UI communication",
+ "SIZE"},
+ {"control",
+ 'c',
+ 0,
+ G_OPTION_ARG_STRING_ARRAY,
+ &opts->controls,
+ "Set control value (e.g. \"vol=1.4\")",
+ "SETTING"},
+ {"dump",
+ 'd',
0,
G_OPTION_ARG_NONE,
- &opts->trace,
- "Print trace messages from plugin",
+ &opts->dump,
+ "Dump plugin <=> UI communication",
NULL},
- {"show-hidden",
- 's',
+ {"generic-ui",
+ 'g',
0,
G_OPTION_ARG_NONE,
- &opts->show_hidden,
- "Show controls for ports with notOnGUI property on generic UI",
+ &opts->generic_ui,
+ "Use Jalv generic UI and not the plugin UI",
NULL},
+ {"load",
+ 'l',
+ 0,
+ G_OPTION_ARG_STRING,
+ &opts->load,
+ "Load state from save directory",
+ "DIR"},
{"no-menu",
'm',
0,
@@ -155,63 +135,50 @@ jalv_init(int* argc, char*** argv, JalvOptions* opts)
&opts->no_menu,
"Do not show Jalv menu on window",
NULL},
- {"generic-ui",
- 'g',
+ {"jack-name",
+ 'n',
+ 0,
+ G_OPTION_ARG_STRING,
+ &opts->name,
+ "JACK client name",
+ "NAME"},
+ {"print-controls",
+ 'p',
0,
G_OPTION_ARG_NONE,
- &opts->generic_ui,
- "Use Jalv generic UI and not the plugin UI",
+ &opts->print_controls,
+ "Print control output changes to stdout",
NULL},
- {"buffer-size",
- 'b',
- 0,
- G_OPTION_ARG_INT,
- &opts->buffer_size,
- "Buffer size for plugin <=> UI communication",
- "SIZE"},
{"update-frequency",
'r',
0,
G_OPTION_ARG_DOUBLE,
&opts->update_rate,
"UI update frequency",
- NULL},
- {"scale-factor",
- 0,
- 0,
- G_OPTION_ARG_DOUBLE,
- &opts->scale_factor,
- "UI scale factor",
- NULL},
- {"control",
- 'c',
- 0,
- G_OPTION_ARG_STRING_ARRAY,
- &opts->controls,
- "Set control value (e.g. \"vol=1.4\")",
- NULL},
- {"print-controls",
- 'p',
+ "HZ"},
+ {"show-hidden",
+ 's',
0,
G_OPTION_ARG_NONE,
- &opts->print_controls,
- "Print control output changes to stdout",
+ &opts->show_hidden,
+ "Show controls for ports with notOnGUI property on generic UI",
NULL},
- {"jack-name",
- 'n',
+ {"trace",
+ 't',
0,
- G_OPTION_ARG_STRING,
- &opts->name,
- "JACK client name",
+ G_OPTION_ARG_NONE,
+ &opts->trace,
+ "Print trace messages from plugin",
NULL},
{"exact-jack-name",
'x',
0,
G_OPTION_ARG_NONE,
&opts->name_exact,
- "Exact JACK client name (exit if taken)",
+ "Exit if the requested JACK client name is taken",
NULL},
{0, 0, 0, G_OPTION_ARG_NONE, 0, 0, 0}};
+
GError* error = NULL;
const int err =
gtk_init_with_args(argc,
@@ -229,11 +196,9 @@ jalv_init(int* argc, char*** argv, JalvOptions* opts)
}
const char*
-jalv_native_ui_type(void)
+jalv_frontend_ui_type(void)
{
-#if GTK_MAJOR_VERSION == 2
- return "http://lv2plug.in/ns/extensions/ui#GtkUI";
-#elif GTK_MAJOR_VERSION == 3
+#if GTK_MAJOR_VERSION == 3
return "http://lv2plug.in/ns/extensions/ui#Gtk3UI";
#else
return NULL;
@@ -485,7 +450,7 @@ on_save_preset_activate(GtkWidget* widget, void* ptr)
free(dot_lv2);
GtkWidget* content = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
- GtkBox* box = GTK_BOX(new_box(true, 8));
+ GtkBox* box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8));
GtkWidget* uri_label = gtk_label_new("URI (Optional):");
GtkWidget* uri_entry = gtk_entry_new();
GtkWidget* add_prefix =
@@ -557,7 +522,7 @@ on_delete_preset_activate(GtkWidget* widget, void* ptr)
(GtkWindow*)jalv->window,
(GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
"_Cancel",
- GTK_RESPONSE_REJECT,
+ GTK_RESPONSE_CANCEL,
"_OK",
GTK_RESPONSE_ACCEPT,
NULL);
@@ -591,7 +556,7 @@ set_control(const ControlID* control,
const void* body)
{
if (!updating) {
- jalv_set_control(control, size, type, body);
+ jalv_set_control(s_jalv, control, size, type, body);
}
}
@@ -604,20 +569,20 @@ differ_enough(float a, float b)
static void
set_float_control(const ControlID* control, float value)
{
- if (control->value_type == control->jalv->forge.Int) {
+ if (control->value_type == control->forge->Int) {
const int32_t ival = lrintf(value);
- set_control(control, sizeof(ival), control->jalv->forge.Int, &ival);
- } else if (control->value_type == control->jalv->forge.Long) {
+ set_control(control, sizeof(ival), control->forge->Int, &ival);
+ } else if (control->value_type == control->forge->Long) {
const int64_t lval = lrintf(value);
- set_control(control, sizeof(lval), control->jalv->forge.Long, &lval);
- } else if (control->value_type == control->jalv->forge.Float) {
- set_control(control, sizeof(value), control->jalv->forge.Float, &value);
- } else if (control->value_type == control->jalv->forge.Double) {
+ set_control(control, sizeof(lval), control->forge->Long, &lval);
+ } else if (control->value_type == control->forge->Float) {
+ set_control(control, sizeof(value), control->forge->Float, &value);
+ } else if (control->value_type == control->forge->Double) {
const double dval = value;
- set_control(control, sizeof(dval), control->jalv->forge.Double, &dval);
- } else if (control->value_type == control->jalv->forge.Bool) {
+ set_control(control, sizeof(dval), control->forge->Double, &dval);
+ } else if (control->value_type == control->forge->Bool) {
const int32_t ival = value;
- set_control(control, sizeof(ival), control->jalv->forge.Bool, &ival);
+ set_control(control, sizeof(ival), control->forge->Bool, &ival);
}
Controller* controller = (Controller*)control->widget;
@@ -680,10 +645,12 @@ control_changed(Jalv* jalv,
}
} else if (GTK_IS_TOGGLE_BUTTON(widget)) {
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), fvalue > 0.0f);
+ } else if (GTK_IS_SWITCH(widget)) {
+ gtk_switch_set_active(GTK_SWITCH(widget), fvalue > 0.f);
} else if (GTK_IS_RANGE(widget)) {
gtk_range_set_value(GTK_RANGE(widget), fvalue);
} else {
- fprintf(stderr, "Unknown widget type for value\n");
+ jalv_log(JALV_LOG_WARNING, "Unknown widget type for value\n");
}
if (controller->spin) {
@@ -695,7 +662,7 @@ control_changed(Jalv* jalv,
} else if (GTK_IS_FILE_CHOOSER(widget) && type == jalv->urids.atom_Path) {
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(widget), (const char*)body);
} else {
- fprintf(stderr, "Unknown widget type for value\n");
+ jalv_log(JALV_LOG_WARNING, "Unknown widget type for value\n");
}
}
@@ -712,12 +679,12 @@ patch_set_get(Jalv* jalv,
value,
0);
if (!*property) {
- fprintf(stderr, "patch:Set message with no property\n");
+ jalv_log(JALV_LOG_WARNING, "patch:Set message with no property\n");
return 1;
}
if ((*property)->atom.type != jalv->forge.URID) {
- fprintf(stderr, "patch:Set property is not a URID\n");
+ jalv_log(JALV_LOG_WARNING, "patch:Set property is not a URID\n");
return 1;
}
@@ -731,12 +698,12 @@ patch_put_get(Jalv* jalv,
{
lv2_atom_object_get(obj, jalv->urids.patch_body, (const LV2_Atom*)body, 0);
if (!*body) {
- fprintf(stderr, "patch:Put message with no body\n");
+ jalv_log(JALV_LOG_WARNING, "patch:Put message with no body\n");
return 1;
}
if (!lv2_atom_forge_is_object_type(&jalv->forge, (*body)->atom.type)) {
- fprintf(stderr, "patch:Put body is not an object\n");
+ jalv_log(JALV_LOG_WARNING, "patch:Put body is not an object\n");
return 1;
}
@@ -763,9 +730,9 @@ on_request_value(LV2UI_Feature_Handle handle,
GtkWidget* dialog = gtk_file_chooser_dialog_new("Choose file",
GTK_WINDOW(jalv->window),
GTK_FILE_CHOOSER_ACTION_OPEN,
- GTK_STOCK_CANCEL,
+ "_Cancel",
GTK_RESPONSE_CANCEL,
- GTK_STOCK_OK,
+ "_OK",
GTK_RESPONSE_OK,
NULL);
@@ -819,7 +786,7 @@ jalv_ui_port_event(Jalv* jalv,
}
if (protocol != jalv->urids.atom_eventTransfer) {
- fprintf(stderr, "Unknown port event protocol\n");
+ jalv_log(JALV_LOG_WARNING, "Unknown port event protocol\n");
return;
}
@@ -842,7 +809,7 @@ jalv_ui_port_event(Jalv* jalv,
}
}
} else {
- printf("Unknown object type?\n");
+ jalv_log(JALV_LOG_ERR, "Unknown object type\n");
}
updating = false;
}
@@ -907,10 +874,12 @@ combo_changed(GtkComboBox* box, gpointer data)
}
static gboolean
-toggle_changed(GtkToggleButton* button, gpointer data)
+switch_changed(GtkSwitch* toggle_switch, gboolean state, gpointer data)
{
- set_float_control((const ControlID*)data,
- gtk_toggle_button_get_active(button) ? 1.0f : 0.0f);
+ (void)toggle_switch;
+ (void)data;
+
+ set_float_control((const ControlID*)data, state ? 1.0f : 0.0f);
return FALSE;
}
@@ -920,18 +889,17 @@ string_changed(GtkEntry* widget, gpointer data)
ControlID* control = (ControlID*)data;
const char* string = gtk_entry_get_text(widget);
- set_control(control, strlen(string) + 1, control->jalv->forge.String, string);
+ set_control(control, strlen(string) + 1, control->forge->String, string);
}
static void
file_changed(GtkFileChooserButton* widget, gpointer data)
{
ControlID* control = (ControlID*)data;
- Jalv* jalv = control->jalv;
const char* filename =
gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget));
- set_control(control, strlen(filename) + 1, jalv->forge.Path, filename);
+ set_control(control, strlen(filename) + 1, s_jalv->forge.Path, filename);
}
static Controller*
@@ -963,6 +931,8 @@ make_combo(ControlID* record, float value)
g_object_unref(list_store);
gtk_widget_set_sensitive(combo, record->is_writable);
+ gtk_widget_set_halign(combo, GTK_ALIGN_START);
+ gtk_widget_set_hexpand(combo, FALSE);
GtkCellRenderer* cell = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
@@ -979,13 +949,16 @@ make_combo(ControlID* record, float value)
static Controller*
make_log_slider(ControlID* record, float value)
{
- const float min = get_float(record->min, 0.0f);
- const float max = get_float(record->max, 1.0f);
- const float lmin = logf(min);
- const float lmax = logf(max);
- const float ldft = logf(value);
- GtkWidget* scale = new_hscale(lmin, lmax, 0.001);
- GtkWidget* spin = gtk_spin_button_new_with_range(min, max, 0.000001);
+ const float min = get_float(record->min, 0.0f);
+ const float max = get_float(record->max, 1.0f);
+ const float lmin = logf(min);
+ const float lmax = logf(max);
+ const float ldft = logf(value);
+
+ GtkWidget* const scale =
+ gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, lmin, lmax, 0.001);
+
+ GtkWidget* const spin = gtk_spin_button_new_with_range(min, max, 0.000001);
gtk_widget_set_sensitive(scale, record->is_writable);
gtk_widget_set_sensitive(spin, record->is_writable);
@@ -1007,11 +980,14 @@ make_log_slider(ControlID* record, float value)
static Controller*
make_slider(ControlID* record, float value)
{
- const float min = get_float(record->min, 0.0f);
- const float max = get_float(record->max, 1.0f);
- const double step = record->is_integer ? 1.0 : ((max - min) / 100.0);
- GtkWidget* scale = new_hscale(min, max, step);
- GtkWidget* spin = gtk_spin_button_new_with_range(min, max, step);
+ const float min = get_float(record->min, 0.0f);
+ const float max = get_float(record->max, 1.0f);
+ const double step = record->is_integer ? 1.0 : ((max - min) / 100.0);
+
+ GtkWidget* const scale =
+ gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, min, max, step);
+
+ GtkWidget* const spin = gtk_spin_button_new_with_range(min, max, step);
gtk_widget_set_sensitive(scale, record->is_writable);
gtk_widget_set_sensitive(spin, record->is_writable);
@@ -1042,26 +1018,30 @@ make_slider(ControlID* record, float value)
G_OBJECT(spin), "value-changed", G_CALLBACK(spin_changed), record);
}
+ gtk_widget_set_halign(scale, GTK_ALIGN_FILL);
+ gtk_widget_set_hexpand(scale, TRUE);
return new_controller(GTK_SPIN_BUTTON(spin), scale);
}
static Controller*
-make_toggle(ControlID* record, float value)
+make_toggle_switch(ControlID* record, float value)
{
- GtkWidget* check = gtk_check_button_new();
+ GtkWidget* toggle_switch = gtk_switch_new();
+ gtk_widget_set_halign(toggle_switch, GTK_ALIGN_START);
+ gtk_widget_set_hexpand(toggle_switch, FALSE);
- gtk_widget_set_sensitive(check, record->is_writable);
+ gtk_widget_set_sensitive(toggle_switch, record->is_writable);
if (value) {
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), TRUE);
+ gtk_switch_set_active(GTK_SWITCH(toggle_switch), TRUE);
}
if (record->is_writable) {
g_signal_connect(
- G_OBJECT(check), "toggled", G_CALLBACK(toggle_changed), record);
+ G_OBJECT(toggle_switch), "state-set", G_CALLBACK(switch_changed), record);
}
- return new_controller(NULL, check);
+ return new_controller(NULL, toggle_switch);
}
static Controller*
@@ -1100,7 +1080,7 @@ make_controller(ControlID* control, float value)
Controller* controller = NULL;
if (control->is_toggle) {
- controller = make_toggle(control, value);
+ controller = make_toggle_switch(control, value);
} else if (control->is_enumeration) {
controller = make_combo(control, value);
} else if (control->is_logarithmic) {
@@ -1113,58 +1093,36 @@ make_controller(ControlID* control, float value)
}
static GtkWidget*
-new_label(const char* text, bool title, float xalign, float yalign)
+new_label(const char* text, bool title, GtkAlign xalign, GtkAlign yalign)
{
GtkWidget* label = gtk_label_new(NULL);
const char* fmt = title ? "<span font_weight=\"bold\">%s</span>" : "%s:";
gchar* str = g_markup_printf_escaped(fmt, text);
+
+ gtk_widget_set_halign(label, xalign);
+ gtk_widget_set_valign(label, yalign);
gtk_label_set_markup(GTK_LABEL(label), str);
+
g_free(str);
- gtk_misc_set_alignment(GTK_MISC(label), xalign, yalign);
return label;
}
static void
-add_control_row(GtkWidget* table,
+add_control_row(GtkWidget* grid,
int row,
const char* name,
Controller* controller)
{
- GtkWidget* label = new_label(name, false, 1.0, 0.5);
- gtk_table_attach(GTK_TABLE(table),
- label,
- 0,
- 1,
- row,
- row + 1,
- GTK_FILL,
- (GtkAttachOptions)(GTK_FILL | GTK_EXPAND),
- 8,
- 1);
- int control_left_attach = 1;
+ GtkWidget* label = new_label(name, false, GTK_ALIGN_END, GTK_ALIGN_BASELINE);
+ gtk_widget_set_margin_end(label, 8);
+ gtk_grid_attach(GTK_GRID(grid), label, 0, row, 1, 1);
+
if (controller->spin) {
- control_left_attach = 2;
- gtk_table_attach(GTK_TABLE(table),
- GTK_WIDGET(controller->spin),
- 1,
- 2,
- row,
- row + 1,
- GTK_FILL,
- GTK_FILL,
- 2,
- 1);
+ gtk_grid_attach(GTK_GRID(grid), GTK_WIDGET(controller->spin), 1, row, 1, 1);
+ gtk_grid_attach(GTK_GRID(grid), controller->control, 2, row, 1, 1);
+ } else {
+ gtk_grid_attach(GTK_GRID(grid), controller->control, 1, row, 2, 1);
}
- gtk_table_attach(GTK_TABLE(table),
- controller->control,
- control_left_attach,
- 3,
- row,
- row + 1,
- (GtkAttachOptions)(GTK_FILL | GTK_EXPAND),
- GTK_FILL,
- 2,
- 1);
}
static int
@@ -1184,7 +1142,8 @@ control_group_cmp(const void* p1, const void* p2, void* ZIX_UNUSED(data))
static GtkWidget*
build_control_widget(Jalv* jalv, GtkWidget* window)
{
- GtkWidget* port_table = gtk_table_new(jalv->num_ports, 3, false);
+ GtkWidget* port_grid = gtk_grid_new();
+ gtk_grid_set_row_spacing(GTK_GRID(port_grid), 4);
// Make an array of controls sorted by group
GArray* controls = g_array_new(FALSE, TRUE, sizeof(ControlID*));
@@ -1205,18 +1164,18 @@ build_control_widget(Jalv* jalv, GtkWidget* window)
if (group && !lilv_node_equals(group, last_group)) {
LilvNode* group_name =
lilv_world_get(jalv->world, group, jalv->nodes.lv2_name, NULL);
- GtkWidget* group_label =
- new_label(lilv_node_as_string(group_name), true, 0.0f, 1.0f);
- gtk_table_attach(GTK_TABLE(port_table),
- group_label,
- 0,
- 2,
- n_rows,
- n_rows + 1,
- GTK_FILL,
- GTK_FILL,
- 0,
- 6);
+
+ if (!group_name) {
+ group_name =
+ lilv_world_get(jalv->world, group, jalv->nodes.rdfs_label, NULL);
+ }
+
+ GtkWidget* group_label = new_label(lilv_node_as_string(group_name),
+ true,
+ GTK_ALIGN_START,
+ GTK_ALIGN_BASELINE);
+
+ gtk_grid_attach(GTK_GRID(port_grid), group_label, 0, n_rows, 3, 1);
++n_rows;
}
last_group = group;
@@ -1237,7 +1196,7 @@ build_control_widget(Jalv* jalv, GtkWidget* window)
}
if (controller) {
// Add row to table for this controller
- add_control_row(port_table,
+ add_control_row(port_grid,
n_rows++,
(record->label ? lilv_node_as_string(record->label)
: lilv_node_as_uri(record->node)),
@@ -1256,13 +1215,16 @@ build_control_widget(Jalv* jalv, GtkWidget* window)
if (n_rows > 0) {
gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
- GtkWidget* alignment = gtk_alignment_new(0.5, 0.0, 1.0, 0.0);
- gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 0, 0, 8, 8);
- gtk_container_add(GTK_CONTAINER(alignment), port_table);
- return alignment;
+ gtk_widget_set_margin_start(port_grid, 8);
+ gtk_widget_set_margin_end(port_grid, 8);
+ gtk_widget_set_halign(port_grid, GTK_ALIGN_FILL);
+ gtk_widget_set_hexpand(port_grid, TRUE);
+ gtk_widget_set_valign(port_grid, GTK_ALIGN_START);
+ gtk_widget_set_vexpand(port_grid, FALSE);
+ return port_grid;
}
- gtk_widget_destroy(port_table);
+ gtk_widget_destroy(port_grid);
GtkWidget* button = gtk_button_new_with_label("Close");
g_signal_connect_swapped(
button, "clicked", G_CALLBACK(gtk_widget_destroy), window);
@@ -1280,8 +1242,8 @@ build_menu(Jalv* jalv, GtkWidget* window, GtkWidget* vbox)
GtkAccelGroup* ag = gtk_accel_group_new();
gtk_window_add_accel_group(GTK_WINDOW(window), ag);
- GtkWidget* save = gtk_image_menu_item_new_from_stock(GTK_STOCK_SAVE, ag);
- GtkWidget* quit = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, ag);
+ GtkWidget* save = gtk_menu_item_new_with_mnemonic("_Save");
+ GtkWidget* quit = gtk_menu_item_new_with_mnemonic("_Quit");
gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), file_menu);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), save);
@@ -1327,37 +1289,29 @@ build_menu(Jalv* jalv, GtkWidget* window, GtkWidget* vbox)
}
bool
-jalv_discover_ui(Jalv* ZIX_UNUSED(jalv))
+jalv_frontend_discover(Jalv* ZIX_UNUSED(jalv))
{
return TRUE;
}
float
-jalv_ui_refresh_rate(Jalv* ZIX_UNUSED(jalv))
+jalv_frontend_refresh_rate(Jalv* ZIX_UNUSED(jalv))
{
-#if GTK_MAJOR_VERSION == 2
- return 30.0f;
-#else
GdkDisplay* const display = gdk_display_get_default();
GdkMonitor* const monitor = gdk_display_get_primary_monitor(display);
const float rate = (float)gdk_monitor_get_refresh_rate(monitor);
return rate < 30.0f ? 30.0f : rate;
-#endif
}
float
-jalv_ui_scale_factor(Jalv* ZIX_UNUSED(jalv))
+jalv_frontend_scale_factor(Jalv* ZIX_UNUSED(jalv))
{
-#if GTK_MAJOR_VERSION == 2
- return 1.0f;
-#else
GdkDisplay* const display = gdk_display_get_default();
GdkMonitor* const monitor = gdk_display_get_primary_monitor(display);
return (float)gdk_monitor_get_scale_factor(monitor);
-#endif
}
static void
@@ -1374,17 +1328,19 @@ on_row_activated(GtkTreeView* const tree_view,
}
LilvNode*
-jalv_select_plugin(Jalv* jalv)
+jalv_frontend_select_plugin(Jalv* jalv)
{
// Create the dialog
- GtkWidget* const dialog = gtk_dialog_new_with_buttons("Plugin Selector",
- NULL,
- (GtkDialogFlags)0,
- "_OK",
- GTK_RESPONSE_ACCEPT,
- "_Cancel",
- GTK_RESPONSE_REJECT,
- NULL);
+ GtkWidget* const dialog = gtk_dialog_new_with_buttons(
+ "Plugin Selector",
+ NULL,
+ (GtkDialogFlags)(GTK_DIALOG_USE_HEADER_BAR | GTK_DIALOG_MODAL |
+ GTK_DIALOG_DESTROY_WITH_PARENT),
+ "_Cancel",
+ GTK_RESPONSE_CANCEL,
+ "_Load",
+ GTK_RESPONSE_ACCEPT,
+ NULL);
gtk_window_set_role(GTK_WINDOW(dialog), "plugin_selector");
gtk_window_set_default_size(GTK_WINDOW(dialog), 800, 600);
@@ -1476,16 +1432,19 @@ jalv_select_plugin(Jalv* jalv)
}
int
-jalv_open_ui(Jalv* jalv)
+jalv_frontend_open(Jalv* jalv)
{
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
jalv->window = window;
+ s_jalv = jalv;
+
g_signal_connect(window, "destroy", G_CALLBACK(on_window_destroy), jalv);
set_window_title(jalv);
- GtkWidget* vbox = new_box(false, 0);
+ GtkWidget* vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
+
gtk_window_set_role(GTK_WINDOW(window), "plugin_ui");
gtk_container_add(GTK_CONTAINER(window), vbox);
@@ -1493,14 +1452,19 @@ jalv_open_ui(Jalv* jalv)
build_menu(jalv, window, vbox);
}
- // Create/show alignment to contain UI (whether custom or generic)
- GtkWidget* alignment = gtk_alignment_new(0.5, 0.5, 1.0, 1.0);
- gtk_box_pack_start(GTK_BOX(vbox), alignment, TRUE, TRUE, 0);
- gtk_widget_show(alignment);
+ // Create and show a box to contain the plugin UI
+ GtkWidget* ui_box = gtk_event_box_new();
+ gtk_widget_set_halign(ui_box, GTK_ALIGN_FILL);
+ gtk_widget_set_hexpand(ui_box, TRUE);
+ gtk_widget_set_valign(ui_box, GTK_ALIGN_FILL);
+ gtk_widget_set_vexpand(ui_box, TRUE);
+ gtk_box_pack_start(GTK_BOX(vbox), ui_box, TRUE, TRUE, 0);
+ gtk_widget_show(ui_box);
+ gtk_widget_show(vbox);
// Attempt to instantiate custom UI if necessary
if (jalv->ui && !jalv->opts.generic_ui) {
- jalv_ui_instantiate(jalv, jalv_native_ui_type(), alignment);
+ jalv_ui_instantiate(jalv, jalv_frontend_ui_type(), ui_box);
}
jalv->features.request_value.request = on_request_value;
@@ -1508,25 +1472,26 @@ jalv_open_ui(Jalv* jalv)
if (jalv->ui_instance) {
GtkWidget* widget = (GtkWidget*)suil_instance_get_widget(jalv->ui_instance);
- gtk_container_add(GTK_CONTAINER(alignment), widget);
+ gtk_container_add(GTK_CONTAINER(ui_box), widget);
gtk_window_set_resizable(GTK_WINDOW(window), jalv_ui_is_resizable(jalv));
gtk_widget_show_all(vbox);
gtk_widget_grab_focus(widget);
} else {
GtkWidget* controls = build_control_widget(jalv, window);
GtkWidget* scroll_win = gtk_scrolled_window_new(NULL, NULL);
- gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll_win),
- controls);
+ gtk_container_add(GTK_CONTAINER(scroll_win), controls);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_win),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
- gtk_container_add(GTK_CONTAINER(alignment), scroll_win);
+ gtk_container_add(GTK_CONTAINER(ui_box), scroll_win);
+ gtk_widget_set_margin_top(controls, 8);
+ gtk_widget_set_margin_bottom(controls, 8);
gtk_widget_show_all(vbox);
GtkRequisition controls_size = {0, 0};
GtkRequisition box_size = {0, 0};
- size_request(GTK_WIDGET(controls), &controls_size);
- size_request(GTK_WIDGET(vbox), &box_size);
+ gtk_widget_get_preferred_size(GTK_WIDGET(controls), NULL, &controls_size);
+ gtk_widget_get_preferred_size(GTK_WIDGET(vbox), NULL, &box_size);
gtk_window_set_default_size(
GTK_WINDOW(window),
@@ -1548,10 +1513,9 @@ jalv_open_ui(Jalv* jalv)
}
int
-jalv_close_ui(Jalv* ZIX_UNUSED(jalv))
+jalv_frontend_close(Jalv* ZIX_UNUSED(jalv))
{
gtk_main_quit();
+ s_jalv = NULL;
return 0;
}
-
-LV2_RESTORE_WARNINGS
diff --git a/src/jalv_internal.h b/src/jalv_internal.h
index 0800405..01d4c86 100644
--- a/src/jalv_internal.h
+++ b/src/jalv_internal.h
@@ -1,38 +1,30 @@
-/*
- Copyright 2007-2022 David Robillard <d@drobilla.net>
-
- 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.
-*/
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
#ifndef JALV_INTERNAL_H
#define JALV_INTERNAL_H
+#include "attributes.h"
+#include "control.h"
#include "jalv_config.h"
-#include "lv2_evbuf.h"
+#include "log.h"
+#include "nodes.h"
+#include "options.h"
#include "symap.h"
+#include "types.h"
+#include "urids.h"
+#include "worker.h"
#include "zix/ring.h"
#include "zix/sem.h"
-#include "zix/thread.h"
#include "lilv/lilv.h"
#include "serd/serd.h"
#include "sratom/sratom.h"
-#ifdef HAVE_SUIL
+#if USE_SUIL
# include "suil/suil.h"
#endif
-#include "lv2/atom/atom.h"
#include "lv2/atom/forge.h"
#include "lv2/core/lv2.h"
#include "lv2/data-access/data-access.h"
@@ -43,225 +35,11 @@
#include "lv2/urid/urid.h"
#include "lv2/worker/worker.h"
-#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#ifdef __clang__
-# define REALTIME __attribute__((annotate("realtime")))
-#else
-# define REALTIME
-#endif
-
-#ifdef __GNUC__
-# define JALV_LOG_FUNC(fmt, arg1) __attribute__((format(printf, fmt, arg1)))
-#else
-# define JALV_LOG_FUNC(fmt, arg1)
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-struct Jalv;
-
-typedef struct JalvBackend JalvBackend;
-
-typedef struct Jalv Jalv;
-
-enum PortFlow { FLOW_UNKNOWN, FLOW_INPUT, FLOW_OUTPUT };
-
-enum PortType { TYPE_UNKNOWN, TYPE_CONTROL, TYPE_AUDIO, TYPE_EVENT, TYPE_CV };
-
-struct Port {
- const LilvPort* lilv_port; ///< LV2 port
- enum PortType type; ///< Data type
- enum PortFlow flow; ///< Data flow direction
- void* sys_port; ///< For audio/MIDI ports, otherwise NULL
- LV2_Evbuf* evbuf; ///< For MIDI ports, otherwise NULL
- void* widget; ///< Control widget, if applicable
- size_t buf_size; ///< Custom buffer size, or 0
- uint32_t index; ///< Port index
- float control; ///< For control ports, otherwise 0.0f
-};
-
-// Controls
-
-/// Type of plugin control
-typedef enum {
- PORT, ///< Control port
- PROPERTY ///< Property (set via atom message)
-} ControlType;
-
-typedef struct {
- float value;
- char* label;
-} ScalePoint;
-
-/// Order scale points by value
-int
-scale_point_cmp(const ScalePoint* a, const ScalePoint* b);
-
-/// Plugin control
-typedef struct {
- Jalv* jalv;
- ControlType type;
- LilvNode* node;
- LilvNode* symbol; ///< Symbol
- LilvNode* label; ///< Human readable label
- LV2_URID property; ///< Iff type == PROPERTY
- uint32_t index; ///< Iff type == PORT
- LilvNode* group; ///< Port/control group, or NULL
- void* widget; ///< Control Widget
- size_t n_points; ///< Number of scale points
- ScalePoint* points; ///< Scale points
- LV2_URID value_type; ///< Type of control value
- LilvNode* min; ///< Minimum value
- LilvNode* max; ///< Maximum value
- LilvNode* def; ///< Default value
- bool is_toggle; ///< Boolean (0 and 1 only)
- bool is_integer; ///< Integer values only
- bool is_enumeration; ///< Point values only
- bool is_logarithmic; ///< Logarithmic scale
- bool is_writable; ///< Writable (input)
- bool is_readable; ///< Readable (output)
-} ControlID;
-
-ControlID*
-new_port_control(Jalv* jalv, uint32_t index);
-
-ControlID*
-new_property_control(Jalv* jalv, const LilvNode* property);
-
-typedef struct {
- size_t n_controls;
- ControlID** controls;
-} Controls;
-
-void
-add_control(Controls* controls, ControlID* control);
-
-ControlID*
-get_property_control(const Controls* controls, LV2_URID property);
-
-/// Control change event, sent through ring buffers for UI updates
-typedef struct {
- uint32_t index;
- uint32_t protocol;
- uint32_t size;
-
- // Followed immediately by size bytes of data
-} ControlChange;
-
-typedef struct {
- char* name; ///< Client name
- int name_exact; ///< Exit if name is taken
- char* load; ///< Path for state to load
- char* preset; ///< URI of preset to load
- char** controls; ///< Control values
- uint32_t buffer_size; ///< Plugin <= >UI communication buffer size
- double update_rate; ///< UI update rate in Hz
- double scale_factor; ///< UI scale factor
- int dump; ///< Dump communication iff true
- int trace; ///< Print trace log iff true
- int generic_ui; ///< Use generic UI iff true
- int show_hidden; ///< Show controls for notOnGUI ports
- int no_menu; ///< Hide menu iff true
- int show_ui; ///< Show non-embedded UI
- int print_controls; ///< Print control changes to stdout
- int non_interactive; ///< Do not listen for commands on stdin
- char* ui_uri; ///< URI of UI to load
-} JalvOptions;
-
-typedef struct {
- LV2_URID atom_Float;
- LV2_URID atom_Int;
- LV2_URID atom_Object;
- LV2_URID atom_Path;
- LV2_URID atom_String;
- LV2_URID atom_eventTransfer;
- LV2_URID bufsz_maxBlockLength;
- LV2_URID bufsz_minBlockLength;
- LV2_URID bufsz_sequenceSize;
- LV2_URID log_Error;
- LV2_URID log_Trace;
- LV2_URID log_Warning;
- LV2_URID midi_MidiEvent;
- LV2_URID param_sampleRate;
- LV2_URID patch_Get;
- LV2_URID patch_Put;
- LV2_URID patch_Set;
- LV2_URID patch_body;
- LV2_URID patch_property;
- LV2_URID patch_value;
- LV2_URID time_Position;
- LV2_URID time_bar;
- LV2_URID time_barBeat;
- LV2_URID time_beatUnit;
- LV2_URID time_beatsPerBar;
- LV2_URID time_beatsPerMinute;
- LV2_URID time_frame;
- LV2_URID time_speed;
- LV2_URID ui_scaleFactor;
- LV2_URID ui_updateRate;
-} JalvURIDs;
-
-typedef struct {
- LilvNode* atom_AtomPort;
- LilvNode* atom_Chunk;
- LilvNode* atom_Float;
- LilvNode* atom_Path;
- LilvNode* atom_Sequence;
- LilvNode* lv2_AudioPort;
- LilvNode* lv2_CVPort;
- LilvNode* lv2_ControlPort;
- LilvNode* lv2_InputPort;
- LilvNode* lv2_OutputPort;
- LilvNode* lv2_connectionOptional;
- LilvNode* lv2_control;
- LilvNode* lv2_default;
- LilvNode* lv2_enumeration;
- LilvNode* lv2_extensionData;
- LilvNode* lv2_integer;
- LilvNode* lv2_maximum;
- LilvNode* lv2_minimum;
- LilvNode* lv2_name;
- LilvNode* lv2_reportsLatency;
- LilvNode* lv2_sampleRate;
- LilvNode* lv2_symbol;
- LilvNode* lv2_toggled;
- LilvNode* midi_MidiEvent;
- LilvNode* pg_group;
- LilvNode* pprops_logarithmic;
- LilvNode* pprops_notOnGUI;
- LilvNode* pprops_rangeSteps;
- LilvNode* pset_Preset;
- LilvNode* pset_bank;
- LilvNode* rdfs_comment;
- LilvNode* rdfs_label;
- LilvNode* rdfs_range;
- LilvNode* rsz_minimumSize;
- LilvNode* ui_showInterface;
- LilvNode* work_interface;
- LilvNode* work_schedule;
- LilvNode* end; ///< NULL terminator for easy freeing of entire structure
-} JalvNodes;
-
-typedef enum { JALV_RUNNING, JALV_PAUSE_REQUESTED, JALV_PAUSED } JalvPlayState;
-
-typedef struct {
- Jalv* jalv; ///< Pointer back to Jalv
- ZixRing* requests; ///< Requests to the worker
- ZixRing* responses; ///< Responses from the worker
- void* response; ///< Worker response buffer
- ZixSem sem; ///< Worker semaphore
- ZixThread thread; ///< Worker thread
- const LV2_Worker_Interface* iface; ///< Plugin worker interface
- bool threaded; ///< Run work in another thread
-} JalvWorker;
+JALV_BEGIN_DECLS
typedef struct {
LV2_Feature map_feature;
@@ -282,39 +60,39 @@ typedef struct {
LV2_Extension_Data_Feature ext_data;
} JalvFeatures;
-struct Jalv {
- JalvOptions opts; ///< Command-line options
- JalvURIDs urids; ///< URIDs
- JalvNodes nodes; ///< Nodes
- LV2_Atom_Forge forge; ///< Atom forge
- const char* prog_name; ///< Program name (argv[0])
- LilvWorld* world; ///< Lilv World
- LV2_URID_Map map; ///< URI => Int map
- LV2_URID_Unmap unmap; ///< Int => URI map
- SerdEnv* env; ///< Environment for RDF printing
- Sratom* sratom; ///< Atom serialiser
- Sratom* ui_sratom; ///< Atom serialiser for UI thread
- Symap* symap; ///< URI map
- ZixSem symap_lock; ///< Lock for URI map
- JalvBackend* backend; ///< Audio system backend
- ZixRing* ui_events; ///< Port events from UI
- ZixRing* plugin_events; ///< Port events from plugin
- void* ui_event_buf; ///< Buffer for reading UI port events
- JalvWorker worker; ///< Worker thread implementation
- JalvWorker state_worker; ///< Synchronous worker for state restore
- ZixSem work_lock; ///< Lock for plugin work() method
- ZixSem done; ///< Exit semaphore
- ZixSem paused; ///< Paused signal from process thread
- JalvPlayState play_state; ///< Current play state
- char* temp_dir; ///< Temporary plugin state directory
- char* save_dir; ///< Plugin save directory
- const LilvPlugin* plugin; ///< Plugin class (RDF data)
- LilvState* preset; ///< Current preset
- LilvUIs* uis; ///< All plugin UIs (RDF data)
- const LilvUI* ui; ///< Plugin UI (RDF data)
- const LilvNode* ui_type; ///< Plugin UI type (unwrapped)
- LilvInstance* instance; ///< Plugin instance (shared library)
-#ifdef HAVE_SUIL
+struct JalvImpl {
+ JalvOptions opts; ///< Command-line options
+ JalvURIDs urids; ///< URIDs
+ JalvNodes nodes; ///< Nodes
+ JalvLog log; ///< Log for error/warning/debug messages
+ LV2_Atom_Forge forge; ///< Atom forge
+ LilvWorld* world; ///< Lilv World
+ LV2_URID_Map map; ///< URI => Int map
+ LV2_URID_Unmap unmap; ///< Int => URI map
+ SerdEnv* env; ///< Environment for RDF printing
+ Sratom* sratom; ///< Atom serialiser
+ Sratom* ui_sratom; ///< Atom serialiser for UI thread
+ Symap* symap; ///< URI map
+ ZixSem symap_lock; ///< Lock for URI map
+ JalvBackend* backend; ///< Audio system backend
+ ZixRing* ui_to_plugin; ///< Port events from UI
+ ZixRing* plugin_to_ui; ///< Port events from plugin
+ void* ui_event_buf; ///< Buffer for reading UI port events
+ JalvWorker* worker; ///< Worker thread implementation
+ JalvWorker* state_worker; ///< Synchronous worker for state restore
+ ZixSem work_lock; ///< Lock for plugin work() method
+ ZixSem done; ///< Exit semaphore
+ ZixSem paused; ///< Paused signal from process thread
+ JalvPlayState play_state; ///< Current play state
+ char* temp_dir; ///< Temporary plugin state directory
+ char* save_dir; ///< Plugin save directory
+ const LilvPlugin* plugin; ///< Plugin class (RDF data)
+ LilvState* preset; ///< Current preset
+ LilvUIs* uis; ///< All plugin UIs (RDF data)
+ const LilvUI* ui; ///< Plugin UI (RDF data)
+ const LilvNode* ui_type; ///< Plugin UI type (unwrapped)
+ LilvInstance* instance; ///< Plugin instance (shared library)
+#if USE_SUIL
SuilHost* ui_host; ///< Plugin UI host support
SuilInstance* ui_instance; ///< Plugin UI instance (shared library)
#endif
@@ -334,7 +112,6 @@ struct Jalv {
float bpm; ///< Transport tempo in beats per minute
bool rolling; ///< Transport speed (0=stop, 1=play)
bool buf_size_set; ///< True iff buffer size callback fired
- bool exit; ///< True iff execution is finished
bool has_ui; ///< True iff a control UI is present
bool request_update; ///< True iff a plugin update is needed
bool safe_restore; ///< Plugin restore() is thread-safe
@@ -346,27 +123,8 @@ int
jalv_open(Jalv* jalv, int* argc, char*** argv);
int
-jalv_init(int* argc, char*** argv, JalvOptions* opts);
-
-int
jalv_close(Jalv* jalv);
-JalvBackend*
-jalv_backend_init(Jalv* jalv);
-
-void
-jalv_backend_activate(Jalv* jalv);
-
-void
-jalv_backend_deactivate(Jalv* jalv);
-
-void
-jalv_backend_close(Jalv* jalv);
-
-/// Expose a port to the system (if applicable) and connect it to its buffer
-void
-jalv_backend_activate_port(Jalv* jalv, uint32_t port_index);
-
void
jalv_create_ports(Jalv* jalv);
@@ -383,35 +141,15 @@ ControlID*
jalv_control_by_symbol(Jalv* jalv, const char* sym);
void
-jalv_set_control(const ControlID* control,
+jalv_set_control(Jalv* jalv,
+ const ControlID* control,
uint32_t size,
LV2_URID type,
const void* body);
-const char*
-jalv_native_ui_type(void);
-
-bool
-jalv_discover_ui(Jalv* jalv);
-
-float
-jalv_ui_refresh_rate(Jalv* jalv);
-
-float
-jalv_ui_scale_factor(Jalv* jalv);
-
-int
-jalv_open_ui(Jalv* jalv);
-
-LilvNode*
-jalv_select_plugin(Jalv* jalv);
-
void
jalv_init_ui(Jalv* jalv);
-int
-jalv_close_ui(Jalv* jalv);
-
void
jalv_ui_instantiate(Jalv* jalv, const char* native_ui_type, void* parent);
@@ -419,18 +157,15 @@ bool
jalv_ui_is_resizable(Jalv* jalv);
void
-jalv_ui_write(void* jalv_handle,
- uint32_t port_index,
- uint32_t buffer_size,
- uint32_t protocol,
- const void* buffer);
+jalv_send_to_plugin(void* jalv_handle,
+ uint32_t port_index,
+ uint32_t buffer_size,
+ uint32_t protocol,
+ const void* buffer);
void
jalv_apply_ui_events(Jalv* jalv, uint32_t nframes);
-uint32_t
-jalv_ui_port_index(void* controller, const char* symbol);
-
void
jalv_ui_port_event(Jalv* jalv,
uint32_t port_index,
@@ -438,84 +173,58 @@ jalv_ui_port_event(Jalv* jalv,
uint32_t protocol,
const void* buffer);
-bool
-jalv_send_to_ui(Jalv* jalv,
- uint32_t port_index,
- uint32_t type,
- uint32_t size,
- const void* body);
-bool
-jalv_run(Jalv* jalv, uint32_t nframes);
-
-int
-jalv_update(Jalv* jalv);
-
-typedef int (*PresetSink)(Jalv* jalv,
- const LilvNode* node,
- const LilvNode* title,
- void* data);
-
-int
-jalv_load_presets(Jalv* jalv, PresetSink sink, void* data);
-
-int
-jalv_unload_presets(Jalv* jalv);
+/**
+ Write a port event using the atom:eventTransfer protocol.
-int
-jalv_apply_preset(Jalv* jalv, const LilvNode* preset);
+ This is used to transfer atoms between the plugin and UI via sequence ports.
+ @param jalv Jalv instance.
+ @param target Communication ring (jalv->plugin_to_ui or jalv->ui_to_plugin).
+ @param port_index Index of the port this change is for.
+ @param size Size of body in bytes.
+ @param type Atom type URID.
+ @param body Atom body.
+ @return 0 on success, non-zero on failure (overflow).
+*/
int
-jalv_delete_current_preset(Jalv* jalv);
-
+jalv_write_event(Jalv* jalv,
+ ZixRing* target,
+ uint32_t port_index,
+ uint32_t size,
+ LV2_URID type,
+ const void* body);
+
+/**
+ Write a control port change using the default (0) protocol.
+
+ This is used to transfer control port value changes between the plugin and
+ UI.
+
+ @param jalv Jalv instance.
+ @param target Communication ring (jalv->plugin_to_ui or jalv->ui_to_plugin).
+ @param port_index Index of the port this change is for.
+ @param value New control port value.
+ @return 0 on success, non-zero on failure (overflow).
+*/
int
-jalv_save_preset(Jalv* jalv,
- const char* dir,
- const char* uri,
- const char* label,
- const char* filename);
-
-void
-jalv_save(Jalv* jalv, const char* dir);
-
-void
-jalv_save_port_values(Jalv* jalv, SerdWriter* writer, const SerdNode* subject);
-char*
-jalv_make_path(LV2_State_Make_Path_Handle handle, const char* path);
-
-void
-jalv_apply_state(Jalv* jalv, LilvState* state);
-
-char*
-atom_to_turtle(LV2_URID_Unmap* unmap,
- const SerdNode* subject,
- const SerdNode* predicate,
- const LV2_Atom* atom);
+jalv_write_control(Jalv* jalv,
+ ZixRing* target,
+ uint32_t port_index,
+ float value);
void
-jalv_print_control(Jalv* jalv, const struct Port* port, float value);
-
-char*
-jalv_strdup(const char* str);
-
-char*
-jalv_strjoin(const char* a, const char* b);
-
-JALV_LOG_FUNC(3, 4)
-int
-jalv_printf(LV2_Log_Handle handle, LV2_URID type, const char* fmt, ...);
-
-JALV_LOG_FUNC(3, 0)
-int
-jalv_vprintf(LV2_Log_Handle handle, LV2_URID type, const char* fmt, va_list ap);
+jalv_dump_atom(Jalv* jalv,
+ FILE* stream,
+ const char* label,
+ const LV2_Atom* atom,
+ int color);
bool
-jalv_ansi_start(FILE* stream, int color);
+jalv_run(Jalv* jalv, uint32_t nframes);
-void
-jalv_ansi_reset(FILE* stream);
+int
+jalv_update(Jalv* jalv);
-#ifdef __cplusplus
-} // extern "C"
-#endif
+JALV_END_DECLS
#endif // JALV_INTERNAL_H
diff --git a/src/jalv_qt.cpp b/src/jalv_qt.cpp
index 7818a58..a63a508 100644
--- a/src/jalv_qt.cpp
+++ b/src/jalv_qt.cpp
@@ -1,28 +1,17 @@
-/*
- Copyright 2007-2022 David Robillard <d@drobilla.net>
-
- 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.
-*/
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
#include "jalv_qt.hpp"
+#include "frontend.h"
#include "jalv_internal.h"
+#include "nodes.h"
+#include "options.h"
+#include "port.h"
#include "lilv/lilv.h"
#include "suil/suil.h"
#include "zix/sem.h"
-#include <QtGlobal>
-
#include <QAction>
#include <QApplication>
#include <QDial>
@@ -59,22 +48,22 @@
#include <map>
#include <vector>
-#define CONTROL_WIDTH 150
-#define DIAL_STEPS 10000
+constexpr int CONTROL_WIDTH = 150;
+constexpr int DIAL_STEPS = 10000;
static QApplication* app = nullptr;
-class FlowLayout : public QLayout
+class FlowLayout final : public QLayout
{
public:
explicit FlowLayout(QWidget* parent, int margin, int hSpacing, int vSpacing);
explicit FlowLayout(int margin, int hSpacing, int vSpacing);
- FlowLayout(const FlowLayout&) = delete;
+ FlowLayout(const FlowLayout&) = delete;
FlowLayout& operator=(const FlowLayout&) = delete;
- FlowLayout(FlowLayout&&) = delete;
+ FlowLayout(FlowLayout&&) = delete;
FlowLayout&& operator=(FlowLayout&&) = delete;
~FlowLayout() override;
@@ -224,10 +213,10 @@ FlowLayout::doLayout(const QRect& rect, bool testOnly) const
int bottom = 0;
getContentsMargins(&left, &top, &right, &bottom);
- QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
- int x = effectiveRect.x();
- int y = effectiveRect.y();
- int lineHeight = 0;
+ const QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
+ int x = effectiveRect.x();
+ int y = effectiveRect.y();
+ int lineHeight = 0;
QLayoutItem* item = nullptr;
foreach (item, itemList) {
@@ -287,7 +276,7 @@ FlowLayout::smartSpacing(QStyle::PixelMetric pm) const
extern "C" {
int
-jalv_init(int* argc, char*** argv, JalvOptions*)
+jalv_frontend_init(int* argc, char*** argv, JalvOptions*)
{
app = new QApplication(*argc, *argv, true);
app->setStyleSheet("QGroupBox::title { subcontrol-position: top center }");
@@ -296,7 +285,7 @@ jalv_init(int* argc, char*** argv, JalvOptions*)
}
const char*
-jalv_native_ui_type(void)
+jalv_frontend_ui_type(void)
{
return "http://lv2plug.in/ns/extensions/ui#Qt5UI";
}
@@ -353,11 +342,6 @@ Control::Control(PortContainer portContainer, QWidget* parent)
, plugin(portContainer.jalv->plugin)
, port(portContainer.port)
, label(new QLabel())
- , max(1.0f)
- , min(0.0f)
- , isInteger(false)
- , isEnum(false)
- , isLogarithmic(false)
{
JalvNodes* nodes = &portContainer.jalv->nodes;
const LilvPort* lilvPort = port->lilv_port;
@@ -412,7 +396,7 @@ Control::Control(PortContainer portContainer, QWidget* parent)
}
// Find and set min, max and default values for port
- float defaultValue = ndef ? lilv_node_as_float(ndef) : port->control;
+ const float defaultValue = ndef ? lilv_node_as_float(ndef) : port->control;
setRange(lilv_node_as_float(nmin), lilv_node_as_float(nmax));
setValue(defaultValue);
@@ -521,10 +505,11 @@ Control::getValue()
}
if (isLogarithmic) {
- return min * powf(max / min, (float)dial->value() / (steps - 1));
+ return min *
+ powf(max / min, static_cast<float>(dial->value()) / (steps - 1));
}
- return (float)dial->value() / steps;
+ return static_cast<float>(dial->value()) / steps;
}
int
@@ -540,7 +525,7 @@ Control::stringWidth(const QString& str)
void
Control::dialChanged(int)
{
- float value = getValue();
+ const float value = getValue();
label->setText(getValueLabel(value));
port->control = value;
@@ -594,14 +579,14 @@ build_control_widget(Jalv* jalv)
LilvNode* lastGroup = nullptr;
QHBoxLayout* groupLayout = nullptr;
for (int i = 0; i < portContainers.count(); ++i) {
- PortContainer portContainer = portContainers[i];
- Port* port = portContainer.port;
+ const PortContainer portContainer = portContainers[i];
+ Port* const port = portContainer.port;
auto* const control = new Control(portContainer, nullptr);
LilvNode* group =
lilv_port_get(plugin, port->lilv_port, jalv->nodes.pg_group);
if (group) {
- if (!lilv_node_equals(group, lastGroup)) {
+ if (!groupLayout || !lilv_node_equals(group, lastGroup)) {
// Group has changed
LilvNode* groupName =
lilv_world_get(world, group, jalv->nodes.lv2_name, nullptr);
@@ -624,7 +609,7 @@ build_control_widget(Jalv* jalv)
lilv_node_free(lastGroup);
lastGroup = group;
- uint32_t index = lilv_port_get_index(plugin, port->lilv_port);
+ const uint32_t index = lilv_port_get_index(plugin, port->lilv_port);
jalv->ports[index].widget = control;
}
lilv_node_free(lastGroup);
@@ -635,31 +620,32 @@ build_control_widget(Jalv* jalv)
}
bool
-jalv_discover_ui(Jalv*)
+jalv_frontend_discover(Jalv*)
{
return true;
}
float
-jalv_ui_refresh_rate(Jalv*)
+jalv_frontend_refresh_rate(Jalv*)
{
- return (float)QGuiApplication::primaryScreen()->refreshRate();
+ return static_cast<float>(QGuiApplication::primaryScreen()->refreshRate());
}
float
-jalv_ui_scale_factor(Jalv*)
+jalv_frontend_scale_factor(Jalv*)
{
- return (float)QGuiApplication::primaryScreen()->devicePixelRatio();
+ return static_cast<float>(
+ QGuiApplication::primaryScreen()->devicePixelRatio());
}
LilvNode*
-jalv_select_plugin(Jalv*)
+jalv_frontend_select_plugin(Jalv*)
{
return nullptr;
}
int
-jalv_open_ui(Jalv* jalv)
+jalv_frontend_open(Jalv* jalv)
{
auto* const win = new QMainWindow();
QMenu* file_menu = win->menuBar()->addMenu("&File");
@@ -674,7 +660,7 @@ jalv_open_ui(Jalv* jalv)
jalv_load_presets(jalv, add_preset_to_menu, presets_menu);
if (jalv->ui && !jalv->opts.generic_ui) {
- jalv_ui_instantiate(jalv, jalv_native_ui_type(), win);
+ jalv_ui_instantiate(jalv, jalv_frontend_ui_type(), win);
}
QWidget* widget = nullptr;
@@ -712,13 +698,13 @@ jalv_open_ui(Jalv* jalv)
auto* const timer = new Timer(jalv);
timer->start(1000 / jalv->ui_update_hz);
- int ret = app->exec();
+ const int ret = app->exec();
zix_sem_post(&jalv->done);
return ret;
}
int
-jalv_close_ui(Jalv*)
+jalv_frontend_close(Jalv*)
{
app->quit();
return 0;
diff --git a/src/jalv_qt.hpp b/src/jalv_qt.hpp
index b114504..d371098 100644
--- a/src/jalv_qt.hpp
+++ b/src/jalv_qt.hpp
@@ -1,63 +1,25 @@
-/*
- Copyright 2007-2022 David Robillard <d@drobilla.net>
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
- 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 "jalv_internal.h"
+#include "state.h"
+#include "types.h"
#include "lilv/lilv.h"
-#include "suil/suil.h"
-#include "zix/sem.h"
-
-#include <QtGlobal>
#include <QAction>
-#include <QApplication>
-#include <QDial>
-#include <QFontMetrics>
#include <QGroupBox>
-#include <QGuiApplication>
-#include <QHBoxLayout>
-#include <QKeySequence>
-#include <QLabel>
-#include <QLayout>
-#include <QLayoutItem>
-#include <QList>
-#include <QMainWindow>
-#include <QMenu>
-#include <QMenuBar>
-#include <QObject>
-#include <QPoint>
-#include <QRect>
-#include <QScreen>
-#include <QScrollArea>
-#include <QSize>
-#include <QSizePolicy>
#include <QString>
-#include <QStyle>
-#include <QTimer>
-#include <QVBoxLayout>
-#include <QWidget>
#include <QtCore>
-#include <algorithm>
-#include <cmath>
-#include <cstdint>
-#include <cstring>
#include <map>
#include <vector>
+struct Port;
+
+class QDial;
+class QLabel;
+class QWidget;
+
class PresetAction : public QAction
{
Q_OBJECT // NOLINT
@@ -79,8 +41,8 @@ private:
};
struct PortContainer {
- Jalv* jalv;
- struct Port* port;
+ Jalv* jalv;
+ Port* port;
};
class Control : public QGroupBox
@@ -102,16 +64,16 @@ private:
QDial* dial;
const LilvPlugin* plugin;
- struct Port* port;
+ Port* port;
QLabel* label;
QString name;
int steps;
- float max;
- float min;
- bool isInteger;
- bool isEnum;
- bool isLogarithmic;
+ float max{1.0f};
+ float min{0.0f};
+ bool isInteger{};
+ bool isEnum{};
+ bool isLogarithmic{};
std::vector<float> scalePoints;
std::map<float, const char*> scaleMap;
diff --git a/src/log.c b/src/log.c
index 9b5949d..e52f445 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1,34 +1,25 @@
-/*
- Copyright 2007-2016 David Robillard <d@drobilla.net>
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
- 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.
-*/
-
-#define _POSIX_C_SOURCE 200809L
+#include "log.h"
#include "jalv_config.h"
#include "jalv_internal.h"
+#include "port.h"
+#include "lilv/lilv.h"
#include "lv2/log/log.h"
#include "lv2/urid/urid.h"
-#ifdef HAVE_ISATTY
+#if USE_ISATTY
# include <unistd.h>
#endif
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
void
jalv_print_control(Jalv* const jalv,
@@ -36,7 +27,7 @@ jalv_print_control(Jalv* const jalv,
const float value)
{
const LilvNode* sym = lilv_port_get_symbol(jalv->plugin, port->lilv_port);
- printf("%s = %f\n", lilv_node_as_string(sym), value);
+ jalv_log(JALV_LOG_INFO, "%s = %f\n", lilv_node_as_string(sym), value);
}
char*
@@ -63,11 +54,43 @@ jalv_strjoin(const char* const a, const char* const b)
}
int
-jalv_printf(LV2_Log_Handle handle, LV2_URID type, const char* fmt, ...)
+jalv_vlog(const JalvLogLevel level, const char* const fmt, va_list ap)
+{
+ bool fancy = false;
+ switch (level) {
+ case JALV_LOG_ERR:
+ fancy = jalv_ansi_start(stderr, 31);
+ fprintf(stderr, "error: ");
+ break;
+ case JALV_LOG_WARNING:
+ fancy = jalv_ansi_start(stderr, 33);
+ fprintf(stderr, "warning: ");
+ break;
+ case JALV_LOG_INFO:
+ break;
+ case JALV_LOG_DEBUG:
+ fancy = jalv_ansi_start(stderr, 32);
+ fprintf(stderr, "trace: ");
+ break;
+ }
+
+ const int st = vfprintf(stderr, fmt, ap);
+
+ if (fancy) {
+ jalv_ansi_reset(stderr);
+ }
+
+ return st;
+}
+
+int
+jalv_log(const JalvLogLevel level, const char* const fmt, ...)
{
va_list args;
va_start(args, fmt);
- const int ret = jalv_vprintf(handle, type, fmt, args);
+
+ const int ret = jalv_vlog(level, fmt, args);
+
va_end(args);
return ret;
}
@@ -75,35 +98,37 @@ jalv_printf(LV2_Log_Handle handle, LV2_URID type, const char* fmt, ...)
int
jalv_vprintf(LV2_Log_Handle handle, LV2_URID type, const char* fmt, va_list ap)
{
- // TODO: Lock
- Jalv* jalv = (Jalv*)handle;
- bool fancy = true;
- if (type == jalv->urids.log_Trace && jalv->opts.trace) {
- jalv_ansi_start(stderr, 32);
- fprintf(stderr, "trace: ");
- } else if (type == jalv->urids.log_Error) {
- jalv_ansi_start(stderr, 31);
- fprintf(stderr, "error: ");
- } else if (type == jalv->urids.log_Warning) {
- jalv_ansi_start(stderr, 33);
- fprintf(stderr, "warning: ");
- } else {
- fancy = false;
+ JalvLog* const log = (JalvLog*)handle;
+
+ if (type == log->urids->log_Trace) {
+ return log->tracing ? jalv_vlog(JALV_LOG_DEBUG, fmt, ap) : 0;
}
- const int st = vfprintf(stderr, fmt, ap);
+ if (type == log->urids->log_Error) {
+ return jalv_vlog(JALV_LOG_ERR, fmt, ap);
+ }
- if (fancy) {
- jalv_ansi_reset(stderr);
+ if (type == log->urids->log_Warning) {
+ return jalv_vlog(JALV_LOG_WARNING, fmt, ap);
}
- return st;
+ return vfprintf(stderr, fmt, ap);
+}
+
+int
+jalv_printf(LV2_Log_Handle handle, LV2_URID type, const char* fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ const int ret = jalv_vprintf(handle, type, fmt, args);
+ va_end(args);
+ return ret;
}
bool
jalv_ansi_start(FILE* stream, int color)
{
-#if defined(HAVE_ISATTY) && defined(HAVE_FILENO)
+#if USE_ISATTY && USE_FILENO
if (isatty(fileno(stream))) {
return fprintf(stream, "\033[0;%dm", color);
}
@@ -114,7 +139,7 @@ jalv_ansi_start(FILE* stream, int color)
void
jalv_ansi_reset(FILE* stream)
{
-#ifdef HAVE_ISATTY
+#if USE_ISATTY
if (isatty(fileno(stream))) {
fprintf(stream, "\033[0m");
fflush(stream);
diff --git a/src/log.h b/src/log.h
new file mode 100644
index 0000000..100fc39
--- /dev/null
+++ b/src/log.h
@@ -0,0 +1,74 @@
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#ifndef JALV_LOG_H
+#define JALV_LOG_H
+
+#include "attributes.h"
+#include "types.h"
+#include "urids.h"
+
+#include "lv2/log/log.h"
+#include "lv2/urid/urid.h"
+
+#include <stdbool.h>
+#include <stdio.h>
+
+#ifdef __GNUC__
+# define JALV_LOG_FUNC(fmt, arg1) __attribute__((format(printf, fmt, arg1)))
+#else
+# define JALV_LOG_FUNC(fmt, arg1)
+#endif
+
+JALV_BEGIN_DECLS
+
+struct Port;
+
+// String and log utilities
+
+typedef enum {
+ JALV_LOG_ERR = 3,
+ JALV_LOG_WARNING = 4,
+ JALV_LOG_INFO = 6,
+ JALV_LOG_DEBUG = 7,
+} JalvLogLevel;
+
+typedef struct {
+ JalvURIDs* urids;
+ bool tracing;
+} JalvLog;
+
+void
+jalv_print_control(Jalv* jalv, const struct Port* port, float value);
+
+char*
+jalv_strdup(const char* str);
+
+char*
+jalv_strjoin(const char* a, const char* b);
+
+JALV_LOG_FUNC(2, 0)
+int
+jalv_vlog(JalvLogLevel level, const char* fmt, va_list ap);
+
+JALV_LOG_FUNC(2, 3)
+int
+jalv_log(JalvLogLevel level, const char* fmt, ...);
+
+JALV_LOG_FUNC(3, 0)
+int
+jalv_vprintf(LV2_Log_Handle handle, LV2_URID type, const char* fmt, va_list ap);
+
+JALV_LOG_FUNC(3, 4)
+int
+jalv_printf(LV2_Log_Handle handle, LV2_URID type, const char* fmt, ...);
+
+bool
+jalv_ansi_start(FILE* stream, int color);
+
+void
+jalv_ansi_reset(FILE* stream);
+
+JALV_END_DECLS
+
+#endif // JALV_LOG_H
diff --git a/src/lv2_evbuf.c b/src/lv2_evbuf.c
index 0d36dc9..f19aac2 100644
--- a/src/lv2_evbuf.c
+++ b/src/lv2_evbuf.c
@@ -1,22 +1,11 @@
-/*
- Copyright 2008-2018 David Robillard <d@drobilla.net>
-
- 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.
-*/
+// Copyright 2008-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
#include "lv2_evbuf.h"
+#include "jalv_config.h"
#include "lv2/atom/atom.h"
+#include "lv2/atom/util.h"
#include <assert.h>
#include <stdlib.h>
@@ -26,25 +15,35 @@ struct LV2_Evbuf_Impl {
uint32_t capacity;
uint32_t atom_Chunk;
uint32_t atom_Sequence;
+ uint32_t pad; // So buf has correct atom alignment
LV2_Atom_Sequence buf;
};
-static inline uint32_t
-lv2_evbuf_pad_size(uint32_t size)
-{
- return (size + 7) & (~7);
-}
-
LV2_Evbuf*
lv2_evbuf_new(uint32_t capacity, uint32_t atom_Chunk, uint32_t atom_Sequence)
{
- // FIXME: memory must be 64-bit aligned
- LV2_Evbuf* evbuf = (LV2_Evbuf*)malloc(sizeof(LV2_Evbuf) +
- sizeof(LV2_Atom_Sequence) + capacity);
- evbuf->capacity = capacity;
- evbuf->atom_Chunk = atom_Chunk;
- evbuf->atom_Sequence = atom_Sequence;
- lv2_evbuf_reset(evbuf, true);
+ const size_t buffer_size =
+ sizeof(LV2_Evbuf) + sizeof(LV2_Atom_Sequence) + capacity;
+
+#if USE_POSIX_MEMALIGN
+ LV2_Evbuf* evbuf = NULL;
+ const int st = posix_memalign((void**)&evbuf, 16, buffer_size);
+ if (st) {
+ return NULL;
+ }
+
+ assert((uintptr_t)evbuf % 8U == 0U);
+#else
+ LV2_Evbuf* evbuf = (LV2_Evbuf*)malloc(buffer_size);
+#endif
+
+ if (evbuf) {
+ memset(evbuf, 0, sizeof(*evbuf));
+ evbuf->capacity = capacity;
+ evbuf->atom_Chunk = atom_Chunk;
+ evbuf->atom_Sequence = atom_Sequence;
+ }
+
return evbuf;
}
@@ -93,7 +92,7 @@ LV2_Evbuf_Iterator
lv2_evbuf_end(LV2_Evbuf* evbuf)
{
const uint32_t size = lv2_evbuf_get_size(evbuf);
- const LV2_Evbuf_Iterator iter = {evbuf, lv2_evbuf_pad_size(size)};
+ const LV2_Evbuf_Iterator iter = {evbuf, lv2_atom_pad_size(size)};
return iter;
}
@@ -104,22 +103,21 @@ lv2_evbuf_is_valid(LV2_Evbuf_Iterator iter)
}
LV2_Evbuf_Iterator
-lv2_evbuf_next(LV2_Evbuf_Iterator iter)
+lv2_evbuf_next(const LV2_Evbuf_Iterator iter)
{
if (!lv2_evbuf_is_valid(iter)) {
return iter;
}
- LV2_Evbuf* evbuf = iter.evbuf;
- uint32_t offset = iter.offset;
- uint32_t size = 0;
- size = ((LV2_Atom_Event*)((char*)LV2_ATOM_CONTENTS(LV2_Atom_Sequence,
- &evbuf->buf.atom) +
- offset))
- ->body.size;
- offset += lv2_evbuf_pad_size(sizeof(LV2_Atom_Event) + size);
+ LV2_Atom_Sequence* aseq = &iter.evbuf->buf;
+ LV2_Atom_Event* aev =
+ (LV2_Atom_Event*)((char*)LV2_ATOM_CONTENTS(LV2_Atom_Sequence, aseq) +
+ iter.offset);
+
+ const uint32_t offset =
+ iter.offset + lv2_atom_pad_size(sizeof(LV2_Atom_Event) + aev->body.size);
- LV2_Evbuf_Iterator next = {evbuf, offset};
+ LV2_Evbuf_Iterator next = {iter.evbuf, offset};
return next;
}
@@ -129,7 +127,7 @@ lv2_evbuf_get(LV2_Evbuf_Iterator iter,
uint32_t* subframes,
uint32_t* type,
uint32_t* size,
- uint8_t** data)
+ void** data)
{
*frames = *subframes = *type = *size = 0;
*data = NULL;
@@ -147,7 +145,7 @@ lv2_evbuf_get(LV2_Evbuf_Iterator iter,
*subframes = 0;
*type = aev->body.type;
*size = aev->body.size;
- *data = (uint8_t*)LV2_ATOM_BODY(&aev->body);
+ *data = LV2_ATOM_BODY(&aev->body);
return true;
}
@@ -158,7 +156,7 @@ lv2_evbuf_write(LV2_Evbuf_Iterator* iter,
uint32_t subframes,
uint32_t type,
uint32_t size,
- const uint8_t* data)
+ const void* data)
{
(void)subframes;
@@ -177,7 +175,7 @@ lv2_evbuf_write(LV2_Evbuf_Iterator* iter,
aev->body.size = size;
memcpy(LV2_ATOM_BODY(&aev->body), data, size);
- size = lv2_evbuf_pad_size(sizeof(LV2_Atom_Event) + size);
+ size = lv2_atom_pad_size(sizeof(LV2_Atom_Event) + size);
aseq->atom.size += size;
iter->offset += size;
diff --git a/src/lv2_evbuf.h b/src/lv2_evbuf.h
index 31f3f08..685bef8 100644
--- a/src/lv2_evbuf.h
+++ b/src/lv2_evbuf.h
@@ -1,18 +1,5 @@
-/*
- Copyright 2008-2022 David Robillard <d@drobilla.net>
-
- 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.
-*/
+// Copyright 2008-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
#ifndef LV2_EVBUF_H
#define LV2_EVBUF_H
@@ -110,7 +97,7 @@ lv2_evbuf_get(LV2_Evbuf_Iterator iter,
uint32_t* subframes,
uint32_t* type,
uint32_t* size,
- uint8_t** data);
+ void** data);
/**
Write an event at `iter`.
@@ -127,7 +114,7 @@ lv2_evbuf_write(LV2_Evbuf_Iterator* iter,
uint32_t subframes,
uint32_t type,
uint32_t size,
- const uint8_t* data);
+ const void* data);
#ifdef __cplusplus
}
diff --git a/src/nodes.h b/src/nodes.h
new file mode 100644
index 0000000..ff9d4da
--- /dev/null
+++ b/src/nodes.h
@@ -0,0 +1,56 @@
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#ifndef JALV_NODES_H
+#define JALV_NODES_H
+
+#include "attributes.h"
+
+#include "lilv/lilv.h"
+
+JALV_BEGIN_DECLS
+
+typedef struct {
+ LilvNode* atom_AtomPort;
+ LilvNode* atom_Chunk;
+ LilvNode* atom_Float;
+ LilvNode* atom_Path;
+ LilvNode* atom_Sequence;
+ LilvNode* lv2_AudioPort;
+ LilvNode* lv2_CVPort;
+ LilvNode* lv2_ControlPort;
+ LilvNode* lv2_InputPort;
+ LilvNode* lv2_OutputPort;
+ LilvNode* lv2_connectionOptional;
+ LilvNode* lv2_control;
+ LilvNode* lv2_default;
+ LilvNode* lv2_enumeration;
+ LilvNode* lv2_extensionData;
+ LilvNode* lv2_integer;
+ LilvNode* lv2_maximum;
+ LilvNode* lv2_minimum;
+ LilvNode* lv2_name;
+ LilvNode* lv2_reportsLatency;
+ LilvNode* lv2_sampleRate;
+ LilvNode* lv2_symbol;
+ LilvNode* lv2_toggled;
+ LilvNode* midi_MidiEvent;
+ LilvNode* pg_group;
+ LilvNode* pprops_logarithmic;
+ LilvNode* pprops_notOnGUI;
+ LilvNode* pprops_rangeSteps;
+ LilvNode* pset_Preset;
+ LilvNode* pset_bank;
+ LilvNode* rdfs_comment;
+ LilvNode* rdfs_label;
+ LilvNode* rdfs_range;
+ LilvNode* rsz_minimumSize;
+ LilvNode* ui_showInterface;
+ LilvNode* work_interface;
+ LilvNode* work_schedule;
+ LilvNode* end; ///< NULL terminator for easy freeing of entire structure
+} JalvNodes;
+
+JALV_END_DECLS
+
+#endif // JALV_NODES_H
diff --git a/src/options.h b/src/options.h
new file mode 100644
index 0000000..91fbb77
--- /dev/null
+++ b/src/options.h
@@ -0,0 +1,35 @@
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#ifndef JALV_OPTIONS_H
+#define JALV_OPTIONS_H
+
+#include "attributes.h"
+
+#include <stdint.h>
+
+JALV_BEGIN_DECLS
+
+typedef struct {
+ char* name; ///< Client name
+ int name_exact; ///< Exit if name is taken
+ char* load; ///< Path for state to load
+ char* preset; ///< URI of preset to load
+ char** controls; ///< Control values
+ uint32_t buffer_size; ///< Plugin <=> UI communication buffer size
+ double update_rate; ///< UI update rate in Hz
+ double scale_factor; ///< UI scale factor
+ int dump; ///< Dump communication iff true
+ int trace; ///< Print trace log iff true
+ int generic_ui; ///< Use generic UI iff true
+ int show_hidden; ///< Show controls for notOnGUI ports
+ int no_menu; ///< Hide menu iff true
+ int show_ui; ///< Show non-embedded UI
+ int print_controls; ///< Print control changes to stdout
+ int non_interactive; ///< Do not listen for commands on stdin
+ char* ui_uri; ///< URI of UI to load
+} JalvOptions;
+
+JALV_END_DECLS
+
+#endif // JALV_OPTIONS_H
diff --git a/src/port.h b/src/port.h
new file mode 100644
index 0000000..5b3e0c9
--- /dev/null
+++ b/src/port.h
@@ -0,0 +1,35 @@
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#ifndef JALV_PORT_H
+#define JALV_PORT_H
+
+#include "attributes.h"
+#include "lv2_evbuf.h"
+
+#include "lilv/lilv.h"
+
+#include <stddef.h>
+#include <stdint.h>
+
+JALV_BEGIN_DECLS
+
+enum PortFlow { FLOW_UNKNOWN, FLOW_INPUT, FLOW_OUTPUT };
+
+enum PortType { TYPE_UNKNOWN, TYPE_CONTROL, TYPE_AUDIO, TYPE_EVENT, TYPE_CV };
+
+struct Port {
+ const LilvPort* lilv_port; ///< LV2 port
+ enum PortType type; ///< Data type
+ enum PortFlow flow; ///< Data flow direction
+ void* sys_port; ///< For audio/MIDI ports, otherwise NULL
+ LV2_Evbuf* evbuf; ///< For MIDI ports, otherwise NULL
+ void* widget; ///< Control widget, if applicable
+ size_t buf_size; ///< Custom buffer size, or 0
+ uint32_t index; ///< Port index
+ float control; ///< For control ports, otherwise 0.0f
+};
+
+JALV_END_DECLS
+
+#endif // JALV_PORT_H
diff --git a/src/portaudio.c b/src/portaudio.c
index 8079e92..f9283dd 100644
--- a/src/portaudio.c
+++ b/src/portaudio.c
@@ -1,27 +1,18 @@
-/*
- Copyright 2007-2022 David Robillard <d@drobilla.net>
-
- 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.
-*/
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#include "backend.h"
#include "jalv_internal.h"
+#include "port.h"
#include "worker.h"
#include <math.h>
#include <portaudio.h>
#include <stdio.h>
+#include <stdlib.h>
-struct JalvBackend {
+struct JalvBackendImpl {
PaStream* stream;
};
@@ -57,12 +48,8 @@ pa_process_cb(const void* inputs,
{sizeof(LV2_Atom_Object_Body), jalv->urids.atom_Object},
{0, jalv->urids.patch_Get}};
LV2_Evbuf_Iterator iter = lv2_evbuf_begin(port->evbuf);
- lv2_evbuf_write(&iter,
- 0,
- 0,
- get.atom.type,
- get.atom.size,
- (const uint8_t*)LV2_ATOM_BODY(&get));
+ lv2_evbuf_write(
+ &iter, 0, 0, get.atom.type, get.atom.size, LV2_ATOM_BODY(&get));
}
} else if (port->type == TYPE_EVENT) {
// Clear event output for plugin to write to
@@ -83,25 +70,17 @@ pa_process_cb(const void* inputs,
i = lv2_evbuf_next(i)) {
// Get event from LV2 buffer
uint32_t frames, subframes, type, size;
- uint8_t* body;
+ void* body;
lv2_evbuf_get(i, &frames, &subframes, &type, &size, &body);
if (jalv->has_ui) {
// Forward event to UI
- jalv_send_to_ui(jalv, p, type, size, body);
+ jalv_write_event(jalv, jalv->plugin_to_ui, p, size, type, body);
}
}
} else if (send_ui_updates && port->flow == FLOW_OUTPUT &&
port->type == TYPE_CONTROL) {
- char buf[sizeof(ControlChange) + sizeof(float)];
- ControlChange* ev = (ControlChange*)buf;
- ev->index = p;
- ev->protocol = 0;
- ev->size = sizeof(float);
- *(float*)(ev + 1) = port->control;
- if (zix_ring_write(jalv->plugin_events, buf, sizeof(buf)) < sizeof(buf)) {
- fprintf(stderr, "Plugin => UI buffer overflow!\n");
- }
+ jalv_write_control(jalv, jalv->plugin_to_ui, p, port->control);
}
}
@@ -111,7 +90,7 @@ pa_process_cb(const void* inputs,
static JalvBackend*
pa_error(const char* msg, PaError err)
{
- fprintf(stderr, "error: %s (%s)\n", msg, Pa_GetErrorText(err));
+ jalv_log(JALV_LOG_ERR, "%s (%s)\n", msg, Pa_GetErrorText(err));
Pa_Terminate();
return NULL;
}
@@ -198,8 +177,8 @@ jalv_backend_activate(Jalv* jalv)
{
const int st = Pa_StartStream(jalv->backend->stream);
if (st != paNoError) {
- fprintf(
- stderr, "error: Error starting audio stream (%s)\n", Pa_GetErrorText(st));
+ jalv_log(
+ JALV_LOG_ERR, "Error starting audio stream (%s)\n", Pa_GetErrorText(st));
}
}
@@ -208,8 +187,8 @@ jalv_backend_deactivate(Jalv* jalv)
{
const int st = Pa_CloseStream(jalv->backend->stream);
if (st != paNoError) {
- fprintf(
- stderr, "error: Error closing audio stream (%s)\n", Pa_GetErrorText(st));
+ jalv_log(
+ JALV_LOG_ERR, "Error closing audio stream (%s)\n", Pa_GetErrorText(st));
}
}
diff --git a/src/state.c b/src/state.c
index 696c28f..282b907 100644
--- a/src/state.c
+++ b/src/state.c
@@ -1,28 +1,16 @@
-/*
- Copyright 2007-2016 David Robillard <d@drobilla.net>
-
- 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.
-*/
+// Copyright 2007-2016 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#include "state.h"
#include "jalv_internal.h"
+#include "log.h"
+#include "port.h"
#include "lilv/lilv.h"
-#include "lv2/atom/forge.h"
#include "lv2/core/lv2.h"
#include "lv2/state/state.h"
-#include "lv2/urid/urid.h"
-#include "zix/common.h"
-#include "zix/ring.h"
+#include "zix/attributes.h"
#include "zix/sem.h"
#include <stdbool.h>
@@ -102,9 +90,9 @@ jalv_load_presets(Jalv* jalv, PresetSink sink, void* data)
sink(jalv, preset, label, data);
lilv_nodes_free(labels);
} else {
- fprintf(stderr,
- "Preset <%s> has no rdfs:label\n",
- lilv_node_as_string(lilv_nodes_get(presets, i)));
+ jalv_log(JALV_LOG_WARNING,
+ "Preset <%s> has no rdfs:label\n",
+ lilv_node_as_string(lilv_nodes_get(presets, i)));
}
}
lilv_nodes_free(presets);
@@ -136,7 +124,7 @@ set_port_value(const char* port_symbol,
Jalv* jalv = (Jalv*)user_data;
struct Port* port = jalv_port_by_symbol(jalv, port_symbol);
if (!port) {
- fprintf(stderr, "error: Preset port `%s' is missing\n", port_symbol);
+ jalv_log(JALV_LOG_ERR, "Preset port `%s' is missing\n", port_symbol);
return;
}
@@ -150,10 +138,10 @@ set_port_value(const char* port_symbol,
} else if (type == jalv->forge.Long) {
fvalue = *(const int64_t*)value;
} else {
- fprintf(stderr,
- "error: Preset `%s' value has bad type <%s>\n",
- port_symbol,
- jalv->unmap.unmap(jalv->unmap.handle, type));
+ jalv_log(JALV_LOG_ERR,
+ "Preset `%s' value has bad type <%s>\n",
+ port_symbol,
+ jalv->unmap.unmap(jalv->unmap.handle, type));
return;
}
@@ -161,19 +149,13 @@ set_port_value(const char* port_symbol,
// Set value on port struct directly
port->control = fvalue;
} else {
- // Send value to running plugin
- jalv_ui_write(jalv, port->index, sizeof(fvalue), 0, &fvalue);
+ // Send value to plugin (as if from UI)
+ jalv_write_control(jalv, jalv->ui_to_plugin, port->index, fvalue);
}
if (jalv->has_ui) {
- // Update UI
- char buf[sizeof(ControlChange) + sizeof(fvalue)];
- ControlChange* ev = (ControlChange*)buf;
- ev->index = port->index;
- ev->protocol = 0;
- ev->size = sizeof(fvalue);
- *(float*)(ev + 1) = fvalue;
- zix_ring_write(jalv->plugin_events, buf, sizeof(buf));
+ // Update UI (as if from plugin)
+ jalv_write_control(jalv, jalv->plugin_to_ui, port->index, fvalue);
}
}
diff --git a/src/state.h b/src/state.h
new file mode 100644
index 0000000..86defd7
--- /dev/null
+++ b/src/state.h
@@ -0,0 +1,64 @@
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#ifndef JALV_STATE_H
+#define JALV_STATE_H
+
+#include "attributes.h"
+#include "types.h"
+
+#include "lilv/lilv.h"
+#include "lv2/atom/atom.h"
+#include "lv2/state/state.h"
+#include "lv2/urid/urid.h"
+#include "serd/serd.h"
+
+JALV_BEGIN_DECLS
+
+// State and preset utilities
+
+typedef int (*PresetSink)(Jalv* jalv,
+ const LilvNode* node,
+ const LilvNode* title,
+ void* data);
+
+int
+jalv_load_presets(Jalv* jalv, PresetSink sink, void* data);
+
+int
+jalv_unload_presets(Jalv* jalv);
+
+int
+jalv_apply_preset(Jalv* jalv, const LilvNode* preset);
+
+int
+jalv_delete_current_preset(Jalv* jalv);
+
+int
+jalv_save_preset(Jalv* jalv,
+ const char* dir,
+ const char* uri,
+ const char* label,
+ const char* filename);
+
+void
+jalv_save(Jalv* jalv, const char* dir);
+
+void
+jalv_save_port_values(Jalv* jalv, SerdWriter* writer, const SerdNode* subject);
+
+char*
+jalv_make_path(LV2_State_Make_Path_Handle handle, const char* path);
+
+void
+jalv_apply_state(Jalv* jalv, LilvState* state);
+
+char*
+atom_to_turtle(LV2_URID_Unmap* unmap,
+ const SerdNode* subject,
+ const SerdNode* predicate,
+ const LV2_Atom* atom);
+
+JALV_END_DECLS
+
+#endif // JALV_STATE_H
diff --git a/src/symap.c b/src/symap.c
index 4a1a989..07002f2 100644
--- a/src/symap.c
+++ b/src/symap.c
@@ -1,18 +1,5 @@
-/*
- Copyright 2011-2022 David Robillard <d@drobilla.net>
-
- 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.
-*/
+// Copyright 2011-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
#include "symap.h"
@@ -38,47 +25,45 @@
*/
struct SymapImpl {
- /// Unsorted array of strings, so symbols[i] is the symbol for ID i
- char** symbols;
-
- /// Array of IDs, sorted by corresponding string in `symbols`
- uint32_t* index;
-
- /// Number of symbols (number of items in `symbols` and `index`)
- uint32_t size;
+ char** symbols; ///< String array where symbols[i] is the symbol for ID i
+ uint32_t* index; ///< ID array sorted by corresponding string in `symbols`
+ uint32_t size; ///< Number of symbols (length of both symbols and index)
+ uint32_t pad; ///< Unused padding
};
Symap*
symap_new(void)
{
- Symap* map = (Symap*)malloc(sizeof(Symap));
- map->symbols = NULL;
- map->index = NULL;
- map->size = 0;
+ Symap* const map = (Symap*)calloc(1, sizeof(Symap));
+
+ if (map) {
+ map->symbols = NULL;
+ map->index = NULL;
+ map->size = 0U;
+ }
+
return map;
}
void
-symap_free(Symap* map)
+symap_free(Symap* const map)
{
- if (!map) {
- return;
- }
+ if (map) {
+ for (uint32_t i = 0U; i < map->size; ++i) {
+ free(map->symbols[i]);
+ }
- for (uint32_t i = 0; i < map->size; ++i) {
- free(map->symbols[i]);
+ free(map->symbols);
+ free(map->index);
+ free(map);
}
-
- free(map->symbols);
- free(map->index);
- free(map);
}
static char*
-symap_strdup(const char* str)
+symap_strdup(const char* const str)
{
const size_t len = strlen(str);
- char* copy = (char*)malloc(len + 1);
+ char* const copy = (char*)malloc(len + 1);
memcpy(copy, str, len + 1);
return copy;
}
@@ -88,9 +73,10 @@ symap_strdup(const char* str)
or the index where a new entry for `sym` should be inserted.
*/
static uint32_t
-symap_search(const Symap* map, const char* sym, bool* exact)
+symap_search(const Symap* const map, const char* const sym, bool* const exact)
{
*exact = false;
+
if (map->size == 0) {
return 0; // Empty map, insert at 0
}
@@ -128,12 +114,11 @@ symap_search(const Symap* map, const char* sym, bool* exact)
}
uint32_t
-symap_try_map(Symap* map, const char* sym)
+symap_try_map(const Symap* const map, const char* const sym)
{
bool exact = false;
const uint32_t index = symap_search(map, sym, &exact);
if (exact) {
- assert(!strcmp(map->symbols[map->index[index]], sym));
return map->index[index];
}
@@ -141,8 +126,9 @@ symap_try_map(Symap* map, const char* sym)
}
uint32_t
-symap_map(Symap* map, const char* sym)
+symap_map(Symap* const map, const char* sym)
{
+ // Search for existing symbol
bool exact = false;
const uint32_t index = symap_search(map, sym, &exact);
if (exact) {
@@ -150,15 +136,31 @@ symap_map(Symap* map, const char* sym)
return map->index[index];
}
- const uint32_t id = ++map->size;
- char* const str = symap_strdup(sym);
+ // Claim a new highest ID
+ const uint32_t id = map->size + 1;
+
+ // Grow symbol array
+ char** new_symbols = (char**)realloc(map->symbols, id * sizeof(sym));
+ if (!new_symbols) {
+ return 0;
+ }
+
+ map->symbols = new_symbols;
+
+ // Grow index array
+ uint32_t* new_index = (uint32_t*)realloc(map->index, id * sizeof(index));
+ if (!new_index) {
+ return 0;
+ }
+
+ map->index = new_index;
// Append new symbol to symbols array
- map->symbols = (char**)realloc(map->symbols, map->size * sizeof(str));
- map->symbols[id - 1] = str;
+ map->size = id;
+ map->symbols[id - 1] = symap_strdup(sym);
// Insert new index element into sorted index
- map->index = (uint32_t*)realloc(map->index, map->size * sizeof(uint32_t));
+ map->index = new_index;
if (index < map->size - 1) {
memmove(map->index + index + 1,
map->index + index,
@@ -171,7 +173,7 @@ symap_map(Symap* map, const char* sym)
}
const char*
-symap_unmap(Symap* map, uint32_t id)
+symap_unmap(const Symap* const map, const uint32_t id)
{
if (id == 0) {
return NULL;
@@ -184,12 +186,12 @@ symap_unmap(Symap* map, uint32_t id)
return NULL;
}
-#ifdef STANDALONE
+#ifdef SYMAP_STANDALONE
# include <stdio.h>
static void
-symap_dump(Symap* map)
+symap_dump(Symap* const map)
{
fprintf(stderr, "{\n");
for (uint32_t i = 0; i < map->size; ++i) {
@@ -199,35 +201,48 @@ symap_dump(Symap* map)
fprintf(stderr, "}\n");
}
-int
-main()
+static int
+symap_test(Symap* const map)
{
# define N_SYMS 5
- char* syms[N_SYMS] = {"hello", "bonjour", "goodbye", "aloha", "salut"};
- Symap* map = symap_new();
+ static const char* const syms[N_SYMS] = {
+ "hello", "bonjour", "goodbye", "aloha", "salut"};
+
for (int i = 0; i < N_SYMS; ++i) {
if (symap_try_map(map, syms[i])) {
- fprintf(stderr, "error: Symbol already mapped\n");
- return 1;
+ return fprintf(stderr, "error: Symbol already mapped\n");
}
const uint32_t id = symap_map(map, syms[i]);
- if (strcmp(map->symbols[id - 1], syms[i])) {
- fprintf(stderr, "error: Corrupt symbol table\n");
- return 1;
+ if (!id) {
+ return fprintf(stderr, "error: Failed to insert ID\n");
+ }
+
+ if (!!strcmp(map->symbols[id - 1], syms[i])) {
+ return fprintf(stderr, "error: Corrupt symbol table\n");
}
if (symap_map(map, syms[i]) != id) {
- fprintf(stderr, "error: Remapped symbol to a different ID\n");
- return 1;
+ return fprintf(stderr, "error: Remapped symbol to a different ID\n");
}
symap_dump(map);
}
- symap_free(map);
return 0;
+
+# undef N_SYMS
+}
+
+int
+main(void)
+{
+ Symap* const map = symap_new();
+ const int st = symap_test(map);
+
+ symap_free(map);
+ return st;
}
-#endif // STANDALONE
+#endif // SYMAP_STANDALONE
diff --git a/src/symap.h b/src/symap.h
index 7b74d9f..74dc59a 100644
--- a/src/symap.h
+++ b/src/symap.h
@@ -1,18 +1,5 @@
-/*
- Copyright 2011-2022 David Robillard <d@drobilla.net>
-
- 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.
-*/
+// Copyright 2011-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
/**
@file symap.h API for Symap, a basic symbol map (string interner).
@@ -25,11 +12,14 @@
#ifndef SYMAP_H
#define SYMAP_H
+#include "zix/attributes.h"
+
#include <stdint.h>
typedef struct SymapImpl Symap;
/// Create a new symbol map
+ZIX_MALLOC_FUNC
Symap*
symap_new(void);
@@ -37,24 +27,18 @@ symap_new(void);
void
symap_free(Symap* map);
-/// Map a string to a symbol ID if it is already mapped, otherwise return 0
+/// Map a string to a symbol if it is already mapped, otherwise return 0
+ZIX_PURE_FUNC
uint32_t
-symap_try_map(Symap* map, const char* sym);
-
-/**
- Map a string to a symbol ID.
+symap_try_map(const Symap* map, const char* sym);
- Note that 0 is never a valid symbol ID.
-*/
+/// Map a string to a symbol
uint32_t
symap_map(Symap* map, const char* sym);
-/**
- Unmap a symbol ID back to a symbol, or NULL if no such ID exists.
-
- Note that 0 is never a valid symbol ID.
-*/
+/// Unmap a symbol back to a string if possible, otherwise return NULL
+ZIX_PURE_FUNC
const char*
-symap_unmap(Symap* map, uint32_t id);
+symap_unmap(const Symap* map, uint32_t id);
#endif // SYMAP_H
diff --git a/src/types.h b/src/types.h
new file mode 100644
index 0000000..ed577f6
--- /dev/null
+++ b/src/types.h
@@ -0,0 +1,22 @@
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#ifndef JALV_TYPES_H
+#define JALV_TYPES_H
+
+#include "attributes.h"
+
+JALV_BEGIN_DECLS
+
+/// Backend playing state
+typedef enum { JALV_RUNNING, JALV_PAUSE_REQUESTED, JALV_PAUSED } JalvPlayState;
+
+/// "Global" application state
+typedef struct JalvImpl Jalv;
+
+/// Audio/MIDI backend
+typedef struct JalvBackendImpl JalvBackend;
+
+JALV_END_DECLS
+
+#endif // JALV_TYPES_H
diff --git a/src/urids.h b/src/urids.h
new file mode 100644
index 0000000..4dcbe20
--- /dev/null
+++ b/src/urids.h
@@ -0,0 +1,48 @@
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#ifndef JALV_URIDS_H
+#define JALV_URIDS_H
+
+#include "attributes.h"
+
+#include "lv2/urid/urid.h"
+
+JALV_BEGIN_DECLS
+
+typedef struct {
+ LV2_URID atom_Float;
+ LV2_URID atom_Int;
+ LV2_URID atom_Object;
+ LV2_URID atom_Path;
+ LV2_URID atom_String;
+ LV2_URID atom_eventTransfer;
+ LV2_URID bufsz_maxBlockLength;
+ LV2_URID bufsz_minBlockLength;
+ LV2_URID bufsz_sequenceSize;
+ LV2_URID log_Error;
+ LV2_URID log_Trace;
+ LV2_URID log_Warning;
+ LV2_URID midi_MidiEvent;
+ LV2_URID param_sampleRate;
+ LV2_URID patch_Get;
+ LV2_URID patch_Put;
+ LV2_URID patch_Set;
+ LV2_URID patch_body;
+ LV2_URID patch_property;
+ LV2_URID patch_value;
+ LV2_URID time_Position;
+ LV2_URID time_bar;
+ LV2_URID time_barBeat;
+ LV2_URID time_beatUnit;
+ LV2_URID time_beatsPerBar;
+ LV2_URID time_beatsPerMinute;
+ LV2_URID time_frame;
+ LV2_URID time_speed;
+ LV2_URID ui_scaleFactor;
+ LV2_URID ui_updateRate;
+} JalvURIDs;
+
+JALV_END_DECLS
+
+#endif // JALV_URIDS_H
diff --git a/src/worker.c b/src/worker.c
index 476c11f..0dca657 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -1,156 +1,226 @@
-/*
- Copyright 2007-2016 David Robillard <d@drobilla.net>
-
- 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.
-*/
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
#include "worker.h"
+#include "lv2/core/lv2.h"
#include "lv2/worker/worker.h"
-#include "zix/common.h"
#include "zix/ring.h"
#include "zix/sem.h"
+#include "zix/status.h"
#include "zix/thread.h"
#include <stdio.h>
#include <stdlib.h>
+#define MAX_PACKET_SIZE 4096U
+
+struct JalvWorkerImpl {
+ ZixRing* requests; ///< Requests to the worker
+ ZixRing* responses; ///< Responses from the worker
+ void* response; ///< Worker response buffer
+ ZixSem* lock; ///< Lock for plugin work() method
+ bool exit; ///< Exit flag
+ ZixSem sem; ///< Worker semaphore
+ ZixThread thread; ///< Worker thread
+ LV2_Handle handle; ///< Plugin handle
+ const LV2_Worker_Interface* iface; ///< Plugin worker interface
+ bool threaded; ///< Run work in another thread
+};
+
+static LV2_Worker_Status
+jalv_worker_write_packet(ZixRing* const target,
+ const uint32_t size,
+ const void* const data)
+{
+ ZixRingTransaction tx = zix_ring_begin_write(target);
+ if (zix_ring_amend_write(target, &tx, &size, sizeof(size)) ||
+ zix_ring_amend_write(target, &tx, data, size)) {
+ return LV2_WORKER_ERR_NO_SPACE;
+ }
+
+ zix_ring_commit_write(target, &tx);
+ return LV2_WORKER_SUCCESS;
+}
+
static LV2_Worker_Status
jalv_worker_respond(LV2_Worker_Respond_Handle handle,
- uint32_t size,
+ const uint32_t size,
const void* data)
{
- JalvWorker* worker = (JalvWorker*)handle;
- zix_ring_write(worker->responses, (const char*)&size, sizeof(size));
- zix_ring_write(worker->responses, (const char*)data, size);
- return LV2_WORKER_SUCCESS;
+ return jalv_worker_write_packet(((JalvWorker*)handle)->responses, size, data);
}
static void*
-worker_func(void* data)
+worker_func(void* const data)
{
- JalvWorker* worker = (JalvWorker*)data;
- Jalv* jalv = worker->jalv;
- void* buf = NULL;
+ JalvWorker* const worker = (JalvWorker*)data;
+ void* buf = NULL;
+
while (true) {
+ // Wait for a request
zix_sem_wait(&worker->sem);
- if (jalv->exit) {
+ if (worker->exit) {
break;
}
+ // Read the size header of the request
uint32_t size = 0;
- zix_ring_read(worker->requests, (char*)&size, sizeof(size));
-
- if (!(buf = realloc(buf, size))) {
- fprintf(stderr, "error: realloc() failed\n");
- free(buf);
- return NULL;
+ zix_ring_read(worker->requests, &size, sizeof(size));
+
+ // Reallocate buffer to accommodate request if necessary
+ void* const new_buf = realloc(buf, size);
+ if (new_buf) {
+ // Read request into buffer
+ buf = new_buf;
+ zix_ring_read(worker->requests, buf, size);
+
+ // Lock and dispatch request to plugin's work handler
+ zix_sem_wait(worker->lock);
+ worker->iface->work(
+ worker->handle, jalv_worker_respond, worker, size, buf);
+ zix_sem_post(worker->lock);
+
+ } else {
+ // Reallocation failed, skip request to avoid corrupting ring
+ zix_ring_skip(worker->requests, size);
}
+ }
+
+ free(buf);
+ return NULL;
+}
- zix_ring_read(worker->requests, (char*)buf, size);
+static ZixStatus
+jalv_worker_launch(JalvWorker* const worker)
+{
+ ZixStatus st = ZIX_STATUS_SUCCESS;
- zix_sem_wait(&jalv->work_lock);
- worker->iface->work(
- jalv->instance->lv2_handle, jalv_worker_respond, worker, size, buf);
- zix_sem_post(&jalv->work_lock);
+ if ((st = zix_sem_init(&worker->sem, 0)) ||
+ (st = zix_thread_create(&worker->thread, 4096U, worker_func, worker))) {
+ return st;
}
- free(buf);
+ ZixRing* const requests = zix_ring_new(NULL, MAX_PACKET_SIZE);
+ if (!requests) {
+ zix_thread_join(worker->thread);
+ zix_sem_destroy(&worker->sem);
+ return ZIX_STATUS_NO_MEM;
+ }
+
+ zix_ring_mlock(requests);
+ worker->requests = requests;
+ return ZIX_STATUS_SUCCESS;
+}
+
+JalvWorker*
+jalv_worker_new(ZixSem* const lock, const bool threaded)
+{
+ JalvWorker* const worker = (JalvWorker*)calloc(1, sizeof(JalvWorker));
+ ZixRing* const responses = zix_ring_new(NULL, MAX_PACKET_SIZE);
+ void* const response = calloc(1, MAX_PACKET_SIZE);
+
+ if (worker && responses && response) {
+ worker->threaded = threaded;
+ worker->responses = responses;
+ worker->response = response;
+ worker->lock = lock;
+ worker->exit = false;
+
+ zix_ring_mlock(responses);
+ if (!threaded || !jalv_worker_launch(worker)) {
+ return worker;
+ }
+ }
+
+ free(worker);
+ zix_ring_free(responses);
+ free(response);
return NULL;
}
void
-jalv_worker_init(Jalv* ZIX_UNUSED(jalv),
- JalvWorker* worker,
- const LV2_Worker_Interface* iface,
- bool threaded)
+jalv_worker_start(JalvWorker* const worker,
+ const LV2_Worker_Interface* const iface,
+ LV2_Handle handle)
{
- worker->iface = iface;
- worker->threaded = threaded;
- if (threaded) {
- zix_thread_create(&worker->thread, 4096, worker_func, worker);
- worker->requests = zix_ring_new(4096);
- zix_ring_mlock(worker->requests);
+ if (worker) {
+ worker->iface = iface;
+ worker->handle = handle;
}
- worker->responses = zix_ring_new(4096);
- worker->response = malloc(4096);
- zix_ring_mlock(worker->responses);
}
void
-jalv_worker_finish(JalvWorker* worker)
+jalv_worker_exit(JalvWorker* const worker)
{
- if (worker->threaded) {
+ if (worker && worker->threaded) {
+ worker->exit = true;
zix_sem_post(&worker->sem);
- zix_thread_join(worker->thread, NULL);
+ zix_thread_join(worker->thread);
+ worker->threaded = false;
}
}
void
-jalv_worker_destroy(JalvWorker* worker)
+jalv_worker_free(JalvWorker* const worker)
{
- if (worker->requests) {
- if (worker->threaded) {
- zix_ring_free(worker->requests);
- }
+ if (worker) {
+ jalv_worker_exit(worker);
+ zix_ring_free(worker->requests);
zix_ring_free(worker->responses);
free(worker->response);
+ free(worker);
}
}
LV2_Worker_Status
jalv_worker_schedule(LV2_Worker_Schedule_Handle handle,
- uint32_t size,
- const void* data)
+ const uint32_t size,
+ const void* const data)
{
- JalvWorker* worker = (JalvWorker*)handle;
- Jalv* jalv = worker->jalv;
+ JalvWorker* const worker = (JalvWorker*)handle;
+ LV2_Worker_Status st = LV2_WORKER_SUCCESS;
- if (!size) {
+ if (!worker || !size) {
return LV2_WORKER_ERR_UNKNOWN;
}
if (worker->threaded) {
// Schedule a request to be executed by the worker thread
- zix_ring_write(worker->requests, (const char*)&size, sizeof(size));
- zix_ring_write(worker->requests, (const char*)data, size);
- zix_sem_post(&worker->sem);
+ if (!(st = jalv_worker_write_packet(worker->requests, size, data))) {
+ zix_sem_post(&worker->sem);
+ }
+
} else {
// Execute work immediately in this thread
- zix_sem_wait(&jalv->work_lock);
- worker->iface->work(
- jalv->instance->lv2_handle, jalv_worker_respond, worker, size, data);
- zix_sem_post(&jalv->work_lock);
+ zix_sem_wait(worker->lock);
+ st = worker->iface->work(
+ worker->handle, jalv_worker_respond, worker, size, data);
+ zix_sem_post(worker->lock);
}
- return LV2_WORKER_SUCCESS;
+ return st;
}
void
-jalv_worker_emit_responses(JalvWorker* worker, LilvInstance* instance)
+jalv_worker_emit_responses(JalvWorker* const worker, LV2_Handle lv2_handle)
{
- if (worker->responses) {
- uint32_t read_space = zix_ring_read_space(worker->responses);
- while (read_space) {
- uint32_t size = 0;
- zix_ring_read(worker->responses, (char*)&size, sizeof(size));
-
- zix_ring_read(worker->responses, (char*)worker->response, size);
-
- worker->iface->work_response(
- instance->lv2_handle, size, worker->response);
-
- read_space -= sizeof(size) + size;
+ static const uint32_t size_size = (uint32_t)sizeof(uint32_t);
+
+ if (worker && worker->responses) {
+ uint32_t size = 0U;
+ while (zix_ring_read(worker->responses, &size, size_size) == size_size) {
+ if (zix_ring_read(worker->responses, worker->response, size) == size) {
+ worker->iface->work_response(lv2_handle, size, worker->response);
+ }
}
}
}
+
+void
+jalv_worker_end_run(JalvWorker* const worker)
+{
+ if (worker && worker->iface && worker->iface->end_run) {
+ worker->iface->end_run(worker->handle);
+ }
+}
diff --git a/src/worker.h b/src/worker.h
index 0e0b69b..09d35ca 100644
--- a/src/worker.h
+++ b/src/worker.h
@@ -1,43 +1,100 @@
-/*
- Copyright 2007-2016 David Robillard <d@drobilla.net>
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
- 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.
+#ifndef JALV_WORKER_H
+#define JALV_WORKER_H
- 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 "attributes.h"
-#include "jalv_internal.h"
+#include "zix/sem.h"
-#include "lilv/lilv.h"
+#include "lv2/core/lv2.h"
#include "lv2/worker/worker.h"
#include <stdbool.h>
#include <stdint.h>
+JALV_BEGIN_DECLS
+
+/**
+ A worker for running non-realtime tasks for plugins.
+
+ The worker can be used in threaded mode, which allows non-realtime work to be
+ done with latency when running realtime, or non-threaded mode, which performs
+ work immediately for state restoration or offline rendering.
+*/
+typedef struct JalvWorkerImpl JalvWorker;
+
+/**
+ Allocate a new worker and launch its thread if necessary.
+
+ @param lock Pointer to lock used to guard doing work.
+ @param threaded If true, launch a thread to perform work in.
+ @return A newly allocated worker, or null on error.
+*/
+JalvWorker*
+jalv_worker_new(ZixSem* lock, bool threaded);
+
+/**
+ Start performing work for a plugin, launching the thread if necessary.
+
+ This must be called before scheduling any work.
+
+ @param iface Worker interface from plugin.
+ @param handle Handle to the LV2 plugin this worker is for.
+*/
void
-jalv_worker_init(Jalv* jalv,
- JalvWorker* worker,
- const LV2_Worker_Interface* iface,
- bool threaded);
+jalv_worker_start(JalvWorker* worker,
+ const LV2_Worker_Interface* iface,
+ LV2_Handle handle);
+
+/**
+ Terminate the worker's thread if necessary.
+ For threaded workers, this blocks until the thread has exited. For
+ non-threaded workers, this does nothing.
+*/
void
-jalv_worker_finish(JalvWorker* worker);
+jalv_worker_exit(JalvWorker* worker);
+/**
+ Free a worker allocated with jalv_worker_new().
+
+ Calls jalv_worker_exit() to terminate the running thread if necessary.
+*/
void
-jalv_worker_destroy(JalvWorker* worker);
+jalv_worker_free(JalvWorker* worker);
+
+/**
+ Schedule work to be performed by the worker in the audio thread.
+ For threaded workers, this enqueues a request that will be handled by the
+ worker thread asynchronously. For non-threaded workers, the work is
+ performed immediately before returning.
+*/
LV2_Worker_Status
jalv_worker_schedule(LV2_Worker_Schedule_Handle handle,
uint32_t size,
const void* data);
+/**
+ Emit any pending responses to the plugin in the audio thread.
+
+ This dispatches responses from work that has been completed since the last
+ call, so the plugin knows it is finished and can apply the changes.
+*/
+void
+jalv_worker_emit_responses(JalvWorker* worker, LV2_Handle lv2_handle);
+
+/**
+ Notify the plugin that the run() cycle is finished.
+
+ This must be called near the end of every cycle, after any potential calls
+ to jalv_worker_emit_responses().
+*/
void
-jalv_worker_emit_responses(JalvWorker* worker, LilvInstance* instance);
+jalv_worker_end_run(JalvWorker* worker);
+
+JALV_END_DECLS
+
+#endif // JALV_WORKER_H
diff --git a/src/zix/common.h b/src/zix/common.h
deleted file mode 100644
index d47586c..0000000
--- a/src/zix/common.h
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- Copyright 2016-2020 David Robillard <d@drobilla.net>
-
- 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.
-*/
-
-#ifndef ZIX_COMMON_H
-#define ZIX_COMMON_H
-
-#include <stdbool.h>
-
-/**
- @addtogroup zix
- @{
-*/
-
-/** @cond */
-#if defined(_WIN32) && !defined(ZIX_STATIC) && defined(ZIX_INTERNAL)
-# define ZIX_API __declspec(dllexport)
-#elif defined(_WIN32) && !defined(ZIX_STATIC)
-# define ZIX_API __declspec(dllimport)
-#elif defined(__GNUC__)
-# define ZIX_API __attribute__((visibility("default")))
-#else
-# define ZIX_API
-#endif
-
-#ifdef __GNUC__
-# define ZIX_PURE_FUNC __attribute__((pure))
-# define ZIX_CONST_FUNC __attribute__((const))
-# define ZIX_MALLOC_FUNC __attribute__((malloc))
-#else
-# define ZIX_PURE_FUNC
-# define ZIX_CONST_FUNC
-# define ZIX_MALLOC_FUNC
-#endif
-
-#define ZIX_PURE_API \
- ZIX_API \
- ZIX_PURE_FUNC
-
-#define ZIX_CONST_API \
- ZIX_API \
- ZIX_CONST_FUNC
-
-#define ZIX_MALLOC_API \
- ZIX_API \
- ZIX_MALLOC_FUNC
-
-/** @endcond */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifdef __GNUC__
-# define ZIX_LOG_FUNC(fmt, arg1) __attribute__((format(printf, fmt, arg1)))
-#else
-# define ZIX_LOG_FUNC(fmt, arg1)
-#endif
-
-// Unused parameter macro to suppresses warnings and make it impossible to use
-#if defined(__cplusplus)
-# define ZIX_UNUSED(name)
-#elif defined(__GNUC__)
-# define ZIX_UNUSED(name) name##_unused __attribute__((__unused__))
-#else
-# define ZIX_UNUSED(name) name
-#endif
-
-typedef enum {
- ZIX_STATUS_SUCCESS,
- ZIX_STATUS_ERROR,
- ZIX_STATUS_NO_MEM,
- ZIX_STATUS_NOT_FOUND,
- ZIX_STATUS_EXISTS,
- ZIX_STATUS_BAD_ARG,
- ZIX_STATUS_BAD_PERMS
-} ZixStatus;
-
-static inline const char*
-zix_strerror(const ZixStatus status)
-{
- switch (status) {
- case ZIX_STATUS_SUCCESS:
- return "Success";
- case ZIX_STATUS_ERROR:
- return "Unknown error";
- case ZIX_STATUS_NO_MEM:
- return "Out of memory";
- case ZIX_STATUS_NOT_FOUND:
- return "Not found";
- case ZIX_STATUS_EXISTS:
- return "Exists";
- case ZIX_STATUS_BAD_ARG:
- return "Bad argument";
- case ZIX_STATUS_BAD_PERMS:
- return "Bad permissions";
- }
- return "Unknown error";
-}
-
-/**
- Function for comparing two elements.
-*/
-typedef int (*ZixComparator)(const void* a,
- const void* b,
- const void* user_data);
-
-/**
- Function for testing equality of two elements.
-*/
-typedef bool (*ZixEqualFunc)(const void* a, const void* b);
-
-/**
- Function to destroy an element.
-*/
-typedef void (*ZixDestroyFunc)(void* ptr);
-
-/**
- @}
-*/
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif /* ZIX_COMMON_H */
diff --git a/src/zix/ring.c b/src/zix/ring.c
deleted file mode 100644
index 4a4692f..0000000
--- a/src/zix/ring.c
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- Copyright 2011-2020 David Robillard <d@drobilla.net>
-
- 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 "zix/ring.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-#ifdef HAVE_MLOCK
-# include <sys/mman.h>
-# define ZIX_MLOCK(ptr, size) mlock((ptr), (size))
-#elif defined(_WIN32)
-# include <windows.h>
-# define ZIX_MLOCK(ptr, size) VirtualLock((ptr), (size))
-#else
-# pragma message("warning: No memory locking, possible RT violations")
-# define ZIX_MLOCK(ptr, size)
-#endif
-
-#if defined(_MSC_VER)
-# include <windows.h>
-# define ZIX_READ_BARRIER() MemoryBarrier()
-# define ZIX_WRITE_BARRIER() MemoryBarrier()
-#elif defined(__GNUC__)
-# define ZIX_READ_BARRIER() __atomic_thread_fence(__ATOMIC_ACQUIRE)
-# define ZIX_WRITE_BARRIER() __atomic_thread_fence(__ATOMIC_RELEASE)
-#else
-# pragma message("warning: No memory barriers, possible SMP bugs")
-# define ZIX_READ_BARRIER()
-# define ZIX_WRITE_BARRIER()
-#endif
-
-struct ZixRingImpl {
- uint32_t write_head; ///< Read index into buf
- uint32_t read_head; ///< Write index into buf
- uint32_t size; ///< Size (capacity) in bytes
- uint32_t size_mask; ///< Mask for fast modulo
- char* buf; ///< Contents
-};
-
-static inline uint32_t
-next_power_of_two(uint32_t size)
-{
- // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
- size--;
- size |= size >> 1u;
- size |= size >> 2u;
- size |= size >> 4u;
- size |= size >> 8u;
- size |= size >> 16u;
- size++;
- return size;
-}
-
-ZixRing*
-zix_ring_new(uint32_t size)
-{
- ZixRing* ring = (ZixRing*)malloc(sizeof(ZixRing));
- ring->write_head = 0;
- ring->read_head = 0;
- ring->size = next_power_of_two(size);
- ring->size_mask = ring->size - 1;
- ring->buf = (char*)malloc(ring->size);
- return ring;
-}
-
-void
-zix_ring_free(ZixRing* ring)
-{
- if (ring) {
- free(ring->buf);
- free(ring);
- }
-}
-
-void
-zix_ring_mlock(ZixRing* ring)
-{
- ZIX_MLOCK(ring, sizeof(ZixRing));
- ZIX_MLOCK(ring->buf, ring->size);
-}
-
-void
-zix_ring_reset(ZixRing* ring)
-{
- ring->write_head = 0;
- ring->read_head = 0;
-}
-
-static inline uint32_t
-read_space_internal(const ZixRing* ring, uint32_t r, uint32_t w)
-{
- if (r < w) {
- return w - r;
- }
-
- return (w - r + ring->size) & ring->size_mask;
-}
-
-uint32_t
-zix_ring_read_space(const ZixRing* ring)
-{
- return read_space_internal(ring, ring->read_head, ring->write_head);
-}
-
-static inline uint32_t
-write_space_internal(const ZixRing* ring, uint32_t r, uint32_t w)
-{
- if (r == w) {
- return ring->size - 1;
- }
-
- if (r < w) {
- return ((r - w + ring->size) & ring->size_mask) - 1;
- }
-
- return (r - w) - 1;
-}
-
-uint32_t
-zix_ring_write_space(const ZixRing* ring)
-{
- return write_space_internal(ring, ring->read_head, ring->write_head);
-}
-
-uint32_t
-zix_ring_capacity(const ZixRing* ring)
-{
- return ring->size - 1;
-}
-
-static inline uint32_t
-peek_internal(const ZixRing* ring,
- uint32_t r,
- uint32_t w,
- uint32_t size,
- void* dst)
-{
- if (read_space_internal(ring, r, w) < size) {
- return 0;
- }
-
- if (r + size < ring->size) {
- memcpy(dst, &ring->buf[r], size);
- } else {
- const uint32_t first_size = ring->size - r;
- memcpy(dst, &ring->buf[r], first_size);
- memcpy((char*)dst + first_size, &ring->buf[0], size - first_size);
- }
-
- return size;
-}
-
-uint32_t
-zix_ring_peek(ZixRing* ring, void* dst, uint32_t size)
-{
- return peek_internal(ring, ring->read_head, ring->write_head, size, dst);
-}
-
-uint32_t
-zix_ring_read(ZixRing* ring, void* dst, uint32_t size)
-{
- const uint32_t r = ring->read_head;
- const uint32_t w = ring->write_head;
-
- if (peek_internal(ring, r, w, size, dst)) {
- ZIX_READ_BARRIER();
- ring->read_head = (r + size) & ring->size_mask;
- return size;
- }
-
- return 0;
-}
-
-uint32_t
-zix_ring_skip(ZixRing* ring, uint32_t size)
-{
- const uint32_t r = ring->read_head;
- const uint32_t w = ring->write_head;
- if (read_space_internal(ring, r, w) < size) {
- return 0;
- }
-
- ZIX_READ_BARRIER();
- ring->read_head = (r + size) & ring->size_mask;
- return size;
-}
-
-uint32_t
-zix_ring_write(ZixRing* ring, const void* src, uint32_t size)
-{
- const uint32_t r = ring->read_head;
- const uint32_t w = ring->write_head;
- if (write_space_internal(ring, r, w) < size) {
- return 0;
- }
-
- if (w + size <= ring->size) {
- memcpy(&ring->buf[w], src, size);
- ZIX_WRITE_BARRIER();
- ring->write_head = (w + size) & ring->size_mask;
- } else {
- const uint32_t this_size = ring->size - w;
- memcpy(&ring->buf[w], src, this_size);
- memcpy(&ring->buf[0], (const char*)src + this_size, size - this_size);
- ZIX_WRITE_BARRIER();
- ring->write_head = size - this_size;
- }
-
- return size;
-}
diff --git a/src/zix/ring.h b/src/zix/ring.h
deleted file mode 100644
index a375cac..0000000
--- a/src/zix/ring.h
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- Copyright 2011-2020 David Robillard <d@drobilla.net>
-
- 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.
-*/
-
-#ifndef ZIX_RING_H
-#define ZIX_RING_H
-
-#include "zix/common.h"
-
-#include <stdint.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- @addtogroup zix
- @{
- @name Ring
- @{
-*/
-
-/**
- A lock-free ring buffer.
-
- Thread-safe with a single reader and single writer, and realtime safe
- on both ends.
-*/
-typedef struct ZixRingImpl ZixRing;
-
-/**
- Create a new ring.
- @param size Size in bytes (note this may be rounded up).
-
- At most `size` - 1 bytes may be stored in the ring at once.
-*/
-ZIX_MALLOC_API
-ZixRing*
-zix_ring_new(uint32_t size);
-
-/**
- Destroy a ring.
-*/
-ZIX_API
-void
-zix_ring_free(ZixRing* ring);
-
-/**
- Lock the ring data into physical memory.
-
- This function is NOT thread safe or real-time safe, but it should be called
- after zix_ring_new() to lock all ring memory to avoid page faults while
- using the ring (i.e. this function MUST be called first in order for the
- ring to be truly real-time safe).
-
-*/
-ZIX_API
-void
-zix_ring_mlock(ZixRing* ring);
-
-/**
- Reset (empty) a ring.
-
- This function is NOT thread-safe, it may only be called when there are no
- readers or writers.
-*/
-ZIX_API
-void
-zix_ring_reset(ZixRing* ring);
-
-/**
- Return the number of bytes of space available for reading.
-*/
-ZIX_CONST_API
-uint32_t
-zix_ring_read_space(const ZixRing* ring);
-
-/**
- Return the number of bytes of space available for writing.
-*/
-ZIX_CONST_API
-uint32_t
-zix_ring_write_space(const ZixRing* ring);
-
-/**
- Return the capacity (i.e. total write space when empty).
-*/
-ZIX_CONST_API
-uint32_t
-zix_ring_capacity(const ZixRing* ring);
-
-/**
- Read from the ring without advancing the read head.
-*/
-ZIX_API
-uint32_t
-zix_ring_peek(ZixRing* ring, void* dst, uint32_t size);
-
-/**
- Read from the ring and advance the read head.
-*/
-ZIX_API
-uint32_t
-zix_ring_read(ZixRing* ring, void* dst, uint32_t size);
-
-/**
- Skip data in the ring (advance read head without reading).
-*/
-ZIX_API
-uint32_t
-zix_ring_skip(ZixRing* ring, uint32_t size);
-
-/**
- Write data to the ring.
-*/
-ZIX_API
-uint32_t
-zix_ring_write(ZixRing* ring, const void* src, uint32_t size);
-
-/**
- @}
- @}
-*/
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif /* ZIX_RING_H */
diff --git a/src/zix/sem.h b/src/zix/sem.h
deleted file mode 100644
index d42fd08..0000000
--- a/src/zix/sem.h
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- Copyright 2012-2020 David Robillard <d@drobilla.net>
-
- 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.
-*/
-
-#ifndef ZIX_SEM_H
-#define ZIX_SEM_H
-
-#include "zix/common.h"
-
-#ifdef __APPLE__
-# include <mach/mach.h>
-#elif defined(_WIN32)
-# include <limits.h>
-# include <windows.h>
-#else
-# include <errno.h>
-# include <semaphore.h>
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stdbool.h>
-
-/**
- @addtogroup zix
- @{
- @name Semaphore
- @{
-*/
-
-struct ZixSemImpl;
-
-/**
- A counting semaphore.
-
- This is an integer that is always positive, and has two main operations:
- increment (post) and decrement (wait). If a decrement can not be performed
- (i.e. the value is 0) the caller will be blocked until another thread posts
- and the operation can succeed.
-
- Semaphores can be created with any starting value, but typically this will
- be 0 so the semaphore can be used as a simple signal where each post
- corresponds to one wait.
-
- Semaphores are very efficient (much moreso than a mutex/cond pair). In
- particular, at least on Linux, post is async-signal-safe, which means it
- does not block and will not be interrupted. If you need to signal from
- a realtime thread, this is the most appropriate primitive to use.
-*/
-typedef struct ZixSemImpl ZixSem;
-
-/**
- Create and initialize `sem` to `initial`.
-*/
-static inline ZixStatus
-zix_sem_init(ZixSem* sem, unsigned initial);
-
-/**
- Destroy `sem`.
-*/
-static inline void
-zix_sem_destroy(ZixSem* sem);
-
-/**
- Increment (and signal any waiters).
- Realtime safe.
-*/
-static inline void
-zix_sem_post(ZixSem* sem);
-
-/**
- Wait until count is > 0, then decrement.
- Obviously not realtime safe.
-*/
-static inline ZixStatus
-zix_sem_wait(ZixSem* sem);
-
-/**
- Non-blocking version of wait().
-
- @return true if decrement was successful (lock was acquired).
-*/
-static inline bool
-zix_sem_try_wait(ZixSem* sem);
-
-/**
- @cond
-*/
-
-#ifdef __APPLE__
-
-struct ZixSemImpl {
- semaphore_t sem;
-};
-
-static inline ZixStatus
-zix_sem_init(ZixSem* sem, unsigned val)
-{
- return semaphore_create(mach_task_self(), &sem->sem, SYNC_POLICY_FIFO, val)
- ? ZIX_STATUS_ERROR
- : ZIX_STATUS_SUCCESS;
-}
-
-static inline void
-zix_sem_destroy(ZixSem* sem)
-{
- semaphore_destroy(mach_task_self(), sem->sem);
-}
-
-static inline void
-zix_sem_post(ZixSem* sem)
-{
- semaphore_signal(sem->sem);
-}
-
-static inline ZixStatus
-zix_sem_wait(ZixSem* sem)
-{
- if (semaphore_wait(sem->sem) != KERN_SUCCESS) {
- return ZIX_STATUS_ERROR;
- }
- return ZIX_STATUS_SUCCESS;
-}
-
-static inline bool
-zix_sem_try_wait(ZixSem* sem)
-{
- const mach_timespec_t zero = {0, 0};
- return semaphore_timedwait(sem->sem, zero) == KERN_SUCCESS;
-}
-
-#elif defined(_WIN32)
-
-struct ZixSemImpl {
- HANDLE sem;
-};
-
-static inline ZixStatus
-zix_sem_init(ZixSem* sem, unsigned initial)
-{
- sem->sem = CreateSemaphore(NULL, initial, LONG_MAX, NULL);
- return (sem->sem) ? ZIX_STATUS_SUCCESS : ZIX_STATUS_ERROR;
-}
-
-static inline void
-zix_sem_destroy(ZixSem* sem)
-{
- CloseHandle(sem->sem);
-}
-
-static inline void
-zix_sem_post(ZixSem* sem)
-{
- ReleaseSemaphore(sem->sem, 1, NULL);
-}
-
-static inline ZixStatus
-zix_sem_wait(ZixSem* sem)
-{
- if (WaitForSingleObject(sem->sem, INFINITE) != WAIT_OBJECT_0) {
- return ZIX_STATUS_ERROR;
- }
- return ZIX_STATUS_SUCCESS;
-}
-
-static inline bool
-zix_sem_try_wait(ZixSem* sem)
-{
- return WaitForSingleObject(sem->sem, 0) == WAIT_OBJECT_0;
-}
-
-#else /* !defined(__APPLE__) && !defined(_WIN32) */
-
-struct ZixSemImpl {
- sem_t sem;
-};
-
-static inline ZixStatus
-zix_sem_init(ZixSem* sem, unsigned initial)
-{
- return sem_init(&sem->sem, 0, initial) ? ZIX_STATUS_ERROR
- : ZIX_STATUS_SUCCESS;
-}
-
-static inline void
-zix_sem_destroy(ZixSem* sem)
-{
- sem_destroy(&sem->sem);
-}
-
-static inline void
-zix_sem_post(ZixSem* sem)
-{
- sem_post(&sem->sem);
-}
-
-static inline ZixStatus
-zix_sem_wait(ZixSem* sem)
-{
- while (sem_wait(&sem->sem)) {
- if (errno != EINTR) {
- return ZIX_STATUS_ERROR;
- }
- /* Otherwise, interrupted, so try again. */
- }
-
- return ZIX_STATUS_SUCCESS;
-}
-
-static inline bool
-zix_sem_try_wait(ZixSem* sem)
-{
- return (sem_trywait(&sem->sem) == 0);
-}
-
-#endif
-
-/**
- @endcond
- @}
- @}
-*/
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif /* ZIX_SEM_H */
diff --git a/src/zix/thread.h b/src/zix/thread.h
deleted file mode 100644
index 77eeb1b..0000000
--- a/src/zix/thread.h
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- Copyright 2012-2020 David Robillard <d@drobilla.net>
-
- 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.
-*/
-
-#ifndef ZIX_THREAD_H
-#define ZIX_THREAD_H
-
-#include "zix/common.h"
-
-#ifdef _WIN32
-# include <windows.h>
-#else
-# include <errno.h>
-# include <pthread.h>
-#endif
-
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- @addtogroup zix
- @{
- @name Thread
- @{
-*/
-
-#ifdef _WIN32
-typedef HANDLE ZixThread;
-#else
-typedef pthread_t ZixThread;
-#endif
-
-/**
- Initialize `thread` to a new thread.
-
- The thread will immediately be launched, calling `function` with `arg`
- as the only parameter.
-*/
-static inline ZixStatus
-zix_thread_create(ZixThread* thread,
- size_t stack_size,
- void* (*function)(void*),
- void* arg);
-
-/**
- Join `thread` (block until `thread` exits).
-*/
-static inline ZixStatus
-zix_thread_join(ZixThread thread, void** retval);
-
-#ifdef _WIN32
-
-static inline ZixStatus
-zix_thread_create(ZixThread* thread,
- size_t stack_size,
- void* (*function)(void*),
- void* arg)
-{
- *thread = CreateThread(
- NULL, stack_size, (LPTHREAD_START_ROUTINE)function, arg, 0, NULL);
- return *thread ? ZIX_STATUS_SUCCESS : ZIX_STATUS_ERROR;
-}
-
-static inline ZixStatus
-zix_thread_join(ZixThread thread, void** retval)
-{
- (void)retval;
-
- return WaitForSingleObject(thread, INFINITE) ? ZIX_STATUS_SUCCESS
- : ZIX_STATUS_ERROR;
-}
-
-#else /* !defined(_WIN32) */
-
-static inline ZixStatus
-zix_thread_create(ZixThread* thread,
- size_t stack_size,
- void* (*function)(void*),
- void* arg)
-{
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- pthread_attr_setstacksize(&attr, stack_size);
-
- const int ret = pthread_create(thread, NULL, function, arg);
- pthread_attr_destroy(&attr);
-
- switch (ret) {
- case EAGAIN:
- return ZIX_STATUS_NO_MEM;
- case EINVAL:
- return ZIX_STATUS_BAD_ARG;
- case EPERM:
- return ZIX_STATUS_BAD_PERMS;
- }
-
- return ret ? ZIX_STATUS_ERROR : ZIX_STATUS_SUCCESS;
-}
-
-static inline ZixStatus
-zix_thread_join(ZixThread thread, void** retval)
-{
- return pthread_join(thread, retval) ? ZIX_STATUS_ERROR : ZIX_STATUS_SUCCESS;
-}
-
-#endif
-
-/**
- @}
- @}
-*/
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif /* ZIX_THREAD_H */
diff --git a/subprojects/lilv.wrap b/subprojects/lilv.wrap
new file mode 100644
index 0000000..ff82752
--- /dev/null
+++ b/subprojects/lilv.wrap
@@ -0,0 +1,8 @@
+# Copyright 2022 David Robillard <d@drobilla.net>
+# SPDX-License-Identifier: 0BSD OR ISC
+
+[wrap-git]
+url = https://gitlab.com/lv2/lilv.git
+push-url = ssh://git@gitlab.com:lv2/lilv.git
+revision = master
+depth = 1
diff --git a/subprojects/lv2.wrap b/subprojects/lv2.wrap
new file mode 100644
index 0000000..7421eb7
--- /dev/null
+++ b/subprojects/lv2.wrap
@@ -0,0 +1,8 @@
+# Copyright 2022 David Robillard <d@drobilla.net>
+# SPDX-License-Identifier: 0BSD OR ISC
+
+[wrap-git]
+url = https://gitlab.com/lv2/lv2.git
+push-url = ssh://git@gitlab.com:lv2/lv2.git
+revision = master
+depth = 1
diff --git a/subprojects/serd.wrap b/subprojects/serd.wrap
new file mode 100644
index 0000000..4bd4109
--- /dev/null
+++ b/subprojects/serd.wrap
@@ -0,0 +1,8 @@
+# Copyright 2022 David Robillard <d@drobilla.net>
+# SPDX-License-Identifier: 0BSD OR ISC
+
+[wrap-git]
+url = https://gitlab.com/drobilla/serd.git
+push-url = ssh://git@gitlab.com:drobilla/serd.git
+revision = master
+depth = 1
diff --git a/subprojects/sord.wrap b/subprojects/sord.wrap
new file mode 100644
index 0000000..7ca49cb
--- /dev/null
+++ b/subprojects/sord.wrap
@@ -0,0 +1,8 @@
+# Copyright 2022 David Robillard <d@drobilla.net>
+# SPDX-License-Identifier: 0BSD OR ISC
+
+[wrap-git]
+url = https://gitlab.com/drobilla/sord.git
+push-url = ssh://git@gitlab.com:drobilla/sord.git
+revision = master
+depth = 1
diff --git a/subprojects/sratom.wrap b/subprojects/sratom.wrap
new file mode 100644
index 0000000..9bfac61
--- /dev/null
+++ b/subprojects/sratom.wrap
@@ -0,0 +1,8 @@
+# Copyright 2022 David Robillard <d@drobilla.net>
+# SPDX-License-Identifier: 0BSD OR ISC
+
+[wrap-git]
+url = https://gitlab.com/lv2/sratom.git
+push-url = ssh://git@gitlab.com:lv2/sratom.git
+revision = master
+depth = 1
diff --git a/subprojects/suil.wrap b/subprojects/suil.wrap
new file mode 100644
index 0000000..dfc1ae8
--- /dev/null
+++ b/subprojects/suil.wrap
@@ -0,0 +1,8 @@
+# Copyright 2022 David Robillard <d@drobilla.net>
+# SPDX-License-Identifier: 0BSD OR ISC
+
+[wrap-git]
+url = https://gitlab.com/lv2/suil.git
+push-url = ssh://git@gitlab.com:lv2/suil.git
+revision = master
+depth = 1
diff --git a/subprojects/zix.wrap b/subprojects/zix.wrap
new file mode 100644
index 0000000..7a50ea2
--- /dev/null
+++ b/subprojects/zix.wrap
@@ -0,0 +1,14 @@
+# Copyright 2022-2023 David Robillard <d@drobilla.net>
+# SPDX-License-Identifier: 0BSD OR ISC
+
+[wrap-file]
+directory = zix-0.4.0
+source_url = https://download.drobilla.net/zix-0.4.0.tar.xz
+source_filename = zix-0.4.0.tar.xz
+source_hash = ac88dbefd9d29bfdce1532165c957d19d474a8367b727edb7be7d524e6cf9a14
+
+# [wrap-git]
+# url = https://gitlab.com/drobilla/zix.git
+# push-url = ssh://git@gitlab.com:drobilla/zix.git
+# revision = v0.4.0
+# depth = 1
diff --git a/test/meson.build b/test/meson.build
new file mode 100644
index 0000000..d7d0e94
--- /dev/null
+++ b/test/meson.build
@@ -0,0 +1,42 @@
+# Copyright 2019-2022 David Robillard <d@drobilla.net>
+# SPDX-License-Identifier: 0BSD OR ISC
+
+if get_option('lint')
+ if not meson.is_subproject()
+ # Check release metadata
+ autoship = find_program('autoship', required: get_option('tests'))
+ if autoship.found()
+ test(
+ 'autoship',
+ autoship,
+ args: ['test', jalv_src_root],
+ suite: 'data',
+ )
+ endif
+ endif
+
+ # Check licensing metadata
+ reuse = find_program('reuse', required: false)
+ if reuse.found()
+ test(
+ 'REUSE',
+ reuse,
+ args: ['--root', jalv_src_root, 'lint'],
+ suite: 'data',
+ )
+ endif
+endif
+
+##############
+# Unit Tests #
+##############
+
+test(
+ 'test_symap',
+ executable(
+ 'test_symap',
+ files('../src/symap.c'),
+ c_args: ['-DSYMAP_STANDALONE'],
+ dependencies: [zix_dep],
+ ),
+)
diff --git a/waf b/waf
deleted file mode 100755
index 887215c..0000000
--- a/waf
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/usr/bin/env python
-
-# Minimal waf script for projects that include waflib directly
-
-import sys
-import inspect
-import os
-
-try:
- from waflib import Context, Scripting
-except Exception as e:
- sys.stderr.write('error: Failed to import waf (%s)\n' % e)
- if os.path.exists('.git'):
- sys.stderr.write("Are submodules up to date? "
- "Try 'git submodule update --init --recursive'\n")
-
- sys.exit(1)
-
-
-def main():
- script_path = os.path.abspath(inspect.getfile(inspect.getmodule(main)))
- project_path = os.path.dirname(script_path)
- Scripting.waf_entry_point(os.getcwd(), Context.WAFVERSION, project_path)
-
-
-if __name__ == '__main__':
- main()
diff --git a/waflib b/waflib
deleted file mode 160000
-Subproject aeef9f5fdf416d9b68c61c75de7dae409f1ac6a
diff --git a/wscript b/wscript
deleted file mode 100644
index 3851356..0000000
--- a/wscript
+++ /dev/null
@@ -1,420 +0,0 @@
-#!/usr/bin/env python
-
-import os
-
-from waflib import Build, Logs, Options, Utils
-from waflib.extras import autowaf as autowaf
-
-# Version of this package (even if built as a child)
-JALV_VERSION = '1.6.7'
-
-# Mandatory waf variables
-APPNAME = 'jalv' # Package name for waf dist
-VERSION = JALV_VERSION # Package version for waf dist
-top = '.' # Source directory
-out = 'build' # Build directory
-
-# Release variables
-uri = 'http://drobilla.net/sw/jalv'
-dist_pattern = 'http://download.drobilla.net/jalv-%d.%d.%d.tar.bz2'
-post_tags = ['Hacking', 'LAD', 'LV2', 'Jalv']
-
-
-def options(ctx):
- ctx.load('compiler_c')
- ctx.load('compiler_cxx')
- ctx.add_flags(
- ctx.configuration_options(),
- {'portaudio': 'use PortAudio backend, not JACK',
- 'no-gui': 'do not build any GUIs',
- 'no-gtk': 'do not build Gtk GUI',
- 'no-gtk2': 'do not build Gtk2 GUI',
- 'no-gtk3': 'do not build Gtk3 GUI',
- 'no-qt': 'do not build Qt GUI',
- 'no-qt5': 'do not build Qt5 GUI'})
-
-
-def configure(conf):
- conf.load('compiler_c', cache=True)
- conf.load('compiler_cxx', cache=True)
- conf.load('autowaf', cache=True)
- autowaf.set_c_lang(conf, 'c99')
- autowaf.set_cxx_lang(conf, 'c++14')
-
- if Options.options.strict:
- # Check for programs used by lint target
- conf.find_program("flake8", var="FLAKE8", mandatory=False)
- conf.find_program("clang-tidy", var="CLANG_TIDY", mandatory=False)
- conf.find_program("iwyu_tool", var="IWYU_TOOL", mandatory=False)
-
- if Options.options.ultra_strict:
- autowaf.add_compiler_flags(conf.env, 'c', {
- 'clang': [
- '-Wno-bad-function-cast',
- '-Wno-missing-noreturn',
- ],
- 'gcc': [
- '-Wno-bad-function-cast',
- '-Wno-c++-compat',
- ],
- 'msvc': [
- '/wd4061', # enumerator in switch is not explicitly handled
- '/wd4100', # unreferenced formal parameter
- '/wd4191', # unsafe function conversion
- '/wd4200', # zero-sized array in struct/union
- '/wd4244', # possible loss of data from integer conversion
- '/wd4267', # possible loss of data from size conversion
- '/wd4365', # signed/unsigned mismatch
- '/wd4514', # unreferenced inline function has been removed
- '/wd4706', # assignment within conditional expression
- '/wd4710', # function not inlined
- '/wd4711', # function selected for automatic inline expansion
- '/wd4800', # implicit conversion from int to bool
- '/wd4820', # padding added after construct
- '/wd4996', # POSIX name for this item is deprecated
- '/wd5045', # compiler will insert Spectre mitigation
- ],
- })
-
- autowaf.add_compiler_flags(conf.env, '*', {
- 'clang': [
- '-Wno-atomic-implicit-seq-cst',
- '-Wno-c99-extensions',
- '-Wno-cast-align',
- '-Wno-cast-qual',
- '-Wno-disabled-macro-expansion',
- '-Wno-documentation-unknown-command',
- '-Wno-double-promotion',
- '-Wno-float-conversion',
- '-Wno-float-equal',
- '-Wno-format-nonliteral',
- '-Wno-implicit-fallthrough',
- '-Wno-implicit-float-conversion',
- '-Wno-nullability-extension',
- '-Wno-padded',
- '-Wno-redundant-parens',
- '-Wno-reserved-id-macro',
- '-Wno-reserved-identifier',
- '-Wno-shorten-64-to-32',
- '-Wno-sign-conversion',
- '-Wno-switch-enum',
- '-Wno-unknown-warning-option',
- '-Wno-unused-macros',
- '-Wno-unused-parameter',
- ],
- 'gcc': [
- '-Wno-cast-align',
- '-Wno-cast-qual',
- '-Wno-conversion',
- '-Wno-double-promotion',
- '-Wno-float-conversion',
- '-Wno-float-equal',
- '-Wno-padded',
- '-Wno-pedantic',
- '-Wno-stack-protector',
- '-Wno-switch-enum',
- '-Wno-unused-macros',
- '-Wno-unused-parameter',
- ],
- })
-
- autowaf.add_compiler_flags(conf.env, 'cxx', {
- 'clang': [
- '-Wno-extra-semi-stmt',
- '-Wno-old-style-cast',
- '-Wno-weak-vtables',
- '-Wno-zero-as-null-pointer-constant',
- ],
- 'gcc': [
- '-Wno-effc++',
- ],
- })
-
- conf.check_pkg('lv2 >= 1.18.0', uselib_store='LV2')
- conf.check_pkg('lilv-0 >= 0.24.0', uselib_store='LILV')
- conf.check_pkg('serd-0 >= 0.24.0', uselib_store='SERD')
- conf.check_pkg('sord-0 >= 0.14.0', uselib_store='SORD')
- conf.check_pkg('sratom-0 >= 0.6.4', uselib_store='SRATOM')
- if Options.options.portaudio:
- conf.check_pkg('portaudio-2.0 >= 2.0.0',
- uselib_store='PORTAUDIO',
- system=True,
- mandatory=False)
- else:
- conf.check_pkg('jack >= 0.120.0',
- uselib_store='JACK',
- system=True)
-
- if not Options.options.no_gui and not Options.options.no_gtk:
- if not Options.options.no_gtk2:
- conf.check_pkg('gtk+-2.0 >= 2.18.0',
- uselib_store='GTK2',
- system=True,
- mandatory=False)
- if not Options.options.no_gtk3:
- conf.check_pkg('gtk+-3.0 >= 3.0.0',
- uselib_store='GTK3',
- system=True,
- mandatory=False)
-
- if not Options.options.no_gui and not Options.options.no_qt:
- if not Options.options.no_qt5:
- conf.check_pkg('Qt5Widgets >= 5.1.0',
- uselib_store='QT5',
- system=True,
- mandatory=False)
- if conf.env.HAVE_QT5:
- if not conf.find_program('moc-qt5', var='MOC5',
- mandatory=False):
- conf.find_program('moc', var='MOC5')
-
- have_gui = (conf.env.HAVE_GTK2 or conf.env.HAVE_GTK3 or conf.env.HAVE_QT5)
-
- conf.check_pkg('suil-0 >= 0.10.0', uselib_store='SUIL')
-
- if conf.env.HAVE_JACK:
- conf.check_function(
- 'c', 'jack_port_type_get_buffer_size',
- header_name = 'jack/jack.h',
- define_name = 'HAVE_JACK_PORT_TYPE_GET_BUFFER_SIZE',
- uselib = 'JACK',
- return_type = 'size_t',
- arg_types = 'jack_client_t*,const char*',
- mandatory = False)
-
- conf.check_function('c', 'jack_set_property',
- header_name = 'jack/metadata.h',
- define_name = 'HAVE_JACK_METADATA',
- uselib = 'JACK',
- return_type = 'int',
- arg_types = '''jack_client_t*,
- jack_uuid_t,
- const char*,
- const char*,
- const char*''',
- mandatory = False)
-
- defines = ['_POSIX_C_SOURCE=200809L']
-
- conf.env.PTHREAD_CFLAGS = []
- conf.env.PTHREAD_LINKFLAGS = []
- if conf.env.DEST_OS != 'win32':
- if conf.check(cflags=['-pthread'], mandatory=False):
- conf.env.PTHREAD_CFLAGS = ['-pthread']
- if conf.check(linkflags=['-pthread'], mandatory=False):
- if not (conf.env.DEST_OS == 'darwin'
- and conf.env.CXX_NAME == 'clang'):
- conf.env.PTHREAD_LINKFLAGS += ['-pthread']
- elif conf.check(linkflags=['-lpthread'], mandatory=False):
- conf.env.PTHREAD_LINKFLAGS += ['-lpthread']
-
- conf.check_function('c', 'isatty',
- header_name = 'unistd.h',
- defines = defines,
- define_name = 'HAVE_ISATTY',
- return_type = 'int',
- arg_types = 'int',
- mandatory = False)
-
- conf.check_function('c', 'fileno',
- header_name = 'stdio.h',
- defines = defines,
- define_name = 'HAVE_FILENO',
- return_type = 'int',
- arg_types = 'FILE*',
- mandatory = False)
-
- conf.check_function('c', 'mlock',
- header_name = 'sys/mman.h',
- defines = defines,
- define_name = 'HAVE_MLOCK',
- return_type = 'int',
- arg_types = 'const void*,size_t',
- mandatory = False)
-
- conf.check_function('c', 'sigaction',
- header_name = 'signal.h',
- defines = defines,
- define_name = 'HAVE_SIGACTION',
- return_type = 'int',
- arg_types = '''int,
- const struct sigaction*,
- struct sigaction*''',
- mandatory = False)
-
- conf.define('JALV_VERSION', JALV_VERSION)
- conf.write_config_header('jalv_config.h', remove=False)
-
- autowaf.display_summary(
- conf,
- {'Backend': 'Jack' if conf.env.HAVE_JACK else 'PortAudio',
- 'Jack metadata support': conf.is_defined('HAVE_JACK_METADATA'),
- 'Gtk 2.0 support': bool(conf.env.HAVE_GTK2),
- 'Gtk 3.0 support': bool(conf.env.HAVE_GTK3),
- 'Qt 5.0 support': bool(conf.env.HAVE_QT5),
- 'Color output': bool(conf.env.JALV_WITH_COLOR)})
-
-
-def build(bld):
- libs = 'LILV SUIL JACK SERD SORD SRATOM LV2 PORTAUDIO'
- source = '''
- src/control.c
- src/jalv.c
- src/log.c
- src/lv2_evbuf.c
- src/state.c
- src/symap.c
- src/worker.c
- src/zix/ring.c
- '''
-
- if bld.env.HAVE_JACK:
- source += 'src/jack.c'
-
- # Non-GUI internal JACK client library
- obj = bld(features = 'c cshlib',
- source = source + ' src/jalv_console.c',
- target = 'jalv',
- cflags = bld.env.PTHREAD_CFLAGS,
- linkflags = bld.env.PTHREAD_LINKFLAGS,
- defines = ['ZIX_INTERNAL'],
- includes = ['.', 'src'],
- lib = ['pthread'],
- uselib = libs,
- install_path = '${LIBDIR}/jack')
- obj.env.cshlib_PATTERN = '%s.so'
- elif bld.env.HAVE_PORTAUDIO:
- source += 'src/portaudio.c'
-
- # Non-GUI version
- obj = bld(features = 'c cprogram',
- source = source + ' src/jalv_console.c',
- target = 'jalv',
- cflags = bld.env.PTHREAD_CFLAGS,
- linkflags = bld.env.PTHREAD_LINKFLAGS,
- defines = ['ZIX_INTERNAL'],
- includes = ['.', 'src'],
- uselib = libs,
- install_path = '${BINDIR}')
-
- # Gtk2 version
- if bld.env.HAVE_GTK2:
- obj = bld(features = 'c cprogram',
- source = source + ' src/jalv_gtk.c',
- target = 'jalv.gtk',
- cflags = bld.env.PTHREAD_CFLAGS,
- linkflags = bld.env.PTHREAD_LINKFLAGS,
- defines = ['ZIX_INTERNAL'],
- includes = ['.', 'src'],
- lib = ['m'],
- uselib = libs + ' GTK2',
- install_path = '${BINDIR}')
-
- # Gtk3 version
- if bld.env.HAVE_GTK3:
- obj = bld(features = 'c cprogram',
- source = source + ' src/jalv_gtk.c',
- target = 'jalv.gtk3',
- cflags = bld.env.PTHREAD_CFLAGS,
- linkflags = bld.env.PTHREAD_LINKFLAGS,
- defines = ['ZIX_INTERNAL'],
- includes = ['.', 'src'],
- lib = ['m'],
- uselib = libs + ' GTK3',
- install_path = '${BINDIR}')
-
- bld(features = 'subst',
- source = 'jalv.desktop.in',
- target = 'jalv.desktop',
- install_path = '${DATADIR}/applications',
- chmod = Utils.O644,
- BINDIR = os.path.normpath(bld.env.BINDIR),
- APP_INSTALL_NAME = 'jalv.gtk3',
- APP_HUMAN_NAME = 'Jalv')
-
- # Qt5 version
- if bld.env.HAVE_QT5:
- obj = bld(rule = '${MOC5} ${SRC} > ${TGT}',
- source = 'src/jalv_qt.hpp',
- target = 'jalv_qt5_meta.cpp')
- obj = bld(features = 'c cxx cxxprogram',
- source = source + ' src/jalv_qt.cpp jalv_qt5_meta.cpp',
- target = 'jalv.qt5',
- cflags = bld.env.PTHREAD_CFLAGS,
- linkflags = bld.env.PTHREAD_LINKFLAGS,
- defines = ['ZIX_INTERNAL'],
- includes = ['.', 'src'],
- uselib = libs + ' QT5',
- install_path = '${BINDIR}',
- cxxflags = ['-fPIC'])
-
- # Man pages
- bld.install_files('${MANDIR}/man1', bld.path.ant_glob('doc/*.1'))
-
-
-class LintContext(Build.BuildContext):
- fun = cmd = 'lint'
-
-
-def lint(ctx):
- "checks code for style issues"
- import os
- import subprocess
- import sys
-
- st = 0
-
- if "FLAKE8" in ctx.env:
- Logs.info("Running flake8")
- st = subprocess.call([ctx.env.FLAKE8[0],
- "wscript",
- "--ignore",
- "E101,E129,W191,E221,W504,E251,E241,E741"])
- else:
- Logs.warn("Not running flake8")
-
- if "IWYU_TOOL" in ctx.env:
- Logs.info("Running include-what-you-use")
-
- qt_mapping_file = "/usr/share/include-what-you-use/qt5_11.imp"
- extra_args = []
- if os.path.exists(qt_mapping_file):
- extra_args += ["--", "-Xiwyu", "--mapping_file=" + qt_mapping_file]
-
- cmd = [ctx.env.IWYU_TOOL[0], "-o", "clang", "-p", "build"] + extra_args
- output = subprocess.check_output(cmd).decode('utf-8')
- if 'error: ' in output:
- sys.stdout.write(output)
- st += 1
- else:
- Logs.warn("Not running include-what-you-use")
-
- if "CLANG_TIDY" in ctx.env and "clang" in ctx.env.CXX[0]:
- Logs.info("Running clang-tidy")
-
- import json
-
- with open('build/compile_commands.json', 'r') as db:
- commands = json.load(db)
- files = [c['file'] for c in commands]
-
- for step_files in zip(*(iter(files),) * Options.options.jobs):
- procs = []
- for f in step_files:
- cmd = [ctx.env.CLANG_TIDY[0], '--quiet', '-p=.', f]
- procs += [subprocess.Popen(cmd, cwd='build')]
-
- for proc in procs:
- proc.communicate()
- st += proc.returncode
- else:
- Logs.warn("Not running clang-tidy")
-
- if st != 0:
- Logs.warn("Lint checks failed")
- sys.exit(st)
-
-
-def dist(ctx):
- ctx.base_path = ctx.path
- ctx.excl = ctx.get_excl() + ' .gitmodules'