add auto zoombar/status color, fix 3 batchrender boobies, rotate plugin tweaks, add...
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / interpolateall / interpolateall.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 "bcdisplayinfo.h"
23 #include "clip.h"
24 #include "bchash.h"
25 #include "guicast.h"
26 #include "filexml.h"
27 #include "language.h"
28 #include "mainprogress.h"
29 #include "pluginaclient.h"
30
31 #include <string.h>
32
33
34
35
36
37
38
39
40
41 class InterpolateAllEffect : public PluginAClient
42 {
43 public:
44         InterpolateAllEffect(PluginServer *server);
45         ~InterpolateAllEffect();
46
47         const char* plugin_title();
48         int is_realtime();
49         int is_multichannel();
50         int get_parameters();
51         int start_loop();
52         int process_loop(double *buffer, long &output_lenght);
53         int stop_loop();
54
55
56
57
58         int state;
59         enum
60         {
61                 READING,
62                 WRITING
63         };
64         double sample1;
65         double sample2;
66         int current_position;
67         double slope;
68         double intercept;
69
70         MainProgressBar *progress;
71 };
72
73
74
75
76 REGISTER_PLUGIN(InterpolateAllEffect)
77
78
79
80
81
82
83
84
85 InterpolateAllEffect::InterpolateAllEffect(PluginServer *server)
86  : PluginAClient(server)
87 {
88 }
89
90 InterpolateAllEffect::~InterpolateAllEffect()
91 {
92 }
93
94
95
96
97 char* InterpolateAllEffect::plugin_title() { return N_("Interpolate"); }
98 int InterpolateAllEffect::is_realtime() { return 0; }
99 int InterpolateAllEffect::is_multichannel() { return 0; }
100
101
102 int InterpolateAllEffect::get_parameters()
103 {
104         return 0;
105 }
106
107 int InterpolateAllEffect::start_loop()
108 {
109         state = READING;
110         char string[BCTEXTLEN];
111         sprintf(string, "%s...", plugin_title());
112         progress = start_progress(string, (PluginClient::end - PluginClient::start));
113         current_position = PluginClient::start;
114         return 0;
115 }
116
117 int InterpolateAllEffect::stop_loop()
118 {
119         progress->stop_progress();
120         delete progress;
121         return 0;
122 }
123
124 int InterpolateAllEffect::process_loop(double *buffer, long &write_length)
125 {
126 //printf("InterpolateAllEffect::process_loop 1\n");
127         int result = 0;
128         if(state == READING)
129         {
130 // Read a certain amount before the first sample
131                 int leadin = PluginClient::in_buffer_size;
132 //printf("InterpolateAllEffect::process_loop 2\n");
133                 double buffer[leadin];
134                 if(PluginClient::start - leadin < 0) leadin = PluginClient::start;
135                 read_samples(buffer, PluginClient::start - leadin, leadin);
136                 sample1 = buffer[leadin - 1];
137
138 // Read a certain amount before the last sample
139                 leadin = PluginClient::in_buffer_size;
140                 if(PluginClient::end - leadin < 0) leadin = PluginClient::end;
141                 read_samples(buffer, PluginClient::end - leadin, leadin);
142                 sample2 = buffer[leadin - 1];
143                 state = WRITING;
144                 current_position = PluginClient::start;
145
146 // Get slope and intercept
147                 slope = (sample2 - sample1) /
148                         (PluginClient::end - PluginClient::start);
149                 intercept = sample1;
150 //printf("InterpolateAllEffect::process_loop 3\n");
151         }
152 //printf("InterpolateAllEffect::process_loop 4\n");
153
154         int fragment_len = PluginClient::in_buffer_size;
155         if(current_position + fragment_len > PluginClient::end) fragment_len = PluginClient::end - current_position;
156         double intercept2 = intercept + slope * (current_position - PluginClient::start);
157         for(int i = 0; i < fragment_len; i++)
158         {
159                 buffer[i] = intercept2 + slope * i;
160         }
161         current_position += fragment_len;
162         write_length = fragment_len;
163         result = progress->update(PluginClient::end -
164                 PluginClient::start +
165                 current_position -
166                 PluginClient::start);
167         if(current_position >= PluginClient::end) result = 1;
168 //printf("InterpolateAllEffect::process_loop 5\n");
169
170
171         return result;
172 }
173
174
175