Mercurial > hg > svcore
changeset 838:33fca917c800
Add toDelimitedDataString alternative with frame extents
author | Chris Cannam |
---|---|
date | Wed, 09 Oct 2013 14:47:19 +0100 (2013-10-09) |
parents | 1de00ee53be1 |
children | 38bb7c8e415d |
files | data/model/DenseTimeValueModel.cpp data/model/DenseTimeValueModel.h data/model/EditableDenseThreeDimensionalModel.cpp data/model/EditableDenseThreeDimensionalModel.h data/model/Model.h data/model/SparseModel.h data/model/WaveFileModel.cpp |
diffstat | 7 files changed, 74 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/data/model/DenseTimeValueModel.cpp Wed Oct 09 14:45:21 2013 +0100 +++ b/data/model/DenseTimeValueModel.cpp Wed Oct 09 14:47:19 2013 +0100 @@ -16,6 +16,8 @@ #include "DenseTimeValueModel.h" #include "base/PlayParameterRepository.h" +#include <QStringList> + DenseTimeValueModel::DenseTimeValueModel() { PlayParameterRepository::getInstance()->addPlayable(this); @@ -26,3 +28,36 @@ PlayParameterRepository::getInstance()->removePlayable(this); } +QString +DenseTimeValueModel::toDelimitedDataString(QString delimiter, size_t f0, size_t f1) const +{ + size_t ch = getChannelCount(); + + std::cerr << "f0 = " << f0 << ", f1 = " << f1 << std::endl; + + if (f1 <= f0) return ""; + + float **all = new float *[ch]; + for (size_t c = 0; c < ch; ++c) { + all[c] = new float[f1 - f0]; + } + + size_t n = getData(0, ch - 1, f0, f1 - f0, all); + + QStringList list; + for (size_t i = 0; i < n; ++i) { + QStringList parts; + parts << QString("%1").arg(f0 + i); + for (size_t c = 0; c < ch; ++c) { + parts << QString("%1").arg(all[c][i]); + } + list << parts.join(delimiter); + } + + for (size_t c = 0; c < ch; ++c) { + delete[] all[c]; + } + delete[] all; + + return list.join("\n"); +}
--- a/data/model/DenseTimeValueModel.h Wed Oct 09 14:45:21 2013 +0100 +++ b/data/model/DenseTimeValueModel.h Wed Oct 09 14:47:19 2013 +0100 @@ -86,6 +86,8 @@ virtual QString getDefaultPlayPluginId() const { return ""; } virtual QString getDefaultPlayPluginConfiguration() const { return ""; } + virtual QString toDelimitedDataString(QString delimiter, size_t f0, size_t f1) const; + QString getTypeName() const { return tr("Dense Time-Value"); } };
--- a/data/model/EditableDenseThreeDimensionalModel.cpp Wed Oct 09 14:45:21 2013 +0100 +++ b/data/model/EditableDenseThreeDimensionalModel.cpp Wed Oct 09 14:47:19 2013 +0100 @@ -483,6 +483,24 @@ return s; } +QString +EditableDenseThreeDimensionalModel::toDelimitedDataString(QString delimiter, size_t f0, size_t f1) const +{ + QReadLocker locker(&m_lock); + QString s; + for (size_t i = 0; i < m_data.size(); ++i) { + size_t fr = m_startFrame + i * m_resolution; + if (fr >= f0 && fr < f1) { + QStringList list; + for (size_t j = 0; j < m_data.at(i).size(); ++j) { + list << QString("%1").arg(m_data.at(i).at(j)); + } + s += list.join(delimiter) + "\n"; + } + } + return s; +} + void EditableDenseThreeDimensionalModel::toXml(QTextStream &out, QString indent,
--- a/data/model/EditableDenseThreeDimensionalModel.h Wed Oct 09 14:45:21 2013 +0100 +++ b/data/model/EditableDenseThreeDimensionalModel.h Wed Oct 09 14:47:19 2013 +0100 @@ -139,6 +139,7 @@ QString getTypeName() const { return tr("Editable Dense 3-D"); } virtual QString toDelimitedDataString(QString delimiter) const; + virtual QString toDelimitedDataString(QString delimiter, size_t f0, size_t f1) const; virtual void toXml(QTextStream &out, QString indent = "",
--- a/data/model/Model.h Wed Oct 09 14:45:21 2013 +0100 +++ b/data/model/Model.h Wed Oct 09 14:47:19 2013 +0100 @@ -213,7 +213,12 @@ QString indent = "", QString extraAttributes = "") const; - virtual QString toDelimitedDataString(QString) const { return ""; } + virtual QString toDelimitedDataString(QString delimiter) const { + return toDelimitedDataString(delimiter, getStartFrame(), getEndFrame()); + } + virtual QString toDelimitedDataString(QString, size_t f0, size_t f1) const { + return ""; + } public slots: void aboutToDelete();
--- a/data/model/SparseModel.h Wed Oct 09 14:45:21 2013 +0100 +++ b/data/model/SparseModel.h Wed Oct 09 14:47:19 2013 +0100 @@ -157,6 +157,17 @@ return s; } + virtual QString toDelimitedDataString(QString delimiter, size_t f0, size_t f1) const + { + QString s; + for (PointListConstIterator i = m_points.begin(); i != m_points.end(); ++i) { + if (i->frame >= f0 && i->frame < f1) { + s += i->toDelimitedDataString(delimiter, m_sampleRate) + "\n"; + } + } + return s; + } + /** * Command to add a point, with undo. */