r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / plugins / synthesizer / synthesizer.h
blob78d7ade3bf768a69feb4b9b63dd5ab7f4aa832de
1 #ifndef SYNTHESIZER_H
2 #define SYNTHESIZER_H
6 #include "filexml.inc"
7 #include "guicast.h"
8 #include "mutex.h"
9 #include "pluginaclient.h"
10 #include "vframe.inc"
13 class Synth;
14 class SynthWindow;
16 #define TOTALOSCILLATORS 1
17 #define OSCILLATORHEIGHT 40
19 #define SINE 0
20 #define SAWTOOTH 1
21 #define SQUARE 2
22 #define TRIANGLE 3
23 #define PULSE 4
24 #define NOISE 5
25 #define DC 6
28 class SynthCanvas;
29 class SynthWaveForm;
30 class SynthBaseFreq;
31 class SynthFreqPot;
32 class SynthOscGUI;
33 class SynthScroll;
34 class SynthSubWindow;
35 class SynthWetness;
37 class SynthWindow : public BC_Window
39 public:
40 SynthWindow(Synth *synth, int x, int y);
41 ~SynthWindow();
43 int create_objects();
44 int close_event();
45 int resize_event(int w, int h);
46 void update_gui();
47 int waveform_to_text(char *text, int waveform);
48 void update_scrollbar();
49 void update_oscillators();
52 Synth *synth;
53 SynthCanvas *canvas;
54 SynthWetness *wetness;
55 SynthWaveForm *waveform;
56 SynthBaseFreq *base_freq;
57 SynthFreqPot *freqpot;
58 SynthSubWindow *subwindow;
59 SynthScroll *scroll;
60 ArrayList<SynthOscGUI*> oscillators;
64 class SynthOscGUILevel;
65 class SynthOscGUIPhase;
66 class SynthOscGUIFreq;
68 class SynthOscGUI
70 public:
71 SynthOscGUI(SynthWindow *window, int number);
72 ~SynthOscGUI();
74 int create_objects(int view_y);
76 SynthOscGUILevel *level;
77 SynthOscGUIPhase *phase;
78 SynthOscGUIFreq *freq;
79 BC_Title *title;
81 int number;
82 SynthWindow *window;
85 class SynthOscGUILevel : public BC_FPot
87 public:
88 SynthOscGUILevel(Synth *synth, SynthOscGUI *gui, int y);
89 ~SynthOscGUILevel();
91 int handle_event();
93 Synth *synth;
94 SynthOscGUI *gui;
97 class SynthOscGUIPhase : public BC_IPot
99 public:
100 SynthOscGUIPhase(Synth *synth, SynthOscGUI *gui, int y);
101 ~SynthOscGUIPhase();
103 int handle_event();
105 Synth *synth;
106 SynthOscGUI *gui;
109 class SynthOscGUIFreq : public BC_IPot
111 public:
112 SynthOscGUIFreq(Synth *synth, SynthOscGUI *gui, int y);
113 ~SynthOscGUIFreq();
115 int handle_event();
117 Synth *synth;
118 SynthOscGUI *gui;
121 class SynthScroll : public BC_ScrollBar
123 public:
124 SynthScroll(Synth *synth, SynthWindow *window, int x, int y, int h);
125 ~SynthScroll();
127 int handle_event();
129 Synth *synth;
130 SynthWindow *window;
133 class SynthAddOsc : public BC_GenericButton
135 public:
136 SynthAddOsc(Synth *synth, SynthWindow *window, int x, int y);
137 ~SynthAddOsc();
139 int handle_event();
141 Synth *synth;
142 SynthWindow *window;
146 class SynthDelOsc : public BC_GenericButton
148 public:
149 SynthDelOsc(Synth *synth, SynthWindow *window, int x, int y);
150 ~SynthDelOsc();
152 int handle_event();
154 Synth *synth;
155 SynthWindow *window;
158 class SynthSubWindow : public BC_SubWindow
160 public:
161 SynthSubWindow(Synth *synth, int x, int y, int w, int h);
162 ~SynthSubWindow();
164 Synth *synth;
167 class SynthClear : public BC_GenericButton
169 public:
170 SynthClear(Synth *synth, int x, int y);
171 ~SynthClear();
172 int handle_event();
173 Synth *synth;
176 class SynthWaveForm : public BC_PopupMenu
178 public:
179 SynthWaveForm(Synth *synth, int x, int y, char *text);
180 ~SynthWaveForm();
182 int create_objects();
183 Synth *synth;
186 class SynthWaveFormItem : public BC_MenuItem
188 public:
189 SynthWaveFormItem(Synth *synth, char *text, int value);
190 ~SynthWaveFormItem();
192 int handle_event();
194 int value;
195 Synth *synth;
198 class SynthBaseFreq : public BC_TextBox
200 public:
201 SynthBaseFreq(Synth *synth, int x, int y);
202 ~SynthBaseFreq();
203 int handle_event();
204 Synth *synth;
205 SynthFreqPot *freq_pot;
208 class SynthFreqPot : public BC_QPot
210 public:
211 SynthFreqPot(Synth *synth, SynthWindow *window, int x, int y);
212 ~SynthFreqPot();
213 int handle_event();
214 SynthWindow *window;
215 Synth *synth;
216 SynthBaseFreq *freq_text;
219 class SynthWetness : public BC_FPot
221 public:
222 SynthWetness(Synth *synth, int x, int y);
223 int handle_event();
224 Synth *synth;
228 class SynthCanvas : public BC_SubWindow
230 public:
231 SynthCanvas(Synth *synth,
232 SynthWindow *window,
233 int x,
234 int y,
235 int w,
236 int h);
237 ~SynthCanvas();
239 int update();
240 Synth *synth;
241 SynthWindow *window;
244 // ======================= level calculations
245 class SynthLevelZero : public BC_MenuItem
247 public:
248 SynthLevelZero(Synth *synth);
249 ~SynthLevelZero();
250 int handle_event();
251 Synth *synth;
254 class SynthLevelMax : public BC_MenuItem
256 public:
257 SynthLevelMax(Synth *synth);
258 ~SynthLevelMax();
259 int handle_event();
260 Synth *synth;
263 class SynthLevelNormalize : public BC_MenuItem
265 public:
266 SynthLevelNormalize(Synth *synth);
267 ~SynthLevelNormalize();
268 int handle_event();
269 Synth *synth;
272 class SynthLevelSlope : public BC_MenuItem
274 public:
275 SynthLevelSlope(Synth *synth);
276 ~SynthLevelSlope();
277 int handle_event();
278 Synth *synth;
281 class SynthLevelRandom : public BC_MenuItem
283 public:
284 SynthLevelRandom(Synth *synth);
285 ~SynthLevelRandom();
286 int handle_event();
287 Synth *synth;
290 class SynthLevelInvert : public BC_MenuItem
292 public:
293 SynthLevelInvert(Synth *synth);
294 ~SynthLevelInvert();
295 int handle_event();
296 Synth *synth;
299 class SynthLevelSine : public BC_MenuItem
301 public:
302 SynthLevelSine(Synth *synth);
303 ~SynthLevelSine();
304 int handle_event();
305 Synth *synth;
308 // ============================ phase calculations
310 class SynthPhaseInvert : public BC_MenuItem
312 public:
313 SynthPhaseInvert(Synth *synth);
314 ~SynthPhaseInvert();
315 int handle_event();
316 Synth *synth;
319 class SynthPhaseZero : public BC_MenuItem
321 public:
322 SynthPhaseZero(Synth *synth);
323 ~SynthPhaseZero();
324 int handle_event();
325 Synth *synth;
328 class SynthPhaseSine : public BC_MenuItem
330 public:
331 SynthPhaseSine(Synth *synth);
332 ~SynthPhaseSine();
333 int handle_event();
334 Synth *synth;
337 class SynthPhaseRandom : public BC_MenuItem
339 public:
340 SynthPhaseRandom(Synth *synth);
341 ~SynthPhaseRandom();
342 int handle_event();
343 Synth *synth;
347 // ============================ freq calculations
349 class SynthFreqRandom : public BC_MenuItem
351 public:
352 SynthFreqRandom(Synth *synth);
353 ~SynthFreqRandom();
354 int handle_event();
355 Synth *synth;
358 class SynthFreqEnum : public BC_MenuItem
360 public:
361 SynthFreqEnum(Synth *synth);
362 ~SynthFreqEnum();
363 int handle_event();
364 Synth *synth;
367 class SynthFreqEven : public BC_MenuItem
369 public:
370 SynthFreqEven(Synth *synth);
371 ~SynthFreqEven();
372 int handle_event();
373 Synth *synth;
376 class SynthFreqOdd : public BC_MenuItem
378 public:
379 SynthFreqOdd(Synth *synth);
380 ~SynthFreqOdd();
381 int handle_event();
382 Synth *synth;
385 class SynthFreqFibonacci : public BC_MenuItem
387 public:
388 SynthFreqFibonacci(Synth *synth);
389 ~SynthFreqFibonacci();
390 int handle_event();
391 Synth *synth;
394 class SynthFreqPrime : public BC_MenuItem
396 public:
397 SynthFreqPrime(Synth *synth);
398 ~SynthFreqPrime();
399 int handle_event();
400 Synth *synth;
401 private:
402 float get_next_prime(float number);
406 class SynthThread : public Thread
408 public:
409 SynthThread(Synth *synth);
410 ~SynthThread();
412 void run();
414 Mutex completion;
415 Synth *synth;
416 SynthWindow *window;
419 class SynthOscillatorConfig
421 public:
422 SynthOscillatorConfig(int number);
423 ~SynthOscillatorConfig();
425 int equivalent(SynthOscillatorConfig &that);
426 void copy_from(SynthOscillatorConfig& that);
427 void reset();
428 void load_defaults(Defaults *defaults);
429 void save_defaults(Defaults *defaults);
430 void read_data(FileXML *file);
431 void save_data(FileXML *file);
432 int is_realtime();
434 float level;
435 float phase;
436 float freq_factor;
437 int number;
442 class SynthConfig
444 public:
445 SynthConfig();
446 ~SynthConfig();
448 int equivalent(SynthConfig &that);
449 void copy_from(SynthConfig &that);
450 void interpolate(SynthConfig &prev,
451 SynthConfig &next,
452 int64_t prev_frame,
453 int64_t next_frame,
454 int64_t current_frame);
455 void reset();
457 float wetness;
458 int64_t base_freq; // base frequency for oscillators
459 int wavefunction; // SINE, SAWTOOTH, etc
460 ArrayList<SynthOscillatorConfig*> oscillator_config;
464 class Synth : public PluginAClient
466 public:
467 Synth(PluginServer *server);
468 ~Synth();
472 int is_realtime();
473 int is_synthesis();
474 int load_configuration();
475 int load_defaults();
476 VFrame* new_picon();
477 char* plugin_title();
478 void read_data(KeyFrame *keyframe);
479 void save_data(KeyFrame *keyframe);
480 int save_defaults();
481 int show_gui();
482 void raise_window();
483 int set_string();
484 int process_realtime(int64_t size, double *input_ptr, double *output_ptr);
492 void add_oscillator();
493 void delete_oscillator();
494 double get_total_power();
495 double get_oscillator_point(float x,
496 double normalize_constant,
497 int oscillator);
498 double solve_eqn(double *output,
499 double x1,
500 double x2,
501 double normalize_constant,
502 int oscillator);
503 double get_point(float x, double normalize_constant);
504 double function_square(double x);
505 double function_pulse(double x);
506 double function_noise();
507 double function_sawtooth(double x);
508 double function_triangle(double x);
509 void reconfigure();
510 int overlay_synth(int64_t start, int64_t length, double *input, double *output);
511 void update_gui();
512 void reset();
516 double *dsp_buffer;
517 int need_reconfigure;
518 Defaults *defaults;
519 SynthThread *thread;
520 SynthConfig config;
521 int w, h;
522 DB db;
523 int64_t waveform_length; // length of loop buffer
524 int64_t waveform_sample; // current sample in waveform of loop
525 int64_t samples_rendered; // samples of the dsp_buffer rendered since last buffer redo
526 float period; // number of samples in a period for this frequency
536 #endif