4 * Copyright (C) 1997-2011 Adam Williams <broadcast at earthling dot net>
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.
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.
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
22 #ifndef PLUGINCLIENT_H
23 #define PLUGINCLIENT_H
25 // Base class inherited by all the different types of plugins.
27 #define MAX_FRAME_BUFFER 8192
32 #include "arraylist.h"
35 #include "condition.h"
36 #include "edlsession.inc"
38 #include "mainprogress.inc"
39 #include "maxbuffers.h"
40 #include "pluginclient.inc"
41 #include "plugincommands.h"
42 #include "pluginserver.inc"
43 #include "samples.inc"
50 extern PluginClient* new_plugin(PluginServer *server);
53 class PluginClientAuto
64 // Convenience functions
66 #define REGISTER_PLUGIN(class_title) \
67 PluginClient* new_plugin(PluginServer *server) \
69 return new class_title(server); \
79 // Prototypes for user to put in class header
80 #define PLUGIN_CLASS_MEMBERS(config_name) \
81 int load_configuration(); \
82 const char* plugin_title(); \
83 PluginClientWindow* new_window(); \
88 // Prototypes for user to put in class header
89 #define PLUGIN_CLASS_MEMBERS2(config_name) \
90 int load_configuration(); \
91 const char* plugin_title(); \
92 PluginClientWindow* new_window(); \
99 #define NEW_WINDOW_MACRO(plugin_class, window_class) \
100 PluginClientWindow* plugin_class::new_window() \
102 return new window_class(this); \
105 // Not all plugins load configuration the same way. Use this to define
107 #define LOAD_CONFIGURATION_MACRO(plugin_class, config_class) \
108 int plugin_class::load_configuration() \
110 KeyFrame *prev_keyframe, *next_keyframe; \
111 prev_keyframe = get_prev_keyframe(get_source_position()); \
112 next_keyframe = get_next_keyframe(get_source_position()); \
114 int64_t next_position = edl_to_local(next_keyframe->position); \
115 int64_t prev_position = edl_to_local(prev_keyframe->position); \
117 config_class old_config, prev_config, next_config; \
118 old_config.copy_from(config); \
119 read_data(prev_keyframe); \
120 prev_config.copy_from(config); \
121 read_data(next_keyframe); \
122 next_config.copy_from(config); \
124 config.interpolate(prev_config, \
126 (next_position == prev_position) ? \
127 get_source_position() : \
129 (next_position == prev_position) ? \
130 get_source_position() + 1 : \
132 get_source_position()); \
134 if(!config.equivalent(old_config)) \
141 class PluginClientFrame : public ListItem<PluginClientFrame>
145 virtual ~PluginClientFrame();
146 // offset in EDL seconds for synchronizing with GUI
150 class PluginClientFrames : public List<PluginClientFrame>
153 PluginClientFrames();
154 ~PluginClientFrames();
156 static int fwd_cmpr(PluginClientFrame *ap, PluginClientFrame *bp);
157 static int rev_cmpr(PluginClientFrame *ap, PluginClientFrame *bp);
158 void fwd_sort() { sort(fwd_cmpr); }
159 void rev_sort() { sort(rev_cmpr); }
160 void sort_position(int dir);
162 void add_gui_frame(PluginClientFrame *frame);
163 void concatenate(PluginClientFrames *frames);
164 PluginClientFrame *get_gui_frame(double pos, int dir);
170 class PluginClientWindow : public BC_Window
173 PluginClientWindow(PluginClient *client,
174 int w, int h, int min_w, int min_h, int allow_resize);
175 PluginClientWindow(const char *title, int x, int y,
176 int w, int h, int min_w, int min_h, int allow_resize);
177 virtual ~PluginClientWindow();
179 virtual int translation_event();
180 virtual int close_event();
181 virtual void done_event(int result) {}
182 // A listener for PluginParam events
183 virtual void param_updated();
185 PluginClient *client;
189 class PluginFPot : public BC_FPot
192 PluginFPot(PluginParam *param, int x, int y);
197 class PluginIPot : public BC_IPot
200 PluginIPot(PluginParam *param, int x, int y);
205 class PluginQPot : public BC_QPot
208 PluginQPot(PluginParam *param, int x, int y);
213 class PluginText : public BC_TextBox
216 PluginText(PluginParam *param, int x, int y, int value);
217 PluginText(PluginParam *param, int x, int y, float value);
225 PluginParam(PluginClient *plugin, PluginClientWindow *gui,
226 int x1, int x2, int x3, int y, int text_w,
227 int *output_i, float *output_f, // floating point output
228 int *output_q, // frequency output
229 const char *title, float min, float max);
233 void update(int skip_text, int skip_pot);
234 // set the number of fractional digits
235 void set_precision(int digits);
247 PluginClientWindow *gui;
248 PluginClient *plugin;
256 class PluginClientThread : public Thread
259 PluginClientThread(PluginClient *client);
260 ~PluginClientThread();
263 friend class PluginClient;
265 BC_WindowBase* get_window();
266 PluginClient* get_client();
267 PluginClientWindow *window;
268 PluginClient *client;
271 Condition *init_complete;
279 PluginClient(PluginServer *server);
280 virtual ~PluginClient();
282 friend class PluginClientThread;
283 friend class PluginClientWindow;
285 // Queries for the plugin server.
286 virtual int is_realtime();
287 virtual int is_audio();
288 virtual int is_video();
289 virtual int is_fileio();
290 virtual int is_theme();
291 virtual int uses_gui();
292 virtual int is_multichannel();
293 virtual int is_synthesis();
294 virtual int is_transition();
295 virtual const char* plugin_title(); // return the title of the plugin
296 virtual Theme* new_theme();
297 // Get theme being used by Cinelerra currently. Used by all plugins.
300 // Non realtime signal processors define these.
301 // Give the samplerate of the output for a non realtime plugin.
302 // For realtime plugins give the requested samplerate.
303 virtual int get_samplerate();
304 // Give the framerate of the output for a non realtime plugin.
305 // For realtime plugins give the requested framerate.
306 virtual double get_framerate();
307 virtual int delete_nonrealtime_parameters();
308 virtual int get_parameters(); // get information from user before non realtime processing
309 virtual int64_t get_in_buffers(int64_t recommended_size); // return desired size for input buffers
310 virtual int64_t get_out_buffers(int64_t recommended_size); // return desired size for output buffers
311 virtual int start_loop();
312 virtual int process_loop();
313 virtual int stop_loop();
314 // Hash files are the defaults for rendered plugins
315 virtual int load_defaults(); // load default settings for the plugin
316 virtual int save_defaults(); // save the current settings as defaults
317 BC_Hash* get_defaults();
319 // Realtime commands for signal processors.
320 // These must be defined by the plugin itself.
321 // Set the GUI title identifying the plugin to modules and patches.
323 // cause the plugin to create a new GUI class
324 virtual BC_WindowBase* new_window();
325 // Load the current keyframe. Return 1 if it changed.
326 virtual int load_configuration();
327 // cause the plugin to hide the gui
328 void client_side_close();
329 void update_display_title();
334 // XML keyframes are the defaults for realtime plugins
335 void load_defaults_xml();
336 void save_defaults_xml();
337 // Tell the client if the load is the defaults
340 virtual void update_gui();
341 virtual void save_data(KeyFrame *keyframe) {}; // write the plugin settings to text in text format
342 virtual void read_data(KeyFrame *keyframe) {}; // read the plugin settings from the text
343 int send_hide_gui(); // should be sent when the GUI receives a close event from the user
344 // Destroys the window but not the thread pointer.
346 void plugin_update_gui();
347 virtual void begin_process_buffer() {}
348 virtual void end_process_buffer() {}
349 virtual int plugin_process_loop(VFrame **buffers, int64_t &write_length) { return 1; };
350 virtual int plugin_process_loop(Samples **buffers, int64_t &write_length) { return 1; };
351 // get parameters depending on video or audio
352 virtual int init_realtime_parameters();
353 // release objects which are required after playback stops
354 virtual void render_stop() {};
355 int get_gui_status();
356 char* get_gui_string();
359 // Used by plugins which need to know where they are.
361 // Get the directory for plugins
362 char* get_plugin_dir();
364 // Return keyframe objects. The position in the resulting object
365 // is relative to the EDL rate. This is the only way to avoid copying the
366 // data for every frame.
367 // If the result is the default keyframe, the keyframe's position is 0.
368 // position - relative to EDL rate or local rate to allow simple
369 // passing of get_source_position.
370 // If -1 the tracking position in the edl is used.
371 // is_local - if 1, the position is converted to the EDL rate.
372 KeyFrame* get_prev_keyframe(int64_t position, int is_local = 1);
373 KeyFrame* get_next_keyframe(int64_t position, int is_local = 1);
374 // get current camera and projector position
375 void get_camera(float *x, float *y, float *z, int64_t position);
376 void get_projector(float *x, float *y, float *z, int64_t position);
378 void output_to_track(float ox, float oy, float &tx, float &ty);
379 void track_to_output(float tx, float ty, float &ox, float &oy);
380 // When this plugin is adjusted, propogate parameters back to EDL and virtual
381 // console. This gets a keyframe from the EDL, with the position set to the
382 // EDL tracking position.
383 int send_configure_change();
386 // Called from process_buffer
387 // Returns 1 if a GUI is open so OpenGL routines can determine if
392 // Length of source. For effects it's the plugin length. For transitions
393 // it's the transition length. Relative to the requested rate.
394 // The only way to get smooth interpolation is to make all position queries
395 // relative to the requested rate.
396 int64_t get_total_len();
398 // For realtime plugins gets the lowest sample of the plugin in the requested
399 // rate. For others it's the start of the EDL selection in the EDL rate.
400 int64_t get_source_start();
402 // Convert the position relative to the requested rate to the position
403 // relative to the EDL rate. If the argument is < 0, it is not changed.
404 // Used for interpreting keyframes.
405 virtual int64_t local_to_edl(int64_t position);
407 // Convert the EDL position to the local position.
408 virtual int64_t edl_to_local(int64_t position);
410 // For transitions the source_position is the playback position relative
411 // to the start of the transition.
412 // For realtime effects, the start of the most recent process_buffer in forward
413 // and the end of the range to process in reverse. Relative to start of EDL in
414 // the requested rate.
415 int64_t get_source_position();
419 // Get the direction of the most recent process_buffer
422 // position and direction for plugin gui tracking draws
423 double get_tracking_position();
424 int get_tracking_direction();
426 // Plugin must call this before performing OpenGL operations.
427 // Returns 1 if the user supports opengl buffers.
428 int get_use_opengl();
430 // Get total tracks to process
431 int get_total_buffers();
433 // Get size of buffer to fill in non-realtime plugin
434 int get_buffer_size();
436 // Get interpolation used by EDL from overlayframe.inc
437 int get_interpolation_type();
439 // Get the values from the color picker
444 // Operations for file handlers
445 virtual int open_file() { return 0; };
446 virtual int get_audio_parameters() { return 0; };
447 virtual int get_video_parameters() { return 0; };
448 virtual int check_header(char *path) { return 0; };
449 virtual int open_file(char *path, int wr, int rd) { return 1; };
450 virtual int close_file() { return 0; };
452 // All plugins define these.
453 PluginClientThread* get_thread();
455 // Non realtime operations for signal processors.
456 virtual int plugin_start_loop(int64_t start, int64_t end,
457 int64_t buffer_size, int total_buffers);
458 int plugin_stop_loop();
459 int plugin_process_loop();
460 MainProgressBar* start_progress(char *string, int64_t length);
461 // get samplerate of EDL
462 int get_project_samplerate();
463 // get framerate of EDL
464 double get_project_framerate();
466 const char *get_source_path();
467 // Total number of processors - 1
468 int get_project_smp();
469 int get_aspect_ratio(float &aspect_w, float &aspect_h);
472 int write_frames(int64_t total_frames); // returns 1 for failure / tells the server that all output channel buffers are ready to go
473 int write_samples(int64_t total_samples); // returns 1 for failure / tells the server that all output channel buffers are ready to go
474 virtual int plugin_get_parameters();
475 const char* get_defaultdir(); // Directory defaults should be stored in
476 void set_interactive();
478 // Realtime operations.
480 // Extension of plugin_run for derived plugins
481 virtual int plugin_command_derived(int plugin_command) { return 0; };
482 int plugin_get_range();
483 int plugin_init_realtime(int realtime_priority,
484 int total_in_buffers, int buffer_size);
486 // GUI updating wrappers for realtime plugins
487 // Append frame to queue for next send_frame_buffer
488 void add_gui_frame(PluginClientFrame *frame);
489 int get_gui_frames();
491 virtual void render_gui(void *data);
492 virtual void render_gui(void *data, int size);
493 void send_render_gui();
494 void send_render_gui(void *data);
495 void send_render_gui(void *data, int size);
496 void plugin_render_gui(void *data);
497 void plugin_render_gui(void *data, int size);
499 void reset_gui_frames();
500 void reset_plugin_gui_frames();
501 void plugin_reset_gui_frames();
502 void plugin_render_gui_frames(PluginClientFrames *frames);
504 int pending_gui_frame();
505 // Called by client to get the total number of frames to draw in update_gui
506 int pending_gui_frames();
507 // pop frames until buffer passes position=pos(-1 or seconds) in direction=dir(-1,0,1)
508 PluginClientFrame *get_gui_frame(double pos, int dir);
509 PluginClientFrame* next_gui_frame();
511 // communication convenience routines for the base class
512 int stop_gui_client();
513 int save_data_client();
514 int load_data_client();
515 int set_string_client(char *string); // set the string identifying the plugin
516 int send_cancelled(); // non realtime plugin sends when cancelled
518 // ================================= Buffers ===============================
520 // number of double buffers for each channel
521 ArrayList<int> double_buffers_in;
522 ArrayList<int> double_buffers_out;
523 // When arming buffers need to know the offsets in all the buffers and which
524 // double buffers for each channel before rendering.
525 ArrayList<int64_t> offset_in_render;
526 ArrayList<int64_t> offset_out_render;
527 ArrayList<int64_t> double_buffer_in_render;
528 ArrayList<int64_t> double_buffer_out_render;
529 // total size of each buffer depends on if it's a master or node
530 ArrayList<int64_t> realtime_in_size;
531 ArrayList<int64_t> realtime_out_size;
533 // ================================= Automation ===========================
535 ArrayList<PluginClientAuto> automation;
537 // ================================== Messages ===========================
538 char gui_string[BCTEXTLEN]; // string identifying module and plugin
539 int master_gui_on; // Status of the master gui plugin
540 int client_gui_on; // Status of this client's gui
542 int show_initially; // set to show a realtime plugin initially
543 // range in project for processing
545 int interactive; // for the progress bar plugin
547 int total_out_buffers; // total send buffers allocated by the server
548 int total_in_buffers; // total receive buffers allocated by the server
549 int wr, rd; // File permissions for fileio plugins.
551 // These give the largest fragment the plugin is expected to handle.
552 // size of a send buffer to the server
553 int64_t out_buffer_size;
554 // size of a receive buffer from the server
555 int64_t in_buffer_size;
560 // Direction of most recent process_buffer
563 // Operating system scheduling
564 int realtime_priority;
566 // Position relative to start of EDL in requested rate. Calculated for every process
567 // command. Used for keyframes.
568 int64_t source_position;
569 // For realtime plugins gets the lowest sample of the plugin in the requested
570 // rate. For others it's always 0.
571 int64_t source_start;
572 // Length of source. For effects it's the plugin length. For transitions
573 // it's the transition length. Relative to the requested rate.
575 // Total number of processors available - 1
577 PluginServer *server;
579 PluginClientThread *thread;
581 // Frames for updating GUI
582 PluginClientFrames client_frames;
583 // Time of last GUI update
589 // Temporaries set in new_window
590 int window_x, window_y;
592 // Asset *asset; // Point to asset structure in shared memory