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, 1, MEDIUMFONT, 6)
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() { return N_("Resample"); }
87 VFrame* ResampleEffect::new_picon()
89 return new VFrame(picon_png);
92 void ResampleEffect::reset()
97 int ResampleEffect::get_parameters()
100 ResampleWindow window(this, info.get_abs_cursor_x(), info.get_abs_cursor_y());
101 window.create_objects();
102 int result = window.run_window();
108 int ResampleEffect::load_defaults()
110 char directory[BCTEXTLEN];
112 // set the default directory
113 sprintf(directory, "%sresample.rc", BCASTDIR);
115 defaults = new BC_Hash(directory);
118 scale = defaults->get("SCALE", (double)1);
122 int ResampleEffect::save_defaults()
124 defaults->update("SCALE", scale);
131 int ResampleEffect::start_loop()
133 if(PluginClient::interactive)
135 char string[BCTEXTLEN];
136 sprintf(string, "%s...", plugin_title());
137 progress = start_progress(string,
138 (int64_t)((double)(PluginClient::end - PluginClient::start) / scale));
141 current_position = PluginClient::start;
144 resample = new Resample(0, 1);
148 int ResampleEffect::stop_loop()
150 if(PluginClient::interactive)
152 progress->stop_progress();
158 int ResampleEffect::process_loop(double *buffer, int64_t &write_length)
162 // Length to read based on desired output size
163 int64_t size = (int64_t)((double)PluginAClient::in_buffer_size * scale);
164 int64_t predicted_total = (int64_t)((double)(PluginClient::end - PluginClient::start) / scale + 0.5);
166 double *input = new double[size];
168 read_samples(input, 0, current_position, size);
169 current_position += size;
171 resample->resample_chunk(input,
174 (int)(1000000.0 / scale),
178 if(resample->get_output_size(0))
180 int64_t output_size = resample->get_output_size(0);
184 total_written += output_size;
187 // Trim output to predicted length of stretched selection.
188 if(total_written > predicted_total)
190 output_size -= total_written - predicted_total;
194 resample->read_output(buffer, 0, output_size);
196 write_length = output_size;
199 if(PluginClient::interactive) result = progress->update(total_written);
200 //printf("TimeStretch::process_loop 1\n");
203 //printf("TimeStretch::process_loop 2\n");