r370: Heroine Virutal's official release 1.2.1
[cinelerra_cv/mob.git] / hvirtual / cinelerra / pluginclient.h
blob85a877a02d48f536da9e9913cec7f2dd97269fad
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 // If automation is used. Obsolete.
359 // int automation_used();
360 // Get the automation value for the position in the current fragment
361 // The position is relative to the current fragment
362 // Obsolete.
363 // float get_automation_value(int64_t position);
368 // Operations for file handlers
369 virtual int open_file() { return 0; };
370 virtual int get_audio_parameters() { return 0; };
371 virtual int get_video_parameters() { return 0; };
372 virtual int check_header(char *path) { return 0; };
373 virtual int open_file(char *path, int wr, int rd) { return 1; };
374 virtual int close_file() { return 0; };
380 // All plugins define these.
381 virtual int load_defaults(); // load default settings for the plugin
382 virtual int save_defaults(); // save the current settings as defaults
387 // Non realtime operations for signal processors.
388 virtual int plugin_start_loop(int64_t start,
389 int64_t end,
390 int64_t buffer_size,
391 int total_buffers);
392 int plugin_stop_loop();
393 int plugin_process_loop();
394 MainProgressBar* start_progress(char *string, int64_t length);
395 // get samplerate of EDL
396 int get_project_samplerate();
397 // get framerate of EDL
398 double get_project_framerate();
399 // Total number of processors - 1
400 int get_project_smp();
401 int get_aspect_ratio(float &aspect_w, float &aspect_h);
404 int write_frames(int64_t total_frames); // returns 1 for failure / tells the server that all output channel buffers are ready to go
405 int write_samples(int64_t total_samples); // returns 1 for failure / tells the server that all output channel buffers are ready to go
406 virtual int plugin_get_parameters();
407 char* get_defaultdir(); // Directory defaults should be stored in
408 void set_interactive();
410 // Realtime operations.
411 int reset();
412 virtual int plugin_command_derived(int plugin_command) {}; // Extension of plugin_run for derived plugins
413 int plugin_get_range();
414 int plugin_init_realtime(int realtime_priority,
415 int total_in_buffers,
416 int buffer_size);
420 // create pointers to buffers of the plugin's type before realtime rendering
421 virtual int delete_buffer_ptrs();
426 // communication convenience routines for the base class
427 int stop_gui_client();
428 int save_data_client();
429 int load_data_client();
430 int set_string_client(char *string); // set the string identifying the plugin
431 int send_cancelled(); // non realtime plugin sends when cancelled
433 // ================================= Buffers ===============================
435 // number of double buffers for each channel
436 ArrayList<int> double_buffers_in;
437 ArrayList<int> double_buffers_out;
438 // When arming buffers need to know the offsets in all the buffers and which
439 // double buffers for each channel before rendering.
440 ArrayList<int64_t> offset_in_render;
441 ArrayList<int64_t> offset_out_render;
442 ArrayList<int64_t> double_buffer_in_render;
443 ArrayList<int64_t> double_buffer_out_render;
444 // total size of each buffer depends on if it's a master or node
445 ArrayList<int64_t> realtime_in_size;
446 ArrayList<int64_t> realtime_out_size;
448 // ================================= Automation ===========================
450 ArrayList<PluginClientAuto> automation;
452 // ================================== Messages ===========================
453 char gui_string[BCTEXTLEN]; // string identifying module and plugin
454 int master_gui_on; // Status of the master gui plugin
455 int client_gui_on; // Status of this client's gui
457 int show_initially; // set to show a realtime plugin initially
458 // range in project for processing
459 int64_t start, end;
460 int interactive; // for the progress bar plugin
461 int success;
462 int total_out_buffers; // total send buffers allocated by the server
463 int total_in_buffers; // total recieve buffers allocated by the server
464 int wr, rd; // File permissions for fileio plugins.
466 // These give the largest fragment the plugin is expected to handle.
467 // size of a send buffer to the server
468 int64_t out_buffer_size;
469 // size of a recieve buffer from the server
470 int64_t in_buffer_size;
475 // Direction of most recent process_buffer
476 int direction;
478 // Operating system scheduling
479 int realtime_priority;
481 // Position relative to start of EDL in requested rate. Calculated for every process
482 // command. Used for keyframes.
483 int64_t source_position;
484 // For realtime plugins gets the lowest sample of the plugin in the requested
485 // rate. For others it's always 0.
486 int64_t source_start;
487 // Length of source. For effects it's the plugin length. For transitions
488 // it's the transition length. Relative to the requested rate.
489 int64_t total_len;
490 // Total number of processors available - 1
491 int smp;
492 PluginServer *server;
494 private:
496 // File handlers:
497 // Asset *asset; // Point to asset structure in shared memory
501 #endif