Merge CV, ver=5.1; ops/methods from HV, and interface from CV where possible
[goodguy/history.git] / cinelerra-5.1 / cinelerra / apluginarray.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2009 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 "amodule.h"
23 #include "apluginarray.h"
24 #include "atrack.h"
25 #include "bcsignals.h"
26 #include "cache.h"
27 #include "edl.h"
28 #include "edlsession.h"
29 #include "file.h"
30 #include "mwindow.h"
31 #include "playbackengine.h"
32 #include "pluginserver.h"
33 #include "preferences.h"
34 #include "recordableatracks.h"
35 #include "samples.h"
36 #include "mainsession.h"
37
38
39 #define RING_BUFFERS 2
40
41
42 APluginArray::APluginArray()
43  : PluginArray(TRACK_AUDIO)
44 {
45         realtime_buffers = 0;
46 }
47
48 APluginArray::~APluginArray()
49 {
50         file->stop_audio_thread();
51         for(int i = 0; i < total_tracks(); i++)
52         {
53                 delete modules[i];
54         }
55         delete tracks;
56 }
57
58 void APluginArray::create_buffers()
59 {
60         file->start_audio_thread(buffer_size, RING_BUFFERS);
61 //      if(!plugin_server->realtime) realtime_buffers = file->get_audio_buffer();
62 }
63
64 void APluginArray::get_buffers()
65 {
66         if(!realtime_buffers) realtime_buffers = file->get_audio_buffer();
67 }
68
69 void APluginArray::create_modules()
70 {
71         modules = new Module*[total_tracks()];
72         for(int i = 0; i < total_tracks(); i++)
73         {
74                 modules[i] = new AModule(0, 0, this, tracks->values[i]);
75                 modules[i]->cache = cache;
76                 modules[i]->edl = edl;
77                 modules[i]->create_objects();
78                 modules[i]->render_init();
79         }
80 }
81
82 void APluginArray::process_realtime(int module, int64_t input_position, int64_t len)
83 {
84         values[module]->process_buffer(realtime_buffers + module,
85                         input_position, 
86                         len,
87                         edl->session->sample_rate,
88                         end - start,
89                         PLAY_FORWARD);
90 }
91
92 int APluginArray::process_loop(int module, int64_t &write_length)
93 {
94         if(!realtime_buffers) realtime_buffers = file->get_audio_buffer();
95         int result = values[module]->process_loop(&realtime_buffers[module], 
96                 write_length);
97         return result;
98 }
99
100
101 int APluginArray::write_buffers(int64_t len)
102 {
103 //printf("APluginArray::write_buffers 1\n");
104         int result = file->write_audio_buffer(len);
105         realtime_buffers = 0;
106
107 //      if(!plugin_server->realtime && !done && !result) 
108 //              realtime_buffers = file->get_audio_buffer();
109         return result;
110 }
111
112 int64_t APluginArray::get_bufsize()
113 {
114         return edl->session->sample_rate;
115 }
116
117
118 void APluginArray::get_recordable_tracks()
119 {
120         tracks = new RecordableATracks(edl->tracks);
121 }
122
123 int APluginArray::total_tracks()
124 {
125         return tracks->total;
126 }
127
128 Track* APluginArray::track_number(int number)
129 {
130         return (Track*)tracks->values[number];
131 }