20 #include <QTextStream> 21 #include <QStringList> 22 #include <QReadLocker> 23 #include <QWriteLocker> 38 m_sampleRate(sampleRate),
39 m_resolution(resolution),
40 m_yBinCount(yBinCount),
41 m_compression(compression),
45 m_notifyOnAdd(notifyOnAdd),
46 m_sinceLastNotifyMin(-1),
47 m_sinceLastNotifyMax(-1),
85 QReadLocker locker(&
m_lock);
95 for (
int i = 0; i <
m_data.size(); ++i) {
159 QReadLocker locker(&
m_lock);
160 if (index < 0 || index >=
m_data.size())
return Column();
168 if (
int(n) < c.size())
return c.at(n);
178 assert(
int(index) <
m_data.size());
201 static int maxdist = 6;
218 }
else if (ptrunc > 0) {
227 if (p.size() == h && tdist <= maxdist) {
229 int bcount = 0, tcount = 0;
230 if (!known || !top) {
232 for (
int i = 0; i < h; ++i) {
233 if (values.at(i) == p.at(i)) ++bcount;
239 for (
int i = h; i > 0; --i) {
240 if (values.at(i-1) == p.at(i-1)) ++tcount;
244 if (!known) top = (tcount > bcount);
247 if ((top ? tcount : bcount) > limit) {
254 for (
int i = bcount; i < h; ++i) {
255 tcol[i - bcount] = values.at(i);
265 for (
int i = 0; i < h - tcount; ++i) {
266 tcol[i] = values.at(i);
290 assert(index >= 0 && index <
int(
m_data.size()));
295 int trunc = (int)
m_trunc[index];
301 if (trunc < 0) { top =
false; tdist = -trunc; }
303 int psize = p.size(), csize = c.size();
305 cerr <<
"WARNING: EditableDenseThreeDimensionalModel::expandAndRetrieve: Trying to expand from incorrectly sized column" << endl;
308 for (
int i = csize; i < psize; ++i) {
309 c.push_back(p.at(i));
317 for (
int i = 0; i < psize - csize; ++i) {
320 for (
int i = 0; i < csize; ++i) {
321 cc[i + (psize - csize)] = c.at(i);
332 QWriteLocker locker(&
m_lock);
334 while (
int(index) >=
m_data.size()) {
339 bool allChange =
false;
343 for (
int i = 0; i < values.size(); ++i) {
344 float value = values[i];
363 long windowStart = index;
446 QReadLocker locker(&
m_lock);
448 QVector<float> sample;
451 for (
int i = 0; i < 10; ++i) {
453 if (index <
m_data.size()) {
455 while (c.size() > sample.size()) {
456 sample.push_back(0.f);
459 for (
int j = 0; j < c.size(); ++j) {
460 sample[j] += c.at(j);
466 if (sample.empty())
return false;
467 for (
int j = 0; j < sample.size(); ++j) {
468 if (n[j]) sample[j] /= n[j];
480 if (completion == 100) {
505 QReadLocker locker(&
m_lock);
507 for (
int i = 0; i <
m_data.size(); ++i) {
509 for (
int j = 0; j <
m_data.at(i).size(); ++j) {
510 list << QString(
"%1").arg(
m_data.at(i).at(j));
512 s += list.join(delimiter) +
"\n";
520 QReadLocker locker(&
m_lock);
522 for (
int i = 0; i <
m_data.size(); ++i) {
524 if (fr >=
int(f0) && fr < int(f1)) {
526 for (
int j = 0; j <
m_data.at(i).size(); ++j) {
527 list << QString(
"%1").arg(
m_data.at(i).at(j));
529 s += list.join(delimiter) +
"\n";
538 QString extraAttributes)
const 540 QReadLocker locker(&
m_lock);
544 SVDEBUG <<
"EditableDenseThreeDimensionalModel::toXml" << endl;
548 QString(
"type=\"dense\" dimensions=\"3\" windowSize=\"%1\" yBinCount=\"%2\" minimum=\"%3\" maximum=\"%4\" dataset=\"%5\" startFrame=\"%6\" %7")
555 .arg(extraAttributes));
558 out << QString(
"<dataset id=\"%1\" dimensions=\"3\" separator=\" \">\n")
561 for (
int i = 0; i < (int)
m_binNames.size(); ++i) {
564 out << QString(
"<bin number=\"%1\" name=\"%2\"/>\n")
569 for (
int i = 0; i < (int)
m_data.size(); ++i) {
571 out << QString(
"<row n=\"%1\">").arg(i);
572 for (
int j = 0; j < (int)
m_data.at(i).size(); ++j) {
573 if (j > 0) out <<
" ";
574 out <<
m_data.at(i).at(j);
576 out << QString(
"</row>\n");
580 out << indent +
"</dataset>\n";
virtual bool isOK() const
Return true if the model was constructed successfully.
virtual void toXml(QTextStream &out, QString indent="", QString extraAttributes="") const
Stream this exportable object out to XML on a text stream.
virtual void setMinimumLevel(float sz)
Set the minimum value of the value in a bin.
long m_sinceLastNotifyMax
virtual QString toDelimitedDataStringSubset(QString delimiter, int f0, int f1) const
virtual QString getBinValueUnit() const
Obtain the name of the unit of the values returned from getBinValue(), if any.
virtual QString getBinName(int n) const
Return the name of bin n.
std::vector< float > m_binValues
long m_sinceLastNotifyMin
virtual void setBinName(int n, QString)
Set the name of bin n.
virtual float getValueAt(int x, int n) const
Get a single value, from the n'th bin of the given column.
void completionChanged()
Emitted when some internal processing has advanced a stage, but the model has not changed externally.
static int getObjectExportId(const void *)
void modelChangedWithin(int startFrame, int endFrame)
Emitted when a model has been edited (or more data retrieved from cache, in the case of a cached mode...
virtual QString toDelimitedDataString(QString delimiter) const
virtual void setCompletion(int completion, bool update=true)
virtual int getStartFrame() const
Return the first audio frame spanned by the model.
virtual float getMinimumLevel() const
Return the minimum value of the value in each bin.
virtual void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const
Stream this exportable object out to XML on a text stream.
EditableDenseThreeDimensionalModel(int sampleRate, int resolution, int yBinCount, CompressionType compression, bool notifyOnAdd=true)
virtual float getMaximumLevel() const
Return the maximum value of the value in each bin.
bool shouldUseLogValueScale() const
Return true if the distribution of values in the bins is such as to suggest a log scale (mapping to c...
virtual int getHeight() const
Return the number of bins in each set of bins.
Column expandAndRetrieve(int index) const
virtual void setBinValueUnit(QString unit)
Set the name of the unit of the values return from getBinValue() if any.
virtual void setStartFrame(int)
Set the frame offset of the first column.
static bool useLogScale(std::vector< float > values)
Estimate whether a set of values would be more properly shown using a logarithmic than a linear scale...
void modelChanged()
Emitted when a model has been edited (or more data retrieved from cache, in the case of a cached mode...
virtual Column getColumn(int x) const
Get the set of bin values at the given column.
virtual float getBinValue(int n) const
Return the value of bin n, if any.
virtual void setBinNames(std::vector< QString > names)
Set the names of all bins.
virtual int getResolution() const
Return the number of sample frames covered by each set of bins.
Model is the base class for all data models that represent any sort of data on a time scale based on ...
virtual void setMaximumLevel(float sz)
Set the maximum value of the value in a bin.
std::vector< signed char > m_trunc
void truncateAndStore(int index, const Column &values)
virtual int getSampleRate() const
Return the frame rate in frames per second.
virtual int getEndFrame() const
Return the last audio frame spanned by the model.
CompressionType m_compression
virtual Model * clone() const
Return a copy of this model.
virtual void setResolution(int sz)
Set the number of sample frames covered by each set of bins.
virtual void setBinValues(std::vector< float > values)
Set the values of all bins (separate from their labels).
virtual void setHeight(int sz)
Set the number of bins in each set of bins.
virtual void setColumn(int x, const Column &values)
Set the entire set of bin values at the given column.
std::vector< QString > m_binNames
virtual bool hasBinValues() const
Return true if the bins have values as well as names.
virtual int getWidth() const
Return the number of columns.