You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
Applying BasePropertiesJSON to all effects in libopenshot, to reduce code duplication
This commit is contained in:
@@ -19,11 +19,11 @@ using namespace openshot;
|
||||
Compressor::Compressor() : Compressor::Compressor(-10, 1, 1, 1, 1, false) {}
|
||||
|
||||
Compressor::Compressor(Keyframe threshold, Keyframe ratio, Keyframe attack,
|
||||
Keyframe release, Keyframe makeup_gain,
|
||||
Keyframe bypass):
|
||||
threshold(threshold), ratio(ratio), attack(attack),
|
||||
release(release), makeup_gain(makeup_gain), bypass(bypass),
|
||||
input_level(0.0), yl_prev(0.0)
|
||||
Keyframe release, Keyframe makeup_gain,
|
||||
Keyframe bypass):
|
||||
threshold(threshold), ratio(ratio), attack(attack),
|
||||
release(release), makeup_gain(makeup_gain), bypass(bypass),
|
||||
input_level(0.0), yl_prev(0.0)
|
||||
{
|
||||
// Init effect properties
|
||||
init_effect_details();
|
||||
@@ -48,33 +48,33 @@ void Compressor::init_effect_details()
|
||||
std::shared_ptr<openshot::Frame> Compressor::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
|
||||
{
|
||||
// Adding Compressor
|
||||
const int num_input_channels = frame->audio->getNumChannels();
|
||||
const int num_output_channels = frame->audio->getNumChannels();
|
||||
const int num_samples = frame->audio->getNumSamples();
|
||||
const int num_input_channels = frame->audio->getNumChannels();
|
||||
const int num_output_channels = frame->audio->getNumChannels();
|
||||
const int num_samples = frame->audio->getNumSamples();
|
||||
|
||||
mixed_down_input.setSize(1, num_samples);
|
||||
mixed_down_input.setSize(1, num_samples);
|
||||
inverse_sample_rate = 1.0f / frame->SampleRate();
|
||||
inverseE = 1.0f / M_E;
|
||||
inverseE = 1.0f / M_E;
|
||||
|
||||
if ((bool)bypass.GetValue(frame_number))
|
||||
return frame;
|
||||
return frame;
|
||||
|
||||
mixed_down_input.clear();
|
||||
|
||||
for (int channel = 0; channel < num_input_channels; ++channel)
|
||||
mixed_down_input.addFrom(0, 0, *frame->audio, channel, 0, num_samples, 1.0f / num_input_channels);
|
||||
mixed_down_input.addFrom(0, 0, *frame->audio, channel, 0, num_samples, 1.0f / num_input_channels);
|
||||
|
||||
for (int sample = 0; sample < num_samples; ++sample) {
|
||||
float T = threshold.GetValue(frame_number);
|
||||
float R = ratio.GetValue(frame_number);
|
||||
float alphaA = calculateAttackOrRelease(attack.GetValue(frame_number));
|
||||
float alphaR = calculateAttackOrRelease(release.GetValue(frame_number));
|
||||
float gain = makeup_gain.GetValue(frame_number);
|
||||
for (int sample = 0; sample < num_samples; ++sample) {
|
||||
float T = threshold.GetValue(frame_number);
|
||||
float R = ratio.GetValue(frame_number);
|
||||
float alphaA = calculateAttackOrRelease(attack.GetValue(frame_number));
|
||||
float alphaR = calculateAttackOrRelease(release.GetValue(frame_number));
|
||||
float gain = makeup_gain.GetValue(frame_number);
|
||||
float input_squared = powf(mixed_down_input.getSample(0, sample), 2.0f);
|
||||
|
||||
input_level = input_squared;
|
||||
|
||||
xg = (input_level <= 1e-6f) ? -60.0f : 10.0f * log10f(input_level);
|
||||
xg = (input_level <= 1e-6f) ? -60.0f : 10.0f * log10f(input_level);
|
||||
|
||||
if (xg < T)
|
||||
yg = xg;
|
||||
@@ -88,17 +88,17 @@ std::shared_ptr<openshot::Frame> Compressor::GetFrame(std::shared_ptr<openshot::
|
||||
else
|
||||
yl = alphaR * yl_prev + (1.0f - alphaR) * xl;
|
||||
|
||||
control = powf (10.0f, (gain - yl) * 0.05f);
|
||||
yl_prev = yl;
|
||||
control = powf (10.0f, (gain - yl) * 0.05f);
|
||||
yl_prev = yl;
|
||||
|
||||
for (int channel = 0; channel < num_input_channels; ++channel) {
|
||||
float new_value = frame->audio->getSample(channel, sample)*control;
|
||||
frame->audio->setSample(channel, sample, new_value);
|
||||
}
|
||||
for (int channel = 0; channel < num_input_channels; ++channel) {
|
||||
float new_value = frame->audio->getSample(channel, sample)*control;
|
||||
frame->audio->setSample(channel, sample, new_value);
|
||||
}
|
||||
}
|
||||
|
||||
for (int channel = num_input_channels; channel < num_output_channels; ++channel)
|
||||
frame->audio->clear(channel, 0, num_samples);
|
||||
for (int channel = num_input_channels; channel < num_output_channels; ++channel)
|
||||
frame->audio->clear(channel, 0, num_samples);
|
||||
|
||||
// return the modified frame
|
||||
return frame;
|
||||
@@ -106,10 +106,10 @@ std::shared_ptr<openshot::Frame> Compressor::GetFrame(std::shared_ptr<openshot::
|
||||
|
||||
float Compressor::calculateAttackOrRelease(float value)
|
||||
{
|
||||
if (value == 0.0f)
|
||||
return 0.0f;
|
||||
else
|
||||
return pow (inverseE, inverse_sample_rate / value);
|
||||
if (value == 0.0f)
|
||||
return 0.0f;
|
||||
else
|
||||
return pow (inverseE, inverse_sample_rate / value);
|
||||
}
|
||||
|
||||
// Generate JSON string of this object
|
||||
@@ -183,12 +183,7 @@ void Compressor::SetJsonValue(const Json::Value root) {
|
||||
std::string Compressor::PropertiesJSON(int64_t requested_frame) const {
|
||||
|
||||
// Generate JSON properties list
|
||||
Json::Value root;
|
||||
root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
|
||||
root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
|
||||
root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 1000 * 60 * 30, true, requested_frame);
|
||||
Json::Value root = BasePropertiesJSON(requested_frame);
|
||||
|
||||
// Keyframes
|
||||
root["threshold"] = add_property_json("Threshold (dB)", threshold.GetValue(requested_frame), "float", "", &threshold, -60, 0, false, requested_frame);
|
||||
|
||||
@@ -68,34 +68,34 @@ std::shared_ptr<openshot::Frame> Delay::GetFrame(std::shared_ptr<openshot::Frame
|
||||
for (int channel = 0; channel < frame->audio->getNumChannels(); channel++)
|
||||
{
|
||||
float *channel_data = frame->audio->getWritePointer(channel);
|
||||
float *delay_data = delay_buffer.getWritePointer(channel);
|
||||
local_write_position = delay_write_position;
|
||||
float *delay_data = delay_buffer.getWritePointer(channel);
|
||||
local_write_position = delay_write_position;
|
||||
|
||||
for (auto sample = 0; sample < frame->audio->getNumSamples(); ++sample)
|
||||
{
|
||||
const float in = (float)(channel_data[sample]);
|
||||
float out = 0.0f;
|
||||
float out = 0.0f;
|
||||
|
||||
float read_position = fmodf((float)local_write_position - delay_time_value + (float)delay_buffer_samples, delay_buffer_samples);
|
||||
int local_read_position = floorf(read_position);
|
||||
float read_position = fmodf((float)local_write_position - delay_time_value + (float)delay_buffer_samples, delay_buffer_samples);
|
||||
int local_read_position = floorf(read_position);
|
||||
|
||||
if (local_read_position != local_write_position)
|
||||
if (local_read_position != local_write_position)
|
||||
{
|
||||
float fraction = read_position - (float)local_read_position;
|
||||
float delayed1 = delay_data[(local_read_position + 0)];
|
||||
float delayed2 = delay_data[(local_read_position + 1) % delay_buffer_samples];
|
||||
out = (float)(delayed1 + fraction * (delayed2 - delayed1));
|
||||
float fraction = read_position - (float)local_read_position;
|
||||
float delayed1 = delay_data[(local_read_position + 0)];
|
||||
float delayed2 = delay_data[(local_read_position + 1) % delay_buffer_samples];
|
||||
out = (float)(delayed1 + fraction * (delayed2 - delayed1));
|
||||
|
||||
channel_data[sample] = in + (out - in);
|
||||
channel_data[sample] = in + (out - in);
|
||||
delay_data[local_write_position] = in;
|
||||
}
|
||||
}
|
||||
|
||||
if (++local_write_position >= delay_buffer_samples)
|
||||
local_write_position -= delay_buffer_samples;
|
||||
if (++local_write_position >= delay_buffer_samples)
|
||||
local_write_position -= delay_buffer_samples;
|
||||
}
|
||||
}
|
||||
|
||||
delay_write_position = local_write_position;
|
||||
delay_write_position = local_write_position;
|
||||
|
||||
// return the modified frame
|
||||
return frame;
|
||||
@@ -152,12 +152,7 @@ void Delay::SetJsonValue(const Json::Value root) {
|
||||
std::string Delay::PropertiesJSON(int64_t requested_frame) const {
|
||||
|
||||
// Generate JSON properties list
|
||||
Json::Value root;
|
||||
root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
|
||||
root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
|
||||
root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 1000 * 60 * 30, true, requested_frame);
|
||||
Json::Value root = BasePropertiesJSON(requested_frame);
|
||||
|
||||
// Keyframes
|
||||
root["delay_time"] = add_property_json("Delay Time", delay_time.GetValue(requested_frame), "float", "", &delay_time, 0, 5, false, requested_frame);
|
||||
|
||||
@@ -18,10 +18,10 @@ using namespace openshot;
|
||||
Distortion::Distortion(): Distortion::Distortion(HARD_CLIPPING, 10, -10, 5) { }
|
||||
|
||||
Distortion::Distortion(openshot::DistortionType distortion_type,
|
||||
Keyframe input_gain, Keyframe output_gain,
|
||||
Keyframe tone):
|
||||
distortion_type(distortion_type), input_gain(input_gain),
|
||||
output_gain(output_gain), tone(tone)
|
||||
Keyframe input_gain, Keyframe output_gain,
|
||||
Keyframe tone):
|
||||
distortion_type(distortion_type), input_gain(input_gain),
|
||||
output_gain(output_gain), tone(tone)
|
||||
{
|
||||
// Init effect properties
|
||||
init_effect_details();
|
||||
@@ -48,12 +48,12 @@ std::shared_ptr<openshot::Frame> Distortion::GetFrame(std::shared_ptr<openshot::
|
||||
{
|
||||
filters.clear();
|
||||
|
||||
for (int i = 0; i < frame->audio->getNumChannels(); ++i) {
|
||||
Filter* filter;
|
||||
filters.add (filter = new Filter());
|
||||
}
|
||||
for (int i = 0; i < frame->audio->getNumChannels(); ++i) {
|
||||
Filter* filter;
|
||||
filters.add (filter = new Filter());
|
||||
}
|
||||
|
||||
updateFilters(frame_number);
|
||||
updateFilters(frame_number);
|
||||
|
||||
// Add distortion
|
||||
for (int channel = 0; channel < frame->audio->getNumChannels(); channel++)
|
||||
@@ -73,53 +73,53 @@ std::shared_ptr<openshot::Frame> Distortion::GetFrame(std::shared_ptr<openshot::
|
||||
|
||||
case HARD_CLIPPING: {
|
||||
float threshold = 0.5f;
|
||||
if (in > threshold)
|
||||
out = threshold;
|
||||
else if (in < -threshold)
|
||||
out = -threshold;
|
||||
else
|
||||
out = in;
|
||||
break;
|
||||
}
|
||||
if (in > threshold)
|
||||
out = threshold;
|
||||
else if (in < -threshold)
|
||||
out = -threshold;
|
||||
else
|
||||
out = in;
|
||||
break;
|
||||
}
|
||||
|
||||
case SOFT_CLIPPING: {
|
||||
float threshold1 = 1.0f / 3.0f;
|
||||
float threshold2 = 2.0f / 3.0f;
|
||||
if (in > threshold2)
|
||||
out = 1.0f;
|
||||
else if (in > threshold1)
|
||||
out = 1.0f - powf (2.0f - 3.0f * in, 2.0f) / 3.0f;
|
||||
else if (in < -threshold2)
|
||||
out = -1.0f;
|
||||
else if (in < -threshold1)
|
||||
out = -1.0f + powf (2.0f + 3.0f * in, 2.0f) / 3.0f;
|
||||
else
|
||||
out = 2.0f * in;
|
||||
out *= 0.5f;
|
||||
break;
|
||||
}
|
||||
case SOFT_CLIPPING: {
|
||||
float threshold1 = 1.0f / 3.0f;
|
||||
float threshold2 = 2.0f / 3.0f;
|
||||
if (in > threshold2)
|
||||
out = 1.0f;
|
||||
else if (in > threshold1)
|
||||
out = 1.0f - powf (2.0f - 3.0f * in, 2.0f) / 3.0f;
|
||||
else if (in < -threshold2)
|
||||
out = -1.0f;
|
||||
else if (in < -threshold1)
|
||||
out = -1.0f + powf (2.0f + 3.0f * in, 2.0f) / 3.0f;
|
||||
else
|
||||
out = 2.0f * in;
|
||||
out *= 0.5f;
|
||||
break;
|
||||
}
|
||||
|
||||
case EXPONENTIAL: {
|
||||
if (in > 0.0f)
|
||||
out = 1.0f - expf (-in);
|
||||
else
|
||||
out = -1.0f + expf (in);
|
||||
break;
|
||||
}
|
||||
case EXPONENTIAL: {
|
||||
if (in > 0.0f)
|
||||
out = 1.0f - expf (-in);
|
||||
else
|
||||
out = -1.0f + expf (in);
|
||||
break;
|
||||
}
|
||||
|
||||
case FULL_WAVE_RECTIFIER: {
|
||||
out = fabsf (in);
|
||||
break;
|
||||
}
|
||||
case FULL_WAVE_RECTIFIER: {
|
||||
out = fabsf (in);
|
||||
break;
|
||||
}
|
||||
|
||||
case HALF_WAVE_RECTIFIER: {
|
||||
if (in > 0.0f)
|
||||
out = in;
|
||||
else
|
||||
out = 0.0f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
case HALF_WAVE_RECTIFIER: {
|
||||
if (in > 0.0f)
|
||||
out = in;
|
||||
else
|
||||
out = 0.0f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
float filtered = filters[channel]->processSingleSampleRaw(out);
|
||||
channel_data[sample] = filtered*powf(10.0f, output_gain_value * 0.05f);
|
||||
@@ -132,11 +132,11 @@ std::shared_ptr<openshot::Frame> Distortion::GetFrame(std::shared_ptr<openshot::
|
||||
|
||||
void Distortion::updateFilters(int64_t frame_number)
|
||||
{
|
||||
double discrete_frequency = M_PI * 0.01;
|
||||
double gain = pow(10.0, (float)tone.GetValue(frame_number) * 0.05);
|
||||
double discrete_frequency = M_PI * 0.01;
|
||||
double gain = pow(10.0, (float)tone.GetValue(frame_number) * 0.05);
|
||||
|
||||
for (int i = 0; i < filters.size(); ++i)
|
||||
filters[i]->updateCoefficients(discrete_frequency, gain);
|
||||
for (int i = 0; i < filters.size(); ++i)
|
||||
filters[i]->updateCoefficients(discrete_frequency, gain);
|
||||
}
|
||||
|
||||
// Generate JSON string of this object
|
||||
@@ -216,12 +216,7 @@ void Distortion::SetJsonValue(const Json::Value root) {
|
||||
std::string Distortion::PropertiesJSON(int64_t requested_frame) const {
|
||||
|
||||
// Generate JSON properties list
|
||||
Json::Value root;
|
||||
root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
|
||||
root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
|
||||
root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 1000 * 60 * 30, true, requested_frame);
|
||||
Json::Value root = BasePropertiesJSON(requested_frame);
|
||||
|
||||
// Keyframes
|
||||
root["distortion_type"] = add_property_json("Distortion Type", distortion_type, "int", "", NULL, 0, 3, false, requested_frame);
|
||||
|
||||
@@ -19,7 +19,7 @@ using namespace openshot;
|
||||
Echo::Echo() : Echo::Echo(0.1, 0.5, 0.5) { }
|
||||
|
||||
Echo::Echo(Keyframe echo_time, Keyframe feedback, Keyframe mix) :
|
||||
echo_time(echo_time), feedback(feedback), mix(mix)
|
||||
echo_time(echo_time), feedback(feedback), mix(mix)
|
||||
{
|
||||
// Init effect properties
|
||||
init_effect_details();
|
||||
@@ -72,33 +72,33 @@ std::shared_ptr<openshot::Frame> Echo::GetFrame(std::shared_ptr<openshot::Frame>
|
||||
for (int channel = 0; channel < frame->audio->getNumChannels(); channel++)
|
||||
{
|
||||
float *channel_data = frame->audio->getWritePointer(channel);
|
||||
float *echo_data = echo_buffer.getWritePointer(channel);
|
||||
local_write_position = echo_write_position;
|
||||
float *echo_data = echo_buffer.getWritePointer(channel);
|
||||
local_write_position = echo_write_position;
|
||||
|
||||
for (auto sample = 0; sample < frame->audio->getNumSamples(); ++sample)
|
||||
{
|
||||
const float in = (float)(channel_data[sample]);
|
||||
float out = 0.0f;
|
||||
float out = 0.0f;
|
||||
|
||||
float read_position = fmodf((float)local_write_position - echo_time_value + (float)echo_buffer_samples, echo_buffer_samples);
|
||||
int local_read_position = floorf(read_position);
|
||||
float read_position = fmodf((float)local_write_position - echo_time_value + (float)echo_buffer_samples, echo_buffer_samples);
|
||||
int local_read_position = floorf(read_position);
|
||||
|
||||
if (local_read_position != local_write_position)
|
||||
if (local_read_position != local_write_position)
|
||||
{
|
||||
float fraction = read_position - (float)local_read_position;
|
||||
float echoed1 = echo_data[(local_read_position + 0)];
|
||||
float echoed2 = echo_data[(local_read_position + 1) % echo_buffer_samples];
|
||||
out = (float)(echoed1 + fraction * (echoed2 - echoed1));
|
||||
channel_data[sample] = in + mix_value*(out - in);
|
||||
float fraction = read_position - (float)local_read_position;
|
||||
float echoed1 = echo_data[(local_read_position + 0)];
|
||||
float echoed2 = echo_data[(local_read_position + 1) % echo_buffer_samples];
|
||||
out = (float)(echoed1 + fraction * (echoed2 - echoed1));
|
||||
channel_data[sample] = in + mix_value*(out - in);
|
||||
echo_data[local_write_position] = in + out*feedback_value;
|
||||
}
|
||||
}
|
||||
|
||||
if (++local_write_position >= echo_buffer_samples)
|
||||
local_write_position -= echo_buffer_samples;
|
||||
if (++local_write_position >= echo_buffer_samples)
|
||||
local_write_position -= echo_buffer_samples;
|
||||
}
|
||||
}
|
||||
|
||||
echo_write_position = local_write_position;
|
||||
echo_write_position = local_write_position;
|
||||
|
||||
// return the modified frame
|
||||
return frame;
|
||||
@@ -161,12 +161,7 @@ void Echo::SetJsonValue(const Json::Value root) {
|
||||
std::string Echo::PropertiesJSON(int64_t requested_frame) const {
|
||||
|
||||
// Generate JSON properties list
|
||||
Json::Value root;
|
||||
root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
|
||||
root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
|
||||
root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 1000 * 60 * 30, true, requested_frame);
|
||||
Json::Value root = BasePropertiesJSON(requested_frame);
|
||||
|
||||
// Keyframes
|
||||
root["echo_time"] = add_property_json("Time", echo_time.GetValue(requested_frame), "float", "", &echo_time, 0, 5, false, requested_frame);
|
||||
|
||||
@@ -20,9 +20,9 @@ Expander::Expander(): Expander::Expander(-10, 1, 1, 1, 1, false) { }
|
||||
|
||||
// Default constructor
|
||||
Expander::Expander(Keyframe threshold, Keyframe ratio, Keyframe attack,
|
||||
Keyframe release, Keyframe makeup_gain, Keyframe bypass) :
|
||||
threshold(threshold), ratio(ratio), attack(attack),
|
||||
release(release), makeup_gain(makeup_gain), bypass(bypass)
|
||||
Keyframe release, Keyframe makeup_gain, Keyframe bypass) :
|
||||
threshold(threshold), ratio(ratio), attack(attack),
|
||||
release(release), makeup_gain(makeup_gain), bypass(bypass)
|
||||
{
|
||||
// Init effect properties
|
||||
init_effect_details();
|
||||
@@ -41,8 +41,8 @@ void Expander::init_effect_details()
|
||||
info.has_audio = true;
|
||||
info.has_video = false;
|
||||
|
||||
input_level = 0.0f;
|
||||
yl_prev = 0.0f;
|
||||
input_level = 0.0f;
|
||||
yl_prev = 0.0f;
|
||||
|
||||
|
||||
}
|
||||
@@ -52,34 +52,34 @@ void Expander::init_effect_details()
|
||||
std::shared_ptr<openshot::Frame> Expander::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
|
||||
{
|
||||
// Adding Expander
|
||||
const int num_input_channels = frame->audio->getNumChannels();
|
||||
const int num_output_channels = frame->audio->getNumChannels();
|
||||
const int num_samples = frame->audio->getNumSamples();
|
||||
const int num_input_channels = frame->audio->getNumChannels();
|
||||
const int num_output_channels = frame->audio->getNumChannels();
|
||||
const int num_samples = frame->audio->getNumSamples();
|
||||
|
||||
mixed_down_input.setSize(1, num_samples);
|
||||
mixed_down_input.setSize(1, num_samples);
|
||||
inverse_sample_rate = 1.0f / frame->SampleRate();
|
||||
inverseE = 1.0f / M_E;
|
||||
inverseE = 1.0f / M_E;
|
||||
|
||||
if ((bool)bypass.GetValue(frame_number))
|
||||
return frame;
|
||||
return frame;
|
||||
|
||||
mixed_down_input.clear();
|
||||
|
||||
for (int channel = 0; channel < num_input_channels; ++channel)
|
||||
mixed_down_input.addFrom(0, 0, *frame->audio, channel, 0, num_samples, 1.0f / num_input_channels);
|
||||
mixed_down_input.addFrom(0, 0, *frame->audio, channel, 0, num_samples, 1.0f / num_input_channels);
|
||||
|
||||
for (int sample = 0; sample < num_samples; ++sample) {
|
||||
float T = threshold.GetValue(frame_number);
|
||||
float R = ratio.GetValue(frame_number);
|
||||
float alphaA = calculateAttackOrRelease(attack.GetValue(frame_number));
|
||||
float alphaR = calculateAttackOrRelease(release.GetValue(frame_number));
|
||||
float gain = makeup_gain.GetValue(frame_number);
|
||||
for (int sample = 0; sample < num_samples; ++sample) {
|
||||
float T = threshold.GetValue(frame_number);
|
||||
float R = ratio.GetValue(frame_number);
|
||||
float alphaA = calculateAttackOrRelease(attack.GetValue(frame_number));
|
||||
float alphaR = calculateAttackOrRelease(release.GetValue(frame_number));
|
||||
float gain = makeup_gain.GetValue(frame_number);
|
||||
float input_squared = powf(mixed_down_input.getSample(0, sample), 2.0f);
|
||||
|
||||
const float average_factor = 0.9999f;
|
||||
input_level = average_factor * input_level + (1.0f - average_factor) * input_squared;
|
||||
|
||||
xg = (input_level <= 1e-6f) ? -60.0f : 10.0f * log10f(input_level);
|
||||
xg = (input_level <= 1e-6f) ? -60.0f : 10.0f * log10f(input_level);
|
||||
|
||||
if (xg > T)
|
||||
yg = xg;
|
||||
@@ -94,17 +94,17 @@ std::shared_ptr<openshot::Frame> Expander::GetFrame(std::shared_ptr<openshot::Fr
|
||||
yl = alphaR * yl_prev + (1.0f - alphaR) * xl;
|
||||
|
||||
|
||||
control = powf (10.0f, (gain - yl) * 0.05f);
|
||||
yl_prev = yl;
|
||||
control = powf (10.0f, (gain - yl) * 0.05f);
|
||||
yl_prev = yl;
|
||||
|
||||
for (int channel = 0; channel < num_input_channels; ++channel) {
|
||||
float new_value = frame->audio->getSample(channel, sample)*control;
|
||||
frame->audio->setSample(channel, sample, new_value);
|
||||
}
|
||||
for (int channel = 0; channel < num_input_channels; ++channel) {
|
||||
float new_value = frame->audio->getSample(channel, sample)*control;
|
||||
frame->audio->setSample(channel, sample, new_value);
|
||||
}
|
||||
}
|
||||
|
||||
for (int channel = num_input_channels; channel < num_output_channels; ++channel)
|
||||
frame->audio->clear(channel, 0, num_samples);
|
||||
for (int channel = num_input_channels; channel < num_output_channels; ++channel)
|
||||
frame->audio->clear(channel, 0, num_samples);
|
||||
|
||||
// return the modified frame
|
||||
return frame;
|
||||
@@ -112,10 +112,10 @@ std::shared_ptr<openshot::Frame> Expander::GetFrame(std::shared_ptr<openshot::Fr
|
||||
|
||||
float Expander::calculateAttackOrRelease(float value)
|
||||
{
|
||||
if (value == 0.0f)
|
||||
return 0.0f;
|
||||
else
|
||||
return pow (inverseE, inverse_sample_rate / value);
|
||||
if (value == 0.0f)
|
||||
return 0.0f;
|
||||
else
|
||||
return pow (inverseE, inverse_sample_rate / value);
|
||||
}
|
||||
|
||||
// Generate JSON string of this object
|
||||
@@ -189,12 +189,7 @@ void Expander::SetJsonValue(const Json::Value root) {
|
||||
std::string Expander::PropertiesJSON(int64_t requested_frame) const {
|
||||
|
||||
// Generate JSON properties list
|
||||
Json::Value root;
|
||||
root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
|
||||
root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
|
||||
root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 1000 * 60 * 30, true, requested_frame);
|
||||
Json::Value root = BasePropertiesJSON(requested_frame);
|
||||
|
||||
// Keyframes
|
||||
root["threshold"] = add_property_json("Threshold (dB)", threshold.GetValue(requested_frame), "float", "", &threshold, -60, 0, false, requested_frame);
|
||||
|
||||
@@ -115,12 +115,7 @@ void Noise::SetJsonValue(const Json::Value root) {
|
||||
std::string Noise::PropertiesJSON(int64_t requested_frame) const {
|
||||
|
||||
// Generate JSON properties list
|
||||
Json::Value root;
|
||||
root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
|
||||
root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
|
||||
root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 1000 * 60 * 30, true, requested_frame);
|
||||
Json::Value root = BasePropertiesJSON(requested_frame);
|
||||
|
||||
// Keyframes
|
||||
root["level"] = add_property_json("Level", level.GetValue(requested_frame), "int", "", &level, 0, 100, false, requested_frame);
|
||||
|
||||
@@ -19,9 +19,9 @@ using namespace juce;
|
||||
ParametricEQ::ParametricEQ(): ParametricEQ::ParametricEQ(LOW_PASS, 500, 0, 0) {}
|
||||
|
||||
ParametricEQ::ParametricEQ(openshot::FilterType filter_type,
|
||||
Keyframe frequency, Keyframe gain, Keyframe q_factor) :
|
||||
filter_type(filter_type),
|
||||
frequency(frequency), gain(gain), q_factor(q_factor)
|
||||
Keyframe frequency, Keyframe gain, Keyframe q_factor) :
|
||||
filter_type(filter_type),
|
||||
frequency(frequency), gain(gain), q_factor(q_factor)
|
||||
{
|
||||
// Init effect properties
|
||||
init_effect_details();
|
||||
@@ -59,9 +59,9 @@ std::shared_ptr<openshot::Frame> ParametricEQ::GetFrame(std::shared_ptr<openshot
|
||||
}
|
||||
|
||||
const int num_input_channels = frame->audio->getNumChannels();
|
||||
const int num_output_channels = frame->audio->getNumChannels();
|
||||
const int num_samples = frame->audio->getNumSamples();
|
||||
updateFilters(frame_number, num_samples);
|
||||
const int num_output_channels = frame->audio->getNumChannels();
|
||||
const int num_samples = frame->audio->getNumSamples();
|
||||
updateFilters(frame_number, num_samples);
|
||||
|
||||
for (int channel = 0; channel < frame->audio->getNumChannels(); channel++)
|
||||
{
|
||||
@@ -69,9 +69,9 @@ std::shared_ptr<openshot::Frame> ParametricEQ::GetFrame(std::shared_ptr<openshot
|
||||
filters[channel]->processSamples(channel_data, num_samples);
|
||||
}
|
||||
|
||||
for (int channel = num_input_channels; channel < num_output_channels; ++channel)
|
||||
for (int channel = num_input_channels; channel < num_output_channels; ++channel)
|
||||
{
|
||||
frame->audio->clear(channel, 0, num_samples);
|
||||
frame->audio->clear(channel, 0, num_samples);
|
||||
}
|
||||
|
||||
// return the modified frame
|
||||
@@ -161,12 +161,12 @@ void ParametricEQ::Filter::updateCoefficients (
|
||||
|
||||
void ParametricEQ::updateFilters(int64_t frame_number, double sample_rate)
|
||||
{
|
||||
double discrete_frequency = 2.0 * M_PI * (double)frequency.GetValue(frame_number) / sample_rate;
|
||||
double discrete_frequency = 2.0 * M_PI * (double)frequency.GetValue(frame_number) / sample_rate;
|
||||
double q_value = (double)q_factor.GetValue(frame_number);
|
||||
double gain_value = pow(10.0, (double)gain.GetValue(frame_number) * 0.05);
|
||||
int filter_type_value = (int)filter_type;
|
||||
|
||||
for (int i = 0; i < filters.size(); ++i)
|
||||
for (int i = 0; i < filters.size(); ++i)
|
||||
filters[i]->updateCoefficients(discrete_frequency, q_value, gain_value, filter_type_value);
|
||||
}
|
||||
|
||||
@@ -233,12 +233,7 @@ void ParametricEQ::SetJsonValue(const Json::Value root) {
|
||||
std::string ParametricEQ::PropertiesJSON(int64_t requested_frame) const {
|
||||
|
||||
// Generate JSON properties list
|
||||
Json::Value root;
|
||||
root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
|
||||
root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
|
||||
root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 1000 * 60 * 30, true, requested_frame);
|
||||
Json::Value root = BasePropertiesJSON(requested_frame);
|
||||
|
||||
// Keyframes
|
||||
root["filter_type"] = add_property_json("Filter Type", filter_type, "int", "", NULL, 0, 3, false, requested_frame);
|
||||
|
||||
@@ -18,13 +18,13 @@ using namespace openshot;
|
||||
using namespace juce;
|
||||
|
||||
Robotization::Robotization()
|
||||
: Robotization::Robotization(FFT_SIZE_512, HOP_SIZE_2, RECTANGULAR) {}
|
||||
: Robotization::Robotization(FFT_SIZE_512, HOP_SIZE_2, RECTANGULAR) {}
|
||||
|
||||
Robotization::Robotization(openshot::FFTSize fft_size,
|
||||
openshot::HopSize hop_size,
|
||||
openshot::WindowType window_type) :
|
||||
fft_size(fft_size), hop_size(hop_size),
|
||||
window_type(window_type), stft(*this)
|
||||
openshot::HopSize hop_size,
|
||||
openshot::WindowType window_type) :
|
||||
fft_size(fft_size), hop_size(hop_size),
|
||||
window_type(window_type), stft(*this)
|
||||
{
|
||||
// Init effect properties
|
||||
init_effect_details();
|
||||
@@ -49,20 +49,20 @@ void Robotization::init_effect_details()
|
||||
std::shared_ptr<openshot::Frame> Robotization::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
|
||||
{
|
||||
const std::lock_guard<std::recursive_mutex> lock(mutex);
|
||||
ScopedNoDenormals noDenormals;
|
||||
ScopedNoDenormals noDenormals;
|
||||
|
||||
const int num_input_channels = frame->audio->getNumChannels();
|
||||
const int num_output_channels = frame->audio->getNumChannels();
|
||||
const int num_samples = frame->audio->getNumSamples();
|
||||
const int hop_size_value = 1 << ((int)hop_size + 1);
|
||||
const int num_input_channels = frame->audio->getNumChannels();
|
||||
const int num_output_channels = frame->audio->getNumChannels();
|
||||
const int num_samples = frame->audio->getNumSamples();
|
||||
const int hop_size_value = 1 << ((int)hop_size + 1);
|
||||
const int fft_size_value = 1 << ((int)fft_size + 5);
|
||||
|
||||
stft.setup(num_output_channels);
|
||||
stft.updateParameters((int)fft_size_value,
|
||||
(int)hop_size_value,
|
||||
(int)window_type);
|
||||
stft.setup(num_output_channels);
|
||||
stft.updateParameters((int)fft_size_value,
|
||||
(int)hop_size_value,
|
||||
(int)window_type);
|
||||
|
||||
stft.process(*frame->audio);
|
||||
stft.process(*frame->audio);
|
||||
|
||||
// return the modified frame
|
||||
return frame;
|
||||
@@ -139,12 +139,7 @@ void Robotization::SetJsonValue(const Json::Value root) {
|
||||
std::string Robotization::PropertiesJSON(int64_t requested_frame) const {
|
||||
|
||||
// Generate JSON properties list
|
||||
Json::Value root;
|
||||
root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
|
||||
root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
|
||||
root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 1000 * 60 * 30, true, requested_frame);
|
||||
Json::Value root = BasePropertiesJSON(requested_frame);
|
||||
|
||||
// Keyframes
|
||||
root["fft_size"] = add_property_json("FFT Size", fft_size, "int", "", NULL, 0, 8, false, requested_frame);
|
||||
|
||||
@@ -18,13 +18,13 @@ using namespace openshot;
|
||||
using namespace juce;
|
||||
|
||||
Whisperization::Whisperization():
|
||||
Whisperization::Whisperization(FFT_SIZE_512, HOP_SIZE_8, RECTANGULAR) {}
|
||||
Whisperization::Whisperization(FFT_SIZE_512, HOP_SIZE_8, RECTANGULAR) {}
|
||||
|
||||
Whisperization::Whisperization(openshot::FFTSize fft_size,
|
||||
openshot::HopSize hop_size,
|
||||
openshot::WindowType window_type) :
|
||||
fft_size(fft_size), hop_size(hop_size),
|
||||
window_type(window_type), stft(*this)
|
||||
openshot::HopSize hop_size,
|
||||
openshot::WindowType window_type) :
|
||||
fft_size(fft_size), hop_size(hop_size),
|
||||
window_type(window_type), stft(*this)
|
||||
{
|
||||
// Init effect properties
|
||||
init_effect_details();
|
||||
@@ -48,21 +48,21 @@ void Whisperization::init_effect_details()
|
||||
// modified openshot::Frame object
|
||||
std::shared_ptr<openshot::Frame> Whisperization::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
|
||||
{
|
||||
const std::lock_guard<std::recursive_mutex> lock(mutex);
|
||||
ScopedNoDenormals noDenormals;
|
||||
const std::lock_guard<std::recursive_mutex> lock(mutex);
|
||||
ScopedNoDenormals noDenormals;
|
||||
|
||||
const int num_input_channels = frame->audio->getNumChannels();
|
||||
const int num_output_channels = frame->audio->getNumChannels();
|
||||
const int num_samples = frame->audio->getNumSamples();
|
||||
const int hop_size_value = 1 << ((int)hop_size + 1);
|
||||
const int num_input_channels = frame->audio->getNumChannels();
|
||||
const int num_output_channels = frame->audio->getNumChannels();
|
||||
const int num_samples = frame->audio->getNumSamples();
|
||||
const int hop_size_value = 1 << ((int)hop_size + 1);
|
||||
const int fft_size_value = 1 << ((int)fft_size + 5);
|
||||
|
||||
stft.setup(num_output_channels);
|
||||
stft.updateParameters((int)fft_size_value,
|
||||
(int)hop_size_value,
|
||||
(int)window_type);
|
||||
stft.setup(num_output_channels);
|
||||
stft.updateParameters((int)fft_size_value,
|
||||
(int)hop_size_value,
|
||||
(int)window_type);
|
||||
|
||||
stft.process(*frame->audio);
|
||||
stft.process(*frame->audio);
|
||||
|
||||
// return the modified frame
|
||||
return frame;
|
||||
@@ -147,12 +147,7 @@ void Whisperization::SetJsonValue(const Json::Value root) {
|
||||
std::string Whisperization::PropertiesJSON(int64_t requested_frame) const {
|
||||
|
||||
// Generate JSON properties list
|
||||
Json::Value root;
|
||||
root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
|
||||
root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
|
||||
root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 1000 * 60 * 30, true, requested_frame);
|
||||
Json::Value root = BasePropertiesJSON(requested_frame);
|
||||
|
||||
// Keyframes
|
||||
root["fft_size"] = add_property_json("FFT Size", fft_size, "int", "", NULL, 0, 8, false, requested_frame);
|
||||
|
||||
@@ -160,13 +160,7 @@ void Bars::SetJsonValue(const Json::Value root) {
|
||||
std::string Bars::PropertiesJSON(int64_t requested_frame) const {
|
||||
|
||||
// Generate JSON properties list
|
||||
Json::Value root;
|
||||
root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
|
||||
root["position"] = add_property_json("Position", Position(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
|
||||
root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 1000 * 60 * 30, true, requested_frame);
|
||||
Json::Value root = BasePropertiesJSON(requested_frame);
|
||||
|
||||
// Keyframes
|
||||
root["color"] = add_property_json("Bar Color", 0.0, "color", "", &color.red, 0, 255, false, requested_frame);
|
||||
|
||||
@@ -211,13 +211,7 @@ void Blur::SetJsonValue(const Json::Value root) {
|
||||
std::string Blur::PropertiesJSON(int64_t requested_frame) const {
|
||||
|
||||
// Generate JSON properties list
|
||||
Json::Value root;
|
||||
root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
|
||||
root["position"] = add_property_json("Position", Position(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
|
||||
root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 1000 * 60 * 30, true, requested_frame);
|
||||
Json::Value root = BasePropertiesJSON(requested_frame);
|
||||
|
||||
// Keyframes
|
||||
root["horizontal_radius"] = add_property_json("Horizontal Radius", horizontal_radius.GetValue(requested_frame), "float", "", &horizontal_radius, 0, 100, false, requested_frame);
|
||||
|
||||
@@ -146,13 +146,7 @@ void Brightness::SetJsonValue(const Json::Value root) {
|
||||
std::string Brightness::PropertiesJSON(int64_t requested_frame) const {
|
||||
|
||||
// Generate JSON properties list
|
||||
Json::Value root;
|
||||
root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
|
||||
root["position"] = add_property_json("Position", Position(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame);
|
||||
root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
|
||||
root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame);
|
||||
root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame);
|
||||
root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 30 * 60 * 60 * 48, true, requested_frame);
|
||||
Json::Value root = BasePropertiesJSON(requested_frame);
|
||||
|
||||
// Keyframes
|
||||
root["brightness"] = add_property_json("Brightness", brightness.GetValue(requested_frame), "float", "", &brightness, -1.0, 1.0, false, requested_frame);
|
||||
|
||||
@@ -454,13 +454,7 @@ void Caption::SetJsonValue(const Json::Value root) {
|
||||
std::string Caption::PropertiesJSON(int64_t requested_frame) const {
|
||||
|
||||
// Generate JSON properties list
|
||||
Json::Value root;
|
||||
root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
|
||||
root["position"] = add_property_json("Position", Position(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
|
||||
root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 1000 * 60 * 30, true, requested_frame);
|
||||
Json::Value root = BasePropertiesJSON(requested_frame);
|
||||
|
||||
// Keyframes
|
||||
root["color"] = add_property_json("Color", 0.0, "color", "", &color.red, 0, 255, false, requested_frame);
|
||||
|
||||
@@ -497,7 +497,7 @@ std::shared_ptr<openshot::Frame> ChromaKey::GetFrame(std::shared_ptr<openshot::F
|
||||
unsigned char G = (pixel[1] / A) * 255.0;
|
||||
unsigned char B = (pixel[2] / A) * 255.0;
|
||||
|
||||
// Get distance between mask color and pixel color
|
||||
// Get distance between mask color and pixel color
|
||||
long distance = Color::GetDistance((long)R, (long)G, (long)B, mask_R, mask_G, mask_B);
|
||||
|
||||
if (distance <= threshold) {
|
||||
@@ -573,13 +573,7 @@ void ChromaKey::SetJsonValue(const Json::Value root) {
|
||||
std::string ChromaKey::PropertiesJSON(int64_t requested_frame) const {
|
||||
|
||||
// Generate JSON properties list
|
||||
Json::Value root;
|
||||
root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
|
||||
root["position"] = add_property_json("Position", Position(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame);
|
||||
root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
|
||||
root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame);
|
||||
root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame);
|
||||
root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 30 * 60 * 60 * 48, true, requested_frame);
|
||||
Json::Value root = BasePropertiesJSON(requested_frame);
|
||||
|
||||
// Keyframes
|
||||
root["color"] = add_property_json("Key Color", 0.0, "color", "", &color.red, 0, 255, false, requested_frame);
|
||||
|
||||
@@ -246,13 +246,7 @@ void ColorShift::SetJsonValue(const Json::Value root) {
|
||||
std::string ColorShift::PropertiesJSON(int64_t requested_frame) const {
|
||||
|
||||
// Generate JSON properties list
|
||||
Json::Value root;
|
||||
root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
|
||||
root["position"] = add_property_json("Position", Position(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
|
||||
root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 1000 * 60 * 30, true, requested_frame);
|
||||
Json::Value root = BasePropertiesJSON(requested_frame);
|
||||
|
||||
// Keyframes
|
||||
root["red_x"] = add_property_json("Red X Shift", red_x.GetValue(requested_frame), "float", "", &red_x, -1, 1, false, requested_frame);
|
||||
|
||||
@@ -26,9 +26,9 @@ using namespace openshot;
|
||||
Crop::Crop() : Crop::Crop(0.0, 0.0, 0.0, 0.0, 0.0, 0.0) {}
|
||||
|
||||
Crop::Crop(
|
||||
Keyframe left, Keyframe top,
|
||||
Keyframe right, Keyframe bottom,
|
||||
Keyframe x, Keyframe y) :
|
||||
Keyframe left, Keyframe top,
|
||||
Keyframe right, Keyframe bottom,
|
||||
Keyframe x, Keyframe y) :
|
||||
left(left), top(top), right(right), bottom(bottom), x(x), y(y)
|
||||
{
|
||||
// Init effect properties
|
||||
@@ -62,48 +62,48 @@ std::shared_ptr<openshot::Frame> Crop::GetFrame(std::shared_ptr<openshot::Frame>
|
||||
double right_value = right.GetValue(frame_number);
|
||||
double bottom_value = bottom.GetValue(frame_number);
|
||||
|
||||
// Get the current shift amount
|
||||
double x_shift = x.GetValue(frame_number);
|
||||
double y_shift = y.GetValue(frame_number);
|
||||
// Get the current shift amount
|
||||
double x_shift = x.GetValue(frame_number);
|
||||
double y_shift = y.GetValue(frame_number);
|
||||
|
||||
QSize sz = frame_image->size();
|
||||
|
||||
// Compute destination rectangle to paint into
|
||||
QRectF paint_r(
|
||||
left_value * sz.width(), top_value * sz.height(),
|
||||
std::max(0.0, 1.0 - left_value - right_value) * sz.width(),
|
||||
std::max(0.0, 1.0 - top_value - bottom_value) * sz.height());
|
||||
// Compute destination rectangle to paint into
|
||||
QRectF paint_r(
|
||||
left_value * sz.width(), top_value * sz.height(),
|
||||
std::max(0.0, 1.0 - left_value - right_value) * sz.width(),
|
||||
std::max(0.0, 1.0 - top_value - bottom_value) * sz.height());
|
||||
|
||||
// Copy rectangle is destination translated by offsets
|
||||
QRectF copy_r = paint_r;
|
||||
copy_r.translate(x_shift * sz.width(), y_shift * sz.height());
|
||||
// Copy rectangle is destination translated by offsets
|
||||
QRectF copy_r = paint_r;
|
||||
copy_r.translate(x_shift * sz.width(), y_shift * sz.height());
|
||||
|
||||
// Constrain offset copy rect to stay within image borders
|
||||
if (copy_r.left() < 0) {
|
||||
paint_r.setLeft(paint_r.left() - copy_r.left());
|
||||
copy_r.setLeft(0);
|
||||
}
|
||||
if (copy_r.right() > sz.width()) {
|
||||
paint_r.setRight(paint_r.right() - (copy_r.right() - sz.width()));
|
||||
copy_r.setRight(sz.width());
|
||||
}
|
||||
if (copy_r.top() < 0) {
|
||||
paint_r.setTop(paint_r.top() - copy_r.top());
|
||||
copy_r.setTop(0);
|
||||
}
|
||||
if (copy_r.bottom() > sz.height()) {
|
||||
paint_r.setBottom(paint_r.bottom() - (copy_r.bottom() - sz.height()));
|
||||
copy_r.setBottom(sz.height());
|
||||
}
|
||||
// Constrain offset copy rect to stay within image borders
|
||||
if (copy_r.left() < 0) {
|
||||
paint_r.setLeft(paint_r.left() - copy_r.left());
|
||||
copy_r.setLeft(0);
|
||||
}
|
||||
if (copy_r.right() > sz.width()) {
|
||||
paint_r.setRight(paint_r.right() - (copy_r.right() - sz.width()));
|
||||
copy_r.setRight(sz.width());
|
||||
}
|
||||
if (copy_r.top() < 0) {
|
||||
paint_r.setTop(paint_r.top() - copy_r.top());
|
||||
copy_r.setTop(0);
|
||||
}
|
||||
if (copy_r.bottom() > sz.height()) {
|
||||
paint_r.setBottom(paint_r.bottom() - (copy_r.bottom() - sz.height()));
|
||||
copy_r.setBottom(sz.height());
|
||||
}
|
||||
|
||||
QImage cropped(sz, QImage::Format_RGBA8888_Premultiplied);
|
||||
cropped.fill(Qt::transparent);
|
||||
QImage cropped(sz, QImage::Format_RGBA8888_Premultiplied);
|
||||
cropped.fill(Qt::transparent);
|
||||
|
||||
const QImage src(*frame_image);
|
||||
const QImage src(*frame_image);
|
||||
|
||||
QPainter p(&cropped);
|
||||
p.drawImage(paint_r, src, copy_r);
|
||||
p.end();
|
||||
QPainter p(&cropped);
|
||||
p.drawImage(paint_r, src, copy_r);
|
||||
p.end();
|
||||
|
||||
// Set frame image
|
||||
frame->AddImage(std::make_shared<QImage>(cropped.copy()));
|
||||
@@ -129,8 +129,8 @@ Json::Value Crop::JsonValue() const {
|
||||
root["top"] = top.JsonValue();
|
||||
root["right"] = right.JsonValue();
|
||||
root["bottom"] = bottom.JsonValue();
|
||||
root["x"] = x.JsonValue();
|
||||
root["y"] = y.JsonValue();
|
||||
root["x"] = x.JsonValue();
|
||||
root["y"] = y.JsonValue();
|
||||
|
||||
// return JsonValue
|
||||
return root;
|
||||
@@ -168,31 +168,25 @@ void Crop::SetJsonValue(const Json::Value root) {
|
||||
right.SetJsonValue(root["right"]);
|
||||
if (!root["bottom"].isNull())
|
||||
bottom.SetJsonValue(root["bottom"]);
|
||||
if (!root["x"].isNull())
|
||||
x.SetJsonValue(root["x"]);
|
||||
if (!root["y"].isNull())
|
||||
y.SetJsonValue(root["y"]);
|
||||
if (!root["x"].isNull())
|
||||
x.SetJsonValue(root["x"]);
|
||||
if (!root["y"].isNull())
|
||||
y.SetJsonValue(root["y"]);
|
||||
}
|
||||
|
||||
// Get all properties for a specific frame
|
||||
std::string Crop::PropertiesJSON(int64_t requested_frame) const {
|
||||
|
||||
// Generate JSON properties list
|
||||
Json::Value root;
|
||||
root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
|
||||
root["position"] = add_property_json("Position", Position(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
|
||||
root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 1000 * 60 * 30, true, requested_frame);
|
||||
Json::Value root = BasePropertiesJSON(requested_frame);
|
||||
|
||||
// Keyframes
|
||||
root["left"] = add_property_json("Left Size", left.GetValue(requested_frame), "float", "", &left, 0.0, 1.0, false, requested_frame);
|
||||
root["top"] = add_property_json("Top Size", top.GetValue(requested_frame), "float", "", &top, 0.0, 1.0, false, requested_frame);
|
||||
root["right"] = add_property_json("Right Size", right.GetValue(requested_frame), "float", "", &right, 0.0, 1.0, false, requested_frame);
|
||||
root["bottom"] = add_property_json("Bottom Size", bottom.GetValue(requested_frame), "float", "", &bottom, 0.0, 1.0, false, requested_frame);
|
||||
root["x"] = add_property_json("X Offset", x.GetValue(requested_frame), "float", "", &x, -1.0, 1.0, false, requested_frame);
|
||||
root["y"] = add_property_json("Y Offset", y.GetValue(requested_frame), "float", "", &y, -1.0, 1.0, false, requested_frame);
|
||||
root["x"] = add_property_json("X Offset", x.GetValue(requested_frame), "float", "", &x, -1.0, 1.0, false, requested_frame);
|
||||
root["y"] = add_property_json("Y Offset", y.GetValue(requested_frame), "float", "", &y, -1.0, 1.0, false, requested_frame);
|
||||
|
||||
// Set the parent effect which properties this effect will inherit
|
||||
root["parent_effect_id"] = add_property_json("Parent", 0.0, "string", info.parent_effect_id, NULL, -1, -1, false, requested_frame);
|
||||
|
||||
@@ -131,16 +131,10 @@ void Deinterlace::SetJsonValue(const Json::Value root) {
|
||||
std::string Deinterlace::PropertiesJSON(int64_t requested_frame) const {
|
||||
|
||||
// Generate JSON properties list
|
||||
Json::Value root;
|
||||
root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
|
||||
root["position"] = add_property_json("Position", Position(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame);
|
||||
root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
|
||||
root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame);
|
||||
root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame);
|
||||
root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 30 * 60 * 60 * 48, true, requested_frame);
|
||||
root["isOdd"] = add_property_json("Is Odd Frame", isOdd, "bool", "", NULL, 0, 1, true, requested_frame);
|
||||
Json::Value root = BasePropertiesJSON(requested_frame);
|
||||
|
||||
// Add Is Odd Frame choices (dropdown style)
|
||||
root["isOdd"] = add_property_json("Is Odd Frame", isOdd, "bool", "", NULL, 0, 1, true, requested_frame);
|
||||
root["isOdd"]["choices"].append(add_property_choice_json("Yes", true, isOdd));
|
||||
root["isOdd"]["choices"].append(add_property_choice_json("No", false, isOdd));
|
||||
|
||||
|
||||
@@ -144,13 +144,7 @@ void Hue::SetJsonValue(const Json::Value root) {
|
||||
std::string Hue::PropertiesJSON(int64_t requested_frame) const {
|
||||
|
||||
// Generate JSON properties list
|
||||
Json::Value root;
|
||||
root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
|
||||
root["position"] = add_property_json("Position", Position(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
|
||||
root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
|
||||
root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 1000 * 60 * 30, true, requested_frame);
|
||||
Json::Value root = BasePropertiesJSON(requested_frame);
|
||||
|
||||
// Keyframes
|
||||
root["hue"] = add_property_json("Hue", hue.GetValue(requested_frame), "float", "", &hue, 0.0, 1.0, false, requested_frame);
|
||||
|
||||
@@ -87,13 +87,7 @@ void Negate::SetJsonValue(const Json::Value root) {
|
||||
std::string Negate::PropertiesJSON(int64_t requested_frame) const {
|
||||
|
||||
// Generate JSON properties list
|
||||
Json::Value root;
|
||||
root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
|
||||
root["position"] = add_property_json("Position", Position(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame);
|
||||
root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
|
||||
root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame);
|
||||
root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame);
|
||||
root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 30 * 60 * 60 * 48, true, requested_frame);
|
||||
Json::Value root = BasePropertiesJSON(requested_frame);
|
||||
|
||||
// Set the parent effect which properties this effect will inherit
|
||||
root["parent_effect_id"] = add_property_json("Parent", 0.0, "string", info.parent_effect_id, NULL, -1, -1, false, requested_frame);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user