Mercurial > hg > svcore
diff data/model/FFTModel.cpp @ 1744:b92bdcd4954b by-id
Update FFT model to ById
author | Chris Cannam |
---|---|
date | Tue, 02 Jul 2019 11:49:28 +0100 |
parents | d08b560102a1 |
children | 6d09d68165a4 |
line wrap: on
line diff
--- a/data/model/FFTModel.cpp Mon Jul 01 14:16:12 2019 +0100 +++ b/data/model/FFTModel.cpp Tue Jul 02 11:49:28 2019 +0100 @@ -32,13 +32,13 @@ static HitCount inSmallCache("FFTModel: Small FFT cache"); static HitCount inSourceCache("FFTModel: Source data cache"); -FFTModel::FFTModel(const DenseTimeValueModel *model, +FFTModel::FFTModel(ModelId modelId, int channel, WindowType windowType, int windowSize, int windowIncrement, int fftSize) : - m_model(model), + m_model(modelId), m_channel(channel), m_windowType(windowType), m_windowSize(windowSize), @@ -61,32 +61,51 @@ m_fft.initFloat(); - connect(model, SIGNAL(modelChanged()), - this, SIGNAL(modelChanged())); - connect(model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)), - this, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t))); - connect(model, SIGNAL(aboutToBeDeleted()), - this, SLOT(sourceModelAboutToBeDeleted())); + auto model = ModelById::getAs<DenseTimeValueModel>(m_model); + if (model) { + connect(model.get(), SIGNAL(modelChanged()), + this, SIGNAL(modelChanged())); + connect(model.get(), SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)), + this, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t))); + } } FFTModel::~FFTModel() { } -void -FFTModel::sourceModelAboutToBeDeleted() +bool +FFTModel::isOK() const { - if (m_model) { - SVDEBUG << "FFTModel[" << this << "]::sourceModelAboutToBeDeleted(" << m_model << ")" << endl; - m_model = nullptr; + auto model = ModelById::getAs<DenseTimeValueModel>(m_model); + return (model && model->isOK()); +} + +int +FFTModel::getCompletion() const +{ + int c = 100; + auto model = ModelById::getAs<DenseTimeValueModel>(m_model); + if (model) { + if (model->isReady(&c)) return 100; } + return c; +} + +sv_samplerate_t +FFTModel::getSampleRate() const +{ + auto model = ModelById::getAs<DenseTimeValueModel>(m_model); + if (model) return model->getSampleRate(); + else return 0; } int FFTModel::getWidth() const { - if (!m_model) return 0; - return int((m_model->getEndFrame() - m_model->getStartFrame()) + auto model = ModelById::getAs<DenseTimeValueModel>(m_model); + if (!model) return 0; + return int((model->getEndFrame() - model->getStartFrame()) / m_windowIncrement) + 1; } @@ -277,7 +296,8 @@ { Profiler profiler("FFTModel::getSourceDataUncached"); - if (!m_model) return {}; + auto model = ModelById::getAs<DenseTimeValueModel>(m_model); + if (!model) return {}; decltype(range.first) pfx = 0; if (range.first < 0) { @@ -285,14 +305,14 @@ range = { 0, range.second }; } - auto data = m_model->getData(m_channel, - range.first, - range.second - range.first); + auto data = model->getData(m_channel, + range.first, + range.second - range.first); if (data.empty()) { SVDEBUG << "NOTE: empty source data for range (" << range.first << "," << range.second << ") (model end frame " - << m_model->getEndFrame() << ")" << endl; + << model->getEndFrame() << ")" << endl; } // don't return a partial frame @@ -304,7 +324,7 @@ } if (m_channel == -1) { - int channels = m_model->getChannelCount(); + int channels = model->getChannelCount(); if (channels > 1) { int n = int(data.size()); float factor = 1.f / float(channels);