remove whitespace at eol
[goodguy/history.git] / cinelerra-5.1 / cinelerra / pluginclient.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2011 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 PLUGINCLIENT_H
23 #define PLUGINCLIENT_H
24
25 // Base class inherited by all the different types of plugins.
26
27 #define MAX_FRAME_BUFFER 1024
28
29 class PluginClient;
30
31
32 #include "arraylist.h"
33 #include "bchash.inc"
34 #include "condition.h"
35 #include "edlsession.inc"
36 #include "keyframe.h"
37 #include "mainprogress.inc"
38 #include "maxbuffers.h"
39 #include "pluginclient.inc"
40 #include "plugincommands.h"
41 #include "pluginserver.inc"
42 #include "samples.inc"
43 #include "theme.inc"
44 #include "vframe.h"
45
46
47 extern "C"
48 {
49 extern PluginClient* new_plugin(PluginServer *server);
50 }
51
52 class PluginClientAuto
53 {
54 public:
55         float position;
56         float intercept;
57         float slope;
58 };
59
60
61
62
63 // Convenience functions
64
65 #define REGISTER_PLUGIN(class_title) \
66 PluginClient* new_plugin(PluginServer *server) \
67 { \
68         return new class_title(server); \
69 }
70
71
72
73
74
75
76
77
78 // Prototypes for user to put in class header
79 #define PLUGIN_CLASS_MEMBERS(config_name) \
80         int load_configuration(); \
81         const char* plugin_title(); \
82         PluginClientWindow* new_window(); \
83         config_name config;
84
85
86
87 // Prototypes for user to put in class header
88 #define PLUGIN_CLASS_MEMBERS2(config_name) \
89         int load_configuration(); \
90         const char* plugin_title(); \
91         PluginClientWindow* new_window(); \
92         config_name config;
93
94
95
96
97
98 #define NEW_WINDOW_MACRO(plugin_class, window_class) \
99 PluginClientWindow* plugin_class::new_window() \
100 { \
101         return new window_class(this); \
102 }
103
104 // Not all plugins load configuration the same way.  Use this to define
105 // the normal way.
106 #define LOAD_CONFIGURATION_MACRO(plugin_class, config_class) \
107 int plugin_class::load_configuration() \
108 { \
109         KeyFrame *prev_keyframe, *next_keyframe; \
110         prev_keyframe = get_prev_keyframe(get_source_position()); \
111         next_keyframe = get_next_keyframe(get_source_position()); \
112  \
113         int64_t next_position = edl_to_local(next_keyframe->position); \
114         int64_t prev_position = edl_to_local(prev_keyframe->position); \
115  \
116         config_class old_config, prev_config, next_config; \
117         old_config.copy_from(config); \
118         read_data(prev_keyframe); \
119         prev_config.copy_from(config); \
120         read_data(next_keyframe); \
121         next_config.copy_from(config); \
122  \
123         config.interpolate(prev_config,  \
124                 next_config,  \
125                 (next_position == prev_position) ? \
126                         get_source_position() : \
127                         prev_position, \
128                 (next_position == prev_position) ? \
129                         get_source_position() + 1 : \
130                         next_position, \
131                 get_source_position()); \
132  \
133         if(!config.equivalent(old_config)) \
134                 return 1; \
135         else \
136                 return 0; \
137 }
138
139
140
141
142 class PluginClientWindow : public BC_Window
143 {
144 public:
145         PluginClientWindow(PluginClient *client,
146                 int w,
147                 int h,
148                 int min_w,
149                 int min_h,
150                 int allow_resize);
151         PluginClientWindow(const char *title,
152                 int x,
153                 int y,
154                 int w,
155                 int h,
156                 int min_w,
157                 int min_h,
158                 int allow_resize);
159         virtual ~PluginClientWindow();
160
161         virtual int translation_event();
162         virtual int close_event();
163
164         PluginClient *client;
165 };
166
167
168
169
170 class PluginClientThread : public Thread
171 {
172 public:
173         PluginClientThread(PluginClient *client);
174         ~PluginClientThread();
175         void run();
176
177         friend class PluginClient;
178
179         BC_WindowBase* get_window();
180         PluginClient* get_client();
181         BC_WindowBase *window;
182         PluginClient *client;
183
184 private:
185         Condition *init_complete;
186 };
187
188
189
190 // Client overrides for GUI update data
191 class PluginClientFrame
192 {
193 public:
194 // Period_d is 1 second
195         PluginClientFrame(int data_size, int period_n, int period_d);
196         virtual ~PluginClientFrame();
197         int data_size;
198         int period_n;
199         int period_d;
200 // Draw immediately
201         int force;
202 };
203
204
205
206 class PluginClient
207 {
208 public:
209         PluginClient(PluginServer *server);
210         virtual ~PluginClient();
211
212         friend class PluginClientThread;
213         friend class PluginClientWindow;
214
215 // Queries for the plugin server.
216         virtual int is_realtime();
217         virtual int is_audio();
218         virtual int is_video();
219         virtual int is_fileio();
220         virtual int is_theme();
221         virtual int uses_gui();
222         virtual int is_multichannel();
223         virtual int is_synthesis();
224         virtual int is_transition();
225         virtual const char* plugin_title();   // return the title of the plugin
226         virtual Theme* new_theme();
227 // Get theme being used by Cinelerra currently.  Used by all plugins.
228         Theme* get_theme();
229
230
231
232
233
234
235 // Non realtime signal processors define these.
236 // Give the samplerate of the output for a non realtime plugin.
237 // For realtime plugins give the requested samplerate.
238         virtual int get_samplerate();
239 // Give the framerate of the output for a non realtime plugin.
240 // For realtime plugins give the requested framerate.
241         virtual double get_framerate();
242         virtual int delete_nonrealtime_parameters();
243         virtual int get_parameters();     // get information from user before non realtime processing
244         virtual int64_t get_in_buffers(int64_t recommended_size);  // return desired size for input buffers
245         virtual int64_t get_out_buffers(int64_t recommended_size);     // return desired size for output buffers
246         virtual int start_loop();
247         virtual int process_loop();
248         virtual int stop_loop();
249 // Hash files are the defaults for rendered plugins
250         virtual int load_defaults();       // load default settings for the plugin
251         virtual int save_defaults();      // save the current settings as defaults
252         BC_Hash* get_defaults();
253
254
255
256
257 // Realtime commands for signal processors.
258 // These must be defined by the plugin itself.
259 // Set the GUI title identifying the plugin to modules and patches.
260         int set_string();
261 // cause the plugin to create a new GUI class
262         virtual BC_WindowBase* new_window();
263 // Load the current keyframe.  Return 1 if it changed.
264         virtual int load_configuration();
265 // cause the plugin to hide the gui
266         void client_side_close();
267         void update_display_title();
268 // Raise the GUI
269         void raise_window();
270 // Create GUI
271         int show_gui();
272 // XML keyframes are the defaults for realtime plugins
273         void load_defaults_xml();
274         void save_defaults_xml();
275 // Tell the client if the load is the defaults
276         int is_defaults();
277
278         virtual void update_gui();
279         virtual void save_data(KeyFrame *keyframe) {};    // write the plugin settings to text in text format
280         virtual void read_data(KeyFrame *keyframe) {};    // read the plugin settings from the text
281         int send_hide_gui();                                    // should be sent when the GUI recieves a close event from the user
282 // Destroys the window but not the thread pointer.
283         void hide_gui();
284
285         int get_configure_change();                             // get propogated configuration change from a send_configure_change
286
287 // Called by plugin server to update GUI with rendered data.
288         void plugin_render_gui(void *data);
289         void plugin_render_gui(void *data, int size);
290
291         void begin_process_buffer();
292         void end_process_buffer();
293
294         void plugin_update_gui();
295         virtual int plugin_process_loop(VFrame **buffers, int64_t &write_length) { return 1; };
296         virtual int plugin_process_loop(Samples **buffers, int64_t &write_length) { return 1; };
297 // get parameters depending on video or audio
298         virtual int init_realtime_parameters();
299 // release objects which are required after playback stops
300         virtual void render_stop() {};
301         int get_gui_status();
302         char* get_gui_string();
303
304 // Used by themes
305 // Used by plugins which need to know where they are.
306         char* get_path();
307 // Get the directory for plugins
308         char* get_plugin_dir();
309
310 // Return keyframe objects.  The position in the resulting object
311 // is relative to the EDL rate.  This is the only way to avoid copying the
312 // data for every frame.
313 // If the result is the default keyframe, the keyframe's position is 0.
314 // position - relative to EDL rate or local rate to allow simple
315 //     passing of get_source_position.
316 //     If -1 the tracking position in the edl is used.
317 // is_local - if 1, the position is converted to the EDL rate.
318         KeyFrame* get_prev_keyframe(int64_t position, int is_local = 1);
319         KeyFrame* get_next_keyframe(int64_t position, int is_local = 1);
320 // get current camera and projector position
321         void get_camera(float *x, float *y, float *z, int64_t position);
322         void get_projector(float *x, float *y, float *z, int64_t position);
323 // When this plugin is adjusted, propogate parameters back to EDL and virtual
324 // console.  This gets a keyframe from the EDL, with the position set to the
325 // EDL tracking position.
326         int send_configure_change();
327
328
329 // Called from process_buffer
330 // Returns 1 if a GUI is open so OpenGL routines can determine if
331 // they can run.
332         int gui_open();
333
334
335
336 // Length of source.  For effects it's the plugin length.  For transitions
337 // it's the transition length.  Relative to the requested rate.
338 // The only way to get smooth interpolation is to make all position queries
339 // relative to the requested rate.
340         int64_t get_total_len();
341
342 // For realtime plugins gets the lowest sample of the plugin in the requested
343 // rate.  For others it's the start of the EDL selection in the EDL rate.
344         int64_t get_source_start();
345
346 // Convert the position relative to the requested rate to the position
347 // relative to the EDL rate.  If the argument is < 0, it is not changed.
348 // Used for interpreting keyframes.
349         virtual int64_t local_to_edl(int64_t position);
350
351 // Convert the EDL position to the local position.
352         virtual int64_t edl_to_local(int64_t position);
353
354 // For transitions the source_position is the playback position relative
355 // to the start of the transition.
356 // For realtime effects, the start of the most recent process_buffer in forward
357 // and the end of the range to process in reverse.  Relative to start of EDL in
358 // the requested rate.
359         int64_t get_source_position();
360
361 // Get the EDL Session.  May return 0 if the server has no edl.
362         EDLSession* get_edlsession();
363
364
365 // Get the direction of the most recent process_buffer
366         int get_direction();
367
368 // Plugin must call this before performing OpenGL operations.
369 // Returns 1 if the user supports opengl buffers.
370         int get_use_opengl();
371
372 // Get total tracks to process
373         int get_total_buffers();
374
375 // Get size of buffer to fill in non-realtime plugin
376         int get_buffer_size();
377
378 // Get interpolation used by EDL from overlayframe.inc
379         int get_interpolation_type();
380
381 // Get the values from the color picker
382         float get_red();
383         float get_green();
384         float get_blue();
385
386
387
388 // Operations for file handlers
389         virtual int open_file() { return 0; };
390         virtual int get_audio_parameters() { return 0; };
391         virtual int get_video_parameters() { return 0; };
392         virtual int check_header(char *path) { return 0; };
393         virtual int open_file(char *path, int wr, int rd) { return 1; };
394         virtual int close_file() { return 0; };
395
396
397
398
399
400 // All plugins define these.
401         PluginClientThread* get_thread();
402
403
404
405 // Non realtime operations for signal processors.
406         virtual int plugin_start_loop(int64_t start,
407                 int64_t end,
408                 int64_t buffer_size,
409                 int total_buffers);
410         int plugin_stop_loop();
411         int plugin_process_loop();
412         MainProgressBar* start_progress(char *string, int64_t length);
413 // get samplerate of EDL
414         int get_project_samplerate();
415 // get framerate of EDL
416         double get_project_framerate();
417 // Total number of processors - 1
418         int get_project_smp();
419         int get_aspect_ratio(float &aspect_w, float &aspect_h);
420
421
422         int write_frames(int64_t total_frames);  // returns 1 for failure / tells the server that all output channel buffers are ready to go
423         int write_samples(int64_t total_samples);  // returns 1 for failure / tells the server that all output channel buffers are ready to go
424         virtual int plugin_get_parameters();
425         const char* get_defaultdir();     // Directory defaults should be stored in
426         void set_interactive();
427
428 // Realtime operations.
429         int reset();
430 // Extension of plugin_run for derived plugins
431         virtual int plugin_command_derived(int plugin_command) { return 0; };
432         int plugin_get_range();
433         int plugin_init_realtime(int realtime_priority,
434                 int total_in_buffers,
435                 int buffer_size);
436
437
438 // GUI updating wrappers for realtime plugins
439 // Append frame to queue for next send_frame_buffer
440         void add_gui_frame(PluginClientFrame *frame);
441
442
443
444         virtual void render_gui(void *data);
445         virtual void render_gui(void *data, int size);
446
447 // Called by client to get the total number of frames to draw in update_gui
448         int get_gui_update_frames();
449 // Get GUI frame from frame_buffer.  Client must delete it.
450         PluginClientFrame* get_gui_frame();
451
452 // Called by client to cause GUI to be rendered with data.
453         void send_render_gui();
454         void send_render_gui(void *data);
455         void send_render_gui(void *data, int size);
456
457
458
459
460
461
462
463
464 // create pointers to buffers of the plugin's type before realtime rendering
465         virtual int delete_buffer_ptrs();
466
467
468
469
470 // communication convenience routines for the base class
471         int stop_gui_client();
472         int save_data_client();
473         int load_data_client();
474         int set_string_client(char *string);                // set the string identifying the plugin
475         int send_cancelled();        // non realtime plugin sends when cancelled
476
477 // ================================= Buffers ===============================
478
479 // number of double buffers for each channel
480         ArrayList<int> double_buffers_in;
481         ArrayList<int> double_buffers_out;
482 // When arming buffers need to know the offsets in all the buffers and which
483 // double buffers for each channel before rendering.
484         ArrayList<int64_t> offset_in_render;
485         ArrayList<int64_t> offset_out_render;
486         ArrayList<int64_t> double_buffer_in_render;
487         ArrayList<int64_t> double_buffer_out_render;
488 // total size of each buffer depends on if it's a master or node
489         ArrayList<int64_t> realtime_in_size;
490         ArrayList<int64_t> realtime_out_size;
491
492 // ================================= Automation ===========================
493
494         ArrayList<PluginClientAuto> automation;
495
496 // ================================== Messages ===========================
497         char gui_string[BCTEXTLEN];          // string identifying module and plugin
498         int master_gui_on;              // Status of the master gui plugin
499         int client_gui_on;              // Status of this client's gui
500
501         int show_initially;             // set to show a realtime plugin initially
502 // range in project for processing
503         int64_t start, end;
504         int interactive;                // for the progress bar plugin
505         int success;
506         int total_out_buffers;          // total send buffers allocated by the server
507         int total_in_buffers;           // total recieve buffers allocated by the server
508         int wr, rd;                     // File permissions for fileio plugins.
509
510 // These give the largest fragment the plugin is expected to handle.
511 // size of a send buffer to the server
512         int64_t out_buffer_size;
513 // size of a recieve buffer from the server
514         int64_t in_buffer_size;
515
516
517
518
519 // Direction of most recent process_buffer
520         int direction;
521
522 // Operating system scheduling
523         int realtime_priority;
524
525 // Position relative to start of EDL in requested rate.  Calculated for every process
526 // command.  Used for keyframes.
527         int64_t source_position;
528 // For realtime plugins gets the lowest sample of the plugin in the requested
529 // rate.  For others it's always 0.
530         int64_t source_start;
531 // Length of source.  For effects it's the plugin length.  For transitions
532 // it's the transition length.  Relative to the requested rate.
533         int64_t total_len;
534 // Total number of processors available - 1
535         int smp;
536         PluginServer *server;
537         BC_Hash *defaults;
538         PluginClientThread *thread;
539
540 // Frames for updating GUI
541         ArrayList<PluginClientFrame*> frame_buffer;
542 // Time of last GUI update
543         Timer *update_timer;
544
545
546 private:
547         int using_defaults;
548 // Temporaries set in new_window
549         int window_x, window_y;
550 // File handlers:
551 //      Asset *asset;     // Point to asset structure in shared memory
552 };
553
554
555 #endif