3 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
21 #ifndef __PLUGINLV2_H__
22 #define __PLUGINLV2_H__
24 #define LV2_SEQ_SIZE 9624
26 #include "pluginlv2config.h"
27 #include "samples.inc"
29 #include <lilv/lilv.h>
30 #define NS_EXT "http://lv2plug.in/ns/ext/"
35 int nb_inputs, nb_outputs;
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
46 class PluginLV2Options : public ArrayList<LV2_Options_Option>
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;
63 void load(const void *vp, unsigned size);
78 float **in_buffers, **out_buffers;
80 int nb_inputs, nb_outputs;
81 int max_bufsz, ui_features;
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);
90 LV2_URID_Unmap uri_unmap;
91 void connect_ports(PluginLV2ClientConfig &conf, int ports);
93 void new_buffer(int64_t sz);
94 shm_bfr_t *shm_buffer(int shmid);
95 void init_buffer(int samples);
99 const LilvPlugin *lilv;
102 PluginLV2UriTable uri_table;
104 LV2_Feature map_feature;
105 LV2_URID_Unmap unmap;
106 LV2_Feature unmap_feature;
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;
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;
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;
141 pthread_t worker_thread;
142 LV2_Worker_Interface *worker_iface;
143 static void *worker_func(void *vp);
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();
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;
165 typedef struct { int sample_rate, bfrsz; char path[1]; } open_bfr_t;