4 * Copyright (C) 2008-2013 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
23 #include "automation.h"
25 #include "commonrender.h"
26 #include "condition.h"
28 #include "edlsession.h"
32 #include "playabletracks.h"
33 #include "renderengine.h"
35 #include "transportque.h"
36 #include "virtualconsole.h"
37 #include "virtualnode.h"
40 VirtualConsole::VirtualConsole(RenderEngine *renderengine,
41 CommonRender *commonrender,
44 this->renderengine = renderengine;
45 this->commonrender = commonrender;
46 this->data_type = data_type;
51 //printf("VirtualConsole::VirtualConsole\n");
55 VirtualConsole::~VirtualConsole()
57 delete_virtual_console();
59 delete playable_tracks;
60 //printf("VirtualConsole::~VirtualConsole\n");
64 void VirtualConsole::create_objects()
69 get_playable_tracks();
70 total_exit_nodes = playable_tracks->size();
71 build_virtual_console(1);
75 void VirtualConsole::start_playback()
81 void VirtualConsole::get_playable_tracks()
85 Module* VirtualConsole::module_of(Track *track)
87 for(int i = 0; i < commonrender->total_modules; i++)
89 if(commonrender->modules[i]->track == track)
90 return commonrender->modules[i];
95 Module* VirtualConsole::module_number(int track_number)
97 // The track number is an absolute number of the track independant of
98 // the tracks with matching data type but virtual modules only exist for
99 // the matching data type.
100 // Convert from absolute track number to data type track number.
101 Track *current = renderengine->get_edl()->tracks->first;
102 int data_type_number = 0, number = 0;
104 for( ; current; current = NEXT, number++)
106 if(current->data_type == data_type)
108 if(number == track_number)
109 return commonrender->modules[data_type_number];
119 void VirtualConsole::build_virtual_console(int persistent_plugins)
121 // allocate the entry nodes
124 entry_nodes = new VirtualNode*[total_exit_nodes];
126 // printf("VirtualConsole::build_virtual_console %d total_exit_nodes=%d\n",
128 // total_exit_nodes);
129 for(int i = 0; i < total_exit_nodes; i++)
131 // printf("VirtualConsole::build_virtual_console %d track=%p module=%p\n",
133 // playable_tracks->get(i),
134 // module_of(playable_tracks->get(i)));
135 entry_nodes[i] = new_entry_node(playable_tracks->get(i),
136 module_of(playable_tracks->get(i)),
140 entry_nodes[i]->expand(persistent_plugins,
141 commonrender->current_position);
143 commonrender->restart_plugins = 1;
148 VirtualNode* VirtualConsole::new_entry_node(Track *track,
152 printf("VirtualConsole::new_entry_node should not be called\n");
156 void VirtualConsole::append_exit_node(VirtualNode *node)
159 exit_nodes.append(node);
162 void VirtualConsole::reset_attachments()
164 for(int i = 0; i < commonrender->total_modules; i++)
166 commonrender->modules[i]->reset_attachments();
170 void VirtualConsole::dump()
172 printf("VirtualConsole\n");
173 printf(" Modules\n");
174 for(int i = 0; i < commonrender->total_modules; i++)
175 commonrender->modules[i]->dump();
177 for(int i = 0; i < total_exit_nodes; i++)
178 entry_nodes[i]->dump(0);
182 int VirtualConsole::test_reconfigure(int64_t position,
186 Track *current_track;
187 int direction = renderengine->command->get_direction();
189 // Test playback status against virtual console for current position.
190 for(current_track = renderengine->get_edl()->tracks->first;
191 current_track && !result;
192 current_track = current_track->next)
194 if(current_track->data_type == data_type)
196 // Playable status changed
197 if(playable_tracks->is_playable(current_track,
198 commonrender->current_position,
202 if(!playable_tracks->is_listed(current_track))
206 if(playable_tracks->is_listed(current_track))
213 // Test plugins against virtual console at current position
214 for(int i = 0; i < commonrender->total_modules && !result; i++)
215 result = commonrender->modules[i]->test_plugins();
221 // Now get the length of time until next reconfiguration.
222 // This part is not concerned with result.
223 // Don't clip input length if only rendering 1 frame.
224 if(length == 1) return result;
230 // GCC 3.2 requires this or optimization error results.
231 int64_t longest_duration1;
232 int64_t longest_duration2;
233 int64_t longest_duration3;
235 // Length of time until next transition, edit, or effect change.
236 // Why do we need the edit change? Probably for changing to and from silence.
237 for(current_track = renderengine->get_edl()->tracks->first;
239 current_track = current_track->next)
241 if(current_track->data_type == data_type)
243 // Test the transitions
244 longest_duration1 = current_track->edit_change_duration(
245 commonrender->current_position,
247 direction == PLAY_REVERSE,
253 longest_duration2 = current_track->edit_change_duration(
254 commonrender->current_position,
262 longest_duration3 = current_track->plugin_change_duration(
263 commonrender->current_position,
265 direction == PLAY_REVERSE,
268 if(longest_duration1 < length)
270 length = longest_duration1;
272 if(longest_duration2 < length)
274 length = longest_duration2;
276 if(longest_duration3 < length)
278 length = longest_duration3;
291 void VirtualConsole::delete_virtual_console()
293 // delete the virtual node tree
294 for(int i = 0; i < total_exit_nodes; i++)
296 delete entry_nodes[i];
298 // Seems to get allocated even if new[0].
299 if(entry_nodes) delete [] entry_nodes;
301 exit_nodes.remove_all();