1 #include "bcdisplayinfo.h"
15 #define _(String) gettext(String)
16 #define gettext_noop(String) String
17 #define N_(String) gettext_noop (String)
25 PluginClient* new_plugin(PluginServer *server)
27 return new PitchEffect(server);
34 PitchEffect::PitchEffect(PluginServer *server)
35 : PluginAClient(server)
41 PitchEffect::~PitchEffect()
45 thread->window->set_done(0);
46 thread->completion.lock();
56 VFrame* PitchEffect::new_picon()
58 return new VFrame(picon_png);
61 char* PitchEffect::plugin_title()
63 return _("Pitch shift");
67 int PitchEffect::is_realtime()
74 void PitchEffect::read_data(KeyFrame *keyframe)
77 input.set_shared_string(keyframe->data, strlen(keyframe->data));
82 result = input.read_tag();
86 if(input.tag.title_is("PITCH"))
88 config.scale = input.tag.get_property("SCALE", config.scale);
94 void PitchEffect::save_data(KeyFrame *keyframe)
97 output.set_shared_string(keyframe->data, MESSAGESIZE);
99 output.tag.set_title("PITCH");
100 output.tag.set_property("SCALE", config.scale);
102 output.append_newline();
104 output.terminate_string();
107 int PitchEffect::load_defaults()
109 char directory[BCTEXTLEN], string[BCTEXTLEN];
110 sprintf(directory, "%spitch.rc", BCASTDIR);
111 defaults = new Defaults(directory);
114 config.scale = defaults->get("SCALE", config.scale);
118 int PitchEffect::save_defaults()
120 char string[BCTEXTLEN];
122 defaults->update("SCALE", config.scale);
129 LOAD_CONFIGURATION_MACRO(PitchEffect, PitchConfig)
132 void PitchEffect::reset()
138 void PitchEffect::update_gui()
142 load_configuration();
143 thread->window->lock_window();
144 thread->window->update();
145 thread->window->unlock_window();
149 int PitchEffect::show_gui()
151 load_configuration();
153 thread = new PitchThread(this);
158 void PitchEffect::raise_window()
162 thread->window->lock_window();
163 thread->window->raise_window();
164 thread->window->flush();
165 thread->window->unlock_window();
169 int PitchEffect::set_string()
173 thread->window->lock_window();
174 thread->window->set_title(gui_string);
175 thread->window->unlock_window();
180 int PitchEffect::process_realtime(int64_t size, double *input_ptr, double *output_ptr)
182 load_configuration();
183 if(!fft) fft = new PitchFFT(this);
184 fft->process_fifo(size, input_ptr, output_ptr);
196 PitchFFT::PitchFFT(PitchEffect *plugin)
199 this->plugin = plugin;
203 int PitchFFT::signal_process()
206 1 + (int)(20.0 / ((double)plugin->PluginAClient::project_sample_rate / window_size * 2) + 0.5);
207 //printf("PitchFFT::signal_process %d\n", min_freq);
208 if(plugin->config.scale < 1)
210 for(int i = min_freq; i < window_size / 2; i++)
212 double destination = i * plugin->config.scale;
213 int dest_i = (int)(destination + 0.5);
216 if(dest_i <= window_size / 2)
218 freq_real[dest_i] = freq_real[i];
219 freq_imag[dest_i] = freq_imag[i];
227 if(plugin->config.scale > 1)
229 for(int i = window_size / 2 - 1; i >= min_freq; i--)
231 double destination = i * plugin->config.scale;
232 int dest_i = (int)(destination + 0.5);
235 if(dest_i <= window_size / 2)
237 freq_real[dest_i] = freq_real[i];
238 freq_imag[dest_i] = freq_imag[i];
246 symmetry(window_size, freq_real, freq_imag);
257 PitchConfig::PitchConfig()
262 int PitchConfig::equivalent(PitchConfig &that)
264 return EQUIV(scale, that.scale);
267 void PitchConfig::copy_from(PitchConfig &that)
272 void PitchConfig::interpolate(PitchConfig &prev,
276 int64_t current_frame)
278 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
279 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
280 scale = prev.scale * prev_scale + next.scale * next_scale;
291 PitchThread::PitchThread(PitchEffect *plugin)
294 this->plugin = plugin;
299 PitchThread::~PitchThread()
305 void PitchThread::run()
309 window = new PitchWindow(plugin,
310 info.get_abs_cursor_x() - 125,
311 info.get_abs_cursor_y() - 115);
313 window->create_objects();
314 int result = window->run_window();
316 // Last command in thread
317 if(result) plugin->client_side_close();
327 PitchWindow::PitchWindow(PitchEffect *plugin, int x, int y)
328 : BC_Window(plugin->gui_string,
339 this->plugin = plugin;
342 void PitchWindow::create_objects()
346 add_subwindow(new BC_Title(x, y, _("Scale:")));
348 add_subwindow(scale = new PitchScale(plugin, x, y));
353 int PitchWindow::close_event()
355 // Set result to 1 to indicate a client side close
360 void PitchWindow::update()
362 scale->update(plugin->config.scale);
376 PitchScale::PitchScale(PitchEffect *plugin, int x, int y)
377 : BC_FPot(x, y, (float)plugin->config.scale, .5, 1.5)
379 this->plugin = plugin;
383 int PitchScale::handle_event()
385 plugin->config.scale = get_value();
386 plugin->send_configure_change();