add missing GPL information in guicast program files
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / pluginaclient.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 "aattachmentpoint.h"
23 #include "audiodevice.h"
24 #include "edl.h"
25 #include "edlsession.h"
26 #include "pluginaclient.h"
27 #include "pluginserver.h"
28 #include "renderengine.h"
29 #include "samples.h"
30
31 #include <string.h>
32
33
34 PluginAClient::PluginAClient(PluginServer *server)
35  : PluginClient(server)
36 {
37         sample_rate = 0;
38         if(server && server->edl && server->edl->session) {
39                 project_sample_rate = server->edl->session->sample_rate;
40                 sample_rate = project_sample_rate;
41         }
42         else {
43                 project_sample_rate = 1;
44                 sample_rate = 1;
45         }
46 }
47
48 PluginAClient::~PluginAClient()
49 {
50 }
51
52 int PluginAClient::is_audio()
53 {
54         return 1;
55 }
56
57
58 int PluginAClient::get_render_ptrs()
59 {
60         int i, double_buffer, fragment_position;
61
62         for(i = 0; i < total_in_buffers; i++)
63         {
64                 double_buffer = double_buffer_in_render.values[i];
65                 fragment_position = offset_in_render.values[i];
66                 input_ptr_render[i] = &input_ptr_master.values[i][double_buffer][fragment_position];
67 //printf("PluginAClient::get_render_ptrs %x\n", input_ptr_master.values[i][double_buffer]);
68         }
69
70         for(i = 0; i < total_out_buffers; i++)
71         {
72                 double_buffer = double_buffer_out_render.values[i];
73                 fragment_position = offset_out_render.values[i];
74                 output_ptr_render[i] = &output_ptr_master.values[i][double_buffer][fragment_position];
75         }
76 //printf("PluginAClient::get_render_ptrs %x %x\n", input_ptr_render[0], output_ptr_render[0]);
77         return 0;
78 }
79
80 int PluginAClient::init_realtime_parameters()
81 {
82         project_sample_rate = server->edl->session->sample_rate;
83         return 0;
84 }
85
86 int PluginAClient::process_realtime(int64_t size,
87         Samples **input_ptr,
88         Samples **output_ptr)
89 {
90         return 0;
91 }
92
93 int PluginAClient::process_realtime(int64_t size,
94         Samples *input_ptr, Samples *output_ptr)
95 {
96         return 0;
97 }
98
99 int PluginAClient::process_buffer(int64_t size, Samples **buffer,
100                 int64_t start_position, int sample_rate)
101 {
102         for(int i = 0; i < PluginClient::total_in_buffers; i++)
103                 read_samples(buffer[i], i, sample_rate, source_position, size);
104         process_realtime(size, buffer, buffer);
105         return 0;
106 }
107
108 int PluginAClient::process_buffer(int64_t size, Samples *buffer,
109                 int64_t start_position, int sample_rate)
110 {
111         read_samples(buffer, 0, sample_rate, source_position, size);
112         process_realtime(size, buffer, buffer);
113         return 0;
114 }
115
116
117 void PluginAClient::begin_process_buffer()
118 {
119         client_frames.destroy();
120 }
121
122 void PluginAClient::end_process_buffer()
123 {
124         if( !client_frames.first ) return;
125         server->render_gui_frames(&client_frames);
126 }
127
128
129 int PluginAClient::plugin_start_loop(int64_t start, int64_t end,
130                 int64_t buffer_size, int total_buffers)
131 {
132         sample_rate = get_project_samplerate();
133         return PluginClient::plugin_start_loop(start, end,
134                 buffer_size, total_buffers);
135 }
136
137 int PluginAClient::plugin_get_parameters()
138 {
139         sample_rate = get_project_samplerate();
140         return PluginClient::plugin_get_parameters();
141 }
142
143
144 int64_t PluginAClient::local_to_edl(int64_t position)
145 {
146         if(position < 0) return position;
147         return (int64_t)(position * get_project_samplerate() / sample_rate);
148         return 0;
149 }
150
151 int64_t PluginAClient::edl_to_local(int64_t position)
152 {
153         if(position < 0) return position;
154         return (int64_t)(position * sample_rate / get_project_samplerate());
155 }
156
157 int PluginAClient::plugin_process_loop(Samples **buffers, int64_t &write_length)
158 {
159         write_length = 0;
160         return is_multichannel() ?
161                 process_loop(buffers, write_length) :
162                 process_loop(buffers[0], write_length);
163 }
164
165 int PluginAClient::read_samples(Samples *buffer,
166                 int channel, int64_t start_position, int64_t total_samples)
167 {
168         return server->read_samples(buffer, channel, start_position, total_samples);
169 }
170
171 int PluginAClient::read_samples(Samples *buffer,
172                 int64_t start_position, int64_t total_samples)
173 {
174         return server->read_samples(buffer, 0, start_position, total_samples);
175 }
176
177 int PluginAClient::read_samples(Samples *buffer,
178                 int channel, int sample_rate, int64_t start_position, int64_t len)
179 {
180         return server->read_samples(buffer,
181                 channel, sample_rate, start_position, len);
182 }
183
184
185 int PluginAClient::get_project_samplerate()
186 {
187         return project_sample_rate;
188 }
189
190 int PluginAClient::get_samplerate()
191 {
192         return sample_rate;
193 }
194
195 Samples* PluginAClient::get_output(int channel)
196 {
197         return output_buffers[channel];
198 }
199
200
201 int64_t PluginAClient::get_startproject()
202 {
203         int64_t pos = server->get_startproject();
204         return  pos >= 0 ? pos : 0;
205 }
206
207 int64_t PluginAClient::get_endproject()
208 {
209         int64_t pos = server->get_endproject();
210         return  pos >= 0 ? pos : get_edl()->get_audio_samples();
211 }
212