1 #include "bcdisplayinfo.h"
4 #include "filesystem.h"
6 #include "leveleffect.h"
17 #define _(String) gettext(String)
18 #define gettext_noop(String) String
19 #define N_(String) gettext_noop (String)
29 REGISTER_PLUGIN(SoundLevelEffect)
39 SoundLevelConfig::SoundLevelConfig()
44 void SoundLevelConfig::copy_from(SoundLevelConfig &that)
46 duration = that.duration;
49 int SoundLevelConfig::equivalent(SoundLevelConfig &that)
51 return EQUIV(duration, that.duration);
54 void SoundLevelConfig::interpolate(SoundLevelConfig &prev,
55 SoundLevelConfig &next,
58 int64_t current_frame)
60 duration = prev.duration;
77 SoundLevelDuration::SoundLevelDuration(SoundLevelEffect *plugin, int x, int y)
78 : BC_FSlider(x, y, 0, 180, 180, 0.0, 10.0, plugin->config.duration)
80 this->plugin = plugin;
84 int SoundLevelDuration::handle_event()
86 plugin->config.duration = get_value();
87 plugin->send_configure_change();
93 SoundLevelWindow::SoundLevelWindow(SoundLevelEffect *plugin, int x, int y)
94 : BC_Window(plugin->gui_string,
105 this->plugin = plugin;
108 void SoundLevelWindow::create_objects()
110 //printf("SoundLevelWindow::create_objects 1\n");
114 add_subwindow(new BC_Title(x, y, _("Duration (seconds):")));
115 add_subwindow(duration = new SoundLevelDuration(plugin, x + 150, y));
117 add_subwindow(new BC_Title(x, y, _("Max soundlevel (dB):")));
118 add_subwindow(soundlevel_max = new BC_Title(x + 150, y, "0.0"));
120 add_subwindow(new BC_Title(x, y, _("RMS soundlevel (dB):")));
121 add_subwindow(soundlevel_rms = new BC_Title(x + 150, y, "0.0"));
125 //printf("SoundLevelWindow::create_objects 2\n");
128 WINDOW_CLOSE_EVENT(SoundLevelWindow)
140 PLUGIN_THREAD_OBJECT(SoundLevelEffect, SoundLevelThread, SoundLevelWindow)
156 SoundLevelEffect::SoundLevelEffect(PluginServer *server)
157 : PluginAClient(server)
159 PLUGIN_CONSTRUCTOR_MACRO
163 SoundLevelEffect::~SoundLevelEffect()
165 PLUGIN_DESTRUCTOR_MACRO
168 NEW_PICON_MACRO(SoundLevelEffect)
170 LOAD_CONFIGURATION_MACRO(SoundLevelEffect, SoundLevelConfig)
172 SHOW_GUI_MACRO(SoundLevelEffect, SoundLevelThread)
174 RAISE_WINDOW_MACRO(SoundLevelEffect)
176 SET_STRING_MACRO(SoundLevelEffect)
179 void SoundLevelEffect::reset()
186 char* SoundLevelEffect::plugin_title()
188 return _("SoundLevel");
192 int SoundLevelEffect::is_realtime()
197 void SoundLevelEffect::read_data(KeyFrame *keyframe)
200 input.set_shared_string(keyframe->data, strlen(keyframe->data));
205 result = input.read_tag();
209 if(input.tag.title_is("SOUNDLEVEL"))
211 config.duration = input.tag.get_property("DURATION", config.duration);
217 void SoundLevelEffect::save_data(KeyFrame *keyframe)
220 output.set_shared_string(keyframe->data, MESSAGESIZE);
222 output.tag.set_title("SOUNDLEVEL");
223 output.tag.set_property("DURATION", config.duration);
225 output.append_newline();
227 output.terminate_string();
230 int SoundLevelEffect::load_defaults()
232 defaults = new Defaults(BCASTDIR "soundlevel.rc");
235 config.duration = defaults->get("DURATION", config.duration);
239 int SoundLevelEffect::save_defaults()
241 defaults->update("DURATION", config.duration);
247 void SoundLevelEffect::update_gui()
249 //printf("SoundLevelEffect::update_gui 1\n");
252 load_configuration();
253 thread->window->lock_window();
254 thread->window->duration->update(config.duration);
255 thread->window->unlock_window();
257 //printf("SoundLevelEffect::update_gui 2\n");
260 int SoundLevelEffect::process_realtime(int64_t size, double *input_ptr, double *output_ptr)
262 load_configuration();
265 for(int i = 0; i < size; i++)
267 double value = fabs(input_ptr[i]);
268 if(value > max_accum) max_accum = value;
269 rms_accum += value * value;
272 if(accum_size > config.duration * PluginAClient::project_sample_rate)
274 //printf("SoundLevelEffect::process_realtime 1 %f %d\n", rms_accum, accum_size);
275 rms_accum = sqrt(rms_accum / accum_size);
279 send_render_gui(arg, 2);
287 void SoundLevelEffect::render_gui(void *data, int size)
291 thread->window->lock_window();
292 char string[BCTEXTLEN];
293 double *arg = (double*)data;
294 sprintf(string, "%.2f", DB::todb(arg[0]));
295 thread->window->soundlevel_max->update(string);
296 sprintf(string, "%.2f", DB::todb(arg[1]));
297 thread->window->soundlevel_rms->update(string);
298 thread->window->flush();
299 thread->window->unlock_window();