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 if(result) plugin->client_side_close(); \
97 #define PLUGIN_CLASS_MEMBERS(config_name, thread_name) \
98 int load_configuration(); \
99 VFrame* new_picon(); \
100 char* plugin_title(); \
103 void raise_window(); \
104 Defaults *defaults; \
105 config_name config; \
108 #define PLUGIN_CONSTRUCTOR_MACRO \
113 #define PLUGIN_DESTRUCTOR_MACRO \
116 thread->window->set_done(0); \
119 if(defaults) save_defaults(); \
120 if(defaults) delete defaults;
125 #define SHOW_GUI_MACRO(plugin_class, thread_class) \
126 int plugin_class::show_gui() \
128 load_configuration(); \
129 thread_class *new_thread = new thread_class(this); \
130 new_thread->start(); \
134 #define RAISE_WINDOW_MACRO(plugin_class) \
135 void plugin_class::raise_window() \
139 thread->window->lock_window(); \
140 thread->window->raise_window(); \
141 thread->window->flush(); \
142 thread->window->unlock_window(); \
146 #define SET_STRING_MACRO(plugin_class) \
147 int plugin_class::set_string() \
151 thread->window->lock_window(); \
152 thread->window->set_title(gui_string); \
153 thread->window->unlock_window(); \
158 #define NEW_PICON_MACRO(plugin_class) \
159 VFrame* plugin_class::new_picon() \
161 return new VFrame(picon_png); \
164 #define LOAD_CONFIGURATION_MACRO(plugin_class, config_class) \
165 int plugin_class::load_configuration() \
167 KeyFrame *prev_keyframe, *next_keyframe; \
168 prev_keyframe = get_prev_keyframe(get_source_position()); \
169 next_keyframe = get_next_keyframe(get_source_position()); \
171 config_class old_config, prev_config, next_config; \
172 old_config.copy_from(config); \
173 read_data(prev_keyframe); \
174 prev_config.copy_from(config); \
175 read_data(next_keyframe); \
176 next_config.copy_from(config); \
177 config.interpolate(prev_config, \
179 (next_keyframe->position == prev_keyframe->position) ? \
180 get_source_position() : \
181 prev_keyframe->position, \
182 (next_keyframe->position == prev_keyframe->position) ? \
183 get_source_position() + 1 : \
184 next_keyframe->position, \
185 get_source_position()); \
187 if(!config.equivalent(old_config)) \
201 PluginClient(PluginServer
*server
);
202 virtual ~PluginClient();
205 // Queries for the plugin server.
206 virtual int is_realtime();
207 virtual int is_audio();
208 virtual int is_video();
209 virtual int is_fileio();
210 virtual int is_theme();
211 virtual int uses_gui();
212 virtual int is_multichannel();
213 virtual int is_synthesis();
214 virtual int is_transition();
215 virtual char* plugin_title(); // return the title of the plugin
216 virtual VFrame
* new_picon();
217 virtual Theme
* new_theme();
224 // Non realtime signal processors define these.
225 virtual int get_samplerate(); // give the samplerate of the output for a non realtime plugin
226 virtual double get_framerate(); // give the framerate of the output for a non realtime plugin
227 virtual int delete_nonrealtime_parameters();
228 virtual int start_plugin(); // run a non realtime plugin
229 virtual int get_parameters(); // get information from user before non realtime processing
230 virtual int64_t get_in_buffers(int64_t recommended_size
); // return desired size for input buffers
231 virtual int64_t get_out_buffers(int64_t recommended_size
); // return desired size for output buffers
232 virtual int start_loop();
233 virtual int process_loop();
234 virtual int stop_loop();
239 // Realtime commands for signal processors.
240 // These must be defined by the plugin itself.
241 virtual int set_string(); // Set the string identifying the plugin to modules and patches.
242 // cause the plugin to show the gui
243 virtual int show_gui();
244 // cause the plugin to hide the gui
245 void client_side_close();
246 void update_display_title();
248 virtual void raise_window() {};
249 virtual void update_gui() {};
250 virtual void save_data(KeyFrame
*keyframe
) {}; // write the plugin settings to text in text format
251 virtual void read_data(KeyFrame
*keyframe
) {}; // read the plugin settings from the text
252 int send_hide_gui(); // should be sent when the GUI recieves a close event from the user
253 int send_configure_change(); // when this plugin is adjusted, propogate parameters to virtual plugins
255 int get_configure_change(); // get propogated configuration change from a send_configure_change
256 virtual void plugin_process_realtime(double **input
,
258 int64_t current_position
,
259 int64_t fragment_size
,
260 int64_t total_len
) {};
261 virtual void plugin_process_realtime(VFrame
**input
,
263 int64_t current_position
,
264 int64_t total_len
) {};
265 // Called by plugin server to update GUI with rendered data.
266 virtual void plugin_render_gui(void *data
) {};
267 virtual void plugin_render_gui(void *data
, int size
) {};
268 virtual int plugin_process_loop(VFrame
**buffers
, int64_t &write_length
) { return 1; };
269 virtual int plugin_process_loop(double **buffers
, int64_t &write_length
) { return 1; };
270 virtual int init_realtime_parameters(); // get parameters depending on video or audio
271 int get_gui_status();
272 char* get_gui_string();
275 // Used by plugins which need to know where they are.
278 // Return keyframe objects. If position -1 use edl selection
279 KeyFrame
* get_prev_keyframe(int64_t position
);
280 KeyFrame
* get_next_keyframe(int64_t position
);
282 // The meaning of these changes depending on the plugin type.
284 // For transitions the source_len is the length of the transition and
285 // is calculated in *Module.
287 // For realtime plugins the source_len is 0 and is calculated in
288 // *AttachmentPoint. This may not be used at all.
289 int64_t get_source_len();
291 // For realtime plugins gets the start of the plugin
292 int64_t get_source_start();
294 // Length of source. For effects it's the plugin length. For transitions
295 // it's the transition length.
296 int64_t get_total_len();
298 // For transitions the source_position is the playback position relative
299 // to the start of the transition.
301 // For plugins the source_position is relative to the start of the plugin.
302 int64_t get_source_position();
304 // Get interpolation used by EDL
305 int get_interpolation_type();
307 // If automation is used
308 int automation_used();
309 // Get the automation value for the position in the current fragment
310 // The position is relative to the current fragment
311 float get_automation_value(int64_t position
);
316 // Operations for file handlers
317 virtual int open_file() { return 0; };
318 virtual int get_audio_parameters() { return 0; };
319 virtual int get_video_parameters() { return 0; };
320 virtual int check_header(char *path
) { return 0; };
321 virtual int open_file(char *path
, int wr
, int rd
) { return 1; };
322 virtual int close_file() { return 0; };
328 // All plugins define these.
329 virtual int load_defaults(); // load default settings for the plugin
330 virtual int save_defaults(); // save the current settings as defaults
335 // Non realtime operations for signal processors.
336 int plugin_start_loop(int64_t start
, int64_t end
, int64_t buffer_size
, int total_buffers
);
337 int plugin_stop_loop();
338 int plugin_process_loop();
339 MainProgressBar
* start_progress(char *string
, int64_t length
);
340 // get samplerate of project data before processing
341 int get_project_samplerate();
342 // get framerate of project data before processing
343 double get_project_framerate();
344 int get_project_smp();
345 int get_aspect_ratio(float &aspect_w
, float &aspect_h
);
346 int write_frames(int64_t total_frames
); // returns 1 for failure / tells the server that all output channel buffers are ready to go
347 int write_samples(int64_t total_samples
); // returns 1 for failure / tells the server that all output channel buffers are ready to go
348 int plugin_get_parameters();
349 char* get_defaultdir(); // Directory defaults should be stored in
350 void set_interactive();
352 // Realtime operations.
354 virtual int plugin_command_derived(int plugin_command
) {}; // Extension of plugin_run for derived plugins
355 int plugin_get_range();
356 int plugin_init_realtime(int realtime_priority
,
357 int total_in_buffers
,
362 // create pointers to buffers of the plugin's type before realtime rendering
363 virtual int delete_buffer_ptrs();
368 // communication convenience routines for the base class
369 int stop_gui_client();
370 int save_data_client();
371 int load_data_client();
372 int set_string_client(char *string
); // set the string identifying the plugin
373 int send_cancelled(); // non realtime plugin sends when cancelled
375 // ================================= Buffers ===============================
377 // number of double buffers for each channel
378 ArrayList
<int> double_buffers_in
;
379 ArrayList
<int> double_buffers_out
;
380 // When arming buffers need to know the offsets in all the buffers and which
381 // double buffers for each channel before rendering.
382 ArrayList
<int64_t> offset_in_render
;
383 ArrayList
<int64_t> offset_out_render
;
384 ArrayList
<int64_t> double_buffer_in_render
;
385 ArrayList
<int64_t> double_buffer_out_render
;
386 // total size of each buffer depends on if it's a master or node
387 ArrayList
<int64_t> realtime_in_size
;
388 ArrayList
<int64_t> realtime_out_size
;
390 // ================================= Automation ===========================
392 ArrayList
<PluginClientAuto
> automation
;
394 // ================================== Messages ===========================
395 char gui_string
[1024]; // string identifying module and plugin
396 int master_gui_on
; // Status of the master gui plugin
397 int client_gui_on
; // Status of this client's gui
399 int show_initially
; // set to show a realtime plugin initially
400 // range in project for processing
402 int interactive
; // for the progress bar plugin
404 int total_out_buffers
; // total send buffers allocated by the server
405 int total_in_buffers
; // total recieve buffers allocated by the server
406 int wr
, rd
; // File permissions for fileio plugins.
408 // These give the largest fragment the plugin is expected to handle.
409 // size of a send buffer to the server
410 int64_t out_buffer_size
;
411 // size of a recieve buffer from the server
412 int64_t in_buffer_size
;
413 // Local parameters of plugin
416 // Operating system scheduling
417 int realtime_priority
;
419 // For transient plugins.
421 int64_t source_position
;
423 // Total number of processors available - 1
425 PluginServer
*server
;
430 // Asset *asset; // Point to asset structure in shared memory