/*
* CINELERRA
- * Copyright (C) 1997-2011 Adam Williams <broadcast at earthling dot net>
+ * Copyright (C) 1997-2017 Adam Williams <broadcast at earthling dot net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
//printf("Synth::read_data %s\n", keyframe->get_data());
int result = 0, current_osc = 0;
- //int total_oscillators = 0;
while(!result)
{
result = input.read_tag();
}
config.wavefunction = input.tag.get_property("WAVEFUNCTION", config.wavefunction);
- //total_oscillators = input.tag.get_property("OSCILLATORS", 0);
+ // int total_oscillators = input.tag.get_property("OSCILLATORS", 0);
}
else
if(input.tag.title_is("OSCILLATOR"))
config.oscillator_config.values[i]->save_data(&output);
}
- output.tag.set_title("/SYNTH");
- output.append_tag();
- output.append_newline();
output.terminate_string();
//printf("Synth::save_data %d %s\n", __LINE__, output.string);
// data is now in *text
void Synth::update_gui()
{
- if( !thread ) return;
- SynthWindow *window = (SynthWindow*)thread->window;
-// load_configuration,read_data deletes oscillator_config
- window->lock_window("Synth::update_gui");
- if( load_configuration() )
- window->update_gui();
- window->unlock_window();
+ if(thread)
+ {
+ if(load_configuration())
+ {
+ thread->window->lock_window();
+ ((SynthWindow*)thread->window)->update_gui();
+ thread->window->unlock_window();
+ }
+ }
}
void Synth::add_oscillator()
{
- if(config.oscillator_config.total > 20) return;
+ if(config.oscillator_config.total > MAX_OSCILLATORS) return;
config.oscillator_config.append(new SynthOscillatorConfig(config.oscillator_config.total - 1));
}
freq;
// Starting sample in waveform
double x = waveform_sample;
- double phase_offset = config->phase * orig_period;
//printf("Synth::solve_eqn %d %f\n", __LINE__, config->phase);
+ double phase_offset = config->phase * orig_period;
// Period of current oscillator
double period = orig_period / config->freq_factor;
int sample;
for(sample = 0; sample < length; sample++)
{
output[sample] += sin((x + phase_offset) /
- period *
- 2 *
- M_PI) * power;
+ period * 2 * M_PI) * power;
x += step;
}
break;
{
double normalize_constant = 1.0 / get_total_power();
for(int i = 0; i < config.oscillator_config.total; i++)
- solve_eqn(output,
- length,
- freq,
- normalize_constant,
- i);
+ solve_eqn(output, length, freq, normalize_constant, i);
return length;
}
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
SynthWindow::SynthWindow(Synth *synth)
- : PluginClientWindow(synth,
- synth->window_w,
- synth->window_h,
- xS(400),
- yS(350),
- 1)
+ : PluginClientWindow(synth, synth->window_w, synth->window_h,
+ xS(400), yS(350), 1)
{
this->synth = synth;
white_key[0] = 0;
void SynthWindow::create_objects()
{
+ int margin = client->get_theme()->widget_border;
+
BC_MenuBar *menu;
add_subwindow(menu = new BC_MenuBar(0, 0, get_w()));
phasemenu->add_item(new SynthPhaseSine(synth));
phasemenu->add_item(new SynthPhaseZero(synth));
+ harmonicmenu->add_item(new SynthFreqMin(synth));
harmonicmenu->add_item(new SynthFreqEnum(synth));
harmonicmenu->add_item(new SynthFreqEven(synth));
harmonicmenu->add_item(new SynthFreqFibonacci(synth));
add_subwindow(waveform = new SynthWaveForm(synth, x, y, string));
waveform->create_objects();
y += ys30;
- int x1 = x + waveform->get_w() + xs10;
+ int x1 = x + waveform->get_w() + xs50;
add_subwindow(new BC_Title(x, y, _("Base Frequency:")));
black_key[4] = new VFramePng(black_checkedhi_png);
- add_subwindow(note_subwindow = new BC_SubWindow(x1,
- y,
- get_w() - x1,
- white_key[0]->get_h() + MARGIN +
- get_text_height(MEDIUMFONT) + MARGIN +
- get_text_height(MEDIUMFONT) + MARGIN));
- add_subwindow(note_scroll = new NoteScroll(synth,
- this,
- x1,
+ add_subwindow(note_subwindow = new BC_SubWindow(x1+xS(20),
+ y, get_w() - (x1+xS(20)),
+ white_key[0]->get_h() + margin +
+ get_text_height(MEDIUMFONT) + margin +
+ get_text_height(MEDIUMFONT) + margin));
+ add_subwindow(note_scroll = new NoteScroll(synth, this, x1,
note_subwindow->get_y() + note_subwindow->get_h(),
note_subwindow->get_w()));
- add_subwindow(momentary = new SynthMomentary(this,
- x1,
- note_scroll->get_y() + note_scroll->get_h() + MARGIN,
+ add_subwindow(momentary = new SynthMomentary(this, x1,
+ note_scroll->get_y() + note_scroll->get_h() + margin,
_("Momentary notes")));
- add_subwindow(note_instructions = new BC_Title(
- x1,
- momentary->get_y() + momentary->get_h() + MARGIN,
+ add_subwindow(note_instructions = new BC_Title( x1,
+ momentary->get_y() + momentary->get_h() + margin,
_("Ctrl or Shift to select multiple notes.")));
update_scrollbar();
set_done(1);
return 1;
}
- return 0;
+ return context_help_check_and_show();
}
int SynthWindow::resize_event(int w, int h)
if(number >= FIRST_TITLE && number < LAST_TITLE)
note_subwindow->add_subwindow(
note_titles[(*current_title)++] = new BC_Title(
- x + text_white_margin,
- y2,
+ x + text_white_margin, y2,
keyboard_map[number - FIRST_TITLE]));
//printf("SynthWindow::update_whitekey %d\n", __LINE__);
}
if(number >= FIRST_TITLE && number < LAST_TITLE)
note_subwindow->add_subwindow(
note_titles[(*current_title)++] = new BC_Title(x + text_black_margin,
- y1,
- keyboard_map[number - FIRST_TITLE]));
+ y1, keyboard_map[number - FIRST_TITLE]));
}
else
{
notes[number]->reposition_window(x, y);
if(number >= FIRST_TITLE && number < LAST_TITLE)
- note_titles[(*current_title)++]->reposition_window(x + text_black_margin,
- y1);
+ note_titles[(*current_title)++]->reposition_window(x + text_black_margin, y1);
}
}
int white_w1 = white_w - black_w / 2 - 2;
int white_w2 = white_w / 2;
int white_w3 = white_w * 2 / 3;
- int y = 0;
- int x = 0;
- y1 = y + white_key[0]->get_h() + 10;
- y2 = y1 + get_text_height(MEDIUMFONT) + 10;
- y3 = y2 + get_text_height(MEDIUMFONT) + 10;
+ int x = 0, y = 0, ys5 = yS(5);
+ y1 = y + white_key[0]->get_h() + ys5;
+ y2 = y1 + get_text_height(MEDIUMFONT) + ys5;
+ y3 = y2 + get_text_height(MEDIUMFONT) + ys5;
text_black_margin = black_w / 2 - get_text_width(MEDIUMFONT, "O") / 2;
text_white_margin = white_w / 2 - get_text_width(MEDIUMFONT, "O") / 2;
{
gui = oscillators.values[i];
- gui->title->reposition_window(gui->title->get_x(), y + 15);
+ gui->title->reposition_window(gui->title->get_x(), y + yS(15));
gui->level->reposition_window(gui->level->get_x(), y);
gui->level->update(config->level);
gui->phase->update((int64_t)(config->phase * 360));
gui->freq->reposition_window(gui->freq->get_x(), y);
- gui->freq->update((int64_t)(config->freq_factor));
+ gui->freq->update(config->freq_factor);
}
y += OSCILLATORHEIGHT;
}
SynthMomentary::SynthMomentary(SynthWindow *window, int x, int y, char *text)
- : BC_CheckBox(x,
- y,
- window->synth->config.momentary_notes,
- text)
+ : BC_CheckBox(x, y, window->synth->config.momentary_notes, text)
{
this->window = window;
}
-SynthNote::SynthNote(SynthWindow *window,
- VFrame **images,
- int number,
- int x,
- int y)
- : BC_Toggle(x,
- y,
- images,
- window->synth->freq_exists(keyboard_freqs[number]))
+SynthNote::SynthNote(SynthWindow *window, VFrame **images, int number, int x, int y)
+ : BC_Toggle(x, y, images, window->synth->freq_exists(keyboard_freqs[number]))
{
this->window = window;
this->number = number;
int SynthNote::keypress_event()
{
+// Evtl catch Alt/H
+ if (get_keypress() == 'h' && alt_down())
+ {
+ context_help_show();
+ return 1;
+ }
+
if(number >= FIRST_TITLE && number < LAST_TITLE)
{
if(get_keypress() == keyboard_map[number - FIRST_TITLE][0])
{
char text[BCTEXTLEN];
sprintf(text, "%d:", number + 1);
- window->osc_subwindow->add_subwindow(title = new BC_Title(10, y + 15, text));
+ window->osc_subwindow->add_subwindow(title = new BC_Title(xS(10), y+yS(15), text));
window->osc_subwindow->add_subwindow(level = new SynthOscGUILevel(window->synth, this, y));
window->osc_subwindow->add_subwindow(phase = new SynthOscGUIPhase(window->synth, this, y));
SynthOscGUILevel::SynthOscGUILevel(Synth *synth, SynthOscGUI *gui, int y)
- : BC_FPot(50,
- y,
+ : BC_FPot(xS(50), y,
synth->config.oscillator_config.values[gui->number]->level,
- INFINITYGAIN,
- 0)
+ INFINITYGAIN, 0)
{
this->synth = synth;
this->gui = gui;
SynthOscGUIPhase::SynthOscGUIPhase(Synth *synth, SynthOscGUI *gui, int y)
- : BC_IPot(125,
- y,
+ : BC_IPot(xS(125), y,
(int64_t)(synth->config.oscillator_config.values[gui->number]->phase * 360),
- 0,
- 360)
+ 0, 360)
{
this->synth = synth;
this->gui = gui;
SynthOscGUIFreq::SynthOscGUIFreq(Synth *synth, SynthOscGUI *gui, int y)
- : BC_IPot(200,
- y,
+ : BC_FPot(xS(200), y,
(int64_t)(synth->config.oscillator_config.values[gui->number]->freq_factor),
- 1,
- 100)
+ 1, 100)
{
this->synth = synth;
this->gui = gui;
}
-
-
-
-
-
SynthAddOsc::SynthAddOsc(Synth *synth, SynthWindow *window, int x, int y)
: BC_GenericButton(x, y, _("Add"))
{
}
-
SynthDelOsc::SynthDelOsc(Synth *synth, SynthWindow *window, int x, int y)
: BC_GenericButton(x, y, _("Delete"))
{
}
-OscScroll::OscScroll(Synth *synth,
- SynthWindow *window,
- int x,
- int y,
- int h)
- : BC_ScrollBar(x,
- y,
- SCROLL_VERT,
- h,
+OscScroll::OscScroll(Synth *synth, SynthWindow *window,
+ int x, int y, int h)
+ : BC_ScrollBar(x, y, SCROLL_VERT, h,
synth->config.oscillator_config.total * OSCILLATORHEIGHT,
- 0,
- window->osc_subwindow->get_h())
+ 0, window->osc_subwindow->get_h())
{
this->synth = synth;
this->window = window;
-NoteScroll::NoteScroll(Synth *synth,
- SynthWindow *window,
- int x,
- int y,
- int w)
- : BC_ScrollBar(x,
- y,
- SCROLL_HORIZ,
- w,
+NoteScroll::NoteScroll(Synth *synth, SynthWindow *window,
+ int x, int y, int w)
+ : BC_ScrollBar(x, y, SCROLL_HORIZ, w,
window->white_key[0]->get_w() * TOTALNOTES * 7 / 12 + window->white_key[0]->get_w(),
- 0,
- window->note_subwindow->get_w())
+ 0, window->note_subwindow->get_w())
{
this->synth = synth;
this->window = window;
}
-
-
-
-
-
-
-
-
-
-
-
-
SynthClear::SynthClear(Synth *synth, int x, int y)
: BC_GenericButton(x, y, _("Clear"))
{
SynthWetness::SynthWetness(Synth *synth, int x, int y)
- : BC_FPot(x,
- y,
- synth->config.wetness,
- INFINITYGAIN,
- 0)
+ : BC_FPot(x, y, synth->config.wetness, INFINITYGAIN, 0)
{
this->synth = synth;
}
-SynthCanvas::SynthCanvas(Synth *synth,
- SynthWindow *window,
- int x,
- int y,
- int w,
- int h)
- : BC_SubWindow(x,
- y,
- w,
- h,
- BLACK)
+SynthCanvas::SynthCanvas(Synth *synth, SynthWindow *window,
+ int x, int y, int w, int h)
+ : BC_SubWindow(x, y, w, h, BLACK)
{
this->synth = synth;
this->window = window;
}
-
-
-
-
-
-
// ======================= level calculations
SynthLevelZero::SynthLevelZero(Synth *synth)
: BC_MenuItem(_("Zero"))
return 1;
}
+SynthFreqPow1::SynthFreqPow1(Synth *synth)
+ : BC_MenuItem(_("Powers of 1.4"))
+{
+ this->synth = synth;
+}
+SynthFreqPow1::~SynthFreqPow1()
+{
+}
+
+int SynthFreqPow1::handle_event()
+{
+ for(int i = 0; i < synth->config.oscillator_config.total; i++)
+ {
+ synth->config.oscillator_config.values[i]->freq_factor = pow(sqrt(2), i);
+ }
+
+ ((SynthWindow*)synth->thread->window)->update_gui();
+ synth->send_configure_change();
+ return 1;
+}
+
+
+SynthFreqPow2::SynthFreqPow2(Synth *synth)
+ : BC_MenuItem(_("Powers of 2"))
+{
+ this->synth = synth;
+}
+SynthFreqPow2::~SynthFreqPow2()
+{
+}
+
+int SynthFreqPow2::handle_event()
+{
+ for(int i = 0; i < synth->config.oscillator_config.total; i++)
+ {
+ synth->config.oscillator_config.values[i]->freq_factor = pow(2, i);
+ }
+
+ ((SynthWindow*)synth->thread->window)->update_gui();
+ synth->send_configure_change();
+ return 1;
+}
+
+
+
+
+SynthFreqMin::SynthFreqMin(Synth *synth)
+ : BC_MenuItem(_("Minimum"))
+{
+ this->synth = synth;
+}
+SynthFreqMin::~SynthFreqMin()
+{
+}
+
+int SynthFreqMin::handle_event()
+{
+ for(int i = 0; i < synth->config.oscillator_config.total; i++)
+ {
+ synth->config.oscillator_config.values[i]->freq_factor = 1;
+ }
+
+ ((SynthWindow*)synth->thread->window)->update_gui();
+ synth->send_configure_change();
+ return 1;
+}
+
+
SynthFreqEnum::SynthFreqEnum(Synth *synth)
: BC_MenuItem(_("Enumerate"))
{
for(int i = 0; i < synth->config.oscillator_config.total; i++)
{
synth->config.oscillator_config.values[i]->freq_factor = last_value1 + last_value2;
- if(synth->config.oscillator_config.values[i]->freq_factor > 100) synth->config.oscillator_config.values[i]->freq_factor = 100;
+ if(synth->config.oscillator_config.values[i]->freq_factor > 100)
+ synth->config.oscillator_config.values[i]->freq_factor = 100;
last_value1 = last_value2;
last_value2 = synth->config.oscillator_config.values[i]->freq_factor;
}