rework keyframe hide popup, keyframe auto render, textbox set_selection wide text
[goodguy/history.git] / cinelerra-5.1 / cinelerra / vpluginarray.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 "cache.h"
24 #include "edl.h"
25 #include "edlsession.h"
26 #include "file.h"
27 #include "mwindow.h"
28 #include "pluginserver.h"
29 #include "preferences.h"
30 #include "recordablevtracks.h"
31 #include "mainsession.h"
32 #include "vframe.h"
33 #include "vmodule.h"
34 #include "vpluginarray.h"
35 #include "vtrack.h"
36
37
38 #define RING_BUFFERS 2
39
40
41
42 VPluginArray::VPluginArray()
43  : PluginArray(TRACK_VIDEO)
44 {
45         realtime_buffers = 0;
46 }
47
48 VPluginArray::~VPluginArray()
49 {
50         file->stop_video_thread();
51         for(int i = 0; i < total_tracks(); i++)
52         {
53                 delete modules[i];
54         }
55         delete tracks;
56 }
57
58 void VPluginArray::get_recordable_tracks()
59 {
60         tracks = new RecordableVTracks(edl->tracks);
61 }
62
63 int64_t VPluginArray::get_bufsize()
64 {
65         return 1;
66 }
67
68 void VPluginArray::create_buffers()
69 {
70         file->start_video_thread(buffer_size,
71                 edl->session->color_model,
72                 RING_BUFFERS,
73                 0);
74 //      if(!plugin_server->realtime) realtime_buffers = file->get_video_buffer();
75 }
76
77 void VPluginArray::get_buffers()
78 {
79         if(!realtime_buffers) realtime_buffers = file->get_video_buffer();
80 }
81
82 void VPluginArray::create_modules()
83 {
84         modules = new Module*[total_tracks()];
85         for(int i = 0; i < total_tracks(); i++)
86         {
87                 modules[i] = new VModule(0, 0, this, tracks->values[i]);
88                 modules[i]->cache = cache;
89                 modules[i]->edl = edl;
90                 modules[i]->create_objects();
91                 modules[i]->render_init();
92         }
93 }
94
95
96 void VPluginArray::process_realtime(int module, 
97         int64_t input_position, 
98         int64_t len)
99 {
100         values[module]->process_buffer(realtime_buffers[module], 
101                         input_position, 
102                         edl->session->frame_rate,
103                         end - start,
104                         PLAY_FORWARD);
105 }
106
107 int VPluginArray::process_loop(int module, int64_t &write_length)
108 {
109         if(!realtime_buffers) realtime_buffers = file->get_video_buffer();
110
111 // Convert from array of frames to array of tracks
112         VFrame **temp_buffer;
113         temp_buffer = new VFrame*[total_tracks()];
114         for(int i = 0; i < total_tracks(); i++)
115         {
116                 temp_buffer[i] = realtime_buffers[i][0];
117         }
118
119         int result = values[module]->process_loop(realtime_buffers[module], write_length);
120         delete [] temp_buffer;
121         return result;
122 }
123
124 int VPluginArray::write_buffers(int64_t len)
125 {
126         int result = file->write_video_buffer(len);
127         realtime_buffers = 0;
128
129 //      if(!plugin_server->realtime && !done && !result) realtime_buffers = file->get_video_buffer();
130         return result;
131 }
132
133
134 int VPluginArray::total_tracks()
135 {
136         return tracks->total;
137 }
138
139 Track* VPluginArray::track_number(int number)
140 {
141         return (Track*)tracks->values[number];
142 }
143
144