test_sdk/script/gtl_scr_spec_harm.cpp

161 lines
3.7 KiB
C++
Raw Normal View History

#include "gtl_scr_spec_harm.h"
namespace gtl
{
namespace scr
{
spec_harm::spec_harm(QObject *parent, qreal freq, int color, qreal weight)
: QObject{parent}
, _freq(freq)
, _color(color)
, _weight(weight)
, _tolerance(1)
{
}
spec_harm::spec_harm(QObject *parent)
: QObject{parent}
, _weight(1)
, _tolerance(1)
{
}
qreal spec_harm::freq() const
{
return _freq;
}
qreal spec_harm::peak_freq() const
{
qreal peak_freq = -1;
emit get_peak_freq(_freq, _tolerance, peak_freq);
return peak_freq;
}
int spec_harm::color() const
{
return _color;
}
qreal spec_harm::weight() const
{
return _weight;
}
bool spec_harm::is_present() const
{
return peak_freq() >= 0;
}
qreal spec_harm::amplitude() const
{
qreal freq = peak_freq();
if(freq < 0)
freq = _freq;
qreal value = 0;
emit get_amplitude(freq, value);
return value;
}
qreal spec_harm::level() const
{
return amplitude() - base();
}
qreal spec_harm::base() const
{
qreal freq = peak_freq();
if(freq < 0)
freq = _freq;
qreal value = 0;
emit get_base(freq, value);
return value;
}
qreal spec_harm::tolerance() const
{
return _tolerance;
}
qreal spec_harm::integral_index() const
{
qreal max_hamr_ampl = 0;
emit get_max_harm_ampl(max_hamr_ampl);
if(max_hamr_ampl == 0)
return 0;
qreal modulating_harms_intergal_index = 0;
emit get_modulating_harms_integral_index(modulating_harms_intergal_index);
return level()/max_hamr_ampl*weight() + modulating_harms_intergal_index;
}
void spec_harm::update()
{
emit amplitude_changed();
}
void spec_harm::save_state(QJsonObject &root)
{
root.insert("freq", freq());
root.insert("color", color());
root.insert("weight", weight());
root.insert("tolerance", tolerance());
root.insert("is_present", is_present());
root.insert("level", level());
root.insert("ampl", amplitude());
root.insert("base", base());
}
void spec_harm::restor_state(const QJsonObject &root)
{
_freq = root["freq"].toDouble();
_color = root["color"].toInt();
_weight = root["weight"].toDouble();
_tolerance = root["tolerance"].toDouble();
}
void spec_harm::get_max_level(qreal &max_ampl)
{
qreal ampl = level();
if(ampl > max_ampl)
max_ampl = ampl;
}
void spec_harm::set_color(int value)
{
if(_color != value)
{
_color = value;
emit color_changed();
}
}
void spec_harm::set_weight(qreal value)
{
if(_weight != value)
{
_weight = value;
emit weight_changed();
}
}
void spec_harm::set_tolerance(qreal value)
{
if(value != _tolerance)
{
_tolerance = value;
emit tolerance_changed();
}
}
}
}