4 * Copyright (C) 1997-2017 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
22 #include "bcdisplayinfo.h"
28 #include "synthesizer.h"
30 #include "transportque.inc"
38 REGISTER_PLUGIN(Synth)
43 Synth::Synth(PluginServer *server)
44 : PluginAClient(server)
58 NEW_WINDOW_MACRO(Synth, SynthWindow);
60 const char* Synth::plugin_title() { return N_("Synthesizer"); }
61 int Synth::is_realtime() { return 1; }
62 int Synth::is_synthesis() { return 1; }
73 LOAD_CONFIGURATION_MACRO(Synth, SynthConfig)
80 void Synth::read_data(KeyFrame *keyframe)
83 char string[BCTEXTLEN];
84 // cause htal file to read directly from text
85 input.set_shared_input(keyframe->xbuf);
87 //printf("Synth::read_data %s\n", keyframe->get_data());
88 int result = 0, current_osc = 0;
91 result = input.read_tag();
95 if(input.tag.title_is("SYNTH"))
97 config.wetness = input.tag.get_property("WETNESS", config.wetness);
101 window_w = input.tag.get_property("WINDOW_W", window_w);
102 window_h = input.tag.get_property("WINDOW_H", window_h);
104 config.momentary_notes = input.tag.get_property("MOMENTARY_NOTES", config.momentary_notes);
106 //printf("Synth::read_data %d %d %d\n", __LINE__, window_w, window_h);
107 for(int i = 0; i < MAX_FREQS; i++)
109 sprintf(string, "BASEFREQ_%d", i);
110 config.base_freq[i] = input.tag.get_property(string, (double)0);
113 config.wavefunction = input.tag.get_property("WAVEFUNCTION", config.wavefunction);
114 // int total_oscillators = input.tag.get_property("OSCILLATORS", 0);
117 if(input.tag.title_is("OSCILLATOR"))
119 if(current_osc >= config.oscillator_config.total)
120 config.oscillator_config.append(new SynthOscillatorConfig(current_osc));
122 config.oscillator_config.values[current_osc]->read_data(&input);
128 while(config.oscillator_config.total > current_osc)
129 config.oscillator_config.remove_object();
132 void Synth::save_data(KeyFrame *keyframe)
135 char string[BCTEXTLEN];
137 // cause htal file to store data directly in text
138 output.set_shared_output(keyframe->xbuf);
140 output.tag.set_title("SYNTH");
141 output.tag.set_property("WETNESS", config.wetness);
142 output.tag.set_property("WINDOW_W", window_w);
143 output.tag.set_property("WINDOW_H", window_h);
144 output.tag.set_property("MOMENTARY_NOTES", config.momentary_notes);
146 for(int i = 0; i < MAX_FREQS; i++)
148 // if(!EQUIV(config.base_freq[i], 0))
150 sprintf(string, "BASEFREQ_%d", i);
151 output.tag.set_property(string, config.base_freq[i]);
152 //printf("Synth::save_data %d %s\n", __LINE__, string);
156 output.tag.set_property("WAVEFUNCTION", config.wavefunction);
157 output.tag.set_property("OSCILLATORS", config.oscillator_config.total);
159 output.append_newline();
161 for(int i = 0; i < config.oscillator_config.total; i++)
163 config.oscillator_config.values[i]->save_data(&output);
166 output.terminate_string();
167 //printf("Synth::save_data %d %s\n", __LINE__, output.string);
168 // data is now in *text
173 void Synth::update_gui()
177 if(load_configuration())
179 thread->window->lock_window();
180 ((SynthWindow*)thread->window)->update_gui();
181 thread->window->unlock_window();
187 void Synth::add_oscillator()
189 if(config.oscillator_config.total > MAX_OSCILLATORS) return;
191 config.oscillator_config.append(new SynthOscillatorConfig(config.oscillator_config.total - 1));
194 void Synth::delete_oscillator()
196 if(config.oscillator_config.total)
198 config.oscillator_config.remove_object();
203 double Synth::get_total_power()
207 if(config.wavefunction == DC) return 1.0;
209 for(int i = 0; i < config.oscillator_config.total; i++)
211 result += db.fromdb(config.oscillator_config.values[i]->level);
214 if(result == 0) result = 1; // prevent division by 0
219 double Synth::solve_eqn(double *output,
222 double normalize_constant,
225 SynthOscillatorConfig *config =
226 this->config.oscillator_config.values[oscillator];
227 if(config->level <= INFINITYGAIN) return 0;
229 double power = this->db.fromdb(config->level) * normalize_constant;
230 // Period of fundamental frequency in samples
231 double orig_period = (double)get_samplerate() /
233 // Starting sample in waveform
234 double x = waveform_sample;
235 //printf("Synth::solve_eqn %d %f\n", __LINE__, config->phase);
236 double phase_offset = config->phase * orig_period;
237 // Period of current oscillator
238 double period = orig_period / config->freq_factor;
241 if(get_direction() == PLAY_REVERSE) step = -1;
243 switch(this->config.wavefunction)
246 for(sample = 0; sample < length; sample++)
248 output[sample] += power;
253 for(sample = 0; sample < length; sample++)
255 output[sample] += sin((x + phase_offset) /
256 period * 2 * M_PI) * power;
262 for(sample = 0; sample < length; sample++)
264 output[sample] += function_sawtooth((x + phase_offset) /
271 for(sample = 0; sample < length; sample++)
273 output[sample] += function_square((x + phase_offset) /
280 for(sample = 0; sample < length; sample++)
282 output[sample] += function_triangle((x + phase_offset) /
289 for(sample = 0; sample < length; sample++)
291 output[sample] += function_pulse((x + phase_offset) /
298 for(sample = 0; sample < length; sample++)
300 output[sample] += function_noise() * power;
307 double Synth::get_point(float x, double normalize_constant)
310 for(int i = 0; i < config.oscillator_config.total; i++)
311 result += get_oscillator_point(x, normalize_constant, i);
316 double Synth::get_oscillator_point(float x,
317 double normalize_constant,
320 SynthOscillatorConfig *config = this->config.oscillator_config.values[oscillator];
321 double power = db.fromdb(config->level) * normalize_constant;
322 switch(this->config.wavefunction)
328 return sin((x + config->phase) * config->freq_factor * 2 * M_PI) * power;
331 return function_sawtooth((x + config->phase) * config->freq_factor) * power;
334 return function_square((x + config->phase) * config->freq_factor) * power;
337 return function_triangle((x + config->phase) * config->freq_factor) * power;
340 return function_pulse((x + config->phase) * config->freq_factor) * power;
343 return function_noise() * power;
349 double Synth::function_square(double x)
351 x -= (int)x; // only fraction counts
352 return (x < .5) ? -1 : 1;
355 double Synth::function_pulse(double x)
357 x -= (int)x; // only fraction counts
358 return (x < .5) ? 0 : 1;
361 double Synth::function_noise()
363 return (double)(rand() % 65536 - 32768) / 32768;
366 double Synth::function_sawtooth(double x)
372 double Synth::function_triangle(double x)
375 return (x < .5) ? 1 - x * 4 : -3 + x * 4;
378 int Synth::process_realtime(int64_t size,
382 // sample relative to start of plugin
383 waveform_sample = get_source_position();
385 need_reconfigure |= load_configuration();
386 if(need_reconfigure) reconfigure();
388 double wetness = DB::fromdb(config.wetness);
389 if(EQUIV(config.wetness, INFINITYGAIN)) wetness = 0;
392 double *output_samples = output_ptr->get_data();
393 double *input_samples = input_ptr->get_data();
394 for(int j = 0; j < size; j++)
395 output_samples[j] = input_samples[j] * wetness;
397 // Overlay each frequency
398 for(int j = 0; j < MAX_FREQS; j++)
400 if(!EQUIV(config.base_freq[j], 0))
407 input_ptr->get_data(),
408 output_ptr->get_data());
409 //printf("Synth::process_realtime 2\n");
413 // waveform_sample += size;
417 int Synth::overlay_synth(double freq,
422 double normalize_constant = 1.0 / get_total_power();
423 for(int i = 0; i < config.oscillator_config.total; i++)
424 solve_eqn(output, length, freq, normalize_constant, i);
428 void Synth::reconfigure()
430 need_reconfigure = 0;
431 // waveform_sample = 0;
434 int Synth::freq_exists(double freq)
436 for(int i = 0; i < MAX_FREQS; i++)
439 // printf("Synth::freq_exists %d %d %f %f\n",
443 // config.base_freq[i]);
444 if(fabs(freq - config.base_freq[i]) < 1.0)
451 void Synth::new_freq(double freq)
454 for(int i = 0; i < MAX_FREQS; i++)
456 if(EQUIV(config.base_freq[i], freq)) return;
459 for(int i = 0; i < MAX_FREQS; i++)
461 if(EQUIV(config.base_freq[i], 0))
463 config.base_freq[i] = freq;
464 //printf("Synth::new_freq %d\n", __LINE__);
470 void Synth::delete_freq(double freq)
472 for(int i = 0; i < MAX_FREQS; i++)
474 if(EQUIV(config.base_freq[i], freq))
476 //printf("Synth::delete_freq %d\n", __LINE__);
477 // Shift frequencies back
478 for(int j = i; j < MAX_FREQS - 1; j++)
480 config.base_freq[j] = config.base_freq[j + 1];
482 config.base_freq[MAX_FREQS - 1] = 0;
489 void Synth::delete_freqs()
491 for(int i = 0; i < MAX_FREQS; i++)
492 config.base_freq[i] = 0;
496 SynthWindow::SynthWindow(Synth *synth)
497 : PluginClientWindow(synth, synth->window_w, synth->window_h,
507 bzero(notes, sizeof(SynthNote*) * TOTALNOTES);
511 SynthWindow::~SynthWindow()
521 static const char *keyboard_map[] =
523 "q", "2", "w", "3", "e", "r", "5", "t", "6", "y", "7", "u",
524 "z", "s", "x", "d", "c", "v", "g", "b", "h", "n", "j", "m"
527 void SynthWindow::create_objects()
529 int margin = client->get_theme()->widget_border;
532 add_subwindow(menu = new BC_MenuBar(0, 0, get_w()));
534 BC_Menu *levelmenu, *phasemenu, *harmonicmenu;
535 menu->add_menu(levelmenu = new BC_Menu(_("Level")));
536 menu->add_menu(phasemenu = new BC_Menu(_("Phase")));
537 menu->add_menu(harmonicmenu = new BC_Menu(_("Harmonic")));
539 levelmenu->add_item(new SynthLevelInvert(synth));
540 levelmenu->add_item(new SynthLevelMax(synth));
541 levelmenu->add_item(new SynthLevelRandom(synth));
542 levelmenu->add_item(new SynthLevelSine(synth));
543 levelmenu->add_item(new SynthLevelSlope(synth));
544 levelmenu->add_item(new SynthLevelZero(synth));
546 phasemenu->add_item(new SynthPhaseInvert(synth));
547 phasemenu->add_item(new SynthPhaseRandom(synth));
548 phasemenu->add_item(new SynthPhaseSine(synth));
549 phasemenu->add_item(new SynthPhaseZero(synth));
551 harmonicmenu->add_item(new SynthFreqMin(synth));
552 harmonicmenu->add_item(new SynthFreqEnum(synth));
553 harmonicmenu->add_item(new SynthFreqEven(synth));
554 harmonicmenu->add_item(new SynthFreqFibonacci(synth));
555 harmonicmenu->add_item(new SynthFreqOdd(synth));
556 harmonicmenu->add_item(new SynthFreqPrime(synth));
558 int xs10 = xS(10), xs20 = xS(20), xs50 = xS(50), xs70 = xS(70), xs75 = xS(75), xs240 = xS(240), xs265 = xS(265);
559 int ys10 = yS(10), ys20 = yS(20), ys30 = yS(30), ys40 = yS(40), ys220 = yS(220);
560 int x = xs10, y = ys30;
562 add_subwindow(new BC_Title(x, y, _("Waveform")));
564 add_subwindow(new BC_Title(x, y, _("Wave Function")));
567 add_subwindow(canvas = new SynthCanvas(synth, this, x, y, xS(230), yS(160)));
571 char string[BCTEXTLEN];
572 waveform_to_text(string, synth->config.wavefunction);
574 add_subwindow(waveform = new SynthWaveForm(synth, x, y, string));
575 waveform->create_objects();
577 int x1 = x + waveform->get_w() + xs50;
580 add_subwindow(new BC_Title(x, y, _("Base Frequency:")));
582 add_subwindow(base_freq = new SynthBaseFreq(synth, this, x, y));
583 base_freq->update((float)synth->config.base_freq[0]);
584 x += base_freq->get_w() + synth->get_theme()->widget_border;
585 add_subwindow(freqpot = new SynthFreqPot(synth, this, x, y - ys10));
586 base_freq->freq_pot = freqpot;
587 freqpot->freq_text = base_freq;
588 x -= base_freq->get_w() + synth->get_theme()->widget_border;
590 add_subwindow(new BC_Title(x, y, _("Wetness:")));
591 add_subwindow(wetness = new SynthWetness(synth, x + xs70, y - ys10));
594 add_subwindow(new SynthClear(synth, x, y));
599 add_subwindow(new BC_Title(x, y, _("Level")));
601 add_subwindow(new BC_Title(x, y, _("Phase")));
603 add_subwindow(new BC_Title(x, y, _("Harmonic")));
608 add_subwindow(osc_subwindow = new BC_SubWindow(x, y, xs265, get_h() - y));
610 add_subwindow(osc_scroll = new OscScroll(synth, this, x, y, get_h() - y));
614 add_subwindow(new SynthAddOsc(synth, this, x, y));
616 add_subwindow(new SynthDelOsc(synth, this, x, y));
621 #include "white_up_png.h"
622 #include "white_hi_png.h"
623 #include "white_dn_png.h"
624 #include "white_checked_png.h"
625 #include "white_checkedhi_png.h"
626 #include "black_up_png.h"
627 #include "black_hi_png.h"
628 #include "black_dn_png.h"
629 #include "black_checked_png.h"
630 #include "black_checkedhi_png.h"
631 white_key[0] = new VFramePng(white_up_png);
632 white_key[1] = new VFramePng(white_hi_png);
633 white_key[2] = new VFramePng(white_checked_png);
634 white_key[3] = new VFramePng(white_dn_png);
635 white_key[4] = new VFramePng(white_checkedhi_png);
636 black_key[0] = new VFramePng(black_up_png);
637 black_key[1] = new VFramePng(black_hi_png);
638 black_key[2] = new VFramePng(black_checked_png);
639 black_key[3] = new VFramePng(black_dn_png);
640 black_key[4] = new VFramePng(black_checkedhi_png);
643 add_subwindow(note_subwindow = new BC_SubWindow(x1+xS(20),
644 y, get_w() - (x1+xS(20)),
645 white_key[0]->get_h() + margin +
646 get_text_height(MEDIUMFONT) + margin +
647 get_text_height(MEDIUMFONT) + margin));
648 add_subwindow(note_scroll = new NoteScroll(synth, this, x1,
649 note_subwindow->get_y() + note_subwindow->get_h(),
650 note_subwindow->get_w()));
652 add_subwindow(momentary = new SynthMomentary(this, x1,
653 note_scroll->get_y() + note_scroll->get_h() + margin,
654 _("Momentary notes")));
657 add_subwindow(note_instructions = new BC_Title( x1,
658 momentary->get_y() + momentary->get_h() + margin,
659 _("Ctrl or Shift to select multiple notes.")));
662 update_oscillators();
668 int SynthWindow::keypress_event()
670 if(ctrl_down() && get_keypress() == 'w')
678 int SynthWindow::resize_event(int w, int h)
680 clear_box(0, 0, w, h);
681 osc_subwindow->reposition_window(osc_subwindow->get_x(),
682 osc_subwindow->get_y(),
683 osc_subwindow->get_w(),
684 h - osc_subwindow->get_y());
685 osc_subwindow->clear_box(0, 0, osc_subwindow->get_w(), osc_subwindow->get_h());
686 osc_scroll->reposition_window(osc_scroll->get_x(),
688 h - osc_scroll->get_y());
689 note_subwindow->reposition_window(note_subwindow->get_x(),
690 note_subwindow->get_y(),
691 w - note_subwindow->get_x(),
692 note_subwindow->get_h());
693 note_scroll->reposition_window(note_scroll->get_x(),
694 note_scroll->get_y(),
695 w - note_scroll->get_x());
696 note_scroll->update_length(white_key[0]->get_w() * TOTALNOTES * 7 / 12 +
697 white_key[0]->get_w(),
698 note_scroll->get_position(),
699 note_subwindow->get_w(),
704 update_oscillators();
710 void SynthWindow::update_gui()
712 char string[BCTEXTLEN];
713 freqpot->update((int)synth->config.base_freq[0]);
714 base_freq->update((float)synth->config.base_freq[0]);
715 wetness->update(synth->config.wetness);
716 waveform_to_text(string, synth->config.wavefunction);
717 waveform->set_text(string);
718 momentary->update(synth->config.momentary_notes);
721 update_oscillators();
723 update_note_selection();
727 void SynthWindow::update_scrollbar()
729 osc_scroll->update_length(synth->config.oscillator_config.total * OSCILLATORHEIGHT,
730 osc_scroll->get_position(),
731 osc_subwindow->get_h(),
736 void SynthWindow::update_whitekey(int number,
743 note_subwindow->add_subwindow(notes[number] = new SynthNote(this,
744 white_key, number, x, y));
745 if(number >= FIRST_TITLE && number < LAST_TITLE)
746 note_subwindow->add_subwindow(
747 note_titles[(*current_title)++] = new BC_Title(
748 x + text_white_margin, y2,
749 keyboard_map[number - FIRST_TITLE]));
750 //printf("SynthWindow::update_whitekey %d\n", __LINE__);
754 notes[number]->reposition_window(x, y);
755 if(number >= FIRST_TITLE && number < LAST_TITLE)
756 note_titles[(*current_title)++]->reposition_window(x + text_white_margin,
762 void SynthWindow::update_blackkey(int number,
769 note_subwindow->add_subwindow(notes[number] = new SynthNote(this,
770 black_key, number, x, y));
771 if(number >= FIRST_TITLE && number < LAST_TITLE)
772 note_subwindow->add_subwindow(
773 note_titles[(*current_title)++] = new BC_Title(x + text_black_margin,
774 y1, keyboard_map[number - FIRST_TITLE]));
778 notes[number]->reposition_window(x, y);
779 if(number >= FIRST_TITLE && number < LAST_TITLE)
780 note_titles[(*current_title)++]->reposition_window(x + text_black_margin, y1);
784 void SynthWindow::update_notes()
786 //int octave_w = white_key[0]->get_w() * 7;
787 int white_w = white_key[0]->get_w();
788 int black_w = black_key[0]->get_w();
789 int white_w1 = white_w - black_w / 2 - 2;
790 int white_w2 = white_w / 2;
791 int white_w3 = white_w * 2 / 3;
792 int x = 0, y = 0, ys5 = yS(5);
793 y1 = y + white_key[0]->get_h() + ys5;
794 y2 = y1 + get_text_height(MEDIUMFONT) + ys5;
795 y3 = y2 + get_text_height(MEDIUMFONT) + ys5;
796 text_black_margin = black_w / 2 - get_text_width(MEDIUMFONT, "O") / 2;
797 text_white_margin = white_w / 2 - get_text_width(MEDIUMFONT, "O") / 2;
800 //printf("SynthWindow::update_notes %d\n", __LINE__);
801 note_subwindow->clear_box(0, 0, get_w(), get_h());
803 note_subwindow->set_color(get_resources()->default_text_color);
806 // To get the stacking order:
807 // pass 0 is white keys
808 // pass 1 is black keys
809 int current_title = 0;
810 for(int pass = 0; pass < 2; pass++)
812 x = -note_scroll->get_position();
814 for(int i = 0; i < TOTALNOTES; i++)
816 int octave_note = i % 12;
823 update_whitekey(i, ¤t_title, x, y);
829 update_whitekey(i, ¤t_title, x, y);
835 update_whitekey(i, ¤t_title, x, y);
839 update_whitekey(i, ¤t_title, x, y);
845 update_whitekey(i, ¤t_title, x, y);
851 update_whitekey(i, ¤t_title, x, y);
857 update_whitekey(i, ¤t_title, x, y);
868 update_blackkey(i, ¤t_title, x + white_w2, y);
872 update_blackkey(i, ¤t_title, x + white_w3, y);
879 update_blackkey(i, ¤t_title, x + white_w2, y);
883 update_blackkey(i, ¤t_title, x + white_w1, y);
887 update_blackkey(i, ¤t_title, x + white_w3, y);
899 void SynthWindow::update_note_selection()
901 for(int i = 0; i < TOTALNOTES; i++)
904 for(int j = 0; j < MAX_FREQS; j++)
906 if(synth->freq_exists(keyboard_freqs[notes[i]->number]))
915 notes[i]->set_value(1);
918 notes[i]->set_value(0);
923 void SynthWindow::update_oscillators()
925 int i, y = -osc_scroll->get_position();
929 // Add new oscillators
931 i < synth->config.oscillator_config.total;
935 SynthOscillatorConfig *config = synth->config.oscillator_config.values[i];
937 if(oscillators.total <= i)
939 oscillators.append(gui = new SynthOscGUI(this, i));
940 gui->create_objects(y);
944 gui = oscillators.values[i];
946 gui->title->reposition_window(gui->title->get_x(), y + yS(15));
948 gui->level->reposition_window(gui->level->get_x(), y);
949 gui->level->update(config->level);
951 gui->phase->reposition_window(gui->phase->get_x(), y);
952 gui->phase->update((int64_t)(config->phase * 360));
954 gui->freq->reposition_window(gui->freq->get_x(), y);
955 gui->freq->update(config->freq_factor);
957 y += OSCILLATORHEIGHT;
960 // Delete old oscillators
962 i < oscillators.total;
964 oscillators.remove_object();
968 int SynthWindow::waveform_to_text(char *text, int waveform)
972 case DC: sprintf(text, _("DC")); break;
973 case SINE: sprintf(text, _("Sine")); break;
974 case SAWTOOTH: sprintf(text, _("Sawtooth")); break;
975 case SQUARE: sprintf(text, _("Square")); break;
976 case TRIANGLE: sprintf(text, _("Triangle")); break;
977 case PULSE: sprintf(text, _("Pulse")); break;
978 case NOISE: sprintf(text, _("Noise")); break;
984 SynthMomentary::SynthMomentary(SynthWindow *window, int x, int y, char *text)
985 : BC_CheckBox(x, y, window->synth->config.momentary_notes, text)
987 this->window = window;
990 int SynthMomentary::handle_event()
992 window->synth->config.momentary_notes = get_value();
993 window->synth->send_configure_change();
1000 SynthNote::SynthNote(SynthWindow *window, VFrame **images, int number, int x, int y)
1001 : BC_Toggle(x, y, images, window->synth->freq_exists(keyboard_freqs[number]))
1003 this->window = window;
1004 this->number = number;
1010 void SynthNote::start_note()
1012 if(window->synth->config.momentary_notes) note_on = 1;
1014 //printf("SynthNote::start_note %d %d\n", __LINE__, ctrl_down());
1015 if(window->synth->config.momentary_notes || (!ctrl_down() && !shift_down()))
1017 // Kill all frequencies
1018 window->synth->delete_freqs();
1021 window->synth->new_freq(keyboard_freqs[number]);
1022 window->base_freq->update((float)window->synth->config.base_freq[0]);
1023 //printf("SynthNote::start_note %d %f\n", __LINE__, window->synth->config.base_freq[0]);
1024 window->freqpot->update(window->synth->config.base_freq[0]);
1025 window->synth->send_configure_change();
1026 window->update_note_selection();
1029 void SynthNote::stop_note()
1032 window->synth->delete_freq(keyboard_freqs[number]);
1033 window->base_freq->update((float)window->synth->config.base_freq[0]);
1034 window->freqpot->update(window->synth->config.base_freq[0]);
1035 window->synth->send_configure_change();
1036 window->update_note_selection();
1039 int SynthNote::keypress_event()
1041 if(number >= FIRST_TITLE && number < LAST_TITLE)
1043 if(get_keypress() == keyboard_map[number - FIRST_TITLE][0])
1045 if((ctrl_down() || shift_down()) &&
1046 window->synth->freq_exists(keyboard_freqs[number]))
1056 // Key releases are repeated, so momentary notes may not work
1063 int SynthNote::keyrelease_event()
1065 if(note_on && window->synth->config.momentary_notes)
1074 int SynthNote::cursor_motion_event()
1077 if(window->current_note > -1)
1079 int cursor_x = get_relative_cursor_x();
1080 int cursor_y = get_relative_cursor_y();
1081 if(cursor_x >= 0 && cursor_x < get_w() &&
1082 cursor_y >= 0 && cursor_y < get_h())
1084 if(window->starting_notes)
1093 window->current_note = number;
1100 int SynthNote::button_press_event()
1102 if(BC_Toggle::button_press_event())
1104 // printf("SynthNote::button_press_event %d %d %d\n",
1107 // window->synth->freq_exists(keyboard_freqs[number]));
1108 window->starting_notes = 1;
1109 if((ctrl_down() || shift_down()) &&
1110 window->synth->freq_exists(keyboard_freqs[number]))
1112 //printf("SynthNote::button_press_event %d\n", __LINE__);
1114 window->starting_notes = 0;
1118 //printf("SynthNote::button_press_event %d\n", __LINE__);
1120 window->starting_notes = 1;
1122 window->current_note = number;
1128 int SynthNote::button_release_event()
1130 // Change frequency permanently
1131 if(window->current_note == number)
1133 if(window->synth->config.momentary_notes)
1135 // Mute on button release
1139 window->current_note = -1;
1142 return BC_Toggle::button_release_event();
1145 int SynthNote::draw_face(int flash, int flush)
1147 BC_Toggle::draw_face(0, 0);
1148 static const char *titles[] =
1165 const char *text = titles[number % (sizeof(titles) / sizeof(char*))];
1166 char string[BCTEXTLEN];
1167 sprintf(string, "%s%d", text, number / 12);
1168 //printf("SynthNote::draw_face %d %d %d %d %s\n", __LINE__, number, get_w(), get_h(), text);
1175 draw_text(get_w() / 2 - get_text_width(MEDIUMFONT, string) / 2,
1176 get_h() - get_text_height(MEDIUMFONT, string) - window->synth->get_theme()->widget_border,
1180 if(flash) this->flash(0);
1181 if(flush) this->flush();
1191 SynthOscGUI::SynthOscGUI(SynthWindow *window, int number)
1193 this->window = window;
1194 this->number = number;
1197 SynthOscGUI::~SynthOscGUI()
1205 void SynthOscGUI::create_objects(int y)
1207 char text[BCTEXTLEN];
1208 sprintf(text, "%d:", number + 1);
1209 window->osc_subwindow->add_subwindow(title = new BC_Title(xS(10), y+yS(15), text));
1211 window->osc_subwindow->add_subwindow(level = new SynthOscGUILevel(window->synth, this, y));
1212 window->osc_subwindow->add_subwindow(phase = new SynthOscGUIPhase(window->synth, this, y));
1213 window->osc_subwindow->add_subwindow(freq = new SynthOscGUIFreq(window->synth, this, y));
1219 SynthOscGUILevel::SynthOscGUILevel(Synth *synth, SynthOscGUI *gui, int y)
1220 : BC_FPot(xS(50), y,
1221 synth->config.oscillator_config.values[gui->number]->level,
1224 this->synth = synth;
1228 SynthOscGUILevel::~SynthOscGUILevel()
1232 int SynthOscGUILevel::handle_event()
1234 SynthOscillatorConfig *config = synth->config.oscillator_config.values[gui->number];
1235 config->level = get_value();
1236 gui->window->canvas->update();
1237 synth->send_configure_change();
1243 SynthOscGUIPhase::SynthOscGUIPhase(Synth *synth, SynthOscGUI *gui, int y)
1244 : BC_IPot(xS(125), y,
1245 (int64_t)(synth->config.oscillator_config.values[gui->number]->phase * 360),
1248 this->synth = synth;
1252 SynthOscGUIPhase::~SynthOscGUIPhase()
1256 int SynthOscGUIPhase::handle_event()
1258 SynthOscillatorConfig *config = synth->config.oscillator_config.values[gui->number];
1259 config->phase = (float)get_value() / 360;
1260 gui->window->canvas->update();
1261 synth->send_configure_change();
1267 SynthOscGUIFreq::SynthOscGUIFreq(Synth *synth, SynthOscGUI *gui, int y)
1268 : BC_FPot(xS(200), y,
1269 (int64_t)(synth->config.oscillator_config.values[gui->number]->freq_factor),
1272 this->synth = synth;
1276 SynthOscGUIFreq::~SynthOscGUIFreq()
1280 int SynthOscGUIFreq::handle_event()
1282 SynthOscillatorConfig *config = synth->config.oscillator_config.values[gui->number];
1283 config->freq_factor = get_value();
1284 gui->window->canvas->update();
1285 synth->send_configure_change();
1290 SynthAddOsc::SynthAddOsc(Synth *synth, SynthWindow *window, int x, int y)
1291 : BC_GenericButton(x, y, _("Add"))
1293 this->synth = synth;
1294 this->window = window;
1297 SynthAddOsc::~SynthAddOsc()
1301 int SynthAddOsc::handle_event()
1303 synth->add_oscillator();
1304 synth->send_configure_change();
1305 window->update_gui();
1310 SynthDelOsc::SynthDelOsc(Synth *synth, SynthWindow *window, int x, int y)
1311 : BC_GenericButton(x, y, _("Delete"))
1313 this->synth = synth;
1314 this->window = window;
1317 SynthDelOsc::~SynthDelOsc()
1321 int SynthDelOsc::handle_event()
1323 synth->delete_oscillator();
1324 synth->send_configure_change();
1325 window->update_gui();
1330 OscScroll::OscScroll(Synth *synth, SynthWindow *window,
1331 int x, int y, int h)
1332 : BC_ScrollBar(x, y, SCROLL_VERT, h,
1333 synth->config.oscillator_config.total * OSCILLATORHEIGHT,
1334 0, window->osc_subwindow->get_h())
1336 this->synth = synth;
1337 this->window = window;
1340 OscScroll::~OscScroll()
1344 int OscScroll::handle_event()
1346 window->update_oscillators();
1352 NoteScroll::NoteScroll(Synth *synth, SynthWindow *window,
1353 int x, int y, int w)
1354 : BC_ScrollBar(x, y, SCROLL_HORIZ, w,
1355 window->white_key[0]->get_w() * TOTALNOTES * 7 / 12 + window->white_key[0]->get_w(),
1356 0, window->note_subwindow->get_w())
1358 this->synth = synth;
1359 this->window = window;
1362 NoteScroll::~NoteScroll()
1366 int NoteScroll::handle_event()
1368 window->update_notes();
1373 SynthClear::SynthClear(Synth *synth, int x, int y)
1374 : BC_GenericButton(x, y, _("Clear"))
1376 this->synth = synth;
1378 SynthClear::~SynthClear()
1381 int SynthClear::handle_event()
1383 synth->config.reset();
1384 synth->send_configure_change();
1385 synth->update_gui();
1394 SynthWaveForm::SynthWaveForm(Synth *synth, int x, int y, char *text)
1395 : BC_PopupMenu(x, y, xS(120), text)
1397 this->synth = synth;
1400 SynthWaveForm::~SynthWaveForm()
1404 void SynthWaveForm::create_objects()
1406 // add_item(new SynthWaveFormItem(synth, _("DC"), DC));
1407 add_item(new SynthWaveFormItem(synth, _("Sine"), SINE));
1408 add_item(new SynthWaveFormItem(synth, _("Sawtooth"), SAWTOOTH));
1409 add_item(new SynthWaveFormItem(synth, _("Square"), SQUARE));
1410 add_item(new SynthWaveFormItem(synth, _("Triangle"), TRIANGLE));
1411 add_item(new SynthWaveFormItem(synth, _("Pulse"), PULSE));
1412 add_item(new SynthWaveFormItem(synth, _("Noise"), NOISE));
1415 SynthWaveFormItem::SynthWaveFormItem(Synth *synth, char *text, int value)
1418 this->synth = synth;
1419 this->value = value;
1422 SynthWaveFormItem::~SynthWaveFormItem()
1426 int SynthWaveFormItem::handle_event()
1428 synth->config.wavefunction = value;
1429 ((SynthWindow*)synth->thread->window)->canvas->update();
1430 get_popup_menu()->set_text(get_text());
1431 synth->send_configure_change();
1436 SynthWetness::SynthWetness(Synth *synth, int x, int y)
1437 : BC_FPot(x, y, synth->config.wetness, INFINITYGAIN, 0)
1439 this->synth = synth;
1442 int SynthWetness::handle_event()
1444 synth->config.wetness = get_value();
1445 synth->send_configure_change();
1451 SynthFreqPot::SynthFreqPot(Synth *synth, SynthWindow *window, int x, int y)
1452 : BC_QPot(x, y, synth->config.base_freq[0])
1454 this->synth = synth;
1455 this->window = window;
1457 SynthFreqPot::~SynthFreqPot()
1460 int SynthFreqPot::handle_event()
1462 if(get_value() > 0 && get_value() < 30000)
1464 synth->config.base_freq[0] = get_value();
1465 freq_text->update(get_value());
1466 synth->send_configure_change();
1467 window->update_note_selection();
1474 SynthBaseFreq::SynthBaseFreq(Synth *synth, SynthWindow *window, int x, int y)
1475 : BC_TextBox(x, y, xS(100), 1, (float)0)
1477 this->synth = synth;
1478 this->window = window;
1481 SynthBaseFreq::~SynthBaseFreq()
1484 int SynthBaseFreq::handle_event()
1486 double new_value = atof(get_text());
1488 if(new_value < 30000)
1490 synth->config.base_freq[0] = new_value;
1491 freq_pot->update(synth->config.base_freq[0]);
1492 synth->send_configure_change();
1493 window->update_note_selection();
1502 SynthCanvas::SynthCanvas(Synth *synth, SynthWindow *window,
1503 int x, int y, int w, int h)
1504 : BC_SubWindow(x, y, w, h, BLACK)
1506 this->synth = synth;
1507 this->window = window;
1510 SynthCanvas::~SynthCanvas()
1514 int SynthCanvas::update()
1518 clear_box(0, 0, get_w(), get_h());
1521 draw_line(0, get_h() / 2 + y, get_w(), get_h() / 2 + y);
1525 double normalize_constant = (double)1 / synth->get_total_power();
1526 y1 = (int)(synth->get_point((float)0, normalize_constant) * get_h() / 2);
1528 for(int i = 1; i < get_w(); i++)
1530 y2 = (int)(synth->get_point((float)i / get_w(), normalize_constant) * get_h() / 2);
1531 draw_line(i - 1, get_h() / 2 - y1, i, get_h() / 2 - y2);
1539 // ======================= level calculations
1540 SynthLevelZero::SynthLevelZero(Synth *synth)
1541 : BC_MenuItem(_("Zero"))
1543 this->synth = synth;
1546 SynthLevelZero::~SynthLevelZero()
1550 int SynthLevelZero::handle_event()
1552 for(int i = 0; i < synth->config.oscillator_config.total; i++)
1554 synth->config.oscillator_config.values[i]->level = INFINITYGAIN;
1557 ((SynthWindow*)synth->thread->window)->update_gui();
1558 synth->send_configure_change();
1562 SynthLevelMax::SynthLevelMax(Synth *synth)
1563 : BC_MenuItem(_("Maximum"))
1565 this->synth = synth;
1568 SynthLevelMax::~SynthLevelMax()
1572 int SynthLevelMax::handle_event()
1574 for(int i = 0; i < synth->config.oscillator_config.total; i++)
1576 synth->config.oscillator_config.values[i]->level = 0;
1578 ((SynthWindow*)synth->thread->window)->update_gui();
1579 synth->send_configure_change();
1583 SynthLevelNormalize::SynthLevelNormalize(Synth *synth)
1584 : BC_MenuItem(_("Normalize"))
1586 this->synth = synth;
1589 SynthLevelNormalize::~SynthLevelNormalize()
1593 int SynthLevelNormalize::handle_event()
1598 for(int i = 0; i < synth->config.oscillator_config.total; i++)
1600 total += synth->db.fromdb(synth->config.oscillator_config.values[i]->level);
1603 float scale = 1 / total;
1606 for(int i = 0; i < synth->config.oscillator_config.total; i++)
1608 new_value = synth->db.fromdb(synth->config.oscillator_config.values[i]->level);
1610 new_value = synth->db.todb(new_value);
1612 synth->config.oscillator_config.values[i]->level = new_value;
1615 ((SynthWindow*)synth->thread->window)->update_gui();
1616 synth->send_configure_change();
1620 SynthLevelSlope::SynthLevelSlope(Synth *synth)
1621 : BC_MenuItem(_("Slope"))
1623 this->synth = synth;
1626 SynthLevelSlope::~SynthLevelSlope()
1630 int SynthLevelSlope::handle_event()
1632 float slope = (float)INFINITYGAIN / synth->config.oscillator_config.total;
1634 for(int i = 0; i < synth->config.oscillator_config.total; i++)
1636 synth->config.oscillator_config.values[i]->level = i * slope;
1639 ((SynthWindow*)synth->thread->window)->update_gui();
1640 synth->send_configure_change();
1644 SynthLevelRandom::SynthLevelRandom(Synth *synth)
1645 : BC_MenuItem(_("Random"))
1647 this->synth = synth;
1649 SynthLevelRandom::~SynthLevelRandom()
1653 int SynthLevelRandom::handle_event()
1656 for(int i = 0; i < synth->config.oscillator_config.total; i++)
1658 synth->config.oscillator_config.values[i]->level = -(rand() % -INFINITYGAIN);
1661 ((SynthWindow*)synth->thread->window)->update_gui();
1662 synth->send_configure_change();
1666 SynthLevelInvert::SynthLevelInvert(Synth *synth)
1667 : BC_MenuItem(_("Invert"))
1669 this->synth = synth;
1671 SynthLevelInvert::~SynthLevelInvert()
1675 int SynthLevelInvert::handle_event()
1677 for(int i = 0; i < synth->config.oscillator_config.total; i++)
1679 synth->config.oscillator_config.values[i]->level =
1680 INFINITYGAIN - synth->config.oscillator_config.values[i]->level;
1683 ((SynthWindow*)synth->thread->window)->update_gui();
1684 synth->send_configure_change();
1688 SynthLevelSine::SynthLevelSine(Synth *synth)
1689 : BC_MenuItem(_("Sine"))
1691 this->synth = synth;
1693 SynthLevelSine::~SynthLevelSine()
1697 int SynthLevelSine::handle_event()
1701 for(int i = 0; i < synth->config.oscillator_config.total; i++)
1703 new_value = (float)i / synth->config.oscillator_config.total * 2 * M_PI;
1704 new_value = sin(new_value) * INFINITYGAIN / 2 + INFINITYGAIN / 2;
1705 synth->config.oscillator_config.values[i]->level = new_value;
1708 ((SynthWindow*)synth->thread->window)->update_gui();
1709 synth->send_configure_change();
1713 // ============================ phase calculations
1715 SynthPhaseInvert::SynthPhaseInvert(Synth *synth)
1716 : BC_MenuItem(_("Invert"))
1718 this->synth = synth;
1720 SynthPhaseInvert::~SynthPhaseInvert()
1724 int SynthPhaseInvert::handle_event()
1726 for(int i = 0; i < synth->config.oscillator_config.total; i++)
1728 synth->config.oscillator_config.values[i]->phase =
1729 1 - synth->config.oscillator_config.values[i]->phase;
1732 ((SynthWindow*)synth->thread->window)->update_gui();
1733 synth->send_configure_change();
1737 SynthPhaseZero::SynthPhaseZero(Synth *synth)
1738 : BC_MenuItem(_("Zero"))
1740 this->synth = synth;
1742 SynthPhaseZero::~SynthPhaseZero()
1746 int SynthPhaseZero::handle_event()
1748 for(int i = 0; i < synth->config.oscillator_config.total; i++)
1750 synth->config.oscillator_config.values[i]->phase = 0;
1753 ((SynthWindow*)synth->thread->window)->update_gui();
1754 synth->send_configure_change();
1758 SynthPhaseSine::SynthPhaseSine(Synth *synth)
1759 : BC_MenuItem(_("Sine"))
1761 this->synth = synth;
1763 SynthPhaseSine::~SynthPhaseSine()
1767 int SynthPhaseSine::handle_event()
1770 for(int i = 0; i < synth->config.oscillator_config.total; i++)
1772 new_value = (float)i / synth->config.oscillator_config.total * 2 * M_PI;
1773 new_value = sin(new_value) / 2 + .5;
1774 synth->config.oscillator_config.values[i]->phase = new_value;
1777 ((SynthWindow*)synth->thread->window)->update_gui();
1778 synth->send_configure_change();
1782 SynthPhaseRandom::SynthPhaseRandom(Synth *synth)
1783 : BC_MenuItem(_("Random"))
1785 this->synth = synth;
1787 SynthPhaseRandom::~SynthPhaseRandom()
1791 int SynthPhaseRandom::handle_event()
1794 for(int i = 0; i < synth->config.oscillator_config.total; i++)
1796 synth->config.oscillator_config.values[i]->phase =
1797 (float)(rand() % 360) / 360;
1800 ((SynthWindow*)synth->thread->window)->update_gui();
1801 synth->send_configure_change();
1806 // ============================ freq calculations
1808 SynthFreqRandom::SynthFreqRandom(Synth *synth)
1809 : BC_MenuItem(_("Random"))
1811 this->synth = synth;
1813 SynthFreqRandom::~SynthFreqRandom()
1817 int SynthFreqRandom::handle_event()
1820 for(int i = 0; i < synth->config.oscillator_config.total; i++)
1822 synth->config.oscillator_config.values[i]->freq_factor = rand() % 100;
1825 ((SynthWindow*)synth->thread->window)->update_gui();
1826 synth->send_configure_change();
1830 SynthFreqPow1::SynthFreqPow1(Synth *synth)
1831 : BC_MenuItem(_("Powers of 1.4"))
1833 this->synth = synth;
1835 SynthFreqPow1::~SynthFreqPow1()
1839 int SynthFreqPow1::handle_event()
1841 for(int i = 0; i < synth->config.oscillator_config.total; i++)
1843 synth->config.oscillator_config.values[i]->freq_factor = pow(sqrt(2), i);
1846 ((SynthWindow*)synth->thread->window)->update_gui();
1847 synth->send_configure_change();
1852 SynthFreqPow2::SynthFreqPow2(Synth *synth)
1853 : BC_MenuItem(_("Powers of 2"))
1855 this->synth = synth;
1857 SynthFreqPow2::~SynthFreqPow2()
1861 int SynthFreqPow2::handle_event()
1863 for(int i = 0; i < synth->config.oscillator_config.total; i++)
1865 synth->config.oscillator_config.values[i]->freq_factor = pow(2, i);
1868 ((SynthWindow*)synth->thread->window)->update_gui();
1869 synth->send_configure_change();
1876 SynthFreqMin::SynthFreqMin(Synth *synth)
1877 : BC_MenuItem(_("Minimum"))
1879 this->synth = synth;
1881 SynthFreqMin::~SynthFreqMin()
1885 int SynthFreqMin::handle_event()
1887 for(int i = 0; i < synth->config.oscillator_config.total; i++)
1889 synth->config.oscillator_config.values[i]->freq_factor = 1;
1892 ((SynthWindow*)synth->thread->window)->update_gui();
1893 synth->send_configure_change();
1898 SynthFreqEnum::SynthFreqEnum(Synth *synth)
1899 : BC_MenuItem(_("Enumerate"))
1901 this->synth = synth;
1903 SynthFreqEnum::~SynthFreqEnum()
1907 int SynthFreqEnum::handle_event()
1909 for(int i = 0; i < synth->config.oscillator_config.total; i++)
1911 synth->config.oscillator_config.values[i]->freq_factor = (float)i + 1;
1914 ((SynthWindow*)synth->thread->window)->update_gui();
1915 synth->send_configure_change();
1919 SynthFreqEven::SynthFreqEven(Synth *synth)
1920 : BC_MenuItem(_("Even"))
1922 this->synth = synth;
1924 SynthFreqEven::~SynthFreqEven()
1928 int SynthFreqEven::handle_event()
1930 if(synth->config.oscillator_config.total)
1931 synth->config.oscillator_config.values[0]->freq_factor = (float)1;
1933 for(int i = 1; i < synth->config.oscillator_config.total; i++)
1935 synth->config.oscillator_config.values[i]->freq_factor = (float)i * 2;
1938 ((SynthWindow*)synth->thread->window)->update_gui();
1939 synth->send_configure_change();
1943 SynthFreqOdd::SynthFreqOdd(Synth *synth)
1944 : BC_MenuItem(_("Odd"))
1945 { this->synth = synth; }
1946 SynthFreqOdd::~SynthFreqOdd()
1950 int SynthFreqOdd::handle_event()
1952 for(int i = 0; i < synth->config.oscillator_config.total; i++)
1954 synth->config.oscillator_config.values[i]->freq_factor = (float)1 + i * 2;
1957 ((SynthWindow*)synth->thread->window)->update_gui();
1958 synth->send_configure_change();
1962 SynthFreqFibonacci::SynthFreqFibonacci(Synth *synth)
1963 : BC_MenuItem(_("Fibonnacci"))
1965 this->synth = synth;
1967 SynthFreqFibonacci::~SynthFreqFibonacci()
1971 int SynthFreqFibonacci::handle_event()
1973 float last_value1 = 0, last_value2 = 1;
1974 for(int i = 0; i < synth->config.oscillator_config.total; i++)
1976 synth->config.oscillator_config.values[i]->freq_factor = last_value1 + last_value2;
1977 if(synth->config.oscillator_config.values[i]->freq_factor > 100)
1978 synth->config.oscillator_config.values[i]->freq_factor = 100;
1979 last_value1 = last_value2;
1980 last_value2 = synth->config.oscillator_config.values[i]->freq_factor;
1983 ((SynthWindow*)synth->thread->window)->update_gui();
1984 synth->send_configure_change();
1988 SynthFreqPrime::SynthFreqPrime(Synth *synth)
1989 : BC_MenuItem(_("Prime"))
1991 this->synth = synth;
1993 SynthFreqPrime::~SynthFreqPrime()
1997 int SynthFreqPrime::handle_event()
2000 for(int i = 0; i < synth->config.oscillator_config.total; i++)
2002 synth->config.oscillator_config.values[i]->freq_factor = number;
2003 number = get_next_prime(number);
2006 ((SynthWindow*)synth->thread->window)->update_gui();
2007 synth->send_configure_change();
2011 float SynthFreqPrime::get_next_prime(float number)
2020 for(float i = number - 1; i > 1 && !result; i--)
2022 if((number / i) - (int)(number / i) == 0) result = 1;
2036 SynthOscillatorConfig::SynthOscillatorConfig(int number)
2039 this->number = number;
2042 SynthOscillatorConfig::~SynthOscillatorConfig()
2046 void SynthOscillatorConfig::reset()
2054 void SynthOscillatorConfig::read_data(FileXML *file)
2056 level = file->tag.get_property("LEVEL", (float)level);
2057 phase = file->tag.get_property("PHASE", (float)phase);
2058 freq_factor = file->tag.get_property("FREQFACTOR", (float)freq_factor);
2061 void SynthOscillatorConfig::save_data(FileXML *file)
2063 file->tag.set_title("OSCILLATOR");
2064 file->tag.set_property("LEVEL", (float)level);
2065 file->tag.set_property("PHASE", (float)phase);
2066 file->tag.set_property("FREQFACTOR", (float)freq_factor);
2068 file->tag.set_title("/OSCILLATOR");
2070 file->append_newline();
2073 int SynthOscillatorConfig::equivalent(SynthOscillatorConfig &that)
2075 if(EQUIV(level, that.level) &&
2076 EQUIV(phase, that.phase) &&
2077 EQUIV(freq_factor, that.freq_factor))
2083 void SynthOscillatorConfig::copy_from(SynthOscillatorConfig& that)
2087 freq_factor = that.freq_factor;
2091 SynthConfig::SynthConfig()
2096 SynthConfig::~SynthConfig()
2098 oscillator_config.remove_all_objects();
2101 void SynthConfig::reset()
2105 for(int i = 1; i < MAX_FREQS; i++)
2107 wavefunction = SINE;
2108 for(int i = 0; i < oscillator_config.total; i++)
2110 oscillator_config.values[i]->reset();
2113 momentary_notes = 0;
2116 int SynthConfig::equivalent(SynthConfig &that)
2118 //printf("SynthConfig::equivalent %d %d\n", base_freq, that.base_freq);
2119 for(int i = 0; i < MAX_FREQS; i++)
2120 if(base_freq[i] != that.base_freq[i]) return 0;
2122 if(wavefunction != that.wavefunction ||
2123 oscillator_config.total != that.oscillator_config.total ||
2124 momentary_notes != that.momentary_notes) return 0;
2126 for(int i = 0; i < oscillator_config.total; i++)
2128 if(!oscillator_config.values[i]->equivalent(*that.oscillator_config.values[i]))
2135 void SynthConfig::copy_from(SynthConfig& that)
2137 wetness = that.wetness;
2138 for(int i = 0; i < MAX_FREQS; i++)
2139 base_freq[i] = that.base_freq[i];
2140 wavefunction = that.wavefunction;
2141 momentary_notes = that.momentary_notes;
2145 i < oscillator_config.total && i < that.oscillator_config.total;
2148 oscillator_config.values[i]->copy_from(*that.oscillator_config.values[i]);
2152 i < that.oscillator_config.total;
2155 oscillator_config.append(new SynthOscillatorConfig(i));
2156 oscillator_config.values[i]->copy_from(*that.oscillator_config.values[i]);
2160 i < oscillator_config.total;
2163 oscillator_config.remove_object();
2168 void SynthConfig::interpolate(SynthConfig &prev,
2172 int64_t current_frame)
2174 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
2175 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
2178 wetness = (int)(prev.wetness * prev_scale + next.wetness * next_scale);
2179 // base_freq = (int)(prev.base_freq * prev_scale + next.base_freq * next_scale);
2181 momentary_notes = prev.momentary_notes;