remove auto kfrm for gang, btn2 select kfrm pos
[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
68         static LV2_URID uri_table_map(LV2_URID_Map_Handle handle, const char *uri);
69         static const char *uri_table_unmap(LV2_URID_Map_Handle handle, LV2_URID urid);
70         static uint32_t uri_to_id(LV2_URI_Map_Callback_Data callback_data,
71                         const char *map, const char *uri);
72         void connect_ports(PluginLV2ClientConfig &conf, int ports);
73         void del_buffer();
74         void new_buffer(int64_t sz);
75         shm_bfr_t *shm_buffer(int shmid);
76         void init_buffer(int samples);
77         void map_buffer();
78
79         LilvWorld         *world;
80         const LilvPlugin  *lilv;
81         LilvUIs           *lilv_uis;
82
83         LV2_URI_Map_Feature uri_map;
84         PluginLV2UriTable  uri_table;
85         LV2_URID_Map       map;
86         LV2_Feature        map_feature;
87         LV2_URID_Unmap     unmap;
88         LV2_Feature        unmap_feature;
89
90         PluginLV2Options   options;
91         Lv2Features        features;
92         LV2_Atom_Sequence  seq_in[2];
93         LV2_Atom_Sequence  *seq_out;
94         float samplerate, refreshrate;
95         int block_length, midi_buf_size;
96
97         LilvInstance *inst;
98         SuilInstance *sinst;
99         SuilHost *ui_host;
100
101         LilvNode *atom_AtomPort;
102         LilvNode *atom_Sequence;
103         LilvNode *lv2_AudioPort;
104         LilvNode *lv2_CVPort;
105         LilvNode *lv2_ControlPort;
106         LilvNode *lv2_Optional;
107         LilvNode *lv2_InputPort;
108         LilvNode *lv2_OutputPort;
109         LilvNode *powerOf2BlockLength;
110         LilvNode *fixedBlockLength;
111         LilvNode *boundedBlockLength;
112
113         LV2_URID atom_int;
114         LV2_URID atom_float;
115
116         LV2_URID param_sampleRate;
117         LV2_URID bufsz_minBlockLength;
118         LV2_URID bufsz_maxBlockLength;
119         LV2_URID bufsz_sequenceSize;
120         LV2_URID ui_updateRate;
121
122         pthread_t worker_thread;
123         LV2_Worker_Interface *worker_iface;
124         static void *worker_func(void *vp);
125         void *worker_func();
126         void worker_start();
127         void worker_stop();
128         LV2_Worker_Status worker_schedule(uint32_t inp_size, const void *inp_data);
129         static LV2_Worker_Status lv2_worker_schedule(LV2_Worker_Schedule_Handle vp,
130                         uint32_t inp_size, const void *inp_data);
131         LV2_Worker_Status worker_respond(uint32_t out_size, const void *out_data);
132         static LV2_Worker_Status lv2_worker_respond(LV2_Worker_Respond_Handle vp,
133                         uint32_t out_size, const void *out_data);
134         PluginLV2Work *get_work();
135         void work_stop(PluginLV2Work *&work);
136         void worker_responses();
137
138         LV2_Worker_Schedule schedule;
139         PluginLV2Work *work_avail, *work_input;
140         PluginLV2Work *work_output, **work_tail;
141         pthread_mutex_t worker_lock;
142         pthread_cond_t worker_ready;
143         int worker_done;
144 };
145
146 typedef struct { int sample_rate, bfrsz;  char path[1]; } open_bfr_t;
147
148 enum { NO_COMMAND,
149         LV2_OPEN,
150         LV2_LOAD,
151         LV2_UPDATE,
152         LV2_SHOW,
153         LV2_HIDE,
154         LV2_SHMID,
155         NB_COMMANDS };
156
157 #endif