fast drag mode honours follow_edits labels/plugins/keyframes
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / virtualvconsole.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "bcsignals.h"
23 #include "bctimer.h"
24 #include "datatype.h"
25 #include "edl.h"
26 #include "edlsession.h"
27 #include "mwindow.h"
28 #include "playabletracks.h"
29 #include "preferences.h"
30 #include "renderengine.h"
31 #include "tracks.h"
32 #include "transportque.h"
33 #include "vdevicex11.h"
34 #include "vframe.h"
35 #include "videodevice.h"
36 #include "virtualvconsole.h"
37 #include "virtualvnode.h"
38 #include "vmodule.h"
39 #include "vrender.h"
40 #include "vtrack.h"
41
42 VirtualVConsole::VirtualVConsole(RenderEngine *renderengine, VRender *vrender)
43  : VirtualConsole(renderengine, vrender, TRACK_VIDEO)
44 {
45         this->vrender = vrender;
46         output_temp = 0;
47 }
48
49 VirtualVConsole::~VirtualVConsole()
50 {
51         if(output_temp)
52         {
53                 delete output_temp;
54         }
55 }
56
57 VDeviceBase* VirtualVConsole::get_vdriver()
58 {
59         return renderengine->video->get_output_base();
60 }
61
62 void VirtualVConsole::get_playable_tracks()
63 {
64         if(!playable_tracks)
65                 playable_tracks = new PlayableTracks(renderengine->get_edl(),
66                         commonrender->current_position,
67                         renderengine->command->get_direction(),
68                         TRACK_VIDEO,
69                         1);
70 //printf("VirtualVConsole::get_playable_tracks %d %d\n", __LINE__, playable_tracks->size());
71 }
72
73 VirtualNode* VirtualVConsole::new_entry_node(Track *track,
74         Module *module,
75         int track_number)
76 {
77         return new VirtualVNode(renderengine,
78                 this,
79                 module,
80                 0,
81                 track,
82                 0);
83 }
84
85 // start of buffer in project if forward / end of buffer if reverse
86 int VirtualVConsole::process_buffer(int64_t input_position,
87         int use_opengl)
88 {
89         int result = 0;
90
91
92
93 // The use of single frame is determined in RenderEngine::arm_command
94 // printf("VirtualVConsole::process_buffer %d this=%p %d\n",
95 // __LINE__,
96 // this,
97 // use_opengl);
98
99         if(debug_tree)
100                 printf("VirtualVConsole::process_buffer %d exit_nodes=%d\n",
101                         __LINE__,
102                         exit_nodes.total);
103
104
105         if(use_opengl)
106         {
107 // clear hardware framebuffer
108
109                 ((VDeviceX11*)get_vdriver())->clear_output();
110
111 // que OpenGL driver that everything is overlaid in the framebuffer
112                 vrender->video_out->set_opengl_state(VFrame::SCREEN);
113
114         }
115         else
116         {
117 // clear device buffer
118 //printf("VirtualVConsole::process_buffer %d %p\n", __LINE__, vrender->video_out);
119 //vrender->video_out->dump();
120                 vrender->video_out->clear_frame();
121 //printf("VirtualVConsole::process_buffer %d\n", __LINE__);
122         }
123
124
125
126
127
128
129 // Reset plugin rendering status
130         reset_attachments();
131
132 //      Timer timer;
133 // Render exit nodes from bottom to top
134         for(current_exit_node = exit_nodes.total - 1; current_exit_node >= 0; current_exit_node--)
135         {
136                 VirtualVNode *node = (VirtualVNode*)exit_nodes.values[current_exit_node];
137                 Track *track = node->track;
138
139 // Create temporary output to match the track size, which is acceptable since
140 // most projects don't have variable track sizes.
141 // If the project has variable track sizes, this object is recreated for each track.
142
143
144
145
146
147                 if(output_temp &&
148                         (output_temp->get_w() != track->track_w ||
149                         output_temp->get_h() != track->track_h))
150                 {
151                         delete output_temp;
152                         output_temp = 0;
153                 }
154
155
156                 if(!output_temp)
157                 {
158 // Texture is created on demand
159                         output_temp = new VFrame( track->track_w, track->track_h,
160                                 renderengine->get_edl()->session->color_model);
161                 }
162
163 // Reset OpenGL state
164                 if(use_opengl)
165                         output_temp->set_opengl_state(VFrame::RAM);
166
167
168 // Assume openGL is used for the final stage and let console
169 // disable.
170                 output_temp->clear_stacks();
171                 result |= node->render(output_temp,
172                         input_position + track->nudge,
173                         renderengine->get_edl()->session->frame_rate,
174                         use_opengl);
175
176         }
177 //printf("VirtualVConsole::process_buffer timer=%jd\n", timer.get_difference());
178
179         if(debug_tree) printf("VirtualVConsole::process_buffer %d\n", __LINE__);
180         return result;
181 }
182