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"
27 #include "mainprogress.h"
28 #include "../../cinelerra/resample.h"
31 #include "transportque.inc"
37 PluginClient* new_plugin(PluginServer *server)
39 return new ResampleEffect(server);
44 ResampleFraction::ResampleFraction(ResampleEffect *plugin, int x, int y)
45 : BC_TextBox(x, y, xS(100), 1, (float)plugin->scale, 1, MEDIUMFONT, 6)
47 this->plugin = plugin;
50 int ResampleFraction::handle_event()
52 plugin->scale = atof(get_text());
63 ResampleWindow::ResampleWindow(ResampleEffect *plugin, int x, int y)
64 : BC_Window(_(PROGRAM_NAME ": Resample"),
75 this->plugin = plugin;
78 void ResampleWindow::create_objects()
81 int ys10 = yS(10), ys20 = yS(20);
82 int x = xs10, y = ys10;
83 lock_window("ResampleWindow::create_objects");
84 add_subwindow(new BC_Title(x, y, _("Scale factor:")));
86 add_subwindow(new ResampleFraction(plugin, x, y));
87 add_subwindow(new BC_OKButton(this));
88 add_subwindow(new BC_CancelButton(this));
100 ResampleResample::ResampleResample(ResampleEffect *plugin)
102 this->plugin = plugin;
105 int ResampleResample::read_samples(Samples *buffer, int64_t start, int64_t len)
107 //printf("ResampleResample::read_samples %d %lld\n", __LINE__, len);
109 return plugin->read_samples(buffer,
111 start + plugin->get_source_start(),
121 ResampleEffect::ResampleEffect(PluginServer *server)
122 : PluginAClient(server)
127 ResampleEffect::~ResampleEffect()
131 const char* ResampleEffect::plugin_title() { return N_("Resample"); }
133 void ResampleEffect::reset()
138 int ResampleEffect::get_parameters()
141 ResampleWindow window(this, info.get_abs_cursor_x(), info.get_abs_cursor_y());
142 window.create_objects();
143 int result = window.run_window();
149 int ResampleEffect::load_defaults()
151 char directory[BCTEXTLEN];
153 // set the default directory
154 sprintf(directory, "%s/resample.rc", File::get_config_path());
156 defaults = new BC_Hash(directory);
159 scale = defaults->get("SCALE", (double)1);
160 //printf("ResampleEffect::load_defaults %d %f\n", __LINE__, scale);
164 int ResampleEffect::save_defaults()
166 //printf("ResampleEffect::save_defaults %d %f\n", __LINE__, scale);
167 defaults->update("SCALE", scale);
174 int ResampleEffect::start_loop()
176 if(PluginClient::interactive)
178 char string[BCTEXTLEN];
179 sprintf(string, "%s...", plugin_title());
180 progress = start_progress(string,
181 (int64_t)((double)(PluginClient::end - PluginClient::start) / scale));
184 current_position = PluginClient::start;
187 resample = new ResampleResample(this);
191 int ResampleEffect::stop_loop()
193 if(PluginClient::interactive)
195 progress->stop_progress();
201 int ResampleEffect::process_loop(Samples *buffer, int64_t &write_length)
205 // Length to read based on desired output size
206 //printf("ResampleEffect::process_loop %d %d\n", __LINE__);
207 // int64_t size = (int64_t)((double)PluginAClient::in_buffer_size * scale);
208 int64_t predicted_total = (int64_t)((double)(PluginClient::end - PluginClient::start) / scale + 0.5);
210 // Samples *input = new Samples(size);
212 // read_samples(input, 0, current_position, size);
213 // current_position += size;
215 resample->resample(buffer,
216 PluginAClient::out_buffer_size,
218 (int)(1000000.0 / scale),
222 write_length = PluginAClient::out_buffer_size;
223 if(total_written + write_length >= predicted_total)
225 write_length = predicted_total - total_written;
228 total_written += write_length;
229 //printf("ResampleEffect::process_loop %d %lld %f\n", __LINE__, write_length, scale);
231 // resample->resample_chunk(input,
234 // (int)(1000000.0 / scale),
238 // if(resample->get_output_size(0))
240 // int64_t output_size = resample->get_output_size(0);
242 // // if(output_size)
244 // total_written += output_size;
247 // // // Trim output to predicted length of stretched selection.
248 // if(total_written > predicted_total)
250 // output_size -= total_written - predicted_total;
254 // // resample->read_output(buffer, 0, output_size);
256 // // write_length = output_size;
259 if(PluginClient::interactive) result |= progress->update(total_written);
260 //printf("ResampleEffect::process_loop %d %lld\n", __LINE__, total_written);