Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

pluginclient.h

Go to the documentation of this file.
00001 #ifndef PLUGINCLIENT_H
00002 #define PLUGINCLIENT_H
00003 
00004 // Base class inherited by all the different types of plugins.
00005 
00006 #define BCASTDIR "~/.bcast/"
00007 
00008 class PluginClient;
00009 
00010 
00011 #include "arraylist.h"
00012 #include "condition.h"
00013 #include "keyframe.h"
00014 #include "mainprogress.inc"
00015 #include "maxbuffers.h"
00016 #include "plugincommands.h"
00017 #include "pluginserver.inc"
00018 #include "theme.inc"
00019 #include "vframe.h"
00020 
00021 
00022 extern "C"
00023 {
00024 extern PluginClient* new_plugin(PluginServer *server);
00025 }
00026 
00027 class PluginClientAuto
00028 {
00029 public:
00030         float position;
00031         float intercept;
00032         float slope;
00033 };
00034 
00035 
00036 
00037 
00038 // Convenience functions
00039 
00040 #define REGISTER_PLUGIN(class_title) \
00041 PluginClient* new_plugin(PluginServer *server) \
00042 { \
00043         return new class_title(server); \
00044 }
00045 
00046 
00047 #define WINDOW_CLOSE_EVENT(window_class) \
00048 int window_class::close_event() \
00049 { \
00050 /* Set result to 1 to indicate a client side close */ \
00051         set_done(1); \
00052         return 1; \
00053 }
00054 
00055 
00056 #define PLUGIN_THREAD_HEADER(plugin_class, thread_class, window_class) \
00057 class thread_class : public Thread \
00058 { \
00059 public: \
00060         thread_class(plugin_class *plugin); \
00061         ~thread_class(); \
00062         void run(); \
00063         window_class *window; \
00064         plugin_class *plugin; \
00065         Condition *completion; \
00066 };
00067 
00068 
00069 #define PLUGIN_THREAD_OBJECT(plugin_class, thread_class, window_class) \
00070 thread_class::thread_class(plugin_class *plugin) \
00071  : Thread(0, 0, 0) \
00072 { \
00073         this->plugin = plugin; \
00074         completion = new Condition(0, "thread_class::completion"); \
00075 } \
00076  \
00077 thread_class::~thread_class() \
00078 { \
00079         delete window; \
00080 } \
00081  \
00082 void thread_class::run() \
00083 { \
00084         BC_DisplayInfo info; \
00085         window = new window_class(plugin,  \
00086                 info.get_abs_cursor_x() - 75,  \
00087                 info.get_abs_cursor_y() - 65); \
00088         window->create_objects(); \
00089  \
00090 /* Only set it here so tracking doesn't update it until everything is created. */ \
00091         plugin->thread = this; \
00092         int result = window->run_window(); \
00093         completion->unlock(); \
00094 /* This is needed when the GUI is closed from itself */ \
00095         if(result) plugin->client_side_close(); \
00096 }
00097 
00098 
00099 
00100 
00101 #define PLUGIN_CLASS_MEMBERS(config_name, thread_name) \
00102         int load_configuration(); \
00103         VFrame* new_picon(); \
00104         char* plugin_title(); \
00105         int show_gui(); \
00106         int set_string(); \
00107         void raise_window(); \
00108         Defaults *defaults; \
00109         config_name config; \
00110         thread_name *thread;
00111 
00112 #define PLUGIN_CONSTRUCTOR_MACRO \
00113         thread = 0; \
00114         defaults = 0; \
00115         load_defaults(); \
00116 
00117 #define PLUGIN_DESTRUCTOR_MACRO \
00118         if(thread) \
00119         { \
00120 /* This is needed when the GUI is closed from elsewhere than itself */ \
00121                 thread->window->lock_window("PLUGIN_DESTRUCTOR_MACRO"); \
00122                 thread->window->set_done(0); \
00123                 thread->window->unlock_window(); \
00124                 thread->completion->lock("PLUGIN_DESTRUCTOR_MACRO"); \
00125                 delete thread; \
00126         } \
00127  \
00128  \
00129         if(defaults) save_defaults(); \
00130         if(defaults) delete defaults;
00131 
00132 
00133 
00134 
00135 #define SHOW_GUI_MACRO(plugin_class, thread_class) \
00136 int plugin_class::show_gui() \
00137 { \
00138         load_configuration(); \
00139         thread_class *new_thread = new thread_class(this); \
00140         new_thread->start(); \
00141         return 0; \
00142 }
00143 
00144 #define RAISE_WINDOW_MACRO(plugin_class) \
00145 void plugin_class::raise_window() \
00146 { \
00147         if(thread) \
00148         { \
00149                 thread->window->lock_window(); \
00150                 thread->window->raise_window(); \
00151                 thread->window->flush(); \
00152                 thread->window->unlock_window(); \
00153         } \
00154 }
00155 
00156 #define SET_STRING_MACRO(plugin_class) \
00157 int plugin_class::set_string() \
00158 { \
00159         if(thread) \
00160         { \
00161                 thread->window->lock_window(); \
00162                 thread->window->set_title(gui_string); \
00163                 thread->window->unlock_window(); \
00164         } \
00165         return 0; \
00166 }
00167 
00168 #define NEW_PICON_MACRO(plugin_class) \
00169 VFrame* plugin_class::new_picon() \
00170 { \
00171         return new VFrame(picon_png); \
00172 }
00173 
00174 #define LOAD_CONFIGURATION_MACRO(plugin_class, config_class) \
00175 int plugin_class::load_configuration() \
00176 { \
00177         KeyFrame *prev_keyframe, *next_keyframe; \
00178         prev_keyframe = get_prev_keyframe(get_source_position()); \
00179         next_keyframe = get_next_keyframe(get_source_position()); \
00180  \
00181         int64_t next_position = edl_to_local(next_keyframe->position); \
00182         int64_t prev_position = edl_to_local(prev_keyframe->position); \
00183  \
00184         config_class old_config, prev_config, next_config; \
00185         old_config.copy_from(config); \
00186         read_data(prev_keyframe); \
00187         prev_config.copy_from(config); \
00188         read_data(next_keyframe); \
00189         next_config.copy_from(config); \
00190  \
00191         config.interpolate(prev_config,  \
00192                 next_config,  \
00193                 (next_position == prev_position) ? \
00194                         get_source_position() : \
00195                         prev_position, \
00196                 (next_position == prev_position) ? \
00197                         get_source_position() + 1 : \
00198                         next_position, \
00199                 get_source_position()); \
00200  \
00201         if(!config.equivalent(old_config)) \
00202                 return 1; \
00203         else \
00204                 return 0; \
00205 }
00206 
00207 
00208 
00209 
00210 
00211 
00212 class PluginClient
00213 {
00214 public:
00215         PluginClient(PluginServer *server);
00216         virtual ~PluginClient();
00217 
00218         
00219 // Queries for the plugin server.
00220         virtual int is_realtime();
00221         virtual int is_audio();
00222         virtual int is_video();
00223         virtual int is_fileio();
00224         virtual int is_theme();
00225         virtual int uses_gui();
00226         virtual int is_multichannel();
00227         virtual int is_synthesis();
00228         virtual int is_transition();
00229         virtual char* plugin_title();   // return the title of the plugin
00230         virtual VFrame* new_picon();
00231         virtual Theme* new_theme();
00232 // Get theme being used by Cinelerra currently.  Used by all plugins.
00233         Theme* get_theme();
00234 
00235 
00236 
00237 
00238 
00239 
00240 // Non realtime signal processors define these.
00241 // Give the samplerate of the output for a non realtime plugin.
00242 // For realtime plugins give the requested samplerate.
00243         virtual int get_samplerate();
00244 // Give the framerate of the output for a non realtime plugin.
00245 // For realtime plugins give the requested framerate.
00246         virtual double get_framerate();
00247         virtual int delete_nonrealtime_parameters();
00248         virtual int start_plugin();         // run a non realtime plugin
00249         virtual int get_parameters();     // get information from user before non realtime processing
00250         virtual int64_t get_in_buffers(int64_t recommended_size);  // return desired size for input buffers
00251         virtual int64_t get_out_buffers(int64_t recommended_size);     // return desired size for output buffers
00252         virtual int start_loop();
00253         virtual int process_loop();
00254         virtual int stop_loop();
00255 
00256 
00257 
00258 
00259 // Realtime commands for signal processors.
00260 // These must be defined by the plugin itself.
00261         virtual int set_string();             // Set the string identifying the plugin to modules and patches.
00262 // cause the plugin to show the gui
00263         virtual int show_gui();               
00264 // cause the plugin to hide the gui
00265         void client_side_close();
00266         void update_display_title();
00267 // Raise the GUI
00268         virtual void raise_window() {};
00269         virtual void update_gui() {};
00270         virtual void save_data(KeyFrame *keyframe) {};    // write the plugin settings to text in text format
00271         virtual void read_data(KeyFrame *keyframe) {};    // read the plugin settings from the text
00272         int send_hide_gui();                                    // should be sent when the GUI recieves a close event from the user
00273 
00274         int get_configure_change();                             // get propogated configuration change from a send_configure_change
00275 
00276 // Replaced by pull method
00277 /*
00278  *      virtual void plugin_process_realtime(double **input, 
00279  *              double **output, 
00280  *              int64_t current_position, 
00281  *              int64_t fragment_size,
00282  *              int64_t total_len) {};
00283  *      virtual void plugin_process_realtime(VFrame **input, 
00284  *              VFrame **output, 
00285  *              int64_t current_position,
00286  *              int64_t total_len) {};
00287  */
00288 // Called by plugin server to update GUI with rendered data.
00289         virtual void plugin_render_gui(void *data) {};
00290         virtual void plugin_render_gui(void *data, int size) {};
00291         virtual int plugin_process_loop(VFrame **buffers, int64_t &write_length) { return 1; };
00292         virtual int plugin_process_loop(double **buffers, int64_t &write_length) { return 1; };
00293         virtual int init_realtime_parameters();     // get parameters depending on video or audio
00294         int get_gui_status();
00295         char* get_gui_string();
00296 
00297 // Used by themes
00298 // Used by plugins which need to know where they are.
00299         char* get_path();
00300 
00301 // Return keyframe objects.  The position in the resulting object 
00302 // is relative to the EDL rate.  This is the only way to avoid copying the
00303 // data for every frame.
00304 // If the result is the default keyframe, the keyframe's position is 0.
00305 // position - relative to EDL rate or local rate to allow simple 
00306 //     passing of get_source_position.
00307 //     If -1 the tracking position in the edl is used.
00308 // is_local - if 1, the position is converted to the EDL rate.
00309         KeyFrame* get_prev_keyframe(int64_t position, int is_local = 1);
00310         KeyFrame* get_next_keyframe(int64_t position, int is_local = 1);
00311 // When this plugin is adjusted, propogate parameters back to EDL and virtual
00312 // console.  This gets a keyframe from the EDL, with the position set to the
00313 // EDL tracking position.
00314         int send_configure_change();                            
00315 
00316 
00317 
00318 // Length of source.  For effects it's the plugin length.  For transitions
00319 // it's the transition length.  Relative to the requested rate.
00320 // The only way to get smooth interpolation is to make all position queries
00321 // relative to the requested rate.
00322         int64_t get_total_len();
00323 
00324 // For realtime plugins gets the lowest sample of the plugin in the requested
00325 // rate.  For others it's the start of the EDL selection in the EDL rate.
00326         int64_t get_source_start();
00327 
00328 // Convert the position relative to the requested rate to the position 
00329 // relative to the EDL rate.  If the argument is < 0, it is not changed.
00330 // Used for interpreting keyframes.
00331         virtual int64_t local_to_edl(int64_t position);
00332 
00333 // Convert the EDL position to the local position.
00334         virtual int64_t edl_to_local(int64_t position);
00335 
00336 // For transitions the source_position is the playback position relative
00337 // to the start of the transition.
00338 // For realtime effects, the start of the most recent process_buffer in forward
00339 // and the end of the range to process in reverse.  Relative to start of EDL in
00340 // the requested rate.
00341         int64_t get_source_position();
00342 
00343 
00344 
00345 
00346 // Get the direction of the most recent process_buffer
00347         int get_direction();
00348 
00349 // Get total tracks to process
00350         int get_total_buffers();
00351 
00352 // Get size of buffer to fill in non-realtime plugin
00353         int get_buffer_size();
00354 
00355 // Get interpolation used by EDL from overlayframe.inc
00356         int get_interpolation_type();
00357 
00358 // Get the values from the color picker
00359         float get_red();
00360         float get_green();
00361         float get_blue();
00362 
00363 
00364 
00365 // Operations for file handlers
00366         virtual int open_file() { return 0; };
00367         virtual int get_audio_parameters() { return 0; };
00368         virtual int get_video_parameters() { return 0; };
00369         virtual int check_header(char *path) { return 0; };
00370         virtual int open_file(char *path, int wr, int rd) { return 1; };
00371         virtual int close_file() { return 0; };
00372 
00373 
00374 
00375 
00376 
00377 // All plugins define these.
00378         virtual int load_defaults();       // load default settings for the plugin
00379         virtual int save_defaults();      // save the current settings as defaults
00380 
00381 
00382 
00383 
00384 // Non realtime operations for signal processors.
00385         virtual int plugin_start_loop(int64_t start, 
00386                 int64_t end, 
00387                 int64_t buffer_size, 
00388                 int total_buffers);
00389         int plugin_stop_loop();
00390         int plugin_process_loop();
00391         MainProgressBar* start_progress(char *string, int64_t length);
00392 // get samplerate of EDL
00393         int get_project_samplerate();
00394 // get framerate of EDL
00395         double get_project_framerate();
00396 // Total number of processors - 1
00397         int get_project_smp();
00398         int get_aspect_ratio(float &aspect_w, float &aspect_h);
00399 
00400 
00401         int write_frames(int64_t total_frames);  // returns 1 for failure / tells the server that all output channel buffers are ready to go
00402         int write_samples(int64_t total_samples);  // returns 1 for failure / tells the server that all output channel buffers are ready to go
00403         virtual int plugin_get_parameters();
00404         char* get_defaultdir();     // Directory defaults should be stored in
00405         void set_interactive();
00406 
00407 // Realtime operations.
00408         int reset();
00409         virtual int plugin_command_derived(int plugin_command) {}; // Extension of plugin_run for derived plugins
00410         int plugin_get_range();
00411         int plugin_init_realtime(int realtime_priority, 
00412                 int total_in_buffers,
00413                 int buffer_size);
00414 
00415 
00416 
00417 // create pointers to buffers of the plugin's type before realtime rendering
00418         virtual int delete_buffer_ptrs();
00419 
00420 
00421 
00422 
00423 // communication convenience routines for the base class
00424         int stop_gui_client();     
00425         int save_data_client();
00426         int load_data_client();
00427         int set_string_client(char *string);                // set the string identifying the plugin
00428         int send_cancelled();        // non realtime plugin sends when cancelled
00429 
00430 // ================================= Buffers ===============================
00431 
00432 // number of double buffers for each channel
00433         ArrayList<int> double_buffers_in;    
00434         ArrayList<int> double_buffers_out;
00435 // When arming buffers need to know the offsets in all the buffers and which
00436 // double buffers for each channel before rendering.
00437         ArrayList<int64_t> offset_in_render;
00438         ArrayList<int64_t> offset_out_render;
00439         ArrayList<int64_t> double_buffer_in_render;
00440         ArrayList<int64_t> double_buffer_out_render;
00441 // total size of each buffer depends on if it's a master or node
00442         ArrayList<int64_t> realtime_in_size;
00443         ArrayList<int64_t> realtime_out_size;
00444 
00445 // ================================= Automation ===========================
00446 
00447         ArrayList<PluginClientAuto> automation;
00448 
00449 // ================================== Messages ===========================
00450         char gui_string[BCTEXTLEN];          // string identifying module and plugin
00451         int master_gui_on;              // Status of the master gui plugin
00452         int client_gui_on;              // Status of this client's gui
00453 
00454         int show_initially;             // set to show a realtime plugin initially
00455 // range in project for processing
00456         int64_t start, end;                
00457         int interactive;                // for the progress bar plugin
00458         int success;
00459         int total_out_buffers;          // total send buffers allocated by the server
00460         int total_in_buffers;           // total recieve buffers allocated by the server
00461         int wr, rd;                     // File permissions for fileio plugins.
00462 
00463 // These give the largest fragment the plugin is expected to handle.
00464 // size of a send buffer to the server
00465         int64_t out_buffer_size;  
00466 // size of a recieve buffer from the server
00467         int64_t in_buffer_size;   
00468 
00469 
00470 
00471 
00472 // Direction of most recent process_buffer
00473         int direction;
00474 
00475 // Operating system scheduling
00476         int realtime_priority;
00477 
00478 // Position relative to start of EDL in requested rate.  Calculated for every process
00479 // command.  Used for keyframes.
00480         int64_t source_position;
00481 // For realtime plugins gets the lowest sample of the plugin in the requested
00482 // rate.  For others it's always 0.
00483         int64_t source_start;
00484 // Length of source.  For effects it's the plugin length.  For transitions
00485 // it's the transition length.  Relative to the requested rate.
00486         int64_t total_len;
00487 // Total number of processors available - 1
00488         int smp;  
00489         PluginServer *server;
00490 
00491 private:
00492 
00493 // File handlers:
00494 //      Asset *asset;     // Point to asset structure in shared memory
00495 };
00496 
00497 
00498 #endif

Generated on Sun Jan 8 13:38:58 2006 for Cinelerra-svn by  doxygen 1.4.4