r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / plugins / gain / gain.C
blob3fbef103adc95b419b483b59eccf244da4e9b52f
1 #include "clip.h"
2 #include "confirmsave.h"
3 #include "defaults.h"
4 #include "errorbox.h"
5 #include "filexml.h"
6 #include "picon_png.h"
7 #include "gain.h"
8 #include "gainwindow.h"
10 #include "vframe.h"
12 #include <string.h>
14 #include <libintl.h>
15 #define _(String) gettext(String)
16 #define gettext_noop(String) String
17 #define N_(String) gettext_noop (String)
20 REGISTER_PLUGIN(Gain)
23 GainConfig::GainConfig()
25         level = 0.0;
28 int GainConfig::equivalent(GainConfig &that)
30         return EQUIV(level, that.level);
33 void GainConfig::copy_from(GainConfig &that)
35         this->level = that.level;
38 void GainConfig::interpolate(GainConfig &prev, 
39         GainConfig &next, 
40         int64_t prev_frame, 
41         int64_t next_frame, 
42         int64_t current_frame)
44         double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
45         double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
46         level = prev.level * prev_scale + next.level * next_scale;
57 Gain::Gain(PluginServer *server)
58  : PluginAClient(server)
60         PLUGIN_CONSTRUCTOR_MACRO
63 Gain::~Gain()
65         PLUGIN_DESTRUCTOR_MACRO
68 char* Gain::plugin_title() { return _("Gain"); }
69 int Gain::is_realtime() { return 1; }
72 SHOW_GUI_MACRO(Gain, GainThread)
73 SET_STRING_MACRO(Gain)
74 RAISE_WINDOW_MACRO(Gain)
75 NEW_PICON_MACRO(Gain)
76 LOAD_CONFIGURATION_MACRO(Gain, GainConfig)
78 int Gain::process_realtime(int64_t size, double *input_ptr, double *output_ptr)
80         load_configuration();
82         double gain = db.fromdb(config.level);
84         for(int64_t i = 0; i < size; i++)
85         {
86                 output_ptr[i] = input_ptr[i] * gain;
87         }
89         return 0;
94 int Gain::load_defaults()
96         char directory[1024];
98 // set the default directory
99         sprintf(directory, "%sgain.rc", get_defaultdir());
100         
101 // load the defaults
103         defaults = new Defaults(directory);
105         defaults->load();
107         config.level = defaults->get("LEVEL", config.level);
109         return 0;
112 int Gain::save_defaults()
114         defaults->update("LEVEL", config.level);
115         defaults->save();
116         return 0;
119 void Gain::save_data(KeyFrame *keyframe)
121         FileXML output;
123 // cause xml file to store data directly in text
124         output.set_shared_string(keyframe->data, MESSAGESIZE);
126         output.tag.set_title("GAIN");
127         output.tag.set_property("LEVEL", config.level);
128         output.append_tag();
129         output.append_newline();
130         output.terminate_string();
133 void Gain::read_data(KeyFrame *keyframe)
135         FileXML input;
136 // cause xml file to read directly from text
137         input.set_shared_string(keyframe->data, strlen(keyframe->data));
138         int result = 0;
140         result = input.read_tag();
142         if(!result)
143         {
144                 if(input.tag.title_is("GAIN"))
145                 {
146                         config.level = input.tag.get_property("LEVEL", config.level);
147                 }
148         }
151 void Gain::update_gui()
153         if(thread)
154         {
155                 load_configuration();
156                 thread->window->lock_window();
157                 thread->window->level->update(config.level);
158                 thread->window->unlock_window();
159         }