r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / pluginclient.h
blob9d4c482262171448d283f8bf806770e99238ec85
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 "keyframe.h"
13 #include "mainprogress.inc"
14 #include "maxbuffers.h"
15 #include "messages.h"
16 #include "plugincommands.h"
17 #include "pluginserver.inc"
18 #include "sema.h"
19 #include "theme.inc"
20 #include "vframe.h"
23 extern "C"
25 extern PluginClient* new_plugin(PluginServer *server);
28 class PluginClientAuto
30 public:
31 float position;
32 float intercept;
33 float slope;
39 // Convenience functions
41 #define REGISTER_PLUGIN(class_title) \
42 PluginClient* new_plugin(PluginServer *server) \
43 { \
44 return new class_title(server); \
48 #define WINDOW_CLOSE_EVENT(window_class) \
49 int window_class::close_event() \
50 { \
51 /* Set result to 1 to indicate a client side close */ \
52 set_done(1); \
53 return 1; \
57 #define PLUGIN_THREAD_HEADER(plugin_class, thread_class, window_class) \
58 class thread_class : public Thread \
59 { \
60 public: \
61 thread_class(plugin_class *plugin); \
62 ~thread_class(); \
63 void run(); \
64 Mutex completion; \
65 window_class *window; \
66 plugin_class *plugin; \
70 #define PLUGIN_THREAD_OBJECT(plugin_class, thread_class, window_class) \
71 thread_class::thread_class(plugin_class *plugin) \
72 : Thread() \
73 { \
74 this->plugin = plugin; \
75 set_synchronous(0); \
76 completion.lock(); \
77 } \
79 thread_class::~thread_class() \
80 { \
81 delete window; \
82 } \
84 void thread_class::run() \
85 { \
86 /* printf("thread_class::run 1\n"); */ \
87 BC_DisplayInfo info; \
88 /* printf("thread_class::run 1\n"); */ \
89 window = new window_class(plugin, \
90 info.get_abs_cursor_x() - 75, \
91 info.get_abs_cursor_y() - 65); \
92 /* printf("thread_class::run 1\n"); */ \
93 window->create_objects(); \
94 /* printf("thread_class::run 1\n"); */ \
96 /* Only set it here so tracking doesn't update it until everything is created. */ \
97 plugin->thread = this; \
98 /* printf("thread_class::run 1\n"); */ \
99 int result = window->run_window(); \
100 /* printf("thread_class::run 1\n"); */ \
101 completion.unlock(); \
102 /* printf("thread_class::run 1\n"); */ \
103 if(result) plugin->client_side_close(); \
104 /* printf("thread_class::run 2\n"); */ \
110 #define PLUGIN_CLASS_MEMBERS(config_name, thread_name) \
111 int load_configuration(); \
112 VFrame* new_picon(); \
113 char* plugin_title(); \
114 int show_gui(); \
115 int set_string(); \
116 void raise_window(); \
117 Defaults *defaults; \
118 config_name config; \
119 thread_name *thread;
121 #define PLUGIN_CONSTRUCTOR_MACRO \
122 thread = 0; \
123 defaults = 0; \
124 load_defaults(); \
126 #define PLUGIN_DESTRUCTOR_MACRO \
127 if(thread) \
129 thread->window->set_done(0); \
130 thread->completion.lock(); \
131 delete thread; \
134 if(defaults) save_defaults(); \
135 if(defaults) delete defaults;
140 #define SHOW_GUI_MACRO(plugin_class, thread_class) \
141 int plugin_class::show_gui() \
143 load_configuration(); \
144 thread_class *new_thread = new thread_class(this); \
145 new_thread->start(); \
146 return 0; \
149 #define RAISE_WINDOW_MACRO(plugin_class) \
150 void plugin_class::raise_window() \
152 if(thread) \
154 thread->window->lock_window(); \
155 thread->window->raise_window(); \
156 thread->window->flush(); \
157 thread->window->unlock_window(); \
161 #define SET_STRING_MACRO(plugin_class) \
162 int plugin_class::set_string() \
164 if(thread) \
166 thread->window->lock_window(); \
167 thread->window->set_title(gui_string); \
168 thread->window->unlock_window(); \
170 return 0; \
173 #define NEW_PICON_MACRO(plugin_class) \
174 VFrame* plugin_class::new_picon() \
176 return new VFrame(picon_png); \
179 #define LOAD_CONFIGURATION_MACRO(plugin_class, config_class) \
180 int plugin_class::load_configuration() \
182 KeyFrame *prev_keyframe, *next_keyframe; \
183 prev_keyframe = get_prev_keyframe(get_source_position()); \
184 next_keyframe = get_next_keyframe(get_source_position()); \
186 config_class old_config, prev_config, next_config; \
187 old_config.copy_from(config); \
188 read_data(prev_keyframe); \
189 prev_config.copy_from(config); \
190 read_data(next_keyframe); \
191 next_config.copy_from(config); \
192 config.interpolate(prev_config, \
193 next_config, \
194 (next_keyframe->position == prev_keyframe->position) ? \
195 get_source_position() : \
196 prev_keyframe->position, \
197 (next_keyframe->position == prev_keyframe->position) ? \
198 get_source_position() + 1 : \
199 next_keyframe->position, \
200 get_source_position()); \
202 if(!config.equivalent(old_config)) \
203 return 1; \
204 else \
205 return 0; \
213 class PluginClient
215 public:
216 PluginClient(PluginServer *server);
217 virtual ~PluginClient();
220 // Queries for the plugin server.
221 virtual int is_realtime();
222 virtual int is_audio();
223 virtual int is_video();
224 virtual int is_fileio();
225 virtual int is_theme();
226 virtual int uses_gui();
227 virtual int is_multichannel();
228 virtual int is_synthesis();
229 virtual int is_transition();
230 virtual char* plugin_title(); // return the title of the plugin
231 virtual VFrame* new_picon();
232 virtual Theme* new_theme();
239 // Non realtime signal processors define these.
240 virtual int get_samplerate(); // give the samplerate of the output for a non realtime plugin
241 virtual double get_framerate(); // give the framerate of the output for a non realtime plugin
242 virtual int delete_nonrealtime_parameters();
243 virtual int start_plugin(); // run a non realtime plugin
244 virtual int get_parameters(); // get information from user before non realtime processing
245 virtual int64_t get_in_buffers(int64_t recommended_size); // return desired size for input buffers
246 virtual int64_t get_out_buffers(int64_t recommended_size); // return desired size for output buffers
247 virtual int start_loop();
248 virtual int process_loop();
249 virtual int stop_loop();
254 // Realtime commands for signal processors.
255 // These must be defined by the plugin itself.
256 virtual int set_string(); // Set the string identifying the plugin to modules and patches.
257 // cause the plugin to show the gui
258 virtual int show_gui();
259 // cause the plugin to hide the gui
260 void client_side_close();
261 void update_display_title();
262 // Raise the GUI
263 virtual void raise_window() {};
264 virtual void update_gui() {};
265 virtual void save_data(KeyFrame *keyframe) {}; // write the plugin settings to text in text format
266 virtual void read_data(KeyFrame *keyframe) {}; // read the plugin settings from the text
267 int send_hide_gui(); // should be sent when the GUI recieves a close event from the user
268 int send_configure_change(); // when this plugin is adjusted, propogate parameters to virtual plugins
270 int get_configure_change(); // get propogated configuration change from a send_configure_change
271 virtual void plugin_process_realtime(double **input,
272 double **output,
273 int64_t current_position,
274 int64_t fragment_size,
275 int64_t total_len) {};
276 virtual void plugin_process_realtime(VFrame **input,
277 VFrame **output,
278 int64_t current_position,
279 int64_t total_len) {};
280 // Called by plugin server to update GUI with rendered data.
281 virtual void plugin_render_gui(void *data) {};
282 virtual void plugin_render_gui(void *data, int size) {};
283 virtual int plugin_process_loop(VFrame **buffers, int64_t &write_length) { return 1; };
284 virtual int plugin_process_loop(double **buffers, int64_t &write_length) { return 1; };
285 virtual int init_realtime_parameters(); // get parameters depending on video or audio
286 int get_gui_status();
287 char* get_gui_string();
289 // Used by themes
290 // Used by plugins which need to know where they are.
291 char* get_path();
293 // Return keyframe objects. If position -1 use edl selection
294 KeyFrame* get_prev_keyframe(int64_t position);
295 KeyFrame* get_next_keyframe(int64_t position);
297 // The meaning of these changes depending on the plugin type.
299 // For transitions the source_len is the length of the transition and
300 // is calculated in *Module.
302 // For realtime plugins the source_len is 0 and is calculated in
303 // *AttachmentPoint. This may not be used at all.
304 int64_t get_source_len();
306 // For realtime plugins gets the start of the plugin
307 int64_t get_source_start();
309 // Length of source. For effects it's the plugin length. For transitions
310 // it's the transition length.
311 int64_t get_total_len();
313 // For transitions the source_position is the playback position relative
314 // to the start of the transition.
316 // For plugins the source_position is relative to the start of the plugin.
317 int64_t get_source_position();
319 // Get interpolation used by EDL
320 int get_interpolation_type();
322 // If automation is used
323 int automation_used();
324 // Get the automation value for the position in the current fragment
325 // The position is relative to the current fragment
326 float get_automation_value(int64_t position);
331 // Operations for file handlers
332 virtual int open_file() { return 0; };
333 virtual int get_audio_parameters() { return 0; };
334 virtual int get_video_parameters() { return 0; };
335 virtual int check_header(char *path) { return 0; };
336 virtual int open_file(char *path, int wr, int rd) { return 1; };
337 virtual int close_file() { return 0; };
343 // All plugins define these.
344 virtual int load_defaults(); // load default settings for the plugin
345 virtual int save_defaults(); // save the current settings as defaults
350 // Non realtime operations for signal processors.
351 int plugin_start_loop(int64_t start, int64_t end, int64_t buffer_size, int total_buffers);
352 int plugin_stop_loop();
353 int plugin_process_loop();
354 MainProgressBar* start_progress(char *string, int64_t length);
355 // get samplerate of project data before processing
356 int get_project_samplerate();
357 // get framerate of project data before processing
358 double get_project_framerate();
359 int get_project_smp();
360 int get_aspect_ratio(float &aspect_w, float &aspect_h);
361 int write_frames(int64_t total_frames); // returns 1 for failure / tells the server that all output channel buffers are ready to go
362 int write_samples(int64_t total_samples); // returns 1 for failure / tells the server that all output channel buffers are ready to go
363 int plugin_get_parameters();
364 char* get_defaultdir(); // Directory defaults should be stored in
365 void set_interactive();
367 // Realtime operations.
368 int plugin_init(int argc, char *argv[]);
369 int reset();
370 virtual int plugin_command_derived(int plugin_command) {}; // Extension of plugin_run for derived plugins
371 int plugin_get_range();
372 int plugin_start_plugin(); // Run a non realtime plugin
373 int plugin_init_realtime(int realtime_priority,
374 int total_in_buffers,
375 int buffer_size);
379 // create pointers to buffers of the plugin's type before realtime rendering
380 virtual int delete_buffer_ptrs();
385 // communication convenience routines for the base class
386 int stop_gui_client();
387 int save_data_client();
388 int load_data_client();
389 int set_string_client(char *string); // set the string identifying the plugin
390 int send_completed(); // send when finished
391 int send_cancelled(); // non realtime plugin sends when cancelled
393 // ================================= Buffers ===============================
395 // number of double buffers for each channel
396 ArrayList<int> double_buffers_in;
397 ArrayList<int> double_buffers_out;
398 // When arming buffers need to know the offsets in all the buffers and which
399 // double buffers for each channel before rendering.
400 ArrayList<int64_t> offset_in_render;
401 ArrayList<int64_t> offset_out_render;
402 ArrayList<int64_t> double_buffer_in_render;
403 ArrayList<int64_t> double_buffer_out_render;
404 // total size of each buffer depends on if it's a master or node
405 ArrayList<int64_t> realtime_in_size;
406 ArrayList<int64_t> realtime_out_size;
408 // ================================= Automation ===========================
410 ArrayList<PluginClientAuto> automation;
412 // ================================== Messages ===========================
413 Messages *messages, *gui_messages;
414 Sema *message_lock; // only used for realtime plugins
415 char gui_string[1024]; // string identifying module and plugin
416 int master_gui_on; // Status of the master gui plugin
417 int client_gui_on; // Status of this client's gui
419 int show_initially; // set to show a realtime plugin initially
420 // range in project for processing
421 int64_t start, end;
422 int interactive; // for the progress bar plugin
423 int success;
424 int total_out_buffers; // total send buffers allocated by the server
425 int total_in_buffers; // total recieve buffers allocated by the server
426 int wr, rd; // File permissions for fileio plugins.
428 // These give the largest fragment the plugin is expected to handle.
429 // size of a send buffer to the server
430 int64_t out_buffer_size;
431 // size of a recieve buffer from the server
432 int64_t in_buffer_size;
433 // Local parameters of plugin
434 int sample_rate;
435 double frame_rate;
436 // Operating system scheduling
437 int realtime_priority;
439 // For transient plugins.
440 int64_t source_len;
441 int64_t source_position;
442 int64_t total_len;
443 // Total number of processors available
444 int smp;
445 PluginServer *server;
447 private:
449 // File handlers:
450 // Asset *asset; // Point to asset structure in shared memory
454 #endif