no longer need ffmpeg patch0 which was for Termux
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / pluginlv2.h
1 /*
2  * CINELERRA
3  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  */
20
21 #ifndef __PLUGINLV2_H__
22 #define __PLUGINLV2_H__
23
24 #define LV2_SEQ_SIZE  9624
25 #include "forkbase.h"
26 #include "pluginlv2config.h"
27 #include "samples.inc"
28
29 #include <lilv/lilv.h>
30 #define NS_EXT "http://lv2plug.in/ns/ext/"
31
32 typedef struct {
33         int64_t sz;
34         int samples, done;
35         int nb_inputs, nb_outputs;
36 } shm_bfr_t;
37
38 #define PORTS_AUDIO   0x01
39 #define PORTS_CONTROL 0x02
40 #define PORTS_ATOM    0x04
41 #define PORTS_ALL (PORTS_AUDIO | PORTS_CONTROL | PORTS_ATOM)
42 #define PORTS_INPUT   0x08
43 #define PORTS_OUTPUT  0x10
44 #define PORTS_UPDATE  0x20
45
46 class PluginLV2Options : public ArrayList<LV2_Options_Option>
47 {
48 public:
49         PluginLV2Options() {}
50         ~PluginLV2Options() {}
51         void add(LV2_URID key, unsigned sz, LV2_URID typ, void *vp) {
52                 LV2_Options_Option *ap = &append();
53                 ap->context = LV2_OPTIONS_INSTANCE; ap->subject = 0;
54                 ap->key = key; ap->size = sz; ap->type = typ; ap->value = vp;
55         }
56 };
57
58 class PluginLV2Work
59 {
60 public:
61         PluginLV2Work();
62         ~PluginLV2Work();
63         void load(const void *vp, unsigned size);
64
65         PluginLV2Work *next;
66         unsigned alloc, used;
67         char *data;
68 };
69
70 class PluginLV2
71 {
72 public:
73         PluginLV2();
74         virtual ~PluginLV2();
75
76         shm_bfr_t *shm_bfr;
77         int use_shm, shmid;
78         float **in_buffers, **out_buffers;
79         int *iport, *oport;
80         int nb_inputs, nb_outputs;
81         int max_bufsz, ui_features;
82
83         void reset_lv2();
84         int load_lv2(const char *path,char *title=0);
85         int init_lv2(PluginLV2ClientConfig &conf, int sample_rate, int bfrsz);
86         virtual int is_forked() { return 0; }
87         static uint32_t map_uri(LV2_URID_Map_Handle handle, const char *uri);
88         static const char *unmap_uri(LV2_URID_Unmap_Handle handle, LV2_URID urid);
89         LV2_URID_Map uri_map;
90         LV2_URID_Unmap uri_unmap;
91         void connect_ports(PluginLV2ClientConfig &conf, int ports);
92         void del_buffer();
93         void new_buffer(int64_t sz);
94         shm_bfr_t *shm_buffer(int shmid);
95         void init_buffer(int samples);
96         void map_buffer();
97
98         LilvWorld         *world;
99         const LilvPlugin  *lilv;
100         LilvUIs           *lilv_uis;
101
102         PluginLV2UriTable  uri_table;
103         LV2_URID_Map       map;
104         LV2_Feature        map_feature;
105         LV2_URID_Unmap     unmap;
106         LV2_Feature        unmap_feature;
107
108         PluginLV2Options   options;
109         Lv2Features        features;
110         LV2_Atom_Sequence  seq_in[2];
111         LV2_Atom_Sequence  *seq_out;
112         float samplerate, refreshrate;
113         int min_block_length, block_length;
114         int midi_buf_size;
115
116         LilvInstance *inst;
117         SuilInstance *sinst;
118         SuilHost *ui_host;
119
120         LilvNode *atom_AtomPort;
121         LilvNode *atom_Sequence;
122         LilvNode *lv2_AudioPort;
123         LilvNode *lv2_CVPort;
124         LilvNode *lv2_ControlPort;
125         LilvNode *lv2_Optional;
126         LilvNode *lv2_InputPort;
127         LilvNode *lv2_OutputPort;
128         LilvNode *powerOf2BlockLength;
129         LilvNode *fixedBlockLength;
130         LilvNode *boundedBlockLength;
131
132         LV2_URID atom_int;
133         LV2_URID atom_float;
134
135         LV2_URID param_sampleRate;
136         LV2_URID bufsz_minBlockLength;
137         LV2_URID bufsz_maxBlockLength;
138         LV2_URID bufsz_sequenceSize;
139         LV2_URID ui_updateRate;
140
141         pthread_t worker_thread;
142         LV2_Worker_Interface *worker_iface;
143         static void *worker_func(void *vp);
144         void *worker_func();
145         void worker_start();
146         void worker_stop();
147         LV2_Worker_Status worker_schedule(uint32_t inp_size, const void *inp_data);
148         static LV2_Worker_Status lv2_worker_schedule(LV2_Worker_Schedule_Handle vp,
149                         uint32_t inp_size, const void *inp_data);
150         LV2_Worker_Status worker_respond(uint32_t out_size, const void *out_data);
151         static LV2_Worker_Status lv2_worker_respond(LV2_Worker_Respond_Handle vp,
152                         uint32_t out_size, const void *out_data);
153         PluginLV2Work *get_work();
154         void work_stop(PluginLV2Work *&work);
155         void worker_responses();
156
157         LV2_Worker_Schedule schedule;
158         PluginLV2Work *work_avail, *work_input;
159         PluginLV2Work *work_output, **work_tail;
160         pthread_mutex_t startup_lock, worker_lock;
161         pthread_cond_t worker_ready;
162         int worker_done;
163 };
164
165 typedef struct { int sample_rate, bfrsz;  char path[1]; } open_bfr_t;
166
167 enum { NO_COMMAND,
168         LV2_OPEN,
169         LV2_LOAD,
170         LV2_CONFIG,
171         LV2_UPDATE,
172         LV2_SHOW,
173         LV2_HIDE,
174         LV2_SHMID,
175         NB_COMMANDS };
176
177 #endif