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 "bcdisplayinfo.h"
24 #include "bcsignals.h"
26 #include "mainprogress.h"
27 #include "../../cinelerra/resample.h"
30 #include "transportque.inc"
36 PluginClient* new_plugin(PluginServer *server)
38 return new ResampleEffect(server);
43 ResampleFraction::ResampleFraction(ResampleEffect *plugin, int x, int y)
44 : BC_TextBox(x, y, 100, 1, (float)plugin->scale, 1, MEDIUMFONT, 6)
46 this->plugin = plugin;
49 int ResampleFraction::handle_event()
51 plugin->scale = atof(get_text());
62 ResampleWindow::ResampleWindow(ResampleEffect *plugin, int x, int y)
63 : BC_Window(_(PROGRAM_NAME ": Resample"),
74 this->plugin = plugin;
77 void ResampleWindow::create_objects()
80 lock_window("ResampleWindow::create_objects");
81 add_subwindow(new BC_Title(x, y, _("Scale factor:")));
83 add_subwindow(new ResampleFraction(plugin, x, y));
84 add_subwindow(new BC_OKButton(this));
85 add_subwindow(new BC_CancelButton(this));
97 ResampleResample::ResampleResample(ResampleEffect *plugin)
99 this->plugin = plugin;
102 int ResampleResample::read_samples(Samples *buffer, int64_t start, int64_t len)
104 //printf("ResampleResample::read_samples %d %lld\n", __LINE__, len);
106 return plugin->read_samples(buffer,
108 start + plugin->get_source_start(),
118 ResampleEffect::ResampleEffect(PluginServer *server)
119 : PluginAClient(server)
124 ResampleEffect::~ResampleEffect()
128 const char* ResampleEffect::plugin_title() { return _("Resample"); }
130 void ResampleEffect::reset()
135 int ResampleEffect::get_parameters()
138 ResampleWindow window(this, info.get_abs_cursor_x(), info.get_abs_cursor_y());
139 window.create_objects();
140 int result = window.run_window();
146 int ResampleEffect::load_defaults()
148 char directory[BCTEXTLEN];
150 // set the default directory
151 sprintf(directory, "%sresample.rc", BCASTDIR);
153 defaults = new BC_Hash(directory);
156 scale = defaults->get("SCALE", (double)1);
157 //printf("ResampleEffect::load_defaults %d %f\n", __LINE__, scale);
161 int ResampleEffect::save_defaults()
163 //printf("ResampleEffect::save_defaults %d %f\n", __LINE__, scale);
164 defaults->update("SCALE", scale);
171 int ResampleEffect::start_loop()
173 if(PluginClient::interactive)
175 char string[BCTEXTLEN];
176 sprintf(string, "%s...", plugin_title());
177 progress = start_progress(string,
178 (int64_t)((double)(PluginClient::end - PluginClient::start) / scale));
181 current_position = PluginClient::start;
184 resample = new ResampleResample(this);
188 int ResampleEffect::stop_loop()
190 if(PluginClient::interactive)
192 progress->stop_progress();
198 int ResampleEffect::process_loop(Samples *buffer, int64_t &write_length)
202 // Length to read based on desired output size
203 //printf("ResampleEffect::process_loop %d %d\n", __LINE__);
204 // int64_t size = (int64_t)((double)PluginAClient::in_buffer_size * scale);
205 int64_t predicted_total = (int64_t)((double)(PluginClient::end - PluginClient::start) / scale + 0.5);
207 // Samples *input = new Samples(size);
209 // read_samples(input, 0, current_position, size);
210 // current_position += size;
212 resample->resample(buffer,
213 PluginAClient::out_buffer_size,
215 (int)(1000000.0 / scale),
219 write_length = PluginAClient::out_buffer_size;
220 if(total_written + write_length >= predicted_total)
222 write_length = predicted_total - total_written;
225 total_written += write_length;
226 //printf("ResampleEffect::process_loop %d %lld %f\n", __LINE__, write_length, scale);
228 // resample->resample_chunk(input,
231 // (int)(1000000.0 / scale),
235 // if(resample->get_output_size(0))
237 // int64_t output_size = resample->get_output_size(0);
239 // // if(output_size)
241 // total_written += output_size;
244 // // // Trim output to predicted length of stretched selection.
245 // if(total_written > predicted_total)
247 // output_size -= total_written - predicted_total;
251 // // resample->read_output(buffer, 0, output_size);
253 // // write_length = output_size;
256 if(PluginClient::interactive) result |= progress->update(total_written);
257 //printf("ResampleEffect::process_loop %d %lld\n", __LINE__, total_written);