1 #include "bcdisplayinfo.h"
3 #include "mainprogress.h"
5 #include "../../cinelerra/resample.h"
12 PluginClient* new_plugin(PluginServer *server)
14 return new ResampleEffect(server);
19 ResampleFraction::ResampleFraction(ResampleEffect *plugin, int x, int y)
20 : BC_TextBox(x, y, 100, 1, (float)plugin->scale)
22 this->plugin = plugin;
25 int ResampleFraction::handle_event()
27 plugin->scale = atof(get_text());
38 ResampleWindow::ResampleWindow(ResampleEffect *plugin, int x, int y)
39 : BC_Window(PROGRAM_NAME ": Resample",
50 this->plugin = plugin;
53 void ResampleWindow::create_objects()
56 add_subwindow(new BC_Title(x, y, _("Scale factor:")));
58 add_subwindow(new ResampleFraction(plugin, x, y));
59 add_subwindow(new BC_OKButton(this));
60 add_subwindow(new BC_CancelButton(this));
72 ResampleEffect::ResampleEffect(PluginServer *server)
73 : PluginAClient(server)
79 ResampleEffect::~ResampleEffect()
85 char* ResampleEffect::plugin_title()
90 VFrame* ResampleEffect::new_picon()
92 return new VFrame(picon_png);
95 void ResampleEffect::reset()
100 int ResampleEffect::get_parameters()
103 ResampleWindow window(this, info.get_abs_cursor_x(), info.get_abs_cursor_y());
104 window.create_objects();
105 int result = window.run_window();
111 int ResampleEffect::load_defaults()
113 char directory[BCTEXTLEN];
115 // set the default directory
116 sprintf(directory, "%sresample.rc", BCASTDIR);
118 defaults = new Defaults(directory);
121 scale = defaults->get("SCALE", (double)1);
125 int ResampleEffect::save_defaults()
127 defaults->update("SCALE", scale);
134 int ResampleEffect::start_loop()
136 if(PluginClient::interactive)
138 char string[BCTEXTLEN];
139 sprintf(string, "%s...", plugin_title());
140 progress = start_progress(string,
141 (int64_t)((double)(PluginClient::end - PluginClient::start) * scale));
144 current_position = PluginClient::start;
147 resample = new Resample(0, 1);
151 int ResampleEffect::stop_loop()
153 if(PluginClient::interactive)
155 progress->stop_progress();
161 int ResampleEffect::process_loop(double *buffer, int64_t &write_length)
165 // Length to read based on desired output size
166 int64_t size = (int64_t)((double)PluginAClient::in_buffer_size / scale);
167 int64_t predicted_total = (int64_t)((double)(PluginClient::end - PluginClient::start) * scale + 0.5);
169 double *input = new double[size];
171 read_samples(input, 0, current_position, size);
172 current_position += size;
174 resample->resample_chunk(input,
177 (int)(1000000.0 * scale),
181 if(resample->get_output_size(0))
183 int64_t output_size = resample->get_output_size(0);
187 total_written += output_size;
190 // Trim output to predicted length of stretched selection.
191 if(total_written > predicted_total)
193 output_size -= total_written - predicted_total;
197 resample->read_output(buffer, 0, output_size);
199 write_length = output_size;
202 if(PluginClient::interactive) result = progress->update(total_written);
203 //printf("TimeStretch::process_loop 1\n");
206 //printf("TimeStretch::process_loop 2\n");