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"
32 #include "floatautos.h"
33 #include "keyframes.h"
34 #include "localsession.h"
35 #include "mainerror.h"
36 #include "mainprogress.h"
37 #include "menueffects.h"
39 #include "mwindowgui.h"
40 #include "playbackengine.h"
42 #include "pluginaclient.h"
43 #include "pluginaclientlad.h"
44 #include "pluginfclient.h"
45 #include "pluginclient.h"
46 #include "plugincommands.h"
47 #include "pluginserver.h"
48 #include "pluginvclient.h"
49 #include "preferences.h"
52 #include "mainsession.h"
54 #include "trackcanvas.h"
55 #include "transportque.h"
56 #include "vdevicex11.h"
58 #include "videodevice.h"
59 #include "virtualanode.h"
60 #include "virtualvnode.h"
68 #include <sys/types.h>
74 void PluginServer::init()
77 this->plugin_type = PLUGIN_TYPE_UNKNOWN;
78 plugin_obj = new PluginObj();
79 modules = new ArrayList<Module*>;
80 nodes = new ArrayList<VirtualNode*>;
83 PluginServer::PluginServer()
88 PluginServer::PluginServer(MWindow *mwindow, char *path, int type)
90 char fpath[BCTEXTLEN];
92 this->plugin_type = type;
93 this->mwindow = mwindow;
94 if( type == PLUGIN_TYPE_FFMPEG ) {
95 ff_name = cstrdup(path);
96 sprintf(fpath, "ff_%s", path);
102 PluginServer::PluginServer(PluginServer &that)
105 plugin_type = that.plugin_type;
106 plugin_obj = that.plugin_obj;
107 plugin_obj->add_user();
108 title = !that.title ? 0 : cstrdup(that.title);
109 path = !that.path ? 0 : cstrdup(that.path);
110 ff_name = !that.ff_name ? 0 : cstrdup(that.ff_name);
111 modules = new ArrayList<Module*>;
112 nodes = new ArrayList<VirtualNode*>;
114 attachment = that.attachment;
115 realtime = that.realtime;
116 multichannel = that.multichannel;
117 preferences = that.preferences;
118 synthesis = that.synthesis;
122 fileio = that.fileio;
123 uses_gui = that.uses_gui;
124 mwindow = that.mwindow;
125 keyframe = that.keyframe;
126 new_plugin = that.new_plugin;
128 lad_descriptor = that.lad_descriptor;
129 lad_descriptor_function = that.lad_descriptor_function;
130 lad_index = that.lad_index;
133 PluginServer::~PluginServer()
142 plugin_obj->remove_user();
145 // Done only once at creation
146 int PluginServer::reset_parameters()
158 audio = video = theme = 0;
161 realtime = multichannel = fileio = 0;
163 start_auto = end_auto = 0;
174 lad_descriptor_function = 0;
179 // Done every time the plugin is opened or closed
180 int PluginServer::cleanup_plugin()
182 in_buffer_size = out_buffer_size = 0;
183 total_in_buffers = total_out_buffers = 0;
188 written_samples = written_frames = 0;
195 void PluginServer::set_mwindow(MWindow *mwindow)
197 this->mwindow = mwindow;
200 void PluginServer::set_attachmentpoint(AttachmentPoint *attachmentpoint)
202 this->attachmentpoint = attachmentpoint;
205 void PluginServer::set_keyframe(KeyFrame *keyframe)
207 this->keyframe = keyframe;
210 void PluginServer::set_prompt(MenuEffectPrompt *prompt)
212 this->prompt = prompt;
215 void PluginServer::set_lad_index(int i)
220 int PluginServer::get_lad_index()
222 return this->lad_index;
225 int PluginServer::is_ladspa()
227 return plugin_type == PLUGIN_TYPE_LADSPA ? 1 : 0;
230 int PluginServer::is_ffmpeg()
232 return plugin_type == PLUGIN_TYPE_FFMPEG ? 1 : 0;
235 void PluginServer::set_path(const char *path)
237 delete [] this->path;
238 this->path = cstrdup(path);
241 char* PluginServer::get_path()
246 int PluginServer::get_synthesis()
252 void PluginServer::set_title(const char *string)
254 if(title) delete [] title;
255 title = cstrdup(string);
258 void PluginServer::generate_display_title(char *string)
260 char ltitle[BCTEXTLEN];
261 if(BC_Resources::locale_utf8)
262 strcpy(ltitle, _(title));
264 BC_Resources::encode(BC_Resources::encoding, 0,
265 _(title),strlen(title)+1, ltitle,BCTEXTLEN);
266 if(plugin && plugin->track)
267 sprintf(string, "%s: %s", plugin->track->title, ltitle);
269 strcpy(string, ltitle);
272 void *PluginObj::load(const char *plugin_dir, const char *path)
274 char dlpath[BCTEXTLEN], *dp = dlpath;
275 const char *cp = path;
277 const char *bp = plugin_dir;
278 while( *bp ) *dp++ = *bp++;
281 while( *cp ) *dp++ = *cp++;
283 return dlobj = load(dlpath);
286 int PluginServer::load_obj()
288 void *obj = plugin_obj->obj();
289 if( !obj ) obj =plugin_obj->load(preferences->plugin_dir, path);
293 const char *PluginServer::load_error()
295 return plugin_obj->load_error();
298 void *PluginServer::get_sym(const char *sym)
300 if( !plugin_obj->obj() ) return 0;
301 return plugin_obj->load_sym(sym);
304 // Open plugin for signal processing
305 int PluginServer::open_plugin(int master,
306 Preferences *preferences,
310 if(plugin_open) return 0;
312 this->preferences = preferences;
313 this->plugin = plugin;
315 if( plugin_type != PLUGIN_TYPE_FFMPEG && plugin_type != PLUGIN_TYPE_EXECUTABLE && !load_obj() ) {
316 // If the load failed it may still be an executable tool for a specific
317 // file format, in which case we just store the path.
319 char string[BCTEXTLEN];
320 strcpy(string, load_error());
321 if( !strstr(string, "executable") ) {
322 eprintf("PluginServer::open_plugin: load_obj %s = %s\n", path, string);
323 return PLUGINSERVER_NOT_RECOGNIZED;
325 plugin_type = PLUGIN_TYPE_EXECUTABLE;
327 if( plugin_type == PLUGIN_TYPE_UNKNOWN || plugin_type == PLUGIN_TYPE_BUILTIN ) {
329 (PluginClient* (*)(PluginServer*)) get_sym("new_plugin");
331 plugin_type = PLUGIN_TYPE_BUILTIN;
333 if( plugin_type == PLUGIN_TYPE_UNKNOWN || plugin_type == PLUGIN_TYPE_LADSPA ) {
334 lad_descriptor_function =
335 (LADSPA_Descriptor_Function) get_sym("ladspa_descriptor");
336 if( lad_descriptor_function ) {
337 if( lad_index < 0 ) return PLUGINSERVER_IS_LAD;
338 lad_descriptor = lad_descriptor_function(lad_index);
339 if( !lad_descriptor )
340 return PLUGINSERVER_NOT_RECOGNIZED;
341 plugin_type = PLUGIN_TYPE_LADSPA;
344 if( plugin_type == PLUGIN_TYPE_UNKNOWN ) {
345 fprintf(stderr, "PluginServer::open_plugin "
346 " %d: plugin undefined in %s\n", __LINE__, path);
347 return PLUGINSERVER_NOT_RECOGNIZED;
349 switch( plugin_type ) {
350 case PLUGIN_TYPE_BUILTIN:
351 client = new_plugin(this);
353 case PLUGIN_TYPE_LADSPA:
354 client = new PluginAClientLAD(this);
356 case PLUGIN_TYPE_FFMPEG:
357 client = new_ffmpeg_plugin();
364 return PLUGINSERVER_NOT_RECOGNIZED;
366 // Run initialization functions
367 realtime = client->is_realtime();
368 // Don't load defaults when probing the directory.
371 client->load_defaults_xml();
373 client->load_defaults();
375 audio = client->is_audio();
376 video = client->is_video();
377 theme = client->is_theme();
378 fileio = client->is_fileio();
379 uses_gui = client->uses_gui();
380 multichannel = client->is_multichannel();
381 synthesis = client->is_synthesis();
382 transition = client->is_transition();
383 set_title(client->plugin_title());
385 //printf("PluginServer::open_plugin 2\n");
387 return PLUGINSERVER_OK;
390 int PluginServer::close_plugin()
392 if(!plugin_open) return 0;
396 // Defaults are saved in the thread.
397 // if(client->defaults) client->save_defaults();
401 // shared object is persistent since plugin deletion would unlink its own object
407 void PluginServer::client_side_close()
409 // Last command executed in client thread
411 mwindow->hide_plugin(plugin, 1);
415 prompt->lock_window();
417 prompt->unlock_window();
421 void PluginServer::render_stop()
424 client->render_stop();
427 void PluginServer::write_table(FILE *fp, int idx)
430 fprintf(fp, "%d \"%s\" \"%s\" %d %d %d %d %d %d %d %d %d %d %d\n",
431 plugin_type, path, title, idx, audio, video, theme, realtime,
432 fileio, uses_gui, multichannel, synthesis, transition, lad_index);
435 int PluginServer::scan_table(char *text, int &type, char *path, char *title)
437 int n = sscanf(text, "%d \"%[^\"]\" \"%[^\"]\"", &type, path, title);
438 return n < 3 ? 1 : 0;
441 int PluginServer::read_table(char *text)
443 char path[BCTEXTLEN], title[BCTEXTLEN];
444 int n = sscanf(text, "%d \"%[^\"]\" \"%[^\"]\" %d %d %d %d %d %d %d %d %d %d %d",
445 &plugin_type, path, title, &dir_idx, &audio, &video, &theme, &realtime,
446 &fileio, &uses_gui, &multichannel, &synthesis, &transition, &lad_index);
447 if( n != 14 ) return 1;
453 int PluginServer::init_realtime(int realtime_sched,
454 int total_in_buffers,
458 if(!plugin_open) return 0;
460 // set for realtime priority
462 // Call start_realtime
463 this->total_in_buffers = this->total_out_buffers = total_in_buffers;
464 client->plugin_init_realtime(realtime_sched,
472 // Replaced by pull method but still needed for transitions
473 void PluginServer::process_transition(VFrame *input,
475 int64_t current_position,
478 if(!plugin_open) return;
479 PluginVClient *vclient = (PluginVClient*)client;
481 vclient->source_position = current_position;
482 vclient->source_start = 0;
483 vclient->total_len = total_len;
485 vclient->input = new VFrame*[1];
486 vclient->output = new VFrame*[1];
488 vclient->input[0] = input;
489 vclient->output[0] = output;
491 vclient->process_realtime(input, output);
493 delete [] vclient->input;
494 delete [] vclient->output;
498 void PluginServer::process_transition(Samples *input,
500 int64_t current_position,
501 int64_t fragment_size,
504 if(!plugin_open) return;
505 PluginAClient *aclient = (PluginAClient*)client;
507 aclient->source_position = current_position;
508 aclient->total_len = total_len;
509 aclient->source_start = 0;
510 aclient->process_realtime(fragment_size,
516 void PluginServer::process_buffer(VFrame **frame,
517 int64_t current_position,
522 if(!plugin_open) return;
523 PluginVClient *vclient = (PluginVClient*)client;
525 vclient->source_position = current_position;
526 vclient->total_len = total_len;
527 vclient->frame_rate = frame_rate;
528 vclient->input = new VFrame*[total_in_buffers];
529 vclient->output = new VFrame*[total_in_buffers];
530 for(int i = 0; i < total_in_buffers; i++)
532 vclient->input[i] = frame[i];
533 vclient->output[i] = frame[i];
538 vclient->source_start = (int64_t)plugin->startproject *
540 vclient->project_frame_rate;
542 vclient->direction = direction;
546 //printf("plugin=%p source_start=%ld\n", plugin, vclient->source_start);
548 vclient->begin_process_buffer();
551 vclient->process_buffer(frame, current_position, frame_rate);
555 vclient->process_buffer(frame[0], current_position, frame_rate);
557 vclient->end_process_buffer();
559 for(int i = 0; i < total_in_buffers; i++)
560 frame[i]->push_prev_effect(title);
562 delete [] vclient->input;
563 delete [] vclient->output;
569 void PluginServer::process_buffer(Samples **buffer,
570 int64_t current_position,
571 int64_t fragment_size,
576 if(!plugin_open) return;
577 PluginAClient *aclient = (PluginAClient*)client;
579 aclient->source_position = current_position;
580 aclient->total_len = total_len;
581 aclient->sample_rate = sample_rate;
584 aclient->source_start = plugin->startproject *
586 aclient->project_sample_rate;
588 aclient->direction = direction;
589 aclient->begin_process_buffer();
592 aclient->process_buffer(fragment_size,
599 aclient->process_buffer(fragment_size,
604 aclient->end_process_buffer();
608 void PluginServer::send_render_gui(void *data)
610 //printf("PluginServer::send_render_gui 1 %p\n", attachmentpoint);
611 if(attachmentpoint) attachmentpoint->render_gui(data, this);
614 void PluginServer::send_render_gui(void *data, int size)
616 //printf("PluginServer::send_render_gui 1 %p\n", attachmentpoint);
617 if(attachmentpoint) attachmentpoint->render_gui(data, size, this);
620 void PluginServer::render_gui(void *data)
622 if(client) client->plugin_render_gui(data);
625 void PluginServer::render_gui(void *data, int size)
627 if(client) client->plugin_render_gui(data, size);
630 MainProgressBar* PluginServer::start_progress(char *string, int64_t length)
632 mwindow->gui->lock_window();
633 MainProgressBar *result = mwindow->mainprogress->start_progress(string, length);
634 mwindow->gui->unlock_window();
638 int64_t PluginServer::get_written_samples()
640 if(!plugin_open) return 0;
641 return written_samples;
644 int64_t PluginServer::get_written_frames()
646 if(!plugin_open) return 0;
647 return written_frames;
659 // ======================= Non-realtime plugin
661 int PluginServer::get_parameters(int64_t start, int64_t end, int channels)
663 if(!plugin_open) return 0;
665 client->start = start;
667 client->source_start = start;
668 client->total_len = end - start;
669 client->total_in_buffers = channels;
672 //printf(" source_start=%ld total_len=%ld\n", client->source_start, client->total_len);
674 return client->plugin_get_parameters();
677 int PluginServer::set_interactive()
679 if(!plugin_open) return 0;
680 client->set_interactive();
684 void PluginServer::append_module(Module *module)
686 modules->append(module);
689 void PluginServer::append_node(VirtualNode *node)
694 void PluginServer::reset_nodes()
699 int PluginServer::set_error()
705 int PluginServer::set_realtime_sched()
707 //struct sched_param params;
708 //params.sched_priority = 1;
709 //sched_setscheduler(0, SCHED_RR, ¶m);
714 int PluginServer::process_loop(VFrame **buffers, int64_t &write_length)
716 if(!plugin_open) return 1;
717 return client->plugin_process_loop(buffers, write_length);
720 int PluginServer::process_loop(Samples **buffers, int64_t &write_length)
722 if(!plugin_open) return 1;
723 return client->plugin_process_loop(buffers, write_length);
727 int PluginServer::start_loop(int64_t start,
732 if(!plugin_open) return 0;
733 client->plugin_start_loop(start, end, buffer_size, total_buffers);
737 int PluginServer::stop_loop()
739 if(!plugin_open) return 0;
740 return client->plugin_stop_loop();
743 int PluginServer::read_frame(VFrame *buffer,
745 int64_t start_position)
747 ((VModule*)modules->values[channel])->render(buffer,
750 mwindow->edl->session->frame_rate,
756 int PluginServer::read_samples(Samples *buffer,
759 int64_t start_position,
762 // len is now in buffer
763 if(!multichannel) channel = 0;
765 if(nodes->total > channel)
766 return ((VirtualANode*)nodes->values[channel])->read_data(buffer,
771 if(modules->total > channel)
772 return ((AModule*)modules->values[channel])->render(buffer,
780 printf("PluginServer::read_samples no object available for channel=%d\n",
788 int PluginServer::read_samples(Samples *buffer,
790 int64_t start_position,
793 // total_samples is now set in buffer
794 ((AModule*)modules->values[channel])->render(buffer,
798 mwindow->edl->session->sample_rate,
803 int PluginServer::read_frame(VFrame *buffer,
805 int64_t start_position,
809 // Data source depends on whether we're part of a virtual console or a
813 // If we're a VirtualNode, read_data in the virtual plugin node handles
814 // backward propogation and produces the data.
815 // If we're a Module, render in the module produces the data.
819 if(!multichannel) channel = 0;
821 // Push our name on the next effect stack
822 buffer->push_next_effect(title);
823 //printf("PluginServer::read_frame %p\n", buffer);
824 //buffer->dump_stacks();
826 if(nodes->total > channel)
828 //printf("PluginServer::read_frame %d\n", __LINE__);
829 result = ((VirtualVNode*)nodes->values[channel])->read_data(buffer,
835 if(modules->total > channel)
837 //printf("PluginServer::read_frame %d\n", __LINE__);
838 result = ((VModule*)modules->values[channel])->render(buffer,
849 printf("PluginServer::read_frame no object available for channel=%d\n",
853 // Pop our name from the next effect stack
854 buffer->pop_next_effect();
879 int PluginServer::get_gui_status()
882 return plugin->show ? GUI_ON : GUI_OFF;
887 void PluginServer::raise_window()
889 if(!plugin_open) return;
890 client->raise_window();
893 void PluginServer::show_gui()
895 if(!plugin_open) return;
896 if(plugin) client->total_len = plugin->length;
897 if(plugin) client->source_start = plugin->startproject;
900 client->source_position = Units::to_int64(
901 mwindow->edl->local_session->get_selectionstart(1) *
902 mwindow->edl->session->frame_rate);
907 client->source_position = Units::to_int64(
908 mwindow->edl->local_session->get_selectionstart(1) *
909 mwindow->edl->session->sample_rate);
912 client->update_display_title();
916 void PluginServer::hide_gui()
918 if(!plugin_open) return;
919 if(client->defaults) client->save_defaults();
923 void PluginServer::update_gui()
925 if(!plugin_open || !plugin) return;
927 client->total_len = plugin->length;
928 client->source_start = plugin->startproject;
932 client->source_position = Units::to_int64(
933 mwindow->edl->local_session->get_selectionstart(1) *
934 mwindow->edl->session->frame_rate);
939 client->source_position = Units::to_int64(
940 mwindow->edl->local_session->get_selectionstart(1) *
941 mwindow->edl->session->sample_rate);
944 client->plugin_update_gui();
947 void PluginServer::update_title()
949 if(!plugin_open) return;
951 client->update_display_title();
955 int PluginServer::set_string(char *string)
957 if(!plugin_open) return 0;
959 client->set_string_client(string);
963 int PluginServer::gui_open()
965 if(attachmentpoint) return attachmentpoint->gui_open();
969 void PluginServer::set_use_opengl(int value, VideoDevice *vdevice)
971 this->use_opengl = value;
972 this->vdevice = vdevice;
975 int PluginServer::get_use_opengl()
981 void PluginServer::run_opengl(PluginClient *plugin_client)
984 ((VDeviceX11*)vdevice->get_output_base())->run_plugin(plugin_client);
987 // ============================= queries
989 void PluginServer::get_defaults_path(char *path)
991 // Get plugin name from path
992 char *ptr1 = strrchr(get_path(), '/');
993 char *ptr2 = strrchr(get_path(), '.');
994 if(!ptr1) ptr1 = get_path();
995 if(!ptr2) ptr2 = get_path() + strlen(get_path());
996 char string2[BCTEXTLEN];
997 char *ptr3 = string2;
1003 sprintf(path, "%s%s.xml", BCASTDIR, string2);
1006 void PluginServer::save_defaults()
1008 if(client) client->save_defaults();
1011 int PluginServer::get_samplerate()
1013 if(!plugin_open) return 0;
1016 return client->get_samplerate();
1020 return mwindow->edl->session->sample_rate;
1023 printf("PluginServer::get_samplerate audio and mwindow == NULL\n");
1029 double PluginServer::get_framerate()
1031 if(!plugin_open) return 0;
1034 return client->get_framerate();
1038 return mwindow->edl->session->frame_rate;
1041 printf("PluginServer::get_framerate video and mwindow == NULL\n");
1046 int PluginServer::get_project_samplerate()
1049 return mwindow->edl->session->sample_rate;
1052 return edl->session->sample_rate;
1055 printf("PluginServer::get_project_samplerate mwindow and edl are NULL.\n");
1060 double PluginServer::get_project_framerate()
1063 return mwindow->edl->session->frame_rate;
1066 return edl->session->frame_rate;
1069 printf("PluginServer::get_project_framerate mwindow and edl are NULL.\n");
1076 int PluginServer::detach_buffers()
1078 ring_buffers_out.remove_all();
1079 offset_out_render.remove_all();
1080 double_buffer_out_render.remove_all();
1081 realtime_out_size.remove_all();
1083 ring_buffers_in.remove_all();
1084 offset_in_render.remove_all();
1085 double_buffer_in_render.remove_all();
1086 realtime_in_size.remove_all();
1088 out_buffer_size = 0;
1090 total_out_buffers = 0;
1092 total_in_buffers = 0;
1096 int PluginServer::arm_buffer(int buffer_number,
1099 int double_buffer_in,
1100 int double_buffer_out)
1102 offset_in_render.values[buffer_number] = offset_in;
1103 offset_out_render.values[buffer_number] = offset_out;
1104 double_buffer_in_render.values[buffer_number] = double_buffer_in;
1105 double_buffer_out_render.values[buffer_number] = double_buffer_out;
1110 int PluginServer::set_automation(FloatAutos *autos, FloatAuto **start_auto, FloatAuto **end_auto, int reverse)
1112 this->autos = autos;
1113 this->start_auto = start_auto;
1114 this->end_auto = end_auto;
1115 this->reverse = reverse;
1121 void PluginServer::save_data(KeyFrame *keyframe)
1123 if(!plugin_open) return;
1124 client->save_data(keyframe);
1127 KeyFrame* PluginServer::get_prev_keyframe(int64_t position)
1129 KeyFrame *result = 0;
1131 result = plugin->get_prev_keyframe(position, client->direction);
1137 KeyFrame* PluginServer::get_next_keyframe(int64_t position)
1139 KeyFrame *result = 0;
1141 result = plugin->get_next_keyframe(position, client->direction);
1148 KeyFrame* PluginServer::get_keyframe()
1151 // Realtime plugin case
1152 return plugin->get_keyframe();
1154 // Rendered plugin case
1159 void PluginServer::apply_keyframe(KeyFrame *src)
1163 keyframe->copy_data(src);
1168 plugin->keyframes->update_parameter(src);
1176 void PluginServer::get_camera(float *x, float *y, float *z,
1177 int64_t position, int direction)
1179 plugin->track->automation->get_camera(x, y, z, position, direction);
1182 void PluginServer::get_projector(float *x, float *y, float *z,
1183 int64_t position, int direction)
1185 plugin->track->automation->get_projector(x, y, z, position, direction);
1189 int PluginServer::get_interpolation_type()
1191 return plugin->edl->session->interpolation_type;
1194 Theme* PluginServer::new_theme()
1198 return client->new_theme();
1204 Theme* PluginServer::get_theme()
1206 if(mwindow) return mwindow->theme;
1207 printf("PluginServer::get_theme mwindow not set\n");
1212 int PluginServer::get_theme_png_path(char *png_path, const char *theme_dir)
1214 char *bp = strrchr(path, '/');
1215 if( !bp ) bp = path; else ++bp;
1216 char *sp = strrchr(bp,'.');
1217 if( !sp || ( strcmp(sp, ".plugin") && strcmp(sp,".so") ) ) return 0;
1218 char *cp = png_path, *dp = bp;
1219 cp += sprintf(cp,"%s/%s/", mwindow->preferences->plugin_dir, theme_dir);
1220 while( dp < sp ) *cp++ = *dp++;
1223 if( stat(png_path, &st) ) return 0;
1224 if( !S_ISREG(st.st_mode) ) return 0;
1225 if( st.st_size == 0 ) return 0;
1229 int PluginServer::get_theme_png_path(char *png_path, Theme *theme)
1231 char *bp = strrchr(theme->path, '/');
1232 if( !bp ) bp = theme->path; else ++bp;
1233 char *sp = strrchr(bp,'.');
1234 if( !sp || ( strcmp(sp, ".plugin") && strcmp(sp,".so") ) ) return 0;
1235 char theme_dir[BCTEXTLEN], *cp = theme_dir;
1236 while( bp < sp ) *cp++ = *bp++;
1238 return get_theme_png_path(png_path, theme_dir);
1241 int PluginServer::get_plugin_png_path(char *png_path)
1243 int len = get_theme_png_path(png_path, mwindow->theme);
1245 len = get_theme_png_path(png_path, "picon");
1249 VFrame *PluginServer::get_plugin_images()
1251 char png_path[BCTEXTLEN];
1252 int len = get_plugin_png_path(png_path);
1253 if( !len ) return 0;
1254 int ret = 0, w = 0, h = 0;
1255 unsigned char *bfr = 0;
1256 int fd = ::open(png_path, O_RDONLY);
1257 if( fd < 0 ) ret = 1;
1259 bfr = (unsigned char *) ::mmap (NULL, len, PROT_READ, MAP_SHARED, fd, 0);
1260 if( bfr == MAP_FAILED ) ret = 1;
1264 double scale = BC_WindowBase::get_resources()->icon_scale;
1265 vframe = new VFramePng(bfr, len, scale, scale);
1266 if( (w=vframe->get_w()) <= 0 || (h=vframe->get_h()) <= 0 ||
1267 vframe->get_data() == 0 ) ret = 1;
1269 if( bfr && bfr != MAP_FAILED ) ::munmap(bfr, len);
1270 if( fd >= 0 ) ::close(fd);
1271 if( ret ) { delete vframe; vframe = 0; }
1275 VFrame *PluginServer::get_picon()
1278 picon = get_plugin_images();
1282 // Called when plugin interface is tweeked
1283 void PluginServer::sync_parameters()
1285 if(video) mwindow->restart_brender();
1286 mwindow->sync_parameters();
1287 mwindow->update_keyframe_guis();
1288 if(mwindow->edl->session->auto_conf->plugins)
1290 mwindow->gui->lock_window("PluginServer::sync_parameters");
1291 mwindow->gui->draw_overlays(1);
1292 mwindow->gui->unlock_window();
1298 void PluginServer::dump(FILE *fp)
1300 fprintf(fp," PluginServer %d %p %s %s %d\n",
1301 __LINE__, this, path, title, realtime);