svcore  1.9
PathModel.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 2007 QMUL.
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 _PATH_MODEL_H_
00017 #define _PATH_MODEL_H_
00018 
00019 #include "Model.h"
00020 #include "SparseModel.h"
00021 #include "base/RealTime.h"
00022 
00023 #include <QStringList>
00024 
00025 
00026 struct PathPoint
00027 {
00028     PathPoint(long _frame) : frame(_frame), mapframe(_frame) { }
00029     PathPoint(long _frame, long _mapframe) :
00030         frame(_frame), mapframe(_mapframe) { }
00031 
00032     int getDimensions() const { return 2; }
00033 
00034     long frame;
00035     long mapframe;
00036 
00037     QString getLabel() const { return ""; }
00038 
00039     void toXml(QTextStream &stream, QString indent = "",
00040                QString extraAttributes = "") const {
00041         stream << QString("%1<point frame=\"%2\" mapframe=\"%3\" %4/>\n")
00042             .arg(indent).arg(frame).arg(mapframe).arg(extraAttributes);
00043     }
00044         
00045     QString toDelimitedDataString(QString delimiter,
00046                                   int sampleRate) const {
00047         QStringList list;
00048         list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str();
00049         list << QString("%1").arg(mapframe);
00050         return list.join(delimiter);
00051     }
00052 
00053     struct Comparator {
00054         bool operator()(const PathPoint &p1, const PathPoint &p2) const {
00055             if (p1.frame != p2.frame) return p1.frame < p2.frame;
00056             return p1.mapframe < p2.mapframe;
00057         }
00058     };
00059     
00060     struct OrderComparator {
00061         bool operator()(const PathPoint &p1, const PathPoint &p2) const {
00062             return p1.frame < p2.frame;
00063         }
00064     };
00065 };
00066 
00067 class PathModel : public SparseModel<PathPoint>
00068 {
00069 public:
00070     PathModel(int sampleRate, int resolution, bool notify = true) :
00071         SparseModel<PathPoint>(sampleRate, resolution, notify) { }
00072 
00073     virtual void toXml(QTextStream &out,
00074                        QString indent = "",
00075                        QString extraAttributes = "") const
00076     {
00077         SparseModel<PathPoint>::toXml
00078             (out, 
00079              indent,
00080              QString("%1 subtype=\"path\"")
00081              .arg(extraAttributes));
00082     }
00083 
00087     virtual QString getHeading(int) const { return ""; }
00088     virtual bool isColumnTimeValue(int) const { return false; }
00089     virtual SortType getSortType(int) const { return SortNumeric; }
00090 
00091 };
00092 
00093 
00094 #endif