/*
* CINELERRA
* Copyright (C) 2008 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
+ *
*/
#include "bcdisplayinfo.h"
}
-char* Piano::plugin_title() { return _("Pianoesizer"); }
+char* Piano::plugin_title() { return N_("Pianoesizer"); }
int Piano::is_realtime() { return 1; }
int Piano::is_synthesis() { return 1; }
{
FileXML input;
// cause htal file to read directly from text
- input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
+ input.set_shared_input(keyframe->xbuf);
//printf("Piano::read_data %s\n", keyframe->get_data());
int result = 0, current_osc = 0, total_oscillators = 0;
{
FileXML output;
// cause htal file to store data directly in text
- output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
+ output.set_shared_output(keyframe->xbuf);
output.tag.set_title("SYNTH");
output.tag.set_property("WETNESS", config.wetness);
int Piano::show_gui()
{
load_configuration();
-
+
thread = new PianoThread(this);
thread->start();
return 0;
void Piano::update_gui()
{
- if(thread)
- {
- load_configuration();
- thread->window->lock_window();
- thread->window->update_gui();
- thread->window->unlock_window();
- }
+ if( !thread ) return;
+ PianoWindow *window = (PianoWindow *)thread->window:
+// load_configuration,read_data deletes oscillator_config
+ window->lock_window("Piano::update_gui");
+ load_configuration();
+ window->update_gui();
+ window->unlock_window();
}
}
-double Piano::solve_eqn(double *output,
- double x1,
- double x2,
+double Piano::solve_eqn(double *output,
+ double x1,
+ double x2,
double normalize_constant,
int oscillator)
{
if(config->level <= INFINITYGAIN) return 0;
double result;
- register double x;
+ double x;
double power = this->db.fromdb(config->level) * normalize_constant;
double phase_offset = config->phase * this->period;
double x3 = x1 + phase_offset;
return result;
}
-double Piano::get_oscillator_point(float x,
- double normalize_constant,
+double Piano::get_oscillator_point(float x,
+ double normalize_constant,
int oscillator)
{
PianoOscillatorConfig *config = this->config.oscillator_config.values[oscillator];
fragment_len = overlay_synth(i, fragment_len, input_ptr, output_ptr);
//printf("Piano::process_realtime 2\n");
}
-
-
+
+
return 0;
}
int Piano::overlay_synth(int64_t start, int64_t length, double *input, double *output)
{
- if(waveform_sample + length > waveform_length)
+ if(waveform_sample + length > waveform_length)
length = waveform_length - waveform_sample;
//printf("Piano::overlay_synth 1 %d %d\n", length, waveform_length);
{
int64_t start = waveform_sample, end = waveform_sample + length;
for(int i = start; i < end; i++) dsp_buffer[i] = 0;
-
+
double normalize_constant = 1 / get_total_power();
for(int i = 0; i < config.oscillator_config.total; i++)
- solve_eqn(dsp_buffer,
- start,
- end,
+ solve_eqn(dsp_buffer,
+ start,
+ end,
normalize_constant,
i);
-
+
samples_rendered = end;
}
//printf("Piano::overlay_synth 2\n");
void PianoThread::run()
{
BC_DisplayInfo info;
- window = new PianoWindow(synth,
- info.get_abs_cursor_x() - 125,
+ window = new PianoWindow(synth,
+ info.get_abs_cursor_x() - 125,
info.get_abs_cursor_y() - 115);
window->create_objects();
int result = window->run_window();
PianoWindow::PianoWindow(Piano *synth, int x, int y)
- : BC_Window(synth->gui_string,
- x,
- y,
- 380,
- synth->h,
- 380,
- 10,
- 1,
+ : BC_Window(synth->gui_string,
+ x,
+ y,
+ 380,
+ synth->h,
+ 380,
+ 10,
+ 1,
0,
1)
{
- this->synth = synth;
+ this->synth = synth;
}
PianoWindow::~PianoWindow()
add_subwindow(new PianoClear(synth, x, y));
- x = 50;
+ x = 50;
y = 220;
- add_subwindow(new BC_Title(x, y, _("Level")));
+ add_subwindow(new BC_Title(x, y, _("Level")));
x += 75;
- add_subwindow(new BC_Title(x, y, _("Phase")));
+ add_subwindow(new BC_Title(x, y, _("Phase")));
x += 75;
add_subwindow(new BC_Title(x, y, _("Harmonic")));
int PianoWindow::resize_event(int w, int h)
{
clear_box(0, 0, w, h);
- subwindow->reposition_window(subwindow->get_x(),
- subwindow->get_y(),
- subwindow->get_w(),
+ subwindow->reposition_window(subwindow->get_x(),
+ subwindow->get_y(),
+ subwindow->get_w(),
h - subwindow->get_y());
subwindow->clear_box(0, 0, subwindow->get_w(), subwindow->get_h());
- scroll->reposition_window(scroll->get_x(),
- scroll->get_y(),
+ scroll->reposition_window(scroll->get_x(),
+ scroll->get_y(),
h - scroll->get_y());
update_scrollbar();
update_oscillators();
wetness->update(synth->config.wetness);
waveform_to_text(string, synth->config.wavefunction);
waveform->set_text(string);
-
+
update_scrollbar();
update_oscillators();
canvas->update();
void PianoWindow::update_scrollbar()
{
- scroll->update_length(synth->config.oscillator_config.total * OSCILLATORHEIGHT,
- scroll->get_position(),
+ scroll->update_length(synth->config.oscillator_config.total * OSCILLATORHEIGHT,
+ scroll->get_position(),
subwindow->get_h());
}
// Add new oscillators
- for(i = 0;
- i < synth->config.oscillator_config.total;
+ for(i = 0;
+ i < synth->config.oscillator_config.total;
i++)
{
PianoOscGUI *gui;
}
// Delete old oscillators
- for( ;
+ for( ;
i < oscillators.total;
i++)
oscillators.remove_object();
PianoOscGUILevel::PianoOscGUILevel(Piano *synth, PianoOscGUI *gui, int y)
- : BC_FPot(50,
- y,
- synth->config.oscillator_config.values[gui->number]->level,
- INFINITYGAIN,
+ : BC_FPot(50,
+ y,
+ synth->config.oscillator_config.values[gui->number]->level,
+ INFINITYGAIN,
0)
{
this->synth = synth;
PianoOscGUIPhase::PianoOscGUIPhase(Piano *synth, PianoOscGUI *gui, int y)
- : BC_IPot(125,
- y,
- (int64_t)(synth->config.oscillator_config.values[gui->number]->phase * 360),
- 0,
+ : BC_IPot(125,
+ y,
+ (int64_t)(synth->config.oscillator_config.values[gui->number]->phase * 360),
+ 0,
360)
{
this->synth = synth;
PianoOscGUIFreq::PianoOscGUIFreq(Piano *synth, PianoOscGUI *gui, int y)
- : BC_IPot(200,
- y,
- (int64_t)(synth->config.oscillator_config.values[gui->number]->freq_factor),
- 1,
+ : BC_IPot(200,
+ y,
+ (int64_t)(synth->config.oscillator_config.values[gui->number]->freq_factor),
+ 1,
100)
{
this->synth = synth;
}
-PianoScroll::PianoScroll(Piano *synth,
- PianoWindow *window,
- int x,
- int y,
+PianoScroll::PianoScroll(Piano *synth,
+ PianoWindow *window,
+ int x,
+ int y,
int h)
- : BC_ScrollBar(x,
- y,
+ : BC_ScrollBar(x,
+ y,
SCROLL_VERT,
- h,
- synth->config.oscillator_config.total * OSCILLATORHEIGHT,
- 0,
+ h,
+ synth->config.oscillator_config.total * OSCILLATORHEIGHT,
+ 0,
window->subwindow->get_h())
{
this->synth = synth;
PianoWetness::PianoWetness(Piano *synth, int x, int y)
- : BC_FPot(x,
- y,
- synth->config.wetness,
- INFINITYGAIN,
+ : BC_FPot(x,
+ y,
+ synth->config.wetness,
+ INFINITYGAIN,
0)
{
this->synth = synth;
int PianoBaseFreq::handle_event()
{
int new_value = atol(get_text());
-
+
if(new_value > 0 && new_value < 30000)
{
synth->config.base_freq = new_value;
-PianoCanvas::PianoCanvas(Piano *synth,
- PianoWindow *window,
- int x,
- int y,
- int w,
+PianoCanvas::PianoCanvas(Piano *synth,
+ PianoWindow *window,
+ int x,
+ int y,
+ int w,
int h)
- : BC_SubWindow(x,
- y,
- w,
- h,
+ : BC_SubWindow(x,
+ y,
+ w,
+ h,
BLACK)
{
this->synth = synth;
int PianoCanvas::update()
{
int y1, y2, y = 0;
-
+
clear_box(0, 0, get_w(), get_h());
set_color(RED);
double normalize_constant = (double)1 / synth->get_total_power();
y1 = (int)(synth->get_point((float)0, normalize_constant) * get_h() / 2);
-
+
for(int i = 1; i < get_w(); i++)
{
y2 = (int)(synth->get_point((float)i / get_w(), normalize_constant) * get_h() / 2);
// ======================= level calculations
PianoLevelZero::PianoLevelZero(Piano *synth)
: BC_MenuItem(_("Zero"))
-{
- this->synth = synth;
+{
+ this->synth = synth;
}
-PianoLevelZero::~PianoLevelZero()
+PianoLevelZero::~PianoLevelZero()
{
}
PianoLevelMax::PianoLevelMax(Piano *synth)
: BC_MenuItem(_("Maximum"))
-{
- this->synth = synth;
+{
+ this->synth = synth;
}
PianoLevelMax::~PianoLevelMax()
new_value = synth->db.fromdb(synth->config.oscillator_config.values[i]->level);
new_value *= scale;
new_value = synth->db.todb(new_value);
-
+
synth->config.oscillator_config.values[i]->level = new_value;
}
int PianoLevelSlope::handle_event()
{
float slope = (float)INFINITYGAIN / synth->config.oscillator_config.total;
-
+
for(int i = 0; i < synth->config.oscillator_config.total; i++)
{
synth->config.oscillator_config.values[i]->level = i * slope;
PianoLevelRandom::PianoLevelRandom(Piano *synth)
: BC_MenuItem(_("Random"))
-{
- this->synth = synth;
+{
+ this->synth = synth;
}
PianoLevelRandom::~PianoLevelRandom()
{
{
for(int i = 0; i < synth->config.oscillator_config.total; i++)
{
- synth->config.oscillator_config.values[i]->level =
+ synth->config.oscillator_config.values[i]->level =
INFINITYGAIN - synth->config.oscillator_config.values[i]->level;
}
{
for(int i = 0; i < synth->config.oscillator_config.total; i++)
{
- synth->config.oscillator_config.values[i]->phase =
+ synth->config.oscillator_config.values[i]->phase =
1 - synth->config.oscillator_config.values[i]->phase;
}
srand(time(0));
for(int i = 0; i < synth->config.oscillator_config.total; i++)
{
- synth->config.oscillator_config.values[i]->phase =
+ synth->config.oscillator_config.values[i]->phase =
(float)(rand() % 360) / 360;
}
PianoFreqFibonacci::PianoFreqFibonacci(Piano *synth)
: BC_MenuItem(_("Fibonnacci"))
-{
- this->synth = synth;
+{
+ this->synth = synth;
}
PianoFreqFibonacci::~PianoFreqFibonacci()
{
PianoFreqPrime::PianoFreqPrime(Piano *synth)
: BC_MenuItem(_("Prime"))
-{
- this->synth = synth;
+{
+ this->synth = synth;
}
PianoFreqPrime::~PianoFreqPrime()
{
float PianoFreqPrime::get_next_prime(float number)
{
int result = 1;
-
+
while(result)
{
result = 0;
number++;
-
+
for(float i = number - 1; i > 1 && !result; i--)
{
if((number / i) - (int)(number / i) == 0) result = 1;
}
}
-
+
return number;
}
int PianoOscillatorConfig::equivalent(PianoOscillatorConfig &that)
{
- if(EQUIV(level, that.level) &&
+ if(EQUIV(level, that.level) &&
EQUIV(phase, that.phase) &&
EQUIV(freq_factor, that.freq_factor))
return 1;
wavefunction = that.wavefunction;
int i;
- for(i = 0;
+ for(i = 0;
i < oscillator_config.total && i < that.oscillator_config.total;
i++)
{
}
}
-void PianoConfig::interpolate(PianoConfig &prev,
- PianoConfig &next,
- int64_t prev_frame,
- int64_t next_frame,
+void PianoConfig::interpolate(PianoConfig &prev,
+ PianoConfig &next,
+ int64_t prev_frame,
+ int64_t next_frame,
int64_t current_frame)
{
double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);