4 * Copyright (C) 2009 Adam Williams <broadcast at earthling dot net>
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.
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.
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
22 #include "aattachmentpoint.h"
23 #include "audiodevice.h"
25 #include "edlsession.h"
26 #include "pluginaclient.h"
27 #include "pluginserver.h"
28 #include "renderengine.h"
34 PluginAClient::PluginAClient(PluginServer *server)
35 : PluginClient(server)
38 if(server && server->edl && server->edl->session) {
39 project_sample_rate = server->edl->session->sample_rate;
40 sample_rate = project_sample_rate;
43 project_sample_rate = 1;
48 PluginAClient::~PluginAClient()
52 int PluginAClient::is_audio()
58 int PluginAClient::get_render_ptrs()
60 int i, double_buffer, fragment_position;
62 for(i = 0; i < total_in_buffers; i++)
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]);
70 for(i = 0; i < total_out_buffers; i++)
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];
76 //printf("PluginAClient::get_render_ptrs %x %x\n", input_ptr_render[0], output_ptr_render[0]);
80 int PluginAClient::init_realtime_parameters()
82 project_sample_rate = server->edl->session->sample_rate;
86 int PluginAClient::process_realtime(int64_t size,
93 int PluginAClient::process_realtime(int64_t size,
94 Samples *input_ptr, Samples *output_ptr)
99 int PluginAClient::process_buffer(int64_t size, Samples **buffer,
100 int64_t start_position, int sample_rate)
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);
108 int PluginAClient::process_buffer(int64_t size, Samples *buffer,
109 int64_t start_position, int sample_rate)
111 read_samples(buffer, 0, sample_rate, source_position, size);
112 process_realtime(size, buffer, buffer);
117 void PluginAClient::begin_process_buffer()
119 client_frames.destroy();
122 void PluginAClient::end_process_buffer()
124 if( !client_frames.first ) return;
125 server->render_gui_frames(&client_frames);
129 int PluginAClient::plugin_start_loop(int64_t start, int64_t end,
130 int64_t buffer_size, int total_buffers)
132 sample_rate = get_project_samplerate();
133 return PluginClient::plugin_start_loop(start, end,
134 buffer_size, total_buffers);
137 int PluginAClient::plugin_get_parameters()
139 sample_rate = get_project_samplerate();
140 return PluginClient::plugin_get_parameters();
144 int64_t PluginAClient::local_to_edl(int64_t position)
146 if(position < 0) return position;
147 return (int64_t)(position * get_project_samplerate() / sample_rate);
151 int64_t PluginAClient::edl_to_local(int64_t position)
153 if(position < 0) return position;
154 return (int64_t)(position * sample_rate / get_project_samplerate());
157 int PluginAClient::plugin_process_loop(Samples **buffers, int64_t &write_length)
160 return is_multichannel() ?
161 process_loop(buffers, write_length) :
162 process_loop(buffers[0], write_length);
165 int PluginAClient::read_samples(Samples *buffer,
166 int channel, int64_t start_position, int64_t total_samples)
168 return server->read_samples(buffer, channel, start_position, total_samples);
171 int PluginAClient::read_samples(Samples *buffer,
172 int64_t start_position, int64_t total_samples)
174 return server->read_samples(buffer, 0, start_position, total_samples);
177 int PluginAClient::read_samples(Samples *buffer,
178 int channel, int sample_rate, int64_t start_position, int64_t len)
180 return server->read_samples(buffer,
181 channel, sample_rate, start_position, len);
185 int PluginAClient::get_project_samplerate()
187 return project_sample_rate;
190 int PluginAClient::get_samplerate()
195 Samples* PluginAClient::get_output(int channel)
197 return output_buffers[channel];
201 int64_t PluginAClient::get_startproject()
203 int64_t pos = server->get_startproject();
204 return pos >= 0 ? pos : 0;
207 int64_t PluginAClient::get_endproject()
209 int64_t pos = server->get_endproject();
210 return pos >= 0 ? pos : get_edl()->get_audio_samples();