4 // Base class inherited by all the different types of plugins.
6 #define BCASTDIR "~/.bcast/"
11 #include "arraylist.h"
12 #include "condition.h"
14 #include "mainprogress.inc"
15 #include "maxbuffers.h"
16 #include "plugincommands.h"
17 #include "pluginserver.inc"
24 extern PluginClient
* new_plugin(PluginServer
*server
);
27 class PluginClientAuto
38 // Convenience functions
40 #define REGISTER_PLUGIN(class_title) \
41 PluginClient* new_plugin(PluginServer *server) \
43 return new class_title(server); \
47 #define WINDOW_CLOSE_EVENT(window_class) \
48 int window_class::close_event() \
50 /* Set result to 1 to indicate a client side close */ \
56 #define PLUGIN_THREAD_HEADER(plugin_class, thread_class, window_class) \
57 class thread_class : public Thread \
60 thread_class(plugin_class *plugin); \
63 window_class *window; \
64 plugin_class *plugin; \
68 #define PLUGIN_THREAD_OBJECT(plugin_class, thread_class, window_class) \
69 thread_class::thread_class(plugin_class *plugin) \
72 this->plugin = plugin; \
75 thread_class::~thread_class() \
80 void thread_class::run() \
82 BC_DisplayInfo info; \
83 window = new window_class(plugin, \
84 info.get_abs_cursor_x() - 75, \
85 info.get_abs_cursor_y() - 65); \
86 window->create_objects(); \
88 /* Only set it here so tracking doesn't update it until everything is created. */ \
89 plugin->thread = this; \
90 int result = window->run_window(); \
91 /* This is needed when the GUI is closed from itself */ \
92 if(result) plugin->client_side_close(); \
98 #define PLUGIN_CLASS_MEMBERS(config_name, thread_name) \
99 int load_configuration(); \
100 VFrame* new_picon(); \
101 char* plugin_title(); \
104 void raise_window(); \
105 Defaults *defaults; \
106 config_name config; \
109 #define PLUGIN_CONSTRUCTOR_MACRO \
114 #define PLUGIN_DESTRUCTOR_MACRO \
117 /* This is needed when the GUI is closed from elsewhere than itself */ \
118 /* Since we now use autodelete, this is all that has to be done, thread will take care of itself ... */ \
119 /* Thread join will wait if this was not called from the thread itself or go on if it was */ \
120 thread->window->lock_window("PLUGIN_DESTRUCTOR_MACRO"); \
121 thread->window->set_done(0); \
122 thread->window->unlock_window(); \
127 if(defaults) save_defaults(); \
128 if(defaults) delete defaults;
133 #define SHOW_GUI_MACRO(plugin_class, thread_class) \
134 int plugin_class::show_gui() \
136 load_configuration(); \
137 thread_class *new_thread = new thread_class(this); \
138 new_thread->start(); \
142 #define RAISE_WINDOW_MACRO(plugin_class) \
143 void plugin_class::raise_window() \
147 thread->window->lock_window(); \
148 thread->window->raise_window(); \
149 thread->window->flush(); \
150 thread->window->unlock_window(); \
154 #define SET_STRING_MACRO(plugin_class) \
155 int plugin_class::set_string() \
159 thread->window->lock_window(); \
160 thread->window->set_title(gui_string); \
161 thread->window->unlock_window(); \
166 #define NEW_PICON_MACRO(plugin_class) \
167 VFrame* plugin_class::new_picon() \
169 return new VFrame(picon_png); \
172 #define LOAD_CONFIGURATION_MACRO(plugin_class, config_class) \
173 int plugin_class::load_configuration() \
175 KeyFrame *prev_keyframe, *next_keyframe; \
176 prev_keyframe = get_prev_keyframe(get_source_position()); \
177 next_keyframe = get_next_keyframe(get_source_position()); \
179 int64_t next_position = edl_to_local(next_keyframe->position); \
180 int64_t prev_position = edl_to_local(prev_keyframe->position); \
182 config_class old_config, prev_config, next_config; \
183 old_config.copy_from(config); \
184 read_data(prev_keyframe); \
185 prev_config.copy_from(config); \
186 read_data(next_keyframe); \
187 next_config.copy_from(config); \
189 config.interpolate(prev_config, \
191 (next_position == prev_position) ? \
192 get_source_position() : \
194 (next_position == prev_position) ? \
195 get_source_position() + 1 : \
197 get_source_position()); \
199 if(!config.equivalent(old_config)) \
213 PluginClient(PluginServer
*server
);
214 virtual ~PluginClient();
217 // Queries for the plugin server.
218 virtual int is_realtime();
219 virtual int is_audio();
220 virtual int is_video();
221 virtual int is_fileio();
222 virtual int is_theme();
223 virtual int uses_gui();
224 virtual int is_multichannel();
225 virtual int is_synthesis();
226 virtual int is_transition();
227 virtual char* plugin_title(); // return the title of the plugin
228 virtual VFrame
* new_picon();
229 virtual Theme
* new_theme();
230 // Get theme being used by Cinelerra currently. Used by all plugins.
238 // Non realtime signal processors define these.
239 // Give the samplerate of the output for a non realtime plugin.
240 // For realtime plugins give the requested samplerate.
241 virtual int get_samplerate();
242 // Give the framerate of the output for a non realtime plugin.
243 // For realtime plugins give the requested framerate.
244 virtual double get_framerate();
245 virtual int delete_nonrealtime_parameters();
246 virtual int start_plugin(); // run a non realtime plugin
247 virtual int get_parameters(); // get information from user before non realtime processing
248 virtual int64_t get_in_buffers(int64_t recommended_size
); // return desired size for input buffers
249 virtual int64_t get_out_buffers(int64_t recommended_size
); // return desired size for output buffers
250 virtual int start_loop();
251 virtual int process_loop();
252 virtual int stop_loop();
257 // Realtime commands for signal processors.
258 // These must be defined by the plugin itself.
259 virtual int set_string(); // Set the string identifying the plugin to modules and patches.
260 // cause the plugin to show the gui
261 virtual int show_gui();
262 // cause the plugin to hide the gui
263 void client_side_close();
264 void update_display_title();
266 virtual void raise_window() {};
267 virtual void update_gui() {};
268 virtual void save_data(KeyFrame
*keyframe
) {}; // write the plugin settings to text in text format
269 virtual void read_data(KeyFrame
*keyframe
) {}; // read the plugin settings from the text
270 int send_hide_gui(); // should be sent when the GUI recieves a close event from the user
272 int get_configure_change(); // get propogated configuration change from a send_configure_change
274 // Replaced by pull method
276 * virtual void plugin_process_realtime(double **input,
278 * int64_t current_position,
279 * int64_t fragment_size,
280 * int64_t total_len) {};
281 * virtual void plugin_process_realtime(VFrame **input,
283 * int64_t current_position,
284 * int64_t total_len) {};
286 // Called by plugin server to update GUI with rendered data.
287 virtual void plugin_render_gui(void *data
) {};
288 virtual void plugin_render_gui(void *data
, int size
) {};
289 virtual int plugin_process_loop(VFrame
**buffers
, int64_t &write_length
) { return 1; };
290 virtual int plugin_process_loop(double **buffers
, int64_t &write_length
) { return 1; };
291 virtual int init_realtime_parameters(); // get parameters depending on video or audio
292 int get_gui_status();
293 char* get_gui_string();
296 // Used by plugins which need to know where they are.
299 // Return keyframe objects. The position in the resulting object
300 // is relative to the EDL rate. This is the only way to avoid copying the
301 // data for every frame.
302 // If the result is the default keyframe, the keyframe's position is 0.
303 // position - relative to EDL rate or local rate to allow simple
304 // passing of get_source_position.
305 // If -1 the tracking position in the edl is used.
306 // is_local - if 1, the position is converted to the EDL rate.
307 KeyFrame
* get_prev_keyframe(int64_t position
, int is_local
= 1);
308 KeyFrame
* get_next_keyframe(int64_t position
, int is_local
= 1);
309 // get camera and projector autos
310 void get_camera(float *x
, float *y
, float *z
, int64_t position
);
311 void get_projector(float *x
, float *y
, float *z
, int64_t position
);
312 // When this plugin is adjusted, propogate parameters back to EDL and virtual
313 // console. This gets a keyframe from the EDL, with the position set to the
314 // EDL tracking position.
315 int send_configure_change();
319 // Length of source. For effects it's the plugin length. For transitions
320 // it's the transition length. Relative to the requested rate.
321 // The only way to get smooth interpolation is to make all position queries
322 // relative to the requested rate.
323 int64_t get_total_len();
325 // For realtime plugins gets the lowest sample of the plugin in the requested
326 // rate. For others it's the start of the EDL selection in the EDL rate.
327 int64_t get_source_start();
329 // Convert the position relative to the requested rate to the position
330 // relative to the EDL rate. If the argument is < 0, it is not changed.
331 // Used for interpreting keyframes.
332 virtual int64_t local_to_edl(int64_t position
);
334 // Convert the EDL position to the local position.
335 virtual int64_t edl_to_local(int64_t position
);
337 // For transitions the source_position is the playback position relative
338 // to the start of the transition.
339 // For realtime effects, the start of the most recent process_buffer in forward
340 // and the end of the range to process in reverse. Relative to start of EDL in
341 // the requested rate.
342 int64_t get_source_position();
347 // Get the direction of the most recent process_buffer
350 // Get total tracks to process
351 int get_total_buffers();
353 // Get size of buffer to fill in non-realtime plugin
354 int get_buffer_size();
356 // Get interpolation used by EDL from overlayframe.inc
357 int get_interpolation_type();
359 // Get the values from the color picker
366 // Operations for file handlers
367 virtual int open_file() { return 0; };
368 virtual int get_audio_parameters() { return 0; };
369 virtual int get_video_parameters() { return 0; };
370 virtual int check_header(char *path
) { return 0; };
371 virtual int open_file(char *path
, int wr
, int rd
) { return 1; };
372 virtual int close_file() { return 0; };
378 // All plugins define these.
379 virtual int load_defaults(); // load default settings for the plugin
380 virtual int save_defaults(); // save the current settings as defaults
385 // Non realtime operations for signal processors.
386 virtual int plugin_start_loop(int64_t start
,
390 int plugin_stop_loop();
391 int plugin_process_loop();
392 MainProgressBar
* start_progress(char *string
, int64_t length
);
393 // get samplerate of EDL
394 int get_project_samplerate();
395 // get framerate of EDL
396 double get_project_framerate();
397 // Total number of processors - 1
398 int get_project_smp();
399 int get_aspect_ratio(float &aspect_w
, float &aspect_h
);
402 int write_frames(int64_t total_frames
); // returns 1 for failure / tells the server that all output channel buffers are ready to go
403 int write_samples(int64_t total_samples
); // returns 1 for failure / tells the server that all output channel buffers are ready to go
404 virtual int plugin_get_parameters();
405 char* get_defaultdir(); // Directory defaults should be stored in
406 void set_interactive();
408 // Realtime operations.
410 virtual int plugin_command_derived(int plugin_command
) {}; // Extension of plugin_run for derived plugins
411 int plugin_get_range();
412 int plugin_init_realtime(int realtime_priority
,
413 int total_in_buffers
,
418 // create pointers to buffers of the plugin's type before realtime rendering
419 virtual int delete_buffer_ptrs();
424 // communication convenience routines for the base class
425 int stop_gui_client();
426 int save_data_client();
427 int load_data_client();
428 int set_string_client(char *string
); // set the string identifying the plugin
429 int send_cancelled(); // non realtime plugin sends when cancelled
431 // ================================= Buffers ===============================
433 // number of double buffers for each channel
434 ArrayList
<int> double_buffers_in
;
435 ArrayList
<int> double_buffers_out
;
436 // When arming buffers need to know the offsets in all the buffers and which
437 // double buffers for each channel before rendering.
438 ArrayList
<int64_t> offset_in_render
;
439 ArrayList
<int64_t> offset_out_render
;
440 ArrayList
<int64_t> double_buffer_in_render
;
441 ArrayList
<int64_t> double_buffer_out_render
;
442 // total size of each buffer depends on if it's a master or node
443 ArrayList
<int64_t> realtime_in_size
;
444 ArrayList
<int64_t> realtime_out_size
;
446 // ================================= Automation ===========================
448 ArrayList
<PluginClientAuto
> automation
;
450 // ================================== Messages ===========================
451 char gui_string
[BCTEXTLEN
]; // string identifying module and plugin
452 int master_gui_on
; // Status of the master gui plugin
453 int client_gui_on
; // Status of this client's gui
455 int show_initially
; // set to show a realtime plugin initially
456 // range in project for processing
458 int interactive
; // for the progress bar plugin
460 int total_out_buffers
; // total send buffers allocated by the server
461 int total_in_buffers
; // total recieve buffers allocated by the server
462 int wr
, rd
; // File permissions for fileio plugins.
464 // These give the largest fragment the plugin is expected to handle.
465 // size of a send buffer to the server
466 int64_t out_buffer_size
;
467 // size of a recieve buffer from the server
468 int64_t in_buffer_size
;
473 // Direction of most recent process_buffer
476 // Operating system scheduling
477 int realtime_priority
;
479 // Position relative to start of EDL in requested rate. Calculated for every process
480 // command. Used for keyframes.
481 int64_t source_position
;
482 // For realtime plugins gets the lowest sample of the plugin in the requested
483 // rate. For others it's always 0.
484 int64_t source_start
;
485 // Length of source. For effects it's the plugin length. For transitions
486 // it's the transition length. Relative to the requested rate.
488 // Total number of processors available - 1
490 PluginServer
*server
;
495 // Asset *asset; // Point to asset structure in shared memory