4 * Copyright (C) 2010 Adam Williams <broadcast at earthling dot net>
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.
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.
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
27 #include "filexml.inc"
30 #include "pluginaclient.h"
37 // Frequency table for piano
38 float keyboard_freqs[] =
111 #define TOTALOSCILLATORS 1
112 #define OSCILLATORHEIGHT 40
113 #define TOTALNOTES ((int)(sizeof(keyboard_freqs) / sizeof(float)))
115 #define FIRST_TITLE (MIDDLE_C - 12)
116 #define LAST_TITLE (MIDDLE_C + 12)
137 class SynthMomentary;
139 class SynthWindow : public PluginClientWindow
142 SynthWindow(Synth *synth);
145 void create_objects();
146 int resize_event(int w, int h);
148 int waveform_to_text(char *text, int waveform);
149 void update_scrollbar();
150 void update_oscillators();
152 void update_note_selection();
153 int keypress_event();
154 void update_blackkey(int number, int *current_title, int x, int y);
155 void update_whitekey(int number, int *current_title, int x, int y);
160 SynthWetness *wetness;
161 SynthWaveForm *waveform;
162 SynthBaseFreq *base_freq;
163 SynthFreqPot *freqpot;
164 BC_SubWindow *osc_subwindow;
165 OscScroll *osc_scroll;
166 BC_SubWindow *note_subwindow;
167 NoteScroll *note_scroll;
168 ArrayList<SynthOscGUI*> oscillators;
169 SynthNote *notes[TOTALNOTES];
170 BC_Title *note_titles[TOTALNOTES];
171 BC_Title *note_instructions;
172 SynthMomentary *momentary;
173 VFrame *white_key[5];
174 VFrame *black_key[5];
178 int text_white_margin;
179 int text_black_margin;
180 // Button press currently happening if > -1
182 // If we are stopping or starting notes in a drag
186 class SynthMomentary : public BC_CheckBox
189 SynthMomentary(SynthWindow *window, int x, int y, char *text);
194 class SynthNote : public BC_Toggle
197 SynthNote(SynthWindow *window, VFrame **images, int number, int x, int y);
200 int keypress_event();
201 int keyrelease_event();
202 int button_press_event();
203 int button_release_event();
204 int cursor_motion_event();
205 int draw_face(int flash, int flush);
212 class SynthOscGUILevel;
213 class SynthOscGUIPhase;
214 class SynthOscGUIFreq;
219 SynthOscGUI(SynthWindow *window, int number);
222 void create_objects(int view_y);
224 SynthOscGUILevel *level;
225 SynthOscGUIPhase *phase;
226 SynthOscGUIFreq *freq;
233 class SynthOscGUILevel : public BC_FPot
236 SynthOscGUILevel(Synth *synth, SynthOscGUI *gui, int y);
245 class SynthOscGUIPhase : public BC_IPot
248 SynthOscGUIPhase(Synth *synth, SynthOscGUI *gui, int y);
257 class SynthOscGUIFreq : public BC_IPot
260 SynthOscGUIFreq(Synth *synth, SynthOscGUI *gui, int y);
269 class OscScroll : public BC_ScrollBar
272 OscScroll(Synth *synth, SynthWindow *window, int x, int y, int h);
281 class NoteScroll : public BC_ScrollBar
284 NoteScroll(Synth *synth, SynthWindow *window, int x, int y, int w);
293 class SynthAddOsc : public BC_GenericButton
296 SynthAddOsc(Synth *synth, SynthWindow *window, int x, int y);
306 class SynthDelOsc : public BC_GenericButton
309 SynthDelOsc(Synth *synth, SynthWindow *window, int x, int y);
318 class SynthClear : public BC_GenericButton
321 SynthClear(Synth *synth, int x, int y);
327 class SynthWaveForm : public BC_PopupMenu
330 SynthWaveForm(Synth *synth, int x, int y, char *text);
333 void create_objects();
337 class SynthWaveFormItem : public BC_MenuItem
340 SynthWaveFormItem(Synth *synth, char *text, int value);
341 ~SynthWaveFormItem();
349 class SynthBaseFreq : public BC_TextBox
352 SynthBaseFreq(Synth *synth, SynthWindow *window, int x, int y);
356 SynthFreqPot *freq_pot;
360 class SynthFreqPot : public BC_QPot
363 SynthFreqPot(Synth *synth, SynthWindow *window, int x, int y);
368 SynthBaseFreq *freq_text;
371 class SynthWetness : public BC_FPot
374 SynthWetness(Synth *synth, int x, int y);
380 class SynthCanvas : public BC_SubWindow
383 SynthCanvas(Synth *synth,
399 // ======================= level calculations
400 class SynthLevelZero : public BC_MenuItem
403 SynthLevelZero(Synth *synth);
409 class SynthLevelMax : public BC_MenuItem
412 SynthLevelMax(Synth *synth);
418 class SynthLevelNormalize : public BC_MenuItem
421 SynthLevelNormalize(Synth *synth);
422 ~SynthLevelNormalize();
427 class SynthLevelSlope : public BC_MenuItem
430 SynthLevelSlope(Synth *synth);
436 class SynthLevelRandom : public BC_MenuItem
439 SynthLevelRandom(Synth *synth);
445 class SynthLevelInvert : public BC_MenuItem
448 SynthLevelInvert(Synth *synth);
454 class SynthLevelSine : public BC_MenuItem
457 SynthLevelSine(Synth *synth);
463 // ============================ phase calculations
465 class SynthPhaseInvert : public BC_MenuItem
468 SynthPhaseInvert(Synth *synth);
474 class SynthPhaseZero : public BC_MenuItem
477 SynthPhaseZero(Synth *synth);
483 class SynthPhaseSine : public BC_MenuItem
486 SynthPhaseSine(Synth *synth);
492 class SynthPhaseRandom : public BC_MenuItem
495 SynthPhaseRandom(Synth *synth);
502 // ============================ freq calculations
504 class SynthFreqRandom : public BC_MenuItem
507 SynthFreqRandom(Synth *synth);
513 class SynthFreqEnum : public BC_MenuItem
516 SynthFreqEnum(Synth *synth);
522 class SynthFreqEven : public BC_MenuItem
525 SynthFreqEven(Synth *synth);
531 class SynthFreqOdd : public BC_MenuItem
534 SynthFreqOdd(Synth *synth);
540 class SynthFreqFibonacci : public BC_MenuItem
543 SynthFreqFibonacci(Synth *synth);
544 ~SynthFreqFibonacci();
549 class SynthFreqPrime : public BC_MenuItem
552 SynthFreqPrime(Synth *synth);
557 float get_next_prime(float number);
562 class SynthOscillatorConfig
565 SynthOscillatorConfig(int number);
566 ~SynthOscillatorConfig();
568 int equivalent(SynthOscillatorConfig &that);
569 void copy_from(SynthOscillatorConfig& that);
571 void read_data(FileXML *file);
572 void save_data(FileXML *file);
589 int equivalent(SynthConfig &that);
590 void copy_from(SynthConfig &that);
591 void interpolate(SynthConfig &prev,
595 int64_t current_frame);
599 // base frequency for oscillators
600 // Freqs of 0 are unused.
601 double base_freq[MAX_FREQS];
602 int wavefunction; // SINE, SAWTOOTH, etc
603 ArrayList<SynthOscillatorConfig*> oscillator_config;
608 class Synth : public PluginAClient
611 Synth(PluginServer *server);
615 PLUGIN_CLASS_MEMBERS(SynthConfig)
618 void read_data(KeyFrame *keyframe);
619 void save_data(KeyFrame *keyframe);
620 int process_realtime(int64_t size, Samples *input_ptr, Samples *output_ptr);
625 // Frequency is in the table of base_freqs
626 int freq_exists(double freq);
627 // Manage frequency table
628 void new_freq(double freq);
629 void delete_freq(double freq);
632 void add_oscillator();
633 void delete_oscillator();
634 double get_total_power();
635 double get_oscillator_point(float x,
636 double normalize_constant,
638 double solve_eqn(double *output,
641 double normalize_constant,
643 double get_point(float x, double normalize_constant);
644 double function_square(double x);
645 double function_pulse(double x);
646 double function_noise();
647 double function_sawtooth(double x);
648 double function_triangle(double x);
650 int overlay_synth(double freq,
659 int window_w, window_h;
660 int need_reconfigure;
662 // Samples since last reconfiguration
663 int64_t waveform_sample;