switch move/swap tracks, add mv trk shortcut, update msg
[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         delete output_temp;
52 }
53
54 VDeviceBase* VirtualVConsole::get_vdriver()
55 {
56         return renderengine->video->get_output_base();
57 }
58
59 void VirtualVConsole::get_playable_tracks()
60 {
61         if(!playable_tracks)
62                 playable_tracks = new PlayableTracks(renderengine->get_edl(),
63                         commonrender->current_position,
64                         renderengine->command->get_direction(),
65                         TRACK_VIDEO,
66                         1);
67 //printf("VirtualVConsole::get_playable_tracks %d %d\n", __LINE__, playable_tracks->size());
68 }
69
70 VirtualNode* VirtualVConsole::new_entry_node(Track *track,
71         Module *module,
72         int track_number)
73 {
74         return new VirtualVNode(renderengine,
75                 this,
76                 module,
77                 0,
78                 track,
79                 0);
80 }
81
82 // start of buffer in project if forward / end of buffer if reverse
83 int VirtualVConsole::process_buffer(int64_t input_position,
84         int use_opengl)
85 {
86         int result = 0;
87
88
89
90 // The use of single frame is determined in RenderEngine::arm_command
91 // printf("VirtualVConsole::process_buffer %d this=%p %d\n",
92 // __LINE__,
93 // this,
94 // use_opengl);
95
96         if(debug_tree)
97                 printf("VirtualVConsole::process_buffer %d exit_nodes=%d\n",
98                         __LINE__,
99                         exit_nodes.total);
100
101
102         EDLSession *session = renderengine->get_edl()->session;
103         int clr_color = session->cwindow_clear_color;
104         vrender->video_out->set_clear_color(clr_color, 0xff);
105
106         if(use_opengl)
107         {
108 // clear hardware framebuffer
109
110                 ((VDeviceX11*)get_vdriver())->clear_output();
111
112 // que OpenGL driver that everything is overlaid in the framebuffer
113                 vrender->video_out->set_opengl_state(VFrame::SCREEN);
114
115         }
116         else
117         {
118 // clear device buffer
119 //printf("VirtualVConsole::process_buffer %d %p\n", __LINE__, vrender->video_out);
120 //vrender->video_out->dump();
121                 vrender->video_out->clear_frame();
122 //printf("VirtualVConsole::process_buffer %d\n", __LINE__);
123         }
124
125
126
127
128
129
130 // Reset plugin rendering status
131         reset_attachments();
132
133 //      Timer timer;
134 // Render exit nodes from bottom to top
135         for(current_exit_node = exit_nodes.total - 1; current_exit_node >= 0; current_exit_node--)
136         {
137                 VirtualVNode *node = (VirtualVNode*)exit_nodes.values[current_exit_node];
138                 Track *track = node->track;
139
140 // Create temporary output to match the track size, which is acceptable since
141 // most projects don't have variable track sizes.
142 // If the project has variable track sizes, this object is recreated for each track.
143
144
145
146
147
148                 if(output_temp &&
149                         (output_temp->get_w() != track->track_w ||
150                         output_temp->get_h() != track->track_h))
151                 {
152                         delete output_temp;
153                         output_temp = 0;
154                 }
155
156
157                 if(!output_temp)
158                 {
159 // Texture is created on demand
160                         EDL *edl = renderengine->get_edl();
161                         output_temp = new VFrame( track->track_w, track->track_h,
162                                 edl->session->color_model);
163                 }
164
165 // Reset OpenGL state
166                 if(use_opengl)
167                         output_temp->set_opengl_state(VFrame::RAM);
168
169
170 // Assume openGL is used for the final stage and let console
171 // disable.
172                 output_temp->clear_stacks();
173                 result |= node->render(output_temp,
174                         input_position + track->nudge,
175                         renderengine->get_edl()->session->frame_rate,
176                         use_opengl);
177
178         }
179 //printf("VirtualVConsole::process_buffer timer=%jd\n", timer.get_difference());
180
181         if(debug_tree) printf("VirtualVConsole::process_buffer %d\n", __LINE__);
182         return result;
183 }
184