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 BCASTDIR "~/.bcast5/"
28 #define MAX_FRAME_BUFFER 1024
33 #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)) \
143 class PluginClientWindow : public BC_Window
146 PluginClientWindow(PluginClient *client,
152 PluginClientWindow(const char *title,
160 virtual ~PluginClientWindow();
162 virtual int translation_event();
163 virtual int close_event();
165 PluginClient *client;
171 class PluginClientThread : public Thread
174 PluginClientThread(PluginClient *client);
175 ~PluginClientThread();
178 friend class PluginClient;
180 BC_WindowBase* get_window();
181 PluginClient* get_client();
182 BC_WindowBase *window;
183 PluginClient *client;
186 Condition *init_complete;
191 // Client overrides for GUI update data
192 class PluginClientFrame
195 // Period_d is 1 second
196 PluginClientFrame(int data_size, int period_n, int period_d);
197 virtual ~PluginClientFrame();
210 PluginClient(PluginServer *server);
211 virtual ~PluginClient();
213 friend class PluginClientThread;
214 friend class PluginClientWindow;
216 // Queries for the plugin server.
217 virtual int is_realtime();
218 virtual int is_audio();
219 virtual int is_video();
220 virtual int is_fileio();
221 virtual int is_theme();
222 virtual int uses_gui();
223 virtual int is_multichannel();
224 virtual int is_synthesis();
225 virtual int is_transition();
226 virtual const char* plugin_title(); // return the title of the plugin
227 virtual Theme* new_theme();
228 // Get theme being used by Cinelerra currently. Used by all plugins.
236 // Non realtime signal processors define these.
237 // Give the samplerate of the output for a non realtime plugin.
238 // For realtime plugins give the requested samplerate.
239 virtual int get_samplerate();
240 // Give the framerate of the output for a non realtime plugin.
241 // For realtime plugins give the requested framerate.
242 virtual double get_framerate();
243 virtual int delete_nonrealtime_parameters();
244 virtual int start_plugin(); // run a non realtime plugin
245 virtual int get_parameters(); // get information from user before non realtime processing
246 virtual int64_t get_in_buffers(int64_t recommended_size); // return desired size for input buffers
247 virtual int64_t get_out_buffers(int64_t recommended_size); // return desired size for output buffers
248 virtual int start_loop();
249 virtual int process_loop();
250 virtual int stop_loop();
251 // Hash files are the defaults for rendered plugins
252 virtual int load_defaults(); // load default settings for the plugin
253 virtual int save_defaults(); // save the current settings as defaults
254 BC_Hash* get_defaults();
259 // Realtime commands for signal processors.
260 // These must be defined by the plugin itself.
261 // Set the GUI title identifying the plugin to modules and patches.
263 // cause the plugin to create a new GUI class
264 virtual BC_WindowBase* new_window();
265 // Load the current keyframe. Return 1 if it changed.
266 virtual int load_configuration();
267 // cause the plugin to hide the gui
268 void client_side_close();
269 void update_display_title();
274 // XML keyframes are the defaults for realtime plugins
275 void load_defaults_xml();
276 void save_defaults_xml();
277 // Tell the client if the load is the defaults
280 virtual void update_gui();
281 virtual void save_data(KeyFrame *keyframe) {}; // write the plugin settings to text in text format
282 virtual void read_data(KeyFrame *keyframe) {}; // read the plugin settings from the text
283 int send_hide_gui(); // should be sent when the GUI recieves a close event from the user
284 // Destroys the window but not the thread pointer.
287 int get_configure_change(); // get propogated configuration change from a send_configure_change
289 // Called by plugin server to update GUI with rendered data.
290 void plugin_render_gui(void *data);
291 void plugin_render_gui(void *data, int size);
293 void begin_process_buffer();
294 void end_process_buffer();
296 void plugin_update_gui();
297 virtual int plugin_process_loop(VFrame **buffers, int64_t &write_length) { return 1; };
298 virtual int plugin_process_loop(Samples **buffers, int64_t &write_length) { return 1; };
299 // get parameters depending on video or audio
300 virtual int init_realtime_parameters();
301 // release objects which are required after playback stops
302 virtual void render_stop() {};
303 int get_gui_status();
304 char* get_gui_string();
307 // Used by plugins which need to know where they are.
309 // Get the directory for plugins
310 char* get_plugin_dir();
312 // Return keyframe objects. The position in the resulting object
313 // is relative to the EDL rate. This is the only way to avoid copying the
314 // data for every frame.
315 // If the result is the default keyframe, the keyframe's position is 0.
316 // position - relative to EDL rate or local rate to allow simple
317 // passing of get_source_position.
318 // If -1 the tracking position in the edl is used.
319 // is_local - if 1, the position is converted to the EDL rate.
320 KeyFrame* get_prev_keyframe(int64_t position, int is_local = 1);
321 KeyFrame* get_next_keyframe(int64_t position, int is_local = 1);
322 // get current camera and projector position
323 void get_camera(float *x, float *y, float *z, int64_t position);
324 void get_projector(float *x, float *y, float *z, int64_t position);
325 // When this plugin is adjusted, propogate parameters back to EDL and virtual
326 // console. This gets a keyframe from the EDL, with the position set to the
327 // EDL tracking position.
328 int send_configure_change();
331 // Called from process_buffer
332 // Returns 1 if a GUI is open so OpenGL routines can determine if
338 // Length of source. For effects it's the plugin length. For transitions
339 // it's the transition length. Relative to the requested rate.
340 // The only way to get smooth interpolation is to make all position queries
341 // relative to the requested rate.
342 int64_t get_total_len();
344 // For realtime plugins gets the lowest sample of the plugin in the requested
345 // rate. For others it's the start of the EDL selection in the EDL rate.
346 int64_t get_source_start();
348 // Convert the position relative to the requested rate to the position
349 // relative to the EDL rate. If the argument is < 0, it is not changed.
350 // Used for interpreting keyframes.
351 virtual int64_t local_to_edl(int64_t position);
353 // Convert the EDL position to the local position.
354 virtual int64_t edl_to_local(int64_t position);
356 // For transitions the source_position is the playback position relative
357 // to the start of the transition.
358 // For realtime effects, the start of the most recent process_buffer in forward
359 // and the end of the range to process in reverse. Relative to start of EDL in
360 // the requested rate.
361 int64_t get_source_position();
363 // Get the EDL Session. May return 0 if the server has no edl.
364 EDLSession* get_edlsession();
367 // Get the direction of the most recent process_buffer
370 // Plugin must call this before performing OpenGL operations.
371 // Returns 1 if the user supports opengl buffers.
372 int get_use_opengl();
374 // Get total tracks to process
375 int get_total_buffers();
377 // Get size of buffer to fill in non-realtime plugin
378 int get_buffer_size();
380 // Get interpolation used by EDL from overlayframe.inc
381 int get_interpolation_type();
383 // Get the values from the color picker
390 // Operations for file handlers
391 virtual int open_file() { return 0; };
392 virtual int get_audio_parameters() { return 0; };
393 virtual int get_video_parameters() { return 0; };
394 virtual int check_header(char *path) { return 0; };
395 virtual int open_file(char *path, int wr, int rd) { return 1; };
396 virtual int close_file() { return 0; };
402 // All plugins define these.
403 PluginClientThread* get_thread();
407 // Non realtime operations for signal processors.
408 virtual int plugin_start_loop(int64_t start,
412 int plugin_stop_loop();
413 int plugin_process_loop();
414 MainProgressBar* start_progress(char *string, int64_t length);
415 // get samplerate of EDL
416 int get_project_samplerate();
417 // get framerate of EDL
418 double get_project_framerate();
419 // Total number of processors - 1
420 int get_project_smp();
421 int get_aspect_ratio(float &aspect_w, float &aspect_h);
424 int write_frames(int64_t total_frames); // returns 1 for failure / tells the server that all output channel buffers are ready to go
425 int write_samples(int64_t total_samples); // returns 1 for failure / tells the server that all output channel buffers are ready to go
426 virtual int plugin_get_parameters();
427 const char* get_defaultdir(); // Directory defaults should be stored in
428 void set_interactive();
430 // Realtime operations.
432 // Extension of plugin_run for derived plugins
433 virtual int plugin_command_derived(int plugin_command) { return 0; };
434 int plugin_get_range();
435 int plugin_init_realtime(int realtime_priority,
436 int total_in_buffers,
440 // GUI updating wrappers for realtime plugins
441 // Append frame to queue for next send_frame_buffer
442 void add_gui_frame(PluginClientFrame *frame);
446 virtual void render_gui(void *data);
447 virtual void render_gui(void *data, int size);
449 // Called by client to get the total number of frames to draw in update_gui
450 int get_gui_update_frames();
451 // Get GUI frame from frame_buffer. Client must delete it.
452 PluginClientFrame* get_gui_frame();
454 // Called by client to cause GUI to be rendered with data.
455 void send_render_gui();
456 void send_render_gui(void *data);
457 void send_render_gui(void *data, int size);
466 // create pointers to buffers of the plugin's type before realtime rendering
467 virtual int delete_buffer_ptrs();
472 // communication convenience routines for the base class
473 int stop_gui_client();
474 int save_data_client();
475 int load_data_client();
476 int set_string_client(char *string); // set the string identifying the plugin
477 int send_cancelled(); // non realtime plugin sends when cancelled
479 // ================================= Buffers ===============================
481 // number of double buffers for each channel
482 ArrayList<int> double_buffers_in;
483 ArrayList<int> double_buffers_out;
484 // When arming buffers need to know the offsets in all the buffers and which
485 // double buffers for each channel before rendering.
486 ArrayList<int64_t> offset_in_render;
487 ArrayList<int64_t> offset_out_render;
488 ArrayList<int64_t> double_buffer_in_render;
489 ArrayList<int64_t> double_buffer_out_render;
490 // total size of each buffer depends on if it's a master or node
491 ArrayList<int64_t> realtime_in_size;
492 ArrayList<int64_t> realtime_out_size;
494 // ================================= Automation ===========================
496 ArrayList<PluginClientAuto> automation;
498 // ================================== Messages ===========================
499 char gui_string[BCTEXTLEN]; // string identifying module and plugin
500 int master_gui_on; // Status of the master gui plugin
501 int client_gui_on; // Status of this client's gui
503 int show_initially; // set to show a realtime plugin initially
504 // range in project for processing
506 int interactive; // for the progress bar plugin
508 int total_out_buffers; // total send buffers allocated by the server
509 int total_in_buffers; // total recieve buffers allocated by the server
510 int wr, rd; // File permissions for fileio plugins.
512 // These give the largest fragment the plugin is expected to handle.
513 // size of a send buffer to the server
514 int64_t out_buffer_size;
515 // size of a recieve buffer from the server
516 int64_t in_buffer_size;
521 // Direction of most recent process_buffer
524 // Operating system scheduling
525 int realtime_priority;
527 // Position relative to start of EDL in requested rate. Calculated for every process
528 // command. Used for keyframes.
529 int64_t source_position;
530 // For realtime plugins gets the lowest sample of the plugin in the requested
531 // rate. For others it's always 0.
532 int64_t source_start;
533 // Length of source. For effects it's the plugin length. For transitions
534 // it's the transition length. Relative to the requested rate.
536 // Total number of processors available - 1
538 PluginServer *server;
540 PluginClientThread *thread;
542 // Frames for updating GUI
543 ArrayList<PluginClientFrame*> frame_buffer;
544 // Time of last GUI update
550 // Temporaries set in new_window
551 int window_x, window_y;
553 // Asset *asset; // Point to asset structure in shared memory