tweak zoom/fullscr to remember cwdw scale after fullscr
[goodguy/cinelerra.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         virtual void done_event(int result) {}
164 // A listener for PluginParam events
165         virtual void param_updated();
166
167         PluginClient *client;
168 };
169
170 // A GUI helper
171 class PluginFPot : public BC_FPot
172 {
173 public:
174     PluginFPot(PluginParam *param, int x, int y);
175     int handle_event();
176         PluginParam *param;
177 };
178
179 class PluginIPot : public BC_IPot
180 {
181 public:
182     PluginIPot(PluginParam *param, int x, int y);
183     int handle_event();
184         PluginParam *param;
185 };
186
187 class PluginQPot : public BC_QPot
188 {
189 public:
190     PluginQPot(PluginParam *param, int x, int y);
191     int handle_event();
192         PluginParam *param;
193 };
194
195 class PluginText : public BC_TextBox
196 {
197 public:
198     PluginText(PluginParam *param, int x, int y, int value);
199     PluginText(PluginParam *param, int x, int y, float value);
200     int handle_event();
201         PluginParam *param;
202 };
203
204 class PluginParam
205 {
206 public:
207     PluginParam(PluginClient *plugin,
208         PluginClientWindow *gui,
209         int x1,
210         int x2,
211         int x3,
212         int y,
213         int text_w,
214         int *output_i,
215         float *output_f, // floating point output
216         int *output_q, // frequency output
217         const char *title,
218         float min,
219         float max);
220     ~PluginParam();
221
222     void initialize();
223     void update(int skip_text, int skip_pot);
224 // set the number of fractional digits
225     void set_precision(int digits);
226
227 // 2 possible outputs
228     float *output_f;
229     PluginFPot *fpot;
230
231     int *output_i;
232     PluginIPot *ipot;
233
234     int *output_q;
235     PluginQPot *qpot;
236
237     char *title;
238     PluginText *text;
239     PluginClientWindow *gui;
240     PluginClient *plugin;
241     int x1;
242     int x2;
243     int x3;
244     int y;
245     int text_w;
246     float min;
247     float max;
248     int precision;
249 };
250
251
252
253
254 class PluginClientThread : public Thread
255 {
256 public:
257         PluginClientThread(PluginClient *client);
258         ~PluginClientThread();
259         void run();
260
261         friend class PluginClient;
262
263         BC_WindowBase* get_window();
264         PluginClient* get_client();
265         PluginClientWindow *window;
266         PluginClient *client;
267
268 private:
269         Condition *init_complete;
270 };
271
272
273
274 // Client overrides for GUI update data
275 class PluginClientFrame
276 {
277 public:
278 // Period_d is 1 second
279         PluginClientFrame(int data_size, int period_n, int period_d);
280         virtual ~PluginClientFrame();
281         int data_size;
282         int period_n;
283         int period_d;
284 // Draw immediately
285         int force;
286 };
287
288
289
290 class PluginClient
291 {
292 public:
293         PluginClient(PluginServer *server);
294         virtual ~PluginClient();
295
296         friend class PluginClientThread;
297         friend class PluginClientWindow;
298
299 // Queries for the plugin server.
300         virtual int is_realtime();
301         virtual int is_audio();
302         virtual int is_video();
303         virtual int is_fileio();
304         virtual int is_theme();
305         virtual int uses_gui();
306         virtual int is_multichannel();
307         virtual int is_synthesis();
308         virtual int is_transition();
309         virtual const char* plugin_title();   // return the title of the plugin
310         virtual Theme* new_theme();
311 // Get theme being used by Cinelerra currently.  Used by all plugins.
312         Theme* get_theme();
313
314
315
316
317
318
319 // Non realtime signal processors define these.
320 // Give the samplerate of the output for a non realtime plugin.
321 // For realtime plugins give the requested samplerate.
322         virtual int get_samplerate();
323 // Give the framerate of the output for a non realtime plugin.
324 // For realtime plugins give the requested framerate.
325         virtual double get_framerate();
326         virtual int delete_nonrealtime_parameters();
327         virtual int get_parameters();     // get information from user before non realtime processing
328         virtual int64_t get_in_buffers(int64_t recommended_size);  // return desired size for input buffers
329         virtual int64_t get_out_buffers(int64_t recommended_size);     // return desired size for output buffers
330         virtual int start_loop();
331         virtual int process_loop();
332         virtual int stop_loop();
333 // Hash files are the defaults for rendered plugins
334         virtual int load_defaults();       // load default settings for the plugin
335         virtual int save_defaults();      // save the current settings as defaults
336         BC_Hash* get_defaults();
337
338
339
340
341 // Realtime commands for signal processors.
342 // These must be defined by the plugin itself.
343 // Set the GUI title identifying the plugin to modules and patches.
344         int set_string();
345 // cause the plugin to create a new GUI class
346         virtual BC_WindowBase* new_window();
347 // Load the current keyframe.  Return 1 if it changed.
348         virtual int load_configuration();
349 // cause the plugin to hide the gui
350         void client_side_close();
351         void update_display_title();
352 // Raise the GUI
353         void raise_window();
354 // Create GUI
355         int show_gui();
356 // XML keyframes are the defaults for realtime plugins
357         void load_defaults_xml();
358         void save_defaults_xml();
359 // Tell the client if the load is the defaults
360         int is_defaults();
361
362         virtual void update_gui();
363         virtual void save_data(KeyFrame *keyframe) {};    // write the plugin settings to text in text format
364         virtual void read_data(KeyFrame *keyframe) {};    // read the plugin settings from the text
365         int send_hide_gui();                                    // should be sent when the GUI receives a close event from the user
366 // Destroys the window but not the thread pointer.
367         void hide_gui();
368
369         int get_configure_change();                             // get propogated configuration change from a send_configure_change
370
371 // Called by plugin server to update GUI with rendered data.
372         void plugin_render_gui(void *data);
373         void plugin_render_gui(void *data, int size);
374
375         void begin_process_buffer();
376         void end_process_buffer();
377
378         void plugin_update_gui();
379         virtual int plugin_process_loop(VFrame **buffers, int64_t &write_length) { return 1; };
380         virtual int plugin_process_loop(Samples **buffers, int64_t &write_length) { return 1; };
381 // get parameters depending on video or audio
382         virtual int init_realtime_parameters();
383 // release objects which are required after playback stops
384         virtual void render_stop() {};
385         int get_gui_status();
386         char* get_gui_string();
387
388 // Used by themes
389 // Used by plugins which need to know where they are.
390         char* get_path();
391 // Get the directory for plugins
392         char* get_plugin_dir();
393
394 // Return keyframe objects.  The position in the resulting object
395 // is relative to the EDL rate.  This is the only way to avoid copying the
396 // data for every frame.
397 // If the result is the default keyframe, the keyframe's position is 0.
398 // position - relative to EDL rate or local rate to allow simple
399 //     passing of get_source_position.
400 //     If -1 the tracking position in the edl is used.
401 // is_local - if 1, the position is converted to the EDL rate.
402         KeyFrame* get_prev_keyframe(int64_t position, int is_local = 1);
403         KeyFrame* get_next_keyframe(int64_t position, int is_local = 1);
404 // get current camera and projector position
405         void get_camera(float *x, float *y, float *z, int64_t position);
406         void get_projector(float *x, float *y, float *z, int64_t position);
407
408         void output_to_track(float ox, float oy, float &tx, float &ty);
409         void track_to_output(float tx, float ty, float &ox, float &oy);
410 // When this plugin is adjusted, propogate parameters back to EDL and virtual
411 // console.  This gets a keyframe from the EDL, with the position set to the
412 // EDL tracking position.
413         int send_configure_change();
414
415
416 // Called from process_buffer
417 // Returns 1 if a GUI is open so OpenGL routines can determine if
418 // they can run.
419         int gui_open();
420
421
422 // Length of source.  For effects it's the plugin length.  For transitions
423 // it's the transition length.  Relative to the requested rate.
424 // The only way to get smooth interpolation is to make all position queries
425 // relative to the requested rate.
426         int64_t get_total_len();
427
428 // For realtime plugins gets the lowest sample of the plugin in the requested
429 // rate.  For others it's the start of the EDL selection in the EDL rate.
430         int64_t get_source_start();
431
432 // Convert the position relative to the requested rate to the position
433 // relative to the EDL rate.  If the argument is < 0, it is not changed.
434 // Used for interpreting keyframes.
435         virtual int64_t local_to_edl(int64_t position);
436
437 // Convert the EDL position to the local position.
438         virtual int64_t edl_to_local(int64_t position);
439
440 // For transitions the source_position is the playback position relative
441 // to the start of the transition.
442 // For realtime effects, the start of the most recent process_buffer in forward
443 // and the end of the range to process in reverse.  Relative to start of EDL in
444 // the requested rate.
445         int64_t get_source_position();
446
447 // Get server edl
448         EDL *get_edl();
449 // Get the direction of the most recent process_buffer
450         int get_direction();
451
452 // Plugin must call this before performing OpenGL operations.
453 // Returns 1 if the user supports opengl buffers.
454         int get_use_opengl();
455
456 // Get total tracks to process
457         int get_total_buffers();
458
459 // Get size of buffer to fill in non-realtime plugin
460         int get_buffer_size();
461
462 // Get interpolation used by EDL from overlayframe.inc
463         int get_interpolation_type();
464
465 // Get the values from the color picker
466         float get_red();
467         float get_green();
468         float get_blue();
469
470
471
472 // Operations for file handlers
473         virtual int open_file() { return 0; };
474         virtual int get_audio_parameters() { return 0; };
475         virtual int get_video_parameters() { return 0; };
476         virtual int check_header(char *path) { return 0; };
477         virtual int open_file(char *path, int wr, int rd) { return 1; };
478         virtual int close_file() { return 0; };
479
480
481
482
483
484 // All plugins define these.
485         PluginClientThread* get_thread();
486
487
488
489 // Non realtime operations for signal processors.
490         virtual int plugin_start_loop(int64_t start,
491                 int64_t end,
492                 int64_t buffer_size,
493                 int total_buffers);
494         int plugin_stop_loop();
495         int plugin_process_loop();
496         MainProgressBar* start_progress(char *string, int64_t length);
497 // get samplerate of EDL
498         int get_project_samplerate();
499 // get framerate of EDL
500         double get_project_framerate();
501 // get asset path
502         const char *get_source_path();
503 // Total number of processors - 1
504         int get_project_smp();
505         int get_aspect_ratio(float &aspect_w, float &aspect_h);
506
507
508         int write_frames(int64_t total_frames);  // returns 1 for failure / tells the server that all output channel buffers are ready to go
509         int write_samples(int64_t total_samples);  // returns 1 for failure / tells the server that all output channel buffers are ready to go
510         virtual int plugin_get_parameters();
511         const char* get_defaultdir();     // Directory defaults should be stored in
512         void set_interactive();
513
514 // Realtime operations.
515         int reset();
516 // Extension of plugin_run for derived plugins
517         virtual int plugin_command_derived(int plugin_command) { return 0; };
518         int plugin_get_range();
519         int plugin_init_realtime(int realtime_priority,
520                 int total_in_buffers,
521                 int buffer_size);
522
523
524 // GUI updating wrappers for realtime plugins
525 // Append frame to queue for next send_frame_buffer
526         void add_gui_frame(PluginClientFrame *frame);
527
528
529
530         virtual void render_gui(void *data);
531         virtual void render_gui(void *data, int size);
532
533 // Called by client to get the total number of frames to draw in update_gui
534         int get_gui_update_frames();
535 // Get GUI frame from frame_buffer.  Client must delete it.
536         PluginClientFrame* get_gui_frame();
537
538 // Called by client to cause GUI to be rendered with data.
539         void send_render_gui();
540         void send_render_gui(void *data);
541         void send_render_gui(void *data, int size);
542
543
544
545
546
547
548
549
550 // create pointers to buffers of the plugin's type before realtime rendering
551         virtual int delete_buffer_ptrs();
552
553
554
555
556 // communication convenience routines for the base class
557         int stop_gui_client();
558         int save_data_client();
559         int load_data_client();
560         int set_string_client(char *string);                // set the string identifying the plugin
561         int send_cancelled();        // non realtime plugin sends when cancelled
562
563 // ================================= Buffers ===============================
564
565 // number of double buffers for each channel
566         ArrayList<int> double_buffers_in;
567         ArrayList<int> double_buffers_out;
568 // When arming buffers need to know the offsets in all the buffers and which
569 // double buffers for each channel before rendering.
570         ArrayList<int64_t> offset_in_render;
571         ArrayList<int64_t> offset_out_render;
572         ArrayList<int64_t> double_buffer_in_render;
573         ArrayList<int64_t> double_buffer_out_render;
574 // total size of each buffer depends on if it's a master or node
575         ArrayList<int64_t> realtime_in_size;
576         ArrayList<int64_t> realtime_out_size;
577
578 // ================================= Automation ===========================
579
580         ArrayList<PluginClientAuto> automation;
581
582 // ================================== Messages ===========================
583         char gui_string[BCTEXTLEN];          // string identifying module and plugin
584         int master_gui_on;              // Status of the master gui plugin
585         int client_gui_on;              // Status of this client's gui
586
587         int show_initially;             // set to show a realtime plugin initially
588 // range in project for processing
589         int64_t start, end;
590         int interactive;                // for the progress bar plugin
591         int success;
592         int total_out_buffers;          // total send buffers allocated by the server
593         int total_in_buffers;           // total receive buffers allocated by the server
594         int wr, rd;                     // File permissions for fileio plugins.
595
596 // These give the largest fragment the plugin is expected to handle.
597 // size of a send buffer to the server
598         int64_t out_buffer_size;
599 // size of a receive buffer from the server
600         int64_t in_buffer_size;
601
602
603
604
605 // Direction of most recent process_buffer
606         int direction;
607
608 // Operating system scheduling
609         int realtime_priority;
610
611 // Position relative to start of EDL in requested rate.  Calculated for every process
612 // command.  Used for keyframes.
613         int64_t source_position;
614 // For realtime plugins gets the lowest sample of the plugin in the requested
615 // rate.  For others it's always 0.
616         int64_t source_start;
617 // Length of source.  For effects it's the plugin length.  For transitions
618 // it's the transition length.  Relative to the requested rate.
619         int64_t total_len;
620 // Total number of processors available - 1
621         int smp;
622         PluginServer *server;
623         BC_Hash *defaults;
624         PluginClientThread *thread;
625
626 // Frames for updating GUI
627         ArrayList<PluginClientFrame*> frame_buffer;
628 // Time of last GUI update
629         Timer *update_timer;
630
631
632 private:
633         int using_defaults;
634 // Temporaries set in new_window
635         int window_x, window_y;
636 // File handlers:
637 //      Asset *asset;     // Point to asset structure in shared memory
638 };
639
640
641 #endif