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, 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 lock_window("ResampleWindow::create_objects");
82 add_subwindow(new BC_Title(x, y, _("Scale factor:")));
84 add_subwindow(new ResampleFraction(plugin, x, y));
85 add_subwindow(new BC_OKButton(this));
86 add_subwindow(new BC_CancelButton(this));
98 ResampleResample::ResampleResample(ResampleEffect *plugin)
100 this->plugin = plugin;
103 int ResampleResample::read_samples(Samples *buffer, int64_t start, int64_t len)
105 //printf("ResampleResample::read_samples %d %lld\n", __LINE__, len);
107 return plugin->read_samples(buffer,
109 start + plugin->get_source_start(),
119 ResampleEffect::ResampleEffect(PluginServer *server)
120 : PluginAClient(server)
125 ResampleEffect::~ResampleEffect()
129 const char* ResampleEffect::plugin_title() { return N_("Resample"); }
131 void ResampleEffect::reset()
136 int ResampleEffect::get_parameters()
139 ResampleWindow window(this, info.get_abs_cursor_x(), info.get_abs_cursor_y());
140 window.create_objects();
141 int result = window.run_window();
147 int ResampleEffect::load_defaults()
149 char directory[BCTEXTLEN];
151 // set the default directory
152 sprintf(directory, "%s/resample.rc", File::get_config_path());
154 defaults = new BC_Hash(directory);
157 scale = defaults->get("SCALE", (double)1);
158 //printf("ResampleEffect::load_defaults %d %f\n", __LINE__, scale);
162 int ResampleEffect::save_defaults()
164 //printf("ResampleEffect::save_defaults %d %f\n", __LINE__, scale);
165 defaults->update("SCALE", scale);
172 int ResampleEffect::start_loop()
174 if(PluginClient::interactive)
176 char string[BCTEXTLEN];
177 sprintf(string, "%s...", plugin_title());
178 progress = start_progress(string,
179 (int64_t)((double)(PluginClient::end - PluginClient::start) / scale));
182 current_position = PluginClient::start;
185 resample = new ResampleResample(this);
189 int ResampleEffect::stop_loop()
191 if(PluginClient::interactive)
193 progress->stop_progress();
199 int ResampleEffect::process_loop(Samples *buffer, int64_t &write_length)
203 // Length to read based on desired output size
204 //printf("ResampleEffect::process_loop %d %d\n", __LINE__);
205 // int64_t size = (int64_t)((double)PluginAClient::in_buffer_size * scale);
206 int64_t predicted_total = (int64_t)((double)(PluginClient::end - PluginClient::start) / scale + 0.5);
208 // Samples *input = new Samples(size);
210 // read_samples(input, 0, current_position, size);
211 // current_position += size;
213 resample->resample(buffer,
214 PluginAClient::out_buffer_size,
216 (int)(1000000.0 / scale),
220 write_length = PluginAClient::out_buffer_size;
221 if(total_written + write_length >= predicted_total)
223 write_length = predicted_total - total_written;
226 total_written += write_length;
227 //printf("ResampleEffect::process_loop %d %lld %f\n", __LINE__, write_length, scale);
229 // resample->resample_chunk(input,
232 // (int)(1000000.0 / scale),
236 // if(resample->get_output_size(0))
238 // int64_t output_size = resample->get_output_size(0);
240 // // if(output_size)
242 // total_written += output_size;
245 // // // Trim output to predicted length of stretched selection.
246 // if(total_written > predicted_total)
248 // output_size -= total_written - predicted_total;
252 // // resample->read_output(buffer, 0, output_size);
254 // // write_length = output_size;
257 if(PluginClient::interactive) result |= progress->update(total_written);
258 //printf("ResampleEffect::process_loop %d %lld\n", __LINE__, total_written);