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