r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / plugins / interpolateall / interpolateall.C
blobe52cff7b2c93db460f6d58ea7eaf03a38de30854
1 #include "bcdisplayinfo.h"
2 #include "clip.h"
3 #include "defaults.h"
4 #include "guicast.h"
5 #include "filexml.h"
6 #include "mainprogress.h"
7 #include "pluginaclient.h"
9 #include <string.h>
12 #include <libintl.h>
13 #define _(String) gettext(String)
14 #define gettext_noop(String) String
15 #define N_(String) gettext_noop (String)
25 class InterpolateAllEffect : public PluginAClient
27 public:
28         InterpolateAllEffect(PluginServer *server);
29         ~InterpolateAllEffect();
31         char* plugin_title();
32         int is_realtime();
33         int is_multichannel();
34         int get_parameters();
35         int start_loop();
36         int process_loop(double *buffer, long &output_lenght);
37         int stop_loop();
42         int state;
43         enum
44         {
45                 READING,
46                 WRITING
47         };
48         double sample1;
49         double sample2;
50         int current_position;
51         double slope;
52         double intercept;
54         MainProgressBar *progress;
60 REGISTER_PLUGIN(InterpolateAllEffect)
69 InterpolateAllEffect::InterpolateAllEffect(PluginServer *server)
70  : PluginAClient(server)
74 InterpolateAllEffect::~InterpolateAllEffect()
81 char* InterpolateAllEffect::plugin_title()
83         return _("Interpolate");
87 int InterpolateAllEffect::is_realtime()
89         return 0;
92 int InterpolateAllEffect::is_multichannel()
94         return 0;
98 int InterpolateAllEffect::get_parameters()
100         return 0;
103 int InterpolateAllEffect::start_loop()
105         state = READING;
106         char string[BCTEXTLEN];
107         sprintf(string, "%s...", plugin_title());
108         progress = start_progress(string, (PluginClient::end - PluginClient::start));
109         current_position = PluginClient::start;
110         return 0;
113 int InterpolateAllEffect::stop_loop()
115         progress->stop_progress();
116         delete progress;
117         return 0;
120 int InterpolateAllEffect::process_loop(double *buffer, long &write_length)
122 //printf("InterpolateAllEffect::process_loop 1\n");
123         int result = 0;
124         if(state == READING)
125         {
126 // Read a certain amount before the first sample
127                 int leadin = PluginClient::in_buffer_size;
128 //printf("InterpolateAllEffect::process_loop 2\n");
129                 double buffer[leadin];
130                 if(PluginClient::start - leadin < 0) leadin = PluginClient::start;
131                 read_samples(buffer, PluginClient::start - leadin, leadin);
132                 sample1 = buffer[leadin - 1];
134 // Read a certain amount before the last sample
135                 leadin = PluginClient::in_buffer_size;
136                 if(PluginClient::end - leadin < 0) leadin = PluginClient::end;
137                 read_samples(buffer, PluginClient::end - leadin, leadin);
138                 sample2 = buffer[leadin - 1];
139                 state = WRITING;
140                 current_position = PluginClient::start;
142 // Get slope and intercept
143                 slope = (sample2 - sample1) /
144                         (PluginClient::end - PluginClient::start);
145                 intercept = sample1;
146 //printf("InterpolateAllEffect::process_loop 3\n");
147         }
148 //printf("InterpolateAllEffect::process_loop 4\n");
150         int fragment_len = PluginClient::in_buffer_size;
151         if(current_position + fragment_len > PluginClient::end) fragment_len = PluginClient::end - current_position;
152         double intercept2 = intercept + slope * (current_position - PluginClient::start);
153         for(int i = 0; i < fragment_len; i++)
154         {
155                 buffer[i] = intercept2 + slope * i;
156         }
157         current_position += fragment_len;
158         write_length = fragment_len;
159         result = progress->update(PluginClient::end - 
160                 PluginClient::start + 
161                 current_position - 
162                 PluginClient::start);
163         if(current_position >= PluginClient::end) result = 1;
164 //printf("InterpolateAllEffect::process_loop 5\n");
167         return result;