prevent popup deactivation while button_down
[goodguy/history.git] / cinelerra-5.1 / cinelerra / pluginserver.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * 
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  * 
20  */
21
22 #ifndef PLUGINSERVER_H
23 #define PLUGINSERVER_H
24
25 // inherited by plugins
26
27
28 #include <stdio.h>
29 #include <stdint.h>
30 #include <string.h>
31 #include <unistd.h>
32
33 #include "arraylist.h"
34 #include "attachmentpoint.inc"
35 #include "edl.inc"
36 #include "floatauto.inc"
37 #include "floatautos.inc"
38 #include "garbage.h"
39 #include "keyframe.inc"
40 #include "ladspa.h"
41 #include "mainprogress.inc"
42 #include "maxbuffers.h"
43 #include "menueffects.inc"
44 #include "module.inc"
45 #include "mwindow.inc"
46 #include "plugin.inc"
47 #include "pluginaclientlad.inc"
48 #include "pluginfclient.inc"
49 #include "pluginclient.inc"
50 #include "pluginserver.inc"
51 #include "preferences.inc"
52 #include "samples.inc"
53 #include "theme.inc"
54 #include "thread.h"
55 #include "track.inc"
56 #include "vframe.inc"
57 #include "videodevice.inc"
58 #include "virtualnode.inc"
59
60 #include <dlfcn.h>
61
62 class PluginObj : public Garbage {
63         void *dlobj;
64 public:
65
66         void *load(const char *dlp) { return dlobj = dlopen(dlp, RTLD_NOW); }
67         void *load(const char *plugin_dir, const char *path);
68         void unload(void *obj) { dlclose(obj); }
69         void *load_sym(const char *sym) { return dlsym(dlobj, sym); }
70         const char *load_error() { return dlerror(); }
71         void *obj() { return dlobj; }
72
73         PluginObj() : Garbage("PluginObj:Garbage") { dlobj = 0; }
74         ~PluginObj() { if( dlobj ) unload(dlobj); }
75 };
76
77 class PluginServer
78 {
79         PluginObj *plugin_obj;
80         int load_obj();
81         const char *load_error();
82         void *get_sym(const char *sym);
83
84         int reset_parameters();
85         void init();
86         int cleanup_plugin();
87
88 // Base class created by client
89         PluginClient *client;
90 // If no path, this is going to be set to a function which 
91 // instantiates the plugin.
92         PluginClient* (*new_plugin)(PluginServer*);
93
94 // LAD support
95         int lad_index;
96         LADSPA_Descriptor_Function lad_descriptor_function;
97         const LADSPA_Descriptor *lad_descriptor;
98         int use_opengl;
99 // FFMPEG support
100         const char *ff_name;
101 // Driver for opengl calls.
102         VideoDevice *vdevice;
103 public:
104         PluginServer();
105         PluginServer(MWindow *mwindow, char *path, int type);
106         PluginServer(PluginServer &);
107         virtual ~PluginServer();
108
109         friend class PluginAClientLAD;
110         friend class PluginAClientConfig;
111         friend class PluginAClientWindow;
112
113         friend class PluginFClient;
114         friend class PluginFAClient;
115         friend class PluginFVClient;
116         friend class PluginFClientConfig;
117         friend class PluginFClientWindow;
118
119 // open a plugin and wait for commands
120 // Get information for plugindb if master.
121 #define PLUGINSERVER_IS_LAD 2
122 #define PLUGINSERVER_NOT_RECOGNIZED 1
123 #define PLUGINSERVER_OK 0
124         int open_plugin(int master, Preferences *preferences,
125                         EDL *edl, Plugin *plugin);
126 // close the plugin
127         int close_plugin();    
128         int get_theme_png_path(char *png_path, const char *theme_dir);
129         int get_theme_png_path(char *png_path, Theme *theme);
130         int get_plugin_png_path(char *png_path);
131         void dump(FILE *fp=stdout);
132 // Release any objects which are required after playback stops.
133         void render_stop();
134 // Write entry into plugin table
135         void write_table(FILE *fp, const char *path, int idx, int64_t mtime);
136         static int scan_table(char *text, int &type, char *path, char *title, int64_t &mtime);
137         int read_table(char *text);
138 // queries
139         void set_title(const char *string);
140 // Generate title for display
141         void generate_display_title(char *string);
142 // Get keyframes for configuration.  Position is always relative to EDL rate.
143         KeyFrame* get_prev_keyframe(int64_t position);
144         KeyFrame* get_next_keyframe(int64_t position);
145 // get camera and projector positions
146         void get_camera(float *x, float *y, float *z,
147                         int64_t position, int direction);
148         void get_projector(float *x, float *y, float *z,
149                         int64_t position, int direction);
150 // Get interpolation used by EDL
151         int get_interpolation_type();
152 // Get or create keyframe for writing, depending on whether auto keyframes
153 // is enabled.  Called by PluginClient::send_configure_change
154         KeyFrame* get_keyframe();
155 // Apply new settings from the plugin GUI.  Called by PluginClient::send_configure_change
156 // Used in keyframe spanning mode.
157         void apply_keyframe(KeyFrame *src);
158
159 // Create new theme object.  Used by theme plugins.
160         Theme* new_theme();
161 // Get theme being used by Cinelerra currently.  Used by all plugins.
162         Theme* get_theme();
163 // Get picon png vframe image
164         VFrame *get_picon();
165         VFrame *get_plugin_images();
166
167 // ladspa
168         void set_lad_index(int i);
169         int get_lad_index();
170         int is_ladspa();
171 // ffmpeg
172         int is_ffmpeg();
173         PluginClient *new_ffmpeg_plugin();
174 // =============================== for realtime plugins
175 // save configuration of plugin
176         void save_data(KeyFrame *keyframe);          
177 // Update EDL and playback engines to reflect changes
178         void sync_parameters();
179 // set for realtime processor usage
180         int set_realtime_sched();
181         int get_gui_status();
182 // Raise the GUI
183         void raise_window();
184 // cause the plugin to show the GUI
185 // Called by MWindow::show_plugin
186         void show_gui();          
187         void hide_gui();
188 // Update GUI with keyframe settings
189         void update_gui();
190         void update_title();
191         void client_side_close();
192 // Set to 1 before every process call if the user supports OpenGL buffers.
193 // Also provides the driver location.
194         void set_use_opengl(int value, VideoDevice *vdevice);
195 // Plugin must call this before performing OpenGL operations.
196         int get_use_opengl();
197
198 // Called from plugin client
199 // Returns 1 if a GUI is open so OpenGL routines can determine if
200 // they can run.
201         int gui_open();
202 // Called by plugin client to request synchronous routine.
203         void run_opengl(PluginClient *plugin_client);
204
205 // set the string that appears on the plugin title
206         int set_string(char *string);
207 // give the buffers and sizes and prepare processing realtime data
208         int init_realtime(int realtime_sched,
209                 int total_in_buffers,
210                 int buffer_size);   
211 // process the data in the buffers
212 // input - the current edit's data
213 // output - the previous edit's data and the destination of the transition output
214 // current_position - Position from start of the transition and 
215 //     relative to the transition.
216 // total_len - total len for transition
217         void process_transition(VFrame *input, 
218                 VFrame *output, 
219                 int64_t current_position,
220                 int64_t total_len);  
221         void process_transition(Samples *input, 
222                 Samples *output,
223                 int64_t current_position, 
224                 int64_t fragment_size,
225                 int64_t total_len);
226
227 // Process using pull method.
228 // current_position - start of region if forward, end of region if reverse
229 //     relative to requested rate
230 // fragment_size - amount of data to put in buffer relative to requested rate
231 // sample_rate - sample rate of requested output
232 // frame_rate - frame rate of requested output
233 // total_len - length of plugin in track units relative to the EDL rate
234 // Units are kept relative to the EDL rate so plugins don't need to convert rates
235 // to get the keyframes.
236         void process_buffer(VFrame **frame, 
237                 int64_t current_position,
238                 double frame_rate,
239                 int64_t total_len,
240                 int direction);
241         void process_buffer(Samples **buffer,
242                 int64_t current_position,
243                 int64_t fragment_size,
244                 int64_t sample_rate,
245                 int64_t total_len,
246                 int direction);
247
248 // Called by rendering client to cause the GUI to display something with the data.
249         void send_render_gui(void *data);
250         void send_render_gui(void *data, int size);
251 // Called by MWindow to cause GUI to display
252         void render_gui(void *data);
253         void render_gui(void *data, int size);
254
255 // Send the boundary autos of the next fragment
256         int set_automation(FloatAutos *autos, FloatAuto **start_auto, FloatAuto **end_auto, int reverse);
257
258
259
260 // set the fragment position of a buffer before rendering
261         int arm_buffer(int buffer_number, 
262                                 int64_t in_fragment_position, 
263                                 int64_t out_fragment_position,
264                                 int double_buffer_in,
265                                 int double_buffer_out);
266 // Detach all the shared buffers.
267         int detach_buffers();
268
269         int send_buffer_info();
270
271
272 // ============================ for non realtime plugins
273 // start processing data in plugin
274         int start_loop(int64_t start, int64_t end, int64_t buffer_size, int total_buffers);
275 // Do one iteration of a nonrealtime plugin and return if finished
276         int process_loop(VFrame **buffers, int64_t &write_length);
277         int process_loop(Samples **buffers, int64_t &write_length);
278         int stop_loop();
279
280
281 // Called by client to read data in non-realtime effect
282         int read_frame(VFrame *buffer, 
283                 int channel, 
284                 int64_t start_position);
285         int read_samples(Samples *buffer, 
286                 int channel, 
287                 int64_t start_position,
288                 int64_t len);
289
290
291 // Called by client to read data in realtime effect.  
292 // Returns -1 if error or 0 if success.
293         int read_frame(VFrame *buffer, 
294                 int channel, 
295                 int64_t start_position, 
296                 double frame_rate,
297 // Set to 1 if the reader can use OpenGL objects.
298                 int use_opengl = 0);
299         int read_samples(Samples *buffer,
300                 int channel,
301                 int64_t sample_rate,
302                 int64_t start_position,
303                 int64_t len);
304
305 // For non realtime, prompt user for parameters, waits for plugin to finish and returns a result
306         int get_parameters(int64_t start, int64_t end, int channels);
307         int get_samplerate();      // get samplerate produced by plugin
308         double get_framerate();     // get framerate produced by plugin
309         int get_project_samplerate();            // get samplerate of project data before processing
310         double get_project_framerate();         // get framerate of project data before processing
311         void set_path(const char *path);        // required first
312         char *get_path();
313         int get_synthesis();
314         void get_defaults_path(char *path);
315         void save_defaults();
316 // Used by PluginArray and MenuEffects to get user parameters and progress bar.
317 // Set pointer to mwindow for opening GUI and reconfiguring EDL.
318         void set_mwindow(MWindow *mwindow);
319 // Used in VirtualConsole
320 // Set pointer to AttachmentPoint to render GUI.
321         void set_attachmentpoint(AttachmentPoint *attachmentpoint);
322 // Set pointer to a default keyframe when there is no plugin
323         void set_keyframe(KeyFrame *keyframe);
324 // Set pointer to menueffect window
325         void set_prompt(MenuEffectPrompt *prompt);
326         int set_interactive();             // make this the master plugin for progress bars
327         int set_error();         // flag to send plugin an error on next request
328         MainProgressBar* start_progress(char *string, int64_t length);
329
330 // add track to the list of affected tracks for a non realtime plugin
331         void append_module(Module *module);
332 // add node for realtime plugin
333         void append_node(VirtualNode *node);
334 // reset node table after virtual console reconfiguration
335         void reset_nodes();
336
337         int64_t get_written_samples();   // after samples are written, get the number written
338         int64_t get_written_frames();   // after frames are written, get the number written
339
340 // client origin
341         int plugin_type;
342
343 // buffers
344         int64_t out_buffer_size;   // size of a send buffer to the plugin
345         int64_t in_buffer_size;    // size of a recieve buffer from the plugin
346         int total_in_buffers;
347         int total_out_buffers;
348
349 // number of double buffers for each channel
350         ArrayList<int> ring_buffers_in;    
351         ArrayList<int> ring_buffers_out;
352 // Parameters for automation.  Setting autos to 0 disables automation.
353         FloatAuto **start_auto, **end_auto;
354         FloatAutos *autos;
355         int reverse;
356
357 // size of each buffer
358         ArrayList<int64_t> realtime_in_size;
359         ArrayList<int64_t> realtime_out_size;
360
361 // When arming buffers need to know the offsets in all the buffers and which
362 // double buffers for each channel before rendering.
363         ArrayList<int64_t> offset_in_render;
364         ArrayList<int64_t> offset_out_render;
365         ArrayList<int64_t> double_buffer_in_render;
366         ArrayList<int64_t> double_buffer_out_render;
367
368 // don't delete buffers if they belong to a virtual module
369         int shared_buffers;
370 // Send new buffer information for next render
371         int new_buffers;
372
373
374         int plugin_open;                 // Whether or not the plugin is open.
375 // Specifies what type of plugin.
376         int realtime, multichannel, fileio;  
377 // Plugin generates media
378         int synthesis;
379 // What data types the plugin can handle.  One of these is set.
380         int audio, video, theme;
381 // Can display a GUI
382         int uses_gui;
383 // Plugin is a transition
384         int transition;
385 // name of plugin in english.
386 // Compared against the title value in the plugin for resolving symbols.
387         char *title;
388         int64_t written_samples, written_frames;
389         char *path;           // location of plugin on disk
390         char *data_text;      // pointer to the data that was requested by a save_data command
391         char *args[4];
392         int total_args;
393         int error_flag;       // send plugin an error code on next request
394         int dir_idx;          // directory id, for icon visibility grouping
395 // Pointers to tracks affected by this plugin during a non realtime operation.
396 // Allows read functions to read data.
397         ArrayList<Module*> *modules;
398 // Used by realtime read functions to get data.  Corresponds to the buffer table in the
399 // attachment point.
400         ArrayList<VirtualNode*> *nodes;
401         AttachmentPoint *attachmentpoint;
402         MWindow *mwindow;
403 // Pointer to keyframe when plugin is not available
404         KeyFrame *keyframe;
405         AttachmentPoint *attachment;
406 // Storage of keyframes and GUI status
407         Plugin *plugin;
408
409 // Storage of session parameters
410         EDL *edl;
411         Preferences *preferences;
412         MenuEffectPrompt *prompt;
413         int gui_on;
414
415         VFrame *temp_frame;
416
417 // Icon for tracking update
418         VFrame *picon;
419 };
420
421
422 #endif