add auto zoombar/status color, fix 3 batchrender boobies, rotate plugin tweaks, add...
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / echo / echo.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2011 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 #ifndef ECHO_H
23 #define ECHO_H
24 #include "bchash.inc"
25 #include "bctimer.inc"
26 #include "fourier.h"
27 #include "guicast.h"
28 #include "mutex.h"
29 #include "pluginaclient.h"
30 #include "vframe.inc"
31
32 #include <string.h>
33
34
35 class Echo;
36
37
38 class EchoPrefix {
39 public:
40         const char *prefix;
41         EchoPrefix(const char *p) : prefix(p) {}
42         ~EchoPrefix() {}
43 };
44
45 class EchoTitle : public EchoPrefix, public BC_Title {
46         char string[BCSTRLEN];
47         char *preset(int value) {
48                 sprintf(string, "%s%d", prefix, value);
49                 return string;
50         }
51         char *preset(double value) {
52                 sprintf(string, "%s%.3f", prefix, value);
53                 return string;
54         }
55 public:
56         void update(int value) { BC_Title::update(preset(value)); }
57         void update(double value) { BC_Title::update(preset(value)); }
58
59         EchoTitle(int x, int y, const char *pfx, int value)
60                 : EchoPrefix(pfx), BC_Title(x, y, preset(value)) {}
61         EchoTitle(int x, int y, const char *pfx, double value)
62                 :  EchoPrefix(pfx),BC_Title(x, y, preset(value)) {}
63         ~EchoTitle() {}
64 };
65
66
67 class EchoWindow;
68
69 class EchoLevel : public BC_FPot
70 {
71 public:
72         EchoLevel(EchoWindow *window, int x, int y);
73         ~EchoLevel();
74         int handle_event();
75         EchoWindow *window;
76 };
77
78 class EchoAtten : public BC_FPot
79 {
80 public:
81         EchoAtten(EchoWindow *window, int x, int y);
82         ~EchoAtten();
83         int handle_event();
84         EchoWindow *window;
85 };
86
87 class EchoOffset : public BC_FPot
88 {
89 public:
90         EchoOffset(EchoWindow *window, int x, int y);
91         ~EchoOffset();
92         int handle_event();
93         EchoWindow *window;
94 };
95
96
97 class EchoWindow : public PluginClientWindow
98 {
99 public:
100         EchoWindow(Echo *plugin);
101         ~EchoWindow();
102
103         void create_objects();
104         void update_gui();
105         int resize_event(int w, int h);
106
107         EchoTitle *level_title;
108         EchoLevel *level;
109
110         EchoTitle *atten_title;
111         EchoAtten *atten;
112         EchoTitle *offset_title;
113         EchoOffset *offset;
114         Echo *plugin;
115 };
116
117
118
119
120
121 class EchoConfig
122 {
123 public:
124         EchoConfig();
125         int equivalent(EchoConfig &that);
126         void copy_from(EchoConfig &that);
127         void interpolate(EchoConfig &prev, EchoConfig &next,
128                 int64_t prev_frame, int64_t next_frame, int64_t current_frame);
129         double level;
130         double atten;
131         double offset;
132 };
133
134
135 class Echo : public PluginAClient
136 {
137 public:
138         class ring_buffer {
139                 int bsz;
140                 double *ip, *op;        // in ptr, out ptr
141                 double *bfr, *lmt;      // first, limit
142                 void reset() { ip = op = bfr;  lmt = bfr + bsz; }
143         public:
144                 ring_buffer(int sz) { bfr = new double[bsz = sz]; reset(); }
145                 ~ring_buffer() { delete [] bfr; }
146                 void clear() { memset(bfr, 0, bsz*sizeof(*bfr)); }
147                 double &icur() { return  *ip; }
148                 double &ocur() { return  *op; }
149                 double &inxt() { double &v=*ip; if( ++ip>=lmt ) ip=bfr; return v; }
150                 double &onxt() { double &v=*op; if( ++op>=lmt ) op=bfr; return v; }
151                 int64_t iseek(int64_t n) { ip = bfr+(n%bsz); return n; }
152                 int64_t oseek(int64_t n) { op = bfr+(n%bsz); return n; }
153         } **rbfr;
154         int64_t rpos;
155
156         Echo(PluginServer *server);
157         ~Echo();
158
159         PLUGIN_CLASS_MEMBERS2(EchoConfig)
160         int is_realtime();
161         int is_multichannel();
162         int process_buffer(int64_t size, Samples **buffer, int64_t start_position, int sample_rate);
163
164         void read_data(KeyFrame *keyframe);
165         void save_data(KeyFrame *keyframe);
166         void update_gui();
167
168         void reset();
169         void alloc_buffers(int nch, int isz, int rsz);
170         void delete_buffers();
171
172         int nch, rsz, isz;
173         int64_t bfr_pos;
174         double **ibfr;
175         DB db;
176 };
177
178
179 #endif