00001 #include "attachmentpoint.h"
00002 #include "bcsignals.h"
00003 #include "commonrender.h"
00004 #include "edl.h"
00005 #include "edlsession.h"
00006 #include "filexml.h"
00007 #include "module.h"
00008 #include "mwindow.h"
00009 #include "patch.h"
00010 #include "patchbay.h"
00011 #include "plugin.h"
00012 #include "pluginarray.h"
00013 #include "pluginserver.h"
00014 #include "renderengine.h"
00015 #include "sharedlocation.h"
00016 #include "track.h"
00017 #include "tracks.h"
00018 #include "transportque.h"
00019
00020
00021 Module::Module(RenderEngine *renderengine,
00022 CommonRender *commonrender,
00023 PluginArray *plugin_array,
00024 Track *track)
00025 {
00026 this->renderengine = renderengine;
00027 this->commonrender = commonrender;
00028 this->plugin_array = plugin_array;
00029 this->track = track;
00030 transition = 0;
00031 transition_server = 0;
00032 attachments = 0;
00033 total_attachments = 0;
00034 new_total_attachments = 0;
00035 new_attachments = 0;
00036 }
00037
00038 Module::~Module()
00039 {
00040 if(attachments)
00041 {
00042 for(int i = 0; i < track->plugin_set.total; i++)
00043 {
00044 if(attachments[i])
00045 {
00046
00047
00048 delete attachments[i];
00049 }
00050 }
00051 delete [] attachments;
00052 }
00053 if(transition_server)
00054 {
00055 transition_server->close_plugin();
00056 delete transition_server;
00057 }
00058 }
00059
00060 void Module::create_objects()
00061 {
00062 create_new_attachments();
00063 swap_attachments();
00064 }
00065
00066 EDL* Module::get_edl()
00067 {
00068 if(renderengine)
00069 return renderengine->edl;
00070 else
00071 return edl;
00072 }
00073
00074 void Module::create_new_attachments()
00075 {
00076
00077 if(commonrender)
00078 {
00079 new_total_attachments = track->plugin_set.total;
00080 if(new_total_attachments)
00081 {
00082 new_attachments = new AttachmentPoint*[new_total_attachments];
00083 for(int i = 0; i < new_total_attachments; i++)
00084 {
00085 Plugin *plugin =
00086 track->get_current_plugin(commonrender->current_position,
00087 i,
00088 renderengine->command->get_direction(),
00089 0,
00090 1);
00091
00092 if(plugin && plugin->plugin_type != PLUGIN_NONE && plugin->on)
00093 new_attachments[i] = new_attachment(plugin);
00094 else
00095 new_attachments[i] = 0;
00096 }
00097 }
00098 else
00099 new_attachments = 0;
00100
00101
00102 }
00103 }
00104
00105 void Module::swap_attachments()
00106 {
00107
00108 for(int i = 0;
00109 i < new_total_attachments &&
00110 i < total_attachments;
00111 i++)
00112 {
00113
00114
00115 if(new_attachments[i] &&
00116 attachments[i] &&
00117 new_attachments[i]->identical(attachments[i]))
00118 {
00119 delete new_attachments[i];
00120 new_attachments[i] = attachments[i];
00121 attachments[i] = 0;
00122 }
00123 }
00124
00125
00126 for(int i = 0; i < total_attachments; i++)
00127 {
00128 if(attachments[i]) delete attachments[i];
00129 }
00130
00131 if(attachments)
00132 {
00133 delete [] attachments;
00134 }
00135
00136 attachments = new_attachments;
00137 total_attachments = new_total_attachments;
00138 }
00139
00140 int Module::render_init()
00141 {
00142 for(int i = 0; i < total_attachments; i++)
00143 {
00144 if(attachments[i])
00145 attachments[i]->render_init();
00146 }
00147
00148 return 0;
00149 }
00150
00151 void Module::render_stop()
00152 {
00153 for(int i = 0; i < total_attachments; i++)
00154 {
00155 if(attachments[i])
00156 attachments[i]->render_stop();
00157 }
00158 }
00159
00160 AttachmentPoint* Module::attachment_of(Plugin *plugin)
00161 {
00162
00163 for(int i = 0; i < total_attachments; i++)
00164 {
00165
00166 if(attachments[i] &&
00167 attachments[i]->plugin == plugin) return attachments[i];
00168 }
00169 return 0;
00170 }
00171
00172 AttachmentPoint* Module::get_attachment(int number)
00173 {
00174 if(number < total_attachments)
00175 return attachments[number];
00176 else
00177 return 0;
00178 }
00179
00180 void Module::reset_attachments()
00181 {
00182
00183 for(int i = 0; i < total_attachments; i++)
00184 {
00185
00186 AttachmentPoint *attachment = attachments[i];
00187 if(attachment) attachment->reset_status();
00188 }
00189 }
00190
00191
00192
00193 int Module::test_plugins()
00194 {
00195 if(total_attachments != track->plugin_set.total) return 1;
00196
00197 for(int i = 0; i < total_attachments; i++)
00198 {
00199 AttachmentPoint *attachment = attachments[i];
00200 Plugin *plugin = track->get_current_plugin(
00201 commonrender->current_position,
00202 i,
00203 renderengine->command->get_direction(),
00204 0,
00205 1);
00206
00207 int use_plugin = plugin &&
00208 plugin->plugin_type != PLUGIN_NONE &&
00209 plugin->on;
00210
00211 if((attachment && !use_plugin) ||
00212 (!attachment && use_plugin)) return 1;
00213
00214
00215 if(plugin &&
00216 attachment &&
00217 attachment->plugin &&
00218 !plugin->identical(attachment->plugin)) return 1;
00219 }
00220
00221 return 0;
00222 }
00223
00224 void Module::update_transition(int64_t current_position,
00225 int direction)
00226 {
00227 transition = track->get_current_transition(current_position,
00228 direction,
00229 0,
00230 0);
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240 if (transition &&
00241 transition_server)
00242 {
00243 if (strcmp(transition->title, transition_server->plugin->title))
00244 {
00245 transition_server->close_plugin();
00246 delete transition_server;
00247 transition_server = 0;
00248 } else
00249 {
00250 transition_server->plugin = transition;
00251 }
00252 }
00253
00254 if(transition && !transition_server)
00255 {
00256 if(renderengine)
00257 {
00258 PluginServer *plugin_server = renderengine->scan_plugindb(transition->title,
00259 track->data_type);
00260 transition_server = new PluginServer(*plugin_server);
00261 transition_server->open_plugin(0,
00262 renderengine->preferences,
00263 get_edl(),
00264 transition,
00265 -1);
00266 transition_server->init_realtime(
00267 get_edl()->session->real_time_playback &&
00268 renderengine->command->realtime,
00269 1,
00270 get_buffer_size());
00271 }
00272 else
00273 if(plugin_array)
00274 {
00275 PluginServer *plugin_server = plugin_array->scan_plugindb(transition->title);
00276 transition_server = new PluginServer(*plugin_server);
00277 transition_server->open_plugin(0,
00278 plugin_array->mwindow->preferences,
00279 get_edl(),
00280 transition,
00281 -1);
00282 transition_server->init_realtime(
00283 0,
00284 1,
00285 get_buffer_size());
00286 }
00287 }
00288 }
00289
00290
00291 void Module::dump()
00292 {
00293 printf(" Module title=%s\n", track->title);
00294 printf(" Plugins total_attachments=%d\n", total_attachments);
00295 for(int i = 0; i < total_attachments; i++)
00296 {
00297 attachments[i]->dump();
00298 }
00299 }
00300
00301
00302
00303
00304
00305