load fn from resources, del kfrm speed update, svg exec cmd/file win fixes, undo...
[goodguy/history.git] / cinelerra-5.1 / plugins / resamplert / resamplert.C
index e6de8c3479548ddbbbfaa15c946c9c8e744c97a3..9408afaaa3a9cc4c84035c0a0ac49899f31b7bea 100644 (file)
@@ -1,22 +1,22 @@
 
 /*
  * CINELERRA
- * Copyright (C) 2010 Adam Williams <broadcast at earthling dot net>
- * 
+ * Copyright (C) 2010-2016 Adam Williams <broadcast at earthling dot net>
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- * 
+ *
  */
 
 #include "bcdisplayinfo.h"
@@ -41,43 +41,48 @@ REGISTER_PLUGIN(ResampleRT);
 
 ResampleRTConfig::ResampleRTConfig()
 {
-       scale = 1;
+       num = 1;
+       denom = 1;
 }
 
 
 int ResampleRTConfig::equivalent(ResampleRTConfig &src)
 {
-       return fabs(scale - src.scale) < 0.0001;
+       return fabs(num - src.num) < 0.0001 &&
+               fabs(denom - src.denom) < 0.0001;
 }
 
 void ResampleRTConfig::copy_from(ResampleRTConfig &src)
 {
-       this->scale = src.scale;
+       this->num = src.num;
+       this->denom = src.denom;
 }
 
-void ResampleRTConfig::interpolate(ResampleRTConfig &prev, 
-       ResampleRTConfig &next, 
-       int64_t prev_frame, 
-       int64_t next_frame, 
+void ResampleRTConfig::interpolate(ResampleRTConfig &prev,
+       ResampleRTConfig &next,
+       int64_t prev_frame,
+       int64_t next_frame,
        int64_t current_frame)
 {
-       this->scale = prev.scale;
+       this->num = prev.num;
+       this->denom = prev.denom;
 }
 
 void ResampleRTConfig::boundaries()
 {
-       if(fabs(scale) < 0.0001) scale = 0.0001;
+       if(num < 0.0001) num = 0.0001;
+       if(denom < 0.0001) denom = 0.0001;
 }
 
 
 
 
 ResampleRTWindow::ResampleRTWindow(ResampleRT *plugin)
- : PluginClientWindow(plugin, 
-       210, 
-       160, 
-       200, 
-       160, 
+ : PluginClientWindow(plugin,
+       210,
+       160,
+       200,
+       160,
        0)
 {
        this->plugin = plugin;
@@ -89,17 +94,21 @@ ResampleRTWindow::~ResampleRTWindow()
 
 void ResampleRTWindow::create_objects()
 {
-       int x = 10, y = 10;
+       int x = plugin->get_theme()->window_border;
+       int y = plugin->get_theme()->window_border;
 
        BC_Title *title;
-       add_subwindow(title = new BC_Title(x, y, _("Scale by amount:")));
+       add_subwindow(title = new BC_Title(x, y, _("Input samples:")));
        y += title->get_h() + plugin->get_theme()->widget_border;
+       num = new ResampleRTNum(this, plugin, x, y);
+       num->create_objects();
+
+       y += num->get_h() + plugin->get_theme()->widget_border;
+       add_subwindow(title = new BC_Title(x, y, _("Output samples:")));
+       y += title->get_h() + plugin->get_theme()->widget_border;
+       denom = new ResampleRTDenom(this, plugin, x, y);
+       denom->create_objects();
 
-       scale = new ResampleRTScale(this,
-               plugin, 
-               x, 
-               y);
-       scale->create_objects();
        show_window();
 }
 
@@ -108,25 +117,53 @@ void ResampleRTWindow::create_objects()
 
 
 
-ResampleRTScale::ResampleRTScale(ResampleRTWindow *window,
-       ResampleRT *plugin, 
-       int x, 
+ResampleRTNum::ResampleRTNum(ResampleRTWindow *window,
+       ResampleRT *plugin,
+       int x,
        int y)
  : BC_TumbleTextBox(window,
-       plugin->config.scale,
+       plugin->config.num,
        (float)0.0001,
        (float)1000,
-       x, 
-       y, 
+       x,
+       y,
        100)
 {
        this->plugin = plugin;
        set_increment(0.001);
 }
 
-int ResampleRTScale::handle_event()
+int ResampleRTNum::handle_event()
 {
-       plugin->config.scale = atof(get_text());
+       plugin->config.num = atof(get_text());
+       plugin->config.boundaries();
+       plugin->send_configure_change();
+       return 1;
+}
+
+
+
+
+ResampleRTDenom::ResampleRTDenom(ResampleRTWindow *window,
+       ResampleRT *plugin,
+       int x,
+       int y)
+ : BC_TumbleTextBox(window,
+       plugin->config.denom,
+       (float)0.0001,
+       (float)1000,
+       x,
+       y,
+       100)
+{
+       this->plugin = plugin;
+       set_increment(0.001);
+}
+
+int ResampleRTDenom::handle_event()
+{
+       plugin->config.denom = atof(get_text());
+       plugin->config.boundaries();
        plugin->send_configure_change();
        return 1;
 }
@@ -144,8 +181,8 @@ ResampleRTResample::ResampleRTResample(ResampleRT *plugin)
 
 // To get the keyframes to work, resampling is always done in the forward
 // direction with the plugin converting to reverse.
-int ResampleRTResample::read_samples(Samples *buffer, 
-       int64_t start, 
+int ResampleRTResample::read_samples(Samples *buffer,
+       int64_t start,
        int64_t len)
 {
        int result = plugin->read_samples(buffer,
@@ -159,7 +196,7 @@ int ResampleRTResample::read_samples(Samples *buffer,
                plugin->source_start += len;
        else
                plugin->source_start -= len;
-       
+
        return result;
 }
 
@@ -183,7 +220,7 @@ ResampleRT::~ResampleRT()
        delete resample;
 }
 
-const char* ResampleRT::plugin_title() { return _("ResampleRT"); }
+const char* ResampleRT::plugin_title() { return N_("ResampleRT"); }
 int ResampleRT::is_realtime() { return 1; }
 int ResampleRT::is_synthesis() { return 1; }
 
@@ -193,7 +230,7 @@ NEW_WINDOW_MACRO(ResampleRT, ResampleRTWindow)
 LOAD_CONFIGURATION_MACRO(ResampleRT, ResampleRTConfig)
 
 
-int ResampleRT::process_buffer(int64_t size, 
+int ResampleRT::process_buffer(int64_t size,
        Samples *buffer,
        int64_t start_position,
        int sample_rate)
@@ -201,8 +238,8 @@ int ResampleRT::process_buffer(int64_t size,
        if(!resample) resample = new ResampleRTResample(this);
 
        need_reconfigure |= load_configuration();
-       
-       
+
+
        if(start_position != dest_start) need_reconfigure = 1;
        dest_start = start_position;
 
@@ -219,8 +256,8 @@ int ResampleRT::process_buffer(int64_t size,
                        prev_position = get_source_start();
                }
 
-               source_start = (int64_t)((start_position - prev_position) * 
-                       config.scale) + prev_position;
+               source_start = (int64_t)((start_position - prev_position) *
+                       config.num / config.denom) + prev_position;
 
                resample->reset();
                need_reconfigure = 0;
@@ -228,10 +265,10 @@ int ResampleRT::process_buffer(int64_t size,
 
        resample->resample(buffer,
                size,
-               (int)1000000,
-               (int)(1000000 / config.scale),
+               (int)(65536 * config.num),
+               (int)(65536 * config.denom),
                start_position,
-               get_direction());       
+               get_direction());
 
        if(get_direction() == PLAY_FORWARD)
                dest_start += size;
@@ -256,7 +293,8 @@ void ResampleRT::save_data(KeyFrame *keyframe)
 // cause data to be stored directly in text
        output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
        output.tag.set_title("RESAMPLERT");
-       output.tag.set_property("SCALE", config.scale);
+       output.tag.set_property("SCALE", config.num);
+       output.tag.set_property("DENOM", config.denom);
        output.append_tag();
        output.tag.set_title("/RESAMPLERT");
        output.append_tag();
@@ -274,7 +312,8 @@ void ResampleRT::read_data(KeyFrame *keyframe)
        {
                if(input.tag.title_is("RESAMPLERT"))
                {
-                       config.scale = input.tag.get_property("SCALE", config.scale);
+                       config.num = input.tag.get_property("SCALE", config.num);
+                       config.denom = input.tag.get_property("DENOM", config.denom);
                }
        }
 }
@@ -286,7 +325,8 @@ void ResampleRT::update_gui()
                if(load_configuration())
                {
                        thread->window->lock_window("ResampleRT::update_gui");
-                       ((ResampleRTWindow*)thread->window)->scale->update((float)config.scale);
+                       ((ResampleRTWindow*)thread->window)->num->update((float)config.num);
+                       ((ResampleRTWindow*)thread->window)->denom->update((float)config.denom);
                        thread->window->unlock_window();
                }
        }