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"
57 #include "transportque.h"
58 #include "vdevicex11.h"
60 #include "videodevice.h"
61 #include "virtualanode.h"
62 #include "virtualvnode.h"
70 #include <sys/types.h>
76 void PluginServer::init()
79 this->plugin_type = PLUGIN_TYPE_UNKNOWN;
80 plugin_obj = new PluginObj();
81 modules = new ArrayList<Module*>;
82 nodes = new ArrayList<VirtualNode*>;
88 PluginServer::PluginServer()
93 PluginServer::PluginServer(MWindow *mwindow, const char *path, int type)
95 char fpath[BCTEXTLEN];
97 this->plugin_type = type;
98 this->mwindow = mwindow;
99 if( type == PLUGIN_TYPE_FFMPEG ) {
100 ff_name = cstrdup(path);
101 sprintf(fpath, "ff_%s", path);
107 PluginServer::PluginServer(PluginServer &that)
110 plugin_type = that.plugin_type;
111 plugin_obj = that.plugin_obj;
112 plugin_obj->add_user();
113 title = !that.title ? 0 : cstrdup(that.title);
114 tip = !that.tip ? 0 : cstrdup(that.tip);
115 path = !that.path ? 0 : cstrdup(that.path);
116 ff_name = !that.ff_name ? 0 : cstrdup(that.ff_name);
117 modules = new ArrayList<Module*>;
118 nodes = new ArrayList<VirtualNode*>;
120 attachment = that.attachment;
121 realtime = that.realtime;
122 multichannel = that.multichannel;
123 preferences = that.preferences;
124 synthesis = that.synthesis;
128 fileio = that.fileio;
129 uses_gui = that.uses_gui;
130 mwindow = that.mwindow;
131 keyframe = that.keyframe;
132 new_plugin = that.new_plugin;
134 lad_descriptor = that.lad_descriptor;
135 lad_descriptor_function = that.lad_descriptor_function;
136 lad_index = that.lad_index;
139 PluginServer::~PluginServer()
149 plugin_obj->remove_user();
152 // Done only once at creation
153 int PluginServer::reset_parameters()
164 lad_descriptor_function = 0;
170 start_auto = end_auto = 0;
174 realtime = multichannel = fileio = 0;
176 audio = video = theme = 0;
183 for( int i=sizeof(args)/sizeof(args[0]); --i>=0; ) args[i] = 0;
198 // Done every time the plugin is opened or closed
199 int PluginServer::cleanup_plugin()
201 in_buffer_size = out_buffer_size = 0;
202 total_in_buffers = total_out_buffers = 0;
207 written_samples = written_frames = 0;
214 void PluginServer::set_mwindow(MWindow *mwindow)
216 this->mwindow = mwindow;
219 void PluginServer::set_attachmentpoint(AttachmentPoint *attachmentpoint)
221 this->attachmentpoint = attachmentpoint;
224 void PluginServer::set_keyframe(KeyFrame *keyframe)
226 this->keyframe = keyframe;
229 void PluginServer::set_prompt(MenuEffectPrompt *prompt)
231 this->prompt = prompt;
234 void PluginServer::set_lad_index(int i)
239 int PluginServer::get_lad_index()
241 return this->lad_index;
244 int PluginServer::is_unknown()
246 return plugin_type == PLUGIN_TYPE_UNKNOWN ? 1 : 0;
249 int PluginServer::is_executable()
251 return plugin_type == PLUGIN_TYPE_EXECUTABLE ? 1 : 0;
254 int PluginServer::is_builtin()
256 return plugin_type == PLUGIN_TYPE_BUILTIN ? 1 : 0;
259 int PluginServer::is_ladspa()
261 return plugin_type == PLUGIN_TYPE_LADSPA ? 1 : 0;
264 int PluginServer::is_ffmpeg()
266 return plugin_type == PLUGIN_TYPE_FFMPEG ? 1 : 0;
269 int PluginServer::is_lv2()
271 return plugin_type == PLUGIN_TYPE_LV2 ? 1 : 0;
274 void PluginServer::set_path(const char *path)
276 delete [] this->path;
277 this->path = cstrdup(path);
280 char* PluginServer::get_path()
285 int PluginServer::get_synthesis()
291 void PluginServer::set_title(const char *string)
294 title = cstrdup(string);
297 void PluginServer::generate_display_title(char *string)
299 char ltitle[BCTEXTLEN];
300 if( BC_Resources::locale_utf8 )
301 strcpy(ltitle, _(title));
303 BC_Resources::encode(BC_Resources::encoding, 0,
304 _(title),strlen(title)+1, ltitle,BCTEXTLEN);
305 Plugin *plugin = edl->tracks->plugin_exists(plugin_id);
306 if( plugin && plugin->track )
307 sprintf(string, "%s: %s", plugin->track->title, ltitle);
309 strcpy(string, ltitle);
312 void *PluginObj::load(const char *plugin_dir, const char *path)
314 char dlpath[BCTEXTLEN], *dp = dlpath;
315 const char *cp = path;
317 const char *bp = plugin_dir;
318 while( *bp ) *dp++ = *bp++;
321 while( *cp ) *dp++ = *cp++;
323 return dlobj = load(dlpath);
326 int PluginServer::load_obj()
328 void *obj = plugin_obj->obj();
329 if( !obj ) obj =plugin_obj->load(preferences->plugin_dir, path);
333 const char *PluginServer::load_error()
335 return plugin_obj->load_error();
338 void *PluginServer::get_sym(const char *sym)
340 if( !plugin_obj->obj() ) return 0;
341 return plugin_obj->load_sym(sym);
344 // Open plugin for signal processing
345 int PluginServer::open_plugin(int master,
346 Preferences *preferences,
350 if( plugin_open ) return 0;
352 this->preferences = preferences;
353 this->plugin_id = plugin ? plugin->orig_id : -1;
355 if( !is_ffmpeg() && !is_lv2() && !is_executable() && !load_obj() ) {
356 // If the load failed, can't use error string to detect executable
357 // because locale and language selection changes the load_error() message
358 // if( !strstr(string, "executable") ) { set_title(path); plugin_type = PLUGIN_TYPE_EXECUTABLE; }
359 eprintf("PluginServer::open_plugin: load_obj %s = %s\n", path, load_error());
360 return PLUGINSERVER_NOT_RECOGNIZED;
362 if( is_unknown() || is_builtin() ) {
364 (PluginClient* (*)(PluginServer*)) get_sym("new_plugin");
366 plugin_type = PLUGIN_TYPE_BUILTIN;
368 if( is_unknown() || is_ladspa() ) {
369 lad_descriptor_function =
370 (LADSPA_Descriptor_Function) get_sym("ladspa_descriptor");
371 if( lad_descriptor_function ) {
372 if( lad_index < 0 ) return PLUGINSERVER_IS_LAD;
373 lad_descriptor = lad_descriptor_function(lad_index);
374 if( !lad_descriptor )
375 return PLUGINSERVER_NOT_RECOGNIZED;
376 plugin_type = PLUGIN_TYPE_LADSPA;
380 fprintf(stderr, "PluginServer::open_plugin "
381 " %d: plugin undefined in %s\n", __LINE__, path);
382 return PLUGINSERVER_NOT_RECOGNIZED;
384 switch( plugin_type ) {
385 case PLUGIN_TYPE_EXECUTABLE:
386 return PLUGINSERVER_OK;
387 case PLUGIN_TYPE_BUILTIN:
388 client = new_plugin(this);
390 case PLUGIN_TYPE_FFMPEG:
391 client = new_ffmpeg_plugin();
393 case PLUGIN_TYPE_LADSPA:
394 client = new PluginAClientLAD(this);
396 case PLUGIN_TYPE_LV2:
397 client = new_lv2_plugin();
404 return PLUGINSERVER_NOT_RECOGNIZED;
406 // Run initialization functions
407 realtime = client->is_realtime();
408 // Don't load defaults when probing the directory.
411 client->load_defaults_xml();
413 client->load_defaults();
415 audio = client->is_audio();
416 video = client->is_video();
417 theme = client->is_theme();
418 fileio = client->is_fileio();
419 uses_gui = client->uses_gui();
420 multichannel = client->is_multichannel();
421 synthesis = client->is_synthesis();
422 transition = client->is_transition();
423 set_title(client->plugin_title());
425 //printf("PluginServer::open_plugin 2\n");
427 return PLUGINSERVER_OK;
430 int PluginServer::close_plugin()
432 if( !plugin_open ) return 0;
439 void PluginServer::client_side_close()
441 // Last command executed in client thread
442 Plugin *plugin = edl->tracks->plugin_exists(plugin_id);
444 mwindow->hide_plugin(plugin, 1);
446 prompt->lock_window();
448 prompt->unlock_window();
452 void PluginServer::render_stop()
455 client->render_stop();
456 send_reset_gui_frames();
459 void PluginServer::write_table(FILE *fp, const char *path, int idx, int64_t mtime)
462 fprintf(fp, "%d \"%s\" \"%s\" %jd %d %d %d %d %d %d %d %d %d %d %d\n",
463 plugin_type, path, title, mtime, idx, audio, video, theme, realtime,
464 fileio, uses_gui, multichannel, synthesis, transition, lad_index);
467 int PluginServer::scan_table(char *text, int &type, char *path, char *title, int64_t &mtime)
469 int n = sscanf(text, "%d \"%[^\"]\" \"%[^\"]\" %jd", &type, path, title, &mtime);
470 return n < 4 ? 1 : 0;
473 int PluginServer::read_table(char *text)
475 char path[BCTEXTLEN], title[BCTEXTLEN];
477 int n = sscanf(text, "%d \"%[^\"]\" \"%[^\"]\" %jd %d %d %d %d %d %d %d %d %d %d %d",
478 &plugin_type, path, title, &mtime, &dir_idx, &audio, &video, &theme, &realtime,
479 &fileio, &uses_gui, &multichannel, &synthesis, &transition, &lad_index);
480 if( n != 15 ) return 1;
485 int PluginServer::init_realtime(int realtime_sched,
486 int total_in_buffers,
490 if( !plugin_open ) return 0;
492 // set for realtime priority
494 // Call start_realtime
495 this->total_in_buffers = this->total_out_buffers = total_in_buffers;
496 client->plugin_init_realtime(realtime_sched,
504 // Replaced by pull method but still needed for transitions
505 void PluginServer::process_transition(VFrame *input,
507 int64_t current_position,
510 if( !plugin_open ) return;
511 PluginVClient *vclient = (PluginVClient*)client;
515 vclient->source_position = current_position;
516 vclient->source_start = 0;
517 vclient->total_len = total_len;
519 vclient->input = new VFrame*[1];
520 vclient->output = new VFrame*[1];
522 vclient->input[0] = input;
523 vclient->output[0] = output;
525 vclient->process_realtime(input, output);
527 delete [] vclient->input;
528 delete [] vclient->output;
532 void PluginServer::process_transition(Samples *input,
534 int64_t current_position,
535 int64_t fragment_size,
538 if( !plugin_open ) return;
539 PluginAClient *aclient = (PluginAClient*)client;
541 aclient->source_position = current_position;
542 aclient->total_len = total_len;
543 aclient->source_start = 0;
544 aclient->process_realtime(fragment_size,
550 void PluginServer::process_buffer(VFrame **frame,
551 int64_t current_position,
556 if( !plugin_open ) return;
557 PluginVClient *vclient = (PluginVClient*)client;
558 vclient->in_buffer_size = vclient->out_buffer_size = 1;
559 vclient->source_position = current_position;
560 vclient->total_len = total_len;
561 vclient->frame_rate = frame_rate;
562 vclient->input = new VFrame*[total_in_buffers];
563 vclient->output = new VFrame*[total_in_buffers];
564 for( int i = 0; i < total_in_buffers; i++ ) {
565 vclient->input[i] = frame[i];
566 vclient->output[i] = frame[i];
569 Plugin *plugin = edl->tracks->plugin_exists(plugin_id);
571 vclient->source_start = (int64_t)plugin->startproject *
572 frame_rate / vclient->project_frame_rate;
574 vclient->direction = direction;
577 //printf("plugin=%p source_start=%ld\n", plugin, vclient->source_start);
578 // vclient->begin_process_buffer();
580 vclient->process_buffer(frame, current_position, frame_rate);
582 vclient->process_buffer(frame[0], current_position, frame_rate);
583 // vclient->end_process_buffer();
585 for( int i = 0; i < total_in_buffers; i++ )
586 frame[i]->push_prev_effect(title);
588 delete [] vclient->input;
589 delete [] vclient->output;
595 void PluginServer::process_buffer(Samples **buffer,
596 int64_t current_position,
597 int64_t fragment_size,
602 if( !plugin_open ) return;
603 PluginAClient *aclient = (PluginAClient*)client;
604 aclient->source_position = current_position;
605 aclient->total_len = total_len;
606 aclient->sample_rate = sample_rate;
607 aclient->in_buffer_size = aclient->out_buffer_size = fragment_size;
608 aclient->output_buffers = buffer;
610 Plugin *plugin = edl->tracks->plugin_exists(plugin_id);
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;
665 PluginGUIs::~PluginGUIs()
669 void PluginGUIs::append(PluginServer *server)
671 server->gui_id = EDL::next_id();
672 ArrayList<PluginServer*>::append(server);
675 PluginServer *PluginGUIs::gui_server(int gui_id)
677 for( int i=0; i<size(); ++i ) {
678 PluginServer *plugin_server = get(i);
679 if( plugin_server->gui_id == gui_id )
680 return plugin_server;
686 void PluginServer::reset_gui_frames()
688 Plugin *plugin = edl->tracks->plugin_exists(plugin_id);
690 mwindow->reset_plugin_gui_frames(plugin);
693 void PluginServer::reset_plugin_gui_frames()
695 if( !client ) return;
696 client->plugin_reset_gui_frames();
699 void PluginServer::render_gui_frames(PluginClientFrames *frames)
701 Plugin *plugin = edl->tracks->plugin_exists(plugin_id);
703 mwindow->render_plugin_gui_frames(frames, plugin);
706 void PluginServer::render_plugin_gui_frames(PluginClientFrames *frames)
708 if( !client ) return;
709 client->plugin_render_gui_frames(frames);
712 MainProgressBar* PluginServer::start_progress(char *string, int64_t length)
714 mwindow->gui->lock_window();
715 MainProgressBar *result = mwindow->mainprogress->start_progress(string, length);
716 mwindow->gui->unlock_window();
720 int64_t PluginServer::get_written_samples()
722 if( !plugin_open ) return 0;
723 return written_samples;
726 int64_t PluginServer::get_written_frames()
728 if( !plugin_open ) return 0;
729 return written_frames;
733 // ======================= Non-realtime plugin
735 int PluginServer::get_parameters(int64_t start, int64_t end, int channels)
737 if( !plugin_open ) return 0;
739 client->start = start;
741 client->source_start = start;
742 client->total_len = end - start;
743 client->total_in_buffers = channels;
746 //printf(" source_start=%ld total_len=%ld\n", client->source_start, client->total_len);
748 return client->plugin_get_parameters();
751 int PluginServer::set_interactive()
753 if( !plugin_open ) return 0;
754 client->set_interactive();
758 void PluginServer::append_module(Module *module)
760 modules->append(module);
763 void PluginServer::append_node(VirtualNode *node)
768 void PluginServer::reset_nodes()
773 int PluginServer::set_error()
779 int PluginServer::set_realtime_sched()
781 //struct sched_param params;
782 //params.sched_priority = 1;
783 //sched_setscheduler(0, SCHED_RR, ¶m);
788 int PluginServer::process_loop(VFrame **buffers, int64_t &write_length)
790 if( !plugin_open ) return 1;
791 return client->plugin_process_loop(buffers, write_length);
794 int PluginServer::process_loop(Samples **buffers, int64_t &write_length)
796 if( !plugin_open ) return 1;
797 return client->plugin_process_loop(buffers, write_length);
801 int PluginServer::start_loop(int64_t start,
806 if( !plugin_open ) return 0;
807 client->plugin_start_loop(start, end, buffer_size, total_buffers);
811 int PluginServer::stop_loop()
813 if( !plugin_open ) return 0;
814 return client->plugin_stop_loop();
817 int PluginServer::read_frame(VFrame *buffer,
819 int64_t start_position)
821 ((VModule*)modules->values[channel])->render(buffer,
822 start_position, PLAY_FORWARD,
823 mwindow->edl->session->frame_rate, 0, 0);
827 int PluginServer::read_samples(Samples *buffer,
828 int channel, int64_t sample_rate, int64_t start_position, int64_t len)
830 // len is now in buffer
831 if( !multichannel ) channel = 0;
833 if( nodes->total > channel )
834 return ((VirtualANode*)nodes->values[channel])->read_data(buffer,
835 len, start_position, sample_rate);
836 if( modules->total > channel )
837 return ((AModule*)modules->values[channel])->render(buffer,
838 len, start_position, PLAY_FORWARD, sample_rate, 0);
839 printf("PluginServer::read_samples no object available for channel=%d\n",
845 int PluginServer::read_samples(Samples *buffer,
846 int channel, int64_t start_position, int64_t size)
848 // total_samples is now set in buffer
849 ((AModule*)modules->values[channel])->render(buffer,
850 size, start_position, PLAY_FORWARD,
851 mwindow->edl->session->sample_rate, 0);
855 int PluginServer::read_frame(VFrame *buffer,
856 int channel, int64_t start_position, double frame_rate,
859 // Data source depends on whether we're part of a virtual console or a
863 // If we're a VirtualNode, read_data in the virtual plugin node handles
864 // backward propogation and produces the data.
865 // If we're a Module, render in the module produces the data.
869 if( !multichannel ) channel = 0;
871 // Push our name on the next effect stack
872 buffer->push_next_effect(title);
873 //printf("PluginServer::read_frame %p\n", buffer);
874 //buffer->dump_stacks();
876 if( nodes->total > channel ) {
877 //printf("PluginServer::read_frame %d\n", __LINE__);
878 result = ((VirtualVNode*)nodes->values[channel])->read_data(buffer,
879 start_position, frame_rate, use_opengl);
882 if( modules->total > channel ) {
883 //printf("PluginServer::read_frame %d\n", __LINE__);
884 result = ((VModule*)modules->values[channel])->render(buffer,
885 start_position, // PLAY_FORWARD,
886 client->direction, frame_rate, 0, 0, use_opengl);
889 printf("PluginServer::read_frame no object available for channel=%d\n",
893 // Pop our name from the next effect stack
894 buffer->pop_next_effect();
901 int PluginServer::get_gui_status()
903 Plugin *plugin = edl->tracks->plugin_exists(plugin_id);
905 return plugin->show ? GUI_ON : GUI_OFF;
910 void PluginServer::raise_window()
912 if( !plugin_open ) return;
913 client->raise_window();
916 void PluginServer::show_gui()
918 if( !plugin_open ) return;
919 Plugin *plugin = edl->tracks->plugin_exists(plugin_id);
921 plugin->gui_id = gui_id;
922 client->total_len = plugin->length;
923 client->source_start = plugin->startproject;
926 client->source_position = Units::to_int64(
927 mwindow->edl->local_session->get_selectionstart(1) *
928 mwindow->edl->session->frame_rate);
932 client->source_position = Units::to_int64(
933 mwindow->edl->local_session->get_selectionstart(1) *
934 mwindow->edl->session->sample_rate);
937 client->update_display_title();
941 void PluginServer::hide_gui()
943 if( !plugin_open ) return;
944 Plugin *plugin = edl->tracks->plugin_exists(plugin_id);
945 if( plugin ) plugin->gui_id = -1;
946 if( client->defaults ) client->save_defaults();
950 void PluginServer::update_gui()
952 if( !plugin_open ) return;
953 Plugin *plugin = edl->tracks->plugin_exists(plugin_id);
954 if( !plugin ) return;
956 client->total_len = plugin->length;
957 client->source_start = plugin->startproject;
960 client->source_position = Units::to_int64(
961 mwindow->edl->local_session->get_selectionstart(1) *
962 mwindow->edl->session->frame_rate);
965 client->source_position = Units::to_int64(
966 mwindow->edl->local_session->get_selectionstart(1) *
967 mwindow->edl->session->sample_rate);
970 client->plugin_update_gui();
973 void PluginServer::update_title()
975 if( !plugin_open ) return;
977 client->update_display_title();
981 int PluginServer::set_string(char *string)
983 if( !plugin_open ) return 0;
985 client->set_string_client(string);
989 int PluginServer::gui_open()
991 if( attachmentpoint ) return attachmentpoint->gui_open();
995 void PluginServer::set_use_opengl(int value, VideoDevice *vdevice)
997 this->use_opengl = value;
998 this->vdevice = vdevice;
1001 int PluginServer::get_use_opengl()
1006 int PluginServer::to_ram(VFrame *vframe)
1008 if( vframe->get_opengl_state() == VFrame::RAM ) return 0;
1009 if( !vdevice ) return -1;
1010 VDeviceX11 *vdevice_x11 = (VDeviceX11*) vdevice->get_output_base();
1011 int vw = vframe->get_w(), vh = vframe->get_h();
1012 vdevice_x11->do_camera(vframe, vframe, 0,0,vw,vh, 0,0,vw,vh); // copy to ram
1016 void PluginServer::run_opengl(PluginClient *plugin_client)
1019 ((VDeviceX11*)vdevice->get_output_base())->run_plugin(plugin_client);
1022 // ============================= queries
1024 void PluginServer::get_defaults_path(char *path)
1026 char string2[BCTEXTLEN];
1027 switch( plugin_type ) {
1028 case PLUGIN_TYPE_FFMPEG:
1029 case PLUGIN_TYPE_LV2:
1030 strcpy(string2, title);
1032 case PLUGIN_TYPE_BUILTIN:
1033 case PLUGIN_TYPE_LADSPA:
1034 default: { // Get plugin name from path
1035 char *ptr1 = strrchr(get_path(), '/');
1036 char *ptr2 = strrchr(get_path(), '.');
1037 if( !ptr1 ) ptr1 = get_path();
1038 if( !ptr2 ) ptr2 = get_path() + strlen(get_path());
1039 char *ptr3 = string2;
1040 while( ptr1 < ptr2 ) *ptr3++ = *ptr1++;
1044 sprintf(path, "%s/%s.xml", File::get_config_path(), string2);
1047 void PluginServer::save_defaults()
1049 if( client ) client->save_defaults();
1052 int PluginServer::get_samplerate()
1054 if( !plugin_open ) return 0;
1056 return client->get_samplerate();
1058 return mwindow->edl->session->sample_rate;
1059 printf("PluginServer::get_samplerate audio and mwindow == NULL\n");
1064 double PluginServer::get_framerate()
1066 if( !plugin_open ) return 0;
1068 return client->get_framerate();
1070 return mwindow->edl->session->frame_rate;
1071 printf("PluginServer::get_framerate video and mwindow == NULL\n");
1075 int PluginServer::get_project_samplerate()
1078 return mwindow->edl->session->sample_rate;
1080 return edl->session->sample_rate;
1081 printf("PluginServer::get_project_samplerate mwindow and edl are NULL.\n");
1085 double PluginServer::get_project_framerate()
1088 return mwindow->edl->session->frame_rate;
1090 return edl->session->frame_rate;
1091 printf("PluginServer::get_project_framerate mwindow and edl are NULL.\n");
1096 int PluginServer::detach_buffers()
1098 ring_buffers_out.remove_all();
1099 offset_out_render.remove_all();
1100 double_buffer_out_render.remove_all();
1101 realtime_out_size.remove_all();
1103 ring_buffers_in.remove_all();
1104 offset_in_render.remove_all();
1105 double_buffer_in_render.remove_all();
1106 realtime_in_size.remove_all();
1108 out_buffer_size = 0;
1110 total_out_buffers = 0;
1112 total_in_buffers = 0;
1116 int PluginServer::arm_buffer(int buffer_number,
1117 int64_t offset_in, int64_t offset_out,
1118 int double_buffer_in, int double_buffer_out)
1120 offset_in_render.values[buffer_number] = offset_in;
1121 offset_out_render.values[buffer_number] = offset_out;
1122 double_buffer_in_render.values[buffer_number] = double_buffer_in;
1123 double_buffer_out_render.values[buffer_number] = double_buffer_out;
1128 int PluginServer::set_automation(FloatAutos *autos, FloatAuto **start_auto, FloatAuto **end_auto, int reverse)
1130 this->autos = autos;
1131 this->start_auto = start_auto;
1132 this->end_auto = end_auto;
1133 this->reverse = reverse;
1139 void PluginServer::save_data(KeyFrame *keyframe)
1141 if( !plugin_open ) return;
1142 client->save_data(keyframe);
1145 KeyFrame* PluginServer::get_prev_keyframe(int64_t position)
1147 KeyFrame *result = 0;
1148 Plugin *plugin = edl->tracks->plugin_exists(plugin_id);
1150 result = plugin->get_prev_keyframe(position, client->direction);
1156 KeyFrame* PluginServer::get_next_keyframe(int64_t position)
1158 Plugin *plugin = edl->tracks->plugin_exists(plugin_id);
1159 KeyFrame *result = !plugin ? 0 :
1160 plugin->get_next_keyframe(position, client->direction);
1165 KeyFrame* PluginServer::get_keyframe()
1167 Plugin *plugin = edl->tracks->plugin_exists(plugin_id);
1169 // Realtime plugin case
1170 return plugin->get_keyframe();
1171 // Rendered plugin case
1176 void PluginServer::apply_keyframe(Plugin *plugin, KeyFrame *src)
1178 KeyFrame* dst = !plugin ? keyframe :
1179 plugin->is_transition() ? plugin->get_keyframe() : 0;
1181 if( edl->session->span_keyframes ) {
1182 double selection_start = edl->local_session->get_selectionstart(0);
1183 double selection_end = edl->local_session->get_selectionend(0);
1184 selection_start = edl->align_to_frame(selection_start, 0);
1185 selection_end = edl->align_to_frame(selection_end, 0);
1186 Track *track = plugin->track;
1187 int64_t start = track->to_units(selection_start, 1);
1188 int64_t end = track->to_units(selection_end, 1);
1189 if( start != end ) {
1190 client->span_keyframes(src, start, end);
1194 dst = get_keyframe();
1197 dst->copy_data(src);
1201 void PluginServer::get_camera(float *x, float *y, float *z,
1202 int64_t position, int direction)
1204 Plugin *plugin = edl->tracks->plugin_exists(plugin_id);
1206 plugin->track->automation->get_camera(x, y, z, position, direction);
1209 void PluginServer::get_projector(float *x, float *y, float *z,
1210 int64_t position, int direction)
1212 Plugin *plugin = edl->tracks->plugin_exists(plugin_id);
1214 plugin->track->automation->get_projector(x, y, z, position, direction);
1218 int PluginServer::get_interpolation_type()
1220 Plugin *plugin = edl->tracks->plugin_exists(plugin_id);
1222 return plugin->edl->session->interpolation_type;
1223 return NEAREST_NEIGHBOR;
1226 Theme* PluginServer::new_theme()
1229 return client->new_theme();
1233 Theme* PluginServer::get_theme()
1235 if( mwindow ) return mwindow->theme;
1236 printf("PluginServer::get_theme mwindow not set\n");
1241 void PluginServer::get_plugin_png_name(char *png_name)
1243 char *pp = png_name, *ep = pp + BCSTRLEN-1;
1244 char *cp = strrchr(path, '/');
1245 cp = !cp ? path : cp+1;
1246 char *sp = strrchr(cp, '.');
1247 if( !sp ) sp = cp+strlen(cp);
1248 while( pp < ep && cp < sp ) *pp++ = *cp++;
1249 snprintf(pp, ep-pp, ".png");
1252 int PluginServer::get_plugin_png_path(char *png_path, const char *plugin_icons)
1254 char png_name[BCSTRLEN];
1255 get_plugin_png_name(png_name);
1256 char *pp = png_path, *ep = pp + BCTEXTLEN-1;
1257 pp += snprintf(pp, ep-pp, "%s/picon/%s/%s",
1258 File::get_plugin_path(), plugin_icons, png_name);
1259 return access(png_path,R_OK) ? 1 : 0;
1262 int PluginServer::get_plugin_png_path(char *png_path)
1264 int ret = get_plugin_png_path(png_path, mwindow->preferences->plugin_icons);
1265 if( ret ) ret = get_plugin_png_path(png_path, DEFAULT_PICON);
1269 VFrame *PluginServer::get_plugin_images()
1271 char png_path[BCTEXTLEN];
1272 if( !get_plugin_png_path(png_path) )
1273 return VFramePng::vframe_png(png_path,0,0);
1274 char png_name[BCSTRLEN];
1275 get_plugin_png_name(png_name);
1276 unsigned char *data = mwindow->theme->get_image_data(png_name, 0);
1277 return data ? new VFramePng(data, 0.) : 0;
1280 VFrame *PluginServer::get_picon()
1283 picon = get_plugin_images();
1287 // Called when plugin interface is tweeked
1288 void PluginServer::sync_parameters()
1290 if( video ) mwindow->restart_brender();
1291 mwindow->sync_parameters();
1292 mwindow->update_keyframe_guis();
1293 if( mwindow->edl->session->auto_conf->plugins ) {
1294 mwindow->gui->lock_window("PluginServer::sync_parameters");
1295 mwindow->gui->draw_overlays(1);
1296 mwindow->gui->unlock_window();
1300 int64_t PluginServer::get_startproject()
1302 Plugin *plugin = edl->tracks->plugin_exists(plugin_id);
1303 return !plugin ? -1 : plugin->startproject;
1305 int64_t PluginServer::get_endproject()
1307 Plugin *plugin = edl->tracks->plugin_exists(plugin_id);
1308 return !plugin ? -1 : plugin->startproject + plugin->length;
1311 void PluginServer::dump(FILE *fp)
1313 fprintf(fp," PluginServer %d %p %s %s %d\n",
1314 __LINE__, this, path, title, realtime);