r663: This commit was generated by cvs2svn to compensate for changes in r662,
[cinelerra_cv.git] / cinelerra / pluginclient.h
blob77a12203b1fff6c2299adc018676896c6d3925bd
1 #ifndef PLUGINCLIENT_H
2 #define PLUGINCLIENT_H
4 // Base class inherited by all the different types of plugins.
6 #define BCASTDIR "~/.bcast/"
8 class PluginClient;
11 #include "arraylist.h"
12 #include "condition.h"
13 #include "keyframe.h"
14 #include "mainprogress.inc"
15 #include "maxbuffers.h"
16 #include "plugincommands.h"
17 #include "pluginserver.inc"
18 #include "theme.inc"
19 #include "vframe.h"
22 extern "C"
24 extern PluginClient* new_plugin(PluginServer *server);
27 class PluginClientAuto
29 public:
30 float position;
31 float intercept;
32 float slope;
38 // Convenience functions
40 #define REGISTER_PLUGIN(class_title) \
41 PluginClient* new_plugin(PluginServer *server) \
42 { \
43 return new class_title(server); \
47 #define WINDOW_CLOSE_EVENT(window_class) \
48 int window_class::close_event() \
49 { \
50 /* Set result to 1 to indicate a client side close */ \
51 set_done(1); \
52 return 1; \
56 #define PLUGIN_THREAD_HEADER(plugin_class, thread_class, window_class) \
57 class thread_class : public Thread \
58 { \
59 public: \
60 thread_class(plugin_class *plugin); \
61 ~thread_class(); \
62 void run(); \
63 window_class *window; \
64 plugin_class *plugin; \
65 Condition *completion; \
69 #define PLUGIN_THREAD_OBJECT(plugin_class, thread_class, window_class) \
70 thread_class::thread_class(plugin_class *plugin) \
71 : Thread(0, 0, 0) \
72 { \
73 this->plugin = plugin; \
74 completion = new Condition(0, "thread_class::completion"); \
75 } \
77 thread_class::~thread_class() \
78 { \
79 delete window; \
80 } \
82 void thread_class::run() \
83 { \
84 BC_DisplayInfo info; \
85 window = new window_class(plugin, \
86 info.get_abs_cursor_x() - 75, \
87 info.get_abs_cursor_y() - 65); \
88 window->create_objects(); \
90 /* Only set it here so tracking doesn't update it until everything is created. */ \
91 plugin->thread = this; \
92 int result = window->run_window(); \
93 completion->unlock(); \
94 /* This is needed when the GUI is closed from itself */ \
95 if(result) plugin->client_side_close(); \
101 #define PLUGIN_CLASS_MEMBERS(config_name, thread_name) \
102 int load_configuration(); \
103 VFrame* new_picon(); \
104 char* plugin_title(); \
105 int show_gui(); \
106 int set_string(); \
107 void raise_window(); \
108 Defaults *defaults; \
109 config_name config; \
110 thread_name *thread;
112 #define PLUGIN_CONSTRUCTOR_MACRO \
113 thread = 0; \
114 defaults = 0; \
115 load_defaults(); \
117 #define PLUGIN_DESTRUCTOR_MACRO \
118 if(thread) \
120 /* This is needed when the GUI is closed from elsewhere than itself */ \
121 thread->window->lock_window("PLUGIN_DESTRUCTOR_MACRO"); \
122 thread->window->set_done(0); \
123 thread->window->unlock_window(); \
124 thread->completion->lock("PLUGIN_DESTRUCTOR_MACRO"); \
125 delete thread; \
129 if(defaults) save_defaults(); \
130 if(defaults) delete defaults;
135 #define SHOW_GUI_MACRO(plugin_class, thread_class) \
136 int plugin_class::show_gui() \
138 load_configuration(); \
139 thread_class *new_thread = new thread_class(this); \
140 new_thread->start(); \
141 return 0; \
144 #define RAISE_WINDOW_MACRO(plugin_class) \
145 void plugin_class::raise_window() \
147 if(thread) \
149 thread->window->lock_window(); \
150 thread->window->raise_window(); \
151 thread->window->flush(); \
152 thread->window->unlock_window(); \
156 #define SET_STRING_MACRO(plugin_class) \
157 int plugin_class::set_string() \
159 if(thread) \
161 thread->window->lock_window(); \
162 thread->window->set_title(gui_string); \
163 thread->window->unlock_window(); \
165 return 0; \
168 #define NEW_PICON_MACRO(plugin_class) \
169 VFrame* plugin_class::new_picon() \
171 return new VFrame(picon_png); \
174 #define LOAD_CONFIGURATION_MACRO(plugin_class, config_class) \
175 int plugin_class::load_configuration() \
177 KeyFrame *prev_keyframe, *next_keyframe; \
178 prev_keyframe = get_prev_keyframe(get_source_position()); \
179 next_keyframe = get_next_keyframe(get_source_position()); \
181 int64_t next_position = edl_to_local(next_keyframe->position); \
182 int64_t prev_position = edl_to_local(prev_keyframe->position); \
184 config_class old_config, prev_config, next_config; \
185 old_config.copy_from(config); \
186 read_data(prev_keyframe); \
187 prev_config.copy_from(config); \
188 read_data(next_keyframe); \
189 next_config.copy_from(config); \
191 config.interpolate(prev_config, \
192 next_config, \
193 (next_position == prev_position) ? \
194 get_source_position() : \
195 prev_position, \
196 (next_position == prev_position) ? \
197 get_source_position() + 1 : \
198 next_position, \
199 get_source_position()); \
201 if(!config.equivalent(old_config)) \
202 return 1; \
203 else \
204 return 0; \
212 class PluginClient
214 public:
215 PluginClient(PluginServer *server);
216 virtual ~PluginClient();
219 // Queries for the plugin server.
220 virtual int is_realtime();
221 virtual int is_audio();
222 virtual int is_video();
223 virtual int is_fileio();
224 virtual int is_theme();
225 virtual int uses_gui();
226 virtual int is_multichannel();
227 virtual int is_synthesis();
228 virtual int is_transition();
229 virtual char* plugin_title(); // return the title of the plugin
230 virtual VFrame* new_picon();
231 virtual Theme* new_theme();
232 // Get theme being used by Cinelerra currently. Used by all plugins.
233 Theme* get_theme();
240 // Non realtime signal processors define these.
241 // Give the samplerate of the output for a non realtime plugin.
242 // For realtime plugins give the requested samplerate.
243 virtual int get_samplerate();
244 // Give the framerate of the output for a non realtime plugin.
245 // For realtime plugins give the requested framerate.
246 virtual double get_framerate();
247 virtual int delete_nonrealtime_parameters();
248 virtual int start_plugin(); // run a non realtime plugin
249 virtual int get_parameters(); // get information from user before non realtime processing
250 virtual int64_t get_in_buffers(int64_t recommended_size); // return desired size for input buffers
251 virtual int64_t get_out_buffers(int64_t recommended_size); // return desired size for output buffers
252 virtual int start_loop();
253 virtual int process_loop();
254 virtual int stop_loop();
259 // Realtime commands for signal processors.
260 // These must be defined by the plugin itself.
261 virtual int set_string(); // Set the string identifying the plugin to modules and patches.
262 // cause the plugin to show the gui
263 virtual int show_gui();
264 // cause the plugin to hide the gui
265 void client_side_close();
266 void update_display_title();
267 // Raise the GUI
268 virtual void raise_window() {};
269 virtual void update_gui() {};
270 virtual void save_data(KeyFrame *keyframe) {}; // write the plugin settings to text in text format
271 virtual void read_data(KeyFrame *keyframe) {}; // read the plugin settings from the text
272 int send_hide_gui(); // should be sent when the GUI recieves a close event from the user
274 int get_configure_change(); // get propogated configuration change from a send_configure_change
276 // Replaced by pull method
278 * virtual void plugin_process_realtime(double **input,
279 * double **output,
280 * int64_t current_position,
281 * int64_t fragment_size,
282 * int64_t total_len) {};
283 * virtual void plugin_process_realtime(VFrame **input,
284 * VFrame **output,
285 * int64_t current_position,
286 * int64_t total_len) {};
288 // Called by plugin server to update GUI with rendered data.
289 virtual void plugin_render_gui(void *data) {};
290 virtual void plugin_render_gui(void *data, int size) {};
291 virtual int plugin_process_loop(VFrame **buffers, int64_t &write_length) { return 1; };
292 virtual int plugin_process_loop(double **buffers, int64_t &write_length) { return 1; };
293 virtual int init_realtime_parameters(); // get parameters depending on video or audio
294 int get_gui_status();
295 char* get_gui_string();
297 // Used by themes
298 // Used by plugins which need to know where they are.
299 char* get_path();
301 // Return keyframe objects. The position in the resulting object
302 // is relative to the EDL rate. This is the only way to avoid copying the
303 // data for every frame.
304 // If the result is the default keyframe, the keyframe's position is 0.
305 // position - relative to EDL rate or local rate to allow simple
306 // passing of get_source_position.
307 // If -1 the tracking position in the edl is used.
308 // is_local - if 1, the position is converted to the EDL rate.
309 KeyFrame* get_prev_keyframe(int64_t position, int is_local = 1);
310 KeyFrame* get_next_keyframe(int64_t position, int is_local = 1);
311 // When this plugin is adjusted, propogate parameters back to EDL and virtual
312 // console. This gets a keyframe from the EDL, with the position set to the
313 // EDL tracking position.
314 int send_configure_change();
318 // Length of source. For effects it's the plugin length. For transitions
319 // it's the transition length. Relative to the requested rate.
320 // The only way to get smooth interpolation is to make all position queries
321 // relative to the requested rate.
322 int64_t get_total_len();
324 // For realtime plugins gets the lowest sample of the plugin in the requested
325 // rate. For others it's the start of the EDL selection in the EDL rate.
326 int64_t get_source_start();
328 // Convert the position relative to the requested rate to the position
329 // relative to the EDL rate. If the argument is < 0, it is not changed.
330 // Used for interpreting keyframes.
331 virtual int64_t local_to_edl(int64_t position);
333 // Convert the EDL position to the local position.
334 virtual int64_t edl_to_local(int64_t position);
336 // For transitions the source_position is the playback position relative
337 // to the start of the transition.
338 // For realtime effects, the start of the most recent process_buffer in forward
339 // and the end of the range to process in reverse. Relative to start of EDL in
340 // the requested rate.
341 int64_t get_source_position();
346 // Get the direction of the most recent process_buffer
347 int get_direction();
349 // Get total tracks to process
350 int get_total_buffers();
352 // Get size of buffer to fill in non-realtime plugin
353 int get_buffer_size();
355 // Get interpolation used by EDL from overlayframe.inc
356 int get_interpolation_type();
358 // Get the values from the color picker
359 float get_red();
360 float get_green();
361 float get_blue();
365 // Operations for file handlers
366 virtual int open_file() { return 0; };
367 virtual int get_audio_parameters() { return 0; };
368 virtual int get_video_parameters() { return 0; };
369 virtual int check_header(char *path) { return 0; };
370 virtual int open_file(char *path, int wr, int rd) { return 1; };
371 virtual int close_file() { return 0; };
377 // All plugins define these.
378 virtual int load_defaults(); // load default settings for the plugin
379 virtual int save_defaults(); // save the current settings as defaults
384 // Non realtime operations for signal processors.
385 virtual int plugin_start_loop(int64_t start,
386 int64_t end,
387 int64_t buffer_size,
388 int total_buffers);
389 int plugin_stop_loop();
390 int plugin_process_loop();
391 MainProgressBar* start_progress(char *string, int64_t length);
392 // get samplerate of EDL
393 int get_project_samplerate();
394 // get framerate of EDL
395 double get_project_framerate();
396 // Total number of processors - 1
397 int get_project_smp();
398 int get_aspect_ratio(float &aspect_w, float &aspect_h);
401 int write_frames(int64_t total_frames); // returns 1 for failure / tells the server that all output channel buffers are ready to go
402 int write_samples(int64_t total_samples); // returns 1 for failure / tells the server that all output channel buffers are ready to go
403 virtual int plugin_get_parameters();
404 char* get_defaultdir(); // Directory defaults should be stored in
405 void set_interactive();
407 // Realtime operations.
408 int reset();
409 virtual int plugin_command_derived(int plugin_command) {}; // Extension of plugin_run for derived plugins
410 int plugin_get_range();
411 int plugin_init_realtime(int realtime_priority,
412 int total_in_buffers,
413 int buffer_size);
417 // create pointers to buffers of the plugin's type before realtime rendering
418 virtual int delete_buffer_ptrs();
423 // communication convenience routines for the base class
424 int stop_gui_client();
425 int save_data_client();
426 int load_data_client();
427 int set_string_client(char *string); // set the string identifying the plugin
428 int send_cancelled(); // non realtime plugin sends when cancelled
430 // ================================= Buffers ===============================
432 // number of double buffers for each channel
433 ArrayList<int> double_buffers_in;
434 ArrayList<int> double_buffers_out;
435 // When arming buffers need to know the offsets in all the buffers and which
436 // double buffers for each channel before rendering.
437 ArrayList<int64_t> offset_in_render;
438 ArrayList<int64_t> offset_out_render;
439 ArrayList<int64_t> double_buffer_in_render;
440 ArrayList<int64_t> double_buffer_out_render;
441 // total size of each buffer depends on if it's a master or node
442 ArrayList<int64_t> realtime_in_size;
443 ArrayList<int64_t> realtime_out_size;
445 // ================================= Automation ===========================
447 ArrayList<PluginClientAuto> automation;
449 // ================================== Messages ===========================
450 char gui_string[BCTEXTLEN]; // string identifying module and plugin
451 int master_gui_on; // Status of the master gui plugin
452 int client_gui_on; // Status of this client's gui
454 int show_initially; // set to show a realtime plugin initially
455 // range in project for processing
456 int64_t start, end;
457 int interactive; // for the progress bar plugin
458 int success;
459 int total_out_buffers; // total send buffers allocated by the server
460 int total_in_buffers; // total recieve buffers allocated by the server
461 int wr, rd; // File permissions for fileio plugins.
463 // These give the largest fragment the plugin is expected to handle.
464 // size of a send buffer to the server
465 int64_t out_buffer_size;
466 // size of a recieve buffer from the server
467 int64_t in_buffer_size;
472 // Direction of most recent process_buffer
473 int direction;
475 // Operating system scheduling
476 int realtime_priority;
478 // Position relative to start of EDL in requested rate. Calculated for every process
479 // command. Used for keyframes.
480 int64_t source_position;
481 // For realtime plugins gets the lowest sample of the plugin in the requested
482 // rate. For others it's always 0.
483 int64_t source_start;
484 // Length of source. For effects it's the plugin length. For transitions
485 // it's the transition length. Relative to the requested rate.
486 int64_t total_len;
487 // Total number of processors available - 1
488 int smp;
489 PluginServer *server;
491 private:
493 // File handlers:
494 // Asset *asset; // Point to asset structure in shared memory
498 #endif