record batch dir path fix, handle yuv in gl masking, sync up maskengine/playback3d...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / pluginlv2.h
1 #ifndef __PLUGINLV2_H__
2 #define __PLUGINLV2_H__
3
4 #define LV2_SEQ_SIZE  9624
5 #include "forkbase.h"
6 #include "pluginlv2config.h"
7 #include "samples.inc"
8
9 #include <lilv/lilv.h>
10 #define NS_EXT "http://lv2plug.in/ns/ext/"
11
12 typedef struct {
13         int64_t sz;
14         int samples, done;
15         int nb_inputs, nb_outputs;
16 } shm_bfr_t;
17
18 #define PORTS_AUDIO   0x01
19 #define PORTS_CONTROL 0x02
20 #define PORTS_ATOM    0x04
21 #define PORTS_ALL (PORTS_AUDIO | PORTS_CONTROL | PORTS_ATOM)
22 #define PORTS_INPUT   0x08
23 #define PORTS_OUTPUT  0x10
24 #define PORTS_UPDATE  0x20
25
26 class PluginLV2Options : public ArrayList<LV2_Options_Option>
27 {
28 public:
29         PluginLV2Options() {}
30         ~PluginLV2Options() {}
31         void add(LV2_URID key, unsigned sz, LV2_URID typ, void *vp) {
32                 LV2_Options_Option *ap = &append();
33                 ap->context = LV2_OPTIONS_INSTANCE; ap->subject = 0;
34                 ap->key = key; ap->size = sz; ap->type = typ; ap->value = vp;
35         }
36 };
37
38 class PluginLV2Work
39 {
40 public:
41         PluginLV2Work();
42         ~PluginLV2Work();
43         void load(const void *vp, unsigned size);
44
45         PluginLV2Work *next;
46         unsigned alloc, used;
47         char *data;
48 };
49
50 class PluginLV2
51 {
52 public:
53         PluginLV2();
54         virtual ~PluginLV2();
55
56         shm_bfr_t *shm_bfr;
57         int use_shm, shmid;
58         float **in_buffers, **out_buffers;
59         int *iport, *oport;
60         int nb_inputs, nb_outputs;
61         int max_bufsz, ui_features;
62
63         void reset_lv2();
64         int load_lv2(const char *path,char *title=0);
65         int init_lv2(PluginLV2ClientConfig &conf, int sample_rate, int bfrsz);
66         virtual int is_forked() { return 0; }
67         static uint32_t map_uri(LV2_URID_Map_Handle handle, const char *uri);
68         static const char *unmap_uri(LV2_URID_Unmap_Handle handle, LV2_URID urid);
69         LV2_URID_Map uri_map;
70         LV2_URID_Unmap uri_unmap;
71         void connect_ports(PluginLV2ClientConfig &conf, int ports);
72         void del_buffer();
73         void new_buffer(int64_t sz);
74         shm_bfr_t *shm_buffer(int shmid);
75         void init_buffer(int samples);
76         void map_buffer();
77
78         LilvWorld         *world;
79         const LilvPlugin  *lilv;
80         LilvUIs           *lilv_uis;
81
82         PluginLV2UriTable  uri_table;
83         LV2_URID_Map       map;
84         LV2_Feature        map_feature;
85         LV2_URID_Unmap     unmap;
86         LV2_Feature        unmap_feature;
87
88         PluginLV2Options   options;
89         Lv2Features        features;
90         LV2_Atom_Sequence  seq_in[2];
91         LV2_Atom_Sequence  *seq_out;
92         float samplerate, refreshrate;
93         int min_block_length, block_length;
94         int midi_buf_size;
95
96         LilvInstance *inst;
97         SuilInstance *sinst;
98         SuilHost *ui_host;
99
100         LilvNode *atom_AtomPort;
101         LilvNode *atom_Sequence;
102         LilvNode *lv2_AudioPort;
103         LilvNode *lv2_CVPort;
104         LilvNode *lv2_ControlPort;
105         LilvNode *lv2_Optional;
106         LilvNode *lv2_InputPort;
107         LilvNode *lv2_OutputPort;
108         LilvNode *powerOf2BlockLength;
109         LilvNode *fixedBlockLength;
110         LilvNode *boundedBlockLength;
111
112         LV2_URID atom_int;
113         LV2_URID atom_float;
114
115         LV2_URID param_sampleRate;
116         LV2_URID bufsz_minBlockLength;
117         LV2_URID bufsz_maxBlockLength;
118         LV2_URID bufsz_sequenceSize;
119         LV2_URID ui_updateRate;
120
121         pthread_t worker_thread;
122         LV2_Worker_Interface *worker_iface;
123         static void *worker_func(void *vp);
124         void *worker_func();
125         void worker_start();
126         void worker_stop();
127         LV2_Worker_Status worker_schedule(uint32_t inp_size, const void *inp_data);
128         static LV2_Worker_Status lv2_worker_schedule(LV2_Worker_Schedule_Handle vp,
129                         uint32_t inp_size, const void *inp_data);
130         LV2_Worker_Status worker_respond(uint32_t out_size, const void *out_data);
131         static LV2_Worker_Status lv2_worker_respond(LV2_Worker_Respond_Handle vp,
132                         uint32_t out_size, const void *out_data);
133         PluginLV2Work *get_work();
134         void work_stop(PluginLV2Work *&work);
135         void worker_responses();
136
137         LV2_Worker_Schedule schedule;
138         PluginLV2Work *work_avail, *work_input;
139         PluginLV2Work *work_output, **work_tail;
140         pthread_mutex_t worker_lock;
141         pthread_cond_t worker_ready;
142         int worker_done;
143 };
144
145 typedef struct { int sample_rate, bfrsz;  char path[1]; } open_bfr_t;
146
147 enum { NO_COMMAND,
148         LV2_OPEN,
149         LV2_LOAD,
150         LV2_CONFIG,
151         LV2_UPDATE,
152         LV2_SHOW,
153         LV2_HIDE,
154         LV2_SHMID,
155         NB_COMMANDS };
156
157 #endif