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