4 * Copyright (C) 2009 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "attachmentpoint.h"
26 #include "bcsignals.h"
27 #include "cplayback.h"
31 #include "edlsession.h"
33 #include "floatautos.h"
34 #include "keyframes.h"
35 #include "localsession.h"
36 #include "mainerror.h"
37 #include "mainprogress.h"
38 #include "menueffects.h"
40 #include "mwindowgui.h"
41 #include "playbackengine.h"
43 #include "pluginaclient.h"
44 #include "pluginaclientlad.h"
45 #include "pluginfclient.h"
46 #include "pluginclient.h"
47 #include "plugincommands.h"
48 #include "pluginserver.h"
49 #include "pluginvclient.h"
50 #include "preferences.h"
53 #include "mainsession.h"
55 #include "trackcanvas.h"
56 #include "transportque.h"
57 #include "vdevicex11.h"
59 #include "videodevice.h"
60 #include "virtualanode.h"
61 #include "virtualvnode.h"
69 #include <sys/types.h>
75 void PluginServer::init()
78 this->plugin_type = PLUGIN_TYPE_UNKNOWN;
79 plugin_obj = new PluginObj();
80 modules = new ArrayList<Module*>;
81 nodes = new ArrayList<VirtualNode*>;
84 PluginServer::PluginServer()
89 PluginServer::PluginServer(MWindow *mwindow, char *path, int type)
91 char fpath[BCTEXTLEN];
93 this->plugin_type = type;
94 this->mwindow = mwindow;
95 if( type == PLUGIN_TYPE_FFMPEG ) {
96 ff_name = cstrdup(path);
97 sprintf(fpath, "ff_%s", path);
103 PluginServer::PluginServer(PluginServer &that)
106 plugin_type = that.plugin_type;
107 plugin_obj = that.plugin_obj;
108 plugin_obj->add_user();
109 title = !that.title ? 0 : cstrdup(that.title);
110 path = !that.path ? 0 : cstrdup(that.path);
111 ff_name = !that.ff_name ? 0 : cstrdup(that.ff_name);
112 modules = new ArrayList<Module*>;
113 nodes = new ArrayList<VirtualNode*>;
115 attachment = that.attachment;
116 realtime = that.realtime;
117 multichannel = that.multichannel;
118 preferences = that.preferences;
119 synthesis = that.synthesis;
123 fileio = that.fileio;
124 uses_gui = that.uses_gui;
125 mwindow = that.mwindow;
126 keyframe = that.keyframe;
127 new_plugin = that.new_plugin;
129 lad_descriptor = that.lad_descriptor;
130 lad_descriptor_function = that.lad_descriptor_function;
131 lad_index = that.lad_index;
134 PluginServer::~PluginServer()
143 plugin_obj->remove_user();
146 // Done only once at creation
147 int PluginServer::reset_parameters()
159 audio = video = theme = 0;
162 realtime = multichannel = fileio = 0;
164 start_auto = end_auto = 0;
175 lad_descriptor_function = 0;
180 // Done every time the plugin is opened or closed
181 int PluginServer::cleanup_plugin()
183 in_buffer_size = out_buffer_size = 0;
184 total_in_buffers = total_out_buffers = 0;
189 written_samples = written_frames = 0;
196 void PluginServer::set_mwindow(MWindow *mwindow)
198 this->mwindow = mwindow;
201 void PluginServer::set_attachmentpoint(AttachmentPoint *attachmentpoint)
203 this->attachmentpoint = attachmentpoint;
206 void PluginServer::set_keyframe(KeyFrame *keyframe)
208 this->keyframe = keyframe;
211 void PluginServer::set_prompt(MenuEffectPrompt *prompt)
213 this->prompt = prompt;
216 void PluginServer::set_lad_index(int i)
221 int PluginServer::get_lad_index()
223 return this->lad_index;
226 int PluginServer::is_ladspa()
228 return plugin_type == PLUGIN_TYPE_LADSPA ? 1 : 0;
231 int PluginServer::is_ffmpeg()
233 return plugin_type == PLUGIN_TYPE_FFMPEG ? 1 : 0;
236 void PluginServer::set_path(const char *path)
238 delete [] this->path;
239 this->path = cstrdup(path);
242 char* PluginServer::get_path()
247 int PluginServer::get_synthesis()
253 void PluginServer::set_title(const char *string)
255 if(title) delete [] title;
256 title = cstrdup(string);
259 void PluginServer::generate_display_title(char *string)
261 char ltitle[BCTEXTLEN];
262 if(BC_Resources::locale_utf8)
263 strcpy(ltitle, _(title));
265 BC_Resources::encode(BC_Resources::encoding, 0,
266 _(title),strlen(title)+1, ltitle,BCTEXTLEN);
267 if(plugin && plugin->track)
268 sprintf(string, "%s: %s", plugin->track->title, ltitle);
270 strcpy(string, ltitle);
273 void *PluginObj::load(const char *plugin_dir, const char *path)
275 char dlpath[BCTEXTLEN], *dp = dlpath;
276 const char *cp = path;
278 const char *bp = plugin_dir;
279 while( *bp ) *dp++ = *bp++;
282 while( *cp ) *dp++ = *cp++;
284 return dlobj = load(dlpath);
287 int PluginServer::load_obj()
289 void *obj = plugin_obj->obj();
290 if( !obj ) obj =plugin_obj->load(preferences->plugin_dir, path);
294 const char *PluginServer::load_error()
296 return plugin_obj->load_error();
299 void *PluginServer::get_sym(const char *sym)
301 if( !plugin_obj->obj() ) return 0;
302 return plugin_obj->load_sym(sym);
305 // Open plugin for signal processing
306 int PluginServer::open_plugin(int master,
307 Preferences *preferences,
311 if(plugin_open) return 0;
313 this->preferences = preferences;
314 this->plugin = plugin;
316 if( plugin_type != PLUGIN_TYPE_FFMPEG && plugin_type != PLUGIN_TYPE_EXECUTABLE && !load_obj() ) {
317 // If the load failed, can't use error to detect executable
318 // because locale and language selection change the load_error()
319 // if( !strstr(string, "executable") ) { set_title(path); plugin_type = PLUGIN_TYPE_EXECUTABLE; }
320 eprintf("PluginServer::open_plugin: load_obj %s = %s\n", path, load_error());
321 return PLUGINSERVER_NOT_RECOGNIZED;
323 if( plugin_type == PLUGIN_TYPE_UNKNOWN || plugin_type == PLUGIN_TYPE_BUILTIN ) {
325 (PluginClient* (*)(PluginServer*)) get_sym("new_plugin");
327 plugin_type = PLUGIN_TYPE_BUILTIN;
329 if( plugin_type == PLUGIN_TYPE_UNKNOWN || plugin_type == PLUGIN_TYPE_LADSPA ) {
330 lad_descriptor_function =
331 (LADSPA_Descriptor_Function) get_sym("ladspa_descriptor");
332 if( lad_descriptor_function ) {
333 if( lad_index < 0 ) return PLUGINSERVER_IS_LAD;
334 lad_descriptor = lad_descriptor_function(lad_index);
335 if( !lad_descriptor )
336 return PLUGINSERVER_NOT_RECOGNIZED;
337 plugin_type = PLUGIN_TYPE_LADSPA;
340 if( plugin_type == PLUGIN_TYPE_UNKNOWN ) {
341 fprintf(stderr, "PluginServer::open_plugin "
342 " %d: plugin undefined in %s\n", __LINE__, path);
343 return PLUGINSERVER_NOT_RECOGNIZED;
345 switch( plugin_type ) {
346 case PLUGIN_TYPE_EXECUTABLE:
347 return PLUGINSERVER_OK;
348 case PLUGIN_TYPE_BUILTIN:
349 client = new_plugin(this);
351 case PLUGIN_TYPE_LADSPA:
352 client = new PluginAClientLAD(this);
354 case PLUGIN_TYPE_FFMPEG:
355 client = new_ffmpeg_plugin();
362 return PLUGINSERVER_NOT_RECOGNIZED;
364 // Run initialization functions
365 realtime = client->is_realtime();
366 // Don't load defaults when probing the directory.
369 client->load_defaults_xml();
371 client->load_defaults();
373 audio = client->is_audio();
374 video = client->is_video();
375 theme = client->is_theme();
376 fileio = client->is_fileio();
377 uses_gui = client->uses_gui();
378 multichannel = client->is_multichannel();
379 synthesis = client->is_synthesis();
380 transition = client->is_transition();
381 set_title(client->plugin_title());
383 //printf("PluginServer::open_plugin 2\n");
385 return PLUGINSERVER_OK;
388 int PluginServer::close_plugin()
390 if(!plugin_open) return 0;
394 // Defaults are saved in the thread.
395 // if(client->defaults) client->save_defaults();
399 // shared object is persistent since plugin deletion would unlink its own object
405 void PluginServer::client_side_close()
407 // Last command executed in client thread
409 mwindow->hide_plugin(plugin, 1);
413 prompt->lock_window();
415 prompt->unlock_window();
419 void PluginServer::render_stop()
422 client->render_stop();
425 void PluginServer::write_table(FILE *fp, const char *path, int idx, int64_t mtime)
428 fprintf(fp, "%d \"%s\" \"%s\" %jd %d %d %d %d %d %d %d %d %d %d %d\n",
429 plugin_type, path, title, mtime, idx, audio, video, theme, realtime,
430 fileio, uses_gui, multichannel, synthesis, transition, lad_index);
433 int PluginServer::scan_table(char *text, int &type, char *path, char *title, int64_t &mtime)
435 int n = sscanf(text, "%d \"%[^\"]\" \"%[^\"]\" %jd", &type, path, title, &mtime);
436 return n < 4 ? 1 : 0;
439 int PluginServer::read_table(char *text)
441 char path[BCTEXTLEN], title[BCTEXTLEN];
443 int n = sscanf(text, "%d \"%[^\"]\" \"%[^\"]\" %jd %d %d %d %d %d %d %d %d %d %d %d",
444 &plugin_type, path, title, &mtime, &dir_idx, &audio, &video, &theme, &realtime,
445 &fileio, &uses_gui, &multichannel, &synthesis, &transition, &lad_index);
446 if( n != 15 ) return 1;
451 int PluginServer::init_realtime(int realtime_sched,
452 int total_in_buffers,
456 if(!plugin_open) return 0;
458 // set for realtime priority
460 // Call start_realtime
461 this->total_in_buffers = this->total_out_buffers = total_in_buffers;
462 client->plugin_init_realtime(realtime_sched,
470 // Replaced by pull method but still needed for transitions
471 void PluginServer::process_transition(VFrame *input,
473 int64_t current_position,
476 if(!plugin_open) return;
477 PluginVClient *vclient = (PluginVClient*)client;
479 vclient->source_position = current_position;
480 vclient->source_start = 0;
481 vclient->total_len = total_len;
483 vclient->input = new VFrame*[1];
484 vclient->output = new VFrame*[1];
486 vclient->input[0] = input;
487 vclient->output[0] = output;
489 vclient->process_realtime(input, output);
491 delete [] vclient->input;
492 delete [] vclient->output;
496 void PluginServer::process_transition(Samples *input,
498 int64_t current_position,
499 int64_t fragment_size,
502 if(!plugin_open) return;
503 PluginAClient *aclient = (PluginAClient*)client;
505 aclient->source_position = current_position;
506 aclient->total_len = total_len;
507 aclient->source_start = 0;
508 aclient->process_realtime(fragment_size,
514 void PluginServer::process_buffer(VFrame **frame,
515 int64_t current_position,
520 if(!plugin_open) return;
521 PluginVClient *vclient = (PluginVClient*)client;
523 vclient->source_position = current_position;
524 vclient->total_len = total_len;
525 vclient->frame_rate = frame_rate;
526 vclient->input = new VFrame*[total_in_buffers];
527 vclient->output = new VFrame*[total_in_buffers];
528 for(int i = 0; i < total_in_buffers; i++)
530 vclient->input[i] = frame[i];
531 vclient->output[i] = frame[i];
536 vclient->source_start = (int64_t)plugin->startproject *
538 vclient->project_frame_rate;
540 vclient->direction = direction;
544 //printf("plugin=%p source_start=%ld\n", plugin, vclient->source_start);
546 vclient->begin_process_buffer();
549 vclient->process_buffer(frame, current_position, frame_rate);
553 vclient->process_buffer(frame[0], current_position, frame_rate);
555 vclient->end_process_buffer();
557 for(int i = 0; i < total_in_buffers; i++)
558 frame[i]->push_prev_effect(title);
560 delete [] vclient->input;
561 delete [] vclient->output;
567 void PluginServer::process_buffer(Samples **buffer,
568 int64_t current_position,
569 int64_t fragment_size,
574 if(!plugin_open) return;
575 PluginAClient *aclient = (PluginAClient*)client;
577 aclient->source_position = current_position;
578 aclient->total_len = total_len;
579 aclient->sample_rate = sample_rate;
582 aclient->source_start = plugin->startproject *
584 aclient->project_sample_rate;
586 aclient->direction = direction;
587 aclient->begin_process_buffer();
590 aclient->process_buffer(fragment_size,
597 aclient->process_buffer(fragment_size,
602 aclient->end_process_buffer();
606 void PluginServer::send_render_gui(void *data)
608 //printf("PluginServer::send_render_gui 1 %p\n", attachmentpoint);
609 if(attachmentpoint) attachmentpoint->render_gui(data, this);
612 void PluginServer::send_render_gui(void *data, int size)
614 //printf("PluginServer::send_render_gui 1 %p\n", attachmentpoint);
615 if(attachmentpoint) attachmentpoint->render_gui(data, size, this);
618 void PluginServer::render_gui(void *data)
620 if(client) client->plugin_render_gui(data);
623 void PluginServer::render_gui(void *data, int size)
625 if(client) client->plugin_render_gui(data, size);
628 MainProgressBar* PluginServer::start_progress(char *string, int64_t length)
630 mwindow->gui->lock_window();
631 MainProgressBar *result = mwindow->mainprogress->start_progress(string, length);
632 mwindow->gui->unlock_window();
636 int64_t PluginServer::get_written_samples()
638 if(!plugin_open) return 0;
639 return written_samples;
642 int64_t PluginServer::get_written_frames()
644 if(!plugin_open) return 0;
645 return written_frames;
657 // ======================= Non-realtime plugin
659 int PluginServer::get_parameters(int64_t start, int64_t end, int channels)
661 if(!plugin_open) return 0;
663 client->start = start;
665 client->source_start = start;
666 client->total_len = end - start;
667 client->total_in_buffers = channels;
670 //printf(" source_start=%ld total_len=%ld\n", client->source_start, client->total_len);
672 return client->plugin_get_parameters();
675 int PluginServer::set_interactive()
677 if(!plugin_open) return 0;
678 client->set_interactive();
682 void PluginServer::append_module(Module *module)
684 modules->append(module);
687 void PluginServer::append_node(VirtualNode *node)
692 void PluginServer::reset_nodes()
697 int PluginServer::set_error()
703 int PluginServer::set_realtime_sched()
705 //struct sched_param params;
706 //params.sched_priority = 1;
707 //sched_setscheduler(0, SCHED_RR, ¶m);
712 int PluginServer::process_loop(VFrame **buffers, int64_t &write_length)
714 if(!plugin_open) return 1;
715 return client->plugin_process_loop(buffers, write_length);
718 int PluginServer::process_loop(Samples **buffers, int64_t &write_length)
720 if(!plugin_open) return 1;
721 return client->plugin_process_loop(buffers, write_length);
725 int PluginServer::start_loop(int64_t start,
730 if(!plugin_open) return 0;
731 client->plugin_start_loop(start, end, buffer_size, total_buffers);
735 int PluginServer::stop_loop()
737 if(!plugin_open) return 0;
738 return client->plugin_stop_loop();
741 int PluginServer::read_frame(VFrame *buffer,
743 int64_t start_position)
745 ((VModule*)modules->values[channel])->render(buffer,
748 mwindow->edl->session->frame_rate,
754 int PluginServer::read_samples(Samples *buffer,
757 int64_t start_position,
760 // len is now in buffer
761 if(!multichannel) channel = 0;
763 if(nodes->total > channel)
764 return ((VirtualANode*)nodes->values[channel])->read_data(buffer,
769 if(modules->total > channel)
770 return ((AModule*)modules->values[channel])->render(buffer,
778 printf("PluginServer::read_samples no object available for channel=%d\n",
786 int PluginServer::read_samples(Samples *buffer,
788 int64_t start_position,
791 // total_samples is now set in buffer
792 ((AModule*)modules->values[channel])->render(buffer,
796 mwindow->edl->session->sample_rate,
801 int PluginServer::read_frame(VFrame *buffer,
803 int64_t start_position,
807 // Data source depends on whether we're part of a virtual console or a
811 // If we're a VirtualNode, read_data in the virtual plugin node handles
812 // backward propogation and produces the data.
813 // If we're a Module, render in the module produces the data.
817 if(!multichannel) channel = 0;
819 // Push our name on the next effect stack
820 buffer->push_next_effect(title);
821 //printf("PluginServer::read_frame %p\n", buffer);
822 //buffer->dump_stacks();
824 if(nodes->total > channel)
826 //printf("PluginServer::read_frame %d\n", __LINE__);
827 result = ((VirtualVNode*)nodes->values[channel])->read_data(buffer,
833 if(modules->total > channel)
835 //printf("PluginServer::read_frame %d\n", __LINE__);
836 result = ((VModule*)modules->values[channel])->render(buffer,
847 printf("PluginServer::read_frame no object available for channel=%d\n",
851 // Pop our name from the next effect stack
852 buffer->pop_next_effect();
877 int PluginServer::get_gui_status()
880 return plugin->show ? GUI_ON : GUI_OFF;
885 void PluginServer::raise_window()
887 if(!plugin_open) return;
888 client->raise_window();
891 void PluginServer::show_gui()
893 if(!plugin_open) return;
894 if(plugin) client->total_len = plugin->length;
895 if(plugin) client->source_start = plugin->startproject;
898 client->source_position = Units::to_int64(
899 mwindow->edl->local_session->get_selectionstart(1) *
900 mwindow->edl->session->frame_rate);
905 client->source_position = Units::to_int64(
906 mwindow->edl->local_session->get_selectionstart(1) *
907 mwindow->edl->session->sample_rate);
910 client->update_display_title();
914 void PluginServer::hide_gui()
916 if(!plugin_open) return;
917 if(client->defaults) client->save_defaults();
921 void PluginServer::update_gui()
923 if(!plugin_open || !plugin) return;
925 client->total_len = plugin->length;
926 client->source_start = plugin->startproject;
930 client->source_position = Units::to_int64(
931 mwindow->edl->local_session->get_selectionstart(1) *
932 mwindow->edl->session->frame_rate);
937 client->source_position = Units::to_int64(
938 mwindow->edl->local_session->get_selectionstart(1) *
939 mwindow->edl->session->sample_rate);
942 client->plugin_update_gui();
945 void PluginServer::update_title()
947 if(!plugin_open) return;
949 client->update_display_title();
953 int PluginServer::set_string(char *string)
955 if(!plugin_open) return 0;
957 client->set_string_client(string);
961 int PluginServer::gui_open()
963 if(attachmentpoint) return attachmentpoint->gui_open();
967 void PluginServer::set_use_opengl(int value, VideoDevice *vdevice)
969 this->use_opengl = value;
970 this->vdevice = vdevice;
973 int PluginServer::get_use_opengl()
979 void PluginServer::run_opengl(PluginClient *plugin_client)
982 ((VDeviceX11*)vdevice->get_output_base())->run_plugin(plugin_client);
985 // ============================= queries
987 void PluginServer::get_defaults_path(char *path)
989 // Get plugin name from path
990 char *ptr1 = strrchr(get_path(), '/');
991 char *ptr2 = strrchr(get_path(), '.');
992 if(!ptr1) ptr1 = get_path();
993 if(!ptr2) ptr2 = get_path() + strlen(get_path());
994 char string2[BCTEXTLEN], *ptr3 = string2;
995 while( ptr1 < ptr2 ) *ptr3++ = *ptr1++;
997 sprintf(path, "%s/%s.xml", File::get_config_path(), string2);
1000 void PluginServer::save_defaults()
1002 if(client) client->save_defaults();
1005 int PluginServer::get_samplerate()
1007 if(!plugin_open) return 0;
1010 return client->get_samplerate();
1014 return mwindow->edl->session->sample_rate;
1017 printf("PluginServer::get_samplerate audio and mwindow == NULL\n");
1023 double PluginServer::get_framerate()
1025 if(!plugin_open) return 0;
1028 return client->get_framerate();
1032 return mwindow->edl->session->frame_rate;
1035 printf("PluginServer::get_framerate video and mwindow == NULL\n");
1040 int PluginServer::get_project_samplerate()
1043 return mwindow->edl->session->sample_rate;
1046 return edl->session->sample_rate;
1049 printf("PluginServer::get_project_samplerate mwindow and edl are NULL.\n");
1054 double PluginServer::get_project_framerate()
1057 return mwindow->edl->session->frame_rate;
1060 return edl->session->frame_rate;
1063 printf("PluginServer::get_project_framerate mwindow and edl are NULL.\n");
1070 int PluginServer::detach_buffers()
1072 ring_buffers_out.remove_all();
1073 offset_out_render.remove_all();
1074 double_buffer_out_render.remove_all();
1075 realtime_out_size.remove_all();
1077 ring_buffers_in.remove_all();
1078 offset_in_render.remove_all();
1079 double_buffer_in_render.remove_all();
1080 realtime_in_size.remove_all();
1082 out_buffer_size = 0;
1084 total_out_buffers = 0;
1086 total_in_buffers = 0;
1090 int PluginServer::arm_buffer(int buffer_number,
1093 int double_buffer_in,
1094 int double_buffer_out)
1096 offset_in_render.values[buffer_number] = offset_in;
1097 offset_out_render.values[buffer_number] = offset_out;
1098 double_buffer_in_render.values[buffer_number] = double_buffer_in;
1099 double_buffer_out_render.values[buffer_number] = double_buffer_out;
1104 int PluginServer::set_automation(FloatAutos *autos, FloatAuto **start_auto, FloatAuto **end_auto, int reverse)
1106 this->autos = autos;
1107 this->start_auto = start_auto;
1108 this->end_auto = end_auto;
1109 this->reverse = reverse;
1115 void PluginServer::save_data(KeyFrame *keyframe)
1117 if(!plugin_open) return;
1118 client->save_data(keyframe);
1121 KeyFrame* PluginServer::get_prev_keyframe(int64_t position)
1123 KeyFrame *result = 0;
1125 result = plugin->get_prev_keyframe(position, client->direction);
1131 KeyFrame* PluginServer::get_next_keyframe(int64_t position)
1133 KeyFrame *result = 0;
1135 result = plugin->get_next_keyframe(position, client->direction);
1142 KeyFrame* PluginServer::get_keyframe()
1145 // Realtime plugin case
1146 return plugin->get_keyframe();
1148 // Rendered plugin case
1153 void PluginServer::apply_keyframe(KeyFrame *src)
1157 keyframe->copy_data(src);
1162 plugin->keyframes->update_parameter(src);
1170 void PluginServer::get_camera(float *x, float *y, float *z,
1171 int64_t position, int direction)
1173 plugin->track->automation->get_camera(x, y, z, position, direction);
1176 void PluginServer::get_projector(float *x, float *y, float *z,
1177 int64_t position, int direction)
1179 plugin->track->automation->get_projector(x, y, z, position, direction);
1183 int PluginServer::get_interpolation_type()
1185 return plugin->edl->session->interpolation_type;
1188 Theme* PluginServer::new_theme()
1192 return client->new_theme();
1198 Theme* PluginServer::get_theme()
1200 if(mwindow) return mwindow->theme;
1201 printf("PluginServer::get_theme mwindow not set\n");
1206 int PluginServer::get_theme_png_path(char *png_path, const char *theme_dir)
1208 char *bp = strrchr(path, '/');
1209 if( !bp ) bp = path; else ++bp;
1210 char *sp = strrchr(bp,'.');
1211 if( !sp ) sp = bp + strlen(bp);
1212 char *cp = png_path, *dp = bp;
1213 cp += sprintf(cp,"%s/%s/", mwindow->preferences->plugin_dir, theme_dir);
1214 while( dp < sp ) *cp++ = *dp++;
1217 if( stat(png_path, &st) ) return 0;
1218 if( !S_ISREG(st.st_mode) ) return 0;
1219 if( st.st_size == 0 ) return 0;
1223 int PluginServer::get_theme_png_path(char *png_path, Theme *theme)
1225 char *bp = strrchr(theme->path, '/');
1226 if( !bp ) bp = theme->path; else ++bp;
1227 char *sp = strrchr(bp,'.');
1228 if( !sp || ( strcmp(sp, ".plugin") && strcmp(sp,".so") ) ) return 0;
1229 char theme_dir[BCTEXTLEN], *cp = theme_dir;
1230 while( bp < sp ) *cp++ = *bp++;
1232 return get_theme_png_path(png_path, theme_dir);
1235 int PluginServer::get_plugin_png_path(char *png_path)
1237 int len = get_theme_png_path(png_path, mwindow->theme);
1239 len = get_theme_png_path(png_path, "picon");
1243 VFrame *PluginServer::get_plugin_images()
1245 char png_path[BCTEXTLEN];
1246 int len = get_plugin_png_path(png_path);
1247 if( !len ) return 0;
1248 int ret = 0, w = 0, h = 0;
1249 unsigned char *bfr = 0;
1250 int fd = ::open(png_path, O_RDONLY);
1251 if( fd < 0 ) ret = 1;
1253 bfr = (unsigned char *) ::mmap (NULL, len, PROT_READ, MAP_SHARED, fd, 0);
1254 if( bfr == MAP_FAILED ) ret = 1;
1258 double scale = BC_WindowBase::get_resources()->icon_scale;
1259 vframe = new VFramePng(bfr, len, scale, scale);
1260 if( (w=vframe->get_w()) <= 0 || (h=vframe->get_h()) <= 0 ||
1261 vframe->get_data() == 0 ) ret = 1;
1263 if( bfr && bfr != MAP_FAILED ) ::munmap(bfr, len);
1264 if( fd >= 0 ) ::close(fd);
1265 if( ret ) { delete vframe; vframe = 0; }
1269 VFrame *PluginServer::get_picon()
1272 picon = get_plugin_images();
1276 // Called when plugin interface is tweeked
1277 void PluginServer::sync_parameters()
1279 if(video) mwindow->restart_brender();
1280 mwindow->sync_parameters();
1281 mwindow->update_keyframe_guis();
1282 if(mwindow->edl->session->auto_conf->plugins)
1284 mwindow->gui->lock_window("PluginServer::sync_parameters");
1285 mwindow->gui->draw_overlays(1);
1286 mwindow->gui->unlock_window();
1292 void PluginServer::dump(FILE *fp)
1294 fprintf(fp," PluginServer %d %p %s %s %d\n",
1295 __LINE__, this, path, title, realtime);