Skip to content

Commit 455603f

Browse files
committed
Add plugin UI
1 parent 01d16cd commit 455603f

11 files changed

+347
-77
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "robtk"]
2+
path = robtk
3+
url = https://github.com/x42/robtk

Makefile

+60-19
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,73 @@
1-
OBJS = lpc.o lpc_plugin.o
2-
CC=gcc
3-
CPP=g++
41
INCLUDES=
5-
CPPFLAGS=-c -s -O3 -ffast-math -fPIC
2+
CPPFLAGS=-s -O3 -ffast-math -fPIC
63
#-g for debug
74
#-s -O3 -ffast-math for release
85
LIBS=
9-
INSTALLDIR=~/.lv2
6+
LV2DEPS=lpc_plugin.cpp lpc.cpp
107

11-
lpc_plugin.so: $(OBJS) manifest.ttl
12-
$(CPP) -shared -o $@ $(OBJS) $(LIBS)
8+
RW ?= robtk/
9+
RT=$(RW)rtk/
10+
PUGL_SRC=$(RW)pugl/pugl_x11.c
11+
GLUILIBS = -lX11 $(shell pkg-config --libs cairo pango pangocairo glu gl)
12+
GLUICFLAGS = -DUSE_GUI_THREAD $(shell pkg-config --cflags cairo pango)
13+
LV2LDFLAGS=-Wl,-Bstatic -Wl,-Bdynamic -Wl,--as-needed -pthread
14+
ROBGL= $(RW)robtk.mk $(UITOOLKIT) $(RW)ui_gl.c $(PUGL_SRC) \
15+
$(RW)gl/common_cgl.h $(RW)gl/layout.h $(RW)gl/robwidget_gl.h $(RW)robtk.h \
16+
$(RT)common.h $(RT)style.h \
17+
$(RW)gl/xternalui.c $(RW)gl/xternalui.h
1318

14-
manifest.ttl:
15-
sed "s/@LIB_EXT@/.so/" manifest.ttl.in > manifest.ttl
19+
LV2_BIN=lpc_plugin
20+
LV2_BUNDLE=lpc.lv2/
21+
UI_BIN=lpcUI_gl
22+
LIB_EXT=.so
23+
INSTALLDIR=~/.lv2/
24+
LV2_URI=http://example.com/plugins/lpc_plugin
25+
UI_TYPE=ui:X11UI
26+
UI_SUFFIX=\#ui_gl
27+
TTL_SUB="s%@LIB_EXT@%$(LIB_EXT)%;s%@LV2_BIN@%$(LV2_BIN)%;s%@LV2_URI@%$(LV2_URI)%;s%@UI_BIN@%$(UI_BIN)%;s%@UI_TYPE@%$(UI_TYPE)%;s%@UI_SUFFIX@%$(UI_SUFFIX)%"
28+
CPPFLAGS+=-DLPC_URI="\"$(LV2_URI)\""
1629

17-
.PHONY: clean install uninstall validate
30+
all: $(LV2_BUNDLE)$(LV2_BIN)$(LIB_EXT) $(LV2_BUNDLE)manifest.ttl $(LV2_BUNDLE)$(LV2_BIN).ttl $(LV2_BUNDLE)$(UI_BIN)$(LIB_EXT)
31+
32+
$(LV2_BUNDLE):
33+
mkdir $(LV2_BUNDLE)
34+
35+
$(LV2_BUNDLE)$(LV2_BIN)$(LIB_EXT): $(LV2_BUNDLE)
36+
$(CXX) $(CPPFLAGS) -shared -o $@ $(LV2DEPS) $(LIBS)
37+
38+
39+
$(LV2_BUNDLE)$(UI_BIN)$(LIB_EXT): $(ROBGL) $(LV2_BUNDLE)
40+
$(CXX) $(CPPFLAGS) $(CFLAGS) $(GLUICFLAGS) $(PTHREADCFLAGS) \
41+
-DUINQHACK="$(shell date +%s$$$$)" \
42+
-DPLUGIN_SOURCE="\"../lpc_ui.cpp\"" \
43+
-o $@ $(RW)ui_gl.c \
44+
$(PUGL_SRC) \
45+
$(value $(*F)_UISRC) \
46+
-shared $(LV2LDFLAGS) $(LDFLAGS) $(GLUILIBS)
47+
48+
$(LV2_BUNDLE)manifest.ttl: $(LV2_BUNDLE) manifest.ttl.in manifest_ui.ttl.in
49+
sed $(TTL_SUB) manifest.ttl.in > $@
50+
sed $(TTL_SUB) manifest_ui.ttl.in >> $@
51+
52+
53+
$(LV2_BUNDLE)$(LV2_BIN).ttl: $(LV2_BUNDLE) $(LV2_BIN).ttl.in $(LV2_BIN)_ui.ttl.in
54+
sed $(TTL_SUB) $(LV2_BIN).ttl.in > $@
55+
sed $(TTL_SUB) $(LV2_BIN)_ui.ttl.in >> $@
1856

1957
clean:
20-
rm -f lpc_plugin.so *~ *.o manifest.ttl
58+
rm -r $(LV2_BUNDLE)
2159

22-
install: manifest.ttl lpc_plugin.so
23-
mkdir -p $(INSTALLDIR)/lpc.lv2
24-
cp manifest.ttl lpc_plugin.ttl lpc_plugin.so $(INSTALLDIR)/lpc.lv2
60+
install: all
61+
mkdir -p $(INSTALLDIR)
62+
cp -r $(LV2_BUNDLE) $(INSTALLDIR)
2563

2664
uninstall:
27-
rm $(INSTALLDIR)/lpc.lv2/*.so
28-
rm $(INSTALLDIR)/lpc.lv2/*.ttl
29-
rmdir $(INSTALLDIR)/lpc.lv2
65+
rm $(INSTALLDIR)$(LV2_BUNDLE)*.so
66+
rm $(INSTALLDIR)$(LV2_BUNDLE)*.ttl
67+
rmdir $(INSTALLDIR)$(LV2_BUNDLE)
68+
69+
validate: $(LV2_BUNDLE)manifest.ttl $(LV2_BUNDLE)$(LV2_BIN).ttl
70+
sord_validate -l $(shell find -L /usr/include/lv2 /usr/lib/lv2/schemas.lv2 -type f -name '*.ttl') $(LV2_BUNDLE)manifest.ttl $(LV2_BUNDLE)$(LV2_BIN).ttl
71+
72+
.PHONY: all clean install uninstall validate
3073

31-
validate: manifest.ttl
32-
sord_validate -l $(shell find -L /usr/include/lv2 /usr/lib/lv2/schemas.lv2 -type f -name '*.ttl') manifest.ttl lpc_plugin.ttl

README

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Ideas of other possible features:
8888
* Try other pitch identification algorithms (e.g. FFT-based rather than
8989
autocorrelation)
9090
* Add MIDI portamento
91+
* Try using LV2 Workers to improve performance?
9192

9293
-- CREDITS --
9394

lpc_plugin.cpp

+7-23
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,27 @@
1010
#include <iostream>
1111

1212
#include "lpc.h"
13-
14-
#define LPC_URI "http://example.com/plugins/lpc_plugin"
13+
#include "lpc_plugin.h"
1514

1615
#define MIN_BUFFER_SIZE 512
1716
#define MAX_BUFFER_SIZE 4096
1817

19-
typedef enum {
20-
LPC_CONTROL,
21-
LPC_INPUT,
22-
LPC_OUTPUT,
23-
LPC_ORDER,
24-
LPC_WHISPER,
25-
LPC_LATENCY,
26-
LPC_OLA,
27-
LPC_GLOTTAL,
28-
LPC_PREEMPHASIS,
29-
LPC_PITCH,
30-
LPC_TUNING,
31-
LPC_BEND_RANGE,
32-
LPC_BUFFER_SIZE
33-
} PortIndex;
34-
3518
typedef struct {
3619
const LV2_Atom_Sequence* control;
3720
const float* input;
3821
float* output;
22+
float* latency;
3923

4024
const float* order;
25+
const float* buffer_size;
4126
const float* whisper;
42-
float* latency;
43-
const float* ola_enable;
27+
const float* ola;
4428
const float* glottal;
4529
const float* preemphasis;
4630
const float* pitch;
4731
const float* tuning;
4832
const float* bend_range;
49-
const float* buffer_size;
33+
5034

5135
LV2_URID midi_MidiEvent;
5236

@@ -148,7 +132,7 @@ static void connect_port (
148132
self->latency = (float*)data;
149133
break;
150134
case LPC_OLA:
151-
self->ola_enable = (const float*)data;
135+
self->ola = (const float*)data;
152136
break;
153137
case LPC_GLOTTAL:
154138
self->glottal = (const float*)data;
@@ -291,7 +275,7 @@ static void run (
291275
int* buffer2_pos = &(self->buffer2_pos);
292276
float* latency = self->latency;
293277

294-
const float* ola = self->ola_enable;
278+
const float* ola = self->ola;
295279

296280
int buffer_size = std::min(std::max((int)(*self->buffer_size),
297281
MIN_BUFFER_SIZE),MAX_BUFFER_SIZE);

lpc_plugin.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
typedef enum {
2+
LPC_CONTROL=0,
3+
LPC_INPUT=1,
4+
LPC_OUTPUT=2,
5+
LPC_LATENCY=3,
6+
LPC_ORDER=4,
7+
LPC_BUFFER_SIZE=5,
8+
LPC_WHISPER=6,
9+
LPC_OLA=7,
10+
LPC_GLOTTAL=8,
11+
LPC_PREEMPHASIS=9,
12+
LPC_PITCH=10,
13+
LPC_TUNING=11,
14+
LPC_BEND_RANGE=12
15+
} PortIndex;

lpc_plugin.ttl lpc_plugin.ttl.in

+34-32
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
55
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
66
@prefix units: <http://lv2plug.in/ns/extensions/units#> .
7-
@prefix urid: <http://lv2plug.in/ns/ext/urid#> .
8-
@prefix midi: <http://lv2plug.in/ns/ext/midi#> .
9-
@prefix atom: <http://lv2plug.in/ns/ext/atom#> .
7+
@prefix urid: <http://lv2plug.in/ns/ext/urid#> .
8+
@prefix midi: <http://lv2plug.in/ns/ext/midi#> .
9+
@prefix atom: <http://lv2plug.in/ns/ext/atom#> .
10+
@prefix ui: <http://lv2plug.in/ns/extensions/ui#> .
1011

11-
<http://example.com/plugins/lpc_plugin>
12+
<@LV2_URI@>
1213
a lv2:Plugin , doap:Project ;
1314
doap:name "Linear Predictive Coding" ;
1415
doap:license <http://usefulinc.com/doap/licenses/gpl> ;
@@ -18,6 +19,7 @@
1819
foaf:homepage <https://example.com> ;
1920
] ;
2021
lv2:optionalFeature lv2:hardRTCapable ;
22+
ui:ui <@LV2_URI@@UI_SUFFIX@> ;
2123
lv2:port [
2224
a lv2:InputPort ,
2325
atom:AtomPort ;
@@ -39,9 +41,17 @@
3941
lv2:symbol "out" ;
4042
lv2:name "Out"
4143
] , [
42-
a lv2:InputPort ,
44+
a lv2:OutputPort ,
4345
lv2:ControlPort ;
4446
lv2:index 3 ;
47+
lv2:symbol "latency" ;
48+
lv2:name "Latency" ;
49+
lv2:portProperty lv2:integer , lv2:reportsLatency ;
50+
units:unit units:frame ;
51+
] , [
52+
a lv2:InputPort ,
53+
lv2:ControlPort ;
54+
lv2:index 4 ;
4555
lv2:symbol "order" ;
4656
lv2:name "Order" ;
4757
lv2:portProperty lv2:integer ;
@@ -51,26 +61,29 @@
5161
] , [
5262
a lv2:InputPort ,
5363
lv2:ControlPort ;
54-
lv2:index 4 ;
64+
lv2:index 5 ;
65+
lv2:symbol "buffer_size" ;
66+
lv2:name "Buffer Size" ;
67+
lv2:default 2048 ;
68+
lv2:minimum 512 ;
69+
lv2:maximum 4096 ;
70+
lv2:portProperty lv2:integer ;
71+
units:unit units:frame ;
72+
] , [
73+
a lv2:InputPort ,
74+
lv2:ControlPort ;
75+
lv2:index 6 ;
5576
lv2:symbol "whisper" ;
5677
lv2:name "Whisper" ;
5778
lv2:portProperty lv2:toggled ;
5879
lv2:default 0 ;
5980
lv2:minimum 0 ;
6081
lv2:maximum 1 ;
61-
] , [
62-
a lv2:OutputPort ,
63-
lv2:ControlPort ;
64-
lv2:index 5 ;
65-
lv2:symbol "latency" ;
66-
lv2:name "Latency" ;
67-
lv2:portProperty lv2:integer , lv2:reportsLatency ;
68-
units:unit units:frame ;
6982
] , [
7083
a lv2:InputPort ,
7184
lv2:ControlPort ;
72-
lv2:index 6 ;
73-
lv2:symbol "ola_enable" ;
85+
lv2:index 7 ;
86+
lv2:symbol "ola" ;
7487
lv2:name "OLA" ;
7588
lv2:portProperty lv2:toggled ;
7689
lv2:default 0 ;
@@ -79,7 +92,7 @@
7992
] , [
8093
a lv2:InputPort ,
8194
lv2:ControlPort ;
82-
lv2:index 7 ;
95+
lv2:index 8 ;
8396
lv2:symbol "glottal" ;
8497
lv2:name "Glottal Pulse" ;
8598
lv2:portProperty lv2:toggled ;
@@ -89,7 +102,7 @@
89102
] , [
90103
a lv2:InputPort ,
91104
lv2:ControlPort ;
92-
lv2:index 8 ;
105+
lv2:index 9 ;
93106
lv2:symbol "preemphasis" ;
94107
lv2:name "Preemphasis" ;
95108
lv2:portProperty lv2:toggled ;
@@ -99,7 +112,7 @@
99112
] , [
100113
a lv2:InputPort ,
101114
lv2:ControlPort ;
102-
lv2:index 9 ;
115+
lv2:index 10 ;
103116
lv2:symbol "pitch" ;
104117
lv2:name "Pitch Shift" ;
105118
lv2:default 0 ;
@@ -109,7 +122,7 @@
109122
] , [
110123
a lv2:InputPort ,
111124
lv2:ControlPort ;
112-
lv2:index 10 ;
125+
lv2:index 11 ;
113126
lv2:symbol "tuning" ;
114127
lv2:name "MIDI Tuning" ;
115128
lv2:default 440 ;
@@ -119,22 +132,11 @@
119132
] , [
120133
a lv2:InputPort ,
121134
lv2:ControlPort ;
122-
lv2:index 11 ;
135+
lv2:index 12 ;
123136
lv2:symbol "bend_range" ;
124137
lv2:name "MIDI Bend Range" ;
125138
lv2:default 2 ;
126139
lv2:minimum 1 ;
127140
lv2:maximum 7 ;
128141
units:unit units:semitone12TET ;
129-
] , [
130-
a lv2:InputPort ,
131-
lv2:ControlPort ;
132-
lv2:index 12 ;
133-
lv2:symbol "buffer_size" ;
134-
lv2:name "Buffer Size" ;
135-
lv2:default 2048 ;
136-
lv2:minimum 512 ;
137-
lv2:maximum 4096 ;
138-
lv2:portProperty lv2:integer ;
139-
units:unit units:frame ;
140142
] .

lpc_plugin_ui.ttl.in

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
<@LV2_URI@@UI_SUFFIX@>
3+
a @UI_TYPE@ ;
4+
lv2:requiredFeature urid:map
5+
.
6+

0 commit comments

Comments
 (0)