00001 #ifndef SYNTHESIZER_H
00002 #define SYNTHESIZER_H
00003
00004
00005
00006 #include "filexml.inc"
00007 #include "guicast.h"
00008 #include "mutex.h"
00009 #include "pluginaclient.h"
00010 #include "vframe.inc"
00011
00012
00013 class Synth;
00014 class SynthWindow;
00015
00016 #define TOTALOSCILLATORS 1
00017 #define OSCILLATORHEIGHT 40
00018
00019 #define SINE 0
00020 #define SAWTOOTH 1
00021 #define SQUARE 2
00022 #define TRIANGLE 3
00023 #define PULSE 4
00024 #define NOISE 5
00025 #define DC 6
00026
00027
00028 class SynthCanvas;
00029 class SynthWaveForm;
00030 class SynthBaseFreq;
00031 class SynthFreqPot;
00032 class SynthOscGUI;
00033 class SynthScroll;
00034 class SynthSubWindow;
00035 class SynthWetness;
00036
00037 class SynthWindow : public BC_Window
00038 {
00039 public:
00040 SynthWindow(Synth *synth, int x, int y);
00041 ~SynthWindow();
00042
00043 int create_objects();
00044 int close_event();
00045 int resize_event(int w, int h);
00046 void update_gui();
00047 int waveform_to_text(char *text, int waveform);
00048 void update_scrollbar();
00049 void update_oscillators();
00050
00051
00052 Synth *synth;
00053 SynthCanvas *canvas;
00054 SynthWetness *wetness;
00055 SynthWaveForm *waveform;
00056 SynthBaseFreq *base_freq;
00057 SynthFreqPot *freqpot;
00058 SynthSubWindow *subwindow;
00059 SynthScroll *scroll;
00060 ArrayList<SynthOscGUI*> oscillators;
00061 };
00062
00063
00064 class SynthOscGUILevel;
00065 class SynthOscGUIPhase;
00066 class SynthOscGUIFreq;
00067
00068 class SynthOscGUI
00069 {
00070 public:
00071 SynthOscGUI(SynthWindow *window, int number);
00072 ~SynthOscGUI();
00073
00074 int create_objects(int view_y);
00075
00076 SynthOscGUILevel *level;
00077 SynthOscGUIPhase *phase;
00078 SynthOscGUIFreq *freq;
00079 BC_Title *title;
00080
00081 int number;
00082 SynthWindow *window;
00083 };
00084
00085 class SynthOscGUILevel : public BC_FPot
00086 {
00087 public:
00088 SynthOscGUILevel(Synth *synth, SynthOscGUI *gui, int y);
00089 ~SynthOscGUILevel();
00090
00091 int handle_event();
00092
00093 Synth *synth;
00094 SynthOscGUI *gui;
00095 };
00096
00097 class SynthOscGUIPhase : public BC_IPot
00098 {
00099 public:
00100 SynthOscGUIPhase(Synth *synth, SynthOscGUI *gui, int y);
00101 ~SynthOscGUIPhase();
00102
00103 int handle_event();
00104
00105 Synth *synth;
00106 SynthOscGUI *gui;
00107 };
00108
00109 class SynthOscGUIFreq : public BC_IPot
00110 {
00111 public:
00112 SynthOscGUIFreq(Synth *synth, SynthOscGUI *gui, int y);
00113 ~SynthOscGUIFreq();
00114
00115 int handle_event();
00116
00117 Synth *synth;
00118 SynthOscGUI *gui;
00119 };
00120
00121 class SynthScroll : public BC_ScrollBar
00122 {
00123 public:
00124 SynthScroll(Synth *synth, SynthWindow *window, int x, int y, int h);
00125 ~SynthScroll();
00126
00127 int handle_event();
00128
00129 Synth *synth;
00130 SynthWindow *window;
00131 };
00132
00133 class SynthAddOsc : public BC_GenericButton
00134 {
00135 public:
00136 SynthAddOsc(Synth *synth, SynthWindow *window, int x, int y);
00137 ~SynthAddOsc();
00138
00139 int handle_event();
00140
00141 Synth *synth;
00142 SynthWindow *window;
00143 };
00144
00145
00146 class SynthDelOsc : public BC_GenericButton
00147 {
00148 public:
00149 SynthDelOsc(Synth *synth, SynthWindow *window, int x, int y);
00150 ~SynthDelOsc();
00151
00152 int handle_event();
00153
00154 Synth *synth;
00155 SynthWindow *window;
00156 };
00157
00158 class SynthSubWindow : public BC_SubWindow
00159 {
00160 public:
00161 SynthSubWindow(Synth *synth, int x, int y, int w, int h);
00162 ~SynthSubWindow();
00163
00164 Synth *synth;
00165 };
00166
00167 class SynthClear : public BC_GenericButton
00168 {
00169 public:
00170 SynthClear(Synth *synth, int x, int y);
00171 ~SynthClear();
00172 int handle_event();
00173 Synth *synth;
00174 };
00175
00176 class SynthWaveForm : public BC_PopupMenu
00177 {
00178 public:
00179 SynthWaveForm(Synth *synth, int x, int y, char *text);
00180 ~SynthWaveForm();
00181
00182 int create_objects();
00183 Synth *synth;
00184 };
00185
00186 class SynthWaveFormItem : public BC_MenuItem
00187 {
00188 public:
00189 SynthWaveFormItem(Synth *synth, char *text, int value);
00190 ~SynthWaveFormItem();
00191
00192 int handle_event();
00193
00194 int value;
00195 Synth *synth;
00196 };
00197
00198 class SynthBaseFreq : public BC_TextBox
00199 {
00200 public:
00201 SynthBaseFreq(Synth *synth, int x, int y);
00202 ~SynthBaseFreq();
00203 int handle_event();
00204 Synth *synth;
00205 SynthFreqPot *freq_pot;
00206 };
00207
00208 class SynthFreqPot : public BC_QPot
00209 {
00210 public:
00211 SynthFreqPot(Synth *synth, SynthWindow *window, int x, int y);
00212 ~SynthFreqPot();
00213 int handle_event();
00214 SynthWindow *window;
00215 Synth *synth;
00216 SynthBaseFreq *freq_text;
00217 };
00218
00219 class SynthWetness : public BC_FPot
00220 {
00221 public:
00222 SynthWetness(Synth *synth, int x, int y);
00223 int handle_event();
00224 Synth *synth;
00225 };
00226
00227
00228 class SynthCanvas : public BC_SubWindow
00229 {
00230 public:
00231 SynthCanvas(Synth *synth,
00232 SynthWindow *window,
00233 int x,
00234 int y,
00235 int w,
00236 int h);
00237 ~SynthCanvas();
00238
00239 int update();
00240 Synth *synth;
00241 SynthWindow *window;
00242 };
00243
00244
00245 class SynthLevelZero : public BC_MenuItem
00246 {
00247 public:
00248 SynthLevelZero(Synth *synth);
00249 ~SynthLevelZero();
00250 int handle_event();
00251 Synth *synth;
00252 };
00253
00254 class SynthLevelMax : public BC_MenuItem
00255 {
00256 public:
00257 SynthLevelMax(Synth *synth);
00258 ~SynthLevelMax();
00259 int handle_event();
00260 Synth *synth;
00261 };
00262
00263 class SynthLevelNormalize : public BC_MenuItem
00264 {
00265 public:
00266 SynthLevelNormalize(Synth *synth);
00267 ~SynthLevelNormalize();
00268 int handle_event();
00269 Synth *synth;
00270 };
00271
00272 class SynthLevelSlope : public BC_MenuItem
00273 {
00274 public:
00275 SynthLevelSlope(Synth *synth);
00276 ~SynthLevelSlope();
00277 int handle_event();
00278 Synth *synth;
00279 };
00280
00281 class SynthLevelRandom : public BC_MenuItem
00282 {
00283 public:
00284 SynthLevelRandom(Synth *synth);
00285 ~SynthLevelRandom();
00286 int handle_event();
00287 Synth *synth;
00288 };
00289
00290 class SynthLevelInvert : public BC_MenuItem
00291 {
00292 public:
00293 SynthLevelInvert(Synth *synth);
00294 ~SynthLevelInvert();
00295 int handle_event();
00296 Synth *synth;
00297 };
00298
00299 class SynthLevelSine : public BC_MenuItem
00300 {
00301 public:
00302 SynthLevelSine(Synth *synth);
00303 ~SynthLevelSine();
00304 int handle_event();
00305 Synth *synth;
00306 };
00307
00308
00309
00310 class SynthPhaseInvert : public BC_MenuItem
00311 {
00312 public:
00313 SynthPhaseInvert(Synth *synth);
00314 ~SynthPhaseInvert();
00315 int handle_event();
00316 Synth *synth;
00317 };
00318
00319 class SynthPhaseZero : public BC_MenuItem
00320 {
00321 public:
00322 SynthPhaseZero(Synth *synth);
00323 ~SynthPhaseZero();
00324 int handle_event();
00325 Synth *synth;
00326 };
00327
00328 class SynthPhaseSine : public BC_MenuItem
00329 {
00330 public:
00331 SynthPhaseSine(Synth *synth);
00332 ~SynthPhaseSine();
00333 int handle_event();
00334 Synth *synth;
00335 };
00336
00337 class SynthPhaseRandom : public BC_MenuItem
00338 {
00339 public:
00340 SynthPhaseRandom(Synth *synth);
00341 ~SynthPhaseRandom();
00342 int handle_event();
00343 Synth *synth;
00344 };
00345
00346
00347
00348
00349 class SynthFreqRandom : public BC_MenuItem
00350 {
00351 public:
00352 SynthFreqRandom(Synth *synth);
00353 ~SynthFreqRandom();
00354 int handle_event();
00355 Synth *synth;
00356 };
00357
00358 class SynthFreqEnum : public BC_MenuItem
00359 {
00360 public:
00361 SynthFreqEnum(Synth *synth);
00362 ~SynthFreqEnum();
00363 int handle_event();
00364 Synth *synth;
00365 };
00366
00367 class SynthFreqEven : public BC_MenuItem
00368 {
00369 public:
00370 SynthFreqEven(Synth *synth);
00371 ~SynthFreqEven();
00372 int handle_event();
00373 Synth *synth;
00374 };
00375
00376 class SynthFreqOdd : public BC_MenuItem
00377 {
00378 public:
00379 SynthFreqOdd(Synth *synth);
00380 ~SynthFreqOdd();
00381 int handle_event();
00382 Synth *synth;
00383 };
00384
00385 class SynthFreqFibonacci : public BC_MenuItem
00386 {
00387 public:
00388 SynthFreqFibonacci(Synth *synth);
00389 ~SynthFreqFibonacci();
00390 int handle_event();
00391 Synth *synth;
00392 };
00393
00394 class SynthFreqPrime : public BC_MenuItem
00395 {
00396 public:
00397 SynthFreqPrime(Synth *synth);
00398 ~SynthFreqPrime();
00399 int handle_event();
00400 Synth *synth;
00401 private:
00402 float get_next_prime(float number);
00403 };
00404
00405
00406 class SynthThread : public Thread
00407 {
00408 public:
00409 SynthThread(Synth *synth);
00410 ~SynthThread();
00411
00412 void run();
00413
00414 Mutex completion;
00415 Synth *synth;
00416 SynthWindow *window;
00417 };
00418
00419 class SynthOscillatorConfig
00420 {
00421 public:
00422 SynthOscillatorConfig(int number);
00423 ~SynthOscillatorConfig();
00424
00425 int equivalent(SynthOscillatorConfig &that);
00426 void copy_from(SynthOscillatorConfig& that);
00427 void reset();
00428 void load_defaults(BC_Hash *defaults);
00429 void save_defaults(BC_Hash *defaults);
00430 void read_data(FileXML *file);
00431 void save_data(FileXML *file);
00432 int is_realtime();
00433
00434 float level;
00435 float phase;
00436 float freq_factor;
00437 int number;
00438 };
00439
00440
00441
00442 class SynthConfig
00443 {
00444 public:
00445 SynthConfig();
00446 ~SynthConfig();
00447
00448 int equivalent(SynthConfig &that);
00449 void copy_from(SynthConfig &that);
00450 void interpolate(SynthConfig &prev,
00451 SynthConfig &next,
00452 int64_t prev_frame,
00453 int64_t next_frame,
00454 int64_t current_frame);
00455 void reset();
00456
00457 float wetness;
00458 int64_t base_freq;
00459 int wavefunction;
00460 ArrayList<SynthOscillatorConfig*> oscillator_config;
00461 };
00462
00463
00464 class Synth : public PluginAClient
00465 {
00466 public:
00467 Synth(PluginServer *server);
00468 ~Synth();
00469
00470
00471
00472 int is_realtime();
00473 int is_synthesis();
00474 int load_configuration();
00475 int load_defaults();
00476 VFrame* new_picon();
00477 char* plugin_title();
00478 void read_data(KeyFrame *keyframe);
00479 void save_data(KeyFrame *keyframe);
00480 int save_defaults();
00481 int show_gui();
00482 void raise_window();
00483 int set_string();
00484 int process_realtime(int64_t size, double *input_ptr, double *output_ptr);
00485
00486
00487
00488
00489
00490
00491
00492 void add_oscillator();
00493 void delete_oscillator();
00494 double get_total_power();
00495 double get_oscillator_point(float x,
00496 double normalize_constant,
00497 int oscillator);
00498 double solve_eqn(double *output,
00499 double x1,
00500 double x2,
00501 double normalize_constant,
00502 int oscillator);
00503 double get_point(float x, double normalize_constant);
00504 double function_square(double x);
00505 double function_pulse(double x);
00506 double function_noise();
00507 double function_sawtooth(double x);
00508 double function_triangle(double x);
00509 void reconfigure();
00510 int overlay_synth(int64_t start, int64_t length, double *input, double *output);
00511 void update_gui();
00512 void reset();
00513
00514
00515
00516 double *dsp_buffer;
00517 int need_reconfigure;
00518 BC_Hash *defaults;
00519 SynthThread *thread;
00520 SynthConfig config;
00521 int w, h;
00522 DB db;
00523 int64_t waveform_length;
00524 int64_t waveform_sample;
00525 int64_t samples_rendered;
00526 float period;
00527 };
00528
00529
00530
00531
00532
00533
00534
00535
00536 #endif