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*>;
86 PluginServer::PluginServer()
91 PluginServer::PluginServer(MWindow *mwindow, const char *path, int type)
93 char fpath[BCTEXTLEN];
95 this->plugin_type = type;
96 this->mwindow = mwindow;
97 if( type == PLUGIN_TYPE_FFMPEG ) {
98 ff_name = cstrdup(path);
99 sprintf(fpath, "ff_%s", path);
105 PluginServer::PluginServer(PluginServer &that)
108 plugin_type = that.plugin_type;
109 plugin_obj = that.plugin_obj;
110 plugin_obj->add_user();
111 title = !that.title ? 0 : cstrdup(that.title);
112 tip = !that.tip ? 0 : cstrdup(that.tip);
113 path = !that.path ? 0 : cstrdup(that.path);
114 ff_name = !that.ff_name ? 0 : cstrdup(that.ff_name);
115 modules = new ArrayList<Module*>;
116 nodes = new ArrayList<VirtualNode*>;
118 attachment = that.attachment;
119 realtime = that.realtime;
120 multichannel = that.multichannel;
121 preferences = that.preferences;
122 synthesis = that.synthesis;
126 fileio = that.fileio;
127 uses_gui = that.uses_gui;
128 mwindow = that.mwindow;
129 keyframe = that.keyframe;
130 new_plugin = that.new_plugin;
132 lad_descriptor = that.lad_descriptor;
133 lad_descriptor_function = that.lad_descriptor_function;
134 lad_index = that.lad_index;
137 PluginServer::~PluginServer()
147 plugin_obj->remove_user();
150 // Done only once at creation
151 int PluginServer::reset_parameters()
162 lad_descriptor_function = 0;
168 start_auto = end_auto = 0;
172 realtime = multichannel = fileio = 0;
174 audio = video = theme = 0;
181 for( int i=sizeof(args)/sizeof(args[0]); --i>=0; ) args[i] = 0;
196 // Done every time the plugin is opened or closed
197 int PluginServer::cleanup_plugin()
199 in_buffer_size = out_buffer_size = 0;
200 total_in_buffers = total_out_buffers = 0;
205 written_samples = written_frames = 0;
212 void PluginServer::set_mwindow(MWindow *mwindow)
214 this->mwindow = mwindow;
217 void PluginServer::set_attachmentpoint(AttachmentPoint *attachmentpoint)
219 this->attachmentpoint = attachmentpoint;
222 void PluginServer::set_keyframe(KeyFrame *keyframe)
224 this->keyframe = keyframe;
227 void PluginServer::set_prompt(MenuEffectPrompt *prompt)
229 this->prompt = prompt;
232 void PluginServer::set_lad_index(int i)
237 int PluginServer::get_lad_index()
239 return this->lad_index;
242 int PluginServer::is_unknown()
244 return plugin_type == PLUGIN_TYPE_UNKNOWN ? 1 : 0;
247 int PluginServer::is_executable()
249 return plugin_type == PLUGIN_TYPE_EXECUTABLE ? 1 : 0;
252 int PluginServer::is_builtin()
254 return plugin_type == PLUGIN_TYPE_BUILTIN ? 1 : 0;
257 int PluginServer::is_ladspa()
259 return plugin_type == PLUGIN_TYPE_LADSPA ? 1 : 0;
262 int PluginServer::is_ffmpeg()
264 return plugin_type == PLUGIN_TYPE_FFMPEG ? 1 : 0;
267 int PluginServer::is_lv2()
269 return plugin_type == PLUGIN_TYPE_LV2 ? 1 : 0;
272 void PluginServer::set_path(const char *path)
274 delete [] this->path;
275 this->path = cstrdup(path);
278 char* PluginServer::get_path()
283 int PluginServer::get_synthesis()
289 void PluginServer::set_title(const char *string)
292 title = cstrdup(string);
295 void PluginServer::generate_display_title(char *string)
297 char ltitle[BCTEXTLEN];
298 if( BC_Resources::locale_utf8 )
299 strcpy(ltitle, _(title));
301 BC_Resources::encode(BC_Resources::encoding, 0,
302 _(title),strlen(title)+1, ltitle,BCTEXTLEN);
303 if( plugin && plugin->track )
304 sprintf(string, "%s: %s", plugin->track->title, ltitle);
306 strcpy(string, ltitle);
309 void *PluginObj::load(const char *plugin_dir, const char *path)
311 char dlpath[BCTEXTLEN], *dp = dlpath;
312 const char *cp = path;
314 const char *bp = plugin_dir;
315 while( *bp ) *dp++ = *bp++;
318 while( *cp ) *dp++ = *cp++;
320 return dlobj = load(dlpath);
323 int PluginServer::load_obj()
325 void *obj = plugin_obj->obj();
326 if( !obj ) obj =plugin_obj->load(preferences->plugin_dir, path);
330 const char *PluginServer::load_error()
332 return plugin_obj->load_error();
335 void *PluginServer::get_sym(const char *sym)
337 if( !plugin_obj->obj() ) return 0;
338 return plugin_obj->load_sym(sym);
341 // Open plugin for signal processing
342 int PluginServer::open_plugin(int master,
343 Preferences *preferences,
347 if( plugin_open ) return 0;
349 this->preferences = preferences;
350 this->plugin = plugin;
352 if( !is_ffmpeg() && !is_lv2() && !is_executable() && !load_obj() ) {
353 // If the load failed, can't use error string to detect executable
354 // because locale and language selection changes the load_error() message
355 // if( !strstr(string, "executable") ) { set_title(path); plugin_type = PLUGIN_TYPE_EXECUTABLE; }
356 eprintf("PluginServer::open_plugin: load_obj %s = %s\n", path, load_error());
357 return PLUGINSERVER_NOT_RECOGNIZED;
359 if( is_unknown() || is_builtin() ) {
361 (PluginClient* (*)(PluginServer*)) get_sym("new_plugin");
363 plugin_type = PLUGIN_TYPE_BUILTIN;
365 if( is_unknown() || is_ladspa() ) {
366 lad_descriptor_function =
367 (LADSPA_Descriptor_Function) get_sym("ladspa_descriptor");
368 if( lad_descriptor_function ) {
369 if( lad_index < 0 ) return PLUGINSERVER_IS_LAD;
370 lad_descriptor = lad_descriptor_function(lad_index);
371 if( !lad_descriptor )
372 return PLUGINSERVER_NOT_RECOGNIZED;
373 plugin_type = PLUGIN_TYPE_LADSPA;
377 fprintf(stderr, "PluginServer::open_plugin "
378 " %d: plugin undefined in %s\n", __LINE__, path);
379 return PLUGINSERVER_NOT_RECOGNIZED;
381 switch( plugin_type ) {
382 case PLUGIN_TYPE_EXECUTABLE:
383 return PLUGINSERVER_OK;
384 case PLUGIN_TYPE_BUILTIN:
385 client = new_plugin(this);
387 case PLUGIN_TYPE_FFMPEG:
388 client = new_ffmpeg_plugin();
390 case PLUGIN_TYPE_LADSPA:
391 client = new PluginAClientLAD(this);
393 case PLUGIN_TYPE_LV2:
394 client = new_lv2_plugin();
401 return PLUGINSERVER_NOT_RECOGNIZED;
403 // Run initialization functions
404 realtime = client->is_realtime();
405 // Don't load defaults when probing the directory.
408 client->load_defaults_xml();
410 client->load_defaults();
412 audio = client->is_audio();
413 video = client->is_video();
414 theme = client->is_theme();
415 fileio = client->is_fileio();
416 uses_gui = client->uses_gui();
417 multichannel = client->is_multichannel();
418 synthesis = client->is_synthesis();
419 transition = client->is_transition();
420 set_title(client->plugin_title());
422 //printf("PluginServer::open_plugin 2\n");
424 return PLUGINSERVER_OK;
427 int PluginServer::close_plugin()
429 if( !plugin_open ) return 0;
432 // Defaults are saved in the thread.
433 // if( client->defaults ) client->save_defaults();
437 // shared object is persistent since plugin deletion would unlink its own object
443 void PluginServer::client_side_close()
445 // Last command executed in client thread
447 mwindow->hide_plugin(plugin, 1);
450 prompt->lock_window();
452 prompt->unlock_window();
456 void PluginServer::render_stop()
459 client->render_stop();
460 send_reset_gui_frames();
463 void PluginServer::write_table(FILE *fp, const char *path, int idx, int64_t mtime)
466 fprintf(fp, "%d \"%s\" \"%s\" %jd %d %d %d %d %d %d %d %d %d %d %d\n",
467 plugin_type, path, title, mtime, idx, audio, video, theme, realtime,
468 fileio, uses_gui, multichannel, synthesis, transition, lad_index);
471 int PluginServer::scan_table(char *text, int &type, char *path, char *title, int64_t &mtime)
473 int n = sscanf(text, "%d \"%[^\"]\" \"%[^\"]\" %jd", &type, path, title, &mtime);
474 return n < 4 ? 1 : 0;
477 int PluginServer::read_table(char *text)
479 char path[BCTEXTLEN], title[BCTEXTLEN];
481 int n = sscanf(text, "%d \"%[^\"]\" \"%[^\"]\" %jd %d %d %d %d %d %d %d %d %d %d %d",
482 &plugin_type, path, title, &mtime, &dir_idx, &audio, &video, &theme, &realtime,
483 &fileio, &uses_gui, &multichannel, &synthesis, &transition, &lad_index);
484 if( n != 15 ) return 1;
489 int PluginServer::init_realtime(int realtime_sched,
490 int total_in_buffers,
494 if( !plugin_open ) return 0;
496 // set for realtime priority
498 // Call start_realtime
499 this->total_in_buffers = this->total_out_buffers = total_in_buffers;
500 client->plugin_init_realtime(realtime_sched,
508 // Replaced by pull method but still needed for transitions
509 void PluginServer::process_transition(VFrame *input,
511 int64_t current_position,
514 if( !plugin_open ) return;
515 PluginVClient *vclient = (PluginVClient*)client;
517 vclient->source_position = current_position;
518 vclient->source_start = 0;
519 vclient->total_len = total_len;
521 vclient->input = new VFrame*[1];
522 vclient->output = new VFrame*[1];
524 vclient->input[0] = input;
525 vclient->output[0] = output;
527 vclient->process_realtime(input, output);
529 delete [] vclient->input;
530 delete [] vclient->output;
534 void PluginServer::process_transition(Samples *input,
536 int64_t current_position,
537 int64_t fragment_size,
540 if( !plugin_open ) return;
541 PluginAClient *aclient = (PluginAClient*)client;
543 aclient->source_position = current_position;
544 aclient->total_len = total_len;
545 aclient->source_start = 0;
546 aclient->process_realtime(fragment_size,
552 void PluginServer::process_buffer(VFrame **frame,
553 int64_t current_position,
558 if( !plugin_open ) return;
559 PluginVClient *vclient = (PluginVClient*)client;
560 vclient->in_buffer_size = vclient->out_buffer_size = 1;
561 vclient->source_position = current_position;
562 vclient->total_len = total_len;
563 vclient->frame_rate = frame_rate;
564 vclient->input = new VFrame*[total_in_buffers];
565 vclient->output = new VFrame*[total_in_buffers];
566 for( int i = 0; i < total_in_buffers; i++ ) {
567 vclient->input[i] = frame[i];
568 vclient->output[i] = frame[i];
572 vclient->source_start = (int64_t)plugin->startproject *
573 frame_rate / vclient->project_frame_rate;
575 vclient->direction = direction;
578 //printf("plugin=%p source_start=%ld\n", plugin, vclient->source_start);
579 // vclient->begin_process_buffer();
581 vclient->process_buffer(frame, current_position, frame_rate);
583 vclient->process_buffer(frame[0], current_position, frame_rate);
584 // vclient->end_process_buffer();
586 for( int i = 0; i < total_in_buffers; i++ )
587 frame[i]->push_prev_effect(title);
589 delete [] vclient->input;
590 delete [] vclient->output;
596 void PluginServer::process_buffer(Samples **buffer,
597 int64_t current_position,
598 int64_t fragment_size,
603 if( !plugin_open ) return;
604 PluginAClient *aclient = (PluginAClient*)client;
605 aclient->source_position = current_position;
606 aclient->total_len = total_len;
607 aclient->sample_rate = sample_rate;
608 aclient->in_buffer_size = aclient->out_buffer_size = fragment_size;
609 aclient->output_buffers = buffer;
612 aclient->source_start = plugin->startproject *
614 aclient->project_sample_rate;
616 aclient->direction = direction;
617 aclient->begin_process_buffer();
619 aclient->process_buffer(fragment_size,
620 buffer, current_position, sample_rate);
623 aclient->process_buffer(fragment_size,
624 buffer[0], current_position, sample_rate);
626 aclient->end_process_buffer();
630 void PluginServer::send_reset_gui_frames()
632 if( !attachmentpoint ) return;
633 attachmentpoint->reset_gui_frames(this);
636 void PluginServer::send_render_gui(void *data)
638 if( !attachmentpoint ) return;
639 attachmentpoint->render_gui(data, this);
642 void PluginServer::send_render_gui(void *data, int size)
644 if( !attachmentpoint ) return;
645 attachmentpoint->render_gui(data, size, this);
648 void PluginServer::render_gui(void *data)
650 if( !client ) return;
651 client->plugin_render_gui(data);
654 void PluginServer::render_gui(void *data, int size)
656 if( !client ) return;
657 client->plugin_render_gui(data, size);
661 PluginGUIs::PluginGUIs(MWindow *mwindow)
663 this->mwindow = mwindow;
666 PluginGUIs::~PluginGUIs()
670 void PluginGUIs::append(PluginServer *server)
672 server->gui_id = next_id++;
673 ArrayList<PluginServer*>::append(server);
676 PluginServer *PluginGUIs::gui_server(int gui_id)
678 for( int i=0; i<size(); ++i ) {
679 PluginServer *plugin_server = get(i);
680 if( plugin_server->gui_id == gui_id )
681 return plugin_server;
687 void PluginServer::reset_gui_frames()
689 mwindow->reset_plugin_gui_frames(plugin);
692 void PluginServer::reset_plugin_gui_frames()
694 if( !client ) return;
695 client->plugin_reset_gui_frames();
698 void PluginServer::render_gui_frames(PluginClientFrames *frames)
700 mwindow->render_plugin_gui_frames(frames, plugin);
703 void PluginServer::render_plugin_gui_frames(PluginClientFrames *frames)
705 if( !client ) return;
706 client->plugin_render_gui_frames(frames);
709 MainProgressBar* PluginServer::start_progress(char *string, int64_t length)
711 mwindow->gui->lock_window();
712 MainProgressBar *result = mwindow->mainprogress->start_progress(string, length);
713 mwindow->gui->unlock_window();
717 int64_t PluginServer::get_written_samples()
719 if( !plugin_open ) return 0;
720 return written_samples;
723 int64_t PluginServer::get_written_frames()
725 if( !plugin_open ) return 0;
726 return written_frames;
730 // ======================= Non-realtime plugin
732 int PluginServer::get_parameters(int64_t start, int64_t end, int channels)
734 if( !plugin_open ) return 0;
736 client->start = start;
738 client->source_start = start;
739 client->total_len = end - start;
740 client->total_in_buffers = channels;
743 //printf(" source_start=%ld total_len=%ld\n", client->source_start, client->total_len);
745 return client->plugin_get_parameters();
748 int PluginServer::set_interactive()
750 if( !plugin_open ) return 0;
751 client->set_interactive();
755 void PluginServer::append_module(Module *module)
757 modules->append(module);
760 void PluginServer::append_node(VirtualNode *node)
765 void PluginServer::reset_nodes()
770 int PluginServer::set_error()
776 int PluginServer::set_realtime_sched()
778 //struct sched_param params;
779 //params.sched_priority = 1;
780 //sched_setscheduler(0, SCHED_RR, ¶m);
785 int PluginServer::process_loop(VFrame **buffers, int64_t &write_length)
787 if( !plugin_open ) return 1;
788 return client->plugin_process_loop(buffers, write_length);
791 int PluginServer::process_loop(Samples **buffers, int64_t &write_length)
793 if( !plugin_open ) return 1;
794 return client->plugin_process_loop(buffers, write_length);
798 int PluginServer::start_loop(int64_t start,
803 if( !plugin_open ) return 0;
804 client->plugin_start_loop(start, end, buffer_size, total_buffers);
808 int PluginServer::stop_loop()
810 if( !plugin_open ) return 0;
811 return client->plugin_stop_loop();
814 int PluginServer::read_frame(VFrame *buffer,
816 int64_t start_position)
818 ((VModule*)modules->values[channel])->render(buffer,
819 start_position, PLAY_FORWARD,
820 mwindow->edl->session->frame_rate, 0, 0);
824 int PluginServer::read_samples(Samples *buffer,
825 int channel, int64_t sample_rate, int64_t start_position, int64_t len)
827 // len is now in buffer
828 if( !multichannel ) channel = 0;
830 if( nodes->total > channel )
831 return ((VirtualANode*)nodes->values[channel])->read_data(buffer,
832 len, start_position, sample_rate);
833 if( modules->total > channel )
834 return ((AModule*)modules->values[channel])->render(buffer,
835 len, start_position, PLAY_FORWARD, sample_rate, 0);
836 printf("PluginServer::read_samples no object available for channel=%d\n",
842 int PluginServer::read_samples(Samples *buffer,
843 int channel, int64_t start_position, int64_t size)
845 // total_samples is now set in buffer
846 ((AModule*)modules->values[channel])->render(buffer,
847 size, start_position, PLAY_FORWARD,
848 mwindow->edl->session->sample_rate, 0);
852 int PluginServer::read_frame(VFrame *buffer,
853 int channel, int64_t start_position, double frame_rate,
856 // Data source depends on whether we're part of a virtual console or a
860 // If we're a VirtualNode, read_data in the virtual plugin node handles
861 // backward propogation and produces the data.
862 // If we're a Module, render in the module produces the data.
866 if( !multichannel ) channel = 0;
868 // Push our name on the next effect stack
869 buffer->push_next_effect(title);
870 //printf("PluginServer::read_frame %p\n", buffer);
871 //buffer->dump_stacks();
873 if( nodes->total > channel ) {
874 //printf("PluginServer::read_frame %d\n", __LINE__);
875 result = ((VirtualVNode*)nodes->values[channel])->read_data(buffer,
876 start_position, frame_rate, use_opengl);
879 if( modules->total > channel ) {
880 //printf("PluginServer::read_frame %d\n", __LINE__);
881 result = ((VModule*)modules->values[channel])->render(buffer,
882 start_position, // PLAY_FORWARD,
883 client->direction, frame_rate, 0, 0, use_opengl);
886 printf("PluginServer::read_frame no object available for channel=%d\n",
890 // Pop our name from the next effect stack
891 buffer->pop_next_effect();
898 int PluginServer::get_gui_status()
901 return plugin->show ? GUI_ON : GUI_OFF;
906 void PluginServer::raise_window()
908 if( !plugin_open ) return;
909 client->raise_window();
912 void PluginServer::show_gui()
914 if( !plugin_open ) return;
916 plugin->gui_id = gui_id;
917 client->total_len = plugin->length;
918 client->source_start = plugin->startproject;
921 client->source_position = Units::to_int64(
922 mwindow->edl->local_session->get_selectionstart(1) *
923 mwindow->edl->session->frame_rate);
927 client->source_position = Units::to_int64(
928 mwindow->edl->local_session->get_selectionstart(1) *
929 mwindow->edl->session->sample_rate);
932 client->update_display_title();
936 void PluginServer::hide_gui()
938 if( !plugin_open ) return;
939 if( plugin ) plugin->gui_id = -1;
940 if( client->defaults ) client->save_defaults();
944 void PluginServer::update_gui()
946 if( !plugin_open || !plugin ) return;
948 client->total_len = plugin->length;
949 client->source_start = plugin->startproject;
952 client->source_position = Units::to_int64(
953 mwindow->edl->local_session->get_selectionstart(1) *
954 mwindow->edl->session->frame_rate);
957 client->source_position = Units::to_int64(
958 mwindow->edl->local_session->get_selectionstart(1) *
959 mwindow->edl->session->sample_rate);
962 client->plugin_update_gui();
965 void PluginServer::update_title()
967 if( !plugin_open ) return;
969 client->update_display_title();
973 int PluginServer::set_string(char *string)
975 if( !plugin_open ) return 0;
977 client->set_string_client(string);
981 int PluginServer::gui_open()
983 if( attachmentpoint ) return attachmentpoint->gui_open();
987 void PluginServer::set_use_opengl(int value, VideoDevice *vdevice)
989 this->use_opengl = value;
990 this->vdevice = vdevice;
993 int PluginServer::get_use_opengl()
999 void PluginServer::run_opengl(PluginClient *plugin_client)
1002 ((VDeviceX11*)vdevice->get_output_base())->run_plugin(plugin_client);
1005 // ============================= queries
1007 void PluginServer::get_defaults_path(char *path)
1009 // Get plugin name from path
1010 char *ptr1 = strrchr(get_path(), '/');
1011 char *ptr2 = strrchr(get_path(), '.');
1012 if( !ptr1 ) ptr1 = get_path();
1013 if( !ptr2 ) ptr2 = get_path() + strlen(get_path());
1014 char string2[BCTEXTLEN], *ptr3 = string2;
1015 while( ptr1 < ptr2 ) *ptr3++ = *ptr1++;
1017 sprintf(path, "%s/%s.xml", File::get_config_path(), string2);
1020 void PluginServer::save_defaults()
1022 if( client ) client->save_defaults();
1025 int PluginServer::get_samplerate()
1027 if( !plugin_open ) return 0;
1029 return client->get_samplerate();
1031 return mwindow->edl->session->sample_rate;
1032 printf("PluginServer::get_samplerate audio and mwindow == NULL\n");
1037 double PluginServer::get_framerate()
1039 if( !plugin_open ) return 0;
1041 return client->get_framerate();
1043 return mwindow->edl->session->frame_rate;
1044 printf("PluginServer::get_framerate video and mwindow == NULL\n");
1048 int PluginServer::get_project_samplerate()
1051 return mwindow->edl->session->sample_rate;
1053 return edl->session->sample_rate;
1054 printf("PluginServer::get_project_samplerate mwindow and edl are NULL.\n");
1058 double PluginServer::get_project_framerate()
1061 return mwindow->edl->session->frame_rate;
1063 return edl->session->frame_rate;
1064 printf("PluginServer::get_project_framerate mwindow and edl are NULL.\n");
1069 int PluginServer::detach_buffers()
1071 ring_buffers_out.remove_all();
1072 offset_out_render.remove_all();
1073 double_buffer_out_render.remove_all();
1074 realtime_out_size.remove_all();
1076 ring_buffers_in.remove_all();
1077 offset_in_render.remove_all();
1078 double_buffer_in_render.remove_all();
1079 realtime_in_size.remove_all();
1081 out_buffer_size = 0;
1083 total_out_buffers = 0;
1085 total_in_buffers = 0;
1089 int PluginServer::arm_buffer(int buffer_number,
1090 int64_t offset_in, int64_t offset_out,
1091 int double_buffer_in, int double_buffer_out)
1093 offset_in_render.values[buffer_number] = offset_in;
1094 offset_out_render.values[buffer_number] = offset_out;
1095 double_buffer_in_render.values[buffer_number] = double_buffer_in;
1096 double_buffer_out_render.values[buffer_number] = double_buffer_out;
1101 int PluginServer::set_automation(FloatAutos *autos, FloatAuto **start_auto, FloatAuto **end_auto, int reverse)
1103 this->autos = autos;
1104 this->start_auto = start_auto;
1105 this->end_auto = end_auto;
1106 this->reverse = reverse;
1112 void PluginServer::save_data(KeyFrame *keyframe)
1114 if( !plugin_open ) return;
1115 client->save_data(keyframe);
1118 KeyFrame* PluginServer::get_prev_keyframe(int64_t position)
1120 KeyFrame *result = 0;
1122 result = plugin->get_prev_keyframe(position, client->direction);
1128 KeyFrame* PluginServer::get_next_keyframe(int64_t position)
1130 KeyFrame *result = !plugin ? 0 :
1131 plugin->get_next_keyframe(position, client->direction);
1136 KeyFrame* PluginServer::get_keyframe()
1139 // Realtime plugin case
1140 return plugin->get_keyframe();
1141 // Rendered plugin case
1146 void PluginServer::apply_keyframe(KeyFrame *src)
1149 keyframe->copy_data(src);
1152 plugin->keyframes->update_parameter(src);
1156 void PluginServer::get_camera(float *x, float *y, float *z,
1157 int64_t position, int direction)
1159 plugin->track->automation->get_camera(x, y, z, position, direction);
1162 void PluginServer::get_projector(float *x, float *y, float *z,
1163 int64_t position, int direction)
1165 plugin->track->automation->get_projector(x, y, z, position, direction);
1169 int PluginServer::get_interpolation_type()
1171 return plugin->edl->session->interpolation_type;
1174 Theme* PluginServer::new_theme()
1177 return client->new_theme();
1181 Theme* PluginServer::get_theme()
1183 if( mwindow ) return mwindow->theme;
1184 printf("PluginServer::get_theme mwindow not set\n");
1189 void PluginServer::get_plugin_png_name(char *png_name)
1191 char *pp = png_name, *ep = pp + BCSTRLEN-1;
1192 char *cp = strrchr(path, '/');
1193 cp = !cp ? path : cp+1;
1194 char *sp = strrchr(cp, '.');
1195 if( !sp ) sp = cp+strlen(cp);
1196 while( pp < ep && cp < sp ) *pp++ = *cp++;
1197 snprintf(pp, ep-pp, ".png");
1200 int PluginServer::get_plugin_png_path(char *png_path, const char *plugin_icons)
1202 char png_name[BCSTRLEN];
1203 get_plugin_png_name(png_name);
1204 char *pp = png_path, *ep = pp + BCTEXTLEN-1;
1205 pp += snprintf(pp, ep-pp, "%s/picon/%s/%s",
1206 File::get_plugin_path(), plugin_icons, png_name);
1207 return access(png_path,R_OK) ? 1 : 0;
1210 int PluginServer::get_plugin_png_path(char *png_path)
1212 int ret = get_plugin_png_path(png_path, mwindow->preferences->plugin_icons);
1213 if( ret ) ret = get_plugin_png_path(png_path, DEFAULT_PICON);
1217 VFrame *PluginServer::get_plugin_images()
1219 char png_path[BCTEXTLEN];
1220 if( !get_plugin_png_path(png_path) )
1221 return VFramePng::vframe_png(png_path,0,0);
1222 char png_name[BCSTRLEN];
1223 get_plugin_png_name(png_name);
1224 unsigned char *data = mwindow->theme->get_image_data(png_name, 0);
1225 return data ? new VFramePng(data, 0.) : 0;
1228 VFrame *PluginServer::get_picon()
1231 picon = get_plugin_images();
1235 // Called when plugin interface is tweeked
1236 void PluginServer::sync_parameters()
1238 if( video ) mwindow->restart_brender();
1239 mwindow->sync_parameters();
1240 mwindow->update_keyframe_guis();
1241 if( mwindow->edl->session->auto_conf->plugins ) {
1242 mwindow->gui->lock_window("PluginServer::sync_parameters");
1243 mwindow->gui->draw_overlays(1);
1244 mwindow->gui->unlock_window();
1248 int64_t PluginServer::get_startproject()
1250 return !plugin ? -1 : plugin->startproject;
1252 int64_t PluginServer::get_endproject()
1254 return !plugin ? -1 : plugin->startproject + plugin->length;
1257 void PluginServer::dump(FILE *fp)
1259 fprintf(fp," PluginServer %d %p %s %s %d\n",
1260 __LINE__, this, path, title, realtime);