00001 #include "clip.h"
00002 #include "confirmsave.h"
00003 #include "bchash.h"
00004 #include "errorbox.h"
00005 #include "filexml.h"
00006 #include "language.h"
00007 #include "picon_png.h"
00008 #include "gain.h"
00009 #include "gainwindow.h"
00010
00011 #include "vframe.h"
00012
00013 #include <string.h>
00014
00015
00016 REGISTER_PLUGIN(Gain)
00017
00018
00019 GainConfig::GainConfig()
00020 {
00021 level = 0.0;
00022 }
00023
00024 int GainConfig::equivalent(GainConfig &that)
00025 {
00026 return EQUIV(level, that.level);
00027 }
00028
00029 void GainConfig::copy_from(GainConfig &that)
00030 {
00031 this->level = that.level;
00032 }
00033
00034 void GainConfig::interpolate(GainConfig &prev,
00035 GainConfig &next,
00036 int64_t prev_frame,
00037 int64_t next_frame,
00038 int64_t current_frame)
00039 {
00040 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
00041 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
00042 level = prev.level * prev_scale + next.level * next_scale;
00043 }
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 Gain::Gain(PluginServer *server)
00054 : PluginAClient(server)
00055 {
00056 PLUGIN_CONSTRUCTOR_MACRO
00057 }
00058
00059 Gain::~Gain()
00060 {
00061 PLUGIN_DESTRUCTOR_MACRO
00062 }
00063
00064 char* Gain::plugin_title() { return N_("Gain"); }
00065 int Gain::is_realtime() { return 1; }
00066
00067
00068 SHOW_GUI_MACRO(Gain, GainThread)
00069 SET_STRING_MACRO(Gain)
00070 RAISE_WINDOW_MACRO(Gain)
00071 NEW_PICON_MACRO(Gain)
00072 LOAD_CONFIGURATION_MACRO(Gain, GainConfig)
00073
00074 int Gain::process_realtime(int64_t size, double *input_ptr, double *output_ptr)
00075 {
00076 load_configuration();
00077
00078 double gain = db.fromdb(config.level);
00079
00080 for(int64_t i = 0; i < size; i++)
00081 {
00082 output_ptr[i] = input_ptr[i] * gain;
00083 }
00084
00085 return 0;
00086 }
00087
00088
00089
00090 int Gain::load_defaults()
00091 {
00092 char directory[BCTEXTLEN];
00093
00094
00095 sprintf(directory, "%sgain.rc", get_defaultdir());
00096
00097
00098
00099 defaults = new BC_Hash(directory);
00100
00101 defaults->load();
00102
00103 config.level = defaults->get("LEVEL", config.level);
00104
00105 return 0;
00106 }
00107
00108 int Gain::save_defaults()
00109 {
00110 defaults->update("LEVEL", config.level);
00111 defaults->save();
00112 return 0;
00113 }
00114
00115 void Gain::save_data(KeyFrame *keyframe)
00116 {
00117 FileXML output;
00118
00119
00120 output.set_shared_string(keyframe->data, MESSAGESIZE);
00121
00122 output.tag.set_title("GAIN");
00123 output.tag.set_property("LEVEL", config.level);
00124 output.append_tag();
00125 output.tag.set_title("/GAIN");
00126 output.append_tag();
00127 output.append_newline();
00128 output.terminate_string();
00129 }
00130
00131 void Gain::read_data(KeyFrame *keyframe)
00132 {
00133 FileXML input;
00134
00135 input.set_shared_string(keyframe->data, strlen(keyframe->data));
00136 int result = 0;
00137
00138 result = input.read_tag();
00139
00140 if(!result)
00141 {
00142 if(input.tag.title_is("GAIN"))
00143 {
00144 config.level = input.tag.get_property("LEVEL", config.level);
00145 }
00146 }
00147 }
00148
00149 void Gain::update_gui()
00150 {
00151 if(thread)
00152 {
00153 load_configuration();
00154 thread->window->lock_window();
00155 thread->window->level->update(config.level);
00156 thread->window->unlock_window();
00157 }
00158 }
00159
00160