00001 #ifndef PLUGINCLIENT_H
00002 #define PLUGINCLIENT_H
00003
00004
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
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 \
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 \
00091 plugin->thread = this; \
00092 int result = window->run_window(); \
00093 completion->unlock(); \
00094 \
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 \
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
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();
00230 virtual VFrame* new_picon();
00231 virtual Theme* new_theme();
00232
00233 Theme* get_theme();
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 virtual int get_samplerate();
00244
00245
00246 virtual double get_framerate();
00247 virtual int delete_nonrealtime_parameters();
00248 virtual int start_plugin();
00249 virtual int get_parameters();
00250 virtual int64_t get_in_buffers(int64_t recommended_size);
00251 virtual int64_t get_out_buffers(int64_t recommended_size);
00252 virtual int start_loop();
00253 virtual int process_loop();
00254 virtual int stop_loop();
00255
00256
00257
00258
00259
00260
00261 virtual int set_string();
00262
00263 virtual int show_gui();
00264
00265 void client_side_close();
00266 void update_display_title();
00267
00268 virtual void raise_window() {};
00269 virtual void update_gui() {};
00270 virtual void save_data(KeyFrame *keyframe) {};
00271 virtual void read_data(KeyFrame *keyframe) {};
00272 int send_hide_gui();
00273
00274 int get_configure_change();
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
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();
00294 int get_gui_status();
00295 char* get_gui_string();
00296
00297
00298
00299 char* get_path();
00300
00301
00302
00303
00304
00305
00306
00307
00308
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
00312
00313
00314 int send_configure_change();
00315
00316
00317
00318
00319
00320
00321
00322 int64_t get_total_len();
00323
00324
00325
00326 int64_t get_source_start();
00327
00328
00329
00330
00331 virtual int64_t local_to_edl(int64_t position);
00332
00333
00334 virtual int64_t edl_to_local(int64_t position);
00335
00336
00337
00338
00339
00340
00341 int64_t get_source_position();
00342
00343
00344
00345
00346
00347 int get_direction();
00348
00349
00350 int get_total_buffers();
00351
00352
00353 int get_buffer_size();
00354
00355
00356 int get_interpolation_type();
00357
00358
00359 float get_red();
00360 float get_green();
00361 float get_blue();
00362
00363
00364
00365
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
00378 virtual int load_defaults();
00379 virtual int save_defaults();
00380
00381
00382
00383
00384
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
00393 int get_project_samplerate();
00394
00395 double get_project_framerate();
00396
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);
00402 int write_samples(int64_t total_samples);
00403 virtual int plugin_get_parameters();
00404 char* get_defaultdir();
00405 void set_interactive();
00406
00407
00408 int reset();
00409 virtual int plugin_command_derived(int plugin_command) {};
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
00418 virtual int delete_buffer_ptrs();
00419
00420
00421
00422
00423
00424 int stop_gui_client();
00425 int save_data_client();
00426 int load_data_client();
00427 int set_string_client(char *string);
00428 int send_cancelled();
00429
00430
00431
00432
00433 ArrayList<int> double_buffers_in;
00434 ArrayList<int> double_buffers_out;
00435
00436
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
00442 ArrayList<int64_t> realtime_in_size;
00443 ArrayList<int64_t> realtime_out_size;
00444
00445
00446
00447 ArrayList<PluginClientAuto> automation;
00448
00449
00450 char gui_string[BCTEXTLEN];
00451 int master_gui_on;
00452 int client_gui_on;
00453
00454 int show_initially;
00455
00456 int64_t start, end;
00457 int interactive;
00458 int success;
00459 int total_out_buffers;
00460 int total_in_buffers;
00461 int wr, rd;
00462
00463
00464
00465 int64_t out_buffer_size;
00466
00467 int64_t in_buffer_size;
00468
00469
00470
00471
00472
00473 int direction;
00474
00475
00476 int realtime_priority;
00477
00478
00479
00480 int64_t source_position;
00481
00482
00483 int64_t source_start;
00484
00485
00486 int64_t total_len;
00487
00488 int smp;
00489 PluginServer *server;
00490
00491 private:
00492
00493
00494
00495 };
00496
00497
00498 #endif