4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
23 #include "confirmsave.h"
29 #include "gainwindow.h"
37 REGISTER_PLUGIN(GainMain)
40 GainConfig::GainConfig()
45 void GainConfig::reset()
50 int GainConfig::equivalent(GainConfig &that)
52 return EQUIV(level, that.level);
55 void GainConfig::copy_from(GainConfig &that)
57 this->level = that.level;
60 void GainConfig::interpolate(GainConfig &prev,
64 int64_t current_frame)
66 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
67 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
68 level = prev.level * prev_scale + next.level * next_scale;
79 GainMain::GainMain(PluginServer *server)
80 : PluginAClient(server)
90 const char* GainMain::plugin_title() { return N_("Gain"); }
91 int GainMain::is_realtime() { return 1; }
94 NEW_WINDOW_MACRO(GainMain, GainWindow)
95 LOAD_CONFIGURATION_MACRO(GainMain, GainConfig)
97 int GainMain::process_realtime(int64_t size, Samples *input_ptr, Samples *output_ptr)
101 double gain = db.fromdb(config.level);
102 double *output_samples = output_ptr->get_data();
103 double *input_samples = input_ptr->get_data();
105 for(int64_t i = 0; i < size; i++)
107 output_samples[i] = input_samples[i] * gain;
116 void GainMain::save_data(KeyFrame *keyframe)
120 // cause xml file to store data directly in text
121 output.set_shared_output(keyframe->xbuf);
123 output.tag.set_title("GAIN");
124 output.tag.set_property("LEVEL", config.level);
126 output.tag.set_title("/GAIN");
128 output.append_newline();
129 output.terminate_string();
132 void GainMain::read_data(KeyFrame *keyframe)
135 // cause xml file to read directly from text
136 input.set_shared_input(keyframe->xbuf);
139 result = input.read_tag();
143 if(input.tag.title_is("GAIN"))
145 config.level = input.tag.get_property("LEVEL", config.level);
150 void GainMain::update_gui()
154 load_configuration();
155 thread->window->lock_window();
156 ((GainWindow*)thread->window)->level_text->update((float)config.level);
157 ((GainWindow*)thread->window)->level_slider->update(config.level);
158 thread->window->unlock_window();