Compare commits

..

2 Commits

Author SHA1 Message Date
Paolo Marrone
8ddf42ea33 output parameters work. UI needs to be synced to params 2025-03-03 15:26:14 +01:00
Paolo Marrone
2d66e616cd parameter via messages system. Input control ones work. Output ones not yet 2025-02-24 23:07:06 +01:00
39 changed files with 1589 additions and 667 deletions

View File

@ -20,7 +20,7 @@ Feel free to try it out anyway and perhaps give us some feedback (we'd appreciat
## Legal
Copyright (C) 2021-2025 Orastron Srl unipersonale.
Copyright (C) 2021-2024 Orastron Srl unipersonale.
Authors: Stefano D'Angelo, Paolo Marrone.

9
notes
View File

@ -268,12 +268,3 @@ product {
}
]
}
makefile dirs:
- make always executed from Makefile directory
- COMMON_DIR: static common sources (e.g., src/lv2.c)
- DATA_DIR: generated sources/data (e.g., src/data.h, data/manifest.ttl.in)
- PLUGIN_DIR: plugin sources (e.g., plugin.h)
- API_DIR: generated Tibia-related API sources (e.g., plugin_api.h)
- MKINC_DIR: Makefile includes (e.g., vars-pre.mk)
- build: build files

View File

@ -1,7 +1,7 @@
#
# Tibia
#
# Copyright (C) 2023-2025 Orastron Srl unipersonale
# Copyright (C) 2023, 2024 Orastron Srl unipersonale
#
# Tibia is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -18,8 +18,6 @@
# File author: Stefano D'Angelo
#
SHELL := bash -o pipefail
TEMPLATE := android
include vars.mk
@ -52,19 +50,8 @@ KOTLIN_STDLIB_FILE := $(KOTLIN_DIR)/kotlin-stdlib-$(KOTLIN_STDLIB_VERSION).jar
KOTLINX_COROUTINES_CORE_FILE := $(KOTLIN_DIR)/kotlinx-coroutines-core-$(KOTLINX_COROUTINES_CORE_VERSION).jar
KOTLINX_COROUTINES_CORE_JVM_FILE := $(KOTLIN_DIR)/kotlinx-coroutines-core-jvm-$(KOTLINX_COROUTINES_CORE_JVM_VERSION).jar
ifeq ($(OS), Windows_NT)
NDK_BIN_DIR ?= $(NDK_DIR)/toolchains/llvm/prebuilt/windows-x86_64/bin/
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Darwin)
NDK_BIN_DIR ?= $(NDK_DIR)/toolchains/llvm/prebuilt/darwin-x86_64/bin/
else
NDK_BIN_DIR ?= $(NDK_DIR)/toolchains/llvm/prebuilt/linux-x86_64/bin/
endif
endif
CC := $(NDK_BIN_DIR)/armv7a-linux-androideabi$(MIN_API)-clang
CXX := $(NDK_BIN_DIR)/armv7a-linux-androideabi$(MIN_API)-clang++
CC := $(NDK_DIR)/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi$(MIN_API)-clang
CXX := $(NDK_DIR)/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi$(MIN_API)-clang++
JC := javac
APKSIGNER := $(BUILD_TOOLS_DIR)/apksigner
@ -92,10 +79,10 @@ ifeq ($(HAS_MIDI_IN), yes)
endif
CFLAGS := -O3 -Wall -Wpedantic -Wextra
CFLAGS_ALL := -I$(DATA_DIR)/src -I$(PLUGIN_DIR) -I$(API_DIR) -fPIC -fvisibility=hidden $(CFLAGS_EXTRA) $(CFLAGS)
CFLAGS_ALL := -I$(DATA_DIR)/src -I$(PLUGIN_DIR) -I$(API_DIR) -fPIC $(CFLAGS_EXTRA) $(CFLAGS)
CXXFLAGS := $(CFLAGS)
CXXFLAGS_ALL := -I$(DATA_DIR)/src -I$(PLUGIN_DIR) -I$(API_DIR) -fPIC -fvisibility=hidden -std=c++11 $(CXXFLAGS_EXTRA) $(CXXFLAGS)
CXXFLAGS_ALL := -I$(DATA_DIR)/src -I$(PLUGIN_DIR) -I$(API_DIR) -fPIC -std=c++11 $(CXXFLAGS_EXTRA) $(CXXFLAGS)
LDFLAGS :=
LDFLAGS_ALL := -shared -static-libstdc++ -landroid
@ -117,8 +104,6 @@ DIRS := build build/gen build/apk build/obj build/apk/lib build/apk/lib/armeabi-
ALL := build/$(BUNDLE_NAME).apk
PHONY := all clean install
-include $(MKINC_DIR)/vars-extra.mk
all: $(ALL)
@ -160,7 +145,7 @@ install: build/$(BUNDLE_NAME).apk
-include $(MKINC_DIR)/rules-extra.mk
.PHONY: $(PHONY)
.PHONY: all clean install
.SECONDEXPANSION:
@ -173,5 +158,3 @@ $(CXX_OBJS): build/obj/%.o: $$(filter $$(PERCENT)/$$(basename $$(notdir $$@)).cp
$(CXX) $^ -o $@ -c $(CXXFLAGS_ALL)
-include $(MKINC_DIR)/rules-secondexp-extra.mk
.DELETE_ON_ERROR:

View File

@ -20,7 +20,6 @@
BUNDLE_NAME := {{=it.product.bundleName}}
JAVA_PACKAGE_NAME := {{=it.android.javaPackageName}}
ANDROID_VERSION := {{=it.android.androidVersion}}
{{?(it.android_make?.commonDir || it.make?.commonDir)}}
COMMON_DIR := {{=it.android_make?.commonDir ?? (it.make?.commonDir ?? "")}}

View File

@ -8,7 +8,7 @@
{{??}}
<uses-sdk android:minSdkVersion="26" /> <!-- for androidx core and AAudio -->
{{?}}
<uses-sdk android:targetSdkVersion="{{=it.android.androidVersion}}" />
<uses-sdk android:targetSdkVersion="34" />
<application android:label="{{=it.product.name}}">
<activity android:name=".MainActivity" android:label="{{=it.product.name}}" android:exported="true">
<intent-filter>

View File

@ -18,8 +18,6 @@
# File author: Stefano D'Angelo
#
SHELL := bash -o pipefail
TEMPLATE := cmd
include vars.mk
@ -51,7 +49,7 @@ CC := gcc
CXX := g++
CFLAGS := -O3 -Wall -Wpedantic -Wextra
CFLAGS_ALL := -I$(DATA_DIR)/src -I$(PLUGIN_DIR) -I$(API_DIR) -I$(TINYWAV_DIR) -I$(MIDI_PARSER_DIR)/include -fvisibility=hidden $(CFLAGS_EXTRA) $(CFLAGS)
CFLAGS_ALL := -I$(DATA_DIR)/src -I$(PLUGIN_DIR) -I$(API_DIR) -I$(TINYWAV_DIR) -I$(MIDI_PARSER_DIR)/include $(CFLAGS_EXTRA) $(CFLAGS)
LDFLAGS :=
LDFLAGS_ALL := $(LDFLAGS_EXTRA) $(LDFLAGS)
@ -81,12 +79,8 @@ DIRS := build build/obj
ALL := build/$(PROGRAM)
STRIP_ALL := build/$(PROGRAM)
STRIP_PREREQS := $(STRIP_ALL)
PHONY := all clean strip
ifneq ($(OS), Windows_NT)
PHONY := $(PHONY) install
endif
STRIP_PHONY :=
STRIP_PREREQS := $(STRIP_ALL) $(STRIP_PHONY)
-include $(MKINC_DIR)/vars-extra.mk
@ -109,13 +103,15 @@ clean:
strip: $(STRIP_PREREQS)
strip build/$(PROGRAM)
ifneq ($(OS), Windows_NT)
ifeq ($(OS), Windows_NT)
.PHONY: all clean strip $(STRIP_PHONY)
else
install: all
mkdir -m 0755 -p $(BINDIR)
install -m 0755 build/$(PROGRAM) $(BINDIR)
endif
.PHONY: $(PHONY)
.PHONY: all clean strip $(STRIP_PHONY) install
endif
-include $(MKINC_DIR)/rules-extra.mk
@ -133,5 +129,3 @@ $(CXX_OBJS): build/obj/%.o: $$(filter $$(PERCENT)/$$(basename $$(notdir $$@)).cp
$(CXX) $^ -o $@ -c $(CXXFLAGS_ALL)
-include $(MKINC_DIR)/rules-secondexp-extra.mk
.DELETE_ON_ERROR:

View File

@ -1,7 +1,7 @@
#
# Tibia
#
# Copyright (C) 2023-2025 Orastron Srl unipersonale
# Copyright (C) 2023, 2024 Orastron Srl unipersonale
#
# Tibia is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -18,8 +18,6 @@
# File author: Stefano D'Angelo
#
SHELL := bash -o pipefail
TEMPLATE := daisy-seed
include vars.mk

View File

@ -1,7 +1,7 @@
#
# Tibia
#
# Copyright (C) 2024, 2025 Orastron Srl unipersonale
# Copyright (C) 2024 Orastron Srl unipersonale
#
# Tibia is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -18,8 +18,6 @@
# File author: Stefano D'Angelo
#
SHELL := bash -o pipefail
TEMPLATE := ios
include vars.mk
@ -36,10 +34,10 @@ BUILD_DATA_DIR := build/gen/res
-include $(MKINC_DIR)/vars-pre.mk
CFLAGS := -O3 -Wall -Wpedantic -Wextra
CFLAGS_ALL := -I$(DATA_DIR)/src -I$(PLUGIN_DIR) -I$(API_DIR) -fvisibility=hidden $(CFLAGS_EXTRA) $(CFLAGS)
CFLAGS_ALL := -I$(DATA_DIR)/src -I$(PLUGIN_DIR) -I$(API_DIR) $(CFLAGS_EXTRA) $(CFLAGS)
CXXFLAGS := $(CFLAGS)
CXXFLAGS_ALL := -I$(DATA_DIR)/src -I$(PLUGIN_DIR) -I$(API_DIR) -fvisibility=hidden $(CXXFLAGS_EXTRA) $(CXXFLAGS)
CXXFLAGS_ALL := -I$(DATA_DIR)/src -I$(PLUGIN_DIR) -I$(API_DIR) $(CXXFLAGS_EXTRA) $(CXXFLAGS)
LDFLAGS :=
LDFLAGS_ALL := $(LDFLAGS_EXTRA) $(LDFLAGS)
@ -97,5 +95,3 @@ $(RESOURCES_OUT): build/gen/res/%: $$(filter $$(PERCENT)/%,$$(RESOURCES)) | buil
cp -R $^ $@
-include $(MKINC_DIR)/rules-secondexp-extra.mk
.DELETE_ON_ERROR:

View File

@ -164,7 +164,6 @@ void (^midiNotifyBlock)(const MIDINotification *message) = ^(const MIDINotificat
};
void (^midiReceiveBlock)(const MIDIEventList *evtlist, void *srcConnRefCon) = ^(const MIDIEventList *evtlist, void *srcConnRefCon) {
(void)srcConnRefCon;
const MIDIEventPacket *p = evtlist->packet;
for (UInt32 i = 0; i < evtlist->numPackets; i++) {
for (UInt32 j = 0; j < p->wordCount; j++) {

View File

@ -26,5 +26,5 @@ module.exports = function (data, api) {
api.generateFileFromTemplateFile(`src${sep}index.html`, `src${sep}index.html`, data);
api.copyFile(`src${sep}native.mm`, `src${sep}native.mm`);
api.copyFile(`src${sep}app-Bridging-Header.h`, `src${sep}app-Bridging-Header.h`);
api.copyFile(`src${sep}app.swift`, `src${sep}app.swift`);
api.copyFile(`src${sep}app.swift`, `src${sep}app.swift`, data);
};

View File

@ -18,8 +18,6 @@
# File author: Stefano D'Angelo
#
SHELL := bash -o pipefail
TEMPLATE := lv2
include vars.mk
@ -40,8 +38,8 @@ BUILD_DATA_DIR := build/$(BUNDLE_DIR)
ifeq ($(OS), Windows_NT)
DLL_SUFFIX := .dll
UI_TYPE := WindowsUI
LV2DIR := $(subst \,/,$(COMMONPROGRAMFILES))/LV2
LV2DIR_USER := $(subst \,/,$(APPDATA))/LV2
LV2DIR := $(shell echo '$(COMMONPROGRAMFILES)' | sed 's:\\:/:g')/LV2
LV2DIR_USER := $(shell echo '$(APPDATA)' | sed 's:\\:/:g')/LV2
CC := gcc
CXX := g++
else
@ -64,14 +62,14 @@ else
endif
endif
CFLAGS := -O3 -Wall -Wpedantic -Wextra
CFLAGS_ALL := -I$(DATA_DIR)/src -I$(PLUGIN_DIR) -I$(API_DIR) $(shell pkg-config --cflags lv2) -fPIC -fvisibility=hidden $(CFLAGS_EXTRA) $(CFLAGS)
CFLAGS := -O0 -g -Wall -Wpedantic -Wextra
CFLAGS_ALL := -I$(DATA_DIR)/src -I$(PLUGIN_DIR) -I$(API_DIR) $(shell pkg-config --cflags lv2) -fPIC $(CFLAGS_EXTRA) $(CFLAGS)
LDFLAGS :=
LDFLAGS_ALL := -shared $(shell pkg-config --libs lv2) $(LDFLAGS_EXTRA) $(LDFLAGS)
CXXFLAGS := $(CFLAGS)
CXXFLAGS_ALL := -I$(DATA_DIR)/src -I$(PLUGIN_DIR) -I$(API_DIR) $(shell pkg-config --cflags lv2) -fPIC -fvisibility=hidden $(CXXFLAGS_EXTRA) $(CXXFLAGS)
CXXFLAGS_ALL := -I$(DATA_DIR)/src -I$(PLUGIN_DIR) -I$(API_DIR) -fPIC $(CXXFLAGS_EXTRA) $(CXXFLAGS)
ifeq ($(UNAME_S), Darwin)
CFLAGS_ALL := $(CFLAGS_ALL) -arch arm64 -arch x86_64
@ -95,9 +93,8 @@ DIRS := build build/$(BUNDLE_DIR) build/obj
ALL := build/$(BUNDLE_DIR)/manifest.ttl build/$(BUNDLE_DIR)/$(DLL_FILE)
STRIP_ALL := build/$(BUNDLE_DIR)/$(DLL_FILE) build/$(BUNDLE_DIR)/manifest.ttl
STRIP_PREREQS := $(STRIP_ALL)
.PHONY: all clean strip install install-user
STRIP_PHONY :=
STRIP_PREREQS := $(STRIP_ALL) $(STRIP_PHONY)
-include $(MKINC_DIR)/vars-extra.mk
@ -121,48 +118,43 @@ clean:
rm -fr build
strip: $(STRIP_PREREQS)
strip -Sx build/$(BUNDLE_DIR)/$(DLL_FILE)
strip build/$(BUNDLE_DIR)/$(DLL_FILE)
#Reaper can't handle this
#rdfproc lv2_store parse build/$(BUNDLE_DIR)/manifest.ttl turtle || (rm lv2_store* && exit 1)
#rdfproc lv2_store serialize ntriples > build/$(BUNDLE_DIR)/manifest.ttl || (rm lv2_store* && exit 1)
#rm lv2_store*
#f=`cat build/$(BUNDLE_DIR)/manifest.ttl` && echo "$f" | sed '/^[[:space:]]**$/d' > build/$(BUNDLE_DIR)/manifest.ttl
$(eval TMP := $(shell mktemp /tmp/index.XXXXXX))
sed '/^[[:space:]]*$$/d' build/$(BUNDLE_DIR)/manifest.ttl > $(TMP) || (rm $(TMP) && exit 1)
cp $(TMP) build/$(BUNDLE_DIR)/manifest.ttl || (rm $(TMP) && exit 1)
rm $(TMP)
install: all
@for d in `find build/$(BUNDLE_DIR) -type d`; do \
d=`echo $$d | sed 's:^build/::'` ; \
echo mkdir -m 0755 -p "$(LV2DIR)/$$d"; \
mkdir -m 0755 -p "$(LV2DIR)/$$d" || exit 1; \
mkdir -m 0755 -p "$(LV2DIR)/$$d"; \
done
@for f in `find build/$(BUNDLE_DIR) -type f`; do \
m=`[ -x $$f ] && echo 0755 || echo 0644`; \
d=`echo $$f | sed 's:^build/::'` ; \
d=`dirname $$d`; \
echo install -m $$m $$f "$(LV2DIR)/$$d"; \
install -m $$m $$f "$(LV2DIR)/$$d" || exit 1; \
install -m $$m $$f "$(LV2DIR)/$$d"; \
done
install-user: all
@for d in `find build/$(BUNDLE_DIR) -type d`; do \
d=`echo $$d | sed 's:^build/::'` ; \
echo mkdir -m 0755 -p "$(LV2DIR_USER)/$$d"; \
mkdir -m 0755 -p "$(LV2DIR_USER)/$$d" || exit 1; \
mkdir -m 0755 -p "$(LV2DIR_USER)/$$d"; \
done
@for f in `find build/$(BUNDLE_DIR) -type f`; do \
m=`[ -x $$f ] && echo 0755 || echo 0644`; \
d=`echo $$f | sed 's:^build/::'` ; \
d=`dirname $$d`; \
echo install -m $$m $$f "$(LV2DIR_USER)/$$d"; \
install -m $$m $$f "$(LV2DIR_USER)/$$d" || exit 1; \
install -m $$m $$f "$(LV2DIR_USER)/$$d"; \
done
-include $(MKINC_DIR)/rules-extra.mk
.PHONY: $(PHONY)
.PHONY: all clean strip $(STRIP_PHONY) install install-user
.SECONDEXPANSION:
@ -178,5 +170,3 @@ $(CXX_OBJS): build/obj/%.o: $$(filter $$(PERCENT)/$$(basename $$(notdir $$@)).cp
$(CXX) $^ -o $@ -c $(CXXFLAGS_ALL)
-include $(MKINC_DIR)/rules-secondexp-extra.mk
.DELETE_ON_ERROR:

View File

@ -0,0 +1 @@
This is experimental and broken, do not use this.

View File

@ -0,0 +1,95 @@
{{~it.tibia.lv2.prefixes :p}}
@prefix {{=p.id}}: <{{=p.uri}}> .
{{~}}
{{~it.product.parameters :p}}
plugin:{{=p.id}}
a lv2:Parameter ;
rdfs:label "{{=p.name}}" ;
lv2:name "{{=p.name}}" ;
{{?"shortName" in p}}
lv2:shortName "{{=p.shortName.substring(0, 16)}}" ;
{{?}}
lv2:symbol "{{=p.id}}" ;
rdfs:range atom:Float .
{{~}}
{{=it.tibia.lv2.ttlURI(it.lv2.uri)}}
a lv2:Plugin ;
{{~it.lv2.types :t}}
a {{=it.tibia.lv2.ttlURI(t)}} ;
{{~}}
{{?it.lv2.project}}
lv2:project {{=it.tibia.lv2.ttlURI(it.lv2.project)}} ;
{{?}}
lv2:binary <{{=it.product.bundleName}}@DLL_SUFFIX@> ;
doap:name "{{=it.product.name}}" ;
doap:maintainer [
a foaf:Organization ;
foaf:name "{{=it.company.name}}" ;
foaf:mbox <mailto:{{=it.company.email}}> ;
rdfs:seeAlso {{=it.tibia.lv2.ttlURI(it.company.url)}}
] ;
lv2:minorVersion {{=/^([0-9]+)\./.exec(it.lv2.version)[1]}} ;
lv2:microVersion {{=/^[0-9]+\.([0-9]+)/.exec(it.lv2.version)[1]}} ;
{{?it.tibia.lv2.ports.find(p => p.type == "midi" || p.type == "param")}}
lv2:requiredFeature urid:map ;
lv2:optionalFeature log:log ;
{{?}}
{{?it.product.parameters.find(p => p.direction == "input")}}
patch:writable {{=it.product.parameters.filter(p => p.direction == "input").map(p => "plugin:" + p.id).join(" , ")}} ;
{{?}}
{{?it.product.parameters.find(p => p.direction == "output")}}
patch:readable {{=it.product.parameters.filter(p => p.direction == "output").map(p => "plugin:" + p.id).join(" , ")}} ;
{{?}}
lv2:optionalFeature lv2:hardRTCapable ;
{{?it.product.ui}}
ui:ui plugin:ui ;
{{?}}
lv2:port [
{{~it.tibia.lv2.ports :p:i}}
a {{?p.type == "control"}}lv2:ControlPort{{??(p.type == "midi" || p.type == "param")}}atom:AtomPort{{??}}{{?p.cv}}lv2:CVPort{{??}}lv2:AudioPort{{?}}{{?}} ,
{{?p.direction == "input"}}lv2:InputPort{{??}}lv2:OutputPort{{?}} ;
lv2:name "{{=p.name}}" ;
{{?"shortName" in p}}
lv2:shortName "{{=p.shortName.substring(0, 16)}}" ;
{{?}}
lv2:symbol "{{=p.id}}" ;
{{?p.type == "param"}}
atom:bufferType atom:Sequence ;
atom:supports atom:Object ;
atom:supports patch:Message ;
{{??p.type == "midi"}}
atom:bufferType atom:Sequence ;
atom:supports midi:MidiEvent ;
{{?}}
{{?p.sidechain}}
lv2:portProperty lv2:isSideChain ;
{{?}}
{{?p.control}}
lv2:designation lv2:control ;
{{?}}
{{?p.optional}}
lv2:portProperty lv2:connectionOptional ;
{{?}}
lv2:index {{=i}}
{{?i < it.tibia.lv2.ports.length - 1}}
] , [
{{??}}
] .
{{?}}
{{~}}
{{?it.product.ui}}
plugin:ui
a ui:@UI_TYPE@ ;
ui:binary <{{=it.product.bundleName}}@DLL_SUFFIX@> ;
{{?!it.product.ui.userResizable}}
lv2:optionalFeature ui:noUserResize ; # doesn't work as lv2:requiredFeature, don't ask me why
{{?!it.product.ui.selfResizable}}
lv2:optionalFeature ui:fixedSize ;
{{?}}
{{?}}
lv2:requiredFeature ui:idleInterface ;
lv2:extensionData ui:idleInterface .
{{?}}

View File

@ -0,0 +1,78 @@
/*
* Tibia
*
* Copyright (C) 2024 Orastron Srl unipersonale
*
* Tibia is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Tibia is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tibia. If not, see <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo
*/
#define DATA_LV2_URI "{{=it.tibia.CGetUTF8StringLiteral(it.tibia.lv2.expandURI(it.lv2.uri))}}"
#define DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N {{=it.product.buses.filter(x => x.type == "audio" && x.direction == "input").reduce((s, x) => s += x.channels == "mono" ? 1 : 2, 0)}}
#define DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N {{=it.product.buses.filter(x => x.type == "audio" && x.direction == "output").reduce((s, x) => s += x.channels == "mono" ? 1 : 2, 0)}}
#define DATA_PRODUCT_MIDI_INPUTS_N {{=it.product.buses.filter(x => x.type == "midi" && x.direction == "input").length}}
#define DATA_PRODUCT_MIDI_OUTPUTS_N {{=it.product.buses.filter(x => x.type == "midi" && x.direction == "output").length}}
#define DATA_PRODUCT_CONTROL_INPUTS_N {{=it.product.parameters.filter(x => x.direction == "input").length}}
#define DATA_PRODUCT_CONTROL_OUTPUTS_N {{=it.product.parameters.filter(x => x.direction == "output").length}}
#if DATA_PRODUCT_MIDI_INPUTS_N > 0
static uint32_t midi_in_index[DATA_PRODUCT_MIDI_INPUTS_N] = {
{{~it.tibia.lv2.ports.filter(x => x.type == "midi" && x.direction == "input") :p}}{{=p.busIndex}}, {{~}}
};
#endif
#if DATA_PRODUCT_CONTROL_INPUTS_N > 0
# define DATA_PARAM_BYPASS 1
# define DATA_PARAM_TOGGLED (1<<1)
# define DATA_PARAM_INTEGER (1<<2)
static struct {
uint32_t index;
float min;
float max;
float def;
uint32_t flags;
} param_data[DATA_PRODUCT_CONTROL_INPUTS_N] = {
{{~it.tibia.lv2.ports.filter(x => x.type == "control" && x.direction == "input") :p}}
{
/* .index = */ {{=p.paramIndex}},
/* .min = */ {{=p.minimum.toExponential()}}f,
/* .max = */ {{=p.maximum.toExponential()}}f,
/* .def = */ {{=p.defaultValue.toExponential()}}f,
/* .flags = */ {{?p.isBypass}}DATA_PARAM_BYPASS{{??p.isLatency}}DATA_PARAM_INTEGER{{??}}0{{?p.toggled}} | DATA_PARAM_TOGGLED{{?}}{{?p.integer}} | DATA_PARAM_INTEGER{{?}}{{?}}
},
{{~}}
};
#endif
#if DATA_PRODUCT_CONTROL_OUTPUTS_N > 0
static uint32_t param_out_index[DATA_PRODUCT_CONTROL_OUTPUTS_N] = {
{{~it.tibia.lv2.ports.filter(x => x.type == "control" && x.direction == "output") :p}}{{=p.paramIndex}}, {{~}}
};
#endif
{{?it.lv2.ui}}
#define DATA_UI
#define DATA_LV2_UI_URI "{{=it.tibia.CGetUTF8StringLiteral(it.tibia.lv2.expandURI(it.lv2.ui.uri))}}"
#define DATA_UI_USER_RESIZABLE {{=it.product.ui.userResizable ? 1 : 0}}
#if DATA_PRODUCT_CONTROL_INPUTS_N > 0
static uint32_t index_to_param[DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N] = {
{{~it.tibia.lv2.ports.filter(x => x.type == "control").map((e, i) => ({ i: i, pi: e.paramIndex })).sort((a, b) => a.pi - b.pi) :p}}{{=p.i + it.tibia.lv2.ports.filter(x => x.type != "control").length}}, {{~}}
};
#endif
{{?}}

View File

@ -0,0 +1,499 @@
/*
* Tibia
*
* Copyright (C) 2024 Orastron Srl unipersonale
*
* Tibia is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Tibia is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tibia. If not, see <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo
*/
#include <stdlib.h>
#include <stdint.h>
#include "data.h"
#include "plugin_api.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#include "plugin.h"
#ifdef DATA_UI
# include "plugin_ui.h"
#endif
#pragma GCC diagnostic pop
#include "lv2/core/lv2.h"
#include "lv2/core/lv2_util.h"
#include "lv2/log/log.h"
#include "lv2/log/logger.h"
#include "lv2/urid/urid.h"
#if DATA_PRODUCT_MIDI_INPUTS_N + DATA_PRODUCT_MIDI_OUTPUTS_N > 0
# include "lv2/atom/util.h"
# include "lv2/atom/atom.h"
# include "lv2/midi/midi.h"
#endif
#ifdef DATA_UI
# include "lv2/ui/ui.h"
#endif
#include <string.h>
#if defined(__i386__) || defined(__x86_64__)
# include <xmmintrin.h>
# include <pmmintrin.h>
#endif
static inline float clampf(float x, float m, float M) {
return x < m ? m : (x > M ? M : x);
}
static float adjust_param(size_t index, float value) {
if (param_data[index].flags & DATA_PARAM_BYPASS)
value = value > 0.f ? 0.f : 1.f;
else if (param_data[index].flags & DATA_PARAM_TOGGLED)
value = value > 0.f ? 1.f : 0.f;
else if (param_data[index].flags & DATA_PARAM_INTEGER)
value = (int32_t)(value + (value >= 0.f ? 0.5f : -0.5f));
return clampf(value, param_data[index].min, param_data[index].max);
}
typedef struct {
plugin p;
#if DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N > 0
const float * x[DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N];
#endif
#if DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N > 0
float * y[DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N];
#endif
#if DATA_PRODUCT_MIDI_INPUTS_N > 0
const LV2_Atom_Sequence * x_midi[DATA_PRODUCT_MIDI_INPUTS_N];
#endif
#if DATA_PRODUCT_MIDI_OUTPUTS_N > 0
LV2_Atom_Sequence * y_midi[DATA_PRODUCT_MIDI_OUTPUTS_N];
#endif
#if (DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N) > 0
float * c[DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N];
#endif
#if DATA_PRODUCT_CONTROL_INPUTS_N > 0
float params[DATA_PRODUCT_CONTROL_INPUTS_N];
#endif
void * mem;
char * bundle_path;
LV2_Log_Logger logger;
LV2_URID_Map * map;
#if DATA_PRODUCT_MIDI_INPUTS_N + DATA_PRODUCT_MIDI_OUTPUTS_N > 0
LV2_URID uri_midi_MidiEvent;
#endif
} plugin_instance;
static const char * get_bundle_path_cb(void *handle) {
plugin_instance *instance = (plugin_instance *)handle;
return instance->bundle_path;
}
static LV2_Handle instantiate(const struct LV2_Descriptor * descriptor, double sample_rate, const char * bundle_path, const LV2_Feature * const * features) {
(void)descriptor;
(void)bundle_path;
plugin_instance *instance = malloc(sizeof(plugin_instance));
if (instance == NULL)
goto err_instance;
instance->bundle_path = strdup(bundle_path);
if (instance->bundle_path == NULL)
goto err_bundle_path;
// from https://lv2plug.in/book
const char* missing = lv2_features_query(features,
LV2_LOG__log, &instance->logger.log, false,
LV2_URID__map, &instance->map, true,
NULL);
lv2_log_logger_set_map(&instance->logger, instance->map);
if (missing) {
lv2_log_error(&instance->logger, "Missing feature <%s>\n", missing);
goto err_urid;
}
#if DATA_PRODUCT_MIDI_INPUTS_N + DATA_PRODUCT_MIDI_OUTPUTS_N > 0
instance->uri_midi_MidiEvent = instance->map->map(instance->map->handle, LV2_MIDI__MidiEvent);
#endif
plugin_callbacks cbs = {
/* .handle = */ (void *)instance,
/* .format = */ "lv2",
/* .get_bindir = */ get_bundle_path_cb,
/* .get_datadir = */ get_bundle_path_cb
};
plugin_init(&instance->p, &cbs);
plugin_set_sample_rate(&instance->p, sample_rate);
size_t req = plugin_mem_req(&instance->p);
if (req != 0) {
instance->mem = malloc(req);
if (instance->mem == NULL) {
lv2_log_error(&instance->logger, "Not enough memory\n");
goto err_mem;
}
plugin_mem_set(&instance->p, instance->mem);
} else
instance->mem = NULL;
#if DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N > 0
for (uint32_t i = 0; i < DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N; i++)
instance->x[i] = NULL;
#endif
#if DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N > 0
for (uint32_t i = 0; i < DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N; i++)
instance->y[i] = NULL;
#endif
#if DATA_PRODUCT_MIDI_INPUTS_N > 0
for (uint32_t i = 0; i < DATA_PRODUCT_MIDI_INPUTS_N; i++)
instance->x_midi[i] = NULL;
#endif
#if DATA_PRODUCT_MIDI_OUTPUTS_N > 0
for (uint32_t i = 0; i < DATA_PRODUCT_MIDI_OUTPUTS_N; i++)
instance->y_midi[i] = NULL;
#endif
#if (DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N) > 0
for (uint32_t i = 0; i < DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N; i++)
instance->c[i] = NULL;
#endif
return instance;
err_mem:
plugin_fini(&instance->p);
err_urid:
free(instance->bundle_path);
err_bundle_path:
free(instance);
err_instance:
return NULL;
}
static void connect_port(LV2_Handle instance, uint32_t port, void * data_location) {
plugin_instance * i = (plugin_instance *)instance;
#if DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N > 0
if (port < DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N) {
i->x[port] = data_location;
return;
}
port -= DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N;
#endif
#if DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N > 0
if (port < DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N) {
i->y[port] = data_location;
return;
}
port -= DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N;
#endif
#if DATA_PRODUCT_MIDI_INPUTS_N > 0
if (port < DATA_PRODUCT_MIDI_INPUTS_N) {
i->x_midi[port] = data_location;
return;
}
port -= DATA_PRODUCT_MIDI_INPUTS_N;
#endif
#if DATA_PRODUCT_MIDI_OUTPUTS_N > 0
if (port < DATA_PRODUCT_MIDI_OUTPUTS_N) {
i->y_midi[port] = data_location;
return;
}
port -= DATA_PRODUCT_MIDI_OUTPUTS_N;
#endif
#if (DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N) > 0
i->c[port] = data_location;
#endif
}
static void activate(LV2_Handle instance) {
plugin_instance * i = (plugin_instance *)instance;
#if DATA_PRODUCT_CONTROL_INPUTS_N > 0
for (uint32_t j = 0; j < DATA_PRODUCT_CONTROL_INPUTS_N; j++) {
i->params[j] = i->c[j] != NULL ? *i->c[j] : param_data[j].def;
plugin_set_parameter(&i->p, param_data[j].index, i->params[j]);
}
#endif
plugin_reset(&i->p);
}
static void run(LV2_Handle instance, uint32_t sample_count) {
plugin_instance * i = (plugin_instance *)instance;
#if defined(__aarch64__)
uint64_t fpcr;
__asm__ __volatile__ ("mrs %0, fpcr" : "=r"(fpcr));
__asm__ __volatile__ ("msr fpcr, %0" :: "r"(fpcr | 0x1000000)); // enable FZ
#elif defined(__i386__) || defined(__x86_64__)
const unsigned int flush_zero_mode = _MM_GET_FLUSH_ZERO_MODE();
const unsigned int denormals_zero_mode = _MM_GET_DENORMALS_ZERO_MODE();
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
#endif
#if DATA_PRODUCT_CONTROL_INPUTS_N > 0
for (uint32_t j = 0; j < DATA_PRODUCT_CONTROL_INPUTS_N; j++) {
if (i->c[j] == NULL)
continue;
float v = adjust_param(j, *i->c[j]);
if (v != i->params[j]) {
i->params[j] = v;
plugin_set_parameter(&i->p, param_data[j].index, v);
}
}
#endif
// from https://lv2plug.in/book
#if DATA_PRODUCT_MIDI_INPUTS_N > 0
for (size_t j = 0; j < DATA_PRODUCT_MIDI_INPUTS_N; j++) {
if (i->x_midi[j] == NULL)
continue;
LV2_ATOM_SEQUENCE_FOREACH(i->x_midi[j], ev) {
if (ev->body.type == i->uri_midi_MidiEvent) {
const uint8_t * data = (const uint8_t *)(ev + 1);
if ((data[0] & 0xf0) != 0xf0)
plugin_midi_msg_in(&i->p, midi_in_index[j], data);
}
}
}
#endif
#if DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N > 0
const float ** x = i->x;
#else
const float ** x = NULL;
#endif
#if DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N > 0
float ** y = i-> y;
#else
float ** y = NULL;
#endif
plugin_process(&i->p, x, y, sample_count);
#if DATA_PRODUCT_CONTROL_OUTPUTS_N > 0
for (uint32_t j = 0; j < DATA_PRODUCT_CONTROL_OUTPUTS_N; j++) {
uint32_t k = param_out_index[j];
if (i->c[k] != NULL)
*i->c[k] = plugin_get_parameter(&i->p, k);
}
#else
(void)plugin_get_parameter;
#endif
#if defined(__aarch64__)
__asm__ __volatile__ ("msr fpcr, %0" : : "r"(fpcr));
#elif defined(__i386__) || defined(__x86_64__)
_MM_SET_FLUSH_ZERO_MODE(flush_zero_mode);
_MM_SET_DENORMALS_ZERO_MODE(denormals_zero_mode);
#endif
}
static void cleanup(LV2_Handle instance) {
plugin_instance * i = (plugin_instance *)instance;
plugin_fini(&i->p);
if (i->mem)
free(i->mem);
free(i->bundle_path);
free(instance);
}
static const LV2_Descriptor descriptor = {
/* .URI = */ DATA_LV2_URI,
/* .instantiate = */ instantiate,
/* .connect_port = */ connect_port,
/* .activate = */ activate,
/* .run = */ run,
/* .deactivate = */ NULL,
/* .cleanup = */ cleanup,
/* .extension_data = */ NULL
};
LV2_SYMBOL_EXPORT const LV2_Descriptor * lv2_descriptor(uint32_t index) {
return index == 0 ? &descriptor : NULL;
}
#ifdef DATA_UI
typedef struct {
plugin_ui * ui;
char * bundle_path;
# if DATA_PRODUCT_CONTROL_INPUTS_N > 0
LV2UI_Write_Function write;
LV2UI_Controller controller;
char has_touch;
LV2UI_Touch touch;
# endif
} ui_instance;
# define CONTROL_INPUT_INDEX_OFFSET ( \
DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N \
+ DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N \
+ DATA_PRODUCT_MIDI_INPUTS_N \
+ DATA_PRODUCT_MIDI_OUTPUTS_N )
# define CONTROL_OUTPUT_INDEX_OFFSET (CONTROL_INPUT_INDEX_OFFSET + DATA_PRODUCT_CONTROL_INPUTS_N)
static const char * ui_get_bundle_path_cb(void *handle) {
ui_instance *instance = (ui_instance *)handle;
return instance->bundle_path;
}
# if DATA_PRODUCT_CONTROL_INPUTS_N > 0
static void ui_set_parameter_begin_cb(void *handle, size_t index, float value) {
ui_instance *instance = (ui_instance *)handle;
if (instance->has_touch) {
index = index_to_param[index];
instance->touch.touch(instance->touch.handle, index, true);
value = adjust_param(index - CONTROL_INPUT_INDEX_OFFSET, value);
instance->write(instance->controller, index, sizeof(float), 0, &value);
}
}
static void ui_set_parameter_cb(void *handle, size_t index, float value) {
ui_instance *instance = (ui_instance *)handle;
index = index_to_param[index];
value = adjust_param(index - CONTROL_INPUT_INDEX_OFFSET, value);
instance->write(instance->controller, index, sizeof(float), 0, &value);
}
static void ui_set_parameter_end_cb(void *handle, size_t index, float value) {
ui_instance *instance = (ui_instance *)handle;
if (instance->has_touch) {
index = index_to_param[index];
value = adjust_param(index - CONTROL_INPUT_INDEX_OFFSET, value);
instance->write(instance->controller, index, sizeof(float), 0, &value);
instance->touch.touch(instance->touch.handle, index, false);
}
}
# endif
static LV2UI_Handle ui_instantiate(const LV2UI_Descriptor * descriptor, const char * plugin_uri, const char * bundle_path, LV2UI_Write_Function write_function, LV2UI_Controller controller, LV2UI_Widget * widget, const LV2_Feature * const * features) {
(void)descriptor;
(void)plugin_uri;
ui_instance *instance = malloc(sizeof(ui_instance));
if (instance == NULL)
goto err_instance;
instance->bundle_path = strdup(bundle_path);
if (instance->bundle_path == NULL)
goto err_bundle_path;
char has_parent = 0;
void *parent = NULL;
instance->has_touch = 0;
for (size_t i = 0; features[i] != NULL; i++) {
if (!strcmp(features[i]->URI, LV2_UI__parent)) {
has_parent = 1;
parent = features[i]->data;
}
if (!strcmp(features[i]->URI, LV2_UI__touch)) {
instance->has_touch = 1;
instance->touch = *((LV2UI_Touch *)features[i]->data);
}
}
plugin_ui_callbacks cbs = {
/* .handle = */ (void *)instance,
/* .format = */ "lv2",
/* .get_bindir = */ ui_get_bundle_path_cb,
/* .get_datadir = */ ui_get_bundle_path_cb,
# if DATA_PRODUCT_CONTROL_INPUTS_N > 0
/* .set_parameter_begin = */ ui_set_parameter_begin_cb,
/* .set_parameter = */ ui_set_parameter_cb,
/* .set_parameter_end = */ ui_set_parameter_end_cb
# else
/* .set_parameter_begin = */ NULL,
/* .set_parameter = */ NULL,
/* .set_parameter_end = */ NULL
# endif
};
# if DATA_PRODUCT_CONTROL_INPUTS_N > 0
instance->write = write_function;
instance->controller = controller;
# else
(void)write_function;
(void)controller;
# endif
instance->ui = plugin_ui_create(has_parent, parent, &cbs);
if (instance->ui == NULL)
goto err_create;
*widget = instance->ui->widget;
return instance;
err_create:
free(instance->bundle_path);
err_bundle_path:
free(instance);
err_instance:
*widget = NULL;
return NULL;
}
static void ui_cleanup(LV2UI_Handle handle) {
ui_instance *instance = (ui_instance *)handle;
plugin_ui_free(instance->ui);
free(instance->bundle_path);
free(instance);
}
# if DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N > 0
static void ui_port_event(LV2UI_Handle handle, uint32_t port_index, uint32_t buffer_size, uint32_t format, const void * buffer) {
(void)buffer_size;
(void)format;
ui_instance *instance = (ui_instance *)handle;
# if DATA_PRODUCT_CONTROL_INPUTS_N > 0
if (port_index < CONTROL_OUTPUT_INDEX_OFFSET) {
size_t index = port_index - CONTROL_INPUT_INDEX_OFFSET;
plugin_ui_set_parameter(instance->ui, param_data[index].index, adjust_param(index, *((float *)buffer)));
}
# endif
# if DATA_PRODUCT_CONTROL_OUTPUTS_N > 0
# if DATA_PRODUCT_CONTROL_INPUTS_N > 0
else
# endif
plugin_ui_set_parameter(instance->ui, param_out_index[port_index - CONTROL_OUTPUT_INDEX_OFFSET], *((float *)buffer));
# endif
}
# endif
static int ui_idle(LV2UI_Handle handle) {
ui_instance *instance = (ui_instance *)handle;
plugin_ui_idle(instance->ui);
return 0;
}
static const void * ui_extension_data(const char * uri) {
static const LV2UI_Idle_Interface idle = { ui_idle };
if (!strcmp(uri, LV2_UI__idleInterface))
return &idle;
return NULL;
}
static const LV2UI_Descriptor ui_descriptor = {
/* .URI = */ DATA_LV2_UI_URI,
/* .instantiate = */ ui_instantiate,
/* .cleanup = */ ui_cleanup,
# if DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N > 0
/* .port_event = */ ui_port_event,
# else
/* .port_event = */ NULL,
# endif
/* .extension_data = */ ui_extension_data
};
LV2_SYMBOL_EXPORT const LV2UI_Descriptor * lv2ui_descriptor(uint32_t index) {
return index == 0 ? &ui_descriptor : NULL;
}
#endif

View File

@ -0,0 +1,136 @@
/*
* Tibia
*
* Copyright (C) 2024 Orastron Srl unipersonale
*
* Tibia is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Tibia is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tibia. If not, see <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo
*/
var path = require("path");
var sep = path.sep;
module.exports = function (data, api, outputCommon, outputData) {
if (outputData) {
data.tibia.lv2 = {
prefixes: [
{ id: "atom", uri: "http://lv2plug.in/ns/ext/atom#" },
{ id: "doap", uri: "http://usefulinc.com/ns/doap#" },
{ id: "foaf", uri: "http://xmlns.com/foaf/0.1/" },
{ id: "log", uri: "http://lv2plug.in/ns/ext/log#" },
{ id: "lv2", uri: "http://lv2plug.in/ns/lv2core#" },
{ id: "midi", uri: "http://lv2plug.in/ns/ext/midi#" },
{ id: "patch", uri: "http://lv2plug.in/ns/ext/patch#" },
{ id: "pprops", uri: "http://lv2plug.in/ns/ext/port-props#" },
{ id: "rdf", uri: "http://www.w3.org/1999/02/22-rdf-syntax-ns#" },
{ id: "rdfs", uri: "http://www.w3.org/2000/01/rdf-schema#" },
{ id: "ui", uri: "http://lv2plug.in/ns/extensions/ui#" },
{ id: "units", uri: "http://lv2plug.in/ns/extensions/units#" },
{ id: "urid", uri: "http://lv2plug.in/ns/ext/urid#" }
],
units: {
"bar": "@units:bar",
"beat": "@units:beat",
"bpm": "@units:bpm",
"cent": "@units:cent",
"cm": "@units:cm",
"coef": "@units:coef",
"db": "@units:db",
"degree": "@units:degree",
"frame": "@units:frame",
"hz": "@units:hz",
"inch": "@units:inch",
"khz": "@units:khz",
"km": "@units:km",
"m": "@units:m",
"mhz": "@units:mhz",
"midiNote": "@units:midiNote",
"mile": "@units:mile",
"min": "@units:min",
"mm": "@units:mm",
"ms": "@units:ms",
"oct": "@units:oct",
"pc": "@units:pc",
"s": "@units:s",
"semitone12TET": "@units:semitone12TET"
},
ports: [],
ttlURI: function (uri) {
if (uri.charAt(0) == "@") {
if (uri.indexOf("#") == -1)
return uri.substring(1);
uri = data.tibia.lv2.expandURI(uri);
}
return "<" + uri + ">";
},
expandURI: function (uri) {
if (uri.charAt(0) != "@")
return uri;
var i = uri.indexOf(":");
var p = uri.substring(1, uri.indexOf(":"));
return data.tibia.lv2.prefixes.find(x => x.id == p).uri + uri.substring(i + 1);
}
};
for (var id in data.lv2.prefixes)
data.tibia.lv2.prefixes.push({ id: id, uri: data.lv2.prefixes[id] });
data.tibia.lv2.prefixes.push({ id: "plugin", uri: data.tibia.lv2.expandURI(data.lv2.uri) + "#" });
var buses = data.product.buses;
var audioPorts = [];
var midiPorts = [];
for (var bi = 0; bi < buses.length; bi++) {
var b = buses[bi];
if (b.type == "audio") {
if (b.channels == "mono") {
var e = { type: "audio", direction: b.direction, name: b.name, sidechain: b.sidechain, cv: b.cv, optional: b.optional, busIndex: bi, id: b.id };
audioPorts.push(e);
} else {
var e = { type: "audio", direction: b.direction, name: b.name + " Left", shortName: b.shortName + " L", sidechain: b.sidechain, cv: b.cv, busIndex: bi, id: b.id + "_l" };
audioPorts.push(e);
var e = { type: "audio", direction: b.direction, name: b.name + " Right", shortName: b.shortName + " R", sidechain: b.sidechain, cv: b.cv, busIndex: bi, id: b.id + "_r" };
audioPorts.push(e);
}
} else {
var e = { type: "midi", direction: b.direction, name: b.name, sidechain: b.sidechain, control: b.control, optional: b.optional, busIndex: bi, id: b.id };
midiPorts.push(e);
}
}
audioPorts.sort((a, b) => a.direction != b.direction ? (a.direction == "input" ? -1 : 1) : 0);
midiPorts.sort((a, b) => a.direction != b.direction ? (a.direction == "input" ? -1 : 1) : 0);
data.tibia.lv2.ports.push.apply(data.tibia.lv2.ports, audioPorts);
data.tibia.lv2.ports.push.apply(data.tibia.lv2.ports, midiPorts);
var hasCtrlIn = false;
var hasCtrlOut = false;
for (var i = 0; i < data.product.parameters.length && !(hasCtrlIn && hasCtrlOut); i++) {
var p = data.product.parameters[i];
if (p.direction == "input")
hasCtrlIn = true;
else
hasCtrlOut = true;
}
if (hasCtrlIn)
data.tibia.lv2.ports.push({ type: "param", direction: "input", name: "Control in", id: "control_in", control: true });
if (hasCtrlOut)
data.tibia.lv2.ports.push({ type: "param", direction: "output", name: "Control out", id: "control_out", control: true });
}
api.generateFileFromTemplateFile(`data${sep}manifest.ttl.in`, `data${sep}manifest.ttl.in`, data);
api.copyFile(`src${sep}lv2.c`, `src${sep}lv2.c`);
api.generateFileFromTemplateFile(`src${sep}data.h`, `src${sep}data.h`, data);
};

View File

@ -31,11 +31,20 @@
lv2:optionalFeature state:threadSafeRestore ;
{{?}}
{{?it.product.ui}}
ui:ui {{=it.tibia.lv2.ttlURI(it.lv2.ui.uri)}} ;
ui:ui plugin:ui ;
{{?}}
{{?(it.product.state && it.product.state.dspCustom)}}
lv2:extensionData state:interface ;
{{?}}
{{~it.tibia.lv2.parameters:p:i}}
{{?p.direction == "input"}}
patch:writable plugin:{{=p.id}};
{{??}}
patch:readable plugin:{{=p.id}};
{{?}}
{{~}}
lv2:port [
{{~it.tibia.lv2.ports :p:i}}
{{?p.isBypass}}
@ -68,6 +77,22 @@
lv2:portProperty lv2:connectionOptional ;
lv2:portProperty lv2:integer ;
lv2:portProperty lv2:reportsLatency ;
{{??p.isInputParameterMessage}}
a lv2:InputPort ,
atom:AtomPort ;
atom:bufferType atom:Sequence ;
atom:supports patch:Message ;
lv2:designation lv2:control ;
lv2:symbol "InputParameterMessage" ;
lv2:name "InputParameterMessage" ;
{{??p.isOutputParameterMessage}}
a lv2:OutputPort ,
atom:AtomPort ;
atom:bufferType atom:Sequence ;
atom:supports patch:Message ;
lv2:designation lv2:control ;
lv2:symbol "OutputParameterMessage" ;
lv2:name "OutputParameterMessage" ;
{{??}}
a {{?p.type == "control"}}lv2:ControlPort{{??p.type == "midi"}}atom:AtomPort{{??}}{{?p.cv}}lv2:CVPort{{??}}lv2:AudioPort{{?}}{{?}} ,
{{?p.direction == "input"}}lv2:InputPort{{??}}lv2:OutputPort{{?}} ;
@ -129,8 +154,22 @@
{{?}}
{{~}}
{{~it.tibia.lv2.parameters:p:i}}
plugin:{{=p.id}}
a lv2:Parameter ;
rdfs:label "{{=p.name}}" ;
rdfs:range {{?p.toggled}}atom:Bool{{??p.integer}}atom:Int{{??}}atom:Float{{?}} ;
{{?p.unit && p.unit in it.tibia.lv2.units}}
units:unit {{=it.tibia.lv2.ttlURI(it.tibia.lv2.units[p.unit])}} ;
{{?}}
lv2:minimum {{=p.minimum.toExponential()}} ;
lv2:maximum {{=p.maximum.toExponential()}} ;
lv2:default {{=p.defaultValue.toExponential()}} .
{{~}}
{{?it.product.ui}}
{{=it.tibia.lv2.ttlURI(it.lv2.ui.uri)}}
plugin:ui
a ui:@UI_TYPE@ ;
ui:binary <{{=it.product.bundleName}}@DLL_SUFFIX@> ;
{{?!it.product.ui.userResizable}}

View File

@ -37,12 +37,56 @@ static uint32_t midi_in_index[DATA_PRODUCT_MIDI_INPUTS_N] = {
};
#endif
#if DATA_PRODUCT_CONTROL_INPUTS_N > 0
# define DATA_PARAM_BYPASS 1
# define DATA_PARAM_TOGGLED (1<<1)
# define DATA_PARAM_INTEGER (1<<2)
{{?it.lv2.use_parameters}}
#define DATA_PRODUCT_USE_PARAMETERS 1
{{?it.tibia.lv2.ports.find(p => p.isInputParameterMessage)}}
#define DATA_PRODUCT_IPM {{=it.tibia.lv2.ports.indexOf(it.tibia.lv2.ports.find(p => p.isInputParameterMessage))}}
{{?}}
{{?it.tibia.lv2.ports.find(p => p.isOutputParameterMessage)}}
#define DATA_PRODUCT_OPM {{=it.tibia.lv2.ports.indexOf(it.tibia.lv2.ports.find(p => p.isOutputParameterMessage))}}
{{?}}
#if DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N > 0
static struct {
uint32_t index;
float min;
float max;
float def;
uint32_t flags;
const char *id;
} param_data[DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N] = {
{{~it.tibia.lv2.parameters :p}}
{
/* .index = */ {{=p.paramIndex}},
/* .min = */ {{=p.minimum.toExponential()}}f,
/* .max = */ {{=p.maximum.toExponential()}}f,
/* .def = */ {{=p.defaultValue.toExponential()}}f,
/* .flags = */ {{?p.isBypass}}DATA_PARAM_BYPASS{{??p.isLatency}}DATA_PARAM_INTEGER{{??}}0{{?p.toggled}} | DATA_PARAM_TOGGLED{{?}}{{?p.integer}} | DATA_PARAM_INTEGER{{?}}{{?}},
/* .id = */ DATA_LV2_URI"#{{=p.id}}"
},
{{~}}
};
#endif
#if DATA_PRODUCT_CONTROL_OUTPUTS_N > 0
static uint32_t param_out_index[DATA_PRODUCT_CONTROL_OUTPUTS_N] = {
{{~it.tibia.lv2.parameters.filter(x => x.direction == "output") :p}}{{=p.paramIndex}}, {{~}}
};
#endif
{{??}}
#if DATA_PRODUCT_CONTROL_INPUTS_N > 0
static struct {
uint32_t index;
float min;
@ -69,9 +113,11 @@ static uint32_t param_out_index[DATA_PRODUCT_CONTROL_OUTPUTS_N] = {
};
#endif
{{?}}
{{?it.product.ui}}
#define DATA_UI
#define DATA_LV2_UI_URI "{{=it.tibia.CGetUTF8StringLiteral(it.tibia.lv2.expandURI(it.lv2.ui.uri))}}"
#define DATA_LV2_UI_URI "{{=it.tibia.CGetUTF8StringLiteral(it.tibia.lv2.expandURI(it.lv2.uri + '#ui'))}}"
#define DATA_UI_USER_RESIZABLE {{=it.product.ui.userResizable ? 1 : 0}}
{{?}}

View File

@ -49,6 +49,10 @@
#ifdef DATA_STATE_DSP_CUSTOM
# include <lv2/state/state.h>
#endif
#if DATA_PRODUCT_USE_PARAMETERS
# include "lv2/lv2plug.in/ns/ext/patch/patch.h"
# include <lv2/lv2plug.in/ns/ext/atom/forge.h>
#endif
#include <string.h>
@ -58,11 +62,7 @@
#endif
#if (DATA_PRODUCT_CONTROL_INPUTS_N > 0) && defined(DATA_STATE_DSP_CUSTOM)
# ifdef __cplusplus
# include <atomic>
# else
# include <stdatomic.h>
# endif
# include <stdatomic.h>
# if defined(_WIN32) || defined(__CYGWIN__)
# include <processthreadsapi.h>
# define yield SwitchToThread
@ -97,7 +97,6 @@ static float adjust_param(size_t index, float value) {
typedef struct {
plugin p;
float sample_rate;
#if DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N > 0
const float * x[DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N];
#endif
@ -110,18 +109,11 @@ typedef struct {
#if DATA_PRODUCT_MIDI_OUTPUTS_N > 0
LV2_Atom_Sequence * y_midi[DATA_PRODUCT_MIDI_OUTPUTS_N];
#endif
#if (DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N) > 0
float * c[DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N];
#endif
#if DATA_PRODUCT_CONTROL_INPUTS_N > 0
float params[DATA_PRODUCT_CONTROL_INPUTS_N];
# ifdef DATA_STATE_DSP_CUSTOM
float params_sync[DATA_PRODUCT_CONTROL_INPUTS_N];
# ifdef __cplusplus
std::atomic_flag sync_lock_flag;
# else
atomic_flag sync_lock_flag;
# endif
char synced;
char loaded;
# endif
@ -140,6 +132,30 @@ typedef struct {
LV2_State_Store_Function state_store;
LV2_State_Handle state_handle;
#endif
#if (DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N) > 0
# if DATA_PRODUCT_USE_PARAMETERS
LV2_URID uri_atom_Blank;
LV2_URID uri_atom_Object;
LV2_URID uri_atom_URID;
LV2_URID uri_atom_Float;
LV2_URID uri_atom_Bool;
LV2_URID uri_patch_Set;
LV2_URID uri_patch_Get;
LV2_URID uri_patch_property;
LV2_URID uri_patch_value;
LV2_URID uri_parameters[DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N]; // TODO: Fix 0 params case
# if DATA_PRODUCT_IPM
const LV2_Atom_Sequence *controlIn;
# endif
# if DATA_PRODUCT_OPM
const LV2_Atom_Sequence *controlOut;
LV2_Atom_Forge forge;
LV2_Atom_Float output_parameter_atoms[DATA_PRODUCT_CONTROL_OUTPUTS_N];
# endif
# else
float *c[DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N];
# endif
#endif
} plugin_instance;
static const char * get_bundle_path_cb(void *handle) {
@ -150,22 +166,14 @@ static const char * get_bundle_path_cb(void *handle) {
#ifdef DATA_STATE_DSP_CUSTOM
static void state_lock_cb(void *handle) {
plugin_instance * i = (plugin_instance *)handle;
# ifdef __cplusplus
while (i->sync_lock_flag.test_and_set())
# else
while (atomic_flag_test_and_set(&i->sync_lock_flag))
# endif
yield();
i->synced = 0;
}
static void state_unlock_cb(void *handle) {
plugin_instance * i = (plugin_instance *)handle;
# ifdef __cplusplus
i->sync_lock_flag.clear();
# else
atomic_flag_clear(&i->sync_lock_flag);
# endif
}
static int state_write_cb(void *handle, const char *data, size_t length) {
@ -188,12 +196,7 @@ static LV2_Handle instantiate(const struct LV2_Descriptor * descriptor, double s
(void)descriptor;
(void)bundle_path;
// make C++ compilers happy
const char * missing;
plugin_callbacks cbs;
size_t req;
plugin_instance *instance = (plugin_instance *)malloc(sizeof(plugin_instance));
plugin_instance *instance = malloc(sizeof(plugin_instance));
if (instance == NULL)
goto err_instance;
@ -202,7 +205,7 @@ static LV2_Handle instantiate(const struct LV2_Descriptor * descriptor, double s
goto err_bundle_path;
// from https://lv2plug.in/book
missing = lv2_features_query(features,
const char * missing = lv2_features_query(features,
LV2_LOG__log, &instance->logger.log, false,
LV2_URID__map, &instance->map, true,
NULL);
@ -226,15 +229,16 @@ static LV2_Handle instantiate(const struct LV2_Descriptor * descriptor, double s
}
#endif
cbs.handle = (void *)instance;
cbs.format = "lv2";
cbs.get_bindir = get_bundle_path_cb;
cbs.get_datadir = get_bundle_path_cb;
plugin_callbacks cbs = {
/* .handle = */ (void *)instance,
/* .format = */ "lv2",
/* .get_bindir = */ get_bundle_path_cb,
/* .get_datadir = */ get_bundle_path_cb
};
plugin_init(&instance->p, &cbs);
instance->sample_rate = (float)sample_rate;
plugin_set_sample_rate(&instance->p, instance->sample_rate);
req = plugin_mem_req(&instance->p);
plugin_set_sample_rate(&instance->p, sample_rate);
size_t req = plugin_mem_req(&instance->p);
if (req != 0) {
instance->mem = malloc(req);
if (instance->mem == NULL) {
@ -262,8 +266,29 @@ static LV2_Handle instantiate(const struct LV2_Descriptor * descriptor, double s
instance->y_midi[i] = NULL;
#endif
#if (DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N) > 0
# if DATA_PRODUCT_USE_PARAMETERS
instance->uri_atom_Blank = instance->map->map (instance->map->handle, LV2_ATOM__Blank);
instance->uri_atom_Object = instance->map->map (instance->map->handle, LV2_ATOM__Object);
instance->uri_atom_URID = instance->map->map (instance->map->handle, LV2_ATOM__URID);
instance->uri_atom_Float = instance->map->map (instance->map->handle, LV2_ATOM__Float);
instance->uri_atom_Bool = instance->map->map (instance->map->handle, LV2_ATOM__Bool);
instance->uri_patch_Set = instance->map->map (instance->map->handle, LV2_PATCH__Set);
instance->uri_patch_Get = instance->map->map (instance->map->handle, LV2_PATCH__Get);
instance->uri_patch_property = instance->map->map (instance->map->handle, LV2_PATCH__property);
instance->uri_patch_value = instance->map->map (instance->map->handle, LV2_PATCH__value);
for (int i = 0; i < DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N; i++) {
instance->uri_parameters[i] = instance->map->map (instance->map->handle, param_data[i].id);
}
lv2_atom_forge_init(&instance->forge, instance->map);
for (int aa = 0; aa < DATA_PRODUCT_CONTROL_OUTPUTS_N; aa++) {
instance->output_parameter_atoms[aa].atom.size = sizeof(float);
instance->output_parameter_atoms[aa].atom.type = instance->uri_atom_Float;
instance->output_parameter_atoms[aa].body = param_data[param_out_index[aa]].def;
}
# else
for (uint32_t i = 0; i < DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N; i++)
instance->c[i] = NULL;
# endif
#endif
return instance;
@ -281,37 +306,56 @@ err_instance:
}
static void connect_port(LV2_Handle instance, uint32_t port, void * data_location) {
#if DATA_PRODUCT_USE_PARAMETERS
const uint32_t port0 = port;
#endif
plugin_instance * i = (plugin_instance *)instance;
#if DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N > 0
if (port < DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N) {
i->x[port] = (const float *)data_location;
i->x[port] = data_location;
return;
}
port -= DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N;
#endif
#if DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N > 0
if (port < DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N) {
i->y[port] = (float *)data_location;
i->y[port] = data_location;
return;
}
port -= DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N;
#endif
#if DATA_PRODUCT_MIDI_INPUTS_N > 0
if (port < DATA_PRODUCT_MIDI_INPUTS_N) {
i->x_midi[port] = (const LV2_Atom_Sequence *)data_location;
i->x_midi[port] = data_location;
return;
}
port -= DATA_PRODUCT_MIDI_INPUTS_N;
#endif
#if DATA_PRODUCT_MIDI_OUTPUTS_N > 0
if (port < DATA_PRODUCT_MIDI_OUTPUTS_N) {
i->y_midi[port] = (LV2_Atom_Sequence *)data_location;
i->y_midi[port] = data_location;
return;
}
port -= DATA_PRODUCT_MIDI_OUTPUTS_N;
#endif
#if (DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N) > 0
i->c[port] = (float *)data_location;
#if DATA_PRODUCT_USE_PARAMETERS
# if DATA_PRODUCT_IPM
if (port0 == DATA_PRODUCT_IPM) {
i->controlIn = (const LV2_Atom_Sequence*) data_location;
return;
}
# endif
# if DATA_PRODUCT_OPM
if (port0 == DATA_PRODUCT_OPM) {
i->controlOut = (const LV2_Atom_Sequence*) data_location;
return;
}
# endif
#else
# if (DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N) > 0
i->c[port] = data_location;
# endif
#endif
}
@ -319,19 +363,19 @@ static void activate(LV2_Handle instance) {
plugin_instance * i = (plugin_instance *)instance;
#if DATA_PRODUCT_CONTROL_INPUTS_N > 0
for (uint32_t j = 0; j < DATA_PRODUCT_CONTROL_INPUTS_N; j++) {
# if DATA_PRODUCT_USE_PARAMETERS
i->params[j] = param_data[j].def;
# else
i->params[j] = i->c[j] != NULL ? *i->c[j] : param_data[j].def;
# endif
plugin_set_parameter(&i->p, param_data[j].index, i->params[j]);
}
# ifdef DATA_STATE_DSP_CUSTOM
for (uint32_t j = 0; j < DATA_PRODUCT_CONTROL_INPUTS_N; j++)
i->params_sync[j] = i->params[j];
# ifdef __cplusplus
i->sync_lock_flag.clear();
# else
// why is this not correct?
// i->sync_lock_flag = ATOMIC_FLAG_INIT;
atomic_flag_clear(&i->sync_lock_flag);
# endif
i->synced = 1;
i->loaded = 0;
# endif
@ -339,9 +383,32 @@ static void activate(LV2_Handle instance) {
plugin_reset(&i->p);
}
#if DATA_PRODUCT_USE_PARAMETERS
static inline int getParamIndexByURI(plugin_instance *instance, LV2_URID uri) {
for (int i = 0; i < DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N; i++)
if (instance->uri_parameters[i] == uri)
return i;
return -1;
}
static LV2_State_Status write_param_to_forge(LV2_State_Handle handle, uint32_t key, const void *value, size_t size, uint32_t type) {
LV2_Atom_Forge* forge = (LV2_Atom_Forge*)handle;
if (!lv2_atom_forge_key(forge, key) || !lv2_atom_forge_atom(forge, size, type) || !lv2_atom_forge_write(forge, value, size))
return LV2_STATE_ERR_UNKNOWN;
return LV2_STATE_SUCCESS;
}
#endif
static void run(LV2_Handle instance, uint32_t sample_count) {
plugin_instance * i = (plugin_instance *)instance;
#if DATA_PRODUCT_USE_PARAMETERS
const uint32_t out_capacity = i->controlOut->atom.size;
lv2_atom_forge_set_buffer(&i->forge, (uint8_t*)i->controlOut, out_capacity);
LV2_Atom_Forge_Frame out_frame;
lv2_atom_forge_sequence_head(&i->forge, &out_frame, 0);
#endif
#if defined(__aarch64__)
uint64_t fpcr;
__asm__ __volatile__ ("mrs %0, fpcr" : "=r"(fpcr));
@ -356,11 +423,7 @@ static void run(LV2_Handle instance, uint32_t sample_count) {
#if DATA_PRODUCT_CONTROL_INPUTS_N > 0
# ifdef DATA_STATE_DSP_CUSTOM
# ifdef __cplusplus
_Bool locked = !i->sync_lock_flag.test_and_set();
# else
_Bool locked = !atomic_flag_test_and_set(&i->sync_lock_flag);
# endif
if (locked) {
if (!i->synced) {
if (i->loaded) {
@ -381,30 +444,96 @@ static void run(LV2_Handle instance, uint32_t sample_count) {
}
# endif
# if DATA_PRODUCT_USE_PARAMETERS
if (i->controlIn && i->map) {
LV2_ATOM_SEQUENCE_FOREACH (i->controlIn, ev) {
if (ev->body.type != i->uri_atom_Object) {
continue;
}
const LV2_Atom_Object *obj = (LV2_Atom_Object*)&ev->body;
if (obj->body.otype == i->uri_patch_Set) {
const LV2_Atom* property = NULL;
lv2_atom_object_get (obj, i->uri_patch_property, &property, 0);
if (!property || property->type != i->uri_atom_URID)
continue;
const LV2_Atom* val = NULL;
lv2_atom_object_get (obj, i->uri_patch_value, &val, 0);
if (!val)
continue;
int index = getParamIndexByURI(i, ((LV2_Atom_URID*)property)->body);
if (index < 0)
continue;
float v = adjust_param(index, *((float*)(val + 1)));
if (v != i->params[index]) {
i->params[index] = v;
# ifdef DATA_STATE_DSP_CUSTOM
if (locked) {
i->params_sync[index] = i->params[index];
# endif
plugin_set_parameter(&i->p, param_data[index].index, v);
# ifdef DATA_STATE_DSP_CUSTOM
}
# endif
}
}
else if (obj->body.otype == i->uri_patch_Get) {
const LV2_Atom_URID *property = NULL;
lv2_atom_object_get(obj, i->uri_patch_property, (const LV2_Atom**)&property, 0);
if (!property || property->atom.type != i->uri_atom_URID)
continue;
const LV2_URID key = property->body;
const int index = getParamIndexByURI(i, key);
if (index < 0)
continue;
int outIndex = -1;
for (int p = 0; p < DATA_PRODUCT_CONTROL_OUTPUTS_N; p++) {
if (param_out_index[p] == (uint32_t) index)
outIndex = p;
}
if (outIndex == -1)
continue;
const LV2_Atom* value = &i->output_parameter_atoms[outIndex].atom;
LV2_Atom_Forge_Frame frame;
lv2_atom_forge_frame_time(&i->forge, ev->time.frames);
lv2_atom_forge_object( &i->forge, &frame, 0, i->uri_patch_Set);
lv2_atom_forge_key( &i->forge, i->uri_patch_property);
lv2_atom_forge_urid( &i->forge, property->body);
write_param_to_forge( &i->forge, i->uri_patch_value, value + 1, value->size, value->type);
lv2_atom_forge_pop( &i->forge, &frame);
}
}
}
# else
for (uint32_t j = 0; j < DATA_PRODUCT_CONTROL_INPUTS_N; j++) {
if (i->c[j] == NULL)
continue;
float v = adjust_param(j, *i->c[j]);
if (v != i->params[j]) {
i->params[j] = v;
# ifdef DATA_STATE_DSP_CUSTOM
# ifdef DATA_STATE_DSP_CUSTOM
if (locked) {
i->params_sync[j] = i->params[j];
# endif
# endif
plugin_set_parameter(&i->p, param_data[j].index, v);
# ifdef DATA_STATE_DSP_CUSTOM
# ifdef DATA_STATE_DSP_CUSTOM
}
# endif
# endif
}
}
# endif
# ifdef DATA_STATE_DSP_CUSTOM
if (locked)
# ifdef __cplusplus
i->sync_lock_flag.clear();
# else
atomic_flag_clear(&i->sync_lock_flag);
# endif
# endif
#endif
@ -437,11 +566,31 @@ static void run(LV2_Handle instance, uint32_t sample_count) {
plugin_process(&i->p, x, y, sample_count);
#if DATA_PRODUCT_CONTROL_OUTPUTS_N > 0
# if DATA_PRODUCT_USE_PARAMETERS
for (uint32_t j = 0; j < DATA_PRODUCT_CONTROL_OUTPUTS_N; j++) {
float v = plugin_get_parameter(&i->p, param_out_index[j]);
i->output_parameter_atoms[j].body = v;
lv2_atom_forge_frame_time(&i->forge, 0);
LV2_Atom_Forge_Frame frame;
lv2_atom_forge_object(&i->forge, &frame, 0, i->uri_patch_Set);
lv2_atom_forge_key( &i->forge, i->uri_patch_property);
lv2_atom_forge_urid( &i->forge, i->uri_parameters[param_out_index[j]]);
lv2_atom_forge_key( &i->forge, i->uri_patch_value);
lv2_atom_forge_float( &i->forge, i->output_parameter_atoms[j].body);
lv2_atom_forge_pop( &i->forge, &frame);
}
lv2_atom_forge_pop(&i->forge, &out_frame);
# else
for (uint32_t j = 0; j < DATA_PRODUCT_CONTROL_OUTPUTS_N; j++) {
uint32_t k = param_out_index[j];
if (i->c[k] != NULL)
*i->c[k] = plugin_get_parameter(&i->p, k);
}
# endif
#else
(void)plugin_get_parameter;
#endif
@ -452,6 +601,7 @@ static void run(LV2_Handle instance, uint32_t sample_count) {
_MM_SET_FLUSH_ZERO_MODE(flush_zero_mode);
_MM_SET_DENORMALS_ZERO_MODE(denormals_zero_mode);
#endif
}
static void cleanup(LV2_Handle instance) {
@ -484,7 +634,7 @@ static LV2_State_Status state_save(LV2_Handle instance, LV2_State_Store_Function
/* .set_parameter = */ NULL
# endif
};
return plugin_state_save(&i->p, &cbs, i->sample_rate) == 0 ? LV2_STATE_SUCCESS : LV2_STATE_ERR_UNKNOWN;
return plugin_state_save(&i->p, &cbs) == 0 ? LV2_STATE_SUCCESS : LV2_STATE_ERR_UNKNOWN;
}
static LV2_State_Status state_restore(LV2_Handle instance, LV2_State_Retrieve_Function retrieve, LV2_State_Handle handle, uint32_t flags, const LV2_Feature * const * features) {
@ -498,7 +648,7 @@ static LV2_State_Status state_restore(LV2_Handle instance, LV2_State_Retrieve_Fu
}
size_t length;
uint32_t type, xflags; // jalv 1.6.6 crashes using NULL as per spec, so we have these two
const char * data = (const char *)retrieve(handle, i->uri_state_data, &length, &type, &xflags);
const char * data = retrieve(handle, i->uri_state_data, &length, &type, &xflags);
if (data == NULL) {
lv2_log_error(&i->logger, "Cannot restore state since property <%s> could not be retrieved\n", DATA_LV2_URI "#state_data");
return LV2_STATE_ERR_NO_PROPERTY;
@ -512,7 +662,7 @@ static LV2_State_Status state_restore(LV2_Handle instance, LV2_State_Retrieve_Fu
/* .set_parameter = */ state_set_parameter_cb
# endif
};
return plugin_state_load(&cbs, i->sample_rate, data, length) == 0 ? LV2_STATE_SUCCESS : LV2_STATE_ERR_UNKNOWN;
return plugin_state_load(&cbs, data, length) == 0 ? LV2_STATE_SUCCESS : LV2_STATE_ERR_UNKNOWN;
}
static const void * extension_data(const char * uri) {
@ -592,12 +742,7 @@ static LV2UI_Handle ui_instantiate(const LV2UI_Descriptor * descriptor, const ch
(void)descriptor;
(void)plugin_uri;
// make C++ compilers happy
char has_parent;
void *parent;
plugin_ui_callbacks cbs;
ui_instance *instance = (ui_instance *)malloc(sizeof(ui_instance));
ui_instance *instance = malloc(sizeof(ui_instance));
if (instance == NULL)
goto err_instance;
@ -605,8 +750,8 @@ static LV2UI_Handle ui_instantiate(const LV2UI_Descriptor * descriptor, const ch
if (instance->bundle_path == NULL)
goto err_bundle_path;
has_parent = 0;
parent = NULL;
char has_parent = 0;
void *parent = NULL;
# if DATA_PRODUCT_CONTROL_INPUTS_N > 0
instance->has_touch = 0;
# endif
@ -623,15 +768,17 @@ static LV2UI_Handle ui_instantiate(const LV2UI_Descriptor * descriptor, const ch
# endif
}
cbs.handle = (void *)instance;
cbs.format = "lv2";
cbs.get_bindir = ui_get_bundle_path_cb;
cbs.get_datadir = ui_get_bundle_path_cb;
plugin_ui_callbacks cbs = {
/* .handle = */ (void *)instance,
/* .format = */ "lv2",
/* .get_bindir = */ ui_get_bundle_path_cb,
/* .get_datadir = */ ui_get_bundle_path_cb,
# if DATA_PRODUCT_CONTROL_INPUTS_N > 0
cbs.set_parameter_begin = ui_set_parameter_begin_cb;
cbs.set_parameter = ui_set_parameter_cb;
cbs.set_parameter_end = ui_set_parameter_end_cb;
/* .set_parameter_begin = */ ui_set_parameter_begin_cb,
/* .set_parameter = */ ui_set_parameter_cb,
/* .set_parameter_end = */ ui_set_parameter_end_cb,
# endif
};
# if DATA_PRODUCT_CONTROL_INPUTS_N > 0
instance->write = write_function;
instance->controller = controller;

View File

@ -37,7 +37,8 @@ module.exports = function (data, api, outputCommon, outputData) {
{ id: "state", uri: "http://lv2plug.in/ns/extensions/state#" },
{ id: "ui", uri: "http://lv2plug.in/ns/extensions/ui#" },
{ id: "units", uri: "http://lv2plug.in/ns/extensions/units#" },
{ id: "urid", uri: "http://lv2plug.in/ns/ext/urid#" }
{ id: "urid", uri: "http://lv2plug.in/ns/ext/urid#" },
{ id: "patch", uri: "http://lv2plug.in/ns/ext/patch#"}
],
units: {
"bar": "@units:bar",
@ -88,6 +89,8 @@ module.exports = function (data, api, outputCommon, outputData) {
for (var id in data.lv2.prefixes)
data.tibia.lv2.prefixes.push({ id: id, uri: data.lv2.prefixes[id] });
data.tibia.lv2.prefixes.push({ id: "plugin", uri: data.tibia.lv2.expandURI(data.lv2.uri) + "#" });
var buses = data.product.buses;
var audioPorts = [];
var midiPorts = [];
@ -113,16 +116,38 @@ module.exports = function (data, api, outputCommon, outputData) {
data.tibia.lv2.ports.push.apply(data.tibia.lv2.ports, audioPorts);
data.tibia.lv2.ports.push.apply(data.tibia.lv2.ports, midiPorts);
var ports = [];
for (var i = 0; i < data.product.parameters.length; i++) {
var p = data.product.parameters[i];
var e = Object.create(p);
e.type = "control";
e.paramIndex = i;
ports.push(e);
if (data.lv2.use_parameters) {
let parameters = [];
for (var i = 0; i < data.product.parameters.length; i++) {
let e = Object.create(data.product.parameters[i]);
e.paramIndex = i;
parameters.push(e);
}
data.tibia.lv2.parameters = parameters;
if (data.product.parameters.find(p => p.direction == "input")) {
data.tibia.lv2.ports.push({
isInputParameterMessage: true
});
}
if (data.product.parameters.find(p => p.direction == "output")) {
data.tibia.lv2.ports.push({
isOutputParameterMessage: true
});
}
}
else {
var ports = [];
for (var i = 0; i < data.product.parameters.length; i++) {
var p = data.product.parameters[i];
var e = Object.create(p);
e.type = "control";
e.paramIndex = i;
ports.push(e);
}
ports.sort((a, b) => a.direction != b.direction ? (a.direction == "input" ? -1 : 1) : 0);
data.tibia.lv2.ports.push.apply(data.tibia.lv2.ports, ports);
}
ports.sort((a, b) => a.direction != b.direction ? (a.direction == "input" ? -1 : 1) : 0);
data.tibia.lv2.ports.push.apply(data.tibia.lv2.ports, ports);
}
api.generateFileFromTemplateFile(`data${sep}manifest.ttl.in`, `data${sep}manifest.ttl.in`, data);

View File

@ -31,33 +31,12 @@ MKINC_DIR ?= $(COMMON_DIR)
BUNDLE_DIR := $(BUNDLE_NAME).vst3
ifeq ($(OS), Windows_NT)
DLL_SUFFIX := .vst3
VST3DIR := $(subst \,/,$(COMMONPROGRAMFILES))/VST3
VST3DIR_USER := $(subst \,/,$(LOCALAPPDATA))/Programs/Common/VST3
CC := gcc
CXX := g++
MACHINE := $(shell $(CC) -dumpmachine | sed 's:-.*::g')
ifeq ($(MACHINE), x86_64)
VST3_PLATFORM := x86_64-win
endif
ifeq ($(MACHINE), aarch64)
VST3_PLATFORM := arm64-win
endif
VST3_PLATFORM := x86_64-win
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Darwin)
DLL_SUFFIX :=
VST3DIR := /Library/Audio/Plug-Ins/VST3
VST3DIR_USER := $(HOME)/Library/Audio/Plug-Ins/VST3
CC := clang
CXX := clang++
VST3_PLATFORM := MacOS
else
DLL_SUFFIX := .so
VST3DIR := /usr/local/lib/vst3
VST3DIR_USER := $(HOME)/.vst3
CC := gcc
CXX := g++
VST3_PLATFORM := $(shell uname -m)-linux
endif
endif
@ -68,8 +47,31 @@ BUILD_DATA_DIR := build/$(BUNDLE_DIR)/Contents/Resources
-include $(MKINC_DIR)/vars-pre.mk
ifeq ($(OS), Windows_NT)
DLL_SUFFIX := .vst3
VST3DIR := $(shell echo '$(COMMONPROGRAMFILES)' | sed 's:\\:/:g')/VST3
VST3DIR_USER := $(shell echo '$(LOCALAPPDATA)' | sed 's:\\:/:g')/Programs/Common/VST3
CC := gcc
CXX := g++
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Darwin)
DLL_SUFFIX :=
VST3DIR := /Library/Audio/Plug-Ins/VST3
VST3DIR_USER := $(HOME)/Library/Audio/Plug-Ins/VST3
CC := clang
CXX := clang++
else
DLL_SUFFIX := .so
VST3DIR := /usr/local/lib/vst3
VST3DIR_USER := $(HOME)/.vst3
CC := gcc
CXX := g++
endif
endif
CFLAGS := -O3 -Wall -Wpedantic -Wextra
CFLAGS_ALL := -I$(DATA_DIR)/src -I$(PLUGIN_DIR) -I$(API_DIR) -fPIC -fvisibility=hidden $(CFLAGS_EXTRA) $(CFLAGS)
CFLAGS_ALL := -I$(DATA_DIR)/src -I$(PLUGIN_DIR) -I$(API_DIR) -fPIC $(CFLAGS_EXTRA) $(CFLAGS)
LDFLAGS :=
LDFLAGS_ALL := -shared -lm $(LDFLAGS_EXTRA) $(LDFLAGS)
@ -114,9 +116,8 @@ ifeq ($(UNAME_S), Darwin)
endif
STRIP_ALL := build/$(BUNDLE_DIR)/$(DLL_FILE)
STRIP_PREREQS := $(STRIP_ALL)
PHONY := all clean strip install install-user
STRIP_PHONY :=
STRIP_PREREQS := $(STRIP_ALL) $(STRIP_PHONY)
-include $(MKINC_DIR)/vars-extra.mk
@ -145,39 +146,39 @@ clean:
rm -fr build
strip: $(STRIP_PREREQS)
strip -Sx build/$(BUNDLE_DIR)/$(DLL_FILE)
strip build/$(BUNDLE_DIR)/$(DLL_FILE)
install: all
@for d in `find build/$(BUNDLE_DIR) -type d`; do \
d=`echo $$d | sed 's:^build/::'` ; \
echo mkdir -m 0755 -p "$(VST3DIR)/$$d"; \
mkdir -m 0755 -p "$(VST3DIR)/$$d" || exit 1; \
mkdir -m 0755 -p "$(VST3DIR)/$$d"; \
done
@for f in `find build/$(BUNDLE_DIR) -type f`; do \
m=`[ -x $$f ] && echo 0755 || echo 0644`; \
d=`echo $$f | sed 's:^build/::'` ; \
d=`dirname $$d`; \
echo install -m $$m $$f "$(VST3DIR)/$$d"; \
install -m $$m $$f "$(VST3DIR)/$$d" || exit 1; \
install -m $$m $$f "$(VST3DIR)/$$d"; \
done
install-user: all
@for d in `find build/$(BUNDLE_DIR) -type d`; do \
d=`echo $$d | sed 's:^build/::'` ; \
echo mkdir -m 0755 -p "$(VST3DIR_USER)/$$d"; \
mkdir -m 0755 -p "$(VST3DIR_USER)/$$d" || exit 1; \
mkdir -m 0755 -p "$(VST3DIR_USER)/$$d"; \
done
@for f in `find build/$(BUNDLE_DIR) -type f`; do \
m=`[ -x $$f ] && echo 0755 || echo 0644`; \
d=`echo $$f | sed 's:^build/::'` ; \
d=`dirname $$d`; \
echo install -m $$m $$f "$(VST3DIR_USER)/$$d"; \
install -m $$m $$f "$(VST3DIR_USER)/$$d" || exit 1; \
install -m $$m $$f "$(VST3DIR_USER)/$$d"; \
done
-include $(MKINC_DIR)/rules-extra.mk
.PHONY: $(PHONY)
.PHONY: all clean strip $(STRIP_PHONY) install install-user
.SECONDEXPANSION:
@ -193,5 +194,3 @@ $(CXX_OBJS): build/obj/%.o: $$(filter $$(PERCENT)/$$(basename $$(notdir $$@)).cp
$(CXX) $^ -o $@ -c $(CXXFLAGS_ALL)
-include $(MKINC_DIR)/rules-secondexp-extra.mk
.DELETE_ON_ERROR:

View File

@ -28,8 +28,8 @@
static Steinberg_char16 dataProductNameW[64] = { {{~Array.from(it.product.name).slice(0, 63) :c}}0x{{=c.charCodeAt(0).toString(16)}}, {{~}}0 };
static Steinberg_char16 dataProductVersionW[64] = { {{~Array.from(it.product.version + "." + it.product.buildVersion).slice(0, 63) :c}}0x{{=c.charCodeAt(0).toString(16)}}, {{~}}0 };
#define DATA_VST3_SDK_VERSION "VST 3.7.13"
static Steinberg_char16 dataVST3SDKVersionW[64] = { {{~Array.from("VST 3.7.13") :c}}0x{{=c.charCodeAt(0).toString(16)}}, {{~}}0 };
#define DATA_VST3_SDK_VERSION "VST 3.7.12"
static Steinberg_char16 dataVST3SDKVersionW[64] = { {{~Array.from("VST 3.7.12") :c}}0x{{=c.charCodeAt(0).toString(16)}}, {{~}}0 };
static Steinberg_char16 dataVST3ControllerNameW[64] = { {{~Array.from(it.product.name + " Controller").slice(0, 63) :c}}0x{{=c.charCodeAt(0).toString(16)}}, {{~}}0 };

View File

@ -265,15 +265,13 @@ static int stateRead(struct Steinberg_IBStream * state, char ** data, Steinberg_
}
typedef struct pluginInstance {
Steinberg_Vst_IComponentVtbl * vtblIComponent; // must stay first
Steinberg_Vst_IComponentVtbl * vtblIComponent;
Steinberg_Vst_IAudioProcessorVtbl * vtblIAudioProcessor;
Steinberg_Vst_IProcessContextRequirementsVtbl * vtblIProcessContextRequirements;
Steinberg_uint32 refs;
Steinberg_FUnknown * context;
plugin p;
float lastSampleRate;
float curSampleRate;
float nextSampleRate;
float sampleRate;
#if DATA_PRODUCT_PARAMETERS_IN_N > 0
float parametersIn[DATA_PRODUCT_PARAMETERS_IN_N];
float parametersInSync[DATA_PRODUCT_PARAMETERS_IN_N];
@ -414,9 +412,6 @@ static Steinberg_tresult pluginInitialize(void *thisInterface, struct Steinberg_
if (p->context != NULL)
return Steinberg_kResultFalse;
p->context = context;
p->lastSampleRate = 0.f;
p->curSampleRate = 0.f;
p->nextSampleRate = 0.f;
plugin_callbacks cbs = {
/* .handle = */ (void *)p,
@ -633,7 +628,7 @@ static Steinberg_tresult pluginSetActive(void* thisInterface, Steinberg_TBool st
p->neededBusesActive = 0;
# endif
#endif
plugin_set_sample_rate(&p->p, p->nextSampleRate);
plugin_set_sample_rate(&p->p, p->sampleRate);
size_t req = plugin_mem_req(&p->p);
if (req != 0) {
p->mem = malloc(req);
@ -641,11 +636,8 @@ static Steinberg_tresult pluginSetActive(void* thisInterface, Steinberg_TBool st
return Steinberg_kOutOfMemory;
plugin_mem_set(&p->p, p->mem);
}
p->curSampleRate = p->nextSampleRate;
p->lastSampleRate = p->nextSampleRate;
plugin_reset(&p->p);
} else
p->curSampleRate = 0.f;
}
return Steinberg_kResultOk;
}
@ -675,7 +667,7 @@ static Steinberg_tresult pluginSetState(void* thisInterface, struct Steinberg_IB
/* .set_parameter = */ pluginStateSetParameterCb
# endif
};
int err = plugin_state_load(&cbs, p->curSampleRate, data, length);
int err = plugin_state_load(&cbs, data, length);
#else
// we need to provide a default implementation because of certain hosts (e.g. Ardour)
int err = 0;
@ -709,7 +701,7 @@ static Steinberg_tresult pluginSetState(void* thisInterface, struct Steinberg_IB
if (data)
free(data);
TRACE(err == 0 ? " ok\n" : " err\n");
TRACE(err == 0 ? " ok" : " err");
return err == 0 ? Steinberg_kResultOk : Steinberg_kResultFalse;
}
@ -731,7 +723,7 @@ static Steinberg_tresult pluginGetState(void* thisInterface, struct Steinberg_IB
/* .set_parameter = */ NULL
# endif
};
int err = plugin_state_save(&p->p, &cbs, p->lastSampleRate);
int err = plugin_state_save(&p->p, &cbs);
#else
// we need to provide a default implementation because of certain hosts (e.g. Ardour)
int err = 0;
@ -863,7 +855,7 @@ static Steinberg_uint32 pluginGetLatencySamples(void* thisInterface) {
static Steinberg_tresult pluginSetupProcessing(void* thisInterface, struct Steinberg_Vst_ProcessSetup* setup) {
TRACE("plugin IAudioProcessor setup processing\n");
pluginInstance *p = (pluginInstance *)((char *)thisInterface - offsetof(pluginInstance, vtblIAudioProcessor));
p->nextSampleRate = (float)setup->sampleRate;
p->sampleRate = (float)setup->sampleRate;
return Steinberg_kResultOk;
}
@ -1149,7 +1141,7 @@ static Steinberg_Vst_IProcessContextRequirementsVtbl pluginVtblIProcessContextRe
typedef struct plugView plugView;
typedef struct controller {
Steinberg_Vst_IEditControllerVtbl * vtblIEditController; // must stay first
Steinberg_Vst_IEditControllerVtbl * vtblIEditController;
Steinberg_Vst_IMidiMappingVtbl * vtblIMidiMapping;
#ifdef DATA_UI
//Steinberg_Vst_IConnectionPointVtbl * vtblIConnectionPoint;
@ -1380,20 +1372,20 @@ static Steinberg_tresult plugViewIsPlatformTypeSupported(void* thisInterface, St
# if DATA_PRODUCT_PARAMETERS_N > 0
# if DATA_PRODUCT_PARAMETERS_IN_N > 0
static void plugViewUpdateParameterIn(plugView *view, size_t index) {
if (view && view->ui)
if (view->ui)
plugin_ui_set_parameter(view->ui, parameterInData[index].index, view->ctrl->parametersIn[index]);
}
# endif
# if DATA_PRODUCT_PARAMETERS_OUT_N > 0
static void plugViewUpdateParameterOut(plugView *view, size_t index) {
if (view && view->ui)
if (view->ui)
plugin_ui_set_parameter(view->ui, parameterOutData[index].index, view->ctrl->parametersOut[index]);
}
# endif
static void plugViewUpdateAllParameters(plugView *view) {
if (view == NULL || view->ui == NULL)
if (view->ui == NULL)
return;
# if DATA_PRODUCT_PARAMETERS_IN_N > 0
for (size_t i = 0; i < DATA_PRODUCT_PARAMETERS_IN_N; i++)
@ -1866,7 +1858,7 @@ static Steinberg_tresult controllerSetComponentState(void* thisInterface, struct
/* .set_parameter = */ controllerStateSetParameterCb
# endif
};
int err = plugin_state_load(&cbs, -1.f, data, length); // -1.f means "does not apply"
int err = plugin_state_load(&cbs, data, length);
#else
// we need to provide a default implementation because of certain hosts (e.g. Reaper)
int err = 0;
@ -2177,7 +2169,7 @@ static struct Steinberg_IPlugView* controllerCreateView(void* thisInterface, Ste
controller *c = (controller *)((char *)thisInterface - offsetof(controller, vtblIEditController));
size_t i;
for (i = 0; i < c->viewsCount; i++)
for (i = 0; i < c->viewsCount; c++)
if (c->views[i] == NULL)
break;
if (i == c->viewsCount) {
@ -2419,10 +2411,25 @@ static Steinberg_tresult factoryCreateInstance(void *thisInterface, Steinberg_FI
TRACE("createInstance\n");
if (memcmp(cid, dataPluginCID, sizeof(Steinberg_TUID)) == 0) {
TRACE(" plugin\n");
if (memcmp(iid, Steinberg_FUnknown_iid, sizeof(Steinberg_TUID))
&& memcmp(iid, Steinberg_IPluginBase_iid, sizeof(Steinberg_TUID))
&& memcmp(iid, Steinberg_Vst_IComponent_iid, sizeof(Steinberg_TUID)))
size_t offset; // does it actually work like this? or is offset always 0? this seems to be correct and works...
if ((memcmp(iid, Steinberg_FUnknown_iid, sizeof(Steinberg_TUID)) == 0)
|| (memcmp(iid, Steinberg_IPluginBase_iid, sizeof(Steinberg_TUID)) != 0)
|| (memcmp(iid, Steinberg_Vst_IComponent_iid, sizeof(Steinberg_TUID)) != 0)) {
TRACE(" IComponent\n");
offset = offsetof(pluginInstance, vtblIComponent);
} else if (memcmp(iid, Steinberg_Vst_IAudioProcessor_iid, sizeof(Steinberg_TUID)) != 0) {
TRACE(" IAudioProcessor\n");
offset = offsetof(pluginInstance, vtblIAudioProcessor);
} else if (memcmp(iid, Steinberg_Vst_IProcessContextRequirements_iid, sizeof(Steinberg_TUID)) != 0) {
TRACE(" IProcessContextRequirements\n");
offset = offsetof(pluginInstance, vtblIProcessContextRequirements);
} else {
TRACE(" INothing :(\n");
for (int i = 0; i < 16; i++)
TRACE(" %x", iid[i]);
TRACE("\n");
return Steinberg_kNoInterface;
}
pluginInstance *p = malloc(sizeof(pluginInstance));
if (p == NULL)
return Steinberg_kOutOfMemory;
@ -2431,7 +2438,7 @@ static Steinberg_tresult factoryCreateInstance(void *thisInterface, Steinberg_FI
p->vtblIProcessContextRequirements = &pluginVtblIProcessContextRequirements;
p->refs = 1;
p->context = NULL;
*obj = p;
*obj = (void *)((char *)p + offset);
TRACE(" instance: %p\n", (void *)p);
} else if (memcmp(cid, dataControllerCID, sizeof(Steinberg_TUID)) == 0) {
TRACE(" controller\n");
@ -2594,77 +2601,36 @@ EXPORT APIENTRY BOOL
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) {
(void)hInstance;
(void)lpReserved;
char * path;
if (dwReason == DLL_PROCESS_ATTACH) {
if (refs == 0) {
DWORD path_length;
DWORD n_size;
char * new_path;
char * c;
HMODULE hm;
if (GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR)&bindir, &hm) == 0) {
TRACE("GetModuleHandle failed, error = %lu\n", GetLastError());
goto err_handle;
int pathLength;
char path[260];
HMODULE hm = NULL;
if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR) &bindir, &hm) == 0) {
TRACE("GetModuleHandle failed, error = %lu\n", GetLastError());
return 0;
}
path = NULL;
n_size = MAX_PATH;
while (1) {
new_path = (char *)realloc(path, n_size);
if (new_path == NULL) {
TRACE("GetModuleFileName failed, not enough memory (requested %lu bytes)\n", n_size);
goto err_realloc;
}
path = new_path;
path_length = GetModuleFileNameA(hm, path, n_size);
if (path_length == 0) {
TRACE("GetModuleFileName failed, error = %lu\n", GetLastError());
goto err_filename;
}
if (path_length < n_size)
break;
n_size *= 2;
if ((pathLength = GetModuleFileName(hm, path, sizeof(path))) == 0) {
TRACE("GetModuleFileName failed, error = %lu\n", GetLastError());
return 0;
}
char *c = strrchr(path, '\\');
*c = '\0';
bindir = (char*) malloc(strlen(path) + 1);
memcpy(bindir, path, strlen(path));
bindir[strlen(path)] = '\0';
c = strrchr(path, '\\');
*c = '\0';
bindir = _strdup(path);
if (bindir == NULL) {
TRACE("bindir _strdup failed\n");
goto err_bindir;
}
c = strrchr(path, '\\');
*c = '\0';
datadir = (char *)malloc(strlen(path) + sizeof("\\Resources") + 1);
if (datadir == NULL) {
TRACE("datadir malloc failed\n");
goto err_datadir;
}
sprintf(datadir, "%s\\Resources", path);
static char* res = "\\Resources";
datadir = malloc(strlen(path) + strlen(res) + 1);
sprintf(datadir, "%s%s", path, res);
TRACE("bindir = %s \ndatadir = %s\n", bindir, datadir);
}
refs++;
} else if (dwReason == DLL_PROCESS_DETACH)
} else if (dwReason == DLL_PROCESS_DETACH) {
vstExit();
}
return 1;
err_datadir:
free(bindir);
err_bindir:
err_filename:
err_realloc:
if (path != NULL)
free(path);
err_handle:
return 0;
}
#elif defined(__APPLE__) || defined(__linux__)
@ -2684,11 +2650,9 @@ char ModuleEntry(void *handle) {
v.f = vstExit;
if (dladdr((void*) v.d, &info) == 0)
return 0;
file = realpath(info.dli_fname, NULL);
if (file == NULL)
return 0;
char *c = strrchr(file, '/');
*c = '\0';
bindir = strdup(file);
@ -2696,13 +2660,10 @@ char ModuleEntry(void *handle) {
goto err_bindir;
c = strrchr(file, '/');
*c = '\0';
datadir = x_asprintf("%s/Resources", file);
if (datadir == NULL)
goto err_datadir;
free(file);
TRACE("bindir = %s \ndatadir = %s\n", bindir, datadir);
}
refs++;

View File

@ -24,7 +24,7 @@ build/web/index.html: $(DATA_DIR)/src/index.html | build/web
build/web/key.pem: build/web/cert.pem
build/web/cert.pem: | build
openssl req -x509 -newkey rsa:2048 -keyout build/web/key.pem -out build/web/cert.pem -days 365 -nodes -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" 2>/dev/null
yes "" | openssl req -x509 -newkey rsa:2048 -keyout build/web/key.pem -out build/web/cert.pem -days 365 -nodes 2>/dev/null
strip-web-demo: build/web/index.html
$(eval TMP := $(shell mktemp /tmp/index.XXXXXX))

View File

@ -3,7 +3,7 @@
Tibia
Copyright (C) 2022-2025 Orastron Srl unipersonale
Copyright (C) 2022-2024 Orastron Srl unipersonale
Tibia is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -75,12 +75,12 @@ var Player = {
};
function map(index, value) {
var p = demo.Module.parameters[index];
var p = demo.Module.data.product.parameters[index];
return p.map == "logarithmic" ? p.minimum * Math.exp((2.0 * Math.log(Math.sqrt(p.maximum * p.minimum) / Math.abs(p.minimum))) * value) : p.minimum + (p.maximum - p.minimum) * value;
}
function unmap(index, value) {
var p = demo.Module.parameters[index];
var p = demo.Module.data.product.parameters[index];
return p.map == "logarithmic" ? Math.log(value / p.minimum) / (2.0 * Math.log(Math.sqrt(p.maximum * p.minimum) / Math.abs(p.minimum))) : (value - p.minimum) / (p.maximum - p.minimum);
}
@ -112,7 +112,7 @@ var units = {
};
function displayValue(elem, index, value) {
var param = demo.Module.parameters[index];
var param = demo.Module.data.product.parameters[index];
var unit = param.unit;
if (param.integer)
value = Math.round(value);
@ -132,9 +132,9 @@ window.addEventListener("load", function (e) {
var playPause = document.getElementById("playPause");
var controls = document.getElementById("controls");
audioInputIndex = demo.Module.buses.filter(x => x.type == "audio" && x.direction == "input").findIndex(x => !x.cv && !x.sidechain);
audioOutputIndex = demo.Module.buses.filter(x => x.type == "audio" && x.direction == "output").findIndex(x => !x.cv && !x.sidechain);
hasMidiInput = demo.Module.buses.filter(x => x.type == "midi" && x.direction == "input").length > 0;
audioInputIndex = demo.Module.data.product.buses.filter(x => x.type == "audio" && x.direction == "input").findIndex(x => !x.cv && !x.sidechain);
audioOutputIndex = demo.Module.data.product.buses.filter(x => x.type == "audio" && x.direction == "output").findIndex(x => !x.cv && !x.sidechain);
hasMidiInput = demo.Module.data.product.buses.filter(x => x.type == "midi" && x.direction == "input").length > 0;
if (hasMidiInput && !navigator.requestMIDIAccess)
alert("Your browser doesn't support the Web MIDI API");
@ -145,7 +145,7 @@ window.addEventListener("load", function (e) {
file.value = "";
playPause.disabled = true;
var parameters = demo.Module.parameters;
var parameters = demo.Module.data.product.parameters;
for (var i = 0; i < parameters.length; i++) {
var div = document.createElement("div");
@ -241,8 +241,8 @@ window.addEventListener("load", function (e) {
if ((e.data[0] & 0xf0) == 0xf0)
return;
var msg = { type: "midi", data: e.data };
for (var i = 0; i < demo.Module.buses.length; i++) {
var b = demo.Module.buses[i];
for (var i = 0; i < demo.Module.data.product.buses.length; i++) {
var b = demo.Module.data.product.buses[i];
if (b.type != "midi" || b.direction != "input")
continue;
msg.index = i;

View File

@ -21,5 +21,5 @@
ALL := $(ALL) build/web/index.html build/web/cert.pem build/web/key.pem
STRIP_ALL := $(STRIP_ALL) build/web/index.html
STRIP_PREREQS := $(STRIP_PREREQS) strip-web-demo
PHONY := $(PHONY) strip-web-demo
STRIP_PHONY := $(STRIP_PHONY) strip-web-demo
STRIP_PREREQS := $(STRIP_ALL) $(STRIP_PHONY)

View File

@ -18,8 +18,6 @@
# File author: Stefano D'Angelo
#
SHELL := bash -o pipefail
TEMPLATE := web
include vars.mk
@ -88,9 +86,8 @@ DIRS := build build/obj build/web build/web/$(BUNDLE_NAME)
ALL := build/web/$(BUNDLE_NAME)/module.wasm build/web/$(BUNDLE_NAME)/processor.js build/web/$(BUNDLE_NAME)/module.js
STRIP_ALL := build/web/$(BUNDLE_NAME)/module.wasm build/web/$(BUNDLE_NAME)/processor.js build/web/$(BUNDLE_NAME)/module.js
STRIP_PREREQS := $(STRIP_ALL)
PHONY := all clean strip
STRIP_PHONY :=
STRIP_PREREQS := $(STRIP_ALL) $(STRIP_PHONY)
-include $(MKINC_DIR)/vars-extra.mk
@ -124,7 +121,7 @@ strip: $(STRIP_PREREQS)
-include $(MKINC_DIR)/rules-extra.mk
.PHONY: $(PHONY)
.PHONY: all clean strip $(STRIP_PHONY)
.SECONDEXPANSION:
@ -137,5 +134,3 @@ $(CXX_OBJS): build/obj/%.o: $$(filter $$(PERCENT)/$$(basename $$(notdir $$@)).cp
$(CXX) $^ -o $@ -c $(CXXFLAGS_ALL)
-include $(MKINC_DIR)/rules-secondexp-extra.mk
.DELETE_ON_ERROR:

View File

@ -1,7 +1,7 @@
/*
* Tibia
*
* Copyright (C) 2022-2025 Orastron Srl unipersonale
* Copyright (C) 2022-2024 Orastron Srl unipersonale
*
* Tibia is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -18,12 +18,13 @@
* File author: Stefano D'Angelo
*/
const buses = {{=JSON.stringify(it.product.buses, null, 2)}};
const parameters = {{=JSON.stringify(it.product.parameters, null, 2)}};
const data = {
company: {{=JSON.stringify(it.company, null, 2)}},
product: {{=JSON.stringify(it.product, null, 2)}}
};
export class Module {
static get buses() { return buses; }
static get parameters() { return parameters; }
static get data() { return data; }
async init(context, processorJsPath, wasmPath) {
var wasmBytes = await fetch(wasmPath)
@ -44,11 +45,11 @@ export class Module {
export class Node extends AudioWorkletNode {
constructor(module) {
super(module.context, "{{=it.product.bundleName}}",
super(module.context, data.product.bundleName,
{
numberOfInputs: buses.filter(b => b.type == "audio" && b.direction == "input").length,
numberOfOutputs: buses.filter(b => b.type == "audio" && b.direction == "output").length,
outputChannelCount: buses.filter(b => b.type == "audio" && b.direction == "output").map(b => b.channels == "mono" ? 1 : 2),
numberOfInputs: data.product.buses.filter(b => b.type == "audio" && b.direction == "input").length,
numberOfOutputs: data.product.buses.filter(b => b.type == "audio" && b.direction == "output").length,
outputChannelCount: data.product.buses.filter(b => b.type == "audio" && b.direction == "output").map(b => b.channels == "mono" ? 1 : 2),
processorOptions: { wasmBytes: module.wasmBytes }
});
}

View File

@ -1,6 +1,5 @@
{
"android": {
"javaPackageName": "com.example.tibia_test",
"androidVersion": "36"
"javaPackageName": "com.example.tibia_test"
}
}

View File

@ -1,6 +1,6 @@
{
"ios_make": {
"headerSearchPaths": [ "../../../../../miniaudio" ],
"deploymentTarget": "16.6"
"deploymentTarget": 16.6
}
}

View File

@ -7,8 +7,7 @@
"project": "@example:project",
"types": [ "@lv2:AmplifierPlugin" ],
"version": "1.0",
"ui": {
"uri": "@example:tibia_test#ui"
}
"use_parameters": true
}
}

View File

@ -138,8 +138,7 @@ static float parse_float(const uint8_t *data) {
return v.f;
}
static int plugin_state_save(plugin *instance, const plugin_state_callbacks *cbs, float last_sample_rate) {
(void)last_sample_rate;
static int plugin_state_save(plugin *instance, const plugin_state_callbacks *cbs) {
uint8_t data[13];
cbs->lock(cbs->handle);
const float gain = instance->gain;
@ -160,8 +159,7 @@ static char x_isnan(float x) {
return ((v.u & 0x7f800000) == 0x7f800000) && (v.u & 0x7fffff);
}
static int plugin_state_load(const plugin_state_callbacks *cbs, float cur_sample_rate, const char *data, size_t length) {
(void)cur_sample_rate;
static int plugin_state_load(const plugin_state_callbacks *cbs, const char *data, size_t length) {
if (length != 13)
return -1;
const uint8_t *d = (const uint8_t *)data;

View File

@ -1,7 +1,7 @@
/*
* Tibia
*
* Copyright (C) 2024, 2025 Orastron Srl unipersonale
* Copyright (C) 2024 Orastron Srl unipersonale
*
* Tibia is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -18,230 +18,303 @@
* File author: Stefano D'Angelo, Paolo Marrone
*/
#include "vinci.h"
#include <stdio.h>
#include <string.h>
#include <pugl/pugl.h>
#include <pugl/cairo.h>
#include <cairo.h>
typedef struct {
void *widget;
void * widget;
PuglWorld * world;
PuglView * view;
vinci *ui;
window *w;
int param_down;
double fw;
double fh;
double x;
double y;
double w;
double h;
float gain;
float delay;
float cutoff;
char bypass;
float y_z1;
float gain;
float delay;
float cutoff;
char bypass;
float y_z1;
int param_down;
plugin_ui_callbacks cbs;
} plugin_ui;
#define WIDTH 600.0
#define HEIGHT 400.0
#define RATIO (WIDTH / HEIGHT)
#define INV_RATIO (HEIGHT / WIDTH)
static void plugin_ui_get_default_size(uint32_t *width, uint32_t *height) {
*width = WIDTH;
*height = HEIGHT;
}
static void draw_rect(window *w, uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint32_t color) {
uint32_t *data = (uint32_t*) malloc(width * height * 4);
uint32_t p = 0;
for (uint32_t i = 0; i < height; i++)
for (uint32_t j = 0; j < width; j++, p++)
data[p] = color;
window_draw(w, (unsigned char*)data, 0, 0, width, height, x, y, width, height);
free(data);
}
static void plugin_ui_update_geometry(plugin_ui *instance) {
PuglRect frame = puglGetFrame(instance->view);
instance->fw = frame.width;
instance->fh = frame.height;
if (frame.width == 0 || frame.height == 0)
return;
static void draw_slider(plugin_ui *pui, int id, float value) {
const int w = window_get_width(pui->w);
const int h = window_get_height(pui->w);
draw_rect(pui->w, 0.1 * w, 0.15 * (id + 1) * h, 0.8 * w * value, 0.1 * h, 0x6789ab);
draw_rect(pui->w, 0.1 * w + 0.8 * w * value, 0.15 * (id + 1) * h, 0.8 * w * (1.f - value), 0.1 * h, 0x1223bc);
}
static void draw_button(plugin_ui *pui, int id, char value) {
const int w = window_get_width(pui->w);
const int h = window_get_height(pui->w);
draw_rect(pui->w, 0.4 * w, 0.15 * (id + 1) * h, 0.2 * w, 0.1 * h, value ? 0x6789ab : 0x1223bc);
}
static void on_close(window *w) {
printf("on_close %p \n", (void*)w); fflush(stdout);
}
static void on_mouse_press (window *win, int32_t x, int32_t y, uint32_t state) {
(void) state;
plugin_ui *pui = (plugin_ui*) window_get_data(win);
const int w = window_get_width(win);
const int h = window_get_height(win);
if (x >= 0.1 * w && x <= 0.9 * w && y >= 0.15 * h && y <= 0.25 * h) {
pui->param_down = 0;
pui->gain = (float)((x - (0.1 * w)) / (0.8 * w));
pui->cbs.set_parameter_begin(pui->cbs.handle, 0, -60.f + 80.f * pui->gain);
draw_slider(pui, 0, pui->gain);
} else if (x >= 0.1 * w && x <= 0.9 * w && y >= 0.3 * h && y <= 0.4 * h) {
pui->param_down = 1;
pui->delay = (float)((x - (0.1 * w)) / (0.8 * w));
pui->cbs.set_parameter_begin(pui->cbs.handle, 1, 1000.f * pui->delay);
draw_slider(pui, 1, pui->delay);
} else if (x >= 0.1 * w && x <= 0.9 * w && y >= 0.45 * h && y <= 0.55 * h) {
pui->param_down = 2;
pui->cutoff = (float)((x - (0.1 * w)) / (0.8 * w));
pui->cbs.set_parameter_begin(pui->cbs.handle, 2, (632.4555320336746f * pui->cutoff + 20.653108640674372f) / (1.0326554320337158f - pui->cutoff));
draw_slider(pui, 2, pui->cutoff);
} else if (x >= 0.4 * w && x <= 0.6 * w && y >= 0.6 * h && y <= 0.7 * h) {
pui->param_down = 4;
if (instance->fw / instance->fh > RATIO) {
instance->w = RATIO * instance->fh;
instance->h = instance->fh;
instance->x = 0.5 * (instance->fw - instance->w);
instance->y = 0.0;
} else {
instance->w = instance->fw;
instance->h = INV_RATIO * instance->fw;
instance->x = 0.0;
instance->y = 0.5 * (instance->fh - instance->h);
}
}
static void on_mouse_release (window *win, int32_t x, int32_t y, uint32_t state) {
(void) state;
static void plugin_ui_draw(plugin_ui *instance) {
cairo_t *cr = (cairo_t *)puglGetContext(instance->view);
double x = instance->x;
double y = instance->y;
double w = instance->w;
double h = instance->h;
plugin_ui *pui = (plugin_ui*) window_get_data(win);
const int w = window_get_width(win);
const int h = window_get_height(win);
cairo_set_line_width(cr, 0.005 * h);
if (pui->param_down == 4)
if (x >= 0.4 * w && x <= 0.6 * w && y >= 0.6 * h && y <= 0.7 * h) {
pui->bypass = !pui->bypass;
pui->cbs.set_parameter(pui->cbs.handle, 3, pui->bypass ? 1.f : 0.f);
draw_button(pui, 3, pui->bypass);
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_paint(cr);
cairo_set_source_rgb(cr, 0.2, 0.2, 0.2);
cairo_rectangle(cr, x, y, w, h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
cairo_rectangle(cr, x + 0.1 * w, y + 0.15 * h, 0.8 * w, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
cairo_rectangle(cr, x + 0.1 * w, y + 0.15 * h, 0.8 * w * instance->gain, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
cairo_rectangle(cr, x + 0.1 * w, y + 0.15 * h, 0.8 * w, 0.1 * h);
cairo_stroke(cr);
cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
cairo_rectangle(cr, x + 0.1 * w, y + 0.3 * h, 0.8 * w, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
cairo_rectangle(cr, x + 0.1 * w, y + 0.3 * h, 0.8 * w * instance->delay, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
cairo_rectangle(cr, x + 0.1 * w, y + 0.3 * h, 0.8 * w, 0.1 * h);
cairo_stroke(cr);
cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
cairo_rectangle(cr, x + 0.1 * w, y + 0.45 * h, 0.8 * w, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
cairo_rectangle(cr, x + 0.1 * w, y + 0.45 * h, 0.8 * w * instance->cutoff, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
cairo_rectangle(cr, x + 0.1 * w, y + 0.45 * h, 0.8 * w, 0.1 * h);
cairo_stroke(cr);
if (instance->bypass)
cairo_set_source_rgb(cr, 1.0, 0, 0);
else
cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
cairo_rectangle(cr, x + 0.4 * w, y + 0.6 * h, 0.2 * w, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
cairo_rectangle(cr, x + 0.1 * w, y + 0.75 * h, 0.8 * w, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
cairo_rectangle(cr, x + 0.1 * w, y + 0.75 * h, 0.8 * w * instance->y_z1, 0.1 * h);
cairo_fill(cr);
}
static PuglStatus plugin_ui_on_event(PuglView *view, const PuglEvent *event) {
switch (event->type) {
case PUGL_CONFIGURE:
{
plugin_ui *instance = (plugin_ui *)puglGetHandle(view);
plugin_ui_update_geometry(instance);
puglPostRedisplay(instance->view);
}
break;
case PUGL_BUTTON_PRESS:
{
plugin_ui *instance = (plugin_ui *)puglGetHandle(view);
const PuglButtonEvent *ev = (const PuglButtonEvent *)event;
double x = instance->x;
double y = instance->y;
double w = instance->w;
double h = instance->h;
if (pui->param_down != -1) {
float v = x < 0.1 * w ? 0.f : (x > 0.9 * w ? 1.f : (float)((x - (0.1 * w)) / (0.8 * w)));
switch (pui->param_down) {
case 0:
pui->gain = v;
pui->cbs.set_parameter_end(pui->cbs.handle, 0, -60.f + 80.f * pui->gain);
draw_slider(pui, 0, pui->gain);
break;
case 1:
pui->delay = v;
pui->cbs.set_parameter_end(pui->cbs.handle, 1, 1000.f * pui->delay);
draw_slider(pui, 1, pui->delay);
break;
case 2:
pui->cutoff = v;
pui->cbs.set_parameter_end(pui->cbs.handle, 2, (632.4555320336746f * pui->cutoff + 20.653108640674372f) / (1.0326554320337158f - pui->cutoff));
draw_slider(pui, 2, pui->cutoff);
break;
if (ev->x >= x + 0.1 * w && ev->x <= x + 0.9 * w
&& ev->y >= y + 0.15 * h && ev->y <= y + 0.25 * h) {
instance->param_down = 0;
instance->gain = (float)((ev->x - (x + 0.1 * w)) / (0.8 * w));
instance->cbs.set_parameter_begin(instance->cbs.handle, 0, -60.f + 80.f * instance->gain);
puglPostRedisplay(instance->view);
} else if (ev->x >= x + 0.1 * w && ev->x <= x + 0.9 * w
&& ev->y >= y + 0.3 * h && ev->y <= y + 0.4 * h) {
instance->param_down = 1;
instance->delay = (float)((ev->x - (x + 0.1 * w)) / (0.8 * w));
instance->cbs.set_parameter_begin(instance->cbs.handle, 1, 1000.f * instance->delay);
puglPostRedisplay(instance->view);
} else if (ev->x >= x + 0.1 * w && ev->x <= x + 0.9 * w
&& ev->y >= y + 0.45 * h && ev->y <= y + 0.55 * h) {
instance->param_down = 2;
instance->cutoff = (float)((ev->x - (x + 0.1 * w)) / (0.8 * w));
instance->cbs.set_parameter_begin(instance->cbs.handle, 2, (632.4555320336746f * instance->cutoff + 20.653108640674372f) / (1.0326554320337158f - instance->cutoff));
puglPostRedisplay(instance->view);
} else if (ev->x >= x + 0.4 * w && ev->x <= x + 0.6 * w
&& ev->y >= y + 0.6 * h && ev->y <= y + 0.7 * h) {
instance->param_down = 3;
}
}
pui->param_down = -1;
break;
case PUGL_MOTION:
{
plugin_ui *instance = (plugin_ui *)puglGetHandle(view);
const PuglMotionEvent *ev = (const PuglMotionEvent *)event;
double x = instance->x;
double w = instance->w;
float v = ev->x < x + 0.1 * w ? 0.f : (ev->x > x + 0.9 * w ? 1.f : (float)((ev->x - (x + 0.1 * w)) / (0.8 * w)));
switch (instance->param_down) {
case 0:
instance->gain = v;
instance->cbs.set_parameter(instance->cbs.handle, 0, -60.f + 80.f * instance->gain);
puglPostRedisplay(instance->view);
break;
case 1:
instance->delay = v;
instance->cbs.set_parameter(instance->cbs.handle, 1, 1000.f * instance->delay);
puglPostRedisplay(instance->view);
break;
case 2:
instance->cutoff = v;
instance->cbs.set_parameter(instance->cbs.handle, 2, (632.4555320336746f * instance->cutoff + 20.653108640674372f) / (1.0326554320337158f - instance->cutoff));
puglPostRedisplay(instance->view);
break;
}
}
break;
case PUGL_BUTTON_RELEASE:
{
plugin_ui *instance = (plugin_ui *)puglGetHandle(view);
const PuglButtonEvent *ev = (const PuglButtonEvent *)event;
double x = instance->x;
double y = instance->y;
double w = instance->w;
double h = instance->h;
if (instance->param_down == 3)
if (ev->x >= x + 0.4 * w && ev->x <= x + 0.6 * w
&& ev->y >= y + 0.6 * h && ev->y <= y + 0.7 * h) {
instance->bypass = !instance->bypass;
instance->cbs.set_parameter(instance->cbs.handle, 3, instance->bypass ? 1.f : 0.f);
puglPostRedisplay(instance->view);
}
if (instance->param_down != -1) {
float v = ev->x < x + 0.1 * w ? 0.f : (ev->x > x + 0.9 * w ? 1.f : (float)((ev->x - (x + 0.1 * w)) / (0.8 * w)));
switch (instance->param_down) {
case 0:
instance->gain = v;
instance->cbs.set_parameter_end(instance->cbs.handle, 0, -60.f + 80.f * instance->gain);
puglPostRedisplay(instance->view);
break;
case 1:
instance->delay = v;
instance->cbs.set_parameter_end(instance->cbs.handle, 1, 1000.f * instance->delay);
puglPostRedisplay(instance->view);
break;
case 2:
instance->cutoff = v;
instance->cbs.set_parameter_end(instance->cbs.handle, 2, (632.4555320336746f * instance->cutoff + 20.653108640674372f) / (1.0326554320337158f - instance->cutoff));
puglPostRedisplay(instance->view);
break;
}
instance->param_down = -1;
}
}
break;
case PUGL_EXPOSE:
{
plugin_ui *instance = (plugin_ui *)puglGetHandle(view);
plugin_ui_update_geometry(instance); // I didn't expect this was needed here for X11 to work decently when resizing
plugin_ui_draw(instance);
}
break;
default:
break;
}
}
static void on_mouse_move (window *win, int32_t x, int32_t y, uint32_t state) {
(void) y;
(void) state;
plugin_ui *pui = (plugin_ui*) window_get_data(win);
const int w = window_get_width(win);
float v = x < 0.1 * w ? 0.f : (x > 0.9 * w ? 1.f : (float)((x - (0.1 * w)) / (0.8 * w)));
switch (pui->param_down) {
case 0:
pui->gain = v;
pui->cbs.set_parameter(pui->cbs.handle, 0, -60.f + 80.f * pui->gain);
draw_slider(pui, 0, pui->gain);
break;
case 1:
pui->delay = v;
pui->cbs.set_parameter(pui->cbs.handle, 1, 1000.f * pui->delay);
draw_slider(pui, 1, pui->delay);
break;
case 2:
pui->cutoff = v;
pui->cbs.set_parameter(pui->cbs.handle, 2, (632.4555320336746f * pui->cutoff + 20.653108640674372f) / (1.0326554320337158f - pui->cutoff));
draw_slider(pui, 2, pui->cutoff);
break;
}
}
static void on_window_resize (window *w, int32_t width, int32_t height) {
draw_rect(w, 0, 0, width, height, 0xff9999);
plugin_ui *pui = (plugin_ui*) window_get_data(w);
draw_slider(pui, 0, pui->gain);
draw_slider(pui, 1, pui->delay);
draw_slider(pui, 2, pui->cutoff);
draw_button(pui, 3, pui->bypass);
draw_slider(pui, 4, pui->y_z1);
return PUGL_SUCCESS;
}
static plugin_ui *plugin_ui_create(char has_parent, void *parent, plugin_ui_callbacks *cbs) {
plugin_ui *instance = (plugin_ui *) malloc(sizeof(plugin_ui));
plugin_ui *instance = malloc(sizeof(plugin_ui));
if (instance == NULL)
return NULL;
struct window_cbs wcbs;
memset(&wcbs, 0, sizeof(window_cbs));
wcbs.on_window_close = on_close;
wcbs.on_mouse_press = on_mouse_press;
wcbs.on_mouse_release = on_mouse_release;
wcbs.on_mouse_move = on_mouse_move;
wcbs.on_window_resize = on_window_resize;
instance->param_down = -1;
instance->ui = vinci_new();
instance->w = window_new(instance->ui, has_parent ? parent : NULL, WIDTH, HEIGHT, &wcbs);
instance->widget = window_get_handle(instance->w);
window_set_data(instance->w, (void*) instance);
window_show(instance->w);
// just some valid values to allow drawing
instance->gain = 0.f;
instance->delay = 0.f;
instance->cutoff = 0.f;
instance->bypass = 0;
instance->y_z1 = 0.f;
on_window_resize(instance->w, window_get_width(instance->w), window_get_height(instance->w));
instance->world = puglNewWorld(PUGL_MODULE, 0);
instance->view = puglNewView(instance->world);
puglSetSizeHint(instance->view, PUGL_DEFAULT_SIZE, WIDTH, HEIGHT);
puglSetViewHint(instance->view, PUGL_RESIZABLE, PUGL_TRUE);
puglSetHandle(instance->view, instance);
puglSetBackend(instance->view, puglCairoBackend());
PuglRect frame = { 0, 0, WIDTH, HEIGHT };
puglSetFrame(instance->view, frame);
puglSetEventFunc(instance->view, plugin_ui_on_event);
if (has_parent)
puglSetParentWindow(instance->view, (PuglNativeView)parent);
if (puglRealize(instance->view)) {
puglFreeView(instance->view);
puglFreeWorld(instance->world);
return NULL;
}
instance->widget = (void *)puglGetNativeView(instance->view);
instance->cbs = *cbs;
puglSetFrame(instance->view, frame); // Intentionally duplicated because of ardour/lv2/mac strange event order call
puglShow(instance->view, PUGL_SHOW_RAISE); // Cocoa calls events at this so it's better this happens late
return instance;
}
static void plugin_ui_free(plugin_ui *instance) {
window_free(instance->w);
vinci_destroy(instance->ui);
puglFreeView(instance->view);
puglFreeWorld(instance->world);
free(instance);
}
static void plugin_ui_idle(plugin_ui *instance) {
vinci_idle(instance->ui);
puglUpdate(instance->world, 0);
}
static void plugin_ui_set_parameter(plugin_ui *instance, size_t index, float value) {
switch (index) {
case 0:
instance->gain = 0.0125f * value + 0.75f;
draw_slider(instance, 0, instance->gain);
break;
case 1:
instance->delay = 0.001f * value;
draw_slider(instance, 1, instance->delay);
break;
case 2:
// (bad) approx log unmap
instance->cutoff = (1.0326554320337176f * value - 20.65310864067435f) / (value + 632.4555320336754f);
draw_slider(instance, 2, instance->cutoff);
break;
case 3:
instance->bypass = value >= 0.5f;
draw_button(instance, 3, instance->bypass);
break;
case 4:
instance->y_z1 = 0.5f * value + 0.5f;
draw_slider(instance, 4, instance->y_z1);
break;
}
puglPostRedisplay(instance->view);
}

View File

@ -2,10 +2,8 @@
"product": {
"name": "Tibia test product",
"version": "1.0.0",
"buildVersion": 0,
"description": "A toy plugin to test Tibia",
"copyright": "Copyright © 2021-2025 Orastron Srl unipersonale",
"bundleName": "tibia-test",
"buildVersion": "1",
"bundleName": "tibia_test",
"buses": [
{
"type": "audio",
@ -138,8 +136,7 @@
],
"ui": {
"userResizable": true,
"selfResizable": false,
"highResolution": true
"selfResizable": false
},
"state": {
"dspCustom": true

View File

@ -1,21 +1 @@
#
# Tibia
#
# Copyright (C) 2024 Orastron Srl unipersonale
#
# Tibia is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# Tibia is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Tibia. If not, see <http://www.gnu.org/licenses/>.
#
# File author: Stefano D'Angelo
#
include rules-extra-web-demo.mk

View File

@ -1,25 +1,5 @@
#!/bin/sh
#
# Tibia
#
# Copyright (C) 2023-2025 Orastron Srl unipersonale
#
# Tibia is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# Tibia is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Tibia. If not, see <http://www.gnu.org/licenses/>.
#
# File author: Stefano D'Angelo
#
dir=`dirname $0`
$dir/../tibia $dir/product.json,$dir/company.json $dir/../templates/api $dir/../out/api

View File

@ -1,21 +1 @@
#
# Tibia
#
# Copyright (C) 2024 Orastron Srl unipersonale
#
# Tibia is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# Tibia is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Tibia. If not, see <http://www.gnu.org/licenses/>.
#
# File author: Stefano D'Angelo
#
include vars-extra-web-demo.mk

View File

@ -1,65 +1,19 @@
#
# Tibia
#
# Copyright (C) 2024, 2025 Orastron Srl unipersonale
#
# Tibia is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# Tibia is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Tibia. If not, see <http://www.gnu.org/licenses/>.
#
# File author: Stefano D'Angelo
#
API_DIR := ../api
VINCI_DIR := ../../../vinci
ifeq ($(TEMPLATE), cmd)
TINYWAV_DIR := ../../../tinywav
MIDI_PARSER_DIR := ../../../midi-parser
endif
ifeq ($(TEMPLATE), lv2)
ifeq ($(OS), Windows_NT)
C_SRCS_EXTRA := $(VINCI_DIR)/vinci-win32.c
LDFLAGS_EXTRA := -mwindows
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Darwin)
M_SRCS_EXTRA := $(VINCI_DIR)/vinci-cocoa.m
LDFLAGS_EXTRA := -framework Cocoa -lobjc
else
C_SRCS_EXTRA := $(VINCI_DIR)/vinci-xcb.c
LDFLAGS_EXTRA := -lxcb
endif
endif
CFLAGS_EXTRA := $(CFLAGS_EXTRA) -I${VINCI_DIR}
CFLAGS_EXTRA := $(shell pkg-config --cflags pugl-cairo-0 pugl-0 cairo)
LDFLAGS_EXTRA := $(shell pkg-config --libs pugl-cairo-0 pugl-0 cairo) -Wl,-rpath,$(shell pkg-config --variable=libdir pugl-cairo-0),-rpath,$(shell pkg-config --variable=libdir pugl-0),-rpath,$(shell pkg-config --variable=libdir cairo)
endif
ifeq ($(TEMPLATE), vst3)
ifeq ($(OS), Windows_NT)
C_SRCS_EXTRA := $(VINCI_DIR)/vinci-win32.c
LDFLAGS_EXTRA := -mwindows
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Darwin)
M_SRCS_EXTRA := $(VINCI_DIR)/vinci-cocoa.m
LDFLAGS_EXTRA := -framework Cocoa -lobjc
else
C_SRCS_EXTRA := $(VINCI_DIR)/vinci-xcb.c
LDFLAGS_EXTRA := -lxcb
endif
endif
CFLAGS_EXTRA := $(CFLAGS_EXTRA) -I../../../vst3_c_api
CFLAGS_EXTRA := $(CFLAGS_EXTRA) -I${VINCI_DIR}
RUTEX_DIR := ../../../rutex
CFLAGS_EXTRA := -I../../../vst3_c_api $(shell pkg-config --cflags pugl-cairo-0)
LDFLAGS_EXTRA := $(shell pkg-config --libs pugl-cairo-0 pugl-0 cairo) -Wl,-rpath,$(shell pkg-config --variable=libdir pugl-cairo-0),-rpath,$(shell pkg-config --variable=libdir pugl-0),-rpath,$(shell pkg-config --variable=libdir cairo)
endif
ifeq ($(TEMPLATE), daisy-seed)
@ -75,12 +29,13 @@ ifeq ($(TEMPLATE), android)
SDK_DIR := $(HOME)/Android/Sdk
ANDROIDX_DIR := $(HOME)/Android/androidx
KOTLIN_DIR := $(HOME)/Android/kotlin
NDK_VERSION := 28.0.13004108
BUILD_TOOLS_VERSION := 36.0.0
ANDROIDX_CORE_VERSION := 1.16.0
NDK_VERSION := 28.0.12674087
BUILD_TOOLS_VERSION := 35.0.0
ANDROID_VERSION := 35
ANDROIDX_CORE_VERSION := 1.15.0
ANDROIDX_LIFECYCLE_COMMON_VERSION := 2.8.7
ANDROIDX_VERSIONEDPARCELABLE_VERSION := 1.2.1
KOTLIN_STDLIB_VERSION := 2.1.20
KOTLINX_COROUTINES_CORE_VERSION := 1.10.2
KOTLINX_COROUTINES_CORE_JVM_VERSION := 1.10.2
KOTLIN_STDLIB_VERSION := 2.1.10
KOTLINX_COROUTINES_CORE_VERSION := 1.10.1
KOTLINX_COROUTINES_CORE_JVM_VERSION := 1.10.1
endif

55
tibia
View File

@ -1,25 +1,5 @@
#!/usr/bin/env node
/*
* Tibia
*
* Copyright (C) 2023-2025 Orastron Srl unipersonale
*
* Tibia is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Tibia is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tibia. If not, see <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo
*/
function usage() {
console.log("Usage:");
console.log(" tibia file1.json,file2.json,...filen.json template outDirectory [override1=value1] [override2=value2] ...");
@ -115,30 +95,39 @@ var doT = require("dot");
doT.templateSettings.strip = false;
var api = {
generateFileFromTemplateFile: function (templateFile, outFile, data, mode) {
// https://coderrocketfuel.com/article/recursively-list-all-the-files-in-a-directory-using-node-js
getAllFiles: function (dirPath, arrayOfFiles, relDir) {
var files = fs.readdirSync(dirPath);
var arrayOfFiles = arrayOfFiles || [];
var relDir = relDir || "";
files.forEach(function(file) {
if (fs.statSync(dirPath + path.sep + file).isDirectory())
arrayOfFiles = api.getAllFiles(dirPath + path.sep + file, arrayOfFiles, relDir + file + path.sep);
else
arrayOfFiles.push(relDir + file);
});
return arrayOfFiles
},
generateFileFromTemplateFile: function (templateFile, outFile, data) {
if (!outputData)
return;
var dir = outputDir + path.sep + path.dirname(outFile);
fs.mkdirSync(dir, { recursive: true });
var t = doT.template(fs.readFileSync(template + path.sep + templateFile, { encoding: "utf-8" }));
var outputFile = outputDir + path.sep + outFile;
fs.writeFileSync(outputFile, t(data), { encoding: "utf-8" });
if (mode !== undefined)
fs.chmodSync(outputFile, mode);
fs.writeFileSync(outputDir + path.sep + outFile, t(data), { encoding: "utf-8" });
},
copyFile: function (inFile, outFile, mode) {
copyFile: function (inFile, outFile) {
if (!outputCommon)
return;
var dir = outputDir + path.sep + path.dirname(outFile);
fs.mkdirSync(dir, { recursive: true });
var outputFile = outputDir + path.sep + outFile;
fs.copyFileSync(template + path.sep + inFile, outputFile);
if (mode !== undefined)
fs.chmodSync(outputFile, mode);
},
templateDir: template
fs.copyFileSync(template + path.sep + inFile, outputDir + path.sep + outFile);
}
};
data.tibia = {