9 #include "pluginaclient.h"
16 #define TOTALOSCILLATORS 1
17 #define OSCILLATORHEIGHT 40
37 class SynthWindow
: public BC_Window
40 SynthWindow(Synth
*synth
, int x
, int y
);
45 int resize_event(int w
, int h
);
47 int waveform_to_text(char *text
, int waveform
);
48 void update_scrollbar();
49 void update_oscillators();
54 SynthWetness
*wetness
;
55 SynthWaveForm
*waveform
;
56 SynthBaseFreq
*base_freq
;
57 SynthFreqPot
*freqpot
;
58 SynthSubWindow
*subwindow
;
60 ArrayList
<SynthOscGUI
*> oscillators
;
64 class SynthOscGUILevel
;
65 class SynthOscGUIPhase
;
66 class SynthOscGUIFreq
;
71 SynthOscGUI(SynthWindow
*window
, int number
);
74 int create_objects(int view_y
);
76 SynthOscGUILevel
*level
;
77 SynthOscGUIPhase
*phase
;
78 SynthOscGUIFreq
*freq
;
85 class SynthOscGUILevel
: public BC_FPot
88 SynthOscGUILevel(Synth
*synth
, SynthOscGUI
*gui
, int y
);
97 class SynthOscGUIPhase
: public BC_IPot
100 SynthOscGUIPhase(Synth
*synth
, SynthOscGUI
*gui
, int y
);
109 class SynthOscGUIFreq
: public BC_IPot
112 SynthOscGUIFreq(Synth
*synth
, SynthOscGUI
*gui
, int y
);
121 class SynthScroll
: public BC_ScrollBar
124 SynthScroll(Synth
*synth
, SynthWindow
*window
, int x
, int y
, int h
);
133 class SynthAddOsc
: public BC_GenericButton
136 SynthAddOsc(Synth
*synth
, SynthWindow
*window
, int x
, int y
);
146 class SynthDelOsc
: public BC_GenericButton
149 SynthDelOsc(Synth
*synth
, SynthWindow
*window
, int x
, int y
);
158 class SynthSubWindow
: public BC_SubWindow
161 SynthSubWindow(Synth
*synth
, int x
, int y
, int w
, int h
);
167 class SynthClear
: public BC_GenericButton
170 SynthClear(Synth
*synth
, int x
, int y
);
176 class SynthWaveForm
: public BC_PopupMenu
179 SynthWaveForm(Synth
*synth
, int x
, int y
, char *text
);
182 int create_objects();
186 class SynthWaveFormItem
: public BC_MenuItem
189 SynthWaveFormItem(Synth
*synth
, char *text
, int value
);
190 ~SynthWaveFormItem();
198 class SynthBaseFreq
: public BC_TextBox
201 SynthBaseFreq(Synth
*synth
, int x
, int y
);
205 SynthFreqPot
*freq_pot
;
208 class SynthFreqPot
: public BC_QPot
211 SynthFreqPot(Synth
*synth
, SynthWindow
*window
, int x
, int y
);
216 SynthBaseFreq
*freq_text
;
219 class SynthWetness
: public BC_FPot
222 SynthWetness(Synth
*synth
, int x
, int y
);
228 class SynthCanvas
: public BC_SubWindow
231 SynthCanvas(Synth
*synth
,
244 // ======================= level calculations
245 class SynthLevelZero
: public BC_MenuItem
248 SynthLevelZero(Synth
*synth
);
254 class SynthLevelMax
: public BC_MenuItem
257 SynthLevelMax(Synth
*synth
);
263 class SynthLevelNormalize
: public BC_MenuItem
266 SynthLevelNormalize(Synth
*synth
);
267 ~SynthLevelNormalize();
272 class SynthLevelSlope
: public BC_MenuItem
275 SynthLevelSlope(Synth
*synth
);
281 class SynthLevelRandom
: public BC_MenuItem
284 SynthLevelRandom(Synth
*synth
);
290 class SynthLevelInvert
: public BC_MenuItem
293 SynthLevelInvert(Synth
*synth
);
299 class SynthLevelSine
: public BC_MenuItem
302 SynthLevelSine(Synth
*synth
);
308 // ============================ phase calculations
310 class SynthPhaseInvert
: public BC_MenuItem
313 SynthPhaseInvert(Synth
*synth
);
319 class SynthPhaseZero
: public BC_MenuItem
322 SynthPhaseZero(Synth
*synth
);
328 class SynthPhaseSine
: public BC_MenuItem
331 SynthPhaseSine(Synth
*synth
);
337 class SynthPhaseRandom
: public BC_MenuItem
340 SynthPhaseRandom(Synth
*synth
);
347 // ============================ freq calculations
349 class SynthFreqRandom
: public BC_MenuItem
352 SynthFreqRandom(Synth
*synth
);
358 class SynthFreqEnum
: public BC_MenuItem
361 SynthFreqEnum(Synth
*synth
);
367 class SynthFreqEven
: public BC_MenuItem
370 SynthFreqEven(Synth
*synth
);
376 class SynthFreqOdd
: public BC_MenuItem
379 SynthFreqOdd(Synth
*synth
);
385 class SynthFreqFibonacci
: public BC_MenuItem
388 SynthFreqFibonacci(Synth
*synth
);
389 ~SynthFreqFibonacci();
394 class SynthFreqPrime
: public BC_MenuItem
397 SynthFreqPrime(Synth
*synth
);
402 float get_next_prime(float number
);
406 class SynthThread
: public Thread
409 SynthThread(Synth
*synth
);
419 class SynthOscillatorConfig
422 SynthOscillatorConfig(int number
);
423 ~SynthOscillatorConfig();
425 int equivalent(SynthOscillatorConfig
&that
);
426 void copy_from(SynthOscillatorConfig
& that
);
428 void load_defaults(Defaults
*defaults
);
429 void save_defaults(Defaults
*defaults
);
430 void read_data(FileXML
*file
);
431 void save_data(FileXML
*file
);
448 int equivalent(SynthConfig
&that
);
449 void copy_from(SynthConfig
&that
);
450 void interpolate(SynthConfig
&prev
,
454 int64_t current_frame
);
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
467 Synth(PluginServer
*server
);
474 int load_configuration();
477 char* plugin_title();
478 void read_data(KeyFrame
*keyframe
);
479 void save_data(KeyFrame
*keyframe
);
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
,
498 double solve_eqn(double *output
,
501 double normalize_constant
,
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
);
510 int overlay_synth(int64_t start
, int64_t length
, double *input
, double *output
);
517 int need_reconfigure
;
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