SparseTimeValueModel.h

Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2006 Chris Cannam.
00008     
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #ifndef _SPARSE_TIME_VALUE_MODEL_H_
00017 #define _SPARSE_TIME_VALUE_MODEL_H_
00018 
00019 #include "SparseValueModel.h"
00020 #include "base/PlayParameterRepository.h"
00021 #include "base/RealTime.h"
00022 
00029 struct TimeValuePoint
00030 {
00031 public:
00032     TimeValuePoint(long _frame) : frame(_frame), value(0.0f) { }
00033     TimeValuePoint(long _frame, float _value, QString _label) : 
00034         frame(_frame), value(_value), label(_label) { }
00035 
00036     int getDimensions() const { return 2; }
00037     
00038     long frame;
00039     float value;
00040     QString label;
00041 
00042     QString getLabel() const { return label; }
00043     
00044     void toXml(QTextStream &stream, QString indent = "",
00045                QString extraAttributes = "") const
00046     {
00047         stream << QString("%1<point frame=\"%2\" value=\"%3\" label=\"%4\" %5/>\n")
00048             .arg(indent).arg(frame).arg(value).arg(label).arg(extraAttributes);
00049     }
00050 
00051     QString toDelimitedDataString(QString delimiter, size_t sampleRate) const
00052     {
00053         QStringList list;
00054         list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str();
00055         list << QString("%1").arg(value);
00056         if (label != "") list << label;
00057         return list.join(delimiter);
00058     }
00059 
00060     struct Comparator {
00061         bool operator()(const TimeValuePoint &p1,
00062                         const TimeValuePoint &p2) const {
00063             if (p1.frame != p2.frame) return p1.frame < p2.frame;
00064             if (p1.value != p2.value) return p1.value < p2.value;
00065             return p1.label < p2.label;
00066         }
00067     };
00068     
00069     struct OrderComparator {
00070         bool operator()(const TimeValuePoint &p1,
00071                         const TimeValuePoint &p2) const {
00072             return p1.frame < p2.frame;
00073         }
00074     };
00075 };
00076 
00077 
00078 class SparseTimeValueModel : public SparseValueModel<TimeValuePoint>
00079 {
00080 public:
00081     SparseTimeValueModel(size_t sampleRate, size_t resolution,
00082                          bool notifyOnAdd = true) :
00083         SparseValueModel<TimeValuePoint>(sampleRate, resolution,
00084                                          notifyOnAdd)
00085     {
00086         PlayParameterRepository::getInstance()->addModel(this);
00087     }
00088 
00089     SparseTimeValueModel(size_t sampleRate, size_t resolution,
00090                          float valueMinimum, float valueMaximum,
00091                          bool notifyOnAdd = true) :
00092         SparseValueModel<TimeValuePoint>(sampleRate, resolution,
00093                                          valueMinimum, valueMaximum,
00094                                          notifyOnAdd)
00095     {
00096         PlayParameterRepository::getInstance()->addModel(this);
00097     }
00098 
00099     QString getTypeName() const { return tr("Sparse Time-Value"); }
00100 };
00101 
00102 
00103 #endif
00104 
00105 
00106     

Generated on Wed Feb 20 15:45:28 2008 for SonicVisualiser by  doxygen 1.5.1