remove whitespace at eol
[goodguy/history.git] / cinelerra-5.1 / plugins / gain / gain.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "clip.h"
23 #include "confirmsave.h"
24 #include "bchash.h"
25 #include "errorbox.h"
26 #include "filexml.h"
27 #include "language.h"
28 #include "gain.h"
29 #include "gainwindow.h"
30 #include "samples.h"
31
32 #include "vframe.h"
33
34 #include <string.h>
35
36
37 REGISTER_PLUGIN(Gain)
38
39
40 GainConfig::GainConfig()
41 {
42         level = 0.0;
43 }
44
45 int GainConfig::equivalent(GainConfig &that)
46 {
47         return EQUIV(level, that.level);
48 }
49
50 void GainConfig::copy_from(GainConfig &that)
51 {
52         this->level = that.level;
53 }
54
55 void GainConfig::interpolate(GainConfig &prev,
56         GainConfig &next,
57         int64_t prev_frame,
58         int64_t next_frame,
59         int64_t current_frame)
60 {
61         double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
62         double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
63         level = prev.level * prev_scale + next.level * next_scale;
64 }
65
66
67
68
69
70
71
72
73
74 Gain::Gain(PluginServer *server)
75  : PluginAClient(server)
76 {
77
78 }
79
80 Gain::~Gain()
81 {
82
83 }
84
85 const char* Gain::plugin_title() { return _("Gain"); }
86 int Gain::is_realtime() { return 1; }
87
88
89 NEW_WINDOW_MACRO(Gain, GainWindow)
90 LOAD_CONFIGURATION_MACRO(Gain, GainConfig)
91
92 int Gain::process_realtime(int64_t size, Samples *input_ptr, Samples *output_ptr)
93 {
94         load_configuration();
95
96         double gain = db.fromdb(config.level);
97         double *output_samples = output_ptr->get_data();
98         double *input_samples = input_ptr->get_data();
99
100         for(int64_t i = 0; i < size; i++)
101         {
102                 output_samples[i] = input_samples[i] * gain;
103         }
104
105         return 0;
106 }
107
108
109
110
111 void Gain::save_data(KeyFrame *keyframe)
112 {
113         FileXML output;
114
115 // cause xml file to store data directly in text
116         output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
117
118         output.tag.set_title("GAIN");
119         output.tag.set_property("LEVEL", config.level);
120         output.append_tag();
121         output.tag.set_title("/GAIN");
122         output.append_tag();
123         output.append_newline();
124         output.terminate_string();
125 }
126
127 void Gain::read_data(KeyFrame *keyframe)
128 {
129         FileXML input;
130 // cause xml file to read directly from text
131         input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
132         int result = 0;
133
134         result = input.read_tag();
135
136         if(!result)
137         {
138                 if(input.tag.title_is("GAIN"))
139                 {
140                         config.level = input.tag.get_property("LEVEL", config.level);
141                 }
142         }
143 }
144
145 void Gain::update_gui()
146 {
147         if(thread)
148         {
149                 load_configuration();
150                 thread->window->lock_window();
151                 ((GainWindow*)thread->window)->level->update(config.level);
152                 thread->window->unlock_window();
153         }
154 }
155
156